Theme Catalog

/app/lib/theme/color.go (1.3 KB)

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package theme

import (
"image/color"

"github.com/muesli/gamut"
)

func ColorTheme(name string, c color.Color) *Theme {
light, dark := themeColors(c)
return &Theme{Key: name, Light: light, Dark: dark}
}

func themeColors(c color.Color) (*Colors, *Colors) {
light, dark := c, c

const threshold = (65535 * 3) / 2
r, g, b, _ := c.RGBA()

if total := r + g + b; total < threshold {
light = gamut.Lighter(c, 0.4)
} else {
dark = gamut.Darker(c, 0.6)
}

lightTints := gamut.Tints(light, 4)
lightShades := gamut.Shades(light, 4)

darkTints := gamut.Tints(dark, 4)
darkShades := gamut.Shades(dark, 4)

x := Default.Clone("")

l := x.Light
l.NavBackground = hex(light)
l.MenuBackground = hex(lightTints[1])
l.MenuSelectedBackground = hex(light)
l.LinkForeground = hex(lightShades[1])
l.LinkVisitedForeground = hex(lightShades[2])
l.BackgroundMuted = hex(lightTints[3])
// l.ForegroundMuted = hex(lightShades[3])

d := x.Dark
d.NavBackground = hex(dark)
d.MenuBackground = hex(darkShades[1])
d.MenuSelectedBackground = hex(dark)
d.LinkForeground = hex(darkTints[1])
d.LinkVisitedForeground = hex(darkTints[2])
d.BackgroundMuted = hex(darkShades[1])
// d.ForegroundMuted = hex(darkTints[3])

return l, d
}

func hex(c color.Color) string {
return gamut.ToHex(c)
}