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

drawable-js

v1.0.4

Published

A lightweight JavaScript library to draw shapes and effects on HTML canvas, inspired by Android's Drawable.

Readme

DrawableJS

GitHub release npm version npm downloads License GitHub language top ESLint CI

DrawableJS is a lightweight JavaScript library to draw shapes, gradients, styled text, and more on HTML5 <canvas>. It is inspired by Android's Drawable resource, but designed for the modern web.

Features

  • Draw basic shapes: rectangles, ovals, lines and images.
  • Support for solid colors and gradients (linear and radial).
  • Option to set borders, rounded corners, and shadows.
  • Render text with font and alignment options.
  • Extendable structure: each shape can include extra content.
  • Compatible with both ES Modules and classic script tags (UMD).
  • Inspired by Android’s Drawable and Canvas system.

Installation

Install via npm:

npm install drawable-js

Or include directly in the browser (UMD version):

<script src="dist/drawable.umd.js"></script>

Usage

With ES Modules

Draw a Rectangle with Linear Gradient:

import { Drawable, Shape, Gradient } from 'drawable-js';

const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");

const rect = new Drawable(200, 100);
rect.ctx = ctx;
rect.update = () => {
    rect.items = [
    {
        shape: Shape.RECTANGLE,
        x: 20,
        y: 20,
        width: 200,
        height: 100,
        gradient: {
            type: Gradient.LINEAR_GRADIENT,
            angle: 45,
            center: { x: '50%', y: '50%' },
            startColor: "#FF5733",
            endColor: "#FFC300"
        },
        stroke: {
            color: "#333333",
            width: 2
        },
        cornerRadius: [15, 15, 15, 15]
    }
    ];
};
rect.build();

Result:

Rectangle

Draw a Circle with Radial Gradient:

import { Drawable, Shape, Gradient } from 'drawable-js';

const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");

const circle = new Drawable(100, 100);
circle.ctx = ctx;
circle.update = () => {
    circle.items = [
        {
            shape: Shape.OVAL,
            x: 300,
            y: 150,
            radius: 50,
            gradient: {
                type: Gradient.RADIAL_GRADIENT,
                center1: { x: 300, y: 150 },
                radius1: 10,
                center2: { x: 300, y: 150 },
                radius2: 50,
                startColor: "#00c6ff",
                endColor: "#0072ff"
            },
            stroke: {
                color: "#333333",
                width: 2
            }
        }
    ];
};
circle.build();

Result:

Circle

With UMD in Browser

Draw a Rectangle with Linear Gradient:

<script src="dist/drawable.umd.js"></script>
<script>
  const canvas = document.getElementById("myCanvas");
  const ctx = canvas.getContext("2d");

  const rect = new DrawableJS.Drawable(200, 100);
  rect.ctx = ctx;
  rect.update = () => {
      rect.items = [
      {
          shape: DrawableJS.Shape.RECTANGLE,
          x: 20,
          y: 20,
          width: 200,
          height: 100,
          gradient: {
              type: DrawableJS.Gradient.LINEAR_GRADIENT,
              angle: 45,
              center: { x: '50%', y: '50%' },
              startColor: "#FF5733",
              endColor: "#FFC300"
          },
          stroke: {
              color: "#333333",
              width: 2
          },
          cornerRadius: [15, 15, 15, 15]
      }
      ];
  };
  rect.build();
</script>

Result:

Rectangle

Draw a Circle with Radial Gradient:

<script src="dist/drawable.umd.js"></script>
<script>
  const canvas = document.getElementById("myCanvas");
  const ctx = canvas.getContext("2d");

  const circle = new DrawableJS.Drawable(100, 100);
  circle.ctx = ctx;
  circle.update = () => {
      circle.items = [
          {
              shape: DrawableJS.Shape.OVAL,
              x: 300,
              y: 150,
              radius: 50,
              gradient: {
                  type: DrawableJS.Gradient.RADIAL_GRADIENT,
                  center1: { x: 300, y: 150 },
                  radius1: 10,
                  center2: { x: 300, y: 150 },
                  radius2: 50,
                  startColor: "#00c6ff",
                  endColor: "#0072ff"
              },
              stroke: {
                  color: "#333333",
                  width: 2
              }
          }
      ];
  };
  circle.build();
</script>

Result:

Circle

Fonts

You can preload fonts into the Canvas using FontLoader.load:

import { FontLoader, Font } from 'drawable-js';

FontLoader.load({
  families: [Font.ARIAL],
  active: () => {
    console.log("Fonts ready!");
  }
});

Demos

You can explore working examples in the /demo folder:

  • demo/esm/drawable-demo.html: for modern projects using <script type="module">
  • demo/umd/drawable-demo.html: for legacy support using UMD script

Run locally:

npm run dev

Then open one of the demo pages in your browser.

Examples in the demo

Color filter in images:

ColorFilterInImages

Text position:

TextPosition

Animations:

Animations

Development

Build the library before testing:

npm run build

Inspiration

This system is inspired by the Android Drawable class. It's made to help developers who are familiar with Android work easily on drawing and graphic design projects in the web environment.

License

DrawableJS is now released under the MIT License.

This change allows for more flexibility in how the library can be used, both in open-source and proprietary software.

For more details, see the LICENSE file or visit: https://opensource.org/licenses/MIT

Note: Previous versions released under the GPLv3 license remain under that license.

Author

Created by jaianper. Feel free to contribute or suggest improvements!