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.cjs +31 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +31 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -101,10 +101,13 @@ async function loadDocument(options) {
|
|
|
101
101
|
const cachedDoc = documentCache.get(cacheKey);
|
|
102
102
|
try {
|
|
103
103
|
const numPages = cachedDoc.numPages;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
if (numPages > 0) {
|
|
105
|
+
await cachedDoc.getPage(1);
|
|
106
|
+
return {
|
|
107
|
+
document: cachedDoc,
|
|
108
|
+
numPages
|
|
109
|
+
};
|
|
110
|
+
}
|
|
108
111
|
} catch {
|
|
109
112
|
documentCache.delete(cacheKey);
|
|
110
113
|
}
|
|
@@ -182,6 +185,20 @@ async function getOutline(document2) {
|
|
|
182
185
|
async function getMetadata(document2) {
|
|
183
186
|
return document2.getMetadata();
|
|
184
187
|
}
|
|
188
|
+
function clearDocumentCache(url) {
|
|
189
|
+
if (url) {
|
|
190
|
+
const doc = documentCache.get(url);
|
|
191
|
+
if (doc) {
|
|
192
|
+
doc.destroy();
|
|
193
|
+
documentCache.delete(url);
|
|
194
|
+
}
|
|
195
|
+
} else {
|
|
196
|
+
for (const doc of documentCache.values()) {
|
|
197
|
+
doc.destroy();
|
|
198
|
+
}
|
|
199
|
+
documentCache.clear();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
185
202
|
var documentCache;
|
|
186
203
|
var init_document_loader = __esm({
|
|
187
204
|
"src/utils/document-loader.ts"() {
|
|
@@ -10169,6 +10186,7 @@ var init_PDFViewerClient = __esm({
|
|
|
10169
10186
|
setLoadState("idle");
|
|
10170
10187
|
}, [viewerStore]);
|
|
10171
10188
|
const abortControllerRef = (0, import_react41.useRef)(null);
|
|
10189
|
+
const currentSrcRef = (0, import_react41.useRef)(null);
|
|
10172
10190
|
(0, import_react41.useEffect)(() => {
|
|
10173
10191
|
mountedRef.current = true;
|
|
10174
10192
|
return () => {
|
|
@@ -10177,10 +10195,17 @@ var init_PDFViewerClient = __esm({
|
|
|
10177
10195
|
abortControllerRef.current.abort();
|
|
10178
10196
|
abortControllerRef.current = null;
|
|
10179
10197
|
}
|
|
10198
|
+
if (currentSrcRef.current && typeof currentSrcRef.current === "string") {
|
|
10199
|
+
clearDocumentCache(currentSrcRef.current);
|
|
10200
|
+
}
|
|
10180
10201
|
srcIdRef.current = null;
|
|
10202
|
+
currentSrcRef.current = null;
|
|
10181
10203
|
const currentDoc = viewerStore.getState().document;
|
|
10182
10204
|
if (currentDoc) {
|
|
10183
|
-
|
|
10205
|
+
try {
|
|
10206
|
+
currentDoc.destroy();
|
|
10207
|
+
} catch {
|
|
10208
|
+
}
|
|
10184
10209
|
}
|
|
10185
10210
|
viewerStore.getState().setDocument(null);
|
|
10186
10211
|
viewerStore.getState().setLoading(false);
|
|
@@ -10193,6 +10218,7 @@ var init_PDFViewerClient = __esm({
|
|
|
10193
10218
|
}
|
|
10194
10219
|
const loadId = srcId;
|
|
10195
10220
|
srcIdRef.current = srcId;
|
|
10221
|
+
currentSrcRef.current = src;
|
|
10196
10222
|
if (abortControllerRef.current) {
|
|
10197
10223
|
abortControllerRef.current.abort();
|
|
10198
10224
|
}
|