Urara-Blog/node_modules/.pnpm-store/v3/files/14/85ad47c8fe60593a0ff2d69e65c276e6dce9ae489aa2d0723fd86bd5e48af3bb99467dfe48be146b3e740f7f31fd2651455ebd541df48de879a4e0e97edb2a
2022-08-14 01:14:53 +08:00

39 lines
902 B
Text

'use strict';
const { unit } = require('postcss-value-parser');
/**
* @param {string} value
* @return {boolean}
*/
function hasUnit(value) {
const parsedVal = unit(value);
return parsedVal && parsedVal.unit !== '';
}
/**
* @param {import('postcss-value-parser').ParsedValue} columns
* @return {import('postcss-value-parser').ParsedValue | string}
*/
module.exports = (columns) => {
/** @type {string[]} */
const widths = [];
/** @type {string[]} */
const other = [];
columns.walk((node) => {
const { type, value } = node;
if (type === 'word') {
if (hasUnit(value)) {
widths.push(value);
} else {
other.push(value);
}
}
});
// only transform if declaration is not invalid or a single value
if (other.length === 1 && widths.length === 1) {
return `${widths[0].trimStart()} ${other[0].trimStart()}`;
}
return columns;
};