@thi.ng/ramp
Version:
Extensible keyframe interpolation/tweening of arbitrary, nested types
23 lines (22 loc) • 511 B
JavaScript
const nested = (children) => {
const pairs = Object.entries(children);
const $minmax = (op) => (acc, x) => pairs.reduce((acc2, [id, impl]) => {
acc2[id] = impl[op](acc2[id], x[id]);
return acc2;
}, acc || {});
return {
min: $minmax("min"),
max: $minmax("max"),
at: (stops, index, t) => pairs.reduce((acc, [id, impl]) => {
acc[id] = impl.at(
stops.map((x) => [x[0], x[1][id]]),
index,
t
);
return acc;
}, {})
};
};
export {
nested
};