diff options
Diffstat (limited to 'node_modules/postcss-ordered-values/src/rules/columns.js')
| -rw-r--r-- | node_modules/postcss-ordered-values/src/rules/columns.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/node_modules/postcss-ordered-values/src/rules/columns.js b/node_modules/postcss-ordered-values/src/rules/columns.js new file mode 100644 index 00000000..10a00a9e --- /dev/null +++ b/node_modules/postcss-ordered-values/src/rules/columns.js @@ -0,0 +1,39 @@ +'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; +}; |
