source: trip-planner-front/node_modules/css-has-pseudo/postcss.mjs@ b738035

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

initial commit

  • Property mode set to 100644
File size: 1.4 KB
RevLine 
[6a3a178]1import parser from 'postcss-selector-parser';
2import postcss from 'postcss';
3
4const selectorRegExp = /:has/;
5var postcss$1 = postcss.plugin('css-has-pseudo', opts => {
6 const preserve = Boolean('preserve' in Object(opts) ? opts.preserve : true);
7 return root => {
8 root.walkRules(selectorRegExp, rule => {
9 const modifiedSelector = parser(selectors => {
10 selectors.walkPseudos(selector => {
11 if (selector.value === ':has' && selector.nodes) {
12 const isNotHas = checkIfParentIsNot(selector);
13 selector.value = isNotHas ? ':not-has' : ':has';
14 const attribute = parser.attribute({
15 attribute: encodeURIComponent(String(selector)).replace(/%3A/g, ':').replace(/%5B/g, '[').replace(/%5D/g, ']').replace(/%2C/g, ',').replace(/[():%\[\],]/g, '\\$&')
16 });
17
18 if (isNotHas) {
19 selector.parent.parent.replaceWith(attribute);
20 } else {
21 selector.replaceWith(attribute);
22 }
23 }
24 });
25 }).processSync(rule.selector);
26 const clone = rule.clone({
27 selector: modifiedSelector
28 });
29
30 if (preserve) {
31 rule.before(clone);
32 } else {
33 rule.replaceWith(clone);
34 }
35 });
36 };
37});
38
39function checkIfParentIsNot(selector) {
40 return Object(Object(selector.parent).parent).type === 'pseudo' && selector.parent.parent.value === ':not';
41}
42
43export default postcss$1;
44//# sourceMappingURL=postcss.mjs.map
Note: See TracBrowser for help on using the repository browser.