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:

  • web is the CSS expression per theme as the stylesheet writes it: a reference stays a var(--name), so a theme switch reaches every alias through the token it names.
  • value is the same expression fully resolved, which is what the snapshot and the Elixir module carry, because neither has a cascade to resolve a var() against.
  • color, for a color, is its authored OKLCH parsed and the sRGB bytes it shows after the clip.
  • redeclare says where else the stylesheet declares the token: under .dark when 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. A var() is resolved on the element that declares it, so an alias declared only on :root would keep its light value inside a dark subtree.
  • ansi256 and ansi16, for a terminal token, are its 256 color index per theme (declared in $ansi256 or 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.

t()

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

color_data()

@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.

entry()

@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()]}
}

t()

@type t() :: %Malachi.UI.TokenGen.Model{
  entries: [entry()],
  source: Malachi.UI.TokenGen.Source.t()
}

theme()

@type theme() :: :light | :dark

themed(value)

@type themed(value) :: %{light: value, dark: value}

Functions

build(source)

@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.

fetch!(model, path)

@spec fetch!(t(), String.t()) :: entry()

The entry for a token path.

number(value)

@spec number(number()) :: String.t()

A number as the token file and CSS both write it: an integer bare, a float in its shortest form.