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

fabric-history-v7

v1.0.0

Published

Undo/Redo history plugin for Fabric.js v7

Downloads

96

Readme

fabric-history-v7

npm version license

Undo / Redo history plugin for Fabric.js v7.

Installation

npm install fabric-history-v7

Usage

Method 1 – Mixin (recommended for bundlers)

import { Canvas } from 'fabric';
import { HistoryMixin } from 'fabric-history-v7';

class MyCanvas extends HistoryMixin(Canvas) {
  constructor(el, options) {
    super(el, options);
    this._historyInit();
  }
  dispose() {
    this._historyDispose();
    return super.dispose();
  }
}

const canvas = new MyCanvas('canvas-id', options);
canvas.undo();
canvas.redo();

Method 2 – Factory function (browser global)

<script src="fabric.min.js"></script>
<script type="module">
  import { createCanvasWithHistory } from 'fabric-history-v7';

  const CanvasWithHistory = createCanvasWithHistory(fabric.Canvas);
  const canvas = new CanvasWithHistory('canvas-id');
</script>

Keyboard shortcuts example

document.addEventListener('keydown', async ({ key, ctrlKey, shiftKey }) => {
  if (!ctrlKey) return;
  if (key === 'z') await canvas.undo();
  if (key === 'y' || (shiftKey && key === 'Z')) await canvas.redo();
});

API

Initialization

| Method | Description | |---|---| | _historyInit(extraProps?) | Initialize history. Call once in constructor after super(). | | _historyDispose() | Remove all event listeners. Call before dispose(). |

Undo / Redo

| Method | Returns | Description | |---|---|---| | undo(callback?) | Promise<void> | Undo the last action. | | redo(callback?) | Promise<void> | Redo the last undone action. | | canUndo() | boolean | Whether there are steps to undo. | | canRedo() | boolean | Whether there are steps to redo. | | undoCount | number | Number of available undo steps. | | redoCount | number | Number of available redo steps. |

History control

| Method | Description | |---|---| | clearHistory() | Reset undo/redo stacks to the current canvas state. | | offHistory() | Pause history recording. | | onHistory() | Resume recording and snapshot the current state. |

Events

| Event | Payload | Fired when | |---|---|---| | history:append | { json } | A new state is saved. | | history:undo | — | After an undo is applied. | | history:redo | — | After a redo is applied. | | history:clear | — | History is cleared. |

canvas.on('history:append', () => console.log('saved', canvas.undoCount));
canvas.on('history:undo',   () => updateButtons());
canvas.on('history:redo',   () => updateButtons());

Options

Pass an array of extra property names to _historyInit() to include them in each serialized snapshot:

this._historyInit(['selectable', 'editable', 'myCustomProp']);

Excluding objects from history

Set excludeFromExport = true on any fabric object to prevent changes to it from triggering a history snapshot:

const guide = new fabric.Line([0, 0, 600, 0]);
guide.excludeFromExport = true;
canvas.add(guide); // does NOT create a history entry

License

MIT © crayonlu