Skip to main content

pointerevents

Unified mouse/pen/touch input handling via the Pointer Events API.

Import: @rtorcato/browser-common/pointerevents

๐Ÿ“– MDN: Pointer Events ยท ๐Ÿ“Š caniuse: pointer

Exampleโ€‹

import { isPointerEventsAvailable, onPointer, getPointerType, isPrimaryPointer } from '@rtorcato/browser-common/pointerevents'

if (isPointerEventsAvailable()) {
const off = onPointer(canvas, 'pointerdown', (e) => {
if (getPointerType(e) === 'pen' && isPrimaryPointer(e)) draw(e.clientX, e.clientY)
})
off()
}

Exportsโ€‹

  • isPointerEventsAvailable() โ€” feature check
  • onPointer(element, type, handler, options?) โ€” subscribes to a pointer event, returns an unsubscribe function
  • getPointerType(event) โ€” input device type: 'mouse' | 'pen' | 'touch' | ''
  • isPrimaryPointer(event) โ€” true if the event is the primary pointer of its type

See the API reference for full signatures.