@file-viewer/renderer-pdf 3.3.3 → 3.3.5
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/README.en.md +6 -0
- package/README.md +6 -0
- package/README.zh-CN.md +6 -0
- package/THIRD_PARTY_NOTICES.md +21 -0
- package/dist/index.js +2 -2
- package/dist/pdf.js +76 -40
- package/dist/pdfAnnotationStyles.d.ts +1 -0
- package/dist/pdfAnnotationStyles.js +387 -0
- package/dist/pdfSignatureInspection.d.ts +6 -0
- package/dist/pdfSignatureInspection.js +228 -0
- package/dist/pdfStyles.d.ts +1 -1
- package/dist/pdfStyles.js +2 -1
- package/dist/vendor/pdfjs/legacy/build/pdf.mjs +2 -32772
- package/dist/vendor/pdfjs/provenance.json +22 -6
- package/package.json +13 -3
package/README.en.md
CHANGED
|
@@ -9,6 +9,12 @@ use asynchronous resource fetching instead of synchronous binary XHR.
|
|
|
9
9
|
|
|
10
10
|
Standalone PDF renderer package for Flyfish File Viewer. It is powered by PDF.js and provides page rendering, navigation, outline, search, zoom, print, and HTML export support.
|
|
11
11
|
|
|
12
|
+
## Optional signature metadata
|
|
13
|
+
|
|
14
|
+
With the optional signatureRenderer, PDF keeps its normal preview and can show metadata-only signature details. For lightweight packages, install the existing optional pdf-lib@1.17.1 peer and call enableFileViewerPdfSignatureInspection() from @file-viewer/renderer-pdf/signature-inspection; Full already registers the reader through its existing PDF capability. The normal PDF entry does not import this parser. Supply an original File/buffer or pdf.streaming:false. A streaming URL without original bytes preserves preview and reports unavailable without an extra fetch. This reads original-source dictionaries/CMS without checking signatures, digests, revision coverage or trust.
|
|
15
|
+
|
|
16
|
+
See the Vanilla example and boundaries in [renderer-signature](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/signature/README.md)。
|
|
17
|
+
|
|
12
18
|
## Usage
|
|
13
19
|
|
|
14
20
|
```ts
|
package/README.md
CHANGED
|
@@ -9,6 +9,12 @@ use asynchronous resource fetching instead of synchronous binary XHR.
|
|
|
9
9
|
|
|
10
10
|
Standalone PDF renderer package for Flyfish File Viewer. It is powered by PDF.js and provides page rendering, navigation, outline, search, zoom, print, and HTML export support.
|
|
11
11
|
|
|
12
|
+
## Optional signature metadata
|
|
13
|
+
|
|
14
|
+
With the optional signatureRenderer, PDF keeps its normal preview and can show metadata-only signature details. For lightweight packages, install the existing optional pdf-lib@1.17.1 peer and call enableFileViewerPdfSignatureInspection() from @file-viewer/renderer-pdf/signature-inspection; Full already registers the reader through its existing PDF capability. The normal PDF entry does not import this parser. Supply an original File/buffer or pdf.streaming:false. A streaming URL without original bytes preserves preview and reports unavailable without an extra fetch. This reads original-source dictionaries/CMS without checking signatures, digests, revision coverage or trust.
|
|
15
|
+
|
|
16
|
+
See the Vanilla example and boundaries in [renderer-signature](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/signature/README.md)。
|
|
17
|
+
|
|
12
18
|
## Usage
|
|
13
19
|
|
|
14
20
|
```ts
|
package/README.zh-CN.md
CHANGED
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
Flyfish File Viewer 的独立 PDF renderer 包,基于 PDF.js,提供 PDF 页面渲染、导航、目录、搜索、缩放、打印和 HTML 导出能力。
|
|
6
6
|
|
|
7
|
+
## 可选签名元数据
|
|
8
|
+
|
|
9
|
+
注册可选 signatureRenderer 后,PDF 原预览旁可显示只读签名元数据。轻量包需安装现有可选 peer pdf-lib@1.17.1 并调用 enableFileViewerPdfSignatureInspection()(来自 @file-viewer/renderer-pdf/signature-inspection);Full 原有 PDF 能力已注册该 reader。普通 PDF 入口不引入此解析器。使用原始 File/buffer 或 pdf.streaming:false;仅流式 URL 缺原字节时保留预览并报告不可检查,不额外请求。只解析原始字节字典/CMS,不验证签名、摘要、修订覆盖或信任。
|
|
10
|
+
|
|
11
|
+
完整 Vanilla 示例及限制见 [renderer-signature](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/signature/README.zh-CN.md)。
|
|
12
|
+
|
|
7
13
|
## 用法
|
|
8
14
|
|
|
9
15
|
```ts
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
## PDF.js viewer CSS
|
|
4
|
+
|
|
5
|
+
The viewer and annotation-layer CSS derives from pdfjs-dist 5.4.624,
|
|
6
|
+
web/pdf_viewer.css. The original upstream declaration is retained below.
|
|
7
|
+
It attributes the upstream CSS, not File Viewer's original integration work.
|
|
8
|
+
|
|
9
|
+
Copyright 2014 Mozilla Foundation
|
|
10
|
+
|
|
11
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
you may not use this file except in compliance with the License.
|
|
13
|
+
You may obtain a copy of the License at
|
|
14
|
+
|
|
15
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
|
|
17
|
+
Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
See the License for the specific language governing permissions and
|
|
21
|
+
limitations under the License.
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEFAULT_RENDERER_DEFINITIONS, } from '@file-viewer/core';
|
|
1
|
+
import { DEFAULT_RENDERER_DEFINITIONS, renderWithFileViewerDocumentInspection, } from '@file-viewer/core';
|
|
2
2
|
export { getFileViewerPdfIdentityFontRepair, registerFileViewerPdfIdentityFontRepair, } from './optionalCapabilities.js';
|
|
3
3
|
const pdfDefinition = DEFAULT_RENDERER_DEFINITIONS.find(definition => definition.id === 'pdf');
|
|
4
4
|
if (!pdfDefinition) {
|
|
@@ -8,7 +8,7 @@ export const pdfRendererDefinition = {
|
|
|
8
8
|
...pdfDefinition,
|
|
9
9
|
sourceAccess: 'stream-preferred',
|
|
10
10
|
};
|
|
11
|
-
export const renderFileViewerPdf = (buffer, target, _type, context) => import('./pdf.js').then(({ default: renderPdf }) => renderPdf(buffer, target, context));
|
|
11
|
+
export const renderFileViewerPdf = (buffer, target, _type, context) => renderWithFileViewerDocumentInspection(buffer, target, 'pdf', context, () => import('./pdf.js').then(({ default: renderPdf }) => renderPdf(buffer, target, context)));
|
|
12
12
|
export const pdfRenderer = {
|
|
13
13
|
id: 'file-viewer-renderer-pdf',
|
|
14
14
|
label: 'Flyfish File Viewer PDF renderer',
|
package/dist/pdf.js
CHANGED
|
@@ -2,7 +2,7 @@ import { installPdfHandTool } from './pdfHandTool.js';
|
|
|
2
2
|
import { scrollPdfPageWithinContainer } from './pdfPageScroll.js';
|
|
3
3
|
import { getDocument, GlobalWorkerOptions, PDFWorker as PdfJsWorker, PixelsPerInch, version as pdfJsVersion, } from './vendor/pdfjs/legacy/build/pdf.mjs';
|
|
4
4
|
import { EventBus, GenericL10n, PDFFindController, PDFLinkService, PDFViewer, } from './vendor/pdfjs/legacy/web/pdf_viewer.mjs';
|
|
5
|
-
import { registerFileViewerSearchProvider, registerFileViewerZoomProvider, unregisterFileViewerSearchProvider, unregisterFileViewerZoomProvider, registerFileViewerViewStateProvider, unregisterFileViewerViewStateProvider, createFileViewerZoomChangeEmitter, createFileViewerViewStateChange, createFileViewerViewStateChangeEmitter, createFileViewerTranslator, observeFileViewerColorScheme, buildPrintPageStyle, formatCssPixels, DEFAULT_PDF_RANGE_CHUNK_SIZE, resolveFileViewerLocale, resolveFileViewerFitScale, } from '@file-viewer/core';
|
|
5
|
+
import { registerFileViewerSearchProvider, registerFileViewerZoomProvider, unregisterFileViewerSearchProvider, unregisterFileViewerZoomProvider, registerFileViewerViewStateProvider, unregisterFileViewerViewStateProvider, createFileViewerZoomChangeEmitter, createFileViewerViewStateChange, createFileViewerViewStateChangeEmitter, createFileViewerTranslator, normalizeFileViewerErrorMessage, observeFileViewerColorScheme, buildPrintPageStyle, formatCssPixels, DEFAULT_PDF_RANGE_CHUNK_SIZE, resolveFileViewerLocale, resolveFileViewerFitScale, } from '@file-viewer/core';
|
|
6
6
|
import { DEFAULT_FILE_VIEWER_PDF_WORKER_PATH, resolveFileViewerPdfAssetUrls, resolveFileViewerRuntimeAssetBaseUrl, } from '@file-viewer/core/assets';
|
|
7
7
|
import { pdfViewerStyle } from './pdfStyles.js';
|
|
8
8
|
import { collectMalformedIdentityFontNames, createPdfCjkFontFallbackManager, detectMalformedIdentityCjkFontFamilies, } from './pdfFontFallback.js';
|
|
@@ -268,10 +268,10 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
268
268
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
269
269
|
const documentRef = target.ownerDocument || document;
|
|
270
270
|
const targetWindow = documentRef.defaultView || (typeof window !== 'undefined' ? window : null);
|
|
271
|
-
const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
|
|
272
|
-
|
|
271
|
+
const t = createFileViewerTranslator((context === null || context === void 0 ? void 0 : context.i18n) || (context === null || context === void 0 ? void 0 : context.options));
|
|
272
|
+
let activeL10n;
|
|
273
273
|
if (!targetWindow) {
|
|
274
|
-
throw
|
|
274
|
+
throw t.error('pdf.error.browserWindow');
|
|
275
275
|
}
|
|
276
276
|
const options = (_a = context === null || context === void 0 ? void 0 : context.options) === null || _a === void 0 ? void 0 : _a.pdf;
|
|
277
277
|
const pdfRuntimeAssetBaseUrl = resolveFileViewerRuntimeAssetBaseUrl(documentRef);
|
|
@@ -295,7 +295,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
295
295
|
: !isCompactViewport();
|
|
296
296
|
let navMode = 'pages';
|
|
297
297
|
let loadStatus = 'loading';
|
|
298
|
-
let errorMessage = '';
|
|
298
|
+
let errorMessage = () => '';
|
|
299
299
|
let currentPage = 1;
|
|
300
300
|
let pageCount = 0;
|
|
301
301
|
let currentScale = 1;
|
|
@@ -366,29 +366,29 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
366
366
|
root.dataset.pdfReadingTheme = ((_a = options === null || options === void 0 ? void 0 : options.darkMode) !== null && _a !== void 0 ? _a : theme === 'dark') ? 'dark' : 'light';
|
|
367
367
|
});
|
|
368
368
|
const toolbar = createElement(documentRef, 'div', 'pdf-toolbar');
|
|
369
|
-
const navToggleButton = createButton(documentRef, 'pdf-icon-button', t('pdf.toolbar.toggleNavigation'));
|
|
369
|
+
const navToggleButton = t.attr(t.attr(createButton(documentRef, 'pdf-icon-button', t('pdf.toolbar.toggleNavigation')), 'title', 'pdf.toolbar.toggleNavigation'), 'aria-label', 'pdf.toolbar.toggleNavigation');
|
|
370
370
|
navToggleButton.setAttribute('aria-pressed', String(navVisible));
|
|
371
371
|
navToggleButton.append(createElement(documentRef, 'span', 'pdf-panel-icon'));
|
|
372
372
|
const pageGroup = createElement(documentRef, 'div', 'pdf-toolbar-group');
|
|
373
|
-
const previousPageButton = createButton(documentRef, 'pdf-icon-button', t('pdf.toolbar.previousPage'), '‹');
|
|
373
|
+
const previousPageButton = t.attr(t.attr(createButton(documentRef, 'pdf-icon-button', t('pdf.toolbar.previousPage'), '‹'), 'title', 'pdf.toolbar.previousPage'), 'aria-label', 'pdf.toolbar.previousPage');
|
|
374
374
|
const pageMeter = createElement(documentRef, 'span', 'pdf-page-meter');
|
|
375
375
|
const pageMeterCurrent = createElement(documentRef, 'strong', undefined, '1');
|
|
376
376
|
const pageMeterTotal = createElement(documentRef, 'span', undefined, '/ -');
|
|
377
377
|
pageMeter.append(pageMeterCurrent, pageMeterTotal);
|
|
378
|
-
const nextPageButton = createButton(documentRef, 'pdf-icon-button', t('pdf.toolbar.nextPage'), '›');
|
|
378
|
+
const nextPageButton = t.attr(t.attr(createButton(documentRef, 'pdf-icon-button', t('pdf.toolbar.nextPage'), '›'), 'title', 'pdf.toolbar.nextPage'), 'aria-label', 'pdf.toolbar.nextPage');
|
|
379
379
|
pageGroup.append(previousPageButton, pageMeter, nextPageButton);
|
|
380
380
|
const zoomGroup = createElement(documentRef, 'div', 'pdf-toolbar-group pdf-toolbar-group--zoom');
|
|
381
|
-
const zoomOutButton = createButton(documentRef, 'pdf-icon-button', t('pdf.toolbar.zoomOut'), '−');
|
|
381
|
+
const zoomOutButton = t.attr(t.attr(createButton(documentRef, 'pdf-icon-button', t('pdf.toolbar.zoomOut'), '−'), 'title', 'pdf.toolbar.zoomOut'), 'aria-label', 'pdf.toolbar.zoomOut');
|
|
382
382
|
const scaleButton = createElement(documentRef, 'button', 'pdf-scale-button', '100%');
|
|
383
383
|
scaleButton.type = 'button';
|
|
384
|
-
scaleButton
|
|
385
|
-
|
|
386
|
-
const zoomInButton = createButton(documentRef, 'pdf-icon-button', t('pdf.toolbar.zoomIn'), '+');
|
|
384
|
+
t.attr(scaleButton, 'title', 'pdf.toolbar.fitWidth');
|
|
385
|
+
t.attr(scaleButton, 'aria-label', 'pdf.toolbar.fitWidth');
|
|
386
|
+
const zoomInButton = t.attr(t.attr(createButton(documentRef, 'pdf-icon-button', t('pdf.toolbar.zoomIn'), '+'), 'title', 'pdf.toolbar.zoomIn'), 'aria-label', 'pdf.toolbar.zoomIn');
|
|
387
387
|
zoomGroup.append(zoomOutButton, scaleButton, zoomInButton);
|
|
388
388
|
const rotateGroup = createElement(documentRef, 'div', 'pdf-toolbar-group pdf-toolbar-group--rotate');
|
|
389
|
-
const rotateLeftButton = createButton(documentRef, 'pdf-icon-button', t('pdf.toolbar.rotateLeft'), '↺');
|
|
389
|
+
const rotateLeftButton = t.attr(t.attr(createButton(documentRef, 'pdf-icon-button', t('pdf.toolbar.rotateLeft'), '↺'), 'title', 'pdf.toolbar.rotateLeft'), 'aria-label', 'pdf.toolbar.rotateLeft');
|
|
390
390
|
const rotationMeter = createElement(documentRef, 'span', 'pdf-rotation-meter', `${currentRotation}°`);
|
|
391
|
-
const rotateRightButton = createButton(documentRef, 'pdf-icon-button', t('pdf.toolbar.rotateRight'), '↻');
|
|
391
|
+
const rotateRightButton = t.attr(t.attr(createButton(documentRef, 'pdf-icon-button', t('pdf.toolbar.rotateRight'), '↻'), 'title', 'pdf.toolbar.rotateRight'), 'aria-label', 'pdf.toolbar.rotateRight');
|
|
392
392
|
rotateGroup.append(rotateLeftButton, rotationMeter, rotateRightButton);
|
|
393
393
|
if (navigationEnabled) {
|
|
394
394
|
toolbar.append(navToggleButton);
|
|
@@ -400,16 +400,16 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
400
400
|
const content = createElement(documentRef, 'div', 'pdf-content');
|
|
401
401
|
const navPane = createElement(documentRef, 'aside', 'pdf-nav-pane');
|
|
402
402
|
const navHead = createElement(documentRef, 'div', 'pdf-nav-head');
|
|
403
|
-
const navTitle = createElement(documentRef, 'span', undefined,
|
|
404
|
-
const navCount = createElement(documentRef, 'strong', undefined,
|
|
403
|
+
const navTitle = t.text(createElement(documentRef, 'span', undefined), 'pdf.nav.pagesTitle');
|
|
404
|
+
const navCount = t.text(createElement(documentRef, 'strong', undefined), 'pdf.nav.pageCount', { count: 0 });
|
|
405
405
|
navHead.append(navTitle, navCount);
|
|
406
406
|
const navTabs = createElement(documentRef, 'div', 'pdf-nav-tabs');
|
|
407
407
|
navTabs.setAttribute('role', 'tablist');
|
|
408
|
-
|
|
409
|
-
const pagesTab = createButton(documentRef, '', t('pdf.nav.pagesTab'));
|
|
410
|
-
const outlineTab = createButton(documentRef, '', t('pdf.nav.outlineTab'));
|
|
411
|
-
pagesTab
|
|
412
|
-
outlineTab
|
|
408
|
+
t.attr(navTabs, 'aria-label', 'pdf.nav.typeLabel');
|
|
409
|
+
const pagesTab = t.attr(t.attr(createButton(documentRef, '', t('pdf.nav.pagesTab')), 'title', 'pdf.nav.pagesTab'), 'aria-label', 'pdf.nav.pagesTab');
|
|
410
|
+
const outlineTab = t.attr(t.attr(createButton(documentRef, '', t('pdf.nav.outlineTab')), 'title', 'pdf.nav.outlineTab'), 'aria-label', 'pdf.nav.outlineTab');
|
|
411
|
+
t.text(pagesTab, 'pdf.nav.pagesTab');
|
|
412
|
+
t.text(outlineTab, 'pdf.nav.outlineTab');
|
|
413
413
|
pagesTab.setAttribute('role', 'tab');
|
|
414
414
|
outlineTab.setAttribute('role', 'tab');
|
|
415
415
|
navTabs.append(pagesTab, outlineTab);
|
|
@@ -419,7 +419,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
419
419
|
const container = createElement(documentRef, 'div', 'pdf-wrapper');
|
|
420
420
|
container.dataset.viewerScrollContainer = 'true';
|
|
421
421
|
const pdfViewerRoot = createElement(documentRef, 'div', 'pdfViewer');
|
|
422
|
-
const stateNode = createElement(documentRef, 'div', 'pdf-state',
|
|
422
|
+
const stateNode = t.text(createElement(documentRef, 'div', 'pdf-state'), 'pdf.state.loading');
|
|
423
423
|
container.append(pdfViewerRoot, stateNode);
|
|
424
424
|
viewport.append(container);
|
|
425
425
|
content.append(navPane, viewport);
|
|
@@ -465,6 +465,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
465
465
|
else if (navList.classList.contains('pdf-outline-list')) {
|
|
466
466
|
navScrollTopByMode.outline = navList.scrollTop;
|
|
467
467
|
}
|
|
468
|
+
t.release(navList);
|
|
468
469
|
navList.replaceChildren();
|
|
469
470
|
navList.className = navMode === 'pages' ? 'pdf-page-list' : 'pdf-outline-list';
|
|
470
471
|
const restoreNavScrollTop = () => {
|
|
@@ -485,7 +486,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
485
486
|
else {
|
|
486
487
|
thumb.textContent = String(page);
|
|
487
488
|
}
|
|
488
|
-
button.append(thumb, createElement(documentRef, 'span', 'pdf-page-label',
|
|
489
|
+
button.append(thumb, t.text(createElement(documentRef, 'span', 'pdf-page-label'), 'pdf.nav.pageLabel', { page }));
|
|
489
490
|
button.addEventListener('click', () => goToPage(page, 'page-click', 'user'));
|
|
490
491
|
navList.append(button);
|
|
491
492
|
}
|
|
@@ -510,7 +511,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
510
511
|
navList.append(button);
|
|
511
512
|
});
|
|
512
513
|
if (!entries.length) {
|
|
513
|
-
navList.append(createElement(documentRef, 'div', 'pdf-outline-empty',
|
|
514
|
+
navList.append(t.text(createElement(documentRef, 'div', 'pdf-outline-empty'), 'pdf.nav.outlineEmpty'));
|
|
514
515
|
}
|
|
515
516
|
restoreNavScrollTop();
|
|
516
517
|
};
|
|
@@ -523,7 +524,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
523
524
|
}
|
|
524
525
|
const image = documentRef.createElement('img');
|
|
525
526
|
image.src = imageUrl;
|
|
526
|
-
image
|
|
527
|
+
t.attr(image, 'alt', 'pdf.thumbnail.alt', { page: pageNumber });
|
|
527
528
|
image.loading = 'lazy';
|
|
528
529
|
thumb.replaceChildren(image);
|
|
529
530
|
return true;
|
|
@@ -631,7 +632,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
631
632
|
await new Promise(resolve => targetWindow.setTimeout(resolve, 16));
|
|
632
633
|
}
|
|
633
634
|
if (loadStatus === 'error') {
|
|
634
|
-
throw new Error(errorMessage || t('pdf.error.loadFailed'));
|
|
635
|
+
throw new Error(errorMessage() || t('pdf.error.loadFailed'));
|
|
635
636
|
}
|
|
636
637
|
},
|
|
637
638
|
capture: renderFirstPageThumbnail,
|
|
@@ -679,10 +680,12 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
679
680
|
outlineTab.classList.toggle('active', navMode === 'outline');
|
|
680
681
|
pagesTab.setAttribute('aria-selected', navMode === 'pages' ? 'true' : 'false');
|
|
681
682
|
outlineTab.setAttribute('aria-selected', navMode === 'outline' ? 'true' : 'false');
|
|
682
|
-
navTitle.textContent = navMode === 'pages' ? t('pdf.nav.pagesTitle') : t('pdf.nav.outlineTitle');
|
|
683
|
-
navCount
|
|
684
|
-
|
|
685
|
-
|
|
683
|
+
t.bind(navTitle, localizedNode => { localizedNode.textContent = navMode === 'pages' ? t('pdf.nav.pagesTitle') : t('pdf.nav.outlineTitle'); }, 'textContent');
|
|
684
|
+
t.bind(navCount, localizedNode => {
|
|
685
|
+
localizedNode.textContent = navMode === 'pages'
|
|
686
|
+
? t('pdf.nav.pageCount', { count: pageCount })
|
|
687
|
+
: t('pdf.nav.itemCount', { count: outlineCount() });
|
|
688
|
+
}, 'textContent');
|
|
686
689
|
pageMeterCurrent.textContent = String(currentPage);
|
|
687
690
|
pageMeterTotal.textContent = `/ ${pageCount || '-'}`;
|
|
688
691
|
scaleButton.textContent = scaleText();
|
|
@@ -693,7 +696,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
693
696
|
zoomInButton.disabled = !canZoomIn();
|
|
694
697
|
stateNode.hidden = loadStatus === 'ready';
|
|
695
698
|
stateNode.classList.toggle('pdf-state--error', loadStatus === 'error');
|
|
696
|
-
stateNode.textContent = loadStatus === 'error' ? errorMessage : t('pdf.state.loading');
|
|
699
|
+
t.bind(stateNode, localizedNode => { localizedNode.textContent = loadStatus === 'error' ? errorMessage() : t('pdf.state.loading'); }, 'textContent');
|
|
697
700
|
renderNavList();
|
|
698
701
|
};
|
|
699
702
|
const writeLegacyCompatiblePageDimensions = () => {
|
|
@@ -1549,7 +1552,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1549
1552
|
var _a, _b;
|
|
1550
1553
|
const pdfDocument = pdfContext.document;
|
|
1551
1554
|
if (!pdfDocument) {
|
|
1552
|
-
throw
|
|
1555
|
+
throw t.error('pdf.error.notLoaded');
|
|
1553
1556
|
}
|
|
1554
1557
|
const page = await pdfDocument.getPage(Math.min(Math.max(pageNumber, 1), pdfDocument.numPages));
|
|
1555
1558
|
const viewport = page.getViewport({
|
|
@@ -1568,7 +1571,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1568
1571
|
const count = ((_a = pdfContext.document) === null || _a === void 0 ? void 0 : _a.numPages) || 1;
|
|
1569
1572
|
for (let number = 1; number <= count; number += 1) {
|
|
1570
1573
|
if (destroyed)
|
|
1571
|
-
throw
|
|
1574
|
+
throw t.error('pdf.error.unloaded');
|
|
1572
1575
|
sizes.push(await getPdfPrintPageSize(number));
|
|
1573
1576
|
}
|
|
1574
1577
|
const size = sizes[0];
|
|
@@ -1583,12 +1586,12 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1583
1586
|
var _a, _b;
|
|
1584
1587
|
const pdfDocument = pdfContext.document;
|
|
1585
1588
|
if (!pdfDocument) {
|
|
1586
|
-
throw
|
|
1589
|
+
throw t.error('pdf.error.notLoaded');
|
|
1587
1590
|
}
|
|
1588
1591
|
const pagesHtml = [];
|
|
1589
1592
|
for (let pageNumber = 1; pageNumber <= pdfDocument.numPages; pageNumber += 1) {
|
|
1590
1593
|
if (destroyed) {
|
|
1591
|
-
throw
|
|
1594
|
+
throw t.error('pdf.error.unloaded');
|
|
1592
1595
|
}
|
|
1593
1596
|
const page = await pdfDocument.getPage(pageNumber);
|
|
1594
1597
|
await ensurePdfPageCjkFontFallback(pageNumber, page);
|
|
@@ -1606,7 +1609,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1606
1609
|
const canvas = documentRef.createElement('canvas');
|
|
1607
1610
|
const canvasContext = canvas.getContext('2d');
|
|
1608
1611
|
if (!canvasContext) {
|
|
1609
|
-
throw
|
|
1612
|
+
throw t.error('pdf.error.canvasUnavailable');
|
|
1610
1613
|
}
|
|
1611
1614
|
canvas.width = Math.ceil(renderViewport.width);
|
|
1612
1615
|
canvas.height = Math.ceil(renderViewport.height);
|
|
@@ -1634,7 +1637,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1634
1637
|
pdfCjkFontFallbackPageLoads.clear();
|
|
1635
1638
|
pdfCjkFontFallbackRenderHandledPages.clear();
|
|
1636
1639
|
loadStatus = 'loading';
|
|
1637
|
-
errorMessage = '';
|
|
1640
|
+
errorMessage = () => '';
|
|
1638
1641
|
pdfContext.document = null;
|
|
1639
1642
|
outlineItems = [];
|
|
1640
1643
|
pdfThumbnails.clear();
|
|
@@ -1654,12 +1657,37 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1654
1657
|
linkService: pdfLinkService,
|
|
1655
1658
|
updateMatchesCountOnProgress: true,
|
|
1656
1659
|
});
|
|
1660
|
+
void (activeL10n === null || activeL10n === void 0 ? void 0 : activeL10n.destroy());
|
|
1661
|
+
const fallbackL10n = new GenericL10n('');
|
|
1662
|
+
activeL10n = fallbackL10n;
|
|
1663
|
+
const bindPageRegions = (element) => {
|
|
1664
|
+
const selector = '[data-l10n-id="pdfjs-page-landmark"]';
|
|
1665
|
+
const pages = [...(element.matches(selector) ? [element] : []), ...element.querySelectorAll(selector)];
|
|
1666
|
+
for (const page of pages) {
|
|
1667
|
+
const number = Number(page.getAttribute('data-page-number'));
|
|
1668
|
+
if (!Number.isInteger(number) || number < 1)
|
|
1669
|
+
continue;
|
|
1670
|
+
page.removeAttribute('data-l10n-id');
|
|
1671
|
+
page.removeAttribute('data-l10n-args');
|
|
1672
|
+
t.attr(page, 'aria-label', 'pdf.nav.pageLabel', { page: number });
|
|
1673
|
+
}
|
|
1674
|
+
};
|
|
1675
|
+
const l10n = {
|
|
1676
|
+
getLanguage: () => resolveFileViewerLocale(context === null || context === void 0 ? void 0 : context.options),
|
|
1677
|
+
getDirection: () => 'ltr',
|
|
1678
|
+
get: fallbackL10n.get.bind(fallbackL10n),
|
|
1679
|
+
translate: async (element) => { bindPageRegions(element); await fallbackL10n.translate(element); },
|
|
1680
|
+
translateOnce: async (element) => { bindPageRegions(element); await fallbackL10n.translateOnce(element); },
|
|
1681
|
+
pause: () => fallbackL10n.pause(),
|
|
1682
|
+
resume: () => fallbackL10n.resume(),
|
|
1683
|
+
destroy: () => fallbackL10n.destroy(),
|
|
1684
|
+
};
|
|
1657
1685
|
const pdfViewer = new PDFViewer({
|
|
1658
1686
|
container,
|
|
1659
1687
|
eventBus,
|
|
1660
1688
|
linkService: pdfLinkService,
|
|
1661
1689
|
findController: pdfFindController,
|
|
1662
|
-
l10n
|
|
1690
|
+
l10n,
|
|
1663
1691
|
enableAutoLinking: false,
|
|
1664
1692
|
});
|
|
1665
1693
|
pdfContext.viewer = pdfViewer;
|
|
@@ -1671,6 +1699,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1671
1699
|
eventBus.on('updatefindcontrolstate', handlePdfFindControlState);
|
|
1672
1700
|
eventBus.on('pagesinit', () => {
|
|
1673
1701
|
var _a;
|
|
1702
|
+
void l10n.translate(container);
|
|
1674
1703
|
applyRotation(currentRotation, 'rotation-change', 'viewer', false);
|
|
1675
1704
|
loadStatus = 'ready';
|
|
1676
1705
|
scheduleLegacyPageDimensionPatch();
|
|
@@ -1730,6 +1759,10 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1730
1759
|
}
|
|
1731
1760
|
});
|
|
1732
1761
|
eventBus.on('pagerendered', ({ pageNumber }) => {
|
|
1762
|
+
var _a;
|
|
1763
|
+
const page = (_a = pdfViewer.getPageView(pageNumber - 1)) === null || _a === void 0 ? void 0 : _a.div;
|
|
1764
|
+
if (page)
|
|
1765
|
+
bindPageRegions(page);
|
|
1733
1766
|
scheduleLegacyPageDimensionPatch();
|
|
1734
1767
|
if (pdfBoundingBoxController.hasBoxes()) {
|
|
1735
1768
|
void pdfBoundingBoxController.render({ pageNumber, source: 'viewer' });
|
|
@@ -1759,7 +1792,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1759
1792
|
});
|
|
1760
1793
|
});
|
|
1761
1794
|
if (!(context === null || context === void 0 ? void 0 : context.streamUrl) && !buffer.byteLength) {
|
|
1762
|
-
throw
|
|
1795
|
+
throw t.error('pdf.error.missingSource');
|
|
1763
1796
|
}
|
|
1764
1797
|
const pdfAssets = resolveFileViewerPdfAssetUrls(options, pdfRuntimeAssetBaseUrl);
|
|
1765
1798
|
if (cjkFontFallbackEnabled) {
|
|
@@ -1937,7 +1970,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1937
1970
|
return;
|
|
1938
1971
|
}
|
|
1939
1972
|
loadStatus = 'error';
|
|
1940
|
-
errorMessage = error
|
|
1973
|
+
errorMessage = () => normalizeFileViewerErrorMessage(error, context === null || context === void 0 ? void 0 : context.options) || t('pdf.error.loadFailed');
|
|
1941
1974
|
syncUi();
|
|
1942
1975
|
}
|
|
1943
1976
|
};
|
|
@@ -2015,6 +2048,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
2015
2048
|
unmount() {
|
|
2016
2049
|
var _a, _b, _c, _d;
|
|
2017
2050
|
destroyed = true;
|
|
2051
|
+
t.release(root);
|
|
2018
2052
|
disposeReadingTheme();
|
|
2019
2053
|
disposeHandTool();
|
|
2020
2054
|
loadVersion += 1;
|
|
@@ -2035,6 +2069,8 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
2035
2069
|
unregisterFileViewerZoomProvider(root);
|
|
2036
2070
|
unregisterFileViewerViewStateProvider(root);
|
|
2037
2071
|
pdfBoundingBoxController.destroy();
|
|
2072
|
+
void (activeL10n === null || activeL10n === void 0 ? void 0 : activeL10n.destroy());
|
|
2073
|
+
activeL10n = undefined;
|
|
2038
2074
|
outlineItems = [];
|
|
2039
2075
|
(_a = context === null || context === void 0 ? void 0 : context.registerExportAdapter) === null || _a === void 0 ? void 0 : _a.call(context, null);
|
|
2040
2076
|
(_b = context === null || context === void 0 ? void 0 : context.registerThumbnailAdapter) === null || _b === void 0 ? void 0 : _b.call(context, null);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const pdfAnnotationLayerStyle: string;
|