You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.3 KiB

4 years ago
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = normalizeTransition;
  6. var _postcssValueParser = require('postcss-value-parser');
  7. var _cssnanoUtilGetArguments = require('cssnano-util-get-arguments');
  8. var _cssnanoUtilGetArguments2 = _interopRequireDefault(_cssnanoUtilGetArguments);
  9. var _addSpace = require('../lib/addSpace');
  10. var _addSpace2 = _interopRequireDefault(_addSpace);
  11. var _getValue = require('../lib/getValue');
  12. var _getValue2 = _interopRequireDefault(_getValue);
  13. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14. // transition: [ none | <single-transition-property> ] || <time> || <single-transition-timing-function> || <time>
  15. const timingFunctions = ['ease', 'linear', 'ease-in', 'ease-out', 'ease-in-out', 'step-start', 'step-end'];
  16. function normalizeTransition(parsed) {
  17. let args = (0, _cssnanoUtilGetArguments2.default)(parsed);
  18. let values = args.reduce((list, arg) => {
  19. let state = {
  20. timingFunction: [],
  21. property: [],
  22. time1: [],
  23. time2: []
  24. };
  25. arg.forEach(node => {
  26. const { type, value } = node;
  27. if (type === 'space') {
  28. return;
  29. }
  30. if (type === 'function' && ~['steps', 'cubic-bezier'].indexOf(value.toLowerCase())) {
  31. state.timingFunction = [...state.timingFunction, node, (0, _addSpace2.default)()];
  32. } else if ((0, _postcssValueParser.unit)(value)) {
  33. if (!state.time1.length) {
  34. state.time1 = [...state.time1, node, (0, _addSpace2.default)()];
  35. } else {
  36. state.time2 = [...state.time2, node, (0, _addSpace2.default)()];
  37. }
  38. } else if (~timingFunctions.indexOf(value.toLowerCase())) {
  39. state.timingFunction = [...state.timingFunction, node, (0, _addSpace2.default)()];
  40. } else {
  41. state.property = [...state.property, node, (0, _addSpace2.default)()];
  42. }
  43. });
  44. return [...list, [...state.property, ...state.time1, ...state.timingFunction, ...state.time2]];
  45. }, []);
  46. return (0, _getValue2.default)(values);
  47. }
  48. module.exports = exports['default'];