1#[cfg(target_arch = "wasm32")]
2use wasm_bindgen::prelude::*;
3#[cfg(target_arch = "wasm32")]
4use wasm_bindgen::JsValue;
5
6pub mod errors;
7pub mod imagesize;
8mod template;
9pub mod utils;
10
11pub use errors::DocxError;
12
13#[cfg(target_arch = "wasm32")]
15#[wasm_bindgen]
16pub fn render_template(
17 zip_bytes: Vec<u8>,
18 data_json: &str,
19) -> Result<JsValue, JsValue> {
20 let data: serde_json::Value = serde_json::from_str(data_json)
21 .map_err(|e| JsValue::from_str(&format!("JSON Parse Error: {e}")))?;
22
23 let result = template::render_template(zip_bytes, &data)
25 .map_err(|e| JsValue::from_str(&e.to_string()))?;
26
27 Ok(JsValue::from(result))
29}
30
31#[cfg(not(target_arch = "wasm32"))]
33pub use template::render_template;