Skip to content

Commit 0e7c8a8

Browse files
committed
Add isColorIdentifier() function
1 parent 14cac01 commit 0e7c8a8

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

lib/parsers.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const {
44
resolve: resolveColor,
5-
utils: { cssCalc, resolveGradient, splitValue }
5+
utils: { cssCalc, isColor, resolveGradient, splitValue }
66
} = require("@asamuzakjp/css-color");
77
const { next: syntaxes } = require("@csstools/css-syntax-patches-for-csstree");
88
const csstree = require("css-tree");
@@ -119,6 +119,17 @@ function isGlobalKeyword(val) {
119119
return GLOBAL_KEYS.has(asciiLowercase(val));
120120
}
121121

122+
/**
123+
* Checks if the value is a color identifier.
124+
*
125+
* @param {string} val - The value to check.
126+
* @returns {boolean} True if the value is a color identifier, false otherwise.
127+
*/
128+
function isColorIdentifier(val) {
129+
const value = asciiLowercase(val);
130+
return SYS_COLORS.has(value) || isColor(value);
131+
}
132+
122133
/**
123134
* Checks if the value starts with or contains a CSS var() function.
124135
*
@@ -826,6 +837,7 @@ module.exports = {
826837
AST_TYPES,
827838
hasCalcFunc,
828839
hasVarFunc,
840+
isColorIdentifier,
829841
isGlobalKeyword,
830842
isValidPropertyValue,
831843
parseCSS,

lib/utils/propertyDescriptors.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
"use strict";
22

3-
const {
4-
utils: { isColor }
5-
} = require("@asamuzakjp/css-color");
63
const parsers = require("../parsers");
74

85
// Constants
@@ -88,7 +85,7 @@ function createGenericPropertyDescriptor(property, { caseSensitive, dimensionTyp
8885
break;
8986
}
9087
case AST_TYPES.IDENTIFIER: {
91-
if ((colorType || paintType) && isColor(value)) {
88+
if ((colorType || paintType) && parsers.isColorIdentifier(value)) {
9289
this._setProperty(property, parsers.serializeColor(parsedValue), priority);
9390
} else {
9491
this._setProperty(property, name, priority);

0 commit comments

Comments
 (0)