Prismv0.4
Reference

Types

Public TypeScript types exported from the package root.

All public Prism imports come from the package root:

import {
  CanvasRuntime,
  type CanvasRuntimeOptions,
  type CanvasSurface,
  type SurfaceOptions
} from "@synthesisengineering/prism";

Do not import runtime internals, backend classes, paint-pass helpers, or platform wrappers from subpaths.

Runtime

type CanvasBackendKind = "native" | "fallback";
type CanvasBackendPreference = "auto" | CanvasBackendKind;

type CanvasRuntimeOptions = Readonly<{
  backend?: CanvasBackendPreference;
}>;

Surface

type SurfaceBoundsInput =
  | RectLike
  | (() => RectLike);

type SurfaceOptions = Readonly<{
  bounds: SurfaceBoundsInput;
  ariaLabel?: string;
}>;

Surface bounds are CSS pixels.

Paint and Update

type UpdateHandler = (time: FrameTime) => void;

type PaintHandler = (api: {
  ctx: CanvasRenderingContext2D;
  time: FrameTime;
  drawSurface: (surface: CanvasSurface) => void;
  invalidate: () => void;
}) => void;

Direct drawing with ctx uses backing-store pixels. Registered surfaces use CSS-pixel bounds and should be drawn with drawSurface(surface).

Coordinates

type CanvasPoint = Readonly<{
  x: number;
  y: number;
}>;

clientToCanvasPoint() returns CSS-pixel coordinates. cssLengthToCanvasPixels() and cssPointToCanvasPixels() convert CSS-space values for direct canvas drawing.