Skip to content

Commit

Permalink
feat: add Symbol.dispose method
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Nov 8, 2024
1 parent ddeb270 commit b9d157f
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 588 deletions.
456 changes: 0 additions & 456 deletions Cargo.lock

This file was deleted.

14 changes: 0 additions & 14 deletions Cargo.toml

This file was deleted.

19 changes: 0 additions & 19 deletions crates/pdf-viewer/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion crates/pdf-viewer/README.md

This file was deleted.

46 changes: 0 additions & 46 deletions crates/pdf-viewer/src/document.rs

This file was deleted.

5 changes: 0 additions & 5 deletions crates/pdf-viewer/src/lib.rs

This file was deleted.

47 changes: 0 additions & 47 deletions crates/pdf-viewer/src/viewer.rs

This file was deleted.

4 changes: 4 additions & 0 deletions packages/pdf-viewer/src/bitmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ export class Bitmap {
this.runtime.free(bufferPtr);
return buffer;
}

[Symbol.dispose]() {
this.close();
}
}
4 changes: 4 additions & 0 deletions packages/pdf-viewer/src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,8 @@ export class Document {

return new Page(this, at, pagePtr);
}

[Symbol.dispose]() {
this.close();
}
}
4 changes: 4 additions & 0 deletions packages/pdf-viewer/src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,8 @@ export class Page {

return [deviceX, deviceY];
}

[Symbol.dispose]() {
this.close();
}
}
1 change: 1 addition & 0 deletions packages/pdf-viewer/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class Runtime {
* Initialize the PDFium library and allocate global resources for it.
*/
init = this.wasm.FPDF_InitLibraryWithConfig;
deinit = this.wasm.FPDF_DestroyLibrary;

/**
* Gets last error code when a function fails.
Expand Down
4 changes: 4 additions & 0 deletions packages/pdf-viewer/src/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ export class Viewer {
);
return new Bitmap(this.runtime, ptr, format);
}

[Symbol.dispose]() {
this.runtime.deinit();
}
}
1 change: 1 addition & 0 deletions packages/pdfium/dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface FPDF_Config {
*/
export interface FPDF_Bindings {
FPDF_InitLibraryWithConfig(config: FPDF_Config): void;
FPDF_DestroyLibrary(): void;

FPDF_GetLastError<T extends number>(): T;

Expand Down

0 comments on commit b9d157f

Please sign in to comment.