/** * The motion: one position, its velocity and a spring that pulls it to a * target. * * The spring is critically damped and solved exactly for each frame's * duration, so the move looks the same at 30 and at 120 frames per second * and cannot overshoot or explode. * * With an easing curve a move to a slide is not the spring but the curve, * in the time of a move; a drag that is let go is the spring all the same, * as it has a speed to go on with. * * Frames are requested only while something changes. At rest the engine * does nothing at all. */ export interface Motion { /** Position, px. */ pos: number; /** Where the spring pulls to. */ target: number; /** Velocity, px per second. */ vel: number; /** Velocity with the jitter filtered out, for effects. */ smooth: number; /** A pointer holds the position. */ dragging: boolean; } export type Engine = ReturnType; /** * @param win The slider's window. * @param handlers Callbacks. * @param handlers.frame Called on every frame with the motion, * the seconds since the last frame and * the time. * @param handlers.settle Called when the position has arrived. * @param handlers.busy Whether something else needs frames. */ export declare function createEngine(win: Window, { frame, settle, busy, }: { frame: (motion: Motion, dt: number, now: number) => void; settle: (motion: Motion) => void; busy?: () => boolean; }): { motion: Motion; wake: () => void; /** @return {boolean} Nothing moves and no frame is on its way. */ resting: () => boolean; /** * @param ms Time a move takes, in milliseconds. */ duration(ms: number): void; /** * @param to Easing curve of a move, * from 0 to 1 in its time; null for the spring. */ ease(to: ((u: number) => number) | null): void; /** * Moves to a position. * * @param target Position. * @param instant Jump instead of moving. */ to(target: number, instant?: boolean): void; /** * Shifts everything by a distance. The speed of the slider does not * know of it, unless it is a push: so the position is brought back * into the first round of a loop without anyone seeing it. * * @param by Distance. * @param push Whether it counts as speed. */ shift(by: number, push?: boolean): void; /** A pointer takes the position. */ grab(): void; /** * The pointer moved. * * @param pos Position. */ drag(pos: number): void; /** * The pointer let go. * * @param vel Velocity of the pointer, px per second. * @param target Where to come to rest. */ release(vel: number, target: number): void; destroy(): void; };