color

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MPL-2.0 Imports: 14 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	N1 = "N1" // foreground color
	N2 = "N2"
	N3 = "N3"
	N4 = "N4"
	N5 = "N5"
	N6 = "N6"
	N7 = "N7" // background color

	// NestedFrameFill uses N5 on a light theme and N7 on a dark theme.
	// Each shade is darker than the outer sequence frame's N6.
	NestedFrameFill = "N5N7"

	// Base Colors: used for containers
	B1 = "B1"
	B2 = "B2"
	B3 = "B3"
	B4 = "B4"
	B5 = "B5"
	B6 = "B6"

	// Alternative colors A
	AA2 = "AA2"
	AA4 = "AA4"
	AA5 = "AA5"

	// Alternative colors B
	AB4 = "AB4"
	AB5 = "AB5"

	// Special
	Empty = ""
	None  = "none"
)

Variables

View Source
var ColorHexRegex = regexp.MustCompile(`^#(([0-9a-fA-F]{2}){3}|([0-9a-fA-F]){3})$`)
View Source
var GradientRegex = regexp.MustCompile(`^(linear|radial)-gradient\((.+)\)$`)
View Source
var NamedColors = []string{}/* 150 elements not displayed */
View Source
var URLGradientID = regexp.MustCompile(`^url\('#grad-[a-f0-9]{40}'\)$`)

Functions

func Darken

func Darken(colorString string) (string, error)

func GradientForBox added in v0.10.1

func GradientForBox(paint string, width, height float64) string

GradientForBox expresses a CSS angle in SVG object-bounding-box coordinates. In pixels the color varies along (sin θ, -cos θ). In the unit box those two coefficients are scaled by width and height. The converted spelling also gives differently proportioned paint boxes distinct SVG resources.

func GradientToSVG

func GradientToSVG(gradient Gradient) string

func InterpolateHex added in v0.10.0

func InterpolateHex(from, to color.NRGBA, fraction float64) string

InterpolateHex mixes sRGB channels with premultiplied alpha. Fading from transparent to a color increases its opacity without darkening it along the way.

func InverseContrast added in v0.10.1

func InverseContrast(bg color.RGBA) color.RGBA

InverseContrast returns the RGB inverse of an opaque background, or the higher-contrast of black and white if the inverse falls below 3:1.

func IsGradient

func IsGradient(color string) bool

func IsOpaqueLiteral added in v0.10.1

func IsOpaqueLiteral(raw string) bool

IsOpaqueLiteral reports whether a CSS color literal has full alpha.

func IsThemeColor

func IsThemeColor(colorString string) bool

func IsURLGradientID

func IsURLGradientID(color string) bool

func LinearGradientToSVG

func LinearGradientToSVG(gradient Gradient) string

func LinearGradientVector added in v0.10.0

func LinearGradientVector(direction string) (x1, y1, x2, y2 float64, err error)

LinearGradientVector returns endpoints in object-bounding-box coordinates. For malformed directions it also reports an error; the coordinates retain the historical SVG fallback for unrecognized direction words.

func Luminance

func Luminance(colorString string) (float64, error)

func LuminanceCategory

func LuminanceCategory(colorString string) (string, error)

func PaintVisibleThroughout added in v0.10.0

func PaintVisibleThroughout(raw string) bool

PaintVisibleThroughout reports whether a stroke can be visible along its entire length. A fade through an isolated transparent stop still qualifies. Gradients that hold zero alpha over an interval use plain crossings because a route-wide mask could otherwise erase a line beneath invisible paint.

func ParseRGBA added in v0.10.0

func ParseRGBA(raw string) (color.NRGBA, bool)

ParseRGBA resolves a CSS color literal to sRGB channels.

func RadialGradientToSVG

func RadialGradientToSVG(gradient Gradient) string

func UniqueGradientID

func UniqueGradientID(cssGradient string) string

func ValidColor

func ValidColor(color string) bool

Types

type ColorStop

type ColorStop struct {
	Color    string
	Position string
}

func (ColorStop) AuthoredOffset added in v0.10.1

func (stop ColorStop) AuthoredOffset(index, total int) (float64, error)

AuthoredOffset resolves an omitted position but retains out-of-range or out-of-order values until a renderer samples the gradient.

func (ColorStop) Offset added in v0.10.0

func (stop ColorStop) Offset(index, total int, previous float64) (float64, error)

Offset returns the rendered stop position, clamped to [previous, 1] so authored stops cannot move backwards along the gradient.

type Gradient

type Gradient struct {
	Type       string
	Direction  string
	ColorStops []ColorStop
	ID         string
}

func ParseGradient

func ParseGradient(cssGradient string) (Gradient, error)

func (Gradient) SameGeometry added in v0.10.1

func (from Gradient) SameGeometry(to Gradient) bool

SameGeometry reports whether the gradients have identical geometry in any paint box.

func (Gradient) SameVisibleStops added in v0.10.1

func (g Gradient) SameVisibleStops(other Gradient) bool

SameVisibleStops tests whether straight-line interpolation of the stops can change the paint. A stop hidden behind a previous stop or a box boundary throughout the transition keeps its rendered offset.

type RGB

type RGB struct {
	Red   uint8
	Green uint8
	Blue  uint8
}

func Name2RGB

func Name2RGB(name string) RGB

Jump to

Keyboard shortcuts

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