Skip to content

API Overview

SymbolPurposeExecution modeCommon gotcha
createPanGesture()Track one-axis pointer movement on an elementSynconStart runs after direction intent is recognized
PanGestureLifecycle-owned pan handleSyncdispose() does not emit onEnd
PanGestureOptionsConfigure axis, admission, capture, and callbacksSyncCompletion thresholds belong in onEnd

Package Entry Point

ImportPurpose
@vielzeug/gesturePan recognizer and related types.

Core Functions

createPanGesture()

ts
function createPanGesture(target: Element, options?: PanGestureOptions): PanGesture;

Attaches a one-axis pointer pan recognizer to target.

ParameterTypeDescription
targetElementElement that owns the pointer interaction.
optionsPanGestureOptionsAxis, disabled state, admission guard, capture policy, and lifecycle callbacks.

Returns: A PanGesture handle.

Example

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

const pan = createPanGesture(element, {
  axis: 'x',
  onEnd: ({ distance, reason }) => {
    if (reason === 'release' && Math.abs(distance) >= 48) dismiss();
  },
});
MemberReturnContract
activebooleantrue after direction intent is accepted and before the interaction ends.
cancel()booleanCancels the pending or active pointer interaction. Active pans emit onEnd with reason: 'cancel'.
dispose()voidDetaches listeners, releases pointer ownership, and aborts disposalSignal. Idempotent.
disposedbooleantrue after the first dispose().
disposalSignalAbortSignalAborts when the handle is disposed.
[Symbol.dispose]()voidCalls dispose().

Types

ts
type PanAxis = 'x' | 'y';
type PanEndReason = 'cancel' | 'release';

type PanGestureDetail = {
  axis: PanAxis;
  current: number;
  distance: number;
  event: PointerEvent;
  pointerId: number;
  pointerType: string;
  start: number;
  target: Element;
};

type PanGestureEndDetail = PanGestureDetail & {
  reason: PanEndReason;
};

type PanGestureOptions = {
  axis?: PanAxis | (() => PanAxis);
  disabled?: boolean | (() => boolean | undefined);
  pointerCapture?: boolean;
  onEnd?: (detail: PanGestureEndDetail) => void;
  onMove?: (detail: PanGestureDetail) => void;
  onStart?: (detail: PanGestureDetail) => void;
  shouldStart?: (event: PointerEvent) => boolean;
};

type PanGesture = {
  readonly active: boolean;
  [Symbol.dispose](): void;
  cancel(): boolean;
  readonly disposalSignal: AbortSignal;
  dispose(): void;
  readonly disposed: boolean;
};
OptionTypeDefaultContract
axisPanAxis | (() => PanAxis)'x'Axis resolved when each pointer interaction starts
disabledboolean | (() => boolean | undefined)falseBlocks new pans and cancels an active pan on the next pointer event
pointerCapturebooleantrueCaptures the pointer on target after axis intent is accepted
shouldStart(event: PointerEvent) => booleanRejects a primary pointer start before tracking begins
onStart(detail: PanGestureDetail) => voidRuns once when axis intent is accepted
onMove(detail: PanGestureDetail) => voidRuns for the activating move and later moves
onEnd(detail: PanGestureEndDetail) => voidRuns for active release or cancellation

Gesture tracks an accepted pan with capture-phase listeners on target.ownerDocument regardless of the pointer-capture setting. Set pointerCapture: false when nested or newly revealed controls must retain native pointer-up and click targeting.

Errors

@vielzeug/gesture does not export custom error classes.