UNPKG

@tempots/dom

Version:

Fully-typed frontend framework alternative to React and Angular

40 lines (39 loc) 1.38 kB
import { RafLoopHandle } from './raf-loop'; /** * Configuration for inertia scroll behavior. * @public */ export type InertiaConfig = { /** Velocity multiplier per frame (0–1). Default: 0.95. */ readonly friction?: number; /** Minimum velocity in px/s to keep animating. Default: 0.5. */ readonly minVelocity?: number; }; /** * Handle returned by {@link createInertiaHandler}. * @public */ export type InertiaHandler = { /** * Call on each pointer/touch move during drag to track velocity. * @param x - Current pointer X position. * @param y - Current pointer Y position. */ track: (x: number, y: number) => void; /** * Call on pointer up to start the inertia decay animation. * @returns A handle to cancel the inertia animation. */ release: () => RafLoopHandle; }; /** * Creates an inertia handler for pan/scroll interactions. During a drag, * call `track(x, y)` on each pointer move to build up velocity. On release, * call `release()` to start an exponential decay animation. * * @param onDelta - Called with `(dx, dy)` deltas each frame during the decay. * @param config - Optional friction and threshold settings. * @returns An inertia handler. * @public */ export declare function createInertiaHandler(onDelta: (dx: number, dy: number) => void, config?: InertiaConfig): InertiaHandler;