/** * PinchGesture - Detects pinch (zoom) movements with two or more pointers * * This gesture tracks when multiple pointers move toward or away from each other, firing events when: * - Two or more pointers begin moving (start) * - The pointers continue changing distance (ongoing) * - One or more pointers are released or lifted (end) * * This gesture is commonly used to implement zoom functionality in touch interfaces. */ import { GestureState } from "../Gesture.mjs"; import { PointerGesture, PointerGestureEventData, PointerGestureOptions } from "../PointerGesture.mjs"; import { PointerData } from "../PointerManager.mjs"; /** * Configuration options for the PinchGesture * Uses the same options as the base PointerGesture */ export type PinchGestureOptions = PointerGestureOptions & { /** * Minimum number of pointers required to activate the gesture. * The gesture will not start until at least this many pointers are active. * * @default 2 */ minPointers?: number; /** * Distance threshold in pixels for gesture activation. * * The gesture will only be recognized once the pointers have moved this many * pixels from their starting positions. Higher values prevent accidental * gesture recognition when the user makes small unintentional movements. * * @default 0 (no threshold) */ threshold?: number; }; /** * Event data specific to pinch gesture events * Contains information about scale, distance, and velocity */ export type PinchGestureEventData = Record> = PointerGestureEventData & { /** Relative scale factor comparing current distance to initial distance (1.0 = no change) */ scale: number; /** Change in scale since the last event */ deltaScale: number; /** Total accumulated scale factor across all pinch operations */ totalScale: number; /** Current distance between pointers in pixels */ distance: number; /** Speed of the pinch movement in pixels per second */ velocity: number; /** Direction of the pinch: 1 for spreading/zooming in, -1 for pinching/zooming out, 0 for no change */ direction: -1 | 0 | 1; }; /** * Type definition for the CustomEvent created by PinchGesture */ export type PinchEvent = Record> = CustomEvent>; /** * State tracking for the PinchGesture */ export type PinchGestureState = GestureState & { /** The initial distance between pointers when the gesture began */ startDistance: number; /** The most recent distance between pointers during the gesture */ lastDistance: number; /** The most recent scale value (ratio of current to initial distance) */ lastScale: number; /** Timestamp of the last pinch event, used for velocity calculation */ lastTime: number; /** Current velocity of the pinch movement in pixels per second */ velocity: number; /** Total accumulated scale factor across all pinch operations */ totalScale: number; /** Change in scale since the last event */ deltaScale: number; }; /** * PinchGesture class for handling pinch/zoom interactions * * This gesture detects when users move multiple pointers toward or away from each other, * and dispatches scale-related events with distance and velocity information. */ export declare class PinchGesture extends PointerGesture { protected state: PinchGestureState; protected readonly isSinglePhase: false; protected readonly eventType: PinchEvent; protected readonly optionsType: PinchGestureOptions; protected readonly mutableOptionsType: Omit; protected readonly mutableStateType: Omit, 'startDistance' | 'lastDistance' | 'lastScale' | 'lastTime' | 'velocity'>; /** * Movement threshold in pixels that must be exceeded before the gesture activates. * Higher values reduce false positive gesture detection for small movements. */ protected threshold: number; constructor(options: PinchGestureOptions); clone(overrides?: Record): PinchGesture; destroy(): void; protected updateOptions(options: typeof this.mutableOptionsType): void; protected resetState(): void; /** * Handle pointer events for the pinch gesture */ protected handlePointerEvent: (pointers: Map, event: PointerEvent) => void; /** * Emit pinch-specific events with additional data */ private emitPinchEvent; }