Foundation: tokens, theme, icons, i18n, Button, Spinner, gallery scaffold
This commit is contained in:
95 files changed
+2489
No files matched your search
@@ -0,0 +1,28 @@
|
||||
package theme
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
"github.com/egoist/mygo/ui"
|
||||
)
|
||||
|
||||
// Contrast returns the WCAG contrast ratio of two opaque colors.
|
||||
func Contrast(a, b ui.Color) float64 {
|
||||
la, lb := luminance(a), luminance(b)
|
||||
if la < lb {
|
||||
la, lb = lb, la
|
||||
}
|
||||
return (la + 0.05) / (lb + 0.05)
|
||||
}
|
||||
|
||||
func luminance(c ui.Color) float64 {
|
||||
return 0.2126*channel(c.R) + 0.7152*channel(c.G) + 0.0722*channel(c.B)
|
||||
}
|
||||
|
||||
func channel(v uint8) float64 {
|
||||
s := float64(v) / 255
|
||||
if s <= 0.04045 {
|
||||
return s / 12.92
|
||||
}
|
||||
return math.Pow((s+0.055)/1.055, 2.4)
|
||||
}
|
||||
Reference in new issue
Block a user