UNPKG

@smoovy/tween

Version:
111 lines (110 loc) 3.29 kB
"use strict"; export const linear = (x) => { return x; }; export const easeInSine = (x) => { return 1 + Math.sin(Math.PI / 2 * x - Math.PI / 2); }; export const easeOutSine = (x) => { return Math.sin(Math.PI / 2 * x); }; export const easeInOutSine = (x) => { return (1 + Math.sin(Math.PI * x - Math.PI / 2)) / 2; }; export const easeInQuad = (x) => { return x * x; }; export const easeOutQuad = (x) => { return x * (2 - x); }; export const easeInOutQuad = (x) => { return x < 0.5 ? 2 * x * x : -1 + (4 - 2 * x) * x; }; export const easeInCubic = (x) => { return x * x * x; }; export const easeOutCubic = (x) => { return --x * x * x + 1; }; export const easeInOutCubic = (x) => { return x < 0.5 ? 4 * x * x * x : (x - 1) * (2 * x - 2) * (2 * x - 2) + 1; }; export const easeInQuart = (x) => { return x * x * x * x; }; export const easeOutQuart = (x) => { return 1 - --x * x * x * x; }; export const easeInOutQuart = (x) => { return x < 0.5 ? 8 * x * x * x * x : 1 - 8 * --x * x * x * x; }; export const easeInQuint = (x) => { return x * x * x * x * x; }; export const easeOutQuint = (x) => { return 1 + --x * x * x * x * x; }; export const easeInOutQuint = (x) => { return x < 0.5 ? 16 * x * x * x * x * x : 1 + 16 * --x * x * x * x * x; }; export const easeInExpo = (x) => { return x === 0 ? 0 : Math.pow(2, 10 * x - 10); }; export const easeOutExpo = (x) => { return x === 1 ? 1 : 1 - Math.pow(2, -10 * x); }; export const easeInOutExpo = (x) => { return x === 0 ? 0 : x === 1 ? 1 : x < 0.5 ? Math.pow(2, 20 * x - 10) / 2 : (2 - Math.pow(2, -20 * x + 10)) / 2; }; export const easeInCirc = (x) => { return 1 - Math.sqrt(1 - Math.pow(x, 2)); }; export const easeOutCirc = (x) => { return Math.sqrt(1 - Math.pow(x - 1, 2)); }; export const easeInOutCirc = (x) => { return x < 0.5 ? (1 - Math.sqrt(1 - Math.pow(2 * x, 2))) / 2 : (Math.sqrt(1 - Math.pow(-2 * x + 2, 2)) + 1) / 2; }; export const easeInBack = (x) => { const c1 = 1.70158; const c3 = c1 + 1; return c3 * x * x * x - c1 * x * x; }; export const easeOutBack = (x) => { const c1 = 1.70158; const c3 = c1 + 1; return 1 + c3 * Math.pow(x - 1, 3) + c1 * Math.pow(x - 1, 2); }; export const easeInOutBack = (x) => { const c1 = 1.70158; const c2 = c1 * 1.525; return x < 0.5 ? Math.pow(2 * x, 2) * ((c2 + 1) * 2 * x - c2) / 2 : (Math.pow(2 * x - 2, 2) * ((c2 + 1) * (x * 2 - 2) + c2) + 2) / 2; }; export const easeInElastic = (x) => { return (0.04 - 0.04 / x) * Math.sin(25 * x) + 1; }; export const easeOutElastic = (x) => { return 0.04 * x / --x * Math.sin(25 * x); }; export const easeInOutElastic = (x) => { return (x -= 0.5) < 0 ? (0.02 + 0.01 / x) * Math.sin(50 * x) : (0.02 - 0.01 / x) * Math.sin(50 * x) + 1; }; export const easeInBounce = (x) => { return 1 - easeOutBounce(1 - x); }; export const easeOutBounce = (x) => { const n1 = 7.5625; const d1 = 2.75; if (x < 1 / d1) { return n1 * x * x; } else if (x < 2 / d1) { return n1 * (x -= 1.5 / d1) * x + 0.75; } else if (x < 2.5 / d1) { return n1 * (x -= 2.25 / d1) * x + 0.9375; } else { return n1 * (x -= 2.625 / d1) * x + 0.984375; } }; export const easeInOutBounce = (x) => { return x < 0.5 ? (1 - easeOutBounce(1 - 2 * x)) / 2 : (1 + easeOutBounce(2 * x - 1)) / 2; };