use rust_pptx::{detect_format, parse_presentation as parse_core_presentation, ParseLimits};
use serde::Serialize;
use serde_wasm_bindgen::Serializer;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn detect_presentation_format(bytes: &[u8]) -> Result<String, JsValue> {
detect_format(bytes)
.map(|format| {
match format {
rust_pptx::PresentationFormat::Pptx => "pptx",
rust_pptx::PresentationFormat::Ppt => "ppt",
}
.into()
})
.map_err(|error| JsValue::from_str(&error.to_string()))
}
#[wasm_bindgen]
pub fn parse_presentation(bytes: &[u8]) -> Result<JsValue, JsValue> {
let document = parse_core_presentation(bytes, &ParseLimits::default())
.map_err(|error| JsValue::from_str(&error.to_string()))?;
document
.serialize(&Serializer::new().serialize_maps_as_objects(true))
.map_err(|error| JsValue::from_str(&error.to_string()))
}