uzor 1.5.46

Core UI engine — geometry, interaction, input state
Documentation
//! The one token contract: semantic colour/geometry roles, colour math, and
//! (from Brief 2 onward) the DTCG loader that resolves a JSON token file
//! into a widget-consumable [`crate::tokens::semantic::SemanticRoles`] +
//! [`crate::tokens::geometry::GeometryRoles`] set. See
//! `docs/uzor/plans/h1-token-contract-design-2026-09-24.md` for the full
//! design (semantic role list, module layout, DTCG file shape, delivery to
//! widgets).
//!
//! H1 Brief 1 landed the colour math and the fixed role types
//! (`color`/`geometry`/`semantic`). Brief 2 added the DTCG loader: `dtcg`
//! (raw parse types, path walking, [`TokenLoadError`]), `loader`
//! (`load_token_set`, alias DFS with cycle detection), and `set`
//! (`TokenSet`/`Tokens`, the `app.*` and `component.*` surfaces). Brief 3
//! added `builtin`: the 4 generic built-in JSON sets and [`Tokens::builtin`].
//! Brief 4 (this) adds `theme` ([`theme::TokenTheme`], the one type that
//! implements every converted widget's colour-theme trait) and
//! `component_macro` (the `component_tokens!` scaffold each widget's own
//! `tokens.rs` uses — `ui::widgets::atomic::button::tokens` is the worked
//! example).

mod component_macro;
pub mod builtin;
pub mod color;
pub mod dtcg;
pub mod geometry;
pub mod loader;
pub mod semantic;
pub mod set;
pub mod theme;

pub(crate) use component_macro::{component_tokens, component_tokens_bytes};
pub use builtin::BuiltinSet;
pub use color::{ColorParseError, ColorValue, Rgba};
pub use dtcg::TokenLoadError;
pub use geometry::GeometryRoles;
pub use loader::load_token_set;
pub use semantic::{Role, SemanticRoles};
pub use set::{AppTokens, ColorSpec, ComponentOverrides, Modifier, TokenSet, TokenValue, Tokens};
pub use theme::TokenTheme;

/// The `component.*` keys a widget accepts, if it has registered any. Until
/// a widget calls this with its own key list, every `component.<widget>.*`
/// path in a token file is rejected as [`TokenLoadError::UnknownPath`]. The
/// set of accepted component paths grows only as widgets are converted;
/// this function's body is the single place that growth happens (one match
/// arm added per converted widget).
pub(crate) fn component_keys(widget: &str) -> Option<&'static [&'static str]> {
    match widget {
        "button" => Some(crate::ui::widgets::atomic::button::tokens::BUTTON_KEYS),
        "checkbox" => Some(crate::ui::widgets::atomic::checkbox::tokens::CHECKBOX_KEYS),
        "chevron" => Some(crate::ui::widgets::atomic::chevron::tokens::CHEVRON_KEYS),
        "clock" => Some(crate::ui::widgets::atomic::clock::tokens::CLOCK_KEYS),
        "close_button" => Some(crate::ui::widgets::atomic::close_button::tokens::CLOSE_BUTTON_KEYS),
        "color_swatch" => Some(crate::ui::widgets::atomic::color_swatch::tokens::COLOR_SWATCH_KEYS),
        "drag_handle" => Some(crate::ui::widgets::atomic::drag_handle::tokens::DRAG_HANDLE_KEYS),
        "dropdown_trigger" => Some(crate::ui::widgets::atomic::dropdown_trigger::tokens::DROPDOWN_TRIGGER_KEYS),
        "item" => Some(crate::ui::widgets::atomic::item::tokens::ITEM_KEYS),
        "radio" => Some(crate::ui::widgets::atomic::radio::tokens::RADIO_KEYS),
        "scrollbar" => Some(crate::ui::widgets::atomic::scrollbar::tokens::SCROLLBAR_KEYS),
        "container" => Some(crate::ui::widgets::atomic::container::tokens::CONTAINER_KEYS),
        "scroll_chevron" => {
            Some(crate::ui::widgets::atomic::scroll_chevron::tokens::SCROLL_CHEVRON_KEYS)
        }
        "separator" => Some(crate::ui::widgets::atomic::separator::tokens::SEPARATOR_KEYS),
        "text" => Some(crate::ui::widgets::atomic::text::tokens::TEXT_KEYS),
        "tab" => Some(crate::ui::widgets::atomic::tab::tokens::TAB_KEYS),
        "slider" => Some(crate::ui::widgets::atomic::slider::tokens::SLIDER_KEYS),
        "text_input" => Some(crate::ui::widgets::atomic::text_input::tokens::TEXT_INPUT_KEYS),
        "toggle" => Some(crate::ui::widgets::atomic::toggle::tokens::TOGGLE_KEYS),
        "toast" => Some(crate::ui::widgets::atomic::toast::tokens::TOAST_KEYS),
        "tooltip" => Some(crate::ui::widgets::atomic::tooltip::tokens::TOOLTIP_KEYS),
        "blackbox_panel" => {
            Some(crate::ui::widgets::composite::blackbox_panel::tokens::BLACKBOX_PANEL_KEYS)
        }
        "chrome" => Some(crate::ui::widgets::composite::chrome::tokens::CHROME_KEYS),
        "context_menu" => {
            Some(crate::ui::widgets::composite::context_menu::tokens::CONTEXT_MENU_KEYS)
        }
        "dropdown" => Some(crate::ui::widgets::composite::dropdown::tokens::DROPDOWN_KEYS),
        "modal" => Some(crate::ui::widgets::composite::modal::tokens::MODAL_KEYS),
        "panel" => Some(crate::ui::widgets::composite::panel::tokens::PANEL_KEYS),
        "popup" => Some(crate::ui::widgets::composite::popup::tokens::POPUP_KEYS),
        "sidebar" => Some(crate::ui::widgets::composite::sidebar::tokens::SIDEBAR_KEYS),
        "toolbar" => Some(crate::ui::widgets::composite::toolbar::tokens::TOOLBAR_KEYS),
        _ => None,
    }
}