motion
Version:
The Motion library for the web
38 lines (33 loc) • 1.12 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var getFunction = require('../targets/js/easing/get-function.cjs.js');
function stagger(duration = 0.1, { start = 0, from = 0, easing } = {}) {
return (i, total) => {
const fromIndex = typeof from === "number" ? from : getFromIndex(from, total);
const distance = Math.abs(fromIndex - i);
let delay = duration * distance;
if (easing) {
const maxDelay = total * i;
const easingFunction = getFunction.getEasingFunction(easing);
delay = easingFunction(delay / maxDelay) * maxDelay;
}
return start + delay;
};
}
function getFromIndex(from, total) {
if (from === "first") {
return 0;
}
else {
const lastIndex = total - 1;
return from === "last" ? lastIndex : lastIndex / 2;
}
}
function resolveOption(option, i, total) {
return typeof option === "function"
? option(i, total)
: option;
}
exports.getFromIndex = getFromIndex;
exports.resolveOption = resolveOption;
exports.stagger = stagger;