source: trip-planner-front/node_modules/postcss-merge-longhand/dist/lib/decl/boxBase.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.1 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _stylehacks = require("stylehacks");
9
10var _canMerge = _interopRequireDefault(require("../canMerge"));
11
12var _getDecls = _interopRequireDefault(require("../getDecls"));
13
14var _minifyTrbl = _interopRequireDefault(require("../minifyTrbl"));
15
16var _parseTrbl = _interopRequireDefault(require("../parseTrbl"));
17
18var _insertCloned = _interopRequireDefault(require("../insertCloned"));
19
20var _mergeRules = _interopRequireDefault(require("../mergeRules"));
21
22var _mergeValues = _interopRequireDefault(require("../mergeValues"));
23
24var _remove = _interopRequireDefault(require("../remove"));
25
26var _trbl = _interopRequireDefault(require("../trbl"));
27
28var _isCustomProp = _interopRequireDefault(require("../isCustomProp"));
29
30var _canExplode = _interopRequireDefault(require("../canExplode"));
31
32function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
34var _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
93exports.default = _default;
94module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.