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.

66 lines
1.8 KiB

4 years ago
  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'];