Pote — canonical color types, default palette, and top-level helpers.
This module defines the core color type definitions used throughout the entire library and provides access to the built-in default color palette.
Summary
Types
A theme resolver: (key :: String.t()) -> {:ok, rgb()} | :not_found.
Functions
Returns a specific color by name (alias for get_color/1).
Checks if a color name exists in the default palette.
Returns all available color names.
Returns the default color palette.
Looks up a color by atom name. Returns RGB tuple or nil.
Parses any color input to an RGB tuple.
Like parse/1 but raises on error.
Registers a theme resolver at runtime. Multiple resolvers can coexist
in a stack — resolve_theme_color/1 walks the stack and returns the
first non-:not_found result. Useful when several apps / themes are
loaded side-by-side (e.g. tests for multiple consumers).
Resolves a theme key ("primary", "ternary", ...) to an RGB tuple.
Returns a combined theme resolver that walks the registered stack.
Returns the current list of registered theme resolvers (newest first).
Types
@type argb() :: {non_neg_integer(), non_neg_integer(), non_neg_integer(), non_neg_integer()}
@type color_output() :: rgb() | nil
@type hex() :: String.t()
@type rgb() :: {non_neg_integer(), non_neg_integer(), non_neg_integer()}
A theme resolver: (key :: String.t()) -> {:ok, rgb()} | :not_found.
@type xterm256() :: 0..255
Functions
Returns a specific color by name (alias for get_color/1).
Checks if a color name exists in the default palette.
@spec color_names() :: [atom()]
Returns all available color names.
@spec default_colors() :: map()
Returns the default color palette.
Looks up a color by atom name. Returns RGB tuple or nil.
@spec parse(color_input()) :: {:ok, rgb()} | {:error, term()}
Parses any color input to an RGB tuple.
Accepts hex strings ("#FF0000", "FF0000"), RGB tuples
({255, 0, 0}), HSL/HSV tuples, atom names (:red, :blue),
and xterm256 integers (0..255).
Delegates to Pote.Orchestrator.parse_color/1.
Returns {:ok, {r, g, b}} on success, {:error, reason} on failure.
@spec parse!(color_input()) :: rgb()
Like parse/1 but raises on error.
@spec put_theme_resolver(theme_resolver() | nil | :pop) :: :ok
Registers a theme resolver at runtime. Multiple resolvers can coexist
in a stack — resolve_theme_color/1 walks the stack and returns the
first non-:not_found result. Useful when several apps / themes are
loaded side-by-side (e.g. tests for multiple consumers).
Pass nil to remove ALL resolvers.
Pass :pop to remove the most recently registered one.
Pass :clear as an alias for nil.
Resolves a theme key ("primary", "ternary", ...) to an RGB tuple.
Strategy (in order):
- The configured theme resolver (via
theme_resolver/0). - Pote's built-in
@default_colors.
Returns {:ok, {r, g, b}} or :not_found.
@spec theme_resolver() :: theme_resolver()
Returns a combined theme resolver that walks the registered stack.
The combined resolver tries each registered resolver in order and
returns the first non-:not_found result. If no resolver is
registered, returns a default that always yields :not_found.
Applications embedding Pote (e.g. Alaja) can register their own
resolver to make "theme:<key>" lookups consult their theme system:
# In Alaja's startup:
Pote.put_theme_resolver(fn key ->
case Alaja.Config.lookup_theme_color(key) do
{:ok, rgb} -> {:ok, rgb}
:error -> :not_found
end
end)Multiple resolvers may be registered; the first one to match wins. This is the recommended pattern when several apps / themes coexist (e.g. in tests for multiple consumers).
@spec theme_resolvers() :: [theme_resolver()]
Returns the current list of registered theme resolvers (newest first).
The combined resolver returned by theme_resolver/0 walks this list
in order until one of them returns {:ok, _}.