use std::future::Future;
use wasm_bindgen::JsCast;
use web_sys::*;
use crate::js::plugin::JsPerspectiveViewerPlugin;
use crate::utils::ApiResult;
pub async fn activate_plugin<T>(
viewer: &HtmlElement,
plugin: &JsPerspectiveViewerPlugin,
task: impl Future<Output = ApiResult<T>>,
) -> ApiResult<T> {
let html_plugin = plugin.unchecked_ref::<HtmlElement>();
if html_plugin.parent_node().is_none() {
html_plugin.style().set_property("opacity", "0")?;
viewer.append_child(html_plugin)?;
}
let result = task.await;
let first_child = viewer.children().item(0).unwrap();
if first_child != *plugin.unchecked_ref::<Element>() {
viewer.remove_child(&first_child)?;
}
html_plugin.style().set_property("opacity", "1")?;
result
}