/* esm.sh - @excalidraw/laser-pointer@1.3.1 */
function ot(e,t,s,n){Object.defineProperty(e,t,{get:s,set:n,enumerable:!0,configurable:!0})}var at={};ot(at,"LaserPointer",()=>H);function a([e,t,s],[n,f,h]){return[e+n,t+f,s+h]}function L([e,t,s],[n,f,h]){return[e-n,t-f,s-h]}function r([e,t,s],n){return[e*n,t*n,s*n]}function z([e,t,s]){return[e/Math.sqrt(e**2+t**2),t/Math.sqrt(e**2+t**2),s]}function l([e,t,s],n){return[Math.cos(n)*e-Math.sin(n)*t,Math.sin(n)*e+Math.cos(n)*t,s]}function rt(e,t,s){return a(e,r(L(t,e),s))}function R(e,t,s){return Math.atan2(s[1]-e[1],s[0]-e[0])-Math.atan2(t[1]-e[1],t[0]-e[0])}function W(e){return Math.atan2(Math.sin(e),Math.cos(e))}function X([e,t]){return Math.sqrt(e**2+t**2)}function S([e,t],[s,n]){return Math.sqrt((s-e)**2+(n-t)**2)}function ct(e){if(e.length<2)return 0;let t=0;for(let s=1;s<=e.length-1;s++)t+=S(e[s-1],e[s]);return t+=S(e[e.length-2],e[e.length-1]),t}var ht=(e,t,s)=>Math.max(t,Math.min(s,e));function ft(e,t,s){let n=S(t,s);if(n===0)return S(e,t);let f=ht(((e[0]-t[0])*(s[0]-t[0])+(e[1]-t[1])*(s[1]-t[1]))/n**2,0,1),h=[t[0]+f*(s[0]-t[0]),t[1]+f*(s[1]-t[1]),e[2]];return S(h,e)}function N(e,t){if(t===0||e.length<=2)return e;let s=e[0],n=e[e.length-1],[f,h]=e.reduce(([P,C],I,y)=>{let $=ft(I,s,n);return $>P?[$,y]:[P,C]},[0,-1]);if(f>=t){let P=e[h];return[...N([s,...e.slice(1,h),P],t).slice(0,-1),P,...N([P,...e.slice(h,-1),n],t).slice(1)]}else return[s,n]}var H=class e{static{this.defaults={size:2,streamline:.45,simplify:.1,simplifyPhase:"output",keepHead:!1,sizeMapping:()=>1}}static{this.constants={cornerDetectionMaxAngle:75,cornerDetectionVariance:t=>t>35?.5:1,maxTailLength:50}}constructor(t){this.originalPoints=[],this.stablePoints=[],this.tailPoints=[],this.isFresh=!0,this.options=Object.assign({},e.defaults,t)}get lastPoint(){return this.tailPoints[this.tailPoints.length-1]??this.stablePoints[this.stablePoints.length-1]}addPoint(t){let s=this.originalPoints[this.originalPoints.length-1];if(!(s&&s[0]===t[0]&&s[1]===t[1])){if(this.originalPoints.push(t),this.isFresh){this.isFresh=!1,this.stablePoints.push(t);return}this.options.streamline>0&&(t=rt(this.lastPoint,t,1-this.options.streamline)),this.tailPoints.push(t),ct(this.tailPoints)>e.constants.maxTailLength&&this.stabilizeTail()}}close(){this.stabilizeTail()}stabilizeTail(){if(this.options.simplify>0&&this.options.simplifyPhase=="tail")throw new Error("Not implemented yet");this.stablePoints.push(...this.tailPoints),this.tailPoints=[]}getSize(t,s,n,f,h){return(t??this.options.size)*this.options.sizeMapping({pressure:s,runningLength:h,currentIndex:n,totalLength:f})}getStrokeOutline(t){if(this.isFresh)return[];let s=[...this.stablePoints,...this.tailPoints];this.options.simplify>0&&this.options.simplifyPhase==="input"&&(s=N(s,this.options.simplify));let n=s.length;if(n===0)return[];if(n===1){let i=s[0],p=this.getSize(t,i[2],0,n,0);if(p<.5)return[];let o=[];for(let b=0;b<=Math.PI*2;b+=Math.PI/16)o.push(a(i,r(l([1,0,0],b),p)));return o.push(a(i,r([1,0,0],this.getSize(t,i[2],0,n,0)))),o}if(n===2){let i=s[0],p=s[1],o=this.getSize(t,i[2],0,n,0),b=this.getSize(t,p[2],0,n,0);if(o<.5||b<.5)return[];let M=[],g=R(i,[i[0],i[1]-100,i[2]],p);for(let c=g;c<=Math.PI+g;c+=Math.PI/16)M.push(a(i,r(l([1,0,0],c),o)));for(let c=Math.PI+g;c<=Math.PI*2+g;c+=Math.PI/16)M.push(a(p,r(l([1,0,0],c),b)));return M.push(M[0]),M}let f=[],h=[],P=0,C=0,I=0,y=0;for(let i=1;i<n-1;i++){let p=s[i-1],o=s[i],b=s[i+1],M=o[2],g=S(p,o);y+=g,P=C+(g-C)*.2;let c=this.getSize(t,M,i,n,y);if(c===0){I=i+1;continue}let F=z(L(p,o)),D=z(L(b,o)),m=l(F,Math.PI/2),G=l(F,-Math.PI/2),B=l(D,Math.PI/2),J=l(D,-Math.PI/2),tt=a(o,r(m,c)),et=a(o,r(G,c)),st=a(o,r(B,c)),nt=a(o,r(J,c)),K=a(m,J),Q=a(G,B),T=a(o,r(X(K)===0?F:z(K),c)),q=a(o,r(X(Q)===0?D:z(Q),c)),w=W(R(o,p,b)),it=e.constants.cornerDetectionMaxAngle/180*Math.PI*e.constants.cornerDetectionVariance(P);if(Math.abs(w)<it){let d=Math.abs(W(Math.PI-w));if(d===0)continue;if(w<0){h.push(et,q);for(let u=0;u<=d;u+=d/4)f.push(a(o,l(r(m,c),u)));for(let u=d;u>=0;u-=d/4)h.push(a(o,l(r(m,c),u)));h.push(q,st)}else{f.push(tt,T);for(let u=0;u<=d;u+=d/4)h.push(a(o,l(r(m,-c),-u)));for(let u=d;u>=0;u-=d/4)f.push(a(o,l(r(m,-c),-u)));f.push(T,nt)}}else f.push(T),h.push(q);C=P}if(I>=n-2)if(this.options.keepHead){let i=s[n-1],p=[];for(let o=0;o<=Math.PI*2;o+=Math.PI/16)p.push(a(i,r(l([1,0,0],o),this.options.size)));return p.push(a(i,r([1,0,0],this.options.size))),p}else return[];let $=s[I],Y=s[I+1],j=s[n-2],E=s[n-1],Z=z(L(Y,$)),v=z(L(j,E)),U=l(Z,-Math.PI/2),O=l(v,Math.PI/2),k=this.getSize(t,$[2],0,n,0),x=[],_=this.options.keepHead?this.options.size:this.getSize(t,j[2],n-2,n,y),V=[];if(k>1){for(let i=0;i<=Math.PI;i+=Math.PI/16)x.unshift(a($,l(r(U,k),-i)));x.unshift(a($,r(U,-k)))}else x.push($);for(let i=0;i<=Math.PI*3;i+=Math.PI/16)V.push(a(E,l(r(O,-_),-i)));let A=[...x,...f,...V.reverse(),...h.reverse()];return x.length>0&&A.push(x[0]),this.options.simplify>0&&this.options.simplifyPhase==="output"?N(A,this.options.simplify):A}};export{H as LaserPointer};
//# sourceMappingURL=laser-pointer.mjs.map