@open-file-viewer/core 0.1.12 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -682,7 +682,7 @@ function createViewer(options) {
682
682
  if (destroyed || token !== renderToken) {
683
683
  return;
684
684
  }
685
- currentInstance?.destroy();
685
+ destroyPreviewInstance(currentInstance);
686
686
  currentInstance = void 0;
687
687
  viewport.replaceChildren();
688
688
  setLoading(true);
@@ -704,7 +704,7 @@ function createViewer(options) {
704
704
  setError
705
705
  });
706
706
  if (destroyed || token !== renderToken) {
707
- nextInstance.destroy();
707
+ destroyPreviewInstance(nextInstance);
708
708
  return;
709
709
  }
710
710
  currentInstance = nextInstance;
@@ -761,7 +761,7 @@ function createViewer(options) {
761
761
  destroyed = true;
762
762
  renderToken += 1;
763
763
  resizeObserver.destroy();
764
- currentInstance?.destroy();
764
+ destroyPreviewInstance(currentInstance);
765
765
  toolbar?.destroy();
766
766
  theme.destroy();
767
767
  container.replaceChildren();
@@ -772,6 +772,16 @@ function createViewer(options) {
772
772
  }
773
773
  };
774
774
  }
775
+ function destroyPreviewInstance(instance) {
776
+ if (!instance) {
777
+ return;
778
+ }
779
+ try {
780
+ instance.destroy();
781
+ } catch (error) {
782
+ console.error("Failed to destroy file preview instance:", error);
783
+ }
784
+ }
775
785
  function normalizeQueue(options) {
776
786
  if (options.files && options.files.length > 0) {
777
787
  return options.files.map(
@@ -4575,7 +4585,7 @@ async function renderPdfDocumentPreview(options) {
4575
4585
  },
4576
4586
  destroy() {
4577
4587
  options.viewport.classList.remove("ofv-center");
4578
- documentTask?.destroy?.();
4588
+ destroyPdfResource(documentTask);
4579
4589
  if (options.revokeUrlOnDestroy) {
4580
4590
  revokeObjectUrl(options.fileUrl, Boolean(options.isExternal));
4581
4591
  }
@@ -4808,13 +4818,27 @@ async function renderPdfDocumentPreview(options) {
4808
4818
  }
4809
4819
  });
4810
4820
  pageStates.length = 0;
4811
- void pdfDocument.destroy?.();
4821
+ destroyPdfResource(pdfDocument);
4822
+ destroyPdfResource(documentTask);
4812
4823
  if (options.revokeUrlOnDestroy) {
4813
4824
  revokeObjectUrl(options.fileUrl, Boolean(options.isExternal));
4814
4825
  }
4815
4826
  }
4816
4827
  };
4817
4828
  }
4829
+ function destroyPdfResource(resource) {
4830
+ if (!resource || typeof resource !== "object") {
4831
+ return;
4832
+ }
4833
+ const candidate = resource;
4834
+ if (typeof candidate.destroy === "function") {
4835
+ void candidate.destroy();
4836
+ return;
4837
+ }
4838
+ if (typeof candidate.cleanup === "function") {
4839
+ void candidate.cleanup();
4840
+ }
4841
+ }
4818
4842
  function getPdfOutputScale() {
4819
4843
  if (typeof window === "undefined") {
4820
4844
  return 1;