css-has-pseudo 2.0.0 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/postcss.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"postcss.js","sources":["src/postcss.js"],"sourcesContent":["import parser from 'postcss-selector-parser'\n\nconst creator = (/** @type {{ preserve: true | false }} */ opts) => {\n\topts = typeof opts === 'object' && opts || defaultOptions\n\n\t/** Whether the original rule should be preserved. */\n\tconst shouldPreserve = Boolean('preserve' in opts ? opts.preserve : true)\n\n\treturn {\n\t\tpostcssPlugin: 'css-has-pseudo',\n\t\tRule: rule => {\n\t\t\tif (rule.selector.includes(':has(')) {\n\t\t\t\tconst fallbackSelector = getFallbackSelector(rule.selector)\n\n\t\t\t\tif (shouldPreserve) rule.cloneBefore({ selector: fallbackSelector })\n\t\t\t\telse rule.assign({ selector: fallbackSelector })\n\t\t\t}\n\t\t},\n\t}\n}\n\ncreator.postcss = true\n\nconst getFallbackSelector = (/** @type {string} */ selectorText) => parser(selectors => {\n\tselectors.walkPseudos(selector => {\n\t\tif (selector.value === ':has' && selector.nodes) {\n\t\t\tconst isNotHas = isParentInNotPseudo(selector)\n\n\t\t\tselector.value = isNotHas ? ':not-has' : ':has'\n\n\t\t\tconst attribute = parser.attribute({\n\t\t\t\tattribute: getEscapedCss(String(selector))\n\t\t\t})\n\n\t\t\tif (isNotHas) {\n\t\t\t\tselector.parent.parent.replaceWith(attribute)\n\t\t\t} else {\n\t\t\t\tselector.replaceWith(attribute)\n\t\t\t}\n\t\t}\n\t})\n}).processSync(selectorText)\n\n/** Default options. */\nconst defaultOptions = { preserve: true }\n\n/** Returns the string as an escaped CSS identifier. */\nconst getEscapedCss = (/** @type {string} */ value) => encodeURIComponent(value).replace(/%3A/g, ':').replace(/%5B/g, '[').replace(/%5D/g, ']').replace(/%2C/g, ',').replace(/[():%[\\],]/g, '\\\\$&')\n\n/** Returns whether the selector is within a `:not` pseudo-class. */\nconst isParentInNotPseudo = (selector) => selector.parent?.parent?.type === 'pseudo' && selector.parent.parent.value === ':not'\n\nexport default creator\n"],"names":["creator","opts","defaultOptions","shouldPreserve","Boolean","preserve","postcssPlugin","Rule","rule","selector","includes","fallbackSelector","getFallbackSelector","cloneBefore","assign","postcss","selectorText","parser","selectors","walkPseudos","value","nodes","isNotHas","isParentInNotPseudo","attribute","getEscapedCss","String","parent","replaceWith","processSync","encodeURIComponent","replace","type"],"mappings":";;;;;;;;MAEMA,OAAO,GAAG;AAAC;AAA0CC,IAA3C,KAAoD;AACnEA,EAAAA,IAAI,GAAG,OAAOA,IAAP,KAAgB,QAAhB,IAA4BA,IAA5B,IAAoCC,cAA3C;AAEA;;AACA,QAAMC,cAAc,GAAGC,OAAO,CAAC,cAAcH,IAAd,GAAqBA,IAAI,CAACI,QAA1B,GAAqC,IAAtC,CAA9B;AAEA,SAAO;AACNC,IAAAA,aAAa,EAAE,gBADT;AAENC,IAAAA,IAAI,EAAEC,IAAI,IAAI;AACb,UAAIA,IAAI,CAACC,QAAL,CAAcC,QAAd,CAAuB,OAAvB,CAAJ,EAAqC;AACpC,cAAMC,gBAAgB,GAAGC,mBAAmB,CAACJ,IAAI,CAACC,QAAN,CAA5C;AAEA,YAAIN,cAAJ,EAAoBK,IAAI,CAACK,WAAL,CAAiB;AAAEJ,UAAAA,QAAQ,EAAEE;AAAZ,SAAjB,EAApB,KACKH,IAAI,CAACM,MAAL,CAAY;AAAEL,UAAAA,QAAQ,EAAEE;AAAZ,SAAZ;AACL;AACD;AATK,GAAP;AAWA;;AAEDX,OAAO,CAACe,OAAR,GAAkB,IAAlB;;AAEA,MAAMH,mBAAmB,GAAG;AAAC;AAAsBI,YAAvB,KAAwCC,0BAAM,CAACC,SAAS,IAAI;AACvFA,EAAAA,SAAS,CAACC,WAAV,CAAsBV,QAAQ,IAAI;AACjC,QAAIA,QAAQ,CAACW,KAAT,KAAmB,MAAnB,IAA6BX,QAAQ,CAACY,KAA1C,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(
4
- /** @type {{ preserve: true | false }} */
5
- opts) => {
6
- opts = typeof opts === 'object' && opts || defaultOptions;
7
- /** Whether the original rule should be preserved. */
8
-
9
- const shouldPreserve = Boolean('preserve' in opts ? opts.preserve : true);
10
- return {
11
- postcssPlugin: 'css-has-pseudo',
12
- Rule: rule => {
13
- if (rule.selector.includes(':has(')) {
14
- const fallbackSelector = getFallbackSelector(rule.selector);
15
- if (shouldPreserve) rule.cloneBefore({
16
- selector: fallbackSelector
17
- });else rule.assign({
18
- selector: fallbackSelector
19
- });
20
- }
21
- }
22
- };
23
- };
24
-
25
- creator.postcss = true;
26
-
27
- const getFallbackSelector = (
28
- /** @type {string} */
29
- selectorText) => parser(selectors => {
30
- selectors.walkPseudos(selector => {
31
- if (selector.value === ':has' && selector.nodes) {
32
- const isNotHas = isParentInNotPseudo(selector);
33
- selector.value = isNotHas ? ':not-has' : ':has';
34
- const attribute = parser.attribute({
35
- attribute: getEscapedCss(String(selector))
36
- });
37
-
38
- if (isNotHas) {
39
- selector.parent.parent.replaceWith(attribute);
40
- } else {
41
- selector.replaceWith(attribute);
42
- }
43
- }
44
- });
45
- }).processSync(selectorText);
46
- /** Default options. */
47
-
48
-
49
- const defaultOptions = {
50
- preserve: true
51
- };
52
- /** Returns the string as an escaped CSS identifier. */
53
-
54
- const getEscapedCss = (
55
- /** @type {string} */
56
- value) => encodeURIComponent(value).replace(/%3A/g, ':').replace(/%5B/g, '[').replace(/%5D/g, ']').replace(/%2C/g, ',').replace(/[():%[\],]/g, '\\$&');
57
- /** Returns whether the selector is within a `:not` pseudo-class. */
58
-
59
-
60
- const isParentInNotPseudo = selector => {
61
- var _selector$parent, _selector$parent$pare;
62
-
63
- return ((_selector$parent = selector.parent) === null || _selector$parent === void 0 ? void 0 : (_selector$parent$pare = _selector$parent.parent) === null || _selector$parent$pare === void 0 ? void 0 : _selector$parent$pare.type) === 'pseudo' && selector.parent.parent.value === ':not';
64
- };
65
-
66
- export { creator as default };
67
- //# sourceMappingURL=postcss.mjs.map
package/postcss.mjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"postcss.mjs","sources":["src/postcss.js"],"sourcesContent":["import parser from 'postcss-selector-parser'\n\nconst creator = (/** @type {{ preserve: true | false }} */ opts) => {\n\topts = typeof opts === 'object' && opts || defaultOptions\n\n\t/** Whether the original rule should be preserved. */\n\tconst shouldPreserve = Boolean('preserve' in opts ? opts.preserve : true)\n\n\treturn {\n\t\tpostcssPlugin: 'css-has-pseudo',\n\t\tRule: rule => {\n\t\t\tif (rule.selector.includes(':has(')) {\n\t\t\t\tconst fallbackSelector = getFallbackSelector(rule.selector)\n\n\t\t\t\tif (shouldPreserve) rule.cloneBefore({ selector: fallbackSelector })\n\t\t\t\telse rule.assign({ selector: fallbackSelector })\n\t\t\t}\n\t\t},\n\t}\n}\n\ncreator.postcss = true\n\nconst getFallbackSelector = (/** @type {string} */ selectorText) => parser(selectors => {\n\tselectors.walkPseudos(selector => {\n\t\tif (selector.value === ':has' && selector.nodes) {\n\t\t\tconst isNotHas = isParentInNotPseudo(selector)\n\n\t\t\tselector.value = isNotHas ? ':not-has' : ':has'\n\n\t\t\tconst attribute = parser.attribute({\n\t\t\t\tattribute: getEscapedCss(String(selector))\n\t\t\t})\n\n\t\t\tif (isNotHas) {\n\t\t\t\tselector.parent.parent.replaceWith(attribute)\n\t\t\t} else {\n\t\t\t\tselector.replaceWith(attribute)\n\t\t\t}\n\t\t}\n\t})\n}).processSync(selectorText)\n\n/** Default options. */\nconst defaultOptions = { preserve: true }\n\n/** Returns the string as an escaped CSS identifier. */\nconst getEscapedCss = (/** @type {string} */ value) => encodeURIComponent(value).replace(/%3A/g, ':').replace(/%5B/g, '[').replace(/%5D/g, ']').replace(/%2C/g, ',').replace(/[():%[\\],]/g, '\\\\$&')\n\n/** Returns whether the selector is within a `:not` pseudo-class. */\nconst isParentInNotPseudo = (selector) => selector.parent?.parent?.type === 'pseudo' && selector.parent.parent.value === ':not'\n\nexport default creator\n"],"names":["creator","opts","defaultOptions","shouldPreserve","Boolean","preserve","postcssPlugin","Rule","rule","selector","includes","fallbackSelector","getFallbackSelector","cloneBefore","assign","postcss","selectorText","parser","selectors","walkPseudos","value","nodes","isNotHas","isParentInNotPseudo","attribute","getEscapedCss","String","parent","replaceWith","processSync","encodeURIComponent","replace","type"],"mappings":";;MAEMA,OAAO,GAAG;AAAC;AAA0CC,IAA3C,KAAoD;AACnEA,EAAAA,IAAI,GAAG,OAAOA,IAAP,KAAgB,QAAhB,IAA4BA,IAA5B,IAAoCC,cAA3C;AAEA;;AACA,QAAMC,cAAc,GAAGC,OAAO,CAAC,cAAcH,IAAd,GAAqBA,IAAI,CAACI,QAA1B,GAAqC,IAAtC,CAA9B;AAEA,SAAO;AACNC,IAAAA,aAAa,EAAE,gBADT;AAENC,IAAAA,IAAI,EAAEC,IAAI,IAAI;AACb,UAAIA,IAAI,CAACC,QAAL,CAAcC,QAAd,CAAuB,OAAvB,CAAJ,EAAqC;AACpC,cAAMC,gBAAgB,GAAGC,mBAAmB,CAACJ,IAAI,CAACC,QAAN,CAA5C;AAEA,YAAIN,cAAJ,EAAoBK,IAAI,CAACK,WAAL,CAAiB;AAAEJ,UAAAA,QAAQ,EAAEE;AAAZ,SAAjB,EAApB,KACKH,IAAI,CAACM,MAAL,CAAY;AAAEL,UAAAA,QAAQ,EAAEE;AAAZ,SAAZ;AACL;AACD;AATK,GAAP;AAWA;;AAEDX,OAAO,CAACe,OAAR,GAAkB,IAAlB;;AAEA,MAAMH,mBAAmB,GAAG;AAAC;AAAsBI,YAAvB,KAAwCC,MAAM,CAACC,SAAS,IAAI;AACvFA,EAAAA,SAAS,CAACC,WAAV,CAAsBV,QAAQ,IAAI;AACjC,QAAIA,QAAQ,CAACW,KAAT,KAAmB,MAAnB,IAA6BX,QAAQ,CAACY,KAA1C,EAAiD;AAChD,YAAMC,QAAQ,GAAGC,mBAAmB,CAACd,QAAD,CAApC;AAEAA,MAAAA,QAAQ,CAACW,KAAT,GAAiB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