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

drawfn

v0.0.1

Published

Cross-framework drawing canvas library for brainstorming and simple sketching

Readme

@21n/drawfn

Cross-framework drawing canvas library for brainstorming and simple sketching.

Features

  • 🎨 Framework-agnostic core (works with React, Svelte, Vue, vanilla JS)
  • ✏️ Multiple drawing tools: pen, shapes, text, images, and more
  • 📐 Element-based retained-mode architecture
  • 💾 Full scene serialization to JSON
  • ⏮️ Undo/redo support
  • 📤 Export to PNG and SVG
  • 🔍 Pan and zoom with viewport culling
  • 🎯 Selection and transformation tools

Installation

npm install @21n/drawfn perfect-freehand

Quick Start

import { Drawfn } from '@21n/drawfn';

const canvas = document.querySelector('canvas');
const drawfn = new Drawfn({ canvas });

// Set a tool
drawfn.setTool('pen');

// Listen to events
drawfn.on('elementAdded', (element) => {
  console.log('New element added:', element);
});

// Export the scene
const scene = drawfn.getScene();
console.log(scene);

Tools

  • select: Select, move, resize, and rotate elements with handles
  • pan: Pan the canvas with mouse/trackpad
  • pen: Freehand drawing with pressure support (perfect-freehand)
  • rectangle: Draw rectangles (hold Shift for squares)
  • ellipse: Draw ellipses (hold Shift for circles)
  • arrow: Draw arrows with arrowhead
  • text: Add text with inline editing overlay
  • image: Add images programmatically
  • node: Add Nucleus node bookmarks (for integrations)

API

Constructor

const drawfn = new Drawfn({
  canvas: HTMLCanvasElement,
  overlayRoot?: HTMLElement,  // For text editing overlay
  getImageBitmap?: (src: string) => Promise<ImageBitmap>  // Custom image loader
});

Methods

Scene Management

  • load(scene: Scene): Load a scene from JSON
  • getScene(): Scene: Get current scene as JSON
  • clear(): Clear the entire canvas

Element Operations

  • add(element: Element): string: Add an element, returns ID
  • update(id: string, patch: Partial<Element>): Update an element
  • remove(id: string): Remove an element
  • bringToFront(id: string): Move element to top layer
  • sendToBack(id: string): Move element to bottom layer
  • getElements(): Element[]: Get all elements
  • getElementById(id: string): Element | undefined: Get element by ID

Tool Management

  • setTool(tool: ToolName, opts?): Set active tool
    • For image tool: setTool('image', { src: 'url', naturalW: 200, naturalH: 150 })
    • For node tool: setTool('node', { nodeId: 'abc', preview: { title: 'Note' } })
  • getTool(): ToolName: Get current tool

Camera & View

  • setCamera(camera: Partial<Camera>): Update camera position/zoom
  • getCamera(): Camera: Get camera state
  • screenToCanvas(point: Point): Point: Convert screen to canvas coordinates

History

  • undo(): Undo last action
  • redo(): Redo last undone action

Selection

  • setSelection(ids: string[]): Set selected element IDs
  • getSelectedIds(): string[]: Get selected element IDs

Export

  • exportPNG(opts?): Promise<Blob>: Export as PNG
    • Options: { padding?: number; scale?: number; transparent?: boolean }
  • exportSVG(opts?): Promise<string>: Export as SVG (includes freedraw, arrows, images)
    • Options: { padding?: number; scale?: number }

Events

  • on(event, handler): () => void: Subscribe to events, returns unsubscribe function
    • Events: pointerDown, pointerMove, pointerUp, elementAdded, elementUpdated, elementRemoved, selectionChanged, historyChanged, cameraChanged

Cleanup

  • destroy(): Cleanup and remove event listeners

Examples

See example.html for a complete vanilla JS example with toolbar and all tools.

For React examples, see @21n/drawfn-react package.

Keyboard Shortcuts

  • Delete/Backspace: Delete selected elements
  • Cmd/Ctrl+Z: Undo
  • Cmd/Ctrl+Shift+Z or Cmd/Ctrl+Y: Redo
  • Space+Drag: Pan (when not in pan tool mode)
  • Shift+Drag: Constrain aspect ratio for shapes

Mouse/Touch Interactions

  • Wheel: Zoom at cursor position
  • Click+Drag: Tool-specific interaction
  • Shift+Click: Multi-select (in select tool)

License

Apache-2.0