File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import createModule , { type QpdfInstance } from '@neslinesli93/qpdf-wasm' ;
2+ import wasmUrl from '@neslinesli93/qpdf-wasm/dist/qpdf.wasm?url' ;
3+
4+ let qpdfPromise : Promise < QpdfInstance > | null = null ;
5+
6+ export function getQpdf ( ) : Promise < QpdfInstance > {
7+ if ( ! qpdfPromise ) {
8+ qpdfPromise = createModule ( {
9+ locateFile : ( ) => wasmUrl ,
10+ // @ts -expect-error missing from types
11+ noInitialRun : true ,
12+ preRun : [
13+ ( module : QpdfInstance ) => {
14+ if ( module . FS ) {
15+ try {
16+ module . FS . mkdir ( '/input' ) ;
17+ module . FS . mkdir ( '/output' ) ;
18+ } catch ( e ) {
19+ console . warn ( 'Error creating directories:' , e ) ;
20+ }
21+ }
22+ }
23+ ]
24+ } ) ;
25+ }
26+ return qpdfPromise ;
27+ }
28+
29+ export type { QpdfInstance } ;
Original file line number Diff line number Diff line change 55 faCircleExclamation ,
66 faTriangleExclamation
77 } from ' @fortawesome/free-solid-svg-icons' ;
8- import createModule , { type QpdfInstance } from ' @neslinesli93/qpdf-wasm' ;
9- import wasmUrl from ' @neslinesli93 /qpdf-wasm/dist/qpdf.wasm?url ' ;
8+ import { type QpdfInstance } from ' @neslinesli93/qpdf-wasm' ;
9+ import { getQpdf } from ' $lib /qpdf' ;
1010
1111 import { onMount } from ' svelte' ;
1212 import { fileListFromFileArray , convertFileHandlesToFileList , download } from ' $lib/file-utils' ;
2121 onMount (async () => {
2222 // Initialize QPDF WASM module
2323 try {
24- qpdf = await createModule ({
25- locateFile : () => wasmUrl ,
26- // @ts-expect-error missing from types
27- noInitialRun: true ,
28- preRun: [
29- (module : QpdfInstance ) => {
30- if (module .FS ) {
31- try {
32- module .FS .mkdir (' /input' );
33- module .FS .mkdir (' /output' );
34- } catch (e ) {
35- console .warn (' Error creating directories:' , e );
36- }
37- }
38- }
39- ]
40- });
24+ qpdf = await getQpdf ();
4125 console .log (' QPDF WASM module initialized successfully' );
4226 } catch (error ) {
4327 console .error (' Failed to initialize QPDF WASM module:' , error );
Original file line number Diff line number Diff line change 11<script lang =" ts" >
22 import { FontAwesomeIcon } from ' @fortawesome/svelte-fontawesome' ;
33 import { faInfoCircle } from ' @fortawesome/free-solid-svg-icons' ;
4- import createModule , { type QpdfInstance } from ' @neslinesli93/qpdf-wasm' ;
5- import wasmUrl from ' @neslinesli93 /qpdf-wasm/dist/qpdf.wasm?url ' ;
4+ import { type QpdfInstance } from ' @neslinesli93/qpdf-wasm' ;
5+ import { getQpdf } from ' $lib /qpdf' ;
66
77 import { onMount } from ' svelte' ;
88 import { fileListFromFileArray , convertFileHandlesToFileList , download } from ' $lib/file-utils' ;
1515 onMount (async () => {
1616 // Initialize QPDF WASM module
1717 try {
18- qpdf = await createModule ({
19- locateFile : () => wasmUrl ,
20- // @ts-expect-error missing from types
21- noInitialRun: true ,
22- preRun: [
23- (module : QpdfInstance ) => {
24- if (module .FS ) {
25- try {
26- module .FS .mkdir (' /input' );
27- module .FS .mkdir (' /output' );
28- } catch (e ) {
29- console .warn (' Error creating directories:' , e );
30- }
31- }
32- }
33- ]
34- });
18+ qpdf = await getQpdf ();
3519 console .log (' QPDF WASM module initialized successfully' );
3620 } catch (error ) {
3721 console .error (' Failed to initialize QPDF WASM module:' , error );
You can’t perform that action at this time.
0 commit comments