This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

22
node_modules/postcss-discard-unused/LICENSE-MIT generated vendored Normal file
View File

@@ -0,0 +1,22 @@
Copyright (c) Ben Briggs <beneb.info@gmail.com> (http://beneb.info)
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.

127
node_modules/postcss-discard-unused/README.md generated vendored Normal file
View File

@@ -0,0 +1,127 @@
# [postcss][postcss]-discard-unused
> Discard unused counter styles, keyframes and fonts.
## Install
With [npm](https://npmjs.org/package/postcss-discard-unused) do:
```
npm install postcss-discard-unused --save
```
## Example
This module will discard unused at rules in your CSS file, if it cannot find
any selectors that make use of them. It works on `@counter-style`, `@keyframes`
and `@font-face`.
### Input
```css
@counter-style custom {
system: extends decimal;
suffix: "> "
}
@counter-style custom2 {
system: extends decimal;
suffix: "| "
}
a {
list-style: custom
}
```
### Output
```css
@counter-style custom {
system: extends decimal;
suffix: "> "
}
a {
list-style: custom
}
```
Note that this plugin is not responsible for normalising font families, as it
makes the assumption that you will write your font names consistently, such that
it considers these two declarations differently:
```css
h1 {
font-family: "Helvetica Neue"
}
h2 {
font-family: Helvetica Neue
}
```
However, you can mitigate this by including [postcss-minify-font-values][mfv]
*before* this plugin, which will take care of normalising quotes, and
deduplicating. For more examples, see the [tests](src/__tests__/index.js).
## Usage
See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for
examples for your environment.
## API
### discardUnused([options])
#### options
##### fontFace
Type: `boolean`
Default: `true`
Pass `false` to disable discarding unused font face rules.
##### counterStyle
Type: `boolean`
Default: `true`
Pass `false` to disable discarding unused counter style rules.
##### keyframes
Type: `boolean`
Default: `true`
Pass `false` to disable discarding unused keyframe rules.
##### namespace
Type: `boolean`
Default: `true`
Pass `false` to disable discarding unused namespace rules.
## Usage
See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for
examples for your environment.
## Contributors
See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).
## License
MIT © [Ben Briggs](http://beneb.info)
[postcss]: https://github.com/postcss/postcss
[mfv]: https://github.com/trysound/postcss-minify-font-values

44
node_modules/postcss-discard-unused/package.json generated vendored Normal file
View File

@@ -0,0 +1,44 @@
{
"name": "postcss-discard-unused",
"version": "5.1.0",
"description": "Discard unused counter styles, keyframes and fonts.",
"main": "src/index.js",
"types": "types/index.d.ts",
"files": [
"LICENSE-MIT",
"src",
"types"
],
"keywords": [
"css",
"minify",
"optimise",
"postcss",
"postcss-plugin",
"unused"
],
"license": "MIT",
"homepage": "https://github.com/cssnano/cssnano",
"author": {
"name": "Ben Briggs",
"email": "beneb.info@gmail.com",
"url": "http://beneb.info"
},
"repository": "cssnano/cssnano",
"dependencies": {
"postcss-selector-parser": "^6.0.5"
},
"bugs": {
"url": "https://github.com/cssnano/cssnano/issues"
},
"engines": {
"node": "^10 || ^12 || >=14.0"
},
"devDependencies": {
"postcss": "^8.2.15"
},
"peerDependencies": {
"postcss": "^8.2.15"
},
"readme": "# [postcss][postcss]-discard-unused\n\n> Discard unused counter styles, keyframes and fonts.\n\n\n## Install\n\nWith [npm](https://npmjs.org/package/postcss-discard-unused) do:\n\n```\nnpm install postcss-discard-unused --save\n```\n\n\n## Example\n\nThis module will discard unused at rules in your CSS file, if it cannot find\nany selectors that make use of them. It works on `@counter-style`, `@keyframes`\nand `@font-face`.\n\n### Input\n\n```css\n@counter-style custom {\n system: extends decimal;\n suffix: \"> \"\n}\n\n@counter-style custom2 {\n system: extends decimal;\n suffix: \"| \"\n}\n\na {\n list-style: custom\n}\n```\n\n### Output\n\n```css\n@counter-style custom {\n system: extends decimal;\n suffix: \"> \"\n}\n\na {\n list-style: custom\n}\n```\n\nNote that this plugin is not responsible for normalising font families, as it\nmakes the assumption that you will write your font names consistently, such that\nit considers these two declarations differently:\n\n```css\nh1 {\n font-family: \"Helvetica Neue\"\n}\n\nh2 {\n font-family: Helvetica Neue\n}\n```\n\nHowever, you can mitigate this by including [postcss-minify-font-values][mfv]\n*before* this plugin, which will take care of normalising quotes, and\ndeduplicating. For more examples, see the [tests](src/__tests__/index.js).\n\n\n## Usage\n\nSee the [PostCSS documentation](https://github.com/postcss/postcss#usage) for\nexamples for your environment.\n\n\n## API\n\n### discardUnused([options])\n\n#### options\n\n##### fontFace\n\nType: `boolean` \nDefault: `true`\n\nPass `false` to disable discarding unused font face rules.\n\n##### counterStyle\n\nType: `boolean` \nDefault: `true`\n\nPass `false` to disable discarding unused counter style rules.\n\n##### keyframes\n\nType: `boolean` \nDefault: `true`\n\nPass `false` to disable discarding unused keyframe rules.\n\n##### namespace\n\nType: `boolean` \nDefault: `true`\n\nPass `false` to disable discarding unused namespace rules.\n\n\n## Usage\n\nSee the [PostCSS documentation](https://github.com/postcss/postcss#usage) for\nexamples for your environment.\n\n## Contributors\n\nSee [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).\n\n## License\n\nMIT © [Ben Briggs](http://beneb.info)\n\n\n[postcss]: https://github.com/postcss/postcss\n[mfv]: https://github.com/trysound/postcss-minify-font-values\n"
}

213
node_modules/postcss-discard-unused/src/index.js generated vendored Normal file
View File

@@ -0,0 +1,213 @@
'use strict';
const selectorParser = require('postcss-selector-parser');
const atrule = 'atrule';
const decl = 'decl';
const rule = 'rule';
/**
* @param {{value: string}} arg
* @param {(input: string) => string[]} comma
* @param {(input: string) => string[]} space
* @return {string[]}
*/
function splitValues({ value }, comma, space) {
/** @type {string[]} */
let result = [];
for (const val of comma(value)) {
result = result.concat(space(val));
}
return result;
}
/**
* @param {{atRules: import('postcss').AtRule[], values: string[]}} arg
* @return {void}
*/
function filterAtRule({ atRules, values }) {
const uniqueValues = new Set(values);
atRules.forEach((node) => {
const hasAtRule = uniqueValues.has(node.params);
if (!hasAtRule) {
node.remove();
}
});
}
/**
* @param {{atRules: import('postcss').AtRule[], rules: (string | true)[]}} arg
* @return {void}
*/
function filterNamespace({ atRules, rules }) {
const uniqueRules = new Set(rules);
atRules.forEach((atRule) => {
const { 0: param, length: len } = atRule.params.split(' ').filter(Boolean);
if (len === 1) {
return;
}
const hasRule = uniqueRules.has(param) || uniqueRules.has('*');
if (!hasRule) {
atRule.remove();
}
});
}
/**
* @param {string} fontFamily
* @param {string[]} cache
* @param {(input: string) => string[]} comma
* @return {boolean}
*/
function hasFont(fontFamily, cache, comma) {
return comma(fontFamily).some((font) => cache.some((c) => c.includes(font)));
}
/**
* fonts have slightly different logic
* @param {{atRules: import('postcss').AtRule[], values: string[]}} cache
* @param {(input: string) => string[]} comma
* @return {void}
*/
function filterFont({ atRules, values }, comma) {
values = [...new Set(values)];
atRules.forEach((r) => {
/** @type {import('postcss').Declaration[]} */
const families = /** @type {import('postcss').Declaration[]} */ (
r.nodes.filter(
(node) => node.type === 'decl' && node.prop === 'font-family'
)
);
// Discard the @font-face if it has no font-family
if (!families.length) {
return r.remove();
}
families.forEach((family) => {
if (!hasFont(family.value.toLowerCase(), values, comma)) {
r.remove();
}
});
});
}
/**@typedef {{fontFace?: boolean, counterStyle?: boolean, keyframes?: boolean, namespace?: boolean}} Options */
/**
* @type {import('postcss').PluginCreator<Options>}
* @param {Options} opts
* @return {import('postcss').Plugin}
*/
function pluginCreator(opts) {
const { fontFace, counterStyle, keyframes, namespace } = Object.assign(
{},
{
fontFace: true,
counterStyle: true,
keyframes: true,
namespace: true,
},
opts
);
return {
postcssPlugin: 'postcss-discard-unused',
prepare() {
/** @type {{atRules: import('postcss').AtRule[], values: string[]}} */
const counterStyleCache = { atRules: [], values: [] };
/** @type {{atRules: import('postcss').AtRule[], values: string[]}} */
const keyframesCache = { atRules: [], values: [] };
/** @type {{atRules: import('postcss').AtRule[], rules: (string | true)[]}} */
const namespaceCache = { atRules: [], rules: [] };
/** @type {{atRules: import('postcss').AtRule[], values: string[]}} */
const fontCache = { atRules: [], values: [] };
return {
OnceExit(css, { list }) {
const { comma, space } = list;
css.walk((node) => {
const { type } = node;
if (type === rule && namespace && node.selector.includes('|')) {
if (node.selector.includes('[')) {
// Attribute selector, so we should parse further.
selectorParser((ast) => {
ast.walkAttributes(({ namespace: ns }) => {
namespaceCache.rules = namespaceCache.rules.concat(ns);
});
}).process(node.selector);
} else {
// Use a simple split function for the namespace
namespaceCache.rules = namespaceCache.rules.concat(
node.selector.split('|')[0]
);
}
return;
}
if (type === decl) {
const { prop } = node;
if (counterStyle && /list-style|system/.test(prop)) {
counterStyleCache.values = counterStyleCache.values.concat(
splitValues(node, comma, space)
);
}
if (
fontFace &&
node.parent !== undefined &&
node.parent.type === rule &&
/font(|-family)/.test(prop)
) {
fontCache.values = fontCache.values.concat(
comma(node.value.toLowerCase())
);
}
if (keyframes && /animation/.test(prop)) {
keyframesCache.values = keyframesCache.values.concat(
splitValues(node, comma, space)
);
}
return;
}
if (type === atrule) {
const { name } = node;
if (counterStyle && /counter-style/.test(name)) {
counterStyleCache.atRules.push(node);
}
if (fontFace && name === 'font-face' && node.nodes) {
fontCache.atRules.push(node);
}
if (keyframes && /keyframes/.test(name)) {
keyframesCache.atRules.push(node);
}
if (namespace && name === 'namespace') {
namespaceCache.atRules.push(node);
}
return;
}
});
counterStyle && filterAtRule(counterStyleCache);
fontFace && filterFont(fontCache, comma);
keyframes && filterAtRule(keyframesCache);
namespace && filterNamespace(namespaceCache);
},
};
},
};
}
pluginCreator.postcss = true;
module.exports = pluginCreator;

18
node_modules/postcss-discard-unused/types/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,18 @@
export = pluginCreator;
/**@typedef {{fontFace?: boolean, counterStyle?: boolean, keyframes?: boolean, namespace?: boolean}} Options */
/**
* @type {import('postcss').PluginCreator<Options>}
* @param {Options} opts
* @return {import('postcss').Plugin}
*/
declare function pluginCreator(opts: Options): import('postcss').Plugin;
declare namespace pluginCreator {
export { postcss, Options };
}
type Options = {
fontFace?: boolean;
counterStyle?: boolean;
keyframes?: boolean;
namespace?: boolean;
};
declare var postcss: true;