diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2024-05-14 14:05:49 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2024-05-14 14:05:49 +0800 |
| commit | 06823fbf1c2e763a5bf76c3990ca98fbbcd98691 (patch) | |
| tree | 4280bece3888d12a022093bf1a9cd1b049393602 /node_modules/postcss-minify-font-values/src | |
| parent | 1368909b3cd552dbb0d12d5863c597f5be46177d (diff) | |
updated node_modules
Diffstat (limited to 'node_modules/postcss-minify-font-values/src')
| -rw-r--r-- | node_modules/postcss-minify-font-values/src/index.js | 19 | ||||
| -rw-r--r-- | node_modules/postcss-minify-font-values/src/lib/minify-font.js | 48 |
2 files changed, 47 insertions, 20 deletions
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(); }; |
