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

@svgdotjs/svg.select.js

v4.0.1

Published

An extension of svg.js which allows to select elements with mouse

Downloads

473

Readme

svg.select.js

An extension of svg.js which allows to select elements with mouse

Demo

For a demo see http://svgdotjs.github.io/svg.select.js/

Get Started

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

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

    <script src="https://unpkg.com/@svgdotjs/svg.js"></script>
    <script src="https://unpkg.com/@svgdotjs/svg.select.js"></script>
  • Select a rectangle using this simple piece of code:

    var canvas = new SVG().addTo('body').size(500, 500)
    canvas.rect(50, 50).fill('red').select()

Usage

Select

var canvas = SVG().addTo('body')
var rect = canvas.rect(100, 100)
var polygon = canvas.polygon([
  [100, 100],
  [200, 100],
  [200, 200],
  [100, 200],
])
rect.select()
polygon.pointSelect()

// both also works
polygon.select().pointSelect()

Unselect

rect.select(false)

Adaptation

Sometimes, the default shape is not to your liking. Therefore, you can create your own handles by passing in a create and update function:

rect.select({
  createHandle: (group, p, index, pointArr, handleName) => group.circle(10).css({ stroke: '#666', fill: 'blue' }),
  updateHandle: (group, p, index, pointArr, handleName) => group.center(p[0], p[1]),
  createRot: (group) => group.circle(10).css({ stroke: '#666', fill: 'blue' }),
  updateRot: (group, rotPoint, handlePoints) => group.center(p[0], p[1]),
})

polygon.pointSelect({
  createHandle: (group, p, index, pointArr, handleName) => group.circle(10).css({ stroke: '#666', fill: 'blue' }),
  updateHandle: (group, p, index, pointArr, handleName) => group.center(p[0], p[1]),
})

You can style the selection with the classes

  • svg_select_shape - normal selection
  • svg_select_shape_pointSelection - point selection
  • svg_select_handle- any normal selection handles
  • svg_select_handle_lt - left top
  • svg_select_handle_rt - right top
  • svg_select_handle_rb - right bottom
  • svg_select_handle_lb - left bottom
  • svg_select_handle_t - top
  • svg_select_handle_r - right
  • svg_select_handle_b - bottom
  • svg_select_handle_l - left
  • svg_select_handle_rot - rotation point
  • svg_select_handle_point - point select point

Contributing

git clone https://github.com/svgdotjs/svg.select.js.git
cd svg.select.js
npm install
npm run dev

Migration from svg.js v2

  • The css classes changed. In case you used your own styling, you'll need to adapt
  • A lot of options got dropped in favor of the create and update functions
    • In case you want to hide certain handles, just create an element without any size and pass a noop to update
  • the deepSelect option was moved to its own function and renamed to pointSelect