Skip to main content
These commands do what the toolbar’s buttons do. Each follows the rules of every command. The examples call the handle editor. See Get the handle.

History

undo()

Takes the last step back, as Undo on the toolbar: a command’s step or the user’s. The image and the view go back to how they were before it. With nothing to undo, it changes nothing.

redo()

Brings back the step undone last, as Redo on the toolbar. With nothing to redo, it changes nothing.

reset()

Takes every edit away, as Reset on the toolbar, without its confirm. Like that button, it takes away a state the editor opened with too, and keeps the crop ratio aspectRatio sets or aspectRatioLocked holds. It is one step, so undo brings the edits back. With nothing to reset, it changes nothing.
undo.ts

Output

save()

Saves, as the Save button: the file and the state go to onProcess (or the file downloads, with no onProcess), the button shows its Saved moment, the save event fires, and openEditor’s modal closes. It resolves to { dest, state }, what onProcess gets. It rejects with the error onProcessError gets (EXPORT_FAILED, MARK_FAILED), or with EXPORT_FAILED when onProcess throws, your error as its cause. While a fixed or required mark is still loading, it waits for it, as the button does.
save.ts

exportFile()

Makes the image as Save makes it (the output size and quality, the marks) and resolves to the File, without saving: nothing goes to onProcess, nothing downloads, and no event fires.
'image/jpeg' | 'image/png' | 'image/webp'
default:"Save's type"
The type written. Left out, Save’s: outputType, or the source’s.
It waits while a fixed or required mark is loading, rejects with MARK_FAILED when one can’t be drawn, and with EXPORT_FAILED when the file can’t be made. Use it for what Save doesn’t do, such as copying or sharing the file yourself.
export-file.ts

Editor

close()

Closes the editor, as its Close button. On EmbedEditor and mountEditor, it calls onClose, and rejects with NOT_AVAILABLE when there is none. On openEditor, it closes the modal, and the handle takes no more commands.
close.ts