Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.tsdraw.com/llms.txt

Use this file to discover all available pages before exploring further.

The Editor class is the main entry point into the tsdraw engine.
import { Editor } from '@tsdraw/core'

Constructor

new Editor(options?: EditorOptions)

EditorOptions

PropertyTypeDefaultDescription
dragDistanceSquarednumber36Distance threshold for differentiating a click from a drag
toolDefinitionsToolDefinition[][]Additional tool definitions to register
initialToolIdToolId'pen'The tool that’s active on startup
zoomRangeZoomRange{ min: 0.1, max: 8 }Min/max zoom levels

Properties

PropertyTypeDescription
storeDocumentStoreShape storage and ordering
inputInputManagerPointer event normalization
toolsToolManagerTool state machine routing
rendererCanvasRendererCanvas 2D rendering
viewportViewportCurrent camera position and zoom

Shape methods

MethodReturnsDescription
getShapes()Shape[]All shapes on the current page
getShapesSorted()Shape[]Shapes sorted by z-order
deleteShape(id)voidRemove a shape by ID
clearAllShapes()voidRemove every shape

Style methods

MethodReturnsDescription
getDrawStyle()DrawStyleStateCurrent color, dash, fill, size
setDrawStyle(partial)voidMerge partial style into the current draw style

Viewport methods

MethodReturnsDescription
setViewport(viewport)voidSet camera position and zoom
zoomIn()voidZoom in one step
zoomOut()voidZoom out one step

Tool methods

MethodReturnsDescription
setCurrentTool(id)voidSwitch the active tool
getCurrentToolId()ToolIdGet the active tool ID

History methods

MethodReturnsDescription
undo()voidUndo the last action
redo()voidRedo the last undone action
canUndo()booleanWhether undo is available
canRedo()booleanWhether redo is available

Snapshot methods

MethodReturnsDescription
getSnapshot()TsdrawEditorSnapshotFull editor state snapshot
loadSnapshot(snapshot)voidRestore from a snapshot
getDocumentSnapshot()TsdrawDocumentSnapshotDocument-only snapshot