Field Notes
    Preparing search index...

    Interface Viewport

    interface Viewport {
        camera: Camera;
        constraintProxy: ConstraintServiceProxy;
        domLayer: HTMLDivElement;
        elementRegistry: ElementRegistry;
        history: HistoryStack;
        historyRecorder: HistoryRecorder;
        layerManager: LayerManager;
        store: ElementStore;
        toolContext: ToolContext;
        toolManager: ToolManager;
        get actions(): ActionsApi;
        get ctx(): CanvasRenderingContext2D | null;
        get palette(): PaletteApi;
        get plugins(): PluginStateManager;
        get presentation(): PresentationApi;
        get renderHooks(): RenderHooks;
        get shortcuts(): ShortcutsApi;
        get shortcutsHelp(): ShortcutsHelpApi;
        get smartGuides(): boolean;
        get snapToGrid(): boolean;
        addHtmlElement(
            dom: HTMLElement,
            position: { x: number; y: number },
            size?: { h: number; w: number },
            opts?: {
                data?: Record<string, unknown>;
                htmlType?: string;
                interactive?: boolean;
                origin?: string;
                transient?: boolean;
            },
        ): string;
        addImage(
            src: string,
            position: { x: number; y: number },
            size?: { h: number; w: number },
        ): string;
        addShape(
            opts?: {
                fillColor?: string;
                position?: { x: number; y: number };
                shape?: ShapeKind;
                size?: { h: number; w: number };
                strokeColor?: string;
                strokeWidth?: number;
            },
        ): string;
        addToFrame(frameId: string, ids: readonly string[]): void;
        alignSelection(edge: AlignEdge): void;
        applyStyleToSelection(style: ElementStyle): void;
        canPaste(): boolean;
        centerCameraAt(world: Point): void;
        destroy(): void;
        dissolveFrame(frameId: string): void;
        distributeSelection(axis: DistributeAxis): void;
        editBoundText(containerId: string): boolean;
        expectCanvasHtmlTypes(htmlTypes: Iterable<string>): () => void;
        exportImage(options?: ExportImageOptions): Promise<Blob | null>;
        exportJSON(): string;
        exportPDF(options?: ExportPdfOptions): Promise<Blob | null>;
        exportState(): CanvasState;
        exportSVG(options?: ExportSvgOptions): Promise<string>;
        fitToContent(padding?: number): void;
        frameSelection(
            ids: readonly string[],
            options?: { color?: string; padding?: number; title?: string },
        ): string;
        getBoundText(containerId: string): TextElement | undefined;
        getCanvasSize(): { h: number; w: number };
        getElementAt(world: Point, options?: HitTestOptions): CanvasElement | null;
        getHtmlPainters(): HtmlPainterRegistry;
        getRenderStats(): RenderStatsSnapshot;
        getSelectedIds(): string[];
        getSelectionStyle(): ElementStyle | null;
        getSelectionStyleDetails(): SelectionStyleDetails | null;
        getService<T>(key: ServiceKey<T>): T | undefined;
        getTheme(): ResolvedTheme;
        getVisibleRect(): Bounds;
        groupSelection(): void;
        isEmbeddedEngaged(): boolean;
        loadJSON(json: string): void;
        loadState(state: ImportableCanvasState): void;
        logPerformance(intervalMs?: number): () => void;
        onElementActivate(
            listener: (e: ElementActivationEvent) => void,
        ): () => void;
        onEmbeddedEngagedChange(listener: (engaged: boolean) => void): () => void;
        onHtmlPaintDiagnostic(
            listener: (d: HtmlPaintDiagnostic) => void,
        ): () => void;
        onResize(listener: () => void): () => void;
        onSelectionChange(listener: () => void): () => void;
        onStateChange(listener: () => void): () => void;
        onThemeChange(listener: (theme: ResolvedTheme) => void): () => void;
        onWheelPassThrough(listener: (e: WheelEvent) => void): () => void;
        openContextMenu(screenPos: Point): void;
        redo(): boolean;
        registerHtmlPainter(htmlType: string, painter: HtmlPainter): () => void;
        registerHtmlRenderer(
            htmlType: string,
            factory: (el: HtmlElement) => HTMLElement,
        ): void;
        registerOverlay(draw: OverlayRenderer): () => void;
        removeElements(ids: Iterable<string>): number;
        removeFromFrame(frameId: string, ids: readonly string[]): void;
        removeLayer(id: string): void;
        requestOverlayRender(): void;
        requestRender(): void;
        resetArrowRoute(id: string): boolean;
        rotateSelection(direction: RotateDirection): void;
        runAction(action: string): boolean;
        setActivation(options: ActivationOptions | null): () => void;
        setBoundText(containerId: string, html: string): string | undefined;
        setEmbeddedEngaged(engaged: boolean): void;
        setLink(ids: readonly string[], link: string | null): void;
        setParent(childId: string, parentId: string | null): void;
        setSmartGuides(enabled: boolean): void;
        setSnapToGrid(enabled: boolean): void;
        setTheme(theme: Theme): void;
        setTool(name: string): void;
        stopInteracting(): void;
        suspendNotifications(): NotificationController;
        toggleLockSelection(): void;
        transaction<T>(operation: () => T): T;
        undo(): boolean;
        ungroupSelection(): void;
        updateHtmlElement(id: string, newContent: HTMLElement): void;
    }
    Index
    camera: Camera
    constraintProxy: ConstraintServiceProxy
    domLayer: HTMLDivElement
    elementRegistry: ElementRegistry
    history: HistoryStack
    historyRecorder: HistoryRecorder
    layerManager: LayerManager
    store: ElementStore
    toolContext: ToolContext
    toolManager: ToolManager
    • get actions(): ActionsApi

      Returns ActionsApi

    • get ctx(): CanvasRenderingContext2D | null

      Returns CanvasRenderingContext2D | null

    • get palette(): PaletteApi

      Command palette controls for this viewport.

      Returns PaletteApi

    • get plugins(): PluginStateManager

      Returns PluginStateManager

    • get presentation(): PresentationApi

      Presentation controls for this viewport.

      Returns PresentationApi

    • get renderHooks(): RenderHooks

      Returns RenderHooks

    • get shortcuts(): ShortcutsApi

      Returns ShortcutsApi

    • get shortcutsHelp(): ShortcutsHelpApi

      Shortcuts help controls for this viewport.

      Returns ShortcutsHelpApi

    • get smartGuides(): boolean

      Returns boolean

    • get snapToGrid(): boolean

      Returns boolean

    • Parameters

      • dom: HTMLElement
      • position: { x: number; y: number }
      • Optionalsize: { h: number; w: number }
      • Optionalopts: {
            data?: Record<string, unknown>;
            htmlType?: string;
            interactive?: boolean;
            origin?: string;
            transient?: boolean;
        }
        • Optionaldata?: Record<string, unknown>
        • OptionalhtmlType?: string
        • Optionalinteractive?: boolean

          Controls take clicks; padding selects and moves. Persisted and synced.

        • Optionalorigin?: string

          Non-'local' origin marks the add as external: no undo step, tagged for observers.

        • Optionaltransient?: boolean

          Host-owned element: excluded from exported state and never sent to the sync hub.

      Returns string

    • Parameters

      • src: string
      • position: { x: number; y: number }
      • Optionalsize: { h: number; w: number }

      Returns string

    • Parameters

      • Optionalopts: {
            fillColor?: string;
            position?: { x: number; y: number };
            shape?: ShapeKind;
            size?: { h: number; w: number };
            strokeColor?: string;
            strokeWidth?: number;
        }

      Returns string

    • Adds selected root subtrees as children of an existing frame.

      Parameters

      • frameId: string
      • ids: readonly string[]

      Returns void

    • Parameters

      Returns void

    • Parameters

      Returns void

    • Returns boolean

    • Centers the camera on a world point without changing zoom.

      Parameters

      Returns void

    • Returns void

    • Removes a frame while preserving its direct children as roots.

      Parameters

      • frameId: string

      Returns void

    • Parameters

      • containerId: string

      Returns boolean

    • Declares htmlTypes that route to canvas painters even before a painter for them registers, so the element renderer never treats them as DOM-backed (avoiding a DOM-mount flash while a host is still loading its painter). Returns an idempotent release; each expect call is independently reference counted by the registry.

      Parameters

      • htmlTypes: Iterable<string>

      Returns () => void

    • Parameters

      Returns Promise<Blob | null>

    • Returns string

    • Parameters

      Returns Promise<Blob | null>

    • Parameters

      Returns Promise<string>

    • Parameters

      • Optionalpadding: number

      Returns void

    • Creates a frame around selected root subtrees and returns its id.

      Parameters

      • ids: readonly string[]
      • Optionaloptions: { color?: string; padding?: number; title?: string }

      Returns string

    • Parameters

      • containerId: string

      Returns TextElement | undefined

    • Size in CSS pixels of the canvas that getVisibleRect() measures. Exposed because canvasEl is private: consumers can only reach the wrapper (via domLayer.parentElement), so without this accessor the canonical size behind getVisibleRect() is unreachable and callers resort to getVisibleRect().w * camera.zoom. Capture and restore must measure the same element or saved views do not round-trip.

      Returns { h: number; w: number }

    • Topmost element at a world point, using the same geometry selection uses (rotation-aware, grid excluded, real stroke/line hit paths).

      match participates in the topmost-first walk rather than filtering the result, so a non-matching element on top does not swallow the hit. Invisible layers are never returned, in any mode.

      Parameters

      • world: Point
      • Optionaloptions: HitTestOptions

      Returns CanvasElement | null

    • Direct access to the viewport's live html-painter registry — the same instance the viewport itself uses to route canvas-backed html elements. Beyond register/expectCanvasHtmlTypes (already exposed above), this hands out getActivePainter, canvasTypes, onChange, and version, so a surface such as the minimap that needs to read routing state or react to registry changes can do so without the viewport re-deriving or proxying each capability individually.

      Returns HtmlPainterRegistry

    • Returns RenderStatsSnapshot

    • getSelectedIds() and the onSelectionChange emitter never surface stale ids: once the enclosing history transaction completes, both reflect the current selection.

      Returns string[]

    • Unlike getSelectionStyle() — which returns {} for a style-less selection — this returns null when no style field is applicable.

      Returns SelectionStyleDetails | null

    • Type Parameters

      • T

      Parameters

      • key: ServiceKey<T>

      Returns T | undefined

    • Returns the active, resolved board theme.

      Returns ResolvedTheme

    • World-space rectangle currently visible through the canvas.

      Returns Bounds

    • Returns void

    • Whether an embedded board takes touch input; always true when not embedded.

      Returns boolean

    • Parameters

      • json: string

      Returns void

    • Parameters

      • OptionalintervalMs: number

      Returns () => void

    • Subscribes to element activations. Persistent and independent of setActivation: subscribing before activation is enabled, or across a replacement, keeps working. Emission iterates a snapshot with per-listener try/catch. Returns an idempotent unsubscribe.

      Parameters

      Returns () => void

    • Notifies on each engaged-state change, including Escape; never fires when not embedded.

      Parameters

      • listener: (engaged: boolean) => void

      Returns () => void

    • Subscribes to diagnostics emitted while painting canvas-routed html elements (missing painter, painter threw, degenerate size). Deduped per element/target/kind against the current registry and element versions, so a fail -> repair -> fail-again sequence reports twice rather than being suppressed forever. Returns an idempotent unsubscribe.

      Parameters

      • listener: (d: HtmlPaintDiagnostic) => void

      Returns () => void

    • Notifies after the host container resizes (ResizeObserver-driven). A resize changes the visible world rect without a camera event; overlays such as the minimap subscribe to stay current. Returns an idempotent unsubscribe.

      Parameters

      • listener: () => void

      Returns () => void

    • Persistent, viewport-owned selection-change emitter. Subscribing works regardless of whether a select tool is registered yet; it forwards events from whichever select tool is currently attached via toolManager.onRegister. Never delivers stale ids once the enclosing history transaction completes.

      Parameters

      • listener: () => void

      Returns () => void

    • Fires synchronously after any change exportState() would reflect; returns a disposer.

      Parameters

      • listener: () => void

      Returns () => void

    • Fires after the viewport resolves to a different theme.

      Parameters

      • listener: (theme: ResolvedTheme) => void

      Returns () => void

    • Notifies for each plain wheel an embedded board leaves to the page; never fires otherwise.

      Parameters

      • listener: (e: WheelEvent) => void

      Returns () => void

    • Parameters

      Returns void

    • Returns boolean

    • Registers the canvas painter for htmlType. Later registrations for the same type shadow earlier ones (LIFO); unregistering restores the previous entry. Existing elements of this type reconcile synchronously — DOM nodes detach and the render loop repaints on the next frame.

      Parameters

      • htmlType: string
      • painter: HtmlPainter

      Returns () => void

    • Parameters

      • htmlType: string
      • factory: (el: HtmlElement) => HTMLElement

      Returns void

    • Registers a world-space overlay drawn on every frame, regardless of the active tool — the surface for remote presence visuals such as laser trails, cursors, pings, and shared rulers. Overlays draw above elements and DOM content, beneath the active tool's own renderOverlay, and never touch elements, history, or persisted state. Returns an idempotent unsubscribe that also erases the overlay's last frame.

      Parameters

      • draw: OverlayRenderer

      Returns () => void

    • Removes existing elements as one undoable operation and returns the number removed.

      Parameters

      • ids: Iterable<string>

      Returns number

    • Removes selected direct children from an existing frame.

      Parameters

      • frameId: string
      • ids: readonly string[]

      Returns void

    • Parameters

      • id: string

      Returns void

    • Repaints only the overlay stratum (tool overlay, registered overlays, overlay hooks) on the next frame. Use requestRender for anything that changes elements, layers, the camera or other hooks.

      Returns void

    • Returns void

    • Clears authored elbow route axes and returns whether an arrow changed.

      Parameters

      • id: string

      Returns boolean

    • Parameters

      • direction: RotateDirection

      Returns void

    • Returns whether the action ran.

      Parameters

      • action: string

      Returns boolean

    • Enables (or replaces, or with null disables) pointer activation of canvas-painted elements — the bridge for elements that are drawn rather than mounted and so cannot receive DOM events. Default off, so every existing consumer behaves identically.

      The controller is a passive observer: listeners are { passive: true } and it never calls preventDefault, stopPropagation, or takes pointer capture. Changing or disabling activation resets all active and pending gestures. Throws RangeError for a non-finite/negative slopPx or a non-positive doubleDelayMs, leaving any existing activation untouched.

      The returned disposer clears only its own generation, so a stale Strict-Mode cleanup cannot tear down a newer registration.

      Parameters

      Returns () => void

    • Parameters

      • containerId: string
      • html: string

      Returns string | undefined

    • Engages or disengages an embedded board; a no-op when not embedded or after destroy().

      Parameters

      • engaged: boolean

      Returns void

    • Sets or clears (null) the link on every id as one undo step; throws before mutating.

      Parameters

      • ids: readonly string[]
      • link: string | null

      Returns void

    • Sets an element's direct parent, or clears its parent when passed null.

      Parameters

      • childId: string
      • parentId: string | null

      Returns void

    • Parameters

      • enabled: boolean

      Returns void

    • Parameters

      • enabled: boolean

      Returns void

    • Sets the board theme.

      Parameters

      Returns void

    • Parameters

      • name: string

      Returns void

    • Returns void

    • Mutations in the window arrive as one batch event, unrecorded in history and without origin.

      Returns NotificationController

    • Returns void

    • Groups synchronous local store and layer mutations into one undo step. Joins any open transaction (a nested call or a live tool gesture); a pending keyboard nudge is committed first. If the callback throws, mutations already applied remain undoable and the original error is rethrown.

      Type Parameters

      • T

      Parameters

      • operation: () => T

      Returns T

    • Returns boolean

    • Returns void

    • Parameters

      • id: string
      • newContent: HTMLElement

      Returns void