weasel API - v0.8.0
    Preparing search index...

    Interface ToolCtx<TScratch>

    Per-event context passed to every channel handler. scratch is typed via the tool's TScratch parameter; it survives across a single gesture (pointer-down through end/cancel) and is replaced on next gesture start by initScratch().

    interface ToolCtx<TScratch = unknown> {
        adapter: unknown;
        applyOps: (ops: Op[], label: string) => void;
        canvasRect: DOMRect;
        debug?: DebugSink;
        modifiers: ToolModifiers;
        scratch: TScratch;
        screenPoint?: { x: number; y: number };
        selection: SelectionApi;
        setView: (next: View) => void;
        view: View;
        worldX: number;
        worldY: number;
    }

    Type Parameters

    • TScratch = unknown
    Index

    Properties

    adapter: unknown

    Adapter/scene access — opaque at this layer; tools that need it cast to a known shape. This layer doesn't constrain it.

    applyOps: (ops: Op[], label: string) => void
    canvasRect: DOMRect

    Bounding rect of the canvas element in viewport coords. Used by zoom/pan tools to convert event clientX/clientY to canvas-relative anchors.

    debug?: DebugSink

    Optional debug sink. When <Canvas debug={...}> is enabled, Canvas threads its sink here so tool-internal hit math (handle hitboxes, rotation handle, etc.) lands in the same overlay as Canvas's own bounds/origin records. Tools should call this conditionally with ?..

    modifiers: ToolModifiers
    scratch: TScratch
    screenPoint?: { x: number; y: number }

    Screen-space pointer coords relative to canvasRect. Useful for viewport tools that pan/zoom in screen space (e.g. hand-pan computes deltas in pixels, not world units). Optional — populated by the dispatcher on pointer events; absent on keyboard events.

    selection: SelectionApi
    setView: (next: View) => void

    Mutate the viewport. In controlled mode this calls the consumer's onViewChange; in uncontrolled mode it updates Canvas's internal state. View changes are not undoable.

    view: View

    Current viewport. Reflects camera-position semantics — see View JSDoc.

    worldX: number
    worldY: number