boxShadow.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = normalizeBoxShadow;
  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. // box-shadow: inset? && <length>{2,4} && <color>?
  15. function normalizeBoxShadow(parsed) {
  16. let args = (0, _cssnanoUtilGetArguments2.default)(parsed);
  17. let abort = false;
  18. let values = args.reduce((list, arg) => {
  19. let val = [];
  20. let state = {
  21. inset: [],
  22. color: []
  23. };
  24. arg.forEach(node => {
  25. const { type, value } = node;
  26. if (type === 'function' && ~value.toLowerCase().indexOf('calc')) {
  27. abort = true;
  28. return;
  29. }
  30. if (type === 'space') {
  31. return;
  32. }
  33. if ((0, _postcssValueParser.unit)(value)) {
  34. val = [...val, node, (0, _addSpace2.default)()];
  35. } else if (value.toLowerCase() === 'inset') {
  36. state.inset = [...state.inset, node, (0, _addSpace2.default)()];
  37. } else {
  38. state.color = [...state.color, node, (0, _addSpace2.default)()];
  39. }
  40. });
  41. return [...list, [...state.inset, ...val, ...state.color]];
  42. }, []);
  43. if (abort) {
  44. return parsed.toString();
  45. }
  46. return (0, _getValue2.default)(values);
  47. }
  48. module.exports = exports['default'];