@file-viewer/renderer-word 3.3.4 → 3.3.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.
package/README.en.md CHANGED
@@ -57,6 +57,10 @@ current preview without replacing the file. It does not accept/reject revisions
57
57
  or rewrite the original bytes. Text revisions are not a claim of complete
58
58
  Word review-history, formatting-change, or move-tracking support.
59
59
 
60
+ In DOCX preview, select a comment marker in `all` review mode to read its
61
+ contents. The `final` and `original` modes hide comment markers. Printing
62
+ and HTML export omit the comment overlays.
63
+
60
64
  ## Offline Assets
61
65
 
62
66
  DOCX Worker defaults to viewer assets:
package/README.md CHANGED
@@ -57,6 +57,10 @@ current preview without replacing the file. It does not accept/reject revisions
57
57
  or rewrite the original bytes. Text revisions are not a claim of complete
58
58
  Word review-history, formatting-change, or move-tracking support.
59
59
 
60
+ In DOCX preview, select a comment marker in `all` review mode to read its
61
+ contents. The `final` and `original` modes hide comment markers. Printing
62
+ and HTML export omit the comment overlays.
63
+
60
64
  ## Offline Assets
61
65
 
62
66
  DOCX Worker defaults to viewer assets:
package/README.zh-CN.md CHANGED
@@ -46,6 +46,8 @@ Word 2003 XML 按根元素及其完整命名空间识别,HTML 注释、正文
46
46
 
47
47
  `options.docx.reviewMode` 同时适用于 DOC 和 DOCX:`all`(默认)用下划线显示实际插入、用删除线显示实际删除;`final` 显示定稿,`original` 显示修订前文字。同一组件修改该参数后会更新预览,不需要重新选择文件,也不会接受、拒绝修订或重写原始文件。文本修订支持不等于完整支持 Word 审阅历史、格式修订或移动记录。
48
48
 
49
+ 在 DOCX 的 `all` 审阅预览中,点击标记可阅读批注。`final` 和 `original` 模式隐藏批注标记。打印和 HTML 导出省略批注浮层。
50
+
49
51
  ## 离线资产
50
52
 
51
53
  DOCX Worker 默认读取 viewer assets 下的:
package/dist/wordDoc.d.ts CHANGED
@@ -1,6 +1,13 @@
1
1
  import { type FileRenderContext, type FileViewerRenderedInstance as AppWrapper } from '@file-viewer/core';
2
+ type WordLayoutPages = Array<{
3
+ width: number;
4
+ height: number;
5
+ html: string;
6
+ }>;
2
7
  export default function render(buffer: ArrayBuffer, target: HTMLDivElement, context?: FileRenderContext): Promise<AppWrapper>;
3
8
  export declare function mountWordDocument(rendered: {
4
9
  html: string;
5
10
  css: string;
11
+ layoutPages?: WordLayoutPages;
6
12
  }, target: HTMLDivElement, context?: FileRenderContext): AppWrapper;
13
+ export {};
package/dist/wordDoc.js CHANGED
@@ -169,11 +169,18 @@ const getTargetWindow = (target) => {
169
169
  function injectPageBreakMarkers(html) {
170
170
  return html.replace(/<(p|table|section)([^>]*?)style="([^"]*?\bbreak-before\s*:\s*page;?[^"]*?)"([^>]*)>/gi, (match) => `${PAGE_BREAK_MARKER}${match}`);
171
171
  }
172
- function wrapAsWordPages(html) {
172
+ function wrapAsWordPages(html, layoutPages) {
173
+ if ((layoutPages === null || layoutPages === void 0 ? void 0 : layoutPages.length) && layoutPages.every(page => isPositiveFinite(page.width) && isPositiveFinite(page.height))) {
174
+ return `<div class="msdoc-stage">${layoutPages.map(page => `<section class="msdoc-page" data-msdoc-page-width="${page.width}" data-msdoc-page-height="${page.height}"><div class="msdoc-root" style="width:${page.width}px;min-height:${page.height}px;padding:0">${page.html}</div></section>`).join('')}</div>`;
175
+ }
173
176
  const normalizedHtml = injectPageBreakMarkers(html);
174
177
  const pages = normalizedHtml.split(PAGE_BREAK_MARKER);
175
178
  return `<div class="msdoc-stage">${pages.map(page => (`<section class="msdoc-page"><div class="msdoc-root">${page || EMPTY_PAGE_HTML}</div></section>`)).join('')}</div>`;
176
179
  }
180
+ function authoredPageSize(page) {
181
+ const width = Number(page.dataset.msdocPageWidth), height = Number(page.dataset.msdocPageHeight);
182
+ return isPositiveFinite(width) && isPositiveFinite(height) ? { width, height } : MSDOC_PAGE_SIZE;
183
+ }
177
184
  function prepareMsDocCloneForExport(target) {
178
185
  const clone = target.cloneNode(true);
179
186
  clone.classList.remove('msdoc-zoom-viewer');
@@ -185,10 +192,11 @@ function prepareMsDocCloneForExport(target) {
185
192
  node.style.transform = 'none';
186
193
  });
187
194
  clone.querySelectorAll('.msdoc-page').forEach((page, index) => {
195
+ const pageSize = authoredPageSize(page);
188
196
  page.dataset.viewerPrintPageIndex = String(index);
189
- applyPrintPageSize(page, MSDOC_PAGE_SIZE, { heightMode: 'min' });
197
+ applyPrintPageSize(page, pageSize, { heightMode: 'min' });
190
198
  page.style.position = 'relative';
191
- page.style.width = formatCssPixels(MSDOC_PAGE_SIZE.width);
199
+ page.style.width = formatCssPixels(pageSize.width);
192
200
  page.style.maxWidth = 'none';
193
201
  page.style.margin = '0 auto 18px';
194
202
  const root = page.querySelector('.msdoc-root');
@@ -198,9 +206,9 @@ function prepareMsDocCloneForExport(target) {
198
206
  root.style.position = 'relative';
199
207
  root.style.top = 'auto';
200
208
  root.style.left = 'auto';
201
- root.style.width = formatCssPixels(MSDOC_PAGE_SIZE.width);
209
+ root.style.width = formatCssPixels(pageSize.width);
202
210
  root.style.maxWidth = 'none';
203
- root.style.minHeight = formatCssPixels(MSDOC_PAGE_SIZE.height);
211
+ root.style.minHeight = formatCssPixels(pageSize.height);
204
212
  root.style.height = 'auto';
205
213
  root.style.transform = 'none';
206
214
  root.style.transformOrigin = 'top left';
@@ -210,11 +218,13 @@ function prepareMsDocCloneForExport(target) {
210
218
  });
211
219
  return clone.innerHTML;
212
220
  }
213
- function buildMsDocPrintStyle() {
221
+ function buildMsDocPrintStyle(target) {
222
+ const page = target.querySelector('.msdoc-page');
223
+ const pageSize = page ? authoredPageSize(page) : MSDOC_PAGE_SIZE;
214
224
  return buildPrintPageStyle({
215
225
  selector: '.viewer-export-content .msdoc-page',
216
- width: MSDOC_PAGE_SIZE.width,
217
- height: MSDOC_PAGE_SIZE.height,
226
+ width: pageSize.width,
227
+ height: pageSize.height,
218
228
  heightMode: 'min'
219
229
  });
220
230
  }
@@ -247,8 +257,9 @@ function makeMsDocResponsive(target) {
247
257
  if (!root) {
248
258
  return;
249
259
  }
250
- const rootWidth = root.offsetWidth || MSDOC_PAGE_SIZE.width;
251
- const rootHeight = Math.max(root.scrollHeight, root.offsetHeight, MSDOC_PAGE_SIZE.height);
260
+ const pageSize = authoredPageSize(page);
261
+ const rootWidth = root.offsetWidth || pageSize.width;
262
+ const rootHeight = Math.max(root.scrollHeight, root.offsetHeight, pageSize.height);
252
263
  const availableWidth = Math.max(target.clientWidth - 48, 120);
253
264
  const fitScale = Math.min(1, Math.max(MSDOC_MIN_SCALE, availableWidth / rootWidth));
254
265
  const scale = clampScale(fitScale * userZoom);
@@ -404,13 +415,13 @@ export function mountWordDocument(rendered, target, context) {
404
415
  style.dataset.msdoc = '';
405
416
  style.textContent = `${rendered.css}\n${WORD_PAGE_CSS}`;
406
417
  const content = target.ownerDocument.createElement('div');
407
- content.append(sanitizeMsDocHtml(wrapAsWordPages(rendered.html), targetWindow));
418
+ content.append(sanitizeMsDocHtml(wrapAsWordPages(rendered.html, rendered.layoutPages), targetWindow));
408
419
  target.replaceChildren(style, ...Array.from(content.childNodes));
409
420
  const disposeResponsive = makeMsDocResponsive(target);
410
421
  (_a = context === null || context === void 0 ? void 0 : context.registerExportAdapter) === null || _a === void 0 ? void 0 : _a.call(context, {
411
422
  includeDocumentStyles: false,
412
423
  getPrintMaskPages: () => Array.from(target.querySelectorAll('.msdoc-page')),
413
- printStyle: buildMsDocPrintStyle,
424
+ printStyle: () => buildMsDocPrintStyle(target),
414
425
  toHtml: () => prepareMsDocCloneForExport(target)
415
426
  });
416
427
  (_b = context === null || context === void 0 ? void 0 : context.registerThumbnailAdapter) === null || _b === void 0 ? void 0 : _b.call(context, {
package/dist/wordDocx.js CHANGED
@@ -115,10 +115,12 @@ export const createDocxOptions = (target, context, notifyProgressiveRender) => {
115
115
  };
116
116
  const externalLinkPolicy = (_b = docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.externalLinkPolicy) !== null && _b !== void 0 ? _b : 'block';
117
117
  const externalResourcePolicy = (_c = docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.externalResourcePolicy) !== null && _c !== void 0 ? _c : 'block';
118
+ const reviewMode = (_d = docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.reviewMode) !== null && _d !== void 0 ? _d : 'all';
118
119
  const options = {
119
120
  useWorker,
120
121
  exposeDisplayTargets: (docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.exposeDisplayTargets) === true,
121
- reviewMode: (_d = docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.reviewMode) !== null && _d !== void 0 ? _d : 'all',
122
+ reviewMode,
123
+ renderComments: reviewMode === 'all',
122
124
  breakPages: true,
123
125
  fixedPageHeight: usePagedLayout,
124
126
  ignoreLastRenderedPageBreak: (_e = docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.ignoreLastRenderedPageBreak) !== null && _e !== void 0 ? _e : !usePagedLayout,
@@ -288,7 +290,7 @@ function makeDocxResponsive(target, context) {
288
290
  measured = true;
289
291
  }
290
292
  page.style.transform = `translateX(-50%) scale(${scale})`;
291
- frame.style.width = `${Math.ceil(Math.max(pageWidth * scale, target.clientWidth - 28, 120))}px`;
293
+ frame.style.width = `${pageWidth * scale}px`;
292
294
  frame.style.maxWidth = 'none';
293
295
  frame.style.height = `${Math.ceil(contentHeight * scale)}px`;
294
296
  });
@@ -519,6 +521,7 @@ async function prepareDocxCloneForExport(target) {
519
521
  const selector = '.docx-page-frame, .docx-flow-frame, .docx-canvas-sheet';
520
522
  const liveFrames = Array.from(target.querySelectorAll(selector));
521
523
  const clone = target.cloneNode(true);
524
+ clone.querySelectorAll('[data-docx-change-kind="comment"]').forEach(comment => comment.remove());
522
525
  replaceFileViewerCanvasWithImages(target, clone);
523
526
  const engineWrapper = clone.querySelector('.docx-wrapper');
524
527
  const printDocument = engineWrapper
@@ -536,8 +539,13 @@ async function prepareDocxCloneForExport(target) {
536
539
  normalizeDocxPageForPrint(frame, getDocxFramePrintSize(liveFrames[index]));
537
540
  printDocument.appendChild(frame.cloneNode(true));
538
541
  });
542
+ const screenPaperStyle = `<style>@media screen {
543
+ .docx-print-document > :is(.docx-page-frame, .docx-flow-frame) > section.docx {
544
+ background-color: var(--file-viewer-docx-page-background, #fff);
545
+ }
546
+ }</style>`;
539
547
  return printDocument.childElementCount
540
- ? `${scopedStyles}${printDocument.outerHTML}`
548
+ ? `${scopedStyles}${screenPaperStyle}${printDocument.outerHTML}`
541
549
  : clone.innerHTML;
542
550
  }
543
551
  finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@file-viewer/renderer-word",
3
- "version": "3.3.4",
3
+ "version": "3.3.6",
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.",
@@ -81,9 +81,9 @@
81
81
  "README.zh-CN.md"
82
82
  ],
83
83
  "dependencies": {
84
- "@file-viewer/core": "3.3.4",
85
- "@file-viewer/doc": "3.3.4",
86
- "@file-viewer/docx": "0.3.39",
84
+ "@file-viewer/core": "3.3.6",
85
+ "@file-viewer/doc": "3.3.6",
86
+ "@file-viewer/docx": "0.3.42",
87
87
  "jszip": "3.10.2"
88
88
  },
89
89
  "fileViewer": {