use js_sys::{wasm_bindgen, Array, JsString};
use wasm_bindgen::prelude::*;
use web_sys::{Blob, BlobPropertyBag, Url};
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen]
type ImportMeta;
#[wasm_bindgen(method, getter)]
fn url(this: &ImportMeta) -> JsString;
#[wasm_bindgen(thread_local_v2, js_namespace = import, js_name = meta)]
static IMPORT_META: ImportMeta;
}
pub fn on_the_fly(code: &str) -> Result<String, JsValue> {
let header = format!(
"import init, * as bindgen from '{}';\n\n",
IMPORT_META.with(ImportMeta::url),
);
let options = BlobPropertyBag::new();
options.set_type("text/javascript");
Url::create_object_url_with_blob(&Blob::new_with_str_sequence_and_options(
&Array::of2(&JsValue::from(header.as_str()), &JsValue::from(code)),
&options,
)?)
}
#[macro_export]
macro_rules! dependent_module {
($file_name:expr) => {
$crate::host::audioworklet::dependent_module::on_the_fly(include_str!($file_name))
};
}