Raxol.UI.ThemeResolver (Raxol v2.0.1)

View Source

Consolidated theme resolution, color processing, and theme-related utilities.

This module provides theme resolution with optional caching for high-performance applications.

Configuration

Set the default caching strategy in application config:

config :raxol, :theme_resolver,
  cache_enabled: true

Or control per-call with options:

ThemeResolver.resolve_styles(attrs, component_type, theme, cache: true)

Migration from ThemeResolverCached

Replace:

Raxol.UI.ThemeResolverCached.resolve_styles(attrs, component_type, theme)
Raxol.UI.ThemeResolverCached.get_default_theme()

With:

Raxol.UI.ThemeResolver.resolve_styles(attrs, component_type, theme, cache: true)
Raxol.UI.ThemeResolver.get_default_theme(cache: true)

Examples

# Non-cached (simple operations)
theme = ThemeResolver.resolve_element_theme(element_theme, default_theme)

# Cached (performance-critical operations)
{fg, bg, attrs} = ThemeResolver.resolve_styles(attrs, :button, theme, cache: true)

Summary

Functions

Clear all theme/style caches.

Creates a fallback theme when no default theme is available.

Gets component styles from theme.

Gets the default theme with fallback creation.

Invalidate cache entries for a specific theme.

Merges themes for inheritance (parent theme as base, child theme overrides).

Resolves background color with proper fallbacks.

Resolves an element's theme, handling string themes and providing fallbacks.

Resolves an element's theme with inheritance support.

Resolves foreground color with proper fallbacks.

Resolves style attributes from explicit attrs and component styles.

Resolves foreground and background colors with proper fallbacks. Returns {fg_color, bg_color, style_attrs}.

Resolves color from theme variant.

Functions

clear_cache()

Clear all theme/style caches.

create_fallback_theme()

Creates a fallback theme when no default theme is available.

get_component_styles(component_type, theme)

Gets component styles from theme.

get_default_theme(opts \\ [])

Gets the default theme with fallback creation.

Options

  • cache: boolean() - Enable caching for this operation (default: false)

invalidate_theme(theme_id)

Invalidate cache entries for a specific theme.

merge_themes_for_inheritance(parent_theme, child_theme)

Merges themes for inheritance (parent theme as base, child theme overrides).

resolve_bg_color(attrs, component_styles, theme)

Resolves background color with proper fallbacks.

resolve_element_theme(element_theme, default_theme, opts \\ [])

Resolves an element's theme, handling string themes and providing fallbacks.

Options

  • cache: boolean() - Enable caching for this operation (default: false)

resolve_element_theme_with_inheritance(element, default_theme, opts \\ [])

Resolves an element's theme with inheritance support.

Options

  • cache: boolean() - Enable caching for this operation (default: false)

resolve_fg_color(attrs, component_styles, theme)

Resolves foreground color with proper fallbacks.

resolve_style_attrs(attrs, component_styles)

Resolves style attributes from explicit attrs and component styles.

resolve_styles(attrs, component_type, theme, opts \\ [])

Resolves foreground and background colors with proper fallbacks. Returns {fg_color, bg_color, style_attrs}.

Options

  • cache: boolean() - Enable caching for this operation (default: false)

resolve_variant_color(attrs, theme, color_type)

Resolves color from theme variant.