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

@zthun/works.draw

v4.0.0

Published

A package that contains the modeling and algorithms to draw to a canvas.

Downloads

84

Readme

Description

The draw package allows a developer to manipulate a canvas object similar to how applications such as The Gimp and Photoshop structure their drawings.

Installation

# NPM
npm install rxjs @zthun/works.draw
# Yarn
yarn add rxjs @zthun/works.draw

Introduction

Draw is structured with the root item being of type ZPrintableDrawing. A printable drawing is a model representation of how to render to an HTML Canvas drawing context and is structured in three stacked layers, the background, the middleground, and the foreground.

All of the layers have the same structure; the only difference between the layers is that any transformations that occur in each of the layers do not affect the other layers. For example, lets say the entire middleground has a scaling transformation of 200%. When the middleground is drawn, it will draw at 200% of its size, but when the foreground is drawn after it, it will reset the transformation.

Printable

Currently, the following printable objects are available to you and each printable object implements the IZPrintable interface.

/**
 * The root printable.  You will always create one of these.
 */
export class ZPrintableDrawing {}

/**
 * A printable that fills the canvas with a color.  Useful for the background.
 */
export class ZPrintableColor {}

/**
 * A grouping of printable objects that will print on top of each other.
 */
export class ZPrintableGroup {}

/**
 * A printable object that can load an image and print that image to the canvas.
 */
export class ZPrintableImage {}

/**
 * A printable that does nothing.
 *
 * Useful for unit testing.
 */
export class ZPrintableNothing {}

/**
 * A printable that applies a world transform to the canvas.
 */
export class ZPrintableTransform {}
import { ZPrintableDrawing, ZPrintableImage, ZPrintableGroup, ZPrintableTransform, ZPrintableColor } from '@zthun/works.draw';

async function draw(canvas: HTMLCanvasElement) {
  const url = 'https://images.to.draw/my-image.jpg';
  const drawing = new ZPrintableDrawing();
  const image = new ZPrintableImage();
  await image.import(url);

  drawing.background = new ZPrintableColor('white');
  drawing.foreground = new ZPrintableNothing();
  drawing.midground = new ZPrintableGroup([new ZPrintableTransform().scale(2.0, 2.0).translate(10, 10), image]);

  drawing.print(canvas.getContext('2d'));
}

Tools

Tools are a concept that help with implementing user actions against a canvas and all tools implement the IZTooling interface. The following tools are currently available:

/**
 * A tool that attaches to a click and drag event to move canvas layers.
 */
export class ZToolingPan {}
import { ZToolingPan, IZPrintable, IZTransformTranslate } from '@zthun/works.draw';

function start(canvas: HTMLCanvasElement, drawing: IZPrintable, transform: IZTransformTranslate) {
  const tool = new ZToolingPan();
  tool.init(canvas, canvas.getContext('2d'), drawing, transform);
}

function stop(tool: IZTooling) {
  tool.destroy();
}