//#region src/types.d.ts interface Point { x: number; y: number; } interface Size { width: number; height: number; } type Axis = "horizontal" | "vertical"; type Direction = Axis | "all"; type PointerMode = "all" | "touch" | "mouse"; type ScrollMode = "transform" | "native" | "none"; type ReducedMotion = "auto" | "always" | "never"; /** * Where `scrollIntoView()` puts the element: `'nearest'` scrolls the least to show it, `'start'`, `'center'` and * `'end'` align it with the start, center or end of viewport. Start is the right side in a right-to-left viewport. */ type ScrollAlign = "nearest" | "start" | "center" | "end"; interface BorderCollision { left: boolean; right: boolean; top: boolean; bottom: boolean; } interface ScrollBoosterState { isMoving: boolean; isDragging: boolean; /** * Scroll position from the start edges, from 0 to `maxPosition`. In a right-to-left viewport `x` is the distance * from the right edge and grows to the left, like negative `scrollLeft`. */ position: Point; /** Pointer offset of the current press on screen, `x` grows to the right */ dragOffset: Point; dragAngle: number; /** Sides of viewport that content touches */ borderCollision: BorderCollision; /** Client size of viewport, without borders and scrollbars */ viewport: Size; /** Size of content, including its overflow */ content: Size; /** Largest `position` on each axis, 0 when content fits viewport */ maxPosition: Point; } interface ScrollBoosterOptions { /** Container element (required) */ viewport: HTMLElement; /** Scrollable content element, first viewport child by default */ content?: HTMLElement; /** Scroll direction */ direction?: Direction; /** * A drag or a wheel gesture moves content only along the axis it starts along, like native scroll on iOS. * Matters with `direction: 'all'`: a table scrolls along a row or a column without drifting across. */ axisLock?: boolean; /** Mouse or touch support, pen counts as mouse. Touch drag sets CSS `touch-action` on viewport */ pointerMode?: PointerMode; /** How content is scrolled: CSS transform, native scroll of viewport, or `'none'` to render in `onUpdate` */ scrollMode?: ScrollMode; /** Bounce effect */ bounce?: boolean; /** Bounce effect factor, per 60 Hz frame */ bounceForce?: number; /** Scroll friction factor, per 60 Hz frame: the same motion on any refresh rate */ friction?: number; /** * Text can be selected with a pointer: a mouse or pen press on text selects it instead of dragging, a long touch * press selects a word and a swipe drags. When off, pointers do not select text, keyboard selection still works. */ textSelection?: boolean; /** * Presses on form controls, `summary`, media with controls and editable content, including their descendants, * focus or use them instead of dragging */ inputsFocus?: boolean; /** * Mouse wheel and trackpad scroll content. The page scrolls instead when content cannot move along the * main axis of the gesture. `'horizontal'` scrolls only along x and turns vertical deltas into it, so a mouse * wheel scrolls a horizontal strip: down goes to the end of the line. */ wheel?: boolean | "horizontal"; /** * Reduced motion: no inertia and bounce, `scrollTo` jumps to the target. * `'auto'` follows `prefers-reduced-motion` media query */ reducedMotion?: ReducedMotion; /** * Arrow keys, Page Up, Page Down, Space, Home and End scroll content when the viewport or an element in it has * focus. A key goes to the page when content cannot move along its axis */ keyboard?: boolean; /** Press that starts dragging, after `shouldDrag` allowed it */ onPointerDown?: (state: ScrollBoosterState, event: PointerEvent) => void; /** Drag pointer released or cancelled */ onPointerUp?: (state: ScrollBoosterState, event: PointerEvent) => void; /** Drag pointer moved */ onPointerMove?: (state: ScrollBoosterState, event: PointerEvent) => void; /** Click on viewport, `event.defaultPrevented` is `true` for the click that ends a drag */ onClick?: (state: ScrollBoosterState, event: MouseEvent) => void; /** State update handler */ onUpdate?: (state: ScrollBoosterState) => void; /** Wheel event that scrolls content, called before the content moves */ onWheel?: (state: ScrollBoosterState, event: WheelEvent) => void; /** * Where content stops after a drag or a wheel gesture, for carousels and paging. Receives the position where * inertia would stop within edges and returns the position to scroll to, a missing coordinate goes to its rest * position. Returning nothing keeps the inertia. */ snap?: (rest: Point, state: ScrollBoosterState) => Partial | undefined; /** Decides on `pointerdown` whether the press starts dragging. Wheel is switched with the `wheel` option */ shouldDrag?: (state: ScrollBoosterState, event: PointerEvent) => boolean; } //#endregion //#region src/scroll-booster.d.ts export declare class ScrollBooster { #private; /** * Create ScrollBooster instance. Throws TypeError for invalid options. */ constructor(options: ScrollBoosterOptions); /** * Update options with given values. Throws TypeError for invalid options and keeps the current ones. */ updateOptions(options: Partial): void; /** * Update DOM container elements metrics (width and height) */ updateMetrics(): void; /** * Smoothly scroll to the position within edges. Does nothing while the user drags content */ scrollTo(position?: Partial): void; /** * Smoothly scroll by the offset from the target of a running scroll or from the current position, so repeated * calls add up. Does nothing while the user drags content */ scrollBy(offset?: Partial): void; /** * Smoothly scroll to show an element of the content, aligned by `align`. Unlike the native * `element.scrollIntoView()` it works in every scroll mode and follows `reducedMotion`. Does nothing while the * user drags content. Throws TypeError for an element outside the content. */ scrollIntoView(element: Element, { align }?: { align?: ScrollAlign; }): void; /** * Jump to the position within edges, stops any motion */ setPosition(position?: Partial): void; /** * Get latest metrics and coordinates */ getState(): ScrollBoosterState; /** * Stop animation, remove DOM listeners and observers, remove the translation from content. * Methods of destroyed instance do nothing. */ destroy(): void; } //#endregion export type { Axis, BorderCollision, Direction, Point, PointerMode, ReducedMotion, ScrollAlign, ScrollBoosterOptions, ScrollBoosterState, ScrollMode, Size }; //# sourceMappingURL=index.d.ts.map