code.gitea.io/gitea@v1.21.7/web_src/js/utils/color.js (about) 1 // Check similar implementation in modules/util/color.go and keep synchronization 2 // Return R, G, B values defined in reletive luminance 3 function getLuminanceRGB(channel) { 4 const sRGB = channel / 255; 5 return (sRGB <= 0.03928) ? sRGB / 12.92 : ((sRGB + 0.055) / 1.055) ** 2.4; 6 } 7 8 // Reference from: https://www.w3.org/WAI/GL/wiki/Relative_luminance 9 function getLuminance(r, g, b) { 10 const R = getLuminanceRGB(r); 11 const G = getLuminanceRGB(g); 12 const B = getLuminanceRGB(b); 13 return 0.2126 * R + 0.7152 * G + 0.0722 * B; 14 } 15 16 // Reference from: https://firsching.ch/github_labels.html 17 // In the future WCAG 3 APCA may be a better solution. 18 // Check if text should use light color based on RGB of background 19 export function useLightTextOnBackground(r, g, b) { 20 return getLuminance(r, g, b) < 0.453; 21 }