@revenuecat/purchases-ui-js
Version:
Web components for Paywalls. Powered by RevenueCat
36 lines (35 loc) • 1.66 kB
TypeScript
import type { VerticalAlignment } from "../../types/alignment";
export declare function mapPageAlignment(alignment: VerticalAlignment): string;
export declare function clamp(value: number, min: number, max: number): number;
/**
* Advance one page when the drag passed this fraction of a page's width,
* matching the iOS SDK carousel. A shorter drag snaps back to the page the
* gesture started on.
*/
export declare const PAGE_ADVANCE_THRESHOLD = 0.2;
/**
* Decides which page a swipe settles on when the pointer is released.
*
* Distance-based (not velocity-based), mirroring the iOS SDK's `handleDragEnd`:
* a drag past `PAGE_ADVANCE_THRESHOLD` of a page's width advances exactly one
* page in the swipe direction regardless of speed; a shorter drag stays put.
* Non-loop carousels clamp at their first and last page; loop carousels may
* return an index just outside `[0, pageCount)` so the caller can animate into
* a clone before normalizing.
*
* @param startPage Page the gesture started on.
* @param dragDistance Signed change in slider translation (negative = finger
* moved left / next page).
* @param pageWidth Width of a single page in px.
* @param pageCount Total number of real pages.
* @param loop Whether the carousel loops.
*/
export declare function getSwipeTargetPage({ startPage, dragDistance, pageWidth, pageCount, loop, advanceThreshold, }: {
startPage: number;
dragDistance: number;
pageWidth: number;
pageCount: number;
loop: boolean;
advanceThreshold?: number;
}): number;
export declare function getTranslation(element: HTMLElement | null): number;