@file-viewer/renderer-pdf 3.0.1 → 3.0.3

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 CHANGED
@@ -52,4 +52,6 @@ When no explicit PDF asset URL is configured, the renderer first uses the public
52
52
 
53
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
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 each upstream source hash, transform count, and staged output hash, so webpack 4 consumers do not need a loader for renderer-internal paths.
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.
package/README.md CHANGED
@@ -52,4 +52,6 @@ const options = {
52
52
 
53
53
  PDF 渲染已经从 `@file-viewer/core` 移入本包,`pdfjs-dist` 只由 `@file-viewer/renderer-pdf` 声明。只安装 core 或标准组件包时不会再拉取 PDF.js;需要 PDF 预览时请显式装配本 renderer,或使用 `@file-viewer/preset-all`。
54
54
 
55
- 发布产物会把 Apache-2.0 的 PDF.js runtime 内封到 `dist/vendor/pdfjs`,并在打包前隔离 PDF.js 内部 webpack bootstrap。`provenance.json` 会记录每个上游源文件哈希、变换次数和产物哈希,因此 webpack 4 消费项目不需要再为 renderer 内部路径配置 loader。
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 和主线程降级路径的取消、后续渲染及损坏文件报错。
@@ -66847,15 +66847,21 @@ class WorkerMessageHandler {
66847
66847
  };
66848
66848
  return pdfManagerCapability.promise;
66849
66849
  }
66850
+ // File Viewer modification: canceled initialization must not reject detached
66851
+ // startup promises or send messages through an already destroyed handler.
66850
66852
  function setupDoc(data) {
66851
66853
  function onSuccess(doc) {
66852
- ensureNotTerminated();
66854
+ if (terminated) {
66855
+ return;
66856
+ }
66853
66857
  handler.send("GetDoc", {
66854
66858
  pdfInfo: doc
66855
66859
  });
66856
66860
  }
66857
66861
  function onFailure(ex) {
66858
- ensureNotTerminated();
66862
+ if (terminated) {
66863
+ return;
66864
+ }
66859
66865
  if (ex instanceof PasswordException) {
66860
66866
  const task = new WorkerTask(`PasswordException: response ${ex.code}`);
66861
66867
  startWorkerTask(task);
@@ -66863,43 +66869,67 @@ class WorkerMessageHandler {
66863
66869
  password
66864
66870
  }) {
66865
66871
  finishWorkerTask(task);
66872
+ if (terminated) {
66873
+ return;
66874
+ }
66866
66875
  pdfManager.updatePassword(password);
66867
66876
  pdfManagerReady();
66868
66877
  }).catch(function () {
66869
66878
  finishWorkerTask(task);
66879
+ if (terminated) {
66880
+ return;
66881
+ }
66870
66882
  handler.send("DocException", ex);
66871
66883
  });
66872
66884
  } else {
66873
66885
  handler.send("DocException", wrapReason(ex));
66874
66886
  }
66875
66887
  }
66876
- function pdfManagerReady() {
66877
- ensureNotTerminated();
66878
- loadDocument(false).then(onSuccess, function (reason) {
66879
- ensureNotTerminated();
66880
- if (!(reason instanceof XRefParseException)) {
66881
- onFailure(reason);
66882
- return;
66888
+ async function pdfManagerReady() {
66889
+ if (terminated) {
66890
+ return;
66891
+ }
66892
+ try {
66893
+ let doc;
66894
+ try {
66895
+ doc = await loadDocument(false);
66896
+ } catch (reason) {
66897
+ if (terminated) {
66898
+ return;
66899
+ }
66900
+ if (!(reason instanceof XRefParseException)) {
66901
+ throw reason;
66902
+ }
66903
+ await pdfManager.requestLoadedStream();
66904
+ if (terminated) {
66905
+ return;
66906
+ }
66907
+ doc = await loadDocument(true);
66883
66908
  }
66884
- pdfManager.requestLoadedStream().then(function () {
66885
- ensureNotTerminated();
66886
- loadDocument(true).then(onSuccess, onFailure);
66887
- });
66888
- });
66909
+ onSuccess(doc);
66910
+ } catch (reason) {
66911
+ onFailure(reason);
66912
+ }
66913
+ }
66914
+ if (terminated) {
66915
+ return;
66889
66916
  }
66890
- ensureNotTerminated();
66891
66917
  getPdfManager(data).then(function (newPdfManager) {
66892
66918
  if (terminated) {
66893
66919
  newPdfManager.terminate(new AbortException("Worker was terminated."));
66894
- throw new Error("Worker was terminated");
66920
+ return;
66895
66921
  }
66896
66922
  pdfManager = newPdfManager;
66897
66923
  pdfManager.requestLoadedStream(true).then(stream => {
66924
+ if (terminated) {
66925
+ return;
66926
+ }
66898
66927
  handler.send("DataLoaded", {
66899
66928
  length: stream.bytes.byteLength
66900
66929
  });
66901
- });
66902
- }).then(pdfManagerReady, onFailure);
66930
+ }, onFailure);
66931
+ return pdfManagerReady();
66932
+ }).catch(onFailure);
66903
66933
  }
66904
66934
  handler.on("GetPage", function (data) {
66905
66935
  return pdfManager.getPage(data.pageIndex).then(function (page) {
@@ -0,0 +1,112 @@
1
+ diff --git a/legacy/build/pdf.worker.mjs b/legacy/build/pdf.worker.mjs
2
+ index b7416c415e6490b16f642562003f54e78ab345f8..d2070ba6f1ecaaa5659977ef5ac577ee89195e75 100644
3
+ --- a/legacy/build/pdf.worker.mjs
4
+ +++ b/legacy/build/pdf.worker.mjs
5
+ @@ -66846,15 +66846,21 @@ class WorkerMessageHandler {
6
+ };
7
+ return pdfManagerCapability.promise;
8
+ }
9
+ + // File Viewer modification: canceled initialization must not reject detached
10
+ + // startup promises or send messages through an already destroyed handler.
11
+ function setupDoc(data) {
12
+ function onSuccess(doc) {
13
+ - ensureNotTerminated();
14
+ + if (terminated) {
15
+ + return;
16
+ + }
17
+ handler.send("GetDoc", {
18
+ pdfInfo: doc
19
+ });
20
+ }
21
+ function onFailure(ex) {
22
+ - ensureNotTerminated();
23
+ + if (terminated) {
24
+ + return;
25
+ + }
26
+ if (ex instanceof PasswordException) {
27
+ const task = new WorkerTask(`PasswordException: response ${ex.code}`);
28
+ startWorkerTask(task);
29
+ @@ -66862,43 +66868,67 @@ class WorkerMessageHandler {
30
+ password
31
+ }) {
32
+ finishWorkerTask(task);
33
+ + if (terminated) {
34
+ + return;
35
+ + }
36
+ pdfManager.updatePassword(password);
37
+ pdfManagerReady();
38
+ }).catch(function () {
39
+ finishWorkerTask(task);
40
+ + if (terminated) {
41
+ + return;
42
+ + }
43
+ handler.send("DocException", ex);
44
+ });
45
+ } else {
46
+ handler.send("DocException", wrapReason(ex));
47
+ }
48
+ }
49
+ - function pdfManagerReady() {
50
+ - ensureNotTerminated();
51
+ - loadDocument(false).then(onSuccess, function (reason) {
52
+ - ensureNotTerminated();
53
+ - if (!(reason instanceof XRefParseException)) {
54
+ - onFailure(reason);
55
+ - return;
56
+ + async function pdfManagerReady() {
57
+ + if (terminated) {
58
+ + return;
59
+ + }
60
+ + try {
61
+ + let doc;
62
+ + try {
63
+ + doc = await loadDocument(false);
64
+ + } catch (reason) {
65
+ + if (terminated) {
66
+ + return;
67
+ + }
68
+ + if (!(reason instanceof XRefParseException)) {
69
+ + throw reason;
70
+ + }
71
+ + await pdfManager.requestLoadedStream();
72
+ + if (terminated) {
73
+ + return;
74
+ + }
75
+ + doc = await loadDocument(true);
76
+ }
77
+ - pdfManager.requestLoadedStream().then(function () {
78
+ - ensureNotTerminated();
79
+ - loadDocument(true).then(onSuccess, onFailure);
80
+ - });
81
+ - });
82
+ + onSuccess(doc);
83
+ + } catch (reason) {
84
+ + onFailure(reason);
85
+ + }
86
+ + }
87
+ + if (terminated) {
88
+ + return;
89
+ }
90
+ - ensureNotTerminated();
91
+ getPdfManager(data).then(function (newPdfManager) {
92
+ if (terminated) {
93
+ newPdfManager.terminate(new AbortException("Worker was terminated."));
94
+ - throw new Error("Worker was terminated");
95
+ + return;
96
+ }
97
+ pdfManager = newPdfManager;
98
+ pdfManager.requestLoadedStream(true).then(stream => {
99
+ + if (terminated) {
100
+ + return;
101
+ + }
102
+ handler.send("DataLoaded", {
103
+ length: stream.bytes.byteLength
104
+ });
105
+ - });
106
+ - }).then(pdfManagerReady, onFailure);
107
+ + }, onFailure);
108
+ + return pdfManagerReady();
109
+ + }).catch(onFailure);
110
+ }
111
+ handler.on("GetPage", function (data) {
112
+ return pdfManager.getPage(data.pageIndex).then(function (page) {
@@ -1,10 +1,17 @@
1
1
  {
2
- "schemaVersion": 3,
2
+ "schemaVersion": 4,
3
3
  "packageName": "pdfjs-dist",
4
4
  "version": "5.4.624",
5
5
  "sourceRepository": "https://github.com/mozilla/pdf.js",
6
6
  "licenseSpdx": "Apache-2.0",
7
7
  "runtimeTransform": "isolate-pdfjs-webpack4-runtime-v1",
8
+ "sourcePatches": [
9
+ {
10
+ "path": "patches/pdfjs-dist@5.4.624.patch",
11
+ "sha256": "a484b7eff884a0e5161286126623b28a0d3100053f850a56f5ae56e587ab4c26",
12
+ "size": 3623
13
+ }
14
+ ],
8
15
  "runtimeFiles": [
9
16
  {
10
17
  "path": "legacy/build/pdf.mjs",
@@ -16,11 +23,11 @@
16
23
  },
17
24
  {
18
25
  "path": "legacy/build/pdf.worker.mjs",
19
- "sourceSize": 2139222,
20
- "sourceSha256": "913e24da1c2a5cc0c3fd595c83eaee15694438001b68ba8cadd4f583af53a15e",
26
+ "sourceSize": 2139821,
27
+ "sourceSha256": "6c97b16c12986a5043311d7c4a15043e6f160db2503795e9a6804b85e8054c1d",
21
28
  "runtimeBindingReplacements": 793,
22
- "size": 2144094,
23
- "sha256": "158744ac1886384bfa4f23ec906fd042c0435d63b0cfb6c840beb119e243fc7e"
29
+ "size": 2144693,
30
+ "sha256": "6dbca20dcff89ef88c00b543bf66873be2ad778d17a65f9e426f75b57774d432"
24
31
  },
25
32
  {
26
33
  "path": "legacy/web/pdf_viewer.mjs",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@file-viewer/renderer-pdf",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Standalone PDF renderer plugin for File Viewer powered by PDF.js.",
@@ -60,7 +60,7 @@
60
60
  "LICENSE"
61
61
  ],
62
62
  "dependencies": {
63
- "@file-viewer/core": "3.0.1"
63
+ "@file-viewer/core": "3.0.3"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "pdf-lib": "1.17.1"
@@ -83,6 +83,7 @@
83
83
  "scripts": {
84
84
  "build": "tsc -b tsconfig.json && node scripts/stage-pdfjs-runtime.mjs",
85
85
  "type-check": "tsc -b tsconfig.json",
86
- "verify:pdfjs-runtime": "node scripts/stage-pdfjs-runtime.mjs --check"
86
+ "verify:pdfjs-runtime": "node scripts/stage-pdfjs-runtime.mjs --check",
87
+ "verify:worker-lifecycle": "npm exec --yes --package playwright@1.61.1 -- node scripts/verify-worker-lifecycle.mjs"
87
88
  }
88
89
  }