svg-path-interpolator
Advanced tools
Comparing version 0.1.1 to 0.2.0
{ | ||
"author": "Justin Wilaby", | ||
"name": "svg-path-interpolator", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"license": "MIT", | ||
"main": "src/index.js" | ||
"description": "The SVG Path Interpolator produces point data representing interpolated values within an SVG path.", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/justinwilaby/svg-path-interpolator.git" | ||
}, | ||
"bin": { | ||
"svgpi": "./bin/svgpi.js" | ||
}, | ||
"main": "src/SVGPathInterpolator.js", | ||
"files": [ | ||
"src" | ||
], | ||
"keywords": [ | ||
"svg", | ||
"points", | ||
"paths", | ||
"drawing", | ||
"interpolate", | ||
"calculate", | ||
"animate", | ||
"bézier", | ||
"bezier", | ||
"curves", | ||
"polygon" | ||
], | ||
"dependencies": { | ||
"sax": "^1.2.1" | ||
} | ||
} |
# SVG Path Interpolator | ||
The SVG Path Interpolator produces point data representing interpolated values within an SVG path. This is handy when you need to calculate complex paths for animation or drawing APIs beforehand. Complex paths that include Bézier curves are converted to polygons with a configurable segment sampling size producing more points with greater precision or fewer points for speed. Polygon path data can be used to animate, draw or for hit detection in games. | ||
## Install | ||
```bash | ||
npm install svg-path-interpolator --save | ||
``` | ||
or as a cli | ||
```bash | ||
npm install -g svg-path-interpolator | ||
``` | ||
## Usage | ||
See the `sample.config.json` for configuration options | ||
```js | ||
For Node cli users, create a config.json somewhere in your project. See the `sample.config.json` for configuration options. | ||
```json | ||
{ | ||
"files": [ | ||
"sample.svg" | ||
], | ||
"outputDirectory": "out/", | ||
"trim": true, | ||
"joinPathData": false, | ||
"minDistance": 0.5, | ||
@@ -20,9 +25,32 @@ "roundToNearest": 0.25, | ||
``` | ||
### files | ||
The `files` array identifies the files to process. | ||
### outputDirectory | ||
`outputDirectory` identifies where to write the path data. If omitted, all path data is written to stdout. | ||
### trim | ||
When `trim` is `true`, paths that were translated are normalized and will begin at 0,0 | ||
Then from your terminal, type | ||
```bash | ||
svgpi ./path/to/config.json ./path/to/target.svg ./output/fileName.json | ||
``` | ||
For ES6 users, create a new instance of the SVGPathInterpolator | ||
```js | ||
import SVGPathInterpolator from 'SVGPathInterpolator'; | ||
const svgString = ` | ||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" | ||
width="792px" height="612px" viewBox="0 0 792 612" enable-background="new 0 0 792 612" xml:space="preserve"> | ||
<g> | ||
<path id="path3789" d="M287.168,442.411 | ||
c-8.65,0-15.652,7.003-15.652,15.653 | ||
c0,8.65,7.003,15.69,15.652,15.69 | ||
s15.653-7.04,15.653-15.69 | ||
"/> | ||
</g> | ||
</svg> | ||
`; | ||
const config = { | ||
joinPathData: false, | ||
minDistance: 0.5, | ||
roundToNearest: 0.25, | ||
sampleFrequency: 0.001 | ||
}; | ||
const interpolator = new SVGPathInterpolator(config); | ||
const pathData = interpolator.processSvg(svgString); | ||
``` | ||
### joinPathData | ||
When `joinPathData` is `true`, all path data is joined in a single array as the output. When `false`, each path is separated by the path `id` attribute in a json object as the output. If no `id` attribute exists on the path, a unique id is created. | ||
### minDistance | ||
@@ -34,5 +62,5 @@ `minDistance` is the minimum distance between the current and previous points when sampling. If a sample results in a distance less than the specified value, the point is discarded. | ||
`sampleFrequency` determines the increment of `t` when sampling. If `sampleFrequency` is set to `.001` , since `t` iterates from 0 to 1, there will be 1000 points sampled per command but only points that are greater than `minDistance` are captured. | ||
### pretty | ||
### pretty (cli only) | ||
When `true`, `pretty` creates formatted json output | ||
### prettyIndent | ||
### prettyIndent (cli only) | ||
Then number of spaces to indent when `pretty` is `true` | ||
@@ -39,0 +67,0 @@ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
69
0
35646
1
7
3
70
777
+ Addedsax@^1.2.1
+ Addedsax@1.4.1(transitive)