Code Monkey home page Code Monkey logo

normalize-svg-path's Introduction

normalize-svg-path build

Convert all segments in a path to curves. Usefull if you intend to animate one shape to another. By defining all segments with curves instead of a mix of lines, arcs, and curves tweening becomes much simpler. It could also help you rewrite your SVG code according to the principles of narcissistic design.

Usage

npm install normalize-svg-path

import parse from 'parse-svg-path'
import abs from 'abs-svg-path'
import normalize from 'normalize-svg-path'

const segments = normalize(abs(parse('M0 0L10 10A10 10 0 0 0 20 20Z')))

API

normalize(path)

Translate each segment in path to an equivalent cubic bézier curve. The input path must be absolute.

normalize([['L',1,2]]) // => [['C',0,0,1,2,1,2]]

normalize-svg-path's People

Contributors

dy avatar jkroso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

normalize-svg-path's Issues

Using π for pi problematic with at least browserify

By default a <script> tag doesn't interpret src as unicode, therefor using π fails with unexpected token. It can be resolved by specifying charset, but overall I don't know if it's worth it to require unicode support just for 1 symbol.

Bump up npm with latest code

Hello,

Is it possible to approve the open PR and update the npm registry with the latest fix? It seems it not part of version 1.0.1.

Thanks.

Warning in Metro Build

warn Package normalize-svg-path has been ignored because it contains invalid configuration. Reason: Package subpath './package.json' is not defined by "exports" in ..../node_modules/normalize-svg-path/package.json

Wrong normalization of arc command

Say we have M 10 10A 15 15 0 1 0 25 5Z, which looks as
image

After we normalize, we get M 10 10C 2.6150075366704613 18.87666714763482 7.608661308541146 32.4190729673544 18.98857679099642 34.376330473536996C 30.368492273451693 36.33358797971959 39.59973285261361 25.237754045176068 35.604809833487884 14.40382939135866C 35.604809833487884 14.40382939135866 10 10 10 10, which looks as
image

Close command left out of normalized path

Is it expected that the close path command is omitted when normalizing path data?

Running the script shown in the README you can see the Z is left off.

no-close-path

Running the same script with just converting the path data to absolute points you can see the Z close path command is included.

abs-close-path

Removes the close path

The close paths are droped when using this.

var normalize = require('normalize-svg-path')
var parse = require("parse-svg-path")

Notice that parse does this correctly:

parse("M0 0L10 10A10 10 0 0 0 20 20 Z M10,10 Z")
[
  [ 'M', 0, 0 ],
  [ 'L', 10, 10 ],
  [
    'A', 10, 10, 0,
    0,   0,  20, 20
  ],
  [ 'Z' ],                                //<--- close path
  [ 'M', 10, 10 ],
  [ 'Z' ]                                // <--- close path
]

Normalize introduces an error

> normalize(parse("M0 0L10 10A10 10 0 0 0 20 20 Z M10,10Z"))
[
  [ 'M', 0, 0 ],
  [
    'C', 0,  0,  10,
    10,  10, 10
  ],
  [
    'C',
    10.000000000000002,
    15.51915024494,
    14.480849755060001,
    20,
    20,
    20
  ],
  [
    'C', 20, 20, 0,
    0,   0,  0
  ],
                                    //<--- missing
  [ 'M', 10, 10 ],
  [
    'C', 10, 10, 10,
    10,  10, 10
  ]
                                   //<--- missing
]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.