Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const {
resolve: resolveColor,
utils: { cssCalc, resolveGradient, splitValue }
utils: { cssCalc, isColor, resolveGradient, splitValue }
} = require("@asamuzakjp/css-color");
const { next: syntaxes } = require("@csstools/css-syntax-patches-for-csstree");
const csstree = require("css-tree");
Expand Down Expand Up @@ -119,6 +119,17 @@ function isGlobalKeyword(val) {
return GLOBAL_KEYS.has(asciiLowercase(val));
}

/**
* Checks if the value is a color identifier.
*
* @param {string} val - The value to check.
* @returns {boolean} True if the value is a color identifier, false otherwise.
*/
function isColorIdentifier(val) {
const value = asciiLowercase(val);
return SYS_COLORS.has(value) || isColor(value);
}

/**
* Checks if the value starts with or contains a CSS var() function.
*
Expand Down Expand Up @@ -826,6 +837,7 @@ module.exports = {
AST_TYPES,
hasCalcFunc,
hasVarFunc,
isColorIdentifier,
isGlobalKeyword,
isValidPropertyValue,
parseCSS,
Expand Down
11 changes: 9 additions & 2 deletions lib/utils/propertyDescriptors.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,18 @@ function createGenericPropertyDescriptor(property, { caseSensitive, dimensionTyp
this._setProperty(property, val, priority);
break;
}
case AST_TYPES.GLOBAL_KEYWORD:
case AST_TYPES.IDENTIFIER: {
case AST_TYPES.GLOBAL_KEYWORD: {
this._setProperty(property, name, priority);
break;
}
case AST_TYPES.IDENTIFIER: {
if ((colorType || paintType) && parsers.isColorIdentifier(value)) {
this._setProperty(property, parsers.serializeColor(parsedValue), priority);
} else {
this._setProperty(property, name, priority);
}
break;
}
case AST_TYPES.PERCENTAGE: {
let numericType;
if (percentageType) {
Expand Down