pdfjs-reader-core 0.2.13 → 0.2.14

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
@@ -78,10 +78,13 @@ async function loadDocument(options) {
78
78
  const cachedDoc = documentCache.get(cacheKey);
79
79
  try {
80
80
  const numPages = cachedDoc.numPages;
81
- return {
82
- document: cachedDoc,
83
- numPages
84
- };
81
+ if (numPages > 0) {
82
+ await cachedDoc.getPage(1);
83
+ return {
84
+ document: cachedDoc,
85
+ numPages
86
+ };
87
+ }
85
88
  } catch {
86
89
  documentCache.delete(cacheKey);
87
90
  }
@@ -159,6 +162,20 @@ async function getOutline(document2) {
159
162
  async function getMetadata(document2) {
160
163
  return document2.getMetadata();
161
164
  }
165
+ function clearDocumentCache(url) {
166
+ if (url) {
167
+ const doc = documentCache.get(url);
168
+ if (doc) {
169
+ doc.destroy();
170
+ documentCache.delete(url);
171
+ }
172
+ } else {
173
+ for (const doc of documentCache.values()) {
174
+ doc.destroy();
175
+ }
176
+ documentCache.clear();
177
+ }
178
+ }
162
179
  var documentCache;
163
180
  var init_document_loader = __esm({
164
181
  "src/utils/document-loader.ts"() {
@@ -10139,6 +10156,7 @@ var init_PDFViewerClient = __esm({
10139
10156
  setLoadState("idle");
10140
10157
  }, [viewerStore]);
10141
10158
  const abortControllerRef = useRef19(null);
10159
+ const currentSrcRef = useRef19(null);
10142
10160
  useEffect22(() => {
10143
10161
  mountedRef.current = true;
10144
10162
  return () => {
@@ -10147,10 +10165,17 @@ var init_PDFViewerClient = __esm({
10147
10165
  abortControllerRef.current.abort();
10148
10166
  abortControllerRef.current = null;
10149
10167
  }
10168
+ if (currentSrcRef.current && typeof currentSrcRef.current === "string") {
10169
+ clearDocumentCache(currentSrcRef.current);
10170
+ }
10150
10171
  srcIdRef.current = null;
10172
+ currentSrcRef.current = null;
10151
10173
  const currentDoc = viewerStore.getState().document;
10152
10174
  if (currentDoc) {
10153
- currentDoc.destroy();
10175
+ try {
10176
+ currentDoc.destroy();
10177
+ } catch {
10178
+ }
10154
10179
  }
10155
10180
  viewerStore.getState().setDocument(null);
10156
10181
  viewerStore.getState().setLoading(false);
@@ -10163,6 +10188,7 @@ var init_PDFViewerClient = __esm({
10163
10188
  }
10164
10189
  const loadId = srcId;
10165
10190
  srcIdRef.current = srcId;
10191
+ currentSrcRef.current = src;
10166
10192
  if (abortControllerRef.current) {
10167
10193
  abortControllerRef.current.abort();
10168
10194
  }