@@ -557,19 +557,30 @@ export const colorParser = (targetObject, styleObj) => {
557557 // Process style object and remove unnecessary properties
558558 const processedStyle = JSON . stringify ( styleObj , ( _ , value ) => {
559559 if ( - 1 < [ 'tone' , 'mode' ] . indexOf ( _ ) ) return value ; // Remove any tone/mode or mode/tone properties as they have already been processed
560- if ( 'string' === typeof value && value . startsWith ( 'theme.' ) ) {
561- // Support theme strings example: theme.radius.md
562- return getValFromObjPath ( targetObject , value ) ; // If no theme value exists, the property will be removed from the object
563- } else if (
560+
561+ // Handle theme strings, e.g., 'theme.radius.md'
562+ if ( typeof value === 'string' && value . startsWith ( 'theme.' ) ) {
563+ // Retrieve the value from the target object using the theme path
564+ return getValFromObjPath ( targetObject , value ) ; // If no theme value exists, the property will be removed
565+ }
566+
567+ function isValidColor ( num ) {
568+ return num >= 0 && num <= 0xffffffff ;
569+ }
570+
571+ // Handle color arrays, e.g., ['#663399', 1] or [255, 0.5]
572+ if (
564573 Array . isArray ( value ) &&
565574 value . length === 2 &&
566- typeof value [ 0 ] === 'string' &&
567- value [ 0 ] . substr ( 0 , 1 ) === '#' &&
575+ ( ( typeof value [ 0 ] === 'string' && value [ 0 ] . startsWith ( '#' ) ) ||
576+ ( typeof value [ 0 ] === 'number' && isValidColor ( value [ 0 ] ) ) ) &&
568577 typeof value [ 1 ] === 'number'
569578 ) {
570- // Process value as a color ['#663399', 1]
579+ // Return processed hex color or the original value if processing fails
571580 return getHexColor ( value [ 0 ] , value [ 1 ] ) || value ;
572581 }
582+
583+ // Return all other values as-is
573584 return value ;
574585 } ) ;
575586
0 commit comments