Skip to content
gesture logoGestureInput
Framework-neutral one-axis pointer pan recognition with lifecycle-owned handles.
Version
v1.0.0
Size
1.0 KB gzip
Dependencies
Zero dependencies
Browser
createPanGesture

Why Gesture?

Pointer-driven interfaces need reliable movement tracking without coupling input recognition to rendering or product-specific thresholds.

ts
// Before
element.addEventListener('pointermove', (event) => {
  // Coordinate tracking, pointer identity, direction locking, and cleanup
});

// After
const pan = createPanGesture(element, {
  axis: 'x',
  onMove: ({ distance }) => render(distance),
  onEnd: ({ distance, reason }) => finish(distance, reason),
});
FeatureAd-hoc pointer handlingGesture
Bundle sizen/a1.0 KB
Zero dependenciesn/a
Axis intent recognitionManualBuilt in
Pointer ownershipManualTracked across the document
Lifecycle cleanupManualdispose() + disposalSignal

Use Gesture when several UI surfaces need consistent one-axis pointer tracking while retaining their own completion rules.

Consider direct pointer handling when the interaction is isolated and does not need reusable lifecycle or direction-lock behavior.

Installation

sh
pnpm add @vielzeug/gesture
sh
npm install @vielzeug/gesture
sh
yarn add @vielzeug/gesture

Quick Start

ts
import { createPanGesture } from '@vielzeug/gesture';

const pan = createPanGesture(element, {
  axis: 'x',
  onMove: ({ distance }) => {
    element.style.transform = `translateX(${distance}px)`;
  },
  onEnd: ({ distance, reason }) => {
    element.style.transform = '';

    if (reason === 'release' && Math.abs(distance) >= 48) {
      dismiss();
    }
  },
});

Features

  • createPanGesture() — one-axis pointer movement tracking
  • Direction locking — activates only when movement favors the configured axis
  • Configurable pointer capture — own the pointer by default or preserve native targeting
  • Consumer-owned policy — thresholds, snapping, and outcomes stay in application code
  • Stable completion — one onEnd callback for release and cancellation
  • Lifecycle ownership — dispose(), disposed, and disposalSignal

Documentation

See Also

  • Refine — components that use pan recognition for carousel, drawer, toast, and list interactions.
  • Dnd — drag-and-drop behavior with drop targets and reordering.
  • Keymap — keyboard interaction primitives for complementary input paths.