animation.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. "use strict";
  2. exports.__esModule = true;
  3. exports["default"] = animation;
  4. var _errors = _interopRequireDefault(require("../internalHelpers/_errors"));
  5. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  6. /**
  7. * Shorthand for easily setting the animation property. Allows either multiple arrays with animations
  8. * or a single animation spread over the arguments.
  9. * @example
  10. * // Styles as object usage
  11. * const styles = {
  12. * ...animation(['rotate', '1s', 'ease-in-out'], ['colorchange', '2s'])
  13. * }
  14. *
  15. * // styled-components usage
  16. * const div = styled.div`
  17. * ${animation(['rotate', '1s', 'ease-in-out'], ['colorchange', '2s'])}
  18. * `
  19. *
  20. * // CSS as JS Output
  21. *
  22. * div {
  23. * 'animation': 'rotate 1s ease-in-out, colorchange 2s'
  24. * }
  25. * @example
  26. * // Styles as object usage
  27. * const styles = {
  28. * ...animation('rotate', '1s', 'ease-in-out')
  29. * }
  30. *
  31. * // styled-components usage
  32. * const div = styled.div`
  33. * ${animation('rotate', '1s', 'ease-in-out')}
  34. * `
  35. *
  36. * // CSS as JS Output
  37. *
  38. * div {
  39. * 'animation': 'rotate 1s ease-in-out'
  40. * }
  41. */
  42. function animation() {
  43. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  44. args[_key] = arguments[_key];
  45. }
  46. // Allow single or multiple animations passed
  47. var multiMode = Array.isArray(args[0]);
  48. if (!multiMode && args.length > 8) {
  49. throw new _errors["default"](64);
  50. }
  51. var code = args.map(function (arg) {
  52. if (multiMode && !Array.isArray(arg) || !multiMode && Array.isArray(arg)) {
  53. throw new _errors["default"](65);
  54. }
  55. if (Array.isArray(arg) && arg.length > 8) {
  56. throw new _errors["default"](66);
  57. }
  58. return Array.isArray(arg) ? arg.join(' ') : arg;
  59. }).join(', ');
  60. return {
  61. animation: code
  62. };
  63. }
  64. module.exports = exports.default;