HyperChad Renderer
Core rendering abstractions and traits for HyperChad UI frameworks.
Overview
The HyperChad Renderer package provides:
- Renderer Traits: Abstract interfaces for different rendering backends
- Content Types: Structured content representation (View, PartialView, JSON)
- Event System: Renderer event handling and processing
- HTML Generation: HTML tag rendering and CSS generation
- Asset Management: Optional static asset handling
- Canvas Support: Optional canvas rendering capabilities
Features
Core Abstractions
- Renderer Trait: Main rendering interface for backends
- RenderRunner: Application execution and lifecycle management
- ToRenderRunner: Conversion trait for renderer instances
- HtmlTagRenderer: HTML-specific rendering capabilities
Content System
- View: Full page view with immediate and future content
- PartialView: Targeted partial content updates
- Content Enum: Unified content representation
- JSON Support: Optional JSON content handling
Event Handling
- RendererEvent: Event types for renderer communication
- Custom Events: User-defined event processing
- Canvas Events: Optional canvas update events
- Async Events: Async event emission and handling
HTML Rendering
- Tag Generation: HTML element and attribute generation
- CSS Media Queries: Responsive CSS generation
- Root HTML: Complete HTML document generation
- Partial HTML: Fragment HTML generation
Installation
Add this to your Cargo.toml:
[]
= { = "../hyperchad/renderer" }
# Enable additional features
= {
path = "../hyperchad/renderer",
= ["json", "canvas", "assets", "viewport"]
}
Usage
Implementing a Renderer
use ;
use async_trait;
Content Creation
use ;
use Container;
// Create view content
let view_content = view;
// Create partial view content
let partial_content = partial_view;
// From string (with HTML parsing)
let string_content: Content = "<div>Hello World</div>".try_into?;
// From container
let container_content = from;
HTML Tag Renderer
use ;
use ;
use HashMap;
Event Handling
use RendererEvent;
// Handle renderer events
match event
Canvas Support (with canvas feature)
use CanvasUpdate;
Asset Management (with assets feature)
use StaticAssetRoute;
Content Types
View
- immediate: Content available immediately
- future: Content that will be available asynchronously
- Container: HyperChad container structure
PartialView
- target: CSS selector for target element
- container: Content to insert/replace
Content Enum
- View: Full page content
- PartialView: Partial content update
- Json: JSON response (with
jsonfeature)
Traits
Renderer
Core rendering interface with initialization, rendering, and event handling.
RenderRunner
Application execution interface for running renderer instances.
ToRenderRunner
Conversion trait for creating runner instances from renderers.
HtmlTagRenderer
HTML-specific rendering with CSS generation and document structure.
Feature Flags
json: Enable JSON content supportcanvas: Enable canvas rendering capabilitiesassets: Enable static asset managementviewport: Enable viewport utilities
Dependencies
- HyperChad Transformer: UI transformation and container system
- HyperChad Color: Color handling and conversion
- Async Trait: Async trait support
- Switchy Async: Runtime abstraction
Integration
This package is designed for:
- Rendering Backends: Implementation base for different renderers
- UI Frameworks: Core rendering abstractions
- Web Applications: HTML and CSS generation
- Desktop Applications: Native rendering interfaces
- Static Generation: Static site and asset generation