motion
Version:
The Motion library for the web
31 lines (28 loc) • 1.2 kB
JavaScript
import { progress, mix } from 'popmotion';
import { noopReturn } from '../../../utils/noop.es.js';
import { getEasingForSegment } from './get-easing.es.js';
import { defaultOffset, fillOffset } from './offset.es.js';
const clampProgress = (p) => Math.min(1, Math.max(p, 0));
function slowInterpolateNumbers(output, input = defaultOffset(output.length), easing = 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 && fillOffset(input, remainder);
return (t) => {
let i = 0;
for (; i < length - 2; i++) {
if (t < input[i + 1])
break;
}
let progressInRange = clampProgress(progress(input[i], input[i + 1], t));
const segmentEasing = getEasingForSegment(easing, i);
progressInRange = segmentEasing(progressInRange);
return mix(output[i], output[i + 1], progressInRange);
};
}
export { slowInterpolateNumbers };