@file-viewer/renderer-pdf 2.1.26 → 2.1.27
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/pdf.js +61 -2
- package/package.json +2 -2
package/dist/pdf.js
CHANGED
|
@@ -312,7 +312,7 @@ const buildOutlineItems = (items, prefix = 'outline', getFallbackTitle = index =
|
|
|
312
312
|
};
|
|
313
313
|
});
|
|
314
314
|
export default async function renderPdf(buffer, target, context) {
|
|
315
|
-
var _a, _b, _c;
|
|
315
|
+
var _a, _b, _c, _d;
|
|
316
316
|
const documentRef = target.ownerDocument || document;
|
|
317
317
|
const targetWindow = documentRef.defaultView || (typeof window !== 'undefined' ? window : null);
|
|
318
318
|
const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
|
|
@@ -586,6 +586,64 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
586
586
|
pendingPdfThumbnails.delete(pageNumber);
|
|
587
587
|
}
|
|
588
588
|
};
|
|
589
|
+
const renderFirstPageThumbnail = async (captureOptions) => {
|
|
590
|
+
var _a, _b, _c, _d, _e, _f;
|
|
591
|
+
const pdfDocument = pdfContext.document;
|
|
592
|
+
if (!pdfDocument) {
|
|
593
|
+
return null;
|
|
594
|
+
}
|
|
595
|
+
if ((_a = captureOptions.signal) === null || _a === void 0 ? void 0 : _a.aborted) {
|
|
596
|
+
throw captureOptions.signal.reason;
|
|
597
|
+
}
|
|
598
|
+
const page = await pdfDocument.getPage(1);
|
|
599
|
+
await ensurePdfPageCjkFontFallback(1, page);
|
|
600
|
+
const baseViewport = page.getViewport({ scale: 1, rotation: currentRotation });
|
|
601
|
+
const scale = Math.max(0.1, Math.min(captureOptions.width / Math.max(baseViewport.width, 1), captureOptions.height / Math.max(baseViewport.height, 1)));
|
|
602
|
+
const viewport = page.getViewport({ scale, rotation: currentRotation });
|
|
603
|
+
const canvas = documentRef.createElement('canvas');
|
|
604
|
+
const canvasContext = canvas.getContext('2d');
|
|
605
|
+
if (!canvasContext) {
|
|
606
|
+
return null;
|
|
607
|
+
}
|
|
608
|
+
canvas.width = Math.max(1, Math.ceil(viewport.width));
|
|
609
|
+
canvas.height = Math.max(1, Math.ceil(viewport.height));
|
|
610
|
+
const renderTask = page.render({ canvas, canvasContext, viewport });
|
|
611
|
+
const cancelRender = () => renderTask.cancel();
|
|
612
|
+
(_b = captureOptions.signal) === null || _b === void 0 ? void 0 : _b.addEventListener('abort', cancelRender, { once: true });
|
|
613
|
+
try {
|
|
614
|
+
await renderTask.promise;
|
|
615
|
+
if ((_c = captureOptions.signal) === null || _c === void 0 ? void 0 : _c.aborted) {
|
|
616
|
+
throw captureOptions.signal.reason;
|
|
617
|
+
}
|
|
618
|
+
return await new Promise(resolve => canvas.toBlob(resolve, 'image/png'));
|
|
619
|
+
}
|
|
620
|
+
catch (error) {
|
|
621
|
+
if ((_d = captureOptions.signal) === null || _d === void 0 ? void 0 : _d.aborted) {
|
|
622
|
+
throw captureOptions.signal.reason;
|
|
623
|
+
}
|
|
624
|
+
throw error;
|
|
625
|
+
}
|
|
626
|
+
finally {
|
|
627
|
+
(_e = captureOptions.signal) === null || _e === void 0 ? void 0 : _e.removeEventListener('abort', cancelRender);
|
|
628
|
+
canvas.width = 0;
|
|
629
|
+
canvas.height = 0;
|
|
630
|
+
(_f = page.cleanup) === null || _f === void 0 ? void 0 : _f.call(page);
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
(_d = context === null || context === void 0 ? void 0 : context.registerThumbnailAdapter) === null || _d === void 0 ? void 0 : _d.call(context, {
|
|
634
|
+
beforeCapture: async ({ signal }) => {
|
|
635
|
+
while (loadStatus === 'loading' && !destroyed) {
|
|
636
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
637
|
+
throw signal.reason;
|
|
638
|
+
}
|
|
639
|
+
await new Promise(resolve => targetWindow.setTimeout(resolve, 16));
|
|
640
|
+
}
|
|
641
|
+
if (loadStatus === 'error') {
|
|
642
|
+
throw new Error(errorMessage || t('pdf.error.loadFailed'));
|
|
643
|
+
}
|
|
644
|
+
},
|
|
645
|
+
capture: renderFirstPageThumbnail,
|
|
646
|
+
});
|
|
589
647
|
const ensureThumbnailObserver = () => {
|
|
590
648
|
if (!thumbnailsEnabled || thumbnailObserver || typeof targetWindow.IntersectionObserver !== 'function') {
|
|
591
649
|
return;
|
|
@@ -1679,7 +1737,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1679
1737
|
return {
|
|
1680
1738
|
$el: root,
|
|
1681
1739
|
unmount() {
|
|
1682
|
-
var _a;
|
|
1740
|
+
var _a, _b;
|
|
1683
1741
|
destroyed = true;
|
|
1684
1742
|
loadVersion += 1;
|
|
1685
1743
|
restorePdfJsMissingSystemFontWarnings();
|
|
@@ -1700,6 +1758,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1700
1758
|
unregisterFileViewerViewStateProvider(root);
|
|
1701
1759
|
outlineItems = [];
|
|
1702
1760
|
(_a = context === null || context === void 0 ? void 0 : context.registerExportAdapter) === null || _a === void 0 ? void 0 : _a.call(context, null);
|
|
1761
|
+
(_b = context === null || context === void 0 ? void 0 : context.registerThumbnailAdapter) === null || _b === void 0 ? void 0 : _b.call(context, null);
|
|
1703
1762
|
const resource = pdfContext.resource;
|
|
1704
1763
|
pdfContext.viewer = null;
|
|
1705
1764
|
pdfContext.linkService = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/renderer-pdf",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.27",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone PDF renderer plugin for Flyfish File Viewer powered by PDF.js.",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"LICENSE"
|
|
55
55
|
],
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@file-viewer/core": "2.1.
|
|
57
|
+
"@file-viewer/core": "2.1.27",
|
|
58
58
|
"@fontsource-variable/noto-sans-sc": "5.2.10",
|
|
59
59
|
"pdf-lib": "1.17.1",
|
|
60
60
|
"pdfjs-dist": "5.4.624"
|