@studiometa/js-toolkit
Version:
A set of useful little bits of JavaScript to boost your project! 🚀
84 lines (83 loc) • 2.37 kB
TypeScript
import type { EasingFunction } from './math/createEases.js';
export type BezierCurve = [number, number, number, number];
/**
* Controls for a tween.
*/
export interface Tween {
/**
* Start the tween from the beginning.
*/
start: () => void;
/**
* Finish the tween and set its state to the end.
*/
finish: () => void;
/**
* Pause the tween.
*/
pause: () => void;
/**
* Start the tween from the current paused progress.
*/
play: () => void;
/**
* Set and get the tween's progress.
*/
progress: (progress?: number) => number;
}
export interface TweenOptions {
/**
* The duration, in seconds.
* Defaults to `1`.
*/
duration?: number;
/**
* The delay, in seconds.
* Defaults to `0`.
*/
delay?: number;
/**
* The easing function or bezier curve to use.
* Defaults to a linear easing function.
*/
easing?: EasingFunction | BezierCurve;
/**
* The smooth factor. Setting this option to `true` or a `number` will disable the `duration` option.
*/
smooth?: true | number;
/**
* Enable spring transition. Setting this option to `true` or a `number` will disable the `duration` option.
* If `true`, a default stiffness of 0.1 will be used, if a `number` is given, it will be used instead.
*/
spring?: true | number;
/**
* When spring physics are enabled, use the mass option to make the object heavier or lighter. Defaults to `1`.
*/
mass?: number;
/**
* The precision for when to consider the tween finished.
* Defaults to `0.00001`.
*/
precision?: number;
/**
* A callback executed on start.
*/
onStart?: (progress: number) => void;
/**
* A callback executed each time the progress is updated.
*/
onProgress?: (progress: number) => void;
/**
* A callback executed when the tween is finished.
*/
onFinish?: (progress: number) => void;
}
/**
* Normalize a easing function with default fallbacks.
*/
export declare function normalizeEase(ease: EasingFunction | BezierCurve): EasingFunction;
/**
* Tween from 0 to 1.
* @link https://js-toolkit.studiometa.dev/utils/tween.html
*/
export declare function tween(callback: (progress: number) => unknown, options?: TweenOptions): Tween;