Class representing the history of a Fabric.js canvas, allowing undo and redo operations.

Constructors

  • Creates an instance of FabricCanvasHistory.

    Parameters

    • canvas: Canvas

      The Fabric.js canvas instance to track.

    • OptionalchangeCallback: (() => void)

      Optional callback function to be called on history change.

        • (): void
        • Returns void

    Returns FabricCanvasHistory

Methods

  • Checks if a redo operation can be performed.

    Returns boolean

    True if redo can be performed, otherwise false.

  • Checks if an undo operation can be performed.

    Returns boolean

    True if undo can be performed, otherwise false.

  • Clears the undo and redo stacks.

    Returns void

  • Initializes the history tracking by enabling events and saving the initial state.

    Returns void

  • Redoes the last undone operation, restoring the canvas to the state before the last undo. If there is no state to redo, the method does nothing.

    Returns Promise<void>

  • Sets the callback function to be called on history change.

    Parameters

    • callback: (() => void)

      The callback function.

        • (): void
        • Returns void

    Returns void

  • Undoes the last operation, reverting the canvas to the previous state. If there is no previous state, the method does nothing.

    Returns Promise<void>