Skip to main content

egui_pop_tokens/
lib.rs

1//! Design tokens for egui-pop, in the DTCG format, with no egui dependency.
2//!
3//! A token file is a tree of groups and tokens in the format of the W3C
4//! Design Tokens Community Group (DTCG 2025.10). A token is an object with
5//! a `$value` and a `$type` given on the token or inherited from its group;
6//! its name is its dotted path (`surface.panel`). A value can be a
7//! whole-value alias of another token, `"{gray.2}"`. `$description` and
8//! `$extensions` are kept. At the root, `$extends` names the theme a file
9//! builds on: every token not given comes from it.
10//!
11//! Tokens come in three tiers ([`Tier`]): the **reference** palette (colour
12//! scales such as `gray.0`..`gray.12`), the **system** roles widgets read
13//! (`surface.panel`, `text.muted`) and **component** tokens
14//! (`slider-fill.rest.fill`), each tier aliasing the one below. Every theme answers
15//! the same [`contract()`]; a theme missing a token, or giving it the wrong
16//! type, gets the built-in `pop-dark` value for it and a reported problem.
17//! Resolving never panics.
18//!
19//! A theme is composed from a [`ThemeSpec`]: a base theme (mode and
20//! contrast), a [`Density`] overlay (space and size tokens only), an accent
21//! (a colour scale whose steps become the accent roles), reduced motion and
22//! the user's overrides.
23//!
24//! ```
25//! use egui_pop_tokens::{ThemeSpec, Themes, contrast};
26//!
27//! let themes = Themes::default();
28//! let tokens = themes.resolve(&ThemeSpec::new("pop-dark").accent("blue"));
29//! assert!(tokens.problems().is_empty());
30//! let text = tokens.color("text.default").unwrap();
31//! let panel = tokens.color("surface.panel").unwrap();
32//! assert!(contrast::contrast_ratio(text, panel) >= 4.5);
33//! ```
34//!
35//! A theme being edited is a [`ThemeDraft`]: a base theme, the tokens
36//! changed over it and their history, saved as a token file that
37//! `$extends` the base.
38//!
39//! A file may carry a format stamp ([`FormatStamp`]): the format and
40//! contract versions it was written for. Loading a theme over its base
41//! never fails on a token: what is read otherwise than written comes
42//! back as [`Warning`]s.
43//!
44//! A colour scale can be generated from one seed colour
45//! ([`palette::ramp`]): twelve steps for a light or a dark theme, the
46//! text on its solid step chosen with APCA ([`apca`]).
47//!
48//! A kit's tokens, fonts and licence come as a folder or embedded in the
49//! binary ([`kit`](mod@kit), [`kit!`]). A theme using font files travels
50//! as a folder or a `.zip` archive holding them ([`package`]).
51//!
52//! Types read: `color` (DTCG colour objects in `srgb`, `srgb-linear`,
53//! `oklch` or `oklab`, any other space through its `hex` fallback, and
54//! `#rrggbb[aa]` strings), `dimension` (`px` or `rem`), `number`,
55//! `duration` (`ms` or `s`) and `fontFamily`. Other types are kept as raw
56//! JSON ([`Value::Other`]).
57
58pub mod apca;
59pub mod cache;
60mod color;
61pub mod contract;
62pub mod contrast;
63mod draft;
64mod error;
65mod file;
66mod format;
67pub mod kit;
68pub mod package;
69pub mod palette;
70mod theme;
71mod value;
72mod yaml;
73mod yaml_trap;
74
75pub use color::Color;
76pub use contract::{
77    CATEGORY, CONTRACT_VERSION, LOG_LEVELS, RENAME_WINDOW, RENAMED, Renamed, Required, Tier,
78    contract,
79};
80#[allow(
81    deprecated,
82    reason = "the draft items stay re-exported, deprecated, until their removal"
83)]
84pub use draft::{
85    DRAFT_EXTENSION, DRAFT_HISTORY_CAP, DRAFT_VERSION, GeneratedVariant, ThemeDraft, TokenEdit,
86};
87pub use error::Error;
88pub use file::{RawToken, TOKENS_COMPILER, TokenFile};
89pub use format::{FORMAT_EXTENSION, FORMAT_VERSION, FormatStamp, Warning};
90pub use theme::{
91    ALPHA_EXTENSION, BASED_ON, BUILT_IN_ACCENTS, BUILT_IN_THEMES, COUNTERPART_EXTENSION,
92    Counterpart, Density, FALLBACK_THEME, POP_THEMES, ResolvedTokens, SEED_SCALE, ScrollBars,
93    TEXT_SIZES, ThemeSpec, Themes, Token, VARIANT_OF_EXTENSION, text_size_step, theme_label,
94};
95pub use value::{PX_PER_REM, Value};