@anaralabs/lector 3.10.5 → 3.11.1
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/_tsup-dts-rollup.d.ts +18 -2
- package/dist/index.js +29 -2
- package/package.json +1 -1
|
@@ -354,7 +354,7 @@ export declare type PDFVirtualizer = Virtualizer<any, any>;
|
|
|
354
354
|
|
|
355
355
|
export declare const PreviousPage: () => void;
|
|
356
356
|
|
|
357
|
-
export declare const Root: ForwardRefExoticComponent<Omit<HTMLProps<HTMLDivElement> & usePDFDocumentParams & {
|
|
357
|
+
export declare const Root: ForwardRefExoticComponent<Omit<Omit<HTMLProps<HTMLDivElement>, "onError"> & usePDFDocumentParams & {
|
|
358
358
|
loader?: ReactNode;
|
|
359
359
|
}, "ref"> & RefAttributes<unknown>>;
|
|
360
360
|
|
|
@@ -452,7 +452,7 @@ declare const usePdf: <T>(selector: (state: PDFState) => T) => T;
|
|
|
452
452
|
export { usePdf }
|
|
453
453
|
export { usePdf as usePdf_alias_1 }
|
|
454
454
|
|
|
455
|
-
export declare const usePDFDocumentContext: ({ onDocumentLoad, source, initialRotation, isZoomFitWidth, zoom, zoomOptions, documentOptions, }: usePDFDocumentParams) => {
|
|
455
|
+
export declare const usePDFDocumentContext: ({ onDocumentLoad, onError, source, initialRotation, isZoomFitWidth, zoom, zoomOptions, documentOptions, }: usePDFDocumentParams) => {
|
|
456
456
|
initialState: InitialPDFState | null | undefined;
|
|
457
457
|
};
|
|
458
458
|
|
|
@@ -465,6 +465,22 @@ export declare interface usePDFDocumentParams {
|
|
|
465
465
|
proxy: PDFDocumentProxy;
|
|
466
466
|
source: Source;
|
|
467
467
|
}) => void;
|
|
468
|
+
/**
|
|
469
|
+
* Called when the document fails to load. Three failure modes:
|
|
470
|
+
* - `phase: "pdfjs-load"` — the PDF.js worker / runtime itself failed to load.
|
|
471
|
+
* - `phase: "document-load"` — `getDocument()` rejected (network error,
|
|
472
|
+
* parse error, password required, etc). `onDocumentLoad` has NOT fired.
|
|
473
|
+
* - `phase: "viewport-generation"` — the document loaded successfully and
|
|
474
|
+
* `onDocumentLoad` already fired, but resolving page proxies / viewports
|
|
475
|
+
* afterwards failed (e.g. corrupted page, transient pdf.js error).
|
|
476
|
+
* The callback fires in addition to the existing console.error, so existing
|
|
477
|
+
* consumers see no behavior change.
|
|
478
|
+
*/
|
|
479
|
+
onError?: ({ error, phase, source, }: {
|
|
480
|
+
error: unknown;
|
|
481
|
+
phase: "pdfjs-load" | "document-load" | "viewport-generation";
|
|
482
|
+
source: Source;
|
|
483
|
+
}) => void;
|
|
468
484
|
initialRotation?: number;
|
|
469
485
|
isZoomFitWidth?: boolean;
|
|
470
486
|
zoom?: number;
|
package/dist/index.js
CHANGED
|
@@ -5388,6 +5388,7 @@ function buildDocumentInitParams(source, pdfJsVersion, overrides) {
|
|
|
5388
5388
|
}
|
|
5389
5389
|
var usePDFDocumentContext = ({
|
|
5390
5390
|
onDocumentLoad,
|
|
5391
|
+
onError,
|
|
5391
5392
|
source,
|
|
5392
5393
|
initialRotation = 0,
|
|
5393
5394
|
isZoomFitWidth,
|
|
@@ -5400,6 +5401,8 @@ var usePDFDocumentContext = ({
|
|
|
5400
5401
|
const [rotation] = useState(initialRotation);
|
|
5401
5402
|
const documentOptionsRef = useRef(documentOptions);
|
|
5402
5403
|
documentOptionsRef.current = documentOptions;
|
|
5404
|
+
const onErrorRef = useRef(onError);
|
|
5405
|
+
onErrorRef.current = onError;
|
|
5403
5406
|
useEffect(() => {
|
|
5404
5407
|
const generateViewports = async (pdf) => {
|
|
5405
5408
|
const pageProxies = [];
|
|
@@ -5452,24 +5455,46 @@ var usePDFDocumentContext = ({
|
|
|
5452
5455
|
}
|
|
5453
5456
|
setProgress(progressEvent.loaded / progressEvent.total);
|
|
5454
5457
|
};
|
|
5455
|
-
return loadingTask.promise.then((proxy) => {
|
|
5458
|
+
return loadingTask.promise.then(async (proxy) => {
|
|
5456
5459
|
if (isDisposed || loadingTask?.destroyed) {
|
|
5457
5460
|
return;
|
|
5458
5461
|
}
|
|
5459
5462
|
onDocumentLoad?.({ proxy, source });
|
|
5460
5463
|
setProgress(1);
|
|
5461
|
-
|
|
5464
|
+
try {
|
|
5465
|
+
await generateViewports(proxy);
|
|
5466
|
+
} catch (error) {
|
|
5467
|
+
if (isDisposed || loadingTask?.destroyed) {
|
|
5468
|
+
return;
|
|
5469
|
+
}
|
|
5470
|
+
console.error("Error generating PDF viewports", error);
|
|
5471
|
+
onErrorRef.current?.({
|
|
5472
|
+
error,
|
|
5473
|
+
phase: "viewport-generation",
|
|
5474
|
+
source
|
|
5475
|
+
});
|
|
5476
|
+
}
|
|
5462
5477
|
}).catch((error) => {
|
|
5463
5478
|
if (isDisposed || loadingTask?.destroyed) {
|
|
5464
5479
|
return;
|
|
5465
5480
|
}
|
|
5466
5481
|
console.error("Error loading PDF document", error);
|
|
5482
|
+
onErrorRef.current?.({
|
|
5483
|
+
error,
|
|
5484
|
+
phase: "document-load",
|
|
5485
|
+
source
|
|
5486
|
+
});
|
|
5467
5487
|
});
|
|
5468
5488
|
}).catch((error) => {
|
|
5469
5489
|
if (isDisposed) {
|
|
5470
5490
|
return;
|
|
5471
5491
|
}
|
|
5472
5492
|
console.error("Error loading PDF.js", error);
|
|
5493
|
+
onErrorRef.current?.({
|
|
5494
|
+
error,
|
|
5495
|
+
phase: "pdfjs-load",
|
|
5496
|
+
source
|
|
5497
|
+
});
|
|
5473
5498
|
});
|
|
5474
5499
|
return () => {
|
|
5475
5500
|
isDisposed = true;
|
|
@@ -5488,6 +5513,7 @@ var Root = forwardRef(
|
|
|
5488
5513
|
source,
|
|
5489
5514
|
loader,
|
|
5490
5515
|
onDocumentLoad,
|
|
5516
|
+
onError,
|
|
5491
5517
|
isZoomFitWidth,
|
|
5492
5518
|
zoom,
|
|
5493
5519
|
zoomOptions,
|
|
@@ -5497,6 +5523,7 @@ var Root = forwardRef(
|
|
|
5497
5523
|
const { initialState } = usePDFDocumentContext({
|
|
5498
5524
|
source,
|
|
5499
5525
|
onDocumentLoad,
|
|
5526
|
+
onError,
|
|
5500
5527
|
isZoomFitWidth,
|
|
5501
5528
|
zoom,
|
|
5502
5529
|
zoomOptions,
|