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

@anth0nycodes/fabric-history

v1.1.0

Published

A library built on top of fabric.js that allows for easy access to canvas history.

Downloads

1,197

Readme

fabric-history

A library built on top of fabric.js that provides undo/redo history management for canvas operations.

Features

  • Undo/Redo functionality for fabric.js canvases
  • Automatic history tracking for path creation, erasing events, object additions, removals, and modifications
  • Multi-selection batching: operations on multiple selected objects are recorded as a single history entry
  • Custom events for history state changes
  • Fully type-safe
  • Support for fabric.js v6 and v7

Installation

npm install @anth0nycodes/fabric-history

or with pnpm:

pnpm add @anth0nycodes/fabric-history

or with yarn:

yarn add @anth0nycodes/fabric-history

Usage

import { CanvasWithHistory } from "@anth0nycodes/fabric-history";
import { Rect } from "fabric";

// Create a canvas with history support (same constructor as fabric.Canvas)
const canvas = new CanvasWithHistory("my-canvas", {
  width: 800,
  height: 600,
});

// Add objects - history is tracked automatically
const rect = new Rect({
  left: 100,
  top: 100,
  width: 50,
  height: 50,
  fill: "red",
});
canvas.add(rect);

// Undo the last action
await canvas.undo();

// Redo the undone action
await canvas.redo();

Using with @erase2d/fabric

To enable history tracking for erasing operations, use the setEraserBrush method with an EraserBrush from @erase2d/fabric. This ensures that erasing actions trigger the erasing:end event required for history tracking.

import { CanvasWithHistory } from "@anth0nycodes/fabric-history";
import { EraserBrush } from "@erase2d/fabric";

const canvas = new CanvasWithHistory("my-canvas", {
  width: 800,
  height: 600,
});

// Create and set the eraser brush
const eraser = new EraserBrush(canvas);
eraser.width = 20;
canvas.setEraserBrush(eraser);

// Enable drawing mode to use the eraser
canvas.isDrawingMode = true;

API

CanvasWithHistory

Extends fabric.js Canvas class with history management capabilities.

Methods

| Method | Returns | Description | | ------------------------ | --------------- | ---------------------------------------------------------------------------------------------------- | | undo() | Promise<void> | Undo the most recent action | | redo() | Promise<void> | Redo the most recently undone action | | canUndo() | boolean | Check if an undo action is available | | canRedo() | boolean | Check if a redo action is available | | setEraserBrush(eraser) | void | Set an EraserBrush from @erase2d/fabric to enable history tracking for erasing operations | | clearHistory() | void | Clear the undo and redo history stacks | | clearCanvas() | void | Clear the canvas and save the cleared state to history (use this instead of the inherited clear()) | | dispose() | void | Clean up event listeners and dispose the canvas |

Tracked Events

History is automatically saved when these fabric.js events occur:

  • path:created - When a path is created (e.g., freehand drawing)
  • erasing:end - When an erasing operation completes
  • object:added - When an object is added to the canvas
  • object:removed - When an object is removed from the canvas
  • object:modified - When an object is modified (moved, scaled, rotated, etc.)

Custom Events

CanvasWithHistory fires custom events that you can listen to for history state changes:

| Event | Payload | Description | | ----------------- | ------------------------------------ | --------------------------------- | | history:append | { json: string, initial: boolean } | Fired when a state is saved | | history:undo | { lastUndoAction: string } | Fired when an undo is performed | | history:redo | { lastRedoAction: string } | Fired when a redo is performed | | history:cleared | {} | Fired when history stacks cleared |

Example:

canvas.on("history:append", ({ json, initial }) => {
  console.log("State saved:", initial ? "initial" : "action");
});

canvas.on("history:undo", ({ lastUndoAction }) => {
  console.log("Undo performed");
});

Requirements

  • fabric.js 6.x or 7.x

Development

# Install dependencies
pnpm install

# Run development server
pnpm dev

# Build the project
pnpm build

# Type check
pnpm check

# Run all tests
pnpm test

# Run integration tests only
pnpm test:it

# Run E2E tests only (uses Playwright)
pnpm test:e2e

# Run tests with coverage
pnpm coverage

Contributing

Contributions are welcome! Please read our CONTRIBUTING.md for details on how to submit pull requests.

License

MIT

Author

Anthony Hoang