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

@potch/pixeleditor

v1.1.2

Published

portable pixel editor widget

Downloads

4

Readme

PixelEditor

a portable pixel editor widget

npm install @potch/pixeleditor

Touch support is quite lacking right now, but mouse and keyboard support is available!

PixelEditor Class

new PixelEditor(options)

creates new PixelEditor object.

options is an object with the following properties:

name | required? | type | default | description ---|---|---|---|--- width | yes | Number | n/a | width of the drawing height | no | Number | value of width | height of the drawing zoom | no | Number | 8 | amount to scale drawing canvas colors | no | Array | see "Default Colors" below | the colors to display in the widget's palette currentColor | no | Number | 1 | index in colors of the initial drawing color bg | no | Number | 0 | index in colors of the color to use to fill the initial drawing and the drawing after calling clear() container | no | Element | n/a | element to append the widget to. Optional as you can also call mount() onUpdate | no | Function | n/a | callback to call when the drawing changes

Colors

colors are provided as an Array of [red, green, blue] Arrays, where the color components go from 0 to 255.

The default colors are:

[
  [255, 255, 255], // white
  [0, 0, 0],       // black
  [255, 0, 0],     // red
  [255, 255, 0],   // yellow
  [0, 255, 0],     // green
  [0, 255, 255],   // cyan
  [0, 0, 255],     // blue
  [255, 0, 255]    // magenta
];

onUpdate

If a Function is provided to the constructor, it will be called when the drawing is updated. this will refer to the PixelEditor instance.

Methods

These are the intended public methods of the class. Other methods are available, but are subject to change.

mount(container)

Appends the widget to a container element. Called automatically if container is passed to the constructor.

  • container - an existing element on the page

clear([color])

Resets the drawing to a single color.

  • color (optional) - the index in colors of the color every pixel should be set to. Defaults to bg.

resize({ [width], [height], [zoom] })

Resize the drawing canvas to the provided dimensions and zoom. At least one of width, height, and zoom must be provided.

undo()

Restore to the previous drawing state.

toImageData({ [zoom] })

Returns an ImageData object containing the drawing scaled to the provided zoom.

  • zoom (optional) - scaling factor to apply to the drawing when exported. Defaults to 1.

toBlob({ [zoom] }).then(blob => ...)

Returns a Promise that resolves with a Blob of type image/png containing the drawing scaled to the provided zoom.

  • zoom (optional) - scaling factor to apply to the drawing when exported. Defaults to 1.

Keyboard Support

When focused, the following key controls are available:

  • up, down, left, right: move cursor
  • D, L, F: select Draw, Line, Fill tools
  • Z: undo
  • space: activate current tool
  • [ and ]: cycle through colors
  • Alt(Option) + X: clear canvas