Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
HyperChad Vanilla JS Renderer
Client-side JavaScript renderer for HyperChad with vanilla JavaScript and optional plugins.
Overview
The HyperChad Vanilla JS Renderer provides:
- Client-side Rendering: Dynamic UI updates in the browser using vanilla JavaScript
- Plugin System: Modular plugin architecture for extended functionality
- Action System: Complete client-side action handling and event processing
- DOM Manipulation: Efficient DOM updates and element management
- Event Handling: Comprehensive event system with custom events
- Form Processing: Advanced form handling and validation
- Navigation: Client-side routing and navigation
- Canvas Support: 2D canvas rendering and graphics
Features
Core Functionality
- DOM Rendering: Convert HyperChad components to DOM elements
- Event System: Mouse, keyboard, and custom event handling
- Action Processing: Client-side action execution and effects
- State Management: Component state tracking and updates
- Element Targeting: Flexible element selection and manipulation
Plugin System
- Modular Architecture: Enable only needed functionality
- Navigation Plugin: Client-side routing and history management
- Idiomorph Plugin: Intelligent DOM morphing for smooth updates
- SSE Plugin: Server-Sent Events for real-time updates
- Tauri Plugin: Integration with Tauri desktop applications
- UUID Plugin: Unique identifier generation
- Canvas Plugin: 2D graphics and drawing support
- Form Plugin: Advanced form handling and validation
Action Plugins
- Click Actions (
plugin-actions-click): Click event handling and processing - Click Outside Actions (
plugin-actions-click-outside): Detect clicks outside elements - Change Actions (
plugin-actions-change): Form input change detection - Mouse Down Actions (
plugin-actions-mouse-down): Mouse down event handling - Mouse Over Actions (
plugin-actions-mouse-over): Mouse over event handling - Key Down Actions (
plugin-actions-key-down): Keyboard key down events - Key Up Actions (
plugin-actions-key-up): Keyboard key up events - Event Key Down Actions (
plugin-actions-event-key-down): Custom key down event handling - Event Key Up Actions (
plugin-actions-event-key-up): Custom key up event handling - Resize Actions (
plugin-actions-resize): Window and element resize handling - Immediate Actions (
plugin-actions-immediate): Instant action execution on load - Event Actions (
plugin-actions-event): Custom event triggering and handling
Installation
Add this to your Cargo.toml:
[]
= { = "../hyperchad/renderer/vanilla_js" }
# With specific plugins
= {
path = "../hyperchad/renderer/vanilla_js",
= [
"plugin-nav",
"plugin-idiomorph",
"plugin-sse",
"plugin-form",
"plugin-canvas"
]
}
# With action plugins
= {
path = "../hyperchad/renderer/vanilla_js",
= [
"plugin-actions-click",
"plugin-actions-change",
"plugin-actions-resize"
]
}
Usage
Basic HTML Integration
use VanillaJsTagRenderer;
use ;
use container;
// Create vanilla JS tag renderer
let tag_renderer = default;
// Wrap in StubApp (or use router_to_actix/router_to_lambda for real backends)
let app = new;
// Create HTML renderer with vanilla JS support
let renderer = new
.with_title;
// Create interactive view
let view = container! ;
// The generated HTML will include the vanilla JS script
renderer.render.await?;
Renderer Event Publishing API
When you need to publish updates to connected clients (for example with SSE), use VanillaJsRenderer.
VanillaJsRenderer::default()creates the renderer extensionemit_event(publisher, event_name, event_value)publishesRendererEvent::Eventrender(publisher, view)publishesRendererEvent::Viewrender_canvas(publisher, update)publishesRendererEvent::CanvasUpdate
VanillaJsRenderer implements hyperchad_renderer_html::extend::ExtendHtmlRenderer, so bring that trait into scope when calling these methods.
JavaScript Asset Constants
Use these public constants when serving the embedded runtime asset:
SCRIPT_NAME- Runtime filename (hyperchad.jsin debug builds,hyperchad.min.jsin release builds)SCRIPT- Embedded runtime JavaScript source (requiresscriptfeature)SCRIPT_NAME_HASHED- Content-hashed runtime filename (requires bothscriptandhashfeatures)
Form Handling
use container;
use ActionType;
let form_view = container! ;
Navigation and Routing
// With plugin-nav feature enabled
use container;
use ActionType;
let navigation_view = container! ;
Working with Background Colors
use container;
use ActionType;
let interactive_view = container! ;
Available Actions
The renderer supports various action types through the ActionType enum. Here are the commonly used actions:
Visibility Actions
ActionType::show_by_id(target)- Show element by IDActionType::hide_by_id(target)- Hide element by IDActionType::toggle_visibility_by_id(target)- Toggle element visibility (requireslogicfeature)ActionType::show_class(class)- Show elements by class nameActionType::hide_class(class)- Hide elements by class name
Display Actions
ActionType::display_by_id(target)- Set display to initialActionType::no_display_by_id(target)- Set display to noneActionType::display_class(class)- Set display to initial for classActionType::no_display_class(class)- Set display to none for class
Focus Actions
ActionType::focus_by_id(target)- Focus element by IDActionType::focus_class(class)- Focus element by class nameActionType::select_by_id(target)- Select input text by ID
Style Actions
ActionType::set_background_by_id(color, target)- Set background colorActionType::remove_background_by_id(target)- Remove background colorActionType::remove_background_class(class)- Remove background color from class
Navigation Actions
ActionType::Navigate { url }- Navigate to URL (requiresplugin-nav)
Utility Actions
ActionType::Log { message, level }- Log message to consoleActionType::Custom { action }- Custom action JavaScript expressionActionType::NoOp- No operation
For literal string action names, include JS quotes in action (for example "'increment'").
Combining Actions
use container;
// Chain multiple actions using fx syntax
let view = container! ;
// Add throttling (300ms) and delay_off (2000ms) using action modifiers
let view_with_effects = container! ;
Plugin Features
Navigation Plugin (plugin-nav)
Provides client-side navigation capabilities:
- Navigation Actions: Use
ActionType::Navigate { url }for programmatic navigation - Browser History: Integration with browser history API
- SPA Support: Single-page application routing
Idiomorph Plugin (plugin-idiomorph)
Enables intelligent DOM updates:
- Smart DOM Morphing: Minimal DOM manipulation for updates
- State Preservation: Maintains form state and element focus during updates
- Performance: Efficient diffing algorithm
SSE Plugin (plugin-sse)
Server-Sent Events support for real-time updates:
- Real-time Updates: Receive server-side events
- Event Handling: Process server-sent data streams
- UUID Generation: Requires
plugin-uuidfor event tracking
Shared State Plugin (plugin-shared-state)
Shared state transport support built on the SSE transport primitives:
- Auto-subscribe channels: Tracks
data-shared-state-channeldeclarations in DOM - Session-aware transport: Streams from
/$shared-state/transport/sseand posts outbound messages to/$shared-state/transport - Event dispatching: Emits
v-shared-state-*events (message,snapshot,event,command-accepted,command-rejected,pong,connected) - No custom JS required: Pair with
fx-shared-state-*action triggers for declarative behavior
Form Plugin (plugin-form)
Enhanced form handling capabilities:
- Form Processing: Client-side form handling
- Data Serialization: Form data collection and serialization
Canvas Plugin (plugin-canvas)
Canvas rendering support:
- 2D Graphics: Canvas 2D rendering context
- Drawing Operations: Basic rendering support (lines, rectangles, fills, strokes) through
CanvasUpdateAPI
Script Inclusion
The renderer automatically includes the appropriate JavaScript:
<!-- Development -->
<!-- Production (minified) -->
<!-- With hash (cache busting) -->
Feature Flags
Core Features
script: Include JavaScript code in the binaryhash: Generate content-based script hashes
Plugins
plugin-nav: Navigation and routingplugin-idiomorph: DOM morphingplugin-sse: Server-Sent Eventsplugin-shared-state: Shared state transport events and channel subscriptionsplugin-tauri-event: Tauri integrationplugin-uuid: UUID generationplugin-uuid-insecure: Insecure UUID (development only)plugin-routing: Advanced routingplugin-event: Custom eventsplugin-canvas: Canvas supportplugin-form: Form handlingplugin-http-events: HTTP request lifecycle events
Action Plugins
plugin-actions-change: Change event actionsplugin-actions-click: Click event actionsplugin-actions-click-outside: Click outside detectionplugin-actions-event: Custom event actionsplugin-actions-event-key-down: Custom key down event handlingplugin-actions-event-key-up: Custom key up event handlingplugin-actions-immediate: Immediate actionsplugin-actions-key-down: Keyboard key down eventsplugin-actions-key-up: Keyboard key up eventsplugin-actions-mouse-down: Mouse down actionsplugin-actions-mouse-over: Mouse over actionsplugin-actions-resize: Resize actions
Dependencies
- hyperchad_renderer: Core renderer with canvas and HTML features
- hyperchad_renderer_html: HTML generation and rendering with assets and extension support
- hyperchad_transformer: Transformer with HTML and logic features
- async-trait: Async trait support
- const_format: Compile-time string formatting
- convert_case: String case conversion for JavaScript generation
- html-escape: HTML attribute escaping
- log: Logging support
- maud: HTML template generation
- md5 (optional): Content hashing for cache busting (with
hashfeature)
Integration
This renderer is designed for:
- Web Applications: Interactive client-side web apps
- Progressive Enhancement: Add interactivity to server-rendered pages
- Single Page Applications: Full SPA functionality
- Desktop Apps: Tauri-based desktop applications
- Real-time Applications: Apps with live updates and notifications
Performance Considerations
- Vanilla JavaScript: No framework overhead
- Modular Loading: Load only needed plugins
- Efficient DOM Updates: Minimal DOM manipulation
- Event Delegation: Efficient event handling
- Caching: Script caching with content hashing