transform.mjs 728 B

123456789101112131415161718192021
  1. import { interpolate } from './interpolate.mjs';
  2. const isCustomValueType = (v) => {
  3. return v && typeof v === "object" && v.mix;
  4. };
  5. const getMixer = (v) => (isCustomValueType(v) ? v.mix : undefined);
  6. function transform(...args) {
  7. const useImmediate = !Array.isArray(args[0]);
  8. const argOffset = useImmediate ? 0 : -1;
  9. const inputValue = args[0 + argOffset];
  10. const inputRange = args[1 + argOffset];
  11. const outputRange = args[2 + argOffset];
  12. const options = args[3 + argOffset];
  13. const interpolator = interpolate(inputRange, outputRange, {
  14. mixer: getMixer(outputRange[0]),
  15. ...options,
  16. });
  17. return useImmediate ? interpolator(inputValue) : interpolator;
  18. }
  19. export { transform };