@excalidraw/element 0.18.0-7876ee524 → 0.18.0-880dbb25e
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 +10 -6
- package/dist/dev/index.js.map +2 -2
- package/dist/prod/index.js +1 -1
- package/package.json +3 -3
package/dist/prod/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var dc=Object.create;var bs=Object.defineProperty;var cc=Object.getOwnPropertyDe
|
|
|
17
17
|
L ${s-f} ${a+E}
|
|
18
18
|
C ${s} ${a}, ${s} ${a}, ${s+f} ${a+E}`,Re(e,!0))}else r=t.polygon([[s,a],[l,d],[c,u],[p,m]],Re(e));return r}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,Re(e));case"line":case"arrow":{let r,s=Re(e),a=e.points.length?e.points:[de(0,0)];if(G(e)?a.every(l=>Math.abs(l[0])<=1e6&&Math.abs(l[1])<=1e6)?r=[t.path(Hl(a,16),Re(e,!0))]:(console.error("Elbow arrow with extreme point positions detected. Arrow not rendered.",e.id,JSON.stringify(a)),r=[]):e.roundness?r=[t.curve(a,s)]:s.fill?r=[t.polygon(a,s)]:r=[t.linearPath(a,s)],e.type==="arrow"){let{startArrowhead:l=null,endArrowhead:d="arrow"}=e;if(l!==null){let c=Nl(e,r,"start",l,t,s,i);r.push(...c)}if(d!==null){let c=Nl(e,r,"end",d,t,s,i);r.push(...c)}}return r}case"freedraw":{let r;if(Ol(e),cn(e.points)){let s=Wn(e.points,.75);r=t.curve(s,{...Re(e),stroke:"none"})}else r=null;return r}case"frame":case"magicframe":case"text":case"image":return null;default:return Qm(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},Hl=(e,t)=>{let n=[];for(let o=1;o<e.length-1;o+=1){let r=e[o-1],s=e[o+1],a=e[o],l=et(a,r),d=et(s,a),c=Math.min(t,Rl(e[o],s)/2,Rl(e[o],r)/2);l?r[0]<a[0]?n.push([e[o][0]-c,e[o][1]]):n.push([e[o][0]+c,e[o][1]]):r[1]<a[1]?n.push([e[o][0],e[o][1]-c]):n.push([e[o][0],e[o][1]+c]),n.push(e[o]),d?s[0]<a[0]?n.push([e[o][0]-c,e[o][1]]):n.push([e[o][0]+c,e[o][1]]):s[1]<a[1]?n.push([e[o][0],e[o][1]-c]):n.push([e[o][0],e[o][1]+c])}let i=[`M ${e[0][0]} ${e[0][1]}`];for(let o=0;o<n.length;o+=3)i.push(`L ${n[o][0]} ${n[o][1]}`),i.push(`Q ${n[o+1][0]} ${n[o+1][1]}, ${n[o+2][0]} ${n[o+2][1]}`);return i.push(`L ${e[e.length-1][0]} ${e[e.length-1][1]}`),i.join(" ")},_l=(e,t)=>{switch(e.type){case"rectangle":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return Rs(e);case"arrow":case"line":{let n=be.get(e)?.[0]??be.generateElementShape(e,null)[0],[,,,,i,o]=_(e,t);return Xi(e)?Hs(e,n,de(e.x,e.y),e.angle,de(i,o)):Ns(n,de(e.x,e.y),e.angle,de(i,o))}case"ellipse":return Fs(e);case"freedraw":{let[,,,,n,i]=_(e,t);return zs(e,de(n,i),Xi(e))}}},nl=(e,t)=>{let n=[...e.points];if(t){if(!la(e.points))return null;let o=n[0],r=n[n.length-1];Math.hypot(o[0]-r[0],o[1]-r[1])>ef||n.length<4?n.push(de(o[0],o[1])):n[n.length-1]=de(o[0],o[1])}return{polygon:t,points:n}};var Ur=class e{static boundsCache=new WeakMap;static nonRotatedBoundsCache=new WeakMap;static getBounds(t,n,i=!1){let o=i&&t.angle!==0?e.nonRotatedBoundsCache.get(t):e.boundsCache.get(t);if(o?.version&&o.version===t.version&&!ce(t))return o.bounds;if(i&&t.angle!==0){let s=e.calculateBounds({...t,angle:0},n);return e.nonRotatedBoundsCache.set(t,{version:t.version,bounds:s}),s}let r=e.calculateBounds(t,n);return e.boundsCache.set(t,{version:t.version,bounds:r}),r}static calculateBounds(t,n){let i,[o,r,s,a,l,d]=_(t,n);if(Se(t)){let[c,u,p,m]=Xr(t.points.map(([f,E])=>se(D(f,E),D(l-t.x,d-t.y),t.angle)));return[c+t.x,u+t.y,p+t.x,m+t.y]}else if(W(t))i=mf(t,l,d,n);else if(t.type==="diamond"){let[c,u]=se(D(l,r),D(l,d),t.angle),[p,m]=se(D(l,a),D(l,d),t.angle),[f,E]=se(D(o,d),D(l,d),t.angle),[h,g]=se(D(s,d),D(l,d),t.angle),x=Math.min(c,p,f,h),y=Math.min(u,m,E,g),b=Math.max(c,p,f,h),w=Math.max(u,m,E,g);i=[x,y,b,w]}else if(t.type==="ellipse"){let c=(s-o)/2,u=(a-r)/2,p=Math.cos(t.angle),m=Math.sin(t.angle),f=Math.hypot(c*p,u*m),E=Math.hypot(u*p,c*m);i=[l-f,d-E,l+f,d+E]}else{let[c,u]=se(D(o,r),D(l,d),t.angle),[p,m]=se(D(o,a),D(l,d),t.angle),[f,E]=se(D(s,a),D(l,d),t.angle),[h,g]=se(D(s,r),D(l,d),t.angle),x=Math.min(c,p,f,h),y=Math.min(u,m,E,g),b=Math.max(c,p,f,h),w=Math.max(u,m,E,g);i=[x,y,b,w]}return i}},_=(e,t,n=!1)=>{if(Se(e))return df(e);if(W(e))return U.getElementAbsoluteCoords(e,t,n);if(ie(e)){let i=t?Ce(e,t):null;if(Y(i)){let{x:o,y:r}=U.getBoundTextElementPosition(i,e,t);return[o,r,o+e.width,r+e.height,o+e.width/2,r+e.height/2]}}return[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2]},Rr=(e,t)=>{let n=_l(e,t),[i,o,r,s,a,l]=_(e,t),d=D(a,l);if(n.type==="polycurve"){let g=n.data.map(b=>Et(b,10)).flat(),x=0,y=[];for(;x<g.length-1;)y.push(Ee(D(g[x][0],g[x][1]),D(g[x+1][0],g[x+1][1]))),x++;return y}else{if(n.type==="polyline")return n.data;if(af(e)){let[h,g]=Pn(e),x=g.map(b=>Xl(b,d,e.angle)).flat();return[...Ul(h,d,e.angle),...x]}else if(e.type==="diamond"){let[h,g]=In(e),x=g.map(b=>Xl(b,d,e.angle)).flat();return[...Ul(h,d,e.angle),...x]}else if(n.type==="polygon"){if(ie(e)){let x=Ce(e,t);if(x&&W(x))return[Ee(D(i,o),D(r,o)),Ee(D(r,o),D(r,s)),Ee(D(r,s),D(i,s)),Ee(D(i,s),D(i,o))]}let h=n.data,g=[];for(let x=0;x<h.length-1;x++)g.push(Ee(h[x],h[x+1]));return g}else if(n.type==="ellipse")return lf(e)}let[c,u,p,m,,,f,E]=[[i,o],[r,o],[i,s],[r,s],[a,o],[a,s],[i,l],[r,l]].map(h=>se(h,d,e.angle));return[Ee(c,u),Ee(p,m),Ee(c,p),Ee(u,m),Ee(c,E),Ee(p,E),Ee(u,f),Ee(m,f)]},af=e=>e!=null&&(e.type==="rectangle"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),Ul=(e,t,n)=>e.map(i=>Ee(se(i[0],t,n),se(i[1],t,n))),Xl=(e,t,n)=>{let i=Et(e,10),o=0,r=[];for(;o<i.length-1;)r.push(Ee(se(D(i[o][0],i[o][1]),t,n),se(D(i[o+1][0],i[o+1][1]),t,n))),o++;return r},lf=e=>{let t=D(e.x+e.width/2,e.y+e.height/2),n=e.width/2,i=e.height/2,o=[],r=[],s=90,a=Math.PI*2/s;for(let l=0;l<s;l++){let d=l*a,c=t[0]+n*Math.cos(d),u=t[1]+i*Math.sin(d);r.push(se(D(c,u),t,e.angle))}for(let l=0;l<r.length-1;l++)o.push(Ee(r[l],r[l+1]));return o.push(Ee(r[r.length-1],r[0])),o},G0=e=>[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2],Bi=e=>{let t=Math.floor(e.width/2)+1,n=0,i=e.width,o=Math.floor(e.height/2)+1,r=t,s=e.height;return[t,n,i,o,r,s,0,o]},Wl=(e,t,n,i,o)=>{let r=1-e;return Math.pow(r,3)*t+3*Math.pow(r,2)*e*n+3*r*Math.pow(e,2)*i+Math.pow(e,3)*o},jl=(e,t,n,i)=>{let o=t-e,r=n-t,s=i-n,a=3*o-6*r+3*s,l=6*r-6*o,d=3*o,c=l*l-4*a*d;if(!(c>=0))return!1;let p=null,m=null,f=1/0,E=1/0;return a===0?f=E=-d/l:(f=(-l+Math.sqrt(c))/(2*a),E=(-l-Math.sqrt(c))/(2*a)),f>=0&&f<=1&&(p=Wl(f,e,t,n,i)),E>=0&&E<=1&&(m=Wl(E,e,t,n,i)),[p,m]},Wi=(e,t,n,i)=>{let o=jl(e[0],t[0],n[0],i[0]),r=jl(e[1],t[1],n[1],i[1]),s=Math.min(e[0],i[0]),a=Math.max(e[0],i[0]);if(o){let c=o.filter(u=>u!==null);s=Math.min(s,...c),a=Math.max(a,...c)}let l=Math.min(e[1],i[1]),d=Math.max(e[1],i[1]);if(r){let c=r.filter(u=>u!==null);l=Math.min(l,...c),d=Math.max(d,...c)}return[s,l,a,d]},si=(e,t)=>{let n=D(0,0),{minX:i,minY:o,maxX:r,maxY:s}=e.reduce((a,{op:l,data:d})=>{if(l==="move"){let c=$l(d);Yr(c!=null,"Op data is not a point"),n=c}else if(l==="bcurveTo"){let c=D(d[0],d[1]),u=D(d[2],d[3]),p=D(d[4],d[5]),m=t?t(c):c,f=t?t(u):u,E=t?t(p):p,h=t?t(n):n;n=p;let[g,x,y,b]=Wi(h,m,f,E);a.minX=Math.min(a.minX,g),a.minY=Math.min(a.minY,x),a.maxX=Math.max(a.maxX,y),a.maxY=Math.max(a.maxY,b)}return a},{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});return[i,o,r,s]},Xr=e=>{let t=1/0,n=1/0,i=-1/0,o=-1/0;for(let[r,s]of e)t=Math.min(t,r),n=Math.min(n,s),i=Math.max(i,r),o=Math.max(o,s);return[t,n,i,o]},df=e=>{let[t,n,i,o]=Xr(e.points),r=t+e.x,s=n+e.y,a=i+e.x,l=o+e.y;return[r,s,a,l,(r+a)/2,(s+l)/2]},cf=e=>{switch(e){case"arrow":return 25;case"diamond":case"diamond_outline":return 12;case"crowfoot_many":case"crowfoot_one":case"crowfoot_one_or_many":return 20;default:return 15}},uf=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},Hr=(e,t,n,i)=>{if(t.length<1)return null;let o=gt(t[0]);if(o.length<1)return null;let r=n==="start"?1:o.length-1,s=o[r].data;Yr(s.length===6,"Op data length is not 6");let a=D(s[4],s[5]),l=D(s[2],s[3]),d=D(s[0],s[1]),c=o[r-1],u=D(0,0);if(c.op==="move"){let z=$l(c.data);Yr(z!=null,"Op data is not a point"),u=z}else c.op==="bcurveTo"&&(u=D(c.data[4],c.data[5]));let p=(z,te)=>Math.pow(1-z,3)*a[te]+3*z*Math.pow(1-z,2)*l[te]+3*Math.pow(z,2)*(1-z)*d[te]+u[te]*Math.pow(z,3),[m,f]=n==="start"?u:a,[E,h]=[p(.3,0),p(.3,1)],g=Math.hypot(m-E,f-h),x=(m-E)/g,y=(f-h)/g,b=cf(i),w=0;{let[z,te]=n==="end"?e.points[e.points.length-1]:e.points[0],[S,Q]=e.points.length>1?n==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];w=Math.hypot(z-S,te-Q)}let M=Math.min(b,w*(i==="diamond"||i==="diamond_outline"?.25:.5)),v=m-x*M,T=f-y*M;if(i==="dot"||i==="circle"||i==="circle_outline"){let z=Math.hypot(T-f,v-m)+e.strokeWidth-2;return[m,f,z]}let F=uf(i);if(i==="crowfoot_many"||i==="crowfoot_one_or_many"){let[z,te]=se(D(m,f),D(v,T),_r(-F)),[S,Q]=se(D(m,f),D(v,T),_r(F));return[v,T,z,te,S,Q]}let[C,R]=se(D(v,T),D(m,f),-F*Math.PI/180),[L,V]=se(D(v,T),D(m,f),_r(F));if(i==="diamond"||i==="diamond_outline"){let z,te;if(n==="start"){let[S,Q]=e.points.length>1?e.points[1]:[0,0];[z,te]=se(D(m+M*2,f),D(m,f),Math.atan2(Q-f,S-m))}else{let[S,Q]=e.points.length>1?e.points[e.points.length-2]:[0,0];[z,te]=se(D(m-M*2,f),D(m,f),Math.atan2(f-Q,m-S))}return[m,f,C,R,z,te,L,V]}return[m,f,C,R,L,V]},pf=e=>{let t=dn.generator(),n=Re(e),i=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[i](e.points,n)},mf=(e,t,n,i)=>{let o=j(e,i);if(e.points.length<2){let[u,p]=e.points[0],[m,f]=se(D(e.x+u,e.y+p),D(t,n),e.angle),E=[m,f,m,f];if(o){let h=U.getMinMaxXYWithBoundText(e,i,[m,f,m,f],o);E=[h[0],h[1],h[2],h[3]]}return E}let s=be.get(e)?.[0]??pf(e),a=gt(s),d=si(a,([u,p])=>se(D(e.x+u,e.y+p),D(t,n),e.angle)),c=[d[0],d[1],d[2],d[3]];if(o){let u=U.getMinMaxXYWithBoundText(e,i,c,o);c=[u[0],u[1],u[2],u[3]]}return c},he=(e,t,n=!1)=>Ur.getBounds(e,t,n),tt=(e,t)=>{if(!rf(e))return[0,0,0,0];let n=1/0,i=-1/0,o=1/0,r=-1/0,s=t||Vl(e);return e.forEach(a=>{let[l,d,c,u]=he(a,s);n=Math.min(n,l),o=Math.min(o,d),i=Math.max(i,c),r=Math.max(r,u)}),[n,o,i,r]},O0=(e,t)=>{let[n,i,o,r]=tt(e);return[n+t.x,i+t.y,o+t.x,r+t.y]},Nt=(e,t,n,i)=>{if(!(W(e)||Se(e)))return[e.x,e.y,e.x+t,e.y+n];let o=Yl(0,t,Yl(1,n,e.points,i),i),r;if(Se(e))r=Xr(o);else{let c=dn.generator(),u=e.roundness?c.curve(o,Re(e)):c.linearPath(o,Re(e)),p=gt(u);r=si(p)}let[s,a,l,d]=r;return[s+e.x,a+e.y,l+e.x,d+e.y]},Lr=(e,t)=>{let n=dn.generator(),i=e.roundness==null?n.linearPath(t,Re(e)):n.curve(t,Re(e)),o=gt(i),[r,s,a,l]=si(o);return[r+e.x,s+e.y,a+e.x,l+e.y]},k0=(e,t)=>{if(!e.length)return[0,0,0,0];let n=1/0,i=e[0],o=Vl(e);return e.forEach(r=>{let[s,a,l,d]=he(r,o),c=sf(D((s+l)/2,(a+d)/2),D(t.x,t.y));c<n&&(n=c,i=r)}),he(i,o)},Ct=e=>{let[t,n,i,o]=tt(e);return{minX:t,minY:n,maxX:i,maxY:o,width:i-t,height:o-n,midX:(t+i)/2,midY:(n+o)/2}},R0=({scrollX:e,scrollY:t,width:n,height:i,zoom:o})=>[-e,-t,-e+n/o.value,-t+i/o.value],dt=e=>D(e[0]+(e[2]-e[0])/2,e[1]+(e[3]-e[1])/2),Ve=(e,t,n)=>{let i={minX:e.x,minY:e.y,maxX:e.x+e.width,maxY:e.y+e.height,midX:e.x+e.width/2,midY:e.y+e.height/2},o=fe(e,t),[r,s]=se(D(i.minX,i.minY),o,e.angle),[a,l]=se(D(i.maxX,i.minY),o,e.angle),[d,c]=se(D(i.maxX,i.maxY),o,e.angle),[u,p]=se(D(i.minX,i.maxY),o,e.angle),m=[Math.min(r,a,d,u),Math.min(s,l,c,p),Math.max(r,a,d,u),Math.max(s,l,c,p)];if(n){let[f,E,h,g]=n;return[m[0]-g,m[1]-f,m[2]+E,m[3]+h]}return m},An=(e,t)=>e[0]>t[0]&&e[0]<t[2]&&e[1]>t[1]&&e[1]<t[3],fn=(e,t)=>{if(e==null||t==null)return!1;let[n,i,o,r]=e,[s,a,l,d]=t;return n<l&&o>s&&i<d&&r>a},fe=(e,t,n=0,i=0)=>{let[o,r]=dt(he(e,t));return D(o+n,r+i)};var gf=.1,ql=e=>W(e)||Se(e)?e.points.length<2||e.points.length===2&&Y(e)&&Ef(e.points[0],e.points[e.points.length-1],gf):e.width===0&&e.height===0,yl=(e,t,n,i,o)=>{let[r,s,a,l]=he(e,o),d=xo({clientX:i.offsetLeft,clientY:i.offsetTop},i),c=xo({clientX:i.offsetLeft+t,clientY:i.offsetTop+n},i);return d.x<=a&&d.y<=l&&c.x>=r&&c.y>=s},X0=(e,t,n,i,o,r)=>{let[s,a,l,d]=tt(e,o),c=xo({clientX:i.offsetLeft+(r?.left||0),clientY:i.offsetTop+(r?.top||0)},i),u=xo({clientX:i.offsetLeft+t-(r?.right||0),clientY:i.offsetTop+n-(r?.bottom||0)},i);return s>=c.x&&a>=c.y&&l<=u.x&&d<=u.y},Wr=(e,t,n)=>{let i=Math.abs(t),o=Math.abs(n);if(e==="line"||e==="arrow"||e==="freedraw"){let r=Math.round(Math.atan(o/i)/Bt)*Bt;r===0?n=0:r===Math.PI/2?t=0:n=i*Math.tan(r)*Math.sign(n)||n}else e!=="selection"&&(n=i*Math.sign(n));return{width:t,height:n}},il=(e,t,n,i,o)=>{let r=n-e,s=i-t,a=Math.atan2(s,r),l=Math.round(a/Bt)*Bt;if(o){let d=Math.floor(o/Bt)*Bt;ff(a,d,d+Bt)&&(hf(a,o)<Bt/6?l=o:Zl(a)>Zl(o)?l=d+Bt:l=d)}if(l===0)s=0;else if(l===Math.PI/2)r=0;else{let d=Math.tan(l),c=-1,u=t-d*e,p=-1/d,m=-1,f=i-p*n,E=(c*f-m*u)/(d*m-p*c),h=(u*p-f*d)/(d*m-p*c);r=E-e,s=h-t}return{width:r,height:s}},W0=e=>{let t={width:e.width,height:e.height,x:e.x,y:e.y};if(e.width<0){let n=Math.abs(e.width);t.width=n,t.x=e.x-n}if(e.height<0){let n=Math.abs(e.height);t.height=n,t.y=e.y-n}return t};P();var K0=(e,t,n,i)=>{let o=uo(e,n.getNonDeletedElementsMap(),i),r=Ct(e);return o.flatMap(s=>{let a=xf(s,r,t);return s.map(l=>{let d=n.mutateElement(l,{x:l.x+a.x,y:l.y+a.y});return Ue(l,n,{simultaneouslyUpdated:s}),d})})},xf=(e,t,{axis:n,position:i})=>{let o=Ct(e),[r,s]=n==="x"?["minX","maxX"]:["minY","maxY"],a={x:0,y:0};return i==="start"?{...a,[n]:t[r]-o[r]}:i==="end"?{...a,[n]:t[s]-o[s]}:{...a,[n]:(t[r]+t[s])/2-(o[r]+o[s])/2}};P();import{arrayToMap as mh,arrayToObject as Gt,assertNever as Ad,isDevEnv as en,isShallowEqual as vd,isTestEnv as tn,randomInteger as Td}from"@excalidraw/common";P();import{assertNever as Df,COLOR_PALETTE as Lf,isDevEnv as Cf,isTestEnv as Bf,randomId as Gf,Emitter as Jl,toIterable as On}from"@excalidraw/common";P();import{ORIG_ID as Pf,randomId as Ql,randomInteger as If,arrayToMap as Sf,castArray as jr,findLastIndex as li,getUpdatedTimestamp as Mf,isTestEnv as Tf}from"@excalidraw/common";P();import{arrayToMapWithIndex as wf}from"@excalidraw/common";var yf=e=>{let t=e.slice(),n=new Set,i=r=>{let s=r[0]?.groupIds?.join(""),a=[r[0]],l=[];for(let d of r.slice(1))d.groupIds?.join("")===s?a.push(d):l.push(d);return l.length?[...a,...i(l)]:a},o=new Map;return t.forEach((r,s)=>{if(!o.has(r.id))if(r.groupIds?.length){let a=r.groupIds[r.groupIds.length-1],l=t.slice(s).filter(d=>{let c=d?.groupIds?.some(u=>u===a);return c&&o.set(d.id,!0),c});for(let d of i(l))n.add(d)}else n.add(r)}),n.size!==e.length?(console.error("normalizeGroupElementOrder: lost some elements... bailing!"),e):[...n]},bf=e=>{let t=wf(e),n=e.slice(),i=new Set;return n.forEach((o,r)=>{o&&(o.boundElements?.length?(i.add(o),n[r]=null,o.boundElements.forEach(s=>{let a=t.get(s.id);a&&s.type==="text"&&(i.add(a[0]),n[a[1]]=null)})):o.type==="text"&&o.containerId&&t.get(o.containerId)?.[0].boundElements?.find(a=>a.id===o.id)||(i.add(o),n[r]=null))}),i.size!==e.length?(console.error("normalizeBoundElementsOrder: lost some elements... bailing!"),e):[...i]},Kl=e=>bf(yf(e));var Af=(e,t,n,i)=>{let o=$r(n);return Tf()&&vf(o,n.id),o.id=Ql(),o.updated=Mf(),i&&(o.seed=If(),ka(o)),o.groupIds=xl(o.groupIds,e,r=>(t.has(r)||t.set(r,Ql()),t.get(r))),o},u1=e=>{let{elements:t}=e,n="appState"in e?e.appState:{editingGroupId:null,selectedGroupIds:{}},i=new Map,o=new Map,r=[],s=[],a=new Map,l=new Map,d=new Map,c=Sf(t),u=e.type==="in-place"?e.idsOfElementsToDuplicate:new Map(t.map(h=>[h.id,h]));if(e.type==="in-place")for(let h of Object.keys(e.appState.selectedGroupIds))t.filter(g=>g.groupIds?.includes(h)).forEach(g=>u.set(g.id,g));t=Kl(t);let p=t.slice(),m=h=>{let x=jr(h).reduce((y,b)=>{if(i.has(b.id))return y;i.set(b.id,!0);let w=Af(n.editingGroupId,o,b,e.randomizeSeed);return i.set(w.id,!0),d.set(w.id,w),a.set(b.id,w.id),l.set(w.id,b),s.push(b),r.push(w),y.push(w),y},[]);return Array.isArray(h)?x:x[0]||null},f=(h,g)=>{if(g){if(h>p.length-1){p.push(...jr(g));return}p.splice(h+1,0,...jr(g))}},E=new Set(t.filter(h=>u.has(h.id)&&Z(h)).map(h=>h.id));for(let h of t){if(i.has(h.id)||!u.has(h.id))continue;let g=Gr(n,h);if(g){let x=Ae(t,g).flatMap(b=>Z(b)?[...qt(t,b.id),b]:[b]),y=li(p,b=>b.groupIds?.includes(g));f(y,m(x));continue}if(!(h.frameId&&E.has(h.frameId))){if(Z(h)){let x=h.id,y=qt(t,x),b=li(p,w=>w.frameId===x||w.id===x);f(b,m([...y,h]));continue}if(st(h)){let x=j(h,c),y=li(p,b=>b.id===h.id||"containerId"in b&&b.containerId===h.id);x?f(y,m([h,x])):f(y,m(h));continue}if(ce(h)){let x=Ce(h,c),y=li(p,b=>b.id===h.id||b.id===x?.id);x?f(y,m([x,h])):f(y,m(h));continue}f(li(p,x=>x.id===h.id),m(h))}}if($a(r,a,d),bl(p,s,a),e.overrides)for(let h of r){let g=l.get(h.id);g&&Object.assign(h,e.overrides({duplicateElement:h,origElement:g,origIdToDuplicateId:a}))}return{duplicatedElements:r,duplicateElementsMap:d,elementsWithDuplicates:p,origIdToDuplicateId:a}},Vr=(e,t=0)=>{if(e==null||typeof e!="object")return e;let n=Object.prototype.toString.call(e);if(n==="[object Object]"){let i=typeof e.constructor=="function"?Object.create(Object.getPrototypeOf(e)):{};for(let o in e)if(e.hasOwnProperty(o)){if(t===0&&(o==="shape"||o==="canvas"))continue;i[o]=Vr(e[o],t+1)}return i}if(Array.isArray(e)){let i=e.length,o=new Array(i);for(;i--;)o[i]=Vr(e[i],t+1);return o}return A.DEV&&n!=="[object Object]"&&n!=="[object Array]"&&n.startsWith("[object ")&&console.warn(`_deepCloneElement: unexpected object type ${n}. This value will not be cloned!`),e},$r=e=>Vr(e),vf=(e,t)=>{Object.defineProperty(e,Pf,{value:t,writable:!1,enumerable:!1})};var Fe={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},ed=class{constructor(t){this.app=t}onDurableIncrementEmitter=new Jl;onStoreIncrementEmitter=new Jl;scheduledMacroActions=new Set;scheduledMicroActions=[];_snapshot=Jt.empty();get snapshot(){return this._snapshot}set snapshot(t){this._snapshot=t}scheduleAction(t){this.scheduledMacroActions.add(t),this.satisfiesScheduledActionsInvariant()}scheduleCapture(){this.scheduleAction(Fe.IMMEDIATELY)}scheduleMicroAction(t){let{action:n}=t,i;if("change"in t)i=t.change;else{let r=Jt.create(this.app.scene.getElementsMapIncludingDeleted(),this.app.state),s=r.maybeClone(n,t.elements?id(t.elements):void 0,t.appState);i=di.create(r,s)}let o="delta"in t?t.delta:void 0;this.scheduledMicroActions.push(()=>this.processAction({action:n,change:i,delta:o}))}commit(t,n){this.flushMicroActions();try{let i=this.getScheduledMacroAction();this.processAction({action:i,elements:t,appState:n})}finally{this.satisfiesScheduledActionsInvariant(),this.scheduledMacroActions=new Set}}clear(){this.snapshot=Jt.empty(),this.scheduledMacroActions=new Set}emitDurableIncrement(t,n=void 0,i=void 0){let o=this.snapshot,r,s;if(n?r=n:r=di.create(o,t),i?s=i:s=Kr.calculate(o,t),!s.isEmpty()){let a=new Zr(r,s);this.onDurableIncrementEmitter.trigger(a),this.onStoreIncrementEmitter.trigger(a)}}emitEphemeralIncrement(t,n=void 0){let i;if(n)i=n;else{let r=this.snapshot;i=di.create(r,t)}let o=new qr(i);this.onStoreIncrementEmitter.trigger(o)}applyChangeToSnapshot(t){let n=this.snapshot,i=this.snapshot.applyChange(t);return n===i?null:i}maybeCloneSnapshot(t,n,i){if(!n&&!i)return null;let o=this.snapshot,r=this.snapshot.maybeClone(t,n,i);return o===r?null:r}flushMicroActions(){for(let t of this.scheduledMicroActions)try{t()}catch(n){console.error("Failed to execute scheduled micro action",n)}this.scheduledMicroActions=[]}processAction(t){let{action:n}=t;if(n===Fe.EVENTUALLY&&!this.onStoreIncrementEmitter.subscribers.length)return;let i;if("change"in t?i=this.applyChangeToSnapshot(t.change):i=this.maybeCloneSnapshot(n,t.elements,t.appState),!i)return;let o="change"in t?t.change:void 0,r="delta"in t?t.delta:void 0;try{switch(n){case Fe.IMMEDIATELY:this.emitDurableIncrement(i,o,r);break;case Fe.NEVER:case Fe.EVENTUALLY:this.emitEphemeralIncrement(i,o);break;default:Df(n,"Unknown store action")}}finally{switch(n){case Fe.IMMEDIATELY:case Fe.NEVER:this.snapshot=i;break}}}getScheduledMacroAction(){let t;return this.scheduledMacroActions.has(Fe.IMMEDIATELY)?t=Fe.IMMEDIATELY:this.scheduledMacroActions.has(Fe.NEVER)?t=Fe.NEVER:t=Fe.EVENTUALLY,t}satisfiesScheduledActionsInvariant(){if(!(this.scheduledMacroActions.size>=0&&this.scheduledMacroActions.size<=Object.keys(Fe).length)){let t=`There can be at most three store actions scheduled at the same time, but there are "${this.scheduledMacroActions.size}".`;if(console.error(t,this.scheduledMacroActions.values()),Bf()||Cf())throw new Error(t)}}},di=class e{constructor(t,n){this.elements=t;this.appState=n}static create(t,n){let i=n.getChangedElements(t),o=n.getChangedAppState(t);return new e(i,o)}},wo=class{constructor(t,n){this.type=t;this.change=n}static isDurable(t){return t.type==="durable"}static isEphemeral(t){return t.type==="ephemeral"}},Zr=class extends wo{constructor(n,i){super("durable",n);this.change=n;this.delta=i}},qr=class extends wo{constructor(n){super("ephemeral",n);this.change=n}},Kr=class{constructor(t,n,i){this.id=t;this.elements=n;this.appState=i}static create(t,n,i={id:Gf()}){return new this(i.id,t,n)}static calculate(t,n){let i=n.metadata.didElementsChange?gn.calculate(t.elements,n.elements):gn.empty(),o=n.metadata.didAppStateChange?En.calculate(t.appState,n.appState):En.empty();return this.create(i,o)}static restore(t){let{id:n,elements:i,appState:o}=t;return new this(n,gn.restore(i),En.restore(o))}static load({id:t,elements:{added:n,removed:i,updated:o},appState:{delta:r}}){let s=gn.create(n,i,o),a=En.create(r);return new this(t,s,a)}squash(t){return this.elements.squash(t.elements),this.appState.squash(t.appState),this}static inverse(t){return this.create(t.elements.inverse(),t.appState.inverse())}static applyTo(t,n,i,o){let[r,s]=t.elements.applyTo(n,Jt.empty().elements,o),[a,l]=t.appState.applyTo(i,r);return[r,a,s||l]}static applyLatestChanges(t,n,i,o){return this.create(t.elements.applyLatestChanges(n,i,o),t.appState,{id:t.id})}isEmpty(){return this.elements.isEmpty()&&this.appState.isEmpty()}},Jt=class e{constructor(t,n,i={didElementsChange:!1,didAppStateChange:!1,isEmpty:!1}){this.elements=t;this.appState=n;this.metadata=i}_lastChangedElementsHash=0;_lastChangedAppStateHash=0;static create(t,n,i={didElementsChange:!1,didAppStateChange:!1}){return new e(t,td(n)?n:kn(n),i)}static empty(){return new e(new Map,Of(),{didElementsChange:!1,didAppStateChange:!1,isEmpty:!0})}getChangedElements(t){let n={};for(let i of On(t.elements))this.elements.get(i.id)||(n[i.id]=Me(i,{isDeleted:!0}));for(let i of On(this.elements))t.elements.get(i.id)!==i&&(n[i.id]=i);return n}getChangedAppState(t){return N.getRightDifferences(t.appState,this.appState).reduce((n,i)=>Object.assign(n,{[i]:this.appState[i]}),{})}isEmpty(){return this.metadata.isEmpty}applyChange(t){let n=new Map(this.elements);for(let[o,r]of Object.entries(t.elements))n.set(o,r);let i=kn({...this.appState,...t.appState});return e.create(n,i,{didElementsChange:Object.keys(t.elements).length>0,didAppStateChange:Object.keys(t.appState).length>0})}maybeClone(t,n,i){let o={shouldCompareHashes:!1};t===Fe.EVENTUALLY&&(o.shouldCompareHashes=!0);let r=this.maybeCreateElementsSnapshot(n,o),s=this.maybeCreateAppStateSnapshot(i,o),a=!1,l=!1;return this.elements!==r&&(a=!0),this.appState!==s&&(l=!0),!a&&!l?this:new e(r,s,{didElementsChange:a,didAppStateChange:l})}maybeCreateAppStateSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.appState;let i=td(t)?t:kn(t);return this.detectChangedAppState(i,n)?i:this.appState}maybeCreateElementsSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.elements;let i=this.detectChangedElements(t,n);return i?.size?this.createElementsSnapshot(i):this.elements}detectChangedAppState(t,n={shouldCompareHashes:!1}){if(this.appState===t)return;let i=N.isRightDifferent(this.appState,t);if(!i)return;let o=rd(JSON.stringify(t));if(!(n.shouldCompareHashes&&this._lastChangedAppStateHash===o))return this._lastChangedAppStateHash=o,i}detectChangedElements(t,n={shouldCompareHashes:!1}){if(this.elements===t)return;let i=new Map;for(let r of On(this.elements))t.get(r.id)||i.set(r.id,Me(r,{isDeleted:!0}));for(let r of On(t)){let s=this.elements.get(r.id);if(!s||s.version<r.version){if(xe(r)&&!zt(r))continue;i.set(r.id,r)}}if(!i.size)return;let o=od(i);if(!(n.shouldCompareHashes&&this._lastChangedElementsHash===o))return this._lastChangedElementsHash=o,i}createElementsSnapshot(t){let n=new Map;for(let i of On(this.elements))n.set(i.id,i);for(let i of On(t))n.set(i.id,$r(i));return n}},nd="__observedAppState",Of=()=>({name:null,editingGroupId:null,viewBackgroundColor:Lf.white,selectedElementIds:{},selectedGroupIds:{},selectedLinearElement:null,croppingElementId:null,activeLockedId:null,lockedMultiSelections:{}}),kn=e=>{let t={name:e.name,editingGroupId:e.editingGroupId,viewBackgroundColor:e.viewBackgroundColor,selectedElementIds:e.selectedElementIds,selectedGroupIds:e.selectedGroupIds,croppingElementId:e.croppingElementId,activeLockedId:e.activeLockedId,lockedMultiSelections:e.lockedMultiSelections,selectedLinearElement:e.selectedLinearElement?{elementId:e.selectedLinearElement.elementId,isEditing:!!e.selectedLinearElement.isEditing}:null};return Reflect.defineProperty(t,nd,{value:!0,enumerable:!1}),t},td=e=>!!Reflect.get(e,nd);P();P();var ld="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function Fn(e,t,n){let i=n[0];if(t!=null&&e>=t)throw new Error(e+" >= "+t);if(e.slice(-1)===i||t&&t.slice(-1)===i)throw new Error("trailing zero");if(t){let s=0;for(;(e[s]||i)===t[s];)s++;if(s>0)return t.slice(0,s)+Fn(e.slice(s),t.slice(s),n)}let o=e?n.indexOf(e[0]):0,r=t!=null?n.indexOf(t[0]):n.length;if(r-o>1){let s=Math.round(.5*(o+r));return n[s]}else return t&&t.length>1?t.slice(0,1):n[o]+Fn(e.slice(1),null,n)}function dd(e){if(e.length!==cd(e[0]))throw new Error("invalid integer part of order key: "+e)}function cd(e){if(e>="a"&&e<="z")return e.charCodeAt(0)-97+2;if(e>="A"&&e<="Z")return 90-e.charCodeAt(0)+2;throw new Error("invalid order key head: "+e)}function ci(e){let t=cd(e[0]);if(t>e.length)throw new Error("invalid order key: "+e);return e.slice(0,t)}function sd(e,t){if(e==="A"+t[0].repeat(26))throw new Error("invalid order key: "+e);let n=ci(e);if(e.slice(n.length).slice(-1)===t[0])throw new Error("invalid order key: "+e)}function ad(e,t){dd(e);let[n,...i]=e.split(""),o=!0;for(let r=i.length-1;o&&r>=0;r--){let s=t.indexOf(i[r])+1;s===t.length?i[r]=t[0]:(i[r]=t[s],o=!1)}if(o){if(n==="Z")return"a"+t[0];if(n==="z")return null;let r=String.fromCharCode(n.charCodeAt(0)+1);return r>"a"?i.push(t[0]):i.pop(),r+i.join("")}else return n+i.join("")}function kf(e,t){dd(e);let[n,...i]=e.split(""),o=!0;for(let r=i.length-1;o&&r>=0;r--){let s=t.indexOf(i[r])-1;s===-1?i[r]=t.slice(-1):(i[r]=t[s],o=!1)}if(o){if(n==="a")return"Z"+t.slice(-1);if(n==="A")return null;let r=String.fromCharCode(n.charCodeAt(0)-1);return r<"Z"?i.push(t.slice(-1)):i.pop(),r+i.join("")}else return n+i.join("")}function Rn(e,t,n=ld){if(e!=null&&sd(e,n),t!=null&&sd(t,n),e!=null&&t!=null&&e>=t)throw new Error(e+" >= "+t);if(e==null){if(t==null)return"a"+n[0];let l=ci(t),d=t.slice(l.length);if(l==="A"+n[0].repeat(26))return l+Fn("",d,n);if(l<t)return l;let c=kf(l,n);if(c==null)throw new Error("cannot decrement any more");return c}if(t==null){let l=ci(e),d=e.slice(l.length),c=ad(l,n);return c??l+Fn(d,null,n)}let i=ci(e),o=e.slice(i.length),r=ci(t),s=t.slice(r.length);if(i===r)return i+Fn(o,s,n);let a=ad(i,n);if(a==null)throw new Error("cannot increment any more");return a<t?a:i+Fn(o,null,n)}function yo(e,t,n,i=ld){if(n===0)return[];if(n===1)return[Rn(e,t,i)];if(t==null){let s=Rn(e,t,i),a=[s];for(let l=0;l<n-1;l++)s=Rn(s,t,i),a.push(s);return a}if(e==null){let s=Rn(e,t,i),a=[s];for(let l=0;l<n-1;l++)s=Rn(e,s,i),a.push(s);return a.reverse(),a}let o=Math.floor(n/2),r=Rn(e,t,i);return[...yo(e,r,o,i),r,...yo(r,t,n-o-1,i)]}import{arrayToMap as bo}from"@excalidraw/common";var Qr=class extends Error{code="ELEMENT_HAS_INVALID_INDEX"},Rf=(e,{shouldThrow:t=!1,includeBoundTextValidation:n=!1,ignoreLogs:i,reconciliationContext:o})=>{let r=[],s=l=>`${l?.index}:${l?.id}:${l?.type}:${l?.isDeleted}:${l?.version}:${l?.versionNonce}`,a=e.map(l=>l.index);for(let[l,d]of a.entries()){let c=a[l-1],u=a[l+1];if(Jr(d,c,u)||r.push(`Fractional indices invariant has been compromised: "${s(e[l-1])}", "${s(e[l])}", "${s(e[l+1])}"`),n&&st(e[l])){let p=e[l],m=j(p,bo(e));m&&m.index<=p.index&&r.push(`Fractional indices invariant for bound elements has been compromised: "${s(m)}", "${s(p)}"`)}}if(r.length){let l=new Qr,d=[];if(o&&(d.push("Additional reconciliation context:"),d.push(o.localElements.map(c=>s(c))),d.push(o.remoteElements.map(c=>s(c)))),i||console.error(r.join(`
|
|
19
19
|
|
|
20
|
-
`),l.stack,e.map(c=>s(c)),...d),t)throw l}},pd=e=>e.sort((t,n)=>ud(t)&&ud(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),ui=(e,t)=>{try{let n=bo(e),i=Nf(e,t),o=es(e,i),r=e.map(s=>{let a=o.get(s);return a?{...s,index:a.index}:s});Rf(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of o)ye(s,n,{index:a})}catch{Ff(e)}return e},Ff=e=>{let t=bo(e),n=md(e),i=es(e,n);for(let[o,{index:r}]of i)ye(o,t,{index:r});return e},id=e=>{let t=bo(e),n=md(e),i=es(e,n);for(let[o,{index:r}]of i)t.set(o.id,Me(o,{index:r}));return t},Nf=(e,t)=>{let n=[],i=0;for(;i<e.length;)if(t.has(e[i].id)){let o=[i-1,i];for(;++i<e.length&&t.has(e[i].id);)o.push(i);o.push(i),n.push(o)}else i++;return n},md=e=>{let t=[],n,i,o=-1,r=0,s=d=>{let c=e[o]?e[o].index:void 0,u=e[d-1]?.index;return!c&&u||c&&u&&u>c?[u,d-1]:[c,o]},a=d=>{let c=e[r]?e[r].index:void 0;if(c&&d<r)return[c,r];let u=r;for(;++u<e.length;){let p=e[u]?.index;if(!c&&p||c&&p&&p>c)return[p,u]}return[void 0,u]},l=0;for(;l<e.length;){let d=e[l].index;if([n,o]=s(l),[i,r]=a(l),Jr(d,n,i))l++;else{let c=[o,l];for(;++l<e.length;){let u=e[l].index,[p,m]=s(l),[f,E]=a(l);if(Jr(u,p,f))break;[n,o]=[p,m],[i,r]=[f,E],c.push(l)}c.push(r),t.push(c)}}return t},Jr=(e,t,n)=>e?t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e:!1,es=(e,t)=>{let n=new Map;for(let i of t){let o=i.shift(),r=i.pop(),s=yo(e[o]?.index,e[r]?.index,i.length);for(let a=0;a<i.length;a++){let l=e[i[a]];n.set(l,{index:s[a]})}}return n},ud=e=>!!e.index;P();var Md=gc(xd(),1);import{randomInteger as nh,arrayToMap as wd,toBrandedType as yd,isDevEnv as bd,isTestEnv as Pd,toArray as ih}from"@excalidraw/common";import{isNonDeletedElement as oh}from"@excalidraw/element";import{isFrameLikeElement as rh}from"@excalidraw/element";import{getElementsInGroup as sh}from"@excalidraw/element";import{syncInvalidIndices as ah,syncMovedIndices as Id,validateFractionalIndices as lh}from"@excalidraw/element";import{getSelectedElements as dh}from"@excalidraw/element";import{mutateElement as ch}from"@excalidraw/element";var Sd=e=>{let t=new Map,n=[];for(let i of e)i.isDeleted||(n.push(i),t.set(i.id,i));return{elementsMap:t,elements:n}},uh=(0,Md.default)(e=>{(bd()||Pd()||window?.DEBUG_FRACTIONAL_INDICES)&&lh(e,{shouldThrow:bd()||Pd(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),ph=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let i of t)n+=`${i}:${e[i]?"1":"0"}`;return n},Io=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=yd(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=yd(new Map);selectedElementsCache={selectedElementIds:null,elements:null,cache:new Map};sceneNonce;getSceneNonce(){return this.sceneNonce}getNonDeletedElementsMap(){return this.nonDeletedElementsMap}getElementsIncludingDeleted(){return this.elements}getElementsMapIncludingDeleted(){return this.elementsMap}getNonDeletedElements(){return this.nonDeletedElements}getFramesIncludingDeleted(){return this.frames}constructor(t=null,n){t&&this.replaceAllElements(t,n)}getSelectedElements(t){let n=ph(t),i=t?.elements||this.nonDeletedElements;if(this.selectedElementsCache.elements===i&&this.selectedElementsCache.selectedElementIds===t.selectedElementIds){let r=this.selectedElementsCache.cache.get(n);if(r)return r}else t?.elements==null&&this.selectedElementsCache.cache.clear();let o=dh(i,{selectedElementIds:t.selectedElementIds},t);return t?.elements==null&&(this.selectedElementsCache.selectedElementIds=t.selectedElementIds,this.selectedElementsCache.elements=this.nonDeletedElements,this.selectedElementsCache.cache.set(n,o)),o}getNonDeletedFramesLikes(){return this.nonDeletedFramesLikes}getElement(t){return this.elementsMap.get(t)||null}getNonDeletedElement(t){let n=this.getElement(t);return n&&oh(n)?n:null}mapElements(t){let n=!1,i=this.elements.map(o=>{let r=t(o);return r!==o&&(n=!0),r});return n&&this.replaceAllElements(i),n}replaceAllElements(t,n){let i=ih(t),o=[];n?.skipValidation||uh(i),this.elements=ah(i),this.elementsMap.clear(),this.elements.forEach(s=>{rh(s)&&o.push(s),this.elementsMap.set(s.id,s)});let r=Sd(this.elements);this.nonDeletedElements=r.elements,this.nonDeletedElementsMap=r.elementsMap,this.frames=o,this.nonDeletedFramesLikes=Sd(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=nh();for(let t of Array.from(this.callbacks))t()}onUpdate(t){if(this.callbacks.has(t))throw new Error;return this.callbacks.add(t),()=>{if(!this.callbacks.has(t))throw new Error;this.callbacks.delete(t)}}destroy(){this.elements=[],this.nonDeletedElements=[],this.nonDeletedFramesLikes=[],this.frames=[],this.elementsMap.clear(),this.selectedElementsCache.selectedElementIds=null,this.selectedElementsCache.elements=null,this.selectedElementsCache.cache.clear(),this.callbacks.clear()}insertElementAtIndex(t,n){if(!Number.isFinite(n)||n<0)throw new Error("insertElementAtIndex can only be called with index >= 0");let i=[...this.elements.slice(0,n),t,...this.elements.slice(n)];Id(i,wd([t])),this.replaceAllElements(i)}insertElementsAtIndex(t,n){if(!t.length)return;if(!Number.isFinite(n)||n<0)throw new Error("insertElementAtIndex can only be called with index >= 0");let i=[...this.elements.slice(0,n),...t,...this.elements.slice(n)];Id(i,wd(t)),this.replaceAllElements(i)}insertElement=t=>{let n=t.frameId?this.getElementIndex(t.frameId):this.elements.length;this.insertElementAtIndex(t,n)};insertElements=t=>{if(!t.length)return;let n=t[0]?.frameId?this.getElementIndex(t[0].frameId):this.elements.length;this.insertElementsAtIndex(t,n)};getElementIndex(t){return this.elements.findIndex(n=>n.id===t)}getContainerElement=t=>t&&t.containerId&&this.getElement(t.containerId)||null;getElementsFromId=t=>{let n=this.getNonDeletedElementsMap(),i=n.get(t);return i?[i]:sh(n,t)};mutateElement(t,n,i={informMutation:!0,isDragging:!1}){let o=this.getNonDeletedElementsMap(),{version:r}=t,{version:s}=ch(t,o,n,i);return this.elementsMap.has(t.id)&&r!==s&&i.informMutation&&this.triggerUpdate(),t}};var N=class e{constructor(t,n){this.deleted=t;this.inserted=n}static create(t,n,i,o){let r=i&&o!=="inserted"?i(t,"deleted"):t,s=i&&o!=="deleted"?i(n,"inserted"):n;return new e(r,s)}static calculate(t,n,i,o){if(t===n)return e.empty();let r={},s={};for(let d of this.getDifferences(t,n))r[d]=t[d],s[d]=n[d];let[a,l]=o?o(r,s):[r,s];return e.create(a,l,i)}static empty(){return new e({},{})}static isEmpty(t){return!Object.keys(t.deleted).length&&!Object.keys(t.inserted).length}static merge(t,n,i){return e.create({...t.deleted,...n.deleted,...i?.deleted??{}},{...t.inserted,...n.inserted,...i?.inserted??{}})}static mergeObjects(t,n,i){let o={...t};for(let r of Object.keys(i??{}))delete o[r];return{...o,...n}}static mergeArrays(t,n,i,o){return Object.values(e.mergeObjects(Gt(t??[],o),Gt(n??[],o),Gt(i??[],o)))}static diffObjects(t,n,i,o){if(!t[i]&&!n[i])return;let r=t[i]!==null&&typeof t[i]=="object",s=n[i]!==null&&typeof n[i]=="object";if(r||s){let a=t[i]??{},l=n[i]??{},d=e.getLeftDifferences(a,l).reduce((u,p)=>(u[p]=o(a[p]),u),{}),c=e.getRightDifferences(a,l).reduce((u,p)=>(u[p]=o(l[p]),u),{});Object.keys(d).length||Object.keys(c).length?(Reflect.set(t,i,d),Reflect.set(n,i,c)):(Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i))}else t[i]===n[i]&&(Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i))}static diffArrays(t,n,i,o){if(!(!t[i]&&!n[i])&&(Array.isArray(t[i])||Array.isArray(n[i]))){let r=Array.isArray(t[i])?t[i]:[],s=Array.isArray(n[i])?n[i]:[],a=Gt(e.getLeftDifferences(Gt(r,o),Gt(s,o)),d=>d),l=Gt(e.getRightDifferences(Gt(r,o),Gt(s,o)),d=>d);if(Object.keys(a).length||Object.keys(l).length){let d=r.filter(u=>a[o?o(u):String(u)]),c=s.filter(u=>l[o?o(u):String(u)]);Reflect.set(t,i,d),Reflect.set(n,i,c)}else Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i)}}static isLeftDifferent(t,n,i=!1){return!!this.distinctKeysIterator("left",t,n,i).next().value}static isRightDifferent(t,n,i=!1){return!!this.distinctKeysIterator("right",t,n,i).next().value}static isInnerDifferent(t,n,i=!1){return!!!!this.distinctKeysIterator("inner",t,n,i).next().value}static isDifferent(t,n,i=!1){return!!!!this.distinctKeysIterator("full",t,n,i).next().value}static getLeftDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("left",t,n,i)).sort()}static getRightDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("right",t,n,i)).sort()}static getInnerDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("inner",t,n,i)).sort()}static getDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("full",t,n,i)).sort()}static*distinctKeysIterator(t,n,i,o=!1){if(n===i)return;let r=[];t==="left"?r=Object.keys(n):t==="right"?r=Object.keys(i):t==="inner"?r=Object.keys(n).filter(s=>s in i):t==="full"?r=Array.from(new Set([...Object.keys(n),...Object.keys(i)])):Ad(t,`Unknown distinctKeysIterator's join param "${t}"`,!0);for(let s of r){let a=n[s],l=i[s];if(a!==l){if(!o&&typeof a=="object"&&typeof l=="object"&&a!==null&&l!==null&&vd(a,l))continue;yield s}}}},En=class e{constructor(t){this.delta=t}static create(t){return new e(t)}static calculate(t,n){let i=N.calculate(t,n,e.orderAppStateKeys,e.postProcess);return new e(i)}static restore(t){let{delta:n}=t;return new e(n)}static empty(){return new e(N.create({},{}))}inverse(){let t=N.create(this.delta.inserted,this.delta.deleted);return new e(t)}squash(t){let n=N.mergeObjects(this.delta.deleted.selectedElementIds??{},t.delta.deleted.selectedElementIds??{}),i=N.mergeObjects(this.delta.inserted.selectedElementIds??{},t.delta.inserted.selectedElementIds??{}),o=N.mergeObjects(this.delta.inserted.selectedGroupIds??{},t.delta.inserted.selectedGroupIds??{}),r=N.mergeObjects(this.delta.deleted.selectedGroupIds??{},t.delta.deleted.selectedGroupIds??{}),s=N.create({selectedElementIds:n,selectedGroupIds:r},{selectedElementIds:i,selectedGroupIds:o});return this.delta=N.merge(this.delta,t.delta,s),this}applyTo(t,n){try{let{selectedElementIds:i={},selectedGroupIds:o={}}=this.delta.deleted,{selectedElementIds:r={},selectedGroupIds:s={},selectedLinearElement:a,...l}=this.delta.inserted,d=N.mergeObjects(t.selectedElementIds,r,i),c=N.mergeObjects(t.selectedGroupIds,s,o),u=a&&n.has(a.elementId)?new U(n.get(a.elementId),n,a.isEditing):null,p={...t,...l,selectedElementIds:d,selectedGroupIds:c,selectedLinearElement:typeof a<"u"?u:t.selectedLinearElement},m=this.filterInvisibleChanges(t,p,n);return[p,m]}catch(i){if(console.error("Couldn't apply appstate change",i),tn()||en())throw i;return[t,!1]}}isEmpty(){return N.isEmpty(this.delta)}filterInvisibleChanges(t,n,i){let o=kn(t),r=kn(n),s=N.isRightDifferent(e.stripElementsProps(o),e.stripElementsProps(r)),a=N.isRightDifferent(e.stripStandaloneProps(o),e.stripStandaloneProps(r));if(!s&&!a)return!1;let l={value:s};if(a){let d=N.getRightDifferences(e.stripStandaloneProps(o),e.stripStandaloneProps(r)),c=new Set;(d.includes("editingGroupId")||d.includes("selectedGroupIds"))&&(c=hl(i));for(let u of d)switch(u){case"selectedElementIds":n[u]=e.filterSelectedElements(n[u],i,l);break;case"selectedGroupIds":n[u]=e.filterSelectedGroups(n[u],c,l);break;case"croppingElementId":{let x=n[u];if(!x)l.value=!0;else{let y=i.get(x);y&&!y.isDeleted?l.value=!0:n[u]=null}break}case"editingGroupId":let p=n[u];p?c.has(p)?l.value=!0:n[u]=null:l.value=!0;break;case"selectedLinearElement":let m=n[u];if(!m)l.value=!0;else{let x=i.get(m.elementId);x&&!x.isDeleted?l.value=!0:n[u]=null}break;case"lockedMultiSelections":let f=t[u]||{},E=n[u]||{};vd(f,E)||(l.value=!0);break;case"activeLockedId":let h=t[u]||null,g=n[u]||null;h!==g&&(l.value=!0);break;default:Ad(u,`Unknown ObservedElementsAppState's key "${u}"`,!0)}}return l.value}static filterSelectedElements(t,n,i){let o=Object.keys(t);if(!o.length)return i.value=!0,t;let r={...t};for(let s of o){let a=n.get(s);a&&!a.isDeleted?i.value=!0:delete r[s]}return r}static filterSelectedGroups(t,n,i){if(!Object.keys(t).length)return i.value=!0,t;let r={...t};for(let s of Object.keys(r))n.has(s)?i.value=!0:delete r[s];return r}static stripElementsProps(t){let{editingGroupId:n,selectedGroupIds:i,selectedElementIds:o,selectedLinearElement:r,croppingElementId:s,lockedMultiSelections:a,activeLockedId:l,...d}=t;return d}static stripStandaloneProps(t){let{name:n,viewBackgroundColor:i,...o}=t;return o}static postProcess(t,n){try{N.diffObjects(t,n,"selectedElementIds",i=>!0),N.diffObjects(t,n,"selectedGroupIds",i=>i??!1),N.diffObjects(t,n,"lockedMultiSelections",i=>i??{}),N.diffObjects(t,n,"activeLockedId",i=>i??null)}catch(i){if(console.error("Couldn't postprocess appstate change deltas."),tn()||en())throw i}finally{return[t,n]}}static orderAppStateKeys(t){let n={};for(let i of Object.keys(t).sort())n[i]=t[i];return n}},gn=class e{constructor(t,n,i){this.added=t;this.removed=n;this.updated=i}static create(t,n,i,o={shouldRedistribute:!1}){let r;if(o.shouldRedistribute){let s={},a={},l={},d=[...Object.entries(t),...Object.entries(n),...Object.entries(i)];for(let[c,u]of d)this.satisfiesAddition(u)?s[c]=u:this.satisfiesRemoval(u)?a[c]=u:l[c]=u;r=new e(s,a,l)}else r=new e(t,n,i);return(tn()||en())&&(e.validate(r,"added",this.satisfiesAddition),e.validate(r,"removed",this.satisfiesRemoval),e.validate(r,"updated",this.satisfiesUpdate)),r}static restore(t){let{added:n,removed:i,updated:o}=t;return e.create(n,i,o)}static satisfiesAddition=({deleted:t,inserted:n})=>t.isDeleted===!0&&!n.isDeleted;static satisfiesRemoval=({deleted:t,inserted:n})=>!t.isDeleted&&n.isDeleted===!0;static satisfiesUpdate=({deleted:t,inserted:n})=>!!t.isDeleted==!!n.isDeleted;static satisfiesCommmonInvariants=({deleted:t,inserted:n})=>!!(t.version&&n.version&&Number.isInteger(t.version)&&Number.isInteger(n.version)&&t.version>=0&&n.version>=0&&t.version!==n.version);static satisfiesUniqueInvariants=(t,n)=>{let{added:i,removed:o,updated:r}=t;return[i[n],o[n],r[n]].filter(Boolean).length===1};static validate(t,n,i){for(let[o,r]of Object.entries(t[n]))if(!this.satisfiesCommmonInvariants(r)||!this.satisfiesUniqueInvariants(t,o)||!i(r))throw console.error(`Broken invariant for "${n}" delta, element "${o}", delta:`,r),new Error(`ElementsDelta invariant broken for element "${o}".`)}static calculate(t,n){if(t===n)return e.empty();let i={},o={},r={};for(let s of t.values())if(!n.get(s.id)){let l={...s},d={isDeleted:!0,version:s.version+1,versionNonce:Td()},c=N.create(l,d,e.stripIrrelevantProps);s.isDeleted||(o[s.id]=c)}for(let s of n.values()){let a=t.get(s.id);if(!a){let l={isDeleted:!0,version:s.version-1,versionNonce:Td()},d={...s},c=N.create(l,d,e.stripIrrelevantProps);s.isDeleted||(i[s.id]=c);continue}if(a.versionNonce!==s.versionNonce){let l=N.calculate(a,s,e.stripIrrelevantProps,e.postProcess);if(typeof a.isDeleted=="boolean"&&typeof s.isDeleted=="boolean"&&a.isDeleted!==s.isDeleted){a.isDeleted&&!s.isDeleted?i[s.id]=l:o[s.id]=l;continue}let d=e.stripVersionProps(l.deleted),c=e.stripVersionProps(l.inserted);N.isInnerDifferent(d,c,!0)&&(r[s.id]=l)}}return e.create(i,o,r)}static empty(){return e.create({},{},{})}inverse(){let t=r=>{let s={};for(let[a,{inserted:l,deleted:d}]of Object.entries(r))s[a]=N.create({...l},{...d});return s},n=t(this.added),i=t(this.removed),o=t(this.updated);return e.create(i,n,o)}isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.removed).length===0&&Object.keys(this.updated).length===0}applyLatestChanges(t,n,i){let o=(d,c)=>(u,p)=>{let m;switch(p){case"deleted":m=d;break;case"inserted":m=c;break}if(!m)return console.error("Element not found when trying to apply latest changes"),u;let f={};for(let E of Object.keys(u))switch(E){case"boundElements":f[E]=u[E];break;default:f[E]=m[E]}return f},r=d=>{let c={};for(let[u,p]of Object.entries(d)){let m=t.get(u),f=n.get(u),E=null;m||f?E=N.create(p.deleted,p.inserted,o(m,f),i):E=p;let h=e.stripVersionProps(E.deleted),g=e.stripVersionProps(E.inserted);N.isInnerDifferent(h,g)&&(c[u]=E)}return c},s=r(this.added),a=r(this.removed),l=r(this.updated);return e.create(s,a,l,{shouldRedistribute:!0})}applyTo(t,n=Jt.empty().elements,i){let o=new Map(t),r,s={containsVisibleDifference:!1,containsZindexDifference:!1,applyDirection:void 0};try{let a=e.createApplier(t,o,n,s,i),l=a(this.added),d=a(this.removed),c=a(this.updated),u=this.resolveConflicts(t,o,s.applyDirection);r=new Map([...l,...d,...c,...u])}catch(a){if(console.error("Couldn't apply elements delta",a),tn()||en())throw a;return[t,!0]}try{o=e.reorderElements(o,r,s),e.redrawElements(o,r)}catch(a){if(console.error("Couldn't mutate elements after applying elements change",a),tn()||en())throw a}finally{return[o,s.containsVisibleDifference]}}squash(t){let{added:n,removed:i,updated:o}=t;function r(s,a){let l=N.mergeArrays(s.deleted.boundElements??[],a.deleted.boundElements??[],void 0,c=>c.id)??[],d=N.mergeArrays(s.inserted.boundElements??[],a.inserted.boundElements??[],void 0,c=>c.id)??[];return N.create({boundElements:l},{boundElements:d})}for(let[s,a]of Object.entries(n)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.added[s]=a;else{let d=r(l,a);this.added[s]=N.merge(l,a,d)}}for(let[s,a]of Object.entries(i)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.removed[s]=a;else{let d=r(l,a);this.removed[s]=N.merge(l,a,d)}}for(let[s,a]of Object.entries(o)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.updated[s]=a;else{let d=r(l,a);this.updated[s]=N.merge(l,a,d),l===this.added[s]?this.added[s]=a:l===this.removed[s]?this.removed[s]=a:this.updated[s]=a}}return(tn()||en())&&(e.validate(this,"added",e.satisfiesAddition),e.validate(this,"removed",e.satisfiesRemoval),e.validate(this,"updated",e.satisfiesUpdate)),this}static createApplier=(t,n,i,o,r)=>s=>{let a=e.createGetter(n,i,o);return Object.entries(s).reduce((l,[d,c])=>{let u=a(d,c.inserted);if(u){let p=e.applyDelta(u,c,o,r);if(n.set(p.id,p),l.set(p.id,p),!o.applyDirection){let m=t.get(d);m&&(o.applyDirection=m.version>p.version?"backward":"forward")}}return l},new Map)};static createGetter=(t,n,i)=>(o,r)=>{let s=t.get(o);return s||(s=n.get(o),s?(i.containsZindexDifference=!0,(!r.isDeleted||r.isDeleted&&!s.isDeleted)&&(i.containsVisibleDifference=!0)):s=Me({id:o,version:1},{...r})),s};static applyDelta(t,n,i,o){let r={};for(let s of Object.keys(n.inserted)){if(s==="boundElements"||o?.excludedProperties?.has(s))continue;let a=n.inserted[s];Reflect.set(r,s,a)}if(n.deleted.boundElements?.length||n.inserted.boundElements?.length){let s=N.mergeArrays(t.boundElements,n.inserted.boundElements,n.deleted.boundElements,a=>a.id);Object.assign(r,{boundElements:s})}if(!i.containsVisibleDifference){let{index:s,...a}=r,l=e.checkForVisibleDifference(t,a);i.containsVisibleDifference=l}return i.containsZindexDifference||(i.containsZindexDifference=n.deleted.index!==n.inserted.index),Me(t,r,!0)}static checkForVisibleDifference(t,n){return t.isDeleted&&n.isDeleted!==!1?!1:t.isDeleted&&n.isDeleted===!1||t.isDeleted===!1&&n.isDeleted?!0:N.isRightDifferent(t,n)}resolveConflicts(t,n,i="forward"){let o=new Map,r=(a,l)=>{let d=n.get(a.id);if(!d)return;let c=t.get(a.id),u=i==="forward"?d.version+1:d.version-1,p=l,m;c===d?m=Me(d,{...p,version:u},!0):m=ye(d,n,{...p,version:c?.version!==d.version?d.version:u}),o.set(m.id,m),n.set(m.id,m)};for(let a of Object.keys(this.removed))e.unbindAffected(t,n,a,r);for(let a of Object.keys(this.added))e.rebindAffected(t,n,a,r);for(let[a]of Array.from(Object.entries(this.updated)).filter(([l,d])=>Object.keys({...d.deleted,...d.inserted}).find(c=>Za.has(c)))){let l=n.get(a);!l||l.isDeleted||e.rebindAffected(t,n,a,r)}let s=new Map(Array.from(t).filter(([a])=>o.has(a)));return this.squash(e.calculate(s,o)),o}static unbindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);Vt.unbindAffected(n,r(),o),Vt.unbindAffected(n,s(),o),$t.unbindAffected(n,r(),o),$t.unbindAffected(n,s(),o)}static rebindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);Vt.unbindAffected(n,r(),o),Vt.rebindAffected(n,s(),o),$t.unbindAffected(n,r(),(a,l)=>{ie(a)&&o(a,l)}),$t.rebindAffected(n,s(),o)}static redrawElements(t,n){try{let i=new Io(t,{skipValidation:!0});e.redrawTextBoundingBoxes(i,n),e.redrawBoundArrows(i,n)}catch(i){if(console.error("Couldn't redraw elements",i),tn()||en())throw i}finally{return t}}static redrawTextBoundingBoxes(t,n){let i=t.getNonDeletedElementsMap(),o=new Map;for(let r of n.values()){if(ce(r)){let{containerId:s}=r,a=s?i.get(s):void 0;a&&o.set(a.id,{container:a,boundText:r})}if(st(r)){let s=It(r),a=s?i.get(s):void 0;a&&o.set(r.id,{container:r,boundText:a})}}for(let{container:r,boundText:s}of o.values())r.isDeleted||s.isDeleted||ga(s,r,t)}static redrawBoundArrows(t,n){for(let i of n.values())!i.isDeleted&&Le(i)&&Ue(i,t,{changedElements:n})}static reorderElements(t,n,i){if(!i.containsZindexDifference)return t;let o=Array.from(t.values()),r=pd([...o]),s=N.getRightDifferences(o,r,!0).reduce((a,l)=>{let d=o[Number(l)];return d&&n.has(d.id)&&a.set(d.id,d),a},new Map);return!i.containsVisibleDifference&&s.size&&(i.containsVisibleDifference=!0),mh(ui(r,s))}static postProcess(t,n){try{N.diffArrays(t,n,"boundElements",r=>r.id);let i=t.points??[],o=n.points??[];N.isDifferent(i,o)||(Reflect.deleteProperty(t,"points"),Reflect.deleteProperty(n,"points"))}catch(i){if(console.error("Couldn't postprocess elements delta."),tn()||en())throw i}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:i,...o}=t;return o}static stripVersionProps(t){let{version:n,versionNonce:i,...o}=t;return o}};P();var iP=(e,t,n,i)=>{let[o,r,s,a]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],l=Ct(e),d=uo(e,t,i).map(m=>[m,Ct(m)]).sort((m,f)=>m[1][r]-f[1][r]),c=0;for(let m of d)c+=m[1][a];let u=(l[a]-c)/(d.length-1);if(u<0){let m=d.findIndex(g=>g[1][o]===l[o]),f=d.findIndex(g=>g[1][s]===l[s]),E=(d[f][1][r]-d[m][1][r])/(d.length-1),h=d[m][1][r];return d.flatMap(([g,x],y)=>{let b={x:0,y:0};return y!==m&&y!==f&&(h+=E,b[n.axis]=h-x[r]),g.map(w=>Me(w,{x:w.x+b.x,y:w.y+b.y}))})}let p=l[o];return d.flatMap(([m,f])=>{let E={x:0,y:0};return E[n.axis]=p-f[o],p+=u,p+=f[a],m.map(h=>Me(h,{x:h.x+E.x,y:h.y+E.y}))})};P();import{TEXT_AUTOWRAP_THRESHOLD as fh,getGridPoint as hh,getFontString as Eh}from"@excalidraw/common";var mP=(e,t,n,i,o,r)=>{if(t.length===1&&G(t[0])&&(t[0].startBinding||t[0].endBinding))return;let s=t.filter(u=>{if(G(u)&&u.startBinding&&u.endBinding){let p=t.find(f=>f.id===u.startBinding?.elementId),m=t.find(f=>f.id===u.endBinding?.elementId);return p&&m}return!0}),a=new Set(s),l=s.filter(u=>Z(u)).map(u=>u.id);if(l.length>0)for(let u of i.getNonDeletedElements())u.frameId!==null&&l.includes(u.frameId)&&a.add(u);let d=[];for(let u of a){let p=e.originalElements.get(u.id);if(!p)return;d.push(p)}let c=gh(tt(d),n,o,r);a.forEach(u=>{if(Dd(e,u,i,c),!Y(u)){let p=j(u,i.getNonDeletedElementsMap());p&&Dd(e,p,i,c),Ue(u,i,{simultaneouslyUpdated:Array.from(a)})}})},gh=(e,t,n,i)=>{let[o,r]=e,s=o+t.x+n.x,a=r+t.y+n.y;if(n.x===0||n.y===0){let[l,d]=hh(o+t.x,r+t.y,i);n.x===0&&(s=l),n.y===0&&(a=d)}return{x:s-o,y:a-r}},Dd=(e,t,n,i)=>{let o=e.originalElements.get(t.id)??t,r=o.x+i.x,s=o.y+i.y;n.mutateElement(t,{x:r,y:s})},fP=(e,t,n)=>{let[i,o]=tt(e);return[t-i,n-o]},hP=({newElement:e,elementType:t,originX:n,originY:i,x:o,y:r,width:s,height:a,shouldMaintainAspectRatio:l,shouldResizeFromCenter:d,zoom:c,scene:u,widthAspectRatio:p=null,originOffset:m=null,informMutation:f=!0})=>{l&&e.type!=="selection"&&(p?a=s/p:(Math.abs(r-i)>Math.abs(o-n)?{width:s,height:a}=Wr(t,a,o<n?-s:s):{width:s,height:a}=Wr(t,s,r<i?-a:a),a<0&&(a=-a)));let E=o<n?n-s:n,h=r<i?i-a:i;d&&(s+=s,a+=a,E=n-s/2,h=i-a/2);let g=null;if(ie(e)){a=e.height;let x=Ni(Eh({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight);s=Math.max(s,x),Math.abs(o-n)>fh/c&&(g={autoResize:!1}),h=i,d&&(E=n-s/2)}if(s!==0&&a!==0){let x=null;xe(e)&&(x={initialWidth:s,initialHeight:a}),u.mutateElement(e,{x:E+(m?.x??0),y:h+(m?.y??0),width:s,height:a,...g,...x},{informMutation:f,isDragging:!1})}};P();import{ELEMENT_LINK_KEY as So,normalizeLink as Ld}from"@excalidraw/common";var yP=(e,t)=>{let n=window.location.href;try{let i=new URL(n);return i.searchParams.set(So,e),Ld(i.toString())}catch(i){console.error(i)}return Ld(n)},bP=(e,t)=>{if(e.length>0&&xh(e)){if(e.length===1)return{id:e[0].id,type:"element"};if(e.length>1){let n=Object.keys(t.selectedGroupIds)[0];return n?{id:n,type:"group"}:{id:e[0].groupIds[0],type:"group"}}}return null},xh=e=>!!(e.length===1||e.length>1&&El(e)),PP=e=>{try{let t=new URL(e);return t.searchParams.has(So)&&t.host===window.location.host}catch{return!1}},IP=e=>{try{let{searchParams:t}=new URL(e);if(t.has(So))return t.get(So)}catch{}return null};P();import{FONT_FAMILY as Lh,VERTICAL_ALIGN as Ch,escapeDoubleQuotes as is,getFontString as Bh}from"@excalidraw/common";P();import{DEFAULT_ELEMENT_PROPS as nn,DEFAULT_FONT_FAMILY as wh,DEFAULT_FONT_SIZE as yh,DEFAULT_TEXT_ALIGN as bh,DEFAULT_VERTICAL_ALIGN as Ph,VERTICAL_ALIGN as Ih,randomInteger as Sh,randomId as Mh,getFontString as Mo,getUpdatedTimestamp as Th,getLineHeight as Ah}from"@excalidraw/common";var nt=(e,{x:t,y:n,strokeColor:i=nn.strokeColor,backgroundColor:o=nn.backgroundColor,fillStyle:r=nn.fillStyle,strokeWidth:s=nn.strokeWidth,strokeStyle:a=nn.strokeStyle,roughness:l=nn.roughness,opacity:d=nn.opacity,width:c=0,height:u=0,angle:p=0,groupIds:m=[],frameId:f=null,index:E=null,roundness:h=null,boundElements:g=null,link:x=null,locked:y=nn.locked,...b})=>((t<-1e6||t>1e6||n<-1e6||n>1e6||c<-1e6||c>1e6||u<-1e6||u>1e6)&&console.error("New element size or position is too large",{x:t,y:n,width:c,height:u,points:b.points}),{id:b.id||Mh(),type:e,x:t,y:n,width:c,height:u,angle:p,strokeColor:i,backgroundColor:o,fillStyle:r,strokeWidth:s,strokeStyle:a,roughness:l,opacity:d,groupIds:m,frameId:f,index:E,roundness:h,seed:b.seed??Sh(),version:b.version||1,versionNonce:b.versionNonce??0,isDeleted:!1,boundElements:g,updated:Th(),link:x,locked:y,customData:b.customData}),ns=e=>nt(e.type,e),GP=e=>nt("embeddable",e),OP=e=>({...nt("iframe",e)}),kP=e=>Me({...nt("frame",e),type:"frame",name:e?.name||null},{}),RP=e=>Me({...nt("magicframe",e),type:"magicframe",name:e?.name||null},{}),Cd=(e,t)=>({x:e.textAlign==="center"?t.width/2:e.textAlign==="right"?t.width:0,y:e.verticalAlign==="middle"?t.height/2:0}),Bd=e=>{let t=e.fontFamily||wh,n=e.fontSize||yh,i=e.lineHeight||Ah(t),o=tr(e.text),r=Qe(o,Mo({fontFamily:t,fontSize:n}),i),s=e.textAlign||bh,a=e.verticalAlign||Ph,l=Cd({textAlign:s,verticalAlign:a},r),d={...nt("text",e),text:o,fontSize:n,fontFamily:t,textAlign:s,verticalAlign:a,x:e.x-l.x,y:e.y-l.y,width:r.width,height:r.height,containerId:e.containerId||null,originalText:e.originalText??o,autoResize:e.autoResize??!0,lineHeight:i};return Me(d,{})},vh=(e,t,n)=>{let{width:i,height:o}=Qe(n,Mo(e),e.lineHeight);e.autoResize||(i=e.width);let{textAlign:r,verticalAlign:s}=e,a,l;if(r==="center"&&s===Ih.MIDDLE&&!e.containerId&&e.autoResize){let d=Qe(e.text,Mo(e),e.lineHeight),c=Cd(e,{width:i-d.width,height:o-d.height});a=e.x-c.x,l=e.y-c.y}else{let[d,c,u,p]=_(e,t),[m,f,E,h]=Nt(e,i,o,!1),g=(d-m)/2,x=(c-f)/2,y=(u-E)/2,b=(p-h)/2;[a,l]=Dh({s:!0,e:r==="center"||r==="left",w:r==="center"||r==="right"},e.x,e.y,e.angle,g,x,y,b)}return{width:i,height:o,x:Number.isFinite(a)?a:e.x,y:Number.isFinite(l)?l:e.y}},Dh=(e,t,n,i,o,r,s,a)=>{let l=Math.cos(i),d=Math.sin(i);return e.e&&e.w?t+=o+s:e.e?(t+=o*(1+l),n+=o*d,t+=s*(1-l),n+=s*-d):e.w&&(t+=o*(1-l),n+=o*-d,t+=s*(1+l),n+=s*d),e.n&&e.s?n+=r+a:e.n?(t+=r*d,n+=r*(1-l),t+=a*-d,n+=a*(1+l)):e.s&&(t+=r*-d,n+=r*(1+l),t+=a*d,n+=a*(1-l)),[t,n]},FP=(e,t,n,i=e.text)=>{if(e.isDeleted)return;(t||!e.autoResize)&&(i=Pt(i,Mo(e),t?Je(t,e):e.width));let o=vh(e,n,i);return{text:i,...o}},NP=e=>({...nt(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure,lastCommittedPoint:null}),zP=e=>{let t={...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return un(t)?{...t,polygon:e.polygon??!1}:t},Gd=e=>e.elbowed?{...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!0,fixedSegments:e.fixedSegments||[],startIsSpecial:!1,endIsSpecial:!1}:{...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!1},HP=e=>({...nt("image",e),strokeColor:"transparent",status:e.status??"pending",fileId:e.fileId??null,scale:e.scale??[1,1],crop:e.crop??null});var ft=new Map,Gh=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,Oh=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,kh=/^https:\/\/(?:www\.)?figma\.com/,Od=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,Rh=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,Fh=/^(?:https?:\/\/)?forms\.microsoft\.com\//,kd=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,Nh=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,zh=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,Hh=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,Rd=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,Fd=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,_h=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,Yh=e=>{let t;try{let s=new URL(e.startsWith("http")?e:`https://${e}`);t=s.searchParams.get("t")||s.searchParams.get("start")}catch{t=e.match(/[?&#](?:t|start)=([^&#\s]+)/)?.[1]}if(!t)return 0;if(/^\d+$/.test(t))return parseInt(t,10);let n=t.match(/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$/);if(!n)return 0;let[,i="0",o="0",r="0"]=n;return parseInt(i)*3600+parseInt(o)*60+parseInt(r)},rs=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","figma.com","link.excalidraw.com","gist.github.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","val.town","giphy.com","reddit.com","forms.microsoft.com"]),Nd=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","figma.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","reddit.com","forms.microsoft.com"]),os=e=>`<html><body>${e}</body></html>`,VP=e=>{if(!e)return null;if(ft.has(e))return ft.get(e);let t=e,n=Nd.has(ss(e,Nd)||""),i="generic",o={w:560,h:840},r=e.match(Gh);if(r?.[2]){let d=Yh(t),c=d>0?`&start=${d}`:"",u=e.includes("shorts");switch(i="video",r[1]){case"embed/":case"watch?v=":case"shorts/":e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${c}`;break;case"playlist?list=":case"embed/videoseries?list=":e=`https://www.youtube.com/embed/videoseries?list=${r[2]}&enablejsapi=1${c}`;break;default:e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${c}`;break}return o=u?{w:315,h:560}:{w:560,h:315},ft.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}let s=e.match(Oh);if(s?.[1]){let d=s?.[1],c=/^\d+$/.test(d)?void 0:new URIError("Invalid embed link format");return i="video",e=`https://player.vimeo.com/video/${d}?api=1`,o={w:560,h:315},ft.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,error:c,sandbox:{allowSameOrigin:n}}}if(e.match(kh))return i="generic",e=`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(e)}`,o={w:550,h:550},ft.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};let l=e.match(zh);if(l)return e=l[1]==="embed"?l[0]:l[0].replace("/v","/embed"),ft.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};if(Fh.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),kd.test(e)){let d=e.match(kd)[1],c=is(`https://twitter.com/x/status/${d}`),u={type:"document",srcdoc:p=>os(`<blockquote class="twitter-tweet" data-dnt="true" data-theme="${p}"><a href="${c}"></a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return ft.set(t,u),u}if(Fd.test(e)){let[,d,c,u]=e.match(Fd),p=is(`https://reddit.com/r/${d}/comments/${c}/${u}`),m={type:"document",srcdoc:f=>os(`<blockquote class="reddit-embed-bq" data-embed-theme="${f}"><a href="${p}"></a><br></blockquote><script async="" src="https://embed.reddit.com/widgets.js" charset="UTF-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return ft.set(t,m),m}if(Od.test(e)){let[,d,c]=e.match(Od),u=is(`https://gist.github.com/${d}/${c}`),p={type:"document",srcdoc:()=>os(`
|
|
20
|
+
`),l.stack,e.map(c=>s(c)),...d),t)throw l}},pd=e=>e.sort((t,n)=>ud(t)&&ud(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),ui=(e,t)=>{try{let n=bo(e),i=Nf(e,t),o=es(e,i),r=e.map(s=>{let a=o.get(s);return a?{...s,index:a.index}:s});Rf(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of o)ye(s,n,{index:a})}catch{Ff(e)}return e},Ff=e=>{let t=bo(e),n=md(e),i=es(e,n);for(let[o,{index:r}]of i)ye(o,t,{index:r});return e},id=e=>{let t=bo(e),n=md(e),i=es(e,n);for(let[o,{index:r}]of i)t.set(o.id,Me(o,{index:r}));return t},Nf=(e,t)=>{let n=[],i=0;for(;i<e.length;)if(t.has(e[i].id)){let o=[i-1,i];for(;++i<e.length&&t.has(e[i].id);)o.push(i);o.push(i),n.push(o)}else i++;return n},md=e=>{let t=[],n,i,o=-1,r=0,s=d=>{let c=e[o]?e[o].index:void 0,u=e[d-1]?.index;return!c&&u||c&&u&&u>c?[u,d-1]:[c,o]},a=d=>{let c=e[r]?e[r].index:void 0;if(c&&d<r)return[c,r];let u=r;for(;++u<e.length;){let p=e[u]?.index;if(!c&&p||c&&p&&p>c)return[p,u]}return[void 0,u]},l=0;for(;l<e.length;){let d=e[l].index;if([n,o]=s(l),[i,r]=a(l),Jr(d,n,i))l++;else{let c=[o,l];for(;++l<e.length;){let u=e[l].index,[p,m]=s(l),[f,E]=a(l);if(Jr(u,p,f))break;[n,o]=[p,m],[i,r]=[f,E],c.push(l)}c.push(r),t.push(c)}}return t},Jr=(e,t,n)=>e?t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e:!1,es=(e,t)=>{let n=new Map;for(let i of t){let o=i.shift(),r=i.pop(),s=yo(e[o]?.index,e[r]?.index,i.length);for(let a=0;a<i.length;a++){let l=e[i[a]];n.set(l,{index:s[a]})}}return n},ud=e=>!!e.index;P();var Md=gc(xd(),1);import{randomInteger as nh,arrayToMap as wd,toBrandedType as yd,isDevEnv as bd,isTestEnv as Pd,toArray as ih}from"@excalidraw/common";import{isNonDeletedElement as oh}from"@excalidraw/element";import{isFrameLikeElement as rh}from"@excalidraw/element";import{getElementsInGroup as sh}from"@excalidraw/element";import{syncInvalidIndices as ah,syncMovedIndices as Id,validateFractionalIndices as lh}from"@excalidraw/element";import{getSelectedElements as dh}from"@excalidraw/element";import{mutateElement as ch}from"@excalidraw/element";var Sd=e=>{let t=new Map,n=[];for(let i of e)i.isDeleted||(n.push(i),t.set(i.id,i));return{elementsMap:t,elements:n}},uh=(0,Md.default)(e=>{(bd()||Pd()||window?.DEBUG_FRACTIONAL_INDICES)&&lh(e,{shouldThrow:bd()||Pd(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),ph=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let i of t)n+=`${i}:${e[i]?"1":"0"}`;return n},Io=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=yd(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=yd(new Map);selectedElementsCache={selectedElementIds:null,elements:null,cache:new Map};sceneNonce;getSceneNonce(){return this.sceneNonce}getNonDeletedElementsMap(){return this.nonDeletedElementsMap}getElementsIncludingDeleted(){return this.elements}getElementsMapIncludingDeleted(){return this.elementsMap}getNonDeletedElements(){return this.nonDeletedElements}getFramesIncludingDeleted(){return this.frames}constructor(t=null,n){t&&this.replaceAllElements(t,n)}getSelectedElements(t){let n=ph(t),i=t?.elements||this.nonDeletedElements;if(this.selectedElementsCache.elements===i&&this.selectedElementsCache.selectedElementIds===t.selectedElementIds){let r=this.selectedElementsCache.cache.get(n);if(r)return r}else t?.elements==null&&this.selectedElementsCache.cache.clear();let o=dh(i,{selectedElementIds:t.selectedElementIds},t);return t?.elements==null&&(this.selectedElementsCache.selectedElementIds=t.selectedElementIds,this.selectedElementsCache.elements=this.nonDeletedElements,this.selectedElementsCache.cache.set(n,o)),o}getNonDeletedFramesLikes(){return this.nonDeletedFramesLikes}getElement(t){return this.elementsMap.get(t)||null}getNonDeletedElement(t){let n=this.getElement(t);return n&&oh(n)?n:null}mapElements(t){let n=!1,i=this.elements.map(o=>{let r=t(o);return r!==o&&(n=!0),r});return n&&this.replaceAllElements(i),n}replaceAllElements(t,n){let i=ih(t),o=[];n?.skipValidation||uh(i),this.elements=ah(i),this.elementsMap.clear(),this.elements.forEach(s=>{rh(s)&&o.push(s),this.elementsMap.set(s.id,s)});let r=Sd(this.elements);this.nonDeletedElements=r.elements,this.nonDeletedElementsMap=r.elementsMap,this.frames=o,this.nonDeletedFramesLikes=Sd(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=nh();for(let t of Array.from(this.callbacks))t()}onUpdate(t){if(this.callbacks.has(t))throw new Error;return this.callbacks.add(t),()=>{if(!this.callbacks.has(t))throw new Error;this.callbacks.delete(t)}}destroy(){this.elements=[],this.nonDeletedElements=[],this.nonDeletedFramesLikes=[],this.frames=[],this.elementsMap.clear(),this.selectedElementsCache.selectedElementIds=null,this.selectedElementsCache.elements=null,this.selectedElementsCache.cache.clear(),this.callbacks.clear()}insertElementAtIndex(t,n){if(!Number.isFinite(n)||n<0)throw new Error("insertElementAtIndex can only be called with index >= 0");let i=[...this.elements.slice(0,n),t,...this.elements.slice(n)];Id(i,wd([t])),this.replaceAllElements(i)}insertElementsAtIndex(t,n){if(!t.length)return;if(!Number.isFinite(n)||n<0)throw new Error("insertElementAtIndex can only be called with index >= 0");let i=[...this.elements.slice(0,n),...t,...this.elements.slice(n)];Id(i,wd(t)),this.replaceAllElements(i)}insertElement=t=>{let n=t.frameId?this.getElementIndex(t.frameId):this.elements.length;this.insertElementAtIndex(t,n)};insertElements=t=>{if(!t.length)return;let n=t[0]?.frameId?this.getElementIndex(t[0].frameId):this.elements.length;this.insertElementsAtIndex(t,n)};getElementIndex(t){return this.elements.findIndex(n=>n.id===t)}getContainerElement=t=>t&&t.containerId&&this.getElement(t.containerId)||null;getElementsFromId=t=>{let n=this.getNonDeletedElementsMap(),i=n.get(t);return i?[i]:sh(n,t)};mutateElement(t,n,i={informMutation:!0,isDragging:!1}){let o=this.getNonDeletedElementsMap(),{version:r}=t,{version:s}=ch(t,o,n,i);return this.elementsMap.has(t.id)&&r!==s&&i.informMutation&&this.triggerUpdate(),t}};var N=class e{constructor(t,n){this.deleted=t;this.inserted=n}static create(t,n,i,o){let r=i&&o!=="inserted"?i(t,"deleted"):t,s=i&&o!=="deleted"?i(n,"inserted"):n;return new e(r,s)}static calculate(t,n,i,o){if(t===n)return e.empty();let r={},s={};for(let d of this.getDifferences(t,n))r[d]=t[d],s[d]=n[d];let[a,l]=o?o(r,s):[r,s];return e.create(a,l,i)}static empty(){return new e({},{})}static isEmpty(t){return!Object.keys(t.deleted).length&&!Object.keys(t.inserted).length}static merge(t,n,i){return e.create({...t.deleted,...n.deleted,...i?.deleted??{}},{...t.inserted,...n.inserted,...i?.inserted??{}})}static mergeObjects(t,n,i){let o={...t};for(let r of Object.keys(i??{}))delete o[r];return{...o,...n}}static mergeArrays(t,n,i,o){return Object.values(e.mergeObjects(Gt(t??[],o),Gt(n??[],o),Gt(i??[],o)))}static diffObjects(t,n,i,o){if(!t[i]&&!n[i])return;let r=t[i]!==null&&typeof t[i]=="object",s=n[i]!==null&&typeof n[i]=="object";if(r||s){let a=t[i]??{},l=n[i]??{},d=e.getLeftDifferences(a,l).reduce((u,p)=>(u[p]=o(a[p]),u),{}),c=e.getRightDifferences(a,l).reduce((u,p)=>(u[p]=o(l[p]),u),{});Object.keys(d).length||Object.keys(c).length?(Reflect.set(t,i,d),Reflect.set(n,i,c)):(Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i))}else t[i]===n[i]&&(Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i))}static diffArrays(t,n,i,o){if(!(!t[i]&&!n[i])&&(Array.isArray(t[i])||Array.isArray(n[i]))){let r=Array.isArray(t[i])?t[i]:[],s=Array.isArray(n[i])?n[i]:[],a=Gt(e.getLeftDifferences(Gt(r,o),Gt(s,o)),d=>d),l=Gt(e.getRightDifferences(Gt(r,o),Gt(s,o)),d=>d);if(Object.keys(a).length||Object.keys(l).length){let d=r.filter(u=>a[o?o(u):String(u)]),c=s.filter(u=>l[o?o(u):String(u)]);Reflect.set(t,i,d),Reflect.set(n,i,c)}else Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i)}}static isLeftDifferent(t,n,i=!1){return!!this.distinctKeysIterator("left",t,n,i).next().value}static isRightDifferent(t,n,i=!1){return!!this.distinctKeysIterator("right",t,n,i).next().value}static isInnerDifferent(t,n,i=!1){return!!!!this.distinctKeysIterator("inner",t,n,i).next().value}static isDifferent(t,n,i=!1){return!!!!this.distinctKeysIterator("full",t,n,i).next().value}static getLeftDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("left",t,n,i)).sort()}static getRightDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("right",t,n,i)).sort()}static getInnerDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("inner",t,n,i)).sort()}static getDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("full",t,n,i)).sort()}static*distinctKeysIterator(t,n,i,o=!1){if(n===i)return;let r=[];t==="left"?r=Object.keys(n):t==="right"?r=Object.keys(i):t==="inner"?r=Object.keys(n).filter(s=>s in i):t==="full"?r=Array.from(new Set([...Object.keys(n),...Object.keys(i)])):Ad(t,`Unknown distinctKeysIterator's join param "${t}"`,!0);for(let s of r){let a=n[s],l=i[s];if(a!==l){if(!o&&typeof a=="object"&&typeof l=="object"&&a!==null&&l!==null&&vd(a,l))continue;yield s}}}},En=class e{constructor(t){this.delta=t}static create(t){return new e(t)}static calculate(t,n){let i=N.calculate(t,n,e.orderAppStateKeys,e.postProcess);return new e(i)}static restore(t){let{delta:n}=t;return new e(n)}static empty(){return new e(N.create({},{}))}inverse(){let t=N.create(this.delta.inserted,this.delta.deleted);return new e(t)}squash(t){let n=N.mergeObjects(this.delta.deleted.selectedElementIds??{},t.delta.deleted.selectedElementIds??{}),i=N.mergeObjects(this.delta.inserted.selectedElementIds??{},t.delta.inserted.selectedElementIds??{}),o=N.mergeObjects(this.delta.inserted.selectedGroupIds??{},t.delta.inserted.selectedGroupIds??{}),r=N.mergeObjects(this.delta.deleted.selectedGroupIds??{},t.delta.deleted.selectedGroupIds??{}),s=N.create({selectedElementIds:n,selectedGroupIds:r},{selectedElementIds:i,selectedGroupIds:o});return this.delta=N.merge(this.delta,t.delta,s),this}applyTo(t,n){try{let{selectedElementIds:i={},selectedGroupIds:o={}}=this.delta.deleted,{selectedElementIds:r={},selectedGroupIds:s={},selectedLinearElement:a,...l}=this.delta.inserted,d=N.mergeObjects(t.selectedElementIds,r,i),c=N.mergeObjects(t.selectedGroupIds,s,o),u=a&&n.has(a.elementId)?new U(n.get(a.elementId),n,a.isEditing):null,p={...t,...l,selectedElementIds:d,selectedGroupIds:c,selectedLinearElement:typeof a<"u"?u:t.selectedLinearElement},m=this.filterInvisibleChanges(t,p,n);return[p,m]}catch(i){if(console.error("Couldn't apply appstate change",i),tn()||en())throw i;return[t,!1]}}isEmpty(){return N.isEmpty(this.delta)}filterInvisibleChanges(t,n,i){let o=kn(t),r=kn(n),s=N.isRightDifferent(e.stripElementsProps(o),e.stripElementsProps(r)),a=N.isRightDifferent(e.stripStandaloneProps(o),e.stripStandaloneProps(r));if(!s&&!a)return!1;let l={value:s};if(a){let d=N.getRightDifferences(e.stripStandaloneProps(o),e.stripStandaloneProps(r)),c=new Set;(d.includes("editingGroupId")||d.includes("selectedGroupIds"))&&(c=hl(i));for(let u of d)switch(u){case"selectedElementIds":n[u]=e.filterSelectedElements(n[u],i,l);break;case"selectedGroupIds":n[u]=e.filterSelectedGroups(n[u],c,l);break;case"croppingElementId":{let x=n[u];if(!x)l.value=!0;else{let y=i.get(x);y&&!y.isDeleted?l.value=!0:n[u]=null}break}case"editingGroupId":let p=n[u];p?c.has(p)?l.value=!0:n[u]=null:l.value=!0;break;case"selectedLinearElement":let m=n[u];if(!m)l.value=!0;else{let x=i.get(m.elementId);x&&!x.isDeleted?l.value=!0:n[u]=null}break;case"lockedMultiSelections":let f=t[u]||{},E=n[u]||{};vd(f,E)||(l.value=!0);break;case"activeLockedId":let h=t[u]||null,g=n[u]||null;h!==g&&(l.value=!0);break;default:Ad(u,`Unknown ObservedElementsAppState's key "${u}"`,!0)}}return l.value}static filterSelectedElements(t,n,i){let o=Object.keys(t);if(!o.length)return i.value=!0,t;let r={...t};for(let s of o){let a=n.get(s);a&&!a.isDeleted?i.value=!0:delete r[s]}return r}static filterSelectedGroups(t,n,i){if(!Object.keys(t).length)return i.value=!0,t;let r={...t};for(let s of Object.keys(r))n.has(s)?i.value=!0:delete r[s];return r}static stripElementsProps(t){let{editingGroupId:n,selectedGroupIds:i,selectedElementIds:o,selectedLinearElement:r,croppingElementId:s,lockedMultiSelections:a,activeLockedId:l,...d}=t;return d}static stripStandaloneProps(t){let{name:n,viewBackgroundColor:i,...o}=t;return o}static postProcess(t,n){try{N.diffObjects(t,n,"selectedElementIds",i=>!0),N.diffObjects(t,n,"selectedGroupIds",i=>i??!1),N.diffObjects(t,n,"lockedMultiSelections",i=>i??{}),N.diffObjects(t,n,"activeLockedId",i=>i??null)}catch(i){if(console.error("Couldn't postprocess appstate change deltas."),tn()||en())throw i}finally{return[t,n]}}static orderAppStateKeys(t){let n={};for(let i of Object.keys(t).sort())n[i]=t[i];return n}},gn=class e{constructor(t,n,i){this.added=t;this.removed=n;this.updated=i}static create(t,n,i,o={shouldRedistribute:!1}){let r;if(o.shouldRedistribute){let s={},a={},l={},d=[...Object.entries(t),...Object.entries(n),...Object.entries(i)];for(let[c,u]of d)this.satisfiesAddition(u)?s[c]=u:this.satisfiesRemoval(u)?a[c]=u:l[c]=u;r=new e(s,a,l)}else r=new e(t,n,i);return(tn()||en())&&(e.validate(r,"added",this.satisfiesAddition),e.validate(r,"removed",this.satisfiesRemoval),e.validate(r,"updated",this.satisfiesUpdate)),r}static restore(t){let{added:n,removed:i,updated:o}=t;return e.create(n,i,o)}static satisfiesAddition=({deleted:t,inserted:n})=>t.isDeleted===!0&&!n.isDeleted;static satisfiesRemoval=({deleted:t,inserted:n})=>!t.isDeleted&&n.isDeleted===!0;static satisfiesUpdate=({deleted:t,inserted:n})=>!!t.isDeleted==!!n.isDeleted;static satisfiesCommmonInvariants=({deleted:t,inserted:n})=>!!(t.version&&n.version&&Number.isInteger(t.version)&&Number.isInteger(n.version)&&t.version>=0&&n.version>=0&&t.version!==n.version);static satisfiesUniqueInvariants=(t,n)=>{let{added:i,removed:o,updated:r}=t;return[i[n],o[n],r[n]].filter(Boolean).length===1};static validate(t,n,i){for(let[o,r]of Object.entries(t[n]))if(!this.satisfiesCommmonInvariants(r)||!this.satisfiesUniqueInvariants(t,o)||!i(r))throw console.error(`Broken invariant for "${n}" delta, element "${o}", delta:`,r),new Error(`ElementsDelta invariant broken for element "${o}".`)}static calculate(t,n){if(t===n)return e.empty();let i={},o={},r={};for(let s of t.values())if(!n.get(s.id)){let l={...s},d={isDeleted:!0,version:s.version+1,versionNonce:Td()},c=N.create(l,d,e.stripIrrelevantProps);s.isDeleted||(o[s.id]=c)}for(let s of n.values()){let a=t.get(s.id);if(!a){let l={isDeleted:!0,version:s.version-1,versionNonce:Td()},d={...s},c=N.create(l,d,e.stripIrrelevantProps);s.isDeleted||(i[s.id]=c);continue}if(a.versionNonce!==s.versionNonce){let l=N.calculate(a,s,e.stripIrrelevantProps,e.postProcess);if(typeof a.isDeleted=="boolean"&&typeof s.isDeleted=="boolean"&&a.isDeleted!==s.isDeleted){a.isDeleted&&!s.isDeleted?i[s.id]=l:o[s.id]=l;continue}let d=e.stripVersionProps(l.deleted),c=e.stripVersionProps(l.inserted);N.isInnerDifferent(d,c,!0)&&(r[s.id]=l)}}return e.create(i,o,r)}static empty(){return e.create({},{},{})}inverse(){let t=r=>{let s={};for(let[a,{inserted:l,deleted:d}]of Object.entries(r))s[a]=N.create({...l},{...d});return s},n=t(this.added),i=t(this.removed),o=t(this.updated);return e.create(i,n,o)}isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.removed).length===0&&Object.keys(this.updated).length===0}applyLatestChanges(t,n,i){let o=(d,c)=>(u,p)=>{let m;switch(p){case"deleted":m=d;break;case"inserted":m=c;break}if(!m)return console.error("Element not found when trying to apply latest changes"),u;let f={};for(let E of Object.keys(u))switch(E){case"boundElements":f[E]=u[E];break;default:f[E]=m[E]}return f},r=d=>{let c={};for(let[u,p]of Object.entries(d)){let m=t.get(u),f=n.get(u),E=null;m||f?E=N.create(p.deleted,p.inserted,o(m,f),i):E=p;let h=e.stripVersionProps(E.deleted),g=e.stripVersionProps(E.inserted);N.isInnerDifferent(h,g)&&(c[u]=E)}return c},s=r(this.added),a=r(this.removed),l=r(this.updated);return e.create(s,a,l,{shouldRedistribute:!0})}applyTo(t,n=Jt.empty().elements,i){let o=new Map(t),r,s={containsVisibleDifference:!1,containsZindexDifference:!1,applyDirection:void 0};try{let a=e.createApplier(t,o,n,s,i),l=a(this.added),d=a(this.removed),c=a(this.updated),u=this.resolveConflicts(t,o,s.applyDirection);r=new Map([...l,...d,...c,...u])}catch(a){if(console.error("Couldn't apply elements delta",a),tn()||en())throw a;return[t,!0]}try{o=e.reorderElements(o,r,s),e.redrawElements(o,r)}catch(a){if(console.error("Couldn't mutate elements after applying elements change",a),tn()||en())throw a}finally{return[o,s.containsVisibleDifference]}}squash(t){let{added:n,removed:i,updated:o}=t,r=(s,a)=>{let l=N.mergeArrays(s.deleted.boundElements??[],a.deleted.boundElements??[],void 0,c=>c.id)??[],d=N.mergeArrays(s.inserted.boundElements??[],a.inserted.boundElements??[],void 0,c=>c.id)??[];return N.create({boundElements:l},{boundElements:d})};for(let[s,a]of Object.entries(n)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.added[s]=a;else{let d=r(l,a);delete this.removed[s],delete this.updated[s],this.added[s]=N.merge(l,a,d)}}for(let[s,a]of Object.entries(i)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.removed[s]=a;else{let d=r(l,a);delete this.added[s],delete this.updated[s],this.removed[s]=N.merge(l,a,d)}}for(let[s,a]of Object.entries(o)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.updated[s]=a;else{let d=r(l,a),c=N.merge(l,a,d);l===this.added[s]?this.added[s]=c:l===this.removed[s]?this.removed[s]=c:this.updated[s]=c}}return(tn()||en())&&(e.validate(this,"added",e.satisfiesAddition),e.validate(this,"removed",e.satisfiesRemoval),e.validate(this,"updated",e.satisfiesUpdate)),this}static createApplier=(t,n,i,o,r)=>s=>{let a=e.createGetter(n,i,o);return Object.entries(s).reduce((l,[d,c])=>{let u=a(d,c.inserted);if(u){let p=e.applyDelta(u,c,o,r);if(n.set(p.id,p),l.set(p.id,p),!o.applyDirection){let m=t.get(d);m&&(o.applyDirection=m.version>p.version?"backward":"forward")}}return l},new Map)};static createGetter=(t,n,i)=>(o,r)=>{let s=t.get(o);return s||(s=n.get(o),s?(i.containsZindexDifference=!0,(!r.isDeleted||r.isDeleted&&!s.isDeleted)&&(i.containsVisibleDifference=!0)):s=Me({id:o,version:1},{...r})),s};static applyDelta(t,n,i,o){let r={};for(let s of Object.keys(n.inserted)){if(s==="boundElements"||o?.excludedProperties?.has(s))continue;let a=n.inserted[s];Reflect.set(r,s,a)}if(n.deleted.boundElements?.length||n.inserted.boundElements?.length){let s=N.mergeArrays(t.boundElements,n.inserted.boundElements,n.deleted.boundElements,a=>a.id);Object.assign(r,{boundElements:s})}if(!i.containsVisibleDifference){let{index:s,...a}=r,l=e.checkForVisibleDifference(t,a);i.containsVisibleDifference=l}return i.containsZindexDifference||(i.containsZindexDifference=n.deleted.index!==n.inserted.index),Me(t,r,!0)}static checkForVisibleDifference(t,n){return t.isDeleted&&n.isDeleted!==!1?!1:t.isDeleted&&n.isDeleted===!1||t.isDeleted===!1&&n.isDeleted?!0:N.isRightDifferent(t,n)}resolveConflicts(t,n,i="forward"){let o=new Map,r=(a,l)=>{let d=n.get(a.id);if(!d)return;let c=t.get(a.id),u=i==="forward"?d.version+1:d.version-1,p=l,m;c===d?m=Me(d,{...p,version:u},!0):m=ye(d,n,{...p,version:c?.version!==d.version?d.version:u}),o.set(m.id,m),n.set(m.id,m)};for(let a of Object.keys(this.removed))e.unbindAffected(t,n,a,r);for(let a of Object.keys(this.added))e.rebindAffected(t,n,a,r);for(let[a]of Array.from(Object.entries(this.updated)).filter(([l,d])=>Object.keys({...d.deleted,...d.inserted}).find(c=>Za.has(c)))){let l=n.get(a);!l||l.isDeleted||e.rebindAffected(t,n,a,r)}let s=new Map(Array.from(t).filter(([a])=>o.has(a)));return this.squash(e.calculate(s,o)),o}static unbindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);Vt.unbindAffected(n,r(),o),Vt.unbindAffected(n,s(),o),$t.unbindAffected(n,r(),o),$t.unbindAffected(n,s(),o)}static rebindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);Vt.unbindAffected(n,r(),o),Vt.rebindAffected(n,s(),o),$t.unbindAffected(n,r(),(a,l)=>{ie(a)&&o(a,l)}),$t.rebindAffected(n,s(),o)}static redrawElements(t,n){try{let i=new Io(t,{skipValidation:!0});e.redrawTextBoundingBoxes(i,n),e.redrawBoundArrows(i,n)}catch(i){if(console.error("Couldn't redraw elements",i),tn()||en())throw i}finally{return t}}static redrawTextBoundingBoxes(t,n){let i=t.getNonDeletedElementsMap(),o=new Map;for(let r of n.values()){if(ce(r)){let{containerId:s}=r,a=s?i.get(s):void 0;a&&o.set(a.id,{container:a,boundText:r})}if(st(r)){let s=It(r),a=s?i.get(s):void 0;a&&o.set(r.id,{container:r,boundText:a})}}for(let{container:r,boundText:s}of o.values())r.isDeleted||s.isDeleted||ga(s,r,t)}static redrawBoundArrows(t,n){for(let i of n.values())!i.isDeleted&&Le(i)&&Ue(i,t,{changedElements:n})}static reorderElements(t,n,i){if(!i.containsZindexDifference)return t;let o=Array.from(t.values()),r=pd([...o]),s=N.getRightDifferences(o,r,!0).reduce((a,l)=>{let d=o[Number(l)];return d&&n.has(d.id)&&a.set(d.id,d),a},new Map);return!i.containsVisibleDifference&&s.size&&(i.containsVisibleDifference=!0),mh(ui(r,s))}static postProcess(t,n){try{N.diffArrays(t,n,"boundElements",r=>r.id);let i=t.points??[],o=n.points??[];N.isDifferent(i,o)||(Reflect.deleteProperty(t,"points"),Reflect.deleteProperty(n,"points"))}catch(i){if(console.error("Couldn't postprocess elements delta."),tn()||en())throw i}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:i,...o}=t;return o}static stripVersionProps(t){let{version:n,versionNonce:i,...o}=t;return o}};P();var iP=(e,t,n,i)=>{let[o,r,s,a]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],l=Ct(e),d=uo(e,t,i).map(m=>[m,Ct(m)]).sort((m,f)=>m[1][r]-f[1][r]),c=0;for(let m of d)c+=m[1][a];let u=(l[a]-c)/(d.length-1);if(u<0){let m=d.findIndex(g=>g[1][o]===l[o]),f=d.findIndex(g=>g[1][s]===l[s]),E=(d[f][1][r]-d[m][1][r])/(d.length-1),h=d[m][1][r];return d.flatMap(([g,x],y)=>{let b={x:0,y:0};return y!==m&&y!==f&&(h+=E,b[n.axis]=h-x[r]),g.map(w=>Me(w,{x:w.x+b.x,y:w.y+b.y}))})}let p=l[o];return d.flatMap(([m,f])=>{let E={x:0,y:0};return E[n.axis]=p-f[o],p+=u,p+=f[a],m.map(h=>Me(h,{x:h.x+E.x,y:h.y+E.y}))})};P();import{TEXT_AUTOWRAP_THRESHOLD as fh,getGridPoint as hh,getFontString as Eh}from"@excalidraw/common";var mP=(e,t,n,i,o,r)=>{if(t.length===1&&G(t[0])&&(t[0].startBinding||t[0].endBinding))return;let s=t.filter(u=>{if(G(u)&&u.startBinding&&u.endBinding){let p=t.find(f=>f.id===u.startBinding?.elementId),m=t.find(f=>f.id===u.endBinding?.elementId);return p&&m}return!0}),a=new Set(s),l=s.filter(u=>Z(u)).map(u=>u.id);if(l.length>0)for(let u of i.getNonDeletedElements())u.frameId!==null&&l.includes(u.frameId)&&a.add(u);let d=[];for(let u of a){let p=e.originalElements.get(u.id);if(!p)return;d.push(p)}let c=gh(tt(d),n,o,r);a.forEach(u=>{if(Dd(e,u,i,c),!Y(u)){let p=j(u,i.getNonDeletedElementsMap());p&&Dd(e,p,i,c),Ue(u,i,{simultaneouslyUpdated:Array.from(a)})}})},gh=(e,t,n,i)=>{let[o,r]=e,s=o+t.x+n.x,a=r+t.y+n.y;if(n.x===0||n.y===0){let[l,d]=hh(o+t.x,r+t.y,i);n.x===0&&(s=l),n.y===0&&(a=d)}return{x:s-o,y:a-r}},Dd=(e,t,n,i)=>{let o=e.originalElements.get(t.id)??t,r=o.x+i.x,s=o.y+i.y;n.mutateElement(t,{x:r,y:s})},fP=(e,t,n)=>{let[i,o]=tt(e);return[t-i,n-o]},hP=({newElement:e,elementType:t,originX:n,originY:i,x:o,y:r,width:s,height:a,shouldMaintainAspectRatio:l,shouldResizeFromCenter:d,zoom:c,scene:u,widthAspectRatio:p=null,originOffset:m=null,informMutation:f=!0})=>{l&&e.type!=="selection"&&(p?a=s/p:(Math.abs(r-i)>Math.abs(o-n)?{width:s,height:a}=Wr(t,a,o<n?-s:s):{width:s,height:a}=Wr(t,s,r<i?-a:a),a<0&&(a=-a)));let E=o<n?n-s:n,h=r<i?i-a:i;d&&(s+=s,a+=a,E=n-s/2,h=i-a/2);let g=null;if(ie(e)){a=e.height;let x=Ni(Eh({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight);s=Math.max(s,x),Math.abs(o-n)>fh/c&&(g={autoResize:!1}),h=i,d&&(E=n-s/2)}if(s!==0&&a!==0){let x=null;xe(e)&&(x={initialWidth:s,initialHeight:a}),u.mutateElement(e,{x:E+(m?.x??0),y:h+(m?.y??0),width:s,height:a,...g,...x},{informMutation:f,isDragging:!1})}};P();import{ELEMENT_LINK_KEY as So,normalizeLink as Ld}from"@excalidraw/common";var yP=(e,t)=>{let n=window.location.href;try{let i=new URL(n);return i.searchParams.set(So,e),Ld(i.toString())}catch(i){console.error(i)}return Ld(n)},bP=(e,t)=>{if(e.length>0&&xh(e)){if(e.length===1)return{id:e[0].id,type:"element"};if(e.length>1){let n=Object.keys(t.selectedGroupIds)[0];return n?{id:n,type:"group"}:{id:e[0].groupIds[0],type:"group"}}}return null},xh=e=>!!(e.length===1||e.length>1&&El(e)),PP=e=>{try{let t=new URL(e);return t.searchParams.has(So)&&t.host===window.location.host}catch{return!1}},IP=e=>{try{let{searchParams:t}=new URL(e);if(t.has(So))return t.get(So)}catch{}return null};P();import{FONT_FAMILY as Lh,VERTICAL_ALIGN as Ch,escapeDoubleQuotes as is,getFontString as Bh}from"@excalidraw/common";P();import{DEFAULT_ELEMENT_PROPS as nn,DEFAULT_FONT_FAMILY as wh,DEFAULT_FONT_SIZE as yh,DEFAULT_TEXT_ALIGN as bh,DEFAULT_VERTICAL_ALIGN as Ph,VERTICAL_ALIGN as Ih,randomInteger as Sh,randomId as Mh,getFontString as Mo,getUpdatedTimestamp as Th,getLineHeight as Ah}from"@excalidraw/common";var nt=(e,{x:t,y:n,strokeColor:i=nn.strokeColor,backgroundColor:o=nn.backgroundColor,fillStyle:r=nn.fillStyle,strokeWidth:s=nn.strokeWidth,strokeStyle:a=nn.strokeStyle,roughness:l=nn.roughness,opacity:d=nn.opacity,width:c=0,height:u=0,angle:p=0,groupIds:m=[],frameId:f=null,index:E=null,roundness:h=null,boundElements:g=null,link:x=null,locked:y=nn.locked,...b})=>((t<-1e6||t>1e6||n<-1e6||n>1e6||c<-1e6||c>1e6||u<-1e6||u>1e6)&&console.error("New element size or position is too large",{x:t,y:n,width:c,height:u,points:b.points}),{id:b.id||Mh(),type:e,x:t,y:n,width:c,height:u,angle:p,strokeColor:i,backgroundColor:o,fillStyle:r,strokeWidth:s,strokeStyle:a,roughness:l,opacity:d,groupIds:m,frameId:f,index:E,roundness:h,seed:b.seed??Sh(),version:b.version||1,versionNonce:b.versionNonce??0,isDeleted:!1,boundElements:g,updated:Th(),link:x,locked:y,customData:b.customData}),ns=e=>nt(e.type,e),GP=e=>nt("embeddable",e),OP=e=>({...nt("iframe",e)}),kP=e=>Me({...nt("frame",e),type:"frame",name:e?.name||null},{}),RP=e=>Me({...nt("magicframe",e),type:"magicframe",name:e?.name||null},{}),Cd=(e,t)=>({x:e.textAlign==="center"?t.width/2:e.textAlign==="right"?t.width:0,y:e.verticalAlign==="middle"?t.height/2:0}),Bd=e=>{let t=e.fontFamily||wh,n=e.fontSize||yh,i=e.lineHeight||Ah(t),o=tr(e.text),r=Qe(o,Mo({fontFamily:t,fontSize:n}),i),s=e.textAlign||bh,a=e.verticalAlign||Ph,l=Cd({textAlign:s,verticalAlign:a},r),d={...nt("text",e),text:o,fontSize:n,fontFamily:t,textAlign:s,verticalAlign:a,x:e.x-l.x,y:e.y-l.y,width:r.width,height:r.height,containerId:e.containerId||null,originalText:e.originalText??o,autoResize:e.autoResize??!0,lineHeight:i};return Me(d,{})},vh=(e,t,n)=>{let{width:i,height:o}=Qe(n,Mo(e),e.lineHeight);e.autoResize||(i=e.width);let{textAlign:r,verticalAlign:s}=e,a,l;if(r==="center"&&s===Ih.MIDDLE&&!e.containerId&&e.autoResize){let d=Qe(e.text,Mo(e),e.lineHeight),c=Cd(e,{width:i-d.width,height:o-d.height});a=e.x-c.x,l=e.y-c.y}else{let[d,c,u,p]=_(e,t),[m,f,E,h]=Nt(e,i,o,!1),g=(d-m)/2,x=(c-f)/2,y=(u-E)/2,b=(p-h)/2;[a,l]=Dh({s:!0,e:r==="center"||r==="left",w:r==="center"||r==="right"},e.x,e.y,e.angle,g,x,y,b)}return{width:i,height:o,x:Number.isFinite(a)?a:e.x,y:Number.isFinite(l)?l:e.y}},Dh=(e,t,n,i,o,r,s,a)=>{let l=Math.cos(i),d=Math.sin(i);return e.e&&e.w?t+=o+s:e.e?(t+=o*(1+l),n+=o*d,t+=s*(1-l),n+=s*-d):e.w&&(t+=o*(1-l),n+=o*-d,t+=s*(1+l),n+=s*d),e.n&&e.s?n+=r+a:e.n?(t+=r*d,n+=r*(1-l),t+=a*-d,n+=a*(1+l)):e.s&&(t+=r*-d,n+=r*(1+l),t+=a*d,n+=a*(1-l)),[t,n]},FP=(e,t,n,i=e.text)=>{if(e.isDeleted)return;(t||!e.autoResize)&&(i=Pt(i,Mo(e),t?Je(t,e):e.width));let o=vh(e,n,i);return{text:i,...o}},NP=e=>({...nt(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure,lastCommittedPoint:null}),zP=e=>{let t={...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return un(t)?{...t,polygon:e.polygon??!1}:t},Gd=e=>e.elbowed?{...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!0,fixedSegments:e.fixedSegments||[],startIsSpecial:!1,endIsSpecial:!1}:{...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!1},HP=e=>({...nt("image",e),strokeColor:"transparent",status:e.status??"pending",fileId:e.fileId??null,scale:e.scale??[1,1],crop:e.crop??null});var ft=new Map,Gh=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,Oh=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,kh=/^https:\/\/(?:www\.)?figma\.com/,Od=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,Rh=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,Fh=/^(?:https?:\/\/)?forms\.microsoft\.com\//,kd=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,Nh=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,zh=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,Hh=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,Rd=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,Fd=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,_h=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,Yh=e=>{let t;try{let s=new URL(e.startsWith("http")?e:`https://${e}`);t=s.searchParams.get("t")||s.searchParams.get("start")}catch{t=e.match(/[?&#](?:t|start)=([^&#\s]+)/)?.[1]}if(!t)return 0;if(/^\d+$/.test(t))return parseInt(t,10);let n=t.match(/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$/);if(!n)return 0;let[,i="0",o="0",r="0"]=n;return parseInt(i)*3600+parseInt(o)*60+parseInt(r)},rs=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","figma.com","link.excalidraw.com","gist.github.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","val.town","giphy.com","reddit.com","forms.microsoft.com"]),Nd=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","figma.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","reddit.com","forms.microsoft.com"]),os=e=>`<html><body>${e}</body></html>`,VP=e=>{if(!e)return null;if(ft.has(e))return ft.get(e);let t=e,n=Nd.has(ss(e,Nd)||""),i="generic",o={w:560,h:840},r=e.match(Gh);if(r?.[2]){let d=Yh(t),c=d>0?`&start=${d}`:"",u=e.includes("shorts");switch(i="video",r[1]){case"embed/":case"watch?v=":case"shorts/":e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${c}`;break;case"playlist?list=":case"embed/videoseries?list=":e=`https://www.youtube.com/embed/videoseries?list=${r[2]}&enablejsapi=1${c}`;break;default:e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${c}`;break}return o=u?{w:315,h:560}:{w:560,h:315},ft.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}let s=e.match(Oh);if(s?.[1]){let d=s?.[1],c=/^\d+$/.test(d)?void 0:new URIError("Invalid embed link format");return i="video",e=`https://player.vimeo.com/video/${d}?api=1`,o={w:560,h:315},ft.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,error:c,sandbox:{allowSameOrigin:n}}}if(e.match(kh))return i="generic",e=`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(e)}`,o={w:550,h:550},ft.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};let l=e.match(zh);if(l)return e=l[1]==="embed"?l[0]:l[0].replace("/v","/embed"),ft.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};if(Fh.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),kd.test(e)){let d=e.match(kd)[1],c=is(`https://twitter.com/x/status/${d}`),u={type:"document",srcdoc:p=>os(`<blockquote class="twitter-tweet" data-dnt="true" data-theme="${p}"><a href="${c}"></a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return ft.set(t,u),u}if(Fd.test(e)){let[,d,c,u]=e.match(Fd),p=is(`https://reddit.com/r/${d}/comments/${c}/${u}`),m={type:"document",srcdoc:f=>os(`<blockquote class="reddit-embed-bq" data-embed-theme="${f}"><a href="${p}"></a><br></blockquote><script async="" src="https://embed.reddit.com/widgets.js" charset="UTF-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return ft.set(t,m),m}if(Od.test(e)){let[,d,c]=e.match(Od),u=is(`https://gist.github.com/${d}/${c}`),p={type:"document",srcdoc:()=>os(`
|
|
21
21
|
<script src="${u}.js"><\/script>
|
|
22
22
|
<style type="text/css">
|
|
23
23
|
* { margin: 0px; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@excalidraw/element",
|
|
3
|
-
"version": "0.18.0-
|
|
3
|
+
"version": "0.18.0-880dbb25e",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/types/element/src/index.d.ts",
|
|
6
6
|
"main": "./dist/prod/index.js",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"build:esm": "rimraf dist && node ../../scripts/buildBase.js && yarn gen:types"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@excalidraw/common": "0.18.0-
|
|
61
|
-
"@excalidraw/math": "0.18.0-
|
|
60
|
+
"@excalidraw/common": "0.18.0-880dbb25e",
|
|
61
|
+
"@excalidraw/math": "0.18.0-880dbb25e"
|
|
62
62
|
}
|
|
63
63
|
}
|