Comprehensive Canvas Module
Streamline your workflow with this create, beautiful, visual, documents. Includes structured workflows, validation checks, and reusable patterns for creative design.
Comprehensive Canvas Module
A Claude Code skill for building canvas-based drawing, editing, and visualization applications using HTML5 Canvas and related libraries. Covers canvas rendering, interaction handling, layer management, export functionality, and performance optimization for drawing and editing tools.
When to Use This Skill
Choose Comprehensive Canvas Module when:
- You're building a drawing or diagramming application
- You need to implement canvas-based image editing or annotation
- You want to create interactive visualizations with custom rendering
- You need to handle complex canvas interactions (drag, resize, rotate)
- You're building a whiteboard, design tool, or annotation overlay
Consider alternatives when:
- You need 3D rendering (use a 3D workspace skill)
- You want pre-built charting (use a data visualization library)
- You need document editing (use a rich text editor skill)
Quick Start
# Install the skill claude install comprehensive-canvas-module # Set up a drawing canvas claude "Create a React canvas drawing component with brush tool, eraser, color picker, and undo/redo" # Build an annotation tool claude "Build a canvas overlay that lets users draw rectangles, arrows, and text annotations on images" # Implement layer management claude "Add a layer system to my canvas app: multiple layers, opacity control, reordering, and visibility toggle"
Core Concepts
Canvas Architecture
Application Layer
āāā Tool Manager (active tool, tool switching)
āāā Layer Manager (add, remove, reorder, visibility)
āāā History Manager (undo/redo stack)
āāā Selection Manager (select, multi-select, transform)
āāā Export Manager (PNG, SVG, JSON)
Rendering Layer
āāā Main Canvas (visible output)
āāā Offscreen Canvas (composition)
āāā Hit-Test Canvas (interaction detection)
āāā Overlay Canvas (selection handles, guides)
Input Layer
āāā Mouse Events (click, drag, scroll)
āāā Touch Events (tap, pinch, gesture)
āāā Keyboard Events (shortcuts, modifiers)
āāā Clipboard Events (copy, paste)
Drawing Tool Patterns
| Tool | Implementation | Key Events |
|---|---|---|
| Brush | Path with quadratic curves | mousedown ā mousemove ā mouseup |
| Eraser | Composite operation: destination-out | Same as brush |
| Shape | Preview during drag, commit on release | mousedown (start) ā mousemove (preview) ā mouseup (commit) |
| Text | Create input overlay at click position | click ā show input ā blur ā render to canvas |
| Selection | Bounding box with transform handles | click to select ā drag corners to transform |
Rendering Optimization
| Technique | When to Use | Performance Gain |
|---|---|---|
| Dirty Rectangle | Only redraw changed areas | 2-5x for small changes |
| Layer Caching | Cache static layers as images | 3-10x for multi-layer scenes |
| requestAnimationFrame | Smooth animation loop | Eliminates jank |
| OffscreenCanvas | Heavy computation off main thread | Prevents UI blocking |
| Resolution Scaling | Reduce canvas resolution on slow devices | 2-4x on mobile |
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
library | string | "fabric" | Library: fabric.js, konva, paper.js, vanilla |
framework | string | "react" | Frontend framework |
features | string[] | ["draw", "select"] | Features: draw, select, layers, export, text |
max_canvas_size | number | 4096 | Maximum canvas dimension in pixels |
touch_support | boolean | true | Enable touch/gesture support |
Best Practices
-
Use a library for complex interactions ā Fabric.js and Konva handle selection, transformation, grouping, and serialization out of the box. Writing these from scratch with raw Canvas API takes months and introduces subtle bugs.
-
Implement undo/redo from the start ā Use a command pattern where each action is a reversible command object. This is extremely hard to add later but trivial to build in from day one. Store state snapshots for complex operations.
-
Separate rendering from state ā Keep your canvas objects in a data model and render from that model. This makes undo/redo, serialization, collaboration, and testing much simpler than trying to reconstruct state from canvas pixels.
-
Handle HiDPI displays ā Set canvas dimensions to
width * devicePixelRatioand scale the context. Without this, your canvas will look blurry on Retina and high-DPI screens. -
Debounce heavy operations ā Operations like full canvas export, history snapshots, and auto-save should be debounced. Triggering a full-canvas toDataURL() on every mousemove will freeze the application.
Common Issues
Canvas looks blurry on Retina displays ā Set canvas width/height attributes to the display size multiplied by window.devicePixelRatio, then scale the CSS size back down. This gives you high-resolution rendering.
Slow performance with many objects ā Switch from immediate-mode rendering (redraw everything each frame) to retained-mode with dirty tracking. Cache static layers as pre-rendered images and only redraw the active layer.
Touch events conflict with scrolling ā Use touch-action: none CSS on the canvas element and call preventDefault() on touch events. But allow scrolling gestures (two-finger) to pass through for mobile usability.
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Full-Stack Code Reviewer
Comprehensive code review skill that checks for security vulnerabilities, performance issues, accessibility, and best practices across frontend and backend code.
Test Suite Generator
Generates comprehensive test suites with unit tests, integration tests, and edge cases. Supports Jest, Vitest, Pytest, and Go testing.
Pro Architecture Workspace
Battle-tested skill for architectural, decision, making, framework. Includes structured workflows, validation checks, and reusable patterns for development.