mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-22 15:10:57 -05:00
fix(theme): use alternative contrast algorithm
This commit is contained in:
parent
50b0e0f5f2
commit
e4b1be591c
1 changed files with 6 additions and 3 deletions
|
@ -220,8 +220,11 @@ function getContrastingColour(hex: string, fallback?: string): string {
|
||||||
const colour = rgba(hex);
|
const colour = rgba(hex);
|
||||||
if (!colour) return fallback ? getContrastingColour(fallback) : "black";
|
if (!colour) return fallback ? getContrastingColour(fallback) : "black";
|
||||||
|
|
||||||
|
// https://awik.io/determine-color-bright-dark-using-javascript/
|
||||||
|
// http://alienryderflex.com/hsp.html
|
||||||
const [r, g, b] = colour;
|
const [r, g, b] = colour;
|
||||||
return (r / 255) * 0.299 + (g / 255) * 0.587 + (b / 255) * 0.114 >= 0.186
|
// const hsp = Math.sqrt(0.299 * r ** 2 + 0.587 * g ** 2 + 0.114 * b ** 2);
|
||||||
? "black"
|
// Using Skia numbers.
|
||||||
: "white";
|
const hsp = Math.sqrt(0.2126 * r ** 2 + 0.7152 * g ** 2 + 0.0722 * b ** 2);
|
||||||
|
return hsp > 175 ? "black" : "white";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue