pdfjs-reader-core 0.1.3 → 0.1.4
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 +52 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +52 -32
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -327,7 +327,7 @@ interface ViewerState {
|
|
|
327
327
|
isPresentationMode: boolean;
|
|
328
328
|
}
|
|
329
329
|
interface ViewerActions {
|
|
330
|
-
setDocument: (doc: PDFDocumentProxy) => void;
|
|
330
|
+
setDocument: (doc: PDFDocumentProxy | null) => void;
|
|
331
331
|
setLoading: (loading: boolean) => void;
|
|
332
332
|
setError: (error: Error | null) => void;
|
|
333
333
|
setCurrentPage: (page: number) => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -327,7 +327,7 @@ interface ViewerState {
|
|
|
327
327
|
isPresentationMode: boolean;
|
|
328
328
|
}
|
|
329
329
|
interface ViewerActions {
|
|
330
|
-
setDocument: (doc: PDFDocumentProxy) => void;
|
|
330
|
+
setDocument: (doc: PDFDocumentProxy | null) => void;
|
|
331
331
|
setLoading: (loading: boolean) => void;
|
|
332
332
|
setError: (error: Error | null) => void;
|
|
333
333
|
setCurrentPage: (page: number) => void;
|
package/dist/index.js
CHANGED
|
@@ -316,13 +316,21 @@ function createViewerStore(initialOverrides = {}) {
|
|
|
316
316
|
...initialOverrides,
|
|
317
317
|
// Document actions
|
|
318
318
|
setDocument: (document2) => {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
319
|
+
if (document2) {
|
|
320
|
+
set({
|
|
321
|
+
document: document2,
|
|
322
|
+
numPages: document2.numPages,
|
|
323
|
+
isLoading: false,
|
|
324
|
+
error: null,
|
|
325
|
+
currentPage: 1
|
|
326
|
+
});
|
|
327
|
+
} else {
|
|
328
|
+
set({
|
|
329
|
+
document: null,
|
|
330
|
+
numPages: 0,
|
|
331
|
+
isLoading: false
|
|
332
|
+
});
|
|
333
|
+
}
|
|
326
334
|
},
|
|
327
335
|
setLoading: (isLoading) => {
|
|
328
336
|
set({ isLoading });
|
|
@@ -8742,6 +8750,17 @@ __export(PDFViewerClient_exports, {
|
|
|
8742
8750
|
});
|
|
8743
8751
|
import { useEffect as useEffect22, useCallback as useCallback32, memo as memo24, useRef as useRef19, useState as useState21 } from "react";
|
|
8744
8752
|
import { jsx as jsx25, jsxs as jsxs21 } from "react/jsx-runtime";
|
|
8753
|
+
function getSrcIdentifier(src) {
|
|
8754
|
+
if (typeof src === "string") {
|
|
8755
|
+
return src;
|
|
8756
|
+
}
|
|
8757
|
+
const data = src instanceof ArrayBuffer ? new Uint8Array(src) : src;
|
|
8758
|
+
const len = data.byteLength;
|
|
8759
|
+
if (len === 0) return "empty";
|
|
8760
|
+
const first = Array.from(data.slice(0, 4)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
8761
|
+
const last = Array.from(data.slice(-4)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
8762
|
+
return `binary:${len}:${first}:${last}`;
|
|
8763
|
+
}
|
|
8745
8764
|
var PDFViewerInner, PDFViewerClient;
|
|
8746
8765
|
var init_PDFViewerClient = __esm({
|
|
8747
8766
|
"src/components/PDFViewer/PDFViewerClient.tsx"() {
|
|
@@ -8771,8 +8790,8 @@ var init_PDFViewerClient = __esm({
|
|
|
8771
8790
|
className
|
|
8772
8791
|
}) {
|
|
8773
8792
|
const { viewerStore } = usePDFViewerStores();
|
|
8774
|
-
const
|
|
8775
|
-
const
|
|
8793
|
+
const mountedRef = useRef19(true);
|
|
8794
|
+
const [, setLoadState] = useState21("idle");
|
|
8776
8795
|
const onDocumentLoadRef = useRef19(onDocumentLoad);
|
|
8777
8796
|
const onErrorRef = useRef19(onError);
|
|
8778
8797
|
const onPageChangeRef = useRef19(onPageChange);
|
|
@@ -8781,42 +8800,49 @@ var init_PDFViewerClient = __esm({
|
|
|
8781
8800
|
onErrorRef.current = onError;
|
|
8782
8801
|
onPageChangeRef.current = onPageChange;
|
|
8783
8802
|
onScaleChangeRef.current = onScaleChange;
|
|
8803
|
+
const srcIdRef = useRef19(null);
|
|
8784
8804
|
const currentPage = useViewerStore((s) => s.currentPage);
|
|
8785
8805
|
const scale = useViewerStore((s) => s.scale);
|
|
8786
8806
|
const theme = useViewerStore((s) => s.theme);
|
|
8787
8807
|
const isLoading = useViewerStore((s) => s.isLoading);
|
|
8788
8808
|
const error = useViewerStore((s) => s.error);
|
|
8789
8809
|
const sidebarOpen = useViewerStore((s) => s.sidebarOpen);
|
|
8790
|
-
const
|
|
8810
|
+
const srcId = getSrcIdentifier(src);
|
|
8791
8811
|
const handleRetry = useCallback32(() => {
|
|
8792
|
-
|
|
8793
|
-
srcRef.current = null;
|
|
8812
|
+
srcIdRef.current = null;
|
|
8794
8813
|
viewerStore.getState().setError(null);
|
|
8795
|
-
|
|
8796
|
-
}, [viewerStore
|
|
8814
|
+
setLoadState("idle");
|
|
8815
|
+
}, [viewerStore]);
|
|
8797
8816
|
useEffect22(() => {
|
|
8798
|
-
|
|
8799
|
-
|
|
8800
|
-
|
|
8801
|
-
|
|
8817
|
+
mountedRef.current = true;
|
|
8818
|
+
return () => {
|
|
8819
|
+
mountedRef.current = false;
|
|
8820
|
+
};
|
|
8821
|
+
}, []);
|
|
8822
|
+
useEffect22(() => {
|
|
8823
|
+
if (srcIdRef.current === srcId && viewerStore.getState().document) {
|
|
8802
8824
|
return;
|
|
8803
8825
|
}
|
|
8804
|
-
|
|
8805
|
-
|
|
8826
|
+
const loadId = srcId;
|
|
8827
|
+
srcIdRef.current = srcId;
|
|
8806
8828
|
const currentDoc = viewerStore.getState().document;
|
|
8807
8829
|
if (currentDoc) {
|
|
8808
|
-
|
|
8830
|
+
currentDoc.destroy();
|
|
8831
|
+
viewerStore.getState().setDocument(null);
|
|
8809
8832
|
}
|
|
8810
8833
|
const loadDoc = async () => {
|
|
8834
|
+
if (!mountedRef.current) return;
|
|
8811
8835
|
try {
|
|
8812
8836
|
viewerStore.getState().setLoading(true);
|
|
8813
8837
|
viewerStore.getState().setError(null);
|
|
8838
|
+
setLoadState("loading");
|
|
8814
8839
|
const { document: document2, numPages } = await loadDocument({
|
|
8815
8840
|
src,
|
|
8816
8841
|
workerSrc
|
|
8817
8842
|
});
|
|
8818
|
-
if (
|
|
8843
|
+
if (mountedRef.current && srcIdRef.current === loadId) {
|
|
8819
8844
|
viewerStore.getState().setDocument(document2);
|
|
8845
|
+
setLoadState("loaded");
|
|
8820
8846
|
if (initialPage !== 1) {
|
|
8821
8847
|
viewerStore.getState().goToPage(initialPage);
|
|
8822
8848
|
}
|
|
@@ -8828,25 +8854,19 @@ var init_PDFViewerClient = __esm({
|
|
|
8828
8854
|
document2.destroy();
|
|
8829
8855
|
}
|
|
8830
8856
|
} catch (err) {
|
|
8831
|
-
if (
|
|
8857
|
+
if (mountedRef.current && srcIdRef.current === loadId) {
|
|
8832
8858
|
const error2 = err instanceof Error ? err : new Error("Failed to load document");
|
|
8833
8859
|
viewerStore.getState().setError(error2);
|
|
8860
|
+
viewerStore.getState().setLoading(false);
|
|
8861
|
+
setLoadState("error");
|
|
8834
8862
|
onErrorRef.current?.(error2);
|
|
8835
8863
|
}
|
|
8836
|
-
} finally {
|
|
8837
|
-
loadingRef.current = false;
|
|
8838
8864
|
}
|
|
8839
8865
|
};
|
|
8840
8866
|
loadDoc();
|
|
8841
8867
|
return () => {
|
|
8842
|
-
srcRef.current = null;
|
|
8843
|
-
};
|
|
8844
|
-
}, [src, workerSrc, initialPage, initialScale, viewerStore, retryTrigger]);
|
|
8845
|
-
useEffect22(() => {
|
|
8846
|
-
return () => {
|
|
8847
|
-
viewerStore.getState().reset();
|
|
8848
8868
|
};
|
|
8849
|
-
}, [viewerStore]);
|
|
8869
|
+
}, [srcId, src, workerSrc, initialPage, initialScale, viewerStore]);
|
|
8850
8870
|
const prevPageRef = useRef19(currentPage);
|
|
8851
8871
|
useEffect22(() => {
|
|
8852
8872
|
if (prevPageRef.current !== currentPage) {
|