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-reduce-idents/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.

139
node_modules/postcss-reduce-idents/README.md generated vendored Normal file
View File

@@ -0,0 +1,139 @@
# [postcss][postcss]-reduce-idents
> Reduce [custom identifiers][idents] with PostCSS.
## Install
With [npm](https://npmjs.org/package/postcss-reduce-idents) do:
```
npm install postcss-reduce-idents --save
```
## Example
### Input
This module will rename custom identifiers in your CSS files; it does so by
converting each name to a index, which is then encoded into a legal identifier.
A legal custom identifier in CSS is case sensitive and must start with a
letter, but can contain digits, hyphens and underscores. There are over 3,000
possible two character identifiers, and 51 possible single character identifiers
that will be generated.
```css
@keyframes whiteToBlack {
0% {
color: #fff
}
to {
color: #000
}
}
.one {
animation-name: whiteToBlack
}
```
### Output
```css
@keyframes a {
0% {
color: #fff
}
to {
color: #000
}
}
.one {
animation-name: a
}
```
Note that this module does not handle identifiers that are not linked together.
The following example will not be transformed in any way:
```css
@keyframes fadeOut {
0% { opacity: 1 }
to { opacity: 0 }
}
.fadeIn {
animation-name: fadeIn;
}
```
It works for `@keyframes`, `@counter-style`, custom `counter` values and grid area definitions. See the
[documentation][idents] for more information, or the [tests](src/__tests__) for more
examples.
## Usage
See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for
examples for your environment.
## API
### reduceIdents([options])
#### options
##### counter
Type: `boolean`
Default: `true`
Pass `false` to disable reducing `content`, `counter-reset` and `counter-increment` declarations.
##### keyframes
Type: `boolean`
Default: `true`
Pass `false` to disable reducing `keyframes` rules and `animation` declarations.
##### counterStyle
Type: `boolean`
Default: `true`
Pass `false` to disable reducing `counter-style` rules and `list-style` and `system` declarations.
##### gridTemplate
Type: `boolean`
Default: `true`
Pass `false` to disable reducing `grid-template`, `grid-area`, `grid-column`, `grid-row` and `grid-template-areas` declarations.
##### encoder
Type: `function`
Default: [`lib/encode.js`](https://github.com/cssnano/postcss-reduce-idents/blob/master/src/lib/encode.js)
Pass a custom function to encode the identifier with (e.g.: as a way of prefixing them automatically).
It receives two parameters:
- A `String` with the node value.
- A `Number` identifying the index of the occurrence.
## Contributors
See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).
## License
MIT © [Ben Briggs](http://beneb.info)
[idents]: https://developer.mozilla.org/en-US/docs/Web/CSS/custom-ident
[postcss]: https://github.com/postcss/postcss

41
node_modules/postcss-reduce-idents/package.json generated vendored Normal file
View File

@@ -0,0 +1,41 @@
{
"name": "postcss-reduce-idents",
"version": "5.2.0",
"description": "Reduce custom identifiers with PostCSS.",
"main": "src/index.js",
"types": "types/index.d.ts",
"files": [
"src",
"LICENSE-MIT",
"types"
],
"keywords": [
"css",
"postcss",
"postcss-plugin"
],
"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-value-parser": "^4.2.0"
},
"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]-reduce-idents\n\n> Reduce [custom identifiers][idents] with PostCSS.\n\n\n## Install\n\nWith [npm](https://npmjs.org/package/postcss-reduce-idents) do:\n\n```\nnpm install postcss-reduce-idents --save\n```\n\n\n## Example\n\n### Input\n\nThis module will rename custom identifiers in your CSS files; it does so by\nconverting each name to a index, which is then encoded into a legal identifier.\nA legal custom identifier in CSS is case sensitive and must start with a\nletter, but can contain digits, hyphens and underscores. There are over 3,000\npossible two character identifiers, and 51 possible single character identifiers\nthat will be generated.\n\n```css\n@keyframes whiteToBlack {\n 0% {\n color: #fff\n }\n to {\n color: #000\n }\n}\n\n.one {\n animation-name: whiteToBlack\n}\n```\n\n### Output\n\n```css\n@keyframes a {\n 0% {\n color: #fff\n }\n to {\n color: #000\n }\n}\n\n.one {\n animation-name: a\n}\n```\n\nNote that this module does not handle identifiers that are not linked together.\nThe following example will not be transformed in any way:\n\n```css\n@keyframes fadeOut {\n 0% { opacity: 1 }\n to { opacity: 0 }\n}\n\n.fadeIn {\n animation-name: fadeIn;\n}\n```\n\nIt works for `@keyframes`, `@counter-style`, custom `counter` values and grid area definitions. See the\n[documentation][idents] for more information, or the [tests](src/__tests__) for more\nexamples.\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### reduceIdents([options])\n\n#### options\n\n##### counter\n\nType: `boolean` \nDefault: `true`\n\nPass `false` to disable reducing `content`, `counter-reset` and `counter-increment` declarations.\n\n##### keyframes\n\nType: `boolean` \nDefault: `true`\n\nPass `false` to disable reducing `keyframes` rules and `animation` declarations.\n\n##### counterStyle\n\nType: `boolean` \nDefault: `true`\n\nPass `false` to disable reducing `counter-style` rules and `list-style` and `system` declarations.\n\n##### gridTemplate\n\nType: `boolean` \nDefault: `true`\n\nPass `false` to disable reducing `grid-template`, `grid-area`, `grid-column`, `grid-row` and `grid-template-areas` declarations.\n\n##### encoder\n\nType: `function` \nDefault: [`lib/encode.js`](https://github.com/cssnano/postcss-reduce-idents/blob/master/src/lib/encode.js)\n\nPass a custom function to encode the identifier with (e.g.: as a way of prefixing them automatically).\n\nIt receives two parameters:\n - A `String` with the node value.\n - A `Number` identifying the index of the occurrence.\n\n## Contributors\n\nSee [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).\n\n\n## License\n\nMIT © [Ben Briggs](http://beneb.info)\n\n[idents]: https://developer.mozilla.org/en-US/docs/Web/CSS/custom-ident\n\n[postcss]: https://github.com/postcss/postcss\n"
}

52
node_modules/postcss-reduce-idents/src/index.js generated vendored Normal file
View File

@@ -0,0 +1,52 @@
'use strict';
const encode = require('./lib/encode');
const counterReducer = require('./lib/counter');
const counterStyleReducer = require('./lib/counter-style');
const keyframesReducer = require('./lib/keyframes');
const gridTemplateReducer = require('./lib/grid-template');
/** @typedef {{
counter?: boolean, counterStyle?: boolean,
keyframes?: boolean, gridTemplate?: boolean,
encoder?: (value: string, index: number) => string}} Options
*/
/** @typedef {{
* collect: (node: import('postcss').AnyNode, encoder: (value: string, num: number) => string) => void,
* transform: () => void
* }} Reducer
*/
/**
* @type {import('postcss').PluginCreator<Options>}
* @param {Options} arg
* @return {import('postcss').Plugin}
*/
function pluginCreator({
counter = true,
counterStyle = true,
keyframes = true,
gridTemplate = true,
encoder = encode,
} = {}) {
/** @type {Reducer[]} */
const reducers = [];
counter && reducers.push(counterReducer());
counterStyle && reducers.push(counterStyleReducer());
keyframes && reducers.push(keyframesReducer());
gridTemplate && reducers.push(gridTemplateReducer());
return {
postcssPlugin: 'postcss-reduce-idents',
OnceExit(css) {
css.walk((node) => {
reducers.forEach((reducer) => reducer.collect(node, encoder));
});
reducers.forEach((reducer) => reducer.transform());
},
};
}
pluginCreator.postcss = true;
module.exports = pluginCreator;

17
node_modules/postcss-reduce-idents/src/lib/cache.js generated vendored Normal file
View File

@@ -0,0 +1,17 @@
'use strict';
/**
* @param {string} value
* @param {(value: string, num: number) => string} encoder
* @param {Record<string, {ident: string, count: number}>} cache
* @return {void}
*/
module.exports = function (value, encoder, cache) {
if (cache[value]) {
return;
}
cache[value] = {
ident: encoder(value, Object.keys(cache).length),
count: 0,
};
};

View File

@@ -0,0 +1,127 @@
'use strict';
const valueParser = require('postcss-value-parser');
const addToCache = require('./cache');
const RESERVED_KEYWORDS = new Set([
'unset',
'initial',
'inherit',
'none',
'inline',
'outside',
'disc',
'circle',
'square',
'decimal',
'cjk-decimal',
'decimal-leading-zero',
'lower-roman',
'upper-roman',
'lower-greek',
'lower-alpha',
'lower-latin',
'upper-alpha',
'upper-latin',
'arabic-indic',
'armenian',
'bengali',
'cambodian',
'cjk-earthly-branch',
'cjk-heavenly-stem',
'cjk-ideographic',
'devanagari',
'ethiopic-numeric',
'georgian',
'gujarati',
'gurmukhi',
'hebrew',
'hiragana',
'hiragana-iroha',
'japanese-formal',
'japanese-informal',
'kannada',
'katakana',
'katakana-iroha',
'khmer',
'korean-hangul-formal',
'korean-hanja-formal',
'korean-hanja-informal',
'lao',
'lower-armenian',
'malayalam',
'mongolian',
'myanmar',
'oriya',
'persian',
'simp-chinese-formal',
'simp-chinese-informal',
'tamil',
'telugu',
'thai',
'tibetan',
'trad-chinese-formal',
'trad-chinese-informal',
'upper-armenian',
'disclosure-open',
'disclosure-close',
]);
/**
* @return {import('../index.js').Reducer}
*/
module.exports = function () {
/** @type {Record<string, {ident: string, count: number}>} */
let cache = {};
/** @type {import('postcss').AtRule[]} */
let atRules = [];
/** @type {import('postcss').Declaration[]} */
let decls = [];
return {
collect(node, encoder) {
const { type } = node;
if (
type === 'atrule' &&
/counter-style/i.test(node.name) &&
!RESERVED_KEYWORDS.has(node.params.toLowerCase())
) {
addToCache(node.params, encoder, cache);
atRules.push(node);
}
if (type === 'decl' && /(list-style|system)/i.test(node.prop)) {
decls.push(node);
}
},
transform() {
// Iterate each property and change their names
decls.forEach((decl) => {
decl.value = valueParser(decl.value)
.walk((node) => {
if (node.type === 'word' && node.value in cache) {
cache[node.value].count++;
node.value = cache[node.value].ident;
}
})
.toString();
});
// Iterate each at rule and change their name if references to them have been found
atRules.forEach((rule) => {
const cached = cache[rule.params];
if (cached && cached.count > 0) {
rule.params = cached.ident;
}
});
// reset cache after transform
atRules = [];
decls = [];
},
};
};

100
node_modules/postcss-reduce-idents/src/lib/counter.js generated vendored Normal file
View File

@@ -0,0 +1,100 @@
'use strict';
const valueParser = require('postcss-value-parser');
const addToCache = require('./cache');
const isNum = require('./isNum');
const RESERVED_KEYWORDS = new Set(['unset', 'initial', 'inherit', 'none']);
/**
* @return {import('../index.js').Reducer}
*/
module.exports = function () {
/** @type {Record<string, {ident: string, count: number}>} */
let cache = {};
/** @type {{value: import('postcss-value-parser').ParsedValue}[]} */
let declOneCache = [];
/** @type {import('postcss').Declaration[]} */
let declTwoCache = [];
return {
collect(node, encoder) {
const { type } = node;
if (type !== 'decl') {
return;
}
const { prop } = node;
if (/counter-(reset|increment)/i.test(prop)) {
/** @type {unknown} */ (node.value) = valueParser(node.value).walk(
(child) => {
if (
child.type === 'word' &&
!isNum(child) &&
!RESERVED_KEYWORDS.has(child.value.toLowerCase())
) {
addToCache(child.value, encoder, cache);
child.value = cache[child.value].ident;
}
}
);
declOneCache.push(/** @type {any} */ (node));
} else if (/content/i.test(prop)) {
declTwoCache.push(node);
}
},
transform() {
declTwoCache.forEach((decl) => {
decl.value = valueParser(decl.value)
.walk((node) => {
const { type } = node;
const value = node.value.toLowerCase();
if (
type === 'function' &&
(value === 'counter' || value === 'counters')
) {
valueParser.walk(node.nodes, (child) => {
if (child.type === 'word' && child.value in cache) {
cache[child.value].count++;
child.value = cache[child.value].ident;
}
});
}
if (type === 'space') {
node.value = ' ';
}
return false;
})
.toString();
});
declOneCache.forEach((decl) => {
/** @type {unknown} */ (decl.value) = decl.value
.walk((node) => {
if (node.type === 'word' && !isNum(node)) {
Object.keys(cache).forEach((key) => {
const cached = cache[key];
if (cached.ident === node.value && !cached.count) {
node.value = key;
}
});
}
})
.toString();
});
// reset cache after transform
declOneCache = [];
declTwoCache = [];
},
};
};

27
node_modules/postcss-reduce-idents/src/lib/encode.js generated vendored Normal file
View File

@@ -0,0 +1,27 @@
'use strict';
/**
* @param {string} val
* @param {number} num
* @return {string}
*/
module.exports = function encode(val, num) {
let base = 52;
let characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
let character = num % base;
let result = characters[character];
let remainder = Math.floor(num / base);
if (remainder) {
base = 64;
characters = characters + '0123456789-_';
while (remainder) {
remainder--;
character = remainder % base;
remainder = Math.floor(remainder / base);
result = result + characters[character];
}
}
return result;
};

View File

@@ -0,0 +1,104 @@
'use strict';
const valueParser = require('postcss-value-parser');
const addToCache = require('./cache');
const isNum = require('./isNum');
const RESERVED_KEYWORDS = new Set([
'auto',
'span',
'inherit',
'initial',
'unset',
]);
const gridTemplateProperties = new Set([
'grid-template',
'grid-template-areas',
]);
const gridChildProperties = new Set([
'grid-area',
'grid-column',
'grid-row',
'grid-column-start',
'grid-column-end',
'grid-row-start',
'grid-row-end',
]);
/**
* @return {import('../index.js').Reducer}
*/
module.exports = function () {
/** @type {Record<string, {ident: string, count: number}>} */
let cache = {};
/** @type {import('postcss').Declaration[]} */
let declCache = [];
return {
collect(node, encoder) {
if (node.type !== 'decl') {
return;
}
if (gridTemplateProperties.has(node.prop.toLowerCase())) {
valueParser(node.value).walk((child) => {
if (child.type === 'string') {
child.value.split(/\s+/).forEach((word) => {
if (/\.+/.test(word)) {
// reduce empty zones to a single `.`
node.value = node.value.replace(word, '.');
} else if (word && !RESERVED_KEYWORDS.has(word.toLowerCase())) {
addToCache(word, encoder, cache);
}
});
}
});
declCache.push(node);
} else if (gridChildProperties.has(node.prop.toLowerCase())) {
valueParser(node.value).walk((child) => {
if (
child.type === 'word' &&
!RESERVED_KEYWORDS.has(child.value.toLowerCase())
) {
addToCache(child.value, encoder, cache);
}
});
declCache.push(node);
}
},
transform() {
declCache.forEach((decl) => {
decl.value = valueParser(decl.value)
.walk((node) => {
if (gridTemplateProperties.has(decl.prop.toLowerCase())) {
node.value.split(/\s+/).forEach((word) => {
if (word in cache) {
node.value = node.value.replace(word, cache[word].ident);
}
});
node.value = node.value.replace(/\s+/g, ' '); // merge white-spaces
}
if (
gridChildProperties.has(decl.prop.toLowerCase()) &&
!isNum(node)
) {
if (node.value in cache) {
node.value = cache[node.value].ident;
}
}
return false;
})
.toString();
});
// reset cache after transform
declCache = [];
},
};
};

10
node_modules/postcss-reduce-idents/src/lib/isNum.js generated vendored Normal file
View File

@@ -0,0 +1,10 @@
'use strict';
const { unit } = require('postcss-value-parser');
/**
* @param {import('postcss-value-parser').Node} node
* @return {import('postcss-value-parser').Dimension | false}
*/
module.exports = function isNum(node) {
return unit(node.value);
};

View File

@@ -0,0 +1,69 @@
'use strict';
const valueParser = require('postcss-value-parser');
const addToCache = require('./cache');
const RESERVED_KEYWORDS = new Set(['none', 'inherit', 'initial', 'unset']);
/**
* @return {import('../index.js').Reducer}
*/
module.exports = function () {
/** @type {Record<string, {ident: string, count: number}>} */
let cache = {};
/** @type {import('postcss').AtRule[]} */
let atRules = [];
/** @type {import('postcss').Declaration[]} */
let decls = [];
return {
collect(node, encoder) {
const { type } = node;
if (
type === 'atrule' &&
/keyframes/i.test(node.name) &&
!RESERVED_KEYWORDS.has(node.params.toLowerCase())
) {
addToCache(node.params, encoder, cache);
atRules.push(node);
}
if (type === 'decl' && /animation/i.test(node.prop)) {
decls.push(node);
}
},
transform() {
const referenced = new Set();
// Iterate each property and change their names
decls.forEach((decl) => {
decl.value = valueParser(decl.value)
.walk((node) => {
if (node.type === 'word' && node.value in cache) {
if (!referenced.has(node.value)) {
referenced.add(node.value);
}
cache[node.value].count++;
node.value = cache[node.value].ident;
}
})
.toString();
});
// Iterate each at rule and change their name if references to them have been found
atRules.forEach((rule) => {
const cached = cache[rule.params];
if (cached && cached.count > 0 && referenced.has(rule.params)) {
rule.params = cached.ident;
}
});
// reset cache after transform
atRules = [];
decls = [];
},
};
};

32
node_modules/postcss-reduce-idents/types/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,32 @@
export = pluginCreator;
/** @typedef {{
counter?: boolean, counterStyle?: boolean,
keyframes?: boolean, gridTemplate?: boolean,
encoder?: (value: string, index: number) => string}} Options
*/
/** @typedef {{
* collect: (node: import('postcss').AnyNode, encoder: (value: string, num: number) => string) => void,
* transform: () => void
* }} Reducer
*/
/**
* @type {import('postcss').PluginCreator<Options>}
* @param {Options} arg
* @return {import('postcss').Plugin}
*/
declare function pluginCreator({ counter, counterStyle, keyframes, gridTemplate, encoder, }?: Options): import('postcss').Plugin;
declare namespace pluginCreator {
export { postcss, Options, Reducer };
}
type Options = {
counter?: boolean | undefined;
counterStyle?: boolean | undefined;
keyframes?: boolean | undefined;
gridTemplate?: boolean | undefined;
encoder?: ((value: string, index: number) => string) | undefined;
};
declare var postcss: true;
type Reducer = {
collect: (node: import('postcss').AnyNode, encoder: (value: string, num: number) => string) => void;
transform: () => void;
};

View File

@@ -0,0 +1,5 @@
declare function _exports(value: string, encoder: (value: string, num: number) => string, cache: Record<string, {
ident: string;
count: number;
}>): void;
export = _exports;

View File

@@ -0,0 +1,2 @@
declare function _exports(): import('../index.js').Reducer;
export = _exports;

View File

@@ -0,0 +1,2 @@
declare function _exports(): import('../index.js').Reducer;
export = _exports;

View File

@@ -0,0 +1,2 @@
declare function _exports(val: string, num: number): string;
export = _exports;

View File

@@ -0,0 +1,2 @@
declare function _exports(): import('../index.js').Reducer;
export = _exports;

View File

@@ -0,0 +1,2 @@
declare function _exports(node: import('postcss-value-parser').Node): import('postcss-value-parser').Dimension | false;
export = _exports;

View File

@@ -0,0 +1,2 @@
declare function _exports(): import('../index.js').Reducer;
export = _exports;