summaryrefslogtreecommitdiff
path: root/node_modules/postcss-minify-font-values
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2024-05-14 14:05:49 +0800
committerlittleblack111 <littleblack11111@gmail.com>2024-05-14 14:05:49 +0800
commit06823fbf1c2e763a5bf76c3990ca98fbbcd98691 (patch)
tree4280bece3888d12a022093bf1a9cd1b049393602 /node_modules/postcss-minify-font-values
parent1368909b3cd552dbb0d12d5863c597f5be46177d (diff)
updated node_modules
Diffstat (limited to 'node_modules/postcss-minify-font-values')
-rw-r--r--node_modules/postcss-minify-font-values/README.md4
-rw-r--r--node_modules/postcss-minify-font-values/package.json4
-rw-r--r--node_modules/postcss-minify-font-values/src/index.js19
-rw-r--r--node_modules/postcss-minify-font-values/src/lib/minify-font.js48
-rw-r--r--node_modules/postcss-minify-font-values/types/index.d.ts9
-rw-r--r--node_modules/postcss-minify-font-values/types/lib/keywords.d.ts1
-rw-r--r--node_modules/postcss-minify-font-values/types/lib/minify-family.d.ts1
-rw-r--r--node_modules/postcss-minify-font-values/types/lib/minify-font.d.ts3
-rw-r--r--node_modules/postcss-minify-font-values/types/lib/minify-weight.d.ts1
9 files changed, 62 insertions, 28 deletions
diff --git a/node_modules/postcss-minify-font-values/README.md b/node_modules/postcss-minify-font-values/README.md
index 23e90b8e..96d7f5d4 100644
--- a/node_modules/postcss-minify-font-values/README.md
+++ b/node_modules/postcss-minify-font-values/README.md
@@ -52,13 +52,15 @@ Pass `false` to disable the module from removing duplicated font families.
##### removeQuotes
-Type: `boolean`
+Type: `boolean` | `(prop: string) => '' | 'font' | 'font-family' | 'font-weight'`
Default: `true`
Pass `false` to disable the module from removing quotes from font families.
Note that oftentimes, this is a *safe optimisation* & is done safely. For more
details, see [Mathias Bynens' article][mathias].
+Pass a function to determine whether a css variable is one of `font`, `font-family`, and `font-weight` to determine whether the variable needs to remove quotes.
+
## Usage
```js
diff --git a/node_modules/postcss-minify-font-values/package.json b/node_modules/postcss-minify-font-values/package.json
index 3560e569..572ba898 100644
--- a/node_modules/postcss-minify-font-values/package.json
+++ b/node_modules/postcss-minify-font-values/package.json
@@ -1,6 +1,6 @@
{
"name": "postcss-minify-font-values",
- "version": "6.0.1",
+ "version": "6.1.0",
"description": "Minify font declarations with PostCSS",
"main": "src/index.js",
"types": "types/index.d.ts",
@@ -31,7 +31,7 @@
"node": "^14 || ^16 || >=18.0"
},
"devDependencies": {
- "postcss": "^8.4.32"
+ "postcss": "^8.4.37"
},
"peerDependencies": {
"postcss": "^8.4.31"
diff --git a/node_modules/postcss-minify-font-values/src/index.js b/node_modules/postcss-minify-font-values/src/index.js
index 2de13504..3d1f5e25 100644
--- a/node_modules/postcss-minify-font-values/src/index.js
+++ b/node_modules/postcss-minify-font-values/src/index.js
@@ -22,27 +22,28 @@ function hasVariableFunction(value) {
*/
function transform(prop, value, opts) {
let lowerCasedProp = prop.toLowerCase();
+ let variableType = '';
- if (lowerCasedProp === 'font-weight' && !hasVariableFunction(value)) {
+ if (typeof opts.removeQuotes === 'function') {
+ variableType = opts.removeQuotes(prop);
+ opts.removeQuotes = true;
+ }
+ if ((lowerCasedProp === 'font-weight' || variableType === 'font-weight') && !hasVariableFunction(value)) {
return minifyWeight(value);
- } else if (lowerCasedProp === 'font-family' && !hasVariableFunction(value)) {
+ } else if ((lowerCasedProp === 'font-family' || variableType === 'font-family') && !hasVariableFunction(value)) {
const tree = valueParser(value);
tree.nodes = minifyFamily(tree.nodes, opts);
return tree.toString();
- } else if (lowerCasedProp === 'font') {
- const tree = valueParser(value);
-
- tree.nodes = minifyFont(tree.nodes, opts);
-
- return tree.toString();
+ } else if (lowerCasedProp === 'font' || variableType === 'font') {
+ return minifyFont(value, opts);
}
return value;
}
-/** @typedef {{removeAfterKeyword?: boolean, removeDuplicates?: boolean, removeQuotes?: boolean}} Options */
+/** @typedef {{removeAfterKeyword?: boolean, removeDuplicates?: boolean, removeQuotes?: boolean | ((prop: string) => '' | 'font' | 'font-family' | 'font-weight')}} Options */
/**
* @type {import('postcss').PluginCreator<Options>}
diff --git a/node_modules/postcss-minify-font-values/src/lib/minify-font.js b/node_modules/postcss-minify-font-values/src/lib/minify-font.js
index 82cd0e49..9e1ed2b8 100644
--- a/node_modules/postcss-minify-font-values/src/lib/minify-font.js
+++ b/node_modules/postcss-minify-font-values/src/lib/minify-font.js
@@ -1,21 +1,46 @@
'use strict';
-const { unit } = require('postcss-value-parser');
+const valueParser = require('postcss-value-parser');
const keywords = require('./keywords');
const minifyFamily = require('./minify-family');
const minifyWeight = require('./minify-weight');
/**
+ * Adds missing spaces before strings.
+ *
+ * @param toBeSpliced {Set<number>}
* @param {import('postcss-value-parser').Node[]} nodes
+ * @return {void}
+ */
+function normalizeNodes(nodes, toBeSpliced) {
+ for (const index of toBeSpliced) {
+ nodes.splice(
+ index,
+ 0,
+ /** @type {import('postcss-value-parser').SpaceNode} */ ({
+ type: 'space',
+ value: ' ',
+ })
+ );
+ }
+}
+
+/**
+ * @param {string} unminified
* @param {import('../index').Options} opts
- * @return {import('postcss-value-parser').Node[]}
+ * @return {string}
*/
-module.exports = function (nodes, opts) {
- let i, max, node, family;
+module.exports = function (unminified, opts) {
+ const tree = valueParser(unminified);
+ const nodes = tree.nodes;
+
let familyStart = NaN;
let hasSize = false;
+ const toBeSpliced = new Set();
- for (i = 0, max = nodes.length; i < max; i += 1) {
- node = nodes[i];
+ for (const [i, node] of nodes.entries()) {
+ if (node.type === 'string' && i > 0 && nodes[i - 1].type !== 'space') {
+ toBeSpliced.add(i);
+ }
if (node.type === 'word') {
if (hasSize) {
@@ -23,7 +48,6 @@ module.exports = function (nodes, opts) {
}
const value = node.value.toLowerCase();
-
if (
value === 'normal' ||
value === 'inherit' ||
@@ -31,7 +55,7 @@ module.exports = function (nodes, opts) {
value === 'unset'
) {
familyStart = i;
- } else if (keywords.style.has(value) || unit(value)) {
+ } else if (keywords.style.has(value) || valueParser.unit(value)) {
familyStart = i;
} else if (keywords.variant.has(value)) {
familyStart = i;
@@ -40,7 +64,7 @@ module.exports = function (nodes, opts) {
familyStart = i;
} else if (keywords.stretch.has(value)) {
familyStart = i;
- } else if (keywords.size.has(value) || unit(value)) {
+ } else if (keywords.size.has(value) || valueParser.unit(value)) {
familyStart = i;
hasSize = true;
}
@@ -56,9 +80,11 @@ module.exports = function (nodes, opts) {
}
}
+ normalizeNodes(nodes, toBeSpliced);
familyStart += 2;
- family = minifyFamily(nodes.slice(familyStart), opts);
+ const family = minifyFamily(nodes.slice(familyStart), opts);
- return nodes.slice(0, familyStart).concat(family);
+ tree.nodes = nodes.slice(0, familyStart).concat(family);
+ return tree.toString();
};
diff --git a/node_modules/postcss-minify-font-values/types/index.d.ts b/node_modules/postcss-minify-font-values/types/index.d.ts
index d474f043..a757affd 100644
--- a/node_modules/postcss-minify-font-values/types/index.d.ts
+++ b/node_modules/postcss-minify-font-values/types/index.d.ts
@@ -1,5 +1,5 @@
export = pluginCreator;
-/** @typedef {{removeAfterKeyword?: boolean, removeDuplicates?: boolean, removeQuotes?: boolean}} Options */
+/** @typedef {{removeAfterKeyword?: boolean, removeDuplicates?: boolean, removeQuotes?: boolean | ((prop: string) => '' | 'font' | 'font-family' | 'font-weight')}} Options */
/**
* @type {import('postcss').PluginCreator<Options>}
* @param {Options} opts
@@ -10,8 +10,9 @@ declare namespace pluginCreator {
export { postcss, Options };
}
type Options = {
- removeAfterKeyword?: boolean;
- removeDuplicates?: boolean;
- removeQuotes?: boolean;
+ removeAfterKeyword?: boolean | undefined;
+ removeDuplicates?: boolean | undefined;
+ removeQuotes?: boolean | ((prop: string) => '' | 'font' | 'font-family' | 'font-weight') | undefined;
};
declare var postcss: true;
+//# sourceMappingURL=index.d.ts.map \ No newline at end of file
diff --git a/node_modules/postcss-minify-font-values/types/lib/keywords.d.ts b/node_modules/postcss-minify-font-values/types/lib/keywords.d.ts
index 6bf544ee..a7b67d7d 100644
--- a/node_modules/postcss-minify-font-values/types/lib/keywords.d.ts
+++ b/node_modules/postcss-minify-font-values/types/lib/keywords.d.ts
@@ -3,3 +3,4 @@ export let variant: Set<string>;
export let weight: Set<string>;
export let stretch: Set<string>;
export let size: Set<string>;
+//# sourceMappingURL=keywords.d.ts.map \ No newline at end of file
diff --git a/node_modules/postcss-minify-font-values/types/lib/minify-family.d.ts b/node_modules/postcss-minify-font-values/types/lib/minify-family.d.ts
index 51d8fd32..d130b929 100644
--- a/node_modules/postcss-minify-font-values/types/lib/minify-family.d.ts
+++ b/node_modules/postcss-minify-font-values/types/lib/minify-family.d.ts
@@ -1,2 +1,3 @@
declare function _exports(nodes: import('postcss-value-parser').Node[], opts: import('../index').Options): import('postcss-value-parser').WordNode[];
export = _exports;
+//# sourceMappingURL=minify-family.d.ts.map \ No newline at end of file
diff --git a/node_modules/postcss-minify-font-values/types/lib/minify-font.d.ts b/node_modules/postcss-minify-font-values/types/lib/minify-font.d.ts
index 1de41fd3..a2ec4627 100644
--- a/node_modules/postcss-minify-font-values/types/lib/minify-font.d.ts
+++ b/node_modules/postcss-minify-font-values/types/lib/minify-font.d.ts
@@ -1,2 +1,3 @@
-declare function _exports(nodes: import('postcss-value-parser').Node[], opts: import('../index').Options): import('postcss-value-parser').Node[];
+declare function _exports(unminified: string, opts: import('../index').Options): string;
export = _exports;
+//# sourceMappingURL=minify-font.d.ts.map \ No newline at end of file
diff --git a/node_modules/postcss-minify-font-values/types/lib/minify-weight.d.ts b/node_modules/postcss-minify-font-values/types/lib/minify-weight.d.ts
index 01eb13be..60a85ce8 100644
--- a/node_modules/postcss-minify-font-values/types/lib/minify-weight.d.ts
+++ b/node_modules/postcss-minify-font-values/types/lib/minify-weight.d.ts
@@ -1,2 +1,3 @@
declare function _exports(value: string): string;
export = _exports;
+//# sourceMappingURL=minify-weight.d.ts.map \ No newline at end of file