diff --git a/src/mobx/stores/helpers/STheme.ts b/src/mobx/stores/helpers/STheme.ts index c4ebb173..4bef8878 100644 --- a/src/mobx/stores/helpers/STheme.ts +++ b/src/mobx/stores/helpers/STheme.ts @@ -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"; }