|
| 1 | +export type Interpolator = ( |
| 2 | + progress: number, |
| 3 | + easeOut?: number, |
| 4 | + easeIn?: number |
| 5 | +) => number; |
| 6 | + |
| 7 | +export const interpolators: Record<string, Interpolator> = { |
| 8 | + // no easing, no acceleration |
| 9 | + linear: t => t, |
| 10 | + // accelerating from zero velocity |
| 11 | + easeInQuad: t => t * t, |
| 12 | + // decelerating to zero velocity |
| 13 | + easeOutQuad: t => t * (2 - t), |
| 14 | + // acceleration until halfway, then deceleration |
| 15 | + easeInOutQuad: t => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t), |
| 16 | + // accelerating from zero velocity |
| 17 | + easeInCubic: t => t * t * t, |
| 18 | + // decelerating to zero velocity |
| 19 | + easeOutCubic: t => --t * t * t + 1, |
| 20 | + // acceleration until halfway, then deceleration |
| 21 | + easeInOutCubic: t => |
| 22 | + t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1, |
| 23 | + // accelerating from zero velocity |
| 24 | + easeInQuart: t => t * t * t * t, |
| 25 | + // decelerating to zero velocity |
| 26 | + easeOutQuart: t => 1 - --t * t * t * t, |
| 27 | + // acceleration until halfway, then deceleration |
| 28 | + easeInOutQuart: t => (t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t), |
| 29 | + // accelerating from zero velocity |
| 30 | + easeInQuint: t => t * t * t * t * t, |
| 31 | + // decelerating to zero velocity |
| 32 | + easeOutQuint: t => 1 + --t * t * t * t * t, |
| 33 | + // acceleration until halfway, then deceleration |
| 34 | + easeInOutQuint: t => |
| 35 | + t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t, |
| 36 | + easeInElastic: t => (0.04 - 0.04 / t) * Math.sin(25 * t) + 1, |
| 37 | + easeOutElastic: t => ((0.04 * t) / --t) * Math.sin(25 * t), |
| 38 | + easeInOutElastic: t => |
| 39 | + (t -= 0.5) < 0 |
| 40 | + ? (0.02 + 0.01 / t) * Math.sin(50 * t) |
| 41 | + : (0.02 - 0.01 / t) * Math.sin(50 * t) + 1, |
| 42 | +}; |
0 commit comments