@file-viewer/renderer-image 2.2.3 → 2.2.4
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/image.js +42 -8
- package/package.json +2 -2
package/dist/image.js
CHANGED
|
@@ -68,6 +68,29 @@ const resolveImageUrl = async (buffer, type) => {
|
|
|
68
68
|
}
|
|
69
69
|
return readBlobDataUrl(new Blob([buffer], { type: getImageBlobType(normalizedType) }));
|
|
70
70
|
};
|
|
71
|
+
const waitForImageReady = async (image) => {
|
|
72
|
+
if (image.complete) {
|
|
73
|
+
if (image.naturalWidth > 0 && image.naturalHeight > 0)
|
|
74
|
+
return;
|
|
75
|
+
throw new Error('The browser could not decode this image format.');
|
|
76
|
+
}
|
|
77
|
+
await new Promise((resolve, reject) => {
|
|
78
|
+
const cleanup = () => {
|
|
79
|
+
image.removeEventListener('load', onLoad);
|
|
80
|
+
image.removeEventListener('error', onError);
|
|
81
|
+
};
|
|
82
|
+
const onLoad = () => {
|
|
83
|
+
cleanup();
|
|
84
|
+
resolve();
|
|
85
|
+
};
|
|
86
|
+
const onError = () => {
|
|
87
|
+
cleanup();
|
|
88
|
+
reject(new Error('The browser could not decode this image format.'));
|
|
89
|
+
};
|
|
90
|
+
image.addEventListener('load', onLoad, { once: true });
|
|
91
|
+
image.addEventListener('error', onError, { once: true });
|
|
92
|
+
});
|
|
93
|
+
};
|
|
71
94
|
const roundImageScale = (value) => {
|
|
72
95
|
return Number(value.toFixed(3));
|
|
73
96
|
};
|
|
@@ -251,17 +274,28 @@ export default async function renderImage(buffer, target, type, context) {
|
|
|
251
274
|
target.replaceChildren(createStyle(documentRef), root);
|
|
252
275
|
(((_b = context === null || context === void 0 ? void 0 : context.surface) === null || _b === void 0 ? void 0 : _b.shadowRoot) || target).append(lightbox.element);
|
|
253
276
|
updateViewportSize();
|
|
277
|
+
const cleanup = () => {
|
|
278
|
+
var _a;
|
|
279
|
+
(_a = context === null || context === void 0 ? void 0 : context.registerThumbnailAdapter) === null || _a === void 0 ? void 0 : _a.call(context, null);
|
|
280
|
+
unregisterFileViewerZoomProvider(root);
|
|
281
|
+
resizeObserver.disconnect();
|
|
282
|
+
image.removeEventListener('load', updateViewportSize);
|
|
283
|
+
image.removeEventListener('click', openLightbox);
|
|
284
|
+
lightbox.destroy();
|
|
285
|
+
target.replaceChildren();
|
|
286
|
+
};
|
|
287
|
+
try {
|
|
288
|
+
await waitForImageReady(image);
|
|
289
|
+
updateViewportSize();
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
cleanup();
|
|
293
|
+
throw error;
|
|
294
|
+
}
|
|
254
295
|
return {
|
|
255
296
|
$el: target,
|
|
256
297
|
unmount() {
|
|
257
|
-
|
|
258
|
-
(_a = context === null || context === void 0 ? void 0 : context.registerThumbnailAdapter) === null || _a === void 0 ? void 0 : _a.call(context, null);
|
|
259
|
-
unregisterFileViewerZoomProvider(root);
|
|
260
|
-
resizeObserver.disconnect();
|
|
261
|
-
image.removeEventListener('load', updateViewportSize);
|
|
262
|
-
image.removeEventListener('click', openLightbox);
|
|
263
|
-
lightbox.destroy();
|
|
264
|
-
target.replaceChildren();
|
|
298
|
+
cleanup();
|
|
265
299
|
},
|
|
266
300
|
};
|
|
267
301
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/renderer-image",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone image renderer plugin for File Viewer with native image preview, HEIC/HEIF conversion, lightbox, and unified zoom support.",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"LICENSE"
|
|
55
55
|
],
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@file-viewer/core": "2.2.
|
|
57
|
+
"@file-viewer/core": "2.2.4",
|
|
58
58
|
"heic2any": "^0.0.4"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|