[6a3a178] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
---|
| 4 | value: true
|
---|
| 5 | });
|
---|
| 6 | exports.default = normalizeBoxShadow;
|
---|
| 7 |
|
---|
| 8 | var _postcssValueParser = require("postcss-value-parser");
|
---|
| 9 |
|
---|
| 10 | var _cssnanoUtils = require("cssnano-utils");
|
---|
| 11 |
|
---|
| 12 | var _addSpace = _interopRequireDefault(require("../lib/addSpace"));
|
---|
| 13 |
|
---|
| 14 | var _getValue = _interopRequireDefault(require("../lib/getValue"));
|
---|
| 15 |
|
---|
| 16 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
| 17 |
|
---|
| 18 | // box-shadow: inset? && <length>{2,4} && <color>?
|
---|
| 19 | function normalizeBoxShadow(parsed) {
|
---|
| 20 | let args = (0, _cssnanoUtils.getArguments)(parsed);
|
---|
| 21 | let abort = false;
|
---|
| 22 | let values = args.reduce((list, arg) => {
|
---|
| 23 | let val = [];
|
---|
| 24 | let state = {
|
---|
| 25 | inset: [],
|
---|
| 26 | color: []
|
---|
| 27 | };
|
---|
| 28 | arg.forEach(node => {
|
---|
| 29 | const {
|
---|
| 30 | type,
|
---|
| 31 | value
|
---|
| 32 | } = node;
|
---|
| 33 |
|
---|
| 34 | if (type === 'function' && ~value.toLowerCase().indexOf('calc')) {
|
---|
| 35 | abort = true;
|
---|
| 36 | return;
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | if (type === 'space') {
|
---|
| 40 | return;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | if ((0, _postcssValueParser.unit)(value)) {
|
---|
| 44 | val = [...val, node, (0, _addSpace.default)()];
|
---|
| 45 | } else if (value.toLowerCase() === 'inset') {
|
---|
| 46 | state.inset = [...state.inset, node, (0, _addSpace.default)()];
|
---|
| 47 | } else {
|
---|
| 48 | state.color = [...state.color, node, (0, _addSpace.default)()];
|
---|
| 49 | }
|
---|
| 50 | });
|
---|
| 51 | return [...list, [...state.inset, ...val, ...state.color]];
|
---|
| 52 | }, []);
|
---|
| 53 |
|
---|
| 54 | if (abort) {
|
---|
| 55 | return parsed.toString();
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | return (0, _getValue.default)(values);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | module.exports = exports.default; |
---|