1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = void 0;
|
---|
7 |
|
---|
8 | var _stylehacks = require("stylehacks");
|
---|
9 |
|
---|
10 | var _canMerge = _interopRequireDefault(require("../canMerge"));
|
---|
11 |
|
---|
12 | var _getDecls = _interopRequireDefault(require("../getDecls"));
|
---|
13 |
|
---|
14 | var _minifyTrbl = _interopRequireDefault(require("../minifyTrbl"));
|
---|
15 |
|
---|
16 | var _parseTrbl = _interopRequireDefault(require("../parseTrbl"));
|
---|
17 |
|
---|
18 | var _insertCloned = _interopRequireDefault(require("../insertCloned"));
|
---|
19 |
|
---|
20 | var _mergeRules = _interopRequireDefault(require("../mergeRules"));
|
---|
21 |
|
---|
22 | var _mergeValues = _interopRequireDefault(require("../mergeValues"));
|
---|
23 |
|
---|
24 | var _remove = _interopRequireDefault(require("../remove"));
|
---|
25 |
|
---|
26 | var _trbl = _interopRequireDefault(require("../trbl"));
|
---|
27 |
|
---|
28 | var _isCustomProp = _interopRequireDefault(require("../isCustomProp"));
|
---|
29 |
|
---|
30 | var _canExplode = _interopRequireDefault(require("../canExplode"));
|
---|
31 |
|
---|
32 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
33 |
|
---|
34 | var _default = prop => {
|
---|
35 | const properties = _trbl.default.map(direction => `${prop}-${direction}`);
|
---|
36 |
|
---|
37 | const cleanup = rule => {
|
---|
38 | let decls = (0, _getDecls.default)(rule, [prop].concat(properties));
|
---|
39 |
|
---|
40 | while (decls.length) {
|
---|
41 | const lastNode = decls[decls.length - 1]; // remove properties of lower precedence
|
---|
42 |
|
---|
43 | const lesser = decls.filter(node => !(0, _stylehacks.detect)(lastNode) && !(0, _stylehacks.detect)(node) && node !== lastNode && node.important === lastNode.important && lastNode.prop === prop && node.prop !== lastNode.prop);
|
---|
44 | lesser.forEach(_remove.default);
|
---|
45 | decls = decls.filter(node => !~lesser.indexOf(node)); // get duplicate properties
|
---|
46 |
|
---|
47 | let duplicates = decls.filter(node => !(0, _stylehacks.detect)(lastNode) && !(0, _stylehacks.detect)(node) && node !== lastNode && node.important === lastNode.important && node.prop === lastNode.prop && !(!(0, _isCustomProp.default)(node) && (0, _isCustomProp.default)(lastNode)));
|
---|
48 | duplicates.forEach(_remove.default);
|
---|
49 | decls = decls.filter(node => node !== lastNode && !~duplicates.indexOf(node));
|
---|
50 | }
|
---|
51 | };
|
---|
52 |
|
---|
53 | const processor = {
|
---|
54 | explode: rule => {
|
---|
55 | rule.walkDecls(new RegExp('^' + prop + '$', 'i'), decl => {
|
---|
56 | if (!(0, _canExplode.default)(decl)) {
|
---|
57 | return;
|
---|
58 | }
|
---|
59 |
|
---|
60 | if ((0, _stylehacks.detect)(decl)) {
|
---|
61 | return;
|
---|
62 | }
|
---|
63 |
|
---|
64 | const values = (0, _parseTrbl.default)(decl.value);
|
---|
65 |
|
---|
66 | _trbl.default.forEach((direction, index) => {
|
---|
67 | (0, _insertCloned.default)(decl.parent, decl, {
|
---|
68 | prop: properties[index],
|
---|
69 | value: values[index]
|
---|
70 | });
|
---|
71 | });
|
---|
72 |
|
---|
73 | decl.remove();
|
---|
74 | });
|
---|
75 | },
|
---|
76 | merge: rule => {
|
---|
77 | (0, _mergeRules.default)(rule, properties, (rules, lastNode) => {
|
---|
78 | if ((0, _canMerge.default)(rules) && !rules.some(_stylehacks.detect)) {
|
---|
79 | (0, _insertCloned.default)(lastNode.parent, lastNode, {
|
---|
80 | prop,
|
---|
81 | value: (0, _minifyTrbl.default)((0, _mergeValues.default)(...rules))
|
---|
82 | });
|
---|
83 | rules.forEach(_remove.default);
|
---|
84 | return true;
|
---|
85 | }
|
---|
86 | });
|
---|
87 | cleanup(rule);
|
---|
88 | }
|
---|
89 | };
|
---|
90 | return processor;
|
---|
91 | };
|
---|
92 |
|
---|
93 | exports.default = _default;
|
---|
94 | module.exports = exports.default; |
---|