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 🙏

© 2026 – Pkg Stats / Ryan Hefner

px-drawer

v0.1.2

Published

![npm](https://img.shields.io/npm/v/px-drawer) ![license](https://img.shields.io/github/license/m-conti/px-drawer) ![bundle size](https://img.shields.io/bundlephobia/min/px-drawer)

Readme

px-drawer

npm license bundle size

px-drawer is a simple, lightweight library that provides a drawable canvas, allowing users to draw, save their drawings, and display them on other canvases.

🚀 Features

  • Easy-to-use drawable canvas
  • Save drawings as images or data
  • Load saved drawings onto other canvases
  • Minimal setup required

📦 Installation

Using npm

npm install px-drawer

Using Yarn

yarn add px-drawer

🔌 Usage

Browser (via CDN)

To use px-drawer in the browser via CDN, include the following script in your HTML file:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>PixelDrawer</title>
  </head>
  <body>
    <div class="container">
      <div id="canvas-editor" class="canvas-container"></div>
      <button onclick="saveTileMap()">SAVE</button>
      <div id="canvas-display" class="canvas-container"></div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/px-drawer@latest/dist/px-drawer.umd.js"></script>
    <script>
      const mapEditor = PixelDrawer.global
        .addColor('#FFFFFF')
        .addColor('#000000')
        .addColor('#FF0000')
        .addColor('#00FF00')
        .addColor('#0000FF')
        .createMapEditor('#canvas-editor', 16, 12)
        .handleCanvasClick()
        .withCursor();

      const map = PixelDrawer.global.createTileMap('#canvas-display');
      globalThis.saveTileMap = () => {
        const mapToSave = mapEditor.saveMap();

        // save it wherever you want ...
        console.log('saveTileMap', mapToSave);

        // you can read it like this :
        map.readMap(mapToSave);
      };
    </script>
    <style>
      body { background-color: #202020; }
      .canvas-container { width: 100%; }
      #canvas-display { width: 80%; }
      .container {
        display: flex;
        flex-direction: column;
        gap: 1rem;
      }
    </style>
  </body>
</html>

Using npm

To use px-drawer in a project with npm, follow these steps:

  1. Install the package:
npm install px-drawer
  1. Import and use it in your JavaScript file:
import PixelDrawer from 'px-drawer';

const mapEditor = PixelDrawer.global
  .addColor('#FFFFFF')
  .addColor('#000000')
  .addColor('#FF0000')
  .addColor('#00FF00')
  .addColor('#0000FF')
  .createMapEditor('#canvas-editor', 16, 12)
  .handleCanvasClick()
  .withCursor();

const map = PixelDrawer.global.createTileMap('#canvas-display');
globalThis.saveTileMap = () => {
  const mapToSave = mapEditor.saveMap();

  // save it wherever you want ...
  console.log('saveTileMap', mapToSave);

  // you can read it like this :
  map.readMap(mapToSave);
};

📜 API Reference

PixelDrawer

You can have multiple PixelDrawer for you app with const pixelDrawer = new PixelDrawer(); or you can use a global one for all the app with PixelDrawer.global

setPixelRatio(ratio: number): PixelDrawer

Sets the pixel ratio for the canvas. It'll not change the size of the pixel but it will change the precision of the canvas to have or avoid blur effect.

addColor(color: ColorStr): PixelDrawer

Adds a new color to the color set.

setColors(data: ColorStr[]): PixelDrawer

Set and replace multiple colors to the color set.

createTileMap(el?: HTMLCanvasElement | string, map?: MapStr): TileMap

Creates a new TileMap instance. linked to a canvas.

If no el is provided, you can link it after with: setElement

If no map is provided, you can add it later with: readMap

createMapEditor(el?: HTMLCanvasElement | string, width?: number, height?: number): MapEditor

Creates a new MapEditor instance.

If no el is provided, you can link it after with: setElement

If no height is provided it will take the width.

If no width is provided it will set to 4.

The width and the height should be > 0.

TileMap

setElement(el: HTMLCanvasElement | string): TileMap

Sets the canvas element for the tile map.

readMap(mapStr: MapStr): TileMap

Reads and sets the map data from a string.

MapEditor

setElement(el: HTMLCanvasElement | string): MapEditor

Sets the canvas element for the tile map.

readMap(mapStr: MapStr): MapEditor

Reads and sets the map data from a string.

setSize(width: number, height: number): MapEditor

Sets the size of the canvas.

hideColorSet(): MapEditor

Hides the color set from the canvas.

showColorSet(): MapEditor

Shows the color set on the canvas.

setSelectedColor(color: number): MapEditor

Sets the selected color for drawing. If you want to use an alternative as handleCanvasClick

createEmptyMap(width: number, height: number): MapEditor

Creates an empty map with the specified width and height.

saveMap(withColorSet = false): MapStr

Saves the current map data as a string. with the color set or not

setColor(x: number, y: number, color = this.selectedColor): MapEditor

Sets the color of a specific pixel in the map.

handleCanvasClick(): MapEditor

Enables handling of canvas click events for drawing.

removeCanvasClick(): MapEditor

Disables handling of canvas click events for drawing.

withCursor(): MapEditor

Enables cursor visibility (under mouse + selected color).

withoutCursor(): MapEditor

Disables cursor visibility (under mouse + selected color).

📖 Examples

Basic Example

Here is a basic example of how to use px-drawer to create a simple drawing application:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>PixelDrawer Example</title>
  </head>
  <body>
    <div class="container">
      <div id="canvas-editor" class="canvas-container"></div>
      <button onclick="saveDrawing()">Save Drawing</button>
      <div id="canvas-display" class="canvas-container"></div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/px-drawer@latest/dist/px-drawer.umd.js"></script>
    <script>
      const editor = PixelDrawer.global
        .addColor('#FFFFFF')
        .addColor('#000000')
        .addColor('#FF0000')
        .addColor('#00FF00')
        .addColor('#0000FF')
        .createMapEditor('#canvas-editor', 16, 16)
        .handleCanvasClick();

      const display = PixelDrawer.global.createTileMap('#canvas-display');

      function saveDrawing() {
        const drawing = editor.saveMap();
        console.log('Saved Drawing:', drawing);
        display.readMap(drawing);
      }
    </script>
    <style>
      body { background-color: #f0f0f0; }
      .canvas-container { border: 1px solid #000; }
      .container { display: flex; flex-direction: column; gap: 1rem; }
    </style>
  </body>
</html>

This example sets up a basic HTML page with two canvases: one for drawing and one for displaying the saved drawing. The saveDrawing function saves the drawing from the editor and displays it on the second canvas.

🛠 Development

git clone https://github.com/m-conti/px-drawer.git
cd px-drawer
npm install
npm run dev

✅ Tests

No tests are implemented for the moment.

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions are welcome! Please open an issue or submit a pull request.

📬 Contact