From ea7954f069bf8bcb87d520f8aab0a80b0768590d Mon Sep 17 00:00:00 2001 From: Hester Gong Date: Wed, 10 May 2023 19:19:03 +0800 Subject: Modify luminance calculation and extract related functions into single files (#24586) Close #24508 Main changes: As discussed in the issue 1. Change luminance calculation function to use [Relative Luminance](https://www.w3.org/WAI/GL/wiki/Relative_luminance) 2. Move the luminance related functions into color.go/color.js 3. Add tests for both the files (Not sure if test cases are too many now) Before (tests included by `UseLightTextOnBackground` are labels started with `##`): https://try.gitea.io/HesterG/testrepo/labels After: Screen Shot 2023-05-08 at 13 37 55 Screen Shot 2023-05-08 at 13 38 06 Screen Shot 2023-05-08 at 13 38 20 --------- Co-authored-by: silverwind Co-authored-by: Giteabot --- web_src/js/features/repo-projects.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'web_src/js/features') diff --git a/web_src/js/features/repo-projects.js b/web_src/js/features/repo-projects.js index 11f5518283..abbe23458e 100644 --- a/web_src/js/features/repo-projects.js +++ b/web_src/js/features/repo-projects.js @@ -1,5 +1,5 @@ import $ from 'jquery'; -import {useLightTextOnBackground} from '../utils.js'; +import {useLightTextOnBackground, hexToRGBColor} from '../utils/color.js'; const {csrfToken} = window.config; @@ -190,7 +190,8 @@ export function initRepoProject() { } function setLabelColor(label, color) { - if (useLightTextOnBackground(color)) { + const [r, g, b] = hexToRGBColor(color); + if (useLightTextOnBackground(r, g, b)) { label.removeClass('dark-label').addClass('light-label'); } else { label.removeClass('light-label').addClass('dark-label'); -- cgit v1.2.3