{"name":"postcss-custom-media","description":"Use Custom Media Queries in CSS","version":"12.0.1","contributors":[{"name":"Antonio Laguna","email":"antonio@laguna.es","url":"https://antonio.laguna.es"},{"name":"Romain Menke","email":"romainmenke@gmail.com"},{"name":"Jonathan Neal","email":"jonathantneal@hotmail.com"},{"name":"Maxime Thirouin"}],"license":"MIT","funding":[{"type":"github","url":"https://github.com/sponsors/csstools"},{"type":"opencollective","url":"https://opencollective.com/csstools"}],"engines":{"node":">=20.19.0"},"type":"module","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.mjs"}},"dependencies":{"@csstools/cascade-layer-name-parser":"^3.0.0","@csstools/css-parser-algorithms":"^4.0.0","@csstools/css-tokenizer":"^4.0.0","@csstools/media-query-list-parser":"^5.0.0"},"peerDependencies":{"postcss":"^8.4"},"scripts":{},"homepage":"https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-custom-media#readme","repository":{"type":"git","url":"git+https://github.com/csstools/postcss-plugins.git","directory":"plugins/postcss-custom-media"},"bugs":{"url":"https://github.com/csstools/postcss-plugins/issues"},"keywords":["at-rule","atrule","css","csswg","custom","media","postcss","postcss-plugin","queries","query","specification","w3c"],"gitHead":"2420eea00a1dd3894290652b0b13658b7e50894d","_id":"postcss-custom-media@12.0.1","_nodeVersion":"25.1.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-66syE14+VeqkUf0rRX0bvbTCbNRJF132jD+ceo8th1dap2YJEAqpdh5uG98CE3IbgHT7m9XM0GIlOazNWqQdeA==","shasum":"92ddc08c0f3140d82e64d26b8481b7be795031b4","tarball":"http://registry-npm.ywwl.com/postcss-custom-media/download/postcss-custom-media-12.0.1.tgz","fileCount":6,"unpackedSize":16560,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIA+LhL9hPyJwxgDnVDjrKp9rKpsC3DPTt3eVeFnboNskAiAbePUVxYD7fM7yETnwLjU64emrS6/BpHkXQof3fMV51Q=="}],"size":6249,"noattachment":false,"key":"/postcss-custom-media/-/postcss-custom-media-12.0.1.tgz"},"_npmUser":{"name":"romainmenke","email":"romainmenke@gmail.com"},"directories":{},"maintainers":[{"name":"jonathantneal","email":"jonathantneal@hotmail.com"},{"name":"alaguna","email":"sombragriselros@gmail.com"},{"name":"romainmenke","email":"romainmenke@gmail.com"},{"name":"moox","email":"npm@moox.io"},{"name":"semigradsky","email":"semigradskyd@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/postcss-custom-media_12.0.1_1771686344415_0.6714196218411932"},"_hasShrinkwrap":false,"readme":"# PostCSS Custom Media [<img src=\"https://postcss.github.io/postcss/logo.svg\" alt=\"PostCSS Logo\" width=\"90\" height=\"90\" align=\"right\">][PostCSS]\n\n`npm install postcss-custom-media --save-dev`\n\n[PostCSS Custom Media] lets you define `@custom-media` in CSS following the [Custom Media Specification].\n\n```css\n@custom-media --small-viewport (max-width: 30em);\n\n@media (--small-viewport) {\n\t/* styles for small viewport */\n}\n\n/* becomes */\n\n@media (max-width: 30em) {\n\t/* styles for small viewport */\n}\n```\n\n## `true` and `false`\n\nWith `@custom-media` you can use the constants `true` and `false`.\nThese are especially handy when debugging.\n\nIf you are unsure how your page is affected when a certain media query matches or not you can use these, to quickly toggle the results.\nThis plugin downgrades these queries to something that works in all browsers.\n\nQuickly check the result as if the query matches:\n\n```css\n@custom-media --small-viewport true;\n\n@media (--small-viewport) {\n\t/* styles for small viewport */\n}\n\n/* becomes */\n\n@media (max-color:2147477350) {\n\t/* styles for small viewport */\n}\n```\n\nQuickly check the result as if the query does not match:\n\n```css\n@custom-media --small-viewport false;\n\n@media (--small-viewport) {\n\t/* styles for small viewport */\n}\n\n/* becomes */\n\n@media (color:2147477350) {\n\t/* styles for small viewport */\n}\n```\n\n## logical evaluation of complex media queries\n\nIt is impossible to accurately and correctly resolve complex `@custom-media` queries\nas these depend on the browser the queries will eventually run in.\n\n_Some of these queries will have only one possible outcome but we have to account for all possible queries in this plugin._\n\n> [!NOTE]\n> When handling complex media queries you will see that your CSS is doubled for each level of complexity.<br>\n> GZIP works great to de-dupe this but having a lot of complex media queries will have a performance impact.\n\nAn example of a very complex (and artificial) use-case :\n\n```css\n\n@custom-media --a-complex-query tty and (min-width: 300px);\n\n@media not screen and ((not (--a-complex-query)) or (color)) {\n\t/* Your CSS */\n}\n\n/* becomes */\n\n\n@media tty and (min-width: 300px) {\n@media not screen and ((not (max-color:2147477350)) or (color)) {\n\t/* Your CSS */\n}\n}\n@media not tty,not all and (min-width: 300px) {\n@media not screen and ((not (color:2147477350)) or (color)) {\n\t/* Your CSS */\n}\n}\n```\n\n## Usage\n\nAdd [PostCSS Custom Media] to your project:\n\n```bash\nnpm install postcss postcss-custom-media --save-dev\n```\n\nUse it as a [PostCSS] plugin:\n\n```js\nconst postcss = require('postcss');\nconst postcssCustomMedia = require('postcss-custom-media');\n\npostcss([\n\tpostcssCustomMedia(/* pluginOptions */)\n]).process(YOUR_CSS /*, processOptions */);\n```\n\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\npostcssCustomMedia({ preserve: true })\n```\n\n```css\n@custom-media --small-viewport (max-width: 30em);\n\n@media (--small-viewport) {\n\t/* styles for small viewport */\n}\n\n/* becomes */\n\n@custom-media --small-viewport (max-width: 30em);\n\n@media (max-width: 30em) {\n\t/* styles for small viewport */\n}\n\n@media (--small-viewport) {\n\t/* styles for small viewport */\n}\n```\n\n## Modular CSS Processing\n\nIf you're using Modular CSS such as, CSS Modules, `postcss-loader` or `vanilla-extract` to name a few, you'll probably \nnotice that custom media queries are not being resolved. This happens because each file is processed separately so \nunless you import the custom media query definitions in each file, they won't be resolved.\n\nTo overcome this, we recommend using the [PostCSS Global Data](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-global-data#readme)\nplugin which allows you to pass a list of files that will be globally available. The plugin won't inject any extra code\nin the output but will provide the context needed to resolve custom media queries.\n\nFor it to run it needs to be placed before the [PostCSS Custom Media] plugin.\n\n```js\nconst postcss = require('postcss');\nconst postcssCustomMedia = require('postcss-custom-media');\nconst postcssGlobalData = require('@csstools/postcss-global-data');\n\npostcss([\n\tpostcssGlobalData({\n\t\tfiles: [\n\t\t\t'path/to/your/custom-media-queries.css'\n\t\t]\n\t}),\n\tpostcssCustomMedia(/* pluginOptions */)\n]).process(YOUR_CSS /*, processOptions */);\n```\n\n[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test\n[css-url]: https://cssdb.org/#custom-media-queries\n[discord]: https://discord.gg/bUadyRwkJS\n[npm-url]: https://www.npmjs.com/package/postcss-custom-media\n\n[PostCSS]: https://github.com/postcss/postcss\n[PostCSS Custom Media]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-custom-media\n[Custom Media Specification]: https://www.w3.org/TR/mediaqueries-5/#at-ruledef-custom-media\n","publish_time":1771686344564,"_cnpm_publish_time":1771686344564,"dist-tags":{"latest":"12.0.4"}}