@file-viewer/renderer-word 2.1.13 → 2.1.14
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/dist/wordDoc.js +37 -25
- package/dist/wordDocx.js +46 -32
- package/package.json +4 -4
package/dist/wordDoc.js
CHANGED
|
@@ -184,33 +184,44 @@ function makeMsDocResponsive(target) {
|
|
|
184
184
|
const clampScale = (scale) => {
|
|
185
185
|
return Math.min(MSDOC_MAX_SCALE, Math.max(MSDOC_MIN_SCALE, Number(scale.toFixed(2))));
|
|
186
186
|
};
|
|
187
|
+
const applyResponsiveLayout = () => {
|
|
188
|
+
let firstScale = currentScale;
|
|
189
|
+
let firstFitScale = currentFitScale;
|
|
190
|
+
let measured = false;
|
|
191
|
+
pages.forEach(page => {
|
|
192
|
+
const root = page.querySelector('.msdoc-root');
|
|
193
|
+
if (!root) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const rootWidth = root.offsetWidth || MSDOC_PAGE_SIZE.width;
|
|
197
|
+
const rootHeight = Math.max(root.scrollHeight, root.offsetHeight, MSDOC_PAGE_SIZE.height);
|
|
198
|
+
const availableWidth = Math.max(target.clientWidth - 48, 120);
|
|
199
|
+
const fitScale = Math.min(1, Math.max(MSDOC_MIN_SCALE, availableWidth / rootWidth));
|
|
200
|
+
const scale = clampScale(fitScale * userZoom);
|
|
201
|
+
if (!measured) {
|
|
202
|
+
firstScale = scale;
|
|
203
|
+
firstFitScale = fitScale;
|
|
204
|
+
measured = true;
|
|
205
|
+
}
|
|
206
|
+
root.style.transform = `translateX(-50%) scale(${scale})`;
|
|
207
|
+
page.style.width = `${Math.ceil(Math.max(rootWidth * scale, 120))}px`;
|
|
208
|
+
page.style.height = `${Math.ceil(rootHeight * scale)}px`;
|
|
209
|
+
});
|
|
210
|
+
if (!measured) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
currentScale = firstScale;
|
|
214
|
+
currentFitScale = firstFitScale;
|
|
215
|
+
zoomEmitter.emit();
|
|
216
|
+
};
|
|
187
217
|
const resize = () => {
|
|
188
218
|
if (!view) {
|
|
219
|
+
applyResponsiveLayout();
|
|
189
220
|
return;
|
|
190
221
|
}
|
|
191
222
|
view.cancelAnimationFrame(resizeFrame);
|
|
192
223
|
resizeFrame = view.requestAnimationFrame(() => {
|
|
193
|
-
|
|
194
|
-
let firstFitScale = 1;
|
|
195
|
-
pages.forEach(page => {
|
|
196
|
-
const root = page.querySelector('.msdoc-root');
|
|
197
|
-
if (!root) {
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
const rootWidth = root.offsetWidth || MSDOC_PAGE_SIZE.width;
|
|
201
|
-
const rootHeight = Math.max(root.scrollHeight, root.offsetHeight, MSDOC_PAGE_SIZE.height);
|
|
202
|
-
const availableWidth = Math.max(target.clientWidth - 48, 120);
|
|
203
|
-
const fitScale = Math.min(1, Math.max(MSDOC_MIN_SCALE, availableWidth / rootWidth));
|
|
204
|
-
const scale = clampScale(fitScale * userZoom);
|
|
205
|
-
firstScale = scale;
|
|
206
|
-
firstFitScale = fitScale;
|
|
207
|
-
root.style.transform = `translateX(-50%) scale(${scale})`;
|
|
208
|
-
page.style.width = `${Math.ceil(Math.max(rootWidth * scale, 120))}px`;
|
|
209
|
-
page.style.height = `${Math.ceil(rootHeight * scale)}px`;
|
|
210
|
-
});
|
|
211
|
-
currentScale = firstScale;
|
|
212
|
-
currentFitScale = firstFitScale;
|
|
213
|
-
zoomEmitter.emit();
|
|
224
|
+
applyResponsiveLayout();
|
|
214
225
|
});
|
|
215
226
|
};
|
|
216
227
|
const getZoomState = () => ({
|
|
@@ -224,13 +235,14 @@ function makeMsDocResponsive(target) {
|
|
|
224
235
|
});
|
|
225
236
|
const setUserZoom = (nextZoom) => {
|
|
226
237
|
userZoom = Math.min(6, Math.max(0.2, Number(nextZoom.toFixed(2))));
|
|
227
|
-
|
|
238
|
+
view === null || view === void 0 ? void 0 : view.cancelAnimationFrame(resizeFrame);
|
|
239
|
+
applyResponsiveLayout();
|
|
228
240
|
return getZoomState();
|
|
229
241
|
};
|
|
230
242
|
target.dataset.viewerZoomProvider = 'doc';
|
|
231
243
|
registerFileViewerZoomProvider(target, {
|
|
232
|
-
zoomIn: () => setUserZoom(
|
|
233
|
-
zoomOut: () => setUserZoom(
|
|
244
|
+
zoomIn: () => setUserZoom((currentScale + MSDOC_ZOOM_STEP) / Math.max(currentFitScale, 0.01)),
|
|
245
|
+
zoomOut: () => setUserZoom((currentScale - MSDOC_ZOOM_STEP) / Math.max(currentFitScale, 0.01)),
|
|
234
246
|
resetZoom: () => setUserZoom(1),
|
|
235
247
|
setZoom: scale => setUserZoom(scale / Math.max(currentFitScale, 0.01)),
|
|
236
248
|
getState: getZoomState,
|
|
@@ -244,7 +256,7 @@ function makeMsDocResponsive(target) {
|
|
|
244
256
|
observer === null || observer === void 0 ? void 0 : observer.observe(root);
|
|
245
257
|
}
|
|
246
258
|
});
|
|
247
|
-
|
|
259
|
+
applyResponsiveLayout();
|
|
248
260
|
return () => {
|
|
249
261
|
view === null || view === void 0 ? void 0 : view.cancelAnimationFrame(resizeFrame);
|
|
250
262
|
observer === null || observer === void 0 ? void 0 : observer.disconnect();
|
package/dist/wordDocx.js
CHANGED
|
@@ -8,7 +8,7 @@ const DOCX_WORKER_UNSAFE_PROTOCOLS = new Set(['file:', 'about:', 'data:']);
|
|
|
8
8
|
const DOCX_MIN_SCALE = 0.24;
|
|
9
9
|
const DOCX_MAX_SCALE = 3;
|
|
10
10
|
const DOCX_ZOOM_STEP = 0.15;
|
|
11
|
-
const DOCX_VENDOR_ASSET_VERSION = '0.3.
|
|
11
|
+
const DOCX_VENDOR_ASSET_VERSION = '0.3.16';
|
|
12
12
|
const ZIP_SIGNATURE_PK = 0x504b;
|
|
13
13
|
const loadLibrary = (() => {
|
|
14
14
|
const loader = {
|
|
@@ -180,7 +180,7 @@ const DOCX_RESPONSIVE_CSS = `
|
|
|
180
180
|
}
|
|
181
181
|
.docx-fit-viewer .docx-flow-frame > section.docx {
|
|
182
182
|
height: auto !important;
|
|
183
|
-
min-height:
|
|
183
|
+
min-height: var(--docx-page-height, auto) !important;
|
|
184
184
|
overflow: visible !important;
|
|
185
185
|
}
|
|
186
186
|
.docx-fit-viewer .docx-page-frame > section.docx > article,
|
|
@@ -227,38 +227,51 @@ function makeDocxResponsive(target, context) {
|
|
|
227
227
|
const clampScale = (scale) => {
|
|
228
228
|
return Math.min(DOCX_MAX_SCALE, Math.max(DOCX_MIN_SCALE, Number(scale.toFixed(2))));
|
|
229
229
|
};
|
|
230
|
+
const applyResponsiveLayout = () => {
|
|
231
|
+
let firstScale = currentScale;
|
|
232
|
+
let firstFitScale = currentFitScale;
|
|
233
|
+
let measured = false;
|
|
234
|
+
frames.forEach(frame => {
|
|
235
|
+
const page = frame.firstElementChild;
|
|
236
|
+
if (!isTargetHTMLElement(page, target)) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
page.style.transform = 'translateX(-50%)';
|
|
240
|
+
const pageWidth = page.offsetWidth;
|
|
241
|
+
const contentHeight = pagedLayout
|
|
242
|
+
? page.offsetHeight
|
|
243
|
+
: Math.max(page.scrollHeight, page.offsetHeight);
|
|
244
|
+
if (!pageWidth || !contentHeight) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const availableWidth = Math.max(target.clientWidth - 28, 120);
|
|
248
|
+
const fitScale = Math.min(1, Math.max(DOCX_MIN_SCALE, availableWidth / pageWidth));
|
|
249
|
+
const scale = clampScale(fitScale * userZoom);
|
|
250
|
+
if (!measured) {
|
|
251
|
+
firstScale = scale;
|
|
252
|
+
firstFitScale = fitScale;
|
|
253
|
+
measured = true;
|
|
254
|
+
}
|
|
255
|
+
page.style.transform = `translateX(-50%) scale(${scale})`;
|
|
256
|
+
frame.style.width = `${Math.ceil(Math.max(pageWidth * scale, target.clientWidth - 28, 120))}px`;
|
|
257
|
+
frame.style.maxWidth = 'none';
|
|
258
|
+
frame.style.height = `${Math.ceil(contentHeight * scale)}px`;
|
|
259
|
+
});
|
|
260
|
+
if (!measured) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
currentScale = firstScale;
|
|
264
|
+
currentFitScale = firstFitScale;
|
|
265
|
+
zoomEmitter.emit();
|
|
266
|
+
};
|
|
230
267
|
const resize = () => {
|
|
231
268
|
if (!view) {
|
|
269
|
+
applyResponsiveLayout();
|
|
232
270
|
return;
|
|
233
271
|
}
|
|
234
272
|
view.cancelAnimationFrame(resizeFrame);
|
|
235
273
|
resizeFrame = view.requestAnimationFrame(() => {
|
|
236
|
-
|
|
237
|
-
frames.forEach(frame => {
|
|
238
|
-
const page = frame.firstElementChild;
|
|
239
|
-
if (!isTargetHTMLElement(page, target)) {
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
page.style.transform = 'translateX(-50%)';
|
|
243
|
-
const pageWidth = page.offsetWidth;
|
|
244
|
-
const contentHeight = pagedLayout
|
|
245
|
-
? page.offsetHeight
|
|
246
|
-
: Math.max(page.scrollHeight, page.offsetHeight);
|
|
247
|
-
if (!pageWidth || !contentHeight) {
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
const availableWidth = Math.max(target.clientWidth - 28, 120);
|
|
251
|
-
const fitScale = Math.min(1, Math.max(DOCX_MIN_SCALE, availableWidth / pageWidth));
|
|
252
|
-
const scale = clampScale(fitScale * userZoom);
|
|
253
|
-
firstScale = scale;
|
|
254
|
-
currentFitScale = fitScale;
|
|
255
|
-
page.style.transform = `translateX(-50%) scale(${scale})`;
|
|
256
|
-
frame.style.width = `${Math.ceil(Math.max(pageWidth * scale, target.clientWidth - 28, 120))}px`;
|
|
257
|
-
frame.style.maxWidth = 'none';
|
|
258
|
-
frame.style.height = `${Math.ceil(contentHeight * scale)}px`;
|
|
259
|
-
});
|
|
260
|
-
currentScale = firstScale;
|
|
261
|
-
zoomEmitter.emit();
|
|
274
|
+
applyResponsiveLayout();
|
|
262
275
|
});
|
|
263
276
|
};
|
|
264
277
|
const getZoomState = () => ({
|
|
@@ -272,13 +285,14 @@ function makeDocxResponsive(target, context) {
|
|
|
272
285
|
});
|
|
273
286
|
const setUserZoom = (nextZoom) => {
|
|
274
287
|
userZoom = Math.min(6, Math.max(0.2, Number(nextZoom.toFixed(2))));
|
|
275
|
-
|
|
288
|
+
view === null || view === void 0 ? void 0 : view.cancelAnimationFrame(resizeFrame);
|
|
289
|
+
applyResponsiveLayout();
|
|
276
290
|
return getZoomState();
|
|
277
291
|
};
|
|
278
292
|
target.dataset.viewerZoomProvider = 'docx';
|
|
279
293
|
registerFileViewerZoomProvider(target, {
|
|
280
|
-
zoomIn: () => setUserZoom(
|
|
281
|
-
zoomOut: () => setUserZoom(
|
|
294
|
+
zoomIn: () => setUserZoom((currentScale + DOCX_ZOOM_STEP) / Math.max(currentFitScale, 0.01)),
|
|
295
|
+
zoomOut: () => setUserZoom((currentScale - DOCX_ZOOM_STEP) / Math.max(currentFitScale, 0.01)),
|
|
282
296
|
resetZoom: () => setUserZoom(1),
|
|
283
297
|
setZoom: scale => setUserZoom(scale / Math.max(currentFitScale, 0.01)),
|
|
284
298
|
getState: getZoomState,
|
|
@@ -292,7 +306,7 @@ function makeDocxResponsive(target, context) {
|
|
|
292
306
|
observer === null || observer === void 0 ? void 0 : observer.observe(page);
|
|
293
307
|
}
|
|
294
308
|
});
|
|
295
|
-
|
|
309
|
+
applyResponsiveLayout();
|
|
296
310
|
return () => {
|
|
297
311
|
view === null || view === void 0 ? void 0 : view.cancelAnimationFrame(resizeFrame);
|
|
298
312
|
observer === null || observer === void 0 ? void 0 : observer.disconnect();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/renderer-word",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.14",
|
|
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, @file-viewer/doc, and RTF/ODF parsing.",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"LICENSE"
|
|
58
58
|
],
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@file-viewer/core": "^2.1.
|
|
61
|
-
"@file-viewer/doc": "^2.1.
|
|
62
|
-
"@file-viewer/docx": "^0.3.
|
|
60
|
+
"@file-viewer/core": "^2.1.14",
|
|
61
|
+
"@file-viewer/doc": "^2.1.14",
|
|
62
|
+
"@file-viewer/docx": "^0.3.16",
|
|
63
63
|
"jszip": "^3.10.1",
|
|
64
64
|
"rtf.js": "^3.0.9"
|
|
65
65
|
},
|