@file-viewer/renderer-ofd 2.1.28 → 2.1.30
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 +71 -7
- package/package.json +2 -2
- package/vendor/dltech/ofd/pipeline.js +4 -19
package/dist/ofd.js
CHANGED
|
@@ -84,8 +84,41 @@ const appendPages = (documentRef, target, pages) => {
|
|
|
84
84
|
});
|
|
85
85
|
target.appendChild(fragment);
|
|
86
86
|
};
|
|
87
|
+
const replacePages = (documentRef, target, pages) => {
|
|
88
|
+
const existingFrames = Array.from(target.children).filter((element) => {
|
|
89
|
+
var _a;
|
|
90
|
+
return (element instanceof (((_a = target.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.HTMLElement) || HTMLElement) &&
|
|
91
|
+
element.classList.contains('ofd-page-frame'));
|
|
92
|
+
});
|
|
93
|
+
const designerActive = existingFrames.some(frame => (frame.querySelector('.fv-print-mask-canvas')));
|
|
94
|
+
if (!designerActive) {
|
|
95
|
+
target.replaceChildren();
|
|
96
|
+
appendPages(documentRef, target, pages);
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
if (existingFrames.length !== pages.length) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
// The print-mask designer owns canvases attached to these stable frame
|
|
103
|
+
// nodes. Replace only the rendered OFD page so a resize cannot detach the
|
|
104
|
+
// active drawing surface or lose its pointer handlers.
|
|
105
|
+
pages.forEach((page, index) => {
|
|
106
|
+
const frame = existingFrames[index];
|
|
107
|
+
const previousPage = Array.from(frame.children).find(child => (child.classList.contains('ofd-page')));
|
|
108
|
+
if (!frame || !previousPage) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
page.classList.add('ofd-page');
|
|
112
|
+
page.dataset.viewerThemeBoundary = 'light';
|
|
113
|
+
page.style.backgroundColor = '#fff';
|
|
114
|
+
page.style.color = '#111827';
|
|
115
|
+
page.style.colorScheme = 'only light';
|
|
116
|
+
previousPage.replaceWith(page);
|
|
117
|
+
});
|
|
118
|
+
return true;
|
|
119
|
+
};
|
|
87
120
|
export default async function renderOfd(buffer, target, context) {
|
|
88
|
-
var _a;
|
|
121
|
+
var _a, _b;
|
|
89
122
|
const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
|
|
90
123
|
const documentRef = target.ownerDocument || document;
|
|
91
124
|
const targetWindow = documentRef.defaultView || (typeof window !== 'undefined' ? window : null);
|
|
@@ -185,10 +218,13 @@ export default async function renderOfd(buffer, target, context) {
|
|
|
185
218
|
return Promise.resolve(ofd.renderOfd(width, ofdDocument));
|
|
186
219
|
};
|
|
187
220
|
const render = async (options = {}) => {
|
|
188
|
-
var _a;
|
|
221
|
+
var _a, _b, _c;
|
|
189
222
|
if (disposed) {
|
|
190
223
|
return;
|
|
191
224
|
}
|
|
225
|
+
if ((_a = context === null || context === void 0 ? void 0 : context.signal) === null || _a === void 0 ? void 0 : _a.aborted) {
|
|
226
|
+
throw context.signal.reason || new DOMException('OFD rendering aborted.', 'AbortError');
|
|
227
|
+
}
|
|
192
228
|
const width = getRenderWidth();
|
|
193
229
|
if (!options.force && state === 'ready' && Math.abs(width - lastRenderedWidth) < 8) {
|
|
194
230
|
return;
|
|
@@ -206,15 +242,19 @@ export default async function renderOfd(buffer, target, context) {
|
|
|
206
242
|
if (disposed || version !== renderVersion) {
|
|
207
243
|
return;
|
|
208
244
|
}
|
|
209
|
-
|
|
210
|
-
|
|
245
|
+
if ((_b = context === null || context === void 0 ? void 0 : context.signal) === null || _b === void 0 ? void 0 : _b.aborted) {
|
|
246
|
+
throw context.signal.reason || new DOMException('OFD rendering aborted.', 'AbortError');
|
|
247
|
+
}
|
|
248
|
+
if (!replacePages(documentRef, stage, pages)) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
211
251
|
lastRenderedWidth = width;
|
|
212
252
|
await waitForPaint(targetWindow);
|
|
213
253
|
syncPageZoom();
|
|
214
254
|
state = 'ready';
|
|
215
255
|
syncState();
|
|
216
256
|
zoomEmitter.emit();
|
|
217
|
-
(
|
|
257
|
+
(_c = context === null || context === void 0 ? void 0 : context.onProgressiveRender) === null || _c === void 0 ? void 0 : _c.call(context);
|
|
218
258
|
}
|
|
219
259
|
catch (reason) {
|
|
220
260
|
if (disposed || version !== renderVersion) {
|
|
@@ -224,6 +264,9 @@ export default async function renderOfd(buffer, target, context) {
|
|
|
224
264
|
state = 'error';
|
|
225
265
|
errorMessage = normalizeError(reason, t('ofd.error.parseFailed'), context) || t('ofd.error.parseFailed');
|
|
226
266
|
syncState();
|
|
267
|
+
if (options.rejectOnError) {
|
|
268
|
+
throw reason;
|
|
269
|
+
}
|
|
227
270
|
}
|
|
228
271
|
};
|
|
229
272
|
const startResizeObserver = () => {
|
|
@@ -238,11 +281,19 @@ export default async function renderOfd(buffer, target, context) {
|
|
|
238
281
|
});
|
|
239
282
|
resizeObserver.observe(viewer);
|
|
240
283
|
};
|
|
241
|
-
|
|
284
|
+
try {
|
|
285
|
+
// Do not report the renderer as loaded until page surfaces exist. This
|
|
286
|
+
// keeps immediate print/mask operations page-aware and propagates initial
|
|
287
|
+
// parse failures through the normal renderer error lifecycle.
|
|
288
|
+
await render({ force: true, showLoading: true, rejectOnError: true });
|
|
242
289
|
if (!disposed) {
|
|
243
290
|
startResizeObserver();
|
|
244
291
|
}
|
|
245
|
-
}
|
|
292
|
+
}
|
|
293
|
+
catch (error) {
|
|
294
|
+
unregisterFileViewerZoomProvider(viewer);
|
|
295
|
+
throw error;
|
|
296
|
+
}
|
|
246
297
|
(_a = context === null || context === void 0 ? void 0 : context.registerThumbnailAdapter) === null || _a === void 0 ? void 0 : _a.call(context, {
|
|
247
298
|
beforeCapture: async ({ signal }) => {
|
|
248
299
|
while (state === 'loading' && !disposed) {
|
|
@@ -262,6 +313,19 @@ export default async function renderOfd(buffer, target, context) {
|
|
|
262
313
|
},
|
|
263
314
|
getTarget: () => stage.querySelector('.ofd-page-frame, .ofd-page') || stage,
|
|
264
315
|
});
|
|
316
|
+
(_b = context === null || context === void 0 ? void 0 : context.registerExportAdapter) === null || _b === void 0 ? void 0 : _b.call(context, {
|
|
317
|
+
print: true,
|
|
318
|
+
exportHtml: true,
|
|
319
|
+
includeDocumentStyles: true,
|
|
320
|
+
getPrintMaskPages: () => Array.from(stage.querySelectorAll('.ofd-page-frame')),
|
|
321
|
+
toHtml: () => {
|
|
322
|
+
const clone = stage.cloneNode(true);
|
|
323
|
+
clone.querySelectorAll('.ofd-page-frame').forEach((page, index) => {
|
|
324
|
+
page.dataset.viewerPrintPageIndex = String(index);
|
|
325
|
+
});
|
|
326
|
+
return clone.outerHTML;
|
|
327
|
+
},
|
|
328
|
+
});
|
|
265
329
|
return {
|
|
266
330
|
$el: viewer,
|
|
267
331
|
unmount() {
|
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.30",
|
|
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.30",
|
|
57
57
|
"jszip": "^3.10.1"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
'use strict';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// does not support strict mode, so this check is actually useless.
|
|
8
|
-
throw new TypeError(
|
|
9
|
-
'Array.prototype.pipeline called on null or undefined');
|
|
10
|
-
}
|
|
11
|
-
if ('function' !== typeof callback) {
|
|
12
|
-
throw new TypeError(callback + ' is not a function');
|
|
13
|
-
}
|
|
14
|
-
var index, value,
|
|
15
|
-
length = this.length >>> 0;
|
|
16
|
-
for (index = 0; length > index; ++index) {
|
|
17
|
-
value = await callback(value, this[index], index, this);
|
|
3
|
+
const _pipeline = async function(...funcs){
|
|
4
|
+
let value;
|
|
5
|
+
for (let index = 0; index < funcs.length; index += 1) {
|
|
6
|
+
value = await funcs[index].call(this, value);
|
|
18
7
|
}
|
|
19
8
|
return value;
|
|
20
9
|
};
|
|
21
10
|
|
|
22
|
-
let _pipeline = function(...funcs){
|
|
23
|
-
return funcs.pipeline((a, b) => b.call(this, a));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
11
|
export const pipeline = _pipeline;
|