mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-07 01:15:28 +00:00
fix(theme): use alternative contrast algorithm
This commit is contained in:
@@ -220,8 +220,11 @@ function getContrastingColour(hex: string, fallback?: string): string {
|
||||
const colour = rgba(hex);
|
||||
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;
|
||||
return (r / 255) * 0.299 + (g / 255) * 0.587 + (b / 255) * 0.114 >= 0.186
|
||||
? "black"
|
||||
: "white";
|
||||
// const hsp = Math.sqrt(0.299 * r ** 2 + 0.587 * g ** 2 + 0.114 * b ** 2);
|
||||
// Using Skia numbers.
|
||||
const hsp = Math.sqrt(0.2126 * r ** 2 + 0.7152 * g ** 2 + 0.0722 * b ** 2);
|
||||
return hsp > 175 ? "black" : "white";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user