@myoc/element 0.19.523 → 0.19.525

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.
@@ -9,7 +9,7 @@ var hm=Object.create;var yl=Object.defineProperty;var fm=Object.getOwnPropertyDe
9
9
 
10
10
  `)=>e.reduce((o,i)=>(ue(i)&&o.push(i.text),o),[]).join(t);S();import{curvePointDistance as Os,distanceToLineSegment as Rs,pointRotateRads as Fs}from"@excalidraw/math";import{ellipse as Kh,ellipseDistanceFromPoint as Qh}from"@excalidraw/math/ellipse";var nn=(e,t,n)=>{switch(e.type){case"selection":case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"magicframe":return Jh(e,t,n);case"diamond":return e1(e,t,n);case"ellipse":return t1(e,t,n);case"line":case"arrow":case"freedraw":return n1(e,t,n)}},Jh=(e,t,n)=>{let o=he(e,t),i=Fs(n,o,-e.angle),[r,s]=Cn(e);return Math.min(...r.map(a=>Rs(i,a)),...s.map(a=>Os(a,i)))},e1=(e,t,n)=>{let o=he(e,t),i=Fs(n,o,-e.angle),[r,s]=Bn(e);return Math.min(...r.map(a=>Rs(i,a)),...s.map(a=>Os(a,i)))},t1=(e,t,n)=>{let o=he(e,t);return Qh(Fs(n,o,-e.angle),Kh(o,e.width/2,e.height/2))},n1=(e,t,n)=>{let[o,i]=so(e,t);return Math.min(...o.map(r=>Rs(n,r)),...i.map(r=>Os(r,n)))};S();var To=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="line"||e==="freedraw"||e==="autoshape"||e==="bucketfill",Jw=e=>e==="rectangle"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line"||e==="text"||e==="embeddable"||e==="autoshape",e3=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line"||e==="autoshape",t3=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="arrow"||e==="line"||e==="autoshape",n3=e=>e==="freedraw",Pd=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image",o3=e=>e==="arrow",i3=e=>e==="arrow";var lr=e=>{if(e.type==="arrow")return!1;let t=To(e.type)&&!kd(e.backgroundColor)||Jt(e)||Ki(e)||ue(e);return e.type==="line"?t&&vt(e.points):e.type==="freedraw"?t&&vt(e.points):t||Ue(e)},Hs=null,Id=null,zs=1/0,_s=!1,Sd=!1,vd=null,d1=(e,t)=>e===t||!!e&&!!t&&e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height,en=({point:e,element:t,threshold:n,elementsMap:o,frameNameBound:i=null,overrideShouldTestInside:r=!1})=>{if(Hs&&Cd(e,Hs)&&(_s?zs<=n:zs>=n)&&r===Sd&&d1(i,vd)){let u=Id?.deref();if(u&&u.id===t.id&&u.version===t.version&&u.versionNonce===t.versionNonce)return _s}let s=i?Ws(ze(i.x-n,i.y-n),e,ze(i.x+i.width+n,i.y+i.height+n)):!1,a=be(t,o,!0);if(!Bd(e,a,t.angle,n)&&!s)return!1;let c=(r||lr(t))&&ft(e,t,o)||Ad(e,t,o,n)||s;return Hs=e,Id=new WeakRef(t),zs=n,Sd=r,vd=i,_s=c,c},Bd=(e,t,n,o=0)=>{let i=n===0?e:Tt(e,yn(t),-n);return Ws(ze(t[0]-o,t[1]-o),i,ze(t[2]+o,t[3]+o))},c1=(e,t,n,o=0)=>{let i=be(t,n,!0);return Bd(e,i,t.angle,o)},y3=(e,t)=>!en(e)&&!u1(e.point,e.element,t)&&c1(e.point,e.element,t),u1=(e,t,n)=>{let o=pe(t,n);if(!o)return!1;let i=le(t)?{...o,...W.getBoundTextElementPosition(t,o,n)}:o;return ft(e,i,n)},Gd=(e,[t,n],o,i=0)=>{let r=ze(t,n),s=!ce(e),a=Math.max(1,i),l=[t-a,n-a,t+a,n+a],d=be(e,o);if(!kt(l,d))return!1;if(e.frameId){let m=o.get(e.frameId);if(m&&ce(m)){let h=be(m,o);if(!on(r,h))return!1}}let c=gt(e,o,hi(he(e,o),r)),u=nn(e,o,r);return s?c.length===0||u<=i:c.length>0&&u<=a},dr=(e,t,n,o)=>{let i=[];for(let r=t.length-1;r>=0;--r){let s=t[r];if(Td(!s.isDeleted,"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements"),De(s,!1)&&Gd(s,e,n,o)&&(i.push(s),To(s.type)&&!kd(s.backgroundColor)))break}return i},xn=(e,t,n,o)=>{let i=dr(e,t,n,o);return!i||i.length===0?null:i.length===1?i[0]:i.sort((r,s)=>s.width**2+s.height**2-(r.width**2+r.height**2)).pop()},Nd=(e,t,n,o,i)=>{let r=[];for(let a=n.length-1;a>=0;--a){let l=n[a];Td(!l.isDeleted,"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements"),De(l,!1)&&Gd(l,e,o,i)&&r.push(l)}if(!r||r.length===0)return null;if(r.length===1)return r[0];let s=r.filter(a=>nn(a,o,e)<=_e(a,t)||ft(e,a,o));return s.length===0?null:s[0]},gt=(e,t,n,o=0,i=!1)=>{let r=[Math.min(n[0][0]-o,n[1][0]-o),Math.min(n[0][1]-o,n[1][1]-o),Math.max(n[0][0]+o,n[1][0]+o),Math.max(n[0][1]+o,n[1][1]+o)],s=be(e,t);if(!kt(r,s))return[];switch(e.type){case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"selection":case"magicframe":return m1(e,t,n,o,i);case"diamond":return h1(e,t,n,o,i);case"ellipse":return f1(e,t,n,o);case"line":case"freedraw":case"arrow":return p1(e,n,t,i)}},Od=(e,t,n,o,i,r=!1)=>{for(let s of e){let a=cr(s[0],s[1],s[2],s[3]),l=[Math.min(t[0][0],t[1][0]),Math.min(t[0][1],t[1][1]),Math.max(t[0][0],t[1][0]),Math.max(t[0][1],t[1][1])];if(!kt(a,l))continue;let d=Ld(s,t);if(d.length>0){for(let c of d)n.push(Tt(c,o,i));if(r)return n}}return n},Rd=(e,t,n,o,i,r=!1)=>{for(let s of e){let a=Dd(s,t);if(a&&(n.push(Tt(a,o,i)),r))return n}return n},p1=(e,t,n,o=!1)=>{let[i,r]=so(e,n),s=[];for(let a of i){let l=Dd(a,t);if(l&&(s.push(l),o))return s}for(let a of r){let l=cr(a[0],a[1],a[2],a[3]),d=[Math.min(t[0][0],t[1][0]),Math.min(t[0][1],t[1][1]),Math.max(t[0][0],t[1][0]),Math.max(t[0][1],t[1][1])];if(!kt(l,d))continue;let c=Ld(a,t,{iterLimit:10});if(c.length>0&&(s.push(...c),o))return s}return s},m1=(e,t,n,o=0,i=!1)=>{let r=he(e,t),s=Tt(n[0],r,-e.angle),a=Tt(n[1],r,-e.angle),l=hi(s,a),[d,c]=Cn(e,o),u=[];return Rd(d,l,u,r,e.angle,i),i&&u.length>0||Od(c,l,u,r,e.angle,i),u},h1=(e,t,n,o=0,i=!1)=>{let r=he(e,t),s=Tt(n[0],r,-e.angle),a=Tt(n[1],r,-e.angle),l=hi(s,a),[d,c]=Bn(e,o),u=[];return Rd(d,l,u,r,e.angle,i),i&&u.length>0||Od(c,l,u,r,e.angle,i),u},f1=(e,t,n,o=0)=>{let i=he(e,t),r=Tt(n[0],i,-e.angle),s=Tt(n[1],i,-e.angle);return l1(a1(i,e.width/2+o,e.height/2+o),hi(r,s)).map(a=>Tt(a,i,e.angle))},Ad=(e,t,n,o=1)=>nn(t,n,e)<=o,ft=(e,t,n)=>{if((le(t)||Le(t))&&!vt(t.points))return!1;let[o,i,r,s]=be(t,n);if(!Ws(ze(o,i),e,ze(r,s)))return!1;let a=ze((o+r)/2,(i+s)/2),l=o1(s1(r1(i1(e,a,.1)),Math.max(t.width,t.height)*2),a),d=hi(e,l);return gt(t,n,d).filter((u,m,h)=>h.findIndex(g=>Cd(g,u))===m).length%2===1},js=(e,t,n)=>{let o=(s,a)=>{let{x:l,y:d,width:c,height:u,angle:m}=s,h=he(s,n);if(s.type==="diamond"){let[f,E,x,y,b,M,w,v]=vo(s);return[ze(l+f,d+E-a),ze(l+x+a,d+y),ze(l+b,d+M+a),ze(l+w-a,d+v)].map(k=>Tt(k,h,m))}if(s.type==="ellipse"){let f=l+c/2,E=d+u/2,x=c/2,y=u/2;return[ze(f,E-y-a),ze(f+x+a,E),ze(f,E+y+a),ze(f-x-a,E)].map(M=>Tt(M,h,m))}return[ze(l-a,d-a),ze(l+c+a,d-a),ze(l+c+a,d+u+a),ze(l-a,d+u+a)].map(f=>Tt(f,h,m))},i=-1*Math.max(e.width,e.height)/20;return o(e,i).every(s=>ft(s,t,n))};S();import{invariant as Fd,isDevEnv as g1,isTestEnv as E1}from"@excalidraw/common";import{pointFrom as Nn,pointFromVector as ur,pointRotateRads as pr,pointScaleFromOrigin as mr,pointsEqual as x1,triangleIncludesPoint as Vs,vectorCross as Et,vectorFromPoint as fe,vectorScale as hr}from"@excalidraw/math";var Se=[1,0],We=[0,1],Xe=[-1,0],st=[0,-1],rn=e=>{let[t,n]=e,o=Math.abs(t),i=Math.abs(n);return t>i?Se:t<=-i?Xe:n>o?We:st},xt=(e,t)=>rn(fe(e,t)),Ut=(e,t)=>yt(xt(e,t)),Pe=(e,t)=>e[0]===t[0]&&e[1]===t[1],yt=e=>Pe(e,Se)||Pe(e,Xe),S3=e=>!yt(e),y1=(e,t,n)=>{let o=yn(t);(g1()||E1())&&(Fd(e.width>0&&e.height>0,"Diamond element has no width or height"),Fd(!x1(o,n),"The point is too close to the element mid point to determine heading"));let i=.95,r=ur(hr(fe(pr(Nn(e.x+e.width/2,e.y),o,e.angle),o),i),o),s=ur(hr(fe(pr(Nn(e.x+e.width,e.y+e.height/2),o,e.angle),o),i),o),a=ur(hr(fe(pr(Nn(e.x+e.width/2,e.y+e.height),o,e.angle),o),i),o),l=ur(hr(fe(pr(Nn(e.x,e.y+e.height/2),o,e.angle),o),i),o);if(Et(fe(n,r),fe(r,s))<=0&&Et(fe(n,r),fe(r,l))>0)return xt(r,o);if(Et(fe(n,s),fe(s,a))<=0&&Et(fe(n,s),fe(s,r))>0)return xt(s,o);if(Et(fe(n,a),fe(a,l))<=0&&Et(fe(n,a),fe(a,s))>0)return xt(a,o);if(Et(fe(n,l),fe(l,r))<=0&&Et(fe(n,l),fe(l,a))>0)return xt(l,o);if(Et(fe(n,o),fe(r,o))<=0&&Et(fe(n,o),fe(s,o))>0){let c=e.width>e.height?r:s;return xt(c,o)}else if(Et(fe(n,o),fe(s,o))<=0&&Et(fe(n,o),fe(a,o))>0){let c=e.width>e.height?a:s;return xt(c,o)}else if(Et(fe(n,o),fe(a,o))<=0&&Et(fe(n,o),fe(l,o))>0){let c=e.width>e.height?a:l;return xt(c,o)}let d=e.width>e.height?r:l;return xt(d,o)},ko=(e,t,n)=>{let i=yn(t);if(e.type==="diamond")return y1(e,t,n);let r=mr(Nn(t[0],t[1]),i,2),s=mr(Nn(t[2],t[1]),i,2),a=mr(Nn(t[0],t[3]),i,2),l=mr(Nn(t[2],t[3]),i,2);return Vs([r,s,i],n)?st:Vs([s,l,i],n)?Se:Vs([l,a,i],n)?We:Xe},Us=e=>[e[0]===0?0:e[0]>0?-1:1,e[1]===0?0:e[1]>0?-1:1];S();import{getSizeFromPoints as R1,randomInteger as na,getUpdatedTimestamp as oa}from"@excalidraw/common";S();import{clamp as fr,pointDistance as $s,pointFrom as re,pointScaleFromOrigin as b1,pointsEqual as gi,pointTranslate as Xs,vector as sn,vectorCross as gr,vectorFromPoint as Zs,vectorScale as w1}from"@excalidraw/math";import{BinaryHeap as M1,invariant as Lo,isAnyTrue as P1,getSizeFromPoints as Hd,isDevEnv as I1,arrayToMap as S1}from"@excalidraw/common";var qs=1,xe=40,v1=(e,t)=>{let n=e.fixedSegments?e.fixedSegments.slice():null;if(n){let o=[];e.points.map(s=>re(e.x+s[0],e.y+s[1])).forEach((s,a,l)=>{if(a<2)return o.push(s);let d=xt(s,l[a-1]),c=xt(l[a-1],l[a-2]);if(Pe(d,c)){let u=n?.findIndex(h=>h.index===a-1)??-1,m=n?.findIndex(h=>h.index===a)??-1;m!==-1&&(n[m].start=re(l[a-2][0]-e.x,l[a-2][1]-e.y)),u!==-1&&n.splice(u,1),o.splice(-1,1),n.forEach(h=>{h.index>a-1&&(h.index-=1)})}return o.push(s)});let i=[];o.forEach((s,a,l)=>{if(a<3)return i.push(s);if($s(l[a-2],l[a-1])<qs){let d=n?.findIndex(m=>m.index===a-2)??-1,c=n?.findIndex(m=>m.index===a-1)??-1;c!==-1&&n.splice(c,1),d!==-1&&n.splice(d,1),i.splice(-2,2),n.forEach(m=>{m.index>a-2&&(m.index-=2)});let u=Ut(s,l[a-1]);return i.push(re(u?s[0]:l[a-2][0],u?l[a-2][1]:s[1]))}i.push(s)});let r=n.filter(s=>s.index!==1&&s.index!==i.length-1);return r.length===0?bn(Js(ea(Qs(e,Ks(e,t,i.map(s=>re(s[0]-e.x,s[1]-e.y))))??[])),r,null,null):(I1()&&Lo(Yd(i),"Invalid elbow points with fixed segments"),bn(i,r,e.startIsSpecial,e.endIsSpecial))}return{x:e.x,y:e.y,points:e.points,fixedSegments:e.fixedSegments,startIsSpecial:e.startIsSpecial,endIsSpecial:e.endIsSpecial}},A1=(e,t,n)=>{let o=t.map(T=>T.index),r=(e.fixedSegments?.map(T=>T.index)??[]).findIndex(T=>!o.includes(T));if(r===-1||!e.fixedSegments?.[r])return{points:e.points};let s=e.fixedSegments[r].index,a=e.fixedSegments[r-1],l=e.fixedSegments[r+1],d=e.x+(a?a.end[0]:0),c=e.y+(a?a.end[1]:0),u=a?null:e.startBinding,m=l?null:e.endBinding,{startHeading:h,endHeading:g,startGlobalPoint:f,endGlobalPoint:E,hoveredStartElement:x,hoveredEndElement:y,...b}=Ks({x:d,y:c,startBinding:u,endBinding:m,startArrowhead:null,endArrowhead:null,points:e.points},n,[re(0,0),re(e.x+(l?.start[0]??e.points[e.points.length-1][0])-d,e.y+(l?.start[1]??e.points[e.points.length-1][1])-c)],{isDragging:!1}),{points:M}=bn(Js(ea(Qs(e,{startHeading:h,endHeading:g,startGlobalPoint:f,endGlobalPoint:E,hoveredStartElement:x,hoveredEndElement:y,...b})??[])),t,null,null);if(!M||M.length<2)throw new Error("Property 'points' is required in the update returned by normalizeArrowElementUpdate()");let w=[];if(a)for(let T=0;T<a.index;T++)w.push(re(e.x+e.points[T][0],e.y+e.points[T][1]));if(M.forEach(T=>{w.push(re(e.x+(a?a.end[0]:0)+T[0],e.y+(a?a.end[1]:0)+T[1]))}),l)for(let T=l.index;T<e.points.length;T++)w.push(re(e.x+e.points[T][0],e.y+e.points[T][1]));let v=(l?.index??e.points.length)-(a?.index??0)-1,A=t.map(T=>T.index>s?{...T,index:T.index-v+(M.length-1)}:T),k=w.flatMap((T,z)=>{let C=w[z-1],O=w[z+1];if(C&&O){let N=xt(T,C),j=xt(O,T);if(Pe(N,j))return A.forEach(V=>{V.index>z&&(V.index-=1)}),[];if(Pe(N,Us(j)))return A.forEach(V=>{V.index>z&&(V.index+=1)}),[T,T]}return[T]});return bn(k,A,!1,!1)},T1=(e,t,n,o,i,r)=>{let s=t.map((w,v)=>e.fixedSegments==null||e.fixedSegments[v]===void 0||e.fixedSegments[v].index!==w.index||(w.start[0]!==e.fixedSegments[v].start[0]&&w.end[0]!==e.fixedSegments[v].end[0])!=(w.start[1]!==e.fixedSegments[v].start[1]&&w.end[1]!==e.fixedSegments[v].end[1])?v:null).filter(w=>w!==null).shift();if(s==null)return{points:e.points};let a=e.fixedSegments?.findIndex(w=>w.index===1)??-1,l=e.fixedSegments?.findIndex(w=>w.index===e.points.length-1)??-1,d=$s(t[s].start,t[s].end),c=d<xe+5;if(a===-1&&t[s].index===1&&i){let w=yt(n),A=(w?Pe(n,Se):Pe(n,We))?c?d/2:xe:c?-d/2:-xe;t[s].start=re(t[s].start[0]+(w?A:0),t[s].start[1]+(w?0:A))}if(l===-1&&t[s].index===e.points.length-1&&r){let w=yt(o),A=(w?Pe(o,Se):Pe(o,We))?c?d/2:xe:c?-d/2:-xe;t[s].end=re(t[s].end[0]+(w?A:0),t[s].end[1]+(w?0:A))}let u=t.map(w=>({...w,start:re(e.x+w.start[0],e.y+w.start[1]),end:re(e.x+w.end[0],e.y+w.end[1])})),m=e.points.map((w,v)=>re(e.x+w[0],e.y+w[1])),h=u[s].index-1,g=u[s].index,f=u[s].start,E=u[s].end,x=m[h-1]&&!gi(m[h],m[h-1])?Ut(m[h-1],m[h]):void 0,y=m[g+1]&&!gi(m[g],m[g+1])?Ut(m[g+1],m[g]):void 0;if(x!==void 0){let w=x?1:0;m[h-1][w]=f[w]}if(m[h]=f,m[g]=E,y!==void 0){let w=y?1:0;m[g+1][w]=E[w]}let b=u.findIndex(w=>w.index===h);if(b!==-1){let w=Ut(u[b].end,u[b].start)?1:0;u[b].start[w]=f[w],u[b].end=f}let M=u.findIndex(w=>w.index===g+1);if(M!==-1){let w=Ut(u[M].end,u[M].start)?1:0;u[M].end[w]=E[w],u[M].start=E}if(a===-1&&h===0){let w=i?yt(n):Ut(m[1],m[0]);m.unshift(re(w?f[0]:e.x+e.points[0][0],w?e.y+e.points[0][1]:f[1])),i&&m.unshift(re(e.x+e.points[0][0],e.y+e.points[0][1]));for(let v of u)v.index+=i?2:1}if(l===-1&&g===e.points.length-1){let w=yt(o);m.push(re(w?E[0]:e.x+e.points[e.points.length-1][0],w?e.y+e.points[e.points.length-1][1]:E[1])),r&&m.push(re(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]))}return bn(m,u.map(w=>({...w,start:re(w.start[0]-e.x,w.start[1]-e.y),end:re(w.end[0]-e.x,w.end[1]-e.y)})),!1,!1)},k1=(e,t,n,o,i,r,s,a,l)=>{let d=e.startIsSpecial??null,c=e.endIsSpecial??null,u=t.map((E,x)=>x===0?re(e.x+E[0],e.y+E[1]):x===t.length-1?re(e.x+E[0],e.y+E[1]):re(e.x+e.points[x][0],e.y+e.points[x][1])),m=n.map(E=>({...E,start:re(e.x+(E.start[0]-t[0][0]),e.y+(E.start[1]-t[0][1])),end:re(e.x+(E.end[0]-t[0][0]),e.y+(E.end[1]-t[0][1]))})),h=[],g=2+(d?1:0),f=2+(c?1:0);for(;h.length+g<u.length-f;)h.push(u[h.length+g]);{let E=u.at(d?2:1),x=u.at(d?3:2);if(!E||!x)throw new Error(`Second and third points must exist when handling endpoint drag (${d})`);let y=yt(o),b=yt(rn(Zs(E,x)));if(a&&y===b){let M=y?Pe(o,Se):Pe(o,We);if(h.unshift(re(b?r[0]+(M?xe:-xe):x[0],b?x[1]:r[1]+(M?xe:-xe))),h.unshift(re(y?r[0]+(M?xe:-xe):r[0],y?r[1]:r[1]+(M?xe:-xe))),!d){d=!0;for(let w of m)w.index>1&&(w.index+=1)}}else if(h.unshift(re(b?r[0]:E[0],b?E[1]:r[1])),d){d=!1;for(let M of m)M.index>1&&(M.index-=1)}h.unshift(r)}{let E=u.at(u.length-(c?3:2)),x=u.at(u.length-(c?4:3));if(!E||!x)throw new Error(`Second and third to last points must exist when handling endpoint drag (${c})`);let y=yt(i),b=Ut(x,E);if(l&&y===b){let M=y?Pe(i,Se):Pe(i,We);h.push(re(b?s[0]+(M?xe:-xe):x[0],b?x[1]:s[1]+(M?xe:-xe))),h.push(re(y?s[0]+(M?xe:-xe):s[0],y?s[1]:s[1]+(M?xe:-xe))),c||(c=!0)}else h.push(re(b?s[0]:E[0],b?E[1]:s[1])),c&&(c=!1)}return h.push(s),bn(h,m.map(({index:E})=>({index:E,start:h[E-1],end:h[E]})).map(E=>({...E,start:re(E.start[0]-r[0],E.start[1]-r[1]),end:re(E.end[0]-r[0],E.end[1]-r[1])})),d,c)},On=1e6,Do=(e,t,n,o)=>{if(e.points.length<2)return{points:n.points??e.points};F.PROD||(Lo(!n.points||n.points.length>=2,"Updated point array length must match the arrow point length, contain exactly the new start and end points or not be specified at all (i.e. you can't add new points between start and end manually to elbow arrows)"),Lo(!e.fixedSegments||e.fixedSegments.map(w=>w.start[0]===w.end[0]||w.start[1]===w.end[1]).every(Boolean),"Fixed segments must be either horizontal or vertical"),Lo(!n.fixedSegments||n.fixedSegments.map(w=>w.start[0]===w.end[0]||w.start[1]===w.end[1]).every(Boolean),"Updates to fixed segments must be either horizontal or vertical"),Lo(e.points.slice(1).map((w,v)=>w[0]===e.points[v][0]||w[1]===e.points[v][1]),"Elbow arrow segments must be either horizontal or vertical"),Lo(n.fixedSegments?.find(w=>w.index===1&&gi(w.start,(n.points??e.points)[0]))==null&&n.fixedSegments?.find(w=>w.index===(n.points??e.points).length-1&&gi(w.end,(n.points??e.points)[(n.points??e.points).length-1]))==null,"The first and last segments cannot be fixed"));let i=n.fixedSegments??e.fixedSegments??[],r=n.points?n.points&&n.points.length===2?e.points.map((w,v)=>v===0?n.points[0]:v===e.points.length-1?n.points[1]:w):n.points.slice():e.points.slice(),{startBinding:s,endBinding:a,...l}=n,d=typeof s<"u"?s:e.startBinding,c=typeof a<"u"?a:e.endBinding,u=d&&xr(d.elementId,t),m=c&&xr(c.elementId,t),h=Yd(r);if(d&&!u&&h||c&&!m&&h||t.size===0&&h||Object.keys(l).length===0&&(u?.id!==d?.elementId||m?.id!==c?.elementId))return bn(r.map(w=>re(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial);let{startHeading:g,endHeading:f,startGlobalPoint:E,endGlobalPoint:x,hoveredStartElement:y,hoveredEndElement:b,...M}=Ks({x:e.x,y:e.y,startBinding:d,endBinding:c,startArrowhead:e.startArrowhead,endArrowhead:e.endArrowhead,points:e.points},t,r,o);return t.size===0&&h?bn(r.map(w=>re(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial):!n.points&&!n.fixedSegments&&!n.startBinding&&!n.endBinding?v1(e,t):n.startBinding===e.startBinding&&n.endBinding===e.endBinding&&(n.points??[]).every((w,v)=>gi(w,e.points[v]??re(1/0,1/0)))&&h?{}:i.length===0?bn(Js(ea(Qs(e,{startHeading:g,endHeading:f,startGlobalPoint:E,endGlobalPoint:x,hoveredStartElement:y,hoveredEndElement:b,...M})??[])),i,null,null):(e.fixedSegments?.length??0)>i.length?A1(e,i,t):n.points?n.points&&n.fixedSegments?n:k1(e,r,i,g,f,E,x,y,b):T1(e,i,g,f,y,b)},Ks=(e,t,n,o)=>{let i=Xs(n[0],sn(e.x,e.y)),r=Xs(n[n.length-1],sn(e.x,e.y)),s=null,a=null;if(o?.isDragging&&o?.isBindingEnabled!==!1){let w=Array.from(t.values());s=jd(i,t,w,o?.zoom)||null,a=jd(r,t,w,o?.zoom)||null}else s=e.startBinding&&xr(e.startBinding.elementId,t)||null,a=e.endBinding&&xr(e.endBinding.elementId,t)||null;let l=_d({...e,angle:0,type:"arrow",elbowed:!0,points:n},"start",e.startBinding?.fixedPoint,i,s,t,o?.isDragging,o?.isBindingEnabled,o?.isMidpointSnappingEnabled),d=_d({...e,angle:0,type:"arrow",elbowed:!0,points:n},"end",e.endBinding?.fixedPoint,r,a,t,o?.isDragging,o?.isBindingEnabled,o?.isMidpointSnappingEnabled),c=Wd(l,d,s,i,t,o?.zoom),u=Wd(d,l,a,r,t,o?.zoom),m=[l[0]-2,l[1]-2,l[0]+2,l[1]+2],h=[d[0]-2,d[1]-2,d[0]+2,d[1]+2],g=s?bt(s,t,Rn(c,e.startArrowhead?_e(s,{elbowed:!0})*6:_e(s,{elbowed:!0})*2,1)):m,f=a?bt(a,t,Rn(u,e.endArrowhead?_e(a,{elbowed:!0})*6:_e(a,{elbowed:!0})*2,1)):h,E=on(l,a?bt(a,t,Rn(u,xe,xe)):h)||on(d,s?bt(s,t,Rn(c,xe,xe)):m),x=Ud(E?[m,h]:[g,f]),y=C1(E?m:g,E?h:f,x,E?Rn(c,!s&&!a?0:xe,0):Rn(c,!s&&!a?0:xe-(e.startArrowhead?co*6:co*2),xe),E?Rn(u,!s&&!a?0:xe,0):Rn(u,!s&&!a?0:xe-(e.endArrowhead?co*6:co*2),xe),E,s&&bt(s,t),a&&bt(a,t)),b=zd(y[0],c,l),M=zd(y[1],u,d);return{dynamicAABBs:y,startDonglePosition:b,startGlobalPoint:l,startHeading:c,endDonglePosition:M,endGlobalPoint:d,endHeading:u,commonBounds:x,hoveredStartElement:s,hoveredEndElement:a,boundsOverlap:E,startElementBounds:g,endElementBounds:f}},Qs=(e,t)=>{let{dynamicAABBs:n,startDonglePosition:o,startGlobalPoint:i,startHeading:r,endDonglePosition:s,endGlobalPoint:a,endHeading:l,commonBounds:d,hoveredEndElement:c}=t,u=B1(n,o||i,r,s||a,l,d),m=o&&Er(o,u),h=s&&Er(s,u),g=Er(a,u);g&&c&&(g.closed=!0);let f=Er(i,u);f&&e.startBinding&&(f.closed=!0);let E=m&&h&&(on(m.pos,n[1])||on(h.pos,n[0])),x=L1(m||f,h||g,u,r||Se,l||Se,E?[]:n);if(x){let y=x.map(b=>[b.pos[0],b.pos[1]]);return m&&y.unshift(i),h&&y.push(a),y}return null},Rn=(e,t,n)=>{switch(e){case st:return[t,n,n,n];case Se:return[n,t,n,n];case We:return[n,n,t,n]}return[n,n,n,t]},L1=(e,t,n,o,i,r)=>{let s=Ys(e.pos,t.pos),a=new M1(l=>l.f);for(a.push(e);a.size()>0;){let l=a.pop();if(!l||l.closed)continue;if(l===t)return D1(e,l);l.closed=!0;let d=N1(l.addr,n);for(let c=0;c<4;c++){let u=d[c];if(!u||u.closed)continue;let m=b1(u.pos,l.pos,.5);if(P1(...r.map(M=>on(m,M))))continue;let h=O1(c),g=l.parent?rn(Zs(l.pos,l.parent.pos)):o,f=Us(g);if(Pe(f,h)||Vd(e.addr,u.addr)&&Pe(h,o)||Vd(t.addr,u.addr)&&Pe(h,i))continue;let x=g!==h,y=l.g+Ys(u.pos,l.pos)+(x?Math.pow(s,3):0),b=u.visited;if(!b||y<u.g){let M=G1(u,t,h,i);u.visited=!0,u.parent=l,u.h=Ys(t.pos,u.pos)+M*Math.pow(s,2),u.g=y,u.f=u.g+u.h,b?a.rescoreElement(u):a.push(u)}}}return null},D1=(e,t)=>{let n=t,o=[];for(;n.parent;)o.unshift(n),n=n.parent;return o.unshift(e),o},Ys=(e,t)=>Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]),C1=(e,t,n,o,i,r,s,a)=>{let l=s??e,d=a??t,[c,u,m,h]=o??[0,0,0,0],[g,f,E,x]=i??[0,0,0,0],y=[e[0]>t[2]?e[1]>t[3]||e[3]<t[1]?Math.min((l[0]+d[2])/2,e[0]-h):(l[0]+d[2])/2:e[0]>t[0]?e[0]-h:n[0]-h,e[1]>t[3]?e[0]>t[2]||e[2]<t[0]?Math.min((l[1]+d[3])/2,e[1]-c):(l[1]+d[3])/2:e[1]>t[1]?e[1]-c:n[1]-c,e[2]<t[0]?e[1]>t[3]||e[3]<t[1]?Math.max((l[2]+d[0])/2,e[2]+u):(l[2]+d[0])/2:e[2]<t[2]?e[2]+u:n[2]+u,e[3]<t[1]?e[0]>t[2]||e[2]<t[0]?Math.max((l[3]+d[1])/2,e[3]+m):(l[3]+d[1])/2:e[3]<t[3]?e[3]+m:n[3]+m],b=[t[0]>e[2]?t[1]>e[3]||t[3]<e[1]?Math.min((d[0]+l[2])/2,t[0]-x):(d[0]+l[2])/2:t[0]>e[0]?t[0]-x:n[0]-x,t[1]>e[3]?t[0]>e[2]||t[2]<e[0]?Math.min((d[1]+l[3])/2,t[1]-g):(d[1]+l[3])/2:t[1]>e[1]?t[1]-g:n[1]-g,t[2]<e[0]?t[1]>e[3]||t[3]<e[1]?Math.max((d[2]+l[0])/2,t[2]+f):(d[2]+l[0])/2:t[2]<e[2]?t[2]+f:n[2]+f,t[3]<e[1]?t[0]>e[2]||t[2]<e[0]?Math.max((d[3]+l[1])/2,t[3]+E):(d[3]+l[1])/2:t[3]<e[3]?t[3]+E:n[3]+E],M=Ud([y,b]);if(!r&&y[2]-y[0]+b[2]-b[0]>M[2]-M[0]+1e-11&&y[3]-y[1]+b[3]-b[1]>M[3]-M[1]+1e-11){let[w,v]=[(b[0]+b[2])/2,(b[1]+b[3])/2];if(t[0]>e[2]&&e[1]>t[3]){let A=y[2]+(b[0]-y[2])/2,k=b[3]+(y[1]-b[3])/2;return gr(sn(e[2]-w,e[1]-v),sn(e[0]-w,e[3]-v))>0?[[y[0],y[1],A,y[3]],[A,b[1],b[2],b[3]]]:[[y[0],k,y[2],y[3]],[b[0],b[1],b[2],k]]}else if(e[2]<t[0]&&e[3]<t[1]){let A=y[2]+(b[0]-y[2])/2,k=y[3]+(b[1]-y[3])/2;return gr(sn(e[0]-w,e[1]-v),sn(e[2]-w,e[3]-v))>0?[[y[0],y[1],y[2],k],[b[0],k,b[2],b[3]]]:[[y[0],y[1],A,y[3]],[A,b[1],b[2],b[3]]]}else if(e[0]>t[2]&&e[3]<t[1]){let A=b[2]+(y[0]-b[2])/2,k=y[3]+(b[1]-y[3])/2;return gr(sn(e[2]-w,e[1]-v),sn(e[0]-w,e[3]-v))>0?[[A,y[1],y[2],y[3]],[b[0],b[1],A,b[3]]]:[[y[0],y[1],y[2],k],[b[0],k,b[2],b[3]]]}else if(e[0]>t[2]&&e[1]>t[3]){let A=b[2]+(y[0]-b[2])/2,k=b[3]+(y[1]-b[3])/2;return gr(sn(e[0]-w,e[1]-v),sn(e[2]-w,e[3]-v))>0?[[A,y[1],y[2],y[3]],[b[0],b[1],A,b[3]]]:[[y[0],k,y[2],y[3]],[b[0],b[1],b[2],k]]}}return[y,b]},B1=(e,t,n,o,i,r)=>{let s=new Set,a=new Set;n===Xe||n===Se?a.add(t[1]):s.add(t[0]),i===Xe||i===Se?a.add(o[1]):s.add(o[0]),e.forEach(c=>{s.add(c[0]),s.add(c[2]),a.add(c[1]),a.add(c[3])}),s.add(r[0]),s.add(r[2]),a.add(r[1]),a.add(r[3]);let l=Array.from(a).sort((c,u)=>c-u),d=Array.from(s).sort((c,u)=>c-u);return{row:l.length,col:d.length,data:l.flatMap((c,u)=>d.map((m,h)=>({f:0,g:0,h:0,closed:!1,visited:!1,parent:null,addr:[h,u],pos:[m,c]})))}},zd=(e,t,n)=>{switch(t){case st:return re(n[0],e[1]);case Se:return re(e[2],n[1]);case We:return re(n[0],e[3])}return re(e[0],n[1])},G1=(e,t,n,o)=>{if(o===Se)switch(n){case Se:return e.pos[0]>=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2;case st:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case We:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case Xe:return e.pos[1]===t.pos[1]?4:2}else if(o===Xe)switch(n){case Se:return e.pos[1]===t.pos[1]?4:2;case st:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case We:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case Xe:return e.pos[0]<=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2}else if(o===st)switch(n){case Se:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case st:return e.pos[1]>=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case We:return e.pos[0]===t.pos[0]?4:2;case Xe:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3}else if(o===We)switch(n){case Se:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case st:return e.pos[0]===t.pos[0]?4:2;case We:return e.pos[1]<=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case Xe:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3}return 0},N1=([e,t],n)=>[fi([e,t-1],n),fi([e+1,t],n),fi([e,t+1],n),fi([e-1,t],n)],fi=([e,t],n)=>e<0||e>=n.col||t<0||t>=n.row?null:n.data[t*n.col+e]??null,Er=(e,t)=>{for(let n=0;n<t.col;n++)for(let o=0;o<t.row;o++){let i=fi([n,o],t);if(i&&e[0]===i.pos[0]&&e[1]===i.pos[1])return i}return null},Ud=e=>[Math.min(...e.map(t=>t[0])),Math.min(...e.map(t=>t[1])),Math.max(...e.map(t=>t[2])),Math.max(...e.map(t=>t[3]))],xr=(e,t)=>{let n=t.get(e);return n&&De(n)?n:null},bn=(e,t,n,o)=>{let i=e[0][0],r=e[0][1],s=e.map(a=>Xs(a,w1(Zs(e[0]),-1)));return(i<-On||i>On||r<-On||r>On||i+s[s.length-1][0]<-On||i+s[s.length-1][0]>On||r+s[s.length-1][1]<-On||r+s[s.length-1][1]>On)&&console.error("Elbow arrow normalization is outside reasonable bounds (> 1e6)",{x:i,y:r,points:s,...Hd(s)}),s=s.map(([a,l])=>re(fr(a,-1e6,1e6),fr(l,-1e6,1e6))),{points:s,x:fr(i,-1e6,1e6),y:fr(r,-1e6,1e6),fixedSegments:(t?.length??0)>0?t:null,...Hd(s),startIsSpecial:n,endIsSpecial:o}},Js=e=>{if(e.length>1){let t=Math.abs(e[0][1]-e[1][1])<Math.abs(e[0][0]-e[1][0]);return e.filter((n,o)=>{if(o===0||o===e.length-1)return!0;let i=e[o+1],r=Math.abs(n[1]-i[1])<Math.abs(n[0]-i[0]);return t===r?(t=r,!1):(t=r,!0)})}return e},ea=e=>e.length>=4?e.filter((t,n)=>{if(n===0||n===e.length-1)return!0;let o=e[n-1];return $s(o,t)>qs}):e,O1=e=>{switch(e){case 0:return st;case 1:return Se;case 2:return We}return Xe},_d=(e,t,n,o,i,r,s,a=!0,l=!0)=>s?a&&i&&r?ta(e,i,t,r,void 0,l):o:i?Qe(n||[0,0],i,r??S1([i])):o,Wd=(e,t,n,o,i,r)=>Xd(e,t,n,n&&bt(n,i,Array(4).fill(nn(n,i,e))),o,i,r),jd=(e,t,n,o)=>xn(e,n,t,Wt(o)),Vd=(e,t)=>e[0]===t[0]&&e[1]===t[1],Yd=(e,t=qs)=>e.slice(1).map((n,o)=>Math.abs(n[0]-e[o][0])<t||Math.abs(n[1]-e[o][1])<t).every(Boolean);var $e=(e,t,n,o)=>{let i=!1,{points:r,fixedSegments:s,fileId:a}=n;ee(e)&&(Object.keys(n).length===0||typeof r<"u"||typeof s<"u")?n={...n,angle:0,...Do({...e,x:n.x||e.x,y:n.y||e.y},t,n,o)}:typeof r<"u"&&(n={...R1(r),...n});for(let l in n){let d=n[l];if(typeof d<"u"){if(e[l]===d&&(typeof d!="object"||d===null||l==="groupIds"||l==="scale"))continue;if(l==="scale"){let c=e[l],u=d;if(c[0]===u[0]&&c[1]===u[1])continue}else if(l==="points"){let c=e[l],u=d;if(c.length===u.length){let m=!1,h=c.length;for(;--h;){let g=c[h],f=u[h];if(g[0]!==f[0]||g[1]!==f[1]){m=!0;break}}if(!m)continue}}e[l]=d,i=!0}}return i&&((typeof n.height<"u"||typeof n.width<"u"||typeof a<"u"||typeof r<"u")&&Lt.delete(e),e.version=n.version??e.version+1,e.versionNonce=n.versionNonce??na(),e.updated=oa()),e},at=(e,t,n=!1)=>{let o=!1;for(let i in t){let r=t[i];if(typeof r<"u"){if(e[i]===r&&(typeof r!="object"||r===null))continue;o=!0}}return!o&&!n?e:{...e,...t,version:t.version??e.version+1,versionNonce:t.versionNonce??na(),updated:oa()}},$d=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=na(),e.updated=oa(),e);var tc=5,co=5,j1=10,xi=10/1.5,Mr=1,_e=(e,t)=>(t.elbowed?co:tc)+e.strokeWidth/2,Wt=e=>{let t=Math.max(tc,15),n=e?.value&&e.value<1?e.value:1;return wr(t/(n*1.5),t,t*2)},an=e=>e.isBindingEnabled,V1=(e,t,n,o,i,r,s)=>{let{start:a,end:l}=sa(e,t,n,o,i.getNonDeletedElementsMap(),i.getNonDeletedElements(),r,{...s,finalize:!0}),d=r.isMidpointSnappingEnabled&&!s?.angleLocked&&!r.gridModeEnabled;if(Zd(e,a,"start",i,r.isBindingEnabled,d),Zd(e,l,"end",i,r.isBindingEnabled,d),a.focusPoint||l.focusPoint){let c=new Map;a.focusPoint&&c.set(0,{point:Yt(e,"startBinding",e.startBinding,a.element,i.getNonDeletedElementsMap())||e.points[0]}),l.focusPoint&&c.set(e.points.length-1,{point:Yt(e,"endBinding",e.endBinding,l.element,i.getNonDeletedElementsMap())||e.points[e.points.length-1]}),W.movePoints(e,i,c)}return{start:a,end:l}},Zd=(e,{mode:t,element:n,focusPoint:o},i,r,s=!0,a=!0)=>{t===null?nt(e,i,r):t!==void 0&&ln(e,n,t,i,r,o,s,a)},nc=(e,t,n,o,i)=>{wn(t.size===1,"Bound elbow arrows cannot be moved");let r=t.entries().next().value;wn(r,"There should be a position update for dragging an elbow arrow endpoint");let[s,{point:a}]=r,l=W.getPointGlobalCoordinates(e,a,n),d=xn(l,o,n,Wt(i)),c=d?{element:d,mode:"orbit",focusPoint:W.getPointAtIndexGlobalCoordinates(e,s,n)}:{mode:null},u={mode:void 0};return s===0?{start:c,end:u}:{start:u,end:c}},U1=(e,t,n,o,i,r,s,a,l,d,c)=>{let u={mode:void 0},m={mode:void 0},h=e.points.length>2,g=W.getPointGlobalCoordinates(e,t.get(i?s:a).point,n),f=xn(g,o,n);if(i)return f?u={element:f,mode:"inside",focusPoint:g}:u={mode:null},{start:u,end:m};if(r){let E=l?.selectedLinearElement?.initialState.origin;if(f&&e.startBinding?.elementId===f.id){let x=de(f.x+f.width/2,f.y+f.height/2);return{start:h?{mode:void 0}:{mode:"inside",element:f,focusPoint:E??x},end:h?{mode:"orbit",element:f,focusPoint:g}:{mode:"inside",element:f,focusPoint:g}}}if(f&&e.startBinding){let x=e.startBinding;if(dr(g,o,n).find(b=>b.id===x.elementId)){let b=n.get(e.startBinding.elementId);return wn(b,"Other element must be in the elements map"),{start:h?{mode:void 0}:{mode:b.id!==f.id?"orbit":"inside",element:b,focusPoint:E??de(e.x,e.y)},end:{mode:"orbit",element:f,focusPoint:g}}}}if(e.startBinding&&e.startBinding.elementId!==f?.id){let x=n.get(e.startBinding.elementId);wn(x,"Other element must be in the elements map");let b={mode:!!l.selectedLinearElement?.initialState.arrowStartIsInside?"inside":"orbit",element:x,focusPoint:c?he(x,n):E??de(e.x,e.y)},M=f&&js(x,f,n),w;if(f){let v=d==="inside"||d==="skip";w={mode:v&&!M?"inside":"orbit",element:f,focusPoint:g}}else w={mode:null};return{start:h?{mode:void 0}:b,end:w}}if(!e.startBinding)return f?m={mode:d==="inside"||d==="skip"?"inside":"orbit",element:f,focusPoint:g}:m={mode:null},{start:u,end:m}}wn(!1,"New arrow creation should not reach here")},qd=(e,t,n,o,i,r,s,a)=>{let l={mode:void 0},d={mode:void 0},c=s.points.length>2,u=xn(e,i,o),m=n?dr(e,i,o).some(E=>E.id===n.elementId):!1,h=n?o.get(n.elementId):null,g=m&&h?H1(h.backgroundColor):!1,f=u&&h&&js(h,u,o);return r==="inside"||r==="skip"?(l=u?{element:!m||!h||g?u:h,focusPoint:e,mode:"inside"}:{mode:null},d=a&&u&&u.id===n?.elementId?{mode:null}:d,{current:l,other:d}):u?u.id===t?.elementId&&t.mode==="inside"?{current:{mode:"inside",focusPoint:e,element:u},other:d}:n?n.elementId===u.id?n.mode==="orbit"?(l={element:u,mode:"orbit",focusPoint:e},d={mode:a?null:void 0},{current:l,other:c?{mode:void 0}:d}):(l={element:u,mode:"inside",focusPoint:e},{current:l,other:c?{mode:void 0}:d}):(m&&h&&!g?l={element:h,mode:"inside",focusPoint:e}:l={element:u,mode:"orbit",focusPoint:e},{current:l,other:c?{mode:void 0}:d}):(l={element:u,mode:"orbit",focusPoint:e},{current:l,other:c?{mode:void 0}:d}):{current:{mode:null},other:d}},sa=(e,t,n,o,i,r,s,a)=>F1("COMPLEX_BINDINGS")?Y1(e,t,i,r,s,a):oc(e,t,n,o,i,r,s,a),oc=(e,t,n,o,i,r,s,a)=>{let d=e.points.length-1,c=t.has(0),u=t.has(d),m={mode:void 0},h={mode:void 0};if(e.points.length<2)return console.error("Attempting to bind a linear element with less than 2 points"),{start:{mode:void 0},end:{mode:void 0}};if(!c&&!u)return{start:m,end:h};if(c&&u)return{start:{mode:null},end:{mode:null}};if(!an(s))return m=c?{mode:null}:m,h=u?{mode:null}:h,{start:m,end:h};if(ee(e))return nc(e,t,i,r,a?.zoom);let g=c?e.endBinding:e.startBinding,f=t.get(c?0:d)?.point;wn(f,`Local point must be defined for ${c?"start":"end"} dragging`);let E=W.getPointGlobalCoordinates(e,f,i),x=xn(a?.angleLocked||s.gridModeEnabled?de(n,o):E,r,i,Wt(s.zoom)),y=x&&(a?.angleLocked?ft(de(n,o),x,i):ft(E,x,i)),b=g?i.get(g.elementId):void 0,M=g&&b&&Qe(g.fixedPoint,b,i),w=b&&M&&en({point:M,element:b,elementsMap:i,threshold:0,overrideShouldTestInside:!0}),v=s.selectedLinearElement?.initialState.arrowOtherEndpointInitialBinding;if(g&&g.elementId===x?.id&&(!a?.newArrow||s.selectedLinearElement?.initialState.origin))return{start:{mode:"inside",element:x,focusPoint:c?E:a?.newArrow?_1(ra(s.selectedLinearElement.initialState.origin[0],s.selectedLinearElement.initialState.origin[1],a.gridSize)):b?Qe(g.fixedPoint,b,i):W.getPointAtIndexGlobalCoordinates(e,0,i)},end:{mode:"inside",element:x,focusPoint:u?E:b?Qe(g.fixedPoint,b,i):W.getPointAtIndexGlobalCoordinates(e,-1,i)}};if(a?.altKey)return{start:c?x?{mode:"inside",element:x,focusPoint:E}:{mode:null}:m,end:u?x?{mode:"inside",element:x,focusPoint:E}:{mode:null}:h};let A=x?y?{mode:"inside",element:x,focusPoint:E}:{mode:"orbit",element:x,focusPoint:So(e,a?.angleLocked?E:s.gridModeEnabled?Q1(de(n,o),x,i,s.gridSize,e,W.getPointAtIndexGlobalCoordinates(e,c?1:-2,i)):E,x,c?"start":"end",i,s.zoom,s.isMidpointSnappingEnabled&&!a?.angleLocked&&!s.gridModeEnabled)||E}:{mode:null},k=W.getPointAtIndexGlobalCoordinates(e,c?-1:0,i),T=M&&b&&en({point:E,element:b,elementsMap:i,threshold:Wt(s.zoom),overrideShouldTestInside:!0}),z=v?.mode==="inside",C=a?.newArrow?s.selectedLinearElement?.initialState.arrowStartIsInside:g?.mode==="inside"&&z,O={mode:void 0};return C||(g?.mode==="inside"&&!z&&b&&!a?.newArrow?O={mode:"orbit",element:b,focusPoint:M||k}:b&&!w&&!T&&s.selectedLinearElement?.initialState.altFocusPoint?O={mode:"orbit",element:b,focusPoint:s.selectedLinearElement.initialState.altFocusPoint}:a?.angleLocked&&b&&(O={mode:"orbit",element:b,focusPoint:So(e,k,b,c?"end":"start",i,s.zoom,s.isMidpointSnappingEnabled)||k})),{start:c?A:O,end:u?A:O}},Y1=(e,t,n,o,i,r)=>{let s=i.bindMode||"orbit",a=0,l=e.points.length-1,d=t.has(a),c=t.has(l),u={mode:void 0},m={mode:void 0};if(e.points.length<2)return console.error("Attempting to bind a linear element with less than 2 points"),{start:{mode:void 0},end:{mode:void 0}};if(!d&&!c)return{start:u,end:m};if(d&&c)return{start:{mode:null},end:{mode:null}};if(!an(i))return u=d?{mode:null}:u,m=c?{mode:null}:m,{start:u,end:m};if(ee(e))return nc(e,t,n,o);if(r?.newArrow){let{start:h,end:g}=U1(e,t,n,o,d,c,a,l,i,s,r?.shiftKey);return{start:h,end:g}}if(d){let h=t.get(a)?.point;wn(h,"Local point must be defined for start dragging");let g=W.getPointGlobalCoordinates(e,h,n),{current:f,other:E}=qd(g,e.startBinding,e.endBinding,n,o,s,e,r?.finalize);return{start:f,end:E}}if(c){let h=t.get(l)?.point;wn(h,"Local point must be defined for end dragging");let g=W.getPointGlobalCoordinates(e,h,n),{current:f,other:E}=qd(g,e.endBinding,e.startBinding,n,o,s,e,r?.finalize);return{start:E,end:f}}return{start:u,end:m}},i6=(e,t,n)=>{e.forEach(o=>{V1(o,new Map,1/0,1/0,t,n)})},ic=(e,t,n,o,i)=>{i.mutateElement(e,{[o==="start"?"startBinding":"endBinding"]:n}),ec(t.boundElements||[]).has(e.id)||i.mutateElement(t,{boundElements:(t.boundElements||[]).concat({id:e.id,type:"arrow"})})},ln=(e,t,n,o,i,r,s=!0,a=!0)=>{let l=i.getNonDeletedElementsMap(),d;ee(e)?d={elementId:t.id,mode:"orbit",...J1(e,t,o,l,s,a)}:d={elementId:t.id,mode:n,...Go(e,t,o,l,r)},ic(e,t,d,o,i)},nt=(e,t,n)=>{let o=t==="start"?"startBinding":"endBinding",i=e[o];if(i==null)return null;let r=e[t==="start"?"endBinding":"startBinding"];if(!r||r.elementId!==i.elementId){let s=n.getNonDeletedElementsMap().get(i.elementId);n.mutateElement(s,{boundElements:s.boundElements?.filter(a=>a.id!==e.id)})}return n.mutateElement(e,{[o]:null}),i.elementId},ot=(e,t,n)=>{if(!De(e))return;let{simultaneouslyUpdated:o}=n??{},i=$1(o),r=t.getNonDeletedElementsMap();n?.changedElements&&(r=new Map(r),n.changedElements.forEach(a=>{r.set(a.id,a)})),Pr(r,e,a=>{if(a&&!rt(a)&&console.error("[NONDELETED][INVARIANT] updateBoundElements(): `isDeleted: true` in visitor"),!J(a)||!rt(a)||!X1(a,e))return;let l=a.startBinding?r.get(a.startBinding.elementId):null,d=a.endBinding?l?.id===a.endBinding.elementId?l:r.get(a.endBinding.elementId):null;if(i.has(a.id))return;let c=Ir(r,a,(m,h)=>{if(m&&De(m)&&(h==="startBinding"||h==="endBinding")&&(e.id===a[h]?.elementId||e.id===a[h==="startBinding"?"endBinding":"startBinding"]?.elementId)){let g=Yt(a,h,a[h],m,r);if(g)return[h==="startBinding"?0:a.points.length-1,{point:g}]}return null}).filter(m=>m!==null);W.movePoints(a,t,new Map(c),{moveMidPointsWithElement:!!l&&l?.id===d?.id});let u=pe(a,r);u&&!u.isDeleted&&lo(a,t,!1)})},Kd=(e,t,n,o,i)=>{wn(!ee(e),"Elbow arrows not supported for indirect updates");let r=e[t],s=r&&n.get(r.elementId),a=W.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?0:-1,n),l=s&&en({element:s,point:a,elementsMap:n,threshold:Wt(i.zoom)}),d=t==="startBinding"?"start":"end";if(nt(e,d,o),l){let c=t==="startBinding"?0:e.points.length-1,u=e.points[c],m=oc(e,new Map([[c,{point:u}]]),a[0],a[1],n,o.getNonDeletedElements(),i);m[d]&&m[d].element?.id===s.id&&m[d].mode&&ln(e,s,m[d].mode,d,o,m[d].focusPoint)}},r6=(e,t,n,o)=>{if(J(e)){let i=t.getNonDeletedElementsMap();e.startBinding&&Kd(e,"startBinding",i,t,n),e.endBinding&&Kd(e,"endBinding",i,t,n)}else ot(e,t,{...o,changedElements:new Map([[e.id,e]])})},X1=(e,t)=>e.startBinding?.elementId===t.id||e.endBinding?.elementId===t.id,$1=e=>new Set((e||[]).map(t=>t.id)),Xd=(e,t,n,o,i,r,s)=>{let a=rn(Bo(t,e));return!n||!o?a:Z1(i,n,r,s)?ko(n,o,e):rn(Bo(e,he(n,r)))},Z1=(e,t,n,o)=>{let i=nn(t,n,e),r=Wt(o);return i>r?null:i},ta=(e,t,n,o,i,r=!0)=>{let s=ee(e),a=W.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,o);if(e.points.length<2)return a;let l=nd(t)&&s?q1(e,t,o,a):a,d=i&&!s?i[1]:W.getPointAtIndexGlobalCoordinates(e,n==="start"?1:-2,o),c=_e(t,e),u=bt(t,o),m=yn(u),h=null;if(s){let g=yt(ko(t,u,a)),E=(r?aa(t,o,l,.05,e):void 0)||a,x=de(g?m[0]:E[0],g?E[1]:m[1]),y=i??Co(x,yr(br(ia(Bo(E,x)),Math.max(t.width,t.height)*2),x));if(h=gt(t,o,y,c).sort(Dt)[0],!h){let b=de(g?E[0]:m[0],g?m[1]:E[1]),M=Co(b,yr(br(ia(Bo(E,b)),Math.max(t.width,t.height)*2),b));h=gt(t,o,M,co).sort(Dt)[0]}}else{let g=i;if(!g){let f=br(ia(Bo(l,d)),Fn(l,d)+Math.max(t.width,t.height)+c*2);g=i??Co(yr(f,d),yr(br(f,-1),d))}h=Fn(l,d)<1?l:gt(t,o,g,c).sort((f,E)=>Dt(f,d)-Dt(E,d))[0]}return!h||Dt(l,h)<z1?l:h},q1=(e,t,n,o)=>{let i=he(t,n),r=ve(o,i,-t.angle),s=_e(t,e);return r[0]<t.x&&r[1]<t.y?r[1]-t.y>-s?ve(de(t.x-s,t.y),i,t.angle):ve(de(t.x,t.y-s),i,t.angle):r[0]<t.x&&r[1]>t.y+t.height?r[0]-t.x>-s?ve(de(t.x,t.y+t.height+s),i,t.angle):ve(de(t.x-s,t.y+t.height),i,t.angle):r[0]>t.x+t.width&&r[1]>t.y+t.height?r[0]-t.x<t.width+s?ve(de(t.x+t.width,t.y+t.height+s),i,t.angle):ve(de(t.x+t.width+s,t.y+t.height),i,t.angle):r[0]>t.x+t.width&&r[1]<t.y?r[0]-t.x<t.width+s?ve(de(t.x+t.width,t.y-s),i,t.angle):ve(de(t.x+t.width+s,t.y),i,t.angle):o},aa=(e,t,n,o=.05,i)=>{let{x:r,y:s,width:a,height:l,angle:d}=e,c=he(e,t,-.1,-.1),u=ve(n,c,-d),m=i?_e(e,i):0,h=wr(o*l,5,80),g=wr(o*a,5,80);if(!(Fn(c,u)<m)){if(u[0]<=r+a/2&&u[1]>c[1]-h&&u[1]<c[1]+h)return ve(de(r-m,c[1]),c,d);if(u[1]<=s+l/2&&u[0]>c[0]-g&&u[0]<c[0]+g)return ve(de(c[0],s-m),c,d);if(u[0]>=r+a/2&&u[1]>c[1]-h&&u[1]<c[1]+h)return ve(de(r+a+m,c[1]),c,d);if(u[1]>=s+l/2&&u[0]>c[0]-g&&u[0]<c[0]+g)return ve(de(c[0],s+l+m),c,d);if(e.type==="diamond"){let f=m,E=de(r+a/4-f,s+l/4-f),x=de(r+3*a/4+f,s+l/4-f),y=de(r+a/4-f,s+3*l/4+f),b=de(r+3*a/4+f,s+3*l/4+f);if(Fn(E,u)<Math.max(g,h))return ve(E,c,d);if(Fn(x,u)<Math.max(g,h))return ve(x,c,d);if(Fn(y,u)<Math.max(g,h))return ve(y,c,d);if(Fn(b,u)<Math.max(g,h))return ve(b,c,d)}}},K1=(e,t,n)=>{let o=e[t];if(!o)return{element:null,fixedPoint:null,focusPoint:null,binding:o,mode:null};let i=n.get(o.elementId);return{element:i,fixedPoint:o.fixedPoint,focusPoint:Qe(Je(o.fixedPoint),i,n),binding:o,mode:o.mode}},Q1=(e,t,n,o,i,r)=>{if(!o)return e;let s=bt(t,n),a=r&&(t.type==="ellipse"||t.type==="diamond")?rn(Bo(r,e)):ko(t,s,e),l=_e(t,i),d=Math.max(t.width,t.height)+l*2,c=yn(s),u=Math.abs(a[0]),m=Math.abs(a[1]);if(u>=m){let[,E]=ra(e[0],e[1],o),x=Co(de(c[0]-d,E),de(c[0]+d,E));return gt(t,n,x,l).sort((b,M)=>Dt(b,e)-Dt(M,e))[0]??de(e[0],E)}let[h]=ra(e[0],e[1],o),g=Co(de(h,c[1]-d),de(h,c[1]+d));return gt(t,n,g,l).sort((E,x)=>Dt(E,e)-Dt(x,e))[0]??de(h,e[1])},Qd=e=>e.width*e.height,Yt=(e,t,n,o,i,r)=>{if(n==null||n.elementId!==o.id&&e.points.length>2||W1(e.points[e.points.length-1],de(0,0)))return null;let s=Qe(Je(n.fixedPoint),o,i);if(n.mode==="inside")return W.createPointAt(e,i,s[0],s[1],null);let{element:a,focusPoint:l}=K1(e,t==="startBinding"?"endBinding":"startBinding",i),d=W.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?1:-2,i),c=e.points.length===2&&l||d,u=c&&Co(s,c),m=a&&u&&gt(a,i,u,_e(a,e)).sort((b,M)=>Dt(b,s)-Dt(M,s))[0],h=u&&gt(o,i,u,_e(o,e)).sort((b,M)=>Dt(b,c)-Dt(M,c))[0],g=e.startArrowhead!==null,f=e.endArrowhead!==null,E=!g&&!f||t==="startBinding"&&g||t==="endBinding"&&f?s:h||s;if(a&&h&&!r&&Qd(a)<Qd(o)*2&&en({element:a,point:h,elementsMap:i,threshold:_e(a,e),overrideShouldTestInside:!0}))return W.createPointAt(e,i,E[0],E[1],null);let y=Fn(a&&(m||l)||d,h||s)<=j1;return a?y?W.createPointAt(e,i,E?.[0]||s[0],E?.[1]||s[1],null):W.createPointAt(e,i,h?.[0]||s[0],h?.[1]||s[1],null):W.createPointAt(e,i,y?s[0]:h?.[0]??s[0],y?s[1]:h?.[1]??s[1],null)},J1=(e,t,n,o,i=!0,r=!0)=>{let s=[t.x,t.y,t.x+t.width,t.y+t.height],a=i?ta(e,t,n,o,void 0,r):W.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,o),l=de(s[0]+(s[2]-s[0])/2,s[1]+(s[3]-s[1])/2),d=ve(a,l,-t.angle);if(t.width<Mr||t.height<Mr)return{fixedPoint:Je([.5,.5])};let c=_e(t,e);return{fixedPoint:Je([(d[0]-t.x)/Math.max(t.width,c),(d[1]-t.y)/Math.max(t.height,c)])}},Go=(e,t,n,o,i)=>{let r=i||W.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,o),s=he(t,o),a=ve(r,s,-t.angle);if(t.width<Mr||t.height<Mr)return{fixedPoint:Je([.5,.5])};let l=_e(t,e),d=(a[0]-t.x)/Math.max(t.width,l),c=(a[1]-t.y)/Math.max(t.height,l);return{fixedPoint:Je([d,c])}},rc=(e,t,n)=>{for(let o of e){if("boundElements"in o&&o.boundElements&&Object.assign(o,{boundElements:o.boundElements.reduce((i,r)=>{let s=t.get(r.id);return s&&i.push({...r,id:s}),i},[])}),"containerId"in o&&o.containerId&&Object.assign(o,{containerId:t.get(o.containerId)??null}),"endBinding"in o&&o.endBinding){let i=t.get(o.endBinding.elementId);Object.assign(o,{endBinding:i?{...o.endBinding,elementId:i}:null})}if("startBinding"in o&&o.startBinding){let i=t.get(o.startBinding.elementId);Object.assign(o,{startBinding:i?{...o.startBinding,elementId:i}:null})}ee(o)&&Object.assign(o,Do(o,n,{points:[o.points[0],o.points[o.points.length-1]]}))}},s6=(e,t)=>{let n=ec(e);for(let o of t)Hn.unbindAffected(n,o,(i,r)=>$e(i,n,r)),zn.unbindAffected(n,o,(i,r)=>$e(i,n,r))},Ei=(e,t,n=[])=>{if(!e)return null;let o=e.filter(i=>!t.has(i.id));return o.push(...n.map(i=>({id:i.id,type:i.type}))),o},sc=new Set(["boundElements","frameId","containerId","startBinding","endBinding"]),Pr=(e,t,n)=>{De(t)&&(t.boundElements?.slice()??[]).forEach(({id:i})=>{n(e.get(i),"boundElements",i)})},Ir=(e,t,n)=>{let o=[];if(t.frameId){let i=t.frameId;o.push(n(e.get(i),"frameId",i))}if(Ne(t)){let i=t.containerId;o.push(n(e.get(i),"containerId",i))}if(J(t)){if(t.startBinding){let i=t.startBinding.elementId;o.push(n(e.get(i),"startBinding",i))}if(t.endBinding){let i=t.endBinding.elementId;o.push(n(e.get(i),"endBinding",i))}}return o},Hn=class{static unbindAffected(t,n,o){n&&Ir(t,n,i=>{!i||i.isDeleted||Pr(t,i,(r,s,a)=>{a===n.id&&o(i,{boundElements:Ei(i.boundElements,new Set([a]))})})})}static rebindAffected=(t,n,o)=>{!n||n.isDeleted||Ir(t,n,(i,r)=>{if(!i||i.isDeleted){o(n,{[r]:null});return}r!=="frameId"&&(i.boundElements?.find(s=>s.id===n.id)||(J(n)&&o(i,{boundElements:Ei(i.boundElements,new Set,new Array(n))}),ue(n)&&(i.boundElements?.find(s=>s.type==="text")?o(n,{[r]:null}):o(i,{boundElements:Ei(i.boundElements,new Set,new Array(n))}))))})}},zn=class{static unbindAffected(t,n,o){n&&Pr(t,n,i=>{!i||i.isDeleted||Ir(t,i,(r,s,a)=>{a===n.id&&o(i,{[s]:null})})})}static rebindAffected=(t,n,o)=>{!n||n.isDeleted||Pr(t,n,(i,r,s)=>{if(!i||i.isDeleted){o(n,{boundElements:Ei(n.boundElements,new Set([s]))});return}ue(i)&&((n.boundElements?.slice()??[]).reverse().find(l=>l.type==="text")?.id===i.id?i.containerId!==n.id&&o(i,{containerId:n.id}):(i.containerId!==null&&o(i,{containerId:null}),o(n,{boundElements:Ei(n.boundElements,new Set([i.id]))})))})}},Qe=(e,t,n)=>{let[o,i]=Je(e);return ve(de(t.x+t.width*o,t.y+t.height*i),he(t,n),t.angle)},ef=(e,t)=>{let n=e.startBinding&&t.get(e.startBinding.elementId),o=e.endBinding&&t.get(e.endBinding.elementId),i=n&&e.startBinding?Qe(e.startBinding.fixedPoint,n,t):de(e.x+e.points[0][0],e.y+e.points[0][1]),r=o&&e.endBinding?Qe(e.endBinding.fixedPoint,o,t):de(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]);return[i,r]},ac=(e,t)=>{let[n,o]=ef(e,t);return[W.pointFromAbsoluteCoords(e,n,t),W.pointFromAbsoluteCoords(e,o,t)]},tf=e=>Array.isArray(e)&&e.length===2&&e.every(t=>Number.isFinite(t)),Jd=10,Je=e=>{if(!tf(e))return[.5001,.5001];let t=1e-4,n=e.map(o=>wr(o,-Jd,Jd));return Math.abs(n[0]-.5)<t||Math.abs(n[1]-.5)<t?n.map(o=>Math.abs(o-.5)<t?.5001:o):n},nf=e=>e.type==="ellipse"||e.type==="diamond"?e.type:"rectangle",of={rectangle:[{centerAngle:0,sectorWidth:75,side:"right"},{centerAngle:45,sectorWidth:15,side:"bottom-right"},{centerAngle:90,sectorWidth:75,side:"bottom"},{centerAngle:135,sectorWidth:15,side:"bottom-left"},{centerAngle:180,sectorWidth:75,side:"left"},{centerAngle:225,sectorWidth:15,side:"top-left"},{centerAngle:270,sectorWidth:75,side:"top"},{centerAngle:315,sectorWidth:15,side:"top-right"}],diamond:[{centerAngle:0,sectorWidth:15,side:"right"},{centerAngle:45,sectorWidth:75,side:"bottom-right"},{centerAngle:90,sectorWidth:15,side:"bottom"},{centerAngle:135,sectorWidth:75,side:"bottom-left"},{centerAngle:180,sectorWidth:15,side:"left"},{centerAngle:225,sectorWidth:75,side:"top-left"},{centerAngle:270,sectorWidth:15,side:"top"},{centerAngle:315,sectorWidth:75,side:"top-right"}],ellipse:[{centerAngle:0,sectorWidth:15,side:"right"},{centerAngle:45,sectorWidth:75,side:"bottom-right"},{centerAngle:90,sectorWidth:15,side:"bottom"},{centerAngle:135,sectorWidth:75,side:"bottom-left"},{centerAngle:180,sectorWidth:15,side:"left"},{centerAngle:225,sectorWidth:75,side:"top-left"},{centerAngle:270,sectorWidth:15,side:"top"},{centerAngle:315,sectorWidth:75,side:"top-right"}]},rf=e=>e.map((t,n)=>{let o=t.sectorWidth/2,i=t.centerAngle-o,r=t.centerAngle+o;return i=(i%360+360)%360,r=(r%360+360)%360,{start:i,end:r,side:t.side}}),sf=(e,t)=>{let[n,o]=e,i=n-.5,r=o-.5,s=Math.atan2(r,i);s<0&&(s+=2*Math.PI);let a=s*180/Math.PI,l=of[t],d=rf(l);for(let m of d)if(m.start<=m.end){if(a>=m.start&&a<=m.end)return m.side}else if(a>=m.start||a<=m.end)return m.side;let c=1/0,u=l[0].side;for(let m of l){let h=Math.abs(a-m.centerAngle);h>180&&(h=360-h),h<c&&(c=h,u=m.side)}return u},a6=(e,t)=>{let n=t.get(e.elementId);if(!n||n.isDeleted||!De(n))return null;let o=he(n,t),i=nf(n),r=sf(Je(e.fixedPoint),i),s=.01;if(n.type==="diamond"){let[a,l]=Bn(n),[d,c,u,m]=a,h,g;switch(r){case"left":{if(l.length>=3){let E=l[2][1];h=E[0]-s,g=E[1]}else{let f=tt(c[1],u[0]);h=f[0]-s,g=f[1]}break}case"right":{if(l.length>=1){let E=l[0][1];h=E[0]+s,g=E[1]}else{let f=tt(m[1],d[0]);h=f[0]+s,g=f[1]}break}case"top":{if(l.length>=4){let E=l[3][1];h=E[0],g=E[1]-s}else{let f=tt(u[1],m[0]);h=f[0],g=f[1]-s}break}case"bottom":{if(l.length>=2){let E=l[1][1];h=E[0],g=E[1]+s}else{let f=tt(d[1],c[0]);h=f[0],g=f[1]+s}break}case"top-right":{let f=tt(m[0],m[1]);h=f[0]+s*.707,g=f[1]-s*.707;break}case"bottom-right":{let f=tt(d[0],d[1]);h=f[0]+s*.707,g=f[1]+s*.707;break}case"bottom-left":{let f=tt(c[0],c[1]);h=f[0]-s*.707,g=f[1]+s*.707;break}case"top-left":{let f=tt(u[0],u[1]);h=f[0]-s*.707,g=f[1]-s*.707;break}default:return null}return ve(de(h,g),o,n.angle)}if(n.type==="ellipse"){let a=n.x+n.width/2,l=n.y+n.height/2,d=n.width/2,c=n.height/2,u,m;switch(r){case"top":{u=a,m=l-c-s;break}case"right":{u=a+d+s,m=l;break}case"bottom":{u=a,m=l+c+s;break}case"left":{u=a-d-s,m=l;break}case"top-right":{let h=-Math.PI/4,g=d*Math.cos(h),f=c*Math.sin(h);u=a+g+s*.707,m=l+f-s*.707;break}case"bottom-right":{let h=Math.PI/4,g=d*Math.cos(h),f=c*Math.sin(h);u=a+g+s*.707,m=l+f+s*.707;break}case"bottom-left":{let h=3*Math.PI/4,g=d*Math.cos(h),f=c*Math.sin(h);u=a+g-s*.707,m=l+f+s*.707;break}case"top-left":{let h=-3*Math.PI/4,g=d*Math.cos(h),f=c*Math.sin(h);u=a+g-s*.707,m=l+f-s*.707;break}default:return null}return ve(de(u,m),o,n.angle)}if(li(n)){let[a,l]=Cn(n),[d,c,u,m]=a,h,g;switch(r){case"top":{let f=tt(d[0],d[1]);h=f[0],g=f[1]-s;break}case"right":{let f=tt(c[0],c[1]);h=f[0]+s,g=f[1];break}case"bottom":{let f=tt(u[0],u[1]);h=f[0],g=f[1]+s;break}case"left":{let f=tt(m[0],m[1]);h=f[0]-s,g=f[1];break}case"top-left":{if(l.length>=1){let f=l[0],E=f[0],x=f[3],y=tt(E,x);h=y[0]-s*.707,g=y[1]-s*.707}else h=n.x-s,g=n.y-s;break}case"top-right":{if(l.length>=2){let f=l[1],E=f[0],x=f[3],y=tt(E,x);h=y[0]+s*.707,g=y[1]-s*.707}else h=n.x+n.width+s,g=n.y-s;break}case"bottom-right":{if(l.length>=3){let f=l[2],E=f[0],x=f[3],y=tt(E,x);h=y[0]+s*.707,g=y[1]+s*.707}else h=n.x+n.width+s,g=n.y+n.height+s;break}case"bottom-left":{if(l.length>=4){let f=l[3],E=f[0],x=f[3],y=tt(E,x);h=y[0]-s*.707,g=y[1]+s*.707}else h=n.x-s,g=n.y+n.height+s;break}default:return null}return ve(de(h,g),o,n.angle)}return null},tt=(e,t)=>de((e[0]+t[0])/2,(e[1]+t[1])/2),l6=(e,t,n,o,i)=>{ic(e,t,{elementId:t.id,fixedPoint:Je(o),mode:"orbit"},n,i)};S();import{arrayToMap as vc,findIndex as Ac,findLastIndex as Tc}from"@excalidraw/common";import{isFiniteNumber as Bf}from"@excalidraw/math";S();S();import{arrayToMap as Mf,isShallowEqual as Pf}from"@excalidraw/common";S();import{arrayToMap as Xt}from"@excalidraw/common";import{isPointWithinBounds as uf,pointFrom as pa,segmentsIntersectAt as pf}from"@excalidraw/math";S();import{arrayToMap as Sr}from"@excalidraw/common";import{validateOrderKey as af,generateNKeysBetween as lf}from"@excalidraw/fractional-indexing";var la=class extends Error{code="ELEMENT_HAS_INVALID_INDEX"},df=(e,{shouldThrow:t=!1,includeBoundTextValidation:n=!1,ignoreLogs:o,reconciliationContext:i})=>{let r=[],s=d=>`${d?.index}:${d?.id}:${d?.type}:${d?.isDeleted}:${d?.version}:${d?.versionNonce}`,a=n?Sr(e):null,l=e.map(d=>d.index);for(let[d,c]of l.entries()){let u=l[d-1],m=l[d+1];if(da(c,u,m)||r.push(`Fractional indices invariant has been compromised: "${s(e[d-1])}", "${s(e[d])}", "${s(e[d+1])}"`),n&&a&&Jt(e[d])&&rt(e[d])){let h=e[d],g=Vt(h),f=g?a.get(g):null;f&&rt(f)&&f.index<=h.index&&r.push(`Fractional indices invariant for bound elements has been compromised: "${s(f)}", "${s(h)}"`)}}if(r.length){let d=new la,c=[];if(i&&(c.push("Additional reconciliation context:"),c.push(i.localElements.map(u=>s(u))),c.push(i.remoteElements.map(u=>s(u)))),o||console.error(r.join(`
11
11
 
12
- `),d.stack,e.map(u=>s(u)),...c),t)throw d}},dc=e=>e.sort((t,n)=>lc(t)&&lc(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),uo=(e,t)=>{try{let n=Sr(e),o=cf(e,t),i=ua(e,o),r=e.map(s=>{let a=i.get(s);return a?{...s,index:a.index}:s});df(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of i)$e(s,n,{index:a})}catch{ca(e)}return e},ca=e=>{let t=Sr(e),n=uc(e),o=ua(e,n);for(let[i,{index:r}]of o)$e(i,t,{index:r});return e},cc=e=>{let t=Sr(e),n=uc(e),o=ua(e,n);for(let[i,{index:r}]of o)t.set(i.id,at(i,{index:r}));return t},cf=(e,t)=>{let n=[],o=0;for(;o<e.length;)if(t.has(e[o].id)){let i=[o-1,o];for(;++o<e.length&&t.has(e[o].id);)i.push(o);i.push(o),n.push(i)}else o++;return n},uc=e=>{let t=[],n,o,i=-1,r=0,s=d=>{let c=e[i]?e[i].index:void 0,u=e[d-1]?.index;return!c&&u||c&&u&&u>c?[u,d-1]:[c,i]},a=d=>{let c=e[r]?e[r].index:void 0;if(c&&d<r)return[c,r];let u=r;for(;++u<e.length;){let m=e[u]?.index;if(!c&&m||c&&m&&m>c)return[m,u]}return[void 0,u]},l=0;for(;l<e.length;){let d=e[l].index;if([n,i]=s(l),[o,r]=a(l),da(d,n,o))l++;else{let c=[i,l];for(;++l<e.length;){let u=e[l].index,[m,h]=s(l),[g,f]=a(l);if(da(u,m,g))break;[n,i]=[m,h],[o,r]=[g,f],c.push(l)}c.push(r),t.push(c)}}return t},da=(e,t,n)=>{if(!e)return!1;try{af(e)}catch{return!1}return t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e},ua=(e,t)=>{let n=new Map;for(let o of t){let i=o.shift(),r=o.pop(),s=lf(e[i]?.index,e[r]?.index,o.length);for(let a=0;a<o.length;a++){let l=e[o[a]];n.set(l,{index:s[a]})}}return n},lc=e=>!!e.index;var pc=(e,t,n)=>{let o=Xt(e);for(let i of t)if(i.frameId){let r=n.get(i.id),s=n.get(i.frameId),a=r&&o.get(r);a&&$e(a,o,{frameId:s??null})}};function Oo(e,t,n){let o=No(t,n),i=No(e,n);return o.some(s=>i.some(a=>pf(s,a)))}var mc=(e,t,n)=>vr(gc(e,t,n,!1)).filter(o=>!ce(o)&&!o.frameId||o.frameId===t.id),ma=(e,t,n)=>fa(be(e,n),be(t,n)),k6=(e,t)=>{let n=Xt(e);return e.filter(o=>Oo(o,t,n))},jn=(e,t,n)=>{let[o,i,r,s]=ae(t,n),[a,l,d,c]=dt(e);return o<=a&&i<=l&&r>=d&&s>=c},_n=(e,t,n)=>jn([e],t,n)||Oo(e,t,n)||ma(e,t,n),L6=(e,t,n)=>{let[o,i,r,s]=ae(t,n);return uf(pa(o,i),pa(e.x,e.y),pa(r,s))},D6=(e,t,n)=>{let o=Xt(e),i=t.flatMap(r=>lt(e,r));return i.length===0?!0:!!i.find(r=>jn([r],n,o)||Oo(r,n,o))},C6=(e,t,n)=>{let o=Xt(e),i=t.flatMap(r=>lt(e,r));return i.length===0?!0:i.find(r=>jn([r],n,o)||Oo(r,n,o))===void 0},B6=e=>{let t=new Map;for(let n of e){let o=ce(n)?n.id:n.frameId;o&&!t.has(o)&&t.set(o,Vn(e,o))}return t},Vn=(e,t)=>{let n=[];for(let o of e.values())o.frameId===t&&n.push(o);return n},ha=e=>e.filter(t=>ce(t)),G6=e=>{let t=Xt(ha(e));return e.filter(n=>t.has(n.id)||!n.frameId||!t.has(n.frameId))},N6=(e,t,n,o)=>{let i=Vn(e,t.id),r=new Set(i),s=new Set([...mc(e,t,o),...i.filter(h=>ma(h,t,o))]),a=i.filter(h=>!s.has(h)),l=new Set(Array.from(s).flatMap(h=>h.groupIds));for(let h of a)if(!Oo(h,t,o))h.groupIds.length===0&&r.delete(h);else if(h.groupIds.length>0)for(let g of h.groupIds)l.add(g);for(let h of a)if(h.groupIds.length>0){let g=!0;for(let f of h.groupIds)l.has(f)&&(g=!1);g&&r.delete(h)}let d=Array.from(s).filter(h=>h.groupIds.length===0);for(let h of d)r.add(h);let c=Array.from(s).filter(h=>h.groupIds.length>0),u=Un(c),m=Ec(u,n);for(let[h,g]of Object.entries(m))if(g){let f=lt(e,h);if(jn(f,t,o))for(let E of f)r.add(E)}return[...r].filter(h=>!(ue(h)&&h.containerId))},O6=(e,t,n)=>mf(vr(e,mc(e,t,n)),t,n),mf=(e,t,n)=>{let o=[],i=new Map;for(let r of e){let s=!1;if(r.groupIds.length>0){if(r.groupIds.some(a=>i.get(a)))s=!0;else{let a=new Set(r.groupIds.flatMap(l=>lt(n,l)));s=!jn(Array.from(a),t,n)}r.groupIds.forEach(a=>{i.set(a,s)})}s||o.push(r)}return o},Wn=(e,t)=>e.frameId&&t.get(e.frameId)||null,R6=(e,t)=>{let n=new Set,o=Xt(e);e=vr(e);for(let s of e)ce(s)&&s.id!==t.id&&n.add(s.id);let i=new Set,r=[];for(let s of e)if(!(ce(s)||s.frameId&&n.has(s.frameId)))if(s.groupIds.length){let a=s.groupIds.at(-1);if(!i.has(a)){i.add(a);let l=lt(e,a);if(l.some(d=>_n(d,t,o)))for(let d of l)r.push(d)}}else _n(s,t,o)&&r.push(s);return r},hf=e=>{let t;for(let n of e){if(ce(n)||!n.frameId)return null;if(t===void 0)t=n.frameId;else if(t!==n.frameId)return null}return t??null},ff=(e,t)=>{for(let n=e.length-1;n>=0;n--){let o=e[n];if(o.id===t)return n;if(o.frameId===t)return n+1}return null},gf=(e,t,n)=>{let o=Xt(e),i=hf(t),r=new Set,s=new Set;for(let c of t)ce(c)&&c.id!==n.id&&s.add(c.id);for(let c of vr(e,t)){if(ce(c)||c.frameId&&s.has(c.frameId))continue;r.add(c);let u=pe(c,o);u&&!r.has(u)&&r.add(u)}for(let c of r)c.frameId!==n.id&&$e(c,o,{frameId:n.id});if(!r.size||i===n.id)return e;let a=Array.from(e.values()).filter(c=>!r.has(c)),l=ff(a,n.id);if(l===null)return e;let d=[...a.slice(0,l),...r,...a.slice(l)];return uo(d,Xt([...r])),Array.isArray(e)?d:new Map(d.map(c=>[c.id,c]))},hc=(e,t)=>{let n=new Map,o=new Map;for(let i of e)if(i.frameId){n.set(i.id,i);let r=o.get(i.frameId)||[];r.push(i);let s=pe(i,t);s&&(n.set(s.id,s),r.push(s)),o.set(i.frameId,r)}for(let[,i]of n)$e(i,t,{frameId:null})},Ef=(e,t)=>{let n=Vn(e,t.id);return hc(n,Xt(e)),e},F6=(e,t,n)=>gf(Ef(e,n),t,n).slice(),H6=(e,t,n)=>{let o=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,elements:e}),i=new Set(o);if(t.editingGroupId)for(let a of o)a.groupIds.length===0?i.add(a):a.groupIds.flatMap(l=>lt(e,l)).forEach(l=>i.add(l));let r=new Set,s=Xt(e);return i.forEach(a=>{a.frameId&&!ce(a)&&!fc(a,s,t)&&r.add(a)}),r.size>0&&hc(r,s),e},vr=(e,t)=>{let n=new Set,o=t||e;for(let s of o.values()){let a=s.groupIds[s.groupIds.length-1];a&&n.add(a)}let i=new Set;for(let s of n)lt(e,s).some(a=>ce(a))&&i.add(s);let r=[];for(let s of o.values())i.has(s.groupIds[s.groupIds.length-1])||r.push(s);return r},xf=(e,t,n)=>{let o=ue(e)&&et(e,t)||e;return o.frameId&&n.selectedElementIds[o.id]&&n.selectedElementIds[o.frameId]?Wn(o,t):n.selectedElementIds[o.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:Wn(o,t)},fc=(e,t,n,o)=>{let i=o?.targetFrame??xf(e,t,n);if(!i)return!1;let r=ue(e)&&et(e,t)||e,s=l=>{o?.checkedGroups&&r.groupIds.forEach(d=>{o.checkedGroups?.set(d,l)})};if(!n.selectedElementIds[r.id]||!n.selectedElementsAreBeingDragged||n.selectedElementIds[r.id]&&n.selectedElementIds[i.id])return!0;if(r.groupIds.length===0)return _n(r,i,t);for(let l of r.groupIds)if(o?.checkedGroups?.has(l))return o.checkedGroups.get(l);let a=new Set(r.groupIds.filter(l=>o?.checkedGroups?!o.checkedGroups.has(l):!0).flatMap(l=>lt(t,l)));if(n.editingGroupId&&n.selectedElementsAreBeingDragged){let l=new Set(dn(t,n));if(n.frameToHighlight!==null)return!0;l.forEach(c=>{a.delete(c)})}for(let l of a)if(ce(l))return s(!1),!1;for(let l of a)if(_n(l,i,t))return s(!0),!0;return!1},z6=(e,t,n,o,i)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let r=Oo(e,t,o)||ma(e,t,o);if(r){for(let s of e.groupIds)i?.set(s,!0);return!0}if(!r&&e.groupIds.length>0&&!jn([e],t,o)){let s=!1;if(n.selectedElementsAreBeingDragged)s=fc(e,o,n,{targetFrame:t,checkedGroups:i});else{s=e.frameId===t.id;for(let a of e.groupIds)i?.set(a,s)}for(let a of e.groupIds)i?.set(a,s);return s}return!1},yf="Frame",bf="AI Frame",wf=e=>Qi(e)?yf:bf,_6=e=>e.name===null?wf(e):e.name,W6=(e,t,n)=>e.filter(o=>(!o.frameId||o.frameId===t.id)&&kt(be(o,n),be(t,n))),j6=e=>{let t=Xt(e);return e.length>1&&e.some(n=>n.frameId&&t.has(n.frameId))};var If=e=>e.locked||Ne(e),Sf=(e,t)=>e.filter(n=>!(n.frameId&&t.has(n.frameId))),vf=e=>{let t=new Set;return e.forEach(n=>{ce(n)&&t.add(n.id)}),Sf(e,t)},gc=(e,t,n,o=!0,i="contain")=>{let[r,s,a,l]=ae(t,n),d=Math.min(r,a),c=Math.min(s,l),u=Math.max(r,a),m=Math.max(s,l);return yc({elements:e,bounds:[d,c,u,m],elementsMap:n,type:i,shouldIgnoreElementFromSelection:If,excludeElementsInFrames:o})},e4=(e,t,n,o)=>{let i=new Set(t.map(r=>r.id));return e.filter(r=>{let s=bc(r,n.width,n.height,n,o);return!i.has(r.id)&&s})},t4=function(){let e=null,t=null,n=null,o=(i,r)=>(n!=null&&i===e&&r.selectedElementIds===t||(n=i.some(s=>r.selectedElementIds[s.id]),e=i,t=r.selectedElementIds),n);return o.clearCache=()=>{e=null,t=null,n=null},o}(),dn=(e,t,n)=>{let o=new Set,i=[];for(let r of e.values()){if(t.selectedElementIds[r.id]){rt(r)?(i.push(r),o.add(r.id)):console.error("[NONDELETED][INVARIANT] getSelectedElements skipping deleted selected element which should not be in the selection");continue}if(n?.includeBoundTextElement&&Ne(r)&&rt(r)&&t.selectedElementIds[r?.containerId]){i.push(r),o.add(r.id);continue}}if(n?.includeElementsInFrames){let r=[];return i.forEach(s=>{ce(s)&&Vn(e,s.id).forEach(a=>!o.has(a.id)&&r.push(a)),r.push(s)}),r}return i},n4=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement&&t.activeTool.type!=="autoshape"?[t.newElement]:dn(e,t,{includeBoundTextElement:!0}),ga=(e,t)=>Pf(t.selectedElementIds,e)?t.selectedElementIds:e,Af=(e,t)=>{let n=e.filter(le);if(n.length===1){let o=n[0],i=o.boundElements?.map(s=>s.id)??[];if(e.every(s=>s.id===o.id||i.includes(s.id)))return new W(o,Mf(t))}return null},o4=(e,t,n)=>({selectedLinearElement:Af(e,t),...xc({editingGroupId:n.editingGroupId,selectedElementIds:vf(e).reduce((o,i)=>(Ne(i)||(o[i.id]=!0),o),{})},t,n,null)}),i4=(e,t)=>t.editingTextElement||e.length===1&&ue(e[0])&&e[0]||null;var Tf=(e,t,n)=>{let o=n.reduce((i,r)=>(r.groupIds.includes(e)&&(i[r.id]=!0),i),{});return Object.keys(o).length<2?t.selectedGroupIds[e]||t.editingGroupId===e?{selectedElementIds:t.selectedElementIds,selectedGroupIds:{...t.selectedGroupIds,[e]:!1},editingGroupId:null}:t:{editingGroupId:t.editingGroupId,selectedGroupIds:{...t.selectedGroupIds,[e]:!0},selectedElementIds:{...t.selectedElementIds,...o}}},xc=function(){let e=null,t=null,n=null,o=(r,s,a,l)=>{if(n!==void 0&&s===t&&r===e&&a.editingGroupId===n?.editingGroupId)return n;let d={};for(let m of r){let h=m.groupIds;if(a.editingGroupId){let g=h.indexOf(a.editingGroupId);g>-1&&(h=h.slice(0,g))}if(h.length>0){let g=h[h.length-1];d[g]=!0}}let c={},u=s.reduce((m,h)=>{if(h.isDeleted)return m;let g=h.groupIds.find(f=>d[f]);return g&&(m[h.id]=!0,Array.isArray(c[g])?c[g].push(h.id):c[g]=[h.id]),m},{});for(let m of Object.keys(c))c[m].length<2&&d[m]&&(d[m]=!1);return t=s,e=r,n={editingGroupId:a.editingGroupId,selectedGroupIds:d,selectedElementIds:ga({...a.selectedElementIds,...u},l)},n},i=(r,s,a,l)=>{let d=l?l.scene.getSelectedElements({selectedElementIds:r.selectedElementIds,elements:s}):dn(s,r);return d.length?o(d,s,r,a):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:ga(r.selectedElementIds,a)}};return i.clearCache=()=>{t=null,e=null,n=null},i}(),kf=(e,t)=>Ea(e,t)!=null,Ea=(e,t)=>t.groupIds.filter(n=>n!==e.editingGroupId).find(n=>e.selectedGroupIds[n]),Lf=e=>Object.entries(e.selectedGroupIds).filter(([t,n])=>n).map(([t,n])=>t),Ec=(e,t)=>{let n={...t,selectedGroupIds:{}};for(let o of e){let i=o.groupIds;if(t.editingGroupId){let r=i.indexOf(t.editingGroupId);r>-1&&(i=i.slice(0,r))}if(i.length>0){let r=i[i.length-1];n={...n,...Tf(r,n,e)}}}return n.selectedGroupIds},c4=(e,t)=>({...e,editingGroupId:t.groupIds.length?t.groupIds[0]:null,selectedGroupIds:{},selectedElementIds:{[t.id]:!0}}),Df=(e,t)=>e.groupIds.includes(t),lt=(e,t)=>{let n=[];for(let o of e.values())Df(o,t)&&n.push(o);return n},Cf=(e,t)=>e.groupIds.find(n=>t[n]),u4=(e,t,n)=>{let o=[...e],i=n?o.indexOf(n):-1,r=i>-1?i:o.length;return o.splice(r,0,t),o},p4=(e,t)=>e.filter(n=>!t[n]),Ar=(e,t)=>{let n=new Map;return e.forEach(o=>{let i=o.groupIds.length===0?o.id:o.groupIds[o.groupIds.length-1],r=n.get(i)||[],s=pe(o,t);s&&r.push(s),n.set(i,[...r,o])}),Array.from(n.values())},wc=e=>{let t=new Set;for(let[,n]of e)if(!n.isDeleted)for(let o of n.groupIds??[])t.add(o);return t},Mc=e=>{let t=e.flatMap(i=>i.groupIds),n=new Map,o=0;for(let i of t)n.set(i,(n.get(i)??0)+1),n.get(i)>o&&(o=n.get(i));return o===e.length},Pc=e=>e.groupIds.length>0,Ic=(e,t,n)=>{let o=[...e],i=t?e.indexOf(t):-1,r=i>-1?i:e.length;for(let s=0;s<r;s++)o[s]=n(o[s]);return o},Tr=(e,t,n)=>{let o=new Map,r=Lf(n).length===1&&e.every(s=>kf(n,s));return e.forEach(s=>{if(Ne(s))return;let a,l=Cf(s,n.selectedGroupIds);if(!l)a=`${s.id}_element`;else{let u=r?s.groupIds.indexOf(l)-1:s.groupIds.indexOf(l);a=u<0?`${s.id}_element`:`${s.groupIds[u]}_group`}let d=o.get(a)??[],c=pe(s,t);o.set(a,[...d,s,...c?[c]:[]])}),[...o.values()]};var xa=(e,t)=>e.frameId===t||e.id===t,kc=(e,t,n)=>{let o=[],i=[],r=null,s=-1,a=vc(n||dn(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0}));for(;++s<e.length;){let l=e[s];a.get(l.id)?(i.length&&(o=o.concat(i),i=[]),o.push(s),r=s+1):l.isDeleted&&r===s?(r=s+1,i.push(s)):i=[]}return o},Gf=e=>{let t=0;return e.reduce((n,o,i)=>(i>0&&e[i-1]!==o-1&&(t=++t),(n[t]||(n[t]=[])).push(o),n),[])},Sc=(e,t,n,o)=>{if("containerId"in e&&e.containerId){let i=o.getElement(e.containerId);if(i)return n==="left"?Math.min(t.indexOf(i),t.indexOf(e)):Math.max(t.indexOf(i),t.indexOf(e))}else{let i=e.boundElements?.find(r=>r.type!=="arrow")?.id;if(i){let r=o.getElement(i);if(r)return n==="left"?Math.min(t.indexOf(r),t.indexOf(e)):Math.max(t.indexOf(r),t.indexOf(e))}}},Nf=(e,t)=>{let n=-1,o=-1;return e.forEach((i,r)=>{xa(i,t)&&(n===-1&&(n=r),o=r)}),n===-1?[]:e.slice(n,o+1)},yi=(e,t,n,o,i,r)=>{let s=r||xn(e,Un(n),o);if(!s)return n;let a=pe(s,o),l=ue(s)?et(s,o):null,d=[s.id,a?.id,l?.id].filter(m=>!!m),c=n.findIndex(m=>d.includes(m.id)),u=n.findIndex(m=>m.id===t.id);if(u!==-1&&c!==-1&&u<c){let m=Array.from(n),h=m.splice(u,1)[0];m.splice(c,0,h),i.replaceAllElements(m)}return n},Of=(e,t,n,o,i,r)=>{let s=t[n],a=m=>m.isDeleted?!1:i?m.frameId===i:e.editingGroupId?m.groupIds.includes(e.editingGroupId):!0,l=o==="left"?Tc(t,m=>a(m),Math.max(0,n-1)):Ac(t,m=>a(m),n+1),d=t[l];if(!d)return-1;if(e.editingGroupId){if(s?.groupIds.join("")===d?.groupIds.join(""))return Sc(d,t,o,r)??l;if(!d?.groupIds.includes(e.editingGroupId))return-1}if(!i&&(d.frameId||ce(d))){let m=Nf(t,d.frameId||d.id);return o==="left"?t.indexOf(m[0]):t.indexOf(m[m.length-1])}if(!d.groupIds.length)return Sc(d,t,o,r)??l;let c=e.editingGroupId?d.groupIds[d.groupIds.indexOf(e.editingGroupId)-1]:d.groupIds[d.groupIds.length-1],u=lt(t,c);return u.length?o==="left"?t.indexOf(u[0]):t.indexOf(u[u.length-1]):l},Lc=(e,t)=>t.reduce((n,o)=>{let i=e[o];return n.set(i.id,i),n},new Map),Dc=(e,t)=>{if(e.length!==t.length)return console.error("z-index reordering failed: resulting array have different lengths"),!1;let n=new Map;for(let o of e)n.set(o.id,(n.get(o.id)||0)+1);for(let o of t){let i=n.get(o.id);if(!i)return console.error("z-index reordering failed: element id mismatch / duplicate ids"),!1;n.set(o.id,i-1)}return!0},Cc=(e,t,n,o)=>{let i=e,r=kc(e,t),s=Lc(e,r),a=Gf(r);n==="right"&&(a=a.reverse());let l=new Set(r.filter(d=>ce(e[d])).map(d=>e[d].id));return a.forEach((d,c)=>{let u=d[0],m=d[d.length-1],h=n==="left"?u:m,g=d.some(M=>{let w=e[M];return w.frameId&&l.has(w.frameId)})?null:e[h]?.frameId,f=Of(t,e,h,n,g,o);if(f===-1||h===f)return;let E=n==="left"?e.slice(0,f):e.slice(0,u),x=e.slice(u,m+1),y=n==="left"?e.slice(f,u):e.slice(m+1,f+1),b=n==="left"?e.slice(m+1):e.slice(f+1);e=n==="left"?[...E,...x,...y,...b]:[...E,...y,...x,...b]}),Dc(i,e)?(uo(e,s),e):i},Bc=(e,t,n,o,i)=>{let r=kc(e,t,i);if(r.length===0)return e;let s=Lc(e,r),a=[],l,d;if(n==="left"){if(o)l=Ac(e,f=>xa(f,o));else if(t.editingGroupId){let f=lt(e,t.editingGroupId);if(!f.length)return e;l=e.indexOf(f[0])}else l=0;d=r[r.length-1]}else{if(o)d=Tc(e,f=>xa(f,o));else if(t.editingGroupId){let f=lt(e,t.editingGroupId);if(!f.length)return e;d=e.indexOf(f[f.length-1])}else d=e.length-1;l=r[0]}l===-1&&(l=0);let c=f=>Bf(f)&&f>=0;if(!c(l)||!c(d)||l>d||r.some(f=>f<l||f>d))return e;for(let f=l;f<d+1;f++)r.includes(f)||a.push(e[f]);let u=Array.from(s.values()),m=e.slice(0,l),h=e.slice(d+1),g=n==="left"?[...m,...u,...a,...h]:[...m,...a,...u,...h];return Dc(e,g)?(uo(g,s),g):e};function Gc(e,t,n,o){let i=vc(dn(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0})),r={regularElements:[],frameChildren:new Map},s=new Set;for(let d of e)i.has(d.id)&&ce(d)&&s.add(d.id);for(let d of e)if(i.has(d.id))if(ce(d)||d.frameId&&s.has(d.frameId))r.regularElements.push(d);else if(!d.frameId)r.regularElements.push(d);else{let c=r.frameChildren.get(d.frameId)||[];c.push(d),r.frameChildren.set(d.frameId,c)}let a=e,l=Array.from(r.frameChildren.entries());for(let[d,c]of l)a=o(a,t,n,d,c);return o(a,t,n,null,r.regularElements)}var I4=(e,t,n)=>Cc(e,t,"left",n),S4=(e,t,n)=>Cc(e,t,"right",n),v4=(e,t)=>Gc(e,t,"left",Bc),A4=(e,t)=>Gc(e,t,"right",Bc);var ya=({points:e})=>{let t=e[0][0],n=e[0][1];return{points:e.map(o=>U(o[0]-t,o[1]-n)),offsetX:t,offsetY:n}},W=class e{elementId;selectedPointsIndices;initialState;isDragging;lastUncommittedPoint;lastCommittedPoint;pointerOffset;hoverPointIndex;segmentMidPointHoveredCoords;hoveredFocusPointBinding;draggedFocusPointBinding;elbowed;customLineAngle;isEditing;pointerDownState;constructor(t,n,o=!1){this.elementId=t.id,Oc(t.points[0],U(0,0))||(console.error("Linear element is not normalized",Error().stack),$e(t,n,e.getNormalizeElementPointsAndCoords(t))),this.selectedPointsIndices=null,this.lastUncommittedPoint=null,this.lastCommittedPoint=null,this.isDragging=!1,this.pointerOffset={x:0,y:0},this.initialState={prevSelectedPointsIndices:null,lastClickedPoint:-1,origin:null,segmentMidpoint:{value:null,index:null,added:!1},arrowStartIsInside:!1,arrowOtherEndpointInitialBinding:null,altFocusPoint:null},this.hoverPointIndex=-1,this.segmentMidPointHoveredCoords=null,this.hoveredFocusPointBinding=null,this.draggedFocusPointBinding=null,this.elbowed=ee(t)&&t.elbowed,this.customLineAngle=null,this.isEditing=o}static POINT_HANDLE_SIZE=10;static getElement(t,n){let o=n.get(t);return o||null}static handleBoxSelection(t,n,o,i){if(!n.selectedLinearElement?.isEditing||!n.selectionElement)return!1;let{selectedLinearElement:r}=n,{selectedPointsIndices:s,elementId:a}=r,l=e.getElement(a,i);if(!l)return!1;let[d,c,u,m]=ae(n.selectionElement,i),g=e.getPointsGlobalCoordinates(l,i).reduce((f,E,x)=>((E[0]>=d&&E[0]<=u&&E[1]>=c&&E[1]<=m||t.shiftKey&&s?.includes(x))&&f.push(x),f),[]).filter(f=>!(ee(l)&&f!==0&&f!==l.points.length-1));o({selectedLinearElement:{...r,selectedPointsIndices:g.length?g:null}})}static handlePointerMove(t,n,o,i,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elementId:l}=r,d=e.getElement(l,s);wt(d,"Element being dragged must exist in the scene"),wt(d.points.length>1,"Element must have at least 2 points");let c=d.points.length-1,u=d.points[c],m=d.points[c-1],h=r.customLineAngle??Hc(m,d.points[c]),g=0,f=0;if(mo(t)){let[v,A]=e._getShiftLockedDelta(d,s,m,U(o,i),t[po.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),h),k=U(v+m[0],A+m[1]);g=k[0]-u[0],f=k[1]-u[1]}else{let v=e.createPointAt(d,s,o-r.pointerOffset.x,i-r.pointerOffset.y,t[po.CTRL_OR_CMD]?null:n.getEffectiveGridSize());g=v[0]-u[0],f=v[1]-u[1]}let E=null,{positions:x,updates:y}=Fc([c],g,f,o,i,s,d,a,n,mo(t),t.altKey,r),b=mo(t);if(e.movePoints(d,n.scene,x,{startBinding:y?.startBinding,endBinding:y?.endBinding,moveMidPointsWithElement:y?.moveMidPointsWithElement},{isBindingEnabled:n.state.isBindingEnabled,isMidpointSnappingEnabled:n.state.isMidpointSnappingEnabled&&!b&&!n.state.gridModeEnabled}),Ke(d,!1)&&an(n.state)&&(E=y?.suggestedBinding??null),Ke(d)&&yi(e.getPointGlobalCoordinates(d,d.points[d.points.length-1],s),d,a,s,n.scene),n.state.selectedLinearElement?.customLineAngle===h&&r.initialState.altFocusPoint&&(!E||_f(n.state.suggestedBinding??[],E)))return null;let M=Ke(d)&&d.startBinding&&s.get(d.startBinding.elementId);return{selectedLinearElement:{...r,customLineAngle:h,initialState:{...r.initialState,altFocusPoint:!r.initialState.altFocusPoint&&M&&y?.suggestedBinding?.element.id!==M.id?So(d,U(d.x,d.y),M,"start",s,n.state.zoom,n.state.isMidpointSnappingEnabled&&!b&&!n.state.gridModeEnabled):r.initialState.altFocusPoint}},suggestedBinding:E}}static handlePointDragging(t,n,o,i,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elbowed:l,elementId:d,initialState:c}=r,u=Array.from(r.selectedPointsIndices??[]),{lastClickedPoint:m}=c,h=e.getElement(d,s);wt(h,"Element being dragged must exist in the scene"),wt(h.points.length>1,"Element must have at least 2 points"),wt(u,"There must be selected points in order to drag them"),l&&u.some((L,G)=>L>0&&L!==h.points.length-1?(u[G]=h.points.length-1,m=h.points.length-1,!0):!1),(m<0||!u.includes(m)||!h.points[m])&&(console.error(`There must be a valid lastClickedPoint in order to drag it. selectedPointsIndices(${JSON.stringify(u)}) points(0..${h.points.length-1}) lastClickedPoint(${m}) isElbowArrow: ${l}`),m=h.points.length-1);let g=h.points[m],f=h.points[m===0?1:m-1],E=u.length===1,x=r.customLineAngle??Hc(f,h.points[m]),y=u.includes(0),b=u.includes(h.points.length-1),M=0,w=0;if(mo(t)&&E){let[L,G]=e._getShiftLockedDelta(h,s,f,U(o,i),t[po.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),x),_=U(L+f[0],G+f[1]);M=_[0]-g[0],w=_[1]-g[1]}else{let L=e.createPointAt(h,s,o-r.pointerOffset.x,i-r.pointerOffset.y,t[po.CTRL_OR_CMD]?null:n.getEffectiveGridSize());M=L[0]-g[0],w=L[1]-g[1]}let v=null,{positions:A,updates:k}=Fc(u,M,w,o,i,s,h,a,n,mo(t)&&E,t.altKey,r),T=mo(t)&&E;e.movePoints(h,n.scene,A,{startBinding:k?.startBinding,endBinding:k?.endBinding,moveMidPointsWithElement:k?.moveMidPointsWithElement},{isBindingEnabled:n.state.isBindingEnabled,isMidpointSnappingEnabled:n.state.isMidpointSnappingEnabled&&!T&&!n.state.gridModeEnabled}),Ke(h,!1)&&an(n.state)&&(y||b)&&(v=k?.suggestedBinding??null),Ke(h)&&y!==b&&yi(e.getPointGlobalCoordinates(h,y?h.points[0]:h.points[h.points.length-1],s),h,a,s,n.scene),pe(h,s)&&lo(h,n.scene,!1);let C=l?b?[h.points.length-1]:[0]:u,O=l?C[0]:m,N=!y&&!b?e.getPointGlobalCoordinates(h,g,s):null,j=O,V=Ke(h)&&h.startBinding&&s.get(h.startBinding.elementId),D=Ke(h)&&h.endBinding&&s.get(h.endBinding.elementId),B=b&&V&&k?.suggestedBinding?.element.id!==V.id?V:y&&D&&k?.suggestedBinding?.element.id!==D.id?D:null;return{selectedLinearElement:{...r,selectedPointsIndices:C,initialState:{...r.initialState,lastClickedPoint:O,altFocusPoint:!r.initialState.altFocusPoint&&Ke(h)&&B?So(h,U(h.x,h.y),B,"start",s,n.state.zoom,n.state.isMidpointSnappingEnabled&&!T&&!n.state.gridModeEnabled):r.initialState.altFocusPoint},segmentMidPointHoveredCoords:N,hoverPointIndex:j,isDragging:!0,customLineAngle:x},suggestedBinding:v}}static handlePointerUp(t,n,o,i){let r=i.getNonDeletedElementsMap(),{elementId:s,selectedPointsIndices:a,isDragging:l,initialState:d}=n,c=e.getElement(s,r);if(!c)return n;if(l&&a)for(let u of a)(u===0||u===c.points.length-1)&&vt(c.points,o.zoom.value)&&(Ye(c)&&i.mutateElement(c,{...zc(c,!0)},{informMutation:!1,isDragging:!1}),e.movePoints(c,i,new Map([[u,{point:u===0?c.points[c.points.length-1]:c.points[0]}]])));return{...n,segmentMidPointHoveredCoords:null,hoverPointIndex:-1,selectedPointsIndices:l||t.shiftKey?!l&&t.shiftKey&&d.prevSelectedPointsIndices?.includes(d.lastClickedPoint)?a&&a.filter(u=>u!==d.lastClickedPoint):a:a?.includes(d.lastClickedPoint)?[d.lastClickedPoint]:a,isDragging:!1,customLineAngle:null,initialState:{...n.initialState,origin:null,arrowStartIsInside:!1,arrowOtherEndpointInitialBinding:null}}}static getEditorMidPoints=(t,n,o)=>{let i=pe(t,n);if(!ee(t)&&!o.selectedLinearElement?.isEditing&&t.points.length>2&&!i)return[];let r=e.getPointsGlobalCoordinates(t,n),s=0,a=[];for(;s<r.length-1;){if(e.isSegmentTooShort(t,t.points[s],t.points[s+1],s,o.zoom,n)){a.push(null),s++;continue}let l=e.getSegmentMidPoint(t,s+1,n);a.push(l),s++}return a};static getSegmentMidpointHitCoords=(t,n,o,i)=>{let{elementId:r}=t,s=e.getElement(r,i);if(!s)return null;let a=e.getPointIndexUnderCursor(s,i,o.zoom,n.x,n.y);if(!ee(s)&&a>=0||e.getPointsGlobalCoordinates(s,i).length>=3&&!o.selectedLinearElement?.isEditing&&!ee(s))return null;let d=(e.POINT_HANDLE_SIZE+1)/o.zoom.value,c=t.segmentMidPointHoveredCoords;if(c&&ho(U(c[0],c[1]),U(n.x,n.y))<=d)return c;let u=0,m=e.getEditorMidPoints(s,i,o);for(;u<m.length;){if(m[u]!==null&&ho(m[u],U(n.x,n.y))<=d)return m[u];u++}return null};static isSegmentTooShort(t,n,o,i,r,s){if(ee(t))return i>=0&&i<t.points.length?ho(n,o)*r.value<e.POINT_HANDLE_SIZE/2:!1;let a=ho(n,o);if(t.points.length>2&&t.roundness){let[l,d]=so(t,s);wt(l.length===0&&d.length>0,"Only linears built out of curves are supported"),wt(l.length+d.length>=i,"Invalid segment index while calculating mid point"),a=Ff(d[i])}return a*r.value<e.POINT_HANDLE_SIZE*4}static getSegmentMidPoint(t,n,o){if(ee(t)){wt(t.points.length>=n,"Invalid segment index while calculating elbow arrow mid point");let s=Nc(t.points[n-1],t.points[n]);return U(t.x+s[0],t.y+s[1])}let[i,r]=so(t,o);if(wt(i.length===0&&r.length>0||i.length>0&&r.length===0,"Only linears built out of either segments or curves are supported"),wt(i.length+r.length>=n,"Invalid segment index while calculating mid point"),i.length){let s=i[n-1];return Nc(s[0],s[1])}if(r.length){let s=r[n-1];return Hf(s,.5)}wt(!1,"Invalid segment type while calculating mid point")}static getSegmentMidPointIndex(t,n,o,i){let r=e.getElement(t.elementId,i);if(!r)return-1;let s=e.getEditorMidPoints(r,i,n),a=0;for(;a<s.length;){if(e.arePointsEqual(o,s[a]))return a+1;a++}return-1}static handlePointerDown(t,n,o,i,r,s){let a=n.state,l=s.getNonDeletedElementsMap(),d={didAddPoint:!1,hitElement:null,linearElementEditor:null};if(!r)return d;let{elementId:c}=r,u=e.getElement(c,l);if(!u)return d;let m=e.getSegmentMidpointHitCoords(r,i,a,l),h=U(i.x,i.y),g=null;if(m)g=e.getSegmentMidPointIndex(r,a,m,l);else if(t.altKey&&a.selectedLinearElement?.isEditing)return r.lastUncommittedPoint==null&&(s.mutateElement(u,{points:[...u.points,e.createPointAt(u,l,i.x,i.y,t[po.CTRL_OR_CMD]?null:n.getEffectiveGridSize())]}),d.didAddPoint=!0),o.scheduleCapture(),d.linearElementEditor={...r,initialState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:-1,origin:h,segmentMidpoint:{value:m,index:g,added:!1},arrowStartIsInside:!!n.state.newElement&&(n.state.bindMode==="inside"||n.state.bindMode==="skip"),altFocusPoint:null,arrowOtherEndpointInitialBinding:u.startBinding},selectedPointsIndices:[u.points.length-1],lastUncommittedPoint:null},d.didAddPoint=!0,d;let f=e.getPointIndexUnderCursor(u,l,a.zoom,i.x,i.y);(f>=0||m)&&(d.hitElement=u);let[E,x,y,b]=ae(u,l),M=(E+y)/2,w=(x+b)/2,v=f>-1&&ct(U(u.x+u.points[f][0],u.y+u.points[f][1]),U(M,w),u.angle),A=f>-1||t.shiftKey?t.shiftKey||r.selectedPointsIndices?.includes(f)?Wf([...r.selectedPointsIndices||[],f]):[f]:null;return d.linearElementEditor={...r,initialState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:f,origin:h,segmentMidpoint:{value:m,index:g,added:!1},arrowStartIsInside:!!n.state.newElement&&(n.state.bindMode==="inside"||n.state.bindMode==="skip"),altFocusPoint:null,arrowOtherEndpointInitialBinding:A?.includes(0)?u.endBinding:u.startBinding},selectedPointsIndices:A,pointerOffset:v?{x:i.x-v[0],y:i.y-v[1]}:{x:0,y:0}},d}static arePointsEqual(t,n){return!t&&!n?!0:!t||!n?!1:Oc(t,n)}static handlePointerMoveInEditMode(t,n,o,i){let r=i.state;if(!r.selectedLinearElement?.isEditing)return null;let{elementId:s,lastUncommittedPoint:a}=r.selectedLinearElement,l=i.scene.getNonDeletedElementsMap(),d=e.getElement(s,l);if(!d)return r.selectedLinearElement;let{points:c}=d,u=c[c.length-1];if(!t.altKey)return u===a&&e.deletePoints(d,i,[c.length-1]),r.selectedLinearElement?.lastUncommittedPoint?{...r.selectedLinearElement,lastUncommittedPoint:null}:r.selectedLinearElement;let m;if(mo(t)&&c.length>=2){let h=c[c.length-2],[g,f]=e._getShiftLockedDelta(d,l,h,U(n,o),t[po.CTRL_OR_CMD]?null:i.getEffectiveGridSize());m=U(g+h[0],f+h[1])}else m=e.createPointAt(d,l,n-r.selectedLinearElement.pointerOffset.x,o-r.selectedLinearElement.pointerOffset.y,t[po.CTRL_OR_CMD]||ee(d)?null:i.getEffectiveGridSize());return u===a?e.movePoints(d,i.scene,new Map([[d.points.length-1,{point:m}]])):e.addPoints(d,i.scene,[m]),{...r.selectedLinearElement,lastUncommittedPoint:d.points[d.points.length-1]}}static getPointGlobalCoordinates(t,n,o){let[i,r,s,a]=ae(t,o),l=(i+s)/2,d=(r+a)/2,{x:c,y:u}=t;return ct(U(c+n[0],u+n[1]),U(l,d),t.angle)}static getPointsGlobalCoordinates(t,n){let[o,i,r,s]=ae(t,n),a=(o+r)/2,l=(i+s)/2;return t.points.map(d=>{let{x:c,y:u}=t;return ct(U(c+d[0],u+d[1]),U(a,l),t.angle)})}static getPointAtIndexGlobalCoordinates(t,n,o){let i=n<0?t.points.length+n:n,[,,,,r,s]=ae(t,o),a=U(r,s),l=t.points[i],{x:d,y:c}=t;return l?ct(U(d+l[0],c+l[1]),a,t.angle):ct(U(d,c),a,t.angle)}static pointFromAbsoluteCoords(t,n,o){if(ee(t))return U(n[0]-t.x,n[1]-t.y);let[i,r,s,a]=ae(t,o),l=(i+s)/2,d=(r+a)/2,[c,u]=ct(U(n[0],n[1]),U(l,d),-t.angle);return U(c-t.x,u-t.y)}static getPointIndexUnderCursor(t,n,o,i,r){let s=e.getPointsGlobalCoordinates(t,n),a=s.length;for(;--a>-1;){let l=s[a];if(ho(U(i,r),U(l[0],l[1]))*o.value<e.POINT_HANDLE_SIZE+1)return a}return-1}static createPointAt(t,n,o,i,r){let s=Rc(o,i,r),[a,l,d,c]=ae(t,n),u=(a+d)/2,m=(l+c)/2,[h,g]=ct(U(s[0],s[1]),U(u,m),-t.angle);return U(h-t.x,g-t.y)}static getNormalizeElementPointsAndCoords(t){let{points:n,offsetX:o,offsetY:i}=ya(t);return{points:n,x:t.x+o,y:t.y+i}}static duplicateSelectedPoints(t,n){wt(t.selectedLinearElement?.isEditing,"Not currently editing a linear element");let o=n.getNonDeletedElementsMap(),{selectedPointsIndices:i,elementId:r}=t.selectedLinearElement,s=e.getElement(r,o);wt(s,"The linear element does not exist in the provided Scene"),wt(i!=null,"There are no selected points to duplicate");let{points:a}=s,l=[],d=!1,c=-1,u=a.reduce((m,h,g)=>{if(++c,m.push(h),i.includes(g)){let E=a[g+1];E||(d=!0),m.push(E?U((h[0]+E[0])/2,(h[1]+E[1])/2):U(h[0],h[1])),l.push(c+1),++c}return m},[]);if(n.mutateElement(s,{points:u}),d){let m=s.points[s.points.length-1];e.movePoints(s,n,new Map([[s.points.length-1,{point:U(m[0]+30,m[1]+30)}]]))}return{...t,selectedLinearElement:{...t.selectedLinearElement,selectedPointsIndices:l}}}static deletePoints(t,n,o){let i=n.state.selectedLinearElement?.isEditing&&n.state.selectedLinearElement?.lastUncommittedPoint===t.points[t.points.length-1],r=t.points.filter((c,u)=>!o.includes(u));Ye(t)&&t.polygon&&(i||o.includes(0)||o.includes(t.points.length-1))&&(r[0]=U(r[r.length-1][0],r[r.length-1][1]));let{points:a,offsetX:l,offsetY:d}=ya({points:r});e._updatePoints(t,n.scene,a,l,d)}static addPoints(t,n,o){let i=[...t.points,...o];Ye(t)&&t.polygon&&(i[0]=U(i[i.length-1][0],i[i.length-1][1]));let{points:r,offsetX:s,offsetY:a}=ya({points:i});e._updatePoints(t,n,r,s,a)}static movePoints(t,n,o,i,r){let{points:s}=t;if(Ye(t)&&t.polygon){let u=o.get(0),m=o.get(s.length-1);u?o.set(s.length-1,{point:U(u.point[0],u.point[1]),isDragging:u.isDragging}):m&&o.set(0,{point:U(m.point[0],m.point[1]),isDragging:m.isDragging})}let a=o.get(0)?.point??U(0,0),[l,d]=a,c=ee(t)?[o.get(0)?.point??s[0],o.get(s.length-1)?.point??s[s.length-1]]:s.map((u,m)=>{let h=o.get(m)?.point??u;return i?.moveMidPointsWithElement&&m!==0&&m!==s.length-1&&!o.has(m)?h:U(h[0]-l,h[1]-d)});e._updatePoints(t,n,c,l,d,i,{isDragging:Array.from(o.values()).some(u=>u.isDragging),isBindingEnabled:r?.isBindingEnabled,isMidpointSnappingEnabled:r?.isMidpointSnappingEnabled})}static shouldAddMidpoint(t,n,o,i){let r=e.getElement(t.elementId,i);if(r&&ee(r)||!r)return!1;let{segmentMidpoint:s}=t.initialState;if(s.added||s.value===null||s.index===null||t.initialState.origin===null)return!1;let a=t.initialState.origin,l=ho(a,U(n.x,n.y));return!(!o.selectedLinearElement?.isEditing&&l<zf/o.zoom.value)}static addMidpoint(t,n,o,i,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a)return;let{segmentMidpoint:l}=t.initialState,d={pointerDownState:t.initialState,selectedPointsIndices:t.selectedPointsIndices},c=e.createPointAt(a,s,n.x,n.y,i&&!ee(a)?o.getEffectiveGridSize():null),u=[...a.points.slice(0,l.index),c,...a.points.slice(l.index)];return r.mutateElement(a,{points:u}),d.pointerDownState={...t.initialState,segmentMidpoint:{...t.initialState.segmentMidpoint,added:!0},lastClickedPoint:l.index},d.selectedPointsIndices=[l.index],d}static _updatePoints(t,n,o,i,r,s,a){if(ee(t)){let l={};s?.startBinding!==void 0&&(l.startBinding=s.startBinding),s?.endBinding!==void 0&&(l.endBinding=s.endBinding),l.points=Array.from(o),n.mutateElement(t,l,{informMutation:!0,isDragging:a?.isDragging??!1,isBindingEnabled:a?.isBindingEnabled,isMidpointSnappingEnabled:a?.isMidpointSnappingEnabled})}else{let l=ba(t,o),d=ba(t,t.points),c=(l[0]+l[2])/2,u=(l[1]+l[3])/2,m=(d[0]+d[2])/2,h=(d[1]+d[3])/2,g=m-c,f=h-u,E=ct(U(i,r),U(g,f),t.angle);n.mutateElement(t,{...s,points:o,x:t.x+E[0],y:t.y+E[1]})}}static _getShiftLockedDelta(t,n,o,i,r,s){let a=e.getPointGlobalCoordinates(t,o,n);if(ee(t))return[i[0]-a[0],i[1]-a[1]];let[l,d]=Rc(i[0],i[1],r),{width:c,height:u}=_c(a[0],a[1],l,d,s);return ct(U(c,u),U(0,0),-t.angle)}static getBoundTextElementCenter=(t,n)=>{if(t.points.length%2===1){let i=Math.floor(t.points.length/2);return e.getPointGlobalCoordinates(t,t.points[i],n)}let o=t.points.length/2-1;return e.getSegmentMidPoint(t,o+1,n)};static getBoundTextElementPosition=(t,n,o)=>{e.getPointsGlobalCoordinates(t,o).length<2&&$e(n,o,{isDeleted:!0});let r=e.getBoundTextElementCenter(t,o);return{x:r[0]-n.width/2,y:r[1]-n.height/2}};static getMinMaxXYWithBoundText=(t,n,o,i)=>{let[r,s,a,l]=o,d=(r+a)/2,c=(s+l)/2,{x:u,y:m}=e.getBoundTextElementPosition(t,i,n),h=u+i.width,g=m+i.height,f=U(d,c),E=ct(U(r,s),f,t.angle),x=ct(U(a,s),f,t.angle),y=ct(U(u,m),f,-t.angle),b=ct(U(h,m),f,-t.angle),M=ct(U(u,g),f,-t.angle),w=ct(U(h,g),f,-t.angle);return E[0]<x[0]&&E[1]>=x[1]?(r=Math.min(r,M[0]),a=Math.max(a,Math.max(b[0],w[0])),s=Math.min(s,y[1]),l=Math.max(l,w[1])):E[0]>=x[0]&&E[1]>x[1]?(r=Math.min(r,w[0]),a=Math.max(a,Math.max(y[0],b[0])),s=Math.min(s,M[1]),l=Math.max(l,b[1])):E[0]>=x[0]?(r=Math.min(r,b[0]),a=Math.max(a,M[0]),s=Math.min(s,w[1]),l=Math.max(l,y[1])):E[1]<=x[1]&&(r=Math.min(r,Math.min(b[0],y[0])),a=Math.max(a,w[0]),s=Math.min(s,b[1]),l=Math.max(l,M[1])),[r,s,a,l,d,c]};static getElementAbsoluteCoords=(t,n,o=!1)=>{let i=Lt.generateElementShape(t,null),r=pn(i[0]),[s,a,l,d]=bi(r),c=s+t.x,u=a+t.y,m=l+t.x,h=d+t.y,g=(c+m)/2,f=(u+h)/2,E=o&&pe(t,n);return E?e.getMinMaxXYWithBoundText(t,n,[c,u,m,h],E):[c,u,m,h,g,f]};static moveFixedSegment(t,n,o,i,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a||!ee(a))return t;if(n&&n>0&&n<a.points.length){let l=yt(rn(Rf(a.points[n],a.points[n-1]))),d=(a.fixedSegments??[]).reduce((h,g)=>(h[g.index]=g,h),{});d[n]={index:n,start:U(l?a.points[n-1][0]:o-a.x,l?i-a.y:a.points[n-1][1]),end:U(l?a.points[n][0]:o-a.x,l?i-a.y:a.points[n][1])};let c=Object.values(d).sort((h,g)=>h.index-g.index),u=c.map(h=>h.index).reduce((h,g)=>g<n?h+1:h,0);r.mutateElement(a,{fixedSegments:c});let m=U(a.x+(a.fixedSegments[u].start[0]+a.fixedSegments[u].end[0])/2,a.y+(a.fixedSegments[u].start[1]+a.fixedSegments[u].end[1])/2);return{...t,segmentMidPointHoveredCoords:m,initialState:{...t.initialState,segmentMidpoint:{added:!1,index:a.fixedSegments[u].index,value:m}}}}return t}static deleteFixedSegment(t,n,o){n.mutateElement(t,{fixedSegments:t.fixedSegments?.filter(i=>i.index!==o)})}},Wf=e=>{let t=[...new Set(e.filter(n=>n!==null&&n!==-1))];return t=t.sort((n,o)=>n-o),t.length?t:null},Fc=(e,t,n,o,i,r,s,a,l,d,c,u)=>{let m=new Map(e.map(V=>{let D=s.points[V]??s.points.at(-1);return[V,{point:U(D[0]+t,D[1]+n),isDragging:!0}]}));if(!J(s))return{positions:m};let h=e.includes(0),g=e.includes(s.points.length-1),{start:f,end:E}=sa(s,m,o,i,r,a,l.state,{newArrow:!!l.state.newElement,angleLocked:d,altKey:c,gridSize:l.getEffectiveGridSize()});if(ee(s)){let V=h?f.element:g?E.element:null;return{positions:m,updates:{suggestedBinding:V?{element:V,midPoint:l.state.isMidpointSnappingEnabled?aa(V,r,U(o-u.pointerOffset.x,i-u.pointerOffset.y)):void 0}:null}}}if(!h&&!g){let V={...s,points:s.points.map((B,I)=>m.get(I)?.point??B)},D=new Map(m);if(s.startBinding){let B=r.get(s.startBinding.elementId);if(B){let I=Yt(V,"startBinding",s.startBinding,B,r)??null;I&&D.set(0,{point:I,isDragging:!0})}}if(s.endBinding){let B=r.get(s.endBinding.elementId);if(B){let I=Yt(V,"endBinding",s.endBinding,B,r)??null;I&&D.set(s.points.length-1,{point:I,isDragging:!0})}}return{positions:D}}if(h===g)return{positions:m};let x={suggestedBinding:null};f.mode===null?x.startBinding=null:f.mode?(x.startBinding={elementId:f.element.id,mode:f.mode,...Go(s,f.element,"start",r,f.focusPoint)},h&&(x.startBinding.mode==="orbit"||!Ro("COMPLEX_BINDINGS"))&&(x.suggestedBinding=f.element?{element:f.element,midPoint:er(U(o-u.pointerOffset.x,i-u.pointerOffset.y),f.element,r,l.state.zoom)}:null)):h&&(x.suggestedBinding=l.state.suggestedBinding),E.mode===null?x.endBinding=null:E.mode?(x.endBinding={elementId:E.element.id,mode:E.mode,...Go(s,E.element,"end",r,E.focusPoint)},g&&(x.endBinding.mode==="orbit"||!Ro("COMPLEX_BINDINGS"))&&(x.suggestedBinding=E.element?{element:E.element,midPoint:er(U(o-u.pointerOffset.x,i-u.pointerOffset.y),E.element,r,l.state.zoom)}:null)):g&&(x.suggestedBinding=l.state.suggestedBinding);let y=h?U(s.points[0][0]+t,s.points[0][1]+n):s.points[0],b=g?U(s.points[s.points.length-1][0]+t,s.points[s.points.length-1][1]+n):s.points[s.points.length-1],M={...s,points:[y,...s.points.slice(1,-1),b],startBinding:x.startBinding===void 0?s.startBinding:x.startBinding===null?null:x.startBinding,endBinding:x.endBinding===void 0?s.endBinding:x.endBinding===null?null:x.endBinding},w=s.endBinding&&M.startBinding&&h&&M.startBinding.elementId===s.endBinding.elementId,v=s.startBinding&&M.endBinding&&g&&s.startBinding.elementId===M.endBinding.elementId,A=M.endBinding?E.element??r.get(M.endBinding.elementId):null,k=v&&l.state.bindMode!=="inside"&&Ro("COMPLEX_BINDINGS")?M.points[0]:A&&Yt(M,"endBinding",M.endBinding,A,r,g)||M.points[M.points.length-1];M.points[M.points.length-1]=k;let T=M.startBinding?f.element??r.get(M.startBinding.elementId):null,z=v&&Ro("COMPLEX_BINDINGS")?M.points[0]:w&&l.state.bindMode!=="inside"&&Ro("COMPLEX_BINDINGS")?k:T&&Yt(M,"startBinding",M.startBinding,T,r,h)||M.points[0],C=!(v&&l.state.bindMode!=="inside"&&Ro("COMPLEX_BINDINGS"))&&!!A,O=ho(z,M.points[0])!==0,N=new Set(e);T&&O&&N.add(0),A&&C&&N.add(s.points.length-1);let j=Array.from(N);return{updates:x,positions:new Map(j.map(V=>[V,V===0?{point:z,isDragging:!0}:V===s.points.length-1?{point:k,isDragging:!0}:m.get(V)]))}},Hc=(e,t)=>Math.atan2(t[1]-e[1],t[0]-e[0]);S();import{MIME_TYPES as Yc,SVG_NS as Vf}from"@excalidraw/common";S();function Wc(e,t,n){if(e>100||t>100)throw new Error(`${e}x${t} doesn't fit in 100x100`);let{PI:o,round:i,max:r,cos:s,abs:a}=Math,l=0,d=0,c=0,u=0;for(let $=0,X=0;$<e*t;$++,X+=4){let Y=n[X+3]/255;l+=Y/255*n[X],d+=Y/255*n[X+1],c+=Y/255*n[X+2],u+=Y}u&&(l/=u,d/=u,c/=u);let m=u<e*t,h=m?5:7,g=r(1,i(h*e/r(e,t))),f=r(1,i(h*t/r(e,t))),E=[],x=[],y=[],b=[];for(let $=0,X=0;$<e*t;$++,X+=4){let Y=n[X+3]/255,we=l*(1-Y)+Y/255*n[X],Q=d*(1-Y)+Y/255*n[X+1],me=c*(1-Y)+Y/255*n[X+2];E[$]=(we+Q+me)/3,x[$]=(we+Q)/2-me,y[$]=we-Q,b[$]=Y}let M=($,X,Y)=>{let we=0,Q=[],me=0,Ae=[];for(let ne=0;ne<Y;ne++)for(let ie=0;ie*Y<X*(Y-ne);ie++){let Ie=0;for(let ye=0;ye<e;ye++)Ae[ye]=s(o/e*ie*(ye+.5));for(let ye=0;ye<t;ye++)for(let He=0,Rt=s(o/t*ne*(ye+.5));He<e;He++)Ie+=$[He+ye*e]*Ae[He]*Rt;Ie/=e*t,ie||ne?(Q.push(Ie),me=r(me,a(Ie))):we=Ie}if(me)for(let ne=0;ne<Q.length;ne++)Q[ne]=.5+.5/me*Q[ne];return[we,Q,me]},[w,v,A]=M(E,r(3,g),r(3,f)),[k,T,z]=M(x,3,3),[C,O,N]=M(y,3,3),[j,V,D]=m?M(b,5,5):[],B=e>t,I=i(63*w)|i(31.5+31.5*k)<<6|i(31.5+31.5*C)<<12|i(31*A)<<18|m<<23,L=(B?f:g)|i(63*z)<<3|i(63*N)<<9|B<<15,G=[I&255,I>>8&255,I>>16,L&255,L>>8],_=m?6:5,K=0;m&&G.push(i(15*j)|i(15*D)<<4);for(let $ of m?[v,T,O,V]:[v,T,O])for(let X of $)G[_+(K>>1)]|=i(15*X)<<((K++&1)<<2);return new Uint8Array(G)}function jc(e){let{PI:t,min:n,max:o,cos:i,round:r}=Math,s=e[0]|e[1]<<8|e[2]<<16,a=e[3]|e[4]<<8,l=(s&63)/63,d=(s>>6&63)/31.5-1,c=(s>>12&63)/31.5-1,u=(s>>18&31)/31,m=s>>23,h=(a>>3&63)/63,g=(a>>9&63)/63,f=a>>15,E=o(3,f?m?5:7:a&7),x=o(3,f?a&7:m?5:7),y=m?(e[5]&15)/15:1,b=(e[5]>>4)/15,M=m?6:5,w=0,v=(B,I,L)=>{let G=[];for(let _=0;_<I;_++)for(let K=_?0:1;K*I<B*(I-_);K++)G.push(((e[M+(w>>1)]>>((w++&1)<<2)&15)/7.5-1)*L);return G},A=v(E,x,u),k=v(3,3,h*1.25),T=v(3,3,g*1.25),z=m&&v(5,5,b),C=jf(e),O=r(C>1?32:32*C),N=r(C>1?32/C:32),j=new Uint8Array(O*N*4),V=[],D=[];for(let B=0,I=0;B<N;B++)for(let L=0;L<O;L++,I+=4){let G=l,_=d,K=c,$=y;for(let Q=0,me=o(E,m?5:3);Q<me;Q++)V[Q]=i(t/O*(L+.5)*Q);for(let Q=0,me=o(x,m?5:3);Q<me;Q++)D[Q]=i(t/N*(B+.5)*Q);for(let Q=0,me=0;Q<x;Q++)for(let Ae=Q?0:1,ne=D[Q]*2;Ae*x<E*(x-Q);Ae++,me++)G+=A[me]*V[Ae]*ne;for(let Q=0,me=0;Q<3;Q++)for(let Ae=Q?0:1,ne=D[Q]*2;Ae<3-Q;Ae++,me++){let ie=V[Ae]*ne;_+=k[me]*ie,K+=T[me]*ie}if(m)for(let Q=0,me=0;Q<5;Q++)for(let Ae=Q?0:1,ne=D[Q]*2;Ae<5-Q;Ae++,me++)$+=z[me]*V[Ae]*ne;let X=G-2/3*_,Y=(3*G-X+K)/2,we=Y-K;j[I]=o(0,255*n(1,Y)),j[I+1]=o(0,255*n(1,we)),j[I+2]=o(0,255*n(1,X)),j[I+3]=o(0,255*n(1,$))}return{w:O,h:N,rgba:j}}function jf(e){let t=e[3],n=e[2]&128,o=e[4]&128,i=o?n?5:7:t&7,r=o?t&7:n?5:7;return i/r}var Uf=100,Vc=new Map,Uc=new Set,Yf=e=>{let t="";for(let n of e)t+=String.fromCharCode(n);return btoa(t)},Xf=e=>{let t=atob(e),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n},K4=e=>{let t=e.naturalWidth||e.width,n=e.naturalHeight||e.height;if(!t||!n)return null;let o=Math.min(1,Uf/Math.max(t,n)),i=Math.max(1,Math.round(t*o)),r=Math.max(1,Math.round(n*o)),s=document.createElement("canvas");s.width=i,s.height=r;let a=s.getContext("2d");if(!a)return null;a.drawImage(e,0,0,i,r);let l=a.getImageData(0,0,i,r);return Yf(Wc(i,r,l.data))},Xc=e=>{if(Uc.has(e))return null;let t=Vc.get(e);if(t)return t;try{let{w:n,h:o,rgba:i}=jc(Xf(e)),r=document.createElement("canvas");r.width=n,r.height=o;let s=r.getContext("2d");if(!s)return null;let a=s.createImageData(n,o);return a.data.set(i),s.putImageData(a,0,0),Vc.set(e,r),r}catch(n){return Uc.add(e),console.warn("Invalid ThumbHash",n),null}},$f=e=>new Promise((t,n)=>{let o=new Image;o.onload=()=>{t(o)},o.onerror=i=>{n(i)},o.src=e}),Q4=async({fileIds:e,files:t,imageCache:n})=>{let o=new Map,i=new Map;return await Promise.all(e.reduce((r,s)=>{let a=t[s];return a&&!o.has(s)?(o.set(s,!0),r.concat((async()=>{try{if(a.mimeType===Yc.binary)throw new Error("Only images can be added to ImageCache");let l=$f(a.dataURL),d={image:l,mimeType:a.mimeType};n.set(s,d);let c=await l;n.set(s,{...d,image:c})}catch{i.set(s,!0)}})())):r},[])),{imageCache:n,updatedFiles:o,erroredFiles:i}},J4=e=>e.filter(t=>Dn(t)),Zf=e=>e?.nodeName.toLowerCase()==="svg",e5=e=>{let t=new DOMParser().parseFromString(e,Yc.svg),n=t.querySelector("svg");if(t.querySelector("parsererror")||!Zf(n))throw new Error("Invalid SVG");{n.hasAttribute("xmlns")||n.setAttribute("xmlns",Vf);let i=n.getAttribute("width"),r=n.getAttribute("height");(i?.includes("%")||i==="auto")&&(i=null),(r?.includes("%")||r==="auto")&&(r=null);let s=n.getAttribute("viewBox");if(!i||!r){if(i=i||"50",r=r||"50",s){let a=s.match(/\d+ +\d+ +(\d+(?:\.\d+)?) +(\d+(?:\.\d+)?)/);a&&([,i,r]=a)}n.setAttribute("width",i),n.setAttribute("height",r)}return s||n.setAttribute("viewBox",`0 0 ${i} ${r}`),n.outerHTML}};var r0=(e,t)=>Dn(e)&&!t.imageCache.has(e.fileId),Br=e=>{switch(e.type){case"freedraw":return e.strokeWidth*12;case"text":return e.fontSize/2;case"arrow":return e.endArrowhead||e.endArrowhead?40:20;default:return 20}},s0=(e,t,n,o,i=1)=>{let r=(t?.opacity??100)*e.opacity/1e4*i;return(n.has(e.id)||o&&o.some(s=>s.id===e.id)||t&&n.has(t.id))&&(r*=Qf/100),r},a0=(e,t,n)=>{let r=Br(e),[s,a,l,d]=ae(e,t),c=le(e)||Le(e)?Xn(s,l):e.width,u=le(e)||Le(e)?Xn(a,d):e.height,m=c*window.devicePixelRatio+r*2,h=u*window.devicePixelRatio+r*2,g=n.value;return(m*g>32767||h*g>32767)&&(g=Math.min(32767/m,32767/h)),m*h*g*g>16777216&&(g=Math.sqrt(16777216/(m*h))),m=Math.floor(m*g),h=Math.floor(h*g),{width:m,height:h,scale:g}},Kc=(e,t,n,o,i)=>{let r=document.createElement("canvas"),s=r.getContext("2d"),a=Br(e),{width:l,height:d,scale:c}=a0(e,t,n);if(!l||!d)return null;r.width=l,r.height=d;let u=-100,m=0;if(le(e)||Le(e)){let[g,f]=ae(e,t);u=e.x>g?Xn(e.x,g)*window.devicePixelRatio*c:0,m=e.y>f?Xn(e.y,f)*window.devicePixelRatio*c:0,s.translate(u,m)}s.save(),s.translate(a*c,a*c),s.scale(window.devicePixelRatio*c,window.devicePixelRatio*c);let h=Mo.canvas(r);return Dr(e,h,s,o),s.restore(),{element:e,canvas:r,theme:i.theme,scale:c,zoomValue:n.value,canvasOffsetX:u,canvasOffsetY:m,containingFrameOpacity:Wn(e,t)?.opacity||100,imageCrop:Ue(e)?e.crop:null}},g5=14,Qc=typeof document<"u"?document.createElement("img"):{src:""};Qc.src=`data:${Pa.svg},${encodeURIComponent('<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="image" class="svg-inline--fa fa-image fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="#888" d="M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48zM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56zM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48z"></path></svg>')}`;var Jc=typeof document<"u"?document.createElement("img"):{src:""};Jc.src=`data:${Pa.svg},${encodeURIComponent('<svg viewBox="0 0 668 668" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2"><path d="M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48ZM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56ZM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48Z" style="fill:#888;fill-rule:nonzero" transform="matrix(.81709 0 0 .81709 124.825 145.825)"/><path d="M256 8C119.034 8 8 119.033 8 256c0 136.967 111.034 248 248 248s248-111.034 248-248S392.967 8 256 8Zm130.108 117.892c65.448 65.448 70 165.481 20.677 235.637L150.47 105.216c70.204-49.356 170.226-44.735 235.638 20.676ZM125.892 386.108c-65.448-65.448-70-165.481-20.677-235.637L361.53 406.784c-70.203 49.356-170.226 44.736-235.638-20.676Z" style="fill:#888;fill-rule:nonzero" transform="matrix(.30366 0 0 .30366 506.822 60.065)"/></svg>')}`;var Zc=(e,t,n)=>{if(e.status!=="error"&&e.thumbHash){let r=Xc(e.thumbHash);if(r){t.drawImage(r,0,0,e.width,e.height);return}}t.fillStyle=n===Fo.DARK?"#2E2E2E":"#E7E7E7",t.fillRect(0,0,e.width,e.height);let o=Math.min(e.width,e.height),i=Math.min(o,Math.min(o*.4,100));t.drawImage(e.status==="error"?Jc:Qc,e.width/2-i/2,e.height/2-i/2,i,i)},Dr=(e,t,n,o)=>{switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":{n.lineJoin="round",n.lineCap="round",t.draw(Lt.generateElementShape(e,o));break}case"arrow":case"line":{n.lineJoin="round",n.lineCap="round",Lt.generateElementShape(e,o).forEach(i=>{t.draw(i)});break}case"freedraw":{n.save();let i=Lt.generateElementShape(e,o);for(let r of i)typeof r=="string"?(n.fillStyle=Cr(e.strokeColor,o.theme===Fo.DARK),n.fill(new Path2D(r))):t.draw(r);n.restore();break}case"image":{n.save();let i=e.fileId!==null?o.imageCache.get(e.fileId):null,r=Dn(e)?i?.image:void 0;if(r!=null&&!(r instanceof Promise)){e.roundness&&n.roundRect&&(n.beginPath(),n.roundRect(0,0,e.width,e.height,fn(Math.min(e.width,e.height),e)),n.clip());let s=o.imageTransitionDuration??0;if(!o.isExporting&&i?.transitionStart!==void 0)if(s>0){let m=Math.min(1,(performance.now()-i.transitionStart)/s);m<1?(i.placeholderImage?n.drawImage(i.placeholderImage,0,0,e.width,e.height):Zc(e,n,o.theme),n.globalAlpha*=m):(delete i.placeholderImage,delete i.transitionStart)}else delete i.placeholderImage,delete i.transitionStart;let{x:a,y:l,width:d,height:c}=e.crop?e.crop:{x:0,y:0,width:r.naturalWidth,height:r.naturalHeight},u=o.theme===Fo.DARK&&i?.mimeType===Pa.svg;if(u&&i0){let m=window.devicePixelRatio||1,h=document.createElement("canvas");h.width=e.width*m,h.height=e.height*m;let g=h.getContext("2d");if(g){g.scale(m,m),g.drawImage(r,a,l,d,c,0,0,e.width,e.height);let f=g.getImageData(0,0,h.width,h.height),E=f.data;for(let x=0;x<E.length;x+=4)E[x]=255-E[x],E[x+1]=255-E[x+1],E[x+2]=255-E[x+2];g.putImageData(f,0,0),n.drawImage(h,0,0,h.width,h.height,0,0,e.width,e.height)}}else u&&(n.filter=Jf),n.drawImage(r,a,l,d,c,0,0,e.width,e.height)}else Zc(e,n,o.theme);n.restore();break}default:if(ue(e)){let i=t0(e.text),r=i&&!n.canvas.isConnected;r&&document.body.appendChild(n.canvas),n.canvas.setAttribute("dir",i?"rtl":"ltr"),n.save(),n.font=e0(e),n.fillStyle=Cr(e.strokeColor,o.theme===Fo.DARK),n.textAlign=e.textAlign;let s=e.text.replace(/\r\n?/g,`
12
+ `),d.stack,e.map(u=>s(u)),...c),t)throw d}},dc=e=>e.sort((t,n)=>lc(t)&&lc(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),uo=(e,t)=>{try{let n=Sr(e),o=cf(e,t),i=ua(e,o),r=e.map(s=>{let a=i.get(s);return a?{...s,index:a.index}:s});df(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of i)$e(s,n,{index:a})}catch{ca(e)}return e},ca=e=>{let t=Sr(e),n=uc(e),o=ua(e,n);for(let[i,{index:r}]of o)$e(i,t,{index:r});return e},cc=e=>{let t=Sr(e),n=uc(e),o=ua(e,n);for(let[i,{index:r}]of o)t.set(i.id,at(i,{index:r}));return t},cf=(e,t)=>{let n=[],o=0;for(;o<e.length;)if(t.has(e[o].id)){let i=[o-1,o];for(;++o<e.length&&t.has(e[o].id);)i.push(o);i.push(o),n.push(i)}else o++;return n},uc=e=>{let t=[],n,o,i=-1,r=0,s=d=>{let c=e[i]?e[i].index:void 0,u=e[d-1]?.index;return!c&&u||c&&u&&u>c?[u,d-1]:[c,i]},a=d=>{let c=e[r]?e[r].index:void 0;if(c&&d<r)return[c,r];let u=r;for(;++u<e.length;){let m=e[u]?.index;if(!c&&m||c&&m&&m>c)return[m,u]}return[void 0,u]},l=0;for(;l<e.length;){let d=e[l].index;if([n,i]=s(l),[o,r]=a(l),da(d,n,o))l++;else{let c=[i,l];for(;++l<e.length;){let u=e[l].index,[m,h]=s(l),[g,f]=a(l);if(da(u,m,g))break;[n,i]=[m,h],[o,r]=[g,f],c.push(l)}c.push(r),t.push(c)}}return t},da=(e,t,n)=>{if(!e)return!1;try{af(e)}catch{return!1}return t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e},ua=(e,t)=>{let n=new Map;for(let o of t){let i=o.shift(),r=o.pop(),s=lf(e[i]?.index,e[r]?.index,o.length);for(let a=0;a<o.length;a++){let l=e[o[a]];n.set(l,{index:s[a]})}}return n},lc=e=>!!e.index;var pc=(e,t,n)=>{let o=Xt(e);for(let i of t)if(i.frameId){let r=n.get(i.id),s=n.get(i.frameId),a=r&&o.get(r);a&&$e(a,o,{frameId:s??null})}};function Oo(e,t,n){let o=No(t,n),i=No(e,n);return o.some(s=>i.some(a=>pf(s,a)))}var mc=(e,t,n)=>vr(gc(e,t,n,!1)).filter(o=>!ce(o)&&!o.frameId||o.frameId===t.id),ma=(e,t,n)=>fa(be(e,n),be(t,n)),k6=(e,t)=>{let n=Xt(e);return e.filter(o=>Oo(o,t,n))},jn=(e,t,n)=>{let[o,i,r,s]=ae(t,n),[a,l,d,c]=dt(e);return o<=a&&i<=l&&r>=d&&s>=c},_n=(e,t,n)=>jn([e],t,n)||Oo(e,t,n)||ma(e,t,n),L6=(e,t,n)=>{let[o,i,r,s]=ae(t,n);return uf(pa(o,i),pa(e.x,e.y),pa(r,s))},D6=(e,t,n)=>{let o=Xt(e),i=t.flatMap(r=>lt(e,r));return i.length===0?!0:!!i.find(r=>jn([r],n,o)||Oo(r,n,o))},C6=(e,t,n)=>{let o=Xt(e),i=t.flatMap(r=>lt(e,r));return i.length===0?!0:i.find(r=>jn([r],n,o)||Oo(r,n,o))===void 0},B6=e=>{let t=new Map;for(let n of e){let o=ce(n)?n.id:n.frameId;o&&!t.has(o)&&t.set(o,Vn(e,o))}return t},Vn=(e,t)=>{let n=[];for(let o of e.values())o.frameId===t&&n.push(o);return n},ha=e=>e.filter(t=>ce(t)),G6=e=>{let t=Xt(ha(e));return e.filter(n=>t.has(n.id)||!n.frameId||!t.has(n.frameId))},N6=(e,t,n,o)=>{let i=Vn(e,t.id),r=new Set(i),s=new Set([...mc(e,t,o),...i.filter(h=>ma(h,t,o))]),a=i.filter(h=>!s.has(h)),l=new Set(Array.from(s).flatMap(h=>h.groupIds));for(let h of a)if(!Oo(h,t,o))h.groupIds.length===0&&r.delete(h);else if(h.groupIds.length>0)for(let g of h.groupIds)l.add(g);for(let h of a)if(h.groupIds.length>0){let g=!0;for(let f of h.groupIds)l.has(f)&&(g=!1);g&&r.delete(h)}let d=Array.from(s).filter(h=>h.groupIds.length===0);for(let h of d)r.add(h);let c=Array.from(s).filter(h=>h.groupIds.length>0),u=Un(c),m=Ec(u,n);for(let[h,g]of Object.entries(m))if(g){let f=lt(e,h);if(jn(f,t,o))for(let E of f)r.add(E)}return[...r].filter(h=>!(ue(h)&&h.containerId))},O6=(e,t,n)=>mf(vr(e,mc(e,t,n)),t,n),mf=(e,t,n)=>{let o=[],i=new Map;for(let r of e){let s=!1;if(r.groupIds.length>0){if(r.groupIds.some(a=>i.get(a)))s=!0;else{let a=new Set(r.groupIds.flatMap(l=>lt(n,l)));s=!jn(Array.from(a),t,n)}r.groupIds.forEach(a=>{i.set(a,s)})}s||o.push(r)}return o},Wn=(e,t)=>e.frameId&&t.get(e.frameId)||null,R6=(e,t)=>{let n=new Set,o=Xt(e);e=vr(e);for(let s of e)ce(s)&&s.id!==t.id&&n.add(s.id);let i=new Set,r=[];for(let s of e)if(!(ce(s)||s.frameId&&n.has(s.frameId)))if(s.groupIds.length){let a=s.groupIds.at(-1);if(!i.has(a)){i.add(a);let l=lt(e,a);if(l.some(d=>_n(d,t,o)))for(let d of l)r.push(d)}}else _n(s,t,o)&&r.push(s);return r},hf=e=>{let t;for(let n of e){if(ce(n)||!n.frameId)return null;if(t===void 0)t=n.frameId;else if(t!==n.frameId)return null}return t??null},ff=(e,t)=>{for(let n=e.length-1;n>=0;n--){let o=e[n];if(o.id===t)return n;if(o.frameId===t)return n+1}return null},gf=(e,t,n)=>{let o=Xt(e),i=hf(t),r=new Set,s=new Set;for(let c of t)ce(c)&&c.id!==n.id&&s.add(c.id);for(let c of vr(e,t)){if(ce(c)||c.frameId&&s.has(c.frameId))continue;r.add(c);let u=pe(c,o);u&&!r.has(u)&&r.add(u)}for(let c of r)c.frameId!==n.id&&$e(c,o,{frameId:n.id});if(!r.size||i===n.id)return e;let a=Array.from(e.values()).filter(c=>!r.has(c)),l=ff(a,n.id);if(l===null)return e;let d=[...a.slice(0,l),...r,...a.slice(l)];return uo(d,Xt([...r])),Array.isArray(e)?d:new Map(d.map(c=>[c.id,c]))},hc=(e,t)=>{let n=new Map,o=new Map;for(let i of e)if(i.frameId){n.set(i.id,i);let r=o.get(i.frameId)||[];r.push(i);let s=pe(i,t);s&&(n.set(s.id,s),r.push(s)),o.set(i.frameId,r)}for(let[,i]of n)$e(i,t,{frameId:null})},Ef=(e,t)=>{let n=Vn(e,t.id);return hc(n,Xt(e)),e},F6=(e,t,n)=>gf(Ef(e,n),t,n).slice(),H6=(e,t,n)=>{let o=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,elements:e}),i=new Set(o);if(t.editingGroupId)for(let a of o)a.groupIds.length===0?i.add(a):a.groupIds.flatMap(l=>lt(e,l)).forEach(l=>i.add(l));let r=new Set,s=Xt(e);return i.forEach(a=>{a.frameId&&!ce(a)&&!fc(a,s,t)&&r.add(a)}),r.size>0&&hc(r,s),e},vr=(e,t)=>{let n=new Set,o=t||e;for(let s of o.values()){let a=s.groupIds[s.groupIds.length-1];a&&n.add(a)}let i=new Set;for(let s of n)lt(e,s).some(a=>ce(a))&&i.add(s);let r=[];for(let s of o.values())i.has(s.groupIds[s.groupIds.length-1])||r.push(s);return r},xf=(e,t,n)=>{let o=ue(e)&&et(e,t)||e;return o.frameId&&n.selectedElementIds[o.id]&&n.selectedElementIds[o.frameId]?Wn(o,t):n.selectedElementIds[o.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:Wn(o,t)},fc=(e,t,n,o)=>{let i=o?.targetFrame??xf(e,t,n);if(!i)return!1;let r=ue(e)&&et(e,t)||e,s=l=>{o?.checkedGroups&&r.groupIds.forEach(d=>{o.checkedGroups?.set(d,l)})};if(!n.selectedElementIds[r.id]||!n.selectedElementsAreBeingDragged||n.selectedElementIds[r.id]&&n.selectedElementIds[i.id])return!0;if(r.groupIds.length===0)return _n(r,i,t);for(let l of r.groupIds)if(o?.checkedGroups?.has(l))return o.checkedGroups.get(l);let a=new Set(r.groupIds.filter(l=>o?.checkedGroups?!o.checkedGroups.has(l):!0).flatMap(l=>lt(t,l)));if(n.editingGroupId&&n.selectedElementsAreBeingDragged){let l=new Set(dn(t,n));if(n.frameToHighlight!==null)return!0;l.forEach(c=>{a.delete(c)})}for(let l of a)if(ce(l))return s(!1),!1;for(let l of a)if(_n(l,i,t))return s(!0),!0;return!1},z6=(e,t,n,o,i)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let r=Oo(e,t,o)||ma(e,t,o);if(r){for(let s of e.groupIds)i?.set(s,!0);return!0}if(!r&&e.groupIds.length>0&&!jn([e],t,o)){let s=!1;if(n.selectedElementsAreBeingDragged)s=fc(e,o,n,{targetFrame:t,checkedGroups:i});else{s=e.frameId===t.id;for(let a of e.groupIds)i?.set(a,s)}for(let a of e.groupIds)i?.set(a,s);return s}return!1},yf="Frame",bf="AI Frame",wf=e=>Qi(e)?yf:bf,_6=e=>e.name===null?wf(e):e.name,W6=(e,t,n)=>e.filter(o=>(!o.frameId||o.frameId===t.id)&&kt(be(o,n),be(t,n))),j6=e=>{let t=Xt(e);return e.length>1&&e.some(n=>n.frameId&&t.has(n.frameId))};var If=e=>e.locked||Ne(e),Sf=(e,t)=>e.filter(n=>!(n.frameId&&t.has(n.frameId))),vf=e=>{let t=new Set;return e.forEach(n=>{ce(n)&&t.add(n.id)}),Sf(e,t)},gc=(e,t,n,o=!0,i="contain")=>{let[r,s,a,l]=ae(t,n),d=Math.min(r,a),c=Math.min(s,l),u=Math.max(r,a),m=Math.max(s,l);return yc({elements:e,bounds:[d,c,u,m],elementsMap:n,type:i,shouldIgnoreElementFromSelection:If,excludeElementsInFrames:o})},e4=(e,t,n,o)=>{let i=new Set(t.map(r=>r.id));return e.filter(r=>{let s=bc(r,n.width,n.height,n,o);return!i.has(r.id)&&s})},t4=function(){let e=null,t=null,n=null,o=(i,r)=>(n!=null&&i===e&&r.selectedElementIds===t||(n=i.some(s=>r.selectedElementIds[s.id]),e=i,t=r.selectedElementIds),n);return o.clearCache=()=>{e=null,t=null,n=null},o}(),dn=(e,t,n)=>{let o=new Set,i=[];for(let r of e.values()){if(t.selectedElementIds[r.id]){rt(r)?(i.push(r),o.add(r.id)):console.error("[NONDELETED][INVARIANT] getSelectedElements skipping deleted selected element which should not be in the selection");continue}if(n?.includeBoundTextElement&&Ne(r)&&rt(r)&&t.selectedElementIds[r?.containerId]){i.push(r),o.add(r.id);continue}}if(n?.includeElementsInFrames){let r=[];return i.forEach(s=>{ce(s)&&Vn(e,s.id).forEach(a=>!o.has(a.id)&&r.push(a)),r.push(s)}),r}return i},n4=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement&&t.activeTool.type!=="autoshape"?[t.newElement]:dn(e,t,{includeBoundTextElement:!0}),ga=(e,t)=>Pf(t.selectedElementIds,e)?t.selectedElementIds:e,Af=(e,t)=>{let n=e.filter(le);if(n.length===1){let o=n[0],i=o.boundElements?.map(s=>s.id)??[];if(e.every(s=>s.id===o.id||i.includes(s.id)))return new W(o,Mf(t))}return null},o4=(e,t,n)=>({selectedLinearElement:Af(e,t),...xc({editingGroupId:n.editingGroupId,selectedElementIds:vf(e).reduce((o,i)=>(Ne(i)||(o[i.id]=!0),o),{})},t,n,null)}),i4=(e,t)=>t.editingTextElement||e.length===1&&ue(e[0])&&e[0]||null;var Tf=(e,t,n)=>{let o=n.reduce((i,r)=>(r.groupIds.includes(e)&&(i[r.id]=!0),i),{});return Object.keys(o).length<2?t.selectedGroupIds[e]||t.editingGroupId===e?{selectedElementIds:t.selectedElementIds,selectedGroupIds:{...t.selectedGroupIds,[e]:!1},editingGroupId:null}:t:{editingGroupId:t.editingGroupId,selectedGroupIds:{...t.selectedGroupIds,[e]:!0},selectedElementIds:{...t.selectedElementIds,...o}}},xc=function(){let e=null,t=null,n=null,o=(r,s,a,l)=>{if(n!==void 0&&s===t&&r===e&&a.editingGroupId===n?.editingGroupId)return n;let d={};for(let m of r){let h=m.groupIds;if(a.editingGroupId){let g=h.indexOf(a.editingGroupId);g>-1&&(h=h.slice(0,g))}if(h.length>0){let g=h[h.length-1];d[g]=!0}}let c={},u=s.reduce((m,h)=>{if(h.isDeleted)return m;let g=h.groupIds.find(f=>d[f]);return g&&(m[h.id]=!0,Array.isArray(c[g])?c[g].push(h.id):c[g]=[h.id]),m},{});for(let m of Object.keys(c))c[m].length<2&&d[m]&&(d[m]=!1);return t=s,e=r,n={editingGroupId:a.editingGroupId,selectedGroupIds:d,selectedElementIds:ga({...a.selectedElementIds,...u},l)},n},i=(r,s,a,l)=>{let d=l?l.scene.getSelectedElements({selectedElementIds:r.selectedElementIds,elements:s}):dn(s,r);return d.length?o(d,s,r,a):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:ga(r.selectedElementIds,a)}};return i.clearCache=()=>{t=null,e=null,n=null},i}(),kf=(e,t)=>Ea(e,t)!=null,Ea=(e,t)=>t.groupIds.filter(n=>n!==e.editingGroupId).find(n=>e.selectedGroupIds[n]),Lf=e=>Object.entries(e.selectedGroupIds).filter(([t,n])=>n).map(([t,n])=>t),Ec=(e,t)=>{let n={...t,selectedGroupIds:{}};for(let o of e){let i=o.groupIds;if(t.editingGroupId){let r=i.indexOf(t.editingGroupId);r>-1&&(i=i.slice(0,r))}if(i.length>0){let r=i[i.length-1];n={...n,...Tf(r,n,e)}}}return n.selectedGroupIds},c4=(e,t)=>({...e,editingGroupId:t.groupIds.length?t.groupIds[0]:null,selectedGroupIds:{},selectedElementIds:{[t.id]:!0}}),Df=(e,t)=>e.groupIds.includes(t),lt=(e,t)=>{let n=[];for(let o of e.values())Df(o,t)&&n.push(o);return n},Cf=(e,t)=>e.groupIds.find(n=>t[n]),u4=(e,t,n)=>{let o=[...e],i=n?o.indexOf(n):-1,r=i>-1?i:o.length;return o.splice(r,0,t),o},p4=(e,t)=>e.filter(n=>!t[n]),Ar=(e,t)=>{let n=new Map;return e.forEach(o=>{let i=o.groupIds.length===0?o.id:o.groupIds[o.groupIds.length-1],r=n.get(i)||[],s=pe(o,t);s&&r.push(s),n.set(i,[...r,o])}),Array.from(n.values())},wc=e=>{let t=new Set;for(let[,n]of e)if(!n.isDeleted)for(let o of n.groupIds??[])t.add(o);return t},Mc=e=>{let t=e.flatMap(i=>i.groupIds),n=new Map,o=0;for(let i of t)n.set(i,(n.get(i)??0)+1),n.get(i)>o&&(o=n.get(i));return o===e.length},Pc=e=>e.groupIds.length>0,Ic=(e,t,n)=>{let o=[...e],i=t?e.indexOf(t):-1,r=i>-1?i:e.length;for(let s=0;s<r;s++)o[s]=n(o[s]);return o},Tr=(e,t,n)=>{let o=new Map,r=Lf(n).length===1&&e.every(s=>kf(n,s));return e.forEach(s=>{if(Ne(s))return;let a,l=Cf(s,n.selectedGroupIds);if(!l)a=`${s.id}_element`;else{let u=r?s.groupIds.indexOf(l)-1:s.groupIds.indexOf(l);a=u<0?`${s.id}_element`:`${s.groupIds[u]}_group`}let d=o.get(a)??[],c=pe(s,t);o.set(a,[...d,s,...c?[c]:[]])}),[...o.values()]};var xa=(e,t)=>e.frameId===t||e.id===t,kc=(e,t,n)=>{let o=[],i=[],r=null,s=-1,a=vc(n||dn(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0}));for(;++s<e.length;){let l=e[s];a.get(l.id)?(i.length&&(o=o.concat(i),i=[]),o.push(s),r=s+1):l.isDeleted&&r===s?(r=s+1,i.push(s)):i=[]}return o},Gf=e=>{let t=0;return e.reduce((n,o,i)=>(i>0&&e[i-1]!==o-1&&(t=++t),(n[t]||(n[t]=[])).push(o),n),[])},Sc=(e,t,n,o)=>{if("containerId"in e&&e.containerId){let i=o.getElement(e.containerId);if(i)return n==="left"?Math.min(t.indexOf(i),t.indexOf(e)):Math.max(t.indexOf(i),t.indexOf(e))}else{let i=e.boundElements?.find(r=>r.type!=="arrow")?.id;if(i){let r=o.getElement(i);if(r)return n==="left"?Math.min(t.indexOf(r),t.indexOf(e)):Math.max(t.indexOf(r),t.indexOf(e))}}},Nf=(e,t)=>{let n=-1,o=-1;return e.forEach((i,r)=>{xa(i,t)&&(n===-1&&(n=r),o=r)}),n===-1?[]:e.slice(n,o+1)},yi=(e,t,n,o,i,r)=>{let s=r||xn(e,Un(n),o);if(!s)return n;let a=pe(s,o),l=ue(s)?et(s,o):null,d=[s.id,a?.id,l?.id].filter(m=>!!m),c=n.findIndex(m=>d.includes(m.id)),u=n.findIndex(m=>m.id===t.id);if(u!==-1&&c!==-1&&u<c){let m=Array.from(n),h=m.splice(u,1)[0];m.splice(c,0,h),i.replaceAllElements(m)}return n},Of=(e,t,n,o,i,r)=>{let s=t[n],a=m=>m.isDeleted?!1:i?m.frameId===i:e.editingGroupId?m.groupIds.includes(e.editingGroupId):!0,l=o==="left"?Tc(t,m=>a(m),Math.max(0,n-1)):Ac(t,m=>a(m),n+1),d=t[l];if(!d)return-1;if(e.editingGroupId){if(s?.groupIds.join("")===d?.groupIds.join(""))return Sc(d,t,o,r)??l;if(!d?.groupIds.includes(e.editingGroupId))return-1}if(!i&&(d.frameId||ce(d))){let m=Nf(t,d.frameId||d.id);return o==="left"?t.indexOf(m[0]):t.indexOf(m[m.length-1])}if(!d.groupIds.length)return Sc(d,t,o,r)??l;let c=e.editingGroupId?d.groupIds[d.groupIds.indexOf(e.editingGroupId)-1]:d.groupIds[d.groupIds.length-1],u=lt(t,c);return u.length?o==="left"?t.indexOf(u[0]):t.indexOf(u[u.length-1]):l},Lc=(e,t)=>t.reduce((n,o)=>{let i=e[o];return n.set(i.id,i),n},new Map),Dc=(e,t)=>{if(e.length!==t.length)return console.error("z-index reordering failed: resulting array have different lengths"),!1;let n=new Map;for(let o of e)n.set(o.id,(n.get(o.id)||0)+1);for(let o of t){let i=n.get(o.id);if(!i)return console.error("z-index reordering failed: element id mismatch / duplicate ids"),!1;n.set(o.id,i-1)}return!0},Cc=(e,t,n,o)=>{let i=e,r=kc(e,t),s=Lc(e,r),a=Gf(r);n==="right"&&(a=a.reverse());let l=new Set(r.filter(d=>ce(e[d])).map(d=>e[d].id));return a.forEach((d,c)=>{let u=d[0],m=d[d.length-1],h=n==="left"?u:m,g=d.some(M=>{let w=e[M];return w.frameId&&l.has(w.frameId)})?null:e[h]?.frameId,f=Of(t,e,h,n,g,o);if(f===-1||h===f)return;let E=n==="left"?e.slice(0,f):e.slice(0,u),x=e.slice(u,m+1),y=n==="left"?e.slice(f,u):e.slice(m+1,f+1),b=n==="left"?e.slice(m+1):e.slice(f+1);e=n==="left"?[...E,...x,...y,...b]:[...E,...y,...x,...b]}),Dc(i,e)?(uo(e,s),e):i},Bc=(e,t,n,o,i)=>{let r=kc(e,t,i);if(r.length===0)return e;let s=Lc(e,r),a=[],l,d;if(n==="left"){if(o)l=Ac(e,f=>xa(f,o));else if(t.editingGroupId){let f=lt(e,t.editingGroupId);if(!f.length)return e;l=e.indexOf(f[0])}else l=0;d=r[r.length-1]}else{if(o)d=Tc(e,f=>xa(f,o));else if(t.editingGroupId){let f=lt(e,t.editingGroupId);if(!f.length)return e;d=e.indexOf(f[f.length-1])}else d=e.length-1;l=r[0]}l===-1&&(l=0);let c=f=>Bf(f)&&f>=0;if(!c(l)||!c(d)||l>d||r.some(f=>f<l||f>d))return e;for(let f=l;f<d+1;f++)r.includes(f)||a.push(e[f]);let u=Array.from(s.values()),m=e.slice(0,l),h=e.slice(d+1),g=n==="left"?[...m,...u,...a,...h]:[...m,...a,...u,...h];return Dc(e,g)?(uo(g,s),g):e};function Gc(e,t,n,o){let i=vc(dn(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0})),r={regularElements:[],frameChildren:new Map},s=new Set;for(let d of e)i.has(d.id)&&ce(d)&&s.add(d.id);for(let d of e)if(i.has(d.id))if(ce(d)||d.frameId&&s.has(d.frameId))r.regularElements.push(d);else if(!d.frameId)r.regularElements.push(d);else{let c=r.frameChildren.get(d.frameId)||[];c.push(d),r.frameChildren.set(d.frameId,c)}let a=e,l=Array.from(r.frameChildren.entries());for(let[d,c]of l)a=o(a,t,n,d,c);return o(a,t,n,null,r.regularElements)}var I4=(e,t,n)=>Cc(e,t,"left",n),S4=(e,t,n)=>Cc(e,t,"right",n),v4=(e,t)=>Gc(e,t,"left",Bc),A4=(e,t)=>Gc(e,t,"right",Bc);var ya=({points:e})=>{let t=e[0][0],n=e[0][1];return{points:e.map(o=>U(o[0]-t,o[1]-n)),offsetX:t,offsetY:n}},W=class e{elementId;selectedPointsIndices;initialState;isDragging;lastUncommittedPoint;lastCommittedPoint;pointerOffset;hoverPointIndex;segmentMidPointHoveredCoords;hoveredFocusPointBinding;draggedFocusPointBinding;elbowed;customLineAngle;isEditing;pointerDownState;constructor(t,n,o=!1){this.elementId=t.id,Oc(t.points[0],U(0,0))||(console.error("Linear element is not normalized",Error().stack),$e(t,n,e.getNormalizeElementPointsAndCoords(t))),this.selectedPointsIndices=null,this.lastUncommittedPoint=null,this.lastCommittedPoint=null,this.isDragging=!1,this.pointerOffset={x:0,y:0},this.initialState={prevSelectedPointsIndices:null,lastClickedPoint:-1,origin:null,segmentMidpoint:{value:null,index:null,added:!1},arrowStartIsInside:!1,arrowOtherEndpointInitialBinding:null,altFocusPoint:null},this.hoverPointIndex=-1,this.segmentMidPointHoveredCoords=null,this.hoveredFocusPointBinding=null,this.draggedFocusPointBinding=null,this.elbowed=ee(t)&&t.elbowed,this.customLineAngle=null,this.isEditing=o}static POINT_HANDLE_SIZE=10;static getElement(t,n){let o=n.get(t);return o||null}static handleBoxSelection(t,n,o,i){if(!n.selectedLinearElement?.isEditing||!n.selectionElement)return!1;let{selectedLinearElement:r}=n,{selectedPointsIndices:s,elementId:a}=r,l=e.getElement(a,i);if(!l)return!1;let[d,c,u,m]=ae(n.selectionElement,i),g=e.getPointsGlobalCoordinates(l,i).reduce((f,E,x)=>((E[0]>=d&&E[0]<=u&&E[1]>=c&&E[1]<=m||t.shiftKey&&s?.includes(x))&&f.push(x),f),[]).filter(f=>!(ee(l)&&f!==0&&f!==l.points.length-1));o({selectedLinearElement:{...r,selectedPointsIndices:g.length?g:null}})}static handlePointerMove(t,n,o,i,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elementId:l}=r,d=e.getElement(l,s);wt(d,"Element being dragged must exist in the scene"),wt(d.points.length>1,"Element must have at least 2 points");let c=d.points.length-1,u=d.points[c],m=d.points[c-1],h=r.customLineAngle??Hc(m,d.points[c]),g=0,f=0;if(mo(t)){let[v,A]=e._getShiftLockedDelta(d,s,m,U(o,i),t[po.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),h),k=U(v+m[0],A+m[1]);g=k[0]-u[0],f=k[1]-u[1]}else{let v=e.createPointAt(d,s,o-r.pointerOffset.x,i-r.pointerOffset.y,t[po.CTRL_OR_CMD]?null:n.getEffectiveGridSize());g=v[0]-u[0],f=v[1]-u[1]}let E=null,{positions:x,updates:y}=Fc([c],g,f,o,i,s,d,a,n,mo(t),t.altKey,r),b=mo(t);if(e.movePoints(d,n.scene,x,{startBinding:y?.startBinding,endBinding:y?.endBinding,moveMidPointsWithElement:y?.moveMidPointsWithElement},{isBindingEnabled:n.state.isBindingEnabled,isMidpointSnappingEnabled:n.state.isMidpointSnappingEnabled&&!b&&!n.state.gridModeEnabled}),Ke(d,!1)&&an(n.state)&&(E=y?.suggestedBinding??null),Ke(d)&&yi(e.getPointGlobalCoordinates(d,d.points[d.points.length-1],s),d,a,s,n.scene),n.state.selectedLinearElement?.customLineAngle===h&&r.initialState.altFocusPoint&&(!E||_f(n.state.suggestedBinding??[],E)))return null;let M=Ke(d)&&d.startBinding&&s.get(d.startBinding.elementId);return{selectedLinearElement:{...r,customLineAngle:h,initialState:{...r.initialState,altFocusPoint:!r.initialState.altFocusPoint&&M&&y?.suggestedBinding?.element.id!==M.id?So(d,U(d.x,d.y),M,"start",s,n.state.zoom,n.state.isMidpointSnappingEnabled&&!b&&!n.state.gridModeEnabled):r.initialState.altFocusPoint}},suggestedBinding:E}}static handlePointDragging(t,n,o,i,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elbowed:l,elementId:d,initialState:c}=r,u=Array.from(r.selectedPointsIndices??[]),{lastClickedPoint:m}=c,h=e.getElement(d,s);wt(h,"Element being dragged must exist in the scene"),wt(h.points.length>1,"Element must have at least 2 points"),wt(u,"There must be selected points in order to drag them"),l&&u.some((L,G)=>L>0&&L!==h.points.length-1?(u[G]=h.points.length-1,m=h.points.length-1,!0):!1),(m<0||!u.includes(m)||!h.points[m])&&(console.error(`There must be a valid lastClickedPoint in order to drag it. selectedPointsIndices(${JSON.stringify(u)}) points(0..${h.points.length-1}) lastClickedPoint(${m}) isElbowArrow: ${l}`),m=h.points.length-1);let g=h.points[m],f=h.points[m===0?1:m-1],E=u.length===1,x=r.customLineAngle??Hc(f,h.points[m]),y=u.includes(0),b=u.includes(h.points.length-1),M=0,w=0;if(mo(t)&&E){let[L,G]=e._getShiftLockedDelta(h,s,f,U(o,i),t[po.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),x),_=U(L+f[0],G+f[1]);M=_[0]-g[0],w=_[1]-g[1]}else{let L=e.createPointAt(h,s,o-r.pointerOffset.x,i-r.pointerOffset.y,t[po.CTRL_OR_CMD]?null:n.getEffectiveGridSize());M=L[0]-g[0],w=L[1]-g[1]}let v=null,{positions:A,updates:k}=Fc(u,M,w,o,i,s,h,a,n,mo(t)&&E,t.altKey,r),T=mo(t)&&E;e.movePoints(h,n.scene,A,{startBinding:k?.startBinding,endBinding:k?.endBinding,moveMidPointsWithElement:k?.moveMidPointsWithElement},{isBindingEnabled:n.state.isBindingEnabled,isMidpointSnappingEnabled:n.state.isMidpointSnappingEnabled&&!T&&!n.state.gridModeEnabled}),Ke(h,!1)&&an(n.state)&&(y||b)&&(v=k?.suggestedBinding??null),Ke(h)&&y!==b&&yi(e.getPointGlobalCoordinates(h,y?h.points[0]:h.points[h.points.length-1],s),h,a,s,n.scene),pe(h,s)&&lo(h,n.scene,!1);let C=l?b?[h.points.length-1]:[0]:u,O=l?C[0]:m,N=!y&&!b?e.getPointGlobalCoordinates(h,g,s):null,j=O,V=Ke(h)&&h.startBinding&&s.get(h.startBinding.elementId),D=Ke(h)&&h.endBinding&&s.get(h.endBinding.elementId),B=b&&V&&k?.suggestedBinding?.element.id!==V.id?V:y&&D&&k?.suggestedBinding?.element.id!==D.id?D:null;return{selectedLinearElement:{...r,selectedPointsIndices:C,initialState:{...r.initialState,lastClickedPoint:O,altFocusPoint:!r.initialState.altFocusPoint&&Ke(h)&&B?So(h,U(h.x,h.y),B,"start",s,n.state.zoom,n.state.isMidpointSnappingEnabled&&!T&&!n.state.gridModeEnabled):r.initialState.altFocusPoint},segmentMidPointHoveredCoords:N,hoverPointIndex:j,isDragging:!0,customLineAngle:x},suggestedBinding:v}}static handlePointerUp(t,n,o,i){let r=i.getNonDeletedElementsMap(),{elementId:s,selectedPointsIndices:a,isDragging:l,initialState:d}=n,c=e.getElement(s,r);if(!c)return n;if(l&&a)for(let u of a)(u===0||u===c.points.length-1)&&vt(c.points,o.zoom.value)&&(Ye(c)&&i.mutateElement(c,{...zc(c,!0)},{informMutation:!1,isDragging:!1}),e.movePoints(c,i,new Map([[u,{point:u===0?c.points[c.points.length-1]:c.points[0]}]])));return{...n,segmentMidPointHoveredCoords:null,hoverPointIndex:-1,selectedPointsIndices:l||t.shiftKey?!l&&t.shiftKey&&d.prevSelectedPointsIndices?.includes(d.lastClickedPoint)?a&&a.filter(u=>u!==d.lastClickedPoint):a:a?.includes(d.lastClickedPoint)?[d.lastClickedPoint]:a,isDragging:!1,customLineAngle:null,initialState:{...n.initialState,origin:null,arrowStartIsInside:!1,arrowOtherEndpointInitialBinding:null}}}static getEditorMidPoints=(t,n,o)=>{let i=pe(t,n);if(!ee(t)&&!o.selectedLinearElement?.isEditing&&t.points.length>2&&!i)return[];let r=e.getPointsGlobalCoordinates(t,n),s=0,a=[];for(;s<r.length-1;){if(e.isSegmentTooShort(t,t.points[s],t.points[s+1],s,o.zoom,n)){a.push(null),s++;continue}let l=e.getSegmentMidPoint(t,s+1,n);a.push(l),s++}return a};static getSegmentMidpointHitCoords=(t,n,o,i)=>{let{elementId:r}=t,s=e.getElement(r,i);if(!s)return null;let a=e.getPointIndexUnderCursor(s,i,o.zoom,n.x,n.y);if(!ee(s)&&a>=0||e.getPointsGlobalCoordinates(s,i).length>=3&&!o.selectedLinearElement?.isEditing&&!ee(s))return null;let d=(e.POINT_HANDLE_SIZE+1)/o.zoom.value,c=t.segmentMidPointHoveredCoords;if(c&&ho(U(c[0],c[1]),U(n.x,n.y))<=d)return c;let u=0,m=e.getEditorMidPoints(s,i,o);for(;u<m.length;){if(m[u]!==null&&ho(m[u],U(n.x,n.y))<=d)return m[u];u++}return null};static isSegmentTooShort(t,n,o,i,r,s){if(ee(t))return i>=0&&i<t.points.length?ho(n,o)*r.value<e.POINT_HANDLE_SIZE/2:!1;let a=ho(n,o);if(t.points.length>2&&t.roundness){let[l,d]=so(t,s);wt(l.length===0&&d.length>0,"Only linears built out of curves are supported"),wt(l.length+d.length>=i,"Invalid segment index while calculating mid point"),a=Ff(d[i])}return a*r.value<e.POINT_HANDLE_SIZE*4}static getSegmentMidPoint(t,n,o){if(ee(t)){wt(t.points.length>=n,"Invalid segment index while calculating elbow arrow mid point");let s=Nc(t.points[n-1],t.points[n]);return U(t.x+s[0],t.y+s[1])}let[i,r]=so(t,o);if(wt(i.length===0&&r.length>0||i.length>0&&r.length===0,"Only linears built out of either segments or curves are supported"),wt(i.length+r.length>=n,"Invalid segment index while calculating mid point"),i.length){let s=i[n-1];return Nc(s[0],s[1])}if(r.length){let s=r[n-1];return Hf(s,.5)}wt(!1,"Invalid segment type while calculating mid point")}static getSegmentMidPointIndex(t,n,o,i){let r=e.getElement(t.elementId,i);if(!r)return-1;let s=e.getEditorMidPoints(r,i,n),a=0;for(;a<s.length;){if(e.arePointsEqual(o,s[a]))return a+1;a++}return-1}static handlePointerDown(t,n,o,i,r,s){let a=n.state,l=s.getNonDeletedElementsMap(),d={didAddPoint:!1,hitElement:null,linearElementEditor:null};if(!r)return d;let{elementId:c}=r,u=e.getElement(c,l);if(!u)return d;let m=e.getSegmentMidpointHitCoords(r,i,a,l),h=U(i.x,i.y),g=null;if(m)g=e.getSegmentMidPointIndex(r,a,m,l);else if(t.altKey&&a.selectedLinearElement?.isEditing)return r.lastUncommittedPoint==null&&(s.mutateElement(u,{points:[...u.points,e.createPointAt(u,l,i.x,i.y,t[po.CTRL_OR_CMD]?null:n.getEffectiveGridSize())]}),d.didAddPoint=!0),o.scheduleCapture(),d.linearElementEditor={...r,initialState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:-1,origin:h,segmentMidpoint:{value:m,index:g,added:!1},arrowStartIsInside:!!n.state.newElement&&(n.state.bindMode==="inside"||n.state.bindMode==="skip"),altFocusPoint:null,arrowOtherEndpointInitialBinding:u.startBinding},selectedPointsIndices:[u.points.length-1],lastUncommittedPoint:null},d.didAddPoint=!0,d;let f=e.getPointIndexUnderCursor(u,l,a.zoom,i.x,i.y);(f>=0||m)&&(d.hitElement=u);let[E,x,y,b]=ae(u,l),M=(E+y)/2,w=(x+b)/2,v=f>-1&&ct(U(u.x+u.points[f][0],u.y+u.points[f][1]),U(M,w),u.angle),A=f>-1||t.shiftKey?t.shiftKey||r.selectedPointsIndices?.includes(f)?Wf([...r.selectedPointsIndices||[],f]):[f]:null;return d.linearElementEditor={...r,initialState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:f,origin:h,segmentMidpoint:{value:m,index:g,added:!1},arrowStartIsInside:!!n.state.newElement&&(n.state.bindMode==="inside"||n.state.bindMode==="skip"),altFocusPoint:null,arrowOtherEndpointInitialBinding:A?.includes(0)?u.endBinding:u.startBinding},selectedPointsIndices:A,pointerOffset:v?{x:i.x-v[0],y:i.y-v[1]}:{x:0,y:0}},d}static arePointsEqual(t,n){return!t&&!n?!0:!t||!n?!1:Oc(t,n)}static handlePointerMoveInEditMode(t,n,o,i){let r=i.state;if(!r.selectedLinearElement?.isEditing)return null;let{elementId:s,lastUncommittedPoint:a}=r.selectedLinearElement,l=i.scene.getNonDeletedElementsMap(),d=e.getElement(s,l);if(!d)return r.selectedLinearElement;let{points:c}=d,u=c[c.length-1];if(!t.altKey)return u===a&&e.deletePoints(d,i,[c.length-1]),r.selectedLinearElement?.lastUncommittedPoint?{...r.selectedLinearElement,lastUncommittedPoint:null}:r.selectedLinearElement;let m;if(mo(t)&&c.length>=2){let h=c[c.length-2],[g,f]=e._getShiftLockedDelta(d,l,h,U(n,o),t[po.CTRL_OR_CMD]?null:i.getEffectiveGridSize());m=U(g+h[0],f+h[1])}else m=e.createPointAt(d,l,n-r.selectedLinearElement.pointerOffset.x,o-r.selectedLinearElement.pointerOffset.y,t[po.CTRL_OR_CMD]||ee(d)?null:i.getEffectiveGridSize());return u===a?e.movePoints(d,i.scene,new Map([[d.points.length-1,{point:m}]])):e.addPoints(d,i.scene,[m]),{...r.selectedLinearElement,lastUncommittedPoint:d.points[d.points.length-1]}}static getPointGlobalCoordinates(t,n,o){let[i,r,s,a]=ae(t,o),l=(i+s)/2,d=(r+a)/2,{x:c,y:u}=t;return ct(U(c+n[0],u+n[1]),U(l,d),t.angle)}static getPointsGlobalCoordinates(t,n){let[o,i,r,s]=ae(t,n),a=(o+r)/2,l=(i+s)/2;return t.points.map(d=>{let{x:c,y:u}=t;return ct(U(c+d[0],u+d[1]),U(a,l),t.angle)})}static getPointAtIndexGlobalCoordinates(t,n,o){let i=n<0?t.points.length+n:n,[,,,,r,s]=ae(t,o),a=U(r,s),l=t.points[i],{x:d,y:c}=t;return l?ct(U(d+l[0],c+l[1]),a,t.angle):ct(U(d,c),a,t.angle)}static pointFromAbsoluteCoords(t,n,o){if(ee(t))return U(n[0]-t.x,n[1]-t.y);let[i,r,s,a]=ae(t,o),l=(i+s)/2,d=(r+a)/2,[c,u]=ct(U(n[0],n[1]),U(l,d),-t.angle);return U(c-t.x,u-t.y)}static getPointIndexUnderCursor(t,n,o,i,r){let s=e.getPointsGlobalCoordinates(t,n),a=s.length;for(;--a>-1;){let l=s[a];if(ho(U(i,r),U(l[0],l[1]))*o.value<e.POINT_HANDLE_SIZE+1)return a}return-1}static createPointAt(t,n,o,i,r){let s=Rc(o,i,r),[a,l,d,c]=ae(t,n),u=(a+d)/2,m=(l+c)/2,[h,g]=ct(U(s[0],s[1]),U(u,m),-t.angle);return U(h-t.x,g-t.y)}static getNormalizeElementPointsAndCoords(t){let{points:n,offsetX:o,offsetY:i}=ya(t);return{points:n,x:t.x+o,y:t.y+i}}static duplicateSelectedPoints(t,n){wt(t.selectedLinearElement?.isEditing,"Not currently editing a linear element");let o=n.getNonDeletedElementsMap(),{selectedPointsIndices:i,elementId:r}=t.selectedLinearElement,s=e.getElement(r,o);wt(s,"The linear element does not exist in the provided Scene"),wt(i!=null,"There are no selected points to duplicate");let{points:a}=s,l=[],d=!1,c=-1,u=a.reduce((m,h,g)=>{if(++c,m.push(h),i.includes(g)){let E=a[g+1];E||(d=!0),m.push(E?U((h[0]+E[0])/2,(h[1]+E[1])/2):U(h[0],h[1])),l.push(c+1),++c}return m},[]);if(n.mutateElement(s,{points:u}),d){let m=s.points[s.points.length-1];e.movePoints(s,n,new Map([[s.points.length-1,{point:U(m[0]+30,m[1]+30)}]]))}return{...t,selectedLinearElement:{...t.selectedLinearElement,selectedPointsIndices:l}}}static deletePoints(t,n,o){let i=n.state.selectedLinearElement?.isEditing&&n.state.selectedLinearElement?.lastUncommittedPoint===t.points[t.points.length-1],r=t.points.filter((c,u)=>!o.includes(u));Ye(t)&&t.polygon&&(i||o.includes(0)||o.includes(t.points.length-1))&&(r[0]=U(r[r.length-1][0],r[r.length-1][1]));let{points:a,offsetX:l,offsetY:d}=ya({points:r});e._updatePoints(t,n.scene,a,l,d)}static addPoints(t,n,o){let i=[...t.points,...o];Ye(t)&&t.polygon&&(i[0]=U(i[i.length-1][0],i[i.length-1][1]));let{points:r,offsetX:s,offsetY:a}=ya({points:i});e._updatePoints(t,n,r,s,a)}static movePoints(t,n,o,i,r){let{points:s}=t;if(Ye(t)&&t.polygon){let u=o.get(0),m=o.get(s.length-1);u?o.set(s.length-1,{point:U(u.point[0],u.point[1]),isDragging:u.isDragging}):m&&o.set(0,{point:U(m.point[0],m.point[1]),isDragging:m.isDragging})}let a=o.get(0)?.point??U(0,0),[l,d]=a,c=ee(t)?[o.get(0)?.point??s[0],o.get(s.length-1)?.point??s[s.length-1]]:s.map((u,m)=>{let h=o.get(m)?.point??u;return i?.moveMidPointsWithElement&&m!==0&&m!==s.length-1&&!o.has(m)?h:U(h[0]-l,h[1]-d)});e._updatePoints(t,n,c,l,d,i,{isDragging:Array.from(o.values()).some(u=>u.isDragging),isBindingEnabled:r?.isBindingEnabled,isMidpointSnappingEnabled:r?.isMidpointSnappingEnabled})}static shouldAddMidpoint(t,n,o,i){let r=e.getElement(t.elementId,i);if(r&&ee(r)||!r)return!1;let{segmentMidpoint:s}=t.initialState;if(s.added||s.value===null||s.index===null||t.initialState.origin===null)return!1;let a=t.initialState.origin,l=ho(a,U(n.x,n.y));return!(!o.selectedLinearElement?.isEditing&&l<zf/o.zoom.value)}static addMidpoint(t,n,o,i,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a)return;let{segmentMidpoint:l}=t.initialState,d={pointerDownState:t.initialState,selectedPointsIndices:t.selectedPointsIndices},c=e.createPointAt(a,s,n.x,n.y,i&&!ee(a)?o.getEffectiveGridSize():null),u=[...a.points.slice(0,l.index),c,...a.points.slice(l.index)];return r.mutateElement(a,{points:u}),d.pointerDownState={...t.initialState,segmentMidpoint:{...t.initialState.segmentMidpoint,added:!0},lastClickedPoint:l.index},d.selectedPointsIndices=[l.index],d}static _updatePoints(t,n,o,i,r,s,a){if(ee(t)){let l={};s?.startBinding!==void 0&&(l.startBinding=s.startBinding),s?.endBinding!==void 0&&(l.endBinding=s.endBinding),l.points=Array.from(o),n.mutateElement(t,l,{informMutation:!0,isDragging:a?.isDragging??!1,isBindingEnabled:a?.isBindingEnabled,isMidpointSnappingEnabled:a?.isMidpointSnappingEnabled})}else{let l=ba(t,o),d=ba(t,t.points),c=(l[0]+l[2])/2,u=(l[1]+l[3])/2,m=(d[0]+d[2])/2,h=(d[1]+d[3])/2,g=m-c,f=h-u,E=ct(U(i,r),U(g,f),t.angle);n.mutateElement(t,{...s,points:o,x:t.x+E[0],y:t.y+E[1]})}}static _getShiftLockedDelta(t,n,o,i,r,s){let a=e.getPointGlobalCoordinates(t,o,n);if(ee(t))return[i[0]-a[0],i[1]-a[1]];let[l,d]=Rc(i[0],i[1],r),{width:c,height:u}=_c(a[0],a[1],l,d,s);return ct(U(c,u),U(0,0),-t.angle)}static getBoundTextElementCenter=(t,n)=>{if(t.points.length%2===1){let i=Math.floor(t.points.length/2);return e.getPointGlobalCoordinates(t,t.points[i],n)}let o=t.points.length/2-1;return e.getSegmentMidPoint(t,o+1,n)};static getBoundTextElementPosition=(t,n,o)=>{e.getPointsGlobalCoordinates(t,o).length<2&&$e(n,o,{isDeleted:!0});let r=e.getBoundTextElementCenter(t,o);return{x:r[0]-n.width/2,y:r[1]-n.height/2}};static getMinMaxXYWithBoundText=(t,n,o,i)=>{let[r,s,a,l]=o,d=(r+a)/2,c=(s+l)/2,{x:u,y:m}=e.getBoundTextElementPosition(t,i,n),h=u+i.width,g=m+i.height,f=U(d,c),E=ct(U(r,s),f,t.angle),x=ct(U(a,s),f,t.angle),y=ct(U(u,m),f,-t.angle),b=ct(U(h,m),f,-t.angle),M=ct(U(u,g),f,-t.angle),w=ct(U(h,g),f,-t.angle);return E[0]<x[0]&&E[1]>=x[1]?(r=Math.min(r,M[0]),a=Math.max(a,Math.max(b[0],w[0])),s=Math.min(s,y[1]),l=Math.max(l,w[1])):E[0]>=x[0]&&E[1]>x[1]?(r=Math.min(r,w[0]),a=Math.max(a,Math.max(y[0],b[0])),s=Math.min(s,M[1]),l=Math.max(l,b[1])):E[0]>=x[0]?(r=Math.min(r,b[0]),a=Math.max(a,M[0]),s=Math.min(s,w[1]),l=Math.max(l,y[1])):E[1]<=x[1]&&(r=Math.min(r,Math.min(b[0],y[0])),a=Math.max(a,w[0]),s=Math.min(s,b[1]),l=Math.max(l,M[1])),[r,s,a,l,d,c]};static getElementAbsoluteCoords=(t,n,o=!1)=>{let i=Lt.generateElementShape(t,null),r=pn(i[0]),[s,a,l,d]=bi(r),c=s+t.x,u=a+t.y,m=l+t.x,h=d+t.y,g=(c+m)/2,f=(u+h)/2,E=o&&pe(t,n);return E?e.getMinMaxXYWithBoundText(t,n,[c,u,m,h],E):[c,u,m,h,g,f]};static moveFixedSegment(t,n,o,i,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a||!ee(a))return t;if(n&&n>0&&n<a.points.length){let l=yt(rn(Rf(a.points[n],a.points[n-1]))),d=(a.fixedSegments??[]).reduce((h,g)=>(h[g.index]=g,h),{});d[n]={index:n,start:U(l?a.points[n-1][0]:o-a.x,l?i-a.y:a.points[n-1][1]),end:U(l?a.points[n][0]:o-a.x,l?i-a.y:a.points[n][1])};let c=Object.values(d).sort((h,g)=>h.index-g.index),u=c.map(h=>h.index).reduce((h,g)=>g<n?h+1:h,0);r.mutateElement(a,{fixedSegments:c});let m=U(a.x+(a.fixedSegments[u].start[0]+a.fixedSegments[u].end[0])/2,a.y+(a.fixedSegments[u].start[1]+a.fixedSegments[u].end[1])/2);return{...t,segmentMidPointHoveredCoords:m,initialState:{...t.initialState,segmentMidpoint:{added:!1,index:a.fixedSegments[u].index,value:m}}}}return t}static deleteFixedSegment(t,n,o){n.mutateElement(t,{fixedSegments:t.fixedSegments?.filter(i=>i.index!==o)})}},Wf=e=>{let t=[...new Set(e.filter(n=>n!==null&&n!==-1))];return t=t.sort((n,o)=>n-o),t.length?t:null},Fc=(e,t,n,o,i,r,s,a,l,d,c,u)=>{let m=new Map(e.map(V=>{let D=s.points[V]??s.points.at(-1);return[V,{point:U(D[0]+t,D[1]+n),isDragging:!0}]}));if(!J(s))return{positions:m};let h=e.includes(0),g=e.includes(s.points.length-1),{start:f,end:E}=sa(s,m,o,i,r,a,l.state,{newArrow:!!l.state.newElement,angleLocked:d,altKey:c,gridSize:l.getEffectiveGridSize()});if(ee(s)){let V=h?f.element:g?E.element:null;return{positions:m,updates:{suggestedBinding:V?{element:V,midPoint:l.state.isMidpointSnappingEnabled?aa(V,r,U(o-u.pointerOffset.x,i-u.pointerOffset.y)):void 0}:null}}}if(!h&&!g){let V={...s,points:s.points.map((B,I)=>m.get(I)?.point??B)},D=new Map(m);if(s.startBinding){let B=r.get(s.startBinding.elementId);if(B){let I=Yt(V,"startBinding",s.startBinding,B,r)??null;I&&D.set(0,{point:I,isDragging:!0})}}if(s.endBinding){let B=r.get(s.endBinding.elementId);if(B){let I=Yt(V,"endBinding",s.endBinding,B,r)??null;I&&D.set(s.points.length-1,{point:I,isDragging:!0})}}return{positions:D}}if(h===g)return{positions:m};let x={suggestedBinding:null};f.mode===null?x.startBinding=null:f.mode?(x.startBinding={elementId:f.element.id,mode:f.mode,...Go(s,f.element,"start",r,f.focusPoint)},h&&(x.startBinding.mode==="orbit"||!Ro("COMPLEX_BINDINGS"))&&(x.suggestedBinding=f.element?{element:f.element,midPoint:er(U(o-u.pointerOffset.x,i-u.pointerOffset.y),f.element,r,l.state.zoom)}:null)):h&&(x.suggestedBinding=l.state.suggestedBinding),E.mode===null?x.endBinding=null:E.mode?(x.endBinding={elementId:E.element.id,mode:E.mode,...Go(s,E.element,"end",r,E.focusPoint)},g&&(x.endBinding.mode==="orbit"||!Ro("COMPLEX_BINDINGS"))&&(x.suggestedBinding=E.element?{element:E.element,midPoint:er(U(o-u.pointerOffset.x,i-u.pointerOffset.y),E.element,r,l.state.zoom)}:null)):g&&(x.suggestedBinding=l.state.suggestedBinding);let y=h?U(s.points[0][0]+t,s.points[0][1]+n):s.points[0],b=g?U(s.points[s.points.length-1][0]+t,s.points[s.points.length-1][1]+n):s.points[s.points.length-1],M={...s,points:[y,...s.points.slice(1,-1),b],startBinding:x.startBinding===void 0?s.startBinding:x.startBinding===null?null:x.startBinding,endBinding:x.endBinding===void 0?s.endBinding:x.endBinding===null?null:x.endBinding},w=s.endBinding&&M.startBinding&&h&&M.startBinding.elementId===s.endBinding.elementId,v=s.startBinding&&M.endBinding&&g&&s.startBinding.elementId===M.endBinding.elementId,A=M.endBinding?E.element??r.get(M.endBinding.elementId):null,k=v&&l.state.bindMode!=="inside"&&Ro("COMPLEX_BINDINGS")?M.points[0]:A&&Yt(M,"endBinding",M.endBinding,A,r,g)||M.points[M.points.length-1];M.points[M.points.length-1]=k;let T=M.startBinding?f.element??r.get(M.startBinding.elementId):null,z=v&&Ro("COMPLEX_BINDINGS")?M.points[0]:w&&l.state.bindMode!=="inside"&&Ro("COMPLEX_BINDINGS")?k:T&&Yt(M,"startBinding",M.startBinding,T,r,h)||M.points[0],C=!(v&&l.state.bindMode!=="inside"&&Ro("COMPLEX_BINDINGS"))&&!!A,O=ho(z,M.points[0])!==0,N=new Set(e);T&&O&&N.add(0),A&&C&&N.add(s.points.length-1);let j=Array.from(N);return{updates:x,positions:new Map(j.map(V=>[V,V===0?{point:z,isDragging:!0}:V===s.points.length-1?{point:k,isDragging:!0}:m.get(V)]))}},Hc=(e,t)=>Math.atan2(t[1]-e[1],t[0]-e[0]);S();import{MIME_TYPES as Yc,SVG_NS as Vf}from"@excalidraw/common";S();function Wc(e,t,n){if(e>100||t>100)throw new Error(`${e}x${t} doesn't fit in 100x100`);let{PI:o,round:i,max:r,cos:s,abs:a}=Math,l=0,d=0,c=0,u=0;for(let $=0,X=0;$<e*t;$++,X+=4){let Y=n[X+3]/255;l+=Y/255*n[X],d+=Y/255*n[X+1],c+=Y/255*n[X+2],u+=Y}u&&(l/=u,d/=u,c/=u);let m=u<e*t,h=m?5:7,g=r(1,i(h*e/r(e,t))),f=r(1,i(h*t/r(e,t))),E=[],x=[],y=[],b=[];for(let $=0,X=0;$<e*t;$++,X+=4){let Y=n[X+3]/255,we=l*(1-Y)+Y/255*n[X],Q=d*(1-Y)+Y/255*n[X+1],me=c*(1-Y)+Y/255*n[X+2];E[$]=(we+Q+me)/3,x[$]=(we+Q)/2-me,y[$]=we-Q,b[$]=Y}let M=($,X,Y)=>{let we=0,Q=[],me=0,Ae=[];for(let ne=0;ne<Y;ne++)for(let ie=0;ie*Y<X*(Y-ne);ie++){let Ie=0;for(let ye=0;ye<e;ye++)Ae[ye]=s(o/e*ie*(ye+.5));for(let ye=0;ye<t;ye++)for(let He=0,Rt=s(o/t*ne*(ye+.5));He<e;He++)Ie+=$[He+ye*e]*Ae[He]*Rt;Ie/=e*t,ie||ne?(Q.push(Ie),me=r(me,a(Ie))):we=Ie}if(me)for(let ne=0;ne<Q.length;ne++)Q[ne]=.5+.5/me*Q[ne];return[we,Q,me]},[w,v,A]=M(E,r(3,g),r(3,f)),[k,T,z]=M(x,3,3),[C,O,N]=M(y,3,3),[j,V,D]=m?M(b,5,5):[],B=e>t,I=i(63*w)|i(31.5+31.5*k)<<6|i(31.5+31.5*C)<<12|i(31*A)<<18|m<<23,L=(B?f:g)|i(63*z)<<3|i(63*N)<<9|B<<15,G=[I&255,I>>8&255,I>>16,L&255,L>>8],_=m?6:5,K=0;m&&G.push(i(15*j)|i(15*D)<<4);for(let $ of m?[v,T,O,V]:[v,T,O])for(let X of $)G[_+(K>>1)]|=i(15*X)<<((K++&1)<<2);return new Uint8Array(G)}function jc(e){let{PI:t,min:n,max:o,cos:i,round:r}=Math,s=e[0]|e[1]<<8|e[2]<<16,a=e[3]|e[4]<<8,l=(s&63)/63,d=(s>>6&63)/31.5-1,c=(s>>12&63)/31.5-1,u=(s>>18&31)/31,m=s>>23,h=(a>>3&63)/63,g=(a>>9&63)/63,f=a>>15,E=o(3,f?m?5:7:a&7),x=o(3,f?a&7:m?5:7),y=m?(e[5]&15)/15:1,b=(e[5]>>4)/15,M=m?6:5,w=0,v=(B,I,L)=>{let G=[];for(let _=0;_<I;_++)for(let K=_?0:1;K*I<B*(I-_);K++)G.push(((e[M+(w>>1)]>>((w++&1)<<2)&15)/7.5-1)*L);return G},A=v(E,x,u),k=v(3,3,h*1.25),T=v(3,3,g*1.25),z=m&&v(5,5,b),C=jf(e),O=r(C>1?32:32*C),N=r(C>1?32/C:32),j=new Uint8Array(O*N*4),V=[],D=[];for(let B=0,I=0;B<N;B++)for(let L=0;L<O;L++,I+=4){let G=l,_=d,K=c,$=y;for(let Q=0,me=o(E,m?5:3);Q<me;Q++)V[Q]=i(t/O*(L+.5)*Q);for(let Q=0,me=o(x,m?5:3);Q<me;Q++)D[Q]=i(t/N*(B+.5)*Q);for(let Q=0,me=0;Q<x;Q++)for(let Ae=Q?0:1,ne=D[Q]*2;Ae*x<E*(x-Q);Ae++,me++)G+=A[me]*V[Ae]*ne;for(let Q=0,me=0;Q<3;Q++)for(let Ae=Q?0:1,ne=D[Q]*2;Ae<3-Q;Ae++,me++){let ie=V[Ae]*ne;_+=k[me]*ie,K+=T[me]*ie}if(m)for(let Q=0,me=0;Q<5;Q++)for(let Ae=Q?0:1,ne=D[Q]*2;Ae<5-Q;Ae++,me++)$+=z[me]*V[Ae]*ne;let X=G-2/3*_,Y=(3*G-X+K)/2,we=Y-K;j[I]=o(0,255*n(1,Y)),j[I+1]=o(0,255*n(1,we)),j[I+2]=o(0,255*n(1,X)),j[I+3]=o(0,255*n(1,$))}return{w:O,h:N,rgba:j}}function jf(e){let t=e[3],n=e[2]&128,o=e[4]&128,i=o?n?5:7:t&7,r=o?t&7:n?5:7;return i/r}var Uf=100,Vc=new Map,Uc=new Set,Yf=e=>{let t="";for(let n of e)t+=String.fromCharCode(n);return btoa(t)},Xf=e=>{let t=atob(e),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n},K4=e=>{let t=e.naturalWidth||e.width,n=e.naturalHeight||e.height;if(!t||!n)return null;let o=Math.min(1,Uf/Math.max(t,n)),i=Math.max(1,Math.round(t*o)),r=Math.max(1,Math.round(n*o)),s=document.createElement("canvas");s.width=i,s.height=r;let a=s.getContext("2d");if(!a)return null;a.drawImage(e,0,0,i,r);let l=a.getImageData(0,0,i,r);return Yf(Wc(i,r,l.data))},Xc=e=>{if(Uc.has(e))return null;let t=Vc.get(e);if(t)return t;try{let{w:n,h:o,rgba:i}=jc(Xf(e)),r=document.createElement("canvas");r.width=n,r.height=o;let s=r.getContext("2d");if(!s)return null;let a=s.createImageData(n,o);return a.data.set(i),s.putImageData(a,0,0),Vc.set(e,r),r}catch(n){return Uc.add(e),console.warn("Invalid ThumbHash",n),null}},$f=e=>new Promise((t,n)=>{let o=new Image;o.onload=()=>{t(o)},o.onerror=i=>{n(i)},o.src=e}),Q4=async({fileIds:e,files:t,imageCache:n})=>{let o=new Map,i=new Map;return await Promise.all(e.reduce((r,s)=>{let a=t[s];return a&&!o.has(s)?(o.set(s,!0),r.concat((async()=>{try{if(a.mimeType===Yc.binary)throw new Error("Only images can be added to ImageCache");let l=n.get(s),d=$f(a.dataURL),c={image:d,mimeType:a.mimeType};n.set(s,c);let u=await d;l?.isPlaceholder?n.set(s,{...c,image:u,placeholderImage:await l.image,transitionStart:performance.now()}):n.set(s,{...c,image:u})}catch{i.set(s,!0)}})())):r},[])),{imageCache:n,updatedFiles:o,erroredFiles:i}},J4=e=>e.filter(t=>Dn(t)),Zf=e=>e?.nodeName.toLowerCase()==="svg",e5=e=>{let t=new DOMParser().parseFromString(e,Yc.svg),n=t.querySelector("svg");if(t.querySelector("parsererror")||!Zf(n))throw new Error("Invalid SVG");{n.hasAttribute("xmlns")||n.setAttribute("xmlns",Vf);let i=n.getAttribute("width"),r=n.getAttribute("height");(i?.includes("%")||i==="auto")&&(i=null),(r?.includes("%")||r==="auto")&&(r=null);let s=n.getAttribute("viewBox");if(!i||!r){if(i=i||"50",r=r||"50",s){let a=s.match(/\d+ +\d+ +(\d+(?:\.\d+)?) +(\d+(?:\.\d+)?)/);a&&([,i,r]=a)}n.setAttribute("width",i),n.setAttribute("height",r)}return s||n.setAttribute("viewBox",`0 0 ${i} ${r}`),n.outerHTML}};var r0=(e,t)=>Dn(e)&&!t.imageCache.has(e.fileId),Br=e=>{switch(e.type){case"freedraw":return e.strokeWidth*12;case"text":return e.fontSize/2;case"arrow":return e.endArrowhead||e.endArrowhead?40:20;default:return 20}},s0=(e,t,n,o,i=1)=>{let r=(t?.opacity??100)*e.opacity/1e4*i;return(n.has(e.id)||o&&o.some(s=>s.id===e.id)||t&&n.has(t.id))&&(r*=Qf/100),r},a0=(e,t,n)=>{let r=Br(e),[s,a,l,d]=ae(e,t),c=le(e)||Le(e)?Xn(s,l):e.width,u=le(e)||Le(e)?Xn(a,d):e.height,m=c*window.devicePixelRatio+r*2,h=u*window.devicePixelRatio+r*2,g=n.value;return(m*g>32767||h*g>32767)&&(g=Math.min(32767/m,32767/h)),m*h*g*g>16777216&&(g=Math.sqrt(16777216/(m*h))),m=Math.floor(m*g),h=Math.floor(h*g),{width:m,height:h,scale:g}},Kc=(e,t,n,o,i)=>{let r=document.createElement("canvas"),s=r.getContext("2d"),a=Br(e),{width:l,height:d,scale:c}=a0(e,t,n);if(!l||!d)return null;r.width=l,r.height=d;let u=-100,m=0;if(le(e)||Le(e)){let[g,f]=ae(e,t);u=e.x>g?Xn(e.x,g)*window.devicePixelRatio*c:0,m=e.y>f?Xn(e.y,f)*window.devicePixelRatio*c:0,s.translate(u,m)}s.save(),s.translate(a*c,a*c),s.scale(window.devicePixelRatio*c,window.devicePixelRatio*c);let h=Mo.canvas(r);return Dr(e,h,s,o),s.restore(),{element:e,canvas:r,theme:i.theme,scale:c,zoomValue:n.value,canvasOffsetX:u,canvasOffsetY:m,containingFrameOpacity:Wn(e,t)?.opacity||100,imageCrop:Ue(e)?e.crop:null}},g5=14,Qc=typeof document<"u"?document.createElement("img"):{src:""};Qc.src=`data:${Pa.svg},${encodeURIComponent('<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="image" class="svg-inline--fa fa-image fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="#888" d="M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48zM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56zM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48z"></path></svg>')}`;var Jc=typeof document<"u"?document.createElement("img"):{src:""};Jc.src=`data:${Pa.svg},${encodeURIComponent('<svg viewBox="0 0 668 668" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2"><path d="M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48ZM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56ZM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48Z" style="fill:#888;fill-rule:nonzero" transform="matrix(.81709 0 0 .81709 124.825 145.825)"/><path d="M256 8C119.034 8 8 119.033 8 256c0 136.967 111.034 248 248 248s248-111.034 248-248S392.967 8 256 8Zm130.108 117.892c65.448 65.448 70 165.481 20.677 235.637L150.47 105.216c70.204-49.356 170.226-44.735 235.638 20.676ZM125.892 386.108c-65.448-65.448-70-165.481-20.677-235.637L361.53 406.784c-70.203 49.356-170.226 44.736-235.638-20.676Z" style="fill:#888;fill-rule:nonzero" transform="matrix(.30366 0 0 .30366 506.822 60.065)"/></svg>')}`;var Zc=(e,t,n)=>{if(e.status!=="error"&&e.thumbHash){let r=Xc(e.thumbHash);if(r){t.drawImage(r,0,0,e.width,e.height);return}}t.fillStyle=n===Fo.DARK?"#2E2E2E":"#E7E7E7",t.fillRect(0,0,e.width,e.height);let o=Math.min(e.width,e.height),i=Math.min(o,Math.min(o*.4,100));t.drawImage(e.status==="error"?Jc:Qc,e.width/2-i/2,e.height/2-i/2,i,i)},Dr=(e,t,n,o)=>{switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":{n.lineJoin="round",n.lineCap="round",t.draw(Lt.generateElementShape(e,o));break}case"arrow":case"line":{n.lineJoin="round",n.lineCap="round",Lt.generateElementShape(e,o).forEach(i=>{t.draw(i)});break}case"freedraw":{n.save();let i=Lt.generateElementShape(e,o);for(let r of i)typeof r=="string"?(n.fillStyle=Cr(e.strokeColor,o.theme===Fo.DARK),n.fill(new Path2D(r))):t.draw(r);n.restore();break}case"image":{n.save();let i=e.fileId!==null?o.imageCache.get(e.fileId):null,r=Dn(e)?i?.image:void 0;if(r!=null&&!(r instanceof Promise)){e.roundness&&n.roundRect&&(n.beginPath(),n.roundRect(0,0,e.width,e.height,fn(Math.min(e.width,e.height),e)),n.clip());let s=o.imageTransitionDuration??0;if(!o.isExporting&&i?.transitionStart!==void 0)if(s>0){let m=Math.min(1,(performance.now()-i.transitionStart)/s);m<1?(i.placeholderImage?n.drawImage(i.placeholderImage,0,0,e.width,e.height):Zc(e,n,o.theme),n.globalAlpha*=m):(delete i.placeholderImage,delete i.transitionStart)}else delete i.placeholderImage,delete i.transitionStart;let{x:a,y:l,width:d,height:c}=e.crop?e.crop:{x:0,y:0,width:r.naturalWidth,height:r.naturalHeight},u=o.theme===Fo.DARK&&i?.mimeType===Pa.svg;if(u&&i0){let m=window.devicePixelRatio||1,h=document.createElement("canvas");h.width=e.width*m,h.height=e.height*m;let g=h.getContext("2d");if(g){g.scale(m,m),g.drawImage(r,a,l,d,c,0,0,e.width,e.height);let f=g.getImageData(0,0,h.width,h.height),E=f.data;for(let x=0;x<E.length;x+=4)E[x]=255-E[x],E[x+1]=255-E[x+1],E[x+2]=255-E[x+2];g.putImageData(f,0,0),n.drawImage(h,0,0,h.width,h.height,0,0,e.width,e.height)}}else u&&(n.filter=Jf),n.drawImage(r,a,l,d,c,0,0,e.width,e.height)}else Zc(e,n,o.theme);n.restore();break}default:if(ue(e)){let i=t0(e.text),r=i&&!n.canvas.isConnected;r&&document.body.appendChild(n.canvas),n.canvas.setAttribute("dir",i?"rtl":"ltr"),n.save(),n.font=e0(e),n.fillStyle=Cr(e.strokeColor,o.theme===Fo.DARK),n.textAlign=e.textAlign;let s=e.text.replace(/\r\n?/g,`
13
13
  `).split(`
14
14
  `),a=e.textAlign==="center"?e.width/2:e.textAlign==="right"?e.width:0,l=ir(e.fontSize,e.lineHeight),d=n0(e.fontFamily,e.fontSize,l);for(let c=0;c<s.length;c++)n.fillText(s[c],a,c*l+d);n.restore(),r&&n.canvas.remove()}else throw new Error(`Unimplemented type ${e.type}`)}},wi=new WeakMap,qc=(e,t,n,o)=>{let i=n?o.zoom:{value:1},r=wi.get(e),s=r&&r.zoomValue!==i.value&&!o?.shouldCacheIgnoreZoom,a=Ue(e)?e.crop:null,l=Dn(e)&&n.imageCache.get(e.fileId)?.transitionStart!==void 0,d=Wn(e,t)?.opacity||100;if(!r||s||r.theme!==o.theme||r.imageCrop!==a||l||r.containingFrameOpacity!==d){let c=Kc(e,t,i,n,o);return c?(wi.set(e,c),c):null}return r},Ma=(e,t,n,o,i)=>{let r=e.element,s=Br(r),[a,l,d,c]=ae(r,i),u=((a+d)/2+o.scrollX)*window.devicePixelRatio,m=((l+c)/2+o.scrollY)*window.devicePixelRatio;t.save(),t.scale(1/window.devicePixelRatio,1/window.devicePixelRatio);let h=pe(r,i);if(J(r)&&h){let[,,,,g,f]=ae(h,i),E=Math.max(Xn(a,d),Xn(l,c))*window.devicePixelRatio+s*10;t.beginPath(),t.rect(u-E,m-E,E*2,E*2),t.rect((g-h.width/2-Yn+o.scrollX)*window.devicePixelRatio,(f-h.height/2-Yn+o.scrollY)*window.devicePixelRatio,(h.width+Yn*2)*window.devicePixelRatio,(h.height+Yn*2)*window.devicePixelRatio),t.clip("evenodd")}if(t.translate(u,m),t.rotate(r.angle),"scale"in e.element&&!r0(r,n)&&t.scale(e.element.scale[0],e.element.scale[1]),t.translate(-u,-m),t.drawImage(e.canvas,(a+o.scrollX)*window.devicePixelRatio-s*e.scale/e.scale,(l+o.scrollY)*window.devicePixelRatio-s*e.scale/e.scale,e.canvas.width/e.scale,e.canvas.height/e.scale),F.VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX==="true"&&Jt(r)){let g=pe(r,i),f=Ns(r);t.strokeStyle="#c92a2a",t.lineWidth=3,t.strokeRect((f.x+o.scrollX)*window.devicePixelRatio,(f.y+o.scrollY)*window.devicePixelRatio,jt(r,g)*window.devicePixelRatio,mi(r,g)*window.devicePixelRatio)}t.restore()},E5=(e,t,n,o)=>{t.save(),t.translate(e.x+n.scrollX,e.y+n.scrollY),t.fillStyle="rgba(0, 0, 200, 0.04)";let i=.5/n.zoom.value;t.fillRect(i,i,e.width,e.height),t.lineWidth=1/n.zoom.value,t.strokeStyle=o,t.strokeRect(i,i,e.width,e.height),t.restore()},x5=(e,t,n,o,i,r,s)=>{let a=s.openDialog?.name==="elementLinkSelector"&&!s.selectedElementIds[e.id]&&!s.hoveredElementIds[e.id];switch(i.globalAlpha=s0(e,Wn(e,t),r.elementsPendingErasure,r.pendingFlowchartNodes,a?Kf:1),e.type){case"magicframe":case"frame":{s.frameRendering.enabled&&s.frameRendering.outline&&(i.save(),i.translate(e.x+s.scrollX,e.y+s.scrollY),i.fillStyle="rgba(0, 0, 200, 0.04)",i.lineWidth=Lr.strokeWidth/s.zoom.value,i.strokeStyle=Cr(Lr.strokeColor,s.theme===Fo.DARK),td(e)&&(i.strokeStyle=s.theme===Fo.LIGHT?"#7affd7":Cr("#1d8264")),Lr.radius&&i.roundRect?(i.beginPath(),i.roundRect(0,0,e.width,e.height,Lr.radius/s.zoom.value),i.stroke(),i.closePath()):i.strokeRect(0,0,e.width,e.height),i.restore());break}case"freedraw":{if(r.isExporting){let[l,d,c,u]=ae(e,t),m=(l+c)/2+s.scrollX,h=(d+u)/2+s.scrollY,g=(c-l)/2-(e.x-l),f=(u-d)/2-(e.y-d);i.save(),i.translate(m,h),i.rotate(e.angle),i.translate(-g,-f),Dr(e,o,i,r),i.restore()}else{let l=qc(e,n,r,s);if(!l)return;Ma(l,i,r,s,n)}break}case"rectangle":case"diamond":case"ellipse":case"line":case"arrow":case"image":case"text":case"iframe":case"embeddable":{if(r.isExporting){let[l,d,c,u]=ae(e,t),m=(l+c)/2,h=(d+u)/2,g=m+s.scrollX,f=h+s.scrollY,E=(c-l)/2-(e.x-l),x=(u-d)/2-(e.y-d);if(ue(e)){let b=et(e,t);if(J(b)){let M=W.getBoundTextElementPosition(b,e,t);E=(c-l)/2-(M.x-l),x=(u-d)/2-(M.y-d)}}i.save(),i.translate(g,f);let y=pe(e,t);if(J(e)&&y){E=e.width/2-(e.x-l),x=e.height/2-(e.y-d);let[,,,,b,M]=ae(y,t),w=b-m-y.width/2-Yn,v=M-h-y.height/2-Yn,A=y.width+Yn*2,k=y.height+Yn*2,T=Math.max(Xn(l,c),Xn(d,u))+Br(e)*10;i.save(),i.beginPath(),i.rect(-T,-T,T*2,T*2),i.rect(w,v,A,k),i.clip("evenodd"),i.rotate(e.angle),i.translate(-E,-x),Dr(e,o,i,r),i.restore()}else i.rotate(e.angle),e.type==="image"&&i.scale(e.scale[0],e.scale[1]),i.translate(-E,-x),Dr(e,o,i,r);i.restore()}else{let l=qc(e,n,r,s);if(!l)return;let d=i.imageSmoothingEnabled;if(!s?.shouldCacheIgnoreZoom&&(!e.angle||qf(e.angle))&&(i.imageSmoothingEnabled=!1),e.id===s.croppingElementId&&Ue(l.element)&&l.element.crop!==null){i.save(),i.globalAlpha=.1;let c=Kc(Ql(l.element,t),n,s.zoom,r,s);c&&Ma(c,i,r,s,n),i.restore()}Ma(l,i,r,s,n),i.imageSmoothingEnabled=d}break}default:throw new Error(`Unimplemented type ${e.type}`)}i.globalAlpha=1};function y5(e,t,n){let o=be({...e,angle:0},n),i=kr((o[0]+o[2])/2,(o[1]+o[3])/2);return o0(t.length>=2,"Freepath outline must have at least 2 points"),t.slice(2).reduce((r,s)=>(r.push($c(r[r.length-1][1],wa(kr(s[0]+e.x,s[1]+e.y),i,e.angle))),r),[$c(wa(kr(t[0][0]+e.x,t[0][1]+e.y),i,e.angle),wa(kr(t[1][0]+e.x,t[1][1]+e.y),i,e.angle))])}var Lt=class e{static rg=new Ct;static cache=new WeakMap;static get=(t,n)=>{let o=e.cache.get(t);if(o&&(n===null||o.theme===n))return o.shape};static delete=t=>{e.cache.delete(t),wi.delete(t)};static destroy=()=>{e.cache=new WeakMap};static generateElementShape=(t,n)=>{let o=n?.isExporting?void 0:e.get(t,n?n.theme:null);if(o!==void 0)return o;wi.delete(t);let i=f0(t,e.rg,n||{isExporting:!1,canvasBackgroundColor:c0.white,embedsValidationStatus:null,theme:Sa.LIGHT});return n?.isExporting||e.cache.set(t,{shape:i,theme:n?.theme||Sa.LIGHT}),i}},m0=e=>[8,8+e],iu=e=>[1.5,6+e];function h0(e){let t=e.roughness,n=Math.max(e.width,e.height),o=Math.min(e.width,e.height);return o>=20&&n>=50||o>=15&&e.roundness&&Pd(e.type)||le(e)&&n>=50?t:Math.min(t/(n<10?3:2),2.5)}var Mt=(e,t=!1,n=!1)=>{let o={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?m0(e.strokeWidth):e.strokeStyle==="dotted"?iu(e.strokeWidth):void 0,disableMultiStroke:e.strokeStyle!=="solid",strokeWidth:e.strokeStyle!=="solid"?e.strokeWidth+.5:e.strokeWidth,fillWeight:e.strokeWidth/2,hachureGap:e.strokeWidth*4,roughness:h0(e),stroke:Ii(e.strokeColor,n),preserveVertices:t||e.roughness<l0.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return o.fillStyle=e.fillStyle,o.fill=Pi(e.backgroundColor)?void 0:Ii(e.backgroundColor,n),e.type==="ellipse"&&(o.curveFitting=1),o;case"line":case"freedraw":return vt(e.points)&&(o.fillStyle=e.fillStyle,o.fill=e.backgroundColor==="transparent"?void 0:Ii(e.backgroundColor,n)),o;case"arrow":return o;default:throw new Error(`Unimplemented type ${e.type}`)}},tu=(e,t,n)=>Ki(e)&&(t||ed(e)&&n?.get(e.id)!==!0)&&Pi(e.backgroundColor)&&Pi(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:qi(e)?{...e,strokeColor:Pi(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:Pi(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,Mi=(e,t,n)=>{if(t===null)return[];let[,,o,i,r,s]=t;return[e.line(o,i,r,s,n)]},Gr=(e,t,n)=>{if(t===null)return[];let[o,i,r,s,a,l]=t;return[e.line(r,s,o,i,n),e.line(a,l,o,i,n)]},fo=(e,t)=>{let n={...t};if(e.strokeStyle==="dotted"){let o=iu(e.strokeWidth-1);n.strokeLineDash=[o[0],o[1]-1]}else delete n.strokeLineDash;return n.roughness=Math.min(1,n.roughness||0),n},Ia=(e,t,n,o,i,r=1)=>{if(o===null)return[];let[s,a,l]=o,d={...t,fill:i,fillStyle:"solid",stroke:n,roughness:Math.min(.5,t.roughness||0)};return delete d.strokeLineDash,[e.circle(s,a,l*r,d)]},nu=(e,t,n,o,i,r,s,a)=>{if(o===null)return[];let l=Ii(e.strokeColor,a),d=Ii(s,a),c=-.25,u=.8;switch(o){case"circle":case"circle_outline":return Ia(i,r,l,ut(e,t,n,o),o==="circle_outline"?d:l);case"triangle":case"triangle_outline":{let m=ut(e,t,n,o);if(m===null)return[];let[h,g,f,E,x,y]=m,b={...r,fill:o==="triangle_outline"?d:l,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)};return delete b.strokeLineDash,[i.polygon([[h,g],[f,E],[x,y],[h,g]],b)]}case"diamond":case"diamond_outline":{let m=ut(e,t,n,o);if(m===null)return[];let[h,g,f,E,x,y,b,M]=m,w={...r,fill:o==="diamond_outline"?d:l,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)};return delete w.strokeLineDash,[i.polygon([[h,g],[f,E],[x,y],[b,M],[h,g]],w)]}case"cardinality_one":return Mi(i,ut(e,t,n,o),fo(e,r));case"cardinality_many":return Gr(i,ut(e,t,n,o),fo(e,r));case"cardinality_one_or_many":{let m=fo(e,r);return[...Gr(i,ut(e,t,n,"cardinality_many"),m),...Mi(i,ut(e,t,n,"cardinality_one",c),m)]}case"cardinality_exactly_one":{let m=fo(e,r);return[...Mi(i,ut(e,t,n,"cardinality_one",-.5),m),...Mi(i,ut(e,t,n,"cardinality_one"),m)]}case"cardinality_zero_or_one":{let m=fo(e,r);return[...Ia(i,r,l,ut(e,t,n,"circle_outline",1.5),d,u),...Mi(i,ut(e,t,n,"cardinality_one",-.5),m)]}case"cardinality_zero_or_many":{let m=fo(e,r);return[...Gr(i,ut(e,t,n,"cardinality_many"),m),...Ia(i,r,l,ut(e,t,n,"circle_outline",1.5),d,u)]}case"bar":case"arrow":default:return Gr(i,ut(e,t,n,o),fo(e,r))}},md=(e,t)=>{let n=new Ct,o={seed:e.seed,disableMultiStroke:!0,disableMultiStrokeFill:!0,roughness:0,preserveVertices:!0},i=he(e,t);switch(e.type){case"line":case"arrow":{let r=e.points.length?e.points:[Ce(0,0)];return ee(e)?n.path(ru(r,16),o).sets[0].ops:e.roundness?n.curve(r,o).sets[0].ops.slice(0,e.points.length).map((s,a)=>{if(a===0){let l=Mn(Ce(e.x+s.data[0],e.y+s.data[1]),i,e.angle);return{op:"move",data:Ce(l[0]-e.x,l[1]-e.y)}}return{op:"bcurveTo",data:[Mn(Ce(e.x+s.data[0],e.y+s.data[1]),i,e.angle),Mn(Ce(e.x+s.data[2],e.y+s.data[3]),i,e.angle),Mn(Ce(e.x+s.data[4],e.y+s.data[5]),i,e.angle)].map(l=>Ce(l[0]-e.x,l[1]-e.y)).flat()}}):r.map((s,a)=>{let l=Mn(Ce(e.x+s[0],e.y+s[1]),i,e.angle);return{op:a===0?"move":"lineTo",data:Ce(l[0]-e.x,l[1]-e.y)}})}case"freedraw":{if(e.points.length<2)return[];let r=Tn(e.points,.75);return n.curve(r,o).sets[0].ops.slice(0,e.points.length).map((s,a)=>{if(a===0){let l=Mn(Ce(e.x+s.data[0],e.y+s.data[1]),i,e.angle);return{op:"move",data:Ce(l[0]-e.x,l[1]-e.y)}}return{op:"bcurveTo",data:[Mn(Ce(e.x+s.data[0],e.y+s.data[1]),i,e.angle),Mn(Ce(e.x+s.data[2],e.y+s.data[3]),i,e.angle),Mn(Ce(e.x+s.data[4],e.y+s.data[5]),i,e.angle)].map(l=>Ce(l[0]-e.x,l[1]-e.y)).flat()}})}}},f0=(e,t,{isExporting:n,canvasBackgroundColor:o,embedsValidationStatus:i,theme:r})=>{let s=r===Sa.DARK;switch(e.type){case"rectangle":case"iframe":case"embeddable":{let a;if(e.roundness){let l=e.width,d=e.height,c=fn(Math.min(l,d),e);a=t.path(`M ${c} 0 L ${l-c} 0 Q ${l} 0, ${l} ${c} L ${l} ${d-c} Q ${l} ${d}, ${l-c} ${d} L ${c} ${d} Q 0 ${d}, 0 ${d-c} L 0 ${c} Q 0 0, ${c} 0`,Mt(tu(e,n,i),!0,s))}else a=t.rectangle(0,0,e.width,e.height,Mt(tu(e,n,i),!1,s));return a}case"diamond":{let a,[l,d,c,u,m,h,g,f]=vo(e);if(e.roundness){let E=fn(Math.abs(l-g),e),x=fn(Math.abs(u-d),e);a=t.path(`M ${l+E} ${d+x} L ${c-E} ${u-x}
15
15
  C ${c} ${u}, ${c} ${u}, ${c-E} ${u+x}
@@ -1,4 +1,4 @@
1
1
  import type { SubtypeOf } from "@excalidraw/common/utility-types";
2
2
  import type { ActionName } from "./types";
3
- export type ShortcutName = SubtypeOf<ActionName, "toggleTheme" | "loadScene" | "cut" | "copy" | "paste" | "copyStyles" | "pasteStyles" | "selectAll" | "deleteSelectedElements" | "duplicateSelection" | "sendBackward" | "bringForward" | "sendToBack" | "bringToFront" | "copyAsPng" | "group" | "ungroup" | "gridMode" | "objectsSnapMode" | "stats" | "viewMode" | "flipHorizontal" | "flipVertical" | "hyperlink" | "toggleElementLock" | "resetZoom" | "zoomOut" | "zoomIn" | "zoomToFit" | "zoomToFitSelectionInViewport" | "zoomToFitSelection" | "saveFileToDisk" | "saveToActiveFile" | "toggleShortcuts" | "wrapSelectionInFrame" | "arrangeElements"> | "saveScene" | "imageExport" | "searchMenu" | "toolLock";
3
+ export type ShortcutName = SubtypeOf<ActionName, "toggleTheme" | "loadScene" | "cut" | "copy" | "paste" | "copyStyles" | "pasteStyles" | "selectAll" | "deleteSelectedElements" | "duplicateSelection" | "sendBackward" | "bringForward" | "sendToBack" | "bringToFront" | "copyAsPng" | "group" | "ungroup" | "gridMode" | "objectsSnapMode" | "stats" | "viewMode" | "flipHorizontal" | "flipVertical" | "hyperlink" | "toggleElementLock" | "resetZoom" | "zoomOut" | "zoomIn" | "zoomToFit" | "zoomToFitSelectionInViewport" | "zoomToFitSelection" | "smartZoom" | "saveFileToDisk" | "saveToActiveFile" | "toggleShortcuts" | "wrapSelectionInFrame" | "arrangeElements"> | "saveScene" | "imageExport" | "searchMenu" | "toolLock";
4
4
  export declare const getShortcutFromShortcutName: (name: ShortcutName, idx?: number) => string;
@@ -2,7 +2,7 @@ import React from "react";
2
2
  import { AppEventBus, type EXPORT_IMAGE_TYPES, Emitter, type EditorInterface, type StylesPanelMode } from "@excalidraw/common";
3
3
  import { LinearElementEditor, Scene, Store, type ElementUpdate, StoreDelta, type ApplyToOptions } from "@excalidraw/element";
4
4
  import type { LocalPoint, Radians } from "@excalidraw/math";
5
- import type { ExcalidrawElement, ExcalidrawTextElement, NonDeleted, FileId, NonDeletedExcalidrawElement, ExcalidrawTextContainer, ExcalidrawFrameLikeElement, ExcalidrawIframeElement, ExcalidrawEmbeddableElement, Ordered, SceneElementsMap } from "@excalidraw/element/types";
5
+ import type { ExcalidrawElement, ExcalidrawTextElement, NonDeleted, FileId, NonDeletedExcalidrawElement, ExcalidrawTextContainer, ExcalidrawFrameLikeElement, ExcalidrawEmbeddableElement, Ordered, SceneElementsMap } from "@excalidraw/element/types";
6
6
  import type { Mutable } from "@excalidraw/common/utility-types";
7
7
  import { ActionManager } from "../actions/manager";
8
8
  import { History } from "../history";
@@ -124,6 +124,7 @@ declare class App extends React.Component<AppProps, AppState> {
124
124
  bucketFill: AppBucketFill;
125
125
  flowchart: AppFlowchart;
126
126
  cursor: AppCursor;
127
+ private zDragZoom;
127
128
  arrowText: AppArrowText;
128
129
  viewport: AppViewport;
129
130
  get lastViewportPosition(): {
@@ -815,6 +816,7 @@ declare class App extends React.Component<AppProps, AppState> {
815
816
  private maybeUpdateFrameToHighlightOnPointerMove;
816
817
  insertNewElements: (elements: readonly ExcalidrawElement[]) => void;
817
818
  insertNewElement: (element: ExcalidrawElement) => void;
819
+ private updateZDragZoom;
818
820
  private handleCanvasPointerMove;
819
821
  private handleEraser;
820
822
  private handleTouchMove;
@@ -852,7 +854,7 @@ declare class App extends React.Component<AppProps, AppState> {
852
854
  sceneY: number;
853
855
  width: number;
854
856
  height: number;
855
- }) => NonDeleted<ExcalidrawIframeElement>;
857
+ }) => NonDeleted<import("@excalidraw/element/types").ExcalidrawIframeElement>;
856
858
  insertEmbeddableElement: ({ sceneX, sceneY, link, }: {
857
859
  sceneX: number;
858
860
  sceneY: number;
@@ -0,0 +1,27 @@
1
+ import type { MarkOptional } from "@excalidraw/common/utility-types";
2
+ import "../components/dropdownMenu/DropdownMenu.scss";
3
+ import type { SidebarProps, SidebarTriggerProps } from "./Sidebar/common";
4
+ export declare const DefaultSidebar: import("react").FC<Omit<MarkOptional<Omit<{
5
+ name: import("../types").SidebarName;
6
+ children: React.ReactNode;
7
+ onStateChange?: (state: import("../types").AppState["openSidebar"]) => void;
8
+ onDock?: (docked: boolean) => void;
9
+ docked?: boolean;
10
+ className?: string;
11
+ __fallback?: boolean;
12
+ }, "name">, "children">, "onDock"> & {
13
+ /** pass `false` to disable docking */
14
+ onDock?: SidebarProps["onDock"] | false;
15
+ } & {
16
+ __fallback?: boolean;
17
+ }> & {
18
+ Trigger: import("react").FC<Omit<SidebarTriggerProps, "name"> & import("react").HTMLAttributes<HTMLDivElement> & {
19
+ __fallback?: boolean;
20
+ }>;
21
+ TabTriggers: {
22
+ ({ children }: {
23
+ children: React.ReactNode;
24
+ }): import("react/jsx-runtime").JSX.Element;
25
+ displayName: string;
26
+ };
27
+ };
@@ -219,6 +219,7 @@ export type SmartZoomPreferences = {
219
219
  fitToViewport?: boolean;
220
220
  animate?: boolean;
221
221
  duration?: number;
222
+ respectUIElements?: boolean;
222
223
  viewportZoomFactor?: number;
223
224
  };
224
225
  export type ArrangePreferences = {
@@ -57,6 +57,11 @@ export type SetViewportOptions = {
57
57
  * combination. See {@link ViewportOffsets}.
58
58
  */
59
59
  offsets?: ViewportOffsets;
60
+ /**
61
+ * Multiplier applied to fit zooms to leave extra breathing room around the
62
+ * target. Ignored for `fit: "none"`.
63
+ */
64
+ viewportZoomFactor?: number;
60
65
  };
61
66
  type Viewport = Pick<AppState, "scrollX" | "scrollY" | "zoom">;
62
67
  /**
@@ -73,7 +78,7 @@ export declare const constrainScrollState: (state: Pick<AppState, "scrollX" | "s
73
78
  * cancelling the other.
74
79
  */
75
80
  export declare const getViewportForZoomWithScrollConstraints: (opts: ZoomOptions, state: AppState) => Viewport;
76
- export declare const zoomToFitBounds: ({ bounds, appState, canvasOffsets, fit, minZoom, maxZoom, steppedZoom, }: {
81
+ export declare const zoomToFitBounds: ({ bounds, appState, canvasOffsets, fit, minZoom, maxZoom, steppedZoom, viewportZoomFactor, }: {
77
82
  bounds: SceneBounds;
78
83
  canvasOffsets?: Offsets;
79
84
  appState: Readonly<AppState>;
@@ -81,6 +86,7 @@ export declare const zoomToFitBounds: ({ bounds, appState, canvasOffsets, fit, m
81
86
  minZoom?: number;
82
87
  maxZoom?: number;
83
88
  steppedZoom?: boolean;
89
+ viewportZoomFactor?: number;
84
90
  }) => {
85
91
  appState: {
86
92
  scrollX: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myoc/element",
3
- "version": "0.19.523",
3
+ "version": "0.19.525",
4
4
  "type": "module",
5
5
  "types": "./dist/types/element/src/index.d.ts",
6
6
  "main": "./dist/prod/index.js",
@@ -64,9 +64,9 @@
64
64
  "build:esm": "rimraf dist && node ../../scripts/buildBase.js && yarn gen:types"
65
65
  },
66
66
  "dependencies": {
67
- "@excalidraw/common": "npm:@myoc/common@0.19.523",
68
- "@excalidraw/fractional-indexing": "npm:@myoc/fractional-indexing@0.19.523",
69
- "@excalidraw/math": "npm:@myoc/math@0.19.523",
67
+ "@excalidraw/common": "npm:@myoc/common@0.19.525",
68
+ "@excalidraw/fractional-indexing": "npm:@myoc/fractional-indexing@0.19.525",
69
+ "@excalidraw/math": "npm:@myoc/math@0.19.525",
70
70
  "thumbhash": "0.1.1"
71
71
  }
72
72
  }