npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svg.pathmorphing2.js

v0.1.0

Published

Another plugin for the svg.js library to enable path morphing / animation

Downloads

11

Readme

svg.pathmorphing2.js

Another plugin for the svg.js library to enable path morphing / animation.

The algorithm used by this plugin is based on the Interpolate extension of Inkscape.

Compared to the other path morphing plugin for svg.js, this plugin feature better support for the arc command but it might be a little bit slower.

Installation

npm install --save svg.pathmorphing2.js

Usage

How to include

In Html

Include this plugin after including svg.js and svg.point.js in your html document.

CommonJs

You can just require this plugin, it will take care of requiring its dependencies (svg.js and svg.point.js), perform the necessary modification and return you the modified SVG object.

var SVG = require('svg.pathmorphing2.js')

Or, you can require this plugin after having required svg.js.

var SVG = require('svg.js')
require('svg.pathmorphing2.js')

If you are using npm3, the two require in the code above would return a reference to the same object since npm3 install secondary dependencies in a flat way. That would not be the case if you are using npm2 since it installs all dependencies in a nested way.

// If using npm3
var SVG1 = require('svg.js')
var SVG2 = require('svg.pathmorphing2.js')
SVG1 === SVG2 // true
SVG1.Utils.makePathsMorphable != null // true

// If using npm2
var SVG1 = require('svg.js')
var SVG2 = require('svg.pathmorphing2.js')
SVG1 === SVG2 // false
SVG1.Utils.makePathsMorphable != null // false

Long story short, to avoid issues you should use npm3 if you plan to use this plugin with a CommonJs module bundler.

Animating paths

Animating paths is done the same way as all other animation explained in the svg.js docs:

// create path
var path = draw.path('m 382,339 a 155,175 0 0 1 -17,112 c 0,0 -175,-31 -100,-160')

// animate path
path.animate().plot('m 503,363 74,-42 64,64 z')

makePathsMorphable()

This plugin provide the function makePathsMorphable in SVG.utils that take two path string (or any format supported by the SVG.PathArray constructor) that don't have the same commands (which mean that they cannot be morphed in one another) and return an array of two SVG.PathArray that represent two paths that are equivalent to the passed paths (meaning that they produce the same shapes) and that have the same commands (moveto and curveto).

var path1 = "M 90,119 71,88 41,107 54,73 20,61 54,50 43,16 l 29,19 19,-30 3,35 35,-3 -25,24 24,25 -34,-4 z"
  , path2 = "m 18,208 109,0 0,77 -109,0 z"
  , pathsMorphable = SVG.utils.makePathsMorphable(path1, path2)

  // pathsMorphable[0] is equivalent to path1
  pathsMorphable[0].toString() // "M90 119C90 119 71 88 71 88C71 88 41 107 41 107 ...
  // pathsMorphable[1] is equivalent to path2
  pathsMorphable[1].toString() // "M18 208C18 208 26.885065510170534 208 39.581696141082865 208 ...

  // And they use the same commands
  pathsMorphable[0].equalCommands(pathsMorphable[1]) // true

Dependencies

svg.js >= v2.3.6
svg.point.js >= v0.0.1

License

svg.pathmorphing2.js is licensed under the MIT License.