Skip to main content

kozan_core/styling/
mod.rs

1//! Styling system — powered by Mozilla's Stylo CSS engine.
2//!
3//! This is the ONLY module that imports Stylo types. All other code
4//! (dom, layout, paint, public API) uses re-exports from here.
5
6pub mod builder;
7pub(crate) mod data;
8pub(crate) mod engine;
9pub(crate) mod font_metrics;
10pub(crate) mod node;
11pub mod taffy_bridge;
12pub(crate) mod traits;
13pub(crate) mod traversal;
14pub mod units;
15
16#[cfg(test)]
17mod tests;
18
19// ── Internal exports (used by dom) ──
20
21pub(crate) use engine::StyleEngine;
22
23// ═══════════════════════════════════════════════════════════════════
24// Public re-exports from Stylo
25// ═══════════════════════════════════════════════════════════════════
26
27/// Computed style values for an element. All CSS properties accessible via
28/// property struct getters (e.g. `cv.get_box().clone_display()`).
29pub use style::properties::ComputedValues;
30
31/// Stylo color type — used by `bg()`, `border_color()`, etc.
32pub use style::color::AbsoluteColor;
33
34/// CSS border-style keyword — `Solid`, `Dashed`, `Dotted`, `None`, etc.
35pub use style::values::specified::border::BorderStyle;
36
37/// A parsed CSS declaration block (inline styles, stylesheet rules).
38pub use style::properties::PropertyDeclarationBlock;
39
40/// Arc wrapper used by Stylo.
41pub use servo_arc::Arc;
42
43/// Returns initial (default) computed values wrapped in Arc.
44/// Stylo equivalent of the old `ComputedStyle::default()`.
45/// Uses a static cache to avoid repeated allocation.
46pub fn initial_values_arc() -> servo_arc::Arc<ComputedValues> {
47    use std::sync::OnceLock;
48    static INITIAL: OnceLock<servo_arc::Arc<ComputedValues>> = OnceLock::new();
49    INITIAL
50        .get_or_init(|| {
51            ComputedValues::initial_values_with_font_override(
52                style::properties::style_structs::Font::initial_values(),
53            )
54        })
55        .clone()
56}
57
58/// Stylo's shared lock — needed to read locked declarations.
59pub use style::shared_lock::{SharedRwLock, SharedRwLockReadGuard};
60
61/// Property struct groups — access computed values by category.
62/// Usage: `computed_values.get_box().clone_display()`
63pub use style::properties::style_structs;
64
65/// Computed value types that exist as standalone re-exports.
66pub mod values {
67    // Box model
68    pub use style::values::computed::Clear;
69    pub use style::values::computed::Display;
70    pub use style::values::computed::Float;
71    pub use style::values::computed::Overflow;
72
73    // Position
74    pub use style::values::computed::PositionProperty as Position;
75
76    // Flex alignment
77    pub use style::values::computed::ContentDistribution;
78    pub use style::values::computed::FlexBasis;
79    pub use style::values::computed::JustifyItems;
80    pub use style::values::computed::SelfAlignment;
81
82    // Size + spacing
83    pub use style::values::computed::CSSPixelLength;
84    pub use style::values::computed::Length;
85    pub use style::values::computed::LengthPercentage;
86    pub use style::values::computed::LengthPercentageOrAuto;
87    pub use style::values::computed::Margin;
88    pub use style::values::computed::MaxSize;
89    pub use style::values::computed::NonNegativeLength;
90    pub use style::values::computed::NonNegativeLengthPercentage;
91    pub use style::values::computed::Size;
92
93    // Text + font
94    pub use style::values::computed::FontFamily;
95    pub use style::values::computed::FontStyle;
96    pub use style::values::computed::FontWeight;
97    pub use style::values::computed::LineHeight;
98    pub use style::values::computed::Opacity;
99    pub use style::values::computed::TextAlign;
100    pub use style::values::computed::TextDecorationLine;
101
102    // Border
103    pub use style::values::computed::BorderStyle;
104
105    // Color
106    pub use style::color::AbsoluteColor as Color;
107
108    // Grid
109    pub use style::values::computed::GridAutoFlow;
110
111    // Transform
112    pub use style::values::computed::Transform;
113}