HistoryStack
Bounded undo/redo stack for PixelArtCanvas. Most consumers use PixelArtCanvas.undo()/redo() rather than this class directly. See PixelArtCanvas.md.
new HistoryStack(buffer: DefaultPixelBuffer, uvMap: UVMap, options?: HistoryStackOptions)interface HistoryStackOptions {
/** @default 10 */
limit?: number;
}limit caps the undo stack; pushing past it drops the oldest entry.
Entry actions
| Action | What it records |
|---|---|
"stroke" | beforeColors per-position, afterColor single color |
"resized" / "texture-replaced" | Whole-buffer beforePixels / afterPixels snapshot |
"select-edit" | beforeColors/afterColors per-position + oldRect/newRect/oldMask/newMask for selection state |
"uv-create" / "uv-delete" | Full region (undo calls the inverse UVMap method) |
"uv-move" | oldRect / newRect |
NOTE
"select-edit" and "uv-*" undo/redo are broadcast over the network. See uv/UVMap.md.
API
canUndo / canRedo
get canUndo(): boolean
get canRedo(): booleanpush(entry)
push(entry: HistoryEntryInput): voidStamps Date.now() and pushes onto the undo stack, clearing redo. Drops the oldest entry when limit is exceeded.
undo()
undo(): HistoryEntry | nullReverts the most recent entry and moves it to the redo stack. Returns null if nothing to undo.
redo()
redo(): HistoryEntry | nullRe-applies the most recently undone entry and moves it back to the undo stack. Returns null if nothing to redo.
clear()
clear(): voidDiscards both stacks. Call when the buffer is replaced from outside (e.g. remote resize or snapshot); PixelArtCanvas does this automatically.