Skip to main content

pathland_render_html/
token_spec.rs

1//! Canonical design-token conventions (spec/TOKENS.md), shared with the
2//! TypeScript DOM client: the Rust renderer consumes these tables directly, and
3//! `pathland-ts-codegen` emits the TS equivalents from them — so the
4//! `--pl-*` naming, the `dark.` scheme prefix, the generative `space.<N>`
5//! family, and the length-token rules cannot drift between the renderers.
6
7/// The scheme prefix stripped when naming a CSS variable (`dark.color.primary`
8/// overrides the same `--pl-color-primary` inside a dark media query).
9pub const DARK_PREFIX: &str = "dark.";
10
11/// The CSS custom-property prefix for every token variable.
12pub const VAR_PREFIX: &str = "--pl-";
13
14/// The generative spacing family: `space.<N>` resolves to
15/// `calc(var(--pl-space-base) * N)`.
16pub const SPACE_FAMILY: &str = "space.";
17
18/// Token paths whose F32 values are CSS lengths (emitted with `px`): the value
19/// renders with a `px` suffix when it matches any of these leading prefixes.
20pub const LENGTH_PREFIXES: &[&str] = &[
21    "space.",
22    "radius.",
23    "border.width.",
24    "size.control.",
25    "control.padding.",
26    "control.height.",
27];
28
29/// Prefix/suffix length rules: a path matching `prefix…suffix` is a length.
30pub const LENGTH_PREFIX_SUFFIX: &[(&str, &str)] = &[
31    ("control.font.", ".size"),
32    ("font.heading.", ".size"),
33];
34
35/// Exact-length token paths.
36pub const LENGTH_EXACT: &[&str] = &["font.body.size", "font.caption.size"];
37
38/// `elevation.<low|high>.<component>`: these suffixes are lengths.
39pub const LENGTH_ELEVATION_SUFFIXES: &[&str] = &[".radius", ".x", ".y", ".blur"];
40
41/// Characters preserved verbatim in a CSS variable name; every other character
42/// maps to `-`. (ASCII alphanumerics plus `-` and `_`.)
43pub const VAR_NAME_PRESERVED: &str = "alphanumeric, '-', '_'";