| Server IP : 146.59.209.152 / Your IP : 216.73.216.152 Web Server : Apache System : Linux webm009.cluster131.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64 User : monpetu ( 144298) PHP Version : 7.4.33 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/monpetu/www/ipprint/wp-content/plugins/cartflows/modules/gutenberg/src/controls/ |
Upload File : |
/**
* Get HEX color and return RGBA. Default return RGB color.
*
* @param {string} color - The color string.
* @return {boolean} opacity The inline CSS class.
*/
function hexToRgba( color, opacity ) {
if ( ! color ) {
return '';
}
if ( 'undefined' === typeof opacity || '' === opacity ) {
opacity = 100;
}
color = color.replace( '#', '' );
opacity = typeof opacity !== 'undefined' ? opacity / 100 : 1;
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
color = color.replace( shorthandRegex, function ( m, r, g, b ) {
return r + r + g + g + b + b;
} );
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec( color );
const parsed_color = result
? {
r: parseInt( result[ 1 ], 16 ),
g: parseInt( result[ 2 ], 16 ),
b: parseInt( result[ 3 ], 16 ),
}
: null;
if ( parsed_color ) {
return (
'rgba(' +
parsed_color.r +
',' +
parsed_color.g +
',' +
parsed_color.b +
',' +
opacity +
')'
);
}
return '';
}
export default hexToRgba;