@dvcol/svelte-utils
Version:
Svelte library for common utility functions and constants
30 lines (29 loc) • 1.27 kB
TypeScript
import type { SwipeDirections, SwipeTolerances } from '@dvcol/common-utils/common/touch';
import type { TouchEventHandler } from 'svelte/elements';
export type SwipeHooks = {
onSwipe?: (swipe: SwipeDirections) => void;
onTouchStart?: TouchEventHandler<HTMLDivElement> | null;
onTouchEnd?: TouchEventHandler<HTMLDivElement> | null;
};
export type SwipeHandlers = {
ontouchstart: TouchEventHandler<HTMLDivElement>;
ontouchend: TouchEventHandler<HTMLDivElement>;
};
export type SwipeNodeTolerances = {
horizontal?: SwipeTolerances['horizontal'] | `${number}%`;
up?: SwipeTolerances['up'] | `${number}%`;
down?: SwipeTolerances['down'] | `${number}%`;
vertical?: SwipeTolerances['vertical'] | `${number}%`;
left?: SwipeTolerances['left'] | `${number}%`;
right?: SwipeTolerances['right'] | `${number}%`;
container?: Element;
} & Omit<SwipeTolerances, 'horizontal' | 'up' | 'down' | 'vertical' | 'left' | 'right'>;
/**
* Register touch events handler for swipe detection.
* @param onSwipe
* @param onTouchStart
* @param onTouchEnd
* @param tolerances
* @param scroll
*/
export declare const useSwipe: ({ onSwipe, onTouchStart, onTouchEnd }?: SwipeHooks, tolerances?: SwipeNodeTolerances, scroll?: any) => SwipeHandlers;