@file-viewer/renderer-word 3.2.2 → 3.3.0
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 +2 -0
- package/README.md +43 -28
- package/README.zh-CN.md +86 -0
- package/dist/docxFrames.js +4 -0
- package/dist/wordDocx.js +1 -0
- package/package.json +6 -5
package/README.en.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @file-viewer/renderer-word
|
|
2
2
|
|
|
3
|
+
[English](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/word/README.md) · [简体中文](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/word/README.zh-CN.md)
|
|
4
|
+
|
|
3
5
|
Word and OpenDocument renderer package for Flyfish File Viewer. Standard/full includes DOCX/DOCM/DOTX/DOTM, legacy DOC/DOT, ODT, and ODP. RTF is enabled explicitly by `@file-viewer/capability-rtf`.
|
|
4
6
|
|
|
5
7
|
## Usage
|
package/README.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# @file-viewer/renderer-word
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[English](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/word/README.md) · [简体中文](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/word/README.zh-CN.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Word and OpenDocument renderer package for Flyfish File Viewer. Standard/full includes DOCX/DOCM/DOTX/DOTM, legacy DOC/DOT, ODT, and ODP. RTF is enabled explicitly by `@file-viewer/capability-rtf`.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
6
8
|
|
|
7
9
|
```ts
|
|
8
10
|
import FileViewer from '@file-viewer/vue3'
|
|
@@ -14,7 +16,7 @@ const options = {
|
|
|
14
16
|
}
|
|
15
17
|
```
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
You can compose it with other renderers:
|
|
18
20
|
|
|
19
21
|
```ts
|
|
20
22
|
import { wordRenderer } from '@file-viewer/renderer-word'
|
|
@@ -27,31 +29,42 @@ const options = {
|
|
|
27
29
|
}
|
|
28
30
|
```
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
Use `@file-viewer/preset-all` when you want the same complete matrix as the official demo.
|
|
31
33
|
|
|
32
|
-
##
|
|
34
|
+
## Capabilities
|
|
33
35
|
|
|
34
|
-
- DOCX / DOCM / DOTX / DOTM
|
|
35
|
-
- DOC / DOT
|
|
36
|
-
-
|
|
37
|
-
-
|
|
36
|
+
- DOCX / DOCM / DOTX / DOTM use the self-maintained `@file-viewer/docx` engine with Worker parsing, continuous reading layout, cached TOC fields, async batched rendering, and a dark document surface that follows the viewer theme.
|
|
37
|
+
- DOC / DOT use `@file-viewer/doc` with a Word-like paper surface, zoom, print, and HTML export adapters.
|
|
38
|
+
- With the RTF capability installed, RTF uses `rtf.js`; without it the viewer shows the exact CLI enablement command. ODT / ODP read `content.xml` from OpenDocument packages for safe structure previews.
|
|
39
|
+
- The renderer reuses core search, zoom, print, export, lifecycle, and operation APIs.
|
|
38
40
|
|
|
39
|
-
|
|
41
|
+
The `docxjs` engine owns DOCX parsing, pagination, tab stops, drawing anchors,
|
|
42
|
+
VML text coordinates, merged-cell borders, page backgrounds and revision styles.
|
|
43
|
+
This package handles container fitting, interaction and output integration;
|
|
44
|
+
it does not rewrite generated document nodes to repair rendering or export.
|
|
40
45
|
|
|
41
|
-
Word 2003 XML
|
|
46
|
+
Word 2003 XML detection checks the document root and its complete namespace;
|
|
47
|
+
HTML comments, embedded examples and namespace substrings do not change the
|
|
48
|
+
container type. DOCX Workers without bundled JSZip use same-origin HTTP(S) or
|
|
49
|
+
Blob library URLs and reject cross-origin URLs or URL credentials.
|
|
42
50
|
|
|
43
|
-
##
|
|
51
|
+
## Text Revisions
|
|
44
52
|
|
|
45
|
-
`options.docx.reviewMode`
|
|
53
|
+
`options.docx.reviewMode` applies to DOC and DOCX: `all` (default) shows actual
|
|
54
|
+
insertions underlined and deletions struck through; `final` shows revised text,
|
|
55
|
+
and `original` shows text before those edits. Changing this option updates the
|
|
56
|
+
current preview without replacing the file. It does not accept/reject revisions
|
|
57
|
+
or rewrite the original bytes. Text revisions are not a claim of complete
|
|
58
|
+
Word review-history, formatting-change, or move-tracking support.
|
|
46
59
|
|
|
47
|
-
##
|
|
60
|
+
## Offline Assets
|
|
48
61
|
|
|
49
|
-
DOCX Worker
|
|
62
|
+
DOCX Worker defaults to viewer assets:
|
|
50
63
|
|
|
51
64
|
- `vendor/docx/docx.worker.js`
|
|
52
65
|
- `vendor/docx/jszip.min.js`
|
|
53
66
|
|
|
54
|
-
|
|
67
|
+
Override them for private deployments:
|
|
55
68
|
|
|
56
69
|
```ts
|
|
57
70
|
const options = {
|
|
@@ -62,23 +75,25 @@ const options = {
|
|
|
62
75
|
}
|
|
63
76
|
```
|
|
64
77
|
|
|
65
|
-
DOCX
|
|
78
|
+
DOCX dark rendering follows `options.theme` by default: `dark` enables it, `light` disables it, and `system` follows the browser color scheme. Pass `options.docx.darkMode: true / false` when the host app needs a fixed result.
|
|
66
79
|
|
|
67
|
-
DOC
|
|
80
|
+
DOC, DOCX, and RTF external links and HTTP(S) image relationships are blocked by default. Enable them explicitly with `options.docx.externalLinkPolicy: 'allow'` and `options.docx.externalResourcePolicy: 'allow'`; links are still limited to HTTP(S), `mailto:`, `tel:`, and safe relative addresses. Unknown and protocol-relative schemes are always rejected. Embedded images, internal bookmarks, and local `data:`/`blob:` image resources remain available.
|
|
68
81
|
|
|
69
|
-
|
|
82
|
+
The standard renderer sanitizes the DOM produced by `rtf.js` before mounting it. Custom RTF integrations that consume HTML directly should first call `sanitizeFileViewerRtfHtml(document, markup, options)`; it uses the same link policy and DOMPurify boundary as the standard mount path. A strict Trusted Types CSP should allow the `file-viewer-document-sanitizer` policy name.
|
|
70
83
|
|
|
71
|
-
##
|
|
84
|
+
## Embedded HTML
|
|
72
85
|
|
|
73
|
-
|
|
86
|
+
Set `options.docx.renderAltChunks: false` to omit embedded HTML parts in DOCX. Normal document text and embedded images remain available. Omitting the option or setting it to `true` preserves the engine sandbox; it does not enable scripts or same-origin access, or relax external link/resource policies. The option applies to both Worker and main-thread parsing, not to binary DOC.
|
|
74
87
|
|
|
75
|
-
##
|
|
88
|
+
## Migration
|
|
76
89
|
|
|
77
|
-
`@file-viewer/core`
|
|
90
|
+
`@file-viewer/core` no longer depends on `@file-viewer/docx`, `@file-viewer/doc`, `rtf.js`, `linkedom`, or `@xmldom/xmldom` directly. Install and pass this renderer for full Word preview, or use `@file-viewer/preset-all`.
|
|
78
91
|
|
|
79
|
-
##
|
|
92
|
+
## Print layout
|
|
80
93
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
94
|
+
Fixed-page DOCX output preserves each page's authored paper size, including
|
|
95
|
+
landscape sections and mixed A4/Letter documents. Preview zoom is not applied to
|
|
96
|
+
physical print dimensions. The browser receives named CSS page rules and zero
|
|
97
|
+
additional outer margins; the document's own margins remain intact. Flow mode
|
|
98
|
+
continues to use browser pagination rather than fixed-page clipping. Printer
|
|
99
|
+
drivers and print-dialog overrides can still change the final paper selection.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# @file-viewer/renderer-word
|
|
2
|
+
|
|
3
|
+
[English](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/word/README.md) · [简体中文](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/word/README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
Flyfish File Viewer 的 Word / OpenDocument renderer 包。standard/full 默认承接 DOCX/DOCM/DOTX/DOTM、旧版 DOC/DOT 与 ODT/ODP;RTF 由 `@file-viewer/capability-rtf` 显式启用。
|
|
6
|
+
|
|
7
|
+
## 用法
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import FileViewer from '@file-viewer/vue3'
|
|
11
|
+
import { wordRenderer } from '@file-viewer/renderer-word'
|
|
12
|
+
|
|
13
|
+
const options = {
|
|
14
|
+
rendererMode: 'replace',
|
|
15
|
+
renderers: wordRenderer,
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
也可以和其他 renderer 一起组合:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { wordRenderer } from '@file-viewer/renderer-word'
|
|
23
|
+
import { pdfRenderer } from '@file-viewer/renderer-pdf'
|
|
24
|
+
import { presentationRenderer } from '@file-viewer/renderer-presentation'
|
|
25
|
+
|
|
26
|
+
const options = {
|
|
27
|
+
rendererMode: 'replace',
|
|
28
|
+
renderers: [wordRenderer, pdfRenderer, presentationRenderer],
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
官方 Demo 和完整格式矩阵可以直接使用 `@file-viewer/preset-all`。
|
|
33
|
+
|
|
34
|
+
## 能力边界
|
|
35
|
+
|
|
36
|
+
- DOCX / DOCM / DOTX / DOTM 使用自研 `@file-viewer/docx`,默认 Worker 解析、连续流式阅读、目录字段缓存、异步分批渲染,并跟随 viewer 主题启用暗黑文档面。
|
|
37
|
+
- DOC / DOT 使用 `@file-viewer/doc`,并套用 Word 风格纸张阅读面、缩放、打印和 HTML 导出适配。
|
|
38
|
+
- 安装 RTF capability 后才使用 `rtf.js`;未安装时会显示精确 CLI 启用命令。ODT / ODP 读取 OpenDocument 包内 `content.xml` 做安全结构预览。
|
|
39
|
+
- 继续复用 core 的统一搜索、缩放、打印、导出、生命周期和操作能力。
|
|
40
|
+
|
|
41
|
+
DOCX 的解析、分页、制表位、绘图锚点、VML 文本坐标、合并单元格边框、背景图和修订样式均由 `docxjs` 引擎负责。本包负责容器适配、交互与输出接入,不再对生成的文档节点做补救改写。
|
|
42
|
+
|
|
43
|
+
Word 2003 XML 按根元素及其完整命名空间识别,HTML 注释、正文中的示例或命名空间子串不会改变容器类型。未内置 JSZip 的 DOCX Worker 使用同源 HTTP(S) 或 Blob 库地址,拒绝跨源及含凭据的地址。
|
|
44
|
+
|
|
45
|
+
## 文本修订
|
|
46
|
+
|
|
47
|
+
`options.docx.reviewMode` 同时适用于 DOC 和 DOCX:`all`(默认)用下划线显示实际插入、用删除线显示实际删除;`final` 显示定稿,`original` 显示修订前文字。同一组件修改该参数后会更新预览,不需要重新选择文件,也不会接受、拒绝修订或重写原始文件。文本修订支持不等于完整支持 Word 审阅历史、格式修订或移动记录。
|
|
48
|
+
|
|
49
|
+
## 离线资产
|
|
50
|
+
|
|
51
|
+
DOCX Worker 默认读取 viewer assets 下的:
|
|
52
|
+
|
|
53
|
+
- `vendor/docx/docx.worker.js`
|
|
54
|
+
- `vendor/docx/jszip.min.js`
|
|
55
|
+
|
|
56
|
+
私有化部署时可以通过 `options.docx.workerUrl` 和 `options.docx.workerJsZipUrl` 覆盖:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
const options = {
|
|
60
|
+
docx: {
|
|
61
|
+
workerUrl: '/file-viewer/vendor/docx/docx.worker.js',
|
|
62
|
+
workerJsZipUrl: '/file-viewer/vendor/docx/jszip.min.js',
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
DOCX 暗黑渲染默认由 `options.theme` 决定:`dark` 开启、`light` 关闭、`system` 跟随浏览器系统主题。需要业务固定效果时可传 `options.docx.darkMode: true / false`。
|
|
68
|
+
|
|
69
|
+
DOC、DOCX 与 RTF 的外部链接及 HTTP(S) 图片关系默认阻断。只有显式设置 `options.docx.externalLinkPolicy: 'allow'` 和 `options.docx.externalResourcePolicy: 'allow'` 才会启用;链接仍只接受 HTTP(S)、`mailto:`、`tel:` 和安全相对地址,未知协议与协议相对地址始终拒绝。内嵌图片、内部书签以及本地 `data:`/`blob:` 图片资源不受影响。
|
|
70
|
+
|
|
71
|
+
标准 renderer 会在挂载前净化 `rtf.js` 产生的 DOM。自定义 RTF 集成若直接消费 HTML,应先调用 `sanitizeFileViewerRtfHtml(document, markup, options)`;该边界与标准挂载使用同一链接策略和 DOMPurify 配置。严格 Trusted Types CSP 需允许 `file-viewer-document-sanitizer` 策略名。
|
|
72
|
+
|
|
73
|
+
## 嵌入 HTML
|
|
74
|
+
|
|
75
|
+
使用 `options.docx.renderAltChunks: false` 可以完全省略 DOCX 内嵌 HTML 部件,正文与普通内嵌图片不受影响。未指定或设为 `true` 时保留引擎原有沙箱渲染,不会开启脚本执行、同源权限或放宽外部链接/资源策略。该选项适用于 Worker 与主线程解析,不涉及旧二进制 DOC。
|
|
76
|
+
|
|
77
|
+
## 迁移说明
|
|
78
|
+
|
|
79
|
+
`@file-viewer/core` 已不再直接依赖 `@file-viewer/docx`、`@file-viewer/doc`、`rtf.js`、`linkedom` 或 `@xmldom/xmldom`。需要 Word 完整预览时,请安装本包并通过 `renderers` 传入,或使用 `@file-viewer/preset-all`。
|
|
80
|
+
|
|
81
|
+
## 打印页面
|
|
82
|
+
|
|
83
|
+
固定分页 DOCX 按每页原始纸张尺寸输出,支持横向分节和 A4/Letter 混排。
|
|
84
|
+
预览缩放不改变打印尺寸;通过具名 CSS 页面规则避免额外添加外层页边距,
|
|
85
|
+
文档本身的页边距保持不变。流式模式仍由浏览器分页,不按固定高度裁切。
|
|
86
|
+
打印驱动或打印对话框中的纸张设置仍可能覆盖浏览器提供的尺寸。
|
package/dist/docxFrames.js
CHANGED
|
@@ -17,6 +17,10 @@ export function observeDocxFrames(target, pagedLayout, onFrames) {
|
|
|
17
17
|
const frame = target.ownerDocument.createElement('div');
|
|
18
18
|
frame.className = pagedLayout ? 'docx-page-frame' : 'docx-flow-frame';
|
|
19
19
|
frame.dataset.docxResponsiveFrame = 'true';
|
|
20
|
+
const paperBackground = view === null || view === void 0 ? void 0 : view.getComputedStyle(child).backgroundColor;
|
|
21
|
+
if (paperBackground) {
|
|
22
|
+
frame.style.setProperty('--file-viewer-docx-page-background', paperBackground);
|
|
23
|
+
}
|
|
20
24
|
child.before(frame);
|
|
21
25
|
frame.appendChild(child);
|
|
22
26
|
next.push(frame);
|
package/dist/wordDocx.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/renderer-word",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone DOCX, DOC, and OpenDocument renderer for File Viewer; RTF parsing is an explicit opt-in capability.",
|
|
@@ -77,12 +77,13 @@
|
|
|
77
77
|
"file-viewer.capability.json",
|
|
78
78
|
"LICENSE",
|
|
79
79
|
"README.en.md",
|
|
80
|
-
"README.md"
|
|
80
|
+
"README.md",
|
|
81
|
+
"README.zh-CN.md"
|
|
81
82
|
],
|
|
82
83
|
"dependencies": {
|
|
83
|
-
"@file-viewer/core": "3.
|
|
84
|
-
"@file-viewer/doc": "3.
|
|
85
|
-
"@file-viewer/docx": "0.3.
|
|
84
|
+
"@file-viewer/core": "3.3.0",
|
|
85
|
+
"@file-viewer/doc": "3.3.0",
|
|
86
|
+
"@file-viewer/docx": "0.3.39",
|
|
86
87
|
"jszip": "3.10.2"
|
|
87
88
|
},
|
|
88
89
|
"fileViewer": {
|