Malachi. UI. TokenGen. Model
(malachi v0.22.7)
View Source
Everything the emitters and the gates need, computed once from a parsed token file.
Each token becomes one entry/0, in declaration order:
webis the CSS expression per theme as the stylesheet writes it: a reference stays avar(--name), so a theme switch reaches every alias through the token it names.valueis the same expression fully resolved, which is what the snapshot and the Elixir module carry, because neither has a cascade to resolve avar()against.color, for a color, is its authored OKLCH parsed and the sRGB bytes it shows after the clip.redeclaresays where else the stylesheet declares the token: under.darkwhen a theme changes its value (a themed color, or anything built from one), and in each.density-*class whose mode changes something it is built from. Avar()is resolved on the element that declares it, so an alias declared only on:rootwould keep its light value inside a dark subtree.ansi256andansi16, for a terminal token, are its 256 color index per theme (declared in$ansi256or else quantised) and its hand declared sixteen color entry.
Every emitter reads this and nothing else, so no two outputs can format or resolve a value differently.
Summary
Types
A color in one theme: the parsed OKLCH, its alpha, its sRGB bytes and how far the clip moved it.
Functions
Computes every entry from a parsed token file. The file must already have passed Source.parse/1.
The entry for a token path.
A number as the token file and CSS both write it: an integer bare, a float in its shortest form.
Types
@type color_data() :: %{ color: Malachi.UI.TokenGen.Color.t(), alpha: float(), srgb8: Malachi.UI.TokenGen.Color.srgb8(), clip_delta: float() }
A color in one theme: the parsed OKLCH, its alpha, its sRGB bytes and how far the clip moved it.
@type entry() :: %{ path: String.t(), name: String.t(), type: Malachi.UI.TokenGen.Token.type(), platforms: [Malachi.UI.TokenGen.Token.platform()], themed: boolean(), ref: String.t() | nil, web: themed(String.t()), value: themed(String.t()), color: themed(color_data()) | nil, ansi256: themed(16..255) | nil, quantised: themed(16..255) | nil, ansi16: Malachi.UI.TokenGen.Source.ansi16() | nil, inherited: boolean(), modes: [{String.t(), String.t()}], reduced_motion: String.t() | nil, redeclare: %{dark: boolean(), modes: [String.t()]} }
@type t() :: %Malachi.UI.TokenGen.Model{ entries: [entry()], source: Malachi.UI.TokenGen.Source.t() }
@type theme() :: :light | :dark
@type themed(value) :: %{light: value, dark: value}
Functions
@spec build(Malachi.UI.TokenGen.Source.t()) :: t()
Computes every entry from a parsed token file. The file must already have passed Source.parse/1.
The entry for a token path.
A number as the token file and CSS both write it: an integer bare, a float in its shortest form.