summaryrefslogtreecommitdiff
path: root/node_modules/@csstools/selector-resolve-nested
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2024-08-30 17:21:18 +0800
committerlittleblack111 <littleblack11111@gmail.com>2024-08-30 17:21:18 +0800
commitefbc2ffe6a1ee5ec38a4396305561d6515d0943e (patch)
tree2b4c94f18f2c792dfda813050755d5c0273fae22 /node_modules/@csstools/selector-resolve-nested
parent43acceb75957c880a5ba5a31aae221394a36d5f6 (diff)
node fixes, updates
Diffstat (limited to 'node_modules/@csstools/selector-resolve-nested')
-rw-r--r--node_modules/@csstools/selector-resolve-nested/CHANGELOG.md31
-rw-r--r--node_modules/@csstools/selector-resolve-nested/LICENSE.md18
-rw-r--r--node_modules/@csstools/selector-resolve-nested/README.md33
-rw-r--r--node_modules/@csstools/selector-resolve-nested/dist/index.cjs1
-rw-r--r--node_modules/@csstools/selector-resolve-nested/dist/index.d.ts47
-rw-r--r--node_modules/@csstools/selector-resolve-nested/dist/index.mjs1
-rw-r--r--node_modules/@csstools/selector-resolve-nested/package.json79
7 files changed, 210 insertions, 0 deletions
diff --git a/node_modules/@csstools/selector-resolve-nested/CHANGELOG.md b/node_modules/@csstools/selector-resolve-nested/CHANGELOG.md
new file mode 100644
index 00000000..3120273a
--- /dev/null
+++ b/node_modules/@csstools/selector-resolve-nested/CHANGELOG.md
@@ -0,0 +1,31 @@
+# Changes to Selector Resolve Nested
+
+## 1.1.0
+
+_February 1, 2024_
+
+- Add `flattenNestedSelector` function to support more kinds of static analysis for nested selectors.
+
+## 1.0.3
+
+_January 25, 2024_
+
+- Correctly add child nodes to newly constructed `Selector` and `Root` AST nodes.
+
+## 1.0.2
+
+_January 22, 2024_
+
+- Preserve extra/unknown fields on source objects of AST nodes
+
+### 1.0.1
+
+_January 21, 2024_
+
+- Improve source index resolution
+
+### 1.0.0
+
+_January 21, 2024_
+
+- Initial version
diff --git a/node_modules/@csstools/selector-resolve-nested/LICENSE.md b/node_modules/@csstools/selector-resolve-nested/LICENSE.md
new file mode 100644
index 00000000..e8ae93b9
--- /dev/null
+++ b/node_modules/@csstools/selector-resolve-nested/LICENSE.md
@@ -0,0 +1,18 @@
+MIT No Attribution (MIT-0)
+
+Copyright © CSSTools Contributors
+
+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.
+
+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/@csstools/selector-resolve-nested/README.md b/node_modules/@csstools/selector-resolve-nested/README.md
new file mode 100644
index 00000000..9f7aa7b0
--- /dev/null
+++ b/node_modules/@csstools/selector-resolve-nested/README.md
@@ -0,0 +1,33 @@
+# Selector Resolve Nested
+
+[<img alt="npm version" src="https://img.shields.io/npm/v/@csstools/selector-resolve-nested.svg" height="20">][npm-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]
+
+## API
+
+[Read the API docs](./docs/selector-resolve-nested.md)
+
+## Usage
+
+Add [Selector Resolve Nested] to your project:
+
+```bash
+npm install @csstools/selector-resolve-nested --save-dev
+```
+
+```js
+import { resolveNestedSelector } from '@csstools/selector-resolve-nested';
+import parser from 'postcss-selector-parser';
+
+const a = parser().astSync('.foo &');
+const b = parser().astSync('.bar');
+
+resolveNestedSelector(a, b); // '.foo .bar'
+```
+
+[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
+[discord]: https://discord.gg/bUadyRwkJS
+[npm-url]: https://www.npmjs.com/package/@csstools/selector-resolve-nested
+
+[Selector Resolve Nested]: https://github.com/csstools/postcss-plugins/tree/main/packages/selector-resolve-nested
diff --git a/node_modules/@csstools/selector-resolve-nested/dist/index.cjs b/node_modules/@csstools/selector-resolve-nested/dist/index.cjs
new file mode 100644
index 00000000..754d81ac
--- /dev/null
+++ b/node_modules/@csstools/selector-resolve-nested/dist/index.cjs
@@ -0,0 +1 @@
+"use strict";var e=require("postcss-selector-parser");function sourceFrom(e){return{sourceIndex:e.sourceIndex??0,source:e.source}}function sortCompoundSelectorsInsideComplexSelector(o){const t=[];let r=[];o.each((o=>{if("combinator"===o.type)return t.push(r,[o]),void(r=[]);if(e.isPseudoElement(o))return t.push(r),void(r=[o]);if("universal"===o.type&&r.find((e=>"universal"===e.type)))o.remove();else{if("tag"===o.type&&r.find((e=>"tag"===e.type))){o.remove();const t=e.selector({value:"",...sourceFrom(o)});t.append(o);const n=e.pseudo({value:":is",...sourceFrom(o)});return n.append(t),void r.push(n)}r.push(o)}})),t.push(r);const n=[];for(let e=0;e<t.length;e++){const o=t[e];o.sort(((e,o)=>selectorTypeOrder(e)-selectorTypeOrder(o))),n.push(...o)}o.removeAll();for(let e=n.length-1;e>=0;e--)n[e].remove(),o.prepend(n[e])}function selectorTypeOrder(t){return e.isPseudoElement(t)?o.pseudoElement:o[t.type]}const o={universal:0,tag:1,pseudoElement:2,nesting:3,id:4,class:5,attribute:6,pseudo:7,comment:8};function prepareParentSelectors(o,t=!1){if(t||!isCompoundSelector(o.nodes)){const t=e.pseudo({value:":is",...sourceFrom(o)});return o.nodes.forEach((e=>{t.append(e.clone())})),[t]}return o.nodes[0].nodes.map((e=>e.clone()))}function isCompoundSelector(o){return 1===o.length&&!o[0].nodes.some((o=>"combinator"===o.type||e.isPseudoElement(o)))}function combinationsWithSizeN(e,o){if(o<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,o)>1e4)throw new Error("Too many combinations when trying to resolve a nested selector with lists, reduce the complexity of your selectors");const t=[];for(let e=0;e<o;e++)t[e]=0;const r=[];for(;;){const n=[];for(let s=o-1;s>=0;s--){let o=t[s];if(o>=e.length){if(o=0,t[s]=0,0===s)return r;t[s-1]+=1}n[s]=e[o].clone()}r.push(n),t[t.length-1]++}}exports.flattenNestedSelector=function flattenNestedSelector(o,t){const r=[];for(let n=0;n<o.nodes.length;n++){const s=o.nodes[n].clone();let c,l=0;{let o=!1;s.walkNesting((()=>{o=!0,l++})),o?"combinator"===s.nodes[0]?.type&&(s.prepend(e.nesting({...sourceFrom(s)})),l++):(s.prepend(e.combinator({value:" ",...sourceFrom(s)})),s.prepend(e.nesting({...sourceFrom(s)})),l++)}let p=[];if(l>1&&t.nodes.length>1)p=combinationsWithSizeN(t.nodes,l),c=p.length;else{c=t.nodes.length;for(let e=0;e<t.nodes.length;e++){p.push([]);for(let o=0;o<l;o++)p[e].push(t.nodes[e].clone())}}for(let e=0;e<c;e++){let o=0;const t=s.clone();t.walkNesting((t=>{const r=p[e][o];o++,t.replaceWith(...r.nodes)})),r.push(t)}}const n=e.root({value:"",...sourceFrom(o)});return r.forEach((e=>{n.append(e)})),n},exports.resolveNestedSelector=function resolveNestedSelector(o,t){const r=[];for(let n=0;n<o.nodes.length;n++){const s=o.nodes[n].clone();{let o=!1;s.walkNesting((()=>(o=!0,!1))),o?"combinator"===s.nodes[0]?.type&&s.prepend(e.nesting({...sourceFrom(s)})):(s.prepend(e.combinator({value:" ",...sourceFrom(s)})),s.prepend(e.nesting({...sourceFrom(s)})))}{const e=new Set;s.walkNesting((o=>{const r=o.parent;e.add(r),"pseudo"===r.parent?.type&&":has"===r.parent.value?.toLowerCase()?o.replaceWith(...prepareParentSelectors(t,!0)):o.replaceWith(...prepareParentSelectors(t))}));for(const o of e)sortCompoundSelectorsInsideComplexSelector(o)}s.walk((e=>{"combinator"===e.type&&""!==e.value.trim()?(e.rawSpaceAfter=" ",e.rawSpaceBefore=" "):(e.rawSpaceAfter="",e.rawSpaceBefore="")})),r.push(s)}const n=e.root({value:"",...sourceFrom(o)});return r.forEach((e=>{n.append(e)})),n};
diff --git a/node_modules/@csstools/selector-resolve-nested/dist/index.d.ts b/node_modules/@csstools/selector-resolve-nested/dist/index.d.ts
new file mode 100644
index 00000000..4150620b
--- /dev/null
+++ b/node_modules/@csstools/selector-resolve-nested/dist/index.d.ts
@@ -0,0 +1,47 @@
+/**
+ * Resolve nested selectors following the CSS nesting specification.
+ *
+ * @example
+ *
+ * ```js
+ * import { resolveNestedSelector } from '@csstools/selector-resolve-nested';
+ * import parser from 'postcss-selector-parser';
+ *
+ * const selector = parser().astSync('.foo &');
+ * const parent = parser().astSync('.bar');
+ *
+ * // .foo .bar
+ * console.log(
+ * resolveNestedSelector(selector, parent).toString()
+ * )
+ * ```
+ *
+ * @packageDocumentation
+ */
+
+import type { Root } from 'postcss-selector-parser';
+
+/**
+ * Flatten a nested selector against a given parent selector.
+ *
+ * ⚠️ This is not a method to generate the equivalent un-nested selector.
+ * It is purely a method to construct a single selector AST that contains the parts of both the current and parent selector.
+ * It will not have the correct specificity and it will not match the right elements when used as a selector.
+ * It will not always serialize to a valid selector.
+ *
+ * @param selector - The selector to resolve.
+ * @param parentSelector - The parent selector to resolve against.
+ * @returns The resolved selector.
+ */
+export declare function flattenNestedSelector(selector: Root, parentSelector: Root): Root;
+
+/**
+ * Resolve a nested selector against a given parent selector.
+ *
+ * @param selector - The selector to resolve.
+ * @param parentSelector - The parent selector to resolve against.
+ * @returns The resolved selector.
+ */
+export declare function resolveNestedSelector(selector: Root, parentSelector: Root): Root;
+
+export { }
diff --git a/node_modules/@csstools/selector-resolve-nested/dist/index.mjs b/node_modules/@csstools/selector-resolve-nested/dist/index.mjs
new file mode 100644
index 00000000..ec2a460d
--- /dev/null
+++ b/node_modules/@csstools/selector-resolve-nested/dist/index.mjs
@@ -0,0 +1 @@
+import e from"postcss-selector-parser";function sourceFrom(e){return{sourceIndex:e.sourceIndex??0,source:e.source}}function sortCompoundSelectorsInsideComplexSelector(o){const t=[];let r=[];o.each((o=>{if("combinator"===o.type)return t.push(r,[o]),void(r=[]);if(e.isPseudoElement(o))return t.push(r),void(r=[o]);if("universal"===o.type&&r.find((e=>"universal"===e.type)))o.remove();else{if("tag"===o.type&&r.find((e=>"tag"===e.type))){o.remove();const t=e.selector({value:"",...sourceFrom(o)});t.append(o);const n=e.pseudo({value:":is",...sourceFrom(o)});return n.append(t),void r.push(n)}r.push(o)}})),t.push(r);const n=[];for(let e=0;e<t.length;e++){const o=t[e];o.sort(((e,o)=>selectorTypeOrder(e)-selectorTypeOrder(o))),n.push(...o)}o.removeAll();for(let e=n.length-1;e>=0;e--)n[e].remove(),o.prepend(n[e])}function selectorTypeOrder(t){return e.isPseudoElement(t)?o.pseudoElement:o[t.type]}const o={universal:0,tag:1,pseudoElement:2,nesting:3,id:4,class:5,attribute:6,pseudo:7,comment:8};function resolveNestedSelector(o,t){const r=[];for(let n=0;n<o.nodes.length;n++){const s=o.nodes[n].clone();{let o=!1;s.walkNesting((()=>(o=!0,!1))),o?"combinator"===s.nodes[0]?.type&&s.prepend(e.nesting({...sourceFrom(s)})):(s.prepend(e.combinator({value:" ",...sourceFrom(s)})),s.prepend(e.nesting({...sourceFrom(s)})))}{const e=new Set;s.walkNesting((o=>{const r=o.parent;e.add(r),"pseudo"===r.parent?.type&&":has"===r.parent.value?.toLowerCase()?o.replaceWith(...prepareParentSelectors(t,!0)):o.replaceWith(...prepareParentSelectors(t))}));for(const o of e)sortCompoundSelectorsInsideComplexSelector(o)}s.walk((e=>{"combinator"===e.type&&""!==e.value.trim()?(e.rawSpaceAfter=" ",e.rawSpaceBefore=" "):(e.rawSpaceAfter="",e.rawSpaceBefore="")})),r.push(s)}const n=e.root({value:"",...sourceFrom(o)});return r.forEach((e=>{n.append(e)})),n}function prepareParentSelectors(o,t=!1){if(t||!isCompoundSelector(o.nodes)){const t=e.pseudo({value:":is",...sourceFrom(o)});return o.nodes.forEach((e=>{t.append(e.clone())})),[t]}return o.nodes[0].nodes.map((e=>e.clone()))}function isCompoundSelector(o){return 1===o.length&&!o[0].nodes.some((o=>"combinator"===o.type||e.isPseudoElement(o)))}function combinationsWithSizeN(e,o){if(o<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,o)>1e4)throw new Error("Too many combinations when trying to resolve a nested selector with lists, reduce the complexity of your selectors");const t=[];for(let e=0;e<o;e++)t[e]=0;const r=[];for(;;){const n=[];for(let s=o-1;s>=0;s--){let o=t[s];if(o>=e.length){if(o=0,t[s]=0,0===s)return r;t[s-1]+=1}n[s]=e[o].clone()}r.push(n),t[t.length-1]++}}function flattenNestedSelector(o,t){const r=[];for(let n=0;n<o.nodes.length;n++){const s=o.nodes[n].clone();let c,l=0;{let o=!1;s.walkNesting((()=>{o=!0,l++})),o?"combinator"===s.nodes[0]?.type&&(s.prepend(e.nesting({...sourceFrom(s)})),l++):(s.prepend(e.combinator({value:" ",...sourceFrom(s)})),s.prepend(e.nesting({...sourceFrom(s)})),l++)}let p=[];if(l>1&&t.nodes.length>1)p=combinationsWithSizeN(t.nodes,l),c=p.length;else{c=t.nodes.length;for(let e=0;e<t.nodes.length;e++){p.push([]);for(let o=0;o<l;o++)p[e].push(t.nodes[e].clone())}}for(let e=0;e<c;e++){let o=0;const t=s.clone();t.walkNesting((t=>{const r=p[e][o];o++,t.replaceWith(...r.nodes)})),r.push(t)}}const n=e.root({value:"",...sourceFrom(o)});return r.forEach((e=>{n.append(e)})),n}export{flattenNestedSelector,resolveNestedSelector};
diff --git a/node_modules/@csstools/selector-resolve-nested/package.json b/node_modules/@csstools/selector-resolve-nested/package.json
new file mode 100644
index 00000000..eff305ec
--- /dev/null
+++ b/node_modules/@csstools/selector-resolve-nested/package.json
@@ -0,0 +1,79 @@
+{
+ "name": "@csstools/selector-resolve-nested",
+ "description": "Resolve nested CSS selectors",
+ "version": "1.1.0",
+ "contributors": [
+ {
+ "name": "Antonio Laguna",
+ "email": "antonio@laguna.es",
+ "url": "https://antonio.laguna.es"
+ },
+ {
+ "name": "Romain Menke",
+ "email": "romainmenke@gmail.com"
+ }
+ ],
+ "license": "MIT-0",
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/csstools"
+ },
+ {
+ "type": "opencollective",
+ "url": "https://opencollective.com/csstools"
+ }
+ ],
+ "engines": {
+ "node": "^14 || ^16 || >=18"
+ },
+ "type": "module",
+ "main": "dist/index.cjs",
+ "module": "dist/index.mjs",
+ "exports": {
+ ".": {
+ "import": {
+ "types": "./dist/index.d.ts",
+ "default": "./dist/index.mjs"
+ },
+ "require": {
+ "default": "./dist/index.cjs"
+ }
+ }
+ },
+ "files": [
+ "CHANGELOG.md",
+ "LICENSE.md",
+ "README.md",
+ "dist"
+ ],
+ "peerDependencies": {
+ "postcss-selector-parser": "^6.0.13"
+ },
+ "devDependencies": {
+ "postcss-selector-parser": "^6.0.13"
+ },
+ "scripts": {
+ "build": "rollup -c ../../rollup/default.mjs",
+ "docs": "node ../../.github/bin/generate-docs/api-documenter.mjs",
+ "lint": "node ../../.github/bin/format-package-json.mjs",
+ "prepublishOnly": "npm run build && npm run test",
+ "stryker": "stryker run --logLevel error",
+ "test": "node --test ./test/index.mjs ./test/_import.mjs && node ./test/_require.cjs"
+ },
+ "homepage": "https://github.com/csstools/postcss-plugins/tree/main/packages/selector-resolve-nested#readme",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/csstools/postcss-plugins.git",
+ "directory": "packages/selector-resolve-nested"
+ },
+ "bugs": "https://github.com/csstools/postcss-plugins/issues",
+ "keywords": [
+ "css",
+ "nested",
+ "postcss-selector-parser"
+ ],
+ "volta": {
+ "extends": "../../package.json"
+ }
+}