map.mjs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { isBezierDefinition } from 'motion-dom';
  2. import { invariant, noop } from 'motion-utils';
  3. import { anticipate } from '../anticipate.mjs';
  4. import { backIn, backInOut, backOut } from '../back.mjs';
  5. import { circIn, circInOut, circOut } from '../circ.mjs';
  6. import { cubicBezier } from '../cubic-bezier.mjs';
  7. import { easeIn, easeInOut, easeOut } from '../ease.mjs';
  8. const easingLookup = {
  9. linear: noop,
  10. easeIn,
  11. easeInOut,
  12. easeOut,
  13. circIn,
  14. circInOut,
  15. circOut,
  16. backIn,
  17. backInOut,
  18. backOut,
  19. anticipate,
  20. };
  21. const easingDefinitionToFunction = (definition) => {
  22. if (isBezierDefinition(definition)) {
  23. // If cubic bezier definition, create bezier curve
  24. invariant(definition.length === 4, `Cubic bezier arrays must contain four numerical values.`);
  25. const [x1, y1, x2, y2] = definition;
  26. return cubicBezier(x1, y1, x2, y2);
  27. }
  28. else if (typeof definition === "string") {
  29. // Else lookup from table
  30. invariant(easingLookup[definition] !== undefined, `Invalid easing type '${definition}'`);
  31. return easingLookup[definition];
  32. }
  33. return definition;
  34. };
  35. export { easingDefinitionToFunction };