Socket
Socket
Sign inDemoInstall

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 0.1.1 to 0.1.2

CHANGELOG.md

6

dist/perfect-freehand.cjs.development.js

@@ -181,3 +181,3 @@ 'use strict';

var sp = Math.min(distance / pressureVelocityEffect, 1);
ip = clamp(pp + (rp - pp) * (pressureChangeRate * sp), 0, 1);
ip = Math.min(1, pp + (rp - pp) * (pressureChangeRate * sp));
}

@@ -187,3 +187,3 @@ } // Size is based on pressure

size = minSize + ip * (maxSize - minSize); // Taper start
size = clamp(minSize + ip * (maxSize - minSize), minSize, maxSize); // Taper start

@@ -222,3 +222,3 @@ if (length < 16) {

prev = [x, y, angle, distance, size];
prev = [x, y, ip];
}

@@ -225,0 +225,0 @@

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=(e=require("polygon-clipping"))&&"object"==typeof e&&"default"in e?e.default:e;function t(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function n(e,r){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return t(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,void 0):void 0}}(e))||r&&e&&"number"==typeof e.length){n&&(e=n);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}var o=Math.hypot,a=Math.cos,i=Math.max,u=Math.min,s=Math.sin,v=Math.atan2,l=Math.PI/2;function f(e,r,t,n){return[a(t)*n+e,s(t)*n+r]}function d(e,r,t,n){return[e+(t-e)/2,r+(n-r)/2]}exports.default=function(e,t){void 0===t&&(t={});var a,s,p,h,c=t.type,y=void 0===c?"mouse":c,m=t.simulatePressure,M=void 0===m||m,b=t.streamline,g=void 0===b?.5:b,A=t.minSize,S=void 0===A?2.5:A,x=t.maxSize,j=void 0===x?8:x,I=t.smooth,w=void 0===I?8:I,O=t.pressureChangeRate,P=void 0===O?.5:O,z=t.pressureMaxVelocity,C=void 0===z?8:z,E=t.pressureVelocityEffect,V=void 0===E?8:E,_=function(e){return Array.isArray(e[0])?e.map((function(e){var r=e[2];return[e[0],e[1],void 0===r?.5:r]})):e.map((function(e){var r=e.pressure;return[e.x,e.y,void 0===r?.5:r]}))}(e),q=[],Q=_.length,R=0,T=_[0],U=_[Q-1],$=T,k=T,B=U,D=T,F=T,G=0,H="";if(0===Q)return"";if(Q<4){var J=(S+(j-S))*("pen"===y?U[2]:.44);H="\n M "+(U[0]-J)+","+U[1]+"\n a "+J+","+J+" 0 1,0 "+2*J+",0\n a "+J+","+J+" 0 1,0 -"+2*J+",0\n "}else{for(var K=0;K<_.length;K++){var L=_[K],N=L[2],W=$[0],X=$[1],Y=$[2];if(p=v((s=X+(L[1]-X)*(1-g))-X,(a=W+(L[0]-W)*(1-g))-W),G+=R=o(s-X,a-W),"pen"===y)N=Y+(N-Y)*P;else if(M){var Z=1-R/C,ee=Math.min(R/V,1);N=i(0,u(1,Y+P*ee*(Z-Y)))}else N=1;if(h=S+N*(j-S),G<16){var re=G/16;h*=re*re*re}T=f(a,s,p-l,h),U=f(a,s,p+l,h),0===K?(k=T,B=U):(Math.hypot(T[0]-k[0],T[1]-k[1])>w&&(q.push(D),D=d(k[0],k[1],T[0],T[1]),k=T),Math.hypot(U[0]-B[0],U[1]-B[1])>w&&(q.unshift(F),F=d(B[0],B[1],U[0],U[1]),B=U)),$=[a,s,p,R,h]}q.push($),q.unshift($);for(var te,ne=n(r.union([q]));!(te=ne()).done;)for(var oe,ae=n(te.value);!(oe=ae()).done;){var ie=oe.value,ue=ie[0],se=ie[1];ie.push(ue),H+=" M "+ue[0]+" "+ue[1];for(var ve=1;ve<ie.length;ve++){var le=d(ue[0],ue[1],se[0],se[1]);H+=" Q "+ue[0]+","+ue[1]+" "+le[0]+","+le[1],ue=se,se=ie[ve+1]}}}return H};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=(e=require("polygon-clipping"))&&"object"==typeof e&&"default"in e?e.default:e;function t(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function n(e,r){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return t(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,void 0):void 0}}(e))||r&&e&&"number"==typeof e.length){n&&(e=n);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}var o=Math.hypot,a=Math.cos,i=Math.max,u=Math.min,s=Math.sin,v=Math.atan2,l=Math.PI/2;function f(e,r,t,n){return[a(t)*n+e,s(t)*n+r]}function d(e,r,t,n){return[e+(t-e)/2,r+(n-r)/2]}exports.default=function(e,t){void 0===t&&(t={});var a,s,h,p,c=t.type,y=void 0===c?"mouse":c,m=t.simulatePressure,M=void 0===m||m,b=t.streamline,g=void 0===b?.5:b,A=t.minSize,S=void 0===A?2.5:A,x=t.maxSize,j=void 0===x?8:x,I=t.smooth,w=void 0===I?8:I,O=t.pressureChangeRate,P=void 0===O?.5:O,z=t.pressureMaxVelocity,C=void 0===z?8:z,E=t.pressureVelocityEffect,V=void 0===E?8:E,_=function(e){return Array.isArray(e[0])?e.map((function(e){var r=e[2];return[e[0],e[1],void 0===r?.5:r]})):e.map((function(e){var r=e.pressure;return[e.x,e.y,void 0===r?.5:r]}))}(e),q=[],Q=_.length,R=0,T=_[0],U=_[Q-1],$=T,k=T,B=U,D=T,F=T,G=0,H="";if(0===Q)return"";if(Q<4){var J=(S+(j-S))*("pen"===y?U[2]:.44);H="\n M "+(U[0]-J)+","+U[1]+"\n a "+J+","+J+" 0 1,0 "+2*J+",0\n a "+J+","+J+" 0 1,0 -"+2*J+",0\n "}else{for(var K=0;K<_.length;K++){var L=_[K],N=L[2],W=$[0],X=$[1],Y=$[2];if(h=v((s=X+(L[1]-X)*(1-g))-X,(a=W+(L[0]-W)*(1-g))-W),G+=R=o(s-X,a-W),"pen"===y)N=Y+(N-Y)*P;else if(M){var Z=1-R/C,ee=Math.min(R/V,1);N=Math.min(1,Y+P*ee*(Z-Y))}else N=1;if(p=i(S,u(j,S+N*(j-S))),G<16){var re=G/16;p*=re*re*re}T=f(a,s,h-l,p),U=f(a,s,h+l,p),0===K?(k=T,B=U):(Math.hypot(T[0]-k[0],T[1]-k[1])>w&&(q.push(D),D=d(k[0],k[1],T[0],T[1]),k=T),Math.hypot(U[0]-B[0],U[1]-B[1])>w&&(q.unshift(F),F=d(B[0],B[1],U[0],U[1]),B=U)),$=[a,s,N]}q.push($),q.unshift($);for(var te,ne=n(r.union([q]));!(te=ne()).done;)for(var oe,ae=n(te.value);!(oe=ae()).done;){var ie=oe.value,ue=ie[0],se=ie[1];ie.push(ue),H+=" M "+ue[0]+" "+ue[1];for(var ve=1;ve<ie.length;ve++){var le=d(ue[0],ue[1],se[0],se[1]);H+=" Q "+ue[0]+","+ue[1]+" "+le[0]+","+le[1],ue=se,se=ie[ve+1]}}}return H};
//# sourceMappingURL=perfect-freehand.cjs.production.min.js.map

@@ -175,3 +175,3 @@ import polygonClipping from 'polygon-clipping';

var sp = Math.min(distance / pressureVelocityEffect, 1);
ip = clamp(pp + (rp - pp) * (pressureChangeRate * sp), 0, 1);
ip = Math.min(1, pp + (rp - pp) * (pressureChangeRate * sp));
}

@@ -181,3 +181,3 @@ } // Size is based on pressure

size = minSize + ip * (maxSize - minSize); // Taper start
size = clamp(minSize + ip * (maxSize - minSize), minSize, maxSize); // Taper start

@@ -216,3 +216,3 @@ if (length < 16) {

prev = [x, y, angle, distance, size];
prev = [x, y, ip];
}

@@ -219,0 +219,0 @@

{
"version": "0.1.1",
"version": "0.1.2",
"license": "MIT",

@@ -4,0 +4,0 @@ "main": "dist/index.js",

# Perfect Freehand
Perfect freehand is a library for creating freehand paths. By [@steveruizok](https://twitter.com/steveruizok).
Perfect freehand is a library for creating freehand paths by [@steveruizok](https://twitter.com/steveruizok).
[!Screenshot](/screenshot.png)
![Screenshot](/screenshot.png)
🔗 [Demo](https://perfect-freehand-example.vercel.app/)
## Installation

@@ -23,6 +25,8 @@

The array of points may be _either_ an array of number pairs or an array of objects with `x` and `y` properties.
The array of points may be _either_ an array of number pairs representing the point's x, y, and (optionally) pressure...
```js
getPath([
import getPath from 'perfect-freehand'
const path = getPath([
[0, 0],

@@ -33,2 +37,12 @@ [10, 5],

const path = getPath([
[0, 0, 0],
[10, 5, 0.5],
[20, 8, 0.3],
])
```
...or an array of objects with `x`, `y`, and (optionally) `pressure` properties.
```
getPath([

@@ -39,4 +53,12 @@ { x: 0, y: 0 },

])
getPath([
{ x: 0, y: 0, pressure: 0, },
{ x: 10, y: 5, pressure: 0.5 },
{ x: 20, y: 8, pressure: 0.3 },
])
```
### Options

@@ -72,4 +94,4 @@

function Example() {
const [currentType, setCurrentType] = React.useState([])
export default function Example() {
const [currentType, setCurrentType] = React.useState("mouse")
const [currentMark, setCurrentMark] = React.useState([])

@@ -95,3 +117,3 @@

>
<path d={getPath(currentMark, { type: currentType })}>
<path d={getPath(currentMark, { type: currentType })}/>
</svg>

@@ -101,1 +123,3 @@ )

```
[![Edit perfect-freehand-example](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/perfect-freehand-example-biwyi?fontsize=14&hidenavigation=1&theme=dark)

@@ -131,3 +131,3 @@ import polygonClipping from 'polygon-clipping'

const sp = Math.min(distance / pressureVelocityEffect, 1)
ip = clamp(pp + (rp - pp) * (pressureChangeRate * sp), 0, 1)
ip = Math.min(1, pp + (rp - pp) * (pressureChangeRate * sp))
}

@@ -137,3 +137,3 @@ }

// Size is based on pressure
size = minSize + ip * (maxSize - minSize)
size = clamp(minSize + ip * (maxSize - minSize), minSize, maxSize)

@@ -170,3 +170,3 @@ // Taper start

prev = [x, y, angle, distance, size]
prev = [x, y, ip]
}

@@ -173,0 +173,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

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