You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
5.5 KiB

4 months ago
import EventEmitter from '@antv/event-emitter';
import { IPointerEvent } from '../types';
/**
* <zh/>
*
* <en/> Represents the coordinates of a pointer position
*/
export interface PointerPoint {
x: number;
y: number;
pointerId: number;
}
/**
* <zh/>
*
* <en/> Pinch event parameters
* @remarks
* <zh/>
*
* <en/> Contains parameters related to pinch gestures, currently supports scale factor,
* can be extended with center coordinates, rotation angle etc. in the future
*/
export interface PinchEventOptions {
/**
* <zh/> >1 <1 表示缩小
*
* <en/> Scaling factor, >1 indicates zoom in, <1 indicates zoom out
*/
scale: number;
}
/**
* <zh/>
* <en/> Pinch gesture phase type
* @remarks
* <zh/>
* - start: 手势开始
* - move: 手势移动中
* - end: 手势结束
*
* <en/> Contains three gesture phases:
* - pinchstart: Gesture started
* - pinchmove: Gesture in progress
* - pinchend: Gesture ended
*/
export type PinchEvent = 'pinchstart' | 'pinchmove' | 'pinchend';
/**
* <zh/>
*
* <en/> Pinch gesture callback function type
* @param event - <zh/> | <en/> Original pointer event object
* @param options - <zh/> | <en/> Pinch event parameters object
*/
export type PinchCallback = (event: IPointerEvent, options: PinchEventOptions) => void;
/**
* <zh/>
*
* <en/> Pinch gesture handler
* @remarks
* <zh/>
*
* <en/> Handles two-finger touch events, calculates zoom ratio and triggers callbacks. Tracks position changes of two touch points to determine zoom ratio based on distance variation.
*/
export declare class PinchHandler {
private phase;
/**
* <zh/> Pinch
*
* <en/> Whether it is in the Pinch stage
*/
static isPinching: boolean;
/**
* <zh/>
*
* <en/> Currently tracked touch points collection
*/
private pointerByTouch;
/**
* <zh/>
*
* <en/> Initial distance between two points
*/
private initialDistance;
private emitter;
private static instance;
private static callbacks;
constructor(emitter: EventEmitter, phase: PinchEvent, callback: PinchCallback);
private bindEvents;
/**
* <zh/>
*
* <en/> Update position of specified pointer
* @param pointerId - <zh/> | <en/> Pointer unique identifier<sup>1</sup>
* @param x - <zh/> X坐标 | <en/> New X coordinate
* @param y - <zh/> Y坐标 | <en/> New Y coordinate
*/
private updatePointerPosition;
/**
* <zh/>
*
* <en/> Handle pointer down event
* @param event - <zh/> | <en/> Pointer event object
* @remarks
* <zh/>
*
* <en/> Record initial distance when detecting two touch points
*/
onPointerDown(event: IPointerEvent): void;
/**
* <zh/>
*
* <en/> Handle pointer move event
* @param event - <zh/> | <en/> Pointer event object
* @remarks
* <zh/>
*
* <en/> Calculate zoom ratio when two valid touch points exist
*/
onPointerMove(event: IPointerEvent): void;
/**
* <zh/>
*
* <en/> Handle pointer up event
* @param event
* @remarks
* <zh/>
*
* <en/> Reset touch state and initial distance
*/
onPointerUp(event: IPointerEvent): void;
/**
* <zh/>
*
* <en/> Destroy pinch gesture listeners
* @remarks
* <zh/>
*
* <en/> Remove listeners for pointer down, move, and up events
*/
destroy(): void;
/**
* <zh/>
* <en/> Unregister gesture callback for specific phase
* @param phase - <zh/> (pinchstart)/(pinchmove)/(pinchend) | <en/> Gesture phase: start/move/end
* @param callback - <zh/> | <en/> Callback function to unregister
* @remarks
* <zh/>
* <en/> Remove specific callback from the phase's callback list, auto-destroy event listeners when all callbacks are unregistered
*/
off(phase: PinchEvent, callback: PinchCallback): void;
/**
* <zh/>
* <en/> Attempt to destroy the gesture handler
* @remarks
* <zh/> //
* <en/> Perform actual destruction when all phase (pinchstart/pinchmove/pinchend) callback lists are empty
* <zh/>
* <en/> Automatically remove event listeners and reset singleton instance
*/
private tryDestroy;
}