euv-core 0.3.11

A declarative, cross-platform UI framework for Rust with virtual DOM, reactive signals, and HTML macros for WebAssembly.
Documentation
use crate::*;

/// Represents a CSS style property.
///
/// A single key-value pair representing a CSS declaration.
#[derive(Data, Default, New)]
pub struct StyleProperty {
    /// The CSS property name (e.g., "margin", "padding").
    #[get(pub)]
    #[set(pub)]
    name: String,
    /// The CSS property value.
    #[get(pub)]
    #[set(pub)]
    value: String,
}

/// A collection of CSS style properties that can be converted to a style string.
#[derive(Data, New)]
pub struct Style {
    /// The list of style properties.
    #[get(pub)]
    #[set(pub)]
    properties: Vec<StyleProperty>,
}

/// Represents a single attribute on a virtual DOM node.
///
/// Combines an attribute name with its corresponding value.
#[derive(Clone, Data, Debug, New)]
pub struct AttributeEntry {
    /// The name of the attribute.
    #[get(pub(crate))]
    #[set(pub(crate))]
    pub(crate) name: String,
    /// The value of the attribute.
    #[get(pub(crate))]
    #[set(pub(crate))]
    pub(crate) value: AttributeValue,
}

/// Represents a CSS class with a name and its style declarations.
///
/// Created by the `class!` macro and used in `html!` via the `class:` attribute.
/// When the renderer encounters a `CssClass`, it injects the styles into the
/// DOM's `<style>` element on first use and applies the class name to the element.
#[derive(Clone, Data, Debug, Default)]
pub struct CssClass {
    /// The CSS class name used in the DOM.
    #[get(pub)]
    #[set(pub)]
    name: String,
    /// The CSS style declarations (e.g., "max-width: 800px; margin: 0 auto;").
    #[get(pub)]
    #[set(pub)]
    style: String,
}

/// Adapts various event value types into an `AttributeValue` for event attributes.
///
/// The `html!` macro generates `EventAdapter::new(expr).into_attribute(event_name)`
/// instead of inline trait dispatch boilerplate. This eliminates the per-attribute-site
/// generation of `__EventWrapper`, `__IsClosure`, `__ClosurePicker`, `__ValuePicker`,
/// `__FallbackHelper`, and `__dispatch` types, significantly reducing macro output size.
///
/// The adapter pattern handles three cases:
/// - `FnMut(NativeEvent)` closure → `AttributeValue::Event` via `NativeEventHandler`
/// - `NativeEventHandler` directly → `AttributeValue::Event` as-is
/// - `Option<NativeEventHandler>` → `AttributeValue::Event` or `AttributeValue::Text`
pub struct EventAdapter<T> {
    /// The wrapped value to be adapted into an attribute.
    pub(crate) inner: T,
}

/// Adapts an arbitrary attribute value expression into an `AttributeValue`.
///
/// Handles the dispatch between event closures and reactive values without
/// requiring the macro to generate inline trait hierarchies. The macro emits
/// `AttrValueAdapter::new(expr).into_attribute_value()` instead of the
/// `__IsClosure` / `__ClosurePicker` / `__ValuePicker` / `__FallbackHelper`
/// / `__dispatch` boilerplate.
///
/// For event attributes (key starts with "on"), event closures are wrapped
/// into `AttributeValue::Event`. For non-event attributes, values are
/// converted via `IntoReactiveValue`.
pub struct AttrValueAdapter<T> {
    /// The wrapped value to be adapted into an attribute.
    pub(crate) inner: T,
}