Documentation
¶
Overview ¶
Package csscolorparser provides function for parsing CSS color string as defined in the W3C's CSS color module level 4.
Example ¶
package main
import (
"fmt"
"github.com/mazznoer/csscolorparser"
)
func main() {
c, err := csscolorparser.Parse("rgb(100% 0% 0% / 50%)")
if err != nil {
panic(err)
}
fmt.Printf("R:%.3f, G:%.3f, B:%.3f, A:%.3f\n", c.R, c.G, c.B, c.A)
fmt.Println(c.RGBA255())
fmt.Println(c.HexString())
fmt.Println(c.RGBString())
}
Output: R:1.000, G:0.000, B:0.000, A:0.500 255 0 0 128 #ff000080 rgb(255 0 0 / 50%)
Index ¶
- Variables
- type Color
- func FromHsl(h, s, l, a float64) Color
- func FromHsv(h, s, v, a float64) Color
- func FromHwb(h, w, b, a float64) Color
- func FromLab(l, a, b, alpha float64) Color
- func FromLch(l, c, h, alpha float64) Color
- func FromLinearRGB(r, g, b, a float64) Color
- func FromOklab(l, a, b, alpha float64) Color
- func FromOklch(l, c, h, alpha float64) Color
- func Parse(s string) (Color, error)
- func (c Color) Clamp() Color
- func (c Color) HexString() string
- func (c Color) MarshalText() ([]byte, error)
- func (c Color) Name() (string, bool)
- func (c Color) RGBA() (r, g, b, a uint32)
- func (c Color) RGBA255() (r, g, b, a uint8)
- func (c Color) RGBString() string
- func (c *Color) UnmarshalText(text []byte) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var NamedColors = map[string][3]uint8{}/* 148 elements not displayed */
Functions ¶
This section is empty.
Types ¶
type Color ¶
type Color struct {
R, G, B, A float64
}
R, G, B, A values in the range 0..1
func FromHsl ¶ added in v0.1.4
FromHsl creates a Color from HSL colors.
Arguments:
- h: Hue angle [0..360]
- s: Saturation [0..1]
- l: Lightness [0..1]
- a: Alpha [0..1]
func FromHsv ¶ added in v0.1.4
FromHsv creates a Color from HSV colors.
Arguments:
- h: Hue angle [0..360]
- s: Saturation [0..1]
- v: Value [0..1]
- a: Alpha [0..1]
func FromHwb ¶ added in v0.1.4
FromHwb creates a Color from HWB colors.
Arguments:
- h: Hue angle [0..360]
- w: Whiteness [0..1]
- b: Blackness [0..1]
- a: Alpha [0..1]
func FromLinearRGB ¶ added in v0.1.4
FromLinearRGB creates a Color from linear-light RGB colors.
Arguments:
- r: Red value [0..1]
- g: Green value [0..1]
- b: Blue value [0..1]
- a: Alpha value [0..1]
func FromOklab ¶ added in v0.1.4
FromOklab creates a Color from Oklab colors.
Arguments:
- l: Perceived lightness
- a: How green/red the color is
- b: How blue/yellow the color is
- alpha: Alpha [0..1]
func FromOklch ¶ added in v0.1.4
FromOklch creates a Color from OKLCh colors.
Arguments:
- l: Perceived lightness
- c: Chroma
- h: Hue angle in radians
- alpha: Alpha [0..1]
func (Color) MarshalText ¶ added in v0.1.3
Implement the Go TextMarshaler interface
func (Color) Name ¶ added in v0.1.3
Name returns name of this color if its available.
Example ¶
package main
import (
"fmt"
"github.com/mazznoer/csscolorparser"
)
func main() {
c, err := csscolorparser.Parse("#ffd700")
if err != nil {
panic(err)
}
fmt.Println(c.RGBString())
name, _ := c.Name()
fmt.Println(name)
}
Output: rgb(255 215 0) gold
func (*Color) UnmarshalText ¶ added in v0.1.3
Implement the Go TextUnmarshaler interface
Click to show internal directories.
Click to hide internal directories.