css-has-pseudo 6.0.0 → 6.0.1
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 +9 -193
- package/README.md +13 -7
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.mjs +1 -1
- package/package.json +11 -31
- package/dist/is-guarded-by-at-supports.d.ts +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
# Changes to CSS Has Pseudo
|
|
2
2
|
|
|
3
|
+
### 6.0.1
|
|
4
|
+
|
|
5
|
+
_December 15, 2023_
|
|
6
|
+
|
|
7
|
+
- Fix type definitions
|
|
8
|
+
- 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)
|
|
9
|
+
|
|
3
10
|
### 6.0.0
|
|
4
11
|
|
|
5
12
|
_July 3, 2023_
|
|
6
13
|
|
|
7
14
|
- Change license to `MIT-0` ([read more about this change in the blog post](https://preset-env.cssdb.org/blog/license-change/))
|
|
8
|
-
- Updated [`@csstools/selector-specificity`](/packages/selector-specificity) to [`3.0.0`](/packages/selector-specificity/CHANGELOG.md#300) (major)
|
|
15
|
+
- 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)
|
|
9
16
|
|
|
10
17
|
### 5.0.2
|
|
11
18
|
|
|
@@ -13,195 +20,4 @@ _February 6, 2023_
|
|
|
13
20
|
|
|
14
21
|
- Reduce the amount of duplicate fallback CSS.
|
|
15
22
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
_January 28, 2023_
|
|
19
|
-
|
|
20
|
-
- Improve `types` declaration in `package.json`
|
|
21
|
-
|
|
22
|
-
### 5.0.0
|
|
23
|
-
|
|
24
|
-
_January 24, 2023_
|
|
25
|
-
|
|
26
|
-
- Updated: Support for Node v14+ (major).
|
|
27
|
-
- Fix: Do not throw when a selector is invalid, show a warning instead.
|
|
28
|
-
- Fix: make `:has()` unforgiving. `:has(.foo, :some-invalid-selector)` will no longer match elements that have children with `.foo`.
|
|
29
|
-
|
|
30
|
-
### 4.0.2
|
|
31
|
-
|
|
32
|
-
_December 12, 2022_
|
|
33
|
-
|
|
34
|
-
- Fix: correctly cleanup style rules when a browser has native support. [backported](https://github.com/csstools/postcss-plugins/pull/752)
|
|
35
|
-
|
|
36
|
-
### 4.0.1
|
|
37
|
-
|
|
38
|
-
_August 23, 2022_
|
|
39
|
-
|
|
40
|
-
- Fix: assign global browser polyfill to `window`, `self` or a blank object.
|
|
41
|
-
|
|
42
|
-
### 4.0.0
|
|
43
|
-
|
|
44
|
-
_July 8, 2022_
|
|
45
|
-
|
|
46
|
-
[Read the full changelog](https://github.com/csstools/postcss-plugins/wiki/PostCSS-Preset-Env-8)
|
|
47
|
-
|
|
48
|
-
- Breaking: removed old CDN urls
|
|
49
|
-
- Added: 'hover' options for browser polyfill
|
|
50
|
-
- Added: 'observedAttributes' options for browser polyfill
|
|
51
|
-
- Added: 'forcePolyfill' options for browser polyfill
|
|
52
|
-
- Added: Rules within `@supports selector(:has(something))` won't be transformed.
|
|
53
|
-
- Fix: Use base36 encoding to support all possible selectors.
|
|
54
|
-
- Fix: case insensitive matching.
|
|
55
|
-
|
|
56
|
-
#### How to migrate :
|
|
57
|
-
|
|
58
|
-
##### Re-build your CSS with the new version of the library.
|
|
59
|
-
|
|
60
|
-
##### If you use a CDN url, please update it.
|
|
61
|
-
|
|
62
|
-
```diff
|
|
63
|
-
- <script src="https://unpkg.com/css-has-pseudo/browser"></script>
|
|
64
|
-
+ <script src="https://unpkg.com/css-has-pseudo/dist/browser-global.js"></script>
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
```diff
|
|
68
|
-
- <script src="https://unpkg.com/css-has-pseudo/browser.min"></script>
|
|
69
|
-
+ <script src="https://unpkg.com/css-has-pseudo/dist/browser-global.js"></script>
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### 3.0.4
|
|
73
|
-
|
|
74
|
-
_February 5, 2022_
|
|
75
|
-
|
|
76
|
-
- Rebuild of browser polyfills
|
|
77
|
-
|
|
78
|
-
### 3.0.3
|
|
79
|
-
|
|
80
|
-
_January 12, 2022_
|
|
81
|
-
|
|
82
|
-
- Fix compatibility with PostCSS `v8.2.x` [#147](https://github.com/csstools/postcss-plugins/issues/147)
|
|
83
|
-
|
|
84
|
-
This version is not officially supported but some tool providers pinned PostCSS to `v8.2.x`,
|
|
85
|
-
making it impossible for end users to have a working setup.
|
|
86
|
-
|
|
87
|
-
### 3.0.2
|
|
88
|
-
|
|
89
|
-
_January 2, 2022_
|
|
90
|
-
|
|
91
|
-
- Removed Sourcemaps from package tarball.
|
|
92
|
-
- Moved CLI to CLI Package. See [announcement](https://github.com/csstools/postcss-plugins/discussions/121).
|
|
93
|
-
|
|
94
|
-
### 3.0.1
|
|
95
|
-
|
|
96
|
-
_December 27, 2021_
|
|
97
|
-
|
|
98
|
-
- Fixed: require/import paths for browser script
|
|
99
|
-
|
|
100
|
-
### 3.0.0
|
|
101
|
-
|
|
102
|
-
_December 13, 2021_
|
|
103
|
-
|
|
104
|
-
- Breaking: require/import paths have changed
|
|
105
|
-
- Changed: new polyfill CDN urls.
|
|
106
|
-
- Updated: documentation
|
|
107
|
-
|
|
108
|
-
**Migrating to 3.0.0**
|
|
109
|
-
|
|
110
|
-
PostCSS plugin :
|
|
111
|
-
|
|
112
|
-
```diff
|
|
113
|
-
- const postcssHasPseudo = require('css-has-pseudo/postcss');
|
|
114
|
-
+ const postcssHasPseudo = require('css-has-pseudo');
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
Browser Polyfill :
|
|
118
|
-
|
|
119
|
-
```diff
|
|
120
|
-
- const cssHasPseudo = require('css-has-pseudo');
|
|
121
|
-
+ const cssHasPseudo = require('css-has-pseudo/browser');
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
_The old CND url is now deprecated and will be removed in a next major release._
|
|
125
|
-
_It will continue to work for now._
|
|
126
|
-
|
|
127
|
-
```diff
|
|
128
|
-
- <script src="https://unpkg.com/css-has-pseudo/browser"></script>
|
|
129
|
-
+ <script src="https://unpkg.com/css-has-pseudo/dist/browser-global.js"></script>
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### 2.0.0
|
|
133
|
-
|
|
134
|
-
_September 16, 2021_
|
|
135
|
-
|
|
136
|
-
- Updated: Support for PostCS 8+ (major).
|
|
137
|
-
- Updated: Support for Node 12+ (major).
|
|
138
|
-
|
|
139
|
-
### 1.0.0
|
|
140
|
-
|
|
141
|
-
_June 10, 2019_
|
|
142
|
-
|
|
143
|
-
- Updated: `postcss-selector-parser` to 6.0.2 (major)
|
|
144
|
-
- Updated: `postcss` to 7.0.16 (patch)
|
|
145
|
-
- Updated: Node 8+ compatibility (major)
|
|
146
|
-
|
|
147
|
-
### 0.10.0
|
|
148
|
-
|
|
149
|
-
_December 11, 2018_
|
|
150
|
-
|
|
151
|
-
- Fixed an issue where inaccessible rules would crash the library
|
|
152
|
-
|
|
153
|
-
### 0.9.0
|
|
154
|
-
|
|
155
|
-
_November 26, 2018_
|
|
156
|
-
|
|
157
|
-
- Improved CLI usage
|
|
158
|
-
|
|
159
|
-
### 0.8.0
|
|
160
|
-
|
|
161
|
-
_November 26, 2018_
|
|
162
|
-
|
|
163
|
-
- Fixed an issue where attribute names were not being properly encoded
|
|
164
|
-
|
|
165
|
-
### 0.7.0
|
|
166
|
-
|
|
167
|
-
_November 25, 2018_
|
|
168
|
-
|
|
169
|
-
- Replaced `setImmediate` with `requestAnimationFrame` for future compatibility
|
|
170
|
-
|
|
171
|
-
### 0.6.0
|
|
172
|
-
|
|
173
|
-
_November 25, 2018_
|
|
174
|
-
|
|
175
|
-
- Fixed an issue where nested rules were not supported
|
|
176
|
-
|
|
177
|
-
### 0.5.0
|
|
178
|
-
|
|
179
|
-
_November 21, 2018_
|
|
180
|
-
|
|
181
|
-
- Further optimize script; from 775 bytes to 757 bytes
|
|
182
|
-
|
|
183
|
-
### 0.4.0
|
|
184
|
-
|
|
185
|
-
_November 21, 2018_
|
|
186
|
-
|
|
187
|
-
- Fixed an issue with the browser script not picking up added nodes
|
|
188
|
-
|
|
189
|
-
### 0.3.0
|
|
190
|
-
|
|
191
|
-
_November 21, 2018_
|
|
192
|
-
|
|
193
|
-
- Fixed the misnamed function name for the browser-ready script
|
|
194
|
-
|
|
195
|
-
### 0.2.0
|
|
196
|
-
|
|
197
|
-
_November 21, 2018_
|
|
198
|
-
|
|
199
|
-
- Improved browser compatibility with updated parsers, encoders, and decoders
|
|
200
|
-
- Improved performance by walking the DOM less
|
|
201
|
-
- Reduced script size by 9%; from 855 bytes to 775 bytes
|
|
202
|
-
|
|
203
|
-
### 0.1.0
|
|
204
|
-
|
|
205
|
-
_November 20, 2018_
|
|
206
|
-
|
|
207
|
-
- Initial version
|
|
23
|
+
[Full CHANGELOG](https://github.com/csstools/postcss-plugins/tree/main/plugins/css-has-pseudo/CHANGELOG.md)
|
package/README.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
[<img alt="npm version" src="https://img.shields.io/npm/v/css-has-pseudo.svg" height="20">][npm-url] [<img alt="CSS Standard Status" src="https://cssdb.org/images/badges/has-pseudo-class.svg" height="20">][css-url] [<img alt="Build Status" src="https://github.com/csstools/postcss-plugins/workflows/test/badge.svg" height="20">][cli-url] [<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
|
|
4
4
|
|
|
5
|
+
```bash
|
|
6
|
+
npm install css-has-pseudo --save-dev
|
|
7
|
+
```
|
|
8
|
+
|
|
5
9
|
[PostCSS Has Pseudo] lets you style elements relative to other elements in CSS, following the [Selectors Level 4] specification.
|
|
6
10
|
|
|
7
11
|
To use this feature you need to do two things :
|
|
@@ -162,12 +166,13 @@ or
|
|
|
162
166
|
|
|
163
167
|
```html
|
|
164
168
|
<!-- When using a CDN url you will have to manually update the version number -->
|
|
165
|
-
<script src="https://unpkg.com/css-has-pseudo@6.0.
|
|
169
|
+
<script src="https://unpkg.com/css-has-pseudo@6.0.1/dist/browser-global.js"></script>
|
|
166
170
|
<script>cssHasPseudo(document)</script>
|
|
167
171
|
```
|
|
168
172
|
|
|
169
|
-
|
|
170
|
-
|
|
173
|
+
> [!TIP]
|
|
174
|
+
> Please use a versioned url, like this : `https://unpkg.com/css-has-pseudo@6.0.1/dist/browser-global.js`
|
|
175
|
+
> Without the version, you might unexpectedly get a new major version of the library with breaking changes.
|
|
171
176
|
|
|
172
177
|
[PostCSS Has Pseudo] works in all major browsers, including
|
|
173
178
|
Internet Explorer 11. With a [Mutation Observer polyfill](https://github.com/webmodules/mutation-observer), the script will work
|
|
@@ -234,10 +239,11 @@ ECMA Script:
|
|
|
234
239
|
|
|
235
240
|
## CORS
|
|
236
241
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
242
|
+
> [!IMPORTANT]
|
|
243
|
+
> Applies to you if you load CSS from a different domain than the page.
|
|
244
|
+
>
|
|
245
|
+
> In this case the CSS is treated as untrusted and will not be made available to the JavaScript polyfill.
|
|
246
|
+
> The polyfill will not work without applying the correct configuration for CORS.
|
|
241
247
|
|
|
242
248
|
Example :
|
|
243
249
|
|
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:(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.message}"`),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;
|
|
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:(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.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { PluginCreator } from 'postcss';
|
|
2
|
+
|
|
3
|
+
declare const creator: PluginCreator<pluginOptions>;
|
|
4
|
+
export default creator;
|
|
5
|
+
|
|
2
6
|
/** css-has-pseudo plugin options */
|
|
3
|
-
export type pluginOptions = {
|
|
7
|
+
export declare type pluginOptions = {
|
|
4
8
|
/** Preserve the original notation. default: true */
|
|
5
9
|
preserve?: boolean;
|
|
6
10
|
/** Change the selector that is used to adjust specificity. default: "does-not-exist" */
|
|
7
11
|
specificityMatchingName?: string;
|
|
8
12
|
};
|
|
9
|
-
|
|
10
|
-
export
|
|
13
|
+
|
|
14
|
+
export { }
|
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:(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.message}"`),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;
|
|
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:(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.1",
|
|
5
5
|
"contributors": [
|
|
6
6
|
{
|
|
7
7
|
"name": "Antonio Laguna",
|
|
@@ -31,15 +31,18 @@
|
|
|
31
31
|
"engines": {
|
|
32
32
|
"node": "^14 || ^16 || >=18"
|
|
33
33
|
},
|
|
34
|
+
"type": "module",
|
|
34
35
|
"main": "dist/index.cjs",
|
|
35
36
|
"module": "dist/index.mjs",
|
|
36
|
-
"types": "dist/index.d.ts",
|
|
37
37
|
"exports": {
|
|
38
38
|
".": {
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
"import": {
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
41
|
+
"default": "./dist/index.mjs"
|
|
42
|
+
},
|
|
43
|
+
"require": {
|
|
44
|
+
"default": "./dist/index.cjs"
|
|
45
|
+
}
|
|
43
46
|
},
|
|
44
47
|
"./browser": {
|
|
45
48
|
"import": "./dist/browser.mjs",
|
|
@@ -57,27 +60,13 @@
|
|
|
57
60
|
"dist"
|
|
58
61
|
],
|
|
59
62
|
"dependencies": {
|
|
60
|
-
"@csstools/selector-specificity": "^3.0.
|
|
63
|
+
"@csstools/selector-specificity": "^3.0.1",
|
|
61
64
|
"postcss-selector-parser": "^6.0.13",
|
|
62
65
|
"postcss-value-parser": "^4.2.0"
|
|
63
66
|
},
|
|
64
67
|
"peerDependencies": {
|
|
65
68
|
"postcss": "^8.4"
|
|
66
69
|
},
|
|
67
|
-
"devDependencies": {
|
|
68
|
-
"@csstools/postcss-tape": "*",
|
|
69
|
-
"@mrhenry/core-web": "^1.1.1",
|
|
70
|
-
"puppeteer": "^20.7.4"
|
|
71
|
-
},
|
|
72
|
-
"scripts": {
|
|
73
|
-
"build": "rollup -c ../../rollup/default.mjs",
|
|
74
|
-
"docs": "node ../../.github/bin/generate-docs/install.mjs && node ../../.github/bin/generate-docs/readme.mjs",
|
|
75
|
-
"lint": "node ../../.github/bin/format-package-json.mjs",
|
|
76
|
-
"prepublishOnly": "npm run build && npm run test",
|
|
77
|
-
"test": "node .tape.mjs && node ./src/encode/test.mjs && node ./test/_import.mjs && node ./test/_require.cjs",
|
|
78
|
-
"test:browser": "node ./test/_browser.mjs",
|
|
79
|
-
"test:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs"
|
|
80
|
-
},
|
|
81
70
|
"homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/css-has-pseudo#readme",
|
|
82
71
|
"repository": {
|
|
83
72
|
"type": "git",
|
|
@@ -97,14 +86,5 @@
|
|
|
97
86
|
"postcss-plugin",
|
|
98
87
|
"pseudo",
|
|
99
88
|
"selector"
|
|
100
|
-
]
|
|
101
|
-
"csstools": {
|
|
102
|
-
"cssdbId": "has-pseudo-class",
|
|
103
|
-
"exportName": "postcssHasPseudo",
|
|
104
|
-
"humanReadableName": "PostCSS Has Pseudo",
|
|
105
|
-
"specUrl": "https://www.w3.org/TR/selectors-4/#has-pseudo"
|
|
106
|
-
},
|
|
107
|
-
"volta": {
|
|
108
|
-
"extends": "../../package.json"
|
|
109
|
-
}
|
|
89
|
+
]
|
|
110
90
|
}
|