stylex_types/traits.rs
1use std::any::Any;
2use std::rc::Rc;
3
4use indexmap::IndexMap;
5use rustc_hash::FxHashMap;
6
7use stylex_structures::stylex_state_options::StyleXStateOptions;
8
9use crate::enums::data_structures::injectable_style::InjectableStyleKind;
10
11/// Type alias for injectable styles map, moved here to be available at the types level.
12pub type InjectableStylesMap = IndexMap<String, Rc<InjectableStyleKind>>;
13
14/// Tier 1: Minimal interface for CSS generation, PreRule, and function pointer signatures.
15///
16/// Object-safe — used as `dyn StyleOptions` in function pointer signatures
17/// (e.g., `StylexExprFn`, `FunctionType::ArrayArgs`).
18///
19/// `StateManager` implements this trait in the `stylex-transform` crate.
20pub trait StyleOptions {
21 /// Access the StyleX configuration options.
22 fn options(&self) -> &StyleXStateOptions;
23
24 /// Map of CSS properties already processed, used to avoid duplicates.
25 fn css_property_seen(&self) -> &FxHashMap<String, String>;
26
27 /// Mutable access to the CSS properties map.
28 fn css_property_seen_mut(&mut self) -> &mut FxHashMap<String, String>;
29
30 /// Access to injected CSS rules for keyframes, position-try, etc.
31 fn other_injected_css_rules(&self) -> &InjectableStylesMap;
32
33 /// Mutable access to injected CSS rules.
34 fn other_injected_css_rules_mut(&mut self) -> &mut InjectableStylesMap;
35
36 /// Downcast to concrete type for bridge during migration.
37 fn as_any_mut(&mut self) -> &mut dyn Any;
38}