dampen_core/ir/
mod.rs

1pub mod layout;
2pub mod node;
3pub mod span;
4pub mod style;
5pub mod theme;
6
7use std::collections::HashMap;
8
9pub use layout::{
10    Alignment, Breakpoint, Direction, Justification, LayoutConstraints, Length, Padding,
11};
12pub use node::InterpolatedPart;
13pub use node::{AttributeValue, EventBinding, EventKind, WidgetKind, WidgetNode};
14pub use span::Span;
15pub use style::{
16    Background, Border, BorderRadius, BorderStyle, Color, Gradient, ImageFit, Shadow,
17    StyleProperties, Transform,
18};
19pub use theme::{
20    FontWeight, IcedPaletteColors, SpacingScale, StateSelector, StyleClass, Theme, ThemeDocument,
21    ThemeError, ThemeErrorKind, ThemePalette, Typography, WidgetState,
22};
23
24/// A complete parsed Dampen UI document.
25///
26/// This is the root structure returned by the parser. It contains
27/// the document's schema version and the root widget tree.
28///
29/// # Example
30///
31/// ```rust
32/// use dampen_core::{parse, DampenDocument};
33///
34/// let xml = r#"<dampen><column><text value="Hello" /></column></dampen>"#;
35/// let doc: DampenDocument = parse(xml).unwrap();
36/// assert_eq!(doc.version.major, 1);
37/// ```
38#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
39pub struct DampenDocument {
40    /// Schema version for compatibility checking
41    pub version: SchemaVersion,
42
43    /// Root widget of the UI tree
44    pub root: WidgetNode,
45
46    /// Theme definitions
47    pub themes: HashMap<String, crate::ir::theme::Theme>,
48
49    /// Style class definitions
50    pub style_classes: HashMap<String, crate::ir::theme::StyleClass>,
51
52    /// Global theme name
53    pub global_theme: Option<String>,
54
55    /// Whether to follow system theme (light/dark mode)
56    pub follow_system: bool,
57}
58
59impl Default for DampenDocument {
60    /// Creates a default document with version 1.0 and an empty root column.
61    fn default() -> Self {
62        Self {
63            version: SchemaVersion { major: 1, minor: 0 },
64            root: WidgetNode::default(),
65            themes: HashMap::new(),
66            style_classes: HashMap::new(),
67            global_theme: None,
68            follow_system: true,
69        }
70    }
71}
72
73/// Schema version for compatibility checking.
74///
75/// Versions follow semantic versioning:
76/// - Major: Breaking changes
77/// - Minor: Backward-compatible additions
78///
79/// Files without an explicit version default to 1.0.
80#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
81pub struct SchemaVersion {
82    /// Major version number
83    pub major: u16,
84    /// Minor version number
85    pub minor: u16,
86}
87
88impl Default for SchemaVersion {
89    /// Default version is 1.0
90    fn default() -> Self {
91        Self { major: 1, minor: 0 }
92    }
93}