@file-viewer/renderer-ofd 2.1.17 → 2.1.19
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/ofd.js +10 -12
- package/package.json +2 -2
package/dist/ofd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createFileViewerZoomChangeEmitter, registerFileViewerZoomProvider, unregisterFileViewerZoomProvider, } from '@file-viewer/core';
|
|
1
|
+
import { createFileViewerTranslator, createFileViewerZoomChangeEmitter, normalizeFileViewerErrorMessage, registerFileViewerZoomProvider, unregisterFileViewerZoomProvider, } from '@file-viewer/core';
|
|
2
2
|
const OFD_MIN_SCALE = 0.35;
|
|
3
3
|
const OFD_MAX_SCALE = 3;
|
|
4
4
|
const OFD_ZOOM_STEP = 0.1;
|
|
@@ -38,18 +38,15 @@ const createElement = (documentRef, tagName, className, text) => {
|
|
|
38
38
|
}
|
|
39
39
|
return element;
|
|
40
40
|
};
|
|
41
|
-
const normalizeError = (reason) => {
|
|
42
|
-
if (reason instanceof Error) {
|
|
43
|
-
return reason.
|
|
44
|
-
}
|
|
45
|
-
if (typeof reason === 'string') {
|
|
46
|
-
return reason;
|
|
41
|
+
const normalizeError = (reason, fallback, context) => {
|
|
42
|
+
if (reason instanceof Error || typeof reason === 'string') {
|
|
43
|
+
return normalizeFileViewerErrorMessage(reason, context === null || context === void 0 ? void 0 : context.options);
|
|
47
44
|
}
|
|
48
45
|
try {
|
|
49
46
|
return JSON.stringify(reason);
|
|
50
47
|
}
|
|
51
48
|
catch {
|
|
52
|
-
return String(reason ||
|
|
49
|
+
return String(reason || fallback);
|
|
53
50
|
}
|
|
54
51
|
};
|
|
55
52
|
const clampZoom = (value) => Math.min(OFD_MAX_SCALE, Math.max(OFD_MIN_SCALE, Number(value.toFixed(2))));
|
|
@@ -82,6 +79,7 @@ const appendPages = (documentRef, target, pages) => {
|
|
|
82
79
|
target.appendChild(fragment);
|
|
83
80
|
};
|
|
84
81
|
export default async function renderOfd(buffer, target, context) {
|
|
82
|
+
const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
|
|
85
83
|
const documentRef = target.ownerDocument || document;
|
|
86
84
|
const targetWindow = documentRef.defaultView || (typeof window !== 'undefined' ? window : null);
|
|
87
85
|
const zoomEmitter = createFileViewerZoomChangeEmitter();
|
|
@@ -97,7 +95,7 @@ export default async function renderOfd(buffer, target, context) {
|
|
|
97
95
|
const style = createStyle(documentRef);
|
|
98
96
|
const viewer = createElement(documentRef, 'div', 'ofd-viewer');
|
|
99
97
|
viewer.dataset.viewerZoomProvider = 'ofd';
|
|
100
|
-
const stateNode = createElement(documentRef, 'div', 'ofd-state', '
|
|
98
|
+
const stateNode = createElement(documentRef, 'div', 'ofd-state', t('ofd.state.loading'));
|
|
101
99
|
stateNode.setAttribute('aria-live', 'polite');
|
|
102
100
|
const stage = createElement(documentRef, 'div', 'ofd-stage');
|
|
103
101
|
viewer.append(stateNode, stage);
|
|
@@ -108,14 +106,14 @@ export default async function renderOfd(buffer, target, context) {
|
|
|
108
106
|
const syncState = () => {
|
|
109
107
|
stateNode.hidden = state === 'ready';
|
|
110
108
|
stateNode.classList.toggle('error', state === 'error');
|
|
111
|
-
stateNode.textContent = state === 'error' ? errorMessage : '
|
|
109
|
+
stateNode.textContent = state === 'error' ? errorMessage : t('ofd.state.loading');
|
|
112
110
|
};
|
|
113
111
|
const getOfdDocument = async (ofd) => {
|
|
114
112
|
// OFD 解压和 XML 解析成本较高,尺寸变化只重排页面,不重复解析压缩包。
|
|
115
113
|
ofdDocumentPromise || (ofdDocumentPromise = parseWithOfdJs(ofd, buffer).then(documents => {
|
|
116
114
|
const ofdDocument = documents[0];
|
|
117
115
|
if (!ofdDocument) {
|
|
118
|
-
throw new Error('
|
|
116
|
+
throw new Error(t('ofd.error.empty'));
|
|
119
117
|
}
|
|
120
118
|
return ofdDocument;
|
|
121
119
|
}));
|
|
@@ -217,7 +215,7 @@ export default async function renderOfd(buffer, target, context) {
|
|
|
217
215
|
}
|
|
218
216
|
console.error(reason);
|
|
219
217
|
state = 'error';
|
|
220
|
-
errorMessage = normalizeError(reason) || '
|
|
218
|
+
errorMessage = normalizeError(reason, t('ofd.error.parseFailed'), context) || t('ofd.error.parseFailed');
|
|
221
219
|
syncState();
|
|
222
220
|
}
|
|
223
221
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/renderer-ofd",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.19",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone OFD renderer plugin for Flyfish File Viewer powered by DLTech21/ofd.js.",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"LICENSE"
|
|
54
54
|
],
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@file-viewer/core": "^2.1.
|
|
56
|
+
"@file-viewer/core": "^2.1.19",
|
|
57
57
|
"jszip": "^3.10.1"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|