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

scene-2d

v2.0.0

Published

Multitouch capable 2d scene implementing pan, zoom and object selection

Downloads

5

Readme

scene-2d

Multitouch capable 2d scene implementing pan, zoom and object selection.

How

Synthesizing touch events from mouse events.

Example

var Scene2d = require('scene-2d')

// create a scene
customElements.define('scene-2d', Scene2d)
var scene = document.createElement('scene-2d')
scene.addEventListener('select', () => console.log('scene selection state changed', scene.selections))
scene.addEventListener('scale', () => console.log('scene zoomed', scene.scale))
scene.addEventListener('move', () => console.log('scene panned', scene.origin))

// add scene to display
var reference = document.querySelector('#reference')
reference.appendChild(scene)

// define an object to use in the scene
customElements.define('object-2d', class extends HTMLElement {
  constructor () {
    super()
    this.origin = [0,0,0]
    this.movable = true
    this.selectable = true
    this.addEventListener('origin', () => {
      this.style.transform = `translate3d(${this.origin[0]}px,${this.origin[1]}px,${this.origin[2]}px)`
    })
    this.addEventListener('select', () => {
      this.classList[this.selected ? 'add' : 'remove']('selected')
    })
    this.addEventListener('move', () => {
      console.log('object moved', this.origin)
    })
  }

  connectedCallback () {
    this.classList.add('object-2d')
    this.innerHTML = `<div id=handle></div>`
    var handle = this.querySelector('#handle')
    handle.object = this
  }
})

// create and add some objects to the scene
scene.objects.appendChild(document.createElement('object-2d'))
scene.objects.appendChild(document.createElement('object-2d'))
scene.objects.appendChild(document.createElement('object-2d'))

You can run this example by doing:

$ npm run example

API (scene)

This is the API for the scene itself, see the object API below for individual objects.

Properties

scene.origin

Array of pixel offsets (e.g. [x,y,z]) representing the current pan position.

scene.scale

Current zoom scale.

scene.selections

Array of all currently selected objects.

scene.objects

Container element for all objects in the scene.

Methods

scene.render()

Writes the scene's current origin and scale to the display.

Events

scene.addEventListener('move', fn)

Dispatched when a pan operation ends.

scene.addEventListener('scale', fn)

Dispatched when a zoom operation ends.

scene.addEventListener('select', fn)

Dispatched when the scene's selection state has changed.

API (objects)

Any elements you append to scene.objects may implement these properties or listen for these events.

Properties

object.object

Pointer to another object to consider as the target. Useful for implementing grip or handle interfaces.

object.selectable

Boolean indicating whether the object is selectable.

object.selected

Boolean representing the object's selection state.

object.movable

Boolean indicating whether the object is movable.

object.origin

Array of pixel offsets (e.g. [x,y,z]) representing the object's current position. Required if object.movable is set to true true.

Events

object.addEventListener('origin', fn)

Dispatched during a drag operation.

object.addEventListener('move', fn)

Dispatched when a drag operation ends.

object.addEventListener('select', fn)

Dispatched when the object's selection state has changed.

Releases

  • 1.0
    • First release

License

MIT