HyperChad Transformer
Core UI transformation system with container models, layout calculations, and HTML generation.
Overview
The HyperChad Transformer package provides:
- Container System: Comprehensive UI container model with styling and layout
- Layout Engine: Advanced layout calculation with flexbox and grid support
- HTML Generation: Complete HTML rendering with CSS generation
- Calculation System: CSS calc() expressions with viewport units
- Element Types: Full HTML element support with semantic elements
- Responsive Design: Conditional styling and responsive breakpoints
- Tree Traversal: Efficient container tree navigation and manipulation
Features
Container Model
- Comprehensive Styling: Complete CSS property support
- Layout Properties: Flexbox, grid, positioning, and spacing
- Typography: Font families, sizes, colors, and text decoration
- Visual Effects: Borders, backgrounds, opacity, and transforms
- Interactive Elements: Actions, routes, and event handling
- State Management: Component state and data attributes
Layout System
- Flexbox Layout: Complete flexbox implementation
- Grid Layout: CSS Grid support with cell sizing
- Positioning: Static, relative, absolute, fixed, and sticky
- Responsive Units: vw, vh, dvw, dvh, percentages
- Calculations: CSS calc() expressions with math operations
- Viewport Handling: Dynamic viewport size calculations
Element Types
- Semantic HTML: div, main, header, footer, section, aside
- Forms: input, button, form elements with validation
- Media: images with responsive loading and sizing
- Navigation: anchors with target and href support
- Typography: headings (h1-h6), paragraphs, spans
- Lists: ordered and unordered lists with items
- Tables: complete table structure (table, thead, tbody, tr, td, th)
- Canvas: Optional canvas element support
Tree Operations
- BFS Traversal: Breadth-first search with level tracking
- Element Finding: Find by ID, string ID, or CSS class
- Parent/Child: Navigate parent-child relationships
- Element Replacement: Replace elements by ID or selector
- Filtering: Filter by visibility, position, or element type
Installation
Add this to your Cargo.toml
:
[]
= { = "../hyperchad/transformer" }
# Enable additional features
= {
path = "../hyperchad/transformer",
= ["html", "layout", "layout-offset"]
}
Usage
Basic Container Creation
use ;
use Color;
let mut container = Container ;
HTML Generation
use Container;
let container = default;
// Convert to HTML string
let html = container.to_string;
// Pretty printed HTML
let pretty_html = container.display_to_string_default_pretty?;
// With debug attributes
let debug_html = container.display_to_string_default?;
Layout Calculations
use ;
// CSS calc() expressions
let width = Calc;
// Viewport units
let height = RealVh; // 50vh
let font_size = RealDvw; // 4dvw
Element Types
use ;
// Form input
let text_input = Input ;
// Image with responsive loading
let image = Image ;
// Heading
let heading = Heading ;
// Link
let link = Anchor ;
Tree Traversal
use Container;
let mut root = default;
// ... populate with children
// Breadth-first traversal
let paths = root.bfs;
paths.traverse;
// Find elements
if let Some = root.find_element_by_str_id
// Find by class
if let Some = root.find_element_by_class
Element Replacement
use Container;
let mut root = default;
let new_elements = vec!;
// Replace children by ID
if let Some = root.replace_str_id_children_with_elements
// Replace element by ID
if let Some = root.replace_str_id_with_elements
Responsive Design
use ;
use LayoutDirection;
let mut container = default;
// Add responsive override
container.overrides.push;
Layout Calculations (with layout
feature)
use Calc;
Table Operations
use Container;
let mut table = Container ;
// Iterate table structure
let table_iter = table.table_iter;
if let Some = table_iter.headings
for row in table_iter.rows
Input Elements
use ;
// Text input
let text_input = Input ;
// Checkbox
let checkbox = Input ;
// Password input
let password = Input ;
Number System
Basic Numbers
use Number;
let pixels = Real;
let percentage = RealPercent;
let viewport_width = RealVw;
let viewport_height = RealVh;
Calculations
use ;
let calc = Calc;
// Represents: calc(50% + 20px)
Container Properties
Layout Properties
- direction: LayoutDirection (Row/Column)
- overflow_x/overflow_y: LayoutOverflow handling
- justify_content: Main axis alignment
- align_items: Cross axis alignment
- flex: Flexbox grow, shrink, basis
Spacing Properties
- width/height: Element dimensions
- min_width/max_width: Size constraints
- margin_*: External spacing
- padding_*: Internal spacing
- column_gap/row_gap: Flexbox/grid gaps
Visual Properties
- background: Background color
- color: Text color
- opacity: Element transparency
- border_*: Border styling
- border_*_radius: Corner rounding
Typography Properties
- font_family: Font stack
- font_size: Text size
- text_align: Text alignment
- text_decoration: Text styling
Feature Flags
html
: Enable HTML generation and parsinglayout
: Enable layout calculation systemlayout-offset
: Enable offset calculations
Dependencies
- HyperChad Actions: Interactive action system
- HyperChad Color: Color handling and conversion
- HyperChad Transformer Models: Layout and styling types
- Serde: Serialization and deserialization
- Strum: Enum utilities
Integration
This package is designed for:
- UI Frameworks: Core UI component system
- Layout Engines: Advanced layout calculation
- HTML Generation: Server-side rendering
- Desktop Applications: Native UI layout
- Responsive Design: Adaptive UI components