Class Pointers<CallbacksMap, StaticProps, MutableProps>

Manages pointer events, including tracking multiple pointers, and emitting callbacks for pointer interactions.

For proper functionality, ensure the container has an appropriate touch-action property.

Documentation

Type Parameters

Hierarchy (View Summary)

Constructors

Properties

_callbacks: Callbacks<CallbacksMap>

Callbacks instance

_destroyable: () => void[] = []

Stores actions that need to be executed when the module is destroyed

_isDestroyed: boolean = false

Tracks whether the module has been destroyed

_isStarted: boolean = false

Indicates whether the start event has been triggered.

_listeners: () => void[] = []

Stores active event listeners for runtime interactions.

_pointersMap: Map<number, IPointersItem>

Map of active pointers.

_props: TTRequiredProps<MutableProps & StaticProps>

Current properties

Accessors

  • get isDestroyed(): boolean

    Checks if the module has been destroyed.

    Returns boolean

  • get name(): string

    The name of the module, derived from the class name

    Returns string

  • get prefix(): string

    Optional prefix for classnames used by the module

    Returns string

Methods

  • Adds a class name on an element, and keeps track of it for removal when the module is destroyed.

    Parameters

    • element: Element

      The target DOM element.

    • className: string

      The class name to toggle.

    Returns void

  • Helper function to generate classnames with the module's prefix.

    Parameters

    • ...classNames: string[]

      The class names to generate.

    Returns string

    A string of class names with the module's prefix applied.

  • Returns pointer coordinates relative to the container.

    Parameters

    • event: PointerEvent

    Returns { x: number; y: number }

  • Handles event cancellations (pointercancel, blur). Triggers the end callback and cleans up all pointers.

    Returns void

  • Handles pointer down events (pointerdown). Adds a new pointer if conditions are met and triggers the pointerdown callback.

    Parameters

    • event: PointerEvent

    Returns void

  • Handles pointer movement (pointermove). Updates pointer positions and triggers the pointermove callback.

    Parameters

    • event: PointerEvent

    Returns void

  • Handles pointer release (pointerup). Removes the pointer and triggers the pointerup callback. If no active pointers remain, fires the end callback.

    Parameters

    • event: PointerEvent

    Returns void

  • Adds a callback on the module's destruction.

    Parameters

    • action: () => void

      The function to execute during destruction.

    Returns void