/* esm.sh - perfect-freehand@1.2.0 */
function tt(t,n,u,m=v=>v){return t*m(.5-n*(.5-u))}function ht(t){return[-t[0],-t[1]]}function g(t,n){return[t[0]+n[0],t[1]+n[1]]}function p(t,n){return[t[0]-n[0],t[1]-n[1]]}function a(t,n){return[t[0]*n,t[1]*n]}function ct(t,n){return[t[0]/n,t[1]/n]}function O(t){return[t[1],-t[0]]}function nt(t,n){return t[0]*n[0]+t[1]*n[1]}function ft(t,n){return t[0]===n[0]&&t[1]===n[1]}function pt(t){return Math.hypot(t[0],t[1])}function at(t){return t[0]*t[0]+t[1]*t[1]}function et(t,n){return at(p(t,n))}function ut(t){return ct(t,pt(t))}function gt(t,n){return Math.hypot(t[1]-n[1],t[0]-n[0])}function W(t,n,u){let m=Math.sin(u),v=Math.cos(u),P=t[0]-n[0],S=t[1]-n[1],r=P*v-S*m,f=P*m+S*v;return[r+n[0],f+n[1]]}function U(t,n,u){return g(t,a(p(n,t),u))}function rt(t,n,u){return g(t,a(n,u))}var{min:b,PI:vt}=Math,it=.275,Z=vt+1e-4;function dt(t,n={}){let{size:u=16,smoothing:m=.5,thinning:v=.5,simulatePressure:P=!0,easing:S=e=>e,start:r={},end:f={},last:_=!1}=n,{cap:j=!0,easing:M=e=>e*(2-e)}=r,{cap:B=!0,easing:h=e=>--e*e*e+1}=f;if(t.length===0||u<=0)return[];let s=t[t.length-1].runningLength,d=r.taper===!1?0:r.taper===!0?Math.max(u,s):r.taper,q=f.taper===!1?0:f.taper===!0?Math.max(u,s):f.taper,V=Math.pow(u*m,2),w=[],A=[],G=t.slice(0,10).reduce((e,o)=>{let i=o.pressure;if(P){let l=b(1,o.distance/u),Q=b(1,1-l);i=b(1,e+(Q-e)*(l*it))}return(e+i)/2},t[0].pressure),c=tt(u,v,t[t.length-1].pressure,S),H,J=t[0].vector,D=t[0].point,C=D,k=D,z=C,K=!1;for(let e=0;e<t.length;e++){let{pressure:o}=t[e],{point:i,vector:l,distance:Q,runningLength:I}=t[e];if(e<t.length-1&&s-I<3)continue;if(v){if(P){let L=b(1,Q/u),T=b(1,1-L);o=b(1,G+(T-G)*(L*it))}c=tt(u,v,o,S)}else c=u/2;H===void 0&&(H=c);let lt=I<d?M(I/d):1,ot=s-I<q?h((s-I)/q):1;c=Math.max(.01,c*Math.min(lt,ot));let X=(e<t.length-1?t[e+1]:t[e]).vector,R=e<t.length-1?nt(l,X):1,st=nt(l,J)<0&&!K,Y=R!==null&&R<0;if(st||Y){let L=a(O(J),c);for(let T=1/13,F=0;F<=1;F+=T)k=W(p(i,L),i,Z*F),w.push(k),z=W(g(i,L),i,Z*-F),A.push(z);D=k,C=z,Y&&(K=!0);continue}if(K=!1,e===t.length-1){let L=a(O(l),c);w.push(p(i,L)),A.push(g(i,L));continue}let $=a(O(U(X,l,R)),c);k=p(i,$),(e<=1||et(D,k)>V)&&(w.push(k),D=k),z=g(i,$),(e<=1||et(C,z)>V)&&(A.push(z),C=z),G=o,J=l}let x=t[0].point.slice(0,2),y=t.length>1?t[t.length-1].point.slice(0,2):g(t[0].point,[1,1]),N=[],E=[];if(t.length===1){if(!(d||q)||_){let e=rt(x,ut(O(p(x,y))),-(H||c)),o=[];for(let i=1/13,l=i;l<=1;l+=i)o.push(W(e,x,Z*2*l));return o}}else{if(!(d||q&&t.length===1))if(j)for(let o=1/13,i=o;i<=1;i+=o){let l=W(A[0],x,Z*i);N.push(l)}else{let o=p(w[0],A[0]),i=a(o,.5),l=a(o,.51);N.push(p(x,i),p(x,l),g(x,l),g(x,i))}let e=O(ht(t[t.length-1].vector));if(q||d&&t.length===1)E.push(y);else if(B){let o=rt(y,e,c);for(let i=1/29,l=i;l<1;l+=i)E.push(W(o,y,Z*3*l))}else E.push(g(y,a(e,c)),g(y,a(e,c*.99)),p(y,a(e,c*.99)),p(y,a(e,c)))}return w.concat(E,A.reverse(),N)}function mt(t,n={}){var u;let{streamline:m=.5,size:v=16,last:P=!1}=n;if(t.length===0)return[];let S=.15+(1-m)*.85,r=Array.isArray(t[0])?t:t.map(({x:h,y:s,pressure:d=.5})=>[h,s,d]);if(r.length===2){let h=r[1];r=r.slice(0,-1);for(let s=1;s<5;s++)r.push(U(r[0],h,s/4))}r.length===1&&(r=[...r,[...g(r[0],[1,1]),...r[0].slice(2)]]);let f=[{point:[r[0][0],r[0][1]],pressure:r[0][2]>=0?r[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],_=!1,j=0,M=f[0],B=r.length-1;for(let h=1;h<r.length;h++){let s=P&&h===B?r[h].slice(0,2):U(M.point,r[h],S);if(ft(M.point,s))continue;let d=gt(s,M.point);if(j+=d,h<B&&!_){if(j<v)continue;_=!0}M={point:s,pressure:r[h][2]>=0?r[h][2]:.5,vector:ut(p(M.point,s)),distance:d,runningLength:j},f.push(M)}return f[0].vector=((u=f[1])==null?void 0:u.vector)||[0,0],f}function Mt(t,n={}){return dt(mt(t,n),n)}var xt=Mt;export{xt as default,Mt as getStroke,dt as getStrokeOutlinePoints,mt as getStrokePoints};
//# sourceMappingURL=perfect-freehand.mjs.map