diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 15:05:55 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 15:05:55 +0800 |
| commit | c06f7ee0a40255214c477e13d9b956a7e07c2900 (patch) | |
| tree | f5982a568ef8fab865d0142e71c7494fea3e4c1b /node_modules/@csstools/postcss-is-pseudo-class | |
| parent | 3fd9400d4dccc25aa29b5702216732e0b7542073 (diff) | |
postcss,(plugins): nanocss, postcss-preset-env
Diffstat (limited to 'node_modules/@csstools/postcss-is-pseudo-class')
14 files changed, 534 insertions, 0 deletions
diff --git a/node_modules/@csstools/postcss-is-pseudo-class/CHANGELOG.md b/node_modules/@csstools/postcss-is-pseudo-class/CHANGELOG.md new file mode 100644 index 00000000..12453434 --- /dev/null +++ b/node_modules/@csstools/postcss-is-pseudo-class/CHANGELOG.md @@ -0,0 +1,148 @@ +# Changes to PostCSS Is Pseudo Class + +### 4.0.3 + +_October 2, 2023_ + +- Prevent incorrect transforms when `:is()` is wrapped in `:has()`. + +### 4.0.2 + +_September 18, 2023_ + +- Improve performance + +### 4.0.1 + +_September 2, 2023_ + +- Fix substitution when selectors have mixed types for compound selectors where one of two parts is a `:is()` pseudo class. + +```diff +header:is(.a .b) {} + +/* becomes : */ + +- header.a .b {} ++ .a header.b {} +``` + +### 4.0.0 + +_July 3, 2023_ + +- Change license to `MIT-0` ([read more about this change in the blog post](https://preset-env.cssdb.org/blog/license-change/)) +- 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) + +### 3.2.1 + +_May 19, 2023_ + +- Fix compound selectors with `*`. + +```diff +:is(.a *):is(h1, h2, h3) {} + +/* becomes : */ + +- .a *h1, .a *h2, .a *h3 {} ++ .a h1, .a h2, .a h3 {} +``` + +### 3.2.0 + +_April 10, 2023_ + +- Add support for more complex selector patterns. In particular anything where `:is()` is in the left-most compound selector. + +### 3.1.1 + +_February 8, 2023_ + +- Reduce the amount of duplicate fallback CSS. + +### 3.1.0 + +_February 2, 2023_ + +- Fix is pseudo inside a not pseudo (`:not(:is(h1, h2, h3))`) +- Reduce the output size when all selectors are known to be valid + +### 3.0.1 + +_January 28, 2023_ + +- Improve `types` declaration in `package.json` + +### 3.0.0 + +_January 24, 2023_ + +- Updated: Support for Node v14+ (major). + +### 2.0.7 + +_July 8, 2022_ + +- Fix case insensitive matching. + +### 2.0.6 + +_June 23, 2022_ + +- Fix selector order with any pseudo element. +- Fix transforming pseudo elements in `:is()`. Following the specification pseudo elements are invalid and we now transform to a known invalid pseudo element. +- Add `onPseudoElement` plugin option. Set `{ onPseudoElement: 'warning' }` to receive warnings when this plugin encounters an unprocessable pseudo element. + +### 2.0.5 + +_June 4, 2022_ + +- Update `@csstools/selector-specificity` (major) + +### 2.0.4 + +_May 17, 2022_ + +- Fix selector order with `:before` and other pseudo elements. + +### 2.0.3 + +_May 11, 2022_ + +- Use `@csstools/selector-specificity` for specificity calculations. + +### 2.0.2 + +_April 4, 2022_ + +- Improved : compound selector order with pseudo elements +- Improved : selector specificity calculation. + +### 2.0.1 + +_March 4, 2022_ + +- Preserve selector order as much as possible. Fixes issues where pseudo elements `::before` were moved. + +### 2.0.0 + +_January 31, 2022_ + +- Remove `skip` flag in `onComplexSelectors` option. + +If a complex selector is encountered that has no known equivalent, it will always be skipped and preserved now. + +The previous behavior was to remove `:is()` even if that broke the selector. + +### 1.0.1 + +_January 17, 2022_ + +- Fix selector order + +### 1.0.0 + +_January 13, 2022_ + +- initial release diff --git a/node_modules/@csstools/postcss-is-pseudo-class/LICENSE.md b/node_modules/@csstools/postcss-is-pseudo-class/LICENSE.md new file mode 100644 index 00000000..e8ae93b9 --- /dev/null +++ b/node_modules/@csstools/postcss-is-pseudo-class/LICENSE.md @@ -0,0 +1,18 @@ +MIT No Attribution (MIT-0) + +Copyright © CSSTools Contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the “Software”), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/node_modules/@csstools/postcss-is-pseudo-class/README.md b/node_modules/@csstools/postcss-is-pseudo-class/README.md new file mode 100644 index 00000000..407fab67 --- /dev/null +++ b/node_modules/@csstools/postcss-is-pseudo-class/README.md @@ -0,0 +1,251 @@ +# PostCSS Is Pseudo [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS" width="90" height="90" align="right">][postcss] + +[![NPM Version][npm-img]][npm-url] +[![CSS Standard Status][css-img]][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] + +[PostCSS Is Pseudo Class] lets you use the `:is` pseudo class function, following the +[CSS Selector] specification. + +```pcss +:is(input, button):is(:hover, :focus) { + order: 1; +} +``` + +Becomes : + +```pcss +input:hover { + order: 1; +} +input:focus { + order: 1; +} +button:hover { + order: 1; +} +button:focus { + order: 1; +} +``` + +## Usage + +Add [PostCSS Is Pseudo Class] to your project: + +```bash +npm install @csstools/postcss-is-pseudo-class --save-dev +``` + +Use [PostCSS Is Pseudo Class] as a [PostCSS] plugin: + +```js +import postcss from 'postcss'; +import postcssIsPseudoClass from '@csstools/postcss-is-pseudo-class'; + +postcss([ + postcssIsPseudoClass(/* pluginOptions */) +]).process(YOUR_CSS /*, processOptions */); +``` + +[PostCSS Is Pseudo Class] runs in all Node environments, with special instructions for: + +| [Node](INSTALL.md#node) | [Webpack](INSTALL.md#webpack) | [Gulp](INSTALL.md#gulp) | [Grunt](INSTALL.md#grunt) | +| --- | --- | --- | --- | + +## Options + +### preserve + +The `preserve` option determines whether the original notation +is preserved. By default, it is not preserved. + +```js +postcss([ + postcssIsPseudoClass({ preserve: true }) +]).process(YOUR_CSS /*, processOptions */); +``` + +```pcss +:is(input, button):is(:hover, :focus) { + order: 1; +} +``` + +Becomes : + +```pcss +input:hover { + order: 1; +} +input:focus { + order: 1; +} +button:hover { + order: 1; +} +button:focus { + order: 1; +} +:is(input, button):is(:hover, :focus) { + order: 1; +} +``` + +### specificityMatchingName + +The `specificityMatchingName` option allows you to change the selector used to adjust specificity. +The default value is `does-not-exist`. +If this is an actual class, id or tag name in your code, you will need to set a different option here. + +See how `:not` is used to modify [specificity](#specificity). + +```js +postcss([ + postcssIsPseudoClass({ specificityMatchingName: 'something-random' }) +]).process(YOUR_CSS /*, processOptions */); +``` + +```pcss +:is(.button, button):hover { + order: 7; +} +``` + +Becomes : + +```pcss +.button:hover { + order: 7; +} + +button:not(.something-random):hover { + order: 7; +} +``` + +### onComplexSelector + +Warn on complex selectors in `:is` pseudo class functions. + +```js +postcss([ + postcssIsPseudoClass({ onComplexSelector: 'warning' }) +]).process(YOUR_CSS /*, processOptions */); +``` + +### onPseudoElement + +Warn when pseudo elements are used in `:is` pseudo class functions. + +⚠️ Pseudo elements are always invalid and will be transformed to `::-csstools-invalid-<pseudo-name>`. + +```js +postcss([ + postcssIsPseudoClass({ onPseudoElement: 'warning' }) +]).process(YOUR_CSS /*, processOptions */); +``` + +```css +:is(::after):hover { + order: 1.0; +} + +/* becomes */ + +::-csstools-invalid-after:hover { + order: 1.0; +} +``` + +## ⚠️ Known shortcomings + +### Specificity + +`:is` takes the specificity of the most specific list item. +We can increase specificity with `:not` selectors, but we can't decrease it. + +Converted selectors are ensured to have the same specificity as `:is` for the most important bit. +Less important bits can have higher specificity that `:is`. + +Before : + +[specificity: 0, 2, 0](https://polypane.app/css-specificity-calculator/#selector=%3Ais(%3Ahover%2C%20%3Afocus)%3Ais(.button%2C%20button)) + +```pcss +:is(:hover, :focus):is(.button, button) { + order: 7; +} +``` + +After : + +```pcss +/* specificity: [0, 2, 0] */ +.button:hover { + order: 7; +} + +/* specificity: [0, 2, 1] */ +/* last bit is higher than it should be, but middle bit matches */ +button:not(.does-not-exist):hover { + order: 7; +} + +/* specificity: [0, 2, 0] */ +.button:focus { + order: 7; +} + +/* specificity: [0, 2, 1] */ +/* last bit is higher than it should be, but middle bit matches */ +button:not(.does-not-exist):focus { + order: 7; +} +``` + +### Complex selectors + +Before : + + +```pcss +:is(.alpha > .beta) ~ :is(:focus > .beta) { + order: 2; +} +``` + +After : + +```pcss +.alpha > .beta ~ :focus > .beta { + order: 2; +} +``` + +_this is a different selector than expected as `.beta ~ :focus` matches `.beta` followed by `:focus`._<br> +_avoid these cases._<br> +_writing the selector without `:is()` is advised here_ + +```pcss +/* without is */ +.alpha:focus > .beta ~ .beta { + order: 2; +} +``` + +If you have a specific pattern you can open an issue to discuss it. +We can detect and transform some cases but can't generalize them into a single solution that tackles all of them. + +[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test +[css-img]: https://cssdb.org/images/badges/is-pseudo-class.svg +[css-url]: https://cssdb.org/#is-pseudo-class +[discord]: https://discord.gg/bUadyRwkJS +[npm-img]: https://img.shields.io/npm/v/@csstools/postcss-is-pseudo-class.svg +[npm-url]: https://www.npmjs.com/package/@csstools/postcss-is-pseudo-class + +[CSS Selector]: https://www.w3.org/TR/selectors-4/#matches +[PostCSS]: https://github.com/postcss/postcss +[PostCSS Is Pseudo Class]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-is-pseudo-class diff --git a/node_modules/@csstools/postcss-is-pseudo-class/dist/index.cjs b/node_modules/@csstools/postcss-is-pseudo-class/dist/index.cjs new file mode 100644 index 00000000..939299bd --- /dev/null +++ b/node_modules/@csstools/postcss-is-pseudo-class/dist/index.cjs @@ -0,0 +1 @@ +"use strict";var e=require("postcss-selector-parser"),o=require("@csstools/selector-specificity");function alwaysValidSelector(o){const s=e().astSync(o);let t=!0;return s.walk((e=>{var o,s;if("class"!==e.type&&"comment"!==e.type&&"id"!==e.type&&"root"!==e.type&&"selector"!==e.type&&"string"!==e.type&&"tag"!==e.type&&"universal"!==e.type&&("attribute"!==e.type||e.insensitive)&&("combinator"!==e.type||"+"!==e.value&&">"!==e.value&&"~"!==e.value&&" "!==e.value)&&("pseudo"!==e.type||null!=(o=e.nodes)&&o.length||":hover"!==e.value.toLowerCase()&&":focus"!==e.value.toLowerCase())){if("pseudo"===e.type&&1===(null==(s=e.nodes)?void 0:s.length)&&":not"===e.value.toLowerCase()){let o=!0;if(e.nodes[0].walkCombinators((()=>{o=!1})),o)return}return t=!1,!1}})),t}function sortCompoundSelectorsInsideComplexSelector(o){if(!o||!o.nodes||1===o.nodes.length)return;const s=[];let t=[];for(let n=0;n<o.nodes.length;n++)"combinator"!==o.nodes[n].type?e.isPseudoElement(o.nodes[n])?(s.push(t),t=[o.nodes[n]]):t.push(o.nodes[n]):(s.push(t),s.push([o.nodes[n]]),t=[]);s.push(t);const n=[];for(let e=0;e<s.length;e++){const o=s[e];o.sort(((e,o)=>"selector"===e.type&&"selector"===o.type&&e.nodes.length&&o.nodes.length?selectorTypeOrder(e.nodes[0],e.nodes[0].type)-selectorTypeOrder(o.nodes[0],o.nodes[0].type):"selector"===e.type&&e.nodes.length?selectorTypeOrder(e.nodes[0],e.nodes[0].type)-selectorTypeOrder(o,o.type):"selector"===o.type&&o.nodes.length?selectorTypeOrder(e,e.type)-selectorTypeOrder(o.nodes[0],o.nodes[0].type):selectorTypeOrder(e,e.type)-selectorTypeOrder(o,o.type)));const t=new Set(o.map((e=>e.type))),r=t.has("universal")&&(t.has("tag")||t.has("attribute")||t.has("class")||t.has("id")||t.has("pseudo"));for(let e=0;e<o.length;e++)"universal"===o[e].type&&r?o[e].remove():n.push(o[e])}for(let s=n.length-1;s>=0;s--){const t=n[s-1];if(n[s].remove(),t&&"tag"===t.type&&"tag"===n[s].type){const t=e.pseudo({value:":is",nodes:[e.selector({value:"",nodes:[n[s]]})]});o.prepend(t)}else o.prepend(n[s])}}function selectorTypeOrder(o,t){return e.isPseudoElement(o)?s.pseudoElement:s[t]}const s={universal:0,tag:1,pseudoElement:2,id:3,class:4,attribute:5,pseudo:6,selector:7,string:8,root:9,comment:10};function childAdjacentChild(e){return!(!e||!e.nodes)&&("selector"===e.type&&(3===e.nodes.length&&(!(!e.nodes[0]||"pseudo"!==e.nodes[0].type||":-csstools-matches"!==e.nodes[0].value)&&(!(!e.nodes[1]||"combinator"!==e.nodes[1].type||"+"!==e.nodes[1].value&&"~"!==e.nodes[1].value)&&(!(!e.nodes[2]||"pseudo"!==e.nodes[2].type||":-csstools-matches"!==e.nodes[2].value)&&(!(!e.nodes[0].nodes||1!==e.nodes[0].nodes.length)&&("selector"===e.nodes[0].nodes[0].type&&(!(!e.nodes[0].nodes[0].nodes||3!==e.nodes[0].nodes[0].nodes.length)&&(!(!e.nodes[0].nodes[0].nodes||"combinator"!==e.nodes[0].nodes[0].nodes[1].type||">"!==e.nodes[0].nodes[0].nodes[1].value)&&(!(!e.nodes[2].nodes||1!==e.nodes[2].nodes.length)&&("selector"===e.nodes[2].nodes[0].type&&(!(!e.nodes[2].nodes[0].nodes||3!==e.nodes[2].nodes[0].nodes.length)&&(!(!e.nodes[2].nodes[0].nodes||"combinator"!==e.nodes[2].nodes[0].nodes[1].type||">"!==e.nodes[2].nodes[0].nodes[1].value)&&(e.nodes[0].nodes[0].insertAfter(e.nodes[0].nodes[0].nodes[0],e.nodes[2].nodes[0].nodes[0].clone()),e.nodes[2].nodes[0].nodes[1].remove(),e.nodes[2].nodes[0].nodes[0].remove(),e.nodes[0].replaceWith(e.nodes[0].nodes[0]),e.nodes[2].replaceWith(e.nodes[2].nodes[0]),!0))))))))))))))}function isInCompoundWithOneOtherElement(o){if(!o||!o.nodes)return!1;if("selector"!==o.type)return!1;if(2!==o.nodes.length)return!1;let s,t;return o.nodes[0]&&"pseudo"===o.nodes[0].type&&":-csstools-matches"===o.nodes[0].value?(s=0,t=1):o.nodes[1]&&"pseudo"===o.nodes[1].type&&":-csstools-matches"===o.nodes[1].value&&(s=1,t=0),!!s&&(!!o.nodes[t]&&(("selector"!==o.nodes[t].type||!o.nodes[t].some((o=>"combinator"===o.type||e.isPseudoElement(o))))&&("combinator"!==o.nodes[t].type&&(o.nodes[s].nodes[0].append(o.nodes[t].clone()),o.nodes[s].replaceWith(...o.nodes[s].nodes[0].nodes),o.nodes[t].remove(),!0))))}function isPseudoInFirstCompound(e){if(!e||!e.nodes)return!1;if("selector"!==e.type)return!1;let o=-1;for(let s=0;s<e.nodes.length;s++){const t=e.nodes[s];if("combinator"===t.type)return!1;if("pseudo"===t.type&&":-csstools-matches"===t.value){if(!t.nodes||1!==t.nodes.length)return!1;o=s;break}}if(-1===o)return!1;const s=e.nodes.slice(0,o),t=e.nodes[o],n=e.nodes.slice(o+1);return s.forEach((e=>{t.nodes[0].append(e.clone())})),n.forEach((e=>{t.nodes[0].append(e.clone())})),t.replaceWith(...t.nodes),s.forEach((e=>{e.remove()})),n.forEach((e=>{e.remove()})),!0}function complexSelectors(o,s,t,n){return o.flatMap((o=>{if(-1===o.indexOf(":-csstools-matches")&&-1===o.toLowerCase().indexOf(":is"))return o;const r=e().astSync(o);return r.walkPseudos((o=>{if(":is"===o.value.toLowerCase()&&o.nodes&&o.nodes.length&&"selector"===o.nodes[0].type&&0===o.nodes[0].nodes.length)return o.value=":not",void o.nodes[0].append(e.universal());if(":-csstools-matches"===o.value)if(!o.nodes||o.nodes.length){if(o.walkPseudos((o=>{if(e.isPseudoElement(o)){let e=o.value;if(e.startsWith("::-csstools-invalid-"))return;for(;e.startsWith(":");)e=e.slice(1);o.value=`::-csstools-invalid-${e}`,n()}})),1===o.nodes.length&&"selector"===o.nodes[0].type){if(1===o.nodes[0].nodes.length)return void o.replaceWith(o.nodes[0].nodes[0]);if(!o.nodes[0].some((e=>"combinator"===e.type)))return void o.replaceWith(...o.nodes[0].nodes)}1!==r.nodes.length||"selector"!==r.nodes[0].type||1!==r.nodes[0].nodes.length||r.nodes[0].nodes[0]!==o?childAdjacentChild(o.parent)||isInCompoundWithOneOtherElement(o.parent)||isPseudoInFirstCompound(o.parent)||("warning"===s.onComplexSelector&&t(),o.value=":is"):o.replaceWith(...o.nodes[0].nodes)}else o.remove()})),r.walk((e=>{"selector"===e.type&&"nodes"in e&&1===e.nodes.length&&"selector"===e.nodes[0].type&&e.replaceWith(e.nodes[0])})),r.walk((e=>{"nodes"in e&&sortCompoundSelectorsInsideComplexSelector(e)})),r.toString()})).filter((e=>!!e))}function splitSelectors(s,t,n=0){const r=":not(#"+t.specificityMatchingName+")",l=":not(."+t.specificityMatchingName+")",d=":not("+t.specificityMatchingName+")";return s.flatMap((s=>{if(-1===s.toLowerCase().indexOf(":is"))return s;let i=!1;const c=[];if(e().astSync(s).walkPseudos((e=>{var s,t,n,a;if(":is"!==e.value.toLowerCase()||!e.nodes||!e.nodes.length)return;if("selector"===e.nodes[0].type&&0===e.nodes[0].nodes.length)return;if("pseudo"===(null==(s=e.parent)||null==(s=s.parent)?void 0:s.type)&&":not"===(null==(t=e.parent)||null==(t=t.parent)||null==(t=t.value)?void 0:t.toLowerCase()))return void c.push([{start:e.parent.parent.sourceIndex,end:e.parent.parent.sourceIndex+e.parent.parent.toString().length,option:`:not(${e.nodes.toString()})`}]);if("pseudo"===(null==(n=e.parent)||null==(n=n.parent)?void 0:n.type)&&":has"===(null==(a=e.parent)||null==(a=a.parent)||null==(a=a.value)?void 0:a.toLowerCase()))return void(e.value=":-csstools-matches");let p=e.parent;for(;p;){if(p.value&&":is"===p.value.toLowerCase()&&"pseudo"===p.type)return void(i=!0);p=p.parent}const u=o.selectorSpecificity(e),h=e.sourceIndex,f=h+e.toString().length,y=[];e.nodes.forEach((e=>{const s={start:h,end:f,option:""},t=o.selectorSpecificity(e);let n=e.toString().trim();const i=Math.max(0,u.a-t.a),c=Math.max(0,u.b-t.b),a=Math.max(0,u.c-t.c);for(let e=0;e<i;e++)n+=r;for(let e=0;e<c;e++)n+=l;for(let e=0;e<a;e++)n+=d;s.option=n,y.push(s)})),c.push(y)})),!c.length)return[s];let a=[];return cartesianProduct(...c).forEach((e=>{let o="";for(let n=0;n<e.length;n++){var t;const r=e[n];o+=s.substring((null==(t=e[n-1])?void 0:t.end)||0,e[n].start),o+=":-csstools-matches("+r.option+")",n===e.length-1&&(o+=s.substring(e[n].end))}a.push(o)})),i&&n<10&&(a=splitSelectors(a,t,n+1)),a})).filter((e=>!!e))}function cartesianProduct(...e){const o=[],s=e.length-1;return function helper(t,n){for(let r=0,l=e[n].length;r<l;r++){const l=t.slice(0);l.push(e[n][r]),n===s?o.push(l):helper(l,n+1)}}([],0),o}const t=/:is\(/i,creator=e=>{const o={specificityMatchingName:"does-not-exist",...e||{}};return{postcssPlugin:"postcss-is-pseudo-class",prepare(){const e=new WeakSet;return{Rule(s,{result:n}){if(!s.selector)return;if(!t.test(s.selector))return;if(e.has(s))return;let r=!1;const warnOnComplexSelector=()=>{"warning"===o.onComplexSelector&&(r||(r=!0,s.warn(n,`Complex selectors in '${s.selector}' can not be transformed to an equivalent selector without ':is()'.`)))};let l=!1;const warnOnPseudoElements=()=>{"warning"===o.onPseudoElement&&(l||(l=!0,s.warn(n,`Pseudo elements are not allowed in ':is()', unable to transform '${s.selector}'`)))};try{let t=!1;const n=[],r=complexSelectors(splitSelectors(s.selectors,{specificityMatchingName:o.specificityMatchingName}),{onComplexSelector:o.onComplexSelector},warnOnComplexSelector,warnOnPseudoElements);if(Array.from(new Set(r)).forEach((o=>{if(s.selectors.indexOf(o)>-1)n.push(o);else{if(alwaysValidSelector(o))return n.push(o),void(t=!0);e.add(s),s.cloneBefore({selector:o}),t=!0}})),n.length&&t&&(e.add(s),s.cloneBefore({selectors:n})),!o.preserve){if(!t)return;s.remove()}}catch(e){if(e.message.indexOf("call stack size exceeded")>-1)throw e;s.warn(n,`Failed to parse selector "${s.selector}"`)}}}}}};creator.postcss=!0,module.exports=creator; diff --git a/node_modules/@csstools/postcss-is-pseudo-class/dist/index.d.ts b/node_modules/@csstools/postcss-is-pseudo-class/dist/index.d.ts new file mode 100644 index 00000000..5b65f016 --- /dev/null +++ b/node_modules/@csstools/postcss-is-pseudo-class/dist/index.d.ts @@ -0,0 +1,23 @@ +import type { PluginCreator } from 'postcss'; +/** postcss-is-pseudo-class plugin options */ +export type pluginOptions = { + /** Preserve the original notation. default: false */ + preserve?: boolean; + /** + * Warn on complex selectors in `:is` pseudo class functions. + * default: _not set_ + */ + onComplexSelector?: 'warning'; + /** + * Warn when pseudo elements are used in `:is` pseudo class functions. + * default: _not set_ + */ + onPseudoElement?: 'warning'; + /** + * Change the selector used to adjust specificity. + * default: `does-not-exist`. + */ + specificityMatchingName?: string; +}; +declare const creator: PluginCreator<pluginOptions>; +export default creator; diff --git a/node_modules/@csstools/postcss-is-pseudo-class/dist/index.mjs b/node_modules/@csstools/postcss-is-pseudo-class/dist/index.mjs new file mode 100644 index 00000000..98bdd1ac --- /dev/null +++ b/node_modules/@csstools/postcss-is-pseudo-class/dist/index.mjs @@ -0,0 +1 @@ +import e from"postcss-selector-parser";import{selectorSpecificity as o}from"@csstools/selector-specificity";function alwaysValidSelector(o){const s=e().astSync(o);let t=!0;return s.walk((e=>{var o,s;if("class"!==e.type&&"comment"!==e.type&&"id"!==e.type&&"root"!==e.type&&"selector"!==e.type&&"string"!==e.type&&"tag"!==e.type&&"universal"!==e.type&&("attribute"!==e.type||e.insensitive)&&("combinator"!==e.type||"+"!==e.value&&">"!==e.value&&"~"!==e.value&&" "!==e.value)&&("pseudo"!==e.type||null!=(o=e.nodes)&&o.length||":hover"!==e.value.toLowerCase()&&":focus"!==e.value.toLowerCase())){if("pseudo"===e.type&&1===(null==(s=e.nodes)?void 0:s.length)&&":not"===e.value.toLowerCase()){let o=!0;if(e.nodes[0].walkCombinators((()=>{o=!1})),o)return}return t=!1,!1}})),t}function sortCompoundSelectorsInsideComplexSelector(o){if(!o||!o.nodes||1===o.nodes.length)return;const s=[];let t=[];for(let n=0;n<o.nodes.length;n++)"combinator"!==o.nodes[n].type?e.isPseudoElement(o.nodes[n])?(s.push(t),t=[o.nodes[n]]):t.push(o.nodes[n]):(s.push(t),s.push([o.nodes[n]]),t=[]);s.push(t);const n=[];for(let e=0;e<s.length;e++){const o=s[e];o.sort(((e,o)=>"selector"===e.type&&"selector"===o.type&&e.nodes.length&&o.nodes.length?selectorTypeOrder(e.nodes[0],e.nodes[0].type)-selectorTypeOrder(o.nodes[0],o.nodes[0].type):"selector"===e.type&&e.nodes.length?selectorTypeOrder(e.nodes[0],e.nodes[0].type)-selectorTypeOrder(o,o.type):"selector"===o.type&&o.nodes.length?selectorTypeOrder(e,e.type)-selectorTypeOrder(o.nodes[0],o.nodes[0].type):selectorTypeOrder(e,e.type)-selectorTypeOrder(o,o.type)));const t=new Set(o.map((e=>e.type))),r=t.has("universal")&&(t.has("tag")||t.has("attribute")||t.has("class")||t.has("id")||t.has("pseudo"));for(let e=0;e<o.length;e++)"universal"===o[e].type&&r?o[e].remove():n.push(o[e])}for(let s=n.length-1;s>=0;s--){const t=n[s-1];if(n[s].remove(),t&&"tag"===t.type&&"tag"===n[s].type){const t=e.pseudo({value:":is",nodes:[e.selector({value:"",nodes:[n[s]]})]});o.prepend(t)}else o.prepend(n[s])}}function selectorTypeOrder(o,t){return e.isPseudoElement(o)?s.pseudoElement:s[t]}const s={universal:0,tag:1,pseudoElement:2,id:3,class:4,attribute:5,pseudo:6,selector:7,string:8,root:9,comment:10};function childAdjacentChild(e){return!(!e||!e.nodes)&&("selector"===e.type&&(3===e.nodes.length&&(!(!e.nodes[0]||"pseudo"!==e.nodes[0].type||":-csstools-matches"!==e.nodes[0].value)&&(!(!e.nodes[1]||"combinator"!==e.nodes[1].type||"+"!==e.nodes[1].value&&"~"!==e.nodes[1].value)&&(!(!e.nodes[2]||"pseudo"!==e.nodes[2].type||":-csstools-matches"!==e.nodes[2].value)&&(!(!e.nodes[0].nodes||1!==e.nodes[0].nodes.length)&&("selector"===e.nodes[0].nodes[0].type&&(!(!e.nodes[0].nodes[0].nodes||3!==e.nodes[0].nodes[0].nodes.length)&&(!(!e.nodes[0].nodes[0].nodes||"combinator"!==e.nodes[0].nodes[0].nodes[1].type||">"!==e.nodes[0].nodes[0].nodes[1].value)&&(!(!e.nodes[2].nodes||1!==e.nodes[2].nodes.length)&&("selector"===e.nodes[2].nodes[0].type&&(!(!e.nodes[2].nodes[0].nodes||3!==e.nodes[2].nodes[0].nodes.length)&&(!(!e.nodes[2].nodes[0].nodes||"combinator"!==e.nodes[2].nodes[0].nodes[1].type||">"!==e.nodes[2].nodes[0].nodes[1].value)&&(e.nodes[0].nodes[0].insertAfter(e.nodes[0].nodes[0].nodes[0],e.nodes[2].nodes[0].nodes[0].clone()),e.nodes[2].nodes[0].nodes[1].remove(),e.nodes[2].nodes[0].nodes[0].remove(),e.nodes[0].replaceWith(e.nodes[0].nodes[0]),e.nodes[2].replaceWith(e.nodes[2].nodes[0]),!0))))))))))))))}function isInCompoundWithOneOtherElement(o){if(!o||!o.nodes)return!1;if("selector"!==o.type)return!1;if(2!==o.nodes.length)return!1;let s,t;return o.nodes[0]&&"pseudo"===o.nodes[0].type&&":-csstools-matches"===o.nodes[0].value?(s=0,t=1):o.nodes[1]&&"pseudo"===o.nodes[1].type&&":-csstools-matches"===o.nodes[1].value&&(s=1,t=0),!!s&&(!!o.nodes[t]&&(("selector"!==o.nodes[t].type||!o.nodes[t].some((o=>"combinator"===o.type||e.isPseudoElement(o))))&&("combinator"!==o.nodes[t].type&&(o.nodes[s].nodes[0].append(o.nodes[t].clone()),o.nodes[s].replaceWith(...o.nodes[s].nodes[0].nodes),o.nodes[t].remove(),!0))))}function isPseudoInFirstCompound(e){if(!e||!e.nodes)return!1;if("selector"!==e.type)return!1;let o=-1;for(let s=0;s<e.nodes.length;s++){const t=e.nodes[s];if("combinator"===t.type)return!1;if("pseudo"===t.type&&":-csstools-matches"===t.value){if(!t.nodes||1!==t.nodes.length)return!1;o=s;break}}if(-1===o)return!1;const s=e.nodes.slice(0,o),t=e.nodes[o],n=e.nodes.slice(o+1);return s.forEach((e=>{t.nodes[0].append(e.clone())})),n.forEach((e=>{t.nodes[0].append(e.clone())})),t.replaceWith(...t.nodes),s.forEach((e=>{e.remove()})),n.forEach((e=>{e.remove()})),!0}function complexSelectors(o,s,t,n){return o.flatMap((o=>{if(-1===o.indexOf(":-csstools-matches")&&-1===o.toLowerCase().indexOf(":is"))return o;const r=e().astSync(o);return r.walkPseudos((o=>{if(":is"===o.value.toLowerCase()&&o.nodes&&o.nodes.length&&"selector"===o.nodes[0].type&&0===o.nodes[0].nodes.length)return o.value=":not",void o.nodes[0].append(e.universal());if(":-csstools-matches"===o.value)if(!o.nodes||o.nodes.length){if(o.walkPseudos((o=>{if(e.isPseudoElement(o)){let e=o.value;if(e.startsWith("::-csstools-invalid-"))return;for(;e.startsWith(":");)e=e.slice(1);o.value=`::-csstools-invalid-${e}`,n()}})),1===o.nodes.length&&"selector"===o.nodes[0].type){if(1===o.nodes[0].nodes.length)return void o.replaceWith(o.nodes[0].nodes[0]);if(!o.nodes[0].some((e=>"combinator"===e.type)))return void o.replaceWith(...o.nodes[0].nodes)}1!==r.nodes.length||"selector"!==r.nodes[0].type||1!==r.nodes[0].nodes.length||r.nodes[0].nodes[0]!==o?childAdjacentChild(o.parent)||isInCompoundWithOneOtherElement(o.parent)||isPseudoInFirstCompound(o.parent)||("warning"===s.onComplexSelector&&t(),o.value=":is"):o.replaceWith(...o.nodes[0].nodes)}else o.remove()})),r.walk((e=>{"selector"===e.type&&"nodes"in e&&1===e.nodes.length&&"selector"===e.nodes[0].type&&e.replaceWith(e.nodes[0])})),r.walk((e=>{"nodes"in e&&sortCompoundSelectorsInsideComplexSelector(e)})),r.toString()})).filter((e=>!!e))}function splitSelectors(s,t,n=0){const r=":not(#"+t.specificityMatchingName+")",l=":not(."+t.specificityMatchingName+")",d=":not("+t.specificityMatchingName+")";return s.flatMap((s=>{if(-1===s.toLowerCase().indexOf(":is"))return s;let a=!1;const i=[];if(e().astSync(s).walkPseudos((e=>{var s,t,n,c;if(":is"!==e.value.toLowerCase()||!e.nodes||!e.nodes.length)return;if("selector"===e.nodes[0].type&&0===e.nodes[0].nodes.length)return;if("pseudo"===(null==(s=e.parent)||null==(s=s.parent)?void 0:s.type)&&":not"===(null==(t=e.parent)||null==(t=t.parent)||null==(t=t.value)?void 0:t.toLowerCase()))return void i.push([{start:e.parent.parent.sourceIndex,end:e.parent.parent.sourceIndex+e.parent.parent.toString().length,option:`:not(${e.nodes.toString()})`}]);if("pseudo"===(null==(n=e.parent)||null==(n=n.parent)?void 0:n.type)&&":has"===(null==(c=e.parent)||null==(c=c.parent)||null==(c=c.value)?void 0:c.toLowerCase()))return void(e.value=":-csstools-matches");let p=e.parent;for(;p;){if(p.value&&":is"===p.value.toLowerCase()&&"pseudo"===p.type)return void(a=!0);p=p.parent}const u=o(e),h=e.sourceIndex,f=h+e.toString().length,y=[];e.nodes.forEach((e=>{const s={start:h,end:f,option:""},t=o(e);let n=e.toString().trim();const a=Math.max(0,u.a-t.a),i=Math.max(0,u.b-t.b),c=Math.max(0,u.c-t.c);for(let e=0;e<a;e++)n+=r;for(let e=0;e<i;e++)n+=l;for(let e=0;e<c;e++)n+=d;s.option=n,y.push(s)})),i.push(y)})),!i.length)return[s];let c=[];return cartesianProduct(...i).forEach((e=>{let o="";for(let n=0;n<e.length;n++){var t;const r=e[n];o+=s.substring((null==(t=e[n-1])?void 0:t.end)||0,e[n].start),o+=":-csstools-matches("+r.option+")",n===e.length-1&&(o+=s.substring(e[n].end))}c.push(o)})),a&&n<10&&(c=splitSelectors(c,t,n+1)),c})).filter((e=>!!e))}function cartesianProduct(...e){const o=[],s=e.length-1;return function helper(t,n){for(let r=0,l=e[n].length;r<l;r++){const l=t.slice(0);l.push(e[n][r]),n===s?o.push(l):helper(l,n+1)}}([],0),o}const t=/:is\(/i,creator=e=>{const o={specificityMatchingName:"does-not-exist",...e||{}};return{postcssPlugin:"postcss-is-pseudo-class",prepare(){const e=new WeakSet;return{Rule(s,{result:n}){if(!s.selector)return;if(!t.test(s.selector))return;if(e.has(s))return;let r=!1;const warnOnComplexSelector=()=>{"warning"===o.onComplexSelector&&(r||(r=!0,s.warn(n,`Complex selectors in '${s.selector}' can not be transformed to an equivalent selector without ':is()'.`)))};let l=!1;const warnOnPseudoElements=()=>{"warning"===o.onPseudoElement&&(l||(l=!0,s.warn(n,`Pseudo elements are not allowed in ':is()', unable to transform '${s.selector}'`)))};try{let t=!1;const n=[],r=complexSelectors(splitSelectors(s.selectors,{specificityMatchingName:o.specificityMatchingName}),{onComplexSelector:o.onComplexSelector},warnOnComplexSelector,warnOnPseudoElements);if(Array.from(new Set(r)).forEach((o=>{if(s.selectors.indexOf(o)>-1)n.push(o);else{if(alwaysValidSelector(o))return n.push(o),void(t=!0);e.add(s),s.cloneBefore({selector:o}),t=!0}})),n.length&&t&&(e.add(s),s.cloneBefore({selectors:n})),!o.preserve){if(!t)return;s.remove()}}catch(e){if(e.message.indexOf("call stack size exceeded")>-1)throw e;s.warn(n,`Failed to parse selector "${s.selector}"`)}}}}}};creator.postcss=!0;export{creator as default}; diff --git a/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/always-valid.d.ts b/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/always-valid.d.ts new file mode 100644 index 00000000..a3bb60b3 --- /dev/null +++ b/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/always-valid.d.ts @@ -0,0 +1 @@ +export default function alwaysValidSelector(selector: string): boolean; diff --git a/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/complex.d.ts b/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/complex.d.ts new file mode 100644 index 00000000..904515e7 --- /dev/null +++ b/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/complex.d.ts @@ -0,0 +1,3 @@ +export default function complexSelectors(selectors: Array<string>, pluginOptions: { + onComplexSelector?: 'warning'; +}, warnOnComplexSelector: () => void, warnOnPseudoElements: () => void): string[]; diff --git a/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/complex/child-adjacent-child.d.ts b/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/complex/child-adjacent-child.d.ts new file mode 100644 index 00000000..644eaaec --- /dev/null +++ b/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/complex/child-adjacent-child.d.ts @@ -0,0 +1 @@ +export declare function childAdjacentChild(selector: any): boolean; diff --git a/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/complex/is-in-compound.d.ts b/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/complex/is-in-compound.d.ts new file mode 100644 index 00000000..3a91eef6 --- /dev/null +++ b/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/complex/is-in-compound.d.ts @@ -0,0 +1 @@ +export declare function isInCompoundWithOneOtherElement(selector: any): boolean; diff --git a/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/complex/is-pseudo-in-first-compound.d.ts b/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/complex/is-pseudo-in-first-compound.d.ts new file mode 100644 index 00000000..06ba1481 --- /dev/null +++ b/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/complex/is-pseudo-in-first-compound.d.ts @@ -0,0 +1 @@ +export declare function isPseudoInFirstCompound(selector: any): boolean; diff --git a/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/compound-selector-order.d.ts b/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/compound-selector-order.d.ts new file mode 100644 index 00000000..3fb1e39f --- /dev/null +++ b/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/compound-selector-order.d.ts @@ -0,0 +1 @@ +export declare function sortCompoundSelectorsInsideComplexSelector(node: any): void; diff --git a/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/split-selectors.d.ts b/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/split-selectors.d.ts new file mode 100644 index 00000000..7bb70f21 --- /dev/null +++ b/node_modules/@csstools/postcss-is-pseudo-class/dist/split-selectors/split-selectors.d.ts @@ -0,0 +1,3 @@ +export default function splitSelectors(selectors: Array<string>, pluginOptions: { + specificityMatchingName: string; +}, recursionDepth?: number): Array<string>; diff --git a/node_modules/@csstools/postcss-is-pseudo-class/package.json b/node_modules/@csstools/postcss-is-pseudo-class/package.json new file mode 100644 index 00000000..05e2749c --- /dev/null +++ b/node_modules/@csstools/postcss-is-pseudo-class/package.json @@ -0,0 +1,81 @@ +{ + "name": "@csstools/postcss-is-pseudo-class", + "description": "A pseudo-class for matching elements in a selector list", + "version": "4.0.3", + "author": "Jonathan Neal <jonathantneal@hotmail.com>", + "license": "MIT-0", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "engines": { + "node": "^14 || ^16 || >=18" + }, + "main": "dist/index.cjs", + "module": "dist/index.mjs", + "types": "dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs", + "require": "./dist/index.cjs", + "default": "./dist/index.mjs" + } + }, + "files": [ + "CHANGELOG.md", + "LICENSE.md", + "README.md", + "dist" + ], + "dependencies": { + "@csstools/selector-specificity": "^3.0.0", + "postcss-selector-parser": "^6.0.13" + }, + "peerDependencies": { + "postcss": "^8.4" + }, + "devDependencies": { + "@csstools/postcss-tape": "*", + "puppeteer": "^21.3.6" + }, + "scripts": { + "build": "rollup -c ../../rollup/default.mjs", + "docs": "node ../../.github/bin/generate-docs/install.mjs", + "lint": "node ../../.github/bin/format-package-json.mjs", + "prepublishOnly": "npm run build && npm run test", + "test": "node .tape.mjs && node ./test/_import.mjs && node ./test/_require.cjs", + "test:browser": "node ./test/_browser.mjs", + "test:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs" + }, + "homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-is-pseudo-class#readme", + "repository": { + "type": "git", + "url": "https://github.com/csstools/postcss-plugins.git", + "directory": "plugins/postcss-is-pseudo-class" + }, + "bugs": "https://github.com/csstools/postcss-plugins/issues", + "keywords": [ + "css", + "is", + "matches", + "polyfill", + "postcss", + "postcss-plugin", + "pseudo", + "selector" + ], + "csstools": { + "exportName": "postcssIsPseudoClass", + "humanReadableName": "PostCSS Is Pseudo" + }, + "volta": { + "extends": "../../package.json" + } +} |
