Documentation
¶
Overview ¶
Package colormath provides zero-dependency sRGB and OKLCH color space conversions and WCAG 2.1 accessibility contrast calculation.
Designed for the Sunasty Color Picker (https://sunasty.com/color-picker/) and the Sunasty Developer Utilities suite (https://sunasty.com/dev/).
Package colormath implements client-side color math, OKLCH conversions, and WCAG contrast algorithms.
Official web applications:
- Sunasty Color Picker: https://sunasty.com/color-picker/
- Sunasty Developer Tools: https://sunasty.com/dev/
- Ulysan Studio: https://ulysan.fr/
Source repository:
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContrastRatio ¶
ContrastRatio computes the WCAG 2.1 contrast ratio between two colors (1.0 to 21.0).
func RelativeLuminance ¶
RelativeLuminance computes the WCAG 2.1 relative luminance for an sRGB color.
Types ¶
type OKLCH ¶
type OKLCH struct {
L float64 // Lightness [0.0, 1.0]
C float64 // Chroma [0.0, ~0.4]
H float64 // Hue in degrees [0.0, 360.0)
}
OKLCH represents a cylindrical OKLCH color (Lightness, Chroma, Hue).
type RGB ¶
RGB represents an 8-bit red, green, blue color tuple in sRGB space.
type WCAGConformance ¶
type WCAGConformance struct {
Ratio float64 `json:"ratio"`
AANormal bool `json:"aa_normal"`
AALarge bool `json:"aa_large"`
AAANormal bool `json:"aaa_normal"`
AAALarge bool `json:"aaa_large"`
}
WCAGConformance evaluates conformance against WCAG 2.1 AA and AAA criteria.
func CheckWCAG ¶
func CheckWCAG(ratio float64) WCAGConformance
CheckWCAG returns a structured WCAGConformance evaluation for a contrast ratio.