csscolorparser

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2021 License: MIT Imports: 4 Imported by: 36

README

CSS Color Parser

PkgGoDev Build Status Build Status go report codecov

Go (Golang) CSS color parser.

It support W3C's CSS color module level 4.

import "github.com/mazznoer/csscolorparser"

Usage

c, err := csscolorparser.Parse("gold")

if err != nil {
	panic(err)
}

Supported Format

It support named colors, hexadecimal (#rgb, #rgba, #rrggbb, #rrggbbaa), rgb(), rgba(), hsl(), hsla(), hwb(), and hsv().

lime
#0f0
#0f0f
#00ff00
#00ff00ff
rgb(0,255,0)
rgb(0% 100% 0%)
rgb(0 255 0 / 100%)
rgba(0,255,0,1)
hsl(120,100%,50%)
hsl(120deg 100% 50%)
hsl(-240 100% 50%)
hsl(-240deg 100% 50%)
hsl(0.3333turn 100% 50%)
hsl(133.333grad 100% 50%)
hsl(2.0944rad 100% 50%)
hsla(120,100%,50%,100%)
hwb(120 0% 0%)
hwb(480deg 0% 0% / 100%)
hsv(120,100%,100%)
hsv(120deg 100% 100% / 100%)

Try It Online

Go Playground

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Color

type Color struct {
	R, G, B, A float64
}

func Parse

func Parse(s string) (Color, error)

Parse parses CSS color string and returns, if successful, a Color.

func (Color) HexString

func (c Color) HexString() string

func (Color) RGBA

func (c Color) RGBA() (r, g, b, a uint32)

func (Color) RGBA255

func (c Color) RGBA255() (r, g, b, a uint8)

func (Color) RGBString

func (c Color) RGBString() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL