11// Copyright 2023 The Gitea Authors. All rights reserved.
22// SPDX-License-Identifier: MIT
3+
34package util
45
56import (
89 "strings"
910)
1011
11- // Get color as RGB values in 0..255 range from the hex color string (with or without #)
12+ // HexToRBGColor parses color as RGB values in 0..255 range from the hex color string (with or without #)
1213func HexToRBGColor (colorString string ) (float64 , float64 , float64 ) {
1314 hexString := colorString
1415 if strings .HasPrefix (colorString , "#" ) {
@@ -35,7 +36,7 @@ func HexToRBGColor(colorString string) (float64, float64, float64) {
3536 return r , g , b
3637}
3738
38- // Returns relative luminance for a SRGB color - https://en.wikipedia.org/wiki/Relative_luminance
39+ // GetRelativeLuminance returns relative luminance for a SRGB color - https://en.wikipedia.org/wiki/Relative_luminance
3940// Keep this in sync with web_src/js/utils/color.js
4041func GetRelativeLuminance (color string ) float64 {
4142 r , g , b := HexToRBGColor (color )
@@ -46,8 +47,8 @@ func UseLightText(backgroundColor string) bool {
4647 return GetRelativeLuminance (backgroundColor ) < 0.453
4748}
4849
49- // Given a background color, returns a black or white foreground color that the highest
50- // contrast ratio. In the future, the APCA contrast function, or CSS `contrast-color` will be better.
50+ // ContrastColor returns a black or white foreground color that the highest contrast ratio.
51+ // In the future, the APCA contrast function, or CSS `contrast-color` will be better.
5152// https://github.com/color-js/color.js/blob/eb7b53f7a13bb716ec8b28c7a56f052cd599acd9/src/contrast/APCA.js#L42
5253func ContrastColor (backgroundColor string ) string {
5354 if UseLightText (backgroundColor ) {
0 commit comments