@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.cjs CHANGED
@@ -735,7 +735,7 @@ function createViewer(options) {
735
735
  if (destroyed || token !== renderToken) {
736
736
  return;
737
737
  }
738
- currentInstance?.destroy();
738
+ destroyPreviewInstance(currentInstance);
739
739
  currentInstance = void 0;
740
740
  viewport.replaceChildren();
741
741
  setLoading(true);
@@ -757,7 +757,7 @@ function createViewer(options) {
757
757
  setError
758
758
  });
759
759
  if (destroyed || token !== renderToken) {
760
- nextInstance.destroy();
760
+ destroyPreviewInstance(nextInstance);
761
761
  return;
762
762
  }
763
763
  currentInstance = nextInstance;
@@ -814,7 +814,7 @@ function createViewer(options) {
814
814
  destroyed = true;
815
815
  renderToken += 1;
816
816
  resizeObserver.destroy();
817
- currentInstance?.destroy();
817
+ destroyPreviewInstance(currentInstance);
818
818
  toolbar?.destroy();
819
819
  theme.destroy();
820
820
  container.replaceChildren();
@@ -825,6 +825,16 @@ function createViewer(options) {
825
825
  }
826
826
  };
827
827
  }
828
+ function destroyPreviewInstance(instance) {
829
+ if (!instance) {
830
+ return;
831
+ }
832
+ try {
833
+ instance.destroy();
834
+ } catch (error) {
835
+ console.error("Failed to destroy file preview instance:", error);
836
+ }
837
+ }
828
838
  function normalizeQueue(options) {
829
839
  if (options.files && options.files.length > 0) {
830
840
  return options.files.map(
@@ -4628,7 +4638,7 @@ async function renderPdfDocumentPreview(options) {
4628
4638
  },
4629
4639
  destroy() {
4630
4640
  options.viewport.classList.remove("ofv-center");
4631
- documentTask?.destroy?.();
4641
+ destroyPdfResource(documentTask);
4632
4642
  if (options.revokeUrlOnDestroy) {
4633
4643
  revokeObjectUrl(options.fileUrl, Boolean(options.isExternal));
4634
4644
  }
@@ -4861,13 +4871,27 @@ async function renderPdfDocumentPreview(options) {
4861
4871
  }
4862
4872
  });
4863
4873
  pageStates.length = 0;
4864
- void pdfDocument.destroy?.();
4874
+ destroyPdfResource(pdfDocument);
4875
+ destroyPdfResource(documentTask);
4865
4876
  if (options.revokeUrlOnDestroy) {
4866
4877
  revokeObjectUrl(options.fileUrl, Boolean(options.isExternal));
4867
4878
  }
4868
4879
  }
4869
4880
  };
4870
4881
  }
4882
+ function destroyPdfResource(resource) {
4883
+ if (!resource || typeof resource !== "object") {
4884
+ return;
4885
+ }
4886
+ const candidate = resource;
4887
+ if (typeof candidate.destroy === "function") {
4888
+ void candidate.destroy();
4889
+ return;
4890
+ }
4891
+ if (typeof candidate.cleanup === "function") {
4892
+ void candidate.cleanup();
4893
+ }
4894
+ }
4871
4895
  function getPdfOutputScale() {
4872
4896
  if (typeof window === "undefined") {
4873
4897
  return 1;