source: trip-planner-front/node_modules/postcss-merge-longhand/dist/lib/mergeRules.js@ fa375fe

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

initial commit

  • Property mode set to 100644
File size: 1.6 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = mergeRules;
7
8var _hasAllProps = _interopRequireDefault(require("./hasAllProps"));
9
10var _getDecls = _interopRequireDefault(require("./getDecls"));
11
12var _getRules = _interopRequireDefault(require("./getRules"));
13
14function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
16function isConflictingProp(propA, propB) {
17 if (!propB.prop || propB.important !== propA.important) {
18 return;
19 }
20
21 const parts = propA.prop.split('-');
22 return parts.some(() => {
23 parts.pop();
24 return parts.join('-') === propB.prop;
25 });
26}
27
28function hasConflicts(match, nodes) {
29 const firstNode = Math.min.apply(null, match.map(n => nodes.indexOf(n)));
30 const lastNode = Math.max.apply(null, match.map(n => nodes.indexOf(n)));
31 const between = nodes.slice(firstNode + 1, lastNode);
32 return match.some(a => between.some(b => isConflictingProp(a, b)));
33}
34
35function mergeRules(rule, properties, callback) {
36 let decls = (0, _getDecls.default)(rule, properties);
37
38 while (decls.length) {
39 const last = decls[decls.length - 1];
40 const props = decls.filter(node => node.important === last.important);
41 const rules = (0, _getRules.default)(props, properties);
42
43 if ((0, _hasAllProps.default)(rules, ...properties) && !hasConflicts(rules, rule.nodes)) {
44 if (callback(rules, last, props)) {
45 decls = decls.filter(node => !~rules.indexOf(node));
46 }
47 }
48
49 decls = decls.filter(node => node !== last);
50 }
51}
52
53module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.