es6-easing
Version:
Robert Penner's easing equations as an ES6 module
241 lines (236 loc) • 9.42 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.easeInQuadOutExpo = exports.easeInQuadOutQuint = exports.easeTo = exports.easeFrom = exports.easeFromTo = exports.bouncePast = exports.bounce = exports.swingTo = exports.swingFrom = exports.swingFromTo = exports.elastic = exports.easeInOutBack = exports.easeOutBack = exports.easeInBack = exports.easeOutBounce = exports.easeInOutCirc = exports.easeOutCirc = exports.easeInCirc = exports.easeInOutExpo = exports.easeOutExpo = exports.easeInExpo = exports.easeInOutSine = exports.easeOutSine = exports.easeInSine = exports.easeInOutQuint = exports.easeOutQuint = exports.easeInQuint = exports.easeInOutQuart = exports.easeOutQuart = exports.easeInQuart = exports.easeInOutCubic = exports.easeOutCubic = exports.easeInCubic = exports.easeInOutQuad = exports.easeOutQuad = exports.easeInQuad = void 0;
var easingFunctions = {
easeInQuad: function easeInQuad(pos) {
return Math.pow(pos, 2);
},
easeOutQuad: function easeOutQuad(pos) {
return -(Math.pow(pos - 1, 2) - 1);
},
easeInOutQuad: function easeInOutQuad(pos) {
if ((pos /= 0.5) < 1) return 0.5 * Math.pow(pos, 2);
return -0.5 * ((pos -= 2) * pos - 2);
},
easeInCubic: function easeInCubic(pos) {
return Math.pow(pos, 3);
},
easeOutCubic: function easeOutCubic(pos) {
return Math.pow(pos - 1, 3) + 1;
},
easeInOutCubic: function easeInOutCubic(pos) {
if ((pos /= 0.5) < 1) return 0.5 * Math.pow(pos, 3);
return 0.5 * (Math.pow(pos - 2, 3) + 2);
},
easeInQuart: function easeInQuart(pos) {
return Math.pow(pos, 4);
},
easeOutQuart: function easeOutQuart(pos) {
return -(Math.pow(pos - 1, 4) - 1);
},
easeInOutQuart: function easeInOutQuart(pos) {
if ((pos /= 0.5) < 1) return 0.5 * Math.pow(pos, 4);
return -0.5 * ((pos -= 2) * Math.pow(pos, 3) - 2);
},
easeInQuint: function easeInQuint(pos) {
return Math.pow(pos, 5);
},
easeOutQuint: function easeOutQuint(pos) {
return Math.pow(pos - 1, 5) + 1;
},
easeInOutQuint: function easeInOutQuint(pos) {
if ((pos /= 0.5) < 1) return 0.5 * Math.pow(pos, 5);
return 0.5 * (Math.pow(pos - 2, 5) + 2);
},
easeInSine: function easeInSine(pos) {
return -Math.cos(pos * (Math.PI / 2)) + 1;
},
easeOutSine: function easeOutSine(pos) {
return Math.sin(pos * (Math.PI / 2));
},
easeInOutSine: function easeInOutSine(pos) {
return -0.5 * (Math.cos(Math.PI * pos) - 1);
},
easeInExpo: function easeInExpo(pos) {
return pos === 0 ? 0 : Math.pow(2, 10 * (pos - 1));
},
easeOutExpo: function easeOutExpo(pos) {
return pos === 1 ? 1 : -Math.pow(2, -10 * pos) + 1;
},
easeInOutExpo: function easeInOutExpo(pos) {
if (pos === 0) return 0;
if (pos === 1) return 1;
if ((pos /= 0.5) < 1) return 0.5 * Math.pow(2, 10 * (pos - 1));
return 0.5 * (-Math.pow(2, -10 * --pos) + 2);
},
easeInCirc: function easeInCirc(pos) {
return -(Math.sqrt(1 - pos * pos) - 1);
},
easeOutCirc: function easeOutCirc(pos) {
return Math.sqrt(1 - Math.pow(pos - 1, 2));
},
easeInOutCirc: function easeInOutCirc(pos) {
if ((pos /= 0.5) < 1) return -0.5 * (Math.sqrt(1 - pos * pos) - 1);
return 0.5 * (Math.sqrt(1 - (pos -= 2) * pos) + 1);
},
easeOutBounce: function easeOutBounce(pos) {
if (pos < 1 / 2.75) {
return 7.5625 * pos * pos;
} else if (pos < 2 / 2.75) {
return 7.5625 * (pos -= 1.5 / 2.75) * pos + 0.75;
} else if (pos < 2.5 / 2.75) {
return 7.5625 * (pos -= 2.25 / 2.75) * pos + 0.9375;
} else {
return 7.5625 * (pos -= 2.625 / 2.75) * pos + 0.984375;
}
},
easeInBack: function easeInBack(pos) {
var s = 1.70158;
return pos * pos * ((s + 1) * pos - s);
},
easeOutBack: function easeOutBack(pos) {
var s = 1.70158;
return (pos = pos - 1) * pos * ((s + 1) * pos + s) + 1;
},
easeInOutBack: function easeInOutBack(pos) {
var s = 1.70158;
if ((pos /= 0.5) < 1) return 0.5 * (pos * pos * (((s *= 1.525) + 1) * pos - s));
return 0.5 * ((pos -= 2) * pos * (((s *= 1.525) + 1) * pos + s) + 2);
},
elastic: function elastic(pos) {
return -1 * Math.pow(4, -8 * pos) * Math.sin((pos * 6 - 1) * (2 * Math.PI) / 2) + 1;
},
swingFromTo: function swingFromTo(pos) {
var s = 1.70158;
return (pos /= 0.5) < 1 ? 0.5 * (pos * pos * (((s *= 1.525) + 1) * pos - s)) : 0.5 * ((pos -= 2) * pos * (((s *= 1.525) + 1) * pos + s) + 2);
},
swingFrom: function swingFrom(pos) {
var s = 1.70158;
return pos * pos * ((s + 1) * pos - s);
},
swingTo: function swingTo(pos) {
var s = 1.70158;
return (pos -= 1) * pos * ((s + 1) * pos + s) + 1;
},
bounce: function bounce(pos) {
if (pos < 1 / 2.75) {
return 7.5625 * pos * pos;
} else if (pos < 2 / 2.75) {
return 7.5625 * (pos -= 1.5 / 2.75) * pos + 0.75;
} else if (pos < 2.5 / 2.75) {
return 7.5625 * (pos -= 2.25 / 2.75) * pos + 0.9375;
} else {
return 7.5625 * (pos -= 2.625 / 2.75) * pos + 0.984375;
}
},
bouncePast: function bouncePast(pos) {
if (pos < 1 / 2.75) {
return 7.5625 * pos * pos;
} else if (pos < 2 / 2.75) {
return 2 - (7.5625 * (pos -= 1.5 / 2.75) * pos + 0.75);
} else if (pos < 2.5 / 2.75) {
return 2 - (7.5625 * (pos -= 2.25 / 2.75) * pos + 0.9375);
} else {
return 2 - (7.5625 * (pos -= 2.625 / 2.75) * pos + 0.984375);
}
},
easeFromTo: function easeFromTo(pos) {
if ((pos /= 0.5) < 1) return 0.5 * Math.pow(pos, 4);
return -0.5 * ((pos -= 2) * Math.pow(pos, 3) - 2);
},
easeFrom: function easeFrom(pos) {
return Math.pow(pos, 4);
},
easeTo: function easeTo(pos) {
return Math.pow(pos, 0.25);
},
easeInQuadOutQuint: function easeInQuadOutQuint(pos) {
// InOutQuad
if ((pos /= 0.5) < 1) return 0.5 * Math.pow(pos, 2); // return -0.5 * ( ( pos -= 2 ) * pos - 2 );
// InOutQuint
// if ( ( pos /= 0.5 ) < 1 ) return 0.5 * Math.pow( pos,5 );
return 0.5 * (Math.pow(pos - 2, 5) + 2);
},
easeInQuadOutExpo: function easeInQuadOutExpo(pos) {
if (pos === 0) return 0;
if (pos === 1) return 1; // InOutQuad
if ((pos /= 0.5) < 1) return 0.5 * Math.pow(pos, 2); // return -0.5 * ( ( pos -= 2 ) * pos - 2 );
// InOutExpo
// if( ( pos /= 0.5 ) < 1 ) return 0.5 * Math.pow( 2,10 * ( pos - 1 ) );
return 0.5 * (-Math.pow(2, -10 * --pos) + 2);
}
};
var easeInQuad = easingFunctions.easeInQuad,
easeOutQuad = easingFunctions.easeOutQuad,
easeInOutQuad = easingFunctions.easeInOutQuad,
easeInCubic = easingFunctions.easeInCubic,
easeOutCubic = easingFunctions.easeOutCubic,
easeInOutCubic = easingFunctions.easeInOutCubic,
easeInQuart = easingFunctions.easeInQuart,
easeOutQuart = easingFunctions.easeOutQuart,
easeInOutQuart = easingFunctions.easeInOutQuart,
easeInQuint = easingFunctions.easeInQuint,
easeOutQuint = easingFunctions.easeOutQuint,
easeInOutQuint = easingFunctions.easeInOutQuint,
easeInSine = easingFunctions.easeInSine,
easeOutSine = easingFunctions.easeOutSine,
easeInOutSine = easingFunctions.easeInOutSine,
easeInExpo = easingFunctions.easeInExpo,
easeOutExpo = easingFunctions.easeOutExpo,
easeInOutExpo = easingFunctions.easeInOutExpo,
easeInCirc = easingFunctions.easeInCirc,
easeOutCirc = easingFunctions.easeOutCirc,
easeInOutCirc = easingFunctions.easeInOutCirc,
easeOutBounce = easingFunctions.easeOutBounce,
easeInBack = easingFunctions.easeInBack,
easeOutBack = easingFunctions.easeOutBack,
easeInOutBack = easingFunctions.easeInOutBack,
elastic = easingFunctions.elastic,
swingFromTo = easingFunctions.swingFromTo,
swingFrom = easingFunctions.swingFrom,
swingTo = easingFunctions.swingTo,
bounce = easingFunctions.bounce,
bouncePast = easingFunctions.bouncePast,
easeFromTo = easingFunctions.easeFromTo,
easeFrom = easingFunctions.easeFrom,
easeTo = easingFunctions.easeTo,
easeInQuadOutQuint = easingFunctions.easeInQuadOutQuint,
easeInQuadOutExpo = easingFunctions.easeInQuadOutExpo;
exports.easeInQuadOutExpo = easeInQuadOutExpo;
exports.easeInQuadOutQuint = easeInQuadOutQuint;
exports.easeTo = easeTo;
exports.easeFrom = easeFrom;
exports.easeFromTo = easeFromTo;
exports.bouncePast = bouncePast;
exports.bounce = bounce;
exports.swingTo = swingTo;
exports.swingFrom = swingFrom;
exports.swingFromTo = swingFromTo;
exports.elastic = elastic;
exports.easeInOutBack = easeInOutBack;
exports.easeOutBack = easeOutBack;
exports.easeInBack = easeInBack;
exports.easeOutBounce = easeOutBounce;
exports.easeInOutCirc = easeInOutCirc;
exports.easeOutCirc = easeOutCirc;
exports.easeInCirc = easeInCirc;
exports.easeInOutExpo = easeInOutExpo;
exports.easeOutExpo = easeOutExpo;
exports.easeInExpo = easeInExpo;
exports.easeInOutSine = easeInOutSine;
exports.easeOutSine = easeOutSine;
exports.easeInSine = easeInSine;
exports.easeInOutQuint = easeInOutQuint;
exports.easeOutQuint = easeOutQuint;
exports.easeInQuint = easeInQuint;
exports.easeInOutQuart = easeInOutQuart;
exports.easeOutQuart = easeOutQuart;
exports.easeInQuart = easeInQuart;
exports.easeInOutCubic = easeInOutCubic;
exports.easeOutCubic = easeOutCubic;
exports.easeInCubic = easeInCubic;
exports.easeInOutQuad = easeInOutQuad;
exports.easeOutQuad = easeOutQuad;
exports.easeInQuad = easeInQuad;