Field Notes
    Preparing search index...

    Class Viewport

    Index
    camera: Camera
    constraintProxy: ConstraintServiceProxy = ...
    domLayer: HTMLDivElement
    elementRegistry: ElementRegistry
    history: HistoryStack
    historyRecorder: HistoryRecorder
    layerManager: LayerManager
    toolContext: ToolContext
    toolManager: ToolManager
    • Parameters

      • dom: HTMLElement
      • position: { x: number; y: number }
      • size: { 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 }
      • size: { h: number; w: number } = ...

      Returns string

    • Parameters

      • opts: {
            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

    • 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

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

      Parameters

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

      Returns string

    • 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

      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

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

      Returns string[]

    • 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

      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

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

      Parameters

      • listener: (e: WheelEvent) => void

      Returns () => void

    • 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

      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

      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

    • 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

    • 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

    • 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

    • 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