// Prevents reinitialization of compiler and renderer options during HMR (Hot Module Replacement). // Use prepareUseOnce flag ensures initialization occurs only once to avoid duplicate calls to setXXXInitOptions. // From https://github.com/Myriad-Dreamin/typst.ts/blob/main/packages/typst.svelte/src/lib/set-init-options-typst.ts import { $typst, loadFonts } from '@myriaddreamin/typst.ts' let inited = false const rendererWasmUrl = 'https://cdn.jsdelivr.net/npm/@myriaddreamin/typst-ts-renderer@v0.8.0-rc3/pkg/typst_ts_renderer_bg.wasm' const compilerWasmUrl = 'https://cdn.jsdelivr.net/npm/@myriaddreamin/typst-ts-web-compiler@v0.8.0-rc3/pkg/typst_ts_web_compiler_bg.wasm' export default async () => { if (!inited) { const font = await import('$lib/assets/GoogleSansFlex/GoogleSansFlex-VariableFont.ttf?url').then(font => font.default) const fonts = loadFonts([font]) $typst.setCompilerInitOptions({ getModule: () => compilerWasmUrl, beforeBuild: [ fonts, ], }) $typst.setRendererInitOptions({ getModule: () => rendererWasmUrl, beforeBuild: [ fonts, ], }) inited = true } return $typst }