@@ -58,10 +58,10 @@ const normalizeColorToHex = (color: string): string => {
5858
5959 const div = document . createElement ( 'div' ) ;
6060 div . style . color = color ;
61- const normalized = div . style . color ;
61+ const normalized = div . style . color || '' ;
6262
63- const match = normalized . match (
64- / r g b a ? \( ( \d + ) , \s * ( \d + ) , \s * ( \d + ) (?: , \s * ( [ \d . ] + ) ) ? \) / ,
63+ const match = / ^ r g b a ? \( ( \d + ) , \s + ( \d + ) , \s + ( \d + ) (?: , \s * ( [ \d . ] + ) ) ? \) $ / . exec (
64+ normalized ,
6565 ) ;
6666 if ( match ) {
6767 return rgbaToHex ( {
@@ -100,8 +100,11 @@ function toDisplayHex(
100100 if ( value in SPECIAL_COLORS ) {
101101 return rgbaToHex ( SPECIAL_COLORS [ value as SpecialColorKey ] ) . toLowerCase ( ) ;
102102 }
103- if ( themeColors && value in themeColors ) {
104- return themeColors [ value ] . toLowerCase ( ) ;
103+ if (
104+ themeColors &&
105+ Object . prototype . hasOwnProperty . call ( themeColors , value )
106+ ) {
107+ return themeColors [ value as string ] . toLowerCase ( ) ;
105108 }
106109 return value . toLowerCase ( ) ;
107110 }
@@ -159,8 +162,11 @@ export default function ColorPickerControl({
159162 SPECIAL_COLORS [ color as SpecialColorKey ] ,
160163 ) . toLowerCase ( ) ;
161164 }
162- if ( themeColors && color in themeColors ) {
163- return themeColors [ color ] . toLowerCase ( ) ;
165+ if (
166+ themeColors &&
167+ Object . prototype . hasOwnProperty . call ( themeColors , color as string )
168+ ) {
169+ return themeColors [ color as string ] . toLowerCase ( ) ;
164170 }
165171 return String ( color ) . toLowerCase ( ) ;
166172 } ) ,
0 commit comments