@file-viewer/core 2.0.7 → 2.0.9

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.
@@ -1,4 +1,4 @@
1
- import { resolveFileViewerDocxWorkerUrl } from '../platform/assets.js';
1
+ import { resolveFileViewerDocxWorkerJsZipUrl, resolveFileViewerDocxWorkerUrl, } from '../platform/assets.js';
2
2
  import { applyPrintPageSize, buildPrintPageStyle, formatCssPixels, getElementPrintPageSize } from '../output/printLayout.js';
3
3
  import { createFileViewerZoomChangeEmitter as createZoomChangeEmitter, } from '../features/document/zoom.js';
4
4
  import { registerFileViewerZoomProvider, unregisterFileViewerZoomProvider } from '../features/document/dom/index.js';
@@ -7,18 +7,17 @@ const DOCX_DEFAULT_PAGE_SIZE = {
7
7
  height: 1123
8
8
  };
9
9
  const DOCX_PROGRESSIVE_BATCH_SIZE = 2;
10
- const DOCX_WORKER_TIMEOUT = 15000;
10
+ const DOCX_WORKER_TIMEOUT = 120000;
11
11
  const DOCX_MIN_SCALE = 0.24;
12
12
  const DOCX_MAX_SCALE = 3;
13
13
  const DOCX_ZOOM_STEP = 0.15;
14
14
  const DOCX_EMU_PER_CSS_PIXEL = 9525;
15
- let docxWorkerRequestId = 0;
16
15
  const loadLibrary = (() => {
17
16
  const loader = {
18
17
  module: null,
19
18
  async load() {
20
19
  if (!this.module) {
21
- this.module = import('docx-preview');
20
+ this.module = import('@file-viewer/docx');
22
21
  }
23
22
  return this.module;
24
23
  }
@@ -27,11 +26,46 @@ const loadLibrary = (() => {
27
26
  return await loader.load();
28
27
  };
29
28
  })();
30
- const createDocxOptions = (experimental = true) => ({
31
- // Word 会写入 autoSpaceDN/autoSpaceDE 等兼容标签;生产预览保持静默,避免 docx-preview 调试告警刷屏。
32
- debug: false,
33
- experimental
34
- });
29
+ const createDocxOptions = (target, context, notifyProgressiveRender) => {
30
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
31
+ const docxOptions = (_a = context === null || context === void 0 ? void 0 : context.options) === null || _a === void 0 ? void 0 : _a.docx;
32
+ const documentBaseUrl = target.ownerDocument.URL || undefined;
33
+ const useWorker = (docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.worker) !== false;
34
+ const usePagedLayout = (docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.visualPagination) === true;
35
+ const progress = (event) => {
36
+ if (event.phase === 'render' || event.phase === 'layout' || event.phase === 'done') {
37
+ notifyProgressiveRender();
38
+ }
39
+ };
40
+ return {
41
+ // Word 会写入 autoSpaceDN/autoSpaceDE 等兼容标签;生产预览保持静默,避免 DOCX 调试告警刷屏。
42
+ debug: false,
43
+ experimental: false,
44
+ useWorker,
45
+ workerUrl: useWorker
46
+ ? resolveFileViewerDocxWorkerUrl(docxOptions, documentBaseUrl)
47
+ : undefined,
48
+ workerJsZipUrl: useWorker
49
+ ? resolveFileViewerDocxWorkerJsZipUrl(docxOptions, documentBaseUrl)
50
+ : undefined,
51
+ workerFallback: true,
52
+ workerTimeout: (_b = docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.workerTimeout) !== null && _b !== void 0 ? _b : DOCX_WORKER_TIMEOUT,
53
+ renderPageBatchSize: (_c = docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.renderPageBatchSize) !== null && _c !== void 0 ? _c : ((docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.progressive) === false ? Number.MAX_SAFE_INTEGER : DOCX_PROGRESSIVE_BATCH_SIZE),
54
+ renderYieldEveryMs: (_d = docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.renderYieldEveryMs) !== null && _d !== void 0 ? _d : 16,
55
+ strictWordCompatibility: (_e = docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.strictWordCompatibility) !== null && _e !== void 0 ? _e : true,
56
+ paginationTolerance: (_f = docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.paginationTolerance) !== null && _f !== void 0 ? _f : 2,
57
+ breakPages: usePagedLayout,
58
+ maxDynamicPaginationPasses: usePagedLayout
59
+ ? (_g = docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.maxDynamicPaginationPasses) !== null && _g !== void 0 ? _g : 1000
60
+ : 0,
61
+ awaitLayout: (_h = docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.awaitLayout) !== null && _h !== void 0 ? _h : usePagedLayout,
62
+ preserveComplexFieldResults: (_j = docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.preserveComplexFieldResults) !== null && _j !== void 0 ? _j : true,
63
+ updatePageReferences: (_k = docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.updatePageReferences) !== null && _k !== void 0 ? _k : false,
64
+ hideWebHiddenContent: (_l = docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.hideWebHiddenContent) !== null && _l !== void 0 ? _l : false,
65
+ ignoreLastRenderedPageBreak: (_m = docxOptions === null || docxOptions === void 0 ? void 0 : docxOptions.ignoreLastRenderedPageBreak) !== null && _m !== void 0 ? _m : !usePagedLayout,
66
+ progress
67
+ };
68
+ };
35
69
  const getTargetWindow = (target) => {
36
70
  return target.ownerDocument.defaultView;
37
71
  };
@@ -40,171 +74,10 @@ const isTargetHTMLElement = (value, target) => {
40
74
  const HTMLElementCtor = (_a = getTargetWindow(target)) === null || _a === void 0 ? void 0 : _a.HTMLElement;
41
75
  return HTMLElementCtor ? value instanceof HTMLElementCtor : value instanceof HTMLElement;
42
76
  };
43
- const shouldUseDocxWorker = (target, context) => {
44
- var _a, _b;
45
- const view = getTargetWindow(target);
46
- return ((_b = (_a = context === null || context === void 0 ? void 0 : context.options) === null || _a === void 0 ? void 0 : _a.docx) === null || _b === void 0 ? void 0 : _b.worker) === true && typeof (view === null || view === void 0 ? void 0 : view.Worker) === 'function';
47
- };
48
- const shouldMountDocxProgressively = (context) => {
49
- var _a, _b;
50
- return ((_b = (_a = context === null || context === void 0 ? void 0 : context.options) === null || _a === void 0 ? void 0 : _a.docx) === null || _b === void 0 ? void 0 : _b.progressive) === true;
51
- };
52
77
  const shouldPaginateOversizedDocxSections = (context) => {
53
78
  var _a, _b;
54
79
  return ((_b = (_a = context === null || context === void 0 ? void 0 : context.options) === null || _a === void 0 ? void 0 : _a.docx) === null || _b === void 0 ? void 0 : _b.visualPagination) === true;
55
80
  };
56
- const waitDocxMountFrame = (target) => {
57
- return new Promise(resolve => {
58
- const view = getTargetWindow(target);
59
- if (!view || typeof view.requestAnimationFrame !== 'function') {
60
- globalThis.setTimeout(resolve, 0);
61
- return;
62
- }
63
- view.requestAnimationFrame(() => resolve());
64
- });
65
- };
66
- async function mountDocxPreviewHtml(html, target, context) {
67
- var _a, _b, _c;
68
- if (!shouldMountDocxProgressively(context)) {
69
- target.innerHTML = html;
70
- (_a = context === null || context === void 0 ? void 0 : context.onProgressiveRender) === null || _a === void 0 ? void 0 : _a.call(context);
71
- return;
72
- }
73
- const template = target.ownerDocument.createElement('template');
74
- template.innerHTML = html;
75
- const sourceWrapper = template.content.querySelector('.docx-wrapper');
76
- if (!sourceWrapper) {
77
- target.innerHTML = html;
78
- (_b = context === null || context === void 0 ? void 0 : context.onProgressiveRender) === null || _b === void 0 ? void 0 : _b.call(context);
79
- return;
80
- }
81
- const pages = Array.from(sourceWrapper.children);
82
- const liveWrapper = sourceWrapper.cloneNode(false);
83
- let hasNotifiedFirstPaint = false;
84
- target.innerHTML = '';
85
- Array.from(template.content.childNodes).forEach(node => {
86
- if (node === sourceWrapper) {
87
- target.appendChild(liveWrapper);
88
- return;
89
- }
90
- target.appendChild(node);
91
- });
92
- for (let index = 0; index < pages.length; index += DOCX_PROGRESSIVE_BATCH_SIZE) {
93
- pages.slice(index, index + DOCX_PROGRESSIVE_BATCH_SIZE).forEach(page => {
94
- liveWrapper.appendChild(page);
95
- });
96
- if (!hasNotifiedFirstPaint) {
97
- hasNotifiedFirstPaint = true;
98
- (_c = context === null || context === void 0 ? void 0 : context.onProgressiveRender) === null || _c === void 0 ? void 0 : _c.call(context);
99
- }
100
- if (index + DOCX_PROGRESSIVE_BATCH_SIZE < pages.length) {
101
- await waitDocxMountFrame(target);
102
- }
103
- }
104
- }
105
- function createDocxWorker(target, context) {
106
- var _a;
107
- const view = getTargetWindow(target);
108
- if (!(view === null || view === void 0 ? void 0 : view.Worker)) {
109
- return null;
110
- }
111
- const workerUrl = resolveFileViewerDocxWorkerUrl((_a = context === null || context === void 0 ? void 0 : context.options) === null || _a === void 0 ? void 0 : _a.docx, target.ownerDocument.URL || undefined);
112
- try {
113
- return new view.Worker(workerUrl, { type: 'module' });
114
- }
115
- catch (moduleWorkerError) {
116
- try {
117
- return new view.Worker(workerUrl);
118
- }
119
- catch (classicWorkerError) {
120
- console.warn('[file-viewer] DOCX Worker 无法创建,回退到 docx-preview 主线程渲染。', classicWorkerError || moduleWorkerError);
121
- return null;
122
- }
123
- }
124
- }
125
- async function renderDocxWithWorker(buffer, target, options, context) {
126
- var _a, _b, _c;
127
- if (!shouldUseDocxWorker(target, context)) {
128
- return false;
129
- }
130
- const worker = createDocxWorker(target, context);
131
- if (!worker) {
132
- return false;
133
- }
134
- const view = getTargetWindow(target);
135
- const id = ++docxWorkerRequestId;
136
- const timeout = (_c = (_b = (_a = context === null || context === void 0 ? void 0 : context.options) === null || _a === void 0 ? void 0 : _a.docx) === null || _b === void 0 ? void 0 : _b.workerTimeout) !== null && _c !== void 0 ? _c : DOCX_WORKER_TIMEOUT;
137
- return await new Promise(resolve => {
138
- let settled = false;
139
- let timeoutId;
140
- const cleanup = () => {
141
- if (timeoutId !== undefined) {
142
- view === null || view === void 0 ? void 0 : view.clearTimeout(timeoutId);
143
- }
144
- worker.removeEventListener('message', handleMessage);
145
- worker.removeEventListener('error', handleError);
146
- worker.removeEventListener('messageerror', handleMessageError);
147
- worker.terminate();
148
- };
149
- const fallback = (reason) => {
150
- if (settled) {
151
- return;
152
- }
153
- settled = true;
154
- cleanup();
155
- console.warn('[file-viewer] DOCX Worker 渲染失败,回退到 docx-preview 主线程渲染。', reason);
156
- resolve(false);
157
- };
158
- const handleMessage = (event) => {
159
- var _a;
160
- if (((_a = event.data) === null || _a === void 0 ? void 0 : _a.id) !== id) {
161
- return;
162
- }
163
- if (settled) {
164
- return;
165
- }
166
- settled = true;
167
- cleanup();
168
- if (event.data.ok) {
169
- void mountDocxPreviewHtml(event.data.html, target, context)
170
- .then(() => resolve(true))
171
- .catch(reason => {
172
- console.warn('[file-viewer] DOCX 渐进挂载失败,回退到 docx-preview 主线程渲染。', reason);
173
- resolve(false);
174
- });
175
- return;
176
- }
177
- console.warn('[file-viewer] DOCX Worker 渲染失败,回退到 docx-preview 主线程渲染。', event.data.message);
178
- resolve(false);
179
- };
180
- const handleError = (event) => {
181
- fallback(event.error || event.message);
182
- };
183
- const handleMessageError = () => {
184
- fallback('DOCX Worker 消息无法结构化传输');
185
- };
186
- worker.addEventListener('message', handleMessage);
187
- worker.addEventListener('error', handleError);
188
- worker.addEventListener('messageerror', handleMessageError);
189
- if (Number.isFinite(timeout) && timeout > 0) {
190
- timeoutId = view === null || view === void 0 ? void 0 : view.setTimeout(() => {
191
- fallback(`DOCX Worker 超过 ${timeout}ms 未返回结果`);
192
- }, timeout);
193
- }
194
- const workerBuffer = buffer.slice(0);
195
- // Worker 内输出 HTML,图片和字体使用 data URL,避免 Worker 生命周期结束后 Blob URL 失效。
196
- worker.postMessage({
197
- id,
198
- buffer: workerBuffer,
199
- options: {
200
- ...options,
201
- // docx-preview 的 experimental tab stop 需要真实布局 API,Worker 内无法可靠计算。
202
- experimental: false,
203
- useBase64URL: true
204
- }
205
- }, [workerBuffer]);
206
- });
207
- }
208
81
  const DOCX_RESPONSIVE_CSS = `
209
82
  .docx-fit-viewer {
210
83
  box-sizing: border-box;
@@ -226,7 +99,15 @@ const DOCX_RESPONSIVE_CSS = `
226
99
  margin: 0 auto 24px;
227
100
  overflow: visible;
228
101
  }
229
- .docx-fit-viewer .docx-page-frame > section.docx {
102
+ .docx-fit-viewer .docx-flow-frame {
103
+ position: relative;
104
+ width: 100%;
105
+ min-width: 0;
106
+ margin: 0 auto 28px;
107
+ overflow: visible;
108
+ }
109
+ .docx-fit-viewer .docx-page-frame > section.docx,
110
+ .docx-fit-viewer .docx-flow-frame > section.docx {
230
111
  position: absolute;
231
112
  top: 0;
232
113
  left: 50%;
@@ -238,7 +119,13 @@ const DOCX_RESPONSIVE_CSS = `
238
119
  overflow: hidden;
239
120
  transform-origin: top center;
240
121
  }
241
- .docx-fit-viewer .docx-page-frame > section.docx > article {
122
+ .docx-fit-viewer .docx-flow-frame > section.docx {
123
+ height: auto !important;
124
+ min-height: 0 !important;
125
+ overflow: visible !important;
126
+ }
127
+ .docx-fit-viewer .docx-page-frame > section.docx > article,
128
+ .docx-fit-viewer .docx-flow-frame > section.docx > article {
242
129
  position: relative;
243
130
  z-index: 1;
244
131
  }
@@ -787,7 +674,7 @@ async function enhanceDocxFallbacks(buffer, target) {
787
674
  }
788
675
  }
789
676
  catch (error) {
790
- console.warn('[file-viewer] DOCX 兼容增强解析失败,已保留 docx-preview 原始渲染结果。', error);
677
+ console.warn('[file-viewer] DOCX 兼容增强解析失败,已保留 @file-viewer/docx 原始渲染结果。', error);
791
678
  }
792
679
  }
793
680
  function installResponsiveStyle(target) {
@@ -836,7 +723,7 @@ function paginateOversizedSections(target) {
836
723
  if (!pageHeight || originalNodes.length < 2 || child.scrollHeight <= pageHeight * 1.15) {
837
724
  return;
838
725
  }
839
- // docx-preview 只能按已有分页符拆页;没有分页符的长文档需要在预览层补一层视觉分页。
726
+ // DOCX 引擎会优先使用 Word 保存的分页;这里保留预览层兜底分页,覆盖缺少分页标记的旧文件。
840
727
  let current = clonePageShell(child, article, pageHeight);
841
728
  child.before(current.page);
842
729
  originalNodes.forEach(node => {
@@ -852,7 +739,7 @@ function paginateOversizedSections(target) {
852
739
  child.remove();
853
740
  });
854
741
  }
855
- function wrapDocxPages(target) {
742
+ function wrapDocxSections(target, pagedLayout) {
856
743
  const wrapper = target.querySelector('.docx-wrapper');
857
744
  if (!wrapper) {
858
745
  return [];
@@ -862,7 +749,7 @@ function wrapDocxPages(target) {
862
749
  return [];
863
750
  }
864
751
  const frame = target.ownerDocument.createElement('div');
865
- frame.className = 'docx-page-frame';
752
+ frame.className = pagedLayout ? 'docx-page-frame' : 'docx-flow-frame';
866
753
  child.before(frame);
867
754
  frame.appendChild(child);
868
755
  return [frame];
@@ -871,10 +758,11 @@ function wrapDocxPages(target) {
871
758
  function makeDocxResponsive(target, context) {
872
759
  target.classList.add('docx-fit-viewer');
873
760
  const style = installResponsiveStyle(target);
874
- if (shouldPaginateOversizedDocxSections(context)) {
761
+ const pagedLayout = shouldPaginateOversizedDocxSections(context);
762
+ if (pagedLayout) {
875
763
  paginateOversizedSections(target);
876
764
  }
877
- const frames = wrapDocxPages(target);
765
+ const frames = wrapDocxSections(target, pagedLayout);
878
766
  const view = getTargetWindow(target);
879
767
  const ResizeObserverCtor = view === null || view === void 0 ? void 0 : view.ResizeObserver;
880
768
  let resizeFrame = 0;
@@ -899,8 +787,10 @@ function makeDocxResponsive(target, context) {
899
787
  }
900
788
  page.style.transform = 'translateX(-50%)';
901
789
  const pageWidth = page.offsetWidth;
902
- const pageHeight = page.offsetHeight;
903
- if (!pageWidth || !pageHeight) {
790
+ const contentHeight = pagedLayout
791
+ ? page.offsetHeight
792
+ : Math.max(page.scrollHeight, page.offsetHeight);
793
+ if (!pageWidth || !contentHeight) {
904
794
  return;
905
795
  }
906
796
  const availableWidth = Math.max(target.clientWidth - 28, 120);
@@ -911,7 +801,7 @@ function makeDocxResponsive(target, context) {
911
801
  page.style.transform = `translateX(-50%) scale(${scale})`;
912
802
  frame.style.width = `${Math.ceil(Math.max(pageWidth * scale, target.clientWidth - 28, 120))}px`;
913
803
  frame.style.maxWidth = 'none';
914
- frame.style.height = `${Math.ceil(pageHeight * scale)}px`;
804
+ frame.style.height = `${Math.ceil(contentHeight * scale)}px`;
915
805
  });
916
806
  currentScale = firstScale;
917
807
  zoomEmitter.emit();
@@ -963,14 +853,28 @@ function getDocxPageElement(frame) {
963
853
  const HTMLElementCtor = (_a = frame.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.HTMLElement;
964
854
  return HTMLElementCtor && page instanceof HTMLElementCtor ? page : null;
965
855
  }
856
+ function isDocxFlowFrame(frame) {
857
+ return !!(frame === null || frame === void 0 ? void 0 : frame.classList.contains('docx-flow-frame'));
858
+ }
966
859
  function getDocxFramePrintSize(frame) {
967
860
  const page = frame ? getDocxPageElement(frame) : null;
968
- return page ? getElementPrintPageSize(page, DOCX_DEFAULT_PAGE_SIZE) : DOCX_DEFAULT_PAGE_SIZE;
861
+ if (!page) {
862
+ return DOCX_DEFAULT_PAGE_SIZE;
863
+ }
864
+ const size = getElementPrintPageSize(page, DOCX_DEFAULT_PAGE_SIZE);
865
+ if (!isDocxFlowFrame(frame)) {
866
+ return size;
867
+ }
868
+ return {
869
+ width: size.width,
870
+ height: Math.max(page.scrollHeight || 0, page.offsetHeight || 0, DOCX_DEFAULT_PAGE_SIZE.height)
871
+ };
969
872
  }
970
873
  function normalizeDocxPageForPrint(frame, pageSize) {
874
+ const flowLayout = isDocxFlowFrame(frame);
971
875
  const pageWidth = formatCssPixels(pageSize.width);
972
876
  const pageHeight = formatCssPixels(pageSize.height);
973
- applyPrintPageSize(frame, pageSize);
877
+ applyPrintPageSize(frame, pageSize, { heightMode: flowLayout ? 'min' : 'fixed' });
974
878
  frame.style.margin = '0 auto 18px';
975
879
  const page = getDocxPageElement(frame);
976
880
  if (!page) {
@@ -981,25 +885,31 @@ function normalizeDocxPageForPrint(frame, pageSize) {
981
885
  page.style.left = 'auto';
982
886
  page.style.width = pageWidth;
983
887
  page.style.maxWidth = 'none';
984
- page.style.minHeight = pageHeight;
985
- page.style.height = pageHeight;
888
+ page.style.minHeight = flowLayout ? '0' : pageHeight;
889
+ page.style.height = flowLayout ? 'auto' : pageHeight;
986
890
  page.style.margin = '0 auto';
987
891
  page.style.transform = 'none';
988
892
  page.style.transformOrigin = 'top left';
989
- page.style.overflow = 'hidden';
893
+ page.style.overflow = flowLayout ? 'visible' : 'hidden';
990
894
  page.style.boxShadow = 'none';
991
895
  }
992
896
  function buildDocxPrintStyle(target) {
993
- const firstFrame = target.querySelector('.docx-page-frame');
897
+ const firstFrame = target.querySelector('.docx-page-frame, .docx-flow-frame');
994
898
  const pageSize = getDocxFramePrintSize(firstFrame || undefined);
899
+ const selector = (firstFrame === null || firstFrame === void 0 ? void 0 : firstFrame.classList.contains('docx-flow-frame'))
900
+ ? '.viewer-export-content .docx-flow-frame'
901
+ : '.viewer-export-content .docx-page-frame';
995
902
  return buildPrintPageStyle({
996
- selector: '.viewer-export-content .docx-page-frame',
903
+ selector,
997
904
  width: pageSize.width,
998
- height: pageSize.height
905
+ height: (firstFrame === null || firstFrame === void 0 ? void 0 : firstFrame.classList.contains('docx-flow-frame'))
906
+ ? DOCX_DEFAULT_PAGE_SIZE.height
907
+ : pageSize.height,
908
+ heightMode: (firstFrame === null || firstFrame === void 0 ? void 0 : firstFrame.classList.contains('docx-flow-frame')) ? 'min' : 'fixed'
999
909
  });
1000
910
  }
1001
911
  function prepareDocxCloneForExport(target) {
1002
- const liveFrames = Array.from(target.querySelectorAll('.docx-page-frame'));
912
+ const liveFrames = Array.from(target.querySelectorAll('.docx-page-frame, .docx-flow-frame'));
1003
913
  const clone = target.cloneNode(true);
1004
914
  const printDocument = target.ownerDocument.createElement('div');
1005
915
  printDocument.className = 'docx-print-document';
@@ -1007,7 +917,7 @@ function prepareDocxCloneForExport(target) {
1007
917
  .filter(style => { var _a; return !((_a = style.textContent) === null || _a === void 0 ? void 0 : _a.includes('.docx-fit-viewer')); })
1008
918
  .map(style => style.outerHTML)
1009
919
  .join('');
1010
- clone.querySelectorAll('.docx-page-frame').forEach((frame, index) => {
920
+ clone.querySelectorAll('.docx-page-frame, .docx-flow-frame').forEach((frame, index) => {
1011
921
  normalizeDocxPageForPrint(frame, getDocxFramePrintSize(liveFrames[index]));
1012
922
  printDocument.appendChild(frame.cloneNode(true));
1013
923
  });
@@ -1018,16 +928,23 @@ function prepareDocxCloneForExport(target) {
1018
928
  */
1019
929
  export default async function (buffer, target, context) {
1020
930
  var _a;
1021
- const docxOptions = createDocxOptions();
1022
- const workerRendered = await renderDocxWithWorker(buffer, target, docxOptions, context);
1023
- target.dataset.docxWorker = workerRendered ? 'true' : 'false';
1024
- if (!workerRendered) {
1025
- const { defaultOptions, renderAsync } = await loadLibrary();
1026
- await renderAsync(buffer, target, undefined, {
1027
- ...defaultOptions,
1028
- ...docxOptions
1029
- });
1030
- }
931
+ let hasNotifiedProgressiveRender = false;
932
+ const notifyProgressiveRender = () => {
933
+ var _a;
934
+ if (hasNotifiedProgressiveRender) {
935
+ return;
936
+ }
937
+ hasNotifiedProgressiveRender = true;
938
+ (_a = context === null || context === void 0 ? void 0 : context.onProgressiveRender) === null || _a === void 0 ? void 0 : _a.call(context);
939
+ };
940
+ const docxOptions = createDocxOptions(target, context, notifyProgressiveRender);
941
+ const { defaultOptions, renderAsync } = await loadLibrary();
942
+ target.dataset.docxWorker = docxOptions.useWorker ? 'self' : 'false';
943
+ await renderAsync(buffer, target, undefined, {
944
+ ...defaultOptions,
945
+ ...docxOptions
946
+ });
947
+ notifyProgressiveRender();
1031
948
  await enhanceDocxFallbacks(buffer, target);
1032
949
  const disposeResponsive = makeDocxResponsive(target, context);
1033
950
  (_a = context === null || context === void 0 ? void 0 : context.registerExportAdapter) === null || _a === void 0 ? void 0 : _a.call(context, {
@@ -1,4 +1,4 @@
1
- import { renderAsync } from 'docx-preview';
1
+ import { renderAsync } from '@file-viewer/docx';
2
2
  import { DOMParser, XMLSerializer } from '@xmldom/xmldom';
3
3
  import { parseHTML } from 'linkedom';
4
4
  const ctx = self;
@@ -56,7 +56,7 @@ const installDomRuntime = () => {
56
56
  const runtime = globalThis;
57
57
  runtime.window = window;
58
58
  runtime.document = window.document;
59
- // docx-preview expects browser XML namespace behavior where `<w:body>` has
59
+ // @file-viewer/docx expects browser XML namespace behavior where `<w:body>` has
60
60
  // localName === "body"; linkedom keeps prefixes, so XML parsing uses xmldom.
61
61
  runtime.DOMParser = BrowserLikeXmlDomParser;
62
62
  runtime.Node = window.Node;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@file-viewer/core",
3
- "version": "2.0.7",
3
+ "version": "2.0.9",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Framework-neutral TypeScript core for Flyfish File Viewer",
@@ -58,20 +58,20 @@
58
58
  "LICENSE"
59
59
  ],
60
60
  "dependencies": {
61
- "@file-viewer/pptx": "^2.0.7",
62
- "@flyfish-dev/cad-viewer": "^0.6.4",
63
61
  "@excalidraw/excalidraw": "^0.18.1",
62
+ "@file-viewer/docx": "^0.3.9",
63
+ "@file-viewer/pptx": "^2.0.9",
64
+ "@flyfish-dev/cad-viewer": "^0.6.4",
64
65
  "@kenjiuno/msgreader": "^1.28.0",
65
- "@myriaddreamin/typst.ts": "0.7.0",
66
66
  "@myriaddreamin/typst-ts-renderer": "0.7.0",
67
67
  "@myriaddreamin/typst-ts-web-compiler": "0.7.0",
68
+ "@myriaddreamin/typst.ts": "0.7.0",
68
69
  "@tmcw/togeojson": "^7.1.2",
69
70
  "@tonejs/midi": "^2.0.28",
70
71
  "@xmldom/xmldom": "^0.9.10",
71
72
  "ag-psd": "^30.1.1",
72
73
  "avsc": "^5.7.9",
73
74
  "cfb": "^1.2.2",
74
- "docx-preview": "^0.3.7",
75
75
  "e-virt-table": "^1.3.26",
76
76
  "epubjs": "^0.3.93",
77
77
  "heic2any": "^0.0.4",
@@ -87,8 +87,6 @@
87
87
  "pako": "^2.1.0",
88
88
  "pdfjs-dist": "^6.0.227",
89
89
  "postal-mime": "^2.7.4",
90
- "react": "^18.3.1",
91
- "react-dom": "^18.3.1",
92
90
  "roughjs": "^4.6.6",
93
91
  "rtf.js": "^3.0.9",
94
92
  "shpjs": "^6.2.0",
@@ -98,10 +96,10 @@
98
96
  "tinycolor2": "^1.6.0"
99
97
  },
100
98
  "devDependencies": {
101
- "@types/tinycolor2": "^1.4.6",
99
+ "@types/pako": "^2.0.4",
102
100
  "@types/three": "^0.184.1",
103
- "typescript": "^6.0.3",
104
- "@types/pako": "^2.0.4"
101
+ "@types/tinycolor2": "^1.4.6",
102
+ "typescript": "^6.0.3"
105
103
  },
106
104
  "license": "Apache-2.0",
107
105
  "scripts": {