UNPKG

@dvcol/common-utils

Version:

Typescript library for common utility functions and constants

77 lines (75 loc) 3.51 kB
declare const SwipeDirection: { readonly Up: "up"; readonly Down: "down"; readonly Left: "left"; readonly Right: "right"; }; type SwipeDirections = (typeof SwipeDirection)[keyof typeof SwipeDirection]; type SwipeTolerances = { horizontal?: number; up?: number; down?: number; vertical?: number; left?: number; right?: number; }; type Position = { x: number; y: number; }; type ScrollState = { /** * The start position of the scroll state. */ start?: Position; /** * The end position of the scroll state. */ end?: Position; /** * If true, all swipes are ignored in the scroll state changed along the observed axis. */ ignore?: boolean; }; type TouchState = { start: Touch; end: Touch; }; /** * Detects swipe up or down from touch events * @param touch - The Touch state positions * @param touch.start - The TouchStart event * @param touch.end - The TouchEnd event * @param tolerance - The vertical tolerance for swipe detection * @param tolerance.up - The vertical tolerance for swipe up detection (default: 20, absolute value, sign will be ignored) * @param tolerance.down - The vertical tolerance for swipe down detection (default: 20, absolute value, sign will be ignored) * @param tolerance.horizontal - The vertical horizontal for swipe detection * @param scroll - The state to detect container scroll * @param scroll.start - The start position of the scroll state * @param scroll.end - The end position of the scroll state * @param scroll.ignore - If true, all swipes are ignored in the scroll state changed along the observed axis (default: true) */ declare const handleSwipeUpDown: ({ start, end }: Partial<TouchState>, { horizontal, up, down }?: Pick<SwipeTolerances, 'horizontal' | 'up' | 'down'>, scroll?: ScrollState) => SwipeDirections | undefined; /** * Detects swipe left or right from touch events * @param touch - The Touch state positions * @param touch.start - The TouchStart event * @param touch.end - The TouchEnd event * @param tolerance - The horizontal tolerance for swipe detection * @param tolerance.left - The horizontal tolerance for swipe left detection (default: 20, absolute value, sign will be ignored) * @param tolerance.right - The horizontal tolerance for swipe right detection (default: 20, absolute value, sign will be ignored) * @param tolerance.vertical - The vertical tolerance for swipe detection * @param scroll - The state to detect container scroll * @param scroll.start - The start position of the scroll state * @param scroll.end - The end position of the scroll state * @param scroll.ignore - If true, all swipes are ignored in the scroll state changed along the observed axis (default: true) */ declare const handleSwipeLeftRight: ({ start, end }: Partial<TouchState>, { vertical, left, right }?: Pick<SwipeTolerances, 'vertical' | 'left' | 'right'>, scroll?: ScrollState) => SwipeDirections | undefined; /** * Detects swipe direction from touch events * @param touch - The Touch state positions * @param tolerances - The tolerances for swipe detection * @param scroll - The state to detect container scroll */ declare const handleSwipe: (touch: TouchState, tolerances?: SwipeTolerances, scroll?: ScrollState) => SwipeDirections | undefined; export { type Position, type ScrollState, SwipeDirection, type SwipeDirections, type SwipeTolerances, type TouchState, handleSwipe, handleSwipeLeftRight, handleSwipeUpDown };