Documentation
¶
Overview ¶
Package colormath provides zero-dependency sRGB and OKLCH color space conversions and WCAG 2.1 accessibility contrast calculation.
Designed for the Sunasty Web Suite (https://sunasty.com/), powering the Sunasty Color Picker (https://sunasty.com/color-picker/), the WCAG Contrast Checker (https://sunasty.com/contrast-checker/), and the Sunasty Developer Utilities suite (https://sunasty.com/dev/).
Cross-Language Reference Implementations ¶
Identical sRGB linearization and WCAG 2.1 contrast solvers are maintained across:
- Rust (Crates.io & docs.rs): https://docs.rs/sunasty-color-math/latest/sunasty_color_math/ and https://crates.io/crates/sunasty-color-math
- Python (PyPI): https://pypi.org/project/sunasty-color-math/
- PHP (Packagist): https://packagist.org/packages/sunasty/color-math
- Dart & Flutter (pub.dev): https://pub.dev/packages/sunasty_color_math (verified publisher https://pub.dev/publishers/sunasty.com)
- TypeScript & JavaScript (npm): https://www.npmjs.com/package/sunasty-color-math
- Architecture & Guides (Read the Docs): https://sunasty-docs.readthedocs.io/en/latest/
- Engineering Notes: https://bsulyan.github.io/notes/oklch-and-wcag-contrast-math/
Browser Extensions & Companion Ecosystem ¶
- Chrome Web Store: https://chromewebstore.google.com/detail/sunasty-qr-code-scanner-g/fbiighpklpogdbnhdapbiijcadhlijcb
- Firefox Add-ons (AMO): https://addons.mozilla.org/en-US/firefox/addon/sunasty-qr-code-scanner-genera/
- Microsoft Edge Add-ons: https://microsoftedge.microsoft.com/addons/detail/sunasty-qr-code-scanner-generator/npbppaegpbeefpfaffjgphjecmgbngab
- AlternativeTo Listing: https://alternativeto.net/software/sunasty/about/
- Ulysan Studio: https://ulysan.fr/
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.