UNPKG

@studiometa/js-toolkit

Version:

A set of useful little bits of JavaScript to boost your project! 🚀

52 lines (51 loc) • 1.61 kB
export type SmoothToOptions = Partial<{ /** * Damping factor, the smaller the smoother, defaults to 0.6. */ damping: number; /** * Precision used to decide when the smoothing should end, defaults to 1 / 1e8. */ precision: number; /** * Enable spring physics, defaults to `true` if one of `stiffness` or `mass` is set, defaults to `false` otherwise. */ spring: boolean; /** * Stiffness factor for spring physics, the higher the stiffer, defaults to 0.1. */ stiffness: number; /** * Mass factor when spring is enabled, the higher the heavier, defaults to 1. */ mass: number; }>; /** * Create a smoothing function that will smoothly tween between two values. * @param {number} [start] The initial value. * @param {SmoothToOptions} [options] Options for the transition. * @see https://js-toolkit.studiometa.dev/utils/math/smoothTo.html * @example * ```js * const x = smoothTo(0); * x.subscribe((value) => console.log(value)); * x(100); // 0.1 * ``` */ export declare function smoothTo(start?: number, options?: SmoothToOptions): { (newValue?: number): number; /** * Subscribe a callback to the value update. */ subscribe: (fn: (value: number) => any) => () => boolean; /** * Unsubscribe a callback from the value update. */ unsubscribe: (fn: (value: number) => any) => boolean; raw(): number; add(val: number): number; damping(val?: number): number; precision(val?: number): number; stiffness(val?: number): number; spring(val?: boolean): boolean; };