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.patheditor.js

v1.0.0

Published

An extension for svg.js which allows editing path with the mouse

Downloads

3

Readme

svg.patheditor.js

An extension for svg.js which allows editing paths with the mouse (Inspired by @svgdotjs/svg.select.js and @svgdotjs/svg.resize.js).

Getting Started

  • Install svg.js and svg.select.js using npm:

    npm i @svgdotjs/svg.js svg.patheditor.js
  • Or get it from a cnd:

    <script src="https://unpkg.com/@svgdotjs/svg.js"></script>
    <script src="https://unpkg.com/svg.patheditor.js"></script>

Demo

Fork the repo, clone it, run npm install and npm run dev to try it out.

Usage

  • Use showControls on a path to show the control points and handles:

    let canvas = new SVG().addTo('body').size(500, 500)
    let path = canvas.path('M10 50 C50 100 100 10 100 50').showControls()
  • Use manipulate to allow dragging around the control points and handles:

    let canvas = new SVG().addTo('body').size(500, 500)
    let path = canvas.path('M10 50 C50 100 100 10 100 50').showControls().manipulate()
  • To disable, pass false to either showControls or manipulate:

    path.manipulate(false)
    path.showControls(false)

Adaptation

You can pass in your own PathSelectHandler or PathManipulator (warning: this feature may disappear)

You can override the styles of the control points, control handles and their stalks with the following classes:

For Arcs, we have control handles for rx, ry and the arc's rotation

Each control point and handle also gets a cpid identifier attribute composed of the segment (path command) number and the point's purpose. For this, we follow the naming conventions of the SVG specification in Chapter 9: Paths.

E.g. the path shown above is an absolute cubic Bézier curve with the following definition:

M10 50 C50 100 100 10 100 50

There are two segments (path commands) in this path: an absolute moveto M and an absolute cubic Bézier curve C.

In the specs, M has an x and y argument, and C has x1 y1 x2 y2 x and y arguments. This is reflected in the cpid attributes places on the controls:

We add additional classes to reflect the type of control

Issues and open points

  • We currently handle only one set of arguments per segment. E.g. for the example path, we only have M x y and C x1 y1 x2 y2 x y, but the path specification allows multiple sets of arguments: M (x y)+ and C (x1 y1 x2 y2 x y)+
    Fixing this will affect the format of the cpid attribute values
  • Smooth quadratic curves (T or t) don't have their own control handles as the control point is assumed to be the reflection of the control point on the previous command relative to the current point. We draw this reflected point in gray, but unfortunately, these reflected points are not always drawn in the correct position. To be fixed.
  • Currently the only way to affect the manipulation is to pass your own PathManipulation class. We plan to replace this with callbacks so you can e.g. limit movement of the control points and handles to the horizontal or the vertical axis; constraint the manipulations to a grid; etc