euv_core/vdom/attribute/struct.rs
1use crate::*;
2
3/// Represents a CSS style property.
4///
5/// A single key-value pair representing a CSS declaration.
6#[derive(Data, Default, New)]
7pub struct StyleProperty {
8 /// The CSS property name (e.g., "margin", "padding").
9 #[get(pub)]
10 #[set(pub)]
11 name: String,
12 /// The CSS property value.
13 #[get(pub)]
14 #[set(pub)]
15 value: String,
16}
17
18/// A collection of CSS style properties that can be converted to a style string.
19#[derive(Data, New)]
20pub struct Style {
21 /// The list of style properties.
22 #[get(pub)]
23 #[set(pub)]
24 properties: Vec<StyleProperty>,
25}
26
27/// Represents a single attribute on a virtual DOM node.
28///
29/// Combines an attribute name with its corresponding value.
30#[derive(Clone, Data, New)]
31pub struct AttributeEntry {
32 /// The name of the attribute.
33 #[get(pub(crate))]
34 #[set(pub(crate))]
35 pub(crate) name: String,
36 /// The value of the attribute.
37 #[get(pub(crate))]
38 #[set(pub(crate))]
39 pub(crate) value: AttributeValue,
40}
41
42/// Represents a CSS class with a name and its style declarations.
43///
44/// Created by the `class!` macro and used in `html!` via the `class:` attribute.
45/// When the renderer encounters a `CssClass`, it injects the styles into the
46/// DOM's `<style>` element on first use and applies the class name to the element.
47#[derive(Clone, Data, Default)]
48pub struct CssClass {
49 /// The CSS class name used in the DOM.
50 #[get(pub)]
51 #[set(pub)]
52 name: String,
53 /// The CSS style declarations (e.g., "max-width: 800px; margin: 0 auto;").
54 #[get(pub)]
55 #[set(pub)]
56 style: String,
57}
58
59/// Adapts various event value types into an `AttributeValue` for event attributes.
60///
61/// The `html!` macro generates `EventAdapter::new(expr).into_attribute(event_name)`
62/// instead of inline trait dispatch boilerplate. This eliminates the per-attribute-site
63/// generation of `__EventWrapper`, `__IsClosure`, `__ClosurePicker`, `__ValuePicker`,
64/// `__FallbackHelper`, and `__dispatch` types, significantly reducing macro output size.
65///
66/// The adapter pattern handles three cases:
67/// - `FnMut(NativeEvent)` closure → `AttributeValue::Event` via `NativeEventHandler`
68/// - `NativeEventHandler` directly → `AttributeValue::Event` as-is
69/// - `Option<NativeEventHandler>` → `AttributeValue::Event` or `AttributeValue::Text`
70pub struct EventAdapter<T> {
71 /// The wrapped value to be adapted into an attribute.
72 pub(crate) inner: T,
73}
74
75/// Adapts an arbitrary attribute value expression into an `AttributeValue`.
76///
77/// Handles the dispatch between event closures and reactive values without
78/// requiring the macro to generate inline trait hierarchies. The macro emits
79/// `AttrValueAdapter::new(expr).into_attribute_value()` instead of the
80/// `__IsClosure` / `__ClosurePicker` / `__ValuePicker` / `__FallbackHelper`
81/// / `__dispatch` boilerplate.
82///
83/// For event attributes (key starts with "on"), event closures are wrapped
84/// into `AttributeValue::Event`. For non-event attributes, values are
85/// converted via `IntoReactiveValue`.
86pub struct AttrValueAdapter<T> {
87 /// The wrapped value to be adapted into an attribute.
88 pub(crate) inner: T,
89}