@file-viewer/pptx
Advanced tools
+4
-0
@@ -23,2 +23,3 @@ import type { PptxViewerOptions } from './types'; | ||
| private charts; | ||
| private readonly mediaRecords; | ||
| private disposed; | ||
@@ -63,2 +64,5 @@ private completed; | ||
| private fail; | ||
| private storeMedia; | ||
| private hydrateMedia; | ||
| private releaseMedia; | ||
| private attachResizeObserver; | ||
@@ -65,0 +69,0 @@ private scheduleResize; |
+75
-0
@@ -103,2 +103,3 @@ import { renderPptxPostProcessing } from './chart.js'; | ||
| this.charts = null; | ||
| this.mediaRecords = new Map(); | ||
| this.disposed = false; | ||
@@ -143,2 +144,3 @@ this.completed = false; | ||
| this.previewThumbnailDataUrl = null; | ||
| this.releaseMedia(); | ||
| (_a = this.worker) === null || _a === void 0 ? void 0 : _a.terminate(); | ||
@@ -160,2 +162,3 @@ this.worker = null; | ||
| (_a = this.worker) === null || _a === void 0 ? void 0 : _a.terminate(); | ||
| this.releaseMedia(); | ||
| this.completed = false; | ||
@@ -201,2 +204,3 @@ this.charts = null; | ||
| const element = appendHtml(this.content, String(message.data || '')); | ||
| this.hydrateMedia(element); | ||
| this.scheduleResize(); | ||
@@ -207,2 +211,5 @@ (_b = (_a = this.options).onSlideRendered) === null || _b === void 0 ? void 0 : _b.call(_a, Number(message.slide_num || 0), element); | ||
| } | ||
| case 'media': | ||
| this.storeMedia(message.data); | ||
| break; | ||
| case 'slide-error': { | ||
@@ -341,2 +348,3 @@ const slideNumber = Number(message.slide_num || 0); | ||
| record.element = appendHtml(record.slot, record.html); | ||
| this.hydrateMedia(record.element); | ||
| record.slot.append(...designerCanvases); | ||
@@ -612,5 +620,72 @@ record.rendered = true; | ||
| this.worker = null; | ||
| this.releaseMedia(); | ||
| this.content.dataset.renderState = 'error'; | ||
| (_c = (_b = this.options).onError) === null || _c === void 0 ? void 0 : _c.call(_b, error); | ||
| } | ||
| storeMedia(data) { | ||
| if (!data || typeof data !== 'object') { | ||
| return; | ||
| } | ||
| const media = data; | ||
| if (typeof media.id !== 'string' || | ||
| !media.id || | ||
| typeof media.mimeType !== 'string' || | ||
| !(media.buffer instanceof ArrayBuffer)) { | ||
| return; | ||
| } | ||
| this.releaseMedia(media.id); | ||
| this.mediaRecords.set(media.id, { | ||
| buffer: media.buffer, | ||
| mimeType: media.mimeType, | ||
| objectUrl: null, | ||
| revokeObjectUrl: null, | ||
| }); | ||
| this.hydrateMedia(this.content); | ||
| } | ||
| hydrateMedia(root) { | ||
| var _a; | ||
| if (!root) { | ||
| return; | ||
| } | ||
| const elements = Array.from(root.querySelectorAll('[data-pptx-media-id]')); | ||
| if (root.matches('[data-pptx-media-id]')) { | ||
| elements.unshift(root); | ||
| } | ||
| for (const element of elements) { | ||
| const mediaId = element.dataset.pptxMediaId; | ||
| const record = mediaId ? this.mediaRecords.get(mediaId) : undefined; | ||
| if (!record) { | ||
| continue; | ||
| } | ||
| if (!record.objectUrl) { | ||
| const view = this.target.ownerDocument.defaultView; | ||
| const BlobCtor = (view === null || view === void 0 ? void 0 : view.Blob) || globalThis.Blob; | ||
| const UrlApi = (view === null || view === void 0 ? void 0 : view.URL) || globalThis.URL; | ||
| if (typeof BlobCtor !== 'function' || | ||
| typeof (UrlApi === null || UrlApi === void 0 ? void 0 : UrlApi.createObjectURL) !== 'function') { | ||
| continue; | ||
| } | ||
| const objectUrl = UrlApi.createObjectURL(new BlobCtor([record.buffer], { type: record.mimeType })); | ||
| record.objectUrl = objectUrl; | ||
| record.revokeObjectUrl = () => UrlApi.revokeObjectURL(objectUrl); | ||
| } | ||
| if (element.src !== record.objectUrl) { | ||
| element.src = record.objectUrl; | ||
| (_a = element.load) === null || _a === void 0 ? void 0 : _a.call(element); | ||
| } | ||
| } | ||
| } | ||
| releaseMedia(mediaId) { | ||
| var _a, _b; | ||
| if (mediaId) { | ||
| const record = this.mediaRecords.get(mediaId); | ||
| (_a = record === null || record === void 0 ? void 0 : record.revokeObjectUrl) === null || _a === void 0 ? void 0 : _a.call(record); | ||
| this.mediaRecords.delete(mediaId); | ||
| return; | ||
| } | ||
| for (const record of this.mediaRecords.values()) { | ||
| (_b = record.revokeObjectUrl) === null || _b === void 0 ? void 0 : _b.call(record); | ||
| } | ||
| this.mediaRecords.clear(); | ||
| } | ||
| attachResizeObserver() { | ||
@@ -617,0 +692,0 @@ if (typeof ResizeObserver === 'undefined') { |
+1
-1
| { | ||
| "name": "@file-viewer/pptx", | ||
| "version": "2.2.3", | ||
| "version": "2.2.4", | ||
| "private": false, | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is too big to display
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
648767
0.81%3741
2.35%4
33.33%