css-has-pseudo 6.0.2 → 6.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/CHANGELOG.md +6 -7
- package/README.md +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changes to CSS Has Pseudo
|
|
2
2
|
|
|
3
|
+
### 6.0.3
|
|
4
|
+
|
|
5
|
+
_March 31, 2024_
|
|
6
|
+
|
|
7
|
+
- Updated [`@csstools/selector-specificity`](https://github.com/csstools/postcss-plugins/tree/main/packages/selector-specificity) to [`3.0.3`](https://github.com/csstools/postcss-plugins/tree/main/packages/selector-specificity/CHANGELOG.md#303) (patch)
|
|
8
|
+
|
|
3
9
|
### 6.0.2
|
|
4
10
|
|
|
5
11
|
_February 19, 2024_
|
|
@@ -13,11 +19,4 @@ _December 15, 2023_
|
|
|
13
19
|
- Fix type definitions
|
|
14
20
|
- Updated [`@csstools/selector-specificity`](https://github.com/csstools/postcss-plugins/tree/main/packages/selector-specificity) to [`3.0.1`](https://github.com/csstools/postcss-plugins/tree/main/packages/selector-specificity/CHANGELOG.md#301) (patch)
|
|
15
21
|
|
|
16
|
-
### 6.0.0
|
|
17
|
-
|
|
18
|
-
_July 3, 2023_
|
|
19
|
-
|
|
20
|
-
- Change license to `MIT-0` ([read more about this change in the blog post](https://preset-env.cssdb.org/blog/license-change/))
|
|
21
|
-
- Updated [`@csstools/selector-specificity`](https://github.com/csstools/postcss-plugins/tree/main/packages/selector-specificity) to [`3.0.0`](https://github.com/csstools/postcss-plugins/tree/main/packages/selector-specificity/CHANGELOG.md#300) (major)
|
|
22
|
-
|
|
23
22
|
[Full CHANGELOG](https://github.com/csstools/postcss-plugins/tree/main/plugins/css-has-pseudo/CHANGELOG.md)
|
package/README.md
CHANGED
|
@@ -166,12 +166,12 @@ or
|
|
|
166
166
|
|
|
167
167
|
```html
|
|
168
168
|
<!-- When using a CDN url you will have to manually update the version number -->
|
|
169
|
-
<script src="https://unpkg.com/css-has-pseudo@6.0.
|
|
169
|
+
<script src="https://unpkg.com/css-has-pseudo@6.0.3/dist/browser-global.js"></script>
|
|
170
170
|
<script>cssHasPseudo(document)</script>
|
|
171
171
|
```
|
|
172
172
|
|
|
173
173
|
> [!TIP]
|
|
174
|
-
> Please use a versioned url, like this : `https://unpkg.com/css-has-pseudo@6.0.
|
|
174
|
+
> Please use a versioned url, like this : `https://unpkg.com/css-has-pseudo@6.0.3/dist/browser-global.js`
|
|
175
175
|
> Without the version, you might unexpectedly get a new major version of the library with breaking changes.
|
|
176
176
|
|
|
177
177
|
[PostCSS Has Pseudo] works in all major browsers, including
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("postcss-selector-parser"),t=require("postcss-value-parser"),s=require("@csstools/selector-specificity");function encodeCSS(e){if(""===e)return"";let t,s="";for(let r=0;r<e.length;r++)t=e.charCodeAt(r).toString(36),s+=0===r?t:"-"+t;return"csstools-has-"+s}function isGuardedByAtSupportsFromAtRuleParams(e){if(!e.toLowerCase().includes(":has("))return!1;let s=!1;try{const r=new Set;t(e).walk((e=>{if("function"===e.type&&"selector"===e.value.toLowerCase())return r.add(t.stringify(e.nodes)),!1})),r.forEach((e=>{selectorContainsHasPseudo(e)&&(s=!0)}))}catch(e){}return s}function selectorContainsHasPseudo(t){if(!t.toLowerCase().includes(":has("))return!1;let s=!1;try{e().astSync(t).walk((e=>{if("pseudo"===e.type&&":has"===e.value.toLowerCase()&&e.nodes&&e.nodes.length>0)return s=!0,!1}))}catch(e){}return s}const creator=t=>{const r={preserve:!0,specificityMatchingName:"does-not-exist",...t||{}},o=":not(#"+r.specificityMatchingName+")",n=":not(."+r.specificityMatchingName+")",a=":not("+r.specificityMatchingName+")";return{postcssPlugin:"css-has-pseudo",prepare(){const t=new WeakSet;return{RuleExit
|
|
1
|
+
"use strict";var e=require("postcss-selector-parser"),t=require("postcss-value-parser"),s=require("@csstools/selector-specificity");function encodeCSS(e){if(""===e)return"";let t,s="";for(let r=0;r<e.length;r++)t=e.charCodeAt(r).toString(36),s+=0===r?t:"-"+t;return"csstools-has-"+s}function isGuardedByAtSupportsFromAtRuleParams(e){if(!e.toLowerCase().includes(":has("))return!1;let s=!1;try{const r=new Set;t(e).walk((e=>{if("function"===e.type&&"selector"===e.value.toLowerCase())return r.add(t.stringify(e.nodes)),!1})),r.forEach((e=>{selectorContainsHasPseudo(e)&&(s=!0)}))}catch(e){}return s}function selectorContainsHasPseudo(t){if(!t.toLowerCase().includes(":has("))return!1;let s=!1;try{e().astSync(t).walk((e=>{if("pseudo"===e.type&&":has"===e.value.toLowerCase()&&e.nodes&&e.nodes.length>0)return s=!0,!1}))}catch(e){}return s}const creator=t=>{const r={preserve:!0,specificityMatchingName:"does-not-exist",...t||{}},o=":not(#"+r.specificityMatchingName+")",n=":not(."+r.specificityMatchingName+")",a=":not("+r.specificityMatchingName+")";return{postcssPlugin:"css-has-pseudo",prepare(){const t=new WeakSet;return{postcssPlugin:"css-has-pseudo",RuleExit(c,{result:i}){if(t.has(c))return;if(!c.selector.toLowerCase().includes(":has(")||isWithinSupportCheck(c))return;const l=c.selectors.map((t=>{if(!t.toLowerCase().includes(":has("))return t;let l;try{l=e().astSync(t)}catch(e){return c.warn(i,`Failed to parse selector : "${t}" with message: "${e instanceof Error?e.message:e}"`),t}if(void 0===l)return t;l.walkPseudos((t=>{let s=t.parent,o=!1;for(;s;)e.isPseudoClass(s)&&":has"===s.value.toLowerCase()&&(o=!0),s=s.parent;o&&(":visited"===t.value.toLowerCase()&&t.replaceWith(e.className({value:r.specificityMatchingName})),":any-link"===t.value.toLowerCase()&&(t.value=":link"))})),l.walkPseudos((t=>{if(":has"!==t.value.toLowerCase()||!t.nodes)return;const r=t.parent;if(!r)return;const c=e.selector({value:"",nodes:[]});{let t=r.nodes.length;e:for(let s=0;s<r.nodes.length;s++){const o=r.nodes[s];if(e.isPseudoElement(o))for(let e=s-1;e>=0;e--)if("combinator"!==r.nodes[s].type&&"comment"!==r.nodes[s].type){t=e+1;break e}}r.nodes.slice(0,t).forEach((e=>{e.remove(),"selector"===e.type?e.nodes.forEach((e=>{delete e.parent,c.append(e)})):(delete e.parent,c.append(e))}))}const i="["+encodeCSS(c.toString())+"]",l=s.selectorSpecificity(c);let u=i;for(let e=0;e<l.a;e++)u+=o;const p=Math.max(1,l.b)-1;for(let e=0;e<p;e++)u+=n;for(let e=0;e<l.c;e++)u+=a;const d=e().astSync(u).nodes[0].nodes;for(let e=d.length-1;e>=0;e--)r.prepend(d[e])}));const u=l.toString();return u!==t?".js-has-pseudo "+u:t}));l.join(",")!==c.selectors.join(",")&&(t.add(c),c.cloneBefore({selectors:l}),r.preserve||c.remove())}}}}};function isWithinSupportCheck(e){let t=e.parent;for(;t;){if("atrule"===t.type&&isGuardedByAtSupportsFromAtRuleParams(t.params))return!0;t=t.parent}return!1}creator.postcss=!0,module.exports=creator;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"postcss-selector-parser";import t from"postcss-value-parser";import{selectorSpecificity as s}from"@csstools/selector-specificity";function encodeCSS(e){if(""===e)return"";let t,s="";for(let o=0;o<e.length;o++)t=e.charCodeAt(o).toString(36),s+=0===o?t:"-"+t;return"csstools-has-"+s}function isGuardedByAtSupportsFromAtRuleParams(e){if(!e.toLowerCase().includes(":has("))return!1;let s=!1;try{const o=new Set;t(e).walk((e=>{if("function"===e.type&&"selector"===e.value.toLowerCase())return o.add(t.stringify(e.nodes)),!1})),o.forEach((e=>{selectorContainsHasPseudo(e)&&(s=!0)}))}catch(e){}return s}function selectorContainsHasPseudo(t){if(!t.toLowerCase().includes(":has("))return!1;let s=!1;try{e().astSync(t).walk((e=>{if("pseudo"===e.type&&":has"===e.value.toLowerCase()&&e.nodes&&e.nodes.length>0)return s=!0,!1}))}catch(e){}return s}const creator=t=>{const o={preserve:!0,specificityMatchingName:"does-not-exist",...t||{}},r=":not(#"+o.specificityMatchingName+")",n=":not(."+o.specificityMatchingName+")",a=":not("+o.specificityMatchingName+")";return{postcssPlugin:"css-has-pseudo",prepare(){const t=new WeakSet;return{RuleExit
|
|
1
|
+
import e from"postcss-selector-parser";import t from"postcss-value-parser";import{selectorSpecificity as s}from"@csstools/selector-specificity";function encodeCSS(e){if(""===e)return"";let t,s="";for(let o=0;o<e.length;o++)t=e.charCodeAt(o).toString(36),s+=0===o?t:"-"+t;return"csstools-has-"+s}function isGuardedByAtSupportsFromAtRuleParams(e){if(!e.toLowerCase().includes(":has("))return!1;let s=!1;try{const o=new Set;t(e).walk((e=>{if("function"===e.type&&"selector"===e.value.toLowerCase())return o.add(t.stringify(e.nodes)),!1})),o.forEach((e=>{selectorContainsHasPseudo(e)&&(s=!0)}))}catch(e){}return s}function selectorContainsHasPseudo(t){if(!t.toLowerCase().includes(":has("))return!1;let s=!1;try{e().astSync(t).walk((e=>{if("pseudo"===e.type&&":has"===e.value.toLowerCase()&&e.nodes&&e.nodes.length>0)return s=!0,!1}))}catch(e){}return s}const creator=t=>{const o={preserve:!0,specificityMatchingName:"does-not-exist",...t||{}},r=":not(#"+o.specificityMatchingName+")",n=":not(."+o.specificityMatchingName+")",a=":not("+o.specificityMatchingName+")";return{postcssPlugin:"css-has-pseudo",prepare(){const t=new WeakSet;return{postcssPlugin:"css-has-pseudo",RuleExit(c,{result:i}){if(t.has(c))return;if(!c.selector.toLowerCase().includes(":has(")||isWithinSupportCheck(c))return;const l=c.selectors.map((t=>{if(!t.toLowerCase().includes(":has("))return t;let l;try{l=e().astSync(t)}catch(e){return c.warn(i,`Failed to parse selector : "${t}" with message: "${e instanceof Error?e.message:e}"`),t}if(void 0===l)return t;l.walkPseudos((t=>{let s=t.parent,r=!1;for(;s;)e.isPseudoClass(s)&&":has"===s.value.toLowerCase()&&(r=!0),s=s.parent;r&&(":visited"===t.value.toLowerCase()&&t.replaceWith(e.className({value:o.specificityMatchingName})),":any-link"===t.value.toLowerCase()&&(t.value=":link"))})),l.walkPseudos((t=>{if(":has"!==t.value.toLowerCase()||!t.nodes)return;const o=t.parent;if(!o)return;const c=e.selector({value:"",nodes:[]});{let t=o.nodes.length;e:for(let s=0;s<o.nodes.length;s++){const r=o.nodes[s];if(e.isPseudoElement(r))for(let e=s-1;e>=0;e--)if("combinator"!==o.nodes[s].type&&"comment"!==o.nodes[s].type){t=e+1;break e}}o.nodes.slice(0,t).forEach((e=>{e.remove(),"selector"===e.type?e.nodes.forEach((e=>{delete e.parent,c.append(e)})):(delete e.parent,c.append(e))}))}const i="["+encodeCSS(c.toString())+"]",l=s(c);let u=i;for(let e=0;e<l.a;e++)u+=r;const p=Math.max(1,l.b)-1;for(let e=0;e<p;e++)u+=n;for(let e=0;e<l.c;e++)u+=a;const d=e().astSync(u).nodes[0].nodes;for(let e=d.length-1;e>=0;e--)o.prepend(d[e])}));const u=l.toString();return u!==t?".js-has-pseudo "+u:t}));l.join(",")!==c.selectors.join(",")&&(t.add(c),c.cloneBefore({selectors:l}),o.preserve||c.remove())}}}}};function isWithinSupportCheck(e){let t=e.parent;for(;t;){if("atrule"===t.type&&isGuardedByAtSupportsFromAtRuleParams(t.params))return!0;t=t.parent}return!1}creator.postcss=!0;export{creator as default};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-has-pseudo",
|
|
3
3
|
"description": "Style elements relative to other elements in CSS",
|
|
4
|
-
"version": "6.0.
|
|
4
|
+
"version": "6.0.3",
|
|
5
5
|
"contributors": [
|
|
6
6
|
{
|
|
7
7
|
"name": "Antonio Laguna",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"dist"
|
|
61
61
|
],
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@csstools/selector-specificity": "^3.0.
|
|
63
|
+
"@csstools/selector-specificity": "^3.0.3",
|
|
64
64
|
"postcss-selector-parser": "^6.0.13",
|
|
65
65
|
"postcss-value-parser": "^4.2.0"
|
|
66
66
|
},
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/css-has-pseudo#readme",
|
|
71
71
|
"repository": {
|
|
72
72
|
"type": "git",
|
|
73
|
-
"url": "https://github.com/csstools/postcss-plugins.git",
|
|
73
|
+
"url": "git+https://github.com/csstools/postcss-plugins.git",
|
|
74
74
|
"directory": "plugins/css-has-pseudo"
|
|
75
75
|
},
|
|
76
76
|
"bugs": "https://github.com/csstools/postcss-plugins/issues",
|