ToolManager
ToolManager handles tool registration, activation, and event routing.
ToolDefinition
ToolId
StateNode
TheStateNode base class defines the interface that every tool state must implement.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
API reference for the tool system
import { ToolManager } from '@tsdraw/core'
ToolManager handles tool registration, activation, and event routing.
| Method | Description |
|---|---|
registerTool(definition) | Register a tool definition |
setCurrentTool(id) | Activate a tool by ID |
getCurrentToolId() | Get the active tool ID |
interface ToolDefinition {
id: ToolId
initialStateId: string
stateConstructors: StateNodeConstructor[]
}
| Property | Description |
|---|---|
id | Unique tool identifier |
initialStateId | The state to enter when the tool activates |
stateConstructors | Factory functions that create StateNode instances |
type ToolId = string
type DefaultToolId = 'pen' | 'eraser' | 'select' | 'hand' | 'square' | 'circle'
StateNode base class defines the interface that every tool state must implement.
| Method | Receives | Description |
|---|---|---|
onEnter(info) | ToolStateTransitionInfo | Called when entering this state |
onExit(info) | ToolStateTransitionInfo | Called when leaving this state |
onPointerDown(info) | ToolPointerDownInfo | Pointer pressed |
onPointerMove(info) | ToolPointerMoveInfo | Pointer moved |
onPointerUp(info) | ToolPointerMoveInfo | Pointer released |
onKeyDown(info) | ToolKeyInfo | Key pressed |
onKeyUp(info) | ToolKeyInfo | Key released |
interface ToolStateContext {
editor: Editor
transition: (stateId: string) => void
}
interface ToolPointerDownInfo {
context: ToolStateContext
pagePoint: Vec3
screenPoint: Vec3
}
interface ToolPointerMoveInfo {
context: ToolStateContext
pagePoint: Vec3
screenPoint: Vec3
}
interface ToolKeyInfo {
context: ToolStateContext
key: string
shiftKey: boolean
ctrlKey: boolean
altKey: boolean
metaKey: boolean
}