UNPKG

@thi.ng/ramp

Version:

Extensible keyframe interpolation/tweening of arbitrary, nested types

29 lines (28 loc) 561 B
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 };