@file-viewer/renderer-ppt 3.0.0
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/LICENSE +160 -0
- package/README.en.md +7 -0
- package/README.md +7 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +598 -0
- package/file-viewer.capability.json +23 -0
- package/package.json +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
|
13
|
+
owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities
|
|
16
|
+
that control, are controlled by, or are under common control with that entity.
|
|
17
|
+
For the purposes of this definition, "control" means (i) the power, direct or
|
|
18
|
+
indirect, to cause the direction or management of such entity, whether by
|
|
19
|
+
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
20
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
21
|
+
|
|
22
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
23
|
+
permissions granted by this License.
|
|
24
|
+
|
|
25
|
+
"Source" form shall mean the preferred form for making modifications, including
|
|
26
|
+
but not limited to software source code, documentation source, and configuration
|
|
27
|
+
files.
|
|
28
|
+
|
|
29
|
+
"Object" form shall mean any form resulting from mechanical transformation or
|
|
30
|
+
translation of a Source form, including but not limited to compiled object code,
|
|
31
|
+
generated documentation, and conversions to other media types.
|
|
32
|
+
|
|
33
|
+
"Work" shall mean the work of authorship, whether in Source or Object form,
|
|
34
|
+
made available under the License, as indicated by a copyright notice that is
|
|
35
|
+
included in or attached to the work.
|
|
36
|
+
|
|
37
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
|
38
|
+
is based on (or derived from) the Work and for which the editorial revisions,
|
|
39
|
+
annotations, elaborations, or other modifications represent, as a whole, an
|
|
40
|
+
original work of authorship. For the purposes of this License, Derivative Works
|
|
41
|
+
shall not include works that remain separable from, or merely link (or bind by
|
|
42
|
+
name) to the interfaces of, the Work and Derivative Works thereof.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the original version
|
|
45
|
+
of the Work and any modifications or additions to that Work or Derivative Works
|
|
46
|
+
thereof, that is intentionally submitted to Licensor for inclusion in the Work by
|
|
47
|
+
the copyright owner or by an individual or Legal Entity authorized to submit on
|
|
48
|
+
behalf of the copyright owner. For the purposes of this definition, "submitted"
|
|
49
|
+
means any form of electronic, verbal, or written communication sent to the
|
|
50
|
+
Licensor or its representatives, including but not limited to communication on
|
|
51
|
+
electronic mailing lists, source code control systems, and issue tracking systems
|
|
52
|
+
that are managed by, or on behalf of, the Licensor for the purpose of discussing
|
|
53
|
+
and improving the Work, but excluding communication that is conspicuously marked
|
|
54
|
+
or otherwise designated in writing by the copyright owner as "Not a
|
|
55
|
+
Contribution."
|
|
56
|
+
|
|
57
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
|
58
|
+
of whom a Contribution has been received by Licensor and subsequently
|
|
59
|
+
incorporated within the Work.
|
|
60
|
+
|
|
61
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this
|
|
62
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
63
|
+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
|
64
|
+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
|
65
|
+
sublicense, and distribute the Work and such Derivative Works in Source or
|
|
66
|
+
Object form.
|
|
67
|
+
|
|
68
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License,
|
|
69
|
+
each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
|
|
70
|
+
no-charge, royalty-free, irrevocable (except as stated in this section) patent
|
|
71
|
+
license to make, have made, use, offer to sell, sell, import, and otherwise
|
|
72
|
+
transfer the Work, where such license applies only to those patent claims
|
|
73
|
+
licensable by such Contributor that are necessarily infringed by their
|
|
74
|
+
Contribution(s) alone or by combination of their Contribution(s) with the Work to
|
|
75
|
+
which such Contribution(s) was submitted. If You institute patent litigation
|
|
76
|
+
against any entity (including a cross-claim or counterclaim in a lawsuit)
|
|
77
|
+
alleging that the Work or a Contribution incorporated within the Work
|
|
78
|
+
constitutes direct or contributory patent infringement, then any patent licenses
|
|
79
|
+
granted to You under this License for that Work shall terminate as of the date
|
|
80
|
+
such litigation is filed.
|
|
81
|
+
|
|
82
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
83
|
+
Derivative Works thereof in any medium, with or without modifications, and in
|
|
84
|
+
Source or Object form, provided that You meet the following conditions:
|
|
85
|
+
|
|
86
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of
|
|
87
|
+
this License; and
|
|
88
|
+
|
|
89
|
+
(b) You must cause any modified files to carry prominent notices stating that
|
|
90
|
+
You changed the files; and
|
|
91
|
+
|
|
92
|
+
(c) You must retain, in the Source form of any Derivative Works that You
|
|
93
|
+
distribute, all copyright, patent, trademark, and attribution notices from the
|
|
94
|
+
Source form of the Work, excluding those notices that do not pertain to any part
|
|
95
|
+
of the Derivative Works; and
|
|
96
|
+
|
|
97
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then
|
|
98
|
+
any Derivative Works that You distribute must include a readable copy of the
|
|
99
|
+
attribution notices contained within such NOTICE file, excluding those notices
|
|
100
|
+
that do not pertain to any part of the Derivative Works, in at least one of the
|
|
101
|
+
following places: within a NOTICE text file distributed as part of the Derivative
|
|
102
|
+
Works; within the Source form or documentation, if provided along with the
|
|
103
|
+
Derivative Works; or, within a display generated by the Derivative Works, if and
|
|
104
|
+
wherever such third-party notices normally appear. The contents of the NOTICE
|
|
105
|
+
file are for informational purposes only and do not modify the License. You may
|
|
106
|
+
add Your own attribution notices within Derivative Works that You distribute,
|
|
107
|
+
alongside or as an addendum to the NOTICE text from the Work, provided that such
|
|
108
|
+
additional attribution notices cannot be construed as modifying the License.
|
|
109
|
+
|
|
110
|
+
You may add Your own copyright statement to Your modifications and may provide
|
|
111
|
+
additional or different license terms and conditions for use, reproduction, or
|
|
112
|
+
distribution of Your modifications, or for any such Derivative Works as a whole,
|
|
113
|
+
provided Your use, reproduction, and distribution of the Work otherwise complies
|
|
114
|
+
with the conditions stated in this License.
|
|
115
|
+
|
|
116
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
117
|
+
Contribution intentionally submitted for inclusion in the Work by You to the
|
|
118
|
+
Licensor shall be under the terms and conditions of this License, without any
|
|
119
|
+
additional terms or conditions. Notwithstanding the above, nothing herein shall
|
|
120
|
+
supersede or modify the terms of any separate license agreement you may have
|
|
121
|
+
executed with Licensor regarding such Contributions.
|
|
122
|
+
|
|
123
|
+
6. Trademarks. This License does not grant permission to use the trade names,
|
|
124
|
+
trademarks, service marks, or product names of the Licensor, except as required
|
|
125
|
+
for reasonable and customary use in describing the origin of the Work and
|
|
126
|
+
reproducing the content of the NOTICE file.
|
|
127
|
+
|
|
128
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
|
|
129
|
+
writing, Licensor provides the Work (and each Contributor provides its
|
|
130
|
+
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
131
|
+
KIND, either express or implied, including, without limitation, any warranties or
|
|
132
|
+
conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
133
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
134
|
+
appropriateness of using or redistributing the Work and assume any risks
|
|
135
|
+
associated with Your exercise of permissions under this License.
|
|
136
|
+
|
|
137
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in
|
|
138
|
+
tort (including negligence), contract, or otherwise, unless required by
|
|
139
|
+
applicable law (such as deliberate and grossly negligent acts) or agreed to in
|
|
140
|
+
writing, shall any Contributor be liable to You for damages, including any
|
|
141
|
+
direct, indirect, special, incidental, or consequential damages of any character
|
|
142
|
+
arising as a result of this License or out of the use or inability to use the
|
|
143
|
+
Work (including but not limited to damages for loss of goodwill, work stoppage,
|
|
144
|
+
computer failure or malfunction, or any and all other commercial damages or
|
|
145
|
+
losses), even if such Contributor has been advised of the possibility of such
|
|
146
|
+
damages.
|
|
147
|
+
|
|
148
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or
|
|
149
|
+
Derivative Works thereof, You may choose to offer, and charge a fee for,
|
|
150
|
+
acceptance of support, warranty, indemnity, or other liability obligations and/or
|
|
151
|
+
rights consistent with this License. However, in accepting such obligations, You
|
|
152
|
+
may act only on Your own behalf and on Your sole responsibility, not on behalf of
|
|
153
|
+
any other Contributor, and only if You agree to indemnify, defend, and hold each
|
|
154
|
+
Contributor harmless for any liability incurred by, or claims asserted against,
|
|
155
|
+
such Contributor by reason of your accepting any such warranty or additional
|
|
156
|
+
liability.
|
|
157
|
+
|
|
158
|
+
END OF TERMS AND CONDITIONS
|
|
159
|
+
|
|
160
|
+
Copyright 2026 Flyfish Viewer
|
package/README.en.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @file-viewer/renderer-ppt
|
|
2
|
+
|
|
3
|
+
Optional renderer for legacy binary `.ppt` and `.pot` files. This capability is excluded from the v3 `standard` profile and enters the dependency and static-asset closure only when installed explicitly.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { pptRenderer } from '@file-viewer/renderer-ppt'
|
|
7
|
+
```
|
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { FileRenderContext, FileRenderHandler, FileViewerRenderedInstance, FileViewerRendererPlugin, RendererDefinition } from '@file-viewer/core';
|
|
2
|
+
export default function renderPpt(buffer: ArrayBuffer, target: HTMLDivElement, _type?: string, context?: FileRenderContext): Promise<FileViewerRenderedInstance>;
|
|
3
|
+
export declare const binaryPresentationRendererDefinition: RendererDefinition;
|
|
4
|
+
export declare const renderFileViewerBinaryPresentation: FileRenderHandler<FileViewerRenderedInstance, HTMLDivElement>;
|
|
5
|
+
export declare const pptRenderer: FileViewerRendererPlugin<FileRenderHandler<FileViewerRenderedInstance, HTMLDivElement>>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
import { DEFAULT_RENDERER_DEFINITIONS, createFileViewerTranslator, createFileViewerZoomChangeEmitter, normalizeFileViewerErrorMessage, registerFileViewerZoomProvider, resolveFileViewerAssetUrl, resolveFileViewerFitScale, resolveFileViewerRuntimeAssetBaseUrl, unregisterFileViewerZoomProvider, waitForFileViewerNextPaint, } from '@file-viewer/core';
|
|
2
|
+
const MIN_ZOOM = 0.25;
|
|
3
|
+
const MAX_ZOOM = 3;
|
|
4
|
+
const ZOOM_STEP = 0.15;
|
|
5
|
+
const MAX_NATIVE_SCALE = 1.5;
|
|
6
|
+
const MIN_NATIVE_SCALE = 0.75;
|
|
7
|
+
const RERENDER_DELAY_MS = 160;
|
|
8
|
+
const pptStyle = `
|
|
9
|
+
.ppt-binary-shell{position:relative;box-sizing:border-box;min-height:100%;padding:24px 20px;background:var(--file-viewer-render-surface-background,#eef3f8);color:#1f2d3b;font-family:Aptos,'Segoe UI','PingFang SC','Microsoft YaHei',sans-serif}
|
|
10
|
+
.ppt-binary-loading{position:sticky;top:12px;z-index:3;box-sizing:border-box;display:flex;width:max-content;max-width:calc(100% - 24px);align-items:center;gap:10px;margin:0 auto 18px;padding:10px 14px;border:1px solid rgba(42,94,144,.14);border-radius:999px;background:rgba(255,255,255,.92);color:#41556b;box-shadow:0 12px 32px rgba(24,44,64,.12);backdrop-filter:blur(18px)}
|
|
11
|
+
.ppt-binary-loading[hidden],.ppt-binary-error[hidden]{display:none!important}
|
|
12
|
+
.ppt-binary-loading-dot{width:9px;height:9px;flex:0 0 auto;border-radius:999px;background:#1f9d67;box-shadow:0 0 0 6px rgba(31,157,103,.13)}
|
|
13
|
+
.ppt-binary-error{box-sizing:border-box;width:min(680px,calc(100% - 32px));margin:48px auto;padding:24px;border:1px solid rgba(28,43,58,.12);border-radius:16px;background:#fff;color:#1f2d3b;box-shadow:0 16px 42px rgba(25,42,54,.08)}
|
|
14
|
+
.ppt-binary-error strong{display:block;margin-bottom:10px;font-size:18px}.ppt-binary-error p{margin:0;color:#607282;line-height:1.7}.ppt-binary-error small{display:block;margin-top:12px;color:#7a8b99;line-height:1.6}
|
|
15
|
+
.ppt-binary-slides{display:grid;box-sizing:border-box;width:max-content;min-width:100%;justify-items:center;gap:22px;margin:0 auto}
|
|
16
|
+
.ppt-binary-page{position:relative;box-sizing:border-box;overflow:hidden;background:#fff;box-shadow:0 10px 34px rgba(15,23,42,.14);transform-origin:top center;transition:width .18s ease}
|
|
17
|
+
.ppt-binary-page canvas{display:block;max-width:none;height:auto;background:#fff}
|
|
18
|
+
.ppt-binary-page-error{position:absolute;inset:0;display:grid;place-items:center;padding:24px;background:#fff;color:#8b3a3a;text-align:center}
|
|
19
|
+
[data-viewer-theme='dark'] .ppt-binary-shell{background:var(--file-viewer-render-surface-background,#101820);color:#e5eef8}
|
|
20
|
+
[data-viewer-theme='dark'] .ppt-binary-loading{border-color:rgba(148,163,184,.18);background:rgba(15,23,42,.9);color:#cbd5e1;box-shadow:0 18px 44px rgba(0,0,0,.26)}
|
|
21
|
+
[data-viewer-theme='dark'] .ppt-binary-error{border-color:rgba(148,163,184,.18);background:#151f2b;color:#f8fafc;box-shadow:0 22px 56px rgba(0,0,0,.32)}
|
|
22
|
+
[data-viewer-theme='dark'] .ppt-binary-error p,[data-viewer-theme='dark'] .ppt-binary-error small{color:#94a3b8}
|
|
23
|
+
[data-viewer-theme='dark'] .ppt-binary-page{color-scheme:only light;forced-color-adjust:none;box-shadow:0 16px 44px rgba(0,0,0,.34)}
|
|
24
|
+
@media (prefers-color-scheme:dark){[data-viewer-theme='system'] .ppt-binary-shell{background:var(--file-viewer-render-surface-background,#101820);color:#e5eef8}[data-viewer-theme='system'] .ppt-binary-loading{border-color:rgba(148,163,184,.18);background:rgba(15,23,42,.9);color:#cbd5e1}[data-viewer-theme='system'] .ppt-binary-error{border-color:rgba(148,163,184,.18);background:#151f2b;color:#f8fafc}[data-viewer-theme='system'] .ppt-binary-error p,[data-viewer-theme='system'] .ppt-binary-error small{color:#94a3b8}}
|
|
25
|
+
@media (max-width:640px){.ppt-binary-shell{padding:14px 10px}.ppt-binary-slides{gap:14px}.ppt-binary-loading{top:8px;margin-bottom:12px;padding:8px 12px;font-size:13px}}
|
|
26
|
+
@media (prefers-reduced-motion:reduce){.ppt-binary-page{transition:none}}
|
|
27
|
+
`;
|
|
28
|
+
const pptPrintStyle = `
|
|
29
|
+
.ppt-binary-shell { background: #fff !important; padding: 0 !important; }
|
|
30
|
+
.ppt-binary-loading, .ppt-binary-error { display: none !important; }
|
|
31
|
+
.ppt-binary-slides { display: block !important; width: 100% !important; min-width: 0 !important; }
|
|
32
|
+
.ppt-binary-page { width: 100% !important; margin: 0 auto !important; box-shadow: none !important; break-after: page; page-break-after: always; }
|
|
33
|
+
.ppt-binary-page:last-child { break-after: auto; page-break-after: auto; }
|
|
34
|
+
.ppt-binary-page canvas, .ppt-binary-page img { display: block; width: 100% !important; height: auto !important; }
|
|
35
|
+
`;
|
|
36
|
+
const clampZoom = (value) => Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, value));
|
|
37
|
+
const createElement = (documentRef, tagName, className, text) => {
|
|
38
|
+
const element = documentRef.createElement(tagName);
|
|
39
|
+
if (className)
|
|
40
|
+
element.className = className;
|
|
41
|
+
if (text !== undefined)
|
|
42
|
+
element.textContent = text;
|
|
43
|
+
return element;
|
|
44
|
+
};
|
|
45
|
+
const loadPptModule = async (moduleUrl) => {
|
|
46
|
+
const module = moduleUrl
|
|
47
|
+
// Both hints are intentional. Vite/Rolldown and legacy webpack 4 must
|
|
48
|
+
// leave the configured browser URL as a native dynamic import instead of
|
|
49
|
+
// turning it into a build-time context module.
|
|
50
|
+
? await import(/* webpackIgnore: true */ /* @vite-ignore */ moduleUrl)
|
|
51
|
+
: await import('@file-viewer/ppt');
|
|
52
|
+
if (!module || typeof module.createPptViewer !== 'function') {
|
|
53
|
+
throw new Error('The configured PPT module does not export createPptViewer().');
|
|
54
|
+
}
|
|
55
|
+
return module;
|
|
56
|
+
};
|
|
57
|
+
const loadPptRuntime = async (moduleUrl, options) => {
|
|
58
|
+
const module = await loadPptModule(moduleUrl);
|
|
59
|
+
// @file-viewer/ppt 0.3 owns one active document per Worker runtime. A fresh
|
|
60
|
+
// runtime per File Viewer instance prevents concurrent viewers from sharing
|
|
61
|
+
// (and closing) each other's Worker/document lifecycle.
|
|
62
|
+
return module.createPptViewer(options);
|
|
63
|
+
};
|
|
64
|
+
const canvasToBlob = (canvas) => new Promise(resolve => {
|
|
65
|
+
if (typeof canvas.toBlob === 'function') {
|
|
66
|
+
try {
|
|
67
|
+
canvas.toBlob(resolve, 'image/png');
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// A Worker-owned HTMLCanvasElement cannot be encoded on the main thread.
|
|
72
|
+
// The renderer's direct snapshot path handles that case below.
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const dataUrl = canvas.toDataURL('image/png');
|
|
77
|
+
fetch(dataUrl).then(response => response.blob()).then(resolve, () => resolve(null));
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
resolve(null);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
const buildExportAdapter = (pages, targetWindow, captureSlideDataUrls) => ({
|
|
84
|
+
print: true,
|
|
85
|
+
exportHtml: true,
|
|
86
|
+
includeDocumentStyles: false,
|
|
87
|
+
beforeSnapshot: () => waitForFileViewerNextPaint(targetWindow || undefined),
|
|
88
|
+
getPrintMaskPages: () => pages,
|
|
89
|
+
printStyle: pptPrintStyle,
|
|
90
|
+
toHtml: async () => {
|
|
91
|
+
const dataUrls = await captureSlideDataUrls();
|
|
92
|
+
const slides = dataUrls.map((dataUrl, index) => {
|
|
93
|
+
return `<section class="ppt-binary-page" data-viewer-print-page-index="${index}"><img src="${dataUrl}" alt="Slide ${index + 1}"></section>`;
|
|
94
|
+
}).join('');
|
|
95
|
+
return `<div class="ppt-binary-shell"><div class="ppt-binary-slides">${slides}</div></div>`;
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
export default async function renderPpt(buffer, target, _type, context) {
|
|
99
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
100
|
+
const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
|
|
101
|
+
const documentRef = target.ownerDocument || document;
|
|
102
|
+
const targetWindow = documentRef.defaultView || (typeof window !== 'undefined' ? window : null);
|
|
103
|
+
const zoomEmitter = createFileViewerZoomChangeEmitter();
|
|
104
|
+
const style = createElement(documentRef, 'style');
|
|
105
|
+
style.textContent = pptStyle;
|
|
106
|
+
const shell = createElement(documentRef, 'div', 'ppt-binary-shell');
|
|
107
|
+
shell.dataset.viewerZoomProvider = 'ppt';
|
|
108
|
+
const loading = createElement(documentRef, 'div', 'ppt-binary-loading');
|
|
109
|
+
loading.setAttribute('role', 'status');
|
|
110
|
+
loading.setAttribute('aria-live', 'polite');
|
|
111
|
+
const loadingLabel = createElement(documentRef, 'span', undefined, t('presentation.ppt.state.loading'));
|
|
112
|
+
loading.append(createElement(documentRef, 'span', 'ppt-binary-loading-dot'), loadingLabel);
|
|
113
|
+
const error = createElement(documentRef, 'div', 'ppt-binary-error');
|
|
114
|
+
error.hidden = true;
|
|
115
|
+
const errorTitle = createElement(documentRef, 'strong', undefined, t('presentation.ppt.error.title'));
|
|
116
|
+
const errorMessage = createElement(documentRef, 'p');
|
|
117
|
+
const errorHint = createElement(documentRef, 'small', undefined, t('presentation.ppt.error.assetHint'));
|
|
118
|
+
error.append(errorTitle, errorMessage, errorHint);
|
|
119
|
+
const slides = createElement(documentRef, 'div', 'ppt-binary-slides');
|
|
120
|
+
shell.append(loading, error, slides);
|
|
121
|
+
target.replaceChildren(style, shell);
|
|
122
|
+
let pptRuntime = null;
|
|
123
|
+
let pptDocument = null;
|
|
124
|
+
let mountedViewer = null;
|
|
125
|
+
let resourceClosePromise = null;
|
|
126
|
+
let pages = [];
|
|
127
|
+
const canvases = [];
|
|
128
|
+
let canvasStateObserver = null;
|
|
129
|
+
let snapshotRuntimeOptions = null;
|
|
130
|
+
let snapshotModuleUrl;
|
|
131
|
+
let currentScale = 1;
|
|
132
|
+
let disposed = false;
|
|
133
|
+
let ready = false;
|
|
134
|
+
let renderGeneration = 0;
|
|
135
|
+
let rerenderTimer = null;
|
|
136
|
+
let statsRefreshTimer = null;
|
|
137
|
+
let statsRefreshGeneration = 0;
|
|
138
|
+
const throwIfAborted = () => {
|
|
139
|
+
var _a, _b;
|
|
140
|
+
if (disposed || ((_a = context === null || context === void 0 ? void 0 : context.signal) === null || _a === void 0 ? void 0 : _a.aborted)) {
|
|
141
|
+
throw ((_b = context === null || context === void 0 ? void 0 : context.signal) === null || _b === void 0 ? void 0 : _b.reason) || new DOMException('PPT rendering aborted.', 'AbortError');
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const clearRerenderTimer = () => {
|
|
145
|
+
if (rerenderTimer !== null) {
|
|
146
|
+
if (targetWindow)
|
|
147
|
+
targetWindow.clearTimeout(rerenderTimer);
|
|
148
|
+
else
|
|
149
|
+
clearTimeout(rerenderTimer);
|
|
150
|
+
rerenderTimer = null;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const clearStatsRefreshTimer = () => {
|
|
154
|
+
if (statsRefreshTimer !== null) {
|
|
155
|
+
if (targetWindow)
|
|
156
|
+
targetWindow.clearTimeout(statsRefreshTimer);
|
|
157
|
+
else
|
|
158
|
+
clearTimeout(statsRefreshTimer);
|
|
159
|
+
statsRefreshTimer = null;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const refreshRuntimeStats = async () => {
|
|
163
|
+
const mounted = mountedViewer;
|
|
164
|
+
if (!mounted || disposed)
|
|
165
|
+
return;
|
|
166
|
+
const generation = ++statsRefreshGeneration;
|
|
167
|
+
try {
|
|
168
|
+
const stats = await mounted.cacheStats();
|
|
169
|
+
if (generation !== statsRefreshGeneration || mounted !== mountedViewer || disposed)
|
|
170
|
+
return;
|
|
171
|
+
const publishNumber = (key, value) => {
|
|
172
|
+
if (Number.isFinite(value))
|
|
173
|
+
shell.dataset[key] = String(value);
|
|
174
|
+
};
|
|
175
|
+
shell.dataset.pptCacheEnabled = String(stats.enabled);
|
|
176
|
+
shell.dataset.pptCacheAvailable = String(stats.available);
|
|
177
|
+
publishNumber('pptCacheEntries', stats.entries);
|
|
178
|
+
publishNumber('pptCacheBytes', stats.bytes);
|
|
179
|
+
publishNumber('pptAttachedCanvases', stats.attachedCanvases);
|
|
180
|
+
publishNumber('pptActiveCanvases', stats.activeCanvases);
|
|
181
|
+
publishNumber('pptWasmMemoryBytes', stats.wasmMemoryBytes);
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
// Diagnostics must never interfere with rendering or cleanup.
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
const scheduleRuntimeStatsRefresh = () => {
|
|
188
|
+
clearStatsRefreshTimer();
|
|
189
|
+
const run = () => {
|
|
190
|
+
statsRefreshTimer = null;
|
|
191
|
+
void refreshRuntimeStats();
|
|
192
|
+
};
|
|
193
|
+
statsRefreshTimer = targetWindow
|
|
194
|
+
? targetWindow.setTimeout(run, 200)
|
|
195
|
+
: setTimeout(run, 200);
|
|
196
|
+
};
|
|
197
|
+
const closeResources = () => {
|
|
198
|
+
if (resourceClosePromise)
|
|
199
|
+
return resourceClosePromise;
|
|
200
|
+
const mountedToClose = mountedViewer;
|
|
201
|
+
const documentToClose = pptDocument;
|
|
202
|
+
const runtimeToClose = pptRuntime;
|
|
203
|
+
mountedViewer = null;
|
|
204
|
+
pptDocument = null;
|
|
205
|
+
pptRuntime = null;
|
|
206
|
+
canvasStateObserver === null || canvasStateObserver === void 0 ? void 0 : canvasStateObserver.disconnect();
|
|
207
|
+
canvasStateObserver = null;
|
|
208
|
+
clearStatsRefreshTimer();
|
|
209
|
+
if (!mountedToClose && !documentToClose && !runtimeToClose)
|
|
210
|
+
return Promise.resolve();
|
|
211
|
+
resourceClosePromise = (async () => {
|
|
212
|
+
try {
|
|
213
|
+
if (mountedToClose) {
|
|
214
|
+
await mountedToClose.close();
|
|
215
|
+
}
|
|
216
|
+
else if (documentToClose && !documentToClose.closed) {
|
|
217
|
+
await documentToClose.close();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
finally {
|
|
221
|
+
await (runtimeToClose === null || runtimeToClose === void 0 ? void 0 : runtimeToClose.close());
|
|
222
|
+
}
|
|
223
|
+
})();
|
|
224
|
+
return resourceClosePromise;
|
|
225
|
+
};
|
|
226
|
+
const disposeResources = () => {
|
|
227
|
+
void closeResources().catch(closeError => {
|
|
228
|
+
console.warn('PPT runtime cleanup warning:', closeError);
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
const abort = () => {
|
|
232
|
+
renderGeneration += 1;
|
|
233
|
+
clearRerenderTimer();
|
|
234
|
+
clearStatsRefreshTimer();
|
|
235
|
+
// The signal can fire while runtime.mount() is still awaiting its first
|
|
236
|
+
// Worker response. Let the surrounding try/catch attach the returned
|
|
237
|
+
// document before closing it; eagerly closing only the runtime here would
|
|
238
|
+
// otherwise leave that late document outside the owned lifecycle.
|
|
239
|
+
};
|
|
240
|
+
(_a = context === null || context === void 0 ? void 0 : context.signal) === null || _a === void 0 ? void 0 : _a.addEventListener('abort', abort, { once: true });
|
|
241
|
+
const getZoomState = () => ({
|
|
242
|
+
scale: currentScale,
|
|
243
|
+
label: `${Math.round(currentScale * 100)}%`,
|
|
244
|
+
canZoomIn: currentScale < MAX_ZOOM,
|
|
245
|
+
canZoomOut: currentScale > MIN_ZOOM,
|
|
246
|
+
canReset: Math.abs(currentScale - 1) > 0.001,
|
|
247
|
+
minScale: MIN_ZOOM,
|
|
248
|
+
maxScale: MAX_ZOOM,
|
|
249
|
+
});
|
|
250
|
+
const applyCssZoom = () => {
|
|
251
|
+
if (!pptDocument)
|
|
252
|
+
return;
|
|
253
|
+
const width = Math.max(1, Math.round(pptDocument.width * currentScale));
|
|
254
|
+
const height = Math.max(1, Math.round(pptDocument.height * currentScale));
|
|
255
|
+
pages.forEach((page, index) => {
|
|
256
|
+
page.style.width = `${width}px`;
|
|
257
|
+
page.style.height = `${height}px`;
|
|
258
|
+
page.style.maxWidth = 'none';
|
|
259
|
+
const canvas = canvases[index];
|
|
260
|
+
if (canvas) {
|
|
261
|
+
canvas.style.width = `${width}px`;
|
|
262
|
+
canvas.style.height = `${height}px`;
|
|
263
|
+
canvas.style.maxWidth = 'none';
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
const renderActiveSlides = async (generation) => {
|
|
268
|
+
var _a, _b, _c, _d;
|
|
269
|
+
const document = pptDocument;
|
|
270
|
+
const mounted = mountedViewer;
|
|
271
|
+
if (!document || !mounted)
|
|
272
|
+
return;
|
|
273
|
+
const pixelRatio = Math.min(2, Math.max(1, (targetWindow === null || targetWindow === void 0 ? void 0 : targetWindow.devicePixelRatio) || 1));
|
|
274
|
+
const nativeScale = Math.min(MAX_NATIVE_SCALE, Math.max(MIN_NATIVE_SCALE, currentScale * pixelRatio));
|
|
275
|
+
const activeIndices = canvases
|
|
276
|
+
.map((canvas, index) => ({ index, state: canvas.dataset.renderState }))
|
|
277
|
+
.filter(item => item.state === 'rendering' || item.state === 'rendered')
|
|
278
|
+
.map(item => item.index);
|
|
279
|
+
for (const index of activeIndices) {
|
|
280
|
+
throwIfAborted();
|
|
281
|
+
if (generation !== renderGeneration)
|
|
282
|
+
return;
|
|
283
|
+
const canvas = canvases[index];
|
|
284
|
+
const page = pages[index];
|
|
285
|
+
try {
|
|
286
|
+
if (canvas.dataset.renderState === 'rendering') {
|
|
287
|
+
await mounted.renderSlide(index);
|
|
288
|
+
if (disposed || ((_a = context === null || context === void 0 ? void 0 : context.signal) === null || _a === void 0 ? void 0 : _a.aborted) || generation !== renderGeneration)
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
if (canvas.dataset.renderState !== 'rendered')
|
|
292
|
+
continue;
|
|
293
|
+
const result = await document.renderSlide(index, canvas, {
|
|
294
|
+
scale: nativeScale,
|
|
295
|
+
pixelRatio: 1,
|
|
296
|
+
});
|
|
297
|
+
if (disposed || ((_b = context === null || context === void 0 ? void 0 : context.signal) === null || _b === void 0 ? void 0 : _b.aborted) || generation !== renderGeneration)
|
|
298
|
+
return;
|
|
299
|
+
if (result.cancelled)
|
|
300
|
+
continue;
|
|
301
|
+
if (!page.isConnected)
|
|
302
|
+
return;
|
|
303
|
+
(_c = page.querySelector('.ppt-binary-page-error')) === null || _c === void 0 ? void 0 : _c.remove();
|
|
304
|
+
}
|
|
305
|
+
catch (slideError) {
|
|
306
|
+
if (disposed || ((_d = context === null || context === void 0 ? void 0 : context.signal) === null || _d === void 0 ? void 0 : _d.aborted) || generation !== renderGeneration || !page.isConnected) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const message = createElement(documentRef, 'div', 'ppt-binary-page-error', `${t('presentation.ppt.error.parseFailed')} (${index + 1})`);
|
|
310
|
+
page.append(message);
|
|
311
|
+
console.warn(`PPT slide ${index + 1} render warning:`, slideError);
|
|
312
|
+
}
|
|
313
|
+
applyCssZoom();
|
|
314
|
+
if (index + 1 < canvases.length) {
|
|
315
|
+
await waitForFileViewerNextPaint(targetWindow || undefined);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
const scheduleQualityRender = () => {
|
|
320
|
+
clearRerenderTimer();
|
|
321
|
+
const generation = renderGeneration;
|
|
322
|
+
const run = () => {
|
|
323
|
+
rerenderTimer = null;
|
|
324
|
+
void renderActiveSlides(generation).catch(renderError => {
|
|
325
|
+
var _a;
|
|
326
|
+
if (!disposed && !((_a = context === null || context === void 0 ? void 0 : context.signal) === null || _a === void 0 ? void 0 : _a.aborted)) {
|
|
327
|
+
console.warn('PPT quality rerender warning:', renderError);
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
};
|
|
331
|
+
rerenderTimer = targetWindow
|
|
332
|
+
? targetWindow.setTimeout(run, RERENDER_DELAY_MS)
|
|
333
|
+
: setTimeout(run, RERENDER_DELAY_MS);
|
|
334
|
+
};
|
|
335
|
+
const setZoom = (scale) => {
|
|
336
|
+
currentScale = clampZoom(scale);
|
|
337
|
+
renderGeneration += 1;
|
|
338
|
+
applyCssZoom();
|
|
339
|
+
zoomEmitter.emit();
|
|
340
|
+
scheduleQualityRender();
|
|
341
|
+
return getZoomState();
|
|
342
|
+
};
|
|
343
|
+
const fit = (request) => {
|
|
344
|
+
var _a, _b;
|
|
345
|
+
if (!pptDocument) {
|
|
346
|
+
return {
|
|
347
|
+
applied: false,
|
|
348
|
+
mode: request.mode,
|
|
349
|
+
resize: request.resize,
|
|
350
|
+
source: request.source,
|
|
351
|
+
reason: 'ppt-not-ready',
|
|
352
|
+
provider: 'zoom',
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
const scale = resolveFileViewerFitScale({
|
|
356
|
+
mode: request.mode,
|
|
357
|
+
viewportWidth: Math.max(1, (request.viewportWidth || shell.clientWidth || 0) - request.padding * 2),
|
|
358
|
+
viewportHeight: Math.max(1, (request.viewportHeight || shell.clientHeight || 0) - request.padding * 2),
|
|
359
|
+
contentWidth: pptDocument.width,
|
|
360
|
+
contentHeight: pptDocument.height,
|
|
361
|
+
currentScale,
|
|
362
|
+
minScale: (_a = request.minScale) !== null && _a !== void 0 ? _a : MIN_ZOOM,
|
|
363
|
+
maxScale: (_b = request.maxScale) !== null && _b !== void 0 ? _b : MAX_ZOOM,
|
|
364
|
+
});
|
|
365
|
+
if (!scale) {
|
|
366
|
+
return {
|
|
367
|
+
applied: false,
|
|
368
|
+
mode: request.mode,
|
|
369
|
+
resize: request.resize,
|
|
370
|
+
source: request.source,
|
|
371
|
+
reason: 'unmeasurable',
|
|
372
|
+
provider: 'zoom',
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
const state = setZoom(scale);
|
|
376
|
+
return {
|
|
377
|
+
applied: true,
|
|
378
|
+
mode: request.mode,
|
|
379
|
+
resize: request.resize,
|
|
380
|
+
scale: state.scale,
|
|
381
|
+
source: request.source,
|
|
382
|
+
provider: 'zoom',
|
|
383
|
+
};
|
|
384
|
+
};
|
|
385
|
+
const captureDirectSlides = async (slideIndices, encode) => {
|
|
386
|
+
const runtimeOptions = snapshotRuntimeOptions;
|
|
387
|
+
if (!runtimeOptions)
|
|
388
|
+
throw new Error(t('presentation.ppt.error.parseFailed'));
|
|
389
|
+
const runtime = await loadPptRuntime(snapshotModuleUrl, {
|
|
390
|
+
...runtimeOptions,
|
|
391
|
+
worker: false,
|
|
392
|
+
cache: false,
|
|
393
|
+
});
|
|
394
|
+
let document = null;
|
|
395
|
+
try {
|
|
396
|
+
document = await runtime.open(buffer.slice(0));
|
|
397
|
+
const output = [];
|
|
398
|
+
for (let position = 0; position < slideIndices.length; position += 1) {
|
|
399
|
+
const slideIndex = slideIndices[position];
|
|
400
|
+
throwIfAborted();
|
|
401
|
+
const canvas = createElement(documentRef, 'canvas');
|
|
402
|
+
try {
|
|
403
|
+
await document.renderSlide(slideIndex, canvas, {
|
|
404
|
+
scale: MAX_NATIVE_SCALE,
|
|
405
|
+
pixelRatio: 1,
|
|
406
|
+
});
|
|
407
|
+
throwIfAborted();
|
|
408
|
+
output.push(await encode(canvas));
|
|
409
|
+
}
|
|
410
|
+
finally {
|
|
411
|
+
canvas.width = 1;
|
|
412
|
+
canvas.height = 1;
|
|
413
|
+
}
|
|
414
|
+
// Direct-mode snapshots run on the main thread. Yield in bounded
|
|
415
|
+
// batches so a long deck does not monopolize input and painting.
|
|
416
|
+
if (position + 1 < slideIndices.length && (position + 1) % 4 === 0) {
|
|
417
|
+
await waitForFileViewerNextPaint(targetWindow || undefined);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return output;
|
|
421
|
+
}
|
|
422
|
+
finally {
|
|
423
|
+
if (document && !document.closed)
|
|
424
|
+
await document.close().catch(() => { });
|
|
425
|
+
await runtime.close().catch(() => { });
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
try {
|
|
429
|
+
throwIfAborted();
|
|
430
|
+
const presentationOptions = (_b = context === null || context === void 0 ? void 0 : context.options) === null || _b === void 0 ? void 0 : _b.presentation;
|
|
431
|
+
const runtimeBaseUrl = resolveFileViewerRuntimeAssetBaseUrl(documentRef);
|
|
432
|
+
const moduleUrl = (presentationOptions === null || presentationOptions === void 0 ? void 0 : presentationOptions.pptModuleUrl)
|
|
433
|
+
? resolveFileViewerAssetUrl(presentationOptions.pptModuleUrl, String(presentationOptions.pptModuleUrl), { documentBaseUrl: runtimeBaseUrl })
|
|
434
|
+
: undefined;
|
|
435
|
+
const resolvePptAssetUrl = (value) => value
|
|
436
|
+
? resolveFileViewerAssetUrl(value, String(value), { documentBaseUrl: runtimeBaseUrl })
|
|
437
|
+
: undefined;
|
|
438
|
+
const runtimeOptions = {
|
|
439
|
+
worker: (_c = presentationOptions === null || presentationOptions === void 0 ? void 0 : presentationOptions.pptWorker) !== null && _c !== void 0 ? _c : 'auto',
|
|
440
|
+
cache: presentationOptions === null || presentationOptions === void 0 ? void 0 : presentationOptions.pptCache,
|
|
441
|
+
wasmUrl: resolvePptAssetUrl(presentationOptions === null || presentationOptions === void 0 ? void 0 : presentationOptions.pptWasmUrl),
|
|
442
|
+
fontUrl: resolvePptAssetUrl(presentationOptions === null || presentationOptions === void 0 ? void 0 : presentationOptions.pptFontUrl),
|
|
443
|
+
workerUrl: resolvePptAssetUrl(presentationOptions === null || presentationOptions === void 0 ? void 0 : presentationOptions.pptWorkerUrl),
|
|
444
|
+
};
|
|
445
|
+
snapshotModuleUrl = moduleUrl;
|
|
446
|
+
snapshotRuntimeOptions = runtimeOptions;
|
|
447
|
+
const runtime = await loadPptRuntime(moduleUrl, runtimeOptions);
|
|
448
|
+
pptRuntime = runtime;
|
|
449
|
+
shell.dataset.pptRuntimeMode = runtime.mode;
|
|
450
|
+
throwIfAborted();
|
|
451
|
+
slides.className = 'ppt-binary-mount';
|
|
452
|
+
const mounted = await runtime.mount(slides, buffer, {
|
|
453
|
+
replace: true,
|
|
454
|
+
className: 'ppt-binary-slides',
|
|
455
|
+
scale: 1,
|
|
456
|
+
pixelRatio: 1,
|
|
457
|
+
virtualize: (presentationOptions === null || presentationOptions === void 0 ? void 0 : presentationOptions.pptVirtualize) !== false,
|
|
458
|
+
rootMargin: presentationOptions === null || presentationOptions === void 0 ? void 0 : presentationOptions.pptVirtualRootMargin,
|
|
459
|
+
releaseDelayMs: presentationOptions === null || presentationOptions === void 0 ? void 0 : presentationOptions.pptReleaseDelayMs,
|
|
460
|
+
});
|
|
461
|
+
mountedViewer = mounted;
|
|
462
|
+
pptDocument = mounted.document;
|
|
463
|
+
shell.dataset.pptVirtualized = String(mounted.virtualized);
|
|
464
|
+
throwIfAborted();
|
|
465
|
+
// @file-viewer/ppt 0.3 supplies standalone defaults as inline styles.
|
|
466
|
+
// File Viewer owns the surrounding scroll/zoom geometry, so normalize the
|
|
467
|
+
// generated root before sizing pages. Otherwise the runtime's 20px padding
|
|
468
|
+
// and max-width constraints squash slides while leaving their CSS height at
|
|
469
|
+
// the requested zoom, especially on mobile and above 100%.
|
|
470
|
+
Object.assign(mounted.root.style, {
|
|
471
|
+
width: 'max-content',
|
|
472
|
+
minWidth: '100%',
|
|
473
|
+
maxWidth: 'none',
|
|
474
|
+
padding: '0px',
|
|
475
|
+
background: 'transparent',
|
|
476
|
+
justifyContent: '',
|
|
477
|
+
gap: '',
|
|
478
|
+
});
|
|
479
|
+
pages = Array.from(mounted.root.children).map((element, index) => {
|
|
480
|
+
const page = element;
|
|
481
|
+
page.classList.add('ppt-binary-page');
|
|
482
|
+
page.dataset.slideIndex = String(index);
|
|
483
|
+
page.dataset.viewerPrintPageIndex = String(index);
|
|
484
|
+
page.style.maxWidth = 'none';
|
|
485
|
+
return page;
|
|
486
|
+
});
|
|
487
|
+
canvases.push(...mounted.canvases);
|
|
488
|
+
canvases.forEach((canvas, index) => {
|
|
489
|
+
canvas.setAttribute('role', 'img');
|
|
490
|
+
canvas.setAttribute('aria-label', `Slide ${index + 1}`);
|
|
491
|
+
canvas.style.maxWidth = 'none';
|
|
492
|
+
});
|
|
493
|
+
const shellStyle = (_d = targetWindow === null || targetWindow === void 0 ? void 0 : targetWindow.getComputedStyle) === null || _d === void 0 ? void 0 : _d.call(targetWindow, shell);
|
|
494
|
+
const horizontalPadding = (Number.parseFloat((shellStyle === null || shellStyle === void 0 ? void 0 : shellStyle.paddingLeft) || '') || 0) +
|
|
495
|
+
(Number.parseFloat((shellStyle === null || shellStyle === void 0 ? void 0 : shellStyle.paddingRight) || '') || 0);
|
|
496
|
+
const availableWidth = Math.max(0, (shell.clientWidth || target.clientWidth || 0) - horizontalPadding);
|
|
497
|
+
currentScale = availableWidth > 0
|
|
498
|
+
? clampZoom(Math.min(1, availableWidth / pptDocument.width))
|
|
499
|
+
: 1;
|
|
500
|
+
applyCssZoom();
|
|
501
|
+
registerFileViewerZoomProvider(shell, {
|
|
502
|
+
zoomIn: () => setZoom(currentScale + ZOOM_STEP),
|
|
503
|
+
zoomOut: () => setZoom(currentScale - ZOOM_STEP),
|
|
504
|
+
resetZoom: () => setZoom(1),
|
|
505
|
+
setZoom,
|
|
506
|
+
fit,
|
|
507
|
+
getState: getZoomState,
|
|
508
|
+
subscribe: zoomEmitter.subscribe,
|
|
509
|
+
});
|
|
510
|
+
const MutationObserverCtor = targetWindow === null || targetWindow === void 0 ? void 0 : targetWindow.MutationObserver;
|
|
511
|
+
if (MutationObserverCtor) {
|
|
512
|
+
canvasStateObserver = new MutationObserverCtor(records => {
|
|
513
|
+
if (records.some(record => {
|
|
514
|
+
var _a;
|
|
515
|
+
return (((_a = record.target.dataset) === null || _a === void 0 ? void 0 : _a.renderState) === 'rendered');
|
|
516
|
+
})) {
|
|
517
|
+
scheduleQualityRender();
|
|
518
|
+
}
|
|
519
|
+
scheduleRuntimeStatsRefresh();
|
|
520
|
+
});
|
|
521
|
+
canvases.forEach(canvas => {
|
|
522
|
+
canvasStateObserver === null || canvasStateObserver === void 0 ? void 0 : canvasStateObserver.observe(canvas, {
|
|
523
|
+
attributes: true,
|
|
524
|
+
attributeFilter: ['data-render-state'],
|
|
525
|
+
});
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
ready = true;
|
|
529
|
+
loading.hidden = true;
|
|
530
|
+
void refreshRuntimeStats();
|
|
531
|
+
(_e = context === null || context === void 0 ? void 0 : context.onProgressiveRender) === null || _e === void 0 ? void 0 : _e.call(context);
|
|
532
|
+
(_f = context === null || context === void 0 ? void 0 : context.registerExportAdapter) === null || _f === void 0 ? void 0 : _f.call(context, buildExportAdapter(pages, targetWindow, () => captureDirectSlides(canvases.map((_, index) => index), canvas => canvas.toDataURL('image/png'))));
|
|
533
|
+
(_g = context === null || context === void 0 ? void 0 : context.registerThumbnailAdapter) === null || _g === void 0 ? void 0 : _g.call(context, {
|
|
534
|
+
captureSource: 'rendered',
|
|
535
|
+
beforeCapture: () => {
|
|
536
|
+
if (!ready)
|
|
537
|
+
throw new Error(t('presentation.ppt.error.parseFailed'));
|
|
538
|
+
},
|
|
539
|
+
capture: async () => (await captureDirectSlides([0], canvasToBlob))[0] || null,
|
|
540
|
+
getTarget: () => pages[0] || null,
|
|
541
|
+
});
|
|
542
|
+
zoomEmitter.emit();
|
|
543
|
+
}
|
|
544
|
+
catch (renderError) {
|
|
545
|
+
if (disposed || ((_h = context === null || context === void 0 ? void 0 : context.signal) === null || _h === void 0 ? void 0 : _h.aborted)) {
|
|
546
|
+
clearRerenderTimer();
|
|
547
|
+
(_j = context === null || context === void 0 ? void 0 : context.registerExportAdapter) === null || _j === void 0 ? void 0 : _j.call(context, null);
|
|
548
|
+
(_k = context === null || context === void 0 ? void 0 : context.registerThumbnailAdapter) === null || _k === void 0 ? void 0 : _k.call(context, null);
|
|
549
|
+
unregisterFileViewerZoomProvider(shell);
|
|
550
|
+
await closeResources().catch(() => { });
|
|
551
|
+
throw renderError;
|
|
552
|
+
}
|
|
553
|
+
loading.hidden = true;
|
|
554
|
+
error.hidden = false;
|
|
555
|
+
errorMessage.textContent = normalizeFileViewerErrorMessage(renderError, context === null || context === void 0 ? void 0 : context.options) ||
|
|
556
|
+
t('presentation.ppt.error.parseFailed');
|
|
557
|
+
(_l = context === null || context === void 0 ? void 0 : context.registerExportAdapter) === null || _l === void 0 ? void 0 : _l.call(context, null);
|
|
558
|
+
(_m = context === null || context === void 0 ? void 0 : context.registerThumbnailAdapter) === null || _m === void 0 ? void 0 : _m.call(context, null);
|
|
559
|
+
unregisterFileViewerZoomProvider(shell);
|
|
560
|
+
await closeResources().catch(() => { });
|
|
561
|
+
throw renderError;
|
|
562
|
+
}
|
|
563
|
+
finally {
|
|
564
|
+
(_o = context === null || context === void 0 ? void 0 : context.signal) === null || _o === void 0 ? void 0 : _o.removeEventListener('abort', abort);
|
|
565
|
+
}
|
|
566
|
+
return {
|
|
567
|
+
$el: shell,
|
|
568
|
+
unmount() {
|
|
569
|
+
var _a, _b;
|
|
570
|
+
disposed = true;
|
|
571
|
+
renderGeneration += 1;
|
|
572
|
+
clearRerenderTimer();
|
|
573
|
+
clearStatsRefreshTimer();
|
|
574
|
+
(_a = context === null || context === void 0 ? void 0 : context.registerExportAdapter) === null || _a === void 0 ? void 0 : _a.call(context, null);
|
|
575
|
+
(_b = context === null || context === void 0 ? void 0 : context.registerThumbnailAdapter) === null || _b === void 0 ? void 0 : _b.call(context, null);
|
|
576
|
+
unregisterFileViewerZoomProvider(shell);
|
|
577
|
+
disposeResources();
|
|
578
|
+
target.replaceChildren();
|
|
579
|
+
},
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
const binaryPresentationDefinition = DEFAULT_RENDERER_DEFINITIONS.find(definition => definition.id === 'office-presentation-binary');
|
|
583
|
+
if (!binaryPresentationDefinition) {
|
|
584
|
+
throw new Error('@file-viewer/renderer-ppt could not locate the core PPT renderer definition.');
|
|
585
|
+
}
|
|
586
|
+
export const binaryPresentationRendererDefinition = binaryPresentationDefinition;
|
|
587
|
+
export const renderFileViewerBinaryPresentation = renderPpt;
|
|
588
|
+
export const pptRenderer = {
|
|
589
|
+
id: 'file-viewer-renderer-presentation-ppt',
|
|
590
|
+
label: 'Flyfish File Viewer PPT renderer',
|
|
591
|
+
definitions: [binaryPresentationRendererDefinition],
|
|
592
|
+
handlers: [
|
|
593
|
+
{
|
|
594
|
+
rendererId: binaryPresentationRendererDefinition.id,
|
|
595
|
+
handler: renderFileViewerBinaryPresentation,
|
|
596
|
+
},
|
|
597
|
+
],
|
|
598
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../../../ecosystem/capability-manifest.schema.json",
|
|
3
|
+
"schemaVersion": 1,
|
|
4
|
+
"id": "legacy-ppt",
|
|
5
|
+
"packageName": "@file-viewer/renderer-ppt",
|
|
6
|
+
"rendererIds": ["office-presentation-binary"],
|
|
7
|
+
"formats": ["ppt", "pot"],
|
|
8
|
+
"assets": {
|
|
9
|
+
"rendererIds": ["office-presentation-binary"],
|
|
10
|
+
"packageName": "@file-viewer/assets-ppt",
|
|
11
|
+
"installerPackageName": "@file-viewer/assets-ppt",
|
|
12
|
+
"bin": "file-viewer-assets-ppt",
|
|
13
|
+
"apiExport": "installFileViewerCapabilityAssetPack",
|
|
14
|
+
"target": "public/file-viewer",
|
|
15
|
+
"copyGroups": ["office-presentation-binary"],
|
|
16
|
+
"copyMode": "capability-pack",
|
|
17
|
+
"receiptFilename": "file-viewer-assets-ppt.receipt.json",
|
|
18
|
+
"notice": "Legacy PPT Worker/WASM runtime with the existing watermark and license boundary."
|
|
19
|
+
},
|
|
20
|
+
"license": { "spdx": "Apache-2.0", "policy": "separately-licensed" },
|
|
21
|
+
"weight": "heavy",
|
|
22
|
+
"profiles": ["office", "all"]
|
|
23
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@file-viewer/renderer-ppt",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Optional standalone renderer for legacy binary PowerPoint PPT and POT files.",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"file-viewer",
|
|
9
|
+
"renderer",
|
|
10
|
+
"ppt",
|
|
11
|
+
"presentation",
|
|
12
|
+
"document-preview",
|
|
13
|
+
"powerpoint",
|
|
14
|
+
"self-hosted"
|
|
15
|
+
],
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public",
|
|
18
|
+
"registry": "https://registry.npmjs.org/"
|
|
19
|
+
},
|
|
20
|
+
"author": {
|
|
21
|
+
"name": "Yu Wang",
|
|
22
|
+
"email": "admin@flyfish.dev"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/flyfish-dev/file-viewer.git",
|
|
27
|
+
"directory": "packages/renderers/presentation-ppt"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://doc.file-viewer.app/guide/on-demand-renderers",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/flyfish-dev/file-viewer/issues"
|
|
32
|
+
},
|
|
33
|
+
"funding": {
|
|
34
|
+
"type": "individual",
|
|
35
|
+
"url": "https://dev.flyfish.group/donate?source=npm"
|
|
36
|
+
},
|
|
37
|
+
"main": "./dist/index.js",
|
|
38
|
+
"module": "./dist/index.js",
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"import": "./dist/index.js",
|
|
44
|
+
"default": "./dist/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./package.json": "./package.json"
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"dist",
|
|
50
|
+
"file-viewer.capability.json",
|
|
51
|
+
"README.md",
|
|
52
|
+
"README.en.md",
|
|
53
|
+
"LICENSE"
|
|
54
|
+
],
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@file-viewer/core": "3.0.0",
|
|
57
|
+
"@file-viewer/ppt": "0.3.3"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"typescript": "^6.0.3"
|
|
61
|
+
},
|
|
62
|
+
"fileViewer": {
|
|
63
|
+
"capabilityManifest": "./file-viewer.capability.json"
|
|
64
|
+
},
|
|
65
|
+
"license": "Apache-2.0",
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "tsc -b tsconfig.json",
|
|
68
|
+
"type-check": "tsc -b tsconfig.json"
|
|
69
|
+
}
|
|
70
|
+
}
|