{"name":"postcss-nesting","version":"13.0.2","keywords":["atrules","child","children","css","cssnext","csswg","nested","nestings","postcss","postcss-plugin","rules","selectors","specifications","specs","syntax","w3c"],"license":"MIT-0","_id":"postcss-nesting@13.0.2","maintainers":[{"name":"jonathantneal","email":"jonathantneal@hotmail.com"},{"name":"alaguna","email":"sombragriselros@gmail.com"},{"name":"romainmenke","email":"romainmenke@gmail.com"}],"contributors":[{"url":"https://antonio.laguna.es","name":"Antonio Laguna","email":"antonio@laguna.es"},{"name":"Jonathan Neal","email":"jonathantneal@hotmail.com"},{"name":"Romain Menke","email":"romainmenke@gmail.com"}],"homepage":"https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting#readme","bugs":{"url":"https://github.com/csstools/postcss-plugins/issues"},"dist":{"shasum":"fde0d4df772b76d03b52eccc84372e8d1ca1402e","tarball":"http://registry-npm.ywwl.com/postcss-nesting/download/postcss-nesting-13.0.2.tgz","fileCount":7,"integrity":"sha512-1YCI290TX+VP0U/K/aFxzHzQWHWURL+CtHMSbex1lCdpXD1SoR2sYuxDu5aNI9lPoXpKTCggFZiDJbwylU0LEQ==","signatures":[{"sig":"MEUCICekeTQmTkBrRU49wDzsJohwrdJIG6X434yyix7zR/lMAiEAxdckEigXPMcsSV51yW39/db7Ul04ghgjJWAQZQNe06s=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":32191,"size":7177,"noattachment":false,"key":"/postcss-nesting/-/postcss-nesting-13.0.2.tgz"},"main":"dist/index.cjs","type":"module","types":"./dist/index.d.ts","unpkg":"dist/index.mjs","module":"dist/index.mjs","engines":{"node":">=18"},"exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.mjs"},"require":{"default":"./dist/index.cjs"}}},"funding":[{"url":"https://github.com/sponsors/csstools","type":"github"},{"url":"https://opencollective.com/csstools","type":"opencollective"}],"gitHead":"dabec01d9b27f8e9fb1f7fe28b1f900be08d29ad","scripts":{},"_npmUser":{"name":"romainmenke","email":"romainmenke@gmail.com"},"jsdelivr":"dist/index.mjs","repository":{"url":"git+https://github.com/csstools/postcss-plugins.git","type":"git","directory":"plugins/postcss-nesting"},"_npmVersion":"10.9.0","description":"Nest rules inside each other in CSS","directories":{},"_nodeVersion":"22.12.0","dependencies":{"postcss-selector-parser":"^7.0.0","@csstools/selector-specificity":"^5.0.0","@csstools/selector-resolve-nested":"^3.1.0"},"_hasShrinkwrap":false,"peerDependencies":{"postcss":"^8.4"},"_npmOperationalInternal":{"tmp":"tmp/postcss-nesting_13.0.2_1749549858736_0.18393262589641002","host":"s3://npm-registry-packages-npm-production"},"readme":"# PostCSS Nesting [<img src=\"https://postcss.github.io/postcss/logo.svg\" alt=\"PostCSS Logo\" width=\"90\" height=\"90\" align=\"right\">][PostCSS]\n\n`npm install postcss-nesting --save-dev`\n\n[PostCSS Nesting] lets you nest style rules inside each other, following the [CSS Nesting specification].\n\nIf you want nested rules the same way [Sass] works\nyou might want to use [PostCSS Nested] instead.\n\n```css\n.foo {\n\tcolor: red;\n\n\t&:hover {\n\t\tcolor: green;\n\t}\n\n\t> .bar {\n\t\tcolor: blue;\n\t}\n\n\t@media (prefers-color-scheme: dark) {\n\t\tcolor: cyan;\n\t}\n\n\tcolor: pink;\n}\n\n/* becomes */\n\n.foo {\n\tcolor: red;\n}\n.foo:hover {\n\t\tcolor: green;\n\t}\n.foo  > .bar {\n\t\tcolor: blue;\n\t}\n@media (prefers-color-scheme: dark) {\n\t.foo {\n\t\tcolor: cyan;\n}\n\t}\n.foo {\n\n\tcolor: pink;\n}\n```\n\n## Usage\n\nAdd [PostCSS Nesting] to your project:\n\n```bash\nnpm install postcss postcss-nesting --save-dev\n```\n\nUse it as a [PostCSS] plugin:\n\n```js\nconst postcss = require('postcss');\nconst postcssNesting = require('postcss-nesting');\n\npostcss([\n\tpostcssNesting(/* pluginOptions */)\n]).process(YOUR_CSS /*, processOptions */);\n```\n\n\n\n## Options\n\n### edition\n\nThe CSS nesting feature has gone through several iterations and what is currently implemented in browsers is not the same as what was originally proposed. This plugin dates back to the original proposal and you might have written your CSS expecting this older behavior.\n\nYou can pick the older behavior by setting the `edition` option.  \nThe `edition` values correspond with rough dates when of a particular version of the specification:\n- `2024-02` (default)\n- `2021`\n\n> [!TIP]\n> If you wrote nested rules with `@nest` you definitely want to set the `edition` to `2021`.  \n> If you are unsure than you should try to omit the `edition` option and use the default.\n\nEventually we will remove support for the older edition, and this plugin option, so it is strongly advised to update your CSS to the latest edition.\n\n\n```js\npostcssNesting({\n\tedition: '2024-02'\n})\n```\n\n#### `2024-02` (default)\n\n- usage of `:is()` pseudo-class in the generated CSS is no longer optional. However you can add [`postcss-is-pseudo-class`](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-is-pseudo-class) to transpile further\n- at rules are not combined with the `and` keyword\n- `@nest` is removed from the specification\n- declarations and nested rules/at-rules are no longer re-ordered\n\n#### `2021`\n\nThis version is a continuation of what existed before CSS nesting was implemented in browsers.  \nIt made a few non-invasive changes to keep up with implementations but it is falling behind.\n\n```css\n.foo {\n\tcolor: red;\n\n\t&:hover {\n\t\tcolor: green;\n\t}\n\n\t> .bar {\n\t\tcolor: blue;\n\t}\n\n\t@media (prefers-color-scheme: dark) {\n\t\tcolor: cyan;\n\t}\n\n\tcolor: pink;\n}\n\n/* becomes */\n\n.foo {\n\tcolor: red;\n\n\tcolor: pink;\n}\n.foo:hover {\n\t\tcolor: green;\n\t}\n.foo > .bar {\n\t\tcolor: blue;\n\t}\n@media (prefers-color-scheme: dark) {\n\t.foo {\n\t\tcolor: cyan;\n}\n\t}\n```\n\n### noIsPseudoSelector (edition: `2021`)\n\n#### Specificity\n\nBefore :\n\n```css\n#alpha,\n.beta {\n\t&:hover {\n\t\torder: 1;\n\t}\n}\n```\n\nAfter **without** the option :\n\n```js\npostcssNesting()\n```\n\n```css\n:is(#alpha,.beta):hover {\n\torder: 1;\n}\n```\n\n_`.beta:hover` has specificity as if `.beta` were an id selector, matching the specification._\n\n[specificity: 1, 1, 0](https://polypane.app/css-specificity-calculator/#selector=%3Ais(%23alpha%2C.beta)%3Ahover)\n\nAfter **with** the option :\n\n```js\npostcssNesting({\n\tnoIsPseudoSelector: true\n})\n```\n\n```css\n#alpha:hover, .beta:hover {\n\torder: 1;\n}\n```\n\n_`.beta:hover` has specificity as if `.beta` were a class selector, conflicting with the specification._\n\n[specificity: 0, 2, 0](https://polypane.app/css-specificity-calculator/#selector=.beta%3Ahover)\n\n\n#### Complex selectors\n\nBefore :\n\n```css\n.alpha > .beta {\n\t& + & {\n\t\torder: 2;\n\t}\n}\n```\n\nAfter **without** the option :\n\n```js\npostcssNesting()\n```\n\n```css\n:is(.alpha > .beta) + :is(.alpha > .beta) {\n\torder: 2;\n}\n```\n\nAfter **with** the option :\n\n```js\npostcssNesting({\n\tnoIsPseudoSelector: true\n})\n```\n\n```css\n.alpha > .beta + .alpha > .beta {\n\torder: 2;\n}\n```\n\n_this is a different selector than expected as `.beta + .alpha` matches `.beta` followed by `.alpha`._<br>\n_avoid these cases when you disable `:is()`._<br>\n_writing the selector without nesting is advised here._\n\n```css\n/* without nesting */\n.alpha > .beta + .beta {\n\torder: 2;\n}\n```\n\n[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test\n[css-url]: https://cssdb.org/#nesting-rules\n[discord]: https://discord.gg/bUadyRwkJS\n[npm-url]: https://www.npmjs.com/package/postcss-nesting\n\n[PostCSS]: https://github.com/postcss/postcss\n[PostCSS Nesting]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting\n[PostCSS Nested]: https://github.com/postcss/postcss-nested\n[Sass]: https://sass-lang.com/\n[CSS Nesting specification]: https://www.w3.org/TR/css-nesting-1/\n","publish_time":1749549858922,"_cnpm_publish_time":1749549858922,"dist-tags":{"latest":"14.0.3"}}