npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

lite-pointer-tracker

v1.0.1

Published

Lightweight pointer events manager — unifies mouse, touch, and pen into a clean start/move/end API with ghost-drag detection and pointer capture.

Downloads

10

Readme

lite-pointer-tracker

npm version npm bundle size npm downloads npm total downloads TypeScript Zero Dependencies License: MIT

A lightweight, zero-dependency pointer events manager that unifies mouse, touch, and pen interactions into a clean start/move/end API.

Built for canvas apps, scratch cards, drawing tools, and any UI where you need reliable drag tracking without fighting the browser.

Features

  • Unified API — one handler set for mouse, touch, and pen
  • Mobile Safari safe — programmatic touch-action: none prevents gesture hijacking
  • Ghost-drag detection — handles macOS edge case where button is released outside the window
  • Lost capture recovery — detects when the browser forcibly releases pointer capture
  • Pointer capture — all events route through the target element, even when the pointer leaves it
  • Zero allocation — passes the raw PointerEvent to handlers (no wrapper objects)
  • Stylus-aware — native access to pressure, tiltX, tiltY, pointerType
  • Clean teardownAbortController-based listener cleanup, restores original touch-action

Installation

npm install lite-pointer-tracker

Or drop the single file into your project.

Quick Start

import { PointerTracker } from 'lite-pointer-tracker';

const canvas = document.querySelector('canvas');

const tracker = new PointerTracker(canvas, {
    onStart(e) {
        console.log('Down at', e.offsetX, e.offsetY);
    },
    onMove(e) {
        console.log('Move to', e.offsetX, e.offsetY);
        // e.pressure available for stylus
    },
    onEnd(e) {
        console.log('Up');
    },
});

// Later: clean up
tracker.destroy();

API

new PointerTracker(target, handlers?)

| Parameter | Type | Description | |-----------|------|-------------| | target | HTMLElement | The element to track pointer events on | | handlers.onStart | (e: PointerEvent) => void | Called on primary button pointerdown | | handlers.onMove | (e: PointerEvent) => void | Called on pointermove while active | | handlers.onEnd | (e: PointerEvent) => void | Called on pointerup, pointercancel, lostpointercapture, or ghost-drag |

Properties

| Property | Type | Description | |----------|------|-------------| | .isActive | boolean | Whether a pointer interaction is in progress |

Methods

| Method | Description | |--------|-------------| | .destroy() | Remove all listeners, restore touch-action, release target. Idempotent. |

How It Works

Pointer capture: On pointerdown, the tracker calls setPointerCapture() so all subsequent pointermove and pointerup events route through the target element — even if the pointer moves outside it. This is what makes drag tracking reliable.

Ghost-drag detection: On macOS, if the user releases the mouse button while the cursor is outside the browser window, pointerup never fires. The tracker detects this by checking e.buttons & 1 on every pointermove — if the primary button is no longer held, it synthesizes an end event.

Lost capture recovery: If the browser forcibly releases pointer capture (element removed from DOM mid-drag, or another element calls setPointerCapture), pointerup may never fire. The tracker listens for lostpointercapture as a safety net to ensure onEnd is always called.

Touch-action: The constructor sets touch-action: none on the target to prevent mobile browsers from interpreting pointer events as scroll or zoom gestures. The original value is saved and restored on destroy().

Cleanup: All event listeners use the same AbortController signal. destroy() calls abort() once, removing everything in a single operation.

Edge Cases Handled

| Scenario | Behavior | |----------|----------| | Right-click / secondary button | Ignored (button !== 0 check) | | Second finger while first is active | Ignored (isActive guard) | | Button released outside window (macOS) | Detected via buttons bitmask on move | | Element removed from DOM mid-drag | lostpointercapture fires onEnd | | Another element steals pointer capture | lostpointercapture fires onEnd | | destroy() called twice | No-op (idempotent) | | destroy() called mid-drag | isActive set to false, listeners removed |

TypeScript

Full type definitions included:

import { PointerTracker, type PointerTrackerHandlers } from 'lite-pointer-tracker';

const handlers: PointerTrackerHandlers = {
    onStart(e) { console.log(e.pressure); },
    onMove(e) { console.log(e.tiltX); },
    onEnd() { console.log('done'); },
};

const tracker = new PointerTracker(myCanvas, handlers);

License

MIT