@file-viewer/renderer-word 2.1.16 → 2.1.18
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/index.js +1 -1
- package/dist/openDocument.d.ts +2 -2
- package/dist/openDocument.js +18 -11
- package/dist/wordDocx.js +6 -5
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ if (wordDefinitions.length !== wordRendererIds.length) {
|
|
|
11
11
|
export const wordRendererDefinitions = wordDefinitions;
|
|
12
12
|
export const renderFileViewerWordDocx = (buffer, target, _type, context) => import('./wordDocx.js').then(({ default: renderWordDocx }) => renderWordDocx(buffer, target, context));
|
|
13
13
|
export const renderFileViewerWordDoc = (buffer, target, _type, context) => import('./wordDoc.js').then(({ default: renderWordDoc }) => renderWordDoc(buffer, target, context));
|
|
14
|
-
export const renderFileViewerOpenDocument = (buffer, target, type) => import('./openDocument.js').then(({ default: renderOpenDocument }) => renderOpenDocument(buffer, target, type));
|
|
14
|
+
export const renderFileViewerOpenDocument = (buffer, target, type, context) => import('./openDocument.js').then(({ default: renderOpenDocument }) => renderOpenDocument(buffer, target, type, context));
|
|
15
15
|
export const wordRenderer = {
|
|
16
16
|
id: 'file-viewer-renderer-word',
|
|
17
17
|
label: 'Flyfish File Viewer Word renderer',
|
package/dist/openDocument.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export default function renderOpenDocument(buffer: ArrayBuffer, target: HTMLDivElement, type?: string): Promise<FileViewerRenderedInstance>;
|
|
1
|
+
import { type FileRenderContext, type FileViewerRenderedInstance } from '@file-viewer/core';
|
|
2
|
+
export default function renderOpenDocument(buffer: ArrayBuffer, target: HTMLDivElement, type?: string, context?: FileRenderContext): Promise<FileViewerRenderedInstance>;
|
package/dist/openDocument.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import JSZip from 'jszip';
|
|
2
|
+
import { createFileViewerTranslator, } from '@file-viewer/core';
|
|
2
3
|
const openDocumentStyle = `
|
|
3
4
|
.odf-viewer{min-height:100%;padding:28px;overflow:auto;background:#dfe5eb;box-sizing:border-box}
|
|
4
5
|
.odf-shell{width:min(100%,980px);margin:0 auto}.odf-shell>header{margin-bottom:18px;padding:18px 22px;border-radius:8px;background:#fff;box-shadow:0 10px 26px rgba(15,23,42,.1);box-sizing:border-box}
|
|
@@ -30,17 +31,17 @@ const appendText = (parent, tag, text, className) => {
|
|
|
30
31
|
const nodeText = (node) => {
|
|
31
32
|
return (node.textContent || '').replace(/\s+/g, ' ').trim();
|
|
32
33
|
};
|
|
33
|
-
const parseOdf = async (buffer, type) => {
|
|
34
|
+
const parseOdf = async (buffer, type, t) => {
|
|
34
35
|
var _a;
|
|
35
36
|
const zip = await JSZip.loadAsync(buffer);
|
|
36
37
|
const content = await ((_a = zip.file('content.xml')) === null || _a === void 0 ? void 0 : _a.async('text'));
|
|
37
38
|
if (!content) {
|
|
38
|
-
throw new Error('
|
|
39
|
+
throw new Error(t('word.error.missingOdfContent'));
|
|
39
40
|
}
|
|
40
41
|
const doc = new DOMParser().parseFromString(content, 'application/xml');
|
|
41
42
|
const parseError = doc.querySelector('parsererror');
|
|
42
43
|
if (parseError) {
|
|
43
|
-
throw new Error(
|
|
44
|
+
throw new Error(t('word.error.odfXmlParseFailed'));
|
|
44
45
|
}
|
|
45
46
|
if (type === 'odp') {
|
|
46
47
|
const slides = Array.from(doc.getElementsByTagName('draw:page'));
|
|
@@ -48,14 +49,17 @@ const parseOdf = async (buffer, type) => {
|
|
|
48
49
|
const blocks = Array.from(slide.getElementsByTagName('text:p'))
|
|
49
50
|
.map(nodeText)
|
|
50
51
|
.filter(Boolean);
|
|
51
|
-
return {
|
|
52
|
+
return {
|
|
53
|
+
title: t('word.page.fallback', { page: index + 1 }),
|
|
54
|
+
blocks: blocks.length ? blocks : [t('word.page.empty')],
|
|
55
|
+
};
|
|
52
56
|
});
|
|
53
57
|
}
|
|
54
58
|
const blocks = [
|
|
55
59
|
...Array.from(doc.getElementsByTagName('text:h')).map(nodeText),
|
|
56
60
|
...Array.from(doc.getElementsByTagName('text:p')).map(nodeText),
|
|
57
61
|
].filter(Boolean);
|
|
58
|
-
return [{ title: '
|
|
62
|
+
return [{ title: t('word.body'), blocks: blocks.length ? blocks : [t('word.body.empty')] }];
|
|
59
63
|
};
|
|
60
64
|
const renderOdfPages = (type, title, pages) => {
|
|
61
65
|
const root = document.createElement('div');
|
|
@@ -80,7 +84,7 @@ const resolveRtfJs = async () => {
|
|
|
80
84
|
const rtfModule = await import('rtf.js/dist/RTFJS.bundle.js');
|
|
81
85
|
return rtfModule.RTFJS || rtfModule.default || rtfModule;
|
|
82
86
|
};
|
|
83
|
-
const renderRtf = async (buffer, target) => {
|
|
87
|
+
const renderRtf = async (buffer, target, t) => {
|
|
84
88
|
var _a, _b;
|
|
85
89
|
const RTFJS = await resolveRtfJs();
|
|
86
90
|
(_a = RTFJS.loggingEnabled) === null || _a === void 0 ? void 0 : _a.call(RTFJS, false);
|
|
@@ -92,7 +96,7 @@ const renderRtf = async (buffer, target) => {
|
|
|
92
96
|
const header = document.createElement('div');
|
|
93
97
|
header.className = 'flyfish-rtf-header';
|
|
94
98
|
appendText(header, 'span', 'RTF');
|
|
95
|
-
appendText(header, 'strong', meta.title || '
|
|
99
|
+
appendText(header, 'strong', meta.title || t('word.title.rtf'));
|
|
96
100
|
const paper = document.createElement('article');
|
|
97
101
|
paper.className = 'flyfish-rtf-paper';
|
|
98
102
|
elements.forEach((element) => paper.appendChild(element));
|
|
@@ -105,13 +109,16 @@ const renderRtf = async (buffer, target) => {
|
|
|
105
109
|
},
|
|
106
110
|
};
|
|
107
111
|
};
|
|
108
|
-
export default async function renderOpenDocument(buffer, target, type) {
|
|
112
|
+
export default async function renderOpenDocument(buffer, target, type, context) {
|
|
113
|
+
const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
|
|
109
114
|
const normalizedType = (type || 'odt').toLowerCase();
|
|
110
115
|
if (normalizedType === 'rtf') {
|
|
111
|
-
return renderRtf(buffer, target);
|
|
116
|
+
return renderRtf(buffer, target, t);
|
|
112
117
|
}
|
|
113
|
-
const pages = await parseOdf(buffer, normalizedType);
|
|
114
|
-
const title = normalizedType === 'odp'
|
|
118
|
+
const pages = await parseOdf(buffer, normalizedType, t);
|
|
119
|
+
const title = normalizedType === 'odp'
|
|
120
|
+
? t('word.title.openDocumentPresentation')
|
|
121
|
+
: t('word.title.openDocumentText');
|
|
115
122
|
target.replaceChildren(createStyle(), renderOdfPages(normalizedType, title, pages));
|
|
116
123
|
return {
|
|
117
124
|
$el: target,
|
package/dist/wordDocx.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolveFileViewerDocxWorkerJsZipUrl, resolveFileViewerDocxWorkerUrl, } from '@file-viewer/core/assets';
|
|
2
|
-
import { applyPrintPageSize, buildPrintPageStyle, createFileViewerZoomChangeEmitter as createZoomChangeEmitter, formatCssPixels, getElementPrintPageSize, registerFileViewerZoomProvider, unregisterFileViewerZoomProvider, } from '@file-viewer/core';
|
|
2
|
+
import { applyPrintPageSize, buildPrintPageStyle, createFileViewerTranslator, createFileViewerZoomChangeEmitter as createZoomChangeEmitter, formatCssPixels, getElementPrintPageSize, registerFileViewerZoomProvider, unregisterFileViewerZoomProvider, } from '@file-viewer/core';
|
|
3
3
|
const DOCX_DEFAULT_PAGE_SIZE = {
|
|
4
4
|
width: 794,
|
|
5
5
|
height: 1123
|
|
@@ -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.17';
|
|
12
12
|
const ZIP_SIGNATURE_PK = 0x504b;
|
|
13
13
|
const loadLibrary = (() => {
|
|
14
14
|
const loader = {
|
|
@@ -29,12 +29,12 @@ const loadLibrary = (() => {
|
|
|
29
29
|
* with a ZIP signature. This catches common enterprise download failures where
|
|
30
30
|
* an object-storage XML error page is saved with a `.docx` extension.
|
|
31
31
|
*/
|
|
32
|
-
const assertValidDocxPackage = (buffer) => {
|
|
32
|
+
const assertValidDocxPackage = (buffer, context) => {
|
|
33
33
|
const signature = buffer.byteLength >= 4 ? new DataView(buffer).getUint16(0, false) : 0;
|
|
34
34
|
if (signature === ZIP_SIGNATURE_PK) {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
throw new Error(
|
|
37
|
+
throw new Error(createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options)('word.error.invalidDocx'));
|
|
38
38
|
};
|
|
39
39
|
const getTargetWindow = (target) => {
|
|
40
40
|
return target.ownerDocument.defaultView;
|
|
@@ -396,7 +396,8 @@ function prepareDocxCloneForExport(target) {
|
|
|
396
396
|
*/
|
|
397
397
|
export default async function (buffer, target, context) {
|
|
398
398
|
var _a;
|
|
399
|
-
assertValidDocxPackage(buffer);
|
|
399
|
+
assertValidDocxPackage(buffer, context);
|
|
400
|
+
target.innerHTML = '';
|
|
400
401
|
let hasNotifiedProgressiveRender = false;
|
|
401
402
|
const notifyProgressiveRender = () => {
|
|
402
403
|
var _a;
|
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.18",
|
|
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.",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"funding": {
|
|
39
39
|
"type": "individual",
|
|
40
|
-
"url": "https://dev.flyfish.group/
|
|
40
|
+
"url": "https://dev.flyfish.group/donate?source=npm"
|
|
41
41
|
},
|
|
42
42
|
"main": "./dist/index.js",
|
|
43
43
|
"module": "./dist/index.js",
|
|
@@ -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.18",
|
|
61
|
+
"@file-viewer/doc": "^2.1.18",
|
|
62
|
+
"@file-viewer/docx": "^0.3.17",
|
|
63
63
|
"jszip": "^3.10.1",
|
|
64
64
|
"rtf.js": "^3.0.9"
|
|
65
65
|
},
|