import { colord , extend } from 'colord' ; import a11yPlugin from 'colord/plugins/a11y' ; extend ( [ a11yPlugin ] ) ; const getReadableColor = ( desiredFgColor ? , isDark ? ) : string | null => { if ( ! desiredFgColor ) return null ; let fgColor = colord ( desiredFgColor ) ; const bgColor = isDark ? '#080f1e' : '#f6f9fe' ; while ( ! fgColor . isReadable ( bgColor ) ) { fgColor = isDark ? fgColor . lighten ( ) : fgColor . darken ( ) ; } return fgColor . toHex ( ) ; } ; export default getReadableColor ;