@file-viewer/pptx 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/styles.d.ts +1 -1
- package/dist/styles.js +3 -0
- package/dist/types.d.ts +1 -1
- package/dist/viewer.d.ts +3 -0
- package/dist/viewer.js +81 -10
- package/dist/worker/pptx.worker.js +8 -8
- package/package.json +1 -1
package/dist/styles.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const pptxViewerCss = "\n.flyfish-pptx-scale-box{position:relative;box-sizing:border-box;max-width:100%;margin:0 auto;min-width:0}\n.flyfish-pptx-content{position:absolute;top:0;left:0;box-sizing:border-box;max-width:none;min-width:0;transform-origin:top left;will-change:transform}\n.flyfish-pptx-content[data-render-state=\"loading\"]{opacity:.82}\n.flyfish-pptx-slide-slot{display:flow-root;box-sizing:border-box;width:100%;min-width:0}\n.flyfish-pptx-content .slide{background:#fff;box-shadow:0 18px 36px rgba(18,35,52,.12)}\n.flyfish-pptx-thumbnail{display:block;box-sizing:border-box;width:min(960px,100%);height:auto;margin:0 auto 28px;border-radius:12px;background:#fff;box-shadow:0 18px 36px rgba(18,35,52,.14)}\n\n.slide{position:relative;border:0;border-radius:0;overflow:hidden;margin-bottom:50px;margin-left:auto;margin-right:auto;z-index:100}\n.slide div.block{position:absolute;top:0;left:0;width:100%;line-height:1}\n.slide div.content{display:flex;flex-direction:column}\n.slide div.diagram-content{display:flex;flex-direction:column}\n.slide div.content-rtl{display:flex;flex-direction:column;direction:rtl}\n.slide .pregraph-rtl{direction:rtl}\n.slide .pregraph-ltr{direction:ltr}\n.slide .pregraph-inherit{direction:inherit}\n.slide .slide-prgrph{width:100%}\n.slide .line-break-br::before{content:\"\\A\";white-space:pre}\n.slide div.v-up{justify-content:flex-start}\n.slide div.v-mid{justify-content:center}\n.slide div.v-down{justify-content:flex-end}\n.slide div.h-left{justify-content:flex-start;align-items:flex-start;text-align:left}\n.slide div.h-left-rtl{justify-content:flex-end;align-items:flex-end;text-align:left}\n.slide div.h-mid{justify-content:center;align-items:center;text-align:center}\n.slide div.h-right{justify-content:flex-end;align-items:flex-end;text-align:right}\n.slide div.h-right-rtl{justify-content:flex-start;align-items:flex-start;text-align:right}\n.slide div.h-just,.slide div.h-dist{text-align:justify}\n.slide div.up-left{justify-content:flex-start;align-items:flex-start;text-align:left}\n.slide div.up-center{justify-content:flex-start;align-items:center}\n.slide div.up-right{justify-content:flex-start;align-items:flex-end}\n.slide div.center-left{justify-content:center;align-items:flex-start;text-align:left}\n.slide div.center-center{justify-content:center;align-items:center}\n.slide div.center-right{justify-content:center;align-items:flex-end}\n.slide div.down-left{justify-content:flex-end;align-items:flex-start;text-align:left}\n.slide div.down-center{justify-content:flex-end;align-items:center}\n.slide div.down-right{justify-content:flex-end;align-items:flex-end}\n.slide li.slide{margin:10px 0;font-size:18px}\n.slide table{position:absolute}\n.slide svg.drawing{position:absolute;overflow:visible}\n\n.flyfish-pptx-content > .slide:last-of-type{margin-bottom:0}\n.flyfish-pptx-slide-slot:last-of-type > .slide{margin-bottom:0}\n";
|
|
1
|
+
export declare const pptxViewerCss = "\n.flyfish-pptx-scale-box{position:relative;box-sizing:border-box;max-width:100%;margin:0 auto;min-width:0}\n.flyfish-pptx-content{position:absolute;top:0;left:0;box-sizing:border-box;max-width:none;min-width:0;transform-origin:top left;will-change:transform}\n.flyfish-pptx-content[data-render-state=\"loading\"]{opacity:.82}\n.flyfish-pptx-slide-slot{display:flow-root;box-sizing:border-box;width:100%;min-width:0}\n.flyfish-pptx-slide-error{display:flex;align-items:center;justify-content:center;background:#fff7ed!important;color:#9a3412}\n.flyfish-pptx-slide-error-card{display:grid;gap:10px;max-width:70%;padding:24px;border:1px solid #fdba74;border-radius:12px;background:#fff;text-align:center;font:14px/1.5 system-ui,sans-serif}\n.flyfish-pptx-slide-error-card strong{font-size:18px}\n.flyfish-pptx-content .slide{background:#fff;box-shadow:0 18px 36px rgba(18,35,52,.12)}\n.flyfish-pptx-thumbnail{display:block;box-sizing:border-box;width:min(960px,100%);height:auto;margin:0 auto 28px;border-radius:12px;background:#fff;box-shadow:0 18px 36px rgba(18,35,52,.14)}\n\n.slide{position:relative;border:0;border-radius:0;overflow:hidden;margin-bottom:50px;margin-left:auto;margin-right:auto;z-index:100}\n.slide div.block{position:absolute;top:0;left:0;width:100%;line-height:1}\n.slide div.content{display:flex;flex-direction:column}\n.slide div.diagram-content{display:flex;flex-direction:column}\n.slide div.content-rtl{display:flex;flex-direction:column;direction:rtl}\n.slide .pregraph-rtl{direction:rtl}\n.slide .pregraph-ltr{direction:ltr}\n.slide .pregraph-inherit{direction:inherit}\n.slide .slide-prgrph{width:100%}\n.slide .line-break-br::before{content:\"\\A\";white-space:pre}\n.slide div.v-up{justify-content:flex-start}\n.slide div.v-mid{justify-content:center}\n.slide div.v-down{justify-content:flex-end}\n.slide div.h-left{justify-content:flex-start;align-items:flex-start;text-align:left}\n.slide div.h-left-rtl{justify-content:flex-end;align-items:flex-end;text-align:left}\n.slide div.h-mid{justify-content:center;align-items:center;text-align:center}\n.slide div.h-right{justify-content:flex-end;align-items:flex-end;text-align:right}\n.slide div.h-right-rtl{justify-content:flex-start;align-items:flex-start;text-align:right}\n.slide div.h-just,.slide div.h-dist{text-align:justify}\n.slide div.up-left{justify-content:flex-start;align-items:flex-start;text-align:left}\n.slide div.up-center{justify-content:flex-start;align-items:center}\n.slide div.up-right{justify-content:flex-start;align-items:flex-end}\n.slide div.center-left{justify-content:center;align-items:flex-start;text-align:left}\n.slide div.center-center{justify-content:center;align-items:center}\n.slide div.center-right{justify-content:center;align-items:flex-end}\n.slide div.down-left{justify-content:flex-end;align-items:flex-start;text-align:left}\n.slide div.down-center{justify-content:flex-end;align-items:center}\n.slide div.down-right{justify-content:flex-end;align-items:flex-end}\n.slide li.slide{margin:10px 0;font-size:18px}\n.slide table{position:absolute}\n.slide svg.drawing{position:absolute;overflow:visible}\n\n.flyfish-pptx-content > .slide:last-of-type{margin-bottom:0}\n.flyfish-pptx-slide-slot:last-of-type > .slide{margin-bottom:0}\n";
|
|
2
2
|
export declare const ensurePptxViewerStyles: (documentRef: Document, root?: Document | ShadowRoot) => void;
|
package/dist/styles.js
CHANGED
|
@@ -36,6 +36,9 @@ export const pptxViewerCss = `
|
|
|
36
36
|
.flyfish-pptx-content{position:absolute;top:0;left:0;box-sizing:border-box;max-width:none;min-width:0;transform-origin:top left;will-change:transform}
|
|
37
37
|
.flyfish-pptx-content[data-render-state="loading"]{opacity:.82}
|
|
38
38
|
.flyfish-pptx-slide-slot{display:flow-root;box-sizing:border-box;width:100%;min-width:0}
|
|
39
|
+
.flyfish-pptx-slide-error{display:flex;align-items:center;justify-content:center;background:#fff7ed!important;color:#9a3412}
|
|
40
|
+
.flyfish-pptx-slide-error-card{display:grid;gap:10px;max-width:70%;padding:24px;border:1px solid #fdba74;border-radius:12px;background:#fff;text-align:center;font:14px/1.5 system-ui,sans-serif}
|
|
41
|
+
.flyfish-pptx-slide-error-card strong{font-size:18px}
|
|
39
42
|
.flyfish-pptx-content .slide{background:#fff;box-shadow:0 18px 36px rgba(18,35,52,.12)}
|
|
40
43
|
.flyfish-pptx-thumbnail{display:block;box-sizing:border-box;width:min(960px,100%);height:auto;margin:0 auto 28px;border-radius:12px;background:#fff;box-shadow:0 18px 36px rgba(18,35,52,.14)}
|
|
41
44
|
${legacyPptxCss}
|
package/dist/types.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export interface PptxSlideSize {
|
|
|
34
34
|
height?: number;
|
|
35
35
|
[key: string]: unknown;
|
|
36
36
|
}
|
|
37
|
-
export type PptxDiagnosticErrorCode = 'PPTX_FILE_EMPTY' | 'PPTX_FILE_TOO_LARGE' | 'PPTX_INVALID_ZIP' | 'PPTX_MISSING_CONTENT_TYPES' | 'PPTX_MISSING_PRESENTATION' | 'PPTX_NO_SLIDES' | 'PPTX_MISSING_SLIDE' | 'PPTX_SLIDE_RENDER_FAILED' | 'PPTX_WORKER_FAILED' | 'PPTX_PARSE_FAILED' | (string & {});
|
|
37
|
+
export type PptxDiagnosticErrorCode = 'PPTX_FILE_EMPTY' | 'PPTX_FILE_TOO_LARGE' | 'PPTX_INVALID_ZIP' | 'PPTX_MISSING_CONTENT_TYPES' | 'PPTX_MISSING_PRESENTATION' | 'PPTX_NO_SLIDES' | 'PPTX_MISSING_SLIDE' | 'PPTX_SLIDE_RENDER_FAILED' | 'PPTX_NO_RENDERABLE_SLIDES' | 'PPTX_WORKER_FAILED' | 'PPTX_PARSE_FAILED' | (string & {});
|
|
38
38
|
export interface PptxDiagnosticError {
|
|
39
39
|
name: 'PptxDiagnosticError';
|
|
40
40
|
code: PptxDiagnosticErrorCode;
|
package/dist/viewer.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export declare class PptxViewer {
|
|
|
39
39
|
private getEstimatedSlideHeight;
|
|
40
40
|
private appendWindowedSlide;
|
|
41
41
|
private createWindowedSlideRecord;
|
|
42
|
+
private getDesignerCanvases;
|
|
42
43
|
private renderSlideRecord;
|
|
43
44
|
private unmountSlideRecord;
|
|
44
45
|
private updateMeasuredSlideHeight;
|
|
@@ -54,6 +55,8 @@ export declare class PptxViewer {
|
|
|
54
55
|
private findSlideWindowTarget;
|
|
55
56
|
private postProcessRenderedContent;
|
|
56
57
|
private postProcessSlideRecord;
|
|
58
|
+
/** Materializes every lazy slide only for the duration of an export snapshot. */
|
|
59
|
+
cloneForExport(): Promise<HTMLElement>;
|
|
57
60
|
private complete;
|
|
58
61
|
private fail;
|
|
59
62
|
private attachResizeObserver;
|
package/dist/viewer.js
CHANGED
|
@@ -51,6 +51,19 @@ const appendHtml = (container, html) => {
|
|
|
51
51
|
container.append(template.content);
|
|
52
52
|
return nodes[0] || null;
|
|
53
53
|
};
|
|
54
|
+
const escapeHtml = (value) => String(value !== null && value !== void 0 ? value : '')
|
|
55
|
+
.replace(/&/g, '&')
|
|
56
|
+
.replace(/</g, '<')
|
|
57
|
+
.replace(/>/g, '>')
|
|
58
|
+
.replace(/"/g, '"')
|
|
59
|
+
.replace(/'/g, ''');
|
|
60
|
+
const buildSlideErrorHtml = (slideNumber, error) => {
|
|
61
|
+
const diagnostic = error && typeof error === 'object'
|
|
62
|
+
? error
|
|
63
|
+
: null;
|
|
64
|
+
const message = (diagnostic === null || diagnostic === void 0 ? void 0 : diagnostic.message) || stringifyErrorDetail(error) || 'This slide could not be rendered.';
|
|
65
|
+
return `<section class="slide flyfish-pptx-slide-error" data-slide-index="${slideNumber}"><div class="flyfish-pptx-slide-error-card" role="status"><strong>Slide ${slideNumber}</strong><span>${escapeHtml(message)}</span></div></section>`;
|
|
66
|
+
};
|
|
54
67
|
const DEFAULT_INITIAL_SLIDES = 3;
|
|
55
68
|
const DEFAULT_BATCH_SIZE = 4;
|
|
56
69
|
const DEFAULT_OVERSCAN_VIEWPORTS = 1.5;
|
|
@@ -170,7 +183,7 @@ export class PptxViewer {
|
|
|
170
183
|
}
|
|
171
184
|
}
|
|
172
185
|
processMessage(message) {
|
|
173
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
186
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
174
187
|
if (this.disposed || this.completed) {
|
|
175
188
|
return;
|
|
176
189
|
}
|
|
@@ -187,27 +200,44 @@ export class PptxViewer {
|
|
|
187
200
|
}
|
|
188
201
|
break;
|
|
189
202
|
}
|
|
203
|
+
case 'slide-error': {
|
|
204
|
+
const slideNumber = Number(message.slide_num || 0);
|
|
205
|
+
const error = message.data;
|
|
206
|
+
const html = buildSlideErrorHtml(slideNumber, error);
|
|
207
|
+
this.clearThumbnail();
|
|
208
|
+
if (this.shouldWindowSlides()) {
|
|
209
|
+
this.appendWindowedSlide(html, slideNumber);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
const element = appendHtml(this.content, html);
|
|
213
|
+
this.scheduleResize();
|
|
214
|
+
(_d = (_c = this.options).onSlideRendered) === null || _d === void 0 ? void 0 : _d.call(_c, slideNumber, element);
|
|
215
|
+
}
|
|
216
|
+
(_f = (_e = this.options).onSlideError) === null || _f === void 0 ? void 0 : _f.call(_e, slideNumber, error);
|
|
217
|
+
(_h = (_g = this.options).onWarning) === null || _h === void 0 ? void 0 : _h.call(_g, error);
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
190
220
|
case 'pptx-thumb':
|
|
191
221
|
this.showThumbnail(String(message.data || ''));
|
|
192
|
-
(
|
|
222
|
+
(_k = (_j = this.options).onThumbnail) === null || _k === void 0 ? void 0 : _k.call(_j, String(message.data || ''));
|
|
193
223
|
break;
|
|
194
224
|
case 'slideSize':
|
|
195
225
|
this.slideSize = (message.data || {});
|
|
196
226
|
this.syncWindowedPlaceholderHeights();
|
|
197
|
-
(
|
|
227
|
+
(_m = (_l = this.options).onSlideSize) === null || _m === void 0 ? void 0 : _m.call(_l, (message.data || {}));
|
|
198
228
|
break;
|
|
199
229
|
case 'globalCSS':
|
|
200
230
|
this.appendGlobalCss(String(message.data || ''));
|
|
201
231
|
break;
|
|
202
232
|
case 'progress-update':
|
|
203
|
-
(
|
|
233
|
+
(_p = (_o = this.options).onProgress) === null || _p === void 0 ? void 0 : _p.call(_o, Number(message.data || 0), message);
|
|
204
234
|
break;
|
|
205
235
|
case 'ExecutionTime':
|
|
206
236
|
case 'Done':
|
|
207
|
-
void this.complete(message.charts);
|
|
237
|
+
void this.complete(message.charts).catch(error => this.fail(createPptxDiagnosticError('PPTX_PARSE_FAILED', 'post-process', 'PPTX 渲染后处理失败。', error)));
|
|
208
238
|
break;
|
|
209
239
|
case 'WARN':
|
|
210
|
-
(
|
|
240
|
+
(_r = (_q = this.options).onWarning) === null || _r === void 0 ? void 0 : _r.call(_q, message.data);
|
|
211
241
|
break;
|
|
212
242
|
case 'ERROR':
|
|
213
243
|
this.fail(message.data);
|
|
@@ -289,15 +319,21 @@ export class PptxViewer {
|
|
|
289
319
|
rendered: false,
|
|
290
320
|
notified: false,
|
|
291
321
|
postProcessed: false,
|
|
322
|
+
postProcessPromise: null,
|
|
292
323
|
};
|
|
293
324
|
}
|
|
325
|
+
getDesignerCanvases(record) {
|
|
326
|
+
return Array.from(record.slot.children).filter(element => (element.classList.contains('fv-print-mask-canvas')));
|
|
327
|
+
}
|
|
294
328
|
renderSlideRecord(record) {
|
|
295
329
|
var _a, _b;
|
|
296
330
|
if (record.rendered || this.disposed) {
|
|
297
331
|
return;
|
|
298
332
|
}
|
|
333
|
+
const designerCanvases = this.getDesignerCanvases(record);
|
|
299
334
|
record.slot.replaceChildren();
|
|
300
335
|
record.element = appendHtml(record.slot, record.html);
|
|
336
|
+
record.slot.append(...designerCanvases);
|
|
301
337
|
record.rendered = true;
|
|
302
338
|
record.postProcessed = false;
|
|
303
339
|
this.updateMeasuredSlideHeight(record);
|
|
@@ -311,7 +347,7 @@ export class PptxViewer {
|
|
|
311
347
|
this.scheduleResize();
|
|
312
348
|
}
|
|
313
349
|
unmountSlideRecord(record) {
|
|
314
|
-
if (!record.rendered) {
|
|
350
|
+
if (!record.rendered || this.getDesignerCanvases(record).length > 0) {
|
|
315
351
|
return;
|
|
316
352
|
}
|
|
317
353
|
this.updateMeasuredSlideHeight(record);
|
|
@@ -319,6 +355,7 @@ export class PptxViewer {
|
|
|
319
355
|
record.element = null;
|
|
320
356
|
record.rendered = false;
|
|
321
357
|
record.postProcessed = false;
|
|
358
|
+
record.postProcessPromise = null;
|
|
322
359
|
}
|
|
323
360
|
updateMeasuredSlideHeight(record) {
|
|
324
361
|
var _a;
|
|
@@ -504,9 +541,40 @@ export class PptxViewer {
|
|
|
504
541
|
if (!record.rendered || record.postProcessed || this.disposed) {
|
|
505
542
|
return;
|
|
506
543
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
544
|
+
if (!record.postProcessPromise) {
|
|
545
|
+
record.postProcessPromise = (async () => {
|
|
546
|
+
await renderPptxPostProcessing(this.charts, record.slot);
|
|
547
|
+
if (this.disposed) {
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
record.postProcessed = true;
|
|
551
|
+
this.updateMeasuredSlideHeight(record);
|
|
552
|
+
})().finally(() => {
|
|
553
|
+
record.postProcessPromise = null;
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
await record.postProcessPromise;
|
|
557
|
+
}
|
|
558
|
+
/** Materializes every lazy slide only for the duration of an export snapshot. */
|
|
559
|
+
async cloneForExport() {
|
|
560
|
+
if (!this.shouldWindowSlides()) {
|
|
561
|
+
return this.target.cloneNode(true);
|
|
562
|
+
}
|
|
563
|
+
const previouslyRendered = new Set(this.slideRecords.filter(record => record.rendered));
|
|
564
|
+
try {
|
|
565
|
+
this.slideRecords.forEach(record => this.renderSlideRecord(record));
|
|
566
|
+
await Promise.all(this.slideRecords.map(record => this.postProcessSlideRecord(record)));
|
|
567
|
+
return this.target.cloneNode(true);
|
|
568
|
+
}
|
|
569
|
+
finally {
|
|
570
|
+
this.slideRecords.forEach(record => {
|
|
571
|
+
if (!previouslyRendered.has(record)) {
|
|
572
|
+
this.unmountSlideRecord(record);
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
this.scheduleSlideWindowUpdate();
|
|
576
|
+
this.scheduleResize();
|
|
577
|
+
}
|
|
510
578
|
}
|
|
511
579
|
async complete(charts) {
|
|
512
580
|
var _a, _b, _c;
|
|
@@ -521,6 +589,9 @@ export class PptxViewer {
|
|
|
521
589
|
this.scheduleSlideWindowUpdate();
|
|
522
590
|
this.scheduleResize();
|
|
523
591
|
await this.postProcessRenderedContent(charts);
|
|
592
|
+
if (this.disposed) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
524
595
|
this.scheduleResize();
|
|
525
596
|
(_c = (_b = this.options).onRenderComplete) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
526
597
|
}
|