328
*/
329
reduceRelativeLuminace(foreground: Color, ratio: number): Color {
330
>
// This is a naive but fast approach to reducing luminance as converting to
color.ts
331
>
// HSL and back is expensive
332
>
let { r: fgR, g: fgG, b: fgB } = foreground.rgba;
333
>
334
>
let cr = this.getContrastRatio(foreground);
335
>
while (cr < ratio && (fgR > 0 || fgG > 0 || fgB > 0)) {
336
>
// Reduce by 10% until the ratio is hit
337
>
fgR -= Math.max(0, Math.ceil(fgR * 0.1));
338
>
fgG -= Math.max(0, Math.ceil(fgG * 0.1));
339
>
fgB -= Math.max(0, Math.ceil(fgB * 0.1));
340
>
cr = this.getContrastRatio(new Color(new RGBA(fgR, fgG, fgB)));
341
>
}
342
>
343
>
return new Color(new RGBA(fgR, fgG, fgB));
344
>
}
345
346
/**