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/// Prefix for the **explicit dark-value** variable family. Every canonical token
15/// also exposes its dark-layer value at `--pl-dark-<path>` regardless of the
16/// active scheme, so a `dark.`-prefixed reference can force the dark value
17/// (spec/TOKENS.md).
18pub const FORCED_DARK_VAR_PREFIX: &str = "--pl-dark-";
19
20/// The generative spacing family: `space.<N>` resolves to
21/// `calc(var(--pl-space-base) * N)`.
22pub const SPACE_FAMILY: &str = "space.";
23
24/// Token paths whose F32 values are CSS lengths (emitted with `px`): the value
25/// renders with a `px` suffix when it matches any of these leading prefixes.
26pub const LENGTH_PREFIXES: &[&str] = &[
27    "space.",
28    "radius.",
29    "border.width.",
30    "size.control.",
31    "control.padding.",
32    "control.height",
33    "control.border.",
34    "control.radius",
35    "control.line-height",
36    "control.focus.ring.",
37    "control.icon.",
38    "control.swatch.inset",
39    "button.padding.",
40    "button.border.",
41    "button.radius",
42    "button.height",
43    "button.line-height",
44    "button.focus.ring.",
45    "input.padding.",
46    "input.focus.ring.",
47    "input.swatch.inset",
48    "input.radius",
49    "icon.",
50    "toggle.gap",
51    "toggle.checkbox.size",
52    "toggle.switch.",
53    "toggle.thumb.",
54    "toggle.focus.ring.",
55    "slider.gap",
56    "slider.height",
57    "slider.track.",
58    "slider.thumb.",
59    "slider.focus.ring.",
60    "progress.height",
61    "progress.radius",
62    "gauge.height",
63    "gauge.radius",
64    "stepper.gap",
65    "stepper.button.size",
66    "stepper.border.width",
67    "stepper.radius",
68    "spinner.size",
69    "spinner.border.width",
70    "menu.min-width",
71    "menu.border.width",
72    "menu.radius",
73    "picker.radius",
74    "color.swatch.inset",
75];
76
77/// Prefix/suffix length rules: a path matching `prefix…suffix` is a length.
78pub const LENGTH_PREFIX_SUFFIX: &[(&str, &str)] = &[
79    ("control.font.", ".size"),
80    ("button.font.", ".size"),
81    ("input.font.", ".size"),
82    ("label.font.", ".size"),
83    ("font.heading.", ".size"),
84];
85
86/// Exact-length token paths.
87pub const LENGTH_EXACT: &[&str] = &["font.body.size", "font.caption.size"];
88
89/// `elevation.<low|high>.<component>`: these suffixes are lengths.
90pub const LENGTH_ELEVATION_SUFFIXES: &[&str] = &[".radius", ".x", ".y", ".blur"];
91
92/// Characters preserved verbatim in a CSS variable name; every other character
93/// maps to `-`. (ASCII alphanumerics plus `-` and `_`.)
94pub const VAR_NAME_PRESERVED: &str = "alphanumeric, '-', '_'";