Prismalpha.9
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;
  nativePaintTimeoutMs?: number;
}>;

nativePaintTimeoutMs defaults to 2000 ms and must be finite, greater than 0 and at most 2147483647. It counts visible time for pending paintOnce() callers. See paintOnce().

type CanvasDiagnostics = Readonly<{
  backend: CanvasBackendKind;
  capability: "supported" | "unavailable" | "unsupported-version";
  health?: "idle" | "pending" | "healthy" | "failed";
  lastError?: PrismNativeError;
}>;

runtime.diagnostics returns this snapshot. Capability describes API presence; native health describes the last paint outcome. Fallback diagnostics omit health and lastError.

PrismNativeError extends Error. Its code is "draw-failed" or "paint-timeout"; draw failures retain the original exception as cause. Import it from the package root.

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.