source: trip-planner-front/node_modules/postcss-merge-longhand/dist/lib/decl/columns.js@ 6fe77af

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

initial commit

  • Property mode set to 100644
File size: 3.7 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _postcss = require("postcss");
9
10var _postcssValueParser = require("postcss-value-parser");
11
12var _stylehacks = require("stylehacks");
13
14var _canMerge = _interopRequireDefault(require("../canMerge"));
15
16var _getDecls = _interopRequireDefault(require("../getDecls"));
17
18var _getValue = _interopRequireDefault(require("../getValue"));
19
20var _mergeRules = _interopRequireDefault(require("../mergeRules"));
21
22var _insertCloned = _interopRequireDefault(require("../insertCloned"));
23
24var _remove = _interopRequireDefault(require("../remove"));
25
26var _isCustomProp = _interopRequireDefault(require("../isCustomProp"));
27
28var _canExplode = _interopRequireDefault(require("../canExplode"));
29
30function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
32const properties = ['column-width', 'column-count'];
33const auto = 'auto';
34const inherit = 'inherit';
35/**
36 * Normalize a columns shorthand definition. Both of the longhand
37 * properties' initial values are 'auto', and as per the spec,
38 * omitted values are set to their initial values. Thus, we can
39 * remove any 'auto' definition when there are two values.
40 *
41 * Specification link: https://www.w3.org/TR/css3-multicol/
42 */
43
44function normalize(values) {
45 if (values[0].toLowerCase() === auto) {
46 return values[1];
47 }
48
49 if (values[1].toLowerCase() === auto) {
50 return values[0];
51 }
52
53 if (values[0].toLowerCase() === inherit && values[1].toLowerCase() === inherit) {
54 return inherit;
55 }
56
57 return values.join(' ');
58}
59
60function explode(rule) {
61 rule.walkDecls(/^columns$/i, decl => {
62 if (!(0, _canExplode.default)(decl)) {
63 return;
64 }
65
66 if ((0, _stylehacks.detect)(decl)) {
67 return;
68 }
69
70 let values = _postcss.list.space(decl.value);
71
72 if (values.length === 1) {
73 values.push(auto);
74 }
75
76 values.forEach((value, i) => {
77 let prop = properties[1];
78
79 if (value.toLowerCase() === auto) {
80 prop = properties[i];
81 } else if ((0, _postcssValueParser.unit)(value).unit) {
82 prop = properties[0];
83 }
84
85 (0, _insertCloned.default)(decl.parent, decl, {
86 prop,
87 value
88 });
89 });
90 decl.remove();
91 });
92}
93
94function cleanup(rule) {
95 let decls = (0, _getDecls.default)(rule, ['columns'].concat(properties));
96
97 while (decls.length) {
98 const lastNode = decls[decls.length - 1]; // remove properties of lower precedence
99
100 const lesser = decls.filter(node => !(0, _stylehacks.detect)(lastNode) && !(0, _stylehacks.detect)(node) && node !== lastNode && node.important === lastNode.important && lastNode.prop === 'columns' && node.prop !== lastNode.prop);
101 lesser.forEach(_remove.default);
102 decls = decls.filter(node => !~lesser.indexOf(node)); // get duplicate properties
103
104 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)));
105 duplicates.forEach(_remove.default);
106 decls = decls.filter(node => node !== lastNode && !~duplicates.indexOf(node));
107 }
108}
109
110function merge(rule) {
111 (0, _mergeRules.default)(rule, properties, (rules, lastNode) => {
112 if ((0, _canMerge.default)(rules) && !rules.some(_stylehacks.detect)) {
113 (0, _insertCloned.default)(lastNode.parent, lastNode, {
114 prop: 'columns',
115 value: normalize(rules.map(_getValue.default))
116 });
117 rules.forEach(_remove.default);
118 return true;
119 }
120 });
121 cleanup(rule);
122}
123
124var _default = {
125 explode,
126 merge
127};
128exports.default = _default;
129module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.