source: trip-planner-front/node_modules/postcss-selector-not/dist/index.js@ 59329aa

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

initial commit

  • Property mode set to 100644
File size: 2.2 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _postcss = require("postcss");
8
9var _postcss2 = _interopRequireDefault(_postcss);
10
11var _list = require("postcss/lib/list");
12
13var _list2 = _interopRequireDefault(_list);
14
15var _balancedMatch = require("balanced-match");
16
17var _balancedMatch2 = _interopRequireDefault(_balancedMatch);
18
19function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
21function explodeSelector(pseudoClass, selector) {
22 var position = locatePseudoClass(selector, pseudoClass);
23 if (selector && position > -1) {
24 var pre = selector.slice(0, position);
25 var matches = (0, _balancedMatch2.default)("(", ")", selector.slice(position));
26
27 if (!matches) {
28 return selector;
29 }
30
31 var bodySelectors = matches.body ? _list2.default.comma(matches.body).map(function (s) {
32 return explodeSelector(pseudoClass, s);
33 }).join(`)${pseudoClass}(`) : "";
34 var postSelectors = matches.post ? explodeSelector(pseudoClass, matches.post) : "";
35
36 return `${pre}${pseudoClass}(${bodySelectors})${postSelectors}`;
37 }
38 return selector;
39}
40
41var patternCache = {};
42
43function locatePseudoClass(selector, pseudoClass) {
44 patternCache[pseudoClass] = patternCache[pseudoClass] || new RegExp(`([^\\\\]|^)${pseudoClass}`);
45
46 // The regex is used to ensure that selectors with
47 // escaped colons in them are treated properly
48 // Ex: .foo\:not-bar is a valid CSS selector
49 // But it is not a reference to a pseudo selector
50 var pattern = patternCache[pseudoClass];
51 var position = selector.search(pattern);
52
53 if (position === -1) {
54 return -1;
55 }
56
57 // The offset returned by the regex may be off by one because
58 // of it including the negated character match in the position
59 return position + selector.slice(position).indexOf(pseudoClass);
60}
61
62function explodeSelectors(pseudoClass) {
63 return function () {
64 return function (css) {
65 css.walkRules(function (rule) {
66 if (rule.selector && rule.selector.indexOf(pseudoClass) > -1) {
67 rule.selector = explodeSelector(pseudoClass, rule.selector);
68 }
69 });
70 };
71 };
72}
73
74exports.default = _postcss2.default.plugin("postcss-selector-not", explodeSelectors(":not"));
75module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.