Skip to main content

PaintCanvas

Open-source painting engine and renderer for the browser, with optional UI. Draw with a mouse, touch, or a pen or stylus with pressure and tilt.

  • Engine (@lvl99dotcom/paintcanvas/lib/*): layers, brushes and erasers, custom brush presets, selection, transforms, clipboard, undo/redo, viewport, pen/touch/mouse input and rendering. No UI, and nothing is stored unless you ask (e.g. keeping the drawing in the browser).
  • Messages: the engine sends and receives small drawing messages (patches of pixels, strokes, undo and redo), so you can share a drawing over any transport you choose.
  • UI (@lvl99dotcom/paintcanvas/ui), optional: Lit web components, from buttons and sliders up to a full <paint-canvas> layout with slots for your own parts.

Tools​

KindTools
Painting and drawingBrush, eraser
MaskingRectangle, circle, polygon and freehand masks
ManipulationMove, scale, rotate
Constructive, destructiveCut, copy, paste, delete, fill, undo, redo
ColoursBrush and background colours, colour palette
Colour samplingSample a point, sample an area
ViewportZoom, pan
LayersVisibility, order, blending mode, opacity, alpha lock, merge
SettingsConfigurable keyboard shortcuts, settings import and export

Installation​

npm install @lvl99dotcom/paintcanvas lit

Lit is a peer dependency, used by the UI only. The package is ES modules with TypeScript types.

Quick start​

A full-page drawing app:

<!doctype html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
html,
body,
paint-canvas {
height: 100%;
margin: 0;
}
</style>
</head>
<body>
<paint-canvas></paint-canvas>
<script type="module">
import "@lvl99dotcom/paintcanvas/ui";
import { translations } from "@lvl99dotcom/paintcanvas/lib/i18n";

await translations.useDeviceLocale();
</script>
</body>
</html>

Each folder of the engine and UI has its own import path, matching the API pages: e.g. @lvl99dotcom/paintcanvas/lib/classes/PaintCanvas or @lvl99dotcom/paintcanvas/ui/elements/PcButton.

Guides​