leptos_helios_wasm_core/
lib.rs1use serde::{Deserialize, Serialize};
7use thiserror::Error;
8use wasm_bindgen::prelude::*;
9
10#[wasm_bindgen]
12pub async fn init_helios() -> Result<(), JsValue> {
13 console_error_panic_hook::set_once();
14 Ok(())
15}
16
17#[wasm_bindgen]
19pub fn get_version() -> String {
20 env!("CARGO_PKG_VERSION").to_string()
21}
22
23#[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#[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#[wasm_bindgen]
55pub struct WasmWebGpuDevice {
56 _private: (),
58}
59
60#[wasm_bindgen]
61impl WasmWebGpuDevice {
62 #[wasm_bindgen]
64 pub async fn new() -> Result<WasmWebGpuDevice, JsValue> {
65 Ok(WasmWebGpuDevice { _private: () })
67 }
68
69 #[wasm_bindgen]
71 pub fn is_available() -> bool {
72 true
74 }
75}
76
77#[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#[wasm_bindgen(start)]
96pub fn main() {
97 console_error_panic_hook::set_once();
98}