@file-viewer/renderer-pdf 3.1.2 → 3.2.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/README.en.md +3 -53
- package/README.md +3 -53
- package/dist/pdf.js +89 -125
- package/dist/pdfBboxController.js +0 -1
- package/dist/pdfConsoleLifecycle.d.ts +0 -8
- package/dist/pdfConsoleLifecycle.js +0 -8
- package/dist/pdfFit.d.ts +0 -5
- package/dist/pdfFit.js +0 -5
- package/dist/pdfFontFallback.d.ts +0 -5
- package/dist/pdfFontFallback.js +0 -5
- package/dist/pdfHandTool.d.ts +1 -0
- package/dist/pdfHandTool.js +126 -0
- package/dist/pdfIdentityFontName.d.ts +0 -1
- package/dist/pdfIdentityFontName.js +0 -1
- package/dist/pdfIdentityFontRepair.js +0 -1
- package/dist/pdfPageScroll.d.ts +1 -0
- package/dist/pdfPageScroll.js +12 -0
- package/dist/pdfViewState.d.ts +1 -0
- package/dist/pdfViewState.js +1 -0
- package/dist/pdfWorkerGlobal.d.ts +0 -9
- package/dist/pdfWorkerGlobal.js +0 -9
- package/dist/pdfWorkerProbe.d.ts +2 -0
- package/dist/pdfWorkerProbe.js +4 -0
- package/dist/pdfWorkerVersion.d.ts +0 -8
- package/dist/pdfWorkerVersion.js +0 -8
- package/dist/vendor/pdfjs/legacy/build/pdf.mjs +1 -2
- package/dist/vendor/pdfjs/legacy/build/pdf.worker.mjs +1 -2
- package/dist/vendor/pdfjs/legacy/web/pdf_viewer.mjs +1 -2
- package/dist/vendor/pdfjs/provenance.json +7 -7
- package/package.json +247 -21
- package/dist/vendor/pdfjs/patches/pdfjs-dist@5.4.624.patch +0 -112
package/README.en.md
CHANGED
|
@@ -1,57 +1,7 @@
|
|
|
1
1
|
# @file-viewer/renderer-pdf
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Runtime package version 3.2.1.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Usage and API documentation: https://doc.file-viewer.app/guide/on-demand-renderers
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
import FileViewer from '@file-viewer/vue3'
|
|
9
|
-
import { pdfRenderer } from '@file-viewer/renderer-pdf'
|
|
10
|
-
|
|
11
|
-
const options = {
|
|
12
|
-
rendererMode: 'replace',
|
|
13
|
-
renderers: pdfRenderer,
|
|
14
|
-
}
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
You can combine it with other renderer packages:
|
|
18
|
-
|
|
19
|
-
```ts
|
|
20
|
-
const options = {
|
|
21
|
-
rendererMode: 'replace',
|
|
22
|
-
renderers: [pdfRenderer],
|
|
23
|
-
}
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Offline Assets
|
|
27
|
-
|
|
28
|
-
PDF preview depends on the PDF.js worker, cMaps, WASM helpers, standard fonts, and an offline fallback for unembedded CJK fonts. Asset paths use the same unified options as `@file-viewer/core`:
|
|
29
|
-
|
|
30
|
-
```ts
|
|
31
|
-
const options = {
|
|
32
|
-
renderers: pdfRenderer,
|
|
33
|
-
pdf: {
|
|
34
|
-
assetBaseUrl: '/workspace/',
|
|
35
|
-
workerUrl: '/vendor/pdf/pdf.worker.mjs',
|
|
36
|
-
cMapUrl: '/vendor/pdf/cmaps/',
|
|
37
|
-
wasmUrl: '/vendor/pdf/wasm/',
|
|
38
|
-
standardFontDataUrl: '/vendor/pdf/standard_fonts/',
|
|
39
|
-
cjkFontFallbackPath: '/vendor/pdf/fonts/',
|
|
40
|
-
identityFontRepair: true,
|
|
41
|
-
},
|
|
42
|
-
}
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
When no explicit PDF asset URL is configured, the renderer first uses the public base exposed by build tools such as Vite and can fall back to the page entry script. An app deployed under `/workspace/` therefore still requests `/workspace/vendor/pdf/pdf.worker.mjs` while its current SPA route is `/workspace/c/`. UMI, custom proxies, and builds whose public path cannot be detected can set `pdf.assetBaseUrl: '/workspace/'` to pin the base for every PDF offline asset. Before creating a static Worker, the renderer reads the official PDF.js version marker; a stale Worker from an older deployment is rejected and the packaged same-version handler is used instead. If the host app did not run `file-viewer-copy-assets`, does not use `@file-viewer/vite-plugin`, or a local dev server falls back to HTML for that path, the same fallback prevents `Setting up fake worker failed`. For best performance, complete cMap/standard-font/WASM decoding, or strict offline deployments, still copy viewer assets and point these URLs at real static files. The pinned PDF.js 5.4 stable line loads local JBIG2, JPEG 2000, color-management, and related helpers through `wasmUrl`; viewer assets and the Vite plugin copy them without relying on the public internet.
|
|
46
|
-
|
|
47
|
-
`cjkFontFallback` is enabled by default. When a PDF references `MicrosoftYaHei-Bold`, SimSun, SimHei, or another CJK font without embedding the font program, the renderer prefers an installed system font and otherwise aliases the original PDF font name to the local Noto Sans SC variable font supplied by `@file-viewer/assets-standard`. The Vite plugin reuses that standard asset set instead of packing a second font copy into the renderer. Only WOFF2 shards needed by the current page text are loaded. The first page waits for the font before rendering, and later pages are redrawn when they introduce new glyphs. Set the option to `false` to disable this behavior, or point `cjkFontFallbackPath` at a self-hosted directory with the same structure.
|
|
48
|
-
|
|
49
|
-
`identityFontRepair` is also enabled by default for malformed PDFs that write TrueType glyph IDs through `Identity-H`/`Identity-V` but omit `ToUnicode`. The repair module is loaded only after CJK font substitution and multiple control-character glyphs are detected. If the same PDF embeds a usable same-family TrueType font, its cmap is used to rebuild the Unicode mapping for the in-memory preview. The repair is applied only to a preview copy and never overwrites the original file or download source; an unsafe or unsupported repair falls back to the original preview. Set the option to `false` to disable this compatibility path.
|
|
50
|
-
|
|
51
|
-
## Migration Note
|
|
52
|
-
|
|
53
|
-
PDF rendering has moved out of `@file-viewer/core` into this package, and `pdfjs-dist` is now declared only by `@file-viewer/renderer-pdf`. Installing core or a standard component package no longer pulls PDF.js; explicitly assemble this renderer when PDF preview is needed, or use `@file-viewer/preset-all`.
|
|
54
|
-
|
|
55
|
-
The published renderer stages its Apache-2.0 PDF.js runtime under `dist/vendor/pdfjs` and isolates PDF.js' internal webpack bootstrap before packing. `provenance.json` records source hashes after the declared patches, transform counts, and staged output hashes, so webpack 4 consumers do not need a loader for renderer-internal paths.
|
|
56
|
-
|
|
57
|
-
The staged runtime also includes a PDF.js 5.4.624 document-startup cancellation patch. It prevents unhandled promise rejections when switching files during main-thread fallback initialization; active parsing and password errors remain visible. The patch is included under `dist/vendor/pdfjs/patches/` with its hash in `provenance.json`. `pnpm verify:worker-lifecycle` tests cancellation, subsequent rendering, and invalid-file errors in both real and main-thread Workers on Chromium and WebKit.
|
|
7
|
+
The package's own license is Apache-2.0. Included third-party notices apply to their respective components.
|
package/README.md
CHANGED
|
@@ -1,57 +1,7 @@
|
|
|
1
1
|
# @file-viewer/renderer-pdf
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Runtime package version 3.2.1.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Usage and API documentation: https://doc.file-viewer.app/guide/on-demand-renderers
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
import FileViewer from '@file-viewer/vue3'
|
|
9
|
-
import { pdfRenderer } from '@file-viewer/renderer-pdf'
|
|
10
|
-
|
|
11
|
-
const options = {
|
|
12
|
-
rendererMode: 'replace',
|
|
13
|
-
renderers: pdfRenderer,
|
|
14
|
-
}
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
也可以和其他 renderer 一起组合:
|
|
18
|
-
|
|
19
|
-
```ts
|
|
20
|
-
const options = {
|
|
21
|
-
rendererMode: 'replace',
|
|
22
|
-
renderers: [pdfRenderer],
|
|
23
|
-
}
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## 离线资源
|
|
27
|
-
|
|
28
|
-
PDF 预览依赖 PDF.js worker、cMaps、WASM、standard fonts,以及未嵌入中文字体的离线回退资源。资源路径沿用 `@file-viewer/core` 的统一 options:
|
|
29
|
-
|
|
30
|
-
```ts
|
|
31
|
-
const options = {
|
|
32
|
-
renderers: pdfRenderer,
|
|
33
|
-
pdf: {
|
|
34
|
-
assetBaseUrl: '/workspace/',
|
|
35
|
-
workerUrl: '/vendor/pdf/pdf.worker.mjs',
|
|
36
|
-
cMapUrl: '/vendor/pdf/cmaps/',
|
|
37
|
-
wasmUrl: '/vendor/pdf/wasm/',
|
|
38
|
-
standardFontDataUrl: '/vendor/pdf/standard_fonts/',
|
|
39
|
-
cjkFontFallbackPath: '/vendor/pdf/fonts/',
|
|
40
|
-
identityFontRepair: true,
|
|
41
|
-
},
|
|
42
|
-
}
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
默认未显式配置时,渲染器优先使用 Vite 等构建器提供的公开基址,并可从页面入口脚本回退识别部署子路径。因此应用部署在 `/workspace/`、当前 SPA 路由为 `/workspace/c/` 时,仍会请求 `/workspace/vendor/pdf/pdf.worker.mjs`。UMI、自定义代理或无法自动识别的构建环境可以设置 `pdf.assetBaseUrl: '/workspace/'` 固定全部 PDF 离线资源的基址。创建静态 Worker 前会先读取 PDF.js 官方版本标记;若部署目录残留的旧 Worker 与当前 API 不一致,会拒绝旧文件并自动使用包内同版本 handler。项目未执行 `file-viewer-copy-assets`、未使用 `@file-viewer/vite-plugin`,或本地临时服务器把该路径回退成 HTML 时,也会使用同一兜底,避免 `Setting up fake worker failed` 直接中断预览。需要最佳性能、完整 cMap/standard fonts/WASM 解码或严格离线部署时,仍建议复制 viewer assets 并配置真实静态地址。当前锁定的 PDF.js 5.4 稳定线会通过 `wasmUrl` 本地加载 JBIG2、JPEG 2000、颜色管理等辅助资源;这些资源由 viewer assets 和 Vite 插件统一复制,不依赖公网。
|
|
46
|
-
|
|
47
|
-
`cjkFontFallback` 默认开启。PDF 引用了 `MicrosoftYaHei-Bold`、宋体、黑体或其他中文字体但没有嵌入字体数据时,渲染器优先使用本机字体;本机缺失时,会把原 PDF 字体名映射到 `@file-viewer/assets-standard` 提供的本地 Noto Sans SC 可变字体,并根据当前页实际文字只加载需要的 WOFF2 分片。Vite 插件会优先复用这份标准资源,避免在 renderer 中重复打包字体。首屏会在字体就绪后再渲染,后续页发现新字形时会自动重绘。可设为 `false` 完全关闭,或用 `cjkFontFallbackPath` 指向同结构的自托管字体目录。
|
|
48
|
-
|
|
49
|
-
`identityFontRepair` 也默认开启,用于少数把 TrueType 字形 ID 写入 `Identity-H`/`Identity-V`、却遗漏 `ToUnicode` 的异常 PDF。只有检测到中文字体替换和多个控制字符乱码时,渲染器才会懒加载修复模块;若文件内同时嵌入了可用的同族 TrueType 字体,就从其 cmap 重建内存预览所需的 Unicode 映射。修复只作用于预览副本,不覆盖原始文件和下载源;无法安全修复时继续使用原预览。可设为 `false` 关闭。
|
|
50
|
-
|
|
51
|
-
## 迁移说明
|
|
52
|
-
|
|
53
|
-
PDF 渲染已经从 `@file-viewer/core` 移入本包,`pdfjs-dist` 只由 `@file-viewer/renderer-pdf` 声明。只安装 core 或标准组件包时不会再拉取 PDF.js;需要 PDF 预览时请显式装配本 renderer,或使用 `@file-viewer/preset-all`。
|
|
54
|
-
|
|
55
|
-
发布产物会把 Apache-2.0 的 PDF.js runtime 内封到 `dist/vendor/pdfjs`,并在打包前隔离 PDF.js 内部 webpack bootstrap。`provenance.json` 会记录应用声明补丁后的源文件哈希、变换次数和产物哈希,因此 webpack 4 消费项目不需要再为 renderer 内部路径配置 loader。
|
|
56
|
-
|
|
57
|
-
内封运行时还包含 PDF.js 5.4.624 的文档初始化取消补丁,避免快速切换文件时主线程降级路径产生未处理的 Promise 异常;正常解析和密码错误仍会报告。补丁原文保留在 `dist/vendor/pdfjs/patches/`,其哈希记入 `provenance.json`。`pnpm verify:worker-lifecycle` 使用 Chromium/WebKit 分别验证真实 Worker 和主线程降级路径的取消、后续渲染及损坏文件报错。
|
|
7
|
+
The package's own license is Apache-2.0. Included third-party notices apply to their respective components.
|
package/dist/pdf.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { installPdfHandTool } from './pdfHandTool.js';
|
|
2
|
+
import { scrollPdfPageWithinContainer } from './pdfPageScroll.js';
|
|
1
3
|
import { getDocument, GlobalWorkerOptions, PDFWorker as PdfJsWorker, PixelsPerInch, version as pdfJsVersion, } from './vendor/pdfjs/legacy/build/pdf.mjs';
|
|
2
4
|
import { EventBus, GenericL10n, PDFFindController, PDFLinkService, PDFViewer, } from './vendor/pdfjs/legacy/web/pdf_viewer.mjs';
|
|
3
5
|
import { registerFileViewerSearchProvider, registerFileViewerZoomProvider, unregisterFileViewerSearchProvider, unregisterFileViewerZoomProvider, registerFileViewerViewStateProvider, unregisterFileViewerViewStateProvider, createFileViewerZoomChangeEmitter, createFileViewerViewStateChange, createFileViewerViewStateChangeEmitter, createFileViewerTranslator, buildPrintPageStyle, formatCssPixels, DEFAULT_PDF_RANGE_CHUNK_SIZE, resolveFileViewerLocale, resolveFileViewerFitScale, } from '@file-viewer/core';
|
|
@@ -6,9 +8,9 @@ import { pdfViewerStyle } from './pdfStyles.js';
|
|
|
6
8
|
import { collectMalformedIdentityFontNames, createPdfCjkFontFallbackManager, detectMalformedIdentityCjkFontFamilies, } from './pdfFontFallback.js';
|
|
7
9
|
import { PDF_FIT_HORIZONTAL_PADDING, PDF_PAGE_BORDER_WIDTH, resolvePdfFitViewportSize, } from './pdfFit.js';
|
|
8
10
|
import { createPdfBoundingBoxController, } from './pdfBboxController.js';
|
|
9
|
-
import { clampPdfScale, normalizePdfRotation, resolvePdfViewStateUpdate, } from './pdfViewState.js';
|
|
11
|
+
import { clampPdfScale, normalizePdfRotation, resolvePdfPageRotation, resolvePdfViewStateUpdate, } from './pdfViewState.js';
|
|
10
12
|
import { capturePdfJsWorkerGlobal, scopePdfJsWorkerMessageHandler, } from './pdfWorkerGlobal.js';
|
|
11
|
-
import {
|
|
13
|
+
import { hasNativePdfWorkerPort, isPdfWorkerVersionMismatch } from './pdfWorkerProbe.js';
|
|
12
14
|
import { getFileViewerPdfIdentityFontRepair } from './optionalCapabilities.js';
|
|
13
15
|
import { isExpectedPdfJsDestroyConsoleError } from './pdfConsoleLifecycle.js';
|
|
14
16
|
export const DEFAULT_FILE_VIEWER_PDF_WORKER_URL = DEFAULT_FILE_VIEWER_PDF_WORKER_PATH;
|
|
@@ -16,15 +18,9 @@ const MIN_SCALE = 0.2;
|
|
|
16
18
|
const MAX_SCALE = 3;
|
|
17
19
|
const SCALE_STEP = 0.1;
|
|
18
20
|
const PDF_EXPORT_MAX_PAGE_PIXELS = 8000000;
|
|
19
|
-
const PDF_WORKER_PROBE_TIMEOUT_MS = 1200;
|
|
20
|
-
const PDF_WORKER_VERSION_PROBE_BYTES = 4096;
|
|
21
21
|
const PDF_JS_DESTROY_CONSOLE_SUPPRESSION_MS = 1500;
|
|
22
22
|
let bundledPdfWorkerModulePromise = null;
|
|
23
23
|
const scopePdfJsRootVariables = (style) => style.replace(/:root(\s*\{)/g, ':root,\n.pdf-shell$1');
|
|
24
|
-
// PDF.js viewer CSS references image assets that are not shipped with the
|
|
25
|
-
// on-demand renderer chunk, so keep the preview self-contained and 404-free.
|
|
26
|
-
// Its root custom properties also need a local scope: a :root selector inside
|
|
27
|
-
// Shadow DOM does not match the document root or the custom-element host.
|
|
28
24
|
const normalizedPdfViewerStyle = `${scopePdfJsRootVariables(pdfViewerStyle)}
|
|
29
25
|
.pdf-shell{background:var(--file-viewer-render-surface-background,#edf2f7)}
|
|
30
26
|
.pdf-wrapper{background:var(--file-viewer-render-surface-background,#e8edf4)}
|
|
@@ -223,29 +219,12 @@ const suppressPdfJsMissingSystemFontWarnings = (view) => {
|
|
|
223
219
|
const isConfiguredUrl = (value) => {
|
|
224
220
|
return value !== undefined && value !== null && String(value).trim().length > 0;
|
|
225
221
|
};
|
|
226
|
-
const isJavaScriptLikeResponse = (response) => {
|
|
227
|
-
var _a;
|
|
228
|
-
const contentType = ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || '';
|
|
229
|
-
return !contentType ||
|
|
230
|
-
contentType.includes('javascript') ||
|
|
231
|
-
contentType.includes('ecmascript') ||
|
|
232
|
-
contentType.includes('application/octet-stream') ||
|
|
233
|
-
contentType.includes('text/plain');
|
|
234
|
-
};
|
|
235
|
-
const readResponsePrefix = async (response, maximumBytes = PDF_WORKER_VERSION_PROBE_BYTES) => {
|
|
236
|
-
// Consume the response even when a server ignores Range. Cancelling after the
|
|
237
|
-
// prefix creates a browser-level ERR_ABORTED event that strict hosts treat as
|
|
238
|
-
// a failed asset request, despite the compatibility probe succeeding.
|
|
239
|
-
return (await response.text()).slice(0, maximumBytes);
|
|
240
|
-
};
|
|
241
222
|
const loadBundledPdfWorkerModule = async () => {
|
|
242
223
|
bundledPdfWorkerModulePromise !== null && bundledPdfWorkerModulePromise !== void 0 ? bundledPdfWorkerModulePromise : (bundledPdfWorkerModulePromise = import('./vendor/pdfjs/legacy/build/pdf.worker.mjs'));
|
|
243
224
|
return bundledPdfWorkerModulePromise;
|
|
244
225
|
};
|
|
245
226
|
const createBundledPdfFakeWorker = async () => {
|
|
246
227
|
const workerGlobal = globalThis;
|
|
247
|
-
// pdf.worker.mjs assigns globalThis.pdfjsWorker as a module side effect, so
|
|
248
|
-
// capture the host namespace before importing it and restore that snapshot.
|
|
249
228
|
const hostWorkerGlobal = capturePdfJsWorkerGlobal(workerGlobal);
|
|
250
229
|
const workerModule = await loadBundledPdfWorkerModule();
|
|
251
230
|
const workerHandlerScope = scopePdfJsWorkerMessageHandler(workerGlobal, workerModule.WorkerMessageHandler, hostWorkerGlobal);
|
|
@@ -277,7 +256,7 @@ const buildOutlineItems = (items, prefix = 'outline', getFallbackTitle = index =
|
|
|
277
256
|
};
|
|
278
257
|
});
|
|
279
258
|
export default async function renderPdf(buffer, target, context) {
|
|
280
|
-
var _a, _b, _c, _d;
|
|
259
|
+
var _a, _b, _c, _d, _e, _f;
|
|
281
260
|
const documentRef = target.ownerDocument || document;
|
|
282
261
|
const targetWindow = documentRef.defaultView || (typeof window !== 'undefined' ? window : null);
|
|
283
262
|
const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
|
|
@@ -319,6 +298,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
319
298
|
let fitFrame = 0;
|
|
320
299
|
let pageDimensionFrame = 0;
|
|
321
300
|
let destroyed = false;
|
|
301
|
+
const unverifiedWorkers = new WeakSet();
|
|
322
302
|
let loadVersion = 0;
|
|
323
303
|
let viewStateApplyVersion = 0;
|
|
324
304
|
let activeViewStateApplyVersion = 0;
|
|
@@ -425,6 +405,9 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
425
405
|
root.insertBefore(toolbar, content);
|
|
426
406
|
}
|
|
427
407
|
target.replaceChildren(createStyle(documentRef), root);
|
|
408
|
+
const disposeHandTool = ((_e = (_d = context === null || context === void 0 ? void 0 : context.options) === null || _d === void 0 ? void 0 : _d.pdf) === null || _e === void 0 ? void 0 : _e.handTool) === true
|
|
409
|
+
? installPdfHandTool(container)
|
|
410
|
+
: () => { };
|
|
428
411
|
const scaleText = () => `${Math.round(currentScale * 100)}%`;
|
|
429
412
|
const rotationText = () => `${currentRotation}°`;
|
|
430
413
|
const canGoPrevious = () => currentPage > 1;
|
|
@@ -537,14 +520,14 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
537
520
|
await ensurePdfPageCjkFontFallback(pageNumber, page);
|
|
538
521
|
const baseViewport = page.getViewport({
|
|
539
522
|
scale: PixelsPerInch.PDF_TO_CSS_UNITS,
|
|
540
|
-
rotation: currentRotation,
|
|
523
|
+
rotation: resolvePdfPageRotation(page.rotate, currentRotation),
|
|
541
524
|
});
|
|
542
525
|
const deviceScale = Math.min(2, Math.max(1, targetWindow.devicePixelRatio || 1));
|
|
543
526
|
const thumbnailWidth = 46;
|
|
544
527
|
const ratio = Math.min(1, thumbnailWidth / Math.max(baseViewport.width, 1));
|
|
545
528
|
const renderViewport = page.getViewport({
|
|
546
529
|
scale: PixelsPerInch.PDF_TO_CSS_UNITS * ratio * deviceScale,
|
|
547
|
-
rotation: currentRotation,
|
|
530
|
+
rotation: resolvePdfPageRotation(page.rotate, currentRotation),
|
|
548
531
|
});
|
|
549
532
|
const canvas = documentRef.createElement('canvas');
|
|
550
533
|
const canvasContext = canvas.getContext('2d');
|
|
@@ -583,9 +566,9 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
583
566
|
}
|
|
584
567
|
const page = await pdfDocument.getPage(1);
|
|
585
568
|
await ensurePdfPageCjkFontFallback(1, page);
|
|
586
|
-
const baseViewport = page.getViewport({ scale: 1, rotation: currentRotation });
|
|
569
|
+
const baseViewport = page.getViewport({ scale: 1, rotation: resolvePdfPageRotation(page.rotate, currentRotation) });
|
|
587
570
|
const scale = Math.max(0.1, Math.min(captureOptions.width / Math.max(baseViewport.width, 1), captureOptions.height / Math.max(baseViewport.height, 1)));
|
|
588
|
-
const viewport = page.getViewport({ scale, rotation: currentRotation });
|
|
571
|
+
const viewport = page.getViewport({ scale, rotation: resolvePdfPageRotation(page.rotate, currentRotation) });
|
|
589
572
|
const canvas = documentRef.createElement('canvas');
|
|
590
573
|
const canvasContext = canvas.getContext('2d');
|
|
591
574
|
if (!canvasContext) {
|
|
@@ -616,7 +599,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
616
599
|
(_f = page.cleanup) === null || _f === void 0 ? void 0 : _f.call(page);
|
|
617
600
|
}
|
|
618
601
|
};
|
|
619
|
-
(
|
|
602
|
+
(_f = context === null || context === void 0 ? void 0 : context.registerThumbnailAdapter) === null || _f === void 0 ? void 0 : _f.call(context, {
|
|
620
603
|
beforeCapture: async ({ signal }) => {
|
|
621
604
|
while (loadStatus === 'loading' && !destroyed) {
|
|
622
605
|
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
@@ -717,89 +700,26 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
717
700
|
targetWindow.requestAnimationFrame(writeLegacyCompatiblePageDimensions);
|
|
718
701
|
});
|
|
719
702
|
};
|
|
720
|
-
const probeResolvedPdfWorkerUrl = async (workerUrl) => {
|
|
721
|
-
var _a, _b;
|
|
722
|
-
const fetcher = ((_a = targetWindow.fetch) === null || _a === void 0 ? void 0 : _a.bind(targetWindow)) || ((_b = globalThis.fetch) === null || _b === void 0 ? void 0 : _b.bind(globalThis));
|
|
723
|
-
const AbortControllerCtor = targetWindow.AbortController || globalThis.AbortController;
|
|
724
|
-
if (!fetcher || !AbortControllerCtor) {
|
|
725
|
-
return { status: 'unavailable', workerVersion: null };
|
|
726
|
-
}
|
|
727
|
-
try {
|
|
728
|
-
const parsed = new URL(workerUrl, documentRef.baseURI || targetWindow.location.href);
|
|
729
|
-
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
730
|
-
return { status: 'unavailable', workerVersion: null };
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
catch {
|
|
734
|
-
return { status: 'unavailable', workerVersion: null };
|
|
735
|
-
}
|
|
736
|
-
const controller = new AbortControllerCtor();
|
|
737
|
-
const timer = targetWindow.setTimeout(() => controller.abort(), PDF_WORKER_PROBE_TIMEOUT_MS);
|
|
738
|
-
try {
|
|
739
|
-
const response = await fetcher(workerUrl, {
|
|
740
|
-
method: 'GET',
|
|
741
|
-
// A successful range probe must never seed the HTTP cache for the
|
|
742
|
-
// subsequent module Worker request. Some static servers correctly
|
|
743
|
-
// return 206 here, and Chromium can otherwise reuse that partial body
|
|
744
|
-
// as the Worker module, which fails with "Invalid or unexpected token".
|
|
745
|
-
cache: 'no-store',
|
|
746
|
-
headers: {
|
|
747
|
-
Range: `bytes=0-${PDF_WORKER_VERSION_PROBE_BYTES - 1}`,
|
|
748
|
-
},
|
|
749
|
-
signal: controller.signal,
|
|
750
|
-
});
|
|
751
|
-
if ((!response.ok && response.status !== 206) || !isJavaScriptLikeResponse(response)) {
|
|
752
|
-
return { status: 'unavailable', workerVersion: null };
|
|
753
|
-
}
|
|
754
|
-
const workerVersion = readPdfJsWorkerVersion(await readResponsePrefix(response));
|
|
755
|
-
if (!workerVersion) {
|
|
756
|
-
return { status: 'unknown', workerVersion: null };
|
|
757
|
-
}
|
|
758
|
-
return {
|
|
759
|
-
status: workerVersion === pdfJsVersion ? 'compatible' : 'incompatible',
|
|
760
|
-
workerVersion,
|
|
761
|
-
};
|
|
762
|
-
}
|
|
763
|
-
catch {
|
|
764
|
-
return { status: 'unavailable', workerVersion: null };
|
|
765
|
-
}
|
|
766
|
-
finally {
|
|
767
|
-
targetWindow.clearTimeout(timer);
|
|
768
|
-
}
|
|
769
|
-
};
|
|
770
703
|
const createPdfWorker = async () => {
|
|
771
704
|
var _a;
|
|
772
705
|
const workerUrl = resolvePdfWorkerUrl(options, pdfRuntimeAssetBaseUrl);
|
|
773
706
|
const workerGlobal = globalThis;
|
|
774
707
|
if ((_a = workerGlobal.pdfjsWorker) === null || _a === void 0 ? void 0 : _a.WorkerMessageHandler) {
|
|
775
708
|
try {
|
|
776
|
-
// PDF.js prefers a preinstalled main-thread handler over workerSrc.
|
|
777
|
-
// Scope our bundled handler only until this PDFWorker captures it, so
|
|
778
|
-
// a vue-office/PDF.js 3.x global cannot hijack this renderer and the
|
|
779
|
-
// host can still use its original handler afterwards.
|
|
780
709
|
return await createBundledPdfFakeWorker();
|
|
781
710
|
}
|
|
782
711
|
catch (error) {
|
|
783
712
|
console.warn('[file-viewer] PDF.js 全局 Worker handler 隔离失败,继续探测静态 Worker。', error);
|
|
784
713
|
}
|
|
785
714
|
}
|
|
786
|
-
|
|
787
|
-
const workerProbe = (targetWindow === null || targetWindow === void 0 ? void 0 : targetWindow.Worker)
|
|
788
|
-
? await probeResolvedPdfWorkerUrl(workerUrl)
|
|
789
|
-
: { status: 'unavailable', workerVersion: null };
|
|
790
|
-
if (workerProbe.status === 'incompatible') {
|
|
791
|
-
console.warn(`[file-viewer] PDF Worker ${workerProbe.workerVersion} 与 PDF.js API ${pdfJsVersion} 不匹配,` +
|
|
792
|
-
'改用包内同版本 PDF.js handler。');
|
|
793
|
-
}
|
|
794
|
-
const shouldUseRealWorker = !!(targetWindow === null || targetWindow === void 0 ? void 0 : targetWindow.Worker) && (workerProbe.status === 'compatible' ||
|
|
795
|
-
(hasExplicitWorkerUrl && workerProbe.status === 'unknown'));
|
|
796
|
-
if (shouldUseRealWorker) {
|
|
715
|
+
if (targetWindow.Worker) {
|
|
797
716
|
GlobalWorkerOptions.workerSrc = workerUrl;
|
|
798
717
|
try {
|
|
799
718
|
const worker = new PdfJsWorker({
|
|
800
719
|
name: 'file-viewer-pdf-worker',
|
|
801
720
|
});
|
|
802
721
|
await worker.promise;
|
|
722
|
+
unverifiedWorkers.add(worker);
|
|
803
723
|
return worker;
|
|
804
724
|
}
|
|
805
725
|
catch (error) {
|
|
@@ -1029,6 +949,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1029
949
|
}
|
|
1030
950
|
autoFitWidth = false;
|
|
1031
951
|
activeFitRequest = null;
|
|
952
|
+
pendingFitRequest = null;
|
|
1032
953
|
};
|
|
1033
954
|
const getPdfPageElement = (pageNumber) => {
|
|
1034
955
|
var _a;
|
|
@@ -1188,9 +1109,6 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1188
1109
|
if (update.page !== undefined) {
|
|
1189
1110
|
goToPage(update.page, 'page-change', source, false);
|
|
1190
1111
|
}
|
|
1191
|
-
// A remote presenter can send scroll snapshots faster than one animation
|
|
1192
|
-
// frame. Apply the latest offset before yielding so superseded promises
|
|
1193
|
-
// cannot starve the projected screen until the presenter stops scrolling.
|
|
1194
1112
|
restoreScrollState(state.scroll, false);
|
|
1195
1113
|
await waitForPaint(targetWindow);
|
|
1196
1114
|
if (applyVersion !== viewStateApplyVersion) {
|
|
@@ -1256,7 +1174,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1256
1174
|
if (pdfPage) {
|
|
1257
1175
|
const viewportAtScaleOne = pdfPage.getViewport({
|
|
1258
1176
|
scale: PixelsPerInch.PDF_TO_CSS_UNITS,
|
|
1259
|
-
rotation: currentRotation,
|
|
1177
|
+
rotation: resolvePdfPageRotation(pdfPage.rotate, currentRotation),
|
|
1260
1178
|
});
|
|
1261
1179
|
return {
|
|
1262
1180
|
width: viewportAtScaleOne.width,
|
|
@@ -1276,6 +1194,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1276
1194
|
const getPageWidthAtScaleOne = (pdfViewer) => {
|
|
1277
1195
|
return getPageSizeAtScaleOne(pdfViewer).width;
|
|
1278
1196
|
};
|
|
1197
|
+
const hasMeasurableViewport = () => container.clientWidth > 0 && container.clientHeight > 0;
|
|
1279
1198
|
const getFitWidthScale = (pdfViewer) => {
|
|
1280
1199
|
const pageWidth = getPageWidthAtScaleOne(pdfViewer);
|
|
1281
1200
|
const containerWidth = container.clientWidth || targetWindow.innerWidth;
|
|
@@ -1290,6 +1209,9 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1290
1209
|
userScrollIntentUntil = 0;
|
|
1291
1210
|
suppressProgrammaticScrollEvents();
|
|
1292
1211
|
autoFitWidth = true;
|
|
1212
|
+
if (!hasMeasurableViewport()) {
|
|
1213
|
+
return;
|
|
1214
|
+
}
|
|
1293
1215
|
setScale(getFitWidthScale(pdfContext.viewer), 'zoom-reset', source, notifyViewState);
|
|
1294
1216
|
void waitForPaint(targetWindow).then(() => {
|
|
1295
1217
|
var _a;
|
|
@@ -1301,8 +1223,8 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1301
1223
|
cancelPendingUserZoomRestore();
|
|
1302
1224
|
userScrollIntentUntil = 0;
|
|
1303
1225
|
activeFitRequest = { ...request };
|
|
1304
|
-
if (!pdfContext.viewer || loadStatus !== 'ready') {
|
|
1305
|
-
pendingFitRequest = request;
|
|
1226
|
+
if (!pdfContext.viewer || loadStatus !== 'ready' || !hasMeasurableViewport()) {
|
|
1227
|
+
pendingFitRequest = { ...request };
|
|
1306
1228
|
return {
|
|
1307
1229
|
applied: false,
|
|
1308
1230
|
mode: request.mode,
|
|
@@ -1312,6 +1234,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1312
1234
|
provider: 'view-state',
|
|
1313
1235
|
};
|
|
1314
1236
|
}
|
|
1237
|
+
pendingFitRequest = null;
|
|
1315
1238
|
const pageSize = getPageSizeAtScaleOne(pdfContext.viewer);
|
|
1316
1239
|
const mode = request.mode === 'auto' ? 'width' : request.mode;
|
|
1317
1240
|
const fitViewport = resolvePdfFitViewportSize({
|
|
@@ -1323,9 +1246,6 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1323
1246
|
});
|
|
1324
1247
|
const scale = resolveFileViewerFitScale({
|
|
1325
1248
|
mode,
|
|
1326
|
-
// The core request measures the whole viewer root. PDF's scroll
|
|
1327
|
-
// container is the actual visible document area after the navigation
|
|
1328
|
-
// pane, so prefer it whenever it has been laid out.
|
|
1329
1249
|
viewportWidth: fitViewport.width,
|
|
1330
1250
|
viewportHeight: fitViewport.height,
|
|
1331
1251
|
contentWidth: pageSize.width,
|
|
@@ -1368,10 +1288,10 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1368
1288
|
};
|
|
1369
1289
|
};
|
|
1370
1290
|
const scheduleFitAfterResize = () => {
|
|
1371
|
-
if (!pdfContext.viewer) {
|
|
1291
|
+
if (destroyed || !pdfContext.viewer || !hasMeasurableViewport()) {
|
|
1372
1292
|
return;
|
|
1373
1293
|
}
|
|
1374
|
-
if ((activeFitRequest === null || activeFitRequest === void 0 ? void 0 : activeFitRequest.resize) === 'initial') {
|
|
1294
|
+
if ((activeFitRequest === null || activeFitRequest === void 0 ? void 0 : activeFitRequest.resize) === 'initial' && !pendingFitRequest) {
|
|
1375
1295
|
return;
|
|
1376
1296
|
}
|
|
1377
1297
|
if (!activeFitRequest && !autoFitWidth) {
|
|
@@ -1379,6 +1299,10 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1379
1299
|
}
|
|
1380
1300
|
targetWindow.cancelAnimationFrame(fitFrame);
|
|
1381
1301
|
fitFrame = targetWindow.requestAnimationFrame(() => {
|
|
1302
|
+
fitFrame = 0;
|
|
1303
|
+
if (destroyed || !hasMeasurableViewport()) {
|
|
1304
|
+
return;
|
|
1305
|
+
}
|
|
1382
1306
|
if (activeFitRequest) {
|
|
1383
1307
|
void applyPdfFit({ ...activeFitRequest, source: 'viewer' });
|
|
1384
1308
|
return;
|
|
@@ -1502,7 +1426,12 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1502
1426
|
markFitInteraction(source);
|
|
1503
1427
|
const nextPage = Math.min(pageCount, Math.max(1, pageNumber));
|
|
1504
1428
|
runWithStableHorizontalScroll(() => {
|
|
1429
|
+
var _a;
|
|
1505
1430
|
pdfContext.viewer.currentPageNumber = nextPage;
|
|
1431
|
+
const page = ((_a = pdfContext.viewer.getPageView(nextPage - 1)) === null || _a === void 0 ? void 0 : _a.div)
|
|
1432
|
+
|| pdfViewerRoot.querySelector(`.page[data-page-number="${nextPage}"]`);
|
|
1433
|
+
if (scrollPdfPageWithinContainer(container, page))
|
|
1434
|
+
pdfContext.viewer.update();
|
|
1506
1435
|
currentPage = nextPage;
|
|
1507
1436
|
syncUi();
|
|
1508
1437
|
if (notifyViewState) {
|
|
@@ -1602,18 +1531,27 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1602
1531
|
const page = await pdfDocument.getPage(Math.min(Math.max(pageNumber, 1), pdfDocument.numPages));
|
|
1603
1532
|
const viewport = page.getViewport({
|
|
1604
1533
|
scale: PixelsPerInch.PDF_TO_CSS_UNITS,
|
|
1605
|
-
rotation: currentRotation,
|
|
1534
|
+
rotation: resolvePdfPageRotation(page.rotate, currentRotation),
|
|
1606
1535
|
});
|
|
1607
1536
|
(_b = (_a = page).cleanup) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
1608
1537
|
return {
|
|
1609
|
-
width:
|
|
1610
|
-
height:
|
|
1538
|
+
width: viewport.width,
|
|
1539
|
+
height: viewport.height,
|
|
1611
1540
|
};
|
|
1612
1541
|
};
|
|
1613
1542
|
const buildPdfPrintStyle = async () => {
|
|
1614
|
-
|
|
1543
|
+
var _a;
|
|
1544
|
+
const sizes = [];
|
|
1545
|
+
const count = ((_a = pdfContext.document) === null || _a === void 0 ? void 0 : _a.numPages) || 1;
|
|
1546
|
+
for (let number = 1; number <= count; number += 1) {
|
|
1547
|
+
if (destroyed)
|
|
1548
|
+
throw new Error(t('pdf.error.unloaded'));
|
|
1549
|
+
sizes.push(await getPdfPrintPageSize(number));
|
|
1550
|
+
}
|
|
1551
|
+
const size = sizes[0];
|
|
1615
1552
|
return buildPrintPageStyle({
|
|
1616
1553
|
selector: '.viewer-export-content .pdf-export-page',
|
|
1554
|
+
pages: sizes,
|
|
1617
1555
|
width: size.width,
|
|
1618
1556
|
height: size.height,
|
|
1619
1557
|
});
|
|
@@ -1633,14 +1571,14 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1633
1571
|
await ensurePdfPageCjkFontFallback(pageNumber, page);
|
|
1634
1572
|
const baseViewport = page.getViewport({
|
|
1635
1573
|
scale: PixelsPerInch.PDF_TO_CSS_UNITS,
|
|
1636
|
-
rotation: currentRotation,
|
|
1574
|
+
rotation: resolvePdfPageRotation(page.rotate, currentRotation),
|
|
1637
1575
|
});
|
|
1638
|
-
const pageWidth =
|
|
1639
|
-
const pageHeight =
|
|
1576
|
+
const pageWidth = baseViewport.width;
|
|
1577
|
+
const pageHeight = baseViewport.height;
|
|
1640
1578
|
const exportRatio = getPdfExportRatio(baseViewport.width, baseViewport.height, exportOptions.mode);
|
|
1641
1579
|
const renderViewport = page.getViewport({
|
|
1642
1580
|
scale: PixelsPerInch.PDF_TO_CSS_UNITS * exportRatio,
|
|
1643
|
-
rotation: currentRotation,
|
|
1581
|
+
rotation: resolvePdfPageRotation(page.rotate, currentRotation),
|
|
1644
1582
|
});
|
|
1645
1583
|
const canvas = documentRef.createElement('canvas');
|
|
1646
1584
|
const canvasContext = canvas.getContext('2d');
|
|
@@ -1820,24 +1758,52 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1820
1758
|
: {
|
|
1821
1759
|
data: buffer,
|
|
1822
1760
|
};
|
|
1823
|
-
const createLoadingResource = async (loadingSource) => {
|
|
1824
|
-
const worker = await createPdfWorker();
|
|
1761
|
+
const createLoadingResource = async (loadingSource, bundledFallback = false) => {
|
|
1762
|
+
const worker = bundledFallback ? await createBundledPdfFakeWorker() : await createPdfWorker();
|
|
1763
|
+
const fallbackSource = worker && unverifiedWorkers.has(worker)
|
|
1764
|
+
? ('data' in loadingSource ? { data: loadingSource.data.slice(0) } : loadingSource)
|
|
1765
|
+
: undefined;
|
|
1825
1766
|
const loadingTask = getDocument({
|
|
1826
1767
|
...loadingSource,
|
|
1827
1768
|
worker: worker || undefined,
|
|
1828
1769
|
cMapUrl: pdfAssets.cMapUrl,
|
|
1829
1770
|
wasmUrl: pdfAssets.wasmUrl,
|
|
1830
1771
|
standardFontDataUrl: pdfAssets.standardFontDataUrl,
|
|
1831
|
-
useWorkerFetch:
|
|
1772
|
+
useWorkerFetch: hasNativePdfWorkerPort(worker === null || worker === void 0 ? void 0 : worker.port, [globalThis.Worker, targetWindow.Worker]),
|
|
1832
1773
|
cMapPacked: true,
|
|
1833
1774
|
enableXfa: true,
|
|
1834
1775
|
fontExtraProperties: fontInspectionEnabled,
|
|
1835
1776
|
});
|
|
1836
|
-
return { loadingTask, worker };
|
|
1777
|
+
return { loadingTask, worker, fallbackSource };
|
|
1778
|
+
};
|
|
1779
|
+
const resolveLoadingDocument = async (currentResource) => {
|
|
1780
|
+
try {
|
|
1781
|
+
return await currentResource.loadingTask.promise;
|
|
1782
|
+
}
|
|
1783
|
+
catch (error) {
|
|
1784
|
+
const retrySource = currentResource.fallbackSource;
|
|
1785
|
+
if (!retrySource || !isPdfWorkerVersionMismatch(error, pdfJsVersion) ||
|
|
1786
|
+
destroyed || requestVersion !== loadVersion)
|
|
1787
|
+
throw error;
|
|
1788
|
+
console.warn(`[file-viewer] PDF Worker 版本不匹配,改用包内同版本 PDF.js ${pdfJsVersion}。`);
|
|
1789
|
+
await destroyPdfResource(currentResource);
|
|
1790
|
+
if (destroyed || requestVersion !== loadVersion)
|
|
1791
|
+
throw error;
|
|
1792
|
+
const replacement = await createLoadingResource(retrySource, true);
|
|
1793
|
+
Object.assign(currentResource, replacement);
|
|
1794
|
+
if (destroyed || requestVersion !== loadVersion) {
|
|
1795
|
+
await destroyPdfResource(currentResource);
|
|
1796
|
+
throw error;
|
|
1797
|
+
}
|
|
1798
|
+
return await currentResource.loadingTask.promise;
|
|
1799
|
+
}
|
|
1800
|
+
finally {
|
|
1801
|
+
delete currentResource.fallbackSource;
|
|
1802
|
+
}
|
|
1837
1803
|
};
|
|
1838
1804
|
resource = await createLoadingResource(source);
|
|
1839
1805
|
pdfContext.resource = resource;
|
|
1840
|
-
let pdfDocument = await resource
|
|
1806
|
+
let pdfDocument = await resolveLoadingDocument(resource);
|
|
1841
1807
|
if (destroyed || requestVersion !== loadVersion || pdfContext.resource !== resource) {
|
|
1842
1808
|
if (pdfContext.resource === resource) {
|
|
1843
1809
|
pdfContext.resource = null;
|
|
@@ -1866,7 +1832,6 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1866
1832
|
}
|
|
1867
1833
|
}
|
|
1868
1834
|
catch {
|
|
1869
|
-
// A font object that is still unresolved cannot be repaired safely.
|
|
1870
1835
|
}
|
|
1871
1836
|
}
|
|
1872
1837
|
const candidateFamilies = detectMalformedIdentityCjkFontFamilies(firstPageTextContent, fontName => malformedFontFamilies.get(fontName) || '');
|
|
@@ -1882,7 +1847,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1882
1847
|
if (repaired.repairedFonts > 0) {
|
|
1883
1848
|
const previousResource = resource;
|
|
1884
1849
|
replacementResource = await createLoadingResource({ data: repaired.bytes });
|
|
1885
|
-
const replacementDocument = await replacementResource
|
|
1850
|
+
const replacementDocument = await resolveLoadingDocument(replacementResource);
|
|
1886
1851
|
const repairedFirstPage = await replacementDocument.getPage(1);
|
|
1887
1852
|
const replacementTextContent = await repairedFirstPage.getTextContent();
|
|
1888
1853
|
if (destroyed ||
|
|
@@ -1998,6 +1963,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1998
1963
|
zoomInButton.addEventListener('click', () => zoomIn('user'));
|
|
1999
1964
|
scaleButton.addEventListener('click', () => {
|
|
2000
1965
|
activeFitRequest = null;
|
|
1966
|
+
pendingFitRequest = null;
|
|
2001
1967
|
fitToWidth('user');
|
|
2002
1968
|
});
|
|
2003
1969
|
rotateLeftButton.addEventListener('click', () => applyRotation(currentRotation - 90, 'rotate-left', 'user'));
|
|
@@ -2016,9 +1982,6 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
2016
1982
|
});
|
|
2017
1983
|
resizeObserver.observe(container);
|
|
2018
1984
|
}
|
|
2019
|
-
// PDFViewer writes this value to documentElement, which cannot safely model
|
|
2020
|
-
// multiple differently-sized viewers. Keep a live shell-local value as well
|
|
2021
|
-
// so Shadow DOM and multi-instance layouts both resolve the dummy-page height.
|
|
2022
1985
|
root.style.setProperty('--viewer-container-height', `${container.clientHeight}px`);
|
|
2023
1986
|
syncUi();
|
|
2024
1987
|
void loadFile();
|
|
@@ -2027,6 +1990,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
2027
1990
|
unmount() {
|
|
2028
1991
|
var _a, _b, _c, _d;
|
|
2029
1992
|
destroyed = true;
|
|
1993
|
+
disposeHandTool();
|
|
2030
1994
|
loadVersion += 1;
|
|
2031
1995
|
restorePdfJsMissingSystemFontWarnings();
|
|
2032
1996
|
restorePdfJsMissingSystemFontWarnings = () => { };
|
|
@@ -117,7 +117,6 @@ export const createPdfBoundingBoxController = ({ documentRef, targetWindow, view
|
|
|
117
117
|
if (focus && page === focusPage) {
|
|
118
118
|
await waitForPaint(targetWindow);
|
|
119
119
|
focusNodes(pageNode, nodes);
|
|
120
|
-
// PDF.js can settle dimensions one frame after fit or rotation.
|
|
121
120
|
await waitForPaint(targetWindow);
|
|
122
121
|
focusNodes(pageNode, nodes);
|
|
123
122
|
}
|
|
@@ -1,9 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PDF.js can finish an already queued page task after File Viewer has started
|
|
3
|
-
* tearing the document down. A queued `forceRendering` callback can also run
|
|
4
|
-
* after PDFViewer has reset its old page views and report that the old
|
|
5
|
-
* `pdfPage` is no longer loaded. Only silence those exact message/reason pairs
|
|
6
|
-
* inside File Viewer's scoped teardown window. All parsing, rendering, worker
|
|
7
|
-
* and network errors remain visible.
|
|
8
|
-
*/
|
|
9
1
|
export declare const isExpectedPdfJsDestroyConsoleError: (args: unknown[]) => boolean;
|
|
@@ -10,14 +10,6 @@ const readErrorLikeMessage = (value) => {
|
|
|
10
10
|
const isPdfJsDestroyLifecycleMessage = (message) => /^Unable to get page \d+ to initialize viewer$/.test(message) ||
|
|
11
11
|
message === 'Unable to get page for page view' ||
|
|
12
12
|
message === 'renderView:';
|
|
13
|
-
/**
|
|
14
|
-
* PDF.js can finish an already queued page task after File Viewer has started
|
|
15
|
-
* tearing the document down. A queued `forceRendering` callback can also run
|
|
16
|
-
* after PDFViewer has reset its old page views and report that the old
|
|
17
|
-
* `pdfPage` is no longer loaded. Only silence those exact message/reason pairs
|
|
18
|
-
* inside File Viewer's scoped teardown window. All parsing, rendering, worker
|
|
19
|
-
* and network errors remain visible.
|
|
20
|
-
*/
|
|
21
13
|
export const isExpectedPdfJsDestroyConsoleError = (args) => {
|
|
22
14
|
const [message, reason] = args;
|
|
23
15
|
if (typeof message !== 'string' || !isPdfJsDestroyLifecycleMessage(message)) {
|
package/dist/pdfFit.d.ts
CHANGED
|
@@ -9,11 +9,6 @@ export interface ResolvePdfFitViewportSizeInput {
|
|
|
9
9
|
fallbackHeight: number;
|
|
10
10
|
request: Pick<FileViewerFitRequest, 'viewportWidth' | 'viewportHeight' | 'padding'>;
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
13
|
-
* Resolves the PDF page viewport after the navigation pane has been laid out.
|
|
14
|
-
* Core request dimensions already exclude fit.padding; live container and
|
|
15
|
-
* window fallback dimensions do not, so only those branches subtract it.
|
|
16
|
-
*/
|
|
17
12
|
export declare const resolvePdfFitViewportSize: ({ containerWidth, containerHeight, fallbackWidth, fallbackHeight, request, }: ResolvePdfFitViewportSizeInput) => {
|
|
18
13
|
width: number;
|
|
19
14
|
height: number;
|