CanvasRuntime
The public runtime class that owns Prism's canvas lifecycle.
CanvasRuntime is the only constructible public runtime class.
import { CanvasRuntime } from "@synthesisengineering/prism";
const runtime = new CanvasRuntime(canvas, { backend: "auto" });The runtime owns the canvas association, backend selection, surface registry, paint lifecycle, invalidation, update handlers, paint handlers, coordinate helpers, and cleanup.
It does not own app state, chart data, template data, React state, game state, or example-specific transforms.
Core methods
registerSurface(element, options)onPaint(handler)onUpdate(handler)paintOnce()start()stop()destroy()- coordinate conversion helpers
Callback semantics
onPaint() and onUpdate() are additive. Calling either method registers another handler; it does not replace existing handlers.
runtime.onPaint(firstHandler);
runtime.onPaint(secondHandler);
// both handlers run during a paint passPrism does not expose a general event system or unsubscribe API today. Register stable handlers and keep app state outside Prism.
Destroyed runtime behavior
destroy() stops the runtime, unregisters registered surfaces, clears handlers, and rejects pending paint waiters. After destroy(), new runtime work such as start(), onPaint(), onUpdate(), registerSurface(), and paintOnce() throws or rejects.
stop() and destroy() are idempotent. Calling either after the runtime has already been destroyed is safe.
Use the package root import. Backend classes, platform wrappers, paint-pass helpers, and runtime internals are not public API.
Prism