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 HTMX integration
- Visual Models: Visibility, image, and text styling 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
layout
feature)
Text & Typography
- TextAlign: Start, Center, End, Justify alignment
- TextDecorationLine: None, Underline, Overline, LineThrough
- TextDecorationStyle: Solid, Double, Dotted, Dashed, Wavy
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 & HTMX
- Route: GET, POST, PUT, DELETE, PATCH HTTP methods
- SwapTarget: This, Children, Id targeting for HTMX swaps
- LinkTarget: SelfTarget, Blank, Parent, Top, Custom
Installation
Add this to your Cargo.toml
:
[]
= { = "../hyperchad/transformer/models" }
# Enable additional features
= {
path = "../hyperchad/transformer/models",
= ["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;
println!;
// Output: "Text: center underline dashed"
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"
HTMX Routing
use ;
// Define routes
let get_route = Get ;
let post_route = Post ;
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"
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
Visual Models
- Visibility: Element visibility states
- Position: CSS positioning types
- Cursor: Mouse cursor appearances
- ImageLoading: Image loading strategies
- ImageFit: Image fitting modes
Interaction Models
- Route: HTTP routing with HTMX support
- SwapTarget: HTMX content swap targets
- LinkTarget: Link navigation targets
String Conversion
All models implement Display
for CSS-compatible string output:
use *;
// All models convert to CSS-compatible strings
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
- Serde: Optional serialization support
Integration
This package is designed for:
- UI Frameworks: Core UI component modeling
- CSS Generation: CSS class and style generation
- HTMX Integration: Server-side rendered applications
- Layout Systems: Flexbox and grid layout systems
- Component Libraries: Reusable UI component definitions