diff options
Diffstat (limited to 'node_modules/postcss-nesting')
25 files changed, 32 insertions, 492 deletions
diff --git a/node_modules/postcss-nesting/CHANGELOG.md b/node_modules/postcss-nesting/CHANGELOG.md index c0ce8508..9613df18 100644 --- a/node_modules/postcss-nesting/CHANGELOG.md +++ b/node_modules/postcss-nesting/CHANGELOG.md @@ -1,5 +1,12 @@ # Changes to PostCSS Nesting +### 12.0.2 + +_December 15, 2023_ + +- Fix type definitions +- Updated [`@csstools/selector-specificity`](https://github.com/csstools/postcss-plugins/tree/main/packages/selector-specificity) to [`3.0.1`](https://github.com/csstools/postcss-plugins/tree/main/packages/selector-specificity/CHANGELOG.md#301) (patch) + ### 12.0.1 _August 5, 2023_ @@ -13,410 +20,4 @@ _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) -### 11.3.0 - -_June 14, 2023_ - -- Add support for nested selectors that that begin with a letter -- Add warning when using the deprecated `@nest` rule - - you can silence this warning with a new `silenceAtNestWarning` plugin option - - you can migrate your code to the latest syntax with our [Stylelint Plugin](https://github.com/csstools/postcss-plugins/tree/main/plugins-stylelint/no-at-nest-rule#csstoolsstylelint-no-at-nest-rule) - -### 11.2.2 - -_March 25, 2023_ - -- Improved: support for mixins - -### 11.2.1 - -_February 16, 2023_ - -- Skip nested rules that have a selector that begins with a letter -- Better warning when nested rules have a selector that begins with a letter - -### 11.2.0 - -_February 13, 2023_ - -- Added: support for `&` at the root -- Improved: support for mixins - -### 11.1.0 - -_January 31, 2023_ - -- Implement latest specification - - relative selector syntax - - `@nest` is obsolete, all selectors can be written without it (sometimes you will need `:is()`) - - allow declarations after nested rules. - -⚠️ We advice everyone to migrate their codebase **now** to nested CSS without `@nest`. -Future versions of this plugin will warn and then error on `@nest`. - -### 11.0.1 - -_January 28, 2023_ - -- Improve `types` declaration in `package.json` - -### 11.0.0 - -_January 24, 2023_ - -- Updated: Support for Node v14+ (major). -- Fix: Do not throw when a selector is invalid, show a warning instead. -- Removed: Support for Deno (breaking) - -### 10.2.0 - -_September 14, 2022_ - -- Added: TypeScript typings - -### 10.1.10 - -_June 30, 2022_ - -- Partially revert the changes to pseudo element selectors from 10.1.9. - -```diff -.anything::before { - @nest .something_else > & { - order: 1; - } -} - -/* becomes */ - -- .something_else > :is(.anything::before) { /* 10.1.9 */ -+ .something_else > .anything::before { /* previous and restored behavior */ - order: 1; -} -``` - -The exact behavior of this pattern is unspecified and might change in the future. -We are reverting to the previous behavior until the specification is clarified. - -### 10.1.9 - -_June 23, 2022_ - -- Fix selector order with any pseudo element. -- Fix semicolons being removed [#497](https://github.com/csstools/postcss-plugins/issues/497). - -### 10.1.8 - -_June 4, 2022_ - -- Update `@csstools/selector-specificity` (major) - -### 10.1.7 - -_May 20, 2022_ - -- Add tentative support for `@layer`. The actual behavior is poorly defined and may change in the future. Use with caution. - -### 10.1.6 - -_May 17, 2022_ - - - Fix selector order with `:before` and other pseudo elements. - -### 10.1.5 - -_May 11, 2022_ - -- Use `@csstools/selector-specificity` for specificity calculations. - -### 10.1.4 - -_April 4, 2022_ - -- Improved : compound selector order with pseudo elements -- Improved : selector specificity calculation. - -### 10.1.3 - -_March 4, 2022_ - -- Avoid creating duplicate selectors containing only comments. - -```diff -.alpha { - /* loose comment */ - & .beta { - order: 1; - } -} - -/* becomes */ - -- .alpha { -- /* loose comment */ -- } -+ /* loose comment */ -.alpha .beta { - order: 1; -} -``` - -### 10.1.2 - -_January 12, 2022_ - -- Improved : selector specificity calculation - -### 10.1.1 - -_January 2, 2022_ - -- Removed Sourcemaps from package tarball. -- Moved CLI to CLI Package. See [announcement](https://github.com/csstools/postcss-plugins/discussions/121). - -### 10.1.0 - -_December 22, 2021_ - -- Added: `noIsPseudoSelector` plugin option. -- Changed: `:is()` pseudo is now avoided as much as possible by default. -- Updated: documentation - -[more info on noIsPseudoSelector](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting#noispseudoselector) - -```js -postcssNesting({ - noIsPseudoSelector: true -}) -``` - -### 10.0.3 - -_December 13, 2021_ - -- Updated: documentation - -### 10.0.2 - -_November 18, 2021_ - -- Fixed: Support for Deno. Ensuring we pack `mod.js` so it can be accessible by CDNs. - -### 10.0.1 - -_November 17, 2021_ - -- Removed: Support for `allowDeclarationsAfterNestedRules`. - -We've realised that enforcing this rule from the spec was going to be problematic -in the long run given how plugins work and the whole ecosystem around mixins and -other features. Treating this as a patch given that this was introduced in the -previous version and was starting to break projects that were using other features. - -### 10.0.0 - -_November 16, 2021_ - -- Added: Support for `allowDeclarationsAfterNestedRules` to deviate from spec. -- Added: `.npmrc` file. - -- Updated: Aligning completely with the [spec](https://www.w3.org/TR/css-nesting-1/) updates. -- Updated: `esbuild` to 0.13.12 (minor) - -- Removed: Support for PostCSS 7 - -### 9.0.0 - -_October 27, 2021_ - -- Added: Support for Deno -- Fixed: Issue with PostCSS 8 compatibility using the RuleExit listener - -### 8.0.1 - -_May 1, 2021_ - -- Fixed: Compatibility issue with CommonJS. - -### 8.0.0 - -_April 26, 2021_ - -- Updated: Support for PostCSS 8+. -- Updated: Support for Node v12+. -- Updated: Support for the `@container` at-rule. - -### 7.0.1 - -_July 29, 2018_ - -- Fixed: Non-breaking issue with rules being unnecessarily split - -### 7.0.0 - -_September 17, 2018_ - -- Updated: Support for PostCSS v7+ -- Updated: Support for Node v6+ - -In a comment, a CSSWG member expressed interest in handling nested `@media` -while handling selector nesting. Since the specification has yet to be added -to the official CSSWG repository, nested at-rule deprecation is further delayed. - -### 6.0.0 - -_June 9, 2018_ - -- Deprecated: Nested at-rules like `@media` will no longer work in 7.0.0 -- Refactored code to improve efficiency - -### 5.0.0 - -_March 24, 2018_ - -- Refactored code to use Imports babel-transformed for Node v4 compatibility - -### 4.2.1 - -_September 19, 2017_ - -- Updated: Exposing the transform function as its own for postcss-extend - -### 4.2.0 - -_September 18, 2017_ - -- Added: Reduced splitting of rules - -### 4.1.0 - -_August 19, 2017_ - -- Added: Mutation-safe walk method -- Improved: Complex selector validity testing -- Thanks: A special thanks to @JLHwung for these improvements - -### 4.0.1 - -_May 22, 2017_ - -- Improved: Selector validity testing - -### 4.0.0 - -_May 20, 2017_ - -- Changed: Transform only compliant nesting -- Added: Preserve more raws formatting - -### 3.0.0 - -_May 8, 2017_ - -- Added: Node 4.x support -- Added: PostCSS 6 support -- Added: Preserved ordering -- Removed: Node 0.12 support - -### 2.3.1 - -_March 16, 2016_ - -- Updated: Allow any direct nesting that follows the syntactic constraints -- Updated: PostCSS 5.0.6 -- Updated: Tests -- Updated: Dependencies -- Updated: Project configuration - -### 2.3.0 - -_February 20, 2016_ - -- Updated: JavaScript formatting, linting, tests, and documentation -- Updated: Properly concatenate at-rules with or expressions -- Updated: Update internal plugin name to postcss-nesting - -### 2.2.0 - -_January 30, 2016_ - -- Added: Nesting of all at-rules -- Updated: Direct nesting order maintains order -- Updated: Tests and documentation - -### 2.1.1 - -_January 3, 2016_ - -- Updated: Project conventions - -### 2.1.0 - -_January 3, 2016_ - -- Added: Support for valid direct nesting - -### 2.0.6 - -_October 15, 2015_ - -- Fixed: Issue with new PostCSS rules - -### 2.0.5 - -_October 12, 2015_ - -- Updated: Nested rules source map to the parent rule -- Updated: PostCSS 5.0.9 -- Updated: Tests and documentation -- Updated: Project configuration - -### 2.0.4 - -_September 23, 2015_ - -- Updated: Map source raws - -### 2.0.3 - -_September 22, 2015_ - -- Updated: Refactored plugin -- Updated: Tests -- Updated: PostCSS 5.0.6 - -### 2.0.2 - -_September 16, 2015_ - -- Fixed: Issue where the new rule’s children were not mapped to the parent internally - -### 2.0.1 - -_September 16, 2015_ - -- Fixed: Issue where a `@nest` rule followed by another bubbling at-rule would not bubble -- Added: CONTRIBUTING.md - -### 2.0.0 - -_September 16, 2015_ - -- Added: Requirement of `&` per the specification -- Added: New prefix option -- Added: `@document` and `@supports` as bubbles -- Updated: Documentation - -### 1.0.0 - -_September 15, 2015_ - -- Added: New `@nest` at-rule syntax -- Updated: PostCSS 5 -- Removed: Old inner bracket syntax - -### 0.1.0 - -_June 17, 2015_ - -- Added: Initial release +[Full CHANGELOG](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting/CHANGELOG.md) diff --git a/node_modules/postcss-nesting/README.md b/node_modules/postcss-nesting/README.md index bec68284..9efe88e7 100644 --- a/node_modules/postcss-nesting/README.md +++ b/node_modules/postcss-nesting/README.md @@ -2,6 +2,10 @@ [<img alt="npm version" src="https://img.shields.io/npm/v/postcss-nesting.svg" height="20">][npm-url] [<img alt="CSS Standard Status" src="https://cssdb.org/images/badges/nesting-rules.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-nesting --save-dev +``` + [PostCSS Nesting] lets you nest style rules inside each other, following the [CSS Nesting specification]. If you want nested rules the same way [Sass] works diff --git a/node_modules/postcss-nesting/dist/index.cjs b/node_modules/postcss-nesting/dist/index.cjs index d5716ad9..2990b02a 100644 --- a/node_modules/postcss-nesting/dist/index.cjs +++ b/node_modules/postcss-nesting/dist/index.cjs @@ -1 +1 @@ -"use strict";var e=require("postcss-selector-parser"),t=require("@csstools/selector-specificity");const n=e.pseudo({value:":is"});function sortCompoundSelectorsInsideComplexSelector(t){if(!t||!t.nodes)return;const r=[];let o=[];for(let s=0;s<t.nodes.length;s++)if("combinator"!==t.nodes[s].type)if(e.isPseudoElement(t.nodes[s]))r.push(o),o=[t.nodes[s]];else{if("tag"===t.nodes[s].type&&o.find((e=>"tag"===e.type))){const r=n.clone({}),o=t.nodes[s];o.replaceWith(r),r.append(e.selector({nodes:[o],value:void 0}))}o.push(t.nodes[s])}else r.push(o),r.push([t.nodes[s]]),o=[];r.push(o);const s=[];for(let e=0;e<r.length;e++){const t=r[e];t.sort(((e,t)=>"selector"===e.type&&"selector"===t.type&&e.nodes.length&&t.nodes.length?selectorTypeOrder(e.nodes[0])-selectorTypeOrder(t.nodes[0]):"selector"===e.type&&e.nodes.length?selectorTypeOrder(e.nodes[0])-selectorTypeOrder(t):"selector"===t.type&&t.nodes.length?selectorTypeOrder(e)-selectorTypeOrder(t.nodes[0]):selectorTypeOrder(e)-selectorTypeOrder(t)));for(let e=0;e<t.length;e++)s.push(t[e])}for(let e=s.length-1;e>=0;e--)s[e].remove(),t.prepend(s[e])}function selectorTypeOrder(t){return e.isPseudoElement(t)?r.pseudoElement:r[t.type]}const r={universal:0,tag:1,pseudoElement:2,id:3,class:4,attribute:5,pseudo:6,selector:7,string:8,root:9,comment:10};function ampersandToScope(t,n){let r,o=t.parent;for(;o;){if("rule"===o.type)return;o=o.parent}try{r=e().astSync(t.selector)}catch(e){return void t.warn(n,`Failed to parse selector : "${t.selector}" with message: "${e.message}"`)}r&&(r.walkNesting((t=>{const n=t.parent;t.replaceWith(e.pseudo({value:":scope"})),n&&sortCompoundSelectorsInsideComplexSelector(n)})),t.selector=r.toString())}function cleanupParent(e){if(!e.nodes.length)return void e.remove();const t=e.nodes.filter((e=>"comment"===e.type));t.length===e.nodes.length&&e.replaceWith(...t)}function shiftNodesBeforeParent(e,t){const n=t.index(e);if(n){const e=t.cloneBefore().removeAll().append(t.nodes.slice(0,n));e.raws.semicolon=!0,cleanupParent(e)}t.before(e),t.raws.semicolon=!0}function combinationsWithSizeN(e,t){if(t<2)throw new Error("n must be greater than 1");if(e.length<2)throw new Error("s must be greater than 1");if(Math.pow(e.length,t)>1e4)throw new Error("Too many combinations when trying to resolve a nested selector with lists, reduce the complexity of your selectors");const n=[];for(let e=0;e<t;e++)n[e]=0;const r=[];for(;;){const o=[];for(let s=t-1;s>=0;s--){let t=n[s];if(t>=e.length){if(t=0,n[s]=0,0===s)return r;n[s-1]+=1}o[s]=e[t]}r.push(o),n[n.length-1]++}}function nodesAreEquallySpecific(n){const r=n.map((t=>e().astSync(t))).map((e=>t.selectorSpecificity(e))),o=r[0];for(let e=1;e<r.length;e++)if(o.a!==r[e].a||o.b!==r[e].b||o.c!==r[e].c)return!1;return!0}function mergeSelectors(t,n,r){let o=[];o=nodesAreEquallySpecific(t)||r.noIsPseudoSelector?t.map((t=>e().astSync(t))):[e().astSync(`:is(${t.join(",")})`)];const s=[];for(let t=0;t<n.length;t++){let i,l=n[t];{const t=e().astSync(l);let n=!1;t.walk((e=>{"nesting"===e.type&&(n=!0)}));const r=t.nodes[0];let o=!1;r.each((e=>"combinator"===e.type&&(o=!0,!1))),n?o&&r.insertBefore(r.at(0),e.nesting({})):(r.insertBefore(r.at(0),e.combinator({value:" "})),r.insertBefore(r.at(0),e.nesting({}))),l=t.toString()}let c=[],a=0;if(e().astSync(l).walkNesting((()=>{a++})),a>1&&o.length>1)c=combinationsWithSizeN(o,a),i=c.length;else{i=o.length;for(let e=0;e<o.length;e++){c.push([]);for(let t=0;t<a;t++)c[e].push(o[e])}}for(let t=0;t<i;t++){let n=0;const o=e().astSync(l);o.walk((o=>{if("nesting"!==o.type)return;let s=c[t][n];n++,"root"===s.type&&1===s.nodes.length&&(s=s.nodes[0]);const i=e().astSync(`:is(${s.toString()})`),l=isSimpleSelector(s.nodes[0]),a=isCompoundSelector(s.nodes[0]),u=isSimpleSelector(o),p=isCompoundSelector(o);if(l&&u)return void o.replaceWith(s.clone());if((l||a)&&(u||p)){const e=o.parent;return l&&"selector"===s.type?o.replaceWith(s.clone().nodes[0]):o.replaceWith(...s.clone().nodes),void(e&&e.nodes.length>1&&sortCompoundSelectorsInsideComplexSelector(e))}if(l){const e=o.parent;return o.replaceWith(s.clone().nodes[0]),void(e&&sortCompoundSelectorsInsideComplexSelector(e))}if(a){const e=o.parent;return o.replaceWith(...s.clone().nodes),void(e&&sortCompoundSelectorsInsideComplexSelector(e))}if(nestingIsFirstAndOnlyInSelectorWithEitherSpaceOrChildCombinator(o)){const e=o.parent;return o.replaceWith(...s.clone().nodes),void(e&&sortCompoundSelectorsInsideComplexSelector(e))}if(nestingIsNotInsideCompoundSelector(o)){const e=o.parent;return o.replaceWith(...s.clone().nodes),void(e&&sortCompoundSelectorsInsideComplexSelector(e))}const d=o.parent;r.noIsPseudoSelector?o.replaceWith(...s.clone().nodes):o.replaceWith(...i.clone({}).nodes),d&&sortCompoundSelectorsInsideComplexSelector(d)})),s.push(o.toString())}}return s}function isSimpleSelector(e){return"combinator"!==e.type&&!(e.parent&&e.parent.nodes.length>1)}function isCompoundSelector(e,t=null){if(isSimpleSelector(e))return!1;if(!e.parent)return!1;if(!!e.parent.nodes.find((e=>"combinator"===e.type)))return!1;return!(!!e.parent.nodes.find((e=>"nesting"===e.type))&&t&&!isCompoundSelector(t))}function nestingIsFirstAndOnlyInSelectorWithEitherSpaceOrChildCombinator(e){if(!e.parent)return!1;if(0!==e.parent.nodes.indexOf(e))return!1;for(let t=1;t<e.parent.nodes.length;t++)if("combinator"===e.parent.nodes[t].type&&" "!==e.parent.nodes[t].value&&">"!==e.parent.nodes[t].value)return!1;return!0}function nestingIsNotInsideCompoundSelector(e){if(isSimpleSelector(e))return!0;if(!e.parent)return!1;for(let t=0;t<e.parent.nodes.length;t++)if("nesting"!==e.parent.nodes[t].type&&(e.parent.nodes[t].prev()||e.parent.nodes[t].next())){if(e.parent.nodes[t].prev()&&"combinator"!==e.parent.nodes[t].prev().type)return!1;if(e.parent.nodes[t].next()&&"combinator"!==e.parent.nodes[t].next().type)return!1}return!0}function groupDeclarations(e){let t=-1;e.each(((n,r)=>{if("decl"===n.type)return t===r-1?void(t=r):(n.remove(),e.insertAfter(t,n),void(t=e.index(n)));if("atrule"===n.type&&"mixin"===n.name.toLowerCase()){let o=n.prev();for(;o;){if("rule"===o.type||"atrule"===o.type)return;o=o.prev()}return t===r-1?void(t=r):(n.remove(),e.insertAfter(t,n),void(t=e.index(n)))}if("comment"===n.type){const o=n.next();if(o&&("comment"===o.type||"rule"===o.type||"atrule"===o.type&&"mixin"!==o.name.toLowerCase()))return;return t===r-1?void(t=r):(n.remove(),e.insertAfter(t,n),void(t=e.index(n)))}}))}function transformRuleWithinRule(e,t,n,r){let o=[];try{o=mergeSelectors(t.selectors,e.selectors,r)}catch(r){return void e.warn(n,`Failed to parse selectors : "${t.selector}" / "${e.selector}" with message: "${r.message}"`)}if(!o.length)return;groupDeclarations(t),shiftNodesBeforeParent(e,t),e.selectors=o;"rule"===e.type&&"rule"===t.type&&e.selector===t.selector&&e.append(...t.nodes),cleanupParent(t)}function isValidRuleWithinRule(e){return e.selectors.every((e=>-1===e.indexOf("|")))}function comma(e){const t=[];let n="",r=!1,o=0,s=!1,i=!1;for(const l of e)i?i=!1:"\\"===l?i=!0:s?l===s&&(s=!1):'"'===l||"'"===l?s=l:"("===l?o+=1:")"===l?o>0&&(o-=1):0===o&&","===l&&(r=!0),r?(""!==n&&t.push(n.trim()),n="",r=!1):n+=l;return t.push(n.trim()),t}function transformNestRuleWithinRule(e,t,n,r,o){let s=[];try{s=mergeSelectors(t.selectors,comma(e.params),o)}catch(r){return void e.warn(n,`Failed to parse selectors : "${t.selector}" / "${e.params}" with message: "${r.message}"`)}if(!s.length)return;shiftNodesBeforeParent(e,t);const i=t.clone().removeAll().append(e.nodes);i.raws.semicolon=!0,i.selectors=s,e.replaceWith(i),cleanupParent(t),r(i,n,o)}function isValidNestRuleWithinRule(e){return comma(e.params).every((e=>e.split("&").length>=2&&-1===e.indexOf("|")))}var o=["container","document","media","supports","layer","starting-style"];function atruleWithinRule(e,t,n,r,o){if(groupDeclarations(t),shiftNodesBeforeParent(e,t),e.nodes){const s=t.clone().removeAll().append(e.nodes);e.append(s),cleanupParent(t),r(s,n,o)}else cleanupParent(t)}function isAtruleWithinRule(e){return o.includes(e.name)}function transformAtruleWithinAtrule(e,t){var n,r;groupDeclarations(t),shiftNodesBeforeParent(e,t),e.params=(n=t.params,r=e.params,comma(n).map((e=>comma(r).map((t=>`${e} and ${t}`)).join(", "))).join(", ")),cleanupParent(t)}function isAtruleWithinAtrule(e,t){return o.includes(e.name)&&e.name===t.name}function isAtRule(e){return e&&"atrule"===e.type}function isNestRule(e){return e&&isAtRule(e)&&"nest"===e.name}function isRule(e){return e&&"rule"===e.type}function walk(e,t,n){e.each((r=>{const o=r.parent;isNestRule(r)&&!n.silenceAtNestWarning&&e.warn(t,`\`@nest\` was removed from the CSS Nesting specification and will be removed from PostCSS Nesting in the next major version.\nChange \`@nest ${r.params} {}\` to \`${r.params} {}\` to migrate to the latest standard.`),isRule(r)&&isRule(o)&&isValidRuleWithinRule(r)?transformRuleWithinRule(r,o,t,n):isNestRule(r)&&isRule(o)&&isValidNestRuleWithinRule(r)?transformNestRuleWithinRule(r,o,t,walk,n):isAtRule(r)&&isRule(o)&&isAtruleWithinRule(r)?atruleWithinRule(r,o,t,walk,n):isAtRule(r)&&isAtRule(o)&&isAtruleWithinAtrule(r,o)&&transformAtruleWithinAtrule(r,o),"nodes"in r&&r.nodes.length&&walk(r,t,n)}))}const creator=e=>{const t=Object.assign({noIsPseudoSelector:!1,silenceAtNestWarning:!1},e);return{postcssPlugin:"postcss-nesting",Rule(e,{result:n}){walk(e,n,t),e.selector.includes("&")&&ersandToScope(e,n)}}};creator.postcss=!0,module.exports=creator; +"use strict";var e=require("postcss-selector-parser"),t=require("@csstools/selector-specificity");const n=e.pseudo({value:":is"});function sortCompoundSelectorsInsideComplexSelector(t){if(!t||!t.nodes)return;const r=[];let o=[];for(let s=0;s<t.nodes.length;s++)if("combinator"!==t.nodes[s].type)if(e.isPseudoElement(t.nodes[s]))r.push(o),o=[t.nodes[s]];else{if("tag"===t.nodes[s].type&&o.find((e=>"tag"===e.type))){const r=n.clone({}),o=t.nodes[s];o.replaceWith(r),r.append(e.selector({nodes:[o],value:void 0}))}o.push(t.nodes[s])}else r.push(o),r.push([t.nodes[s]]),o=[];r.push(o);const s=[];for(let e=0;e<r.length;e++){const t=r[e];t.sort(((e,t)=>"selector"===e.type&&"selector"===t.type&&e.nodes.length&&t.nodes.length?selectorTypeOrder(e.nodes[0])-selectorTypeOrder(t.nodes[0]):"selector"===e.type&&e.nodes.length?selectorTypeOrder(e.nodes[0])-selectorTypeOrder(t):"selector"===t.type&&t.nodes.length?selectorTypeOrder(e)-selectorTypeOrder(t.nodes[0]):selectorTypeOrder(e)-selectorTypeOrder(t)));for(let e=0;e<t.length;e++)s.push(t[e])}for(let e=s.length-1;e>=0;e--)s[e].remove(),t.prepend(s[e])}function selectorTypeOrder(t){return e.isPseudoElement(t)?r.pseudoElement:r[t.type]}const r={universal:0,tag:1,pseudoElement:2,id:3,class:4,attribute:5,pseudo:6,selector:7,string:8,root:9,comment:10};function ampersandToScope(t,n){let r,o=t.parent;for(;o;){if("rule"===o.type)return;o=o.parent}try{r=e().astSync(t.selector)}catch(e){return void t.warn(n,`Failed to parse selector : "${t.selector}" with message: "${e instanceof Error?e.message:e}"`)}r&&(r.walkNesting((t=>{const n=t.parent;t.replaceWith(e.pseudo({value:":scope"})),n&&sortCompoundSelectorsInsideComplexSelector(n)})),t.selector=r.toString())}function cleanupParent(e){if(!e.nodes.length)return void e.remove();const t=e.nodes.filter((e=>"comment"===e.type));t.length===e.nodes.length&&e.replaceWith(...t)}function shiftNodesBeforeParent(e,t){const n=t.index(e);if(n){const e=t.cloneBefore().removeAll().append(t.nodes.slice(0,n));e.raws.semicolon=!0,cleanupParent(e)}t.before(e),t.raws.semicolon=!0}function combinationsWithSizeN(e,t){if(t<2)throw new Error("n must be greater than 1");if(e.length<2)throw new Error("s must be greater than 1");if(Math.pow(e.length,t)>1e4)throw new Error("Too many combinations when trying to resolve a nested selector with lists, reduce the complexity of your selectors");const n=[];for(let e=0;e<t;e++)n[e]=0;const r=[];for(;;){const o=[];for(let s=t-1;s>=0;s--){let t=n[s];if(t>=e.length){if(t=0,n[s]=0,0===s)return r;n[s-1]+=1}o[s]=e[t]}r.push(o),n[n.length-1]++}}function nodesAreEquallySpecific(n){const r=n.map((t=>e().astSync(t))).map((e=>t.selectorSpecificity(e))),o=r[0];for(let e=1;e<r.length;e++)if(o.a!==r[e].a||o.b!==r[e].b||o.c!==r[e].c)return!1;return!0}function mergeSelectors(t,n,r){let o=[];o=nodesAreEquallySpecific(t)||r.noIsPseudoSelector?t.map((t=>e().astSync(t))):[e().astSync(`:is(${t.join(",")})`)];const s=[];for(let t=0;t<n.length;t++){let i,l=n[t];{const t=e().astSync(l);let n=!1;t.walk((e=>{"nesting"===e.type&&(n=!0)}));const r=t.nodes[0];let o=!1;r.each((e=>"combinator"===e.type&&(o=!0,!1))),n?o&&r.insertBefore(r.at(0),e.nesting({})):(r.insertBefore(r.at(0),e.combinator({value:" "})),r.insertBefore(r.at(0),e.nesting({}))),l=t.toString()}let c=[],a=0;if(e().astSync(l).walkNesting((()=>{a++})),a>1&&o.length>1)c=combinationsWithSizeN(o,a),i=c.length;else{i=o.length;for(let e=0;e<o.length;e++){c.push([]);for(let t=0;t<a;t++)c[e].push(o[e])}}for(let t=0;t<i;t++){let n=0;const o=e().astSync(l);o.walk((o=>{if("nesting"!==o.type)return;let s=c[t][n];n++,"root"===s.type&&1===s.nodes.length&&(s=s.nodes[0]);const i=e().astSync(`:is(${s.toString()})`),l=isSimpleSelector(s.nodes[0]),a=isCompoundSelector(s.nodes[0]),u=isSimpleSelector(o),p=isCompoundSelector(o);if(l&&u)return void o.replaceWith(s.clone());if((l||a)&&(u||p)){const e=o.parent;return l&&"selector"===s.type?o.replaceWith(s.clone().nodes[0]):o.replaceWith(...s.clone().nodes),void(e&&e.nodes.length>1&&sortCompoundSelectorsInsideComplexSelector(e))}if(l){const e=o.parent;return o.replaceWith(s.clone().nodes[0]),void(e&&sortCompoundSelectorsInsideComplexSelector(e))}if(a){const e=o.parent;return o.replaceWith(...s.clone().nodes),void(e&&sortCompoundSelectorsInsideComplexSelector(e))}if(nestingIsFirstAndOnlyInSelectorWithEitherSpaceOrChildCombinator(o)){const e=o.parent;return o.replaceWith(...s.clone().nodes),void(e&&sortCompoundSelectorsInsideComplexSelector(e))}if(nestingIsNotInsideCompoundSelector(o)){const e=o.parent;return o.replaceWith(...s.clone().nodes),void(e&&sortCompoundSelectorsInsideComplexSelector(e))}const d=o.parent;r.noIsPseudoSelector?o.replaceWith(...s.clone().nodes):o.replaceWith(...i.clone({}).nodes),d&&sortCompoundSelectorsInsideComplexSelector(d)})),s.push(o.toString())}}return s}function isSimpleSelector(e){return"combinator"!==e.type&&!(e.parent&&e.parent.nodes.length>1)}function isCompoundSelector(e,t=null){if(isSimpleSelector(e))return!1;if(!e.parent)return!1;if(!!e.parent.nodes.find((e=>"combinator"===e.type)))return!1;return!(!!e.parent.nodes.find((e=>"nesting"===e.type))&&t&&!isCompoundSelector(t))}function nestingIsFirstAndOnlyInSelectorWithEitherSpaceOrChildCombinator(e){if(!e.parent)return!1;if(0!==e.parent.nodes.indexOf(e))return!1;for(let t=1;t<e.parent.nodes.length;t++)if("combinator"===e.parent.nodes[t].type&&" "!==e.parent.nodes[t].value&&">"!==e.parent.nodes[t].value)return!1;return!0}function nestingIsNotInsideCompoundSelector(e){if(isSimpleSelector(e))return!0;if(!e.parent)return!1;for(let t=0;t<e.parent.nodes.length;t++)if("nesting"!==e.parent.nodes[t].type&&(e.parent.nodes[t].prev()||e.parent.nodes[t].next())){if(e.parent.nodes[t].prev()&&"combinator"!==e.parent.nodes[t].prev().type)return!1;if(e.parent.nodes[t].next()&&"combinator"!==e.parent.nodes[t].next().type)return!1}return!0}function groupDeclarations(e){let t=-1;e.each(((n,r)=>{if("decl"===n.type)return t===r-1?void(t=r):(n.remove(),e.insertAfter(t,n),void(t=e.index(n)));if("atrule"===n.type&&"mixin"===n.name.toLowerCase()){let o=n.prev();for(;o;){if("rule"===o.type||"atrule"===o.type)return;o=o.prev()}return t===r-1?void(t=r):(n.remove(),e.insertAfter(t,n),void(t=e.index(n)))}if("comment"===n.type){const o=n.next();if(o&&("comment"===o.type||"rule"===o.type||"atrule"===o.type&&"mixin"!==o.name.toLowerCase()))return;return t===r-1?void(t=r):(n.remove(),e.insertAfter(t,n),void(t=e.index(n)))}}))}function transformRuleWithinRule(e,t,n,r){let o=[];try{o=mergeSelectors(t.selectors,e.selectors,r)}catch(r){return void e.warn(n,`Failed to parse selectors : "${t.selector}" / "${e.selector}" with message: "${r instanceof Error?r.message:r}"`)}if(!o.length)return;groupDeclarations(t),shiftNodesBeforeParent(e,t),e.selectors=o;"rule"===e.type&&"rule"===t.type&&e.selector===t.selector&&e.append(...t.nodes),cleanupParent(t)}function isValidRuleWithinRule(e){return e.selectors.every((e=>-1===e.indexOf("|")))}function comma(e){const t=[];let n="",r=!1,o=0,s=!1,i=!1;for(const l of e)i?i=!1:"\\"===l?i=!0:s?l===s&&(s=!1):'"'===l||"'"===l?s=l:"("===l?o+=1:")"===l?o>0&&(o-=1):0===o&&","===l&&(r=!0),r?(""!==n&&t.push(n.trim()),n="",r=!1):n+=l;return t.push(n.trim()),t}function transformNestRuleWithinRule(e,t,n,r,o){let s=[];try{s=mergeSelectors(t.selectors,comma(e.params),o)}catch(r){return void e.warn(n,`Failed to parse selectors : "${t.selector}" / "${e.params}" with message: "${r instanceof Error?r.message:r}"`)}if(!s.length)return;shiftNodesBeforeParent(e,t);const i=t.clone().removeAll().append(e.nodes);i.raws.semicolon=!0,i.selectors=s,e.replaceWith(i),cleanupParent(t),r(i,n,o)}function isValidNestRuleWithinRule(e){return comma(e.params).every((e=>e.split("&").length>=2&&-1===e.indexOf("|")))}var o=["container","document","media","supports","layer","starting-style"];function atruleWithinRule(e,t,n,r,o){if(groupDeclarations(t),shiftNodesBeforeParent(e,t),e.nodes){const s=t.clone().removeAll().append(e.nodes);e.append(s),cleanupParent(t),r(s,n,o)}else cleanupParent(t)}function isAtruleWithinRule(e){return o.includes(e.name)}function transformAtruleWithinAtrule(e,t){var n,r;groupDeclarations(t),shiftNodesBeforeParent(e,t),e.params=(n=t.params,r=e.params,comma(n).map((e=>comma(r).map((t=>`${e} and ${t}`)).join(", "))).join(", ")),cleanupParent(t)}function isAtruleWithinAtrule(e,t){return o.includes(e.name)&&e.name===t.name}function isAtRule(e){return e&&"atrule"===e.type}function isNestRule(e){return e&&isAtRule(e)&&"nest"===e.name}function isRule(e){return e&&"rule"===e.type}function walk(e,t,n){e.each((r=>{const o=r.parent;isNestRule(r)&&!n.silenceAtNestWarning&&e.warn(t,`\`@nest\` was removed from the CSS Nesting specification and will be removed from PostCSS Nesting in the next major version.\nChange \`@nest ${r.params} {}\` to \`${r.params} {}\` to migrate to the latest standard.`),isRule(r)&&isRule(o)&&isValidRuleWithinRule(r)?transformRuleWithinRule(r,o,t,n):isNestRule(r)&&isRule(o)&&isValidNestRuleWithinRule(r)?transformNestRuleWithinRule(r,o,t,walk,n):isAtRule(r)&&isRule(o)&&isAtruleWithinRule(r)?atruleWithinRule(r,o,t,walk,n):isAtRule(r)&&isAtRule(o)&&isAtruleWithinAtrule(r,o)&&transformAtruleWithinAtrule(r,o),"nodes"in r&&r.nodes.length&&walk(r,t,n)}))}const creator=e=>{const t=Object.assign({noIsPseudoSelector:!1,silenceAtNestWarning:!1},e);return{postcssPlugin:"postcss-nesting",Rule(e,{result:n}){walk(e,n,t),e.selector.includes("&")&&ersandToScope(e,n)}}};creator.postcss=!0,module.exports=creator; diff --git a/node_modules/postcss-nesting/dist/index.d.ts b/node_modules/postcss-nesting/dist/index.d.ts index 777ed3e5..c441b417 100644 --- a/node_modules/postcss-nesting/dist/index.d.ts +++ b/node_modules/postcss-nesting/dist/index.d.ts @@ -1,10 +1,14 @@ import type { PluginCreator } from 'postcss'; + +declare const creator: PluginCreator<pluginOptions>; +export default creator; + /** postcss-nesting plugin options */ -export type pluginOptions = { +export declare type pluginOptions = { /** Avoid the `:is()` pseudo class as much as possible. default: false */ noIsPseudoSelector?: boolean; /** Silence the `@nest` warning. */ silenceAtNestWarning?: boolean; }; -declare const creator: PluginCreator<pluginOptions>; -export default creator; + +export { } diff --git a/node_modules/postcss-nesting/dist/index.mjs b/node_modules/postcss-nesting/dist/index.mjs index 442c0159..593ade04 100644 --- a/node_modules/postcss-nesting/dist/index.mjs +++ b/node_modules/postcss-nesting/dist/index.mjs @@ -1 +1 @@ -import e from"postcss-selector-parser";import{selectorSpecificity as t}from"@csstools/selector-specificity";const n=e.pseudo({value:":is"});function sortCompoundSelectorsInsideComplexSelector(t){if(!t||!t.nodes)return;const r=[];let o=[];for(let s=0;s<t.nodes.length;s++)if("combinator"!==t.nodes[s].type)if(e.isPseudoElement(t.nodes[s]))r.push(o),o=[t.nodes[s]];else{if("tag"===t.nodes[s].type&&o.find((e=>"tag"===e.type))){const r=n.clone({}),o=t.nodes[s];o.replaceWith(r),r.append(e.selector({nodes:[o],value:void 0}))}o.push(t.nodes[s])}else r.push(o),r.push([t.nodes[s]]),o=[];r.push(o);const s=[];for(let e=0;e<r.length;e++){const t=r[e];t.sort(((e,t)=>"selector"===e.type&&"selector"===t.type&&e.nodes.length&&t.nodes.length?selectorTypeOrder(e.nodes[0])-selectorTypeOrder(t.nodes[0]):"selector"===e.type&&e.nodes.length?selectorTypeOrder(e.nodes[0])-selectorTypeOrder(t):"selector"===t.type&&t.nodes.length?selectorTypeOrder(e)-selectorTypeOrder(t.nodes[0]):selectorTypeOrder(e)-selectorTypeOrder(t)));for(let e=0;e<t.length;e++)s.push(t[e])}for(let e=s.length-1;e>=0;e--)s[e].remove(),t.prepend(s[e])}function selectorTypeOrder(t){return e.isPseudoElement(t)?r.pseudoElement:r[t.type]}const r={universal:0,tag:1,pseudoElement:2,id:3,class:4,attribute:5,pseudo:6,selector:7,string:8,root:9,comment:10};function ampersandToScope(t,n){let r,o=t.parent;for(;o;){if("rule"===o.type)return;o=o.parent}try{r=e().astSync(t.selector)}catch(e){return void t.warn(n,`Failed to parse selector : "${t.selector}" with message: "${e.message}"`)}r&&(r.walkNesting((t=>{const n=t.parent;t.replaceWith(e.pseudo({value:":scope"})),n&&sortCompoundSelectorsInsideComplexSelector(n)})),t.selector=r.toString())}function cleanupParent(e){if(!e.nodes.length)return void e.remove();const t=e.nodes.filter((e=>"comment"===e.type));t.length===e.nodes.length&&e.replaceWith(...t)}function shiftNodesBeforeParent(e,t){const n=t.index(e);if(n){const e=t.cloneBefore().removeAll().append(t.nodes.slice(0,n));e.raws.semicolon=!0,cleanupParent(e)}t.before(e),t.raws.semicolon=!0}function combinationsWithSizeN(e,t){if(t<2)throw new Error("n must be greater than 1");if(e.length<2)throw new Error("s must be greater than 1");if(Math.pow(e.length,t)>1e4)throw new Error("Too many combinations when trying to resolve a nested selector with lists, reduce the complexity of your selectors");const n=[];for(let e=0;e<t;e++)n[e]=0;const r=[];for(;;){const o=[];for(let s=t-1;s>=0;s--){let t=n[s];if(t>=e.length){if(t=0,n[s]=0,0===s)return r;n[s-1]+=1}o[s]=e[t]}r.push(o),n[n.length-1]++}}function nodesAreEquallySpecific(n){const r=n.map((t=>e().astSync(t))).map((e=>t(e))),o=r[0];for(let e=1;e<r.length;e++)if(o.a!==r[e].a||o.b!==r[e].b||o.c!==r[e].c)return!1;return!0}function mergeSelectors(t,n,r){let o=[];o=nodesAreEquallySpecific(t)||r.noIsPseudoSelector?t.map((t=>e().astSync(t))):[e().astSync(`:is(${t.join(",")})`)];const s=[];for(let t=0;t<n.length;t++){let i,l=n[t];{const t=e().astSync(l);let n=!1;t.walk((e=>{"nesting"===e.type&&(n=!0)}));const r=t.nodes[0];let o=!1;r.each((e=>"combinator"===e.type&&(o=!0,!1))),n?o&&r.insertBefore(r.at(0),e.nesting({})):(r.insertBefore(r.at(0),e.combinator({value:" "})),r.insertBefore(r.at(0),e.nesting({}))),l=t.toString()}let c=[],a=0;if(e().astSync(l).walkNesting((()=>{a++})),a>1&&o.length>1)c=combinationsWithSizeN(o,a),i=c.length;else{i=o.length;for(let e=0;e<o.length;e++){c.push([]);for(let t=0;t<a;t++)c[e].push(o[e])}}for(let t=0;t<i;t++){let n=0;const o=e().astSync(l);o.walk((o=>{if("nesting"!==o.type)return;let s=c[t][n];n++,"root"===s.type&&1===s.nodes.length&&(s=s.nodes[0]);const i=e().astSync(`:is(${s.toString()})`),l=isSimpleSelector(s.nodes[0]),a=isCompoundSelector(s.nodes[0]),p=isSimpleSelector(o),u=isCompoundSelector(o);if(l&&p)return void o.replaceWith(s.clone());if((l||a)&&(p||u)){const e=o.parent;return l&&"selector"===s.type?o.replaceWith(s.clone().nodes[0]):o.replaceWith(...s.clone().nodes),void(e&&e.nodes.length>1&&sortCompoundSelectorsInsideComplexSelector(e))}if(l){const e=o.parent;return o.replaceWith(s.clone().nodes[0]),void(e&&sortCompoundSelectorsInsideComplexSelector(e))}if(a){const e=o.parent;return o.replaceWith(...s.clone().nodes),void(e&&sortCompoundSelectorsInsideComplexSelector(e))}if(nestingIsFirstAndOnlyInSelectorWithEitherSpaceOrChildCombinator(o)){const e=o.parent;return o.replaceWith(...s.clone().nodes),void(e&&sortCompoundSelectorsInsideComplexSelector(e))}if(nestingIsNotInsideCompoundSelector(o)){const e=o.parent;return o.replaceWith(...s.clone().nodes),void(e&&sortCompoundSelectorsInsideComplexSelector(e))}const d=o.parent;r.noIsPseudoSelector?o.replaceWith(...s.clone().nodes):o.replaceWith(...i.clone({}).nodes),d&&sortCompoundSelectorsInsideComplexSelector(d)})),s.push(o.toString())}}return s}function isSimpleSelector(e){return"combinator"!==e.type&&!(e.parent&&e.parent.nodes.length>1)}function isCompoundSelector(e,t=null){if(isSimpleSelector(e))return!1;if(!e.parent)return!1;if(!!e.parent.nodes.find((e=>"combinator"===e.type)))return!1;return!(!!e.parent.nodes.find((e=>"nesting"===e.type))&&t&&!isCompoundSelector(t))}function nestingIsFirstAndOnlyInSelectorWithEitherSpaceOrChildCombinator(e){if(!e.parent)return!1;if(0!==e.parent.nodes.indexOf(e))return!1;for(let t=1;t<e.parent.nodes.length;t++)if("combinator"===e.parent.nodes[t].type&&" "!==e.parent.nodes[t].value&&">"!==e.parent.nodes[t].value)return!1;return!0}function nestingIsNotInsideCompoundSelector(e){if(isSimpleSelector(e))return!0;if(!e.parent)return!1;for(let t=0;t<e.parent.nodes.length;t++)if("nesting"!==e.parent.nodes[t].type&&(e.parent.nodes[t].prev()||e.parent.nodes[t].next())){if(e.parent.nodes[t].prev()&&"combinator"!==e.parent.nodes[t].prev().type)return!1;if(e.parent.nodes[t].next()&&"combinator"!==e.parent.nodes[t].next().type)return!1}return!0}function groupDeclarations(e){let t=-1;e.each(((n,r)=>{if("decl"===n.type)return t===r-1?void(t=r):(n.remove(),e.insertAfter(t,n),void(t=e.index(n)));if("atrule"===n.type&&"mixin"===n.name.toLowerCase()){let o=n.prev();for(;o;){if("rule"===o.type||"atrule"===o.type)return;o=o.prev()}return t===r-1?void(t=r):(n.remove(),e.insertAfter(t,n),void(t=e.index(n)))}if("comment"===n.type){const o=n.next();if(o&&("comment"===o.type||"rule"===o.type||"atrule"===o.type&&"mixin"!==o.name.toLowerCase()))return;return t===r-1?void(t=r):(n.remove(),e.insertAfter(t,n),void(t=e.index(n)))}}))}function transformRuleWithinRule(e,t,n,r){let o=[];try{o=mergeSelectors(t.selectors,e.selectors,r)}catch(r){return void e.warn(n,`Failed to parse selectors : "${t.selector}" / "${e.selector}" with message: "${r.message}"`)}if(!o.length)return;groupDeclarations(t),shiftNodesBeforeParent(e,t),e.selectors=o;"rule"===e.type&&"rule"===t.type&&e.selector===t.selector&&e.append(...t.nodes),cleanupParent(t)}function isValidRuleWithinRule(e){return e.selectors.every((e=>-1===e.indexOf("|")))}function comma(e){const t=[];let n="",r=!1,o=0,s=!1,i=!1;for(const l of e)i?i=!1:"\\"===l?i=!0:s?l===s&&(s=!1):'"'===l||"'"===l?s=l:"("===l?o+=1:")"===l?o>0&&(o-=1):0===o&&","===l&&(r=!0),r?(""!==n&&t.push(n.trim()),n="",r=!1):n+=l;return t.push(n.trim()),t}function transformNestRuleWithinRule(e,t,n,r,o){let s=[];try{s=mergeSelectors(t.selectors,comma(e.params),o)}catch(r){return void e.warn(n,`Failed to parse selectors : "${t.selector}" / "${e.params}" with message: "${r.message}"`)}if(!s.length)return;shiftNodesBeforeParent(e,t);const i=t.clone().removeAll().append(e.nodes);i.raws.semicolon=!0,i.selectors=s,e.replaceWith(i),cleanupParent(t),r(i,n,o)}function isValidNestRuleWithinRule(e){return comma(e.params).every((e=>e.split("&").length>=2&&-1===e.indexOf("|")))}var o=["container","document","media","supports","layer","starting-style"];function atruleWithinRule(e,t,n,r,o){if(groupDeclarations(t),shiftNodesBeforeParent(e,t),e.nodes){const s=t.clone().removeAll().append(e.nodes);e.append(s),cleanupParent(t),r(s,n,o)}else cleanupParent(t)}function isAtruleWithinRule(e){return o.includes(e.name)}function transformAtruleWithinAtrule(e,t){var n,r;groupDeclarations(t),shiftNodesBeforeParent(e,t),e.params=(n=t.params,r=e.params,comma(n).map((e=>comma(r).map((t=>`${e} and ${t}`)).join(", "))).join(", ")),cleanupParent(t)}function isAtruleWithinAtrule(e,t){return o.includes(e.name)&&e.name===t.name}function isAtRule(e){return e&&"atrule"===e.type}function isNestRule(e){return e&&isAtRule(e)&&"nest"===e.name}function isRule(e){return e&&"rule"===e.type}function walk(e,t,n){e.each((r=>{const o=r.parent;isNestRule(r)&&!n.silenceAtNestWarning&&e.warn(t,`\`@nest\` was removed from the CSS Nesting specification and will be removed from PostCSS Nesting in the next major version.\nChange \`@nest ${r.params} {}\` to \`${r.params} {}\` to migrate to the latest standard.`),isRule(r)&&isRule(o)&&isValidRuleWithinRule(r)?transformRuleWithinRule(r,o,t,n):isNestRule(r)&&isRule(o)&&isValidNestRuleWithinRule(r)?transformNestRuleWithinRule(r,o,t,walk,n):isAtRule(r)&&isRule(o)&&isAtruleWithinRule(r)?atruleWithinRule(r,o,t,walk,n):isAtRule(r)&&isAtRule(o)&&isAtruleWithinAtrule(r,o)&&transformAtruleWithinAtrule(r,o),"nodes"in r&&r.nodes.length&&walk(r,t,n)}))}const creator=e=>{const t=Object.assign({noIsPseudoSelector:!1,silenceAtNestWarning:!1},e);return{postcssPlugin:"postcss-nesting",Rule(e,{result:n}){walk(e,n,t),e.selector.includes("&")&&ersandToScope(e,n)}}};creator.postcss=!0;export{creator as default}; +import e from"postcss-selector-parser";import{selectorSpecificity as t}from"@csstools/selector-specificity";const n=e.pseudo({value:":is"});function sortCompoundSelectorsInsideComplexSelector(t){if(!t||!t.nodes)return;const r=[];let o=[];for(let s=0;s<t.nodes.length;s++)if("combinator"!==t.nodes[s].type)if(e.isPseudoElement(t.nodes[s]))r.push(o),o=[t.nodes[s]];else{if("tag"===t.nodes[s].type&&o.find((e=>"tag"===e.type))){const r=n.clone({}),o=t.nodes[s];o.replaceWith(r),r.append(e.selector({nodes:[o],value:void 0}))}o.push(t.nodes[s])}else r.push(o),r.push([t.nodes[s]]),o=[];r.push(o);const s=[];for(let e=0;e<r.length;e++){const t=r[e];t.sort(((e,t)=>"selector"===e.type&&"selector"===t.type&&e.nodes.length&&t.nodes.length?selectorTypeOrder(e.nodes[0])-selectorTypeOrder(t.nodes[0]):"selector"===e.type&&e.nodes.length?selectorTypeOrder(e.nodes[0])-selectorTypeOrder(t):"selector"===t.type&&t.nodes.length?selectorTypeOrder(e)-selectorTypeOrder(t.nodes[0]):selectorTypeOrder(e)-selectorTypeOrder(t)));for(let e=0;e<t.length;e++)s.push(t[e])}for(let e=s.length-1;e>=0;e--)s[e].remove(),t.prepend(s[e])}function selectorTypeOrder(t){return e.isPseudoElement(t)?r.pseudoElement:r[t.type]}const r={universal:0,tag:1,pseudoElement:2,id:3,class:4,attribute:5,pseudo:6,selector:7,string:8,root:9,comment:10};function ampersandToScope(t,n){let r,o=t.parent;for(;o;){if("rule"===o.type)return;o=o.parent}try{r=e().astSync(t.selector)}catch(e){return void t.warn(n,`Failed to parse selector : "${t.selector}" with message: "${e instanceof Error?e.message:e}"`)}r&&(r.walkNesting((t=>{const n=t.parent;t.replaceWith(e.pseudo({value:":scope"})),n&&sortCompoundSelectorsInsideComplexSelector(n)})),t.selector=r.toString())}function cleanupParent(e){if(!e.nodes.length)return void e.remove();const t=e.nodes.filter((e=>"comment"===e.type));t.length===e.nodes.length&&e.replaceWith(...t)}function shiftNodesBeforeParent(e,t){const n=t.index(e);if(n){const e=t.cloneBefore().removeAll().append(t.nodes.slice(0,n));e.raws.semicolon=!0,cleanupParent(e)}t.before(e),t.raws.semicolon=!0}function combinationsWithSizeN(e,t){if(t<2)throw new Error("n must be greater than 1");if(e.length<2)throw new Error("s must be greater than 1");if(Math.pow(e.length,t)>1e4)throw new Error("Too many combinations when trying to resolve a nested selector with lists, reduce the complexity of your selectors");const n=[];for(let e=0;e<t;e++)n[e]=0;const r=[];for(;;){const o=[];for(let s=t-1;s>=0;s--){let t=n[s];if(t>=e.length){if(t=0,n[s]=0,0===s)return r;n[s-1]+=1}o[s]=e[t]}r.push(o),n[n.length-1]++}}function nodesAreEquallySpecific(n){const r=n.map((t=>e().astSync(t))).map((e=>t(e))),o=r[0];for(let e=1;e<r.length;e++)if(o.a!==r[e].a||o.b!==r[e].b||o.c!==r[e].c)return!1;return!0}function mergeSelectors(t,n,r){let o=[];o=nodesAreEquallySpecific(t)||r.noIsPseudoSelector?t.map((t=>e().astSync(t))):[e().astSync(`:is(${t.join(",")})`)];const s=[];for(let t=0;t<n.length;t++){let i,l=n[t];{const t=e().astSync(l);let n=!1;t.walk((e=>{"nesting"===e.type&&(n=!0)}));const r=t.nodes[0];let o=!1;r.each((e=>"combinator"===e.type&&(o=!0,!1))),n?o&&r.insertBefore(r.at(0),e.nesting({})):(r.insertBefore(r.at(0),e.combinator({value:" "})),r.insertBefore(r.at(0),e.nesting({}))),l=t.toString()}let c=[],a=0;if(e().astSync(l).walkNesting((()=>{a++})),a>1&&o.length>1)c=combinationsWithSizeN(o,a),i=c.length;else{i=o.length;for(let e=0;e<o.length;e++){c.push([]);for(let t=0;t<a;t++)c[e].push(o[e])}}for(let t=0;t<i;t++){let n=0;const o=e().astSync(l);o.walk((o=>{if("nesting"!==o.type)return;let s=c[t][n];n++,"root"===s.type&&1===s.nodes.length&&(s=s.nodes[0]);const i=e().astSync(`:is(${s.toString()})`),l=isSimpleSelector(s.nodes[0]),a=isCompoundSelector(s.nodes[0]),p=isSimpleSelector(o),u=isCompoundSelector(o);if(l&&p)return void o.replaceWith(s.clone());if((l||a)&&(p||u)){const e=o.parent;return l&&"selector"===s.type?o.replaceWith(s.clone().nodes[0]):o.replaceWith(...s.clone().nodes),void(e&&e.nodes.length>1&&sortCompoundSelectorsInsideComplexSelector(e))}if(l){const e=o.parent;return o.replaceWith(s.clone().nodes[0]),void(e&&sortCompoundSelectorsInsideComplexSelector(e))}if(a){const e=o.parent;return o.replaceWith(...s.clone().nodes),void(e&&sortCompoundSelectorsInsideComplexSelector(e))}if(nestingIsFirstAndOnlyInSelectorWithEitherSpaceOrChildCombinator(o)){const e=o.parent;return o.replaceWith(...s.clone().nodes),void(e&&sortCompoundSelectorsInsideComplexSelector(e))}if(nestingIsNotInsideCompoundSelector(o)){const e=o.parent;return o.replaceWith(...s.clone().nodes),void(e&&sortCompoundSelectorsInsideComplexSelector(e))}const d=o.parent;r.noIsPseudoSelector?o.replaceWith(...s.clone().nodes):o.replaceWith(...i.clone({}).nodes),d&&sortCompoundSelectorsInsideComplexSelector(d)})),s.push(o.toString())}}return s}function isSimpleSelector(e){return"combinator"!==e.type&&!(e.parent&&e.parent.nodes.length>1)}function isCompoundSelector(e,t=null){if(isSimpleSelector(e))return!1;if(!e.parent)return!1;if(!!e.parent.nodes.find((e=>"combinator"===e.type)))return!1;return!(!!e.parent.nodes.find((e=>"nesting"===e.type))&&t&&!isCompoundSelector(t))}function nestingIsFirstAndOnlyInSelectorWithEitherSpaceOrChildCombinator(e){if(!e.parent)return!1;if(0!==e.parent.nodes.indexOf(e))return!1;for(let t=1;t<e.parent.nodes.length;t++)if("combinator"===e.parent.nodes[t].type&&" "!==e.parent.nodes[t].value&&">"!==e.parent.nodes[t].value)return!1;return!0}function nestingIsNotInsideCompoundSelector(e){if(isSimpleSelector(e))return!0;if(!e.parent)return!1;for(let t=0;t<e.parent.nodes.length;t++)if("nesting"!==e.parent.nodes[t].type&&(e.parent.nodes[t].prev()||e.parent.nodes[t].next())){if(e.parent.nodes[t].prev()&&"combinator"!==e.parent.nodes[t].prev().type)return!1;if(e.parent.nodes[t].next()&&"combinator"!==e.parent.nodes[t].next().type)return!1}return!0}function groupDeclarations(e){let t=-1;e.each(((n,r)=>{if("decl"===n.type)return t===r-1?void(t=r):(n.remove(),e.insertAfter(t,n),void(t=e.index(n)));if("atrule"===n.type&&"mixin"===n.name.toLowerCase()){let o=n.prev();for(;o;){if("rule"===o.type||"atrule"===o.type)return;o=o.prev()}return t===r-1?void(t=r):(n.remove(),e.insertAfter(t,n),void(t=e.index(n)))}if("comment"===n.type){const o=n.next();if(o&&("comment"===o.type||"rule"===o.type||"atrule"===o.type&&"mixin"!==o.name.toLowerCase()))return;return t===r-1?void(t=r):(n.remove(),e.insertAfter(t,n),void(t=e.index(n)))}}))}function transformRuleWithinRule(e,t,n,r){let o=[];try{o=mergeSelectors(t.selectors,e.selectors,r)}catch(r){return void e.warn(n,`Failed to parse selectors : "${t.selector}" / "${e.selector}" with message: "${r instanceof Error?r.message:r}"`)}if(!o.length)return;groupDeclarations(t),shiftNodesBeforeParent(e,t),e.selectors=o;"rule"===e.type&&"rule"===t.type&&e.selector===t.selector&&e.append(...t.nodes),cleanupParent(t)}function isValidRuleWithinRule(e){return e.selectors.every((e=>-1===e.indexOf("|")))}function comma(e){const t=[];let n="",r=!1,o=0,s=!1,i=!1;for(const l of e)i?i=!1:"\\"===l?i=!0:s?l===s&&(s=!1):'"'===l||"'"===l?s=l:"("===l?o+=1:")"===l?o>0&&(o-=1):0===o&&","===l&&(r=!0),r?(""!==n&&t.push(n.trim()),n="",r=!1):n+=l;return t.push(n.trim()),t}function transformNestRuleWithinRule(e,t,n,r,o){let s=[];try{s=mergeSelectors(t.selectors,comma(e.params),o)}catch(r){return void e.warn(n,`Failed to parse selectors : "${t.selector}" / "${e.params}" with message: "${r instanceof Error?r.message:r}"`)}if(!s.length)return;shiftNodesBeforeParent(e,t);const i=t.clone().removeAll().append(e.nodes);i.raws.semicolon=!0,i.selectors=s,e.replaceWith(i),cleanupParent(t),r(i,n,o)}function isValidNestRuleWithinRule(e){return comma(e.params).every((e=>e.split("&").length>=2&&-1===e.indexOf("|")))}var o=["container","document","media","supports","layer","starting-style"];function atruleWithinRule(e,t,n,r,o){if(groupDeclarations(t),shiftNodesBeforeParent(e,t),e.nodes){const s=t.clone().removeAll().append(e.nodes);e.append(s),cleanupParent(t),r(s,n,o)}else cleanupParent(t)}function isAtruleWithinRule(e){return o.includes(e.name)}function transformAtruleWithinAtrule(e,t){var n,r;groupDeclarations(t),shiftNodesBeforeParent(e,t),e.params=(n=t.params,r=e.params,comma(n).map((e=>comma(r).map((t=>`${e} and ${t}`)).join(", "))).join(", ")),cleanupParent(t)}function isAtruleWithinAtrule(e,t){return o.includes(e.name)&&e.name===t.name}function isAtRule(e){return e&&"atrule"===e.type}function isNestRule(e){return e&&isAtRule(e)&&"nest"===e.name}function isRule(e){return e&&"rule"===e.type}function walk(e,t,n){e.each((r=>{const o=r.parent;isNestRule(r)&&!n.silenceAtNestWarning&&e.warn(t,`\`@nest\` was removed from the CSS Nesting specification and will be removed from PostCSS Nesting in the next major version.\nChange \`@nest ${r.params} {}\` to \`${r.params} {}\` to migrate to the latest standard.`),isRule(r)&&isRule(o)&&isValidRuleWithinRule(r)?transformRuleWithinRule(r,o,t,n):isNestRule(r)&&isRule(o)&&isValidNestRuleWithinRule(r)?transformNestRuleWithinRule(r,o,t,walk,n):isAtRule(r)&&isRule(o)&&isAtruleWithinRule(r)?atruleWithinRule(r,o,t,walk,n):isAtRule(r)&&isAtRule(o)&&isAtruleWithinAtrule(r,o)&&transformAtruleWithinAtrule(r,o),"nodes"in r&&r.nodes.length&&walk(r,t,n)}))}const creator=e=>{const t=Object.assign({noIsPseudoSelector:!1,silenceAtNestWarning:!1},e);return{postcssPlugin:"postcss-nesting",Rule(e,{result:n}){walk(e,n,t),e.selector.includes("&")&&ersandToScope(e,n)}}};creator.postcss=!0;export{creator as default}; diff --git a/node_modules/postcss-nesting/dist/lib/ampersand-to-scope.d.ts b/node_modules/postcss-nesting/dist/lib/ampersand-to-scope.d.ts deleted file mode 100644 index f82c36f9..00000000 --- a/node_modules/postcss-nesting/dist/lib/ampersand-to-scope.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import type { Result, Rule } from 'postcss'; -export default function ampersandToScope(rule: Rule, result: Result): void; diff --git a/node_modules/postcss-nesting/dist/lib/atrule-within-atrule.d.ts b/node_modules/postcss-nesting/dist/lib/atrule-within-atrule.d.ts deleted file mode 100644 index f06ffa9a..00000000 --- a/node_modules/postcss-nesting/dist/lib/atrule-within-atrule.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { AtRule } from 'postcss'; -export default function transformAtruleWithinAtrule(node: AtRule, parent: AtRule): void; -export declare function isAtruleWithinAtrule(node: AtRule, parent: AtRule): boolean; diff --git a/node_modules/postcss-nesting/dist/lib/atrule-within-rule.d.ts b/node_modules/postcss-nesting/dist/lib/atrule-within-rule.d.ts deleted file mode 100644 index 3c7c0911..00000000 --- a/node_modules/postcss-nesting/dist/lib/atrule-within-rule.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { options } from './options.js'; -import { walkFunc } from './walk-func.js'; -import type { AtRule, Result, Rule } from 'postcss'; -export default function atruleWithinRule(node: AtRule, parent: Rule, result: Result, walk: walkFunc, opts: options): void; -export declare function isAtruleWithinRule(node: AtRule): boolean; diff --git a/node_modules/postcss-nesting/dist/lib/cleanup-parent.d.ts b/node_modules/postcss-nesting/dist/lib/cleanup-parent.d.ts deleted file mode 100644 index 5547db14..00000000 --- a/node_modules/postcss-nesting/dist/lib/cleanup-parent.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import type { ChildNode, Container } from 'postcss'; -export default function cleanupParent(parent: Container<ChildNode>): void; diff --git a/node_modules/postcss-nesting/dist/lib/group-declarations.d.ts b/node_modules/postcss-nesting/dist/lib/group-declarations.d.ts deleted file mode 100644 index 11643420..00000000 --- a/node_modules/postcss-nesting/dist/lib/group-declarations.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import type { ChildNode, Container } from 'postcss'; -export default function groupDeclarations(node: Container<ChildNode>): void; diff --git a/node_modules/postcss-nesting/dist/lib/is-type-of-rule.d.ts b/node_modules/postcss-nesting/dist/lib/is-type-of-rule.d.ts deleted file mode 100644 index d6cb2458..00000000 --- a/node_modules/postcss-nesting/dist/lib/is-type-of-rule.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import type { AtRule, Node, Rule } from 'postcss'; -export declare function isAtRule(node?: Node): node is AtRule; -export declare function isNestRule(node?: Node): node is AtRule; -export declare function isRule(node?: Node): node is Rule; diff --git a/node_modules/postcss-nesting/dist/lib/list.d.ts b/node_modules/postcss-nesting/dist/lib/list.d.ts deleted file mode 100644 index 67a64736..00000000 --- a/node_modules/postcss-nesting/dist/lib/list.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function comma(string: string): string[]; diff --git a/node_modules/postcss-nesting/dist/lib/merge-params.d.ts b/node_modules/postcss-nesting/dist/lib/merge-params.d.ts deleted file mode 100644 index 0547e8f7..00000000 --- a/node_modules/postcss-nesting/dist/lib/merge-params.d.ts +++ /dev/null @@ -1 +0,0 @@ -export default function mergeParams(fromParams: string, toParams: string): string; diff --git a/node_modules/postcss-nesting/dist/lib/merge-selectors/combinations-of-size-n.d.ts b/node_modules/postcss-nesting/dist/lib/merge-selectors/combinations-of-size-n.d.ts deleted file mode 100644 index 56bbf723..00000000 --- a/node_modules/postcss-nesting/dist/lib/merge-selectors/combinations-of-size-n.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function combinationsWithSizeN(set: Array<string>, n: number): Array<Array<string>>; diff --git a/node_modules/postcss-nesting/dist/lib/merge-selectors/compound-selector-order.d.ts b/node_modules/postcss-nesting/dist/lib/merge-selectors/compound-selector-order.d.ts deleted file mode 100644 index 3d43458e..00000000 --- a/node_modules/postcss-nesting/dist/lib/merge-selectors/compound-selector-order.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import type { Container, Node } from 'postcss-selector-parser'; -export declare function sortCompoundSelectorsInsideComplexSelector(node: Container<string, Node>): void; diff --git a/node_modules/postcss-nesting/dist/lib/merge-selectors/merge-selectors.d.ts b/node_modules/postcss-nesting/dist/lib/merge-selectors/merge-selectors.d.ts deleted file mode 100644 index f46fd8d7..00000000 --- a/node_modules/postcss-nesting/dist/lib/merge-selectors/merge-selectors.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { options } from '../options'; -export default function mergeSelectors(fromSelectors: Array<string>, toSelectors: Array<string>, opts: options): any[]; diff --git a/node_modules/postcss-nesting/dist/lib/merge-selectors/specificity.d.ts b/node_modules/postcss-nesting/dist/lib/merge-selectors/specificity.d.ts deleted file mode 100644 index 2afcbaf9..00000000 --- a/node_modules/postcss-nesting/dist/lib/merge-selectors/specificity.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function nodesAreEquallySpecific(nodes: Array<string>): boolean; diff --git a/node_modules/postcss-nesting/dist/lib/nest-rule-within-rule.d.ts b/node_modules/postcss-nesting/dist/lib/nest-rule-within-rule.d.ts deleted file mode 100644 index a0ea699b..00000000 --- a/node_modules/postcss-nesting/dist/lib/nest-rule-within-rule.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type { AtRule, Result, Rule } from 'postcss'; -import { walkFunc } from './walk-func.js'; -import { options } from './options.js'; -export default function transformNestRuleWithinRule(node: AtRule, parent: Rule, result: Result, walk: walkFunc, opts: options): void; -export declare function isValidNestRuleWithinRule(node: AtRule): boolean; diff --git a/node_modules/postcss-nesting/dist/lib/options.d.ts b/node_modules/postcss-nesting/dist/lib/options.d.ts deleted file mode 100644 index 87677184..00000000 --- a/node_modules/postcss-nesting/dist/lib/options.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type options = { - noIsPseudoSelector: boolean; - silenceAtNestWarning: boolean; -}; diff --git a/node_modules/postcss-nesting/dist/lib/rule-within-rule.d.ts b/node_modules/postcss-nesting/dist/lib/rule-within-rule.d.ts deleted file mode 100644 index 5f733d3b..00000000 --- a/node_modules/postcss-nesting/dist/lib/rule-within-rule.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import type { Result, Rule } from 'postcss'; -import { options } from './options.js'; -export default function transformRuleWithinRule(node: Rule, parent: Rule, result: Result, opts: options): void; -export declare function isValidRuleWithinRule(node: Rule): boolean; diff --git a/node_modules/postcss-nesting/dist/lib/shift-nodes-before-parent.d.ts b/node_modules/postcss-nesting/dist/lib/shift-nodes-before-parent.d.ts deleted file mode 100644 index 0876f2ba..00000000 --- a/node_modules/postcss-nesting/dist/lib/shift-nodes-before-parent.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import type { ChildNode, Container } from 'postcss'; -export default function shiftNodesBeforeParent(node: ChildNode, parent: Container<ChildNode>): void; diff --git a/node_modules/postcss-nesting/dist/lib/valid-atrules.d.ts b/node_modules/postcss-nesting/dist/lib/valid-atrules.d.ts deleted file mode 100644 index d451d2bc..00000000 --- a/node_modules/postcss-nesting/dist/lib/valid-atrules.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -declare const _default: string[]; -export default _default; diff --git a/node_modules/postcss-nesting/dist/lib/walk-func.d.ts b/node_modules/postcss-nesting/dist/lib/walk-func.d.ts deleted file mode 100644 index 36cff833..00000000 --- a/node_modules/postcss-nesting/dist/lib/walk-func.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import type { Container, Result } from 'postcss'; -export type walkFunc = (node: Container, result: Result, opts: { - noIsPseudoSelector: boolean; -}) => void; diff --git a/node_modules/postcss-nesting/dist/lib/walk.d.ts b/node_modules/postcss-nesting/dist/lib/walk.d.ts deleted file mode 100644 index b50ece78..00000000 --- a/node_modules/postcss-nesting/dist/lib/walk.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { Container, Result } from 'postcss'; -import { options } from './options.js'; -export default function walk(node: Container, result: Result, opts: options): void; diff --git a/node_modules/postcss-nesting/package.json b/node_modules/postcss-nesting/package.json index 53907745..010bd51c 100644 --- a/node_modules/postcss-nesting/package.json +++ b/node_modules/postcss-nesting/package.json @@ -1,7 +1,7 @@ { "name": "postcss-nesting", "description": "Nest rules inside each other in CSS", - "version": "12.0.1", + "version": "12.0.2", "contributors": [ { "name": "Antonio Laguna", @@ -31,17 +31,20 @@ "engines": { "node": "^14 || ^16 || >=18" }, + "type": "module", "main": "dist/index.cjs", "module": "dist/index.mjs", - "types": "dist/index.d.ts", "jsdelivr": "dist/index.mjs", "unpkg": "dist/index.mjs", "exports": { ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "require": "./dist/index.cjs", - "default": "./dist/index.mjs" + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.mjs" + }, + "require": { + "default": "./dist/index.cjs" + } } }, "files": [ @@ -51,25 +54,12 @@ "dist" ], "dependencies": { - "@csstools/selector-specificity": "^3.0.0", + "@csstools/selector-specificity": "^3.0.1", "postcss-selector-parser": "^6.0.13" }, "peerDependencies": { "postcss": "^8.4" }, - "devDependencies": { - "@csstools/postcss-tape": "*", - "puppeteer": "^21.0.1" - }, - "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: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-nesting#readme", "repository": { "type": "git", @@ -94,14 +84,5 @@ "specs", "syntax", "w3c" - ], - "csstools": { - "cssdbId": "nesting-rules", - "exportName": "postcssNesting", - "humanReadableName": "PostCSS Nesting", - "specUrl": "https://www.w3.org/TR/css-nesting-1/" - }, - "volta": { - "extends": "../../package.json" - } + ] } |
