Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

perfect-freehand

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

perfect-freehand - npm Package Compare versions

Comparing version 1.0.11 to 1.0.12

4

CHANGELOG.md
# Changelog
## 1.0.12
- Fixes cusp at the end of tapered lines.
## 1.0.11

@@ -4,0 +8,0 @@

2

dist/cjs/index.js

@@ -1,1 +0,1 @@

var ue=Object.defineProperty;var be=e=>ue(e,"__esModule",{value:!0});var ge=(e,t)=>{be(e);for(var r in t)ue(e,r,{get:t[r],enumerable:!0})};ge(exports,{default:()=>ke,getStroke:()=>ee,getStrokeOutlinePoints:()=>B,getStrokePoints:()=>A});function Y(e,t,r,S=g=>g){return e*S(.5-t*(.5-r))}function p(e,t){return[e[0]+t[0],e[1]+t[1]]}function m(e,t){return[e[0]-t[0],e[1]-t[1]]}function f(e,t){return[e[0]*t,e[1]*t]}function de(e,t){return[e[0]/t,e[1]/t]}function I(e){return[e[1],-e[0]]}function ie(e,t){return e[0]*t[0]+e[1]*t[1]}function pe(e,t){return e[0]===t[0]&&e[1]===t[1]}function he(e){return Math.hypot(e[0],e[1])}function xe(e){return e[0]*e[0]+e[1]*e[1]}function Z(e,t){return xe(m(e,t))}function K(e){return de(e,he(e))}function me(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function ce(e,t){return f(p(e,t),.5)}function V(e,t,r){let S=Math.sin(r),g=Math.cos(r),y=e[0]-t[0],s=e[1]-t[1],x=y*g-s*S,L=y*S+s*g;return[x+t[0],L+t[1]]}function N(e,t,r){return p(e,f(m(t,e),r))}function $(e,t,r){return p(e,f(t,r))}var{min:_,PI:Se}=Math,ae=.275,j=Se+1e-4;function B(e,t={}){let{size:r=16,smoothing:S=.5,thinning:g=.5,simulatePressure:y=!0,easing:s=n=>n,start:x={},end:L={},last:q=!1}=t,{cap:k=!0,taper:P=0,easing:C=n=>n*(2-n)}=x,{cap:b=!0,taper:a=0,easing:T=n=>--n*n*n+1}=L;if(e.length===0||r<=0)return[];let U=e[e.length-1].runningLength,te=Math.pow(r*S,2),O=[],v=[],X=e.slice(0,10).reduce((n,i)=>{let o=i.pressure;if(y){let u=_(1,i.distance/r),l=_(1,1-u);o=_(1,n+(l-n)*(u*ae))}return(n+o)/2},e[0].pressure),c=Y(r,g,e[e.length-1].pressure,s),J,ne=e[0].vector,z=e[0].point,F=z,E=z,M=F;for(let n=0;n<e.length-1;n++){let{pressure:i}=e[n],{point:o,vector:u,distance:l,runningLength:R}=e[n];if(U-R<3)continue;if(g){if(y){let D=_(1,l/r),W=_(1,1-D);i=_(1,X+(W-X)*(D*ae))}c=Y(r,g,i,s)}else c=r/2;J===void 0&&(J=c);let le=R<P?C(R/P):1,fe=U-R<a?T((U-R)/a):1;c=Math.max(.01,c*Math.min(le,fe));let re=e[n+1].vector,oe=ie(u,re);if(oe<0){let D=f(I(ne),c);for(let W=1/13,H=0;H<=1;H+=W)E=V(m(o,D),o,j*H),O.push(E),M=V(p(o,D),o,j*-H),v.push(M);z=E,F=M;continue}let se=f(I(N(re,u,oe)),c);E=m(o,se),(n===0||Z(z,E)>te)&&(O.push(E),z=E),M=p(o,se),(n===0||Z(F,M)>te)&&(v.push(M),F=M),X=i,ne=u}let d=e[0].point.slice(0,2),h=e.length>1?e[e.length-1].point.slice(0,2):p(e[0].point,[1,1]),Q=O.length<=1||v.length<=1,w=[],G=[];if(Q){if(!(P||a)||q){let n=$(d,K(I(m(d,h))),-(J||c)),i=[];for(let o=1/13,u=o;u<=1;u+=o)i.push(V(n,d,j*2*u));return i}}else{if(P||a&&Q)w.push(d,p(d,[.1,0]));else if(k)for(let o=1/13,u=o;u<=1;u+=o){let l=V(v[0],d,j*u);w.push(l)}else{let o=m(O[0],v[0]),u=f(o,.5),l=f(o,.51);w.push(m(d,u),m(d,l),p(d,l),p(d,u))}let n=ce(O[O.length-1],v[v.length-1]),i=I(K(m(h,n)));if(a||P&&Q)G.push(h,p(h,[1,0]));else if(b){let o=$(h,i,c);for(let u=1/29,l=0;l<=1;l+=u){let R=V(o,h,j*3*l);G.push(R)}}else G.push(p(h,f(i,c)),p(h,f(i,c*.99)),m(h,f(i,c*.99)),m(h,f(i,c)))}return O.concat(G,v.reverse(),w)}function A(e,t={}){var C;let{streamline:r=.5,size:S=16,last:g=!1}=t;if(e.length===0)return[];let y=.15+(1-r)*.85,s=Array.isArray(e[0])?e:e.map(({x:b,y:a,pressure:T=.5})=>[b,a,T]);s.length===1&&(s=[...s,[...p(s[0],[1,1]),...s[0].slice(2)]]);let x=[{point:[s[0][0],s[0][1]],pressure:s[0][2]||.25,vector:[1,1],distance:0,runningLength:0}],L=!1,q=0,k=x[0],P=s.length-1;for(let b=1;b<s.length;b++){let a=g&&b===P?s[b]:N(k.point,s[b],y);if(pe(k.point,a))continue;let T=me(a,k.point);if(q+=T,b<P&&!L){if(q<S)continue;L=!0}k={point:a,pressure:s[b][2]||.5,vector:K(m(k.point,a)),distance:T,runningLength:q},x.push(k)}return x[0].vector=((C=x[1])==null?void 0:C.vector)||[0,0],x}function ee(e,t={}){return B(A(e,t),t)}var ke=ee;
var ue=Object.defineProperty;var be=e=>ue(e,"__esModule",{value:!0});var ge=(e,t)=>{be(e);for(var r in t)ue(e,r,{get:t[r],enumerable:!0})};ge(exports,{default:()=>ke,getStroke:()=>ee,getStrokeOutlinePoints:()=>B,getStrokePoints:()=>A});function Y(e,t,r,x=g=>g){return e*x(.5-t*(.5-r))}function c(e,t){return[e[0]+t[0],e[1]+t[1]]}function p(e,t){return[e[0]-t[0],e[1]-t[1]]}function f(e,t){return[e[0]*t,e[1]*t]}function de(e,t){return[e[0]/t,e[1]/t]}function I(e){return[e[1],-e[0]]}function ie(e,t){return e[0]*t[0]+e[1]*t[1]}function pe(e,t){return e[0]===t[0]&&e[1]===t[1]}function he(e){return Math.hypot(e[0],e[1])}function xe(e){return e[0]*e[0]+e[1]*e[1]}function Z(e,t){return xe(p(e,t))}function K(e){return de(e,he(e))}function me(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function ce(e,t){return f(c(e,t),.5)}function V(e,t,r){let x=Math.sin(r),g=Math.cos(r),y=e[0]-t[0],s=e[1]-t[1],d=y*g-s*x,L=y*x+s*g;return[d+t[0],L+t[1]]}function H(e,t,r){return c(e,f(p(t,e),r))}function $(e,t,r){return c(e,f(t,r))}var{min:_,PI:Se}=Math,ae=.275,j=Se+1e-4;function B(e,t={}){let{size:r=16,smoothing:x=.5,thinning:g=.5,simulatePressure:y=!0,easing:s=n=>n,start:d={},end:L={},last:q=!1}=t,{cap:S=!0,taper:k=0,easing:C=n=>n*(2-n)}=d,{cap:b=!0,taper:a=0,easing:T=n=>--n*n*n+1}=L;if(e.length===0||r<=0)return[];let N=e[e.length-1].runningLength,te=Math.pow(r*x,2),O=[],P=[],U=e.slice(0,10).reduce((n,i)=>{let o=i.pressure;if(y){let u=_(1,i.distance/r),l=_(1,1-u);o=_(1,n+(l-n)*(u*ae))}return(n+o)/2},e[0].pressure),m=Y(r,g,e[e.length-1].pressure,s),X,ne=e[0].vector,z=e[0].point,F=z,E=z,M=F;for(let n=0;n<e.length-1;n++){let{pressure:i}=e[n],{point:o,vector:u,distance:l,runningLength:R}=e[n];if(N-R<3)continue;if(g){if(y){let D=_(1,l/r),W=_(1,1-D);i=_(1,U+(W-U)*(D*ae))}m=Y(r,g,i,s)}else m=r/2;X===void 0&&(X=m);let le=R<k?C(R/k):1,fe=N-R<a?T((N-R)/a):1;m=Math.max(.01,m*Math.min(le,fe));let re=e[n+1].vector,oe=ie(u,re);if(oe<0){let D=f(I(ne),m);for(let W=1/13,G=0;G<=1;G+=W)E=V(p(o,D),o,j*G),O.push(E),M=V(c(o,D),o,j*-G),P.push(M);z=E,F=M;continue}let se=f(I(H(re,u,oe)),m);E=p(o,se),(n===0||Z(z,E)>te)&&(O.push(E),z=E),M=c(o,se),(n===0||Z(F,M)>te)&&(P.push(M),F=M),U=i,ne=u}let v=e[0].point.slice(0,2),h=e.length>1?e[e.length-1].point.slice(0,2):c(e[0].point,[1,1]),J=O.length<=1||P.length<=1,Q=[],w=[];if(J){if(!(k||a)||q){let n=$(v,K(I(p(v,h))),-(X||m)),i=[];for(let o=1/13,u=o;u<=1;u+=o)i.push(V(n,v,j*2*u));return i}}else{if(!(k||a&&J))if(S)for(let o=1/13,u=o;u<=1;u+=o){let l=V(P[0],v,j*u);Q.push(l)}else{let o=p(O[0],P[0]),u=f(o,.5),l=f(o,.51);Q.push(p(v,u),p(v,l),c(v,l),c(v,u))}let n=ce(O[O.length-1],P[P.length-1]),i=I(K(p(h,n)));if(a||k&&J)w.push(h);else if(b){let o=$(h,i,m);for(let u=1/29,l=0;l<=1;l+=u){let R=V(o,h,j*3*l);w.push(R)}}else w.push(c(h,f(i,m)),c(h,f(i,m*.99)),p(h,f(i,m*.99)),p(h,f(i,m)))}return O.concat(w,P.reverse(),Q)}function A(e,t={}){var C;let{streamline:r=.5,size:x=16,last:g=!1}=t;if(e.length===0)return[];let y=.15+(1-r)*.85,s=Array.isArray(e[0])?e:e.map(({x:b,y:a,pressure:T=.5})=>[b,a,T]);s.length===1&&(s=[...s,[...c(s[0],[1,1]),...s[0].slice(2)]]);let d=[{point:[s[0][0],s[0][1]],pressure:s[0][2]||.25,vector:[1,1],distance:0,runningLength:0}],L=!1,q=0,S=d[0],k=s.length-1;for(let b=1;b<s.length;b++){let a=g&&b===k?s[b]:H(S.point,s[b],y);if(pe(S.point,a))continue;let T=me(a,S.point);if(q+=T,b<k&&!L){if(q<x)continue;L=!0}S={point:a,pressure:s[b][2]||.5,vector:K(p(S.point,a)),distance:T,runningLength:q},d.push(S)}return d[0].vector=((C=d[1])==null?void 0:C.vector)||[0,0],d}function ee(e,t={}){return B(A(e,t),t)}var ke=ee;

@@ -1,1 +0,1 @@

function Y(e,t,u,S=g=>g){return e*S(.5-t*(.5-u))}function p(e,t){return[e[0]+t[0],e[1]+t[1]]}function m(e,t){return[e[0]-t[0],e[1]-t[1]]}function f(e,t){return[e[0]*t,e[1]*t]}function fe(e,t){return[e[0]/t,e[1]/t]}function I(e){return[e[1],-e[0]]}function re(e,t){return e[0]*t[0]+e[1]*t[1]}function oe(e,t){return e[0]===t[0]&&e[1]===t[1]}function be(e){return Math.hypot(e[0],e[1])}function ge(e){return e[0]*e[0]+e[1]*e[1]}function Z(e,t){return ge(m(e,t))}function K(e){return fe(e,be(e))}function se(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function ue(e,t){return f(p(e,t),.5)}function V(e,t,u){let S=Math.sin(u),g=Math.cos(u),y=e[0]-t[0],o=e[1]-t[1],x=y*g-o*S,L=y*S+o*g;return[x+t[0],L+t[1]]}function N(e,t,u){return p(e,f(m(t,e),u))}function $(e,t,u){return p(e,f(t,u))}var{min:_,PI:de}=Math,ie=.275,j=de+1e-4;function pe(e,t={}){let{size:u=16,smoothing:S=.5,thinning:g=.5,simulatePressure:y=!0,easing:o=n=>n,start:x={},end:L={},last:q=!1}=t,{cap:k=!0,taper:P=0,easing:C=n=>n*(2-n)}=x,{cap:b=!0,taper:a=0,easing:T=n=>--n*n*n+1}=L;if(e.length===0||u<=0)return[];let U=e[e.length-1].runningLength,B=Math.pow(u*S,2),O=[],v=[],X=e.slice(0,10).reduce((n,i)=>{let r=i.pressure;if(y){let s=_(1,i.distance/u),l=_(1,1-s);r=_(1,n+(l-n)*(s*ie))}return(n+r)/2},e[0].pressure),c=Y(u,g,e[e.length-1].pressure,o),J,A=e[0].vector,z=e[0].point,F=z,E=z,M=F;for(let n=0;n<e.length-1;n++){let{pressure:i}=e[n],{point:r,vector:s,distance:l,runningLength:R}=e[n];if(U-R<3)continue;if(g){if(y){let D=_(1,l/u),W=_(1,1-D);i=_(1,X+(W-X)*(D*ie))}c=Y(u,g,i,o)}else c=u/2;J===void 0&&(J=c);let ae=R<P?C(R/P):1,le=U-R<a?T((U-R)/a):1;c=Math.max(.01,c*Math.min(ae,le));let ee=e[n+1].vector,te=re(s,ee);if(te<0){let D=f(I(A),c);for(let W=1/13,H=0;H<=1;H+=W)E=V(m(r,D),r,j*H),O.push(E),M=V(p(r,D),r,j*-H),v.push(M);z=E,F=M;continue}let ne=f(I(N(ee,s,te)),c);E=m(r,ne),(n===0||Z(z,E)>B)&&(O.push(E),z=E),M=p(r,ne),(n===0||Z(F,M)>B)&&(v.push(M),F=M),X=i,A=s}let d=e[0].point.slice(0,2),h=e.length>1?e[e.length-1].point.slice(0,2):p(e[0].point,[1,1]),Q=O.length<=1||v.length<=1,w=[],G=[];if(Q){if(!(P||a)||q){let n=$(d,K(I(m(d,h))),-(J||c)),i=[];for(let r=1/13,s=r;s<=1;s+=r)i.push(V(n,d,j*2*s));return i}}else{if(P||a&&Q)w.push(d,p(d,[.1,0]));else if(k)for(let r=1/13,s=r;s<=1;s+=r){let l=V(v[0],d,j*s);w.push(l)}else{let r=m(O[0],v[0]),s=f(r,.5),l=f(r,.51);w.push(m(d,s),m(d,l),p(d,l),p(d,s))}let n=ue(O[O.length-1],v[v.length-1]),i=I(K(m(h,n)));if(a||P&&Q)G.push(h,p(h,[1,0]));else if(b){let r=$(h,i,c);for(let s=1/29,l=0;l<=1;l+=s){let R=V(r,h,j*3*l);G.push(R)}}else G.push(p(h,f(i,c)),p(h,f(i,c*.99)),m(h,f(i,c*.99)),m(h,f(i,c)))}return O.concat(G,v.reverse(),w)}function me(e,t={}){var C;let{streamline:u=.5,size:S=16,last:g=!1}=t;if(e.length===0)return[];let y=.15+(1-u)*.85,o=Array.isArray(e[0])?e:e.map(({x:b,y:a,pressure:T=.5})=>[b,a,T]);o.length===1&&(o=[...o,[...p(o[0],[1,1]),...o[0].slice(2)]]);let x=[{point:[o[0][0],o[0][1]],pressure:o[0][2]||.25,vector:[1,1],distance:0,runningLength:0}],L=!1,q=0,k=x[0],P=o.length-1;for(let b=1;b<o.length;b++){let a=g&&b===P?o[b]:N(k.point,o[b],y);if(oe(k.point,a))continue;let T=se(a,k.point);if(q+=T,b<P&&!L){if(q<S)continue;L=!0}k={point:a,pressure:o[b][2]||.5,vector:K(m(k.point,a)),distance:T,runningLength:q},x.push(k)}return x[0].vector=((C=x[1])==null?void 0:C.vector)||[0,0],x}function ce(e,t={}){return pe(me(e,t),t)}var qe=ce;export{qe as default,ce as getStroke,pe as getStrokeOutlinePoints,me as getStrokePoints};
function Y(e,t,u,x=g=>g){return e*x(.5-t*(.5-u))}function c(e,t){return[e[0]+t[0],e[1]+t[1]]}function p(e,t){return[e[0]-t[0],e[1]-t[1]]}function f(e,t){return[e[0]*t,e[1]*t]}function fe(e,t){return[e[0]/t,e[1]/t]}function I(e){return[e[1],-e[0]]}function re(e,t){return e[0]*t[0]+e[1]*t[1]}function oe(e,t){return e[0]===t[0]&&e[1]===t[1]}function be(e){return Math.hypot(e[0],e[1])}function ge(e){return e[0]*e[0]+e[1]*e[1]}function Z(e,t){return ge(p(e,t))}function K(e){return fe(e,be(e))}function se(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function ue(e,t){return f(c(e,t),.5)}function V(e,t,u){let x=Math.sin(u),g=Math.cos(u),y=e[0]-t[0],o=e[1]-t[1],d=y*g-o*x,L=y*x+o*g;return[d+t[0],L+t[1]]}function H(e,t,u){return c(e,f(p(t,e),u))}function $(e,t,u){return c(e,f(t,u))}var{min:_,PI:de}=Math,ie=.275,j=de+1e-4;function pe(e,t={}){let{size:u=16,smoothing:x=.5,thinning:g=.5,simulatePressure:y=!0,easing:o=n=>n,start:d={},end:L={},last:q=!1}=t,{cap:S=!0,taper:k=0,easing:C=n=>n*(2-n)}=d,{cap:b=!0,taper:a=0,easing:T=n=>--n*n*n+1}=L;if(e.length===0||u<=0)return[];let N=e[e.length-1].runningLength,B=Math.pow(u*x,2),O=[],P=[],U=e.slice(0,10).reduce((n,i)=>{let r=i.pressure;if(y){let s=_(1,i.distance/u),l=_(1,1-s);r=_(1,n+(l-n)*(s*ie))}return(n+r)/2},e[0].pressure),m=Y(u,g,e[e.length-1].pressure,o),X,A=e[0].vector,z=e[0].point,F=z,E=z,M=F;for(let n=0;n<e.length-1;n++){let{pressure:i}=e[n],{point:r,vector:s,distance:l,runningLength:R}=e[n];if(N-R<3)continue;if(g){if(y){let D=_(1,l/u),W=_(1,1-D);i=_(1,U+(W-U)*(D*ie))}m=Y(u,g,i,o)}else m=u/2;X===void 0&&(X=m);let ae=R<k?C(R/k):1,le=N-R<a?T((N-R)/a):1;m=Math.max(.01,m*Math.min(ae,le));let ee=e[n+1].vector,te=re(s,ee);if(te<0){let D=f(I(A),m);for(let W=1/13,G=0;G<=1;G+=W)E=V(p(r,D),r,j*G),O.push(E),M=V(c(r,D),r,j*-G),P.push(M);z=E,F=M;continue}let ne=f(I(H(ee,s,te)),m);E=p(r,ne),(n===0||Z(z,E)>B)&&(O.push(E),z=E),M=c(r,ne),(n===0||Z(F,M)>B)&&(P.push(M),F=M),U=i,A=s}let v=e[0].point.slice(0,2),h=e.length>1?e[e.length-1].point.slice(0,2):c(e[0].point,[1,1]),J=O.length<=1||P.length<=1,Q=[],w=[];if(J){if(!(k||a)||q){let n=$(v,K(I(p(v,h))),-(X||m)),i=[];for(let r=1/13,s=r;s<=1;s+=r)i.push(V(n,v,j*2*s));return i}}else{if(!(k||a&&J))if(S)for(let r=1/13,s=r;s<=1;s+=r){let l=V(P[0],v,j*s);Q.push(l)}else{let r=p(O[0],P[0]),s=f(r,.5),l=f(r,.51);Q.push(p(v,s),p(v,l),c(v,l),c(v,s))}let n=ue(O[O.length-1],P[P.length-1]),i=I(K(p(h,n)));if(a||k&&J)w.push(h);else if(b){let r=$(h,i,m);for(let s=1/29,l=0;l<=1;l+=s){let R=V(r,h,j*3*l);w.push(R)}}else w.push(c(h,f(i,m)),c(h,f(i,m*.99)),p(h,f(i,m*.99)),p(h,f(i,m)))}return O.concat(w,P.reverse(),Q)}function me(e,t={}){var C;let{streamline:u=.5,size:x=16,last:g=!1}=t;if(e.length===0)return[];let y=.15+(1-u)*.85,o=Array.isArray(e[0])?e:e.map(({x:b,y:a,pressure:T=.5})=>[b,a,T]);o.length===1&&(o=[...o,[...c(o[0],[1,1]),...o[0].slice(2)]]);let d=[{point:[o[0][0],o[0][1]],pressure:o[0][2]||.25,vector:[1,1],distance:0,runningLength:0}],L=!1,q=0,S=d[0],k=o.length-1;for(let b=1;b<o.length;b++){let a=g&&b===k?o[b]:H(S.point,o[b],y);if(oe(S.point,a))continue;let T=se(a,S.point);if(q+=T,b<k&&!L){if(q<x)continue;L=!0}S={point:a,pressure:o[b][2]||.5,vector:K(p(S.point,a)),distance:T,runningLength:q},d.push(S)}return d[0].vector=((C=d[1])==null?void 0:C.vector)||[0,0],d}function ce(e,t={}){return pe(me(e,t),t)}var qe=ce;export{qe as default,ce as getStroke,pe as getStrokeOutlinePoints,me as getStrokePoints};
{
"version": "1.0.11",
"version": "1.0.12",
"name": "perfect-freehand",

@@ -59,3 +59,3 @@ "private": false,

},
"gitHead": "cbc2e2ed268b77521ec8464e743adabc906a7485"
"gitHead": "d3a6f8a0f9757ad02d620652c64a310ea6fcb0b1"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc