All files / roosterjs-color-utils/lib/utils getDarkColor.ts

100% Statements 10/10
50% Branches 2/4
100% Functions 1/1
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 261x   1x             1x   96x   48x 48x 48x 48x 48x           48x    
import * as Color from 'color';
 
const DefaultBaseLValue = 21.247; // L-value of #333333
 
/**
 * Get dark mode color for a given color
 * @param color The color to calculate from
 * @param baseLValue The Light value for base dark color in LAB format. @default the Light value for #333333
 */
export default function getDarkColor(
    color: string,
    EbaseLValue: number = DefaultBaseLValue
): string {
    try {
        const computedColor = Color(color || undefined);
        const colorLab = computedColor.lab().array();
        const newLValue = (100 - colorLab[0]) * ((100 - baseLValue) / 100) + baseLValue;
        color = Color.lab(newLValue, colorLab[1], colorLab[2])
            .rgb()
            .alpha(computedColor.alpha())
            .toString();
    } catch {}
 
    return color;
}