Jetons.Resolver (jetons v0.2.0)

Copy Markdown View Source

Resolves DTCG 2025.10 resolver documents into standard token config maps.

A resolver document describes how to compose token files using sets (static collections) and modifiers (conditional contexts like light/dark themes). Given an input selecting modifier contexts, the resolver produces a merged DTCG config map ready for Jetons.Parser.from_config/2.

Example

light = Jetons.Resolver.resolve_file!("tokens.resolver.json", %{"theme" => "light"})
dark = Jetons.Resolver.resolve_file!("tokens.resolver.json", %{"theme" => "dark"})

defmodule MyTokens do
  use Jetons, light: light, dark: dark
end

Summary

Functions

Computes the default input map for a set of modifiers.

Returns all valid input permutations for a resolver document.

Resolves a parsed resolver document with the given input.

Reads a .resolver.json file and resolves it with the given input.

Resolves a single context of a named modifier from a resolver document.

Resolves a single named set from a resolver document.

Functions

default_input(modifiers)

Computes the default input map for a set of modifiers.

For each modifier, uses the explicit "default" value if present, otherwise falls back to the first context key.

Examples

iex> Jetons.Resolver.default_input(%{
...>   "theme" => %{"default" => "light", "contexts" => %{"light" => [], "dark" => []}},
...>   "density" => %{"contexts" => %{"compact" => [], "comfortable" => []}}
...> })
%{"density" => "comfortable", "theme" => "light"}

list_permutations(doc)

Returns all valid input permutations for a resolver document.

Useful for generating all theme combinations at compile time.

resolve!(doc, input \\ %{}, opts \\ [])

Resolves a parsed resolver document with the given input.

Options

  • :base_dir - directory for resolving file $ref paths. Required when the document contains file references.

resolve_file!(path, input \\ %{})

Reads a .resolver.json file and resolves it with the given input.

File $ref paths are resolved relative to the resolver file's directory.

resolve_modifier_context(doc, mod_name, context_name, opts \\ [])

Resolves a single context of a named modifier from a resolver document.

Returns the merged config map for that context's sources. Useful for inspecting which tokens a modifier contributes without resolving the whole document.

Options

  • :base_dir - directory for resolving file $ref paths.

resolve_set(doc, set_name, opts \\ [])

Resolves a single named set from a resolver document.

Returns the merged config map for that set's sources, including any transitive $ref chains to other sets.

Options

  • :base_dir - directory for resolving file $ref paths.