@tsdraw/core
v0.9.7
Published
the core engine for tsdraw
Downloads
830
Readme
Feature highlights
@tsdraw/core is the framework-agnostic foundation of tsdraw with a state-based tool architecture.
- state-based tools: Tools are built as state machines for predictable interaction handling
- framework-agnostic: Use with any UI framework or vanilla JavaScript
- built-in tools: Pen, shapes (square, circle), eraser, select, and hand/pan tools
- shape recognition: Auto-recognize hand-drawn shapes
- viewport & camera: Pan and zoom with built-in camera controls
- tremendously small: Made to be small and load instantly when needed
Usage
npm install @tsdraw/coreimport { Editor, createDocumentStore } from '@tsdraw/core';
// Create a document store
const store = createDocumentStore();
// Initialize the editor
const editor = new Editor({
store,
container: document.getElementById('canvas'),
});
// Set the active tool
editor.toolManager.setTool('pen');Tools
| Tool | Description |
|------|-------------|
| pen | Freehand drawing with pressure support via perfect-freehand |
| square | Rectangle/square shapes |
| circle | Circle and ellipse shapes |
| eraser | Erase elements with configurable size |
| select | Select and manipulate elements |
| hand | Pan and navigate the canvas |
API Overview
Core Classes
Editor- Main editor instance that orchestrates all systemsDocumentStore- Central state management for the drawing documentToolManager- Manages tool registration and activationInputManager- Handles pointer/touch input eventsRenderer- Renders the canvas and elements
Utilities
pathCodec- Encode/decode path datageometry- Geometric calculations and helperscolors- Color utilities and constantsshapeRecognition- Hand-drawn shape recognitionsnapshots- Save and restore document state
