fix: stabilize web loading and paper rendering
This commit is contained in:
parent
fe49cc8eb5
commit
bca65600cd
25 changed files with 109 additions and 62 deletions
|
|
@ -10,6 +10,7 @@ crate-type = ["cdylib"]
|
|||
[dependencies]
|
||||
acadrust = { version = "0.4", features = ["serde"] }
|
||||
bincode = "1.3"
|
||||
console_error_panic_hook = "0.1"
|
||||
getrandom = { version = "0.3", features = ["wasm_js"] }
|
||||
js-sys = "0.3"
|
||||
wasm-bindgen = "0.2"
|
||||
|
|
|
|||
|
|
@ -2,15 +2,22 @@ use std::io::Cursor;
|
|||
|
||||
use acadrust::io::dwg::DwgReader;
|
||||
use acadrust::DxfReader;
|
||||
use js_sys::Uint8Array;
|
||||
use js_sys::{Function, Uint8Array};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
/// Parse DWG/DXF on a dedicated browser worker and return a compact serialized
|
||||
/// document. The main wasm instance only deserializes and installs it, so the
|
||||
/// expensive bit/handle/object decode never occupies the browser UI thread.
|
||||
#[wasm_bindgen]
|
||||
pub fn parse_document(name: String, bytes: Uint8Array) -> Result<Uint8Array, JsValue> {
|
||||
pub fn parse_document(
|
||||
name: String,
|
||||
bytes: Uint8Array,
|
||||
report_stage: &Function,
|
||||
) -> Result<Uint8Array, JsValue> {
|
||||
console_error_panic_hook::set_once();
|
||||
report_stage.call1(&JsValue::NULL, &JsValue::from_str("copy input"))?;
|
||||
let bytes = bytes.to_vec();
|
||||
report_stage.call1(&JsValue::NULL, &JsValue::from_str("parse document"))?;
|
||||
let ext = name.rsplit('.').next().unwrap_or_default().to_lowercase();
|
||||
let document = match ext.as_str() {
|
||||
"dwg" => DwgReader::from_stream(Cursor::new(bytes))
|
||||
|
|
@ -26,7 +33,9 @@ pub fn parse_document(name: String, bytes: Uint8Array) -> Result<Uint8Array, JsV
|
|||
)))
|
||||
}
|
||||
};
|
||||
report_stage.call1(&JsValue::NULL, &JsValue::from_str("serialize document"))?;
|
||||
let encoded =
|
||||
bincode::serialize(&document).map_err(|error| JsValue::from_str(&error.to_string()))?;
|
||||
report_stage.call1(&JsValue::NULL, &JsValue::from_str("copy output"))?;
|
||||
Ok(Uint8Array::from(encoded.as_slice()))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue