leptos_helios_wasm_core/
lib.rs

1//! Helios WASM Core - Minimal WASM-compatible version
2//!
3//! This crate provides a minimal, WASM-compatible version of Helios core
4//! that focuses on WebGPU rendering without heavy data processing dependencies.
5
6use serde::{Deserialize, Serialize};
7use thiserror::Error;
8use wasm_bindgen::prelude::*;
9
10/// Initialize Helios for WASM
11#[wasm_bindgen]
12pub async fn init_helios() -> Result<(), JsValue> {
13    console_error_panic_hook::set_once();
14    Ok(())
15}
16
17/// Get Helios version
18#[wasm_bindgen]
19pub fn get_version() -> String {
20    env!("CARGO_PKG_VERSION").to_string()
21}
22
23/// Simple chart specification for WASM
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct WasmChartSpec {
26    pub chart_type: String,
27    pub data: Vec<f32>,
28    pub width: u32,
29    pub height: u32,
30    pub title: Option<String>,
31}
32
33/// Create a simple chart specification
34#[wasm_bindgen]
35pub fn create_chart_spec(
36    chart_type: &str,
37    data: &[f32],
38    width: u32,
39    height: u32,
40    title: Option<String>,
41) -> Result<JsValue, JsValue> {
42    let spec = WasmChartSpec {
43        chart_type: chart_type.to_string(),
44        data: data.to_vec(),
45        width,
46        height,
47        title,
48    };
49
50    serde_wasm_bindgen::to_value(&spec).map_err(|e| JsValue::from_str(&e.to_string()))
51}
52
53/// WebGPU device wrapper for WASM
54#[wasm_bindgen]
55pub struct WasmWebGpuDevice {
56    // We'll store the actual device here when we implement it
57    _private: (),
58}
59
60#[wasm_bindgen]
61impl WasmWebGpuDevice {
62    /// Create a new WebGPU device
63    #[wasm_bindgen]
64    pub async fn new() -> Result<WasmWebGpuDevice, JsValue> {
65        // TODO: Implement actual WebGPU device creation
66        Ok(WasmWebGpuDevice { _private: () })
67    }
68
69    /// Check if WebGPU is available
70    #[wasm_bindgen]
71    pub fn is_available() -> bool {
72        // TODO: Check actual WebGPU availability
73        true
74    }
75}
76
77/// Error types for WASM
78#[derive(Error, Debug)]
79pub enum WasmError {
80    #[error("WebGPU not available")]
81    WebGpuNotAvailable,
82    #[error("Invalid chart specification: {0}")]
83    InvalidChartSpec(String),
84    #[error("Rendering error: {0}")]
85    RenderingError(String),
86}
87
88impl From<WasmError> for JsValue {
89    fn from(err: WasmError) -> Self {
90        JsValue::from_str(&err.to_string())
91    }
92}
93
94/// Initialize the WASM module
95#[wasm_bindgen(start)]
96pub fn main() {
97    console_error_panic_hook::set_once();
98}