From c06f7ee0a40255214c477e13d9b956a7e07c2900 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sat, 14 Oct 2023 15:05:55 +0800 Subject: postcss,(plugins): nanocss, postcss-preset-env --- .../@csstools/selector-specificity/CHANGELOG.md | 63 ++++++++++++++++++ .../@csstools/selector-specificity/LICENSE.md | 18 ++++++ .../@csstools/selector-specificity/README.md | 57 ++++++++++++++++ .../@csstools/selector-specificity/dist/index.cjs | 1 + .../@csstools/selector-specificity/dist/index.d.ts | 8 +++ .../@csstools/selector-specificity/dist/index.mjs | 1 + .../dist/to-lower-case-a-z.d.ts | 1 + .../@csstools/selector-specificity/package.json | 75 ++++++++++++++++++++++ 8 files changed, 224 insertions(+) create mode 100644 node_modules/@csstools/selector-specificity/CHANGELOG.md create mode 100644 node_modules/@csstools/selector-specificity/LICENSE.md create mode 100644 node_modules/@csstools/selector-specificity/README.md create mode 100644 node_modules/@csstools/selector-specificity/dist/index.cjs create mode 100644 node_modules/@csstools/selector-specificity/dist/index.d.ts create mode 100644 node_modules/@csstools/selector-specificity/dist/index.mjs create mode 100644 node_modules/@csstools/selector-specificity/dist/to-lower-case-a-z.d.ts create mode 100644 node_modules/@csstools/selector-specificity/package.json (limited to 'node_modules/@csstools/selector-specificity') diff --git a/node_modules/@csstools/selector-specificity/CHANGELOG.md b/node_modules/@csstools/selector-specificity/CHANGELOG.md new file mode 100644 index 00000000..770a6b9f --- /dev/null +++ b/node_modules/@csstools/selector-specificity/CHANGELOG.md @@ -0,0 +1,63 @@ +# Changes to Selector Specificity + +### 3.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/)) + +### 2.2.0 + +_March 21, 2023_ + +- Improve case insensitive string matching. +- Add support for: + - `::view-transition` + - `::view-transition-group(*)` and `::view-transition-group(name)` + - `::view-transition-image-par(*)` and `::view-transition-image-par(name)` + - `::view-transition-old(*)` and `::view-transition-old(name)` + - `::view-transition-new(*)` and `::view-transition-new(name)` + +### 2.1.1 + +_January 28, 2023_ + +- Improve `types` declaration in `package.json` + +### 2.1.0 + +_January 19, 2023_ + +- Add support for `::slotted` +- Add support for `:host` +- Add support for `:host-context` + +### 2.0.2 + +_July 8, 2022_ + +- Fix case insensitive matching. + +### 2.0.1 + +_June 10, 2022_ + +- Fixed: Exception on `:nth-child` without arguments. [#439](https://github.com/csstools/postcss-plugins/issues/439) + +### 2.0.0 + +_June 4, 2022_ + +- Breaking: use only named exports instead of `default` +- Added: `compare(a, b)` function to compare selectors by specificity + +```diff +- `import selectorSpecificity from '@csstools/selector-specificity';` ++ `import { selectorSpecificity } from '@csstools/selector-specificity';` +``` + +### 1.0.0 + +_April 26, 2022_ + +- Initial version diff --git a/node_modules/@csstools/selector-specificity/LICENSE.md b/node_modules/@csstools/selector-specificity/LICENSE.md new file mode 100644 index 00000000..e8ae93b9 --- /dev/null +++ b/node_modules/@csstools/selector-specificity/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-specificity/README.md b/node_modules/@csstools/selector-specificity/README.md new file mode 100644 index 00000000..3868d7d0 --- /dev/null +++ b/node_modules/@csstools/selector-specificity/README.md @@ -0,0 +1,57 @@ +# Selector Specificity + +[npm version][npm-url] +[Build Status][cli-url] +[Discord][discord] + +## Usage + +Add [Selector Specificity] to your project: + +```bash +npm install @csstools/selector-specificity --save-dev +``` + +```js +import parser from 'postcss-selector-parser'; +import { selectorSpecificity } from '@csstools/selector-specificity'; + +const selectorAST = parser().astSync('#foo:has(> .foo)'); +const specificity = selectorSpecificity(selectorAST); + +console.log(specificity.a); // 1 +console.log(specificity.b); // 1 +console.log(specificity.c); // 0 +``` + +_`selectorSpecificity` takes a single selector, not a list of selectors (not : `a, b, c`). +To compare or otherwise manipulate lists of selectors you need to call `selectorSpecificity` on each part._ + +### Comparing + +The package exports a utility function to compare two specificities. + +```js +import { selectorSpecificity, compare } from '@csstools/selector-specificity'; + +const s1 = selectorSpecificity(ast1); +const s2 = selectorSpecificity(ast2); +compare(s1, s2); // -1 | 0 | 1 +``` + +- if `s1 < s2` then `compare(s1, s2)` returns a negative number (`< 0`) +- if `s1 > s2` then `compare(s1, s2)` returns a positive number (`> 0`) +- if `s1 === s2` then `compare(s1, s2)` returns zero (`=== 0`) + +## Prior Art + +- [keeganstreet/specificity](https://github.com/keeganstreet/specificity) +- [bramus/specificity](https://github.com/bramus/specificity) + +For CSSTools we always use `postcss-selector-parser` and want to calculate specificity from this AST. + +[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-specificity + +[Selector Specificity]: https://github.com/csstools/postcss-plugins/tree/main/packages/selector-specificity diff --git a/node_modules/@csstools/selector-specificity/dist/index.cjs b/node_modules/@csstools/selector-specificity/dist/index.cjs new file mode 100644 index 00000000..4633d0fc --- /dev/null +++ b/node_modules/@csstools/selector-specificity/dist/index.cjs @@ -0,0 +1 @@ +"use strict";var e=require("postcss-selector-parser");const s=/[A-Z]/g;function toLowerCaseAZ(e){return e.replace(s,(e=>String.fromCharCode(e.charCodeAt(0)+32)))}function selectorSpecificity(s){if(!s)return{a:0,b:0,c:0};let t=0,c=0,i=0;if("universal"==s.type)return{a:0,b:0,c:0};if("id"===s.type)t+=1;else if("tag"===s.type)i+=1;else if("class"===s.type)c+=1;else if("attribute"===s.type)c+=1;else if(isPseudoElement(s))switch(toLowerCaseAZ(s.value)){case"::slotted":if(i+=1,s.nodes&&s.nodes.length>0){const e=specificityOfMostSpecificListItem(s.nodes);t+=e.a,c+=e.b,i+=e.c}break;case"::view-transition-group":case"::view-transition-image-pair":case"::view-transition-old":case"::view-transition-new":if(s.nodes&&1===s.nodes.length&&"selector"===s.nodes[0].type&&selectorNodeContainsOnlyUniversal(s.nodes[0]))return{a:0,b:0,c:0};i+=1;break;default:i+=1}else if(e.isPseudoClass(s))switch(toLowerCaseAZ(s.value)){case":-moz-any":case":-webkit-any":case":any":case":has":case":is":case":matches":case":not":if(s.nodes&&s.nodes.length>0){const e=specificityOfMostSpecificListItem(s.nodes);t+=e.a,c+=e.b,i+=e.c}break;case":where":break;case":nth-child":case":nth-last-child":if(c+=1,s.nodes&&s.nodes.length>0){const n=s.nodes[0].nodes.findIndex((e=>"tag"===e.type&&"of"===toLowerCaseAZ(e.value)));if(n>-1){const o=[e.selector({nodes:s.nodes[0].nodes.slice(n+1),value:""})];s.nodes.length>1&&o.push(...s.nodes.slice(1));const a=specificityOfMostSpecificListItem(o);t+=a.a,c+=a.b,i+=a.c}}break;case":local":case":global":s.nodes&&s.nodes.length>0&&s.nodes.forEach((e=>{const s=selectorSpecificity(e);t+=s.a,c+=s.b,i+=s.c}));break;case":host":case":host-context":if(c+=1,s.nodes&&s.nodes.length>0){const e=specificityOfMostSpecificListItem(s.nodes);t+=e.a,c+=e.b,i+=e.c}break;default:c+=1}else e.isContainer(s)&&s.nodes.length>0&&s.nodes.forEach((e=>{const s=selectorSpecificity(e);t+=s.a,c+=s.b,i+=s.c}));return{a:t,b:c,c:i}}function specificityOfMostSpecificListItem(e){let s={a:0,b:0,c:0};return e.forEach((e=>{const t=selectorSpecificity(e);t.a>s.a?s=t:t.as.b?s=t:t.bs.c&&(s=t))})),s}function isPseudoElement(s){return e.isPseudoElement(s)}function selectorNodeContainsOnlyUniversal(e){if(!e)return!1;if(!e.nodes)return!1;const s=e.nodes.filter((e=>"comment"!==e.type));return 1===s.length&&"universal"===s[0].type}exports.compare=function compare(e,s){return e.a===s.a?e.b===s.b?e.c-s.c:e.b-s.b:e.a-s.a},exports.selectorSpecificity=selectorSpecificity; diff --git a/node_modules/@csstools/selector-specificity/dist/index.d.ts b/node_modules/@csstools/selector-specificity/dist/index.d.ts new file mode 100644 index 00000000..f92ce6d8 --- /dev/null +++ b/node_modules/@csstools/selector-specificity/dist/index.d.ts @@ -0,0 +1,8 @@ +import type { Node } from 'postcss-selector-parser'; +export type Specificity = { + a: number; + b: number; + c: number; +}; +export declare function compare(s1: Specificity, s2: Specificity): number; +export declare function selectorSpecificity(node: Node): Specificity; diff --git a/node_modules/@csstools/selector-specificity/dist/index.mjs b/node_modules/@csstools/selector-specificity/dist/index.mjs new file mode 100644 index 00000000..8ac79c74 --- /dev/null +++ b/node_modules/@csstools/selector-specificity/dist/index.mjs @@ -0,0 +1 @@ +import e from"postcss-selector-parser";const s=/[A-Z]/g;function toLowerCaseAZ(e){return e.replace(s,(e=>String.fromCharCode(e.charCodeAt(0)+32)))}function compare(e,s){return e.a===s.a?e.b===s.b?e.c-s.c:e.b-s.b:e.a-s.a}function selectorSpecificity(s){if(!s)return{a:0,b:0,c:0};let t=0,c=0,i=0;if("universal"==s.type)return{a:0,b:0,c:0};if("id"===s.type)t+=1;else if("tag"===s.type)i+=1;else if("class"===s.type)c+=1;else if("attribute"===s.type)c+=1;else if(isPseudoElement(s))switch(toLowerCaseAZ(s.value)){case"::slotted":if(i+=1,s.nodes&&s.nodes.length>0){const e=specificityOfMostSpecificListItem(s.nodes);t+=e.a,c+=e.b,i+=e.c}break;case"::view-transition-group":case"::view-transition-image-pair":case"::view-transition-old":case"::view-transition-new":if(s.nodes&&1===s.nodes.length&&"selector"===s.nodes[0].type&&selectorNodeContainsOnlyUniversal(s.nodes[0]))return{a:0,b:0,c:0};i+=1;break;default:i+=1}else if(e.isPseudoClass(s))switch(toLowerCaseAZ(s.value)){case":-moz-any":case":-webkit-any":case":any":case":has":case":is":case":matches":case":not":if(s.nodes&&s.nodes.length>0){const e=specificityOfMostSpecificListItem(s.nodes);t+=e.a,c+=e.b,i+=e.c}break;case":where":break;case":nth-child":case":nth-last-child":if(c+=1,s.nodes&&s.nodes.length>0){const n=s.nodes[0].nodes.findIndex((e=>"tag"===e.type&&"of"===toLowerCaseAZ(e.value)));if(n>-1){const o=[e.selector({nodes:s.nodes[0].nodes.slice(n+1),value:""})];s.nodes.length>1&&o.push(...s.nodes.slice(1));const a=specificityOfMostSpecificListItem(o);t+=a.a,c+=a.b,i+=a.c}}break;case":local":case":global":s.nodes&&s.nodes.length>0&&s.nodes.forEach((e=>{const s=selectorSpecificity(e);t+=s.a,c+=s.b,i+=s.c}));break;case":host":case":host-context":if(c+=1,s.nodes&&s.nodes.length>0){const e=specificityOfMostSpecificListItem(s.nodes);t+=e.a,c+=e.b,i+=e.c}break;default:c+=1}else e.isContainer(s)&&s.nodes.length>0&&s.nodes.forEach((e=>{const s=selectorSpecificity(e);t+=s.a,c+=s.b,i+=s.c}));return{a:t,b:c,c:i}}function specificityOfMostSpecificListItem(e){let s={a:0,b:0,c:0};return e.forEach((e=>{const t=selectorSpecificity(e);t.a>s.a?s=t:t.as.b?s=t:t.bs.c&&(s=t))})),s}function isPseudoElement(s){return e.isPseudoElement(s)}function selectorNodeContainsOnlyUniversal(e){if(!e)return!1;if(!e.nodes)return!1;const s=e.nodes.filter((e=>"comment"!==e.type));return 1===s.length&&"universal"===s[0].type}export{compare,selectorSpecificity}; diff --git a/node_modules/@csstools/selector-specificity/dist/to-lower-case-a-z.d.ts b/node_modules/@csstools/selector-specificity/dist/to-lower-case-a-z.d.ts new file mode 100644 index 00000000..396b252e --- /dev/null +++ b/node_modules/@csstools/selector-specificity/dist/to-lower-case-a-z.d.ts @@ -0,0 +1 @@ +export declare function toLowerCaseAZ(x: string): string; diff --git a/node_modules/@csstools/selector-specificity/package.json b/node_modules/@csstools/selector-specificity/package.json new file mode 100644 index 00000000..36e08389 --- /dev/null +++ b/node_modules/@csstools/selector-specificity/package.json @@ -0,0 +1,75 @@ +{ + "name": "@csstools/selector-specificity", + "description": "Determine selector specificity with postcss-selector-parser", + "version": "3.0.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" + }, + "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" + ], + "peerDependencies": { + "postcss-selector-parser": "^6.0.13" + }, + "devDependencies": { + "postcss-selector-parser": "^6.0.13" + }, + "scripts": { + "build": "rollup -c ../../rollup/default.mjs", + "lint": "node ../../.github/bin/format-package-json.mjs", + "prepublishOnly": "npm run build && npm run test", + "stryker": "stryker run --logLevel error", + "test": "node ./test/index.mjs && node ./test/_import.mjs && node ./test/_require.cjs" + }, + "homepage": "https://github.com/csstools/postcss-plugins/tree/main/packages/selector-specificity#readme", + "repository": { + "type": "git", + "url": "https://github.com/csstools/postcss-plugins.git", + "directory": "packages/selector-specificity" + }, + "bugs": "https://github.com/csstools/postcss-plugins/issues", + "keywords": [ + "css", + "postcss-selector-parser", + "specificity" + ], + "volta": { + "extends": "../../package.json" + } +} -- cgit v1.2.3