iink-ts - v4.0.0
    Preparing search index...

    Class InteractiveInkCanvas

    Implements

    Index
    • Create and attach an InteractiveInk canvas to the given DOM element. Use Canvas.load() instead of calling this constructor directly.

      Parameters

      • rootElement: HTMLElement

        Host DOM element that will contain the canvas layers

      • Optionaloptions: TInteractiveInkCanvasOptions

        Canvas options: configuration, CSS vars, manager overrides

      Returns InteractiveInkCanvas

    WebSocket client handling real-time communication with the MyScript backend.

    Manages smart connectors and anchor-based endpoint updates.

    Converts ink strokes to recognized text, math, or shape symbols.

    dom: typeof DOMFactory = DOMFactory

    Static utility class for creating DOM elements.

    eraser: EraseManager

    Handles erasing strokes and symbols via pointer interaction.

    Event bus for subscribing to canvas lifecycle and content events.

    EXPORT_RETRY_DEBOUNCE_MS: 300

    Detects and processes touch/pointer gestures (scratch-out, join, insert, etc.).

    Manages undo/redo history stack for all symbol changes.

    info?: TApiInfos

    Server API information (version, etc.) loaded on first connection.

    Queries and maps JIIX data to local symbols for math/text label resolution.

    Handles keyboard shortcuts and hotkey-based tool switching.

    layers: CanvasLayer

    DOM layer manager handling rendering, UI, and modal elements.

    logger: Logger = ...

    Logger instance for this canvas.

    Manages math recognition: variables, computation, and evaluation rendering.

    Manages the floating UI menu (tool selector, style panel, action buttons).

    Handles canvas panning when the Move tool is active.

    Manages all visual overlays: math/text block indicators, debug visualizations.

    PASTE_OFFSET: 20

    Replays a recorded set of strokes with play/pause/speed control.

    renderer: SVGRenderer

    SVG renderer responsible for drawing symbols onto the canvas layer.

    Handles symbol selection, selection group rendering, and hit-testing.

    Manages snapping behavior for symbols during move/resize operations.

    synchronizer: IISynchronizerManager

    Synchronizes the local model with the JIIX export from the backend client.

    Orchestrates translate, resize, and rotation transforms on selected symbols.

    Manages text and math symbol layout: bounds computation and reflow after edits.

    Handles ink input: captures pointer events and creates strokes.

    ZOOM_FIT_MARGIN: 40
    • get connectionState(): TCanvasConnectionState

      Derived, UI-oriented canvas state — see TCanvasConnectionState. Listen to event.addConnectionStateChangedListener for change notifications.

      Returns TCanvasConnectionState

    • get initializationPromise(): Promise<void>

      Promise that resolves when the WebSocket session is fully initialized. Await this before calling any recognition methods.

      Returns Promise<void>

    • get isOffline(): boolean

      True while strokes are queued locally waiting for reconnection. Listen to event.addConnectionStatusChangedListener for change notifications.

      Returns boolean

    • get model(): IIModel

      Current symbol model containing all ink, text, math, and shape symbols.

      Returns IIModel

    • get penStyle(): TStyle

      Current pen style applied to new strokes. Setting this merges the provided partial style with the current style.

      Returns TStyle

    • set penStyle(
          penStyle: {
              color?: string;
              fill?: string;
              opacity?: number;
              width?: number;
              [key: string]: string | number | undefined;
          },
      ): void

      Parameters

      • penStyle: {
            color?: string;
            fill?: string;
            opacity?: number;
            width?: number;
            [key: string]: string | number | undefined;
        }

      Returns void

    • get readOnly(): boolean

      Whether real pointer input (write/erase/select/move) is currently blocked - see readOnly setter.

      Returns boolean

    • set readOnly(value: boolean): void

      Block or restore real pointer input across every tool at once (write/erase/select/move all attach through layers.rendering), and reflect it with a "not-allowed" cursor. Used e.g. by canvas.playback so a replayed stroke can't race the user's own input.

      Parameters

      • value: boolean

      Returns void

    • set renderingConfiguration(
          renderingConfiguration: TIIRendererConfiguration,
      ): void

      Apply a partial rendering configuration at runtime. Triggers a resize and guide-row recompute.

      Parameters

      Returns void

    • get tool(): CanvasTool

      Active editing tool. Setting this switches cursor style, attaches/detaches the corresponding manager, clears selection, and emits a toolChanged event.

      Returns CanvasTool

    • set tool(i: CanvasTool): void

      Parameters

      Returns void

    • Add multiple symbols to the model and renderer

      Parameters

      • symList: TSymbol[]

        Array of symbols to add

      • addToHistory: boolean = true

        Whether to add to history (default: true)

      Returns Promise<TSymbol[]>

      Promise resolving to array of added symbols

    • Parameters

      Returns Blob

    • Switch the recognition language without destroying the canvas. Opens a new backend session and re-sends all existing strokes.

      Parameters

      • code: string

        BCP 47 language code (e.g. "en_US", "fr_FR")

      Returns Promise<void>

      If the new session fails to open

    • Change the order of a symbol in the rendering stack

      Parameters

      • symbol: TSymbol

        Symbol to reorder

      • position: "first" | "last" | "forward" | "backward"

        New position (first, last, forward, backward)

      Returns void

    • Change the order of multiple symbols in the rendering stack

      Parameters

      • symbols: TSymbol[]

        Symbols to reorder

      • position: "first" | "last" | "forward" | "backward"

        New position (first, last, forward, backward)

      Returns void

    • Clear all content from the canvas

      Returns Promise<void>

      Promise that resolves when cleared

    • Force label fully inactive regardless of how many startOperation calls are pending. For level-triggered signals with a single external "done" event (e.g. the client's idle event) rather than one end call per start call.

      Parameters

      Returns void

    • Convert specific symbols, or all symbols if none specified

      Parameters

      • Optionalsymbols: TSymbol[]

        Symbols to convert (defaults to all symbols)

      Returns Promise<void>

      Promise that resolves when conversion is complete

    • Copy selected symbols (or all symbols if nothing selected) to the internal clipboard

      Returns void

    • Create a symbol from partial data

      Parameters

      Returns Promise<TSymbol>

      Promise resolving to created symbol

    • Create multiple symbols from partial data

      Parameters

      Returns Promise<TSymbol[]>

      Promise resolving to array of created symbols

    • Cut selected symbols: copy them to clipboard, then remove from model

      Returns Promise<void>

    • Destroy the canvas and clean up resources

      Returns Promise<void>

      Promise that resolves when destruction is complete

    • Download symbols as JSON file, either all symbols or only selected ones

      Parameters

      • selection: boolean = false

        Whether to download only selected symbols (default: false, downloads all symbols)

      Returns void

    • Download symbols as PNG file, either all symbols or only selected ones

      Parameters

      • selection: boolean = false

        Whether to download only selected symbols (default: false, downloads all symbols)

      Returns void

    • Download symbols as SVG file, either all symbols or only selected ones

      Parameters

      • selection: boolean = false

        Whether to download only selected symbols (default: false, downloads all symbols)

      Returns void

    • Download symbols as plain text file, either all symbols or only selected ones

      Parameters

      • selection: boolean = false

        Whether to download only selected symbols (default: false, downloads all symbols)

      Returns void

    • Duplicate specific symbols, or all symbols if none specified

      Parameters

      • Optionalsymbols: TSymbol[]

        Symbols to duplicate (defaults to all symbols)

      Returns Promise<TSymbol[]>

      Promise resolving with duplicated symbols

    • Mark one occurrence of label as finished. Must be paired with a prior startOperation.

      Parameters

      Returns void

    • Export content to specified MIME types

      Parameters

      • OptionalmimeTypes: string[]

        Array of MIME types to export

      Returns Promise<TExport>

      Promise resolving with exports

    • Extract all math symbols recursively

      Parameters

      • symbols: TSymbol[] | undefined

        Symbols to extract maths from

      Returns TMath[]

      Array of extracted math symbols

    • Extract all strokes from symbols recursively

      Parameters

      • symbols: TSymbol[] | undefined

        Symbols to extract strokes from

      Returns TStroke[]

      Array of extracted strokes

    • Parameters

      Returns string

    • Parameters

      • extension: string

      Returns string

    • Get bounding box for a list of symbols

      Parameters

      • symbols: TSymbol[]

        Symbols to calculate bounds for

      • margin: number = SELECTION_MARGIN

        TMargin to add around bounds (default: SELECTION_MARGIN)

      Returns TBox

      Bounding box containing all symbols

    • Type Parameters

      Parameters

      • type: string

      Returns SymbolUtil<T> | undefined

    • Get the current viewport zoom level.

      Returns number

      Current zoom factor (1.0 = 100 %)

    • Parameters

      • event: WheelEvent

      Returns void

    • Whether label is currently active (at least one unmatched startOperation call).

      Parameters

      Returns boolean

    • Import strokes from point events

      Parameters

      • partialStrokes: {
            bounds?: {
                angle?: number;
                center?: { x?: number; y?: number };
                height?: number;
                width?: number;
            };
            creationTime?: number;
            decoratorKind?: DecoratorKind;
            edges?: (
                | { p1?: { x?: number; y?: number }; p2?: { x?: number; y?: number } }
                | undefined
            )[];
            id?: string;
            isSolverOutput?: boolean;
            jiixBlockId?: string;
            jiixBlockType?: "Text" | "Math" | "Node" | "Edge" | "Decorator";
            length?: number;
            modificationDate?: number;
            pointers?: ({ p?: number; t?: number; x?: number; y?: number } | undefined)[];
            pointerType?: string;
            snapPoints?: ({ x?: number; y?: number } | undefined)[];
            style?: {
                color?: string;
                fill?: string;
                opacity?: number;
                width?: number;
                [key: string]: string | number | undefined;
            };
            type?: Stroke;
            vertices?: ({ p?: number; t?: number; x?: number; y?: number } | undefined)[];
        }[]

        Array of partial stroke data

      Returns Promise<IIModel>

      Promise resolving to updated model

    • Initialize the canvas: render layers, attach input handlers, connect to the WebSocket client, and load the initial session. Called automatically by Canvas.load() — do not call manually.

      Returns Promise<void>

      If the client connection or session setup fails

    • Only relevant for WebSocket-backed canvas; other variants never call this.

      Parameters

      Returns void

    • Display an error in the canvas overlay and emit an error event.

      Parameters

      • error: Error

        Error to display and emit

      Returns void

    • Parameters

      • idle: boolean

      Returns void

      The client's idle event only fires in response to an explicit client.waitForIdle() call (a request/response pair, not a push notification) — it does NOT fire automatically after every addStrokes()/transform/etc. So it cannot be used to end a "Recognizing" operation reliably. This only preserves the public event.emitIdle passthrough for consumers who call waitForIdle() themselves.

    • Called once the canvas has connected to its backend for the first time.

      Returns void

    • Parameters

      Returns Promise<void>

    • With ignoreGestureStrokes the backend never emits a contentChanged for a gesture stroke, so the debounced synchronize scheduled by onContentChanged has nothing left to reschedule it - force one here instead of relying on that mechanism.

      Returns Promise<void>

    • Shift the viewport by the given pixel delta without changing zoom.

      Parameters

      • dx: number

        Horizontal offset in pixels (positive = pan right)

      • dy: number

        Vertical offset in pixels (positive = pan down)

      Returns void

    • Paste clipboard symbols at an offset and select them

      Returns Promise<void>

    • Redo the previously undone action

      Returns Promise<IIModel>

      Promise resolving to updated model

    • Type Parameters

      Parameters

      Returns void

    • Remove a symbol from the model

      Parameters

      • id: string

        ID of symbol to remove

      • addToHistory: boolean = true

        Whether to add to history (default: true)

      Returns Promise<void>

      Promise that resolves when symbol is removed

    • Remove multiple symbols from the model

      Parameters

      • ids: string[]

        Array of symbol IDs to remove

      • addToHistory: boolean = true

        Whether to add to history (default: true)

      Returns Promise<TSymbol[]>

      Promise that resolves when symbols are removed

    • Replace old symbols with new symbols

      Parameters

      • oldSymbols: TSymbol[]

        Array of old symbols to be replaced

      • newSymbols: TSymbol[]

        Array of new symbols to replace with

      • addToHistory: boolean = true

        Whether to add this operation to history (default: true)

      Returns Promise<void>

    • Resize the canvas

      Parameters

      • dimensions: { height?: number; width?: number } = {}

        New height and/or width

      Returns Promise<void>

      Promise that resolves when resize is complete

    • Select symbols by their IDs

      Parameters

      • ids: string[]

        Array of symbol IDs to select

      Returns void

    • Select all symbols

      Returns void

    • Returns void

    • On top of the base badge tracking, cancels the pending debounced synchronize() as soon as a new gesture starts - so a stroke/transform beginning right as the debounce timer would otherwise fire never races it (it'll be rescheduled once that gesture's own content change comes in).

      Parameters

      Returns void

    • Returns void

    • Returns void

    • Synchronize strokes with JIIX export

      Returns Promise<void>

    • Run fn, marking label as an active operation for the duration (shown on the canvas state badge tooltip). Safe against overlapping/concurrent calls with the same or different labels, and against fn throwing (the operation is always ended).

      Type Parameters

      • T

      Parameters

      Returns Promise<T>

    • Parameters

      • fileName: string
      • urlData: string

      Returns void

    • Undo the last action

      Returns Promise<IIModel>

      Promise resolving to updated model

    • Unselect all currently selected symbols

      Returns void

    • Update layer UI with debouncing

      Parameters

      • timeout: number = 500

        Debounce timeout in milliseconds (default: 500ms)

      Returns void

    • Update an existing symbol

      Parameters

      • sym: TSymbol

        Symbol to update

      • addToHistory: boolean = true

        Whether to add to history (default: true)

      Returns Promise<TSymbol>

      Promise resolving to updated symbol

    • Update multiple existing symbols

      Parameters

      • symList: TSymbol[]

        Array of symbols to update

      • addToHistory: boolean = true

        Whether to add to history (default: true)

      Returns Promise<TSymbol[]>

      Promise resolving to array of updated symbols

    • Update style of multiple symbols

      Parameters

      • symbolIds: string[]

        Array of symbol IDs to update

      • style: {
            color?: string;
            fill?: string;
            opacity?: number;
            width?: number;
            [key: string]: string | number | undefined;
        }

        Partial style to apply

      • addToHistory: boolean = true

        Whether to add to history (default: true)

      Returns void

    • Update font style of text symbols

      Parameters

      • textIds: string[]

        Array of text symbol IDs

      • options: { fontSize?: number; fontWeight?: "bold" | "normal" | "auto" }

        Font style options (fontSize, fontWeight)

      Returns void

    • Wait for the client to become idle

      Returns Promise<void>

      Promise that resolves when idle

    • Set the viewport zoom level, optionally anchored to a point.

      Parameters

      • zoom: number

        Target zoom factor (e.g. 1.5 = 150 %)

      • OptionalcenterX: number

        X coordinate to zoom around (pixels, default: viewport center)

      • OptionalcenterY: number

        Y coordinate to zoom around (pixels, default: viewport center)

      Returns void

    • Zoom and pan the view to fit the given symbols (or all symbols) within the viewport. Resets to zoom 1 if there are no symbols.

      Parameters

      • Optionalsymbols: TSymbol[]

        Symbols to fit (default: all model symbols)

      Returns void

    • Apply or replace CSS custom properties on the canvas root element. Clears all existing --ms-ink-* properties first, then sets the provided vars. Does not reinitialize — current model and session are preserved. Pass undefined to reset to stylesheet defaults.

      Parameters

      • vars: Record<string, string> | undefined

      Returns void