@silurus/ooxml 0.74.5 → 0.75.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.
Files changed (47) hide show
  1. package/README.md +105 -6
  2. package/dist/bounded-raw-part-cache-BTfZD_Sz.js +1248 -0
  3. package/dist/{docx-DftZMp7R.js → document-pull-client-H80_E10V.js} +11165 -11517
  4. package/dist/docx-BX0mJqS1.js +1274 -0
  5. package/dist/docx.mjs +6 -3
  6. package/dist/docx_parser_bg.wasm +0 -0
  7. package/dist/duotone-bitmap-by-path-Dv5Ikbzl.js +28 -0
  8. package/dist/find-cursor-Dc5iM6s7.js +815 -0
  9. package/dist/highlight-rect-cCvVU-MW.js +48 -0
  10. package/dist/hyperlink-D85FexTa.js +27 -0
  11. package/dist/index.mjs +4 -4
  12. package/dist/{highlight-rect-IjFkGg4X.js → line-distribute-DkLgIa7B.js} +37 -84
  13. package/dist/{find-cursor-DtgyGs5V.js → line-metrics-qwIyTk7Q.js} +1169 -3641
  14. package/dist/math.mjs +1 -1
  15. package/dist/node.mjs +998 -0
  16. package/dist/pptx-BEYjiTnZ.js +822 -0
  17. package/dist/pptx-CXgyi7wu.js +1705 -0
  18. package/dist/pptx.mjs +7 -3
  19. package/dist/pptx_parser_bg.wasm +0 -0
  20. package/dist/preload-BEouWnlI.js +132 -0
  21. package/dist/render-C0wMf5eT.js +71 -0
  22. package/dist/render-worker-host-CLdOlxFu.js +27 -0
  23. package/dist/render-worker-host-DZ4u0RFs.js +27 -0
  24. package/dist/render-worker-host-s3J-mWBP.js +27 -0
  25. package/dist/renderer-CwzTv9hH.js +5225 -0
  26. package/dist/resource-measurement-6aReN3K0.js +93 -0
  27. package/dist/slide-pull-client-D_T0AIoX.js +175 -0
  28. package/dist/svg-image-by-path-C1M3N2pT.js +1623 -0
  29. package/dist/transfer-3QEJrsJa.js +6 -0
  30. package/dist/types/docx.d.ts +290 -105
  31. package/dist/types/index.d.ts +399 -142
  32. package/dist/types/math.d.ts +1 -1
  33. package/dist/types/node.d.ts +4855 -0
  34. package/dist/types/pptx.d.ts +431 -245
  35. package/dist/types/xlsx.d.ts +320 -120
  36. package/dist/visible-index-CKvgpUrf.js +17 -0
  37. package/dist/worksheet-pull-worker-DCei8u-4.js +347 -0
  38. package/dist/{xlsx-BqMHvfsE.js → xlsx-DJyPlzjB.js} +1499 -1284
  39. package/dist/xlsx.mjs +7 -3
  40. package/dist/xlsx_parser_bg.wasm +0 -0
  41. package/package.json +12 -2
  42. package/dist/pptx-BxU0Lb3J.js +0 -6761
  43. package/dist/render-worker-host-Bcm9j4-H.js +0 -27
  44. package/dist/render-worker-host-BqSTDaYt.js +0 -27
  45. package/dist/render-worker-host-C523QxVw.js +0 -27
  46. package/dist/visible-index-C3_3gBg-.js +0 -50
  47. /package/dist/{mathjax-BPjQ2C_j.js → mathjax-Dqo857oC.js} +0 -0
@@ -0,0 +1,1705 @@
1
+ import { t as e } from "./chunk-DmhlhrBa.js";
2
+ import { D as t, E as n, M as r, N as i, _ as a, c as o, h as s, l as c, n as l, t as u, u as d } from "./bounded-raw-part-cache-BTfZD_Sz.js";
3
+ import { a as f, c as p, d as m, f as h, h as g, i as _, l as v, m as y, n as b, o as x, p as S, r as C, s as w, t as ee, u as te } from "./find-cursor-Dc5iM6s7.js";
4
+ import { n as ne, r as re } from "./preload-BEouWnlI.js";
5
+ import { f as ie, i as ae, p as oe, t as se } from "./svg-image-by-path-C1M3N2pT.js";
6
+ import { M as T, N as ce, st as E } from "./line-metrics-qwIyTk7Q.js";
7
+ import { r as D, t as O } from "./renderer-CwzTv9hH.js";
8
+ import { n as le, r as k, t as ue } from "./visible-index-CKvgpUrf.js";
9
+ import { n as de, r as A, t as j } from "./highlight-rect-cCvVU-MW.js";
10
+ import { r as M } from "./hyperlink-D85FexTa.js";
11
+ import { a as N, i as fe, n as pe, o as me, r as he, t as ge } from "./slide-pull-client-D_T0AIoX.js";
12
+ import { n as _e } from "./resource-measurement-6aReN3K0.js";
13
+ //#region packages/core/src/nav/internal-target.ts
14
+ function ve(e, t) {
15
+ let n = t.startsWith("/") ? [] : e.split("/").filter((e) => e !== "");
16
+ for (let e of t.split("/")) if (e === "..") n.pop();
17
+ else if (e === "." || e === "") continue;
18
+ else n.push(e);
19
+ return n.join("/");
20
+ }
21
+ function ye(e) {
22
+ let t = /[?&]jump=([a-zA-Z]+)/.exec(e);
23
+ if (!t) return null;
24
+ let n = t[1].toLowerCase();
25
+ return n === "firstslide" || n === "lastslide" || n === "nextslide" || n === "previousslide" ? n : null;
26
+ }
27
+ function be(e, t, n) {
28
+ if (!(n <= 0)) switch (e) {
29
+ case "firstslide": return 0;
30
+ case "lastslide": return n - 1;
31
+ case "nextslide": return Math.min(t + 1, n - 1);
32
+ case "previousslide": return Math.max(t - 1, 0);
33
+ }
34
+ }
35
+ //#endregion
36
+ //#region packages/pptx/src/text-layer.ts
37
+ function P(e, t, n, r, i) {
38
+ e.innerHTML = "";
39
+ let a = /* @__PURE__ */ new Map();
40
+ for (let o of t) {
41
+ let t = o.rotation + (o.textBodyRotation ?? 0), s = `${o.shapeX},${o.shapeY},${o.shapeW},${o.shapeH},${t}`;
42
+ if (!a.has(s)) {
43
+ let i = document.createElement("div");
44
+ i.style.cssText = `position:absolute;left:${j(o.shapeX, n)};top:${j(o.shapeY, r)};width:${j(o.shapeW, n)};height:${j(o.shapeH, r)};pointer-events:all;overflow:hidden;`, t !== 0 && (i.style.transformOrigin = "center center", i.style.transform = `rotate(${t}deg)`), a.set(s, {
45
+ div: i,
46
+ x: o.shapeX,
47
+ y: o.shapeY,
48
+ w: o.shapeW,
49
+ h: o.shapeH,
50
+ rot: t
51
+ }), e.appendChild(i);
52
+ }
53
+ let c = a.get(s), l = document.createElement("span");
54
+ l.textContent = o.text;
55
+ let u = i ? o.hyperlink : void 0;
56
+ l.style.cssText = `position:absolute;left:${j(o.inShapeX, c.w)};top:${j(o.inShapeY, c.h)};font:${o.font};line-height:${o.h}px;letter-spacing:0;white-space:pre;color:transparent;cursor:${u ? "pointer" : "text"};`, u && i && (l.title = u.kind === "external" ? u.url : u.ref, l.addEventListener("click", (e) => {
57
+ e.preventDefault(), i(u);
58
+ })), c.div.appendChild(l);
59
+ }
60
+ }
61
+ function F(e, t, n, r, i, a, o = {}) {
62
+ e.innerHTML = "";
63
+ let s = o.match ?? "rgba(255, 214, 0, 0.42)", c = o.active ?? "rgba(255, 140, 0, 0.55)", l = /* @__PURE__ */ new Map(), u = (t) => {
64
+ let n = t.rotation + (t.textBodyRotation ?? 0), a = `${t.shapeX},${t.shapeY},${t.shapeW},${t.shapeH},${n}`, o = l.get(a);
65
+ if (!o) {
66
+ let s = document.createElement("div");
67
+ s.style.cssText = `position:absolute;left:${j(t.shapeX, r)};top:${j(t.shapeY, i)};width:${j(t.shapeW, r)};height:${j(t.shapeH, i)};pointer-events:none;overflow:hidden;`, n !== 0 && (s.style.transformOrigin = "center center", s.style.transform = `rotate(${n}deg)`), o = {
68
+ div: s,
69
+ w: t.shapeW,
70
+ h: t.shapeH
71
+ }, l.set(a, o), e.appendChild(s);
72
+ }
73
+ return o;
74
+ };
75
+ for (let e of n) {
76
+ let n = e.active ? c : s;
77
+ for (let r of e.slices) {
78
+ let e = t[r.runIndex];
79
+ if (!e) continue;
80
+ let i = a(e.font), { x: o, width: s } = de(e.text, r.start, r.end, i);
81
+ if (s <= 0) continue;
82
+ let c = u(e), l = document.createElement("div");
83
+ l.style.cssText = `position:absolute;left:${j(e.inShapeX + o, c.w)};top:${j(e.inShapeY, c.h)};width:${j(s, c.w)};height:${j(e.h, c.h)};background:${n};pointer-events:none;`, c.div.appendChild(l);
84
+ }
85
+ }
86
+ }
87
+ //#endregion
88
+ //#region packages/pptx/src/find.ts
89
+ var I = class {
90
+ _slideRuns = /* @__PURE__ */ new Map();
91
+ _matches = [];
92
+ _active = -1;
93
+ _generation = 0;
94
+ _runsRevision = 0;
95
+ constructor(e, t) {
96
+ this._slideCount = e, this._collectSlideRuns = t;
97
+ }
98
+ invalidate() {
99
+ this._generation++, this._runsRevision++, this._slideRuns.clear(), this._matches = [], this._active = -1;
100
+ }
101
+ slideRuns(e) {
102
+ return this._slideRuns.get(e);
103
+ }
104
+ setSlideRuns(e, t) {
105
+ this._runsRevision++, this._slideRuns.set(e, t);
106
+ }
107
+ slideHighlights(e) {
108
+ let t = [];
109
+ for (let n = 0; n < this._matches.length; n++) {
110
+ let r = this._matches[n];
111
+ r.slide === e && t.push({
112
+ slices: r.slices,
113
+ active: n === this._active
114
+ });
115
+ }
116
+ return t;
117
+ }
118
+ activeSlide() {
119
+ let e = this._matches[this._active];
120
+ return e ? e.slide : null;
121
+ }
122
+ matches() {
123
+ return this._matches.map((e, t) => ({
124
+ matchIndex: t,
125
+ text: e.text,
126
+ location: { slide: e.slide }
127
+ }));
128
+ }
129
+ async find(e, t = {}) {
130
+ let n = ++this._generation;
131
+ if (e.length === 0) return this._runsRevision++, this._slideRuns.clear(), this._matches = [], this._active = -1, [];
132
+ let r = this._runsRevision, i = new Map(this._slideRuns), a = this._slideCount();
133
+ for (let e = 0; e < a; e++) {
134
+ let t = i.get(e);
135
+ if (!t) {
136
+ if (t = await this._collectSlideRuns(e), n !== this._generation) return [];
137
+ i.set(e, t);
138
+ }
139
+ }
140
+ if (n !== this._generation) return [];
141
+ let o = r === this._runsRevision ? i : new Map([...i, ...this._slideRuns]), s = [];
142
+ for (let n = 0; n < a; n++) {
143
+ let r = o.get(n) ?? [], i = C(r);
144
+ for (let a of _(i, e, t)) {
145
+ let e = a.slices.map((e) => r[e.runIndex].text.slice(e.start, e.end)).join("");
146
+ s.push({
147
+ slide: n,
148
+ text: e,
149
+ slices: a.slices
150
+ });
151
+ }
152
+ }
153
+ return this._runsRevision++, this._slideRuns = o, this._matches = s, this._active = -1, this.matches();
154
+ }
155
+ next() {
156
+ return this._active = ee(this._active, this._matches.length), this._activePublic();
157
+ }
158
+ prev() {
159
+ return this._active = b(this._active, this._matches.length), this._activePublic();
160
+ }
161
+ _activePublic() {
162
+ let e = this._matches[this._active];
163
+ return e ? {
164
+ matchIndex: this._active,
165
+ text: e.text,
166
+ location: { slide: e.slide }
167
+ } : null;
168
+ }
169
+ }, L = (e) => e >= "0" && e <= "9";
170
+ function xe(e) {
171
+ let t = 0;
172
+ for (let n = 0; n < 10; n++) t = Math.max(t, e.measureText(String(n)).width);
173
+ return t;
174
+ }
175
+ function Se(e, t, n) {
176
+ let r = 0;
177
+ for (let i of t) r += L(i) ? n : e.measureText(i).width;
178
+ return r;
179
+ }
180
+ function Ce(e, t, n, r, i) {
181
+ let a = e.textAlign;
182
+ e.textAlign = "left";
183
+ let o = n;
184
+ for (let n of t) if (L(n)) {
185
+ let t = e.measureText(n).width;
186
+ e.fillText(n, o + (i - t) / 2, r), o += i;
187
+ } else e.fillText(n, o, r), o += e.measureText(n).width;
188
+ e.textAlign = a;
189
+ }
190
+ //#endregion
191
+ //#region packages/pptx/src/presentation-handle.ts
192
+ var R = (e, t) => e / E * t;
193
+ async function we(e, t, n) {
194
+ let r = e.getContext("2d");
195
+ if (!r) throw Error("2D context not available");
196
+ let i = n.width / (n.slideWidthEmu / E);
197
+ await n.drawBase();
198
+ let a = document.createElement("canvas");
199
+ a.width = e.width, a.height = e.height;
200
+ let o = a.getContext("2d");
201
+ if (!o) throw Error("base 2D context not available");
202
+ o.drawImage(e, 0, 0);
203
+ let s = [], c = [], l = !1, u = (e) => {
204
+ l || (n.onError ? n.onError(e) : console.error("[ooxml] PPTX embedded media failed:", e));
205
+ };
206
+ for (let e of t) {
207
+ let t;
208
+ try {
209
+ t = await n.fetchMedia(e.mediaPath);
210
+ } catch (t) {
211
+ u(Te(e, t)), c.push(z(e, i));
212
+ continue;
213
+ }
214
+ let r = e.mimeType || t.type, a = t.type === r ? t : new Blob([t], { type: r }), o = URL.createObjectURL(a), d = e.mediaKind === "video" ? document.createElement("video") : document.createElement("audio");
215
+ d.src = o, d.preload = "metadata", e.mediaKind === "video" && (d.playsInline = !0);
216
+ let f = z(e, i), p = {
217
+ el: e,
218
+ rect: e.mediaKind === "audio" ? {
219
+ x: f.x + f.w / 2 - Math.max(f.w, 260) / 2,
220
+ y: f.y,
221
+ w: Math.max(f.w, 260),
222
+ h: f.h + 36
223
+ } : f,
224
+ posterRect: f,
225
+ media: d,
226
+ objectUrl: o,
227
+ loadState: "loading",
228
+ detachListeners: () => {}
229
+ }, m = () => {
230
+ l || (p.loadState = "metadata");
231
+ }, h = () => {
232
+ l || (p.loadState = "ready");
233
+ }, g = () => {
234
+ l || (p.loadState = "error", u(V(e, d, "decode")));
235
+ };
236
+ d.addEventListener("loadedmetadata", m), d.addEventListener("canplay", h), d.addEventListener("error", g), p.detachListeners = () => {
237
+ d.removeEventListener("loadedmetadata", m), d.removeEventListener("canplay", h), d.removeEventListener("error", g);
238
+ }, s.push(p);
239
+ try {
240
+ d.load();
241
+ } catch (t) {
242
+ p.loadState = "error", u(V(e, d, "load", t));
243
+ }
244
+ }
245
+ let d = null, f = null, p = () => {
246
+ r.setTransform(n.dpr, 0, 0, n.dpr, 0, 0);
247
+ let t = e.width / n.dpr, i = e.height / n.dpr;
248
+ r.drawImage(a, 0, 0, e.width, e.height, 0, 0, t, i);
249
+ for (let e of c) B(r, e, "Media unavailable");
250
+ for (let e of s) {
251
+ let t = e.media;
252
+ if (e.loadState !== "loading") {
253
+ if (e.loadState === "error") {
254
+ B(r, e.posterRect, "Media unavailable");
255
+ continue;
256
+ }
257
+ if (e.el.mediaKind === "video" && t.readyState >= 2) {
258
+ let { x: n, y: i, w: a, h: o } = e.posterRect;
259
+ r.drawImage(t, n, i, a, o);
260
+ }
261
+ if (e === f || _?.state === e) Oe(r, e, t);
262
+ else if (t.paused) {
263
+ let { x: t, y: n, w: i, h: a } = e.posterRect;
264
+ D(r, t + i / 2, n + a / 2, i, a, "paused");
265
+ }
266
+ }
267
+ }
268
+ }, m = () => {
269
+ l || (p(), d = requestAnimationFrame(m));
270
+ }, h = (t, r) => {
271
+ let i = e.getBoundingClientRect(), a = e.width / n.dpr, o = e.height / n.dpr;
272
+ return {
273
+ x: (t - i.left) / i.width * a,
274
+ y: (r - i.top) / i.height * o
275
+ };
276
+ }, g = (e, t) => {
277
+ for (let n of s) {
278
+ let { x: r, y: i, w: a, h: o } = n.rect;
279
+ if (e < r || e > r + a || t < i || t > i + o) continue;
280
+ let s = Y(n), c = s.y - 12, l = s.y + s.h + 8;
281
+ return (Number.isFinite(n.media.duration) ? n.media.duration : 0) > 0 && e >= s.x && e <= s.x + s.w && t >= c && t <= l ? {
282
+ kind: "seek",
283
+ state: n,
284
+ fraction: Math.max(0, Math.min(1, (e - s.x) / s.w))
285
+ } : {
286
+ kind: "toggle",
287
+ state: n
288
+ };
289
+ }
290
+ return null;
291
+ }, _ = null, v = (e, t) => {
292
+ let n = Number.isFinite(e.media.duration) ? e.media.duration : 0;
293
+ n <= 0 || (e.media.currentTime = n * t);
294
+ }, y = (e) => {
295
+ try {
296
+ e.media.play().catch((t) => {
297
+ u(V(e.el, e.media, "play", t));
298
+ });
299
+ } catch (t) {
300
+ u(V(e.el, e.media, "play", t));
301
+ }
302
+ }, b = (t) => {
303
+ let { x: n, y: r } = h(t.clientX, t.clientY), i = g(n, r);
304
+ i && (i.kind === "seek" ? (_ = {
305
+ state: i.state,
306
+ wasPlaying: !i.state.media.paused
307
+ }, i.state.media.pause(), v(i.state, i.fraction), e.setPointerCapture(t.pointerId), t.preventDefault()) : i.state.media.paused ? y(i.state) : i.state.media.pause());
308
+ }, x = (e) => {
309
+ let { x: t, y: n } = h(e.clientX, e.clientY);
310
+ f = null;
311
+ for (let e of s) {
312
+ let { x: r, y: i, w: a, h: o } = e.rect;
313
+ if (t >= r && t <= r + a && n >= i && n <= i + o) {
314
+ f = e;
315
+ break;
316
+ }
317
+ }
318
+ if (_) {
319
+ let e = Y(_.state), n = Math.max(0, Math.min(1, (t - e.x) / e.w));
320
+ v(_.state, n);
321
+ }
322
+ }, S = () => {
323
+ f = null;
324
+ }, C = (t) => {
325
+ if (!_) return;
326
+ let { wasPlaying: n, state: r } = _;
327
+ _ = null, e.releasePointerCapture(t.pointerId), n && y(r);
328
+ };
329
+ return s.length > 0 ? (e.addEventListener("pointerdown", b), e.addEventListener("pointermove", x), e.addEventListener("pointerleave", S), e.addEventListener("pointerup", C), e.addEventListener("pointercancel", C), e.style.cursor = "pointer", m()) : c.length > 0 && p(), {
330
+ play(e) {
331
+ for (let t of s) (!e || t.el.mediaPath === e) && y(t);
332
+ },
333
+ pause(e) {
334
+ for (let t of s) (!e || t.el.mediaPath === e) && t.media.pause();
335
+ },
336
+ destroy() {
337
+ if (!l) {
338
+ l = !0, d !== null && cancelAnimationFrame(d), e.removeEventListener("pointerdown", b), e.removeEventListener("pointermove", x), e.removeEventListener("pointerleave", S), e.removeEventListener("pointerup", C), e.removeEventListener("pointercancel", C), e.style.cursor = "";
339
+ for (let e of s) e.detachListeners(), e.media.pause(), e.media.removeAttribute("src"), e.media.load(), URL.revokeObjectURL(e.objectUrl);
340
+ }
341
+ }
342
+ };
343
+ }
344
+ function z(e, t) {
345
+ return {
346
+ x: R(e.x, t),
347
+ y: R(e.y, t),
348
+ w: R(e.width, t),
349
+ h: R(e.height, t)
350
+ };
351
+ }
352
+ function B(e, t, n) {
353
+ let r = Math.max(10, Math.min(14, t.h * .12));
354
+ e.save(), e.font = `500 ${r}px system-ui, -apple-system, sans-serif`, e.textAlign = "center", e.textBaseline = "middle";
355
+ let i = r + 12, a = Math.min(t.w, Math.max(100, e.measureText(n).width + 24));
356
+ X(e, t.x + (t.w - a) / 2, t.y + (t.h - i) / 2, a, i, i / 2), e.fillStyle = "rgba(20, 20, 20, 0.72)", e.fill(), e.fillStyle = "rgba(255, 255, 255, 0.95)", e.fillText(n, t.x + t.w / 2, t.y + t.h / 2), e.restore();
357
+ }
358
+ function Te(e, t) {
359
+ return /* @__PURE__ */ Error(`Embedded ${e.mediaKind} fetch failed for "${e.mediaPath}" (mime=${e.mimeType || "unknown"}): ${H(t)}`);
360
+ }
361
+ function V(e, t, n, r) {
362
+ let i = "";
363
+ try {
364
+ i = e.mimeType ? t.canPlayType(e.mimeType) : "";
365
+ } catch {}
366
+ let a = t.error, o = [
367
+ `mime=${e.mimeType || "unknown"}`,
368
+ `canPlayType=${i || "no"}`,
369
+ `readyState=${t.readyState}`,
370
+ `networkState=${t.networkState}`
371
+ ];
372
+ a && o.push(`mediaError=${a.code}${a.message ? ` ${a.message}` : ""}`);
373
+ let s = r === void 0 ? "" : `: ${H(r)}`;
374
+ return /* @__PURE__ */ Error(`Embedded ${e.mediaKind} ${n} failed for "${e.mediaPath}" (${o.join("; ")})${s}`);
375
+ }
376
+ function H(e) {
377
+ return e instanceof Error ? `${e.name || "Error"}${e.message ? `: ${e.message}` : ""}` : String(e);
378
+ }
379
+ var U = 28, W = 14, Ee = 72, De = 10, G = 3;
380
+ function Oe(e, t, n) {
381
+ let r = Number.isFinite(n.duration) ? n.duration : 0, i = r > 0 ? Math.min(1, n.currentTime / r) : 0, a = t.posterRect;
382
+ D(e, a.x + a.w / 2, a.y + a.h / 2, a.w, a.h, n.paused ? "paused" : "playing"), t.el.mediaKind === "audio" ? Ae(e, t, n, r, i) : ke(e, t, n, r, i);
383
+ }
384
+ function ke(e, t, n, r, i) {
385
+ let { x: a, y: o, w: s, h: c } = t.rect, l = Math.max(28, Math.min(56, c * .22)), u = o + c - l;
386
+ e.save();
387
+ let d = e.createLinearGradient(0, u, 0, o + c);
388
+ d.addColorStop(0, "rgba(0, 0, 0, 0)"), d.addColorStop(1, "rgba(0, 0, 0, 0.55)"), e.fillStyle = d, e.fillRect(a, u, s, l), e.restore();
389
+ let f = Y(t);
390
+ q(e, f, i, r > 0), e.save(), e.font = "500 11px system-ui, -apple-system, sans-serif", e.textBaseline = "middle", e.shadowColor = "rgba(0, 0, 0, 0.75)", e.shadowBlur = 3, e.fillStyle = "rgba(255, 255, 255, 0.95)", K(e, n.currentTime, r, f.x, f.y - 10, "bottom"), e.restore();
391
+ }
392
+ function Ae(e, t, n, r, i) {
393
+ let a = J(t.rect);
394
+ e.save(), X(e, a.x, a.y, a.w, a.h, a.h / 2), e.fillStyle = "rgba(20, 20, 20, 0.72)", e.fill(), e.font = "500 11px system-ui, -apple-system, sans-serif", e.textBaseline = "middle", e.fillStyle = "rgba(255, 255, 255, 0.95)", K(e, n.currentTime, r, a.x + W, a.y + a.h / 2, "middle"), e.restore(), q(e, Y(t), i, r > 0);
395
+ }
396
+ function K(e, t, n, r, i, a) {
397
+ let o = Z(t), s = Z(n), c = xe(e), l = Se(e, o, c), u = Se(e, s, c), d = e.measureText(" / ").width, f = Math.max(l, u);
398
+ Ce(e, o, r + f - l, i, c);
399
+ let p = e.textAlign;
400
+ e.textAlign = "left", e.fillText(" / ", r + f, i), e.textAlign = p, Ce(e, s, r + f + d, i, c);
401
+ }
402
+ function q(e, t, n, r) {
403
+ let i = t.h / 2;
404
+ if (e.save(), X(e, t.x, t.y, t.w, t.h, i), e.fillStyle = "rgba(255, 255, 255, 0.35)", e.fill(), n > 0 && (X(e, t.x, t.y, t.w * n, t.h, i), e.fillStyle = "#fff", e.fill()), r) {
405
+ let r = Math.max(t.x + 5, Math.min(t.x + t.w - 5, t.x + t.w * n));
406
+ e.shadowColor = "rgba(0, 0, 0, 0.3)", e.shadowBlur = 3, e.fillStyle = "#fff", e.beginPath(), e.arc(r, t.y + t.h / 2, 5, 0, Math.PI * 2), e.fill();
407
+ }
408
+ e.restore();
409
+ }
410
+ function J(e) {
411
+ let t = Math.max(220, e.w - 24);
412
+ return {
413
+ x: e.x + e.w / 2 - t / 2,
414
+ y: e.y + e.h - U - 4,
415
+ w: t,
416
+ h: U
417
+ };
418
+ }
419
+ function Y(e) {
420
+ if (e.el.mediaKind === "audio") {
421
+ let t = J(e.rect), n = t.x + W + Ee + De, r = Math.max(40, t.x + t.w - W - n);
422
+ return {
423
+ x: n,
424
+ y: t.y + (t.h - G) / 2,
425
+ w: r,
426
+ h: G
427
+ };
428
+ }
429
+ let t = e.rect, n = Math.max(12, t.w * .025), r = Math.max(12, Math.min(18, t.h * .05));
430
+ return {
431
+ x: t.x + n,
432
+ y: t.y + t.h - G - r,
433
+ w: t.w - n * 2,
434
+ h: G
435
+ };
436
+ }
437
+ function X(e, t, n, r, i, a) {
438
+ let o = Math.min(a, i / 2, r / 2);
439
+ e.beginPath(), e.moveTo(t + o, n), e.lineTo(t + r - o, n), e.quadraticCurveTo(t + r, n, t + r, n + o), e.lineTo(t + r, n + i - o), e.quadraticCurveTo(t + r, n + i, t + r - o, n + i), e.lineTo(t + o, n + i), e.quadraticCurveTo(t, n + i, t, n + i - o), e.lineTo(t, n + o), e.quadraticCurveTo(t, n, t + o, n), e.closePath();
440
+ }
441
+ function Z(e) {
442
+ if (!Number.isFinite(e) || e < 0) return "0:00";
443
+ let t = Math.floor(e);
444
+ return `${Math.floor(t / 60)}:${(t % 60).toString().padStart(2, "0")}`;
445
+ }
446
+ //#endregion
447
+ //#region packages/pptx/src/slide-nav.ts
448
+ function je(e) {
449
+ let t = /* @__PURE__ */ new Map();
450
+ for (let n = 0; n < e.length; n++) {
451
+ let r = e[n];
452
+ r !== void 0 && r !== "" && !t.has(r) && t.set(r, n);
453
+ }
454
+ return t;
455
+ }
456
+ function Me(e, t) {
457
+ if (e === "") return;
458
+ let n = ve("ppt/slides", e);
459
+ return t.get(n);
460
+ }
461
+ function Ne(e, t, n) {
462
+ let r = ye(e);
463
+ return r === null ? Me(e, t) : be(r, n, t.size);
464
+ }
465
+ //#endregion
466
+ //#region packages/pptx/src/slide-repository.ts
467
+ var Pe = class {
468
+ #e;
469
+ #t;
470
+ #n;
471
+ #r = 0;
472
+ #i = Promise.resolve();
473
+ #a;
474
+ #o;
475
+ constructor(e) {
476
+ if (!Number.isSafeInteger(e.slideCount) || e.slideCount < 0) throw TypeError("slideCount must be a non-negative safe integer");
477
+ this.#e = e.slideCount, this.#t = e.loadSlide, this.#n = new l({
478
+ maxEntries: e.maxCachedSlides,
479
+ maxWeight: e.maxCachedStructuralBytes,
480
+ measure: (e) => _e(e).jsonBytes
481
+ });
482
+ }
483
+ get slideCount() {
484
+ return this.#e;
485
+ }
486
+ get usage() {
487
+ return this.#n.usage;
488
+ }
489
+ withSlide(e, t) {
490
+ this.#c(e);
491
+ let n = this.#r, r = this.#i.then(async () => {
492
+ if (n !== this.#r) throw this.#a ? this.#a : Error("PPTX slide repository generation is stale");
493
+ if (this.#a) throw this.#a;
494
+ let r = await this.#s(e, n);
495
+ try {
496
+ return await t(r);
497
+ } catch (e) {
498
+ let t = Q(e);
499
+ throw t ? (this.#l(t, n), this.#o === n ? this.#a ?? t : t) : e;
500
+ }
501
+ });
502
+ return this.#i = r.then(() => void 0, () => void 0), r;
503
+ }
504
+ async #s(e, t) {
505
+ return this.#n.getOrLoad(e, async () => {
506
+ let n;
507
+ try {
508
+ n = await this.#t(e);
509
+ } catch (e) {
510
+ let n = Q(e);
511
+ throw n ? (this.#l(n, t), this.#o === t ? this.#a ?? n : n) : e;
512
+ }
513
+ if (this.#o === t && this.#a) throw this.#a;
514
+ return n;
515
+ });
516
+ }
517
+ clear() {
518
+ this.#r += 1, this.#a = void 0, this.#o = void 0, this.#n.clear();
519
+ }
520
+ #c(e) {
521
+ if (!Number.isSafeInteger(e) || e < 0 || e >= this.#e) throw RangeError(`Slide index ${e} out of range (count: ${this.#e})`);
522
+ }
523
+ #l(e, t) {
524
+ t !== this.#r || this.#a || (this.#a = e, this.#o = t, this.#r += 1, this.#n.clear());
525
+ }
526
+ };
527
+ function Q(e) {
528
+ return e instanceof i ? e : t(e);
529
+ }
530
+ //#endregion
531
+ //#region packages/pptx/src/worker.ts?worker&inline
532
+ var Fe = "var e=class e extends Error{code;constructor(t,n){super(n),this.name=`OoxmlError`,this.code=t,Object.setPrototypeOf(this,e.prototype)}},t=class e extends Error{code=`ooxml-resource-limit`;details;constructor(t,n){super(t),this.name=`OoxmlResourceLimitError`;let r=n.violation,i=Object.freeze({format:r.format,operation:r.operation,resource:r.resource,metric:r.metric,...r.part===void 0?{}:{part:r.part},limit:r.limit,observed:r.observed,configurable:r.configurable,usage:Object.freeze({archiveEntryCount:r.usage.archiveEntryCount,declaredInflatedBytes:r.usage.declaredInflatedBytes,...r.usage.largestInflatedEntryBytes===void 0?{}:{largestInflatedEntryBytes:r.usage.largestInflatedEntryBytes},distinctInflatedBytes:r.usage.distinctInflatedBytes,operationInflatedBytes:r.usage.operationInflatedBytes})});this.details=Object.freeze({stage:n.stage,violation:i}),Object.setPrototypeOf(this,e.prototype)}};const n=`https://fonts.googleapis.com/css2?family=Noto+Naskh+Arabic:wght@400;700&display=swap`,r=`https://fonts.googleapis.com/css2?family=Noto+Sans+Arabic:wght@400;700&display=swap`,i={calibri:{url:`https://fonts.googleapis.com/css2?family=Carlito:ital,wght@0,400;0,700;1,400;1,700&display=swap`,loadFamily:`Carlito`},\"calibri light\":{url:`https://fonts.googleapis.com/css2?family=Carlito:ital,wght@0,400;0,700;1,400;1,700&display=swap`,loadFamily:`Carlito`},cambria:{url:`https://fonts.googleapis.com/css2?family=Caladea:ital,wght@0,400;0,700;1,400;1,700&display=swap`,loadFamily:`Caladea`},\"cambria math\":{url:`https://fonts.googleapis.com/css2?family=Caladea:ital,wght@0,400;0,700;1,400;1,700&display=swap`,loadFamily:`Caladea`},\"nunito sans\":{url:`https://fonts.googleapis.com/css2?family=Nunito+Sans:ital,wght@0,400;0,700;1,400;1,700&display=swap`},nunito:{url:`https://fonts.googleapis.com/css2?family=Nunito:ital,wght@0,400;0,700;1,400;1,700&display=swap`},\"open sans\":{url:`https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,400;0,700;1,400;1,700&display=swap`},roboto:{url:`https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700;1,400;1,700&display=swap`},lato:{url:`https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,400;0,700;1,400;1,700&display=swap`},montserrat:{url:`https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,400;0,700;1,400;1,700&display=swap`},poppins:{url:`https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,400;0,700;1,400;1,700&display=swap`},raleway:{url:`https://fonts.googleapis.com/css2?family=Raleway:ital,wght@0,400;0,700;1,400;1,700&display=swap`},\"playfair display\":{url:`https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,700;1,400;1,700&display=swap`},ubuntu:{url:`https://fonts.googleapis.com/css2?family=Ubuntu:ital,wght@0,400;0,700;1,400;1,700&display=swap`},\"sakkal majalla\":{url:n,loadFamily:`Noto Naskh Arabic`},\"traditional arabic\":{url:n,loadFamily:`Noto Naskh Arabic`},\"simplified arabic\":{url:n,loadFamily:`Noto Naskh Arabic`},\"arabic typesetting\":{url:n,loadFamily:`Noto Naskh Arabic`},\"univers next arabic\":{url:r,loadFamily:`Noto Sans Arabic`},\"noto naskh arabic\":{url:n,loadFamily:`Noto Naskh Arabic`},\"noto sans arabic\":{url:r,loadFamily:`Noto Sans Arabic`}};function a(e){if(!e)return null;let t=e.toLowerCase();return/[ᄀ-ᇿ㄰-㆏가-힯]/.test(e)?`kr`:/[぀-ヿ]/.test(e)?`jp`:/jhenghei|微軟正黑|新細明|細明|pmingliu|mingliu|dfkai|標楷|華康|cns11643|kaiti tc|ming\\s*liu/.test(t)||/新細明體|細明體|標楷體|微軟正黑體|華康/.test(e)?`tc`:/simsun|nsimsun|simhei|simkai|simfang|yahei|dengxian|fangsong|kaiti|youyuan|lisu|stsong|stkaiti|stfangsong|stheiti|stxihei|stzhongsong|songti sc|heiti sc|微软雅黑/.test(t)||/宋体|黑体|楷体|仿宋|等线|微软雅黑|隶书|幼圆/.test(e)?`sc`:/malgun|batang|gulim|dotum|gungsuh|nanum|new gulim|hancom|hy(gothic|graphic|namu)?/.test(t)?`kr`:/\\bmeiryo\\b|\\byu\\s*(gothic|mincho)\\b|yugothic|yumincho|hiragino|\\bms\\s*(gothic|mincho|pgothic|pmincho|ui\\s*gothic)\\b|\\bms[pg]?(gothic|mincho)\\b|ipa(ex)?(gothic|mincho)|noto\\s+(sans|serif)\\s+jp|游ゴシック|游明朝|MS|メイリオ|ヒラギノ/.test(t)||/游ゴシック|游明朝|MS ゴシック|MS 明朝|MS Pゴシック|メイリオ|ヒラギノ/.test(e)?`jp`:null}const o=e=>`https://fonts.googleapis.com/css2?family=${e}:wght@400;700&display=swap`,s={\"noto sans kr\":{url:o(`Noto+Sans+KR`)},\"noto sans sc\":{url:o(`Noto+Sans+SC`)},\"noto sans tc\":{url:o(`Noto+Sans+TC`)},\"noto sans jp\":{url:o(`Noto+Sans+JP`)},\"noto serif kr\":{url:o(`Noto+Serif+KR`)},\"noto serif sc\":{url:o(`Noto+Serif+SC`)},\"noto serif tc\":{url:o(`Noto+Serif+TC`)},\"noto serif jp\":{url:o(`Noto+Serif+JP`)},\"noto sans\":{url:o(`Noto+Sans`)},\"noto serif\":{url:o(`Noto+Serif`)},\"noto sans devanagari\":{url:o(`Noto+Sans+Devanagari`)},\"noto sans thai\":{url:o(`Noto+Sans+Thai`)},\"noto sans hebrew\":{url:o(`Noto+Sans+Hebrew`)},\"noto serif hebrew\":{url:o(`Noto+Serif+Hebrew`)}};var ee=class e{hasHan=!1;hasHangul=!1;hasKana=!1;hasArabic=!1;hasThai=!1;hasHebrew=!1;hasDevanagari=!1;hasCyrGreek=!1;constructor(e){this.cjkLang=e}clone(){let t=new e(this.cjkLang);return t.hasHan=this.hasHan,t.hasHangul=this.hasHangul,t.hasKana=this.hasKana,t.hasArabic=this.hasArabic,t.hasThai=this.hasThai,t.hasHebrew=this.hasHebrew,t.hasDevanagari=this.hasDevanagari,t.hasCyrGreek=this.hasCyrGreek,t}addText(e){let t=()=>this.hasHan&&this.hasHangul&&this.hasKana&&this.hasArabic&&this.hasThai&&this.hasHebrew&&this.hasDevanagari&&this.hasCyrGreek;outer:for(let n of e)if(n)for(let e of n){let n=e.codePointAt(0);if(n!==void 0&&!(n<=591)&&(n>=4352&&n<=4607||n>=12592&&n<=12687||n>=44032&&n<=55215?this.hasHangul=!0:n>=12352&&n<=12543?this.hasKana=!0:n>=13312&&n<=19903||n>=19968&&n<=40959||n>=63744&&n<=64255||n>=131072&&n<=195103?this.hasHan=!0:n>=1536&&n<=1791||n>=1872&&n<=1919||n>=2208&&n<=2303||n>=64336&&n<=65023||n>=65136&&n<=65279?this.hasArabic=!0:n>=3584&&n<=3711?this.hasThai=!0:n>=1424&&n<=1535||n>=64285&&n<=64335?this.hasHebrew=!0:n>=2304&&n<=2431?this.hasDevanagari=!0:(n>=1024&&n<=1279||n>=880&&n<=1023)&&(this.hasCyrGreek=!0),t()))break outer}}names(){let e=[],t=new Set;this.hasHangul&&t.add(`kr`),this.hasKana&&t.add(`jp`),this.hasHan&&t.size===0&&t.add(this.cjkLang??`jp`);for(let n of[`kr`,`sc`,`tc`,`jp`])if(t.has(n)){let t={kr:`KR`,sc:`SC`,tc:`TC`,jp:`JP`}[n];e.push(`Noto Sans ${t}`,`Noto Serif ${t}`)}return this.hasCyrGreek&&e.push(`Noto Sans`,`Noto Serif`),this.hasArabic&&e.push(`Noto Naskh Arabic`,`Noto Sans Arabic`),this.hasThai&&e.push(`Noto Sans Thai`),this.hasHebrew&&e.push(`Noto Sans Hebrew`,`Noto Serif Hebrew`),this.hasDevanagari&&e.push(`Noto Sans Devanagari`),e}},c=class e extends RangeError{code=`ooxml-decoded-image-limit`;constructor(t,n,r){super(`OOXML decoded image limit exceeded: ${t} ${r} > ${n}`),this.metric=t,this.limit=n,this.observed=r,this.name=`OoxmlDecodedImageLimitError`,Object.setPrototypeOf(this,e.prototype)}};function te(e){if(!e.startsWith(`data:`))return null;let t=e.indexOf(`,`);if(t===-1)return null;let n=atob(e.slice(t+1)),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return r.buffer}var l=class e extends Error{code=`parser-crashed`;constructor(t){super(t),this.name=`WasmTrapError`,Object.setPrototypeOf(this,e.prototype)}};function u(e){let t=globalThis.WebAssembly?.RuntimeError;if(t&&e instanceof t||e instanceof RangeError)return!0;if(e instanceof Error){let t=e.name;if(t===`RuntimeError`||t===`CompileError`||t===`LinkError`||t===`InternalError`||t===`OOMError`)return!0}return!1}function ne(e,t){return e({module_or_path:t})}var re=class{_init;_opts;_wasmInput=null;_initPromise=null;_poisoned=!1;_archive=null;constructor(e,t={}){this._init=e,this._opts=t}setWasmInput(e){this._wasmInput=e,this._poisoned=!1,this._initPromise=ne(this._init,e)}setWasmUrl(e){this.setWasmInput(e)}get archive(){return this._archive}setArchive(e){this._freeArchive(),this._archive=e}disposeArchive(){this._freeArchive()}_freeArchive(){this._archive!=null&&this._opts.freeArchive&&this._opts.freeArchive(this._archive),this._archive=null}get poisoned(){return this._poisoned}async ensureReady(){if(this._poisoned){if(this._wasmInput===null)throw Error(`WasmParserHost: setWasmInput was never called`);let e=ne(this._opts.reinit??this._init,this._wasmInput);this._initPromise=e,await e,this._poisoned=!1;return}if(this._initPromise===null)throw Error(`WasmParserHost: setWasmInput was never called`);await this._initPromise}run(e){try{return e()}catch(e){throw u(e)?(this._poison(),new l(`WASM parser trapped and was recycled: ${e instanceof Error?e.message:String(e)}`)):e}}poison(){this._poison()}_poison(){if(this._poisoned=!0,this._initPromise=null,this._archive!=null&&this._opts.freeArchive)try{this._opts.freeArchive(this._archive)}catch{}this._archive=null}};function ie(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>0}function d(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return ie(t.requiredBytes)&&ie(t.offeredBytes)&&t.requiredBytes>t.offeredBytes}var f=class e extends RangeError{code=`ooxml-insufficient-credit`;requiredBytes;offeredBytes;constructor(t){super(`Pull unit requires ${t.requiredBytes} bytes but credit is ${t.offeredBytes}`),this.name=`PullSessionInsufficientCreditError`,this.requiredBytes=t.requiredBytes,this.offeredBytes=t.offeredBytes,Object.setPrototypeOf(this,e.prototype)}};function p(e){if(e instanceof f)return e;let t=e instanceof Error?e.message:String(e);if(!t.startsWith(`OOXML_INSUFFICIENT_CREDIT:`))return;let n;try{n=JSON.parse(t.slice(26))}catch{return}if(!n||typeof n!=`object`||Array.isArray(n))return;let r=n;if(!(r.code!==`ooxml-insufficient-credit`||!d(r)))return new f(r)}function ae(e,t,n){let r=p(e);if(!(!r||r.offeredBytes!==t||r.requiredBytes>n))return r}const m=`OOXML_RESOURCE_LIMIT:`;function h(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function oe(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return h(t.archiveEntryCount)&&h(t.declaredInflatedBytes)&&(t.largestInflatedEntryBytes===void 0||h(t.largestInflatedEntryBytes))&&h(t.distinctInflatedBytes)&&h(t.operationInflatedBytes)}function se(e){let t;try{t=JSON.parse(new TextDecoder().decode(e))}catch{throw TypeError(`OOXML resource usage checkpoint is not valid JSON`)}if(!oe(t))throw TypeError(`OOXML resource usage checkpoint is invalid`);return t}function ce(e){return e===`docx`||e===`xlsx`||e===`pptx`}function le(e){return e===`container`||e===`decompression`||e===`parsing`||e===`serialization`||e===`layout`||e===`rendering`||e===`worker`}function g(e,t){return typeof e==`string`&&e.length>0&&e.length<=t&&!/[\\u0000-\\u001f\\u007f]/u.test(e)}function _(e){return g(e,128)&&/^[a-z0-9][a-z0-9-]*$/u.test(e)}function ue(e){return!g(e,4096)||e.startsWith(`/`)||e.startsWith(`\\\\`)||e.includes(`\\\\`)||e.includes(`?`)||e.includes(`#`)||e.includes(`://`)||/^[a-z]:/iu.test(e)?!1:e.split(`/`).every(e=>e!==``&&e!==`.`&&e!==`..`)}const v=new Map([[`archive-entry:declared-inflated-bytes`,{stage:`container`,part:`required`}],[`archive-entry:actual-inflated-bytes`,{stage:`decompression`,part:`required`}],[`archive:entry-count`,{stage:`container`,part:`forbidden`,configurable:!1}],[`archive:central-directory-bytes`,{stage:`container`,part:`forbidden`,configurable:!1}],[`archive:distinct-inflated-bytes`,{stage:`decompression`,part:`required`}],[`xml-event:bytes`,{stage:`parsing`,part:`optional`,configurable:!1}],[`xml-context:bytes`,{stage:`parsing`,part:`optional`,configurable:!1}],[`xml-tree:depth`,{stage:`parsing`,part:`optional`,configurable:!1}],[`worksheet-row:projected-bytes`,{stage:`parsing`,part:`optional`,configurable:!1}],[`worksheet-shell:projected-bytes`,{stage:`parsing`,part:`optional`,configurable:!1}]]),de=new Set([...v.keys()].map(e=>e.slice(0,e.indexOf(`:`)))),fe=new Set([...v.keys()].map(e=>e.slice(e.indexOf(`:`)+1)));function pe(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return!ce(t.format)||!g(t.operation,256)||!_(t.resource)||!_(t.metric)||!h(t.limit)||!h(t.observed)||typeof t.configurable!=`boolean`||!oe(t.usage)?!1:!(`part`in t)||ue(t.part)}function y(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;if(!le(t.stage)||!pe(t.violation))return!1;let n=t.violation,r=v.get(`${n.resource}:${n.metric}`);return r?t.stage!==r.stage||r.configurable===!1&&n.configurable!==!1?!1:r.part===`required`?n.part!==void 0:r.part===`forbidden`?n.part===void 0:!0:!(de.has(n.resource)&&fe.has(n.metric))}function me(e){return{archiveEntryCount:e.archiveEntryCount,declaredInflatedBytes:e.declaredInflatedBytes,...e.largestInflatedEntryBytes===void 0?{}:{largestInflatedEntryBytes:e.largestInflatedEntryBytes},distinctInflatedBytes:e.distinctInflatedBytes,operationInflatedBytes:e.operationInflatedBytes}}function he(e){if(!y(e))return;let t=e.violation,n={stage:e.stage,violation:{format:t.format,operation:t.operation,resource:t.resource,metric:t.metric,...t.part===void 0?{}:{part:t.part},limit:t.limit,observed:t.observed,configurable:t.configurable,usage:me(t.usage)}};return y(n)?n:void 0}function ge(e){let t=e.violation;return`OOXML resource limit exceeded${t.part?` for ${t.part}`:``}: ${t.metric} ${t.observed} > ${t.limit}`}function _e(e){let n=e instanceof Error?e.message:String(e);if(!n.startsWith(m))return;let r;try{r=JSON.parse(n.slice(21))}catch{return}if(!r||typeof r!=`object`)return;let i=r;if(!(i.code!==`ooxml-resource-limit`||!y(i.details)))return new t(ge(i.details),i.details)}function ve(n){if(n instanceof c)return{message:n.message,errorName:n.name,code:n.code,decodedImage:{metric:n.metric,limit:n.limit,observed:n.observed}};let r=p(n);if(r)return{message:r.message,errorName:r.name,code:r.code,insufficientCredit:{requiredBytes:r.requiredBytes,offeredBytes:r.offeredBytes}};let i=n instanceof e||n instanceof t?n:_e(n);if(i instanceof t){let e=he(i.details);return e?{message:typeof i.message==`string`?i.message:ge(e),errorName:`OoxmlResourceLimitError`,code:`ooxml-resource-limit`,resourceLimit:e}:{message:`Invalid OOXML resource-limit error payload`,errorName:`Error`}}if(i instanceof e)return{message:typeof i.message==`string`?i.message:String(i.message),errorName:g(i.name,128)?i.name:`OoxmlError`,..._(i.code)?{code:i.code}:{}};let a=n instanceof Error?n.message:String(n);if(typeof a==`string`&&a.startsWith(m))return{message:`Invalid OOXML resource-limit payload`,errorName:`Error`};let o=n instanceof Error?n:Error(a),s=o;return{message:typeof o.message==`string`?o.message:String(o.message),errorName:g(o.name,128)?o.name:`Error`,...typeof s.code==`string`?{code:s.code}:{}}}function b(e){try{return ve(e)}catch{return{message:`Worker operation failed with an unreadable error`,errorName:`Error`}}}const ye=new Set([`encrypted`,`invalid-password`,`unsupported-encryption`,`legacy-binary-format`,`not-ooxml`]);function be(n){if(n.code===`ooxml-decoded-image-limit`&&n.decodedImage&&(n.decodedImage.metric===`image-pixels`||n.decodedImage.metric===`active-decoded-bytes`)&&h(n.decodedImage.limit)&&h(n.decodedImage.observed)&&n.decodedImage.observed>n.decodedImage.limit)return new c(n.decodedImage.metric,n.decodedImage.limit,n.decodedImage.observed);if(n.code===`ooxml-insufficient-credit`&&d(n.insufficientCredit))return new f(n.insufficientCredit);if(n.code===`ooxml-resource-limit`&&y(n.resourceLimit))return new t(n.message,n.resourceLimit);if(n.code&&ye.has(n.code))return new e(n.code,n.message);let r=n.errorName===`TypeError`?TypeError(n.message):n.errorName===`RangeError`?RangeError(n.message):Error(n.message);return n.errorName&&(r.name=n.errorName),n.code!==void 0&&Object.assign(r,{code:n.code}),r}function xe(e){return e.byteOffset===0&&e.byteLength===e.buffer.byteLength&&e.buffer instanceof ArrayBuffer?e.buffer:e.slice().buffer}const x=67108864;Object.freeze({maxArchiveEntryBytes:134217728,maxTotalInflatedBytes:268435456});function Se(e){return[e.maxArchiveEntryBytes===null?0n:BigInt(e.maxArchiveEntryBytes),e.maxTotalInflatedBytes===null?0n:BigInt(e.maxTotalInflatedBytes)]}const S=`ooxml-pull-v1`;function C(e,t){if(!Number.isSafeInteger(e)||e<=0)throw RangeError(`${t} must be a positive safe integer`)}function Ce(e){if(!(typeof e==`string`&&e.length>0||typeof e==`number`&&Number.isSafeInteger(e)&&e>0))throw RangeError(`session id must be a non-empty string or positive safe integer`)}var w=class{owner;queue=Promise.resolve();leases=new Map;retainedBytes=0;retainedCount=0;maxRetainedBytes;maxRetainedCount;cleanups=new Set;pendingFatalCleanups=[];poisonRunning=!1;fatal;constructor(e){this.maxRetainedBytes=e?.maxRetainedBytes??64*1024*1024,this.maxRetainedCount=e?.maxRetainedCount??256,C(this.maxRetainedBytes,`max retained lease bytes`),C(this.maxRetainedCount,`max retained lease count`)}enqueue(e){let t=this.queue.then(e,e);return this.queue=t.then(()=>void 0,()=>void 0),t}acquire(e){return this.owner===void 0?(this.owner=e,!0):this.owner===e}release(e){this.owner===e&&(this.owner=void 0)}retainLease(e,t,n){if(!Number.isSafeInteger(n)||n<0)throw RangeError(`retained lease bytes are invalid`);let r=this.leases.get(e)??new Map;if(r.has(t))throw Error(`driver returned a duplicate lease id`);if(this.retainedCount+1>this.maxRetainedCount)throw RangeError(`retained lease count exceeds limit`);if(this.retainedBytes+n>this.maxRetainedBytes)throw RangeError(`retained lease bytes exceed limit`);r.set(t,n),this.leases.set(e,r),this.retainedCount++,this.retainedBytes+=n}releaseLease(e,t){let n=this.leases.get(e),r=n?.get(t);r!==void 0&&(n?.delete(t),n?.size===0&&this.leases.delete(e),this.retainedCount--,this.retainedBytes-=r)}registerCleanup(e){return this.fatal?(this.poisonRunning?this.pendingFatalCleanups.push(e):this.enqueue(e).catch(()=>void 0),()=>void 0):(this.cleanups.add(e),()=>this.cleanups.delete(e))}get fatalError(){return this.fatal}get registeredHostCount(){return this.cleanups.size}async poison(e){if(this.fatal??=e,this.poisonRunning)return this.fatal;this.poisonRunning=!0,this.pendingFatalCleanups.push(...this.cleanups);try{let e;for(;(e=this.pendingFatalCleanups.shift())!==void 0;)await e().catch(()=>void 0)}finally{this.poisonRunning=!1}return this.fatal}},we=class{options;coordinator;coordinatorOwner=Symbol(`pull-session-host`);unregisterCleanup;sequence=0;unacked;leases=new Map;activeDriverLeases=new Set;nextWireLeaseId;cancelRequested=!1;cancelComplete=!1;closeRequested=!1;closeComplete=!1;driverCancelComplete=!1;driverCloseComplete=!1;completed=!1;constructor(e){Ce(e.sessionId),C(e.operationId,`operation id`),C(e.generation,`generation`),C(e.maxByteCredit,`max byte credit`),e.wireLeaseIdStart!==void 0&&C(e.wireLeaseIdStart,`wire lease id start`),this.options=e,this.coordinator=e.coordinator,this.nextWireLeaseId=e.wireLeaseIdStart??1,this.unregisterCleanup=this.coordinator.registerCleanup(()=>this.forceFatalCleanup())}dispatch(e,t){return this.coordinator.enqueue(async()=>{let n=await this.execute(e);try{t(n.response,n.transfer)}catch(e){throw await this.rollbackFailedPost(n),e}})}async rollbackFailedPost(e){let t=e.response;if(t.kind===`chunk`){let n=t.leaseId===void 0?void 0:this.leases.get(t.leaseId);try{await this.options.driver.disposeInvalidChunk?.({payload:t.payload,byteLength:t.byteLength,done:t.done,leaseId:n?.driverLeaseId,retainedBytes:n?.retainedBytes,transfer:e.transfer})}catch{}}this.unacked=void 0,this.coordinator.release(this.coordinatorOwner);for(let[e,t]of[...this.leases])try{await this.options.driver.releaseLease?.(t.driverLeaseId)}catch{}finally{this.leases.delete(e),this.activeDriverLeases.delete(t.driverLeaseId),this.coordinator.releaseLease(this.coordinatorOwner,e)}if(this.cancelRequested=!0,!this.driverCancelComplete)try{await this.options.driver.cancel?.(),this.driverCancelComplete=!0}catch{}this.unregisterCleanup()}async execute(e){try{if(this.isStaleLifecycle(e)){let t=e.kind===`cancel`?`cancel`:`close`;return this.sameOperationIdentity(e)?{response:this.accepted(e,t,!0)}:{response:this.errorResponse(e,{message:`stale lifecycle targets another session or operation`,errorName:`PullSessionProtocolError`,code:`ooxml-stale-lifecycle`})}}this.validateCommandIdentity(e);let t=this.coordinator.fatalError;if(t)return e.kind===`pull`?{response:this.errorResponse(e,t)}:(e.kind===`cancel`?await this.cancel():e.kind===`close`?await this.close():e.kind===`release`&&await this.release(e.leaseId),{response:this.accepted(e,e.kind)});switch(e.kind){case`pull`:return await this.pull(e);case`ack`:return await this.ack(e.sequence),{response:this.accepted(e,`ack`)};case`release`:return await this.release(e.leaseId),{response:this.accepted(e,`release`)};case`cancel`:return await this.cancel(),{response:this.accepted(e,`cancel`)};case`close`:return await this.close(),{response:this.accepted(e,`close`)}}}catch(t){let n=b(t);return n.code===`ooxml-resource-limit`&&(n=await this.coordinator.poison(n)),{response:this.errorResponse(e,n)}}}async pull(e){if(this.closeRequested||this.cancelRequested||this.completed)throw Error(`pull session is closed`);if(this.unacked)throw Error(`previous chunk is not acknowledged`);if(!Number.isSafeInteger(e.sequence)||e.sequence<0||e.sequence!==this.sequence)throw Error(`pull command sequence mismatch`);if(this.validateHostCredit(e.byteCredit),!this.coordinator.acquire(this.coordinatorOwner))throw Error(`another operation has an unacknowledged package chunk`);let t;try{t=await this.options.driver.pull(e.byteCredit)}catch(e){throw this.coordinator.release(this.coordinatorOwner),e}let n=!1,r=!1,i,a;try{let o=this.options.driver.measureChunk(t),s=this.arrayBufferTransferBytes(t.transfer);if(o<s)throw RangeError(`measured chunk bytes are below ArrayBuffer transfer bytes`);if(a=Math.max(o,s),t.leaseId!==void 0){if(C(t.leaseId,`lease id`),t.retainedBytes===void 0)throw Error(`retained lease bytes are required`);if(this.activeDriverLeases.has(t.leaseId))throw r=!0,Error(`driver returned an active duplicate lease id`);i=this.allocateWireLeaseId(),this.coordinator.retainLease(this.coordinatorOwner,i,t.retainedBytes),this.leases.set(i,{driverLeaseId:t.leaseId,retainedBytes:t.retainedBytes}),this.activeDriverLeases.add(t.leaseId),n=!0}else if(t.retainedBytes!==void 0)throw Error(`retained lease bytes require a lease id`);if(!Number.isSafeInteger(a)||a<0)throw RangeError(`host chunk byte length must be a non-negative safe integer`);if(a>e.byteCredit)throw RangeError(`host chunk exceeds byte credit`)}catch(e){let a;try{await this.options.driver.disposeInvalidChunk?.(t)}catch(e){a=e}if(n&&i!==void 0)try{await this.release(i)}catch(e){a??=e}else if(t.leaseId!==void 0&&!r)try{await this.options.driver.releaseLease?.(t.leaseId)}catch(e){a??=e}if(r)try{await this.cancel()}catch(e){a??=e}throw this.coordinator.release(this.coordinatorOwner),a||e}return this.unacked={sequence:this.sequence,done:t.done},{response:{kind:`chunk`,protocol:S,...this.identity(),requestId:e.requestId,sequence:this.sequence,byteLength:a,done:t.done,payload:t.payload,leaseId:i,usage:this.resourceUsage()},transfer:t.transfer}}async ack(e){if(!Number.isSafeInteger(e)||e<0)throw RangeError(`invalid ack sequence`);if(e<this.sequence)return;if(!this.unacked||e!==this.sequence)throw Error(`ack sequence mismatch`);let t=this.unacked.done;await this.options.driver.acknowledge?.(e),this.unacked=void 0,this.coordinator.release(this.coordinatorOwner),this.sequence++,t&&(this.completed=!0,this.maybeUnregisterCompleted())}async release(e){C(e,`wire lease id`);let t=this.leases.get(e);t&&(await this.options.driver.releaseLease?.(t.driverLeaseId),this.leases.delete(e),this.activeDriverLeases.delete(t.driverLeaseId),this.coordinator.releaseLease(this.coordinatorOwner,e),this.maybeUnregisterCompleted())}async cancel(){if(this.cancelComplete)return;this.cancelRequested=!0,this.unacked=void 0,this.coordinator.release(this.coordinatorOwner);let e;try{await this.releaseAllLeases()}catch(t){e=t}if(!this.driverCancelComplete)try{await this.options.driver.cancel?.(),this.driverCancelComplete=!0}catch(t){e??=t}if(e)throw e;this.cancelComplete=!0,this.unregisterCleanup()}async close(){if(this.closeComplete)return;this.closeRequested=!0,this.unacked=void 0,this.coordinator.release(this.coordinatorOwner);let e;try{await this.releaseAllLeases()}catch(t){e=t}if(!this.driverCloseComplete)try{await this.options.driver.close?.(),this.driverCloseComplete=!0}catch(t){e??=t}if(e)throw e;this.closeComplete=!0,this.unregisterCleanup()}async releaseAllLeases(){let e;for(let t of[...this.leases.keys()])try{await this.release(t)}catch(t){e??=t}if(e)throw e}validateCommandIdentity(e){if(e.protocol!==`ooxml-pull-v1`||e.sessionId!==this.options.sessionId||e.operationId!==this.options.operationId||e.generation!==this.options.generation||!Number.isSafeInteger(e.requestId)||e.requestId<=0)throw Error(`stale or mismatched pull session command`)}validateHostCredit(e){if(C(e,`byte credit`),e>this.options.maxByteCredit)throw RangeError(`byte credit exceeds host maximum`)}accepted(e,t,n=!1){return{kind:`accepted`,protocol:S,...n?{sessionId:e.sessionId,operationId:e.operationId,generation:e.generation}:this.identity(),requestId:e.requestId,command:t,usage:this.resourceUsage()}}identity(){return{sessionId:this.options.sessionId,operationId:this.options.operationId,generation:this.options.generation}}isStaleLifecycle(e){return(e.kind===`cancel`||e.kind===`close`)&&e.protocol===`ooxml-pull-v1`&&Number.isSafeInteger(e.requestId)&&e.requestId>0&&Number.isSafeInteger(e.generation)&&e.generation>0&&e.generation<this.options.generation}sameOperationIdentity(e){return e.sessionId===this.options.sessionId&&e.operationId===this.options.operationId}errorResponse(e,t){return{kind:`error`,protocol:S,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:t,usage:this.errorResourceUsage()}}async forceFatalCleanup(){this.cancelRequested=!0,this.unacked=void 0,this.coordinator.release(this.coordinatorOwner);let e;for(let t of[...this.leases.keys()])try{await this.release(t)}catch(t){e??=t}if(!this.driverCancelComplete)try{await this.options.driver.cancel?.(),this.driverCancelComplete=!0}catch(t){e??=t}if(e)throw e;this.unregisterCleanup()}allocateWireLeaseId(){if(!Number.isSafeInteger(this.nextWireLeaseId)||this.nextWireLeaseId<=0)throw RangeError(`wire lease id space exhausted`);return this.nextWireLeaseId++}arrayBufferTransferBytes(e){let t=0;for(let n of e??[])if(n instanceof ArrayBuffer&&(t+=n.byteLength,!Number.isSafeInteger(t)))throw RangeError(`ArrayBuffer transfer bytes overflow`);return t}maybeUnregisterCompleted(){this.completed&&this.leases.size===0&&this.unregisterCleanup()}resourceUsage(){return this.options.driver.resourceUsage?.()}errorResourceUsage(){try{return this.resourceUsage()}catch{return}}};function T(e,t){if(!Number.isSafeInteger(e)||e<0)throw Error(`${t} must be a non-negative safe integer`)}function E(e,t,n){return T(e,`resource measurement`),T(t,`resource measurement`),T(n,`resource measurement limit`),e>n||t>n||t>n-e?n===2**53-1?n:n+1:e+t}function Te(e,t=2**53-1){T(t,`resource measurement limit`);let n=0;for(let r=0;r<e.length;r+=1){let i=e.charCodeAt(r),a;if(i<=127)a=1;else if(i<=2047)a=2;else if(i>=55296&&i<=56319&&r+1<e.length){let t=e.charCodeAt(r+1);t>=56320&&t<=57343?(a=4,r+=1):a=3}else a=3;if(n=E(n,a,t),n>t)return n}return n}function D(e,t=2**53-1){T(t,`resource measurement limit`);let n=E(0,2,t);if(n>t)return n;for(let r=0;r<e.length;r+=1){let i=e.charCodeAt(r),a;if(i===34||i===92||i===8||i===9||i===10||i===12||i===13)a=2;else if(i<=31)a=6;else if(i<=127)a=1;else if(i<=2047)a=2;else if(i>=55296&&i<=56319&&r+1<e.length){let t=e.charCodeAt(r+1);t>=56320&&t<=57343?(a=4,r+=1):a=6}else a=i>=55296&&i<=57343?6:3;if(n=E(n,a,t),n>t)return n}return n}function O(e,t){return E(0,e,t)}function k(e,t=2**53-1,n=!1){if(T(t,`resource measurement limit`),e===null)return{jsonBytes:O(4,t),stringValueUtf8Bytes:0};if(typeof e==`string`)return{jsonBytes:D(e,t),stringValueUtf8Bytes:Te(e,t)};if(typeof e==`boolean`)return{jsonBytes:O(e?4:5,t),stringValueUtf8Bytes:0};if(typeof e==`number`)return{jsonBytes:O((Number.isFinite(e)?String(Object.is(e,-0)?0:e):`null`).length,t),stringValueUtf8Bytes:0};if(typeof e==`bigint`)throw TypeError(`BigInt values cannot be serialized to JSON`);if(Array.isArray(e)){let n=O(2,t),r=0;for(let i=0;i<e.length;i+=1){i!==0&&(n=E(n,1,t));let a=k(e[i],t,!0);n=E(n,a.jsonBytes,t),r=E(r,a.stringValueUtf8Bytes,t)}return{jsonBytes:n,stringValueUtf8Bytes:r}}if(typeof e==`object`){let n=O(2,t),r=0,i=0;for(let[a,o]of Object.entries(e)){if(o===void 0||typeof o==`function`||typeof o==`symbol`)continue;i++!==0&&(n=E(n,1,t)),n=E(n,D(a,t),t),n=E(n,1,t);let e=k(o,t);n=E(n,e.jsonBytes,t),r=E(r,e.stringValueUtf8Bytes,t)}return{jsonBytes:n,stringValueUtf8Bytes:r}}return{jsonBytes:n?O(4,t):0,stringValueUtf8Bytes:0}}({...i,...s});function*A(e){for(let t of e?.paragraphs??[])for(let e of t.runs)e.type===`text`&&(yield e.text)}function*Ee(e){for(let t of e.elements)if(t.type===`shape`)yield*A(t.textBody);else if(t.type===`table`)for(let e of t.rows)for(let t of e.cells)yield*A(t.textBody);else if(t.type===`chart`){t.chart.title&&(yield t.chart.title);for(let e of t.chart.categories)yield e;for(let e of t.chart.series)e.name&&(yield e.name)}}var De=class e{scripts;constructor(e,t,n){this.majorFont=e,this.minorFont=t;let r=a(e)??a(t)??null;this.scripts=n??new ee(r)}addSlide(e){this.scripts.addText(Ee(e))}names(){return[this.majorFont,this.minorFont,...this.scripts.names()]}withSlide(t){let n=new e(this.majorFont,this.minorFont,this.scripts.clone());return n.addSlide(t),n}};const j=Object.freeze({archiveEntryCount:0,declaredInflatedBytes:0,distinctInflatedBytes:0,operationInflatedBytes:0}),M=67108864;function N(e,t){if(e!==null&&typeof e!=`string`)throw Error(`invalid PPTX presentation bootstrap ${t}`)}function Oe(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`invalid PPTX presentation bootstrap slide at ${t}`);let n=e;if(n.index!==t)throw Error(`invalid PPTX presentation bootstrap slide index ${n.index}`);if(n.partName!==void 0&&typeof n.partName!=`string`)throw Error(`invalid PPTX presentation bootstrap slide partName at ${t}`);return Object.freeze({index:n.index,...n.partName===void 0?{}:{partName:n.partName}})}function ke(e){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`invalid PPTX presentation bootstrap payload`);let t=e;if(!Number.isSafeInteger(t.slideCount)||(t.slideCount??-1)<0||!Number.isSafeInteger(t.slideWidth)||(t.slideWidth??0)<=0||!Number.isSafeInteger(t.slideHeight)||(t.slideHeight??0)<=0||!Array.isArray(t.slides)||t.slides.length!==t.slideCount)throw Error(`invalid PPTX presentation bootstrap dimensions or slide count`);return N(t.defaultTextColor,`defaultTextColor`),N(t.majorFont,`majorFont`),N(t.minorFont,`minorFont`),N(t.hlinkColor,`hlinkColor`),N(t.folHlinkColor,`folHlinkColor`),Object.freeze({slideCount:t.slideCount,slideWidth:t.slideWidth,slideHeight:t.slideHeight,defaultTextColor:t.defaultTextColor,majorFont:t.majorFont,minorFont:t.minorFont,hlinkColor:t.hlinkColor,folHlinkColor:t.folHlinkColor,slides:Object.freeze(t.slides.map(Oe))})}function Ae(e){return Object.freeze({type:`media`,x:e.x,y:e.y,width:e.width,height:e.height,rotation:e.rotation,flipH:e.flipH,flipV:e.flipV,mediaKind:e.mediaKind,posterPath:e.posterPath,posterMimeType:e.posterMimeType,mediaPath:e.mediaPath,mimeType:e.mimeType})}function je(e,t){if(e.index!==t.index||e.partName!==t.partName)throw Error(`PPTX pulled slide identity does not match bootstrap index ${t.index}`);return Object.freeze({index:t.index,...t.partName===void 0?{}:{partName:t.partName},notes:e.notes??null,hidden:e.hidden??!1,mediaElements:Object.freeze(e.elements.filter(e=>e.type===`media`).map(Ae))})}function Me(e,n,r){if(!(e<=n))throw new t(`PPTX presentation preflight exceeded its hard limit of ${n} projected bytes`,{stage:`parsing`,violation:{format:`pptx`,operation:`presentation-preflight`,resource:`presentation-preflight`,metric:`projected-bytes`,limit:n,observed:Math.min(e,n+1),configurable:!1,usage:r}})}var Ne=class{slideCountValue;slideWidthValue;slideHeightValue;defaultTextColorValue;majorFontValue;minorFontValue;hlinkColorValue;folHlinkColorValue;descriptors;slides=[];fonts;fontPreloadNames;fontProjectionBytes;projectionBytesValue;limit;pending=null;finished=null;constructor(e,t={}){let n=ke(e),r=t.hardLimitForTesting??M;if(!Number.isSafeInteger(r)||r<=0||r>M)throw Error(`invalid PPTX presentation preflight test limit`);this.limit=r,this.slideCountValue=n.slideCount,this.slideWidthValue=n.slideWidth,this.slideHeightValue=n.slideHeight,this.defaultTextColorValue=n.defaultTextColor,this.majorFontValue=n.majorFont,this.minorFontValue=n.minorFont,this.hlinkColorValue=n.hlinkColor,this.folHlinkColorValue=n.folHlinkColor,this.descriptors=[...n.slides],this.fonts=new De(this.majorFontValue,this.minorFontValue),this.fontPreloadNames=Object.freeze(this.fonts.names()),this.fontProjectionBytes=k(this.fontPreloadNames,this.limit).jsonBytes,this.projectionBytesValue=k({slideCount:this.slideCountValue,slideWidth:this.slideWidthValue,slideHeight:this.slideHeightValue,defaultTextColor:this.defaultTextColorValue,majorFont:this.majorFontValue,minorFont:this.minorFontValue,hlinkColor:this.hlinkColorValue,folHlinkColor:this.folHlinkColorValue,remainingSlides:this.descriptors,slides:[],fontPreloadNames:this.fontPreloadNames},this.limit).jsonBytes,Me(this.projectionBytesValue,this.limit,j)}get acceptedSlideCount(){return this.finished?.slideCount??this.slides.length}get projectedBytes(){return this.projectionBytesValue}get remainingDescriptorCount(){return this.descriptors.reduce((e,t)=>e+Number(t!==void 0),0)}addSlide(e,t=j){this.prepareSlide(e,t).commit()}prepareSlide(e,t=j){if(this.finished)throw Error(`PPTX presentation preflight is already finished`);if(this.pending)throw Error(`PPTX presentation preflight already has a prepared slide`);let n=this.slides.length,r=this.descriptors[n];if(!r)throw Error(`PPTX presentation preflight received an extra slide`);let i=je(e,r),a=this.fonts.withSlide(e),o=Object.freeze(a.names()),s=k(o,this.limit).jsonBytes,ee=k(i,this.limit).jsonBytes,c=this.projectionBytesValue-this.fontProjectionBytes-k(r,this.limit).jsonBytes+4;c=E(c,s,this.limit),c=E(c,ee,this.limit),this.slides.length!==0&&(c=E(c,1,this.limit));let te=k({slide:i,fontPreloadNames:o},this.limit).jsonBytes,l=E(this.projectionBytesValue,te,this.limit);Me(Math.max(l,c),this.limit,t);let u={state:`prepared`,fact:i,fonts:a,fontNames:o,fontBytes:s,committedBytes:c};return this.pending=u,{projectedBytes:l,commit:()=>{if(u.state!==`committed`){if(u.state===`rolled-back`)throw Error(`PPTX presentation preflight cannot commit a rolled-back slide`);if(this.pending!==u)throw Error(`PPTX presentation preflight prepared slide is stale`);this.descriptors[n]=void 0,this.slides.push(u.fact),this.fonts=u.fonts,this.fontPreloadNames=u.fontNames,this.fontProjectionBytes=u.fontBytes,this.projectionBytesValue=u.committedBytes,u.state=`committed`,this.pending=null}},rollback:()=>{if(u.state!==`rolled-back`){if(u.state===`committed`)throw Error(`PPTX presentation preflight cannot roll back a committed slide`);if(this.pending!==u)throw Error(`PPTX presentation preflight prepared slide is stale`);u.state=`rolled-back`,this.pending=null}}}}finish(){if(this.finished)return this.finished;if(this.pending)throw Error(`PPTX presentation preflight has an uncommitted slide`);if(this.slides.length!==this.slideCountValue)throw Error(`PPTX presentation preflight is incomplete: ${this.slides.length}/${this.slideCountValue} slides`);return this.finished=Object.freeze({slideCount:this.slideCountValue,slideWidth:this.slideWidthValue,slideHeight:this.slideHeightValue,defaultTextColor:this.defaultTextColorValue,majorFont:this.majorFontValue,minorFont:this.minorFontValue,hlinkColor:this.hlinkColorValue,folHlinkColor:this.folHlinkColorValue,slides:Object.freeze([...this.slides]),fontPreloadNames:this.fontPreloadNames}),this.descriptors=[],this.slides=[],this.projectionBytesValue=k(this.finished,this.limit).jsonBytes,this.finished}};function Pe(e){try{return se(e(e=>e.slide_cursor_resource_usage()))}catch(e){if(String(e).includes(`slide cursor usage is unavailable`))return;throw e}}function Fe(e,t,n,r,i){let a,o;try{if(i){if(!r)throw Error(`slide payload is missing before acknowledgement`);let t=i(n,r,Pe(e));typeof t==`function`?a=t:t&&({rollback:a,commit:o}=t)}e(e=>e.acknowledge_slide(t.operationId,t.generation)),o?.()}catch(e){try{a?.()}catch{}throw e}}var Ie=class{coordinatorGeneration=new w;sessions=new Map;pendingOpens=new Map;operationTail=Promise.resolve();resourceFailure;lifecycleState=`ready`;resetBarrier;resetIdentities=new Map;constructor(e,t,n=e=>e(this.requireArchive())){this.archive=e,this.acceptSlide=t,this.executeArchive=n}get coordinator(){return this.coordinatorGeneration}reserveOpen(e){if(this.assertReady(),Re(e),this.pendingOpens.has(e.sessionId)||this.sessions.has(e.sessionId))throw Error(`slide pull session id is already reserved`);this.pendingOpens.set(e.sessionId,{identity:e,canceled:!1})}abandonOpen(e){this.pendingOpens.delete(e)}get pendingOpenCount(){return this.pendingOpens.size}async open(e,t){if(this.assertReady(),this.resourceFailure)throw this.resourceFailure;if(!Number.isSafeInteger(e)||e<0)throw RangeError(`slide index must be a non-negative safe integer`);let n=this.pendingOpens.get(t.sessionId);if(!n||!P(n.identity,t))throw Error(`slide pull session open reservation is stale or missing`);let r,i=new Promise(e=>{r=e}),a=this.operationTail.then(()=>this.coordinator.enqueue(async()=>{if(n.canceled)throw Error(`slide pull session open was canceled`);let i,a=!1,o=new we({...t,maxByteCredit:x,coordinator:this.coordinator,driver:{pull:n=>{let r;try{r=this.executeArchive(r=>r.pull_slide(e,t.operationId,t.generation,n))}catch(e){throw ae(e,n,x)||(this.latchResourceFailure(e),e)}let o=xe(r);return this.acceptSlide&&(i=JSON.parse(new TextDecoder().decode(new Uint8Array(o)))),a=!0,{payload:o,byteLength:o.byteLength,done:!0,transfer:[o]}},measureChunk:({payload:e})=>e.byteLength,acknowledge:()=>{if(!a)throw Error(`slide unit is not awaiting acknowledgement`);try{Fe(this.executeArchive,t,e,i,this.acceptSlide)}catch(e){throw this.latchResourceFailure(e),e}a=!1,i=void 0,this.sessions.delete(t.sessionId),r()},cancel:async()=>{try{this.archive()&&await this.executeArchive(e=>e.cancel_slide())}finally{i=void 0,a=!1,this.sessions.delete(t.sessionId),r()}},close:async()=>{try{this.archive()&&await this.executeArchive(e=>e.cancel_slide())}finally{i=void 0,a=!1,this.sessions.delete(t.sessionId),r()}},resourceUsage:()=>{try{return this.readResourceUsage()}catch(e){throw this.latchResourceFailure(e),e}}}});this.sessions.set(t.sessionId,{host:o,identity:t}),this.pendingOpens.delete(t.sessionId)}));this.operationTail=a.then(()=>i,()=>void 0);try{await a}catch(e){throw this.pendingOpens.delete(t.sessionId),r(),e}}async postOpenedSafely(e,t,n){if(this.lifecycleState!==`ready`){try{n(this.lifecycleError())}catch{}return}try{t()}catch(t){await this.closeIdentity(e);try{n(t)}catch{}}}dispatch(e,t){if(this.lifecycleState!==`ready`)return t(this.responseDuringReset(e)),Promise.resolve();let n=this.sessions.get(e.sessionId);if(n)return n.host.dispatch(e,t);let r=this.pendingOpens.get(e.sessionId);if(r&&(e.kind===`cancel`||e.kind===`close`)){let n=P(r.identity,e);return n&&(r.canceled=!0),t(n?{protocol:S,kind:`accepted`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,command:e.kind}:this.staleLifecycleResponse(e)),Promise.resolve()}return e.kind===`cancel`||e.kind===`close`?(t({protocol:S,kind:`accepted`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,command:e.kind}),Promise.resolve()):(t({protocol:S,kind:`error`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:b(Error(`slide pull session is not open`))}),Promise.resolve())}async dispatchSafely(e,t){try{await this.dispatch(e,t)}catch(n){try{t({protocol:S,kind:`error`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:b(n)})}catch{}}}run(e){if(this.lifecycleState!==`ready`)return Promise.reject(this.lifecycleError());let t=this.operationTail.then(()=>this.coordinator.enqueue(async()=>{if(this.resourceFailure)throw this.resourceFailure;return e()})).catch(e=>{throw this.latchResourceFailure(e),e});return this.operationTail=t.then(()=>void 0,()=>void 0),t}reset(){if(this.resetBarrier)return this.resetBarrier;this.lifecycleState=`resetting`,this.captureResetIdentities();let e=this.performReset().then(()=>{this.resetIdentities.clear(),this.lifecycleState=`ready`},e=>{throw this.lifecycleState=`reset-failed`,e}).finally(()=>{this.resetBarrier===e&&(this.resetBarrier=void 0)});return this.resetBarrier=e,e}async performReset(){for(let e of this.pendingOpens.values())e.canceled=!0;let e=1;for(let{host:t,identity:n}of[...this.sessions.values()]){let r;if(await t.dispatch({protocol:S,kind:`close`,...n,requestId:e++},e=>{e.kind===`error`&&(r=be(e.error))}),r)throw r}this.sessions.clear(),await this.operationTail,this.pendingOpens.clear(),this.archive()&&await this.executeArchive(e=>e.close_presentation_session()),this.coordinatorGeneration=new w,this.resourceFailure=void 0}assertReady(){if(this.lifecycleState!==`ready`)throw this.lifecycleError()}lifecycleError(){let e=this.lifecycleState===`reset-failed`,t=Error(e?`slide pull worker reset failed; retry reset before new work`:`slide pull worker reset is in progress`);return t.name=`PullSessionLifecycleError`,Object.assign(t,{code:e?`ooxml-pull-reset-failed`:`ooxml-pull-resetting`})}captureResetIdentities(){for(let{identity:e}of this.sessions.values())this.resetIdentities.set(e.sessionId,e);for(let{identity:e}of this.pendingOpens.values())this.resetIdentities.set(e.sessionId,e)}responseDuringReset(e){if(e.kind===`cancel`||e.kind===`close`){let t=this.resetIdentities.get(e.sessionId);return t&&!P(t,e)?this.staleLifecycleResponse(e):{protocol:S,kind:`accepted`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,command:e.kind}}return{protocol:S,kind:`error`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:b(this.lifecycleError())}}requireArchive(){let e=this.archive();if(!e)throw Error(`Presentation not loaded`);return e}async closeIdentity(e){if(this.lifecycleState!==`ready`)return;let t=this.sessions.get(e.sessionId);if(t){await t.host.dispatch({protocol:S,kind:`close`,...e,requestId:1},()=>void 0);return}let n=this.pendingOpens.get(e.sessionId);n&&P(n.identity,e)&&(n.canceled=!0)}readResourceUsage(){return Pe(this.executeArchive)}latchResourceFailure(e){let n=e instanceof t?e:_e(e);n&&(this.resourceFailure??=n)}staleLifecycleResponse(e){return{protocol:S,kind:`error`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:{message:`stale lifecycle targets another slide operation`,errorName:`PullSessionProtocolError`,code:`ooxml-stale-lifecycle`}}}};function Le(e){return!!e&&typeof e==`object`&&e.protocol===`ooxml-pull-v1`}function Re(e){if(!Number.isSafeInteger(e.sessionId)||e.sessionId<=0)throw RangeError(`session id must be a positive safe integer`);if(!Number.isSafeInteger(e.operationId)||e.operationId<=0)throw RangeError(`operation id must be a positive safe integer`);if(!Number.isSafeInteger(e.generation)||e.generation<=0)throw RangeError(`generation must be a positive safe integer`)}function P(e,t){return e.sessionId===t.sessionId&&e.operationId===t.operationId&&e.generation===t.generation}var F=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,Be.unregister(this),e}free(){let e=this.__destroy_into_raw();J.__wbg_pptxarchive_free(e,0)}acknowledge_slide(e,t){let n=J.pptxarchive_acknowledge_slide(this.__wbg_ptr,e,t);if(n[1])throw U(n[0])}assert_healthy(){let e=J.pptxarchive_assert_healthy(this.__wbg_ptr);if(e[1])throw U(e[0])}cancel_slide(){J.pptxarchive_cancel_slide(this.__wbg_ptr)}close_presentation_session(){J.pptxarchive_close_presentation_session(this.__wbg_ptr)}extract_image(e){let t=H(e,J.__wbindgen_malloc,J.__wbindgen_realloc),n=q,r=J.pptxarchive_extract_image(this.__wbg_ptr,t,n);if(r[3])throw U(r[2]);var i=I(r[0],r[1]).slice();return J.__wbindgen_free(r[0],r[1]*1,1),i}extract_media(e){let t=H(e,J.__wbindgen_malloc,J.__wbindgen_realloc),n=q,r=J.pptxarchive_extract_media(this.__wbg_ptr,t,n);if(r[3])throw U(r[2]);var i=I(r[0],r[1]).slice();return J.__wbindgen_free(r[0],r[1]*1,1),i}constructor(e,t,n){let r=He(e,J.__wbindgen_malloc),i=q,a=J.pptxarchive_new(r,i,!V(t),V(t)?BigInt(0):t,!V(n),V(n)?BigInt(0):n);if(a[2])throw U(a[1]);return this.__wbg_ptr=a[0]>>>0,Be.register(this,this.__wbg_ptr,this),this}parse(){let e=J.pptxarchive_parse(this.__wbg_ptr);if(e[3])throw U(e[2]);var t=I(e[0],e[1]).slice();return J.__wbindgen_free(e[0],e[1]*1,1),t}presentation_bootstrap(){let e=J.pptxarchive_presentation_bootstrap(this.__wbg_ptr);if(e[3])throw U(e[2]);var t=I(e[0],e[1]).slice();return J.__wbindgen_free(e[0],e[1]*1,1),t}pull_slide(e,t,n,r){let i=J.pptxarchive_pull_slide(this.__wbg_ptr,e,t,n,r);if(i[3])throw U(i[2]);var a=I(i[0],i[1]).slice();return J.__wbindgen_free(i[0],i[1]*1,1),a}resource_usage(){let e=J.pptxarchive_resource_usage(this.__wbg_ptr);if(e[3])throw U(e[2]);var t=I(e[0],e[1]).slice();return J.__wbindgen_free(e[0],e[1]*1,1),t}slide_cursor_resource_usage(){let e=J.pptxarchive_slide_cursor_resource_usage(this.__wbg_ptr);if(e[3])throw U(e[2]);var t=I(e[0],e[1]).slice();return J.__wbindgen_free(e[0],e[1]*1,1),t}to_markdown(){let e,t;try{let i=J.pptxarchive_to_markdown(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,U(i[2]);return e=n,t=r,R(n,r)}finally{J.__wbindgen_free(e,t,1)}}};Symbol.dispose&&(F.prototype[Symbol.dispose]=F.prototype.free);function ze(){return{__proto__:null,\"./pptx_parser_bg.js\":{__proto__:null,__wbg___wbindgen_throw_6b64449b9b9ed33c:function(e,t){throw Error(R(e,t))},__wbg_error_a6fa202b58aa1cd3:function(e,t){let n,r;try{n=e,r=t,console.error(R(e,t))}finally{J.__wbindgen_free(n,r,1)}},__wbg_new_227d7c05414eb861:function(){return Error()},__wbg_stack_3b0d974bbf31e44f:function(e,t){let n=t.stack,r=H(n,J.__wbindgen_malloc,J.__wbindgen_realloc),i=q;Ve().setInt32(e+4,i,!0),Ve().setInt32(e+0,r,!0)},__wbindgen_cast_0000000000000001:function(e,t){return R(e,t)},__wbindgen_init_externref_table:function(){let e=J.__wbindgen_externrefs,t=e.grow(4);e.set(0,void 0),e.set(t+0,void 0),e.set(t+1,null),e.set(t+2,!0),e.set(t+3,!1)}}}}const Be=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>J.__wbg_pptxarchive_free(e>>>0,1));function I(e,t){return e>>>=0,B().subarray(e/1,e/1+t)}let L=null;function Ve(){return(L===null||L.buffer.detached===!0||L.buffer.detached===void 0&&L.buffer!==J.memory.buffer)&&(L=new DataView(J.memory.buffer)),L}function R(e,t){return e>>>=0,Ue(e,t)}let z=null;function B(){return(z===null||z.byteLength===0)&&(z=new Uint8Array(J.memory.buffer)),z}function V(e){return e==null}function He(e,t){let n=t(e.length*1,1)>>>0;return B().set(e,n/1),q=e.length,n}function H(e,t,n){if(n===void 0){let n=K.encode(e),r=t(n.length,1)>>>0;return B().subarray(r,r+n.length).set(n),q=n.length,r}let r=e.length,i=t(r,1)>>>0,a=B(),o=0;for(;o<r;o++){let t=e.charCodeAt(o);if(t>127)break;a[i+o]=t}if(o!==r){o!==0&&(e=e.slice(o)),i=n(i,r,r=o+e.length*3,1)>>>0;let t=B().subarray(i+o,i+r),a=K.encodeInto(e,t);o+=a.written,i=n(i,r,o,1)>>>0}return q=o,i}function U(e){let t=J.__wbindgen_externrefs.get(e);return J.__externref_table_dealloc(e),t}let W=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0});W.decode();let G=0;function Ue(e,t){return G+=t,G>=2146435072&&(W=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0}),W.decode(),G=t),W.decode(B().subarray(e,e+t))}const K=new TextEncoder;`encodeInto`in K||(K.encodeInto=function(e,t){let n=K.encode(e);return t.set(n),{read:e.length,written:n.length}});let q=0,J;function We(e,t){return J=e.exports,L=null,z=null,J.__wbindgen_start(),J}async function Ge(e,t){if(typeof Response==`function`&&e instanceof Response){if(typeof WebAssembly.instantiateStreaming==`function`)try{return await WebAssembly.instantiateStreaming(e,t)}catch(t){if(e.ok&&n(e.type)&&e.headers.get(`Content-Type`)!==`application/wasm`)console.warn(\"`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n\",t);else throw t}let r=await e.arrayBuffer();return await WebAssembly.instantiate(r,t)}else{let n=await WebAssembly.instantiate(e,t);return n instanceof WebAssembly.Instance?{instance:n,module:e}:n}function n(e){switch(e){case`basic`:case`cors`:case`default`:return!0}return!1}}async function Ke(e){if(J!==void 0)return J;e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn(`using deprecated parameters for the initialization function; pass a single object instead`));let t=ze();(typeof e==`string`||typeof Request==`function`&&e instanceof Request||typeof URL==`function`&&e instanceof URL)&&(e=fetch(e));let{instance:n,module:r}=await Ge(await e,t);return We(n,r)}async function qe(e){return J=void 0,L=null,z=null,Ke(e)}const Y=new re(Ke,{freeArchive:e=>e.free(),reinit:qe});let X=null,Z=`empty`;function Je(){if(Z!==`empty`){let e=Error(`this PPTX worker already owns a presentation parse`);throw e.name=`PptxWorkerStateError`,Object.assign(e,{code:`ooxml-pptx-parse-already-started`})}Z=`opening`}const Q=new Ie(()=>Y.archive,(e,t,n)=>{if(X){if(e!==X.acceptedSlideCount)throw Error(`PPTX preflight expected slide ${X.acceptedSlideCount}, received ${e}`);return X.prepareSlide(t,n)}},e=>{let t=Y.archive;if(!t)throw Error(`Presentation not loaded`);return Y.run(()=>e(t))}),$=(e,t)=>self.postMessage(e,t);self.onmessage=async e=>{let t=e.data;if(Le(t)){await Q.dispatchSafely(t,$);return}if(t.kind===`init`){Y.setWasmInput(te(t.wasmUrl)??t.wasmUrl);return}let n=t.id,r=!1;try{if(t.kind===`openSlideSession`&&Q.reserveOpen(t),t.kind===`parse`&&(Je(),r=!0),t.kind===`openSlideSession`){await Y.ensureReady(),await Q.open(t.slideIndex,t),await Q.postOpenedSafely(t,()=>$({kind:`slideSessionOpened`,id:n,sessionId:t.sessionId,operationId:t.operationId,generation:t.generation}),e=>$({kind:`error`,id:n,...b(e)}));return}t.kind===`parse`&&await Q.reset(),await Q.run(async()=>{if(await Y.ensureReady(),t.kind!==`parse`&&Y.archive){let e=Y.archive;Y.run(()=>e.assert_healthy())}if(t.kind===`parse`){X=null;let[e,r]=Se(t.resourcePolicy),i=Y.run(()=>{let n=new F(new Uint8Array(t.buffer),e,r);return Y.setArchive(n),JSON.parse(new TextDecoder().decode(n.presentation_bootstrap()))});X=new Ne(i),$({kind:`presentationOpened`,id:n,bootstrap:i}),Z=`ready`;return}let e=Y.archive;if(!e)throw Error(`No pptx loaded`);if(t.kind===`finishPresentationPreflight`){if(!X)throw Error(`PPTX presentation preflight is not active`);let e=X.finish();X=null,$({kind:`presentationPreflightReady`,id:n,preflight:e});return}if(t.kind===`extractMedia`){let r=Y.run(()=>e.extract_media(t.path).buffer);$({kind:`mediaExtracted`,id:n,bytes:r},[r]);return}if(t.kind===`extractImage`){let r=Y.run(()=>e.extract_image(t.path).buffer);$({kind:`imageExtracted`,id:n,bytes:r},[r]);return}if(t.kind===`resourceUsage`){$({kind:`resourceUsage`,id:n,usage:se(Y.run(()=>e.resource_usage()))});return}t.kind===`toMarkdown`&&$({kind:`markdownRendered`,id:n,markdown:Y.run(()=>e.to_markdown())})})}catch(e){r&&(Z=`failed`),t.kind===`openSlideSession`&&Q.abandonOpen(t.sessionId);try{$({kind:`error`,id:n,...b(e)})}catch{}}};", Ie = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", Fe], { type: "text/javascript;charset=utf-8" });
533
+ function Le(e) {
534
+ let t;
535
+ try {
536
+ if (t = Ie && (self.URL || self.webkitURL).createObjectURL(Ie), !t) throw "";
537
+ let n = new Worker(t, {
538
+ type: "module",
539
+ name: e?.name
540
+ });
541
+ return n.addEventListener("error", () => {
542
+ (self.URL || self.webkitURL).revokeObjectURL(t);
543
+ }), n;
544
+ } catch {
545
+ return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(Fe), {
546
+ type: "module",
547
+ name: e?.name
548
+ });
549
+ }
550
+ }
551
+ //#endregion
552
+ //#region packages/pptx/src/wasm/pptx_parser_bg.wasm?url
553
+ var Re = new URL("pptx_parser_bg.wasm", import.meta.url).href, $ = class e {
554
+ _metrics = null;
555
+ _worker;
556
+ _bridge;
557
+ _mode = "main";
558
+ _preflight = null;
559
+ _slides = null;
560
+ _slidePullClient = null;
561
+ _resourceFailure = null;
562
+ _slidePartIndex = null;
563
+ _rawParts = new u({
564
+ maxEntries: 64,
565
+ maxBytes: a
566
+ });
567
+ _googleFontFaces = [];
568
+ _fetchImage = (e, t) => this.getImage(e, t);
569
+ _fetchMedia = (e) => this.getMedia(e);
570
+ _math;
571
+ constructor(e, t, r) {
572
+ this._worker = e, this._mode = t, this._bridge = new h(this._worker, {
573
+ correlate: (e) => "protocol" in e && e.protocol === "ooxml-pull-v1" ? e.requestId : "id" in e ? e.id : void 0,
574
+ toError: (e) => !("protocol" in e) && e.kind === "error" ? n(e) : void 0
575
+ });
576
+ let i = new URL(r ?? Re, location.href).href;
577
+ this._bridge.post({
578
+ kind: "init",
579
+ wasmUrl: i
580
+ });
581
+ }
582
+ _assertResourceHealthy() {
583
+ if (this._resourceFailure) throw this._resourceFailure;
584
+ }
585
+ _rethrowWithResourceFailure(e) {
586
+ let n = e instanceof i ? e : t(e);
587
+ throw n ? (this._resourceFailure ??= n, this._resourceFailure) : e;
588
+ }
589
+ static async load(t, n = {}) {
590
+ let r = d(n), i = n.mode ?? "main", a = new o({
591
+ enabled: !0,
592
+ format: "pptx",
593
+ mode: i,
594
+ policy: r.policy,
595
+ onMetrics: r.onResourceMetrics,
596
+ emitToConsole: r.debug
597
+ });
598
+ try {
599
+ if (i === "worker" && (typeof Worker > "u" || typeof OffscreenCanvas > "u")) throw Error("mode: 'worker' requires Worker and OffscreenCanvas support");
600
+ let o;
601
+ if (typeof t == "string") {
602
+ let e = await fetch(t);
603
+ if (!e.ok) throw Error(`Failed to fetch: ${e.status} ${e.statusText}`);
604
+ o = await e.arrayBuffer();
605
+ } else o = t;
606
+ o = g(await y(o, n.password)), a.setSourceBytes(o.byteLength), a.checkpoint("container ready");
607
+ let s = i === "worker" ? (await import("./render-worker-host-s3J-mWBP.js")).createRenderWorker() : new Le(), c;
608
+ try {
609
+ return c = new e(s, i, n.wasmUrl), c._metrics = a, n.math && i === "worker" && console.warn("[ooxml] the math engine is unavailable in mode: 'worker'; equations will be skipped. Use mode: 'main' for documents with equations."), c._math = i === "worker" ? void 0 : n.math, await c._parse(o, r.policy, i === "worker" ? !!n.useGoogleFonts : !1, n.workerTimeoutMs, (e) => a.observeUsage(e)), a.checkpoint("presentation preflight ready"), i === "main" && n.useGoogleFonts && c._preflight && (c._googleFontFaces = await ne(c._preflight.fontPreloadNames, me)), a.succeed({ slides: c.slideCount }), c;
610
+ } catch (e) {
611
+ let t = c;
612
+ throw m(s, t ? () => t.destroy() : void 0), e;
613
+ }
614
+ } catch (e) {
615
+ throw a.fail(e), e;
616
+ }
617
+ }
618
+ async _parse(e, t, n = !1, r, i) {
619
+ let a = await this._bridge.request((r) => this._mode === "worker" ? {
620
+ kind: "parse",
621
+ id: r,
622
+ buffer: e,
623
+ resourcePolicy: t,
624
+ useGoogleFonts: n
625
+ } : {
626
+ kind: "parse",
627
+ id: r,
628
+ buffer: e,
629
+ resourcePolicy: t
630
+ }, [e], { timeoutMs: r });
631
+ if (this._mode === "worker") {
632
+ let e = a;
633
+ e.usage && i?.(e.usage), this._preflight = N(a.preflight);
634
+ return;
635
+ }
636
+ let o = fe(a.bootstrap);
637
+ this._slidePullClient = new ge({
638
+ slideCount: o.slideCount,
639
+ transport: this._bridge.transport(pe),
640
+ open: async (e, t, n) => {
641
+ await this._bridge.request((n) => ({
642
+ kind: "openSlideSession",
643
+ id: n,
644
+ slideIndex: e,
645
+ ...t
646
+ }), void 0, { timeoutMs: n });
647
+ },
648
+ onUsage: i
649
+ });
650
+ for (let e = 0; e < o.slideCount; e += 1) await this._slidePullClient.load(e, !1, r);
651
+ this._preflight = N((await this._bridge.request((e) => ({
652
+ kind: "finishPresentationPreflight",
653
+ id: e
654
+ }), void 0, { timeoutMs: r })).preflight), this._slides = new Pe({
655
+ slideCount: this._preflight.slideCount,
656
+ maxCachedSlides: 8,
657
+ maxCachedStructuralBytes: s,
658
+ loadSlide: async (e) => {
659
+ let t = await this._slidePullClient?.load(e, !0);
660
+ if (!t) throw Error("PPTX slide pull client is unavailable");
661
+ return t;
662
+ }
663
+ });
664
+ }
665
+ get slideCount() {
666
+ return this._preflight?.slideCount ?? 0;
667
+ }
668
+ get slideWidth() {
669
+ return this._preflight?.slideWidth ?? 0;
670
+ }
671
+ get slideHeight() {
672
+ return this._preflight?.slideHeight ?? 0;
673
+ }
674
+ get mode() {
675
+ return this._mode;
676
+ }
677
+ getNotes(e) {
678
+ return Number.isInteger(e) ? this._preflight?.slides[e]?.notes ?? null : null;
679
+ }
680
+ isHidden(e) {
681
+ return Number.isInteger(e) ? this._preflight?.slides[e]?.hidden ?? !1 : !1;
682
+ }
683
+ _partNames() {
684
+ return (this._preflight?.slides ?? []).map((e) => e.partName);
685
+ }
686
+ _partIndex() {
687
+ return this._slidePartIndex ||= je(this._partNames()), this._slidePartIndex;
688
+ }
689
+ getSlideIndexByPartName(e) {
690
+ return this._partIndex().get(e);
691
+ }
692
+ resolveInternalTarget(e, t = 0) {
693
+ return Ne(e, this._partIndex(), t);
694
+ }
695
+ async renderSlide(e, t, n = {}) {
696
+ this._assertResourceHealthy();
697
+ try {
698
+ if (this._mode === "worker") throw Error("renderSlide(canvas) is unavailable in mode: 'worker'; use renderSlideToBitmap() and paint it via an ImageBitmapRenderingContext");
699
+ let r = this._preflight, i = this._slides;
700
+ if (!r || !i) throw Error("Presentation not loaded");
701
+ let a = n.dpr ?? T(), o = n.width ?? ((ce(e) ? e.offsetWidth : 0) || 960);
702
+ await i.withSlide(t, (t) => (this._assertResourceHealthy(), O(e, t, r.slideWidth, r.slideHeight, {
703
+ width: o,
704
+ dpr: a,
705
+ defaultTextColor: r.defaultTextColor,
706
+ majorFont: r.majorFont,
707
+ minorFont: r.minorFont,
708
+ hlinkColor: r.hlinkColor,
709
+ fetchMedia: this._fetchMedia,
710
+ fetchImage: this._fetchImage,
711
+ skipMediaControls: n.skipMediaControls,
712
+ dim: n.dim,
713
+ math: this._math
714
+ }, n.onTextRun)));
715
+ } catch (e) {
716
+ this._rethrowWithResourceFailure(e);
717
+ }
718
+ }
719
+ async renderSlideToBitmap(e, t = {}) {
720
+ this._assertResourceHealthy();
721
+ try {
722
+ let n = t.width ?? 960, r = t.dpr ?? T();
723
+ if (this._mode === "worker") {
724
+ if (!Number.isInteger(e) || e < 0 || e >= this.slideCount) throw Error(`Slide index ${e} out of range (count: ${this.slideCount})`);
725
+ let i = await this._bridge.request((i) => ({
726
+ kind: "renderSlide",
727
+ id: i,
728
+ slideIndex: e,
729
+ width: n,
730
+ dpr: r,
731
+ skipMediaControls: t.skipMediaControls,
732
+ dim: t.dim
733
+ }));
734
+ if (t.onTextRun) for (let e of i.runs) t.onTextRun(e);
735
+ return i.bitmap;
736
+ }
737
+ let i = new OffscreenCanvas(1, 1);
738
+ return await this.renderSlide(i, e, {
739
+ width: n,
740
+ dpr: r,
741
+ skipMediaControls: t.skipMediaControls,
742
+ dim: t.dim,
743
+ onTextRun: t.onTextRun
744
+ }), i.transferToImageBitmap();
745
+ } catch (e) {
746
+ this._rethrowWithResourceFailure(e);
747
+ }
748
+ }
749
+ async collectSlideRuns(e, t = 960) {
750
+ this._assertResourceHealthy();
751
+ try {
752
+ if (this._mode === "worker") {
753
+ if (!Number.isInteger(e) || e < 0 || e >= this.slideCount) throw Error(`Slide index ${e} out of range (count: ${this.slideCount})`);
754
+ return (await this._bridge.request((n) => ({
755
+ kind: "collectRuns",
756
+ id: n,
757
+ slideIndex: e,
758
+ width: t
759
+ }))).runs;
760
+ }
761
+ let n = [], r = new OffscreenCanvas(1, 1);
762
+ return await this.renderSlide(r, e, {
763
+ width: t,
764
+ onTextRun: (e) => n.push(e)
765
+ }), n;
766
+ } catch (e) {
767
+ this._rethrowWithResourceFailure(e);
768
+ }
769
+ }
770
+ async getMedia(e) {
771
+ this._assertResourceHealthy();
772
+ try {
773
+ let t = this._findMimeTypeForPath(e);
774
+ return await this._rawParts.get(e, t, async () => {
775
+ let n = (await this._bridge.request((t) => ({
776
+ kind: "extractMedia",
777
+ id: t,
778
+ path: e
779
+ }))).bytes;
780
+ return new Blob([n], { type: t });
781
+ });
782
+ } catch (e) {
783
+ this._rethrowWithResourceFailure(e);
784
+ }
785
+ }
786
+ _findMimeTypeForPath(e) {
787
+ return this._preflight ? he(this._preflight, e) : "";
788
+ }
789
+ async getImage(e, t) {
790
+ this._assertResourceHealthy();
791
+ try {
792
+ return await this._rawParts.get(e, t, async () => {
793
+ let n = (await this._bridge.request((t) => ({
794
+ kind: "extractImage",
795
+ id: t,
796
+ path: e
797
+ }))).bytes;
798
+ return new Blob([n], { type: t });
799
+ });
800
+ } catch (e) {
801
+ this._rethrowWithResourceFailure(e);
802
+ }
803
+ }
804
+ async getResourceMetrics() {
805
+ let e = this._metrics;
806
+ if (!e) throw Error("Presentation not loaded");
807
+ return c(e, async (e) => (await this._bridge.request((e) => ({
808
+ kind: "resourceUsage",
809
+ id: e
810
+ }), void 0, { timeoutMs: e })).usage);
811
+ }
812
+ async toMarkdown() {
813
+ this._assertResourceHealthy();
814
+ try {
815
+ return (await this._bridge.request((e) => ({
816
+ kind: "toMarkdown",
817
+ id: e
818
+ }))).markdown;
819
+ } catch (e) {
820
+ this._rethrowWithResourceFailure(e);
821
+ }
822
+ }
823
+ async presentSlide(e, t, n = {}) {
824
+ this._assertResourceHealthy();
825
+ try {
826
+ if (!this._preflight) throw Error("Presentation not loaded");
827
+ if (!Number.isInteger(t) || t < 0 || t >= this.slideCount) throw Error(`Slide index ${t} out of range (count: ${this.slideCount})`);
828
+ let r = n.dpr ?? T(), i = n.width ?? (e.offsetWidth || 960), a = this._mode === "worker" ? async () => {
829
+ let a = await this.renderSlideToBitmap(t, {
830
+ width: i,
831
+ dpr: r,
832
+ skipMediaControls: !0,
833
+ dim: n.dim,
834
+ onTextRun: n.onTextRun
835
+ });
836
+ e.width = a.width, e.height = a.height, e.style.width = `${Math.round(a.width / r)}px`, e.style.display || (e.style.display = "block");
837
+ let o = e.getContext("2d");
838
+ if (!o) throw Error("2D context not available");
839
+ o.drawImage(a, 0, 0), a.close();
840
+ } : () => this.renderSlide(e, t, {
841
+ width: i,
842
+ dpr: r,
843
+ skipMediaControls: !0,
844
+ dim: n.dim,
845
+ onTextRun: n.onTextRun
846
+ });
847
+ return await we(e, this._preflight.slides[t]?.mediaElements ?? [], {
848
+ width: i,
849
+ dpr: r,
850
+ slideWidthEmu: this.slideWidth,
851
+ fetchMedia: this._fetchMedia,
852
+ fetchImage: this._fetchImage,
853
+ drawBase: a,
854
+ onError: n.onError
855
+ });
856
+ } catch (e) {
857
+ this._rethrowWithResourceFailure(e);
858
+ }
859
+ }
860
+ destroy() {
861
+ this._slidePullClient?.cancelAll(), this._bridge.terminate(), this._slides?.clear(), this._slides = null, this._slidePullClient = null, this._preflight = null, this._resourceFailure = null, this._slidePartIndex = null, this._rawParts.clear(), this._googleFontFaces.length > 0 && (re(this._googleFontFaces), this._googleFontFaces = []), ae(this._fetchImage), se(this._fetchImage);
862
+ }
863
+ }, ze = {
864
+ color: "#ffffff",
865
+ opacity: .6
866
+ }, Be = class {
867
+ canvas;
868
+ wrapper;
869
+ _scale = null;
870
+ _originalParent;
871
+ _originalNextSibling;
872
+ _originalDisplay;
873
+ textLayer = null;
874
+ highlightLayer = null;
875
+ _find;
876
+ _measureCtx = null;
877
+ engine = null;
878
+ opts;
879
+ currentSlide = 0;
880
+ _hiddenMode;
881
+ handle = null;
882
+ _mode;
883
+ _bitmapCtx = null;
884
+ _destroyed = !1;
885
+ _loadGen = 0;
886
+ constructor(e, t = {}) {
887
+ this.opts = t, this.canvas = e, this._mode = t.mode ?? "main", this._hiddenMode = t.hiddenSlideMode ?? "show";
888
+ let n = e.parentElement;
889
+ this._originalParent = n, this._originalNextSibling = e.nextSibling, this._originalDisplay = e.style.display, this.wrapper = document.createElement("div"), this.wrapper.style.cssText = "position:relative;display:inline-block;vertical-align:top;", e.style.display || (e.style.display = "block"), n && n.insertBefore(this.wrapper, e), this.wrapper.appendChild(e), this._mode === "worker" && !t.enableMediaPlayback && (this._bitmapCtx = e.getContext("bitmaprenderer")), t.enableTextSelection && (this.textLayer = document.createElement("div"), this.textLayer.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;overflow:hidden;pointer-events:none;user-select:text;-webkit-user-select:text;", this.wrapper.appendChild(this.textLayer)), this.highlightLayer = document.createElement("div"), this.highlightLayer.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;overflow:hidden;pointer-events:none;", this.wrapper.appendChild(this.highlightLayer), this._find = new I(() => this.slideCount, (e) => this._collectSlideRuns(e));
890
+ }
891
+ async load(e) {
892
+ let t = ++this._loadGen, n = this.engine;
893
+ try {
894
+ let r = await $.load(e, {
895
+ useGoogleFonts: this.opts.useGoogleFonts,
896
+ maxZipEntryBytes: this.opts.maxZipEntryBytes,
897
+ resourceLimits: this.opts.resourceLimits,
898
+ debug: this.opts.debug,
899
+ onResourceMetrics: this.opts.onResourceMetrics,
900
+ workerTimeoutMs: this.opts.workerTimeoutMs,
901
+ wasmUrl: this.opts.wasmUrl,
902
+ math: this.opts.math,
903
+ mode: this._mode
904
+ });
905
+ if (t !== this._loadGen) {
906
+ r.destroy();
907
+ return;
908
+ }
909
+ this.handle?.destroy(), this.handle = null, this.engine = r, n?.destroy(), this.currentSlide = this._initialSlide(), this._find.invalidate(), await this.renderCurrentSlide();
910
+ } catch (e) {
911
+ if (t !== this._loadGen) return;
912
+ let n = e instanceof Error ? e : Error(String(e));
913
+ if (this.opts.onError) {
914
+ this.opts.onError(n);
915
+ return;
916
+ }
917
+ throw n;
918
+ }
919
+ }
920
+ async goToSlide(e) {
921
+ !this.engine || this.slideCount === 0 || (this.currentSlide = Math.max(0, Math.min(e, this.slideCount - 1)), await this.renderCurrentSlide());
922
+ }
923
+ async nextSlide() {
924
+ await this.goToSlide(this._step(1));
925
+ }
926
+ async prevSlide() {
927
+ await this.goToSlide(this._step(-1));
928
+ }
929
+ _step(e) {
930
+ return this._hiddenMode === "skip" && this.engine ? le(this.currentSlide, e, (e) => this.engine.isHidden(e), this.slideCount) : this.currentSlide + e;
931
+ }
932
+ _initialSlide() {
933
+ return this._hiddenMode === "skip" && this.engine ? k(0, (e) => this.engine.isHidden(e), this.slideCount) : 0;
934
+ }
935
+ _dim() {
936
+ return {
937
+ color: this.opts.hiddenSlideDim?.color ?? ze.color,
938
+ opacity: this.opts.hiddenSlideDim?.opacity ?? ze.opacity
939
+ };
940
+ }
941
+ async setHiddenSlideMode(e) {
942
+ this._hiddenMode = e, e === "skip" && this.engine && (this.currentSlide = k(this.currentSlide, (e) => this.engine.isHidden(e), this.slideCount)), await this.renderCurrentSlide();
943
+ }
944
+ get hiddenSlideMode() {
945
+ return this._hiddenMode;
946
+ }
947
+ get visibleSlideCount() {
948
+ if (!this.engine) return 0;
949
+ let e = this.engine;
950
+ return ue((t) => e.isHidden(t), this.slideCount);
951
+ }
952
+ get slideIndex() {
953
+ return this.currentSlide;
954
+ }
955
+ get slideCount() {
956
+ return this.engine?.slideCount ?? 0;
957
+ }
958
+ getNotes(e) {
959
+ return this.engine?.getNotes(e) ?? null;
960
+ }
961
+ get canvasElement() {
962
+ return this.canvas;
963
+ }
964
+ _naturalWidthPx() {
965
+ let e = this.engine?.slideWidth ?? 0;
966
+ return e > 0 ? e / E : 0;
967
+ }
968
+ _targetWidth() {
969
+ if (this._scale === null) return this.opts.width ?? (this.canvas.offsetWidth || 960);
970
+ let e = this._naturalWidthPx();
971
+ return e <= 0 ? this.opts.width ?? (this.canvas.offsetWidth || 960) : Math.round(e * this._scale);
972
+ }
973
+ getScale() {
974
+ if (this._scale !== null) return this._scale;
975
+ let e = this._naturalWidthPx();
976
+ return e <= 0 ? 1 : this._targetWidth() / e;
977
+ }
978
+ _zoomMin() {
979
+ return this.opts.zoomMin ?? .1;
980
+ }
981
+ _zoomMax() {
982
+ return this.opts.zoomMax ?? 4;
983
+ }
984
+ async setScale(e) {
985
+ let t = f(e, this._zoomMin(), this._zoomMax()), n = t !== this.getScale();
986
+ this._scale = t, await this.renderCurrentSlide(), n && this.opts.onScaleChange?.(t);
987
+ }
988
+ async zoomIn() {
989
+ await this.setScale(w(this.getScale()));
990
+ }
991
+ async zoomOut() {
992
+ await this.setScale(p(this.getScale()));
993
+ }
994
+ async fitWidth() {
995
+ await this._fit("width");
996
+ }
997
+ async fitPage() {
998
+ await this._fit("page");
999
+ }
1000
+ async _fit(e) {
1001
+ if (!this.engine) return;
1002
+ let t = this.wrapper.parentElement;
1003
+ if (!t) return;
1004
+ let n = x({
1005
+ contentWidth: this.engine.slideWidth / E,
1006
+ contentHeight: this.engine.slideHeight / E,
1007
+ containerWidth: t.clientWidth,
1008
+ containerHeight: t.clientHeight
1009
+ }, e);
1010
+ n <= 0 || await this.setScale(n);
1011
+ }
1012
+ async renderCurrentSlide() {
1013
+ if (!this.engine) return;
1014
+ let e = this._hiddenMode === "dim" && this.engine.isHidden(this.currentSlide) ? this._dim() : void 0, t = this._targetWidth(), n = this.opts.dpr ?? (window.devicePixelRatio || 1), r = t / this.engine.slideWidth, i = Math.round(this.engine.slideHeight * r);
1015
+ this.canvas.style.width = `${t}px`, this.canvas.style.height = `${i}px`, this.handle?.destroy(), this.handle = null;
1016
+ let a = this._mode === "worker", o = [], s = (e) => o.push(e);
1017
+ try {
1018
+ if (this.opts.enableMediaPlayback) this.handle = await this.engine.presentSlide(this.canvas, this.currentSlide, {
1019
+ width: t,
1020
+ dpr: n,
1021
+ dim: e,
1022
+ onTextRun: s,
1023
+ onError: (e) => this._reportRenderError(e)
1024
+ });
1025
+ else if (a) {
1026
+ let r = await this.engine.renderSlideToBitmap(this.currentSlide, {
1027
+ width: t,
1028
+ dpr: n,
1029
+ dim: e,
1030
+ onTextRun: s
1031
+ });
1032
+ this.canvas.width = r.width, this.canvas.height = r.height, this._bitmapCtx?.transferFromImageBitmap(r);
1033
+ } else await this.engine.renderSlide(this.canvas, this.currentSlide, {
1034
+ width: t,
1035
+ dpr: n,
1036
+ onTextRun: s,
1037
+ dim: e
1038
+ });
1039
+ this.opts.onSlideChange?.(this.currentSlide, this.slideCount);
1040
+ } catch (e) {
1041
+ this._reportRenderError(e);
1042
+ }
1043
+ this.textLayer && this._buildTextLayer(this.textLayer, o, t, i), this._find.setSlideRuns(this.currentSlide, o), this._buildHighlightLayer(o, t, i);
1044
+ }
1045
+ _buildHighlightLayer(e, t, n) {
1046
+ let r = this.highlightLayer;
1047
+ r && F(r, e, this._find.slideHighlights(this.currentSlide), t, n, (e) => this._measureForFont(e), this.opts.findHighlightColors);
1048
+ }
1049
+ _measureForFont(e) {
1050
+ this._measureCtx ||= document.createElement("canvas").getContext("2d");
1051
+ let t = this._measureCtx;
1052
+ return t ? (t.font = e, (e) => t.measureText(e).width) : (e) => e.length;
1053
+ }
1054
+ async _collectSlideRuns(e) {
1055
+ return this.engine ? this.engine.collectSlideRuns(e, this._targetWidth()) : [];
1056
+ }
1057
+ async findText(e, t = {}) {
1058
+ if (!this.engine) return [];
1059
+ let n = await this._find.find(e, t);
1060
+ return this._redrawHighlights(), n;
1061
+ }
1062
+ async findNext() {
1063
+ return this._activateMatch(this._find.next());
1064
+ }
1065
+ async findPrev() {
1066
+ return this._activateMatch(this._find.prev());
1067
+ }
1068
+ clearFind() {
1069
+ this._find.invalidate(), this._redrawHighlights();
1070
+ }
1071
+ async _activateMatch(e) {
1072
+ return e ? (e.location.slide === this.currentSlide ? this._redrawHighlights() : await this.goToSlide(e.location.slide), e) : (this._redrawHighlights(), null);
1073
+ }
1074
+ _redrawHighlights() {
1075
+ let e = this._find.slideRuns(this.currentSlide) ?? [], t = this._targetWidth(), n = this.engine ? Math.round(this.engine.slideHeight * (t / this.engine.slideWidth)) : 0;
1076
+ this._buildHighlightLayer(e, t, n);
1077
+ }
1078
+ _buildTextLayer(e, t, n, r) {
1079
+ P(e, t, n, r, this._hyperlinkHandler());
1080
+ }
1081
+ _hyperlinkHandler() {
1082
+ if (this.opts.enableHyperlinks !== !1) return (e) => this._onHyperlinkClick(e);
1083
+ }
1084
+ _onHyperlinkClick(e) {
1085
+ let t = this._resolveInternalSlideIndex(e);
1086
+ if (this.opts.onHyperlinkClick) {
1087
+ this.opts.onHyperlinkClick(t);
1088
+ return;
1089
+ }
1090
+ if (t.kind === "external") {
1091
+ M(t.url);
1092
+ return;
1093
+ }
1094
+ t.slideIndex !== void 0 && this.goToSlide(t.slideIndex);
1095
+ }
1096
+ _resolveInternalSlideIndex(e) {
1097
+ if (e.kind !== "internal" || e.slideIndex !== void 0) return e;
1098
+ let t = this.engine?.resolveInternalTarget(e.ref, this.currentSlide);
1099
+ return t === void 0 ? e : {
1100
+ ...e,
1101
+ slideIndex: t
1102
+ };
1103
+ }
1104
+ _reportRenderError(e) {
1105
+ if (this._destroyed) return;
1106
+ let t = e instanceof Error ? e : Error(String(e));
1107
+ this.opts.onError ? this.opts.onError(t) : console.error("[ooxml] PptxViewer render failed:", t);
1108
+ }
1109
+ async getResourceMetrics() {
1110
+ if (!this.engine) throw Error("Presentation not loaded");
1111
+ return await this.engine.getResourceMetrics();
1112
+ }
1113
+ destroy() {
1114
+ if (this._destroyed = !0, this._loadGen++, this.handle?.destroy(), this.handle = null, this.engine?.destroy(), this._find.invalidate(), this._originalParent) {
1115
+ let e = this._originalNextSibling && this._originalNextSibling.parentNode === this._originalParent ? this._originalNextSibling : null;
1116
+ this._originalParent.insertBefore(this.canvas, e);
1117
+ } else this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
1118
+ this.canvas.style.display = this._originalDisplay, this.wrapper.remove();
1119
+ }
1120
+ }, Ve = 150, He = "0 1px 3px rgba(0,0,0,0.2)", Ue = class {
1121
+ _pres = null;
1122
+ _injected;
1123
+ _opts;
1124
+ _container;
1125
+ _wrapper;
1126
+ _scrollHost;
1127
+ _spacer;
1128
+ _mode;
1129
+ _scale = 1;
1130
+ _scaleEstablished = !1;
1131
+ _pendingScale = null;
1132
+ _slots = /* @__PURE__ */ new Map();
1133
+ _free = [];
1134
+ _heights = [];
1135
+ _lastRange = null;
1136
+ _lastTopIndex = -1;
1137
+ _scrollListener = null;
1138
+ _destroyed = !1;
1139
+ _loadGen = 0;
1140
+ _slideInFlight = /* @__PURE__ */ new Set();
1141
+ _renderEpoch = 0;
1142
+ _settleTimer = null;
1143
+ _wheelListener = null;
1144
+ _pendingZoomAnchor = null;
1145
+ _resizeObserver = null;
1146
+ _prevBase = 0;
1147
+ _lastFitWidth = 0;
1148
+ _pageShadow;
1149
+ _find = new I(() => this.slideCount, (e) => this._collectSlideRuns(e));
1150
+ _findActive = !1;
1151
+ _findMeasureCtx;
1152
+ constructor(e, t = {}) {
1153
+ if (e.tagName === "CANVAS") throw Error("PptxScrollViewer takes a container element (e.g. a <div>), not a <canvas> — the viewer creates and manages its own canvases. Pass a block container; for the single-slide canvas API use PptxViewer.");
1154
+ if (this._container = e, this._opts = t, this._pageShadow = t.pageShadow ?? He, this._injected = !!t.presentation, this._injected) {
1155
+ let e = t.presentation;
1156
+ if (t.mode !== void 0 && t.mode !== e.mode) throw Error(`PptxScrollViewer: opts.mode='${t.mode}' conflicts with the injected engine's mode='${e.mode}'. Omit opts.mode when injecting an engine — the engine owns its render mode.`);
1157
+ this._pres = e, this._mode = e.mode;
1158
+ } else this._mode = t.mode ?? "main";
1159
+ this._wrapper = document.createElement("div"), this._wrapper.style.cssText = "position:relative;width:100%;height:100%;overflow:hidden;", this._scrollHost = document.createElement("div"), this._scrollHost.style.cssText = "position:absolute;inset:0;overflow:auto;", this._scrollHost.style.scrollbarGutter = "stable", t.background && (this._scrollHost.style.background = t.background), this._spacer = document.createElement("div"), this._spacer.style.cssText = "position:absolute;top:0;left:0;width:1px;height:0;pointer-events:none;", this._scrollHost.appendChild(this._spacer), this._wrapper.appendChild(this._scrollHost), this._container.appendChild(this._wrapper), this._scrollListener = () => this._onScroll(), this._scrollHost.addEventListener("scroll", this._scrollListener), this._opts.enableZoom !== !1 && (this._wheelListener = (e) => {
1160
+ if (!(e.ctrlKey || e.metaKey) || (e.preventDefault(), e.deltaY === 0)) return;
1161
+ let t = this._scrollHost.getBoundingClientRect(), n = e.clientX - t.left, r = e.clientY - t.top;
1162
+ this._pendingZoomAnchor = Number.isFinite(n) && Number.isFinite(r) ? {
1163
+ x: n,
1164
+ y: r
1165
+ } : null, this.setScale(te(this._scale, e.deltaY));
1166
+ }, this._scrollHost.addEventListener("wheel", this._wheelListener, { passive: !1 })), typeof ResizeObserver < "u" && (this._resizeObserver = new ResizeObserver(() => this._onResize()), this._resizeObserver.observe(this._container)), this._injected && this.relayout();
1167
+ }
1168
+ async load(e) {
1169
+ if (this._injected) throw Error("PptxScrollViewer.load() is unsupported when an engine is injected via opts.presentation; the injected engine is already loaded.");
1170
+ let t = ++this._loadGen, n = this._pres;
1171
+ try {
1172
+ let r = await $.load(e, {
1173
+ useGoogleFonts: this._opts.useGoogleFonts,
1174
+ maxZipEntryBytes: this._opts.maxZipEntryBytes,
1175
+ resourceLimits: this._opts.resourceLimits,
1176
+ debug: this._opts.debug,
1177
+ onResourceMetrics: this._opts.onResourceMetrics,
1178
+ workerTimeoutMs: this._opts.workerTimeoutMs,
1179
+ wasmUrl: this._opts.wasmUrl,
1180
+ math: this._opts.math,
1181
+ mode: this._mode
1182
+ });
1183
+ if (t !== this._loadGen) {
1184
+ r.destroy();
1185
+ return;
1186
+ }
1187
+ if (this._pres = r, n?.destroy(), this._find.invalidate(), this._findActive = !1, n) {
1188
+ for (let [e, t] of [...this._slots]) this._recycleSlot(e, t);
1189
+ this._lastTopIndex = -1;
1190
+ }
1191
+ this.relayout();
1192
+ } catch (e) {
1193
+ if (t !== this._loadGen) return;
1194
+ let n = e instanceof Error ? e : Error(String(e));
1195
+ if (this._opts.onError) {
1196
+ this._opts.onError(n);
1197
+ return;
1198
+ }
1199
+ throw n;
1200
+ }
1201
+ }
1202
+ get slideCount() {
1203
+ return this._pres?.slideCount ?? 0;
1204
+ }
1205
+ _slideWidthPx() {
1206
+ return this._pres.slideWidth / E * this._scale;
1207
+ }
1208
+ _slideHeightPx() {
1209
+ return this._pres.slideHeight / E * this._scale;
1210
+ }
1211
+ _fitWidthPx() {
1212
+ if (this._opts.width && this._opts.width > 0) return this._opts.width;
1213
+ let e = this._scrollHost.clientWidth || this._container.clientWidth;
1214
+ if (e <= 0) return 0;
1215
+ let { left: t, right: n } = this._padH(), r = e - t - n;
1216
+ return r > 0 ? r : 0;
1217
+ }
1218
+ _baseScale() {
1219
+ if (!this._pres || this._pres.slideCount === 0) return 0;
1220
+ let e = this._fitWidthPx(), t = this._pres.slideWidth / E;
1221
+ return e <= 0 || t <= 0 ? 0 : e / t;
1222
+ }
1223
+ relayout() {
1224
+ if (this._pres) {
1225
+ if (!this._scaleEstablished) {
1226
+ let e = this._baseScale();
1227
+ if (e > 0) {
1228
+ if (this._scale = e, this._prevBase = e, this._lastFitWidth = this._fitWidthPx(), this._scaleEstablished = !0, this._pendingScale !== null) {
1229
+ let e = this._pendingScale;
1230
+ this._pendingScale = null, e !== this._scale && (this._scale = e, this._opts.onScaleChange?.(e));
1231
+ }
1232
+ } else return;
1233
+ }
1234
+ this._recomputeHeights(), this._syncSpacer(), this._mountVisible();
1235
+ }
1236
+ }
1237
+ _recomputeHeights() {
1238
+ let e = this._pres.slideCount, t = this._slideHeightPx();
1239
+ this._heights = Array(e).fill(t);
1240
+ }
1241
+ _gap() {
1242
+ return this._opts.gap ?? 16;
1243
+ }
1244
+ _overscan() {
1245
+ return this._opts.overscan ?? 1;
1246
+ }
1247
+ _mediaOverscan() {
1248
+ return this._opts.mediaOverscan ?? 1;
1249
+ }
1250
+ _pad() {
1251
+ let e = this._gap();
1252
+ return {
1253
+ leading: this._opts.paddingTop ?? e,
1254
+ trailing: this._opts.paddingBottom ?? e
1255
+ };
1256
+ }
1257
+ _padH() {
1258
+ let e = this._gap();
1259
+ return {
1260
+ left: this._opts.paddingLeft ?? e,
1261
+ right: this._opts.paddingRight ?? e
1262
+ };
1263
+ }
1264
+ _slideIndexAtOffset(e, t) {
1265
+ let { offsets: n } = e, r = 0, i = n.length - 1, a = 0;
1266
+ for (; r <= i;) {
1267
+ let e = r + i >> 1;
1268
+ n[e] <= t ? (a = e, r = e + 1) : i = e - 1;
1269
+ }
1270
+ return a;
1271
+ }
1272
+ _range() {
1273
+ return A(this._heights, this._gap(), this._scrollHost.scrollTop, this._scrollHost.clientHeight, this._overscan(), this._pad());
1274
+ }
1275
+ _mediaRange() {
1276
+ return A(this._heights, this._gap(), this._scrollHost.scrollTop, this._scrollHost.clientHeight, this._mediaOverscan(), this._pad());
1277
+ }
1278
+ _rangeContains(e, t) {
1279
+ return t >= e.start && t <= e.end;
1280
+ }
1281
+ _syncSpacer() {
1282
+ let e = this._range();
1283
+ this._lastRange = e, this._spacer.style.height = `${e.totalHeight}px`, this._syncSpacerWidth();
1284
+ }
1285
+ _syncSpacerWidth() {
1286
+ let { left: e, right: t } = this._padH();
1287
+ this._spacer.style.width = `${this._slideWidthPx() + e + t}px`;
1288
+ }
1289
+ _onScroll() {
1290
+ !this._pres || !this._scaleEstablished || this._mountVisible();
1291
+ }
1292
+ _mountVisible() {
1293
+ if (!this._pres || this._pres.slideCount === 0) return;
1294
+ let e = this._range(), t = this._opts.enableMediaPlayback ? this._mediaRange() : null;
1295
+ this._lastRange = e;
1296
+ for (let [t, n] of [...this._slots]) (t < e.start || t > e.end) && this._recycleSlot(t, n);
1297
+ for (let n = e.start; n <= e.end; n++) if (this._slots.has(n)) this._positionSlot(this._slots.get(n), n, e);
1298
+ else {
1299
+ let r = this._acquireSlot();
1300
+ this._positionSlot(r, n, e), this._slots.set(n, r), this._renderSlot(n, r, !!t && this._rangeContains(t, n));
1301
+ }
1302
+ t && this._syncMediaPlayback(t), e.topIndex !== this._lastTopIndex && (this._lastTopIndex = e.topIndex, this._opts.onVisibleSlideChange?.(e.topIndex, this._pres.slideCount));
1303
+ }
1304
+ _applyPageShadow(e) {
1305
+ this._pageShadow !== !1 && (e.style.boxShadow = this._pageShadow);
1306
+ }
1307
+ _acquireSlot() {
1308
+ let e = this._free.pop();
1309
+ if (e) return this._scrollHost.appendChild(e.wrapper), e;
1310
+ let t = document.createElement("div");
1311
+ t.style.cssText = "position:absolute;";
1312
+ let n = document.createElement("canvas");
1313
+ n.style.cssText = "display:block;background:#fff;", this._applyPageShadow(n), t.appendChild(n);
1314
+ let r = null;
1315
+ this._opts.enableTextSelection && (r = document.createElement("div"), r.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;overflow:hidden;pointer-events:none;user-select:text;-webkit-user-select:text;", t.appendChild(r));
1316
+ let i = document.createElement("div");
1317
+ return i.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;overflow:hidden;pointer-events:none;", t.appendChild(i), this._scrollHost.appendChild(t), {
1318
+ wrapper: t,
1319
+ canvas: n,
1320
+ textLayer: r,
1321
+ highlightLayer: i,
1322
+ renderedSlide: -1,
1323
+ renderedScale: -1,
1324
+ bitmap: null,
1325
+ bitmapCtx: null,
1326
+ presentationHandle: null,
1327
+ mediaInteractive: !1,
1328
+ renderGeneration: 0,
1329
+ presentationGeneration: 0
1330
+ };
1331
+ }
1332
+ _recycleSlot(e, t) {
1333
+ this._slots.delete(e), t.renderGeneration++, t.presentationGeneration++, t.presentationHandle?.destroy(), t.presentationHandle = null, t.mediaInteractive = !1, t.bitmap &&= (t.bitmap.close(), null), t.textLayer && (t.textLayer.innerHTML = "", t.textLayer.style.transform = "", t.textLayer.style.transformOrigin = ""), t.highlightLayer.innerHTML = "", t.highlightLayer.style.transform = "", t.highlightLayer.style.transformOrigin = "", t.canvas.style.height = "", t.renderedSlide = -1, t.renderedScale = -1, t.wrapper.remove(), this._free.push(t);
1334
+ }
1335
+ _positionSlot(e, t, n) {
1336
+ e.wrapper.style.top = `${n.offsets[t]}px`;
1337
+ let r = this._slideWidthPx();
1338
+ e.wrapper.style.width = `${r}px`, e.wrapper.style.height = `${this._slideHeightPx()}px`;
1339
+ let { left: i } = this._padH(), a = this._scrollHost.clientWidth;
1340
+ e.wrapper.style.left = `${Math.max(i, (a - r) / 2)}px`;
1341
+ }
1342
+ _dpr() {
1343
+ return this._opts.dpr ?? (typeof window < "u" && window.devicePixelRatio || 1);
1344
+ }
1345
+ _renderSlot(e, t, n = !1) {
1346
+ if (!this._pres || t.renderedSlide === e) return;
1347
+ t.renderedSlide = e;
1348
+ let r = ++t.renderGeneration, i = this._dpr(), a = this._slideWidthPx(), o = this._renderEpoch, s = this._scale;
1349
+ if (this._opts.enableMediaPlayback && n) {
1350
+ t.mediaInteractive = !0, this._renderInteractiveSlot(e, t, a, i, s, o);
1351
+ return;
1352
+ }
1353
+ if (t.mediaInteractive = !1, this._mode === "worker") {
1354
+ this._renderSlotBitmap(e, t, a, i, s, r);
1355
+ return;
1356
+ }
1357
+ let c = [], l = !!this._opts.enableTextSelection && !!t.textLayer, u = l || this._findActive, d = u ? (e) => c.push(e) : void 0, f = t.canvas;
1358
+ this._pres.renderSlide(f, e, {
1359
+ width: a,
1360
+ dpr: i,
1361
+ onTextRun: d
1362
+ }).then(() => {
1363
+ r !== t.renderGeneration || f !== t.canvas || o !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e || (t.renderedScale = s, l && t.textLayer && P(t.textLayer, c, Math.round(a), Math.round(this._slideHeightPx()), this._hyperlinkHandler()), u && this._refreshFindRuns(e, c), this._redrawSlotHighlights(e, t));
1364
+ }).catch((e) => {
1365
+ this._reportRenderError(e);
1366
+ });
1367
+ }
1368
+ _renderInteractiveSlot(e, t, n, r, i, a) {
1369
+ if (!this._pres) return;
1370
+ let o = ++t.presentationGeneration;
1371
+ t.presentationHandle?.destroy(), t.presentationHandle = null;
1372
+ let s = [], c = !!this._opts.enableTextSelection && !!t.textLayer, l = c || this._findActive, u = l ? (e) => s.push(e) : void 0;
1373
+ this._pres.presentSlide(t.canvas, e, {
1374
+ width: n,
1375
+ dpr: r,
1376
+ onTextRun: u,
1377
+ onError: (e) => {
1378
+ o === t.presentationGeneration && this._reportRenderError(e);
1379
+ }
1380
+ }).then((r) => {
1381
+ if (o !== t.presentationGeneration || !t.mediaInteractive || a !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e) {
1382
+ r.destroy();
1383
+ return;
1384
+ }
1385
+ t.presentationHandle = r, t.renderedScale = i, c && t.textLayer && P(t.textLayer, s, Math.round(n), Math.round(this._slideHeightPx()), this._hyperlinkHandler()), l && this._refreshFindRuns(e, s), this._redrawSlotHighlights(e, t);
1386
+ }).catch((e) => {
1387
+ o === t.presentationGeneration && this._reportRenderError(e);
1388
+ });
1389
+ }
1390
+ _syncMediaPlayback(e = this._mediaRange()) {
1391
+ if (this._opts.enableMediaPlayback) for (let [t, n] of this._slots) {
1392
+ let r = this._rangeContains(e, t);
1393
+ r !== n.mediaInteractive && (r ? (n.mediaInteractive = !0, this._settleInteractiveSlot(t, n, this._slideWidthPx(), this._dpr(), this._scale, this._renderEpoch)) : (n.mediaInteractive = !1, n.presentationGeneration++, n.presentationHandle?.destroy(), n.presentationHandle = null));
1394
+ }
1395
+ }
1396
+ _reportRenderError(e) {
1397
+ if (this._destroyed) return;
1398
+ let t = e instanceof Error ? e : Error(String(e));
1399
+ this._opts.onError ? this._opts.onError(t) : console.error("[ooxml] PptxScrollViewer render failed:", t);
1400
+ }
1401
+ async _renderSlotBitmap(e, t, n, r, i, a = ++t.renderGeneration) {
1402
+ if (this._slideInFlight.has(e) || this._slots.get(e) !== t) return;
1403
+ let o = this._renderEpoch;
1404
+ this._slideInFlight.add(e);
1405
+ let s = t.canvas, c = !1;
1406
+ t.bitmapCtx ||= s.getContext("bitmaprenderer");
1407
+ let l = t.bitmapCtx, u = !!this._opts.enableTextSelection && !!t.textLayer, d = u || this._findActive, f = [];
1408
+ try {
1409
+ let p = await this._pres.renderSlideToBitmap(e, {
1410
+ width: n,
1411
+ dpr: r,
1412
+ onTextRun: d ? (e) => f.push(e) : void 0
1413
+ });
1414
+ if (a !== t.renderGeneration || s !== t.canvas || o !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e) {
1415
+ p.close();
1416
+ return;
1417
+ }
1418
+ if (!l) throw p.close(), Error("bitmaprenderer context not available");
1419
+ t.bitmap && t.bitmap.close(), t.bitmap = p, s.width = p.width, s.height = p.height, s.style.width = `${Math.round(p.width / r)}px`, s.style.height = `${Math.round(p.height / r)}px`, l.transferFromImageBitmap(p), t.bitmap = null, t.renderedScale = i, t.textLayer && (t.textLayer.style.transform = "", t.textLayer.style.transformOrigin = "", u && P(t.textLayer, f, Math.round(n), Math.round(this._slideHeightPx()), this._hyperlinkHandler())), d && this._refreshFindRuns(e, f), this._redrawSlotHighlights(e, t), c = !0;
1420
+ } catch (e) {
1421
+ this._reportRenderError(e);
1422
+ } finally {
1423
+ this._slideInFlight.delete(e);
1424
+ let n = this._slots.get(e);
1425
+ !c && n && (n !== t || o !== this._renderEpoch || a !== n.renderGeneration) && !this._slideInFlight.has(e) && !this._destroyed && !(this._opts.enableMediaPlayback && n.mediaInteractive) && this._renderSlotBitmap(e, n, this._slideWidthPx(), this._dpr(), this._scale);
1426
+ }
1427
+ }
1428
+ setScale(e) {
1429
+ let t = this._opts.zoomMin ?? .1, n = this._opts.zoomMax ?? 4, r = Math.min(n, Math.max(t, e)), i = this._pendingZoomAnchor;
1430
+ if (this._pendingZoomAnchor = null, !this._pres || this._pres.slideCount === 0 || !this._scaleEstablished) {
1431
+ this._pendingScale = r;
1432
+ return;
1433
+ }
1434
+ if (r === this._scale) return;
1435
+ let a = this._scale, o = i ? i.y : 0, s = this._range(), c = this._scrollHost.scrollTop + o, l = this._slideIndexAtOffset(s, c), u = this._heights[l] || 0, d = u > 0 ? (c - s.offsets[l]) / u : 0;
1436
+ d = Math.min(1, Math.max(0, d));
1437
+ let f = this._padH().left, p = this._scrollHost.scrollLeft || 0;
1438
+ this._renderEpoch++, this._scale = r, this._recomputeHeights();
1439
+ let m = A(this._heights, this._gap(), 0, this._scrollHost.clientHeight, this._overscan(), this._pad());
1440
+ this._spacer.style.height = `${m.totalHeight}px`, this._syncSpacerWidth();
1441
+ let h = Math.max(0, m.totalHeight - this._scrollHost.clientHeight), g = (m.offsets[l] ?? 0) + d * (this._heights[l] || 0);
1442
+ if (this._scrollHost.scrollTop = Math.min(h, Math.max(0, g - o)), i) {
1443
+ let e = Math.max(0, (this._spacer.offsetWidth || 0) - this._scrollHost.clientWidth);
1444
+ this._scrollHost.scrollLeft = v(p, i.x - f, a, r, { maxScroll: e });
1445
+ }
1446
+ this._previewVisible(), this._scheduleSettle(), this._opts.onScaleChange?.(r);
1447
+ }
1448
+ getScale() {
1449
+ return this._scaleEstablished ? this._scale : this._pendingScale ?? 1;
1450
+ }
1451
+ zoomIn() {
1452
+ this.setScale(w(this.getScale()));
1453
+ }
1454
+ zoomOut() {
1455
+ this.setScale(p(this.getScale()));
1456
+ }
1457
+ fitWidth() {
1458
+ this._fit("width");
1459
+ }
1460
+ fitPage() {
1461
+ this._fit("page");
1462
+ }
1463
+ _fit(e) {
1464
+ if (!this._pres || this._pres.slideCount === 0) return;
1465
+ let t = x({
1466
+ contentWidth: this._pres.slideWidth / E,
1467
+ contentHeight: this._pres.slideHeight / E,
1468
+ containerWidth: this._fitWidthPx(),
1469
+ containerHeight: this._scrollHost.clientHeight
1470
+ }, e);
1471
+ t <= 0 || this.setScale(t);
1472
+ }
1473
+ _previewVisible() {
1474
+ if (!this._pres || this._pres.slideCount === 0) return;
1475
+ let e = this._range(), t = this._opts.enableMediaPlayback ? this._mediaRange() : null;
1476
+ this._lastRange = e;
1477
+ for (let [t, n] of [...this._slots]) (t < e.start || t > e.end) && this._recycleSlot(t, n);
1478
+ for (let n = e.start; n <= e.end; n++) {
1479
+ let r = this._slots.get(n);
1480
+ if (r) this._previewSlot(r, n, e);
1481
+ else {
1482
+ let r = this._acquireSlot();
1483
+ this._positionSlot(r, n, e), this._slots.set(n, r), this._renderSlot(n, r, !!t && this._rangeContains(t, n));
1484
+ }
1485
+ }
1486
+ t && this._syncMediaPlayback(t), e.topIndex !== this._lastTopIndex && (this._lastTopIndex = e.topIndex, this._opts.onVisibleSlideChange?.(e.topIndex, this._pres.slideCount));
1487
+ }
1488
+ _previewSlot(e, t, n) {
1489
+ if (this._positionSlot(e, t, n), e.canvas.style.width = `${this._slideWidthPx()}px`, e.canvas.style.height = `${this._slideHeightPx()}px`, e.textLayer && e.renderedScale > 0) {
1490
+ let t = this._scale / e.renderedScale;
1491
+ e.textLayer.style.transformOrigin = "0 0", e.textLayer.style.transform = `scale(${t})`;
1492
+ }
1493
+ }
1494
+ _scheduleSettle() {
1495
+ this._settleTimer !== null && clearTimeout(this._settleTimer), this._settleTimer = setTimeout(() => {
1496
+ this._settleTimer = null, this._settleRender();
1497
+ }, Ve);
1498
+ }
1499
+ _settleRender() {
1500
+ if (this._destroyed || !this._pres || this._pres.slideCount === 0) return;
1501
+ let e = this._opts.enableMediaPlayback ? this._mediaRange() : null;
1502
+ for (let [t, n] of [...this._slots]) e && !this._rangeContains(e, t) || n.renderedScale !== this._scale && this._settleSlot(t, n);
1503
+ }
1504
+ _settleSlot(e, t) {
1505
+ if (!this._pres) return;
1506
+ let n = this._dpr(), r = this._slideWidthPx(), i = this._scale, a = this._renderEpoch;
1507
+ if (this._opts.enableMediaPlayback && t.mediaInteractive) {
1508
+ this._settleInteractiveSlot(e, t, r, n, i, a);
1509
+ return;
1510
+ }
1511
+ if (this._opts.enableMediaPlayback) return;
1512
+ if (this._mode === "worker") {
1513
+ this._renderSlotBitmap(e, t, r, n, i);
1514
+ return;
1515
+ }
1516
+ let o = document.createElement("canvas"), s = ++t.renderGeneration;
1517
+ o.style.cssText = "display:block;background:#fff;", this._applyPageShadow(o);
1518
+ let c = [], l = !!this._opts.enableTextSelection && !!t.textLayer, u = l || this._findActive, d = u ? (e) => c.push(e) : void 0;
1519
+ this._pres.renderSlide(o, e, {
1520
+ width: r,
1521
+ dpr: n,
1522
+ onTextRun: d
1523
+ }).then(() => {
1524
+ if (s !== t.renderGeneration || a !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e) return;
1525
+ let n = t.canvas;
1526
+ t.wrapper.insertBefore(o, n), n.remove(), t.canvas = o, t.bitmapCtx = null, t.renderedScale = i, t.textLayer && (t.textLayer.style.transform = "", t.textLayer.style.transformOrigin = "", l && P(t.textLayer, c, Math.round(r), Math.round(this._slideHeightPx()), this._hyperlinkHandler())), u && this._refreshFindRuns(e, c), this._redrawSlotHighlights(e, t);
1527
+ }).catch((e) => {
1528
+ this._reportRenderError(e);
1529
+ });
1530
+ }
1531
+ _settleInteractiveSlot(e, t, n, r, i, a) {
1532
+ if (!this._pres) return;
1533
+ let o = ++t.presentationGeneration, s = document.createElement("canvas");
1534
+ s.style.cssText = "display:block;background:#fff;", this._applyPageShadow(s);
1535
+ let c = [], l = !!this._opts.enableTextSelection && !!t.textLayer, u = l || this._findActive, d = u ? (e) => c.push(e) : void 0;
1536
+ this._pres.presentSlide(s, e, {
1537
+ width: n,
1538
+ dpr: r,
1539
+ onTextRun: d,
1540
+ onError: (e) => {
1541
+ o === t.presentationGeneration && this._reportRenderError(e);
1542
+ }
1543
+ }).then((r) => {
1544
+ if (o !== t.presentationGeneration || !t.mediaInteractive || a !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e) {
1545
+ r.destroy();
1546
+ return;
1547
+ }
1548
+ let d = t.canvas, f = t.presentationHandle;
1549
+ t.wrapper.insertBefore(s, d), d.remove(), t.canvas = s, t.bitmapCtx = null, t.presentationHandle = r, t.renderedScale = i, f?.destroy(), t.textLayer && (t.textLayer.style.transform = "", t.textLayer.style.transformOrigin = "", l && P(t.textLayer, c, Math.round(n), Math.round(this._slideHeightPx()), this._hyperlinkHandler())), u && this._refreshFindRuns(e, c), this._redrawSlotHighlights(e, t);
1550
+ }).catch((e) => {
1551
+ o === t.presentationGeneration && this._reportRenderError(e);
1552
+ });
1553
+ }
1554
+ scrollToSlide(e, t) {
1555
+ if (!this._pres || this._pres.slideCount === 0 || !this._scaleEstablished) return;
1556
+ let n = Math.max(0, Math.min(e, this._pres.slideCount - 1)), r = A(this._heights, this._gap(), 0, this._scrollHost.clientHeight, this._overscan(), this._pad()), i = r.offsets[n] ?? 0, a = Math.max(0, r.totalHeight - this._scrollHost.clientHeight), o = Math.min(a, Math.max(0, i)), s = this._scrollHost;
1557
+ typeof s.scrollTo == "function" ? s.scrollTo({
1558
+ top: o,
1559
+ behavior: t?.behavior ?? "auto"
1560
+ }) : this._scrollHost.scrollTop = o, this._mountVisible();
1561
+ }
1562
+ async findText(e, t = {}) {
1563
+ if (!this._pres) return [];
1564
+ this._findActive = e.length > 0;
1565
+ let n = await this._find.find(e, t);
1566
+ return this._redrawHighlights(), n;
1567
+ }
1568
+ async findNext() {
1569
+ return this._activateMatch(this._find.next());
1570
+ }
1571
+ async findPrev() {
1572
+ return this._activateMatch(this._find.prev());
1573
+ }
1574
+ clearFind() {
1575
+ this._findActive = !1, this._find.invalidate(), this._redrawHighlights();
1576
+ }
1577
+ async _activateMatch(e) {
1578
+ return e && this.scrollToSlide(e.location.slide), this._redrawHighlights(), e;
1579
+ }
1580
+ async _collectSlideRuns(e) {
1581
+ return this._pres ? this._pres.collectSlideRuns(e, this._slideWidthPx()) : [];
1582
+ }
1583
+ _redrawHighlights() {
1584
+ for (let [e, t] of this._slots) this._redrawSlotHighlights(e, t);
1585
+ }
1586
+ _refreshFindRuns(e, t) {
1587
+ this._findActive && this._find.setSlideRuns(e, t);
1588
+ }
1589
+ _redrawSlotHighlights(e, t) {
1590
+ if (!this._findActive) {
1591
+ t.highlightLayer.innerHTML = "";
1592
+ return;
1593
+ }
1594
+ let n = this._find.slideRuns(e);
1595
+ if (!n) {
1596
+ t.highlightLayer.innerHTML = "";
1597
+ return;
1598
+ }
1599
+ F(t.highlightLayer, n, this._find.slideHighlights(e), this._slideWidthPx(), this._slideHeightPx(), (e) => this._measureForFind(e), this._opts.findHighlightColors);
1600
+ }
1601
+ _measureForFind(e) {
1602
+ this._findMeasureCtx === void 0 && (this._findMeasureCtx = document.createElement("canvas").getContext("2d"));
1603
+ let t = this._findMeasureCtx;
1604
+ return !t || typeof t.measureText != "function" ? (e) => e.length : (t.font = e, (e) => t.measureText(e).width);
1605
+ }
1606
+ _hyperlinkHandler() {
1607
+ if (this._opts.enableHyperlinks !== !1) return (e) => this._onHyperlinkClick(e);
1608
+ }
1609
+ _onHyperlinkClick(e) {
1610
+ let t = this._resolveInternalSlideIndex(e);
1611
+ if (this._opts.onHyperlinkClick) {
1612
+ this._opts.onHyperlinkClick(t);
1613
+ return;
1614
+ }
1615
+ if (t.kind === "external") {
1616
+ M(t.url);
1617
+ return;
1618
+ }
1619
+ t.slideIndex !== void 0 && this.scrollToSlide(t.slideIndex);
1620
+ }
1621
+ _resolveInternalSlideIndex(e) {
1622
+ if (e.kind !== "internal" || e.slideIndex !== void 0) return e;
1623
+ let t = this._pres?.resolveInternalTarget(e.ref, this._range().topIndex);
1624
+ return t === void 0 ? e : {
1625
+ ...e,
1626
+ slideIndex: t
1627
+ };
1628
+ }
1629
+ _onResize() {
1630
+ if (!this._pres || this._pres.slideCount === 0) return;
1631
+ if (!this._scaleEstablished) {
1632
+ this.relayout();
1633
+ return;
1634
+ }
1635
+ if (this._opts.refitOnResize === !1) {
1636
+ this._lastFitWidth = this._fitWidthPx(), this._mountVisible();
1637
+ return;
1638
+ }
1639
+ let e = this._baseScale();
1640
+ if (e <= 0) return;
1641
+ let t = this._fitWidthPx();
1642
+ if (t === this._lastFitWidth) {
1643
+ this._mountVisible();
1644
+ return;
1645
+ }
1646
+ this._lastFitWidth = t;
1647
+ let n = this._prevBase > 0 ? this._scale / this._prevBase : 1;
1648
+ this._prevBase = e, this.setScale(e * n), this._mountVisible();
1649
+ }
1650
+ get topVisibleSlide() {
1651
+ return this._lastRange?.topIndex ?? 0;
1652
+ }
1653
+ mountedSlideIndicesForTest() {
1654
+ return [...this._slots.keys()];
1655
+ }
1656
+ interactiveSlideIndicesForTest() {
1657
+ return [...this._slots].filter(([, e]) => e.mediaInteractive).map(([e]) => e);
1658
+ }
1659
+ scaleForTest() {
1660
+ return this._scale;
1661
+ }
1662
+ baseScaleForTest() {
1663
+ return this._baseScale();
1664
+ }
1665
+ renderEpochForTest() {
1666
+ return this._renderEpoch;
1667
+ }
1668
+ resizeForTest() {
1669
+ this._onResize();
1670
+ }
1671
+ contentAtViewportYForTest(e) {
1672
+ let t = this._range(), n = this._scrollHost.scrollTop + e, r = this._slideIndexAtOffset(t, n), i = this._heights[r] || 0;
1673
+ return {
1674
+ slide: r,
1675
+ frac: i > 0 ? Math.min(1, Math.max(0, (n - t.offsets[r]) / i)) : 0
1676
+ };
1677
+ }
1678
+ viewportYOfForTest(e, t) {
1679
+ return (this._range().offsets[e] ?? 0) + t * (this._heights[e] || 0) - this._scrollHost.scrollTop;
1680
+ }
1681
+ async getResourceMetrics() {
1682
+ if (!this._pres) throw Error("Presentation not loaded");
1683
+ return await this._pres.getResourceMetrics();
1684
+ }
1685
+ destroy() {
1686
+ this._destroyed = !0, this._loadGen++, this._find.invalidate(), this._findActive = !1, this._scrollListener &&= (this._scrollHost.removeEventListener("scroll", this._scrollListener), null), this._wheelListener &&= (this._scrollHost.removeEventListener("wheel", this._wheelListener), null), this._resizeObserver?.disconnect(), this._resizeObserver = null, this._settleTimer !== null && (clearTimeout(this._settleTimer), this._settleTimer = null);
1687
+ for (let [e, t] of [...this._slots]) this._recycleSlot(e, t);
1688
+ this._free.length = 0, this._injected || this._pres?.destroy(), this._pres = null, this._wrapper.remove();
1689
+ }
1690
+ }, We = /* @__PURE__ */ e({
1691
+ OoxmlDecodedImageLimitError: () => ie,
1692
+ OoxmlError: () => r,
1693
+ OoxmlResourceLimitError: () => i,
1694
+ PptxPresentation: () => $,
1695
+ PptxScrollViewer: () => Ue,
1696
+ PptxViewer: () => Be,
1697
+ autoResize: () => S,
1698
+ buildPptxHighlightLayer: () => F,
1699
+ buildPptxTextLayer: () => P,
1700
+ isOoxmlDecodedImageLimitError: () => oe,
1701
+ openExternalHyperlink: () => M,
1702
+ renderSlide: () => O
1703
+ });
1704
+ //#endregion
1705
+ export { F as a, $ as i, Ue as n, P as o, Be as r, We as t };