gradum-kit - v0.1.0
    Preparing search index...

    Class GradumDragEvent

    GradumDragEvent

    The event fired for gradum-drag, gradum-drag-start, and gradum-drag-end. It tracks every active pointer at once, so a multi-touch drag reports one entry per finger: each map below is keyed by pointer id. Every position is available raw and scaled into document space, along with the per-event deltas.

    Hierarchy (View Summary)

    Index
    origins: GradumMap<number, Point>

    Where each pointer started its drag, keyed by pointer id.

    previousPositions: GradumMap<number, Point>

    Where each pointer was on the previous drag event, keyed by pointer id.

    positions: GradumMap<number, Point>

    Where each pointer is now, keyed by pointer id.

    eventManager: GradumEventManager

    The event manager that fired this event.

    toolName: string

    The name of the tool this event is attributed to, or undefined when no tool was current. Resolve it to the tool itself with GradumEvent.tool.

    The name this event was dispatched under, such as gradum-click.

    clickMode: ClickMode

    The pointer button or input mode this event belongs to.

    inputDevice: InputDevice

    The device that produced this event.

    keys: string[]

    The keys held down when the event fired.

    position: Point

    The screen position the event was fired from.

    authorizeScaling: boolean | (() => boolean)

    Whether GradumEvent.scaledPosition and its per-pointer equivalents actually scale, or hand back the raw position. Assign a callback to decide per read — useful when a canvas is only sometimes transformed. Defaults to true.

    scalePosition: (position: Point) => Point

    How a screen position is mapped into document space. Assign it to make events aware of a panned or zoomed canvas. Defaults to returning the position unchanged.

    • get deltaPositions(): GradumMap<number, Point>

      Returns GradumMap<number, Point>

      How far each pointer moved since the previous event, keyed by pointer id. A pointer with no previous position — on drag start, or when a finger has just joined — reports a zero delta rather than being left out, so a delta is always defined for every active pointer.

    • get deltaPosition(): Point

      Returns Point

      The average movement across all pointers since the previous event. Use it to move something with the drag without caring how many fingers are down.

    • get scaledDeltaPosition(): Point

      Returns Point

      The average movement across all pointers since the previous event, in document space.

    • get tool(): Node

      Returns Node

      The tool associated with this event, or null if the event carries no tool name.

    • get target(): Element | Document

      Returns Element | Document

      The element the event was fired on, or the document when there is no element target.

    • get scaledPosition(): Point

      Returns Point

      The event position in document space, obtained by running GradumEvent.position through scalePosition. Falls back to the raw position when scaling is not authorized.

    • get scalingAuthorized(): boolean

      Returns boolean

      Whether scaled positions are computed for this event. Resolves authorizeScaling, calling it first if it is a callback.

    • Function

      closest

      Type Parameters

      • T extends Element

        The type of element to look for.

      Parameters

      • type: new (...args: any[]) => T

        The constructor to match against.

      • Optionalstrict: boolean | Element

        When true, the match must also contain the event position, so an ancestor the pointer has left is rejected. Pass an Element to test against that element's bounds instead, or false to skip the check.

      • Optionalfrom: ClosestOrigin

        Where to start searching from.

      Returns T

      The nearest matching element, or null if there is none.

      Find the nearest element of the given class, starting from the event target or the event position and walking up. Matching is by instanceof.

    • Function

      closest

      Parameters

      • type: string

        A custom-element tag name, or a CSS selector.

      • Optionalstrict: boolean | Element

        When true, the match must also contain the event position. Pass an Element to test against that element's bounds instead, or false to skip it.

      • Optionalfrom: ClosestOrigin

        Where to start searching from.

      Returns Element

      The nearest matching element, or null if there is none.

      Find the nearest element matching the given string. A registered custom-element tag such as "my-component" is resolved to its constructor and matched by instanceof; anything else is treated as a CSS selector.

    • Protected Function

      scalePositionsMap

      Parameters

      • Optionalpositions: GradumMap<number, Point>

        Positions keyed by pointer id.

      Returns GradumMap<number, Point>

      A new map with each position scaled. The input is unchanged.

      Map every point in a per-pointer map into document space. Used by GradumDragEvent to expose scaled variants of its position maps.