Draw (candraw)
Primary APIs
| API | Behavior |
|---|---|
createCanvasController(options) | Creates a canvas editor with the candraw editable element set. |
controller.dispatch(command) | Runs a typed candraw command and records it in shared history. |
createRectanglePath(id, bounds, style) | Builds path geometry for rectangular shape rendering. |
renderVectorProject(ctx, snapshot, options) | Paints a vector project snapshot to a canvas context. |
createVectorProjectSvg(snapshot, options) | Serializes a vector project snapshot to SVG markup. |
<CandrawEditor /> | The full drawing editor from @pixxl-tools/candraw/editor: document / defaultDocument, onChange, onSave, onOpen (File → Open read a file: format, warnings, removedImages, fileName; return false to cancel or a CanvasDocument to load instead), slots, locale, messages and headingLevel (inspector section headings, default 2 under the page’s h1); autosave={{ key, delayMs, load, save, onSaveResult }} keeps the drawing in localStorage (restored on mount; written after each change, after File → Open and when the page is hidden; a value that no longer opens is moved to <key>:unreadable; File → Clear drawing keeps the previous drawing in <key>:before-clear until the next change, so Undo brings it back after a reload). load and save replace the localStorage read and write (convert older formats, use your own keys); onSaveResult(saved) reports every write so you can show "Not saved in this browser", and warnOnUnsavedChanges (default: on without onChange) makes the browser ask before a reload drops unsaved work. With a shape tool, Enter on the canvas inserts a default-size shape in the middle of the view. Needs @pixxl-tools/candraw/editor.css. |
createHistory / pushHistory / undoHistory | Pure undo history with a depth limit, coalescing keys and reset on load; useCandrawHistory wraps it in React state. |
snapBounds(moving, targets, { threshold }) | Smart-guide snapping to other items and pages; returns the offset and the guide lines to draw. |