import chroma , { contrast as chromaContrast } from 'chroma-js' ; import { hexToHsluv , hsluvToHex } from 'hsluv' ; import { Rgb , Rgba , Hsv , Hsl } from './interfaces' ; /**
 * This is a variety of color utilities to minimize additional direct dependencies
 * that a thematic consumer might need to be aware of.
 */ /**
 * Convert a standard CSS-compatible string to [h, s, l] array
 */ export function css2hsluv ( css ) { return hexToHsluv ( chroma ( css ) . hex ( ) ) . map ( ( v ) => Math . round ( v ) ) as [ number , number , number ] ; } export function hsluv2hex ( h , s , l ) { return hsluvToHex ( [ h , s , l ] ) ; } param css export function css2lch ( css ) { return chroma ( css ) . lch ( ) . map ( ( v ) => Math . round ( v ) ) as [ number , number , number ] ; } /**
 * Convert a set of l, c, and h values to a standard CSS-comptible hex string
 */ export function lch2hex ( l , c , h ) { return chroma ( l , c , h , 'lch' ) . hex ( ) ; } param css param value export function darken ( css , value ? ) { return chroma ( css ) . darken ( value ) . hex ( ) ; } param css param value export function lighten ( css , value ? ) { return chroma ( css ) . brighten ( value ) . hex ( ) ; } param foreground param background export function contrast ( foreground , background ) { return chromaContrast ( foreground , background ) ; } param css param alpha export function css2rgb ( css , alpha ? ) { if ( css === 'none' ) { return { r : 0 , g : 0 , b : 0 , } ; } const [ r , g , b ] = chroma ( css ) . rgb ( ) ; return { r , g , b , } ; } param css param alpha export function css2rgba ( css , alpha ? ) { if ( css === 'none' ) { return { r : 0 , g : 0 , b : 0 , a : 0 , } ; } const [ r , g , b , aa ] = chroma ( css ) . rgba ( ) ; const a = alpha !== undefined ? alpha : aa ; return { r , g , b , a , } ; } param css param alpha export function css2hsv ( css , alpha ? ) { if ( css === 'none' ) { return { h : 0 , s : 0 , v : 0 , } ; } const [ h , s , v ] = chroma ( css ) . hsv ( ) ; return { h , s , v , } ; } param css param alpha export function css2hsl ( css , alpha ? ) { if ( css === 'none' ) { return { h : 0 , s : 0 , l : 0 , } ; } const [ h , s , l ] = chroma ( css ) . hsl ( ) ; return { h , s , l , } ; } param css param alpha export function css2css ( css , alpha ? ) { if ( css === 'none' ) { return 'transparent' ; } const c = chroma ( css ) ; const ca = alpha !== undefined ? c . alpha ( alpha ) : c ; return ca . css ( ) ; } param css param alpha export function css2hex ( css , alpha ? ) { if ( css === 'none' ) { return 'none' ; } const c = chroma ( css ) ; const ca = alpha !== undefined ? c . alpha ( alpha ) : c ; return ca . hex ( ) ; } param css param alpha export function css2rgbaVector ( css , alpha ? ) { if ( css === 'none' ) { return [ 0 , 0 , 0 , 0 ] ; } const [ r , g , b , aa ] = chroma ( css ) . rgba ( ) ; const a = alpha !== undefined ? alpha : aa ; return [ r / 255 , g / 255 , b / 255 , a ] ; } param css param alpha export function css2rgbaNumber ( css , alpha ? ) { if ( css === 'none' ) { return 0 ; } const [ r , g , b , aa ] = chroma ( css ) . rgba ( ) ; const a = alpha !== undefined ? alpha : aa ; let color = 0 ; color |= r ; color |= g << 8 ; color |= b << 16 ; color |= ( a * 255 ) << 24 ; return color ; }