Raxol.Style.Colors.PaletteManager (Raxol v0.2.0)
View SourceManages color palettes for the Raxol terminal emulator.
This module provides functionality to create, store, and retrieve color palettes. It works with the ColorSystem to provide a comprehensive color management solution that respects user preferences and accessibility settings.
Features
- Create and manage named color palettes
- Generate color scales (light to dark variations)
- Create accessible color combinations
- Calculate contrast ratios
- Support for user preference persistence
- Integration with the accessibility system
Usage
# Initialize the palette manager
PaletteManager.init()
# Register a custom palette
PaletteManager.register_palette(:brand, %{
main: "#0077CC",
accent: "#FF5722",
neutral: "#F0F0F0"
})
# Generate a color scale
scale = PaletteManager.generate_scale("#0077CC", 9)
Summary
Functions
Generate a color scale from a base color.
Get a color from a registered palette.
Get all registered palettes.
Get user color preferences.
Initialize the palette manager.
Register a color palette.
Save user color preferences.
Suggest an accessible color alternative for a given color.
Functions
Generate a color scale from a base color.
Creates a series of color variations from light to dark based on the given color.
Parameters
base_color- The starting color (hex string like "#0077CC")steps- The number of steps in the scale (default: 9)opts- Additional options
Options
:name- Name to identify this scale:lightness_range- Tuple of {min_lightness, max_lightness} (default: {0.1, 0.9}):saturation_adjust- Adjustment to saturation for each step (default: 0.05)
Examples
iex> PaletteManager.generate_scale("#0077CC", 9)
[
"#E6F0FA", "#CCE0F5", "#B3D1F0", "#99C2EB",
"#80B3E6", "#66A3E0", "#4D94DB", "#3385D6", "#0077CC"
]
Get a color from a registered palette.
Parameters
palette_name- The name of the palettecolor_name- The name of the color within the palette
Examples
iex> PaletteManager.get_color(:ocean, :main)
"#0077CC"
Get all registered palettes.
Options
:category- Filter palettes by category:tags- Filter palettes by tags:accessible- Filter by accessibility
Examples
iex> PaletteManager.get_palettes()
%{ocean: %{colors: %{main: "#0077CC", ...}, ...}, ...}
iex> PaletteManager.get_palettes(category: :brand)
%{brand: %{colors: %{main: "#FF5722", ...}, ...}}
Get user color preferences.
Parameters
user_id- Identifier for the user
Examples
iex> PaletteManager.get_user_preferences("user123")
%{theme: :dark, accent_color: "#FF5722"}
Initialize the palette manager.
This sets up the necessary state for managing color palettes and integrates with the ColorSystem.
Examples
iex> PaletteManager.init()
:ok
Register a color palette.
Parameters
palette_name- Unique identifier for the palettecolors- Map of color names to color valuesopts- Additional options
Options
:description- Description of the palette:category- Category for organizing palettes:tags- List of tags for filtering:accessible- Whether the palette is designed for accessibility
Examples
iex> PaletteManager.register_palette(:ocean, %{
...> main: "#0077CC",
...> accent: "#00AAFF",
...> background: "#F0F7FF"
...> })
:ok
Save user color preferences.
Parameters
user_id- Identifier for the userpreferences- Map of color preferences
Examples
iex> PaletteManager.save_user_preferences("user123", %{
...> theme: :dark,
...> accent_color: "#FF5722"
...> })
:ok
Suggest an accessible color alternative for a given color.
Parameters
color- The original colorbackground- The background color the text will appear onlevel- The WCAG level to achieve (:aaor:aaa) (default::aa)
Examples
iex> PaletteManager.suggest_accessible_color("#777777", "#FFFFFF")
"#595959"