{"name":"@csstools/postcss-is-pseudo-class","description":"A pseudo-class for matching elements in a selector list","version":"4.0.5","author":{"name":"Jonathan Neal","email":"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"},"type":"module","main":"dist/index.cjs","module":"dist/index.mjs","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.mjs"},"require":{"default":"./dist/index.cjs"}}},"dependencies":{"@csstools/selector-specificity":"^3.0.2","postcss-selector-parser":"^6.0.13"},"peerDependencies":{"postcss":"^8.4"},"homepage":"https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-is-pseudo-class#readme","repository":{"type":"git","url":"git+https://github.com/csstools/postcss-plugins.git","directory":"plugins/postcss-is-pseudo-class"},"bugs":{"url":"https://github.com/csstools/postcss-plugins/issues"},"keywords":["css","is","matches","polyfill","postcss","postcss-plugin","pseudo","selector"],"_id":"@csstools/postcss-is-pseudo-class@4.0.5","gitHead":"e7cdd8bf36ca98c30c212ce15a3a853976d91c9c","types":"./dist/index.d.ts","_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-qG3MI7IN3KY9UwdaE9E7G7sFydscVW7nAj5OGwaBP9tQPEEVdxXTGI+l1ZW5EUpZFSj+u3q/22fH5+8HI72+Bg==","shasum":"c2b9a89e8c2f4cb80c3587dae1ed544447bbd16e","tarball":"http://registry-npm.ywwl.com/@csstools/postcss-is-pseudo-class/download/@csstools/postcss-is-pseudo-class-4.0.5.tgz","fileCount":7,"unpackedSize":27451,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCfSXBex32jN5ES4vDn6Kk2ST+lUkQt9t5Z8yN2xGYdoAIhALkIsiGmXRqVxDFZr6NA6jU8WLabiHZJQKyHYLcvMGrk"}],"size":6558,"noattachment":false,"key":"/@csstools/postcss-is-pseudo-class/-/@csstools/postcss-is-pseudo-class-4.0.5.tgz"},"_npmUser":{"name":"romainmenke","email":"romainmenke@gmail.com"},"directories":{},"maintainers":[{"name":"romainmenke","email":"romainmenke@gmail.com"},{"name":"alaguna","email":"sombragriselros@gmail.com"},{"name":"jonathantneal","email":"jonathantneal@hotmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/postcss-is-pseudo-class_4.0.5_1708330110982_0.7573610510232258"},"_hasShrinkwrap":false,"readme":"# PostCSS Is Pseudo [<img src=\"https://postcss.github.io/postcss/logo.svg\" alt=\"PostCSS\" width=\"90\" height=\"90\" align=\"right\">][postcss]\n\n[![NPM Version][npm-img]][npm-url]\n[<img alt=\"Build Status\" src=\"https://github.com/csstools/postcss-plugins/workflows/test/badge.svg\" height=\"20\">][cli-url]\n[<img alt=\"Discord\" src=\"https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white\">][discord]\n<br><br>\n[<img alt=\"Baseline Status\" src=\"https://cssdb.org/images/badges-baseline/is-pseudo-class.svg\" height=\"20\">][css-url]\n[![CSS Standard Status][css-img]][css-url]\n\n[PostCSS Is Pseudo Class] lets you use the `:is` pseudo class function, following the\n[CSS Selector] specification.\n\n```pcss\n:is(input, button):is(:hover, :focus) {\n\torder: 1;\n}\n```\n\nBecomes :\n\n```pcss\ninput:hover {\n\torder: 1;\n}\ninput:focus {\n\torder: 1;\n}\nbutton:hover {\n\torder: 1;\n}\nbutton:focus {\n\torder: 1;\n}\n```\n\n## Usage\n\nAdd [PostCSS Is Pseudo Class] to your project:\n\n```bash\nnpm install @csstools/postcss-is-pseudo-class --save-dev\n```\n\nUse [PostCSS Is Pseudo Class] as a [PostCSS] plugin:\n\n```js\nimport postcss from 'postcss';\nimport postcssIsPseudoClass from '@csstools/postcss-is-pseudo-class';\n\npostcss([\n  postcssIsPseudoClass(/* pluginOptions */)\n]).process(YOUR_CSS /*, processOptions */);\n```\n\n[PostCSS Is Pseudo Class] runs in all Node environments, with special instructions for:\n\n| [Node](INSTALL.md#node) | [Webpack](INSTALL.md#webpack) | [Gulp](INSTALL.md#gulp) | [Grunt](INSTALL.md#grunt) |\n| --- | --- | --- | --- |\n\n## Options\n\n### preserve\n\nThe `preserve` option determines whether the original notation\nis preserved. By default, it is not preserved.\n\n```js\npostcss([\n  postcssIsPseudoClass({ preserve: true })\n]).process(YOUR_CSS /*, processOptions */);\n```\n\n```pcss\n:is(input, button):is(:hover, :focus) {\n\torder: 1;\n}\n```\n\nBecomes :\n\n```pcss\ninput:hover {\n\torder: 1;\n}\ninput:focus {\n\torder: 1;\n}\nbutton:hover {\n\torder: 1;\n}\nbutton:focus {\n\torder: 1;\n}\n:is(input, button):is(:hover, :focus) {\n\torder: 1;\n}\n```\n\n### specificityMatchingName\n\nThe `specificityMatchingName` option allows you to change the selector used to adjust specificity.\nThe default value is `does-not-exist`.\nIf this is an actual class, id or tag name in your code, you will need to set a different option here.\n\nSee how `:not` is used to modify [specificity](#specificity).\n\n```js\npostcss([\n  postcssIsPseudoClass({ specificityMatchingName: 'something-random' })\n]).process(YOUR_CSS /*, processOptions */);\n```\n\n```pcss\n:is(.button, button):hover {\n\torder: 7;\n}\n```\n\nBecomes :\n\n```pcss\n.button:hover {\n\torder: 7;\n}\n\nbutton:not(.something-random):hover {\n\torder: 7;\n}\n```\n\n### onComplexSelector\n\nWarn on complex selectors in `:is` pseudo class functions.\n\n```js\npostcss([\n  postcssIsPseudoClass({ onComplexSelector: 'warning' })\n]).process(YOUR_CSS /*, processOptions */);\n```\n\n### onPseudoElement\n\nWarn when pseudo elements are used in `:is` pseudo class functions.\n\n⚠️ Pseudo elements are always invalid and will be transformed to `::-csstools-invalid-<pseudo-name>`.\n\n```js\npostcss([\n  postcssIsPseudoClass({ onPseudoElement: 'warning' })\n]).process(YOUR_CSS /*, processOptions */);\n```\n\n```css\n:is(::after):hover {\n\torder: 1.0;\n}\n\n/* becomes */\n\n::-csstools-invalid-after:hover {\n\torder: 1.0;\n}\n```\n\n## ⚠️ Known shortcomings\n\n### Specificity\n\n`:is` takes the specificity of the most specific list item.\nWe can increase specificity with `:not` selectors, but we can't decrease it.\n\nConverted selectors are ensured to have the same specificity as `:is` for the most important bit.\nLess important bits can have higher specificity that `:is`.\n\nBefore :\n\n[specificity: 0, 2, 0](https://polypane.app/css-specificity-calculator/#selector=%3Ais(%3Ahover%2C%20%3Afocus)%3Ais(.button%2C%20button))\n\n```pcss\n:is(:hover, :focus):is(.button, button) {\n\torder: 7;\n}\n```\n\nAfter :\n\n```pcss\n/* specificity: [0, 2, 0] */\n.button:hover {\n\torder: 7;\n}\n\n/* specificity: [0, 2, 1] */\n/* last bit is higher than it should be, but middle bit matches */\nbutton:not(.does-not-exist):hover {\n\torder: 7;\n}\n\n/* specificity: [0, 2, 0] */\n.button:focus {\n\torder: 7;\n}\n\n/* specificity: [0, 2, 1] */\n/* last bit is higher than it should be, but middle bit matches */\nbutton:not(.does-not-exist):focus {\n\torder: 7;\n}\n```\n\n### Complex selectors\n\nBefore :\n\n\n```pcss\n:is(.alpha > .beta) ~ :is(:focus > .beta) {\n\torder: 2;\n}\n```\n\nAfter :\n\n```pcss\n.alpha > .beta ~ :focus > .beta {\n\torder: 2;\n}\n```\n\n_this is a different selector than expected as `.beta ~ :focus` matches `.beta` followed by `:focus`._<br>\n_avoid these cases._<br>\n_writing the selector without `:is()` is advised here_\n\n```pcss\n/* without is */\n.alpha:focus > .beta ~ .beta {\n\torder: 2;\n}\n```\n\nIf you have a specific pattern you can open an issue to discuss it.\nWe can detect and transform some cases but can't generalize them into a single solution that tackles all of them. \n\n[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test\n[css-img]: https://cssdb.org/images/badges/is-pseudo-class.svg\n[css-url]: https://cssdb.org/#is-pseudo-class\n[discord]: https://discord.gg/bUadyRwkJS\n[npm-img]: https://img.shields.io/npm/v/@csstools/postcss-is-pseudo-class.svg\n[npm-url]: https://www.npmjs.com/package/@csstools/postcss-is-pseudo-class\n\n[CSS Selector]: https://www.w3.org/TR/selectors-4/#matches\n[PostCSS]: https://github.com/postcss/postcss\n[PostCSS Is Pseudo Class]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-is-pseudo-class\n","publish_time":1708330111191,"_cnpm_publish_time":1708330111191,"dist-tags":{"latest":"6.0.3"}}