WebAssembly: auto-download and build Typst packages

This is a very specific question. I’m currently working on a Typst PowerPoint Addin-in here. PowerPoint Add-ins are basically web sites run in an Edge browser sandbox and can interact with PowerPoint through a JavaScript API.

Currently, Typst is compiled to WebAssembly via wasm-bindgen. The WebAssembly is called from JS to produce SVGs that are inserted into the PowerPoint slide. This works fine thanks to the great proof of concept by Johannes here.

Now, I’d like to also support Typst Universe packages. I was wondering how Typst itself automatically downloads these packages whenever a user writes an import statement. Can anybody give me some pointers about where to find this in the code?

Furthermore, I don’t quite see how I could then automatically compile those packages to WebAssembly on the fly. In the end, I don’t want to host any backend for the Add-in. At most a static site via GitHub Pages. To my understanding, this means that I would need the Rust toolchain itself as WebAssembly to then bundle a downloaded Typst package on-the-fly. Inception ;) But wait, Typst packages are itself written in Typst, not Rust. So how would I even convert those to WebAssembly?

Thanks for your help. I’m grateful even just for pointers in the right direction. See also this issue.

I’d probably have to rewrite this part of the code in JS I guess.

Do you think this functionality could be packaged as a WebAssembly component ? With an appropriate WIT definition ?

thanks, yeah maybe… Meanwhile, I’ve switched from the custom engine to the awesome typst.ts project by Myriad Dreamin. On that repo, I have opened an issue for my question here.