# `Raxol.Core.Theming.ThemeRegistry`
[🔗](https://github.com/DROOdotFOO/raxol/blob/v2.8.0/lib/raxol/core/theming/theme_registry.ex#L1)

Unified theme registry - single source of truth for all Raxol themes.

Provides theme definitions that can be consumed by both terminal and web
components. Each theme includes the standard 16-color ANSI palette plus
UI colors (background, foreground, cursor, selection).

## Design

Following Chris McCord's recommendation: one source of truth for themes
that both LiveView and terminal components can consume.

## Color Formats

Colors are stored as hex strings internally. Use conversion functions
to get colors in the format needed:

- `to_hex/1` - Returns hex string (for CSS/web)
- `to_rgb/1` - Returns `{r, g, b}` tuple (for terminal)
- `to_rgba_map/1` - Returns `%{r: r, g: g, b: b, a: 1.0}` (for terminal manager)

## Usage

    # Get a theme
    {:ok, theme} = ThemeRegistry.get(:dracula)

    # List available themes
    ThemeRegistry.list()

    # Get color in different formats
    ThemeRegistry.get_color(:dracula, :red)           # "#ff5555"
    ThemeRegistry.get_color(:dracula, :red, :rgb)     # {255, 85, 85}
    ThemeRegistry.get_color(:dracula, :red, :rgba)    # %{r: 255, g: 85, b: 85, a: 1.0}

    # Convert entire theme
    ThemeRegistry.to_terminal_format(:dracula)
    ThemeRegistry.to_liveview_format(:dracula)

# `color_format`

```elixir
@type color_format() :: :hex | :rgb | :rgba
```

# `hex_color`

```elixir
@type hex_color() :: String.t()
```

# `rgb_color`

```elixir
@type rgb_color() :: {non_neg_integer(), non_neg_integer(), non_neg_integer()}
```

# `rgba_color`

```elixir
@type rgba_color() :: %{
  r: non_neg_integer(),
  g: non_neg_integer(),
  b: non_neg_integer(),
  a: float()
}
```

# `theme`

```elixir
@type theme() :: %{
  name: theme_name(),
  display_name: String.t(),
  description: String.t(),
  dark_mode: boolean(),
  ui: %{
    background: hex_color(),
    foreground: hex_color(),
    cursor: hex_color(),
    selection: hex_color()
  },
  colors: %{
    black: hex_color(),
    red: hex_color(),
    green: hex_color(),
    yellow: hex_color(),
    blue: hex_color(),
    magenta: hex_color(),
    cyan: hex_color(),
    white: hex_color(),
    bright_black: hex_color(),
    bright_red: hex_color(),
    bright_green: hex_color(),
    bright_yellow: hex_color(),
    bright_blue: hex_color(),
    bright_magenta: hex_color(),
    bright_cyan: hex_color(),
    bright_white: hex_color()
  }
}
```

# `theme_name`

```elixir
@type theme_name() :: atom()
```

# `convert_color`

```elixir
@spec convert_color(hex_color() | nil, color_format()) ::
  hex_color() | rgb_color() | rgba_color() | nil
```

Converts a hex color to the specified format.

# `default`

```elixir
@spec default() :: :dracula
```

Returns the default theme name.

# `get`

```elixir
@spec get(theme_name()) :: {:ok, theme()} | {:error, :not_found}
```

Gets a theme by name.

Returns `{:ok, theme}` or `{:error, :not_found}`.

# `get!`

```elixir
@spec get!(theme_name()) :: theme() | nil
```

Gets a theme by name, returning nil if not found.

# `get_color`

```elixir
@spec get_color(theme_name(), atom(), color_format()) ::
  hex_color() | rgb_color() | rgba_color() | nil
```

Gets a specific color from a theme.

## Options

- `:hex` (default) - Returns hex string
- `:rgb` - Returns `{r, g, b}` tuple
- `:rgba` - Returns `%{r: r, g: g, b: b, a: 1.0}` map

# `list`

```elixir
@spec list() :: [theme_name()]
```

Lists all available theme names.

# `list_with_names`

```elixir
@spec list_with_names() :: [{theme_name(), String.t()}]
```

Lists all themes with their display names.

# `to_liveview_format`

```elixir
@spec to_liveview_format(theme_name()) ::
  %{
    name: atom(),
    background: hex_color(),
    foreground: hex_color(),
    cursor: hex_color(),
    selection: hex_color(),
    colors: map()
  }
  | nil
```

Converts a theme to LiveView format.

# `to_terminal_format`

```elixir
@spec to_terminal_format(theme_name()) ::
  %{
    name: String.t(),
    description: String.t(),
    author: String.t(),
    version: String.t(),
    colors: map()
  }
  | nil
```

Converts a theme to terminal manager format (RGBA maps).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
