HyperChad Transformer Models
Core data models and types for HyperChad UI transformations and layout.
Overview
The HyperChad Transformer Models package provides:
- Layout Models: Flexible layout direction and overflow handling
- Alignment Types: Content and item alignment options
- Position Models: Element positioning and cursor types
- Route Models: HTTP routing and dynamic content swapping
- Element Targets: Flexible element targeting with literal and reference values
- Visual Models: Visibility, image, and text styling options
- Typography Models: Font weight and text decoration options
- Serialization: Optional serde support for all models
Models
Layout System
- LayoutDirection: Row/Column layout directions
- LayoutOverflow: Auto, Scroll, Expand, Squash, Wrap, Hidden
- JustifyContent: Start, Center, End, SpaceBetween, SpaceEvenly
- AlignItems: Start, Center, End alignment
- LayoutPosition: Grid positioning with row/column (with
layoutfeature)
Text & Typography
- TextAlign: Start, Center, End, Justify alignment
- TextDecorationLine: Inherit, None, Underline, Overline, LineThrough
- TextDecorationStyle: Inherit, Solid, Double, Dotted, Dashed, Wavy
- FontWeight: Thin, ExtraLight, Light, Normal, Medium, SemiBold, Bold, ExtraBold, Black, Lighter, Bolder, and numeric weights (100-900)
- WhiteSpace: Normal, Preserve, PreserveWrap
- UserSelect: Auto, None, Text, All
- OverflowWrap: Normal, BreakWord, Anywhere
- TextOverflow: Clip, Ellipsis
Visual Properties
- Visibility: Visible/Hidden states
- Position: Static, Relative, Absolute, Sticky, Fixed
- Cursor: Comprehensive cursor type definitions
- ImageLoading: Eager/Lazy loading strategies
- ImageFit: Default, Contain, Cover, Fill, None
Routing & Swapping
- Route: GET, POST, PUT, DELETE, PATCH HTTP methods
- Selector: Id, Class, ChildClass, SelfTarget element targeting
- ElementTarget: ById, Selector, Class, ChildClass, Id, SelfTarget, LastChild targeting
- Target: Literal and Ref target value forms for element targeting
- SwapStrategy: This, Children, BeforeBegin, AfterBegin, BeforeEnd, AfterEnd, Delete, None swap strategies
- LinkTarget: SelfTarget, Blank, Parent, Top, Custom
Installation
Add this to your Cargo.toml:
[]
= { = "../hyperchad/transformer/models" }
# Customize features
# hyperchad_transformer_models = {
# path = "../hyperchad/transformer/models",
# default-features = false,
# features = ["serde", "layout", "arb"]
# }
Usage
Layout Configuration
use ;
// Configure layout
let direction = Row;
let overflow = Wrap ;
let justify = SpaceBetween;
let align = Center;
println!;
// Output: "Layout: row wrap-grid space-between center"
Text Styling
use ;
// Text configuration
let align = Center;
let decoration = Underline;
let style = Dashed;
let weight = Bold;
println!;
// Output: "Text: center underline dashed bold"
Visual Properties
use ;
// Visual configuration
let visibility = Visible;
let position = Relative;
let cursor = Pointer;
println!;
// Output: "Visual: visible relative pointer"
Image Configuration
use ;
// Image settings
let loading = Lazy;
let fit = Cover;
println!;
// Output: "Image: lazy cover"
Dynamic Routing
use ;
// Define routes
let get_route = Get ;
let post_route = Post ;
Element Targeting
use ;
let target = by_id;
let selector_target = selector;
let child_target = child_class;
let selector = try_from.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Link Targets
use LinkTarget;
// Link target configurations
let self_target = SelfTarget;
let blank_target = Blank;
let custom_target = Custom;
println!;
// Output: "Targets: _self _blank custom-frame"
Font Weights
use FontWeight;
// Semantic font weights
let normal = Normal;
let bold = Bold;
// Numeric font weights
let weight_400 = Weight400;
let weight_700 = Weight700;
println!;
// Output: "Semantic: normal bold"
println!;
// Output: "Numeric: 400 700"
Layout Positioning (with layout feature)
use LayoutPosition;
Model Categories
Layout Models
- LayoutDirection: Flexbox direction (row/column)
- LayoutOverflow: Content overflow behavior
- JustifyContent: Main axis alignment
- AlignItems: Cross axis alignment
- LayoutPosition: Grid positioning (feature-gated)
Typography Models
- TextAlign: Text alignment options
- TextDecorationLine: Text decoration types
- TextDecorationStyle: Decoration styling
- FontWeight: Font weight variants (semantic and numeric)
- WhiteSpace: Whitespace handling
- UserSelect: Text selection behavior
- OverflowWrap: Word wrapping behavior
- TextOverflow: Text overflow handling
Visual Models
- Visibility: Element visibility states
- Position: Element positioning types
- Cursor: Mouse cursor appearances
- ImageLoading: Image loading strategies
- ImageFit: Image fitting modes
Interaction Models
- Route: HTTP routing with dynamic content swapping
- Selector: Element selector targeting
- ElementTarget: Targeting by id, class, selector, or structural position
- Target: Literal and reference target values
- SwapStrategy: Content swap strategies
- LinkTarget: Link navigation targets
String Conversion
All models implement Display for string output compatible with various backends:
use *;
// All models convert to backend-compatible strings
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Feature Flags
serde: Enable serialization/deserializationlayout: Enable layout positioning modelsarb: Enable arbitrary data generation for testing
Dependencies
Core dependencies:
- log: Logging support
- moosicbox_assert: Assertion utilities
- thiserror: Error type definitions
Optional dependencies:
- serde: Serialization/deserialization support (with
serdefeature) - test-strategy: Arbitrary derive macro support (with
arbfeature) - proptest: Property-based testing support (with
arbfeature)
Integration
This package is designed for:
- UI Frameworks: Core UI component modeling
- Style Generation: Class and style generation for various backends
- Dynamic Content: Server-side rendered applications
- Layout Systems: Flexbox and grid layout systems
- Component Libraries: Reusable UI component definitions