351
*/
352
increaseRelativeLuminace(foreground: Color, ratio: number): Color {
353
>
// This is a naive but fast approach to reducing luminance as converting to
color.ts
354
>
// HSL and back is expensive
355
>
let { r: fgR, g: fgG, b: fgB } = foreground.rgba;
356
>
let cr = this.getContrastRatio(foreground);
357
>
while (cr < ratio && (fgR < 0xFF || fgG < 0xFF || fgB < 0xFF)) {
358
>
fgR = Math.min(0xFF, fgR + Math.ceil((255 - fgR) * 0.1));
359
>
fgG = Math.min(0xFF, fgG + Math.ceil((255 - fgG) * 0.1));
360
>
fgB = Math.min(0xFF, fgB + Math.ceil((255 - fgB) * 0.1));
361
>
cr = this.getContrastRatio(new Color(new RGBA(fgR, fgG, fgB)));
362
>
}
363
>
364
>
return new Color(new RGBA(fgR, fgG, fgB));
365
>
}
366
367
private static _relativeLuminanceForComponent(color: number): number {