use docx_core; use wasm_bindgen::prelude::*; #[wasm_bindgen] #[derive(Debug)] pub struct Docx(docx_core::Docx); #[wasm_bindgen(js_name = createDocx)] pub fn create_docx() -> Docx { Docx(docx_core::Docx::new()) } #[wasm_bindgen] impl Docx { pub fn add_paragraph(mut self, p: Paragraph) -> Self { self.0 = self.0.add_paragraph(p.0); self } pub fn build(&mut self) -> Result, JsValue> { let buf = Vec::new(); let mut cur = std::io::Cursor::new(buf); let res = self.0.build().pack(&mut cur); if res.is_err() { return Err(format!("{:?}", res).into()); } Ok(cur.into_inner()) } } #[wasm_bindgen] #[derive(Debug)] pub struct Paragraph(docx_core::Paragraph); #[wasm_bindgen(js_name = createParagraph)] pub fn create_paragraph() -> Paragraph { Paragraph(docx_core::Paragraph::new()) } #[wasm_bindgen] impl Paragraph { pub fn add_run(mut self, run: Run) -> Self { self.0 = self.0.add_run(run.0); self } } #[wasm_bindgen] #[derive(Debug)] pub struct Run(docx_core::Run); #[wasm_bindgen(js_name = createRun)] pub fn create_run() -> Run { Run(docx_core::Run::new()) } #[wasm_bindgen] impl Run { pub fn add_text(mut self, text: &str) -> Self { self.0 = self.0.add_text(text); self } }