import Color from "@ctrl/tinycolor" ; export const transparent = ( color , alpha = 0.6 ) => "#" + Color ( color ) . setAlpha ( alpha ) . toHex8 ( ) ; const padZero = ( str ) => { const len = 2 ; const zeros = new Array ( len ) . join ( "0" ) ; return ( zeros + str ) . slice ( - len ) ; } ; export const invertColor = ( hex ) => { if ( hex . indexOf ( "#" ) === 0 ) { hex = hex . slice ( 1 ) ; } if ( hex . length === 3 ) { hex = hex [ 0 ] + hex [ 0 ] + hex [ 1 ] + hex [ 1 ] + hex [ 2 ] + hex [ 2 ] ; } if ( hex . length !== 6 ) { throw new Error ( "Invalid HEX color." ) ; } const r = ( 255 - parseInt ( hex . slice ( 0 , 2 ) , 16 ) ) . toString ( 16 ) , g = ( 255 - parseInt ( hex . slice ( 2 , 4 ) , 16 ) ) . toString ( 16 ) , b = ( 255 - parseInt ( hex . slice ( 4 , 6 ) , 16 ) ) . toString ( 16 ) ; return "#" + padZero ( r ) + padZero ( g ) + padZero ( b ) ; } ; export const makeAppColor = ( color = "#ffffff" ) : string => { const black = Color ( color ) . darken ( 4 ) . toString ( ) ; return `linear-gradient(to bottom, ${ color } 70%, ${ black })` ; } ;