@@ -296,7 +296,7 @@ const colorsCssConditions = [
296296 value => value . startsWith ( 'hsl(' ) || value . startsWith ( 'hsla(' ) ,
297297] ;
298298
299- const parse = ( raw , _format ) => {
299+ const parse = ( raw , _format , disableAlpha = false ) => {
300300 const color = { raw } ;
301301 let value ;
302302 let alpha ;
@@ -363,7 +363,14 @@ const parse = (raw, _format) => {
363363 color . value = value ;
364364 color . alpha = Number . isNaN ( alpha ) || alpha === undefined ? 1 : alpha / 255 ;
365365 color . format = format ;
366- const hex = getCssHexa ( value , alpha ) ;
366+ let alpha255 ;
367+ if ( ! disableAlpha && color . alpha !== 1 ) {
368+ alpha255 = Math . floor ( color . alpha * 255 ) ;
369+ } else if ( color . alpha === 1 && color . value === - 16777216 ) {
370+ // special case to distinguish between black 0x000000FF and transparent 0x000
371+ alpha255 = 255 ;
372+ }
373+ const hex = getCssHexa ( value , alpha255 ) ;
367374 color . hex = hex ;
368375 rgb = rgb || getRgb ( value ) ;
369376 color . rgb = rgb ;
@@ -379,18 +386,21 @@ const parse = (raw, _format) => {
379386 return color ;
380387} ;
381388
382- const getCssColor = ( color , format , noAlpha ) => {
389+ const getCssColor = ( color , format , disableAlpha ) => {
383390 let value ;
384391 if ( format === 'hex' ) {
385- value = `#${ getCssHexa ( color . value , noAlpha || color . alpha === 1 ? undefined : Math . floor ( color . alpha * 255 ) ) } ` ;
392+ value = `#${ getCssHexa (
393+ color . value ,
394+ disableAlpha || color . alpha === 1 ? undefined : Math . floor ( color . alpha * 255 ) ,
395+ ) } `;
386396 }
387397 return value ;
388398} ;
389399
390400let cssColorsTranslated ;
391401let language ;
392402
393- const validateColor = ( _color , translate , translateLanguage ) => {
403+ const validateColor = ( _color , disableAlpha , translate , translateLanguage ) => {
394404 let color = _color ;
395405 let isTranslated = false ;
396406 if ( ! ( _color && _color . format && _color . name ) ) {
@@ -406,7 +416,7 @@ const validateColor = (_color, translate, translateLanguage) => {
406416 color = cssColorsTranslated [ color ] || color ;
407417 isTranslated = color !== _color ;
408418 }
409- color = parse ( color ) ;
419+ color = parse ( color , null , disableAlpha ) ;
410420 if ( color . name && translate ) {
411421 color . translated = translate ( color . name ) ;
412422 if ( isTranslated && color . translated ) {
@@ -420,8 +430,8 @@ const validateColor = (_color, translate, translateLanguage) => {
420430 return color ;
421431} ;
422432
423- const getComponents = ( _color , format , translate = value => value ) => {
424- const color = validateColor ( _color , translate ) ;
433+ const getComponents = ( _color , format , disableAlpha , translate = value => value ) => {
434+ const color = validateColor ( _color , disableAlpha , translate ) ;
425435 const components = { } ;
426436 if ( format === 'rgb' ) {
427437 components . r = { value : color . rgb [ 0 ] , format : 'integer' , min : 0 , max : 255 , name : translate ( 'R' ) } ;
0 commit comments