d2/lib/color/color.go

17 lines
378 B
Go
Raw Normal View History

2022-11-10 19:21:14 +00:00
package color
import (
"github.com/lucasb-eyer/go-colorful"
"github.com/mazznoer/csscolorparser"
)
func Darken(colorString string) (string, error) {
c, err := csscolorparser.Parse(colorString)
if err != nil {
return "", err
}
h, s, l := colorful.Color{R: c.R, G: c.G, B: c.B}.Hsl()
// decrease luminance by 10%
return colorful.Hsl(h, s, l-.1).Clamped().Hex(), nil
}