@file-viewer/renderer-word 2.1.4 → 2.1.6

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.
Files changed (2) hide show
  1. package/dist/wordDocx.js +37 -5
  2. package/package.json +2 -2
package/dist/wordDocx.js CHANGED
@@ -5,7 +5,8 @@ const DOCX_DEFAULT_PAGE_SIZE = {
5
5
  height: 1123
6
6
  };
7
7
  const DOCX_PROGRESSIVE_BATCH_SIZE = 2;
8
- const DOCX_WORKER_TIMEOUT = 120000;
8
+ const DOCX_WORKER_TIMEOUT = 5000;
9
+ const DOCX_WORKER_UNSAFE_PROTOCOLS = new Set(['file:', 'about:', 'data:']);
9
10
  const DOCX_MIN_SCALE = 0.24;
10
11
  const DOCX_MAX_SCALE = 3;
11
12
  const DOCX_ZOOM_STEP = 0.15;
@@ -37,11 +38,45 @@ const assertValidDocxPackage = (buffer) => {
37
38
  }
38
39
  throw new Error('文件不是有效的 DOCX/OOXML 压缩包,可能下载不完整或被服务端错误内容替换,请重新上传或检查文件源。');
39
40
  };
41
+ const getTargetWindow = (target) => {
42
+ return target.ownerDocument.defaultView;
43
+ };
44
+ const getTargetProtocol = (target) => {
45
+ var _a, _b, _c;
46
+ const candidates = [
47
+ target.ownerDocument.URL,
48
+ (_b = (_a = getTargetWindow(target)) === null || _a === void 0 ? void 0 : _a.location) === null || _b === void 0 ? void 0 : _b.href,
49
+ (_c = globalThis.location) === null || _c === void 0 ? void 0 : _c.href
50
+ ].filter(Boolean);
51
+ for (const candidate of candidates) {
52
+ try {
53
+ return new URL(candidate).protocol;
54
+ }
55
+ catch {
56
+ // Ignore synthetic document URLs created by tests or embedded hosts.
57
+ }
58
+ }
59
+ return '';
60
+ };
61
+ const shouldUseDocxWorker = (target, docxOptions) => {
62
+ var _a, _b;
63
+ if ((docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.worker) === false) {
64
+ return false;
65
+ }
66
+ if ((docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.worker) === true) {
67
+ return true;
68
+ }
69
+ const WorkerCtor = (_b = (_a = getTargetWindow(target)) === null || _a === void 0 ? void 0 : _a.Worker) !== null && _b !== void 0 ? _b : globalThis.Worker;
70
+ if (!WorkerCtor) {
71
+ return false;
72
+ }
73
+ return !DOCX_WORKER_UNSAFE_PROTOCOLS.has(getTargetProtocol(target));
74
+ };
40
75
  const createDocxOptions = (target, context, notifyProgressiveRender) => {
41
76
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
42
77
  const docxOptions = (_a = context === null || context === void 0 ? void 0 : context.options) === null || _a === void 0 ? void 0 : _a.docx;
43
78
  const documentBaseUrl = target.ownerDocument.URL || undefined;
44
- const useWorker = (docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.worker) !== false;
79
+ const useWorker = shouldUseDocxWorker(target, docxOptions);
45
80
  const usePagedLayout = (docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.visualPagination) === true;
46
81
  const progress = (event) => {
47
82
  if (event.phase === 'render' || event.phase === 'layout' || event.phase === 'done') {
@@ -77,9 +112,6 @@ const createDocxOptions = (target, context, notifyProgressiveRender) => {
77
112
  progress
78
113
  };
79
114
  };
80
- const getTargetWindow = (target) => {
81
- return target.ownerDocument.defaultView;
82
- };
83
115
  const isTargetHTMLElement = (value, target) => {
84
116
  var _a;
85
117
  const HTMLElementCtor = (_a = getTargetWindow(target)) === null || _a === void 0 ? void 0 : _a.HTMLElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@file-viewer/renderer-word",
3
- "version": "2.1.4",
3
+ "version": "2.1.6",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Standalone Word and compatible document renderer plugin for Flyfish File Viewer powered by @file-viewer/docx, msdoc-viewer, and RTF/ODF parsing.",
@@ -57,7 +57,7 @@
57
57
  "LICENSE"
58
58
  ],
59
59
  "dependencies": {
60
- "@file-viewer/core": "^2.1.4",
60
+ "@file-viewer/core": "^2.1.6",
61
61
  "@file-viewer/docx": "^0.3.12",
62
62
  "jszip": "^3.10.1",
63
63
  "msdoc-viewer": "^0.2.0",