Gesture Migration
Touch ownership and activation
A second touch now cancels pending or active drag, pan, and long-press recognition rather than leaving the first pointer in control. Exact diagonal pans wait for strict axis dominance. No compatibility mode is provided.
Commit only releases and reset canceled interactions:
// Before: cancellation could commit an action.
createPanGesture(panel, { onEnd: ({ distance }) => commit(distance) });
// After
createPanGesture(panel, {
onEnd: ({ distance, reason }) => {
if (reason === 'release') commit(distance);
else reset();
},
});Move activation rejection out of onStart and into shouldActivate, which runs before capture:
// Before
const pan = createPanGesture(panel, {
onStart: ({ distance }) => {
if (distance < 0) pan.cancel();
},
});
// After
createPanGesture(panel, { shouldActivate: ({ distance }) => distance > 0 });Velocity now includes pointerdown and release coordinates and removes samples older than 90 ms, including sparse samples. Short single-move flicks can therefore produce nonzero velocity. Keep distance-only completion logic when fling behavior is not desired.
Long presses recheck dynamic disabling before firing and no longer swallow keyboard-generated clicks.
26.10
Gesture 26.10 replaces raw RangeError throws with typed errors. createGesture(), createPanGesture(), and createDragGesture() calls with valid options continue to work without changes.
Typed configuration errors
Invalid options now throw GestureConfigError (extending a new GestureError base) instead of RangeError:
// Before
try {
createPanGesture(element, { activationDistance: -5 });
} catch (e) {
if (e instanceof RangeError) {
/* ... */
}
}
// After
import { GestureConfigError } from '@vielzeug/gesture';
try {
createPanGesture(element, { activationDistance: -5 });
} catch (e) {
if (e instanceof GestureConfigError) {
/* ... */
}
}3.0
Existing createPanGesture() calls continue to work without changes.
Use shared two-dimensional dragging
createDragGesture() is the pointer-recognition layer for free movement. It reports readonly { x, y } values for start, current, and delta while leaving previews, hit-testing, DOM mutation, and outcomes to consumers. Dnd touch sorting now builds on this primitive instead of maintaining a separate Touch Event state machine.
const drag = createDragGesture(element, {
onMove: ({ delta }) => render(delta),
onEnd: ({ reason }) => settle(reason),
});Configure recognition slop
Use activationDistance to control movement before direction intent is accepted:
const pan = createPanGesture(element, {
activationDistance: 12,
axis: 'x',
onMove,
onEnd,
});The default remains 6 CSS pixels. Zero activates on the first pointer move with non-zero displacement; zero-motion events remain pending. Completion thresholds still belong in onEnd because they represent product behavior rather than recognition slop.
Compose lifecycle ownership
disposalSignal remains available and aborts when the handle is disposed. The new input signal binds Gesture to an existing owner:
const pan = createPanGesture(element, {
signal: owner.signal,
onEnd,
onMove,
});
const childSignal = AbortSignal.any([pan.disposalSignal, request.signal]);Manual dispose() remains valid. Call cancel() before disposal when a still-connected surface needs the onEnd cancellation reset path.
Pointer behavior
Gesture now:
- falls back to document tracking when pointer capture acquisition or release fails
- accepts pointer events from the target document's realm
- rejects secondary mouse and pen buttons
- cancels active tracking on owner-window blur or hidden-document transition
- resolves the target's owner document when each interaction begins
Options and callback details are now readonly. Fixed callbacks and pointer-capture policy are snapshotted during construction; function-valued axis and disabled options remain dynamic. No callback or result field changed.