New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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

to
0.4.5

5

CHANGELOG.md

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

## 0.4.5
- Fixes typings.
- Fixes dot product check for left vs right.
## 0.4.4

@@ -2,0 +7,0 @@

21

dist/perfect-freehand.cjs.development.js

@@ -148,2 +148,11 @@ 'use strict';

/**
* Mean between two vectors or mid vector between two vectors
* @param A
* @param B
*/
function med(A, B) {
return mul(add(A, B), 0.5);
}
/**
* Rotate a vector around another vector by r (radians)

@@ -431,10 +440,10 @@ * @param A vector

if (alwaysAdd || dist(pr, tr) > minDistance && dpr(tlu, vector) > 0) {
rightPts.push(tr);
pr = tr;
if (alwaysAdd || dist(pl, tl) > minDistance && dpr(tlu, vector) > 0) {
leftPts.push(med(pl, tl));
pl = tl;
}
if (alwaysAdd || dist(pl, tl) > minDistance && dpr(tru, vector) > 0) {
leftPts.push(tl);
pl = tl;
if (alwaysAdd || dist(pr, tr) > minDistance && dpr(tru, vector) > 0) {
rightPts.push(med(pr, tr));
pr = tr;
} // Set variables for next iteration

@@ -441,0 +450,0 @@

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

"use strict";function r(r,n,t){return r*(1-t)+n*t}function n(r,n,t){return Math.max(n,Math.min(t,r))}function t(t,e,i,o){return void 0===o&&(o=.5),e?(o=n(i(o),0,1),(e<0?r(t,t+t*n(e,-.95,-.05),o):r(t-t*n(e,.05,.95),t,o))/2):t/2}function e(r,n){return[r[0]+n[0],r[1]+n[1]]}function i(r,n){return[r[0]-n[0],r[1]-n[1]]}function o(r,n){return[n[0]-r[0],n[1]-r[1]]}function u(r,n){return[r[0]*n,r[1]*n]}function a(r){return[r[1],-r[0]]}function v(r,n){return r[0]*n[0]+r[1]*n[1]}function s(r){return function(r,n){return[r[0]/n,r[1]/n]}(r,function(r){return Math.hypot(r[0],r[1])}(r))}function f(r,n){return Math.hypot(r[1]-n[1],r[0]-n[0])}function p(r,n,t){var e=Math.sin(t),i=Math.cos(t),o=r[0]-n[0],u=r[1]-n[1];return[o*i-u*e+n[0],o*e+u*i+n[1]]}function c(r,n,t){return e(r,u(o(r,n),t))}Object.defineProperty(exports,"__esModule",{value:!0});var h=Math.min,g=Math.PI;function d(r,n,t){void 0===n&&(n=.5),void 0===t&&(t=8);var i=function(r){return Array.isArray(r[0])?r.map((function(r){var n=r[2];return[r[0],r[1],void 0===n?.5:n]})):r.map((function(r){var n=r.pressure;return[r.x,r.y,void 0===n?.5:n]}))}(r),u=i.length;if(0===u)return[];1===u&&i.push(e(i[0],[1,0]));for(var a=[{point:[i[0][0],i[0][1]],pressure:i[0][2],vector:[0,0],distance:0,runningLength:0}],v=1,p=i[v],h=a[0];v<i.length;p=i[++v],h=a[v-1]){var g=c(h.point,p,1-n),d=p[2],l=s(o(g,h.point)),M=f(g,h.point);a.push({point:g,pressure:d,vector:l,distance:M,runningLength:h.runningLength+M})}for(var m=0;m<u;m++){var L=a[m],x=L.vector;if(L.runningLength>t||m===u-1){for(var y=0;y<m;y++)a[y].vector=x;break}}for(var k=a[u-1].runningLength,P=u-1;P>1;P--){var b=a[P],A=b.vector;if(k-b.runningLength>t/2){for(var O=P;O<u;O++)a[O].vector=A;break}}return a}function l(r,n){void 0===n&&(n={});var d=n.size,l=void 0===d?8:d,M=n.thinning,m=void 0===M?.5:M,L=n.smoothing,x=void 0===L?.5:L,y=n.simulatePressure,k=void 0===y||y,P=n.easing,b=void 0===P?function(r){return r}:P,A=n.start,O=void 0===A?{}:A,S=n.end,_=void 0===S?{}:S,j=n.last,z=void 0!==j&&j,I=O.taper,q=void 0===I?0:I,w=O.easing,B=void 0===w?function(r){return r*(2-r)}:w,C=_.taper,D=void 0===C?0:C,E=_.easing,F=void 0===E?function(r){return--r*r*r+1}:E,G=r.length;if(0===G)return[];for(var H=r[G-1].runningLength,J=[],K=[],N=r.slice(0,5).reduce((function(r,n){return(r+n.pressure)/2}),r[0].pressure),Q=t(l,m,b,r[G-1].pressure),R=r[0].vector,T=r[0].point,U=T,V=T,W=U,X=1;X<G-1;X++){var Y=r[X],Z=Y.point,$=Y.pressure,rr=Y.vector,nr=Y.distance,tr=Y.runningLength;if(m){if(k){var er=h(1,1-nr/l),ir=h(1,nr/l);$=h(1,N+ir/2*(er-N))}Q=t(l,m,b,$)}else Q=l/2;var or=tr<q?B(tr/q):1,ur=H-tr<D?F((H-tr)/D):1;Q*=Math.min(or,ur);var ar=r[X+1].vector,vr=v(rr,ar);if(vr<0){for(var sr=u(a(R),Q),fr=e(Z,sr),pr=i(Z,sr),cr=.2;cr<1;cr+=.2)W=p(fr,Z,g*-cr),V=p(pr,Z,g*cr),K.push(W),J.push(V);T=V,U=W}else{var hr=u(a(c(ar,rr,vr)),Q);V=i(Z,hr);var gr=s(o(W=e(Z,hr),U)),dr=s(o(V,T)),lr=1===X||vr<.25,Mr=(tr>l?l:l/2)*x;(lr||f(U,W)>Mr&&v(gr,rr)>0)&&(K.push(W),U=W),(lr||f(T,V)>Mr&&v(dr,rr)>0)&&(J.push(V),T=V),N=$,R=rr}}var mr=r[0],Lr=r[G-1],xr=K.length<2||J.length<2;if(xr&&(!q&&!D||z)){for(var yr=0,kr=0;kr<G;kr++){var Pr=r[kr];if(Pr.runningLength>l){yr=t(l,m,b,Pr.pressure);break}}for(var br=i(mr.point,u(a(s(o(Lr.point,mr.point))),yr||Q)),Ar=[],Or=0;Or<=1;Or+=.1)Ar.push(p(br,mr.point,2*g*Or));return Ar}var Sr=[];if(!(q||D&&xr)){for(var _r=i(mr.point,u(s(o(W=K[1],V=J[1])),f(W,V)/2)),jr=0;jr<=1;jr+=.2)Sr.push(p(_r,mr.point,g*jr));J.shift(),K.shift()}var zr=[];if(D||q&&xr)zr.push(Lr.point);else{for(var Ir=i(Lr.point,u(a(Lr.vector),Q)),qr=0;qr<=1;qr+=.1)zr.push(p(Ir,Lr.point,3*g*qr));J.pop(),K.pop()}return J.concat(zr,K.reverse(),Sr)}exports.default=function(r,n){return void 0===n&&(n={}),l(d(r,n.streamline),n)},exports.getStrokeOutlinePoints=l,exports.getStrokePoints=d;
"use strict";function n(n,r,t){return n*(1-t)+r*t}function r(n,r,t){return Math.max(r,Math.min(t,n))}function t(t,e,i,o){return void 0===o&&(o=.5),e?(o=r(i(o),0,1),(e<0?n(t,t+t*r(e,-.95,-.05),o):n(t-t*r(e,.05,.95),t,o))/2):t/2}function e(n,r){return[n[0]+r[0],n[1]+r[1]]}function i(n,r){return[n[0]-r[0],n[1]-r[1]]}function o(n,r){return[r[0]-n[0],r[1]-n[1]]}function u(n,r){return[n[0]*r,n[1]*r]}function a(n){return[n[1],-n[0]]}function v(n,r){return n[0]*r[0]+n[1]*r[1]}function s(n){return function(n,r){return[n[0]/r,n[1]/r]}(n,function(n){return Math.hypot(n[0],n[1])}(n))}function f(n,r){return Math.hypot(n[1]-r[1],n[0]-r[0])}function p(n,r){return u(e(n,r),.5)}function c(n,r,t){var e=Math.sin(t),i=Math.cos(t),o=n[0]-r[0],u=n[1]-r[1];return[o*i-u*e+r[0],o*e+u*i+r[1]]}function h(n,r,t){return e(n,u(o(n,r),t))}Object.defineProperty(exports,"__esModule",{value:!0});var g=Math.min,d=Math.PI;function l(n,r,t){void 0===r&&(r=.5),void 0===t&&(t=8);var i=function(n){return Array.isArray(n[0])?n.map((function(n){var r=n[2];return[n[0],n[1],void 0===r?.5:r]})):n.map((function(n){var r=n.pressure;return[n.x,n.y,void 0===r?.5:r]}))}(n),u=i.length;if(0===u)return[];1===u&&i.push(e(i[0],[1,0]));for(var a=[{point:[i[0][0],i[0][1]],pressure:i[0][2],vector:[0,0],distance:0,runningLength:0}],v=1,p=i[v],c=a[0];v<i.length;p=i[++v],c=a[v-1]){var g=h(c.point,p,1-r),d=p[2],l=s(o(g,c.point)),M=f(g,c.point);a.push({point:g,pressure:d,vector:l,distance:M,runningLength:c.runningLength+M})}for(var m=0;m<u;m++){var L=a[m],x=L.vector;if(L.runningLength>t||m===u-1){for(var y=0;y<m;y++)a[y].vector=x;break}}for(var k=a[u-1].runningLength,P=u-1;P>1;P--){var b=a[P],A=b.vector;if(k-b.runningLength>t/2){for(var O=P;O<u;O++)a[O].vector=A;break}}return a}function M(n,r){void 0===r&&(r={});var l=r.size,M=void 0===l?8:l,m=r.thinning,L=void 0===m?.5:m,x=r.smoothing,y=void 0===x?.5:x,k=r.simulatePressure,P=void 0===k||k,b=r.easing,A=void 0===b?function(n){return n}:b,O=r.start,S=void 0===O?{}:O,_=r.end,j=void 0===_?{}:_,z=r.last,I=void 0!==z&&z,q=S.taper,w=void 0===q?0:q,B=S.easing,C=void 0===B?function(n){return n*(2-n)}:B,D=j.taper,E=void 0===D?0:D,F=j.easing,G=void 0===F?function(n){return--n*n*n+1}:F,H=n.length;if(0===H)return[];for(var J=n[H-1].runningLength,K=[],N=[],Q=n.slice(0,5).reduce((function(n,r){return(n+r.pressure)/2}),n[0].pressure),R=t(M,L,A,n[H-1].pressure),T=n[0].vector,U=n[0].point,V=U,W=U,X=V,Y=1;Y<H-1;Y++){var Z=n[Y],$=Z.point,nn=Z.pressure,rn=Z.vector,tn=Z.distance,en=Z.runningLength;if(L){if(P){var on=g(1,1-tn/M),un=g(1,tn/M);nn=g(1,Q+un/2*(on-Q))}R=t(M,L,A,nn)}else R=M/2;var an=en<w?C(en/w):1,vn=J-en<E?G((J-en)/E):1;R*=Math.min(an,vn);var sn=n[Y+1].vector,fn=v(rn,sn);if(fn<0){for(var pn=u(a(T),R),cn=e($,pn),hn=i($,pn),gn=.2;gn<1;gn+=.2)X=c(cn,$,d*-gn),W=c(hn,$,d*gn),N.push(X),K.push(W);U=W,V=X}else{var dn=u(a(h(sn,rn,fn)),R);W=i($,dn);var ln=s(o(X=e($,dn),V)),Mn=s(o(W,U)),mn=1===Y||fn<.25,Ln=(en>M?M:M/2)*y;(mn||f(U,W)>Ln&&v(ln,rn)>0)&&(K.push(p(U,W)),U=W),(mn||f(V,X)>Ln&&v(Mn,rn)>0)&&(N.push(p(V,X)),V=X),Q=nn,T=rn}}var xn=n[0],yn=n[H-1],kn=N.length<2||K.length<2;if(kn&&(!w&&!E||I)){for(var Pn=0,bn=0;bn<H;bn++){var An=n[bn];if(An.runningLength>M){Pn=t(M,L,A,An.pressure);break}}for(var On=i(xn.point,u(a(s(o(yn.point,xn.point))),Pn||R)),Sn=[],_n=0;_n<=1;_n+=.1)Sn.push(c(On,xn.point,2*d*_n));return Sn}var jn=[];if(!(w||E&&kn)){for(var zn=i(xn.point,u(s(o(X=N[1],W=K[1])),f(X,W)/2)),In=0;In<=1;In+=.2)jn.push(c(zn,xn.point,d*In));K.shift(),N.shift()}var qn=[];if(E||w&&kn)qn.push(yn.point);else{for(var wn=i(yn.point,u(a(yn.vector),R)),Bn=0;Bn<=1;Bn+=.1)qn.push(c(wn,yn.point,3*d*Bn));K.pop(),N.pop()}return K.concat(qn,N.reverse(),jn)}exports.default=function(n,r){return void 0===r&&(r={}),M(l(n,r.streamline),r)},exports.getStrokeOutlinePoints=M,exports.getStrokePoints=l;
//# sourceMappingURL=perfect-freehand.cjs.production.min.js.map

@@ -144,2 +144,11 @@ function lerp(y1, y2, mu) {

/**
* Mean between two vectors or mid vector between two vectors
* @param A
* @param B
*/
function med(A, B) {
return mul(add(A, B), 0.5);
}
/**
* Rotate a vector around another vector by r (radians)

@@ -427,10 +436,10 @@ * @param A vector

if (alwaysAdd || dist(pr, tr) > minDistance && dpr(tlu, vector) > 0) {
rightPts.push(tr);
pr = tr;
if (alwaysAdd || dist(pl, tl) > minDistance && dpr(tlu, vector) > 0) {
leftPts.push(med(pl, tl));
pl = tl;
}
if (alwaysAdd || dist(pl, tl) > minDistance && dpr(tru, vector) > 0) {
leftPts.push(tl);
pl = tl;
if (alwaysAdd || dist(pr, tr) > minDistance && dpr(tru, vector) > 0) {
rightPts.push(med(pr, tr));
pr = tr;
} // Set variables for next iteration

@@ -437,0 +446,0 @@

{
"version": "0.4.4",
"version": "0.4.5",
"name": "perfect-freehand",

@@ -4,0 +4,0 @@ "author": {

@@ -120,4 +120,4 @@ import { toPointsArray, getStrokeRadius } from './utils'

easing = t => t,
start = {} as Partial<StrokeOptions['start']>,
end = {} as Partial<StrokeOptions['end']>,
start = {},
end = {},
last: isComplete = false,

@@ -272,6 +272,6 @@ } = options

alwaysAdd ||
(vec.dist(pr, tr) > minDistance && vec.dpr(tlu, vector) > 0)
(vec.dist(pl, tl) > minDistance && vec.dpr(tlu, vector) > 0)
) {
rightPts.push(tr)
pr = tr
leftPts.push(vec.med(pl, tl))
pl = tl
}

@@ -281,6 +281,6 @@

alwaysAdd ||
(vec.dist(pl, tl) > minDistance && vec.dpr(tru, vector) > 0)
(vec.dist(pr, tr) > minDistance && vec.dpr(tru, vector) > 0)
) {
leftPts.push(tl)
pl = tl
rightPts.push(vec.med(pr, tr))
pr = tr
}

@@ -287,0 +287,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet