remotion
Version:
Make videos programmatically
53 lines (52 loc) • 1.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.interpolateKeyframedStatus = void 0;
const bezier_js_1 = require("./bezier.js");
const easing_js_1 = require("./easing.js");
const interpolate_colors_js_1 = require("./interpolate-colors.js");
const interpolate_js_1 = require("./interpolate.js");
const easingToFn = (e) => {
if (e === 'linear') {
return easing_js_1.Easing.linear;
}
return (0, bezier_js_1.bezier)(e[0], e[1], e[2], e[3]);
};
const interpolateKeyframedStatus = ({ frame, status, }) => {
const { keyframes, easing, clamping, interpolationFunction } = status;
if (keyframes.length === 0) {
return null;
}
const inputRange = keyframes.map((k) => k.frame);
const outputs = keyframes.map((k) => k.value);
if (interpolationFunction === 'interpolateColors') {
if (!outputs.every((v) => typeof v === 'string')) {
return null;
}
if (keyframes.length === 1) {
return outputs[0];
}
try {
return (0, interpolate_colors_js_1.interpolateColors)(frame, inputRange, outputs, {
posterize: status.posterize,
});
}
catch (_a) {
return null;
}
}
if (interpolationFunction !== 'interpolate') {
return null;
}
try {
return (0, interpolate_js_1.interpolate)(frame, inputRange, outputs, {
easing: easing.map(easingToFn),
extrapolateLeft: clamping.left,
extrapolateRight: clamping.right,
posterize: status.posterize,
});
}
catch (_b) {
return null;
}
};
exports.interpolateKeyframedStatus = interpolateKeyframedStatus;