addimated
Version:
An always interruptable, declarative animation library for React
157 lines (129 loc) • 2.94 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.step0 = step0;
exports.step1 = step1;
exports.linear = linear;
exports.ease = ease;
exports.quad = quad;
exports.cubic = cubic;
exports.poly = poly;
exports.sin = sin;
exports.circle = circle;
exports.exp = exp;
exports.elastic = elastic;
exports.back = back;
exports.bounce = bounce;
exports.in = _in;
exports.out = out;
exports.inOut = inOut;
Object.defineProperty(exports, "bezier", {
enumerable: true,
get: function get() {
return _bezierEasing.default;
}
});
var _bezierEasing = _interopRequireDefault(require("bezier-easing"));
/**
* This class implements common easing functions. The math is pretty obscure,
* but this cool website has nice visual illustrations of what they represent:
* http://xaedes.de/dev/transitions/
*/
var _ease = (0, _bezierEasing.default)(0.42, 0, 1, 1);
function step0(n) {
return n > 0 ? 1 : 0;
}
function step1(n) {
return n >= 1 ? 1 : 0;
}
function linear(t) {
return t;
}
function ease(t) {
return _ease(t);
}
function quad(t) {
return t * t;
}
function cubic(t) {
return t * t * t;
}
function poly(n) {
return function (t) {
return Math.pow(t, n);
};
}
function sin(t) {
return 1 - Math.cos(t * Math.PI / 2);
}
function circle(t) {
return 1 - Math.sqrt(1 - t * t);
}
function exp(t) {
return Math.pow(2, 10 * (t - 1));
}
/**
* A simple elastic interaction, similar to a spring. Default bounciness
* is 1, which overshoots a little bit once. 0 bounciness doesn't overshoot
* at all, and bounciness of N > 1 will overshoot about N times.
*
* Wolfram Plots:
*
* http://tiny.cc/elastic_b_1 (default bounciness = 1)
* http://tiny.cc/elastic_b_3 (bounciness = 3)
*/
function elastic() {
var bounciness = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
var p = bounciness * Math.PI;
return function (t) {
return 1 - Math.pow(Math.cos(t * Math.PI / 2), 3) * Math.cos(t * p);
};
}
function back(s) {
if (s === undefined) {
s = 1.70158;
}
return function (t) {
return t * t * ((s + 1) * t - s);
};
}
function bounce(t) {
if (t < 1 / 2.75) {
return 7.5625 * t * t;
}
if (t < 2 / 2.75) {
t -= 1.5 / 2.75;
return 7.5625 * t * t + 0.75;
}
if (t < 2.5 / 2.75) {
t -= 2.25 / 2.75;
return 7.5625 * t * t + 0.9375;
}
t -= 2.625 / 2.75;
return 7.5625 * t * t + 0.984375;
}
function _in(easing) {
return easing;
}
/**
* Runs an easing function backwards.
*/
function out(easing) {
return function (t) {
return 1 - easing(1 - t);
};
}
/**
* Makes any easing function symmetrical.
*/
function inOut(easing) {
return function (t) {
if (t < 0.5) {
return easing(t * 2) / 2;
}
return 1 - easing((1 - t) * 2) / 2;
};
}
//# sourceMappingURL=Easing.js.map