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.

ToolManager

import { ToolManager } from '@tsdraw/core'
The ToolManager handles tool registration, activation, and event routing.
MethodDescription
registerTool(definition)Register a tool definition
setCurrentTool(id)Activate a tool by ID
getCurrentToolId()Get the active tool ID

ToolDefinition

interface ToolDefinition {
  id: ToolId
  initialStateId: string
  stateConstructors: StateNodeConstructor[]
}
PropertyDescription
idUnique tool identifier
initialStateIdThe state to enter when the tool activates
stateConstructorsFactory functions that create StateNode instances

ToolId

type ToolId = string
type DefaultToolId = 'pen' | 'eraser' | 'select' | 'hand' | 'square' | 'circle'

StateNode

The StateNode base class defines the interface that every tool state must implement.
MethodReceivesDescription
onEnter(info)ToolStateTransitionInfoCalled when entering this state
onExit(info)ToolStateTransitionInfoCalled when leaving this state
onPointerDown(info)ToolPointerDownInfoPointer pressed
onPointerMove(info)ToolPointerMoveInfoPointer moved
onPointerUp(info)ToolPointerMoveInfoPointer released
onKeyDown(info)ToolKeyInfoKey pressed
onKeyUp(info)ToolKeyInfoKey released

ToolStateContext

interface ToolStateContext {
  editor: Editor
  transition: (stateId: string) => void
}
Passed to state nodes so they can access the editor and transition between states.

Event info types

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
}