Raxol.Style.Colors.Utilities (Raxol v0.4.0)
View SourceShared color utilities for the Raxol color system.
This module provides common color manipulation and analysis functions, including contrast calculations, accessibility checks, and color format conversions.
Summary
Functions
Adjusts a color to meet contrast requirements with another color.
Returns black or white, whichever has better contrast with the background.
Checks if two colors have sufficient contrast according to WCAG guidelines.
Calculates the contrast ratio between two colors according to WCAG 2.0.
Increases the contrast of a color by making it more extreme.
Checks if two colors meet WCAG contrast requirements.
Calculates the relative luminance of a color according to WCAG 2.0.
Functions
Adjusts a color to meet contrast requirements with another color.
Parameters
color
- The color to adjust (Color struct or RGB tuple)background
- The background color (Color struct or RGB tuple)level
- WCAG level (:A, :AA, or :AAA)size
- Text size (:normal or :large)
Returns
An adjusted Color struct that meets contrast requirements
Returns black or white, whichever has better contrast with the background.
Checks if two colors have sufficient contrast according to WCAG guidelines.
Calculates the contrast ratio between two colors according to WCAG 2.0.
Parameters
color1
- First color (Color struct or RGB tuple)color2
- Second color (Color struct or RGB tuple)
Returns
A float representing the contrast ratio (1:1 to 21:1)
Increases the contrast of a color by making it more extreme.
Parameters
color
- The color to increase contrast for (Color struct or RGB tuple)
Returns
A new Color struct with increased contrast
Checks if two colors meet WCAG contrast requirements.
Parameters
color1
- First color (Color struct or RGB tuple)color2
- Second color (Color struct or RGB tuple)level
- WCAG level (:A, :AA, or :AAA)size
- Text size (:normal or :large)
Returns
true
if the contrast meets requirements, false
otherwise
Calculates the relative luminance of a color according to WCAG 2.0.
Parameters
color
- A Color struct or RGB tuple
Returns
A float between 0 and 1 representing the relative luminance