mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-10-20 00:06:09 +00:00
38844e0869
Monaco can not deal with color formats other than 6-digit hex, so we convert the colors for it via new [`tinycolor2`](https://github.com/bgrins/TinyColor) dependency (5kB minzipped). Also, with the addition of the module, we can replace the existing `hexToRGBColor` usage, I verified it is compatible with the current tests before removing the function. Fixes: https://github.com/go-gitea/gitea/issues/25770
22 lines
806 B
JavaScript
22 lines
806 B
JavaScript
// Check similar implementation in modules/util/color.go and keep synchronization
|
|
// Return R, G, B values defined in reletive luminance
|
|
function getLuminanceRGB(channel) {
|
|
const sRGB = channel / 255;
|
|
return (sRGB <= 0.03928) ? sRGB / 12.92 : ((sRGB + 0.055) / 1.055) ** 2.4;
|
|
}
|
|
|
|
// Reference from: https://www.w3.org/WAI/GL/wiki/Relative_luminance
|
|
function getLuminance(r, g, b) {
|
|
const R = getLuminanceRGB(r);
|
|
const G = getLuminanceRGB(g);
|
|
const B = getLuminanceRGB(b);
|
|
return 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
|
}
|
|
|
|
// Reference from: https://firsching.ch/github_labels.html
|
|
// In the future WCAG 3 APCA may be a better solution.
|
|
// Check if text should use light color based on RGB of background
|
|
export function useLightTextOnBackground(r, g, b) {
|
|
return getLuminance(r, g, b) < 0.453;
|
|
}
|