import { ColorValue } from '@emmetio/css-abbreviation' ; export default function color ( token , shortHex ? ) { if ( ! token . r && ! token . g && ! token . b && ! token . a ) { return 'transparent' ; } else if ( token . a === 1 ) { return asHex ( token , shortHex ) ; } return asRGB ( token ) ; } param short export function asHex ( token , short ? ) { const fn = ( short && isShortHex ( token . r ) && isShortHex ( token . g ) && isShortHex ( token . b ) ) ? toShortHex : toHex ; return '#' + fn ( token . r ) + fn ( token . g ) + fn ( token . b ) ; } /**
 * Output current color as `rgba?(...)` CSS color
 */ function asRGB ( token ) { const values = [ token . r , token . g , token . b ] ; if ( token . a !== 1 ) { values . push ( frac ( token . a , 8 ) ) ; } return `${ values . length === 3 ? 'rgb' : 'rgba' }(${ values . join ( ', ' ) })` ; } export function frac ( num , digits = 4 ) { return num . toFixed ( digits ) . replace ( /\.?0+$/ , '' ) ; } function isShortHex ( hex ) { return ! ( hex % 17 ) ; } function toShortHex ( num ) { return ( num >> 4 ) . toString ( 16 ) ; } function toHex ( num ) { return pad ( num . toString ( 16 ) , 2 ) ; } function pad ( value , len ) { while ( value . length < len ) { value = '0' + value ; } return value ; }