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

    Interface CanvasExtensionApi

    The base imperative ref handle shared by the canvas components. For <SceneCanvas> refs use SceneCanvasApi (this type plus the scene-level surfaces, e.g. a non-optional ingest):

    const ref = useRef<SceneCanvasApi>(null);
    <SceneCanvas ref={ref} />;
    ref.current?.element?.focus();

    This is a deliberately small, supported consumer surface — not internal. Consumers use element for focus / screenshots / getBoundingClientRect; plugin packages (e.g. @weasel-js/hud) additionally use requestRedraw and registerLayer to attach externally-owned draw layers.

    interface CanvasExtensionApi {
        element: HTMLCanvasElement | null;
        hitTestExtras(
            worldX: number,
            worldY: number,
        ): { binding: AffordanceBinding; layerId: string } | null;
        ingest?(
            input: File[] | IngestItem[],
            point?: { x: number; y: number },
        ): void;
        registerLayer(layer: RenderLayer<unknown>): () => void;
        requestRedraw(): void;
    }

    Hierarchy (View Summary)

    Index

    Properties

    element: HTMLCanvasElement | null

    The underlying HTMLCanvasElement. Null until the canvas mounts. Use this for screenshots, getBoundingClientRect, focus management, etc. (Replaces the pre-A2 pattern where ref.current directly was the element.)

    Methods

    • Hit-test the registered layers (topmost-first, last-registered wins) at a world-space point. Returns the id of the layer that claimed the point and whatever its hitTest resolved, or null when none did.

      <SceneCanvas> folds this into the affordanceAt thunk it hands the gesture dispatcher — ahead of the kit's own selection chrome, since registered layers draw on top — so a hit surfaces to actions as an AffordanceHit with kind layer:<id> and the binding's initialScratch as its payload. A layer's owner binds a kindOf predicate on that kind to claim the gesture; see @weasel-js/hud for the worked example.

      Parameters

      • worldX: number
      • worldY: number

      Returns { binding: AffordanceBinding; layerId: string } | null

    • Feed external content into the ingestion pipeline imperatively — the same content-handler registry that OS drop and clipboard paste hit. input may be raw File[] (e.g. from openFilePicker) or pre-normalized IngestItem[]. point is a world-space placement anchor; omitted → handlers use their point-less policy (the kit image handler centers on the viewport).

      Optional because ingestion needs the SceneCanvas action stack — the handle is always populated on <SceneCanvas> refs, absent on the bare-primitive handle.

      Parameters

      • input: File[] | IngestItem[]
      • Optionalpoint: { x: number; y: number }

      Returns void