[6a3a178] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
---|
| 4 |
|
---|
| 5 | var parser = _interopDefault(require('postcss-selector-parser'));
|
---|
| 6 | var postcss = _interopDefault(require('postcss'));
|
---|
| 7 |
|
---|
| 8 | const selectorRegExp = /:has/;
|
---|
| 9 | var 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 |
|
---|
| 43 | function checkIfParentIsNot(selector) {
|
---|
| 44 | return Object(Object(selector.parent).parent).type === 'pseudo' && selector.parent.parent.value === ':not';
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | module.exports = postcss$1;
|
---|
| 48 | //# sourceMappingURL=postcss.js.map
|
---|