star-drawing
SVG drawing canvas web component for StarHTML and Datastar.
One app.register() call gives you a <drawing-canvas> custom element with drawing, shape, text, and annotation tools — plus a reactive toolbar wired to the canvas state. Built on starelements, so each canvas instance gets its own scoped signal namespace.
Why?
Adding a drawing surface to a web app typically means choosing a JS canvas library, wiring up toolbars, managing undo state, and handling pointer events yourself. star-drawing wraps all of that into a single starelements component — import it, register it, and you have a working canvas with 10 tools, undo/redo, keyboard shortcuts, and collaboration hooks.
Features
- Full drawing toolkit — pen, highlighter, line, arrow, rectangle, ellipse, diamond, text, and eraser tools out of the box.
- WYSIWYG text editing — click to place text, edit inline with font family, size, and alignment options.
- Toolbar presets —
drawing_toolbar()for the full suite,annotation_toolbar()for markup,diagram_toolbar()for shapes and connectors. - Undo/redo and keyboard shortcuts — Ctrl+Z, Ctrl+Y, Delete, Ctrl+A, Ctrl+D, and arrow-key nudging all wired up.
- SVG export/import —
export_svg()andimport_svg()for serialization and persistence. - Scoped signals — built on starelements, so each canvas instance has its own signal namespace. No cross-instance interference.
- Collaboration-ready —
onElementChangecallback andapplyRemoteChangesmethod for syncing state across clients. - Configurable palettes — stroke colors, fill colors, highlighter colors, width presets, font options, and arrowhead styles are all customizable.
- Readonly mode — set the
readonlyattribute for view-only canvases. - Skeleton loading — shimmer placeholder shown until the component initializes, preventing layout shift.
Installation
Requires Python 3.12+ and StarHTML.
pip install star-drawing
Quick Start
from starhtml import *
from star_drawing import DrawingCanvas, drawing_toolbar
app, rt = star_app()
app.register(DrawingCanvas)
@rt("/")
def index():
canvas = DrawingCanvas(cls="drawing-container")
return Div(
drawing_toolbar(canvas),
canvas,
)
serve()
This gives you a full-featured drawing canvas with all tools, color palettes, style options, and undo/redo.
Toolbar Presets
For focused use cases, use a preset instead of the full toolbar:
# Annotation — pen, highlighter, eraser only
annotation_toolbar(canvas)
# Diagramming — select, shapes, lines, arrows, text
diagram_toolbar(canvas)
Both presets accept the same keyword arguments as drawing_toolbar() for further customization.
Configuration
Attributes on <drawing-canvas> control defaults:
| Attribute | Default | Description |
|---|---|---|
default-tool |
"pen" |
Initial active tool |
default-stroke-color |
"#1a1a2e" |
Initial stroke color |
default-fill-color |
"#ffffff" |
Initial fill color |
default-stroke-width |
2 |
Initial stroke width in px |
default-opacity |
1 |
Initial element opacity |
default-layer |
"default" |
Initial active layer |
throttle-ms |
16 |
Input throttle interval |
readonly |
— | Disables all drawing interaction |
Set these as element attributes in Python:
DrawingCanvas(
default_tool="select",
default_stroke_color="#3568d4",
default_stroke_width=4,
readonly=True,
)
Toolbar Customization
drawing_toolbar() accepts keyword arguments to override defaults:
drawing_toolbar(
canvas,
tools=("pen", "line", "rect", "text"), # subset of tools to show
show_colors=True, # color palette panel
show_styles=True, # style options panel
show_undo=True, # undo/redo/clear buttons
color_palette=[("#000", "Black"), ("#fff", "White")],
width_presets=(1, 2, 4, 8),
)
Development
TypeScript sources live in typescript/ and are bundled with bun:
bun run build # build drawing-canvas.js
bun run dev # watch mode
uv run ruff check src/ tests/ # lint Python
uv run ruff format --check src/ # check formatting
npx tsc --noEmit # type-check TypeScript
The hatch build hook runs bun run build automatically during pip install / uv build, so the generated JS is never checked into git.
License
Metadata
Release files for star-drawing 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| star_drawing-0.1.3.tar.gz | 78.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| star_drawing-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 115.7 kB
Release files / star_drawing-0.1.3.tar.gz
| Download URL | star_drawing-0.1.3.tar.gz |
|---|---|
| Size | 78.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a8f0fd39a257c342056833fd5bac2cd46246103beb5ead650f51cd812bf70f48
|
|
BLAKE2b-256 checksum How to use checksums |
85be7bcf00e8cdf127ea1d688163979452aece5cbe9fb3b7d7509a0b16c2c7ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 21, 2026.
Transparency logRelease files / star_drawing-0.1.3-py3-none-any.whl
| Download URL | star_drawing-0.1.3-py3-none-any.whl |
|---|---|
| Size | 37.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cefeecce5a46aa5060a4af2b157e65763ccfdf1440d1f98cbddfc86cc3caad6a
|
|
BLAKE2b-256 checksum How to use checksums |
07052ca1a5dfc5ee90ca9e1e8f92a960b89d9e79cb5c08f9f6fbe66e1bcf900d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 21, 2026.
Transparency log