source: trip-planner-front/node_modules/css-has-pseudo/postcss.js@ eed0bf8

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

initial commit

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