diff options
Diffstat (limited to 'node_modules/postcss-custom-media')
16 files changed, 609 insertions, 0 deletions
diff --git a/node_modules/postcss-custom-media/CHANGELOG.md b/node_modules/postcss-custom-media/CHANGELOG.md new file mode 100644 index 00000000..e673ad2e --- /dev/null +++ b/node_modules/postcss-custom-media/CHANGELOG.md @@ -0,0 +1,228 @@ +# Changes to PostCSS Custom Media + +### 10.0.2 + +_October 9, 2023_ + +- Updated [`@csstools/css-tokenizer`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-tokenizer) to [`2.2.1`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-tokenizer/CHANGELOG.md#221) (patch) +- Updated [`@csstools/css-parser-algorithms`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-parser-algorithms) to [`2.3.2`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-parser-algorithms/CHANGELOG.md#232) (patch) +- Updated [`@csstools/cascade-layer-name-parser`](https://github.com/csstools/postcss-plugins/tree/main/packages/cascade-layer-name-parser) to [`1.0.5`](https://github.com/csstools/postcss-plugins/tree/main/packages/cascade-layer-name-parser/CHANGELOG.md#105) (patch) +- Updated [`@csstools/media-query-list-parser`](https://github.com/csstools/postcss-plugins/tree/main/packages/media-query-list-parser) to [`2.1.5`](https://github.com/csstools/postcss-plugins/tree/main/packages/media-query-list-parser/CHANGELOG.md#215) (patch) + +### 10.0.1 + +_September 18, 2023_ + +- Updated [`@csstools/css-tokenizer`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-tokenizer) to [`2.2.0`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-tokenizer/CHANGELOG.md#220) (minor) +- Updated [`@csstools/css-parser-algorithms`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-parser-algorithms) to [`2.3.1`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-parser-algorithms/CHANGELOG.md#231) (patch) +- Updated [`@csstools/cascade-layer-name-parser`](https://github.com/csstools/postcss-plugins/tree/main/packages/cascade-layer-name-parser) to [`1.0.4`](https://github.com/csstools/postcss-plugins/tree/main/packages/cascade-layer-name-parser/CHANGELOG.md#104) (patch) +- Updated [`@csstools/media-query-list-parser`](https://github.com/csstools/postcss-plugins/tree/main/packages/media-query-list-parser) to [`2.1.4`](https://github.com/csstools/postcss-plugins/tree/main/packages/media-query-list-parser/CHANGELOG.md#214) (patch) + +### 10.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/css-parser-algorithms`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-parser-algorithms) to [`2.3.0`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-parser-algorithms/CHANGELOG.md#230) (minor) +- Updated [`@csstools/cascade-layer-name-parser`](https://github.com/csstools/postcss-plugins/tree/main/packages/cascade-layer-name-parser) to [`1.0.3`](https://github.com/csstools/postcss-plugins/tree/main/packages/cascade-layer-name-parser/CHANGELOG.md#103) (patch) +- Updated [`@csstools/media-query-list-parser`](https://github.com/csstools/postcss-plugins/tree/main/packages/media-query-list-parser) to [`2.1.2`](https://github.com/csstools/postcss-plugins/tree/main/packages/media-query-list-parser/CHANGELOG.md#212) (patch) + +### 9.1.5 + +_June 21, 2023_ + +- Updated `@csstools/media-query-list-parser` to `2.1.1` (patch) + + +### 9.1.4 + +_June 1, 2023_ + +- Updated `@csstools/media-query-list-parser` to `2.1.0` (minor) + + +### 9.1.3 + +_April 10, 2023_ + +- Updated `@csstools/css-tokenizer` to `2.1.1` (patch) +- Updated `@csstools/css-parser-algorithms` to `2.1.1` (patch) +- Updated `@csstools/cascade-layer-name-parser` to `1.0.2` (patch) +- Updated `@csstools/media-query-list-parser` to `2.0.4` (patch) + +### 9.1.2 + +_February 8, 2023_ + +- Fixed: exception on missing media queries. +- Reduce the amount of duplicate fallback CSS. + +### 9.1.1 + +_January 28, 2023_ + +- Improve `types` declaration in `package.json` + +### 9.1.0 + +_January 24, 2023_ + +- Added: Support for Cascade Layers. + +### 9.0.1 + +_November 19, 2022_ + +- Fixed: avoid complex generated CSS when `@custom-media` contains only a single simple media feature. + +### 9.0.0 + +_November 14, 2022_ + +- Updated: Support for Node v14+ (major). +- Removed: `importFrom` feature (breaking). +- Removed: `exportTo` feature (breaking). +- Removed: References without parenthesis `@media --foo {}` (breaking). +- Fixed: implement logical evaluation of custom media queries. +- Added: Support for `true` and `false` keywords in `@custom-media`. + +### 8.0.2 + +_June 4, 2022_ + +- Fixed: dependency declarations in package.json + +### 8.0.1 + +_June 3, 2022_ + +- Updated: use specific AtRule visitor +- Fixed: allow any valid ident in custom media (`@custom-media --🧑🏾🎤 (min-width: 320px);`) +- Fixed: allow white space around custom media (`@media ( --mq-1 );`) (https://github.com/csstools/postcss-custom-media/pull/59) (https://github.com/csstools/postcss-custom-media/pull/71) + +### 8.0.0 + +_January 12, 2021_ + +- Added: Support for PostCSS v8 + +### 7.0.8 + +_March 30, 2019_ + +- Fixed: Issue importing from `.pcss` files +- Updated: `postcss` to 7.0.14 (patch) + +### 7.0.7 + +_October 19, 2018_ + +- Fixed: Issue combining custom media media queries with `and` + +### 7.0.6 + +_October 12, 2018_ + +- Fixed: Issue combining multiple custom media + +### 7.0.5 + +_October 5, 2018_ + +- Fixed: Possible issues resolving paths to imports and exports +- Added: Imports from `customMedia` and `custom-media` simultaneously +- Updated: `postcss` to 7.0.5 + +### 7.0.4 + +_September 23, 2018_ + +- Added: `importFromPlugins` option to process imports + +### 7.0.3 + +_September 20, 2018_ + +- Fixed: Do not break on an empty `importFrom` object + +### 7.0.2 + +_September 15, 2018_ + +- Fixed: An issue with re-assigning params as a non-string + +### 7.0.1 + +_September 14, 2018_ + +- Fixed: An issue with how opposing queries are resolved. + +### 7.0.0 + +_September 14, 2018_ + +- Added: New `preserve` option to preserve custom media and atrules using them +- Added: New `exportTo` function to specify where to export custom media +- Added: New `importFrom` option to specify where to import custom media +- Added: Support for PostCSS v7 +- Added: Support for Node v6+ + +# 6.0.0 (May 12, 2017) + +- Added: compatibility with postcss v6.x + +# 5.0.1 (February 3, 2016) + +- Fixed: circular dependencies are properly detected +(https://github.com/postcss/postcss-custom-media/pull/17) + +# 5.0.0 (August 25, 2015) + +- Removed: compatibility with postcss v4.x +- Added: compatibility with postcss v5.x + +# 4.1.0 (06 30, 2015) + +- Added: Allow custom media to reference each other +(https://github.com/postcss/postcss-custom-media/pull/10) + +# 4.0.0 (May 17, 2015) + +- Changed: warning messages are now sent via postcss messages api (^4.1.0) +- Added: automatic custom media `--` prefixing +(https://github.com/postcss/postcss-custom-media/issues/11) +- Added: `preserve` allows you to preserve custom media query defintions +- Added: `appendExtensions` allows you (when `preserve` is truthy) to append your extensions as media queries + +# 3.0.0 (January 29, 2015) + +- Added: compatibility with postcss v4.x +- Removed: compatibility with postcss v3.x + +# 2.0.0 [Yanked] + +_You never saw this version (this is a bad release that points to 1.0.0)._ + +# 1.3.0 (November 25, 2014) + +- Changed: better gnu message + +# 1.2.1 (October 9, 2014) + +- Fixed: npm description + +# 1.2.0 (October 1, 2014) + +- Added: support for multiples media in query list (ref https://github.com/reworkcss/rework-custom-media/pull/5) + +# 1.1.0 (September 30, 2014) + +- Added: support for js-defined media queries (fix https://github.com/postcss/postcss-custom-media/issues/3) + +# 1.0.1 (September 16, 2014) + +- Added: Allow whitespace around custom media name (fix https://github.com/postcss/postcss-custom-media/issues/2) + +# 1.0.0 (August 12, 2014) + +✨ First release based on https://github.com/reworkcss/rework-custom-media v0.1.1 diff --git a/node_modules/postcss-custom-media/LICENSE.md b/node_modules/postcss-custom-media/LICENSE.md new file mode 100644 index 00000000..6d704708 --- /dev/null +++ b/node_modules/postcss-custom-media/LICENSE.md @@ -0,0 +1,21 @@ +# The MIT License (MIT) + +Copyright © PostCSS + +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, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +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/postcss-custom-media/README.md b/node_modules/postcss-custom-media/README.md new file mode 100644 index 00000000..4290866e --- /dev/null +++ b/node_modules/postcss-custom-media/README.md @@ -0,0 +1,195 @@ +# PostCSS Custom Media [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][PostCSS] + +[<img alt="npm version" src="https://img.shields.io/npm/v/postcss-custom-media.svg" height="20">][npm-url] [<img alt="CSS Standard Status" src="https://cssdb.org/images/badges/custom-media-queries.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] + +```bash +npm install postcss-custom-media --save-dev +``` + +[PostCSS Custom Media] lets you define `@custom-media` in CSS following the [Custom Media Specification]. + +```pcss +@custom-media --small-viewport (max-width: 30em); + +@media (--small-viewport) { + /* styles for small viewport */ +} + +/* becomes */ + +@media (max-width: 30em) { + /* styles for small viewport */ +} +``` + +## `true` and `false` + +With `@custom-media` you can use the constants `true` and `false`. +These are especially handy when debugging. + +If 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. +This plugin downgrades these queries to something that works in all browsers. + +Quickly check the result as if the query matches: + +```pcss +@custom-media --small-viewport true; + +@media (--small-viewport) { + /* styles for small viewport */ +} + +/* becomes */ + +@media (max-color:2147477350) { + /* styles for small viewport */ +} +``` + +Quickly check the result as if the query does not match: + +```pcss +@custom-media --small-viewport false; + +@media (--small-viewport) { + /* styles for small viewport */ +} + +/* becomes */ + +@media (color:2147477350) { + /* styles for small viewport */ +} +``` + +## logical evaluation of complex media queries + +It is impossible to accurately and correctly resolve complex `@custom-media` queries +as these depend on the browser the queries will eventually run in. + +_Some of these queries will have only one possible outcome but we have to account for all possible queries in this plugin._ + +⚠️ When handling complex media queries you will see that your CSS is doubled for each level of complexity.<br> +GZIP works great to de-dupe this but having a lot of complex media queries will have a performance impact. + +An example of a very complex (and artificial) use-case : + +```pcss + +@custom-media --a-complex-query tty and (min-width: 300px); + +@media not screen and ((not (--a-complex-query)) or (color)) { + /* Your CSS */ +} + +/* becomes */ + + +@media tty and (min-width: 300px) { +@media not screen and ((not (max-color:2147477350)) or (color)) { + /* Your CSS */ +} +} +@media not tty and (min-width: 300px) { +@media not screen and ((not (color:2147477350)) or (color)) { + /* Your CSS */ +} +} +``` + +## Usage + +Add [PostCSS Custom Media] to your project: + +```bash +npm install postcss postcss-custom-media --save-dev +``` + +Use it as a [PostCSS] plugin: + +```js +const postcss = require('postcss'); +const postcssCustomMedia = require('postcss-custom-media'); + +postcss([ + postcssCustomMedia(/* pluginOptions */) +]).process(YOUR_CSS /*, processOptions */); +``` + +[PostCSS Custom Media] runs in all Node environments, with special +instructions for: + +- [Node](INSTALL.md#node) +- [PostCSS CLI](INSTALL.md#postcss-cli) +- [PostCSS Load Config](INSTALL.md#postcss-load-config) +- [Webpack](INSTALL.md#webpack) +- [Next.js](INSTALL.md#nextjs) +- [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 +postcssCustomMedia({ preserve: true }) +``` + +```pcss +@custom-media --small-viewport (max-width: 30em); + +@media (--small-viewport) { + /* styles for small viewport */ +} + +/* becomes */ + +@custom-media --small-viewport (max-width: 30em); + +@media (max-width: 30em) { + /* styles for small viewport */ +} + +@media (--small-viewport) { + /* styles for small viewport */ +} +``` + +## Modular CSS Processing + +If you're using Modular CSS such as, CSS Modules, `postcss-loader` or `vanilla-extract` to name a few, you'll probably +notice that custom media queries are not being resolved. This happens because each file is processed separately so +unless you import the custom media query definitions in each file, they won't be resolved. + +To overcome this, we recommend using the [PostCSS Global Data](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-global-data#readme) +plugin which allows you to pass a list of files that will be globally available. The plugin won't inject any extra code +in the output but will provide the context needed to resolve custom media queries. + +For it to run it needs to be placed before the [PostCSS Custom Media] plugin. + +```js +const postcss = require('postcss'); +const postcssCustomMedia = require('postcss-custom-media'); +const postcssGlobalData = require('@csstools/postcss-global-data'); + +postcss([ + postcssGlobalData({ + files: [ + 'path/to/your/custom-media-queries.css' + ] + }), + postcssCustomMedia(/* pluginOptions */) +]).process(YOUR_CSS /*, processOptions */); +``` + +[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test +[css-url]: https://cssdb.org/#custom-media-queries +[discord]: https://discord.gg/bUadyRwkJS +[npm-url]: https://www.npmjs.com/package/postcss-custom-media + +[PostCSS]: https://github.com/postcss/postcss +[PostCSS Custom Media]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-custom-media +[Custom Media Specification]: https://www.w3.org/TR/mediaqueries-5/#at-ruledef-custom-media diff --git a/node_modules/postcss-custom-media/dist/cascade-layers.d.ts b/node_modules/postcss-custom-media/dist/cascade-layers.d.ts new file mode 100644 index 00000000..b9891949 --- /dev/null +++ b/node_modules/postcss-custom-media/dist/cascade-layers.d.ts @@ -0,0 +1,3 @@ +import type { Node, Root } from 'postcss'; +export declare function collectCascadeLayerOrder(root: Root): WeakMap<Node, number>; +export declare function cascadeLayerNumberForNode(node: Node, layers: WeakMap<Node, number>): number; diff --git a/node_modules/postcss-custom-media/dist/custom-media-from-root.d.ts b/node_modules/postcss-custom-media/dist/custom-media-from-root.d.ts new file mode 100644 index 00000000..f248ed93 --- /dev/null +++ b/node_modules/postcss-custom-media/dist/custom-media-from-root.d.ts @@ -0,0 +1,8 @@ +import { MediaQuery } from '@csstools/media-query-list-parser'; +import type { Result, Root as PostCSSRoot } from 'postcss'; +export default function getCustomMedia(root: PostCSSRoot, result: Result, opts: { + preserve?: boolean; +}): Map<string, { + truthy: Array<MediaQuery>; + falsy: Array<MediaQuery>; +}>; diff --git a/node_modules/postcss-custom-media/dist/index.cjs b/node_modules/postcss-custom-media/dist/index.cjs new file mode 100644 index 00000000..b1c9e8d6 --- /dev/null +++ b/node_modules/postcss-custom-media/dist/index.cjs @@ -0,0 +1 @@ +"use strict";var e=require("@csstools/cascade-layer-name-parser"),r=require("@csstools/css-tokenizer"),t=require("@csstools/media-query-list-parser");const n=e.parse("csstools-implicit-layer")[0];function collectCascadeLayerOrder(r){const t=new Map,o=new Map,a=[];r.walkAtRules((r=>{var s;if("layer"!==r.name.toLowerCase())return;{let e=r.parent;for(;e;){if("atrule"!==e.type||"layer"!==e.name.toLowerCase()){if(e===r.root())break;return}e=e.parent}}let i;if(r.nodes)i=normalizeLayerName(r.params,1);else{if(!r.params.trim())return;i=r.params}let l=e.parse(i);if(null!=(s=l)&&s.length){{let e=r.parent;for(;e&&"atrule"===e.type&&"layer"===e.name.toLowerCase();){const r=o.get(e);r?(l=l.map((e=>r.concat(e))),e=e.parent):e=e.parent}}if(e.addLayerToModel(a,l),r.nodes){const e=l[0].concat(n);t.set(r,e),o.set(r,l[0])}}}));for(const r of t.values())e.addLayerToModel(a,[r]);const s=new WeakMap;for(const[e,r]of t)s.set(e,a.findIndex((e=>r.equal(e))));return s}function normalizeLayerName(e,r){return e.trim()?e:"csstools-anon-layer--"+r++}const o=new Set(["scope","container","layer"]);function isProcessableCustomMediaRule(e){if("custom-media"!==e.name.toLowerCase())return!1;if(!e.params||!e.params.includes("--"))return!1;if(e.nodes&&e.nodes.length>0)return!1;let r=e.parent;for(;r;){if("atrule"===r.type&&!o.has(r.name.toLowerCase()))return!1;r=r.parent}return!0}function removeCyclicReferences(e,r){const t=new Set;let n=r;for(;e.size>0;)try{toposort(Array.from(e.keys()),n);break}catch(r){if(!r._graphNode)throw r;e.delete(r._graphNode),t.add(r._graphNode),n=n.filter((e=>-1===e.indexOf(r._graphNode)))}return t}function toposort(e,r){let t=e.length;const n=new Array(t),o={};let a=t;const s=makeOutgoingEdges(r),i=makeNodesHash(e);for(;a--;)o[a]||visit(e[a],a,new Set);return n;function visit(e,r,a){if(a.has(e)){const r=new Error("Cyclic dependency"+JSON.stringify(e));throw r._graphNode=e,r}if(!i.has(e))return;if(o[r])return;o[r]=!0;let l=s.get(e)||new Set;if(l=Array.from(l),r=l.length){a.add(e);do{const e=l[--r];visit(e,i.get(e),a)}while(r);a.delete(e)}n[--t]=e}}function makeOutgoingEdges(e){const r=new Map;for(let t=0,n=e.length;t<n;t++){const n=e[t];r.has(n[0])||r.set(n[0],new Set),r.has(n[1])||r.set(n[1],new Set),r.get(n[0]).add(n[1])}return r}function makeNodesHash(e){const r=new Map;for(let t=0,n=e.length;t<n;t++)r.set(e[t],t);return r}function atMediaParamsTokens(e){const t=r.tokenizer({css:e},{onParseError:()=>{throw new Error(`Unable to parse media query "${e}"`)}}),n=[];for(;!t.endOfFile();)n.push(t.nextToken());return n}const a=[[r.TokenType.Ident,"max-color",0,0,{value:"max-color"}],[r.TokenType.Colon,":",0,0,void 0],[r.TokenType.Number,"2147477350",0,0,{value:2147477350,type:r.NumberType.Integer}]],s=[[r.TokenType.Ident,"color",0,0,{value:"color"}],[r.TokenType.Colon,":",0,0,void 0],[r.TokenType.Number,"2147477350",0,0,{value:2147477350,type:r.NumberType.Integer}]];function replaceTrueAndFalseTokens(e){let t,n=[];for(let o=0;o<e.length;o++)if(e[o][0]!==r.TokenType.Comment&&e[o][0]!==r.TokenType.Whitespace){if(e[o][0]===r.TokenType.Ident){const r=e[o];if("true"===r[4].value.toLowerCase()){t="true",n=e.slice(o+1);break}if("false"===r[4].value.toLowerCase()){t="false",n=e.slice(o+1);break}}return e}if(!t)return e;for(let t=0;t<n.length;t++)if(n[t][0]!==r.TokenType.Comment&&n[t][0]!==r.TokenType.Whitespace)return e;return"true"===t?[[r.TokenType.Whitespace," ",0,0,void 0],[r.TokenType.OpenParen,"(",0,0,void 0],...a,[r.TokenType.CloseParen,")",0,0,void 0]]:[[r.TokenType.Whitespace," ",0,0,void 0],[r.TokenType.OpenParen,"(",0,0,void 0],...s,[r.TokenType.CloseParen,")",0,0,void 0]]}function parseCustomMedia(e){const n=atMediaParamsTokens(e),o=new Set;let a="",s=n;for(let e=0;e<n.length;e++)if(n[e][0]!==r.TokenType.Comment&&n[e][0]!==r.TokenType.Whitespace){if(n[e][0]===r.TokenType.Ident){const r=n[e];if(r[4].value.startsWith("--")){a=r[4].value,s=n.slice(e+1);break}}return!1}for(let e=0;e<s.length;e++)if(s[e][0]===r.TokenType.Ident){const r=s[e];r[4].value.startsWith("--")&&o.add(r[4].value)}s=replaceTrueAndFalseTokens(s);const i=t.parseFromTokens(r.cloneTokens(s),{preserveInvalidMediaQueries:!0,onParseError:()=>{throw new Error(`Unable to parse media query "${r.stringify(...s)}"`)}}),l=t.parseFromTokens(r.cloneTokens(s),{preserveInvalidMediaQueries:!0,onParseError:()=>{throw new Error(`Unable to parse media query "${r.stringify(...s)}"`)}});for(let e=0;e<l.length;e++)l[e]=l[e].negateQuery();return{name:a,truthy:i,falsy:l,dependsOn:Array.from(o).map((e=>[e,a]))}}function getCustomMedia(e,r,t){const n=new Map,o=new Map,a=[],s=collectCascadeLayerOrder(e);e.walkAtRules((e=>{if(!isProcessableCustomMediaRule(e))return;const r=parseCustomMedia(e.params);if(!r)return;if(0===r.truthy.length)return;const i=(u=s,(l=e).parent&&"atrule"===l.parent.type&&"layer"===l.parent.name.toLowerCase()?u.has(l.parent)?u.get(l.parent)+1:0:1e7);var l,u;const c=o.get(r.name)??-1;if(i&&i>=c&&(o.set(r.name,i),n.set(r.name,{truthy:r.truthy,falsy:r.falsy}),a.push(...r.dependsOn)),!t.preserve){const r=e.parent;e.remove(),removeEmptyAncestorBlocks(r)}}));const i=removeCyclicReferences(n,a);for(const t of i.values())e.warn(r,`@custom-media rules have cyclic dependencies for "${t}"`);return n}function removeEmptyAncestorBlocks(e){if(!e)return;let r=e;for(;r;){if(r.nodes&&r.nodes.length>0)return;const e=r.parent;r.remove(),r=e}}function transformAtMediaListTokens(e,r){const n=t.parse(e,{preserveInvalidMediaQueries:!0,onParseError:()=>{throw new Error(`Unable to parse media query "${e}"`)}}),o=n.map((e=>e.toString()));for(let e=0;e<n.length;e++){const t=n[e],a=o[e];{const n=transformSimpleMediaQuery(t,r);if(n&&n.replaceWith!==a)return o.map(((r,t)=>t===e?n:{replaceWith:r}))}const s=transformComplexMediaQuery(t,r);if(s&&0!==s.length&&s[0].replaceWith!==a)return o.flatMap(((r,t)=>t===e?s:[{replaceWith:r}]))}return[]}function transformSimpleMediaQuery(e,r){if(!mediaQueryIsSimple(e))return null;let n=null;return e.walk((e=>{const o=e.node;if(!t.isMediaFeatureBoolean(o))return;const a=o.getName();if(!a.startsWith("--"))return!1;const s=r.get(a);return s?(n={replaceWith:s.truthy.map((e=>e.toString().trim())).join(",")},!1):void 0})),n}function transformComplexMediaQuery(e,r){let n=[];return e.walk((o=>{const i=o.node;if(!t.isMediaFeatureBoolean(i))return;const l=o.parent;if(!t.isMediaFeature(l))return;const u=i.getName();if(!u.startsWith("--"))return!1;const c=r.get(u);if(c){if(1===c.truthy.length&&mediaQueryIsSimple(c.truthy[0])){let r=null;if(c.truthy[0].walk((e=>{if(t.isMediaFeature(e.node))return r=e.node,!1})),r&&r.feature)return l.feature=r.feature,n=[{replaceWith:e.toString()}],!1}const r=t.newMediaFeaturePlain(a[0][4].value,a[2]);l.feature=r.feature;const o=e.toString(),i=t.newMediaFeaturePlain(s[0][4].value,s[2]);l.feature=i.feature;const u=e.toString();return n=[{replaceWith:o,encapsulateWith:c.truthy.map((e=>e.toString().trim())).join(",")},{replaceWith:u,encapsulateWith:c.falsy.map((e=>e.toString().trim())).join(",")}],!1}})),n}function mediaQueryIsSimple(e){if(t.isMediaQueryInvalid(e))return!1;if(t.isMediaQueryWithType(e))return!1;let r=!0;return e.walk((e=>{if(t.isMediaAnd(e.node)||t.isMediaOr(e.node)||t.isMediaNot(e.node)||t.isMediaConditionList(e.node)||t.isGeneralEnclosed(e.node))return r=!1,!1})),r}const creator=e=>{const r=Boolean(Object(e).preserve);if("importFrom"in Object(e))throw new Error('[postcss-custom-media] "importFrom" is no longer supported');if("exportTo"in Object(e))throw new Error('[postcss-custom-media] "exportTo" is no longer supported');return{postcssPlugin:"postcss-custom-media",prepare(){const e=new WeakSet;let t=new Map;return{Once:(e,{result:n})=>{t=getCustomMedia(e,n,{preserve:r})},AtRule:(n,{result:o})=>{if(e.has(n))return;if("media"!==n.name.toLowerCase())return;if(!n.params)return;if(!n.params.includes("--"))return;let a=[];try{a=transformAtMediaListTokens(n.params,t)}catch(e){return void n.warn(o,`Failed to parse @custom-media params with error message: "${e.message}"`)}if(!a||0===a.length)return;if(1===a.length){if(n.params.trim()===a[0].replaceWith.trim())return;return e.add(n),n.cloneBefore({params:a[0].replaceWith.trim()}),r?void 0:void n.remove()}if(!!!a.find((e=>!!e.encapsulateWith)))return e.add(n),n.cloneBefore({params:a.map((e=>e.replaceWith)).join(",").trim()}),void(r||n.remove());a.forEach((r=>{if(!r.encapsulateWith)return void n.cloneBefore({params:r.replaceWith.trim()});const t=n.clone({params:r.replaceWith}),o=n.clone({params:r.encapsulateWith.trim(),nodes:[]});t.parent=void 0,o.parent=void 0,e.add(n),o.append(t),n.before(o)})),r||n.remove()}}}}};creator.postcss=!0,module.exports=creator; diff --git a/node_modules/postcss-custom-media/dist/index.d.ts b/node_modules/postcss-custom-media/dist/index.d.ts new file mode 100644 index 00000000..79f6f1e7 --- /dev/null +++ b/node_modules/postcss-custom-media/dist/index.d.ts @@ -0,0 +1,8 @@ +import type { PluginCreator } from 'postcss'; +/** postcss-custom-media plugin options */ +export type pluginOptions = { + /** Preserve the original notation. default: false */ + preserve?: boolean; +}; +declare const creator: PluginCreator<pluginOptions>; +export default creator; diff --git a/node_modules/postcss-custom-media/dist/index.mjs b/node_modules/postcss-custom-media/dist/index.mjs new file mode 100644 index 00000000..e9a7ad25 --- /dev/null +++ b/node_modules/postcss-custom-media/dist/index.mjs @@ -0,0 +1 @@ +import{parse as e,addLayerToModel as r}from"@csstools/cascade-layer-name-parser";import{tokenizer as t,TokenType as n,NumberType as a,cloneTokens as o,stringify as s}from"@csstools/css-tokenizer";import{parseFromTokens as i,parse as l,isMediaFeatureBoolean as u,isMediaFeature as c,newMediaFeaturePlain as p,isMediaQueryInvalid as f,isMediaQueryWithType as m,isMediaAnd as d,isMediaOr as h,isMediaNot as y,isMediaConditionList as g,isGeneralEnclosed as v}from"@csstools/media-query-list-parser";const w=e("csstools-implicit-layer")[0];function collectCascadeLayerOrder(t){const n=new Map,a=new Map,o=[];t.walkAtRules((t=>{var s;if("layer"!==t.name.toLowerCase())return;{let e=t.parent;for(;e;){if("atrule"!==e.type||"layer"!==e.name.toLowerCase()){if(e===t.root())break;return}e=e.parent}}let i;if(t.nodes)i=normalizeLayerName(t.params,1);else{if(!t.params.trim())return;i=t.params}let l=e(i);if(null!=(s=l)&&s.length){{let e=t.parent;for(;e&&"atrule"===e.type&&"layer"===e.name.toLowerCase();){const r=a.get(e);r?(l=l.map((e=>r.concat(e))),e=e.parent):e=e.parent}}if(r(o,l),t.nodes){const e=l[0].concat(w);n.set(t,e),a.set(t,l[0])}}}));for(const e of n.values())r(o,[e]);const s=new WeakMap;for(const[e,r]of n)s.set(e,o.findIndex((e=>r.equal(e))));return s}function normalizeLayerName(e,r){return e.trim()?e:"csstools-anon-layer--"+r++}const C=new Set(["scope","container","layer"]);function isProcessableCustomMediaRule(e){if("custom-media"!==e.name.toLowerCase())return!1;if(!e.params||!e.params.includes("--"))return!1;if(e.nodes&&e.nodes.length>0)return!1;let r=e.parent;for(;r;){if("atrule"===r.type&&!C.has(r.name.toLowerCase()))return!1;r=r.parent}return!0}function removeCyclicReferences(e,r){const t=new Set;let n=r;for(;e.size>0;)try{toposort(Array.from(e.keys()),n);break}catch(r){if(!r._graphNode)throw r;e.delete(r._graphNode),t.add(r._graphNode),n=n.filter((e=>-1===e.indexOf(r._graphNode)))}return t}function toposort(e,r){let t=e.length;const n=new Array(t),a={};let o=t;const s=makeOutgoingEdges(r),i=makeNodesHash(e);for(;o--;)a[o]||visit(e[o],o,new Set);return n;function visit(e,r,o){if(o.has(e)){const r=new Error("Cyclic dependency"+JSON.stringify(e));throw r._graphNode=e,r}if(!i.has(e))return;if(a[r])return;a[r]=!0;let l=s.get(e)||new Set;if(l=Array.from(l),r=l.length){o.add(e);do{const e=l[--r];visit(e,i.get(e),o)}while(r);o.delete(e)}n[--t]=e}}function makeOutgoingEdges(e){const r=new Map;for(let t=0,n=e.length;t<n;t++){const n=e[t];r.has(n[0])||r.set(n[0],new Set),r.has(n[1])||r.set(n[1],new Set),r.get(n[0]).add(n[1])}return r}function makeNodesHash(e){const r=new Map;for(let t=0,n=e.length;t<n;t++)r.set(e[t],t);return r}function atMediaParamsTokens(e){const r=t({css:e},{onParseError:()=>{throw new Error(`Unable to parse media query "${e}"`)}}),n=[];for(;!r.endOfFile();)n.push(r.nextToken());return n}const W=[[n.Ident,"max-color",0,0,{value:"max-color"}],[n.Colon,":",0,0,void 0],[n.Number,"2147477350",0,0,{value:2147477350,type:a.Integer}]],k=[[n.Ident,"color",0,0,{value:"color"}],[n.Colon,":",0,0,void 0],[n.Number,"2147477350",0,0,{value:2147477350,type:a.Integer}]];function replaceTrueAndFalseTokens(e){let r,t=[];for(let a=0;a<e.length;a++)if(e[a][0]!==n.Comment&&e[a][0]!==n.Whitespace){if(e[a][0]===n.Ident){const n=e[a];if("true"===n[4].value.toLowerCase()){r="true",t=e.slice(a+1);break}if("false"===n[4].value.toLowerCase()){r="false",t=e.slice(a+1);break}}return e}if(!r)return e;for(let r=0;r<t.length;r++)if(t[r][0]!==n.Comment&&t[r][0]!==n.Whitespace)return e;return"true"===r?[[n.Whitespace," ",0,0,void 0],[n.OpenParen,"(",0,0,void 0],...W,[n.CloseParen,")",0,0,void 0]]:[[n.Whitespace," ",0,0,void 0],[n.OpenParen,"(",0,0,void 0],...k,[n.CloseParen,")",0,0,void 0]]}function parseCustomMedia(e){const r=atMediaParamsTokens(e),t=new Set;let a="",l=r;for(let e=0;e<r.length;e++)if(r[e][0]!==n.Comment&&r[e][0]!==n.Whitespace){if(r[e][0]===n.Ident){const t=r[e];if(t[4].value.startsWith("--")){a=t[4].value,l=r.slice(e+1);break}}return!1}for(let e=0;e<l.length;e++)if(l[e][0]===n.Ident){const r=l[e];r[4].value.startsWith("--")&&t.add(r[4].value)}l=replaceTrueAndFalseTokens(l);const u=i(o(l),{preserveInvalidMediaQueries:!0,onParseError:()=>{throw new Error(`Unable to parse media query "${s(...l)}"`)}}),c=i(o(l),{preserveInvalidMediaQueries:!0,onParseError:()=>{throw new Error(`Unable to parse media query "${s(...l)}"`)}});for(let e=0;e<c.length;e++)c[e]=c[e].negateQuery();return{name:a,truthy:u,falsy:c,dependsOn:Array.from(t).map((e=>[e,a]))}}function getCustomMedia(e,r,t){const n=new Map,a=new Map,o=[],s=collectCascadeLayerOrder(e);e.walkAtRules((e=>{if(!isProcessableCustomMediaRule(e))return;const r=parseCustomMedia(e.params);if(!r)return;if(0===r.truthy.length)return;const i=(u=s,(l=e).parent&&"atrule"===l.parent.type&&"layer"===l.parent.name.toLowerCase()?u.has(l.parent)?u.get(l.parent)+1:0:1e7);var l,u;const c=a.get(r.name)??-1;if(i&&i>=c&&(a.set(r.name,i),n.set(r.name,{truthy:r.truthy,falsy:r.falsy}),o.push(...r.dependsOn)),!t.preserve){const r=e.parent;e.remove(),removeEmptyAncestorBlocks(r)}}));const i=removeCyclicReferences(n,o);for(const t of i.values())e.warn(r,`@custom-media rules have cyclic dependencies for "${t}"`);return n}function removeEmptyAncestorBlocks(e){if(!e)return;let r=e;for(;r;){if(r.nodes&&r.nodes.length>0)return;const e=r.parent;r.remove(),r=e}}function transformAtMediaListTokens(e,r){const t=l(e,{preserveInvalidMediaQueries:!0,onParseError:()=>{throw new Error(`Unable to parse media query "${e}"`)}}),n=t.map((e=>e.toString()));for(let e=0;e<t.length;e++){const a=t[e],o=n[e];{const t=transformSimpleMediaQuery(a,r);if(t&&t.replaceWith!==o)return n.map(((r,n)=>n===e?t:{replaceWith:r}))}const s=transformComplexMediaQuery(a,r);if(s&&0!==s.length&&s[0].replaceWith!==o)return n.flatMap(((r,t)=>t===e?s:[{replaceWith:r}]))}return[]}function transformSimpleMediaQuery(e,r){if(!mediaQueryIsSimple(e))return null;let t=null;return e.walk((e=>{const n=e.node;if(!u(n))return;const a=n.getName();if(!a.startsWith("--"))return!1;const o=r.get(a);return o?(t={replaceWith:o.truthy.map((e=>e.toString().trim())).join(",")},!1):void 0})),t}function transformComplexMediaQuery(e,r){let t=[];return e.walk((n=>{const a=n.node;if(!u(a))return;const o=n.parent;if(!c(o))return;const s=a.getName();if(!s.startsWith("--"))return!1;const i=r.get(s);if(i){if(1===i.truthy.length&&mediaQueryIsSimple(i.truthy[0])){let r=null;if(i.truthy[0].walk((e=>{if(c(e.node))return r=e.node,!1})),r&&r.feature)return o.feature=r.feature,t=[{replaceWith:e.toString()}],!1}const r=p(W[0][4].value,W[2]);o.feature=r.feature;const n=e.toString(),a=p(k[0][4].value,k[2]);o.feature=a.feature;const s=e.toString();return t=[{replaceWith:n,encapsulateWith:i.truthy.map((e=>e.toString().trim())).join(",")},{replaceWith:s,encapsulateWith:i.falsy.map((e=>e.toString().trim())).join(",")}],!1}})),t}function mediaQueryIsSimple(e){if(f(e))return!1;if(m(e))return!1;let r=!0;return e.walk((e=>{if(d(e.node)||h(e.node)||y(e.node)||g(e.node)||v(e.node))return r=!1,!1})),r}const creator=e=>{const r=Boolean(Object(e).preserve);if("importFrom"in Object(e))throw new Error('[postcss-custom-media] "importFrom" is no longer supported');if("exportTo"in Object(e))throw new Error('[postcss-custom-media] "exportTo" is no longer supported');return{postcssPlugin:"postcss-custom-media",prepare(){const e=new WeakSet;let t=new Map;return{Once:(e,{result:n})=>{t=getCustomMedia(e,n,{preserve:r})},AtRule:(n,{result:a})=>{if(e.has(n))return;if("media"!==n.name.toLowerCase())return;if(!n.params)return;if(!n.params.includes("--"))return;let o=[];try{o=transformAtMediaListTokens(n.params,t)}catch(e){return void n.warn(a,`Failed to parse @custom-media params with error message: "${e.message}"`)}if(!o||0===o.length)return;if(1===o.length){if(n.params.trim()===o[0].replaceWith.trim())return;return e.add(n),n.cloneBefore({params:o[0].replaceWith.trim()}),r?void 0:void n.remove()}if(!!!o.find((e=>!!e.encapsulateWith)))return e.add(n),n.cloneBefore({params:o.map((e=>e.replaceWith)).join(",").trim()}),void(r||n.remove());o.forEach((r=>{if(!r.encapsulateWith)return void n.cloneBefore({params:r.replaceWith.trim()});const t=n.clone({params:r.replaceWith}),a=n.clone({params:r.encapsulateWith.trim(),nodes:[]});t.parent=void 0,a.parent=void 0,e.add(n),a.append(t),n.before(a)})),r||n.remove()}}}}};creator.postcss=!0;export{creator as default}; diff --git a/node_modules/postcss-custom-media/dist/is-processable-custom-media-rule.d.ts b/node_modules/postcss-custom-media/dist/is-processable-custom-media-rule.d.ts new file mode 100644 index 00000000..04c46a3d --- /dev/null +++ b/node_modules/postcss-custom-media/dist/is-processable-custom-media-rule.d.ts @@ -0,0 +1,2 @@ +import type { AtRule } from 'postcss'; +export declare function isProcessableCustomMediaRule(atRule: AtRule): boolean; diff --git a/node_modules/postcss-custom-media/dist/toposort.d.ts b/node_modules/postcss-custom-media/dist/toposort.d.ts new file mode 100644 index 00000000..ffb196fd --- /dev/null +++ b/node_modules/postcss-custom-media/dist/toposort.d.ts @@ -0,0 +1 @@ +export declare function removeCyclicReferences(nodes: Map<string, unknown>, edges: Array<Array<string>>): Set<string>; diff --git a/node_modules/postcss-custom-media/dist/transform-at-media/always-true-or-false.d.ts b/node_modules/postcss-custom-media/dist/transform-at-media/always-true-or-false.d.ts new file mode 100644 index 00000000..e37de5a3 --- /dev/null +++ b/node_modules/postcss-custom-media/dist/transform-at-media/always-true-or-false.d.ts @@ -0,0 +1,3 @@ +import type { TokenColon, TokenIdent, TokenNumber } from '@csstools/css-tokenizer'; +export declare const alwaysTrue: [TokenIdent, TokenColon, TokenNumber]; +export declare const neverTrue: [TokenIdent, TokenColon, TokenNumber]; diff --git a/node_modules/postcss-custom-media/dist/transform-at-media/at-media-params-tokens.d.ts b/node_modules/postcss-custom-media/dist/transform-at-media/at-media-params-tokens.d.ts new file mode 100644 index 00000000..e9a83130 --- /dev/null +++ b/node_modules/postcss-custom-media/dist/transform-at-media/at-media-params-tokens.d.ts @@ -0,0 +1,2 @@ +import type { CSSToken } from '@csstools/css-tokenizer'; +export declare function atMediaParamsTokens(params: string): Array<CSSToken>; diff --git a/node_modules/postcss-custom-media/dist/transform-at-media/custom-media.d.ts b/node_modules/postcss-custom-media/dist/transform-at-media/custom-media.d.ts new file mode 100644 index 00000000..5ef92dc5 --- /dev/null +++ b/node_modules/postcss-custom-media/dist/transform-at-media/custom-media.d.ts @@ -0,0 +1,7 @@ +import { MediaQuery } from '@csstools/media-query-list-parser'; +export declare function parseCustomMedia(params: string): { + name: string; + truthy: Array<MediaQuery>; + falsy: Array<MediaQuery>; + dependsOn: Array<[string, string]>; +} | false; diff --git a/node_modules/postcss-custom-media/dist/transform-at-media/transform-at-media.d.ts b/node_modules/postcss-custom-media/dist/transform-at-media/transform-at-media.d.ts new file mode 100644 index 00000000..e3367390 --- /dev/null +++ b/node_modules/postcss-custom-media/dist/transform-at-media/transform-at-media.d.ts @@ -0,0 +1,22 @@ +import { MediaQuery } from '@csstools/media-query-list-parser'; +export declare function transformAtMediaListTokens(params: string, replacements: Map<string, { + truthy: Array<MediaQuery>; + falsy: Array<MediaQuery>; +}>): Array<{ + replaceWith: string; + encapsulateWith?: string; +}>; +export declare function transformSimpleMediaQuery(mediaQuery: MediaQuery, replacements: Map<string, { + truthy: Array<MediaQuery>; + falsy: Array<MediaQuery>; +}>): { + replaceWith: string; + encapsulateWith?: string; +} | null; +export declare function transformComplexMediaQuery(mediaQuery: MediaQuery, replacements: Map<string, { + truthy: Array<MediaQuery>; + falsy: Array<MediaQuery>; +}>): Array<{ + replaceWith: string; + encapsulateWith?: string; +}>; diff --git a/node_modules/postcss-custom-media/dist/transform-at-media/true-and-false.d.ts b/node_modules/postcss-custom-media/dist/transform-at-media/true-and-false.d.ts new file mode 100644 index 00000000..ba1fa3a9 --- /dev/null +++ b/node_modules/postcss-custom-media/dist/transform-at-media/true-and-false.d.ts @@ -0,0 +1,2 @@ +import type { CSSToken } from '@csstools/css-tokenizer'; +export declare function replaceTrueAndFalseTokens(tokens: Array<CSSToken>): Array<CSSToken>; diff --git a/node_modules/postcss-custom-media/package.json b/node_modules/postcss-custom-media/package.json new file mode 100644 index 00000000..bdff6eb4 --- /dev/null +++ b/node_modules/postcss-custom-media/package.json @@ -0,0 +1,105 @@ +{ + "name": "postcss-custom-media", + "description": "Use Custom Media Queries in CSS", + "version": "10.0.2", + "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": "^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/cascade-layer-name-parser": "^1.0.5", + "@csstools/css-parser-algorithms": "^2.3.2", + "@csstools/css-tokenizer": "^2.2.1", + "@csstools/media-query-list-parser": "^2.1.5" + }, + "peerDependencies": { + "postcss": "^8.4" + }, + "devDependencies": { + "@csstools/postcss-tape": "*" + }, + "scripts": { + "build": "rollup -c ../../rollup/default.mjs", + "docs": "node ../../.github/bin/generate-docs/install.mjs && node ../../.github/bin/generate-docs/readme.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:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs" + }, + "homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-custom-media#readme", + "repository": { + "type": "git", + "url": "https://github.com/csstools/postcss-plugins.git", + "directory": "plugins/postcss-custom-media" + }, + "bugs": "https://github.com/csstools/postcss-plugins/issues", + "keywords": [ + "at-rule", + "atrule", + "css", + "csswg", + "custom", + "media", + "postcss", + "postcss-plugin", + "queries", + "query", + "specification", + "w3c" + ], + "csstools": { + "assumesToProcessBundledCSS": true, + "cssdbId": "custom-media-queries", + "exportName": "postcssCustomMedia", + "humanReadableName": "PostCSS Custom Media", + "specUrl": "https://www.w3.org/TR/mediaqueries-5/#at-ruledef-custom-media" + }, + "volta": { + "extends": "../../package.json" + } +} |
