Skip to content

Commit 1afb3ee

Browse files
fix: use wrapper script (#804)
1 parent 54bf90e commit 1afb3ee

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

packages/typst.ts/src/compiler.mts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,10 @@ export interface TypstCompiler {
445445
withIncrementalServer<T>(f: (s: IncrementalServer) => Promise<T>): Promise<T>;
446446
}
447447

448-
const gCompilerModule = new LazyWasmModule(async (bin?: any) => {
449-
const module = await import('@myriaddreamin/typst-ts-web-compiler');
450-
return await module.default(bin);
451-
});
448+
const gCompilerModule = (module: typeof typst) =>
449+
new LazyWasmModule(async (bin?: any) => {
450+
return await module.default(bin);
451+
});
452452

453453
/**
454454
* create a Typst compiler.
@@ -471,9 +471,9 @@ export class TypstFontBuilderDriver implements TypstFontBuilder {
471471
private fontBuilder: typst.TypstFontResolverBuilder;
472472

473473
async init(options?: Partial<InitOptions>): Promise<void> {
474-
this.fontBuilderJs = await import('@myriaddreamin/typst-ts-web-compiler');
474+
this.fontBuilderJs = await (options?.getWrapper?.() || import('@myriaddreamin/typst-ts-web-compiler'));
475475
/// init typst wasm module
476-
await gCompilerModule.init(options?.getModule?.());
476+
await gCompilerModule(this.fontBuilderJs).init(options?.getModule?.());
477477

478478
this.fontBuilder = new this.fontBuilderJs.TypstFontResolverBuilder();
479479
}
@@ -508,7 +508,7 @@ class TypstCompilerDriver implements TypstCompiler {
508508
constructor() { }
509509

510510
async init(options?: Partial<InitOptions>): Promise<void> {
511-
this.compilerJs = await import('@myriaddreamin/typst-ts-web-compiler');
511+
this.compilerJs = await (options?.getWrapper?.() || import('@myriaddreamin/typst-ts-web-compiler'));
512512
const TypstCompilerBuilder = this.compilerJs.TypstCompilerBuilder;
513513

514514
const compilerOptions = { ...(options || {}) };
@@ -533,7 +533,7 @@ class TypstCompilerDriver implements TypstCompiler {
533533
'TypstCompiler: no font loader found, please use font loaders, e.g. loadFonts or preloadSystemFonts',
534534
);
535535
}
536-
this.compiler = await buildComponent(options, gCompilerModule, TypstCompilerBuilder, {});
536+
this.compiler = await buildComponent(options, gCompilerModule(this.compilerJs), TypstCompilerBuilder, {});
537537
}
538538

539539
setFonts(fonts: TypstFontResolver): void {

0 commit comments

Comments
 (0)