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

trackpad-input

v0.1.1

Published

Distinguish trackpad gestures from mouse-wheel input and route two-finger scrolling to pan.

Readme

trackpad-input

Route trackpad panning separately from mouse-wheel and pinch zoom input. trackpad-input is framework-agnostic, has no runtime dependencies, and can connect to any component that exposes a drag or pan operation.

Install

npm install trackpad-input

Usage

import { WheelInputRouter } from 'trackpad-input';

const surface = document.querySelector<HTMLElement>('.surface')!;

const input = new WheelInputRouter<WheelEvent>({
    onPan(event) {
        dragController.moveBy({
            x: -event.deltaX,
            y: -event.deltaY,
        });
    },
    onZoom(event, { device }) {
        zoomController.zoomBy(-event.deltaY, { device });
    },
    onGestureEnd({ mode }) {
        if (mode === 'pan') dragController.end();
    },
});

const handleWheel = (event: WheelEvent) => {
    event.preventDefault();
    input.route(event);
};

surface.addEventListener('wheel', handleWheel, { passive: false });

// Cleanup
surface.removeEventListener('wheel', handleWheel);
input.dispose();

The drag and zoom controllers are application-owned. They can be DOM transforms, canvas viewports, editors, timelines, diagrams, 3D scenes, or any other interface that accepts relative movement.

WheelInputRouter

const input = new WheelInputRouter<WheelEvent>({
    onPan(sample, input) {},
    onZoom(sample, input) {},
    onGestureEnd(input) {},
    decisionTimeout: 40,
    idleTimeout: 120,
});

Options

| Option | Required | Description | | ----------------------- | -------- | -------------------------------------------------------------------------------- | | onPan(sample, input) | Yes | Receives input assigned to drag or pan. | | onZoom(sample, input) | Yes | Receives mouse-wheel or pinch zoom input. | | onGestureEnd(input) | No | Runs when the current input gesture ends. | | decisionTimeout | No | Overrides the decision timeout in milliseconds. Must be less than idleTimeout. | | idleTimeout | No | Overrides the gesture idle timeout in milliseconds. |

Each callback receives a routing result:

interface RoutedWheelInput {
    device: 'mouse' | 'trackpad' | 'unknown';
    mode: 'pan' | 'zoom';
}

The routed sample must match this interface. WheelEvent can be passed directly.

interface WheelGestureSample {
    ctrlKey: boolean;
    deltaMode: number;
    deltaX: number;
    deltaY: number;
    timeStamp?: number;
    wheelDelta?: number;
    wheelDeltaX?: number;
    wheelDeltaY?: number;
}

Methods

route(sample)

Accepts a WheelEvent or another object matching WheelGestureSample.

const decision = input.route(event);
// "pan" | "zoom" | "pending"

The numeric input fields must be finite. Calling route after dispose throws an error.

reset()

Clears the current gesture state while keeping the router reusable.

input.reset();

dispose()

Clears the router and prevents it from routing additional input.

input.dispose();

Classification API

Use the stateless API when callback routing is not needed:

import { classifyWheelInput } from 'trackpad-input';

const result = classifyWheelInput(event);
// {
//   device: "mouse" | "trackpad" | "unknown",
//   mode: "pan" | "zoom" | "pending"
// }

Use WheelGestureClassifier when gesture lifecycle is managed by the host:

import { WheelGestureClassifier } from 'trackpad-input';

const classifier = new WheelGestureClassifier();

classifier.classify(event);
classifier.classifyDetailed(event);
classifier.resolvePendingAsZoom();
classifier.reset();

Exports

import {
    WHEEL_GESTURE_DECISION_MS,
    WHEEL_GESTURE_IDLE_MS,
    WheelGestureClassifier,
    WheelInputRouter,
    classifyWheelInput,
    hasExplicitMouseWheelSignature,
    hasTrackpadPanEvidence,
    inferWheelGestureMode,
} from 'trackpad-input';

The package ships ESM, CommonJS, and TypeScript declarations.

License

MIT