react-use-count-up
Version:
A React hook with Typescript typings for animating a number counting up
90 lines (89 loc) • 2.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.easeInPoly = exports.easeOutPoly = exports.easeInQuint = exports.easeOutQuint = exports.easeInQuart = exports.easeOutQuart = exports.easeInCubic = exports.easeOutCubic = exports.easeInQuad = exports.easeOutQuad = exports.easeInExpo = exports.easeOutExpo = exports.linear = void 0;
var linear = function (t, b, c, d) {
return (c * t / d) + b;
};
exports.linear = linear;
var easeOutExpo = function (t, b, c, d) {
return (c * (-Math.pow(2, -10 * t / d) + 1)) + b;
};
exports.easeOutExpo = easeOutExpo;
var easeInExpo = function (t, b, c, d) {
return (c * Math.pow(2, 10 * ((t / d) - 1))) + b;
};
exports.easeInExpo = easeInExpo;
var easeOutQuad = function (t, b, c, d) {
return (-c * (t /= d) * (t - 2)) + b;
};
exports.easeOutQuad = easeOutQuad;
var easeInQuad = function (t, b, c, d) {
t /= d;
return (c * t * t) + b;
};
exports.easeInQuad = easeInQuad;
var easeOutCubic = function (t, b, c, d) {
t /= d;
t--;
return (c * ((t * t * t) + 1)) + b;
};
exports.easeOutCubic = easeOutCubic;
var easeInCubic = function (t, b, c, d) {
t /= d;
return (c * t * t * t) + b;
};
exports.easeInCubic = easeInCubic;
var easeOutQuart = function (t, b, c, d) {
t /= d;
t--;
return (-c * ((t * t * t * t) - 1)) + b;
};
exports.easeOutQuart = easeOutQuart;
var easeInQuart = function (t, b, c, d) {
t /= d;
return (c * t * t * t * t) + b;
};
exports.easeInQuart = easeInQuart;
var easeOutQuint = function (t, b, c, d) {
t /= d;
t--;
return (c * ((t * t * t * t * t) + 1)) + b;
};
exports.easeOutQuint = easeOutQuint;
var easeInQuint = function (t, b, c, d) {
t /= d;
return (c * t * t * t * t * t) + b;
};
exports.easeInQuint = easeInQuint;
var easeOutPoly = function (n) {
if (n <= 1) {
return exports.linear;
} // use the faster implementation
if (n <= 2) {
return exports.easeOutQuad;
} // use the faster implementation
// use the general-purpose function
n = Math.round(n);
var x = n % 2 === 0 ? -1 : 1;
return function (t, b, c, d) {
t /= d;
t--;
return (c * x * ((Math.pow(t, n)) + x)) + b;
};
};
exports.easeOutPoly = easeOutPoly;
var easeInPoly = function (n) {
if (n <= 1) {
return exports.linear;
} // use the faster implementation
if (n <= 2) {
return exports.easeInQuad;
} // use the faster implementation
// use the general-purpose function
n = Math.round(n);
return function (t, b, c, d) {
t /= d;
return (c * (Math.pow(t, n))) + b;
};
};
exports.easeInPoly = easeInPoly;