mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-29 02:10:59 -05:00
Update Appearance.tsx
This commit is contained in:
parent
98d1f06ce6
commit
b60d590385
1 changed files with 7 additions and 9 deletions
|
@ -453,14 +453,12 @@ export const Appearance = connectState(Component, (state) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
function getContrastingColour(hex: string, fallback: string): string {
|
function getContrastingColour(hex: string, fallback: string): string {
|
||||||
try {
|
|
||||||
hex = hex.replace("#", "");
|
hex = hex.replace("#", "");
|
||||||
const r = parseInt(hex.substr(0, 2), 16);
|
const r = parseInt(hex.substr(0, 2), 16);
|
||||||
const g = parseInt(hex.substr(2, 2), 16);
|
const g = parseInt(hex.substr(2, 2), 16);
|
||||||
const b = parseInt(hex.substr(4, 2), 16);
|
const b = parseInt(hex.substr(4, 2), 16);
|
||||||
const cc = (r * 299 + g * 587 + b * 114) / 1000;
|
const cc = (r * 299 + g * 587 + b * 114) / 1000;
|
||||||
return cc >= 175 ? "black" : "white";
|
if (isNaN(r) || isNaN(g) || isNaN(b) || isNaN(cc))
|
||||||
} catch (e) {
|
|
||||||
return getContrastingColour(fallback, "#fffff");
|
return getContrastingColour(fallback, "#fffff");
|
||||||
}
|
return cc >= 175 ? "black" : "white";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue