motion
Version:
The Motion library for the web
35 lines (30 loc) • 1.31 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var popmotion = require('popmotion');
var noop = require('../../../utils/noop.cjs.js');
var getEasing = require('./get-easing.cjs.js');
var offset = require('./offset.cjs.js');
const clampProgress = (p) => Math.min(1, Math.max(p, 0));
function slowInterpolateNumbers(output, input = offset.defaultOffset(output.length), easing = noop.noopReturn) {
const length = output.length;
/**
* If the input length is lower than the output we
* fill the input to match. This currently assumes the input
* is an animation progress value so is a good candidate for
* moving outside the function.
*/
const remainder = length - input.length;
remainder > 0 && offset.fillOffset(input, remainder);
return (t) => {
let i = 0;
for (; i < length - 2; i++) {
if (t < input[i + 1])
break;
}
let progressInRange = clampProgress(popmotion.progress(input[i], input[i + 1], t));
const segmentEasing = getEasing.getEasingForSegment(easing, i);
progressInRange = segmentEasing(progressInRange);
return popmotion.mix(output[i], output[i + 1], progressInRange);
};
}
exports.slowInterpolateNumbers = slowInterpolateNumbers;