import { ColorRgba } from '@typings/valueTypes' ; import roundWithDecimals from './roundWithDecimals' ; import { fromRatio } from '@ctrl/tinycolor' ; export const roundRgba = ( rgba , opacity ? ) : ColorRgba => ( { r : roundWithDecimals ( rgba . r * 255 , 0 ) , g : roundWithDecimals ( rgba . g * 255 , 0 ) , b : roundWithDecimals ( rgba . b * 255 , 0 ) , a : roundWithDecimals ( opacity || rgba . a || 1 ) } ) ; export const convertPaintToRgba = ( paint ) : ColorRgba => { if ( paint . type === 'SOLID' && paint . visible === true ) { return roundRgba ( paint . color , ( paint . opacity || null ) ) ; } return null ; } ; export const convertRgbaObjectToString = ( rgbaObject ) : string => `rgba(${ rgbaObject . r }, ${ rgbaObject . g }, ${ rgbaObject . b }, ${ rgbaObject . a })` ; export const rgbaObjectToHex8 = ( rgbaObject ) : string => fromRatio ( rgbaObject ) . toHex8String ( ) ;