@silurus/ooxml 0.82.1 → 0.83.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 (42) hide show
  1. package/README.md +72 -3
  2. package/dist/assets/{render-worker-Cy-QsDge.js → render-worker-Bu31cf1J.js} +4 -4
  3. package/dist/assets/render-worker-DuztdEcX.js +11 -0
  4. package/dist/{canvas-viewer-mechanics-CS_qbr6T.js → canvas-viewer-mechanics-h07vpVOQ.js} +42 -2
  5. package/dist/{comment-ui-runtime-C1RV_3iu.js → comment-ui-runtime-BelHJt73.js} +2 -2
  6. package/dist/{comment-ui-runtime-DgCZpPR0.js → comment-ui-runtime-DD5a3x3k.js} +2 -2
  7. package/dist/{comments-Cf9W7r3M.js → comments-AAaNnQTi.js} +7 -2
  8. package/dist/{document-pull-client-B1WOjA0z.js → document-pull-client-BAhqoTmm.js} +4508 -3952
  9. package/dist/docx-Dg73PGgC.js +2707 -0
  10. package/dist/docx.mjs +6 -6
  11. package/dist/docx_parser_bg.wasm +0 -0
  12. package/dist/dom-interaction-boundary-CepOlXt6.js +217 -0
  13. package/dist/index.mjs +4 -4
  14. package/dist/line-distribute-D7A_wnJg.js +1003 -0
  15. package/dist/{line-metrics-B3syvDn2.js → line-metrics-Bpn7OeZD.js} +616 -616
  16. package/dist/node.mjs +308 -308
  17. package/dist/pptx-BcUCETmQ.js +2990 -0
  18. package/dist/pptx.mjs +5 -5
  19. package/dist/pptx_parser_bg.wasm +0 -0
  20. package/dist/{render-BC8p7vZQ.js → render-CL-7V3E8.js} +1 -1
  21. package/dist/{render-worker-host-DhnkTyjj.js → render-worker-host-DDZo0feh.js} +1 -1
  22. package/dist/{render-worker-host-BNnXCtAu.js → render-worker-host-FJ19-fUI.js} +1 -1
  23. package/dist/{resource-measurement-CsW4_eYt.js → resource-measurement-DuiFWzam.js} +3 -3
  24. package/dist/{session-Da7LEQUB.js → session-BjydZEDF.js} +107 -94
  25. package/dist/{slide-pull-client-Bg9DusLX.js → slide-pull-client-CwvvncPA.js} +1158 -935
  26. package/dist/types/docx.d.ts +98 -8
  27. package/dist/types/index.d.ts +184 -13
  28. package/dist/types/node.d.ts +2 -2
  29. package/dist/types/pptx.d.ts +94 -5
  30. package/dist/types/xlsx.d.ts +2 -2
  31. package/dist/{worksheet-pull-client-CYtwXP5D.js → worksheet-pull-client-DyFsDF4A.js} +32 -32
  32. package/dist/{xlsx-DMWeXT-c.js → xlsx-BibrHQ52.js} +476 -476
  33. package/dist/xlsx.mjs +5 -5
  34. package/dist/xlsx_parser_bg.wasm +0 -0
  35. package/package.json +3 -1
  36. package/dist/assets/render-worker-aHayzR7v.js +0 -11
  37. package/dist/docx-HoZXZUPA.js +0 -2162
  38. package/dist/dom-interaction-boundary-C8F6HO5x.js +0 -119
  39. package/dist/line-distribute-iXsUCIH-.js +0 -1003
  40. package/dist/pptx-DEUP4Yq5.js +0 -2432
  41. /package/dist/{comment-occurrence-C34fWs_F.js → comment-occurrence-X54si2ob.js} +0 -0
  42. /package/dist/{highlight-rect-MaCt0om0.js → highlight-rect-Hes0z_Mj.js} +0 -0
@@ -0,0 +1,2990 @@
1
+ import { t as e } from "./chunk-DmhlhrBa.js";
2
+ import { a as t, c as n, d as r, f as i, i as a, l as o, n as s, o as c, r as l, s as u, t as d, u as f } from "./slide-pull-client-CwvvncPA.js";
3
+ import { B as p, G as m, Qt as h, R as g, Rt as _, Vt as v, W as y, Zt as b, a as x, et as S, ft as C, lt as w, tt as ee, z as te } from "./line-metrics-Bpn7OeZD.js";
4
+ import { C as ne, E as re, S as ie, T as ae, _ as T, a as E, b as oe, c as D, d as se, f as ce, g as le, h as ue, i as O, l as k, m as de, n as fe, o as pe, p as me, r as he, s as ge, t as _e, v as ve, w as ye, x as be, y as xe } from "./canvas-viewer-mechanics-h07vpVOQ.js";
5
+ import { a as Se, i as Ce, n as we, t as Te } from "./bounded-raw-part-cache-C6ro6Ezf.js";
6
+ import { a as A, c as Ee, i as De, l as j, n as Oe, r as ke, t as Ae } from "./dom-interaction-boundary-CepOlXt6.js";
7
+ import { cn as je, ln as Me } from "./plot-area-frame-DHV02PJU.js";
8
+ import { i as M } from "./units-BzZ0gAxs.js";
9
+ import { n as Ne } from "./resource-measurement-DuiFWzam.js";
10
+ import { n as Pe } from "./renderer-module-contract-DLbb7zY0.js";
11
+ import { t as Fe } from "./visible-index-BFE3PWiY.js";
12
+ import { n as Ie, t as N } from "./highlight-rect-Hes0z_Mj.js";
13
+ import { t as P } from "./comment-occurrence-X54si2ob.js";
14
+ //#region packages/core/src/nav/internal-target.ts
15
+ function Le(e, t) {
16
+ let n = t.startsWith("/") ? [] : e.split("/").filter((e) => e !== "");
17
+ for (let e of t.split("/")) if (e === "..") n.pop();
18
+ else if (e === "." || e === "") continue;
19
+ else n.push(e);
20
+ return n.join("/");
21
+ }
22
+ function Re(e) {
23
+ let t = /[?&]jump=([a-zA-Z]+)/.exec(e);
24
+ if (!t) return null;
25
+ let n = t[1].toLowerCase();
26
+ return n === "firstslide" || n === "lastslide" || n === "nextslide" || n === "previousslide" ? n : null;
27
+ }
28
+ function ze(e, t, n) {
29
+ if (!(n <= 0)) switch (e) {
30
+ case "firstslide": return 0;
31
+ case "lastslide": return n - 1;
32
+ case "nextslide": return Math.min(t + 1, n - 1);
33
+ case "previousslide": return Math.max(t - 1, 0);
34
+ }
35
+ }
36
+ //#endregion
37
+ //#region packages/pptx/src/text-layer.ts
38
+ function F(e, t, n) {
39
+ e.dataset ? n === void 0 ? delete e.dataset[t] : e.dataset[t] = n : n !== void 0 && e.setAttribute?.(`data-${t.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`)}`, n);
40
+ }
41
+ function I(e, t, n, r, i, a) {
42
+ e.innerHTML = "", F(e, "ooxmlSelectionSurface", "pptx"), F(e, "slideIndex", a === void 0 ? void 0 : String(a));
43
+ let o = /* @__PURE__ */ new Map(), s = e.ownerDocument ?? document;
44
+ for (let [a, c] of t.entries()) {
45
+ let t = c.rotation + (c.textBodyRotation ?? 0), l = `${c.shapeX},${c.shapeY},${c.shapeW},${c.shapeH},${t}`;
46
+ if (!o.has(l)) {
47
+ let i = s.createElement("div");
48
+ i.style.cssText = `position:absolute;left:${N(c.shapeX, n)};top:${N(c.shapeY, r)};width:${N(c.shapeW, n)};height:${N(c.shapeH, r)};pointer-events:all;overflow:visible;`, t !== 0 && (i.style.transformOrigin = "center center", i.style.transform = `rotate(${t}deg)`), o.set(l, {
49
+ div: i,
50
+ x: c.shapeX,
51
+ y: c.shapeY,
52
+ w: c.shapeW,
53
+ h: c.shapeH,
54
+ rot: t
55
+ }), e.appendChild(i);
56
+ }
57
+ let u = o.get(l), d = s.createElement("span");
58
+ F(d, "ooxmlSelectionRun", "pptx"), F(d, "runIndex", String(a)), c.shapeId !== void 0 && F(d, "shapeId", c.shapeId), c.elementIndex !== void 0 && F(d, "elementIndex", String(c.elementIndex)), c.origin !== void 0 && F(d, "elementOrigin", c.origin), d.textContent = c.text;
59
+ let f = i ? c.hyperlink : void 0;
60
+ d.style.cssText = `position:absolute;left:${N(c.inShapeX, u.w)};top:${N(c.inShapeY, u.h)};font:${c.font};line-height:${c.h}px;letter-spacing:0;white-space:pre;color:transparent;cursor:${f ? "pointer" : "text"};`, f && i && (d.title = f.kind === "external" ? f.url : f.ref, d.addEventListener("click", (e) => {
61
+ e.preventDefault(), i(f);
62
+ })), u.div.appendChild(d);
63
+ }
64
+ }
65
+ function L(e, t, n, r, i, a, o = {}) {
66
+ e.innerHTML = "";
67
+ 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) => {
68
+ let n = t.rotation + (t.textBodyRotation ?? 0), a = `${t.shapeX},${t.shapeY},${t.shapeW},${t.shapeH},${n}`, o = l.get(a);
69
+ if (!o) {
70
+ let s = document.createElement("div");
71
+ s.style.cssText = `position:absolute;left:${N(t.shapeX, r)};top:${N(t.shapeY, i)};width:${N(t.shapeW, r)};height:${N(t.shapeH, i)};pointer-events:none;overflow:hidden;`, n !== 0 && (s.style.transformOrigin = "center center", s.style.transform = `rotate(${n}deg)`), o = {
72
+ div: s,
73
+ w: t.shapeW,
74
+ h: t.shapeH
75
+ }, l.set(a, o), e.appendChild(s);
76
+ }
77
+ return o;
78
+ };
79
+ for (let e of n) {
80
+ let n = e.active ? c : s;
81
+ for (let r of e.slices) {
82
+ let e = t[r.runIndex];
83
+ if (!e) continue;
84
+ let i = a(e.font), { x: o, width: s } = Ie(e.text, r.start, r.end, i);
85
+ if (s <= 0) continue;
86
+ let c = u(e), l = document.createElement("div");
87
+ l.style.cssText = `position:absolute;left:${N(e.inShapeX + o, c.w)};top:${N(e.inShapeY, c.h)};width:${N(s, c.w)};height:${N(e.h, c.h)};background:${n};pointer-events:none;`, c.div.appendChild(l);
88
+ }
89
+ }
90
+ }
91
+ //#endregion
92
+ //#region packages/pptx/src/find.ts
93
+ var Be = class {
94
+ _slideRuns = /* @__PURE__ */ new Map();
95
+ _matches = [];
96
+ _active = -1;
97
+ _generation = 0;
98
+ _runsRevision = 0;
99
+ constructor(e, t) {
100
+ this._slideCount = e, this._collectSlideRuns = t;
101
+ }
102
+ invalidate() {
103
+ this._generation++, this._runsRevision++, this._slideRuns.clear(), this._matches = [], this._active = -1;
104
+ }
105
+ slideRuns(e) {
106
+ return this._slideRuns.get(e);
107
+ }
108
+ setSlideRuns(e, t) {
109
+ this._runsRevision++, this._slideRuns.set(e, t);
110
+ }
111
+ slideHighlights(e) {
112
+ let t = [];
113
+ for (let n = 0; n < this._matches.length; n++) {
114
+ let r = this._matches[n];
115
+ r.slide === e && t.push({
116
+ slices: r.slices,
117
+ active: n === this._active
118
+ });
119
+ }
120
+ return t;
121
+ }
122
+ activeSlide() {
123
+ let e = this._matches[this._active];
124
+ return e ? e.slide : null;
125
+ }
126
+ matches() {
127
+ return this._matches.map((e, t) => ({
128
+ matchIndex: t,
129
+ text: e.text,
130
+ location: { slide: e.slide }
131
+ }));
132
+ }
133
+ async find(e, t = {}) {
134
+ let n = ++this._generation;
135
+ if (e.length === 0) return this._runsRevision++, this._slideRuns.clear(), this._matches = [], this._active = -1, [];
136
+ let r = this._runsRevision, i = new Map(this._slideRuns), a = this._slideCount();
137
+ for (let e = 0; e < a; e++) {
138
+ let t = i.get(e);
139
+ if (!t) {
140
+ try {
141
+ t = await this._collectSlideRuns(e);
142
+ } catch (e) {
143
+ if (n !== this._generation) return [];
144
+ throw e;
145
+ }
146
+ if (n !== this._generation) return [];
147
+ i.set(e, t);
148
+ }
149
+ }
150
+ if (n !== this._generation) return [];
151
+ let o = r === this._runsRevision ? i : new Map([...i, ...this._slideRuns]), s = [];
152
+ for (let n = 0; n < a; n++) {
153
+ let r = o.get(n) ?? [], i = de(r);
154
+ for (let a of ue(i, e, t)) {
155
+ let e = a.slices.map((e) => r[e.runIndex].text.slice(e.start, e.end)).join("");
156
+ s.push({
157
+ slide: n,
158
+ text: e,
159
+ slices: a.slices
160
+ });
161
+ }
162
+ }
163
+ return this._runsRevision++, this._slideRuns = o, this._matches = s, this._active = -1, this.matches();
164
+ }
165
+ next() {
166
+ return this._active = ce(this._active, this._matches.length), this._activePublic();
167
+ }
168
+ prev() {
169
+ return this._active = me(this._active, this._matches.length), this._activePublic();
170
+ }
171
+ _activePublic() {
172
+ let e = this._matches[this._active];
173
+ return e ? {
174
+ matchIndex: this._active,
175
+ text: e.text,
176
+ location: { slide: e.slide }
177
+ } : null;
178
+ }
179
+ }, Ve = (e) => e >= "0" && e <= "9";
180
+ function He(e) {
181
+ let t = 0;
182
+ for (let n = 0; n < 10; n++) t = Math.max(t, e.measureText(String(n)).width);
183
+ return t;
184
+ }
185
+ function Ue(e, t, n) {
186
+ let r = 0;
187
+ for (let i of t) r += Ve(i) ? n : e.measureText(i).width;
188
+ return r;
189
+ }
190
+ function We(e, t, n, r, i) {
191
+ let a = e.textAlign;
192
+ e.textAlign = "left";
193
+ let o = n;
194
+ for (let n of t) if (Ve(n)) {
195
+ let t = e.measureText(n).width;
196
+ e.fillText(n, o + (i - t) / 2, r), o += i;
197
+ } else e.fillText(n, o, r), o += e.measureText(n).width;
198
+ e.textAlign = a;
199
+ }
200
+ //#endregion
201
+ //#region packages/pptx/src/presentation-handle.ts
202
+ var R = (e, t) => e / M * t;
203
+ async function Ge(e, t, n) {
204
+ let r = e.getContext("2d");
205
+ if (!r) throw Error("2D context not available");
206
+ let a = n.width / (n.slideWidthEmu / M);
207
+ await n.drawBase();
208
+ let o = document.createElement("canvas");
209
+ o.width = e.width, o.height = e.height;
210
+ let s = o.getContext("2d");
211
+ if (!s) throw Error("base 2D context not available");
212
+ s.drawImage(e, 0, 0);
213
+ let c = [], l = !1, u = () => {
214
+ for (let e of c) {
215
+ e.detachListeners(), e.media.pause(), e.media.removeAttribute("src");
216
+ try {
217
+ e.media.load();
218
+ } catch {}
219
+ URL.revokeObjectURL(e.objectUrl);
220
+ }
221
+ c.length = 0;
222
+ }, d = (e) => {
223
+ l || (n.onError ? n.onError(e) : console.error("[ooxml] PPTX embedded media failed:", e));
224
+ };
225
+ for (let e of t) {
226
+ let t;
227
+ try {
228
+ t = await n.fetchMedia(e.mediaPath);
229
+ } catch (t) {
230
+ throw u(), Je(e, t);
231
+ }
232
+ let r = e.mimeType || t.type, i = t.type === r ? t : new Blob([t], { type: r }), o = URL.createObjectURL(i), s = e.mediaKind === "video" ? document.createElement("video") : document.createElement("audio");
233
+ s.src = o, s.preload = "metadata", e.mediaKind === "video" && (s.playsInline = !0);
234
+ let f = Ke(e, a), p = {
235
+ el: e,
236
+ rect: e.mediaKind === "audio" ? {
237
+ x: f.x + f.w / 2 - Math.max(f.w, 260) / 2,
238
+ y: f.y,
239
+ w: Math.max(f.w, 260),
240
+ h: f.h + 36
241
+ } : f,
242
+ posterRect: f,
243
+ media: s,
244
+ objectUrl: o,
245
+ loadState: "loading",
246
+ detachListeners: () => {}
247
+ }, m = () => {
248
+ l || (p.loadState = "metadata");
249
+ }, h = () => {
250
+ l || (p.loadState = "ready");
251
+ }, g = () => {
252
+ l || (p.loadState = "error", d(z(e, s, "decode")));
253
+ };
254
+ s.addEventListener("loadedmetadata", m), s.addEventListener("canplay", h), s.addEventListener("error", g), p.detachListeners = () => {
255
+ s.removeEventListener("loadedmetadata", m), s.removeEventListener("canplay", h), s.removeEventListener("error", g);
256
+ }, c.push(p);
257
+ try {
258
+ s.load();
259
+ } catch (t) {
260
+ let n = z(e, s, "load", t);
261
+ throw u(), n;
262
+ }
263
+ }
264
+ let f = null, p = null, m = () => {
265
+ r.setTransform(n.dpr, 0, 0, n.dpr, 0, 0);
266
+ let t = e.width / n.dpr, a = e.height / n.dpr;
267
+ r.drawImage(o, 0, 0, e.width, e.height, 0, 0, t, a);
268
+ for (let e of c) {
269
+ let t = e.media;
270
+ if (e.loadState !== "loading") {
271
+ if (e.loadState === "error") {
272
+ qe(r, e.posterRect, "Media unavailable");
273
+ continue;
274
+ }
275
+ if (e.el.mediaKind === "video" && t.readyState >= 2) {
276
+ let { x: n, y: i, w: a, h: o } = e.posterRect;
277
+ r.drawImage(t, n, i, a, o);
278
+ }
279
+ if (e === p || v?.state === e) $e(r, e, t);
280
+ else if (t.paused) {
281
+ let { x: t, y: n, w: a, h: o } = e.posterRect;
282
+ i(r, t + a / 2, n + o / 2, a, o, "paused");
283
+ }
284
+ }
285
+ }
286
+ }, h = () => {
287
+ l || (m(), f = requestAnimationFrame(h));
288
+ }, g = (t, r) => {
289
+ let i = e.getBoundingClientRect(), a = e.width / n.dpr, o = e.height / n.dpr;
290
+ return {
291
+ x: (t - i.left) / i.width * a,
292
+ y: (r - i.top) / i.height * o
293
+ };
294
+ }, _ = (e, t) => {
295
+ for (let n of c) {
296
+ let { x: r, y: i, w: a, h: o } = n.rect;
297
+ if (e < r || e > r + a || t < i || t > i + o) continue;
298
+ let s = H(n), c = s.y - 12, l = s.y + s.h + 8;
299
+ return (Number.isFinite(n.media.duration) ? n.media.duration : 0) > 0 && e >= s.x && e <= s.x + s.w && t >= c && t <= l ? {
300
+ kind: "seek",
301
+ state: n,
302
+ fraction: Math.max(0, Math.min(1, (e - s.x) / s.w))
303
+ } : {
304
+ kind: "toggle",
305
+ state: n
306
+ };
307
+ }
308
+ return null;
309
+ }, v = null, y = (e, t) => {
310
+ let n = Number.isFinite(e.media.duration) ? e.media.duration : 0;
311
+ n <= 0 || (e.media.currentTime = n * t);
312
+ }, b = (e) => {
313
+ try {
314
+ e.media.play().catch((t) => {
315
+ d(z(e.el, e.media, "play", t));
316
+ });
317
+ } catch (t) {
318
+ d(z(e.el, e.media, "play", t));
319
+ }
320
+ }, x = (t) => {
321
+ let { x: n, y: r } = g(t.clientX, t.clientY), i = _(n, r);
322
+ i && (i.kind === "seek" ? (v = {
323
+ state: i.state,
324
+ wasPlaying: !i.state.media.paused
325
+ }, i.state.media.pause(), y(i.state, i.fraction), e.setPointerCapture(t.pointerId), t.preventDefault()) : i.state.media.paused ? b(i.state) : i.state.media.pause());
326
+ }, S = (e) => {
327
+ let { x: t, y: n } = g(e.clientX, e.clientY);
328
+ p = null;
329
+ for (let e of c) {
330
+ let { x: r, y: i, w: a, h: o } = e.rect;
331
+ if (t >= r && t <= r + a && n >= i && n <= i + o) {
332
+ p = e;
333
+ break;
334
+ }
335
+ }
336
+ if (v) {
337
+ let e = H(v.state), n = Math.max(0, Math.min(1, (t - e.x) / e.w));
338
+ y(v.state, n);
339
+ }
340
+ }, C = () => {
341
+ p = null;
342
+ }, w = (t) => {
343
+ if (!v) return;
344
+ let { wasPlaying: n, state: r } = v;
345
+ v = null, e.releasePointerCapture(t.pointerId), n && b(r);
346
+ };
347
+ return c.length > 0 && (e.addEventListener("pointerdown", x), e.addEventListener("pointermove", S), e.addEventListener("pointerleave", C), e.addEventListener("pointerup", w), e.addEventListener("pointercancel", w), e.style.cursor = "pointer", h()), {
348
+ play(e) {
349
+ for (let t of c) (!e || t.el.mediaPath === e) && b(t);
350
+ },
351
+ pause(e) {
352
+ for (let t of c) (!e || t.el.mediaPath === e) && t.media.pause();
353
+ },
354
+ destroy() {
355
+ l || (l = !0, f !== null && cancelAnimationFrame(f), e.removeEventListener("pointerdown", x), e.removeEventListener("pointermove", S), e.removeEventListener("pointerleave", C), e.removeEventListener("pointerup", w), e.removeEventListener("pointercancel", w), e.style.cursor = "", u());
356
+ }
357
+ };
358
+ }
359
+ function Ke(e, t) {
360
+ return {
361
+ x: R(e.x, t),
362
+ y: R(e.y, t),
363
+ w: R(e.width, t),
364
+ h: R(e.height, t)
365
+ };
366
+ }
367
+ function qe(e, t, n) {
368
+ let r = Math.max(10, Math.min(14, t.h * .12));
369
+ e.save(), e.font = `500 ${r}px system-ui, -apple-system, sans-serif`, e.textAlign = "center", e.textBaseline = "middle";
370
+ let i = r + 12, a = Math.min(t.w, Math.max(100, e.measureText(n).width + 24));
371
+ U(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();
372
+ }
373
+ function Je(e, t) {
374
+ return /* @__PURE__ */ Error(`Embedded ${e.mediaKind} fetch failed for "${e.mediaPath}" (mime=${e.mimeType || "unknown"}): ${Ye(t)}`);
375
+ }
376
+ function z(e, t, n, r) {
377
+ let i = "";
378
+ try {
379
+ i = e.mimeType ? t.canPlayType(e.mimeType) : "";
380
+ } catch {}
381
+ let a = t.error, o = [
382
+ `mime=${e.mimeType || "unknown"}`,
383
+ `canPlayType=${i || "no"}`,
384
+ `readyState=${t.readyState}`,
385
+ `networkState=${t.networkState}`
386
+ ];
387
+ a && o.push(`mediaError=${a.code}${a.message ? ` ${a.message}` : ""}`);
388
+ let s = r === void 0 ? "" : `: ${Ye(r)}`;
389
+ return /* @__PURE__ */ Error(`Embedded ${e.mediaKind} ${n} failed for "${e.mediaPath}" (${o.join("; ")})${s}`);
390
+ }
391
+ function Ye(e) {
392
+ return e instanceof Error ? `${e.name || "Error"}${e.message ? `: ${e.message}` : ""}` : String(e);
393
+ }
394
+ var Xe = 28, B = 14, Ze = 72, Qe = 10, V = 3;
395
+ function $e(e, t, n) {
396
+ let r = Number.isFinite(n.duration) ? n.duration : 0, a = r > 0 ? Math.min(1, n.currentTime / r) : 0, o = t.posterRect;
397
+ i(e, o.x + o.w / 2, o.y + o.h / 2, o.w, o.h, n.paused ? "paused" : "playing"), t.el.mediaKind === "audio" ? tt(e, t, n, r, a) : et(e, t, n, r, a);
398
+ }
399
+ function et(e, t, n, r, i) {
400
+ let { x: a, y: o, w: s, h: c } = t.rect, l = Math.max(28, Math.min(56, c * .22)), u = o + c - l;
401
+ e.save();
402
+ let d = e.createLinearGradient(0, u, 0, o + c);
403
+ 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();
404
+ let f = H(t);
405
+ rt(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)", nt(e, n.currentTime, r, f.x, f.y - 10, "bottom"), e.restore();
406
+ }
407
+ function tt(e, t, n, r, i) {
408
+ let a = it(t.rect);
409
+ e.save(), U(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)", nt(e, n.currentTime, r, a.x + B, a.y + a.h / 2, "middle"), e.restore(), rt(e, H(t), i, r > 0);
410
+ }
411
+ function nt(e, t, n, r, i, a) {
412
+ let o = at(t), s = at(n), c = He(e), l = Ue(e, o, c), u = Ue(e, s, c), d = e.measureText(" / ").width, f = Math.max(l, u);
413
+ We(e, o, r + f - l, i, c);
414
+ let p = e.textAlign;
415
+ e.textAlign = "left", e.fillText(" / ", r + f, i), e.textAlign = p, We(e, s, r + f + d, i, c);
416
+ }
417
+ function rt(e, t, n, r) {
418
+ let i = t.h / 2;
419
+ if (e.save(), U(e, t.x, t.y, t.w, t.h, i), e.fillStyle = "rgba(255, 255, 255, 0.35)", e.fill(), n > 0 && (U(e, t.x, t.y, t.w * n, t.h, i), e.fillStyle = "#fff", e.fill()), r) {
420
+ let r = Math.max(t.x + 5, Math.min(t.x + t.w - 5, t.x + t.w * n));
421
+ 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();
422
+ }
423
+ e.restore();
424
+ }
425
+ function it(e) {
426
+ let t = Math.max(220, e.w - 24);
427
+ return {
428
+ x: e.x + e.w / 2 - t / 2,
429
+ y: e.y + e.h - Xe - 4,
430
+ w: t,
431
+ h: Xe
432
+ };
433
+ }
434
+ function H(e) {
435
+ if (e.el.mediaKind === "audio") {
436
+ let t = it(e.rect), n = t.x + B + Ze + Qe, r = Math.max(40, t.x + t.w - B - n);
437
+ return {
438
+ x: n,
439
+ y: t.y + (t.h - V) / 2,
440
+ w: r,
441
+ h: V
442
+ };
443
+ }
444
+ let t = e.rect, n = Math.max(12, t.w * .025), r = Math.max(12, Math.min(18, t.h * .05));
445
+ return {
446
+ x: t.x + n,
447
+ y: t.y + t.h - V - r,
448
+ w: t.w - n * 2,
449
+ h: V
450
+ };
451
+ }
452
+ function U(e, t, n, r, i, a) {
453
+ let o = Math.min(a, i / 2, r / 2);
454
+ 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();
455
+ }
456
+ function at(e) {
457
+ if (!Number.isFinite(e) || e < 0) return "0:00";
458
+ let t = Math.floor(e);
459
+ return `${Math.floor(t / 60)}:${(t % 60).toString().padStart(2, "0")}`;
460
+ }
461
+ //#endregion
462
+ //#region packages/pptx/src/slide-nav.ts
463
+ function ot(e) {
464
+ let t = /* @__PURE__ */ new Map();
465
+ for (let n = 0; n < e.length; n++) {
466
+ let r = e[n];
467
+ r !== void 0 && r !== "" && !t.has(r) && t.set(r, n);
468
+ }
469
+ return t;
470
+ }
471
+ function st(e, t) {
472
+ if (e === "") return;
473
+ let n = Le("ppt/slides", e);
474
+ return t.get(n);
475
+ }
476
+ function ct(e, t, n) {
477
+ let r = Re(e);
478
+ return r === null ? st(e, t) : ze(r, n, t.size);
479
+ }
480
+ //#endregion
481
+ //#region packages/pptx/src/slide-repository.ts
482
+ var lt = class {
483
+ #e;
484
+ #t;
485
+ #n;
486
+ #r = 0;
487
+ #i = Promise.resolve();
488
+ #a;
489
+ #o;
490
+ constructor(e) {
491
+ if (!Number.isSafeInteger(e.slideCount) || e.slideCount < 0) throw TypeError("slideCount must be a non-negative safe integer");
492
+ this.#e = e.slideCount, this.#t = e.loadSlide, this.#n = new we({
493
+ maxEntries: e.maxCachedSlides,
494
+ maxWeight: e.maxCachedStructuralBytes,
495
+ measure: (e) => Ne(e).jsonBytes
496
+ });
497
+ }
498
+ get slideCount() {
499
+ return this.#e;
500
+ }
501
+ get usage() {
502
+ return this.#n.usage;
503
+ }
504
+ withSlide(e, t) {
505
+ this.#c(e);
506
+ let n = this.#r, r = this.#i.then(async () => {
507
+ if (n !== this.#r) throw this.#a ? this.#a : Error("PPTX slide repository generation is stale");
508
+ if (this.#a) throw this.#a;
509
+ let r = await this.#s(e, n);
510
+ try {
511
+ return await t(r);
512
+ } catch (e) {
513
+ let t = ut(e);
514
+ throw t ? (this.#l(t, n), this.#o === n ? this.#a ?? t : t) : e;
515
+ }
516
+ });
517
+ return this.#i = r.then(() => void 0, () => void 0), r;
518
+ }
519
+ async #s(e, t) {
520
+ return this.#n.getOrLoad(e, async () => {
521
+ let n;
522
+ try {
523
+ n = await this.#t(e);
524
+ } catch (e) {
525
+ let n = ut(e);
526
+ throw n ? (this.#l(n, t), this.#o === t ? this.#a ?? n : n) : e;
527
+ }
528
+ if (this.#o === t && this.#a) throw this.#a;
529
+ return n;
530
+ });
531
+ }
532
+ clear() {
533
+ this.#r += 1, this.#a = void 0, this.#o = void 0, this.#n.clear();
534
+ }
535
+ #c(e) {
536
+ if (!Number.isSafeInteger(e) || e < 0 || e >= this.#e) throw RangeError(`Slide index ${e} out of range (count: ${this.#e})`);
537
+ }
538
+ #l(e, t) {
539
+ t !== this.#r || this.#a || (this.#a = e, this.#o = t, this.#r += 1, this.#n.clear());
540
+ }
541
+ };
542
+ function ut(e) {
543
+ return e instanceof h ? e : m(e);
544
+ }
545
+ //#endregion
546
+ //#region packages/pptx/src/embedded-fonts.ts
547
+ var dt = 1;
548
+ function W(e) {
549
+ return e.trim().toLowerCase();
550
+ }
551
+ async function ft(e, t) {
552
+ if (e.length === 0) return {
553
+ faces: [],
554
+ aliases: /* @__PURE__ */ new Map(),
555
+ authoredFamilies: /* @__PURE__ */ new Map()
556
+ };
557
+ let n = dt++, r = /* @__PURE__ */ new Map();
558
+ for (let t of e) {
559
+ let e = W(t.fontName);
560
+ r.has(e) || r.set(e, `__ooxml_pptx_${n}_${r.size + 1}`);
561
+ }
562
+ let i = [], a = /* @__PURE__ */ new Set();
563
+ for (let n = 0; n < e.length; n += 2) {
564
+ let o = (await Promise.all(e.slice(n, n + 2).map(async (e) => {
565
+ try {
566
+ return {
567
+ family: r.get(W(e.fontName)),
568
+ bytes: await t(e.partPath),
569
+ odttf: !1,
570
+ weight: e.style === "bold" || e.style === "boldItalic" ? "bold" : "normal",
571
+ style: e.style === "italic" || e.style === "boldItalic" ? "italic" : "normal"
572
+ };
573
+ } catch {
574
+ return null;
575
+ }
576
+ }))).filter((e) => e !== null);
577
+ if (o.length !== 0) for (let e of await Ee(o)) a.has(e) ? j([e]) : (a.add(e), i.push(e));
578
+ }
579
+ let o = new Set(i.map((e) => W(e.family))), s = new Map([...r].filter(([, e]) => o.has(W(e))));
580
+ return {
581
+ faces: i,
582
+ aliases: s,
583
+ authoredFamilies: new Map([...s].map(([e, t]) => [t, e]))
584
+ };
585
+ }
586
+ function pt(e, t) {
587
+ return e.filter((e) => e === null || !t.has(e.trim().toLowerCase()));
588
+ }
589
+ //#endregion
590
+ //#region packages/pptx/src/worker.ts?worker&inline
591
+ var mt = "var e=(e,t)=>()=>(e&&(t=e(e=0)),t),t=class e extends Error{code;constructor(t,n){super(n),this.name=`OoxmlError`,this.code=t,Object.setPrototypeOf(this,e.prototype)}},n=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 r=67108864,i=`https://fonts.googleapis.com/css2?family=Noto+Naskh+Arabic:wght@400;700&display=swap`,a=`https://fonts.googleapis.com/css2?family=Noto+Sans+Arabic:wght@400;700&display=swap`,o=`https://fonts.googleapis.com/css2?family=Libre+Franklin:ital,wght@0,400;0,600;0,700;1,400;1,600;1,700&display=swap`,s={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`},\"franklin gothic book\":{url:o,loadFamily:`Libre Franklin`},\"franklin gothic medium\":{url:o,loadFamily:`Libre Franklin`},\"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:i,loadFamily:`Noto Naskh Arabic`},\"traditional arabic\":{url:i,loadFamily:`Noto Naskh Arabic`},\"simplified arabic\":{url:i,loadFamily:`Noto Naskh Arabic`},\"arabic typesetting\":{url:i,loadFamily:`Noto Naskh Arabic`},\"univers next arabic\":{url:a,loadFamily:`Noto Sans Arabic`},\"noto naskh arabic\":{url:i,loadFamily:`Noto Naskh Arabic`},\"noto sans arabic\":{url:a,loadFamily:`Noto Sans Arabic`}};function c(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 l=e=>`https://fonts.googleapis.com/css2?family=${e}:wght@400;700&display=swap`,ee={\"noto sans kr\":{url:l(`Noto+Sans+KR`)},\"noto sans sc\":{url:l(`Noto+Sans+SC`)},\"noto sans tc\":{url:l(`Noto+Sans+TC`)},\"noto sans jp\":{url:l(`Noto+Sans+JP`)},\"noto serif kr\":{url:l(`Noto+Serif+KR`)},\"noto serif sc\":{url:l(`Noto+Serif+SC`)},\"noto serif tc\":{url:l(`Noto+Serif+TC`)},\"noto serif jp\":{url:l(`Noto+Serif+JP`)},\"noto sans\":{url:l(`Noto+Sans`)},\"noto serif\":{url:l(`Noto+Serif`)},\"noto sans devanagari\":{url:l(`Noto+Sans+Devanagari`)},\"noto sans thai\":{url:l(`Noto+Sans+Thai`)},\"noto sans hebrew\":{url:l(`Noto+Sans+Hebrew`)},\"noto serif hebrew\":{url:l(`Noto+Serif+Hebrew`)}};var u=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}},d,f,te=e((()=>{d=1<<25,d*4,f=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 ne(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 re=class{state=`uninitialized`;generationValue=0;readiness;poisonListeners=new Set;constructor(e,t,n){this.initialize=e,this.reinitialize=t,this.normalizeFailure=n}get generation(){return this.generationValue}get poisoned(){return this.state===`poisoned`}onPoison(e){return this.poisonListeners.add(e),()=>this.poisonListeners.delete(e)}async ensureReady(){if(this.state!==`ready`){if(!this.readiness){let e=this.state===`uninitialized`?this.initialize:this.reinitialize;this.readiness=Promise.resolve().then(e).then(()=>{this.generationValue+=1,this.state=`ready`,this.readiness=void 0},e=>{throw this.readiness=void 0,e})}await this.readiness}}run(e){try{return e()}catch(e){let t=this.normalizeFailure(e);throw t?(this.poison(t),t):e}}tryRunReady(e){if(this.state!==`ready`)return{current:!1};let t=this.generationValue,n=this.run(e);return this.state!==`ready`||t!==this.generationValue?{current:!1}:{current:!0,generation:t,value:n}}poison(e){this.state=`poisoned`,this.readiness=void 0;for(let t of this.poisonListeners)t(e)}assertCurrent(e){if(this.state!==`ready`||e!==this.generationValue)throw Error(`WASM archive session belongs to a discarded runtime generation`)}},ie=class e extends Error{code=`parser-crashed`;constructor(t){super(t),this.name=`WasmTrapError`,Object.setPrototypeOf(this,e.prototype)}};function ae(e){let t=globalThis.WebAssembly?.RuntimeError;return t&&e instanceof t||e instanceof RangeError?!0:e instanceof Error?e.name===`RuntimeError`||e.name===`CompileError`||e.name===`LinkError`||e.name===`InternalError`||e.name===`OOMError`:!1}function oe(e){try{if((typeof e!=`object`||!e)&&typeof e!=`function`)return;let t=Reflect.get(e,`__destroy_into_raw`);typeof t==`function`&&Reflect.apply(t,e,[])}catch{}}function se(e,t){return e({module_or_path:t})}var ce=class{runtime;wasmInput=null;currentArchive=null;constructor(e,t={}){this.init=e,this.options=t,this.runtime=new re(()=>this.invokeConfigured(this.init),()=>this.invokeConfigured(this.options.reinit??this.init),le),this.runtime.onPoison(()=>this.dropPoisonedArchive())}setWasmInput(e){this.wasmInput=e,this.runtime.ensureReady().catch(()=>void 0)}setWasmUrl(e){this.setWasmInput(e)}get archive(){return this.currentArchive}setArchive(e){this.freeArchive(),this.currentArchive=e}disposeArchive(){this.freeArchive()}get poisoned(){return this.runtime.poisoned}async ensureReady(){await this.runtime.ensureReady()}run(e){return this.runtime.run(e)}poison(){this.runtime.poison(new ie(`WASM parser was recycled`))}invokeConfigured(e){return this.wasmInput===null?Promise.reject(Error(`WasmParserHost: setWasmInput was never called`)):se(e,this.wasmInput)}freeArchive(){this.currentArchive!==null&&this.options.freeArchive&&this.options.freeArchive(this.currentArchive),this.currentArchive=null}dropPoisonedArchive(){let e=this.currentArchive;this.currentArchive=null,oe(e)}};function le(e){return ae(e)?new ie(`WASM parser trapped and was recycled: ${e instanceof Error?e.message:String(e)}`):null}function ue(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>0}function de(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return ue(t.requiredBytes)&&ue(t.offeredBytes)&&t.requiredBytes>t.offeredBytes}var p=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 fe(e){if(e instanceof p)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`||!de(r)))return new p(r)}function pe(e,t,n){let r=fe(e);if(!(!r||r.offeredBytes!==t||r.requiredBytes>n))return r}te();const me=`OOXML_RESOURCE_LIMIT:`;function m(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function he(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return m(t.archiveEntryCount)&&m(t.declaredInflatedBytes)&&(t.largestInflatedEntryBytes===void 0||m(t.largestInflatedEntryBytes))&&m(t.distinctInflatedBytes)&&m(t.operationInflatedBytes)}function ge(e){let t;try{t=JSON.parse(new TextDecoder().decode(e))}catch{throw TypeError(`OOXML resource usage checkpoint is not valid JSON`)}if(!he(t))throw TypeError(`OOXML resource usage checkpoint is invalid`);return t}function _e(e){return e===`docx`||e===`xlsx`||e===`pptx`}function ve(e){return e===`container`||e===`decompression`||e===`parsing`||e===`serialization`||e===`layout`||e===`rendering`||e===`worker`}function h(e,t){return typeof e==`string`&&e.length>0&&e.length<=t&&!/[\\u0000-\\u001f\\u007f]/u.test(e)}function g(e){return h(e,128)&&/^[a-z0-9][a-z0-9-]*$/u.test(e)}function ye(e){return!h(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 _=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`}],[`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}]]),be=new Set([..._.keys()].map(e=>e.slice(0,e.indexOf(`:`)))),xe=new Set([..._.keys()].map(e=>e.slice(e.indexOf(`:`)+1)));function Se(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return!_e(t.format)||!h(t.operation,256)||!g(t.resource)||!g(t.metric)||!m(t.limit)||!m(t.observed)||typeof t.configurable!=`boolean`||!he(t.usage)?!1:!(`part`in t)||ye(t.part)}function v(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;if(!ve(t.stage)||!Se(t.violation))return!1;let n=t.violation,r=_.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:!(be.has(n.resource)&&xe.has(n.metric))}function Ce(e){return{archiveEntryCount:e.archiveEntryCount,declaredInflatedBytes:e.declaredInflatedBytes,...e.largestInflatedEntryBytes===void 0?{}:{largestInflatedEntryBytes:e.largestInflatedEntryBytes},distinctInflatedBytes:e.distinctInflatedBytes,operationInflatedBytes:e.operationInflatedBytes}}function we(e){if(!v(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:Ce(t.usage)}};return v(n)?n:void 0}function Te(e){let t=e.violation;return`OOXML resource limit exceeded${t.part?` for ${t.part}`:``}: ${t.metric} ${t.observed} > ${t.limit}`}function Ee(e){let t=e instanceof Error?e.message:String(e);if(!t.startsWith(me))return;let r;try{r=JSON.parse(t.slice(21))}catch{return}if(!r||typeof r!=`object`)return;let i=r;if(!(i.code!==`ooxml-resource-limit`||!v(i.details)))return new n(Te(i.details),i.details)}function De(e){if(e instanceof f)return{message:e.message,errorName:e.name,code:e.code,decodedImage:{metric:e.metric,limit:e.limit,observed:e.observed}};let r=fe(e);if(r)return{message:r.message,errorName:r.name,code:r.code,insufficientCredit:{requiredBytes:r.requiredBytes,offeredBytes:r.offeredBytes}};let i=e instanceof t||e instanceof n?e:Ee(e);if(i instanceof n){let e=we(i.details);return e?{message:typeof i.message==`string`?i.message:Te(e),errorName:`OoxmlResourceLimitError`,code:`ooxml-resource-limit`,resourceLimit:e}:{message:`Invalid OOXML resource-limit error payload`,errorName:`Error`}}if(i instanceof t)return{message:typeof i.message==`string`?i.message:String(i.message),errorName:h(i.name,128)?i.name:`OoxmlError`,...g(i.code)?{code:i.code}:{}};let a=e instanceof Error?e.message:String(e);if(typeof a==`string`&&a.startsWith(me))return{message:`Invalid OOXML resource-limit payload`,errorName:`Error`};let o=e instanceof Error?e:Error(a),s=o;return{message:typeof o.message==`string`?o.message:String(o.message),errorName:h(o.name,128)?o.name:`Error`,...typeof s.code==`string`?{code:s.code}:{}}}function y(e){try{return De(e)}catch{return{message:`Worker operation failed with an unreadable error`,errorName:`Error`}}}const Oe=new Set([`encrypted`,`invalid-password`,`unsupported-encryption`,`legacy-binary-format`,`not-ooxml`]);function ke(e){if(e.code===`ooxml-decoded-image-limit`&&e.decodedImage&&(e.decodedImage.metric===`image-pixels`||e.decodedImage.metric===`active-decoded-bytes`)&&m(e.decodedImage.limit)&&m(e.decodedImage.observed)&&e.decodedImage.observed>e.decodedImage.limit)return new f(e.decodedImage.metric,e.decodedImage.limit,e.decodedImage.observed);if(e.code===`ooxml-insufficient-credit`&&de(e.insufficientCredit))return new p(e.insufficientCredit);if(e.code===`ooxml-resource-limit`&&v(e.resourceLimit))return new n(e.message,e.resourceLimit);if(e.code&&Oe.has(e.code))return new t(e.code,e.message);let r=e.errorName===`TypeError`?TypeError(e.message):e.errorName===`RangeError`?RangeError(e.message):Error(e.message);return e.errorName&&(r.name=e.errorName),e.code!==void 0&&Object.assign(r,{code:e.code}),r}function Ae(e){return e.byteOffset===0&&e.byteLength===e.buffer.byteLength&&e.buffer instanceof ArrayBuffer?e.buffer:e.slice().buffer}Object.freeze({maxArchiveEntryBytes:134217728,maxTotalInflatedBytes:268435456,maxArchiveEntries:4096});function je(e){return[e.maxArchiveEntryBytes===null?0n:BigInt(e.maxArchiveEntryBytes),e.maxTotalInflatedBytes===null?0n:BigInt(e.maxTotalInflatedBytes),e.maxArchiveEntries===null?0n:BigInt(e.maxArchiveEntries)]}const b=`ooxml-pull-v1`;function x(e,t){if(!Number.isSafeInteger(e)||e<=0)throw RangeError(`${t} must be a positive safe integer`)}function Me(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 S=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,x(this.maxRetainedBytes,`max retained lease bytes`),x(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}},Ne=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){Me(e.sessionId),x(e.operationId,`operation id`),x(e.generation,`generation`),x(e.maxByteCredit,`max byte credit`),e.wireLeaseIdStart!==void 0&&x(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=y(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(x(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:b,...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){x(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(x(e,`byte credit`),e>this.options.maxByteCredit)throw RangeError(`byte credit exceeds host maximum`)}accepted(e,t,n=!1){return{kind:`accepted`,protocol:b,...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:b,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 C(e,t){if(!Number.isSafeInteger(e)||e<0)throw Error(`${t} must be a non-negative safe integer`)}function w(e,t,n){return C(e,`resource measurement`),C(t,`resource measurement`),C(n,`resource measurement limit`),e>n||t>n||t>n-e?n===2**53-1?n:n+1:e+t}function Pe(e,t=2**53-1){C(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=w(n,a,t),n>t)return n}return n}function T(e,t=2**53-1){C(t,`resource measurement limit`);let n=w(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=w(n,a,t),n>t)return n}return n}function E(e,t){return w(0,e,t)}function D(e,t=2**53-1,n=!1){if(C(t,`resource measurement limit`),e===null)return{jsonBytes:E(4,t),stringValueUtf8Bytes:0};if(typeof e==`string`)return{jsonBytes:T(e,t),stringValueUtf8Bytes:Pe(e,t)};if(typeof e==`boolean`)return{jsonBytes:E(e?4:5,t),stringValueUtf8Bytes:0};if(typeof e==`number`)return{jsonBytes:E((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=E(2,t),r=0;for(let i=0;i<e.length;i+=1){i!==0&&(n=w(n,1,t));let a=D(e[i],t,!0);n=w(n,a.jsonBytes,t),r=w(r,a.stringValueUtf8Bytes,t)}return{jsonBytes:n,stringValueUtf8Bytes:r}}if(typeof e==`object`){let n=E(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=w(n,1,t)),n=w(n,T(a,t),t),n=w(n,1,t);let e=D(o,t);n=w(n,e.jsonBytes,t),r=w(r,e.stringValueUtf8Bytes,t)}return{jsonBytes:n,stringValueUtf8Bytes:r}}return{jsonBytes:n?E(4,t):0,stringValueUtf8Bytes:0}}({...s,...ee});function*Fe(e){for(let t of e?.paragraphs??[])for(let e of t.runs)e.type===`text`&&(yield e.text)}function*Ie(e){for(let t of e?.paragraphs??[]){t.defFontFamily&&(yield t.defFontFamily);for(let e of t.runs)e.type===`text`&&(e.fontFamily&&(yield e.fontFamily),e.fontFamilyEa&&(yield e.fontFamilyEa),e.fontFamilySym&&(yield e.fontFamilySym))}}function*Le(e){for(let t of e.elements)if(t.type===`shape`)yield*Fe(t.textBody);else if(t.type===`table`)for(let e of t.rows)for(let t of e.cells)yield*Fe(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 Re=class e{scripts;families;constructor(e,t,n,r){this.majorFont=e,this.minorFont=t;let i=c(e)??c(t)??null;this.scripts=n??new u(i),this.families=r??new Set,e&&this.families.add(e),t&&this.families.add(t)}addSlide(e){this.scripts.addText(Le(e));for(let t of e.elements)if(t.type===`shape`)for(let e of Ie(t.textBody))this.families.add(e);else if(t.type===`table`)for(let e of t.rows)for(let t of e.cells)for(let e of Ie(t.textBody))this.families.add(e)}names(){return[...this.families,...this.scripts.names()]}withSlide(t){let n=new e(this.majorFont,this.minorFont,this.scripts.clone(),new Set(this.families));return n.addSlide(t),n}};const O=Object.freeze({archiveEntryCount:0,declaredInflatedBytes:0,distinctInflatedBytes:0,operationInflatedBytes:0}),k=67108864;function A(e,t){if(e!==null&&typeof e!=`string`)throw Error(`invalid PPTX presentation bootstrap ${t}`)}function ze(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 Be(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`invalid PPTX presentation bootstrap embedded font at ${t}`);let n=e;if(typeof n.fontName!=`string`||n.fontName.length===0||![`regular`,`bold`,`italic`,`boldItalic`].includes(n.style??``)||typeof n.partPath!=`string`||n.partPath.length===0||n.partPath.startsWith(`/`)||n.partPath.split(`/`).includes(`..`)||![`application/x-font-ttf`,`application/x-fontdata`].includes(n.contentType??``))throw Error(`invalid PPTX presentation bootstrap embedded font fields at ${t}`);return Object.freeze({fontName:n.fontName,style:n.style,partPath:n.partPath,contentType:n.contentType})}function Ve(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.embeddedFonts)||!Array.isArray(t.slides)||t.slides.length!==t.slideCount)throw Error(`invalid PPTX presentation bootstrap dimensions or slide count`);return A(t.defaultTextColor,`defaultTextColor`),A(t.majorFont,`majorFont`),A(t.minorFont,`minorFont`),A(t.hlinkColor,`hlinkColor`),A(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,embeddedFonts:Object.freeze(t.embeddedFonts.map(Be)),slides:Object.freeze(t.slides.map(ze))})}function He(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 Ue(e){return Object.freeze({...e.id===void 0?{}:{id:e.id},...e.authorId===void 0?{}:{authorId:e.authorId},...e.author===void 0?{}:{author:e.author},...e.date===void 0?{}:{date:e.date},...e.status===void 0?{}:{status:e.status},text:e.text})}function We(e){return Object.freeze({...e})}function Ge(e){return Object.freeze({...e.authorId===void 0?{}:{authorId:e.authorId},...e.modernAuthorId===void 0?{}:{modernAuthorId:e.modernAuthorId},...e.id===void 0?{}:{id:e.id},...e.index===void 0?{}:{index:e.index},...e.author===void 0?{}:{author:e.author},...e.date===void 0?{}:{date:e.date},...e.x===void 0?{}:{x:e.x},...e.y===void 0?{}:{y:e.y},...e.anchors?.length?{anchors:Object.freeze(e.anchors.map(We))}:{},...e.status===void 0?{}:{status:e.status},text:e.text,...e.replies?.length?{replies:Object.freeze(e.replies.map(Ue))}:{}})}function Ke(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(He)),...e.comments?.length?{comments:Object.freeze(e.comments.map(Ge))}:{}})}function j(e,t,r){if(!(e<=t))throw new n(`PPTX presentation preflight exceeded its hard limit of ${t} projected bytes`,{stage:`parsing`,violation:{format:`pptx`,operation:`presentation-preflight`,resource:`presentation-preflight`,metric:`projected-bytes`,limit:t,observed:Math.min(e,t+1),configurable:!1,usage:r}})}var qe=class{slideCountValue;slideWidthValue;slideHeightValue;defaultTextColorValue;majorFontValue;minorFontValue;hlinkColorValue;folHlinkColorValue;embeddedFontsValue;descriptors;slides=[];fonts;fontPreloadNames;fontProjectionBytes;projectionBytesValue;limit;pending=null;finished=null;constructor(e,t={}){let n=Ve(e),r=t.hardLimitForTesting??k;if(!Number.isSafeInteger(r)||r<=0||r>k)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.embeddedFontsValue=n.embeddedFonts,this.descriptors=[...n.slides],this.fonts=new Re(this.majorFontValue,this.minorFontValue),this.fontPreloadNames=Object.freeze(this.fonts.names()),this.fontProjectionBytes=D(this.fontPreloadNames,this.limit).jsonBytes,this.projectionBytesValue=D({slideCount:this.slideCountValue,slideWidth:this.slideWidthValue,slideHeight:this.slideHeightValue,defaultTextColor:this.defaultTextColorValue,majorFont:this.majorFontValue,minorFont:this.minorFontValue,hlinkColor:this.hlinkColorValue,folHlinkColor:this.folHlinkColorValue,embeddedFonts:this.embeddedFontsValue,remainingSlides:this.descriptors,slides:[],fontPreloadNames:this.fontPreloadNames},this.limit).jsonBytes,j(this.projectionBytesValue,this.limit,O)}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)}get latestSlide(){return this.slides[this.slides.length-1]}get currentFontPreloadNames(){return this.fontPreloadNames}snapshot(){if(this.finished)return this.finished;if(this.pending)throw Error(`PPTX presentation preflight has an uncommitted slide`);return 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,embeddedFonts:this.embeddedFontsValue,slides:Object.freeze([...this.slides]),fontPreloadNames:this.fontPreloadNames})}addSlide(e,t=O){this.prepareSlide(e,t).commit()}prepareSlide(e,t=O){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=Ke(e,r),a=this.fonts.withSlide(e),o=Object.freeze(a.names()),s=D(o,this.limit).jsonBytes,c=D(i,this.limit).jsonBytes,l=this.projectionBytesValue-this.fontProjectionBytes-D(r,this.limit).jsonBytes+4;l=w(l,s,this.limit),l=w(l,c,this.limit),this.slides.length!==0&&(l=w(l,1,this.limit));let ee=D({slide:i,fontPreloadNames:o},this.limit).jsonBytes,u=w(this.projectionBytesValue,ee,this.limit);j(Math.max(u,l),this.limit,t);let d={state:`prepared`,fact:i,fonts:a,fontNames:o,fontBytes:s,committedBytes:l};return this.pending=d,{projectedBytes:u,commit:()=>{if(d.state!==`committed`){if(d.state===`rolled-back`)throw Error(`PPTX presentation preflight cannot commit a rolled-back slide`);if(this.pending!==d)throw Error(`PPTX presentation preflight prepared slide is stale`);this.descriptors[n]=void 0,this.slides.push(d.fact),this.fonts=d.fonts,this.fontPreloadNames=d.fontNames,this.fontProjectionBytes=d.fontBytes,this.projectionBytesValue=d.committedBytes,d.state=`committed`,this.pending=null}},rollback:()=>{if(d.state!==`rolled-back`){if(d.state===`committed`)throw Error(`PPTX presentation preflight cannot roll back a committed slide`);if(this.pending!==d)throw Error(`PPTX presentation preflight prepared slide is stale`);d.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,embeddedFonts:this.embeddedFontsValue,slides:Object.freeze([...this.slides]),fontPreloadNames:this.fontPreloadNames}),this.descriptors=[],this.slides=[],this.projectionBytesValue=D(this.finished,this.limit).jsonBytes,this.finished}};function M(e){try{return ge(e(e=>e.slide_cursor_resource_usage()))}catch(e){if(String(e).includes(`slide cursor usage is unavailable`))return;throw e}}function Je(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,M(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 Ye=class{coordinatorGeneration=new S;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(),Ze(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||!N(n.identity,t))throw Error(`slide pull session open reservation is stale or missing`);let i,a=new Promise(e=>{i=e}),o=this.operationTail.then(()=>this.coordinator.enqueue(async()=>{if(n.canceled)throw Error(`slide pull session open was canceled`);let a,o=!1,s=new Ne({...t,maxByteCredit:r,coordinator:this.coordinator,driver:{pull:n=>{let i;try{i=this.executeArchive(r=>r.pull_slide(e,t.operationId,t.generation,n))}catch(e){throw pe(e,n,r)||(this.latchResourceFailure(e),e)}let s=Ae(i);return this.acceptSlide&&(a=JSON.parse(new TextDecoder().decode(new Uint8Array(s)))),o=!0,{payload:s,byteLength:s.byteLength,done:!0,transfer:[s]}},measureChunk:({payload:e})=>e.byteLength,acknowledge:()=>{if(!o)throw Error(`slide unit is not awaiting acknowledgement`);try{Je(this.executeArchive,t,e,a,this.acceptSlide)}catch(e){throw this.latchResourceFailure(e),e}o=!1,a=void 0,this.sessions.delete(t.sessionId),i()},cancel:async()=>{try{this.archive()&&await this.executeArchive(e=>e.cancel_slide())}finally{a=void 0,o=!1,this.sessions.delete(t.sessionId),i()}},close:async()=>{try{this.archive()&&await this.executeArchive(e=>e.cancel_slide())}finally{a=void 0,o=!1,this.sessions.delete(t.sessionId),i()}},resourceUsage:()=>{try{return this.readResourceUsage()}catch(e){throw this.latchResourceFailure(e),e}}}});this.sessions.set(t.sessionId,{host:s,identity:t}),this.pendingOpens.delete(t.sessionId)}));this.operationTail=o.then(()=>a,()=>void 0);try{await o}catch(e){throw this.pendingOpens.delete(t.sessionId),i(),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=N(r.identity,e);return n&&(r.canceled=!0),t(n?{protocol:b,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:b,kind:`accepted`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,command:e.kind}),Promise.resolve()):(t({protocol:b,kind:`error`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:y(Error(`slide pull session is not open`))}),Promise.resolve())}async dispatchSafely(e,t){try{await this.dispatch(e,t)}catch(n){try{t({protocol:b,kind:`error`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:y(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:b,kind:`close`,...n,requestId:e++},e=>{e.kind===`error`&&(r=ke(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 S,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&&!N(t,e)?this.staleLifecycleResponse(e):{protocol:b,kind:`accepted`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,command:e.kind}}return{protocol:b,kind:`error`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:y(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:b,kind:`close`,...e,requestId:1},()=>void 0);return}let n=this.pendingOpens.get(e.sessionId);n&&N(n.identity,e)&&(n.canceled=!0)}readResourceUsage(){return M(this.executeArchive)}latchResourceFailure(e){let t=e instanceof n?e:Ee(e);t&&(this.resourceFailure??=t)}staleLifecycleResponse(e){return{protocol:b,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 Xe(e){return!!e&&typeof e==`object`&&e.protocol===`ooxml-pull-v1`}function Ze(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 N(e,t){return e.sessionId===t.sessionId&&e.operationId===t.operationId&&e.generation===t.generation}var P=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,F.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_font(e){let t=H(e,J.__wbindgen_malloc,J.__wbindgen_realloc),n=q,r=J.pptxarchive_extract_font(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_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,r){let i=et(e,J.__wbindgen_malloc),a=q,o=J.pptxarchive_new(i,a,!V(t),V(t)?BigInt(0):t,!V(n),V(n)?BigInt(0):n,!V(r),V(r)?BigInt(0):r);if(o[2])throw U(o[1]);return this.__wbg_ptr=o[0]>>>0,F.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&&(P.prototype[Symbol.dispose]=P.prototype.free);function Qe(){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;$e().setInt32(e+4,i,!0),$e().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 F=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 $e(){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,tt(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 et(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 tt(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 nt(e,t){return J=e.exports,L=null,z=null,J.__wbindgen_start(),J}async function rt(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 it(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=Qe();(typeof e==`string`||typeof Request==`function`&&e instanceof Request||typeof URL==`function`&&e instanceof URL)&&(e=fetch(e));let{instance:n,module:r}=await rt(await e,t);return nt(n,r)}async function at(e){return J=void 0,L=null,z=null,it(e)}const Y=new ce(it,{freeArchive:e=>e.free(),reinit:at});let X=null,Z=`empty`;function ot(){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 Ye(()=>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(Xe(t)){await Q.dispatchSafely(t,$);return}if(t.kind===`init`){Y.setWasmInput(ne(t.wasmUrl)??t.wasmUrl);return}let n=t.id,r=!1;try{if(t.kind===`openSlideSession`&&Q.reserveOpen(t),t.kind===`parse`&&(ot(),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,...y(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,i]=je(t.resourcePolicy),a=Y.run(()=>{let n=new P(new Uint8Array(t.buffer),e,r,i);return Y.setArchive(n),JSON.parse(new TextDecoder().decode(n.presentation_bootstrap()))});X=t.progressiveLayout?null:new qe(a),$({kind:`presentationOpened`,id:n,bootstrap:a}),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===`extractFont`){let r=Y.run(()=>e.extract_font(t.path).buffer);$({kind:`fontExtracted`,id:n,bytes:r},[r]);return}if(t.kind===`resourceUsage`){$({kind:`resourceUsage`,id:n,usage:ge(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,...y(e)})}catch{}}};", ht = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", mt], { type: "text/javascript;charset=utf-8" });
592
+ function gt(e) {
593
+ let t;
594
+ try {
595
+ if (t = ht && (self.URL || self.webkitURL).createObjectURL(ht), !t) throw "";
596
+ let n = new Worker(t, {
597
+ type: "module",
598
+ name: e?.name
599
+ });
600
+ return n.addEventListener("error", () => {
601
+ (self.URL || self.webkitURL).revokeObjectURL(t);
602
+ }), n;
603
+ } catch {
604
+ return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(mt), {
605
+ type: "module",
606
+ name: e?.name
607
+ });
608
+ }
609
+ }
610
+ //#endregion
611
+ //#region packages/pptx/src/wasm/pptx_parser_bg.wasm?url
612
+ var _t = new URL("pptx_parser_bg.wasm", import.meta.url).href, G = 65536, vt = 16384, yt = new Set(["line", "straightconnector1"]);
613
+ function bt(e, t) {
614
+ let n = e.x + e.width / 2, r = e.y + e.height / 2, i = -e.rotation * Math.PI / 180, a = Math.cos(i), o = Math.sin(i), s = t.x - n, c = t.y - r, l = n + a * s - o * c, u = r + o * s + a * c;
615
+ return e.flipH && (l = 2 * n - l), e.flipV && (u = 2 * r - u), {
616
+ x: l,
617
+ y: u
618
+ };
619
+ }
620
+ function xt(e, t, n) {
621
+ let r = n.x - t.x, i = n.y - t.y, a = r * r + i * i;
622
+ if (a === 0) return Math.hypot(e.x - t.x, e.y - t.y);
623
+ let o = Math.max(0, Math.min(1, ((e.x - t.x) * r + (e.y - t.y) * i) / a));
624
+ return Math.hypot(e.x - (t.x + o * r), e.y - (t.y + o * i));
625
+ }
626
+ function St(e, t, n = 0) {
627
+ if (!Number.isFinite(t.x) || !Number.isFinite(t.y)) return !1;
628
+ let r = bt(e, t), i = Number.isFinite(n) && n > 0 ? n : 0;
629
+ if (e.type === "shape" && (yt.has(e.geometry.toLowerCase()) || e.width === 0 || e.height === 0)) return xt(r, {
630
+ x: e.x,
631
+ y: e.y
632
+ }, {
633
+ x: e.x + e.width,
634
+ y: e.y + e.height
635
+ }) <= i;
636
+ let a = Math.min(e.x, e.x + e.width), o = Math.max(e.x, e.x + e.width), s = Math.min(e.y, e.y + e.height), c = Math.max(e.y, e.y + e.height);
637
+ return r.x >= a && r.x <= o && r.y >= s && r.y <= c;
638
+ }
639
+ function* Ct(e) {
640
+ if (e) for (let t of e.paragraphs) {
641
+ let e = !0;
642
+ for (let n of t.runs) {
643
+ let t = n.type === "text" ? n.text : n.type === "break" ? "\n" : "[equation]";
644
+ t && (yield {
645
+ text: t,
646
+ beginsPart: e
647
+ }, e = !1);
648
+ }
649
+ }
650
+ }
651
+ function* wt(e) {
652
+ if (e.type === "shape") {
653
+ yield* Ct(e.textBody);
654
+ return;
655
+ }
656
+ if (e.type === "table") {
657
+ for (let t of e.rows) for (let e of t.cells) yield* Ct(e.textBody);
658
+ return;
659
+ }
660
+ }
661
+ function Tt(e, t) {
662
+ let n = Math.min(e.length, t);
663
+ if (n > 0 && n < e.length) {
664
+ let t = e.charCodeAt(n - 1), r = e.charCodeAt(n);
665
+ t >= 55296 && t <= 56319 && r >= 56320 && r <= 57343 && n--;
666
+ }
667
+ return e.slice(0, n);
668
+ }
669
+ function Et(e, t = vt) {
670
+ if (!Number.isFinite(t) || t < 0) throw RangeError("maxTextCharacters must be a finite non-negative number.");
671
+ let n = Math.min(G, Math.floor(t)), r = e.text, i = r === void 0 ? void 0 : Tt(r, n), a = r !== void 0 && i.length < r.length;
672
+ return {
673
+ ...structuredClone(e),
674
+ ...i === void 0 ? {} : { text: i },
675
+ truncated: e.truncated || a,
676
+ truncationReasons: e.truncated || a ? ["text"] : [],
677
+ textCharacters: i?.length ?? 0,
678
+ maxTextCharacters: n
679
+ };
680
+ }
681
+ function Dt(e, t) {
682
+ let n = [], r = 0, i = !1, a = !1;
683
+ for (let o of e) {
684
+ if (a = !0, o.beginsPart && n.length > 0) {
685
+ if (r >= t) {
686
+ i = !0;
687
+ break;
688
+ }
689
+ n.push("\n"), r++;
690
+ }
691
+ let e = Math.max(0, t - r), s = Tt(o.text, e);
692
+ if (n.push(s), r += s.length, s.length < o.text.length) {
693
+ i = !0;
694
+ break;
695
+ }
696
+ }
697
+ return a ? {
698
+ text: n.join(""),
699
+ truncated: i,
700
+ textCharacters: r
701
+ } : {
702
+ truncated: !1,
703
+ textCharacters: 0
704
+ };
705
+ }
706
+ function Ot(e, t, n, r = {}) {
707
+ if (!Number.isFinite(n.x) || !Number.isFinite(n.y)) throw RangeError("PPTX hit-test point must contain finite coordinates.");
708
+ let i = r.maxTextCharacters ?? vt;
709
+ if (!Number.isFinite(i) || i < 0) throw RangeError("maxTextCharacters must be a finite non-negative number.");
710
+ let a = Math.min(G, Math.floor(i)), o = r.tolerance ?? 0;
711
+ if (!Number.isFinite(o) || o < 0) throw RangeError("tolerance must be a finite non-negative number.");
712
+ for (let r = t.elements.length - 1; r >= 0; r--) {
713
+ let i = t.elements[r];
714
+ if (!St(i, n, o)) continue;
715
+ let s = i.type === "chart" ? se(i.chart, a) : Dt(wt(i), a);
716
+ return {
717
+ format: "pptx",
718
+ kind: "element",
719
+ slideIndex: e,
720
+ elementIndex: r,
721
+ origin: t.elementSources?.[r]?.origin ?? "unknown",
722
+ elementType: i.type,
723
+ point: { ...n },
724
+ bounds: {
725
+ x: i.x,
726
+ y: i.y,
727
+ width: i.width,
728
+ height: i.height,
729
+ rotation: i.rotation,
730
+ flipH: i.flipH,
731
+ flipV: i.flipV
732
+ },
733
+ ...i.type === "shape" ? {
734
+ ...i.id === void 0 ? {} : { shapeId: i.id },
735
+ ...i.name === void 0 ? {} : { name: i.name },
736
+ geometry: i.geometry
737
+ } : {},
738
+ ...s.text === void 0 ? {} : { text: s.text },
739
+ ...i.type === "picture" ? { mimeType: i.mimeType } : {},
740
+ ...i.type === "media" ? {
741
+ mimeType: i.mimeType,
742
+ mediaKind: i.mediaKind
743
+ } : {},
744
+ ...i.type === "table" ? {
745
+ rowCount: i.rows.length,
746
+ columnCount: i.cols.length
747
+ } : {},
748
+ ...i.type === "chart" ? { seriesCount: i.chart.series.length } : {},
749
+ truncated: s.truncated,
750
+ truncationReasons: s.truncated ? ["text"] : [],
751
+ textCharacters: s.textCharacters,
752
+ maxTextCharacters: a
753
+ };
754
+ }
755
+ return null;
756
+ }
757
+ function kt(e, t) {
758
+ let n = new Set(t.filter((e) => e.length > 0));
759
+ if (n.size === 0) return Object.freeze([]);
760
+ let r = /* @__PURE__ */ new Map();
761
+ for (let [t, i] of e.elements.entries()) {
762
+ let a = i.id;
763
+ if (!a || !n.has(a)) continue;
764
+ let o = e.elementSources?.[t]?.origin ?? "unknown", s = o === "slide" ? 3 : o === "layout" ? 2 : +(o === "master"), c = r.get(a), l = c?.origin === "slide" ? 3 : c?.origin === "layout" ? 2 : +(c?.origin === "master");
765
+ c && l > s || r.set(a, Object.freeze({
766
+ elementId: a,
767
+ elementIndex: t,
768
+ origin: o,
769
+ elementType: i.type,
770
+ bounds: Object.freeze({
771
+ x: i.x,
772
+ y: i.y,
773
+ width: i.width,
774
+ height: i.height,
775
+ rotation: i.rotation,
776
+ flipH: i.flipH,
777
+ flipV: i.flipV
778
+ })
779
+ }));
780
+ }
781
+ return Object.freeze(t.flatMap((e) => {
782
+ let t = r.get(e);
783
+ return t ? [t] : [];
784
+ }));
785
+ }
786
+ //#endregion
787
+ //#region packages/pptx/src/presentation-layout-events.ts
788
+ var K = /* @__PURE__ */ new WeakMap();
789
+ function q(e, t) {
790
+ let n = Object.freeze({ ...t });
791
+ for (let t of [...K.get(e) ?? []]) try {
792
+ t.notify(n);
793
+ } catch (e) {
794
+ try {
795
+ t.report(e);
796
+ } catch {}
797
+ }
798
+ }
799
+ function At(e, t, n, r) {
800
+ let i = K.get(e);
801
+ i || (i = /* @__PURE__ */ new Set(), K.set(e, i));
802
+ let a = Object.freeze({
803
+ notify: n,
804
+ report: r
805
+ });
806
+ i.add(a);
807
+ try {
808
+ n(Object.freeze({ ...t() }));
809
+ } catch (e) {
810
+ try {
811
+ r(e);
812
+ } catch {}
813
+ }
814
+ return () => {
815
+ i?.delete(a), i?.size === 0 && K.delete(e);
816
+ };
817
+ }
818
+ //#endregion
819
+ //#region packages/pptx/src/worker-task-scheduler.ts
820
+ function J() {
821
+ return new Promise((e) => {
822
+ let t = new MessageChannel();
823
+ t.port1.onmessage = () => {
824
+ t.port1.close(), t.port2.close(), e();
825
+ }, t.port2.postMessage(void 0);
826
+ });
827
+ }
828
+ //#endregion
829
+ //#region packages/pptx/src/presentation.ts
830
+ function jt() {
831
+ let e, t;
832
+ return {
833
+ promise: new Promise((n, r) => {
834
+ e = n, t = r;
835
+ }),
836
+ resolve: e,
837
+ reject: t
838
+ };
839
+ }
840
+ var Y = class e {
841
+ _metrics = null;
842
+ _worker;
843
+ _bridge;
844
+ _mode = "main";
845
+ _bootstrap = null;
846
+ _preflight = null;
847
+ _availableSlideCount = 0;
848
+ _layoutLifecycle = new De();
849
+ _layoutObservers = new ke();
850
+ _layoutCompletion = null;
851
+ _parseRequestId = null;
852
+ _progressive = null;
853
+ _progressiveWatchdog;
854
+ _progressiveWatchdogMs;
855
+ _layoutWaiters = /* @__PURE__ */ new Set();
856
+ _slides = null;
857
+ _slidePullClient = null;
858
+ _resourceFailure = null;
859
+ _slidePartIndex = null;
860
+ _rawParts = new Te({
861
+ maxEntries: 64,
862
+ maxBytes: v
863
+ });
864
+ _googleFontFaces = [];
865
+ _embeddedFontFaces = [];
866
+ _embeddedFontAliases = /* @__PURE__ */ new Map();
867
+ _embeddedFontAuthoredFamilies = /* @__PURE__ */ new Map();
868
+ _destroyed = !1;
869
+ _fetchImage = (e, t) => this.getImage(e, t);
870
+ _fetchMedia = (e) => this.getMedia(e);
871
+ _math;
872
+ _threeD;
873
+ _regionMap;
874
+ _chartEx;
875
+ constructor(e, t, n) {
876
+ this._worker = e, this._mode = t, this._bridge = new ne(this._worker, {
877
+ correlate: (e) => "protocol" in e && e.protocol === "ooxml-pull-v1" ? e.requestId : "id" in e ? e.id : void 0,
878
+ toError: (e) => !("protocol" in e) && e.kind === "error" ? y(e) : void 0,
879
+ onUnsolicited: (e) => this._onWorkerLayoutPush(e)
880
+ });
881
+ let r = new URL(n ?? _t, location.href).href;
882
+ this._bridge.post({
883
+ kind: "init",
884
+ wasmUrl: r
885
+ });
886
+ }
887
+ _assertResourceHealthy() {
888
+ if (this._resourceFailure) throw this._resourceFailure;
889
+ }
890
+ _rethrowWithResourceFailure(e) {
891
+ let t = e instanceof h ? e : m(e);
892
+ throw t ? (this._resourceFailure ??= t, this._resourceFailure) : e;
893
+ }
894
+ static async load(t, r = {}) {
895
+ let i = p(r), a = r.mode ?? "main", o = new g({
896
+ enabled: !0,
897
+ format: "pptx",
898
+ mode: a,
899
+ policy: i.policy,
900
+ onMetrics: i.onResourceMetrics,
901
+ emitToConsole: i.debug
902
+ });
903
+ try {
904
+ if (a === "worker" && (typeof Worker > "u" || typeof OffscreenCanvas > "u")) throw Error("mode: 'worker' requires Worker and OffscreenCanvas support");
905
+ let s;
906
+ if (typeof t == "string") {
907
+ let e = await fetch(t);
908
+ if (!e.ok) throw Error(`Failed to fetch: ${e.status} ${e.statusText}`);
909
+ s = await e.arrayBuffer();
910
+ } else s = t;
911
+ s = re(await ae(s, r.password)), o.setSourceBytes(s.byteLength), o.checkpoint("container ready");
912
+ let c = a === "worker" ? (await import("./render-worker-host-FJ19-fUI.js")).createRenderWorker() : new gt(), l = a === "worker" ? Pe(r) : void 0, u;
913
+ try {
914
+ u = new e(c, a, r.wasmUrl), u._metrics = o, r.math && a === "worker" && !l?.math && console.warn("[ooxml] a custom math renderer cannot cross the worker boundary; equations will be skipped in mode: 'worker'. Use the math renderer from @silurus/ooxml/math."), r.threeD && a === "worker" && !l?.threeD && console.warn("[ooxml] a custom 3-D chart renderer cannot cross the worker boundary; charts use their 2-D family fallback in mode: 'worker'. Use the renderer from @silurus/ooxml/three-d."), u._math = a === "worker" ? void 0 : r.math, u._threeD = a === "worker" ? void 0 : r.threeD, r.regionMap && a === "worker" && !l?.regionMap && console.warn("[ooxml] a custom Region Map renderer cannot cross the worker boundary; geospatial charts use the unsupported-chart placeholder in mode: 'worker'. Use the renderer from @silurus/ooxml/region-map."), u._regionMap = a === "worker" ? void 0 : r.regionMap, r.chartEx && a === "worker" && !l?.chartEx && console.warn("[ooxml] a custom ChartEx renderer cannot cross the worker boundary; ChartEx charts use the unsupported-chart placeholder in mode: 'worker'. Use the renderer from @silurus/ooxml/chart-ex."), u._chartEx = a === "worker" ? void 0 : r.chartEx;
915
+ let t = r.progressiveLayout ? {
916
+ onProgress: r.onLayoutProgress,
917
+ onPartial: r.onLayoutPartial,
918
+ onComplete: r.onLayoutComplete,
919
+ firstPublication: jt(),
920
+ published: !1,
921
+ deferred: !1,
922
+ settled: !1
923
+ } : void 0;
924
+ return await u._parse(s, i.policy, !!r.useGoogleFonts, r.workerTimeoutMs, (e) => o.observeUsage(e), l, t), o.checkpoint("presentation preflight ready"), a === "main" && r.useGoogleFonts && u._preflight && !t && (u._googleFontFaces = await Ce(pt(u._preflight.fontPreloadNames, u._embeddedFontAliases), n)), o.succeed({ slides: u.slideCount }), u;
925
+ } catch (e) {
926
+ let t = u;
927
+ throw ie(c, t ? () => t.destroy() : void 0), e;
928
+ }
929
+ } catch (e) {
930
+ throw o.fail(e), e;
931
+ }
932
+ }
933
+ async _parse(e, n, r = !1, i, a, o, l) {
934
+ if (l) {
935
+ this._progressive = l, this._mode === "worker" ? await this._parseWorkerProgressively(e, n, r, i, a, o, l) : await this._parseMainProgressively(e, n, r, i, a, l);
936
+ return;
937
+ }
938
+ let u = await this._bridge.request((t) => this._mode === "worker" ? {
939
+ kind: "parse",
940
+ id: t,
941
+ buffer: e,
942
+ resourcePolicy: n,
943
+ useGoogleFonts: r,
944
+ renderers: o
945
+ } : {
946
+ kind: "parse",
947
+ id: t,
948
+ buffer: e,
949
+ resourcePolicy: n
950
+ }, [e], { timeoutMs: i });
951
+ if (this._mode === "worker") {
952
+ let e = u;
953
+ e.usage && a?.(e.usage), this._preflight = c(u.preflight), this._bootstrap = this._preflight, this._availableSlideCount = this._preflight.slideCount;
954
+ return;
955
+ }
956
+ let f = t(u.bootstrap);
957
+ this._bootstrap = f;
958
+ let p = ft(f.embeddedFonts, (e) => this.getFontBytes(e)).then((e) => {
959
+ this._destroyed ? j(e.faces) : (this._embeddedFontFaces = e.faces, this._embeddedFontAliases = e.aliases, this._embeddedFontAuthoredFamilies = e.authoredFamilies);
960
+ });
961
+ this._slidePullClient = new d({
962
+ slideCount: f.slideCount,
963
+ transport: this._bridge.transport(s),
964
+ open: async (e, t, n) => {
965
+ await this._bridge.request((n) => ({
966
+ kind: "openSlideSession",
967
+ id: n,
968
+ slideIndex: e,
969
+ ...t
970
+ }), void 0, { timeoutMs: n });
971
+ },
972
+ onUsage: a
973
+ });
974
+ let m;
975
+ try {
976
+ for (let e = 0; e < f.slideCount; e += 1) await this._slidePullClient.load(e, !1, i);
977
+ m = await this._bridge.request((e) => ({
978
+ kind: "finishPresentationPreflight",
979
+ id: e
980
+ }), void 0, { timeoutMs: i }), await p;
981
+ } catch (e) {
982
+ throw p.catch(() => void 0), e;
983
+ }
984
+ this._preflight = c(m.preflight), this._availableSlideCount = this._preflight.slideCount, this._slides = new lt({
985
+ slideCount: this._preflight.slideCount,
986
+ maxCachedSlides: 8,
987
+ maxCachedStructuralBytes: _,
988
+ loadSlide: async (e) => {
989
+ let t = await this._slidePullClient?.load(e, !0, i);
990
+ if (!t) throw Error("PPTX slide pull client is unavailable");
991
+ return t;
992
+ }
993
+ });
994
+ }
995
+ async _parseMainProgressively(e, r, i, a, o, s) {
996
+ let c = t((await this._bridge.request((t) => ({
997
+ kind: "parse",
998
+ id: t,
999
+ buffer: e,
1000
+ resourcePolicy: r,
1001
+ progressiveLayout: !0
1002
+ }), [e], { timeoutMs: a })).bootstrap);
1003
+ this._bootstrap = c;
1004
+ let u = ft(c.embeddedFonts, (e) => this.getFontBytes(e)).then((e) => {
1005
+ this._destroyed ? j(e.faces) : (this._embeddedFontFaces = e.faces, this._embeddedFontAliases = e.aliases, this._embeddedFontAuthoredFamilies = e.authoredFamilies);
1006
+ });
1007
+ this._slidePullClient = this._createSlidePullClient(c.slideCount, a, o), this._slides = new lt({
1008
+ slideCount: c.slideCount,
1009
+ maxCachedSlides: 8,
1010
+ maxCachedStructuralBytes: _,
1011
+ loadSlide: async (e) => {
1012
+ let t = await this._slidePullClient?.load(e, !0, a);
1013
+ if (!t) throw Error("PPTX slide pull client is unavailable");
1014
+ return t;
1015
+ }
1016
+ });
1017
+ let d = new l(c), f = /* @__PURE__ */ new Set(), p = async () => {
1018
+ if (await u, !i) return;
1019
+ let e = pt(d.currentFontPreloadNames, this._embeddedFontAliases).filter((e) => !!e && !f.has(e));
1020
+ if (e.length !== 0) {
1021
+ for (let t of e) f.add(t);
1022
+ this._googleFontFaces.push(...await Ce(e, n));
1023
+ }
1024
+ };
1025
+ this._layoutCompletion = (async () => {
1026
+ for (let e = 0; e < c.slideCount; e += 1) await this._slides.withSlide(e, (e) => {
1027
+ d.addSlide(e);
1028
+ }), await p(), this._applyProgressivePrefix(d.snapshot(), s), e === 0 && s.deferred && await J();
1029
+ await u, this._finishProgressiveLayout(d.finish(), s);
1030
+ })().then(() => void 0, (e) => this._failProgressiveLayout(e, s)), await s.firstPublication.promise;
1031
+ }
1032
+ async _parseWorkerProgressively(e, t, n, r, i, a, o) {
1033
+ this._progressiveWatchdogMs = r;
1034
+ let s = this._bridge.request((r) => (this._parseRequestId = r, {
1035
+ kind: "parse",
1036
+ id: r,
1037
+ buffer: e,
1038
+ resourcePolicy: t,
1039
+ useGoogleFonts: n,
1040
+ renderers: a,
1041
+ progressiveLayout: !0
1042
+ }), [e], { timeoutMs: !1 });
1043
+ this._rearmProgressiveWatchdog(), this._layoutCompletion = s.then((e) => {
1044
+ this._parseRequestId = null;
1045
+ let t = e;
1046
+ t.usage && i?.(t.usage), this._finishProgressiveLayout(c(t.preflight), o);
1047
+ }, (e) => {
1048
+ this._parseRequestId = null, this._failProgressiveLayout(e, o);
1049
+ }), await o.firstPublication.promise;
1050
+ }
1051
+ _createSlidePullClient(e, t, n) {
1052
+ return new d({
1053
+ slideCount: e,
1054
+ transport: this._bridge.transport(s),
1055
+ open: async (e, n, r) => {
1056
+ await this._bridge.request((t) => ({
1057
+ kind: "openSlideSession",
1058
+ id: t,
1059
+ slideIndex: e,
1060
+ ...n
1061
+ }), void 0, { timeoutMs: r ?? t });
1062
+ },
1063
+ onUsage: n
1064
+ });
1065
+ }
1066
+ _onWorkerLayoutPush(e) {
1067
+ if (!(!("kind" in e) || e.kind !== "presentationLayoutPartial" || e.forId !== this._parseRequestId || !this._progressive)) try {
1068
+ this._rearmProgressiveWatchdog(), e.usage && this._metrics?.observeUsage(e.usage), e.bootstrap && (this._bootstrap = t(e.bootstrap));
1069
+ let n = this._bootstrap;
1070
+ if (!n) throw Error("PPTX progressive worker published before bootstrap");
1071
+ let r = this._preflight?.slides ?? [];
1072
+ if (e.availableSlides !== r.length + 1 || e.slide.index !== r.length) throw Error("PPTX progressive worker published a non-sequential slide");
1073
+ this._applyProgressivePrefix(u({
1074
+ ...n,
1075
+ slides: [...r, e.slide],
1076
+ fontPreloadNames: e.fontPreloadNames
1077
+ }), this._progressive), J().then(() => {
1078
+ this._destroyed || this._parseRequestId !== e.forId || this._bridge.post({
1079
+ kind: "continuePresentationPreflight",
1080
+ forId: e.forId,
1081
+ availableSlides: e.availableSlides
1082
+ });
1083
+ }).catch((t) => {
1084
+ this._destroyed || this._parseRequestId !== e.forId || !this._progressive || (this._failProgressiveLayout(t, this._progressive), this._bridge.terminate());
1085
+ });
1086
+ } catch (e) {
1087
+ this._failProgressiveLayout(e, this._progressive), this._bridge.terminate();
1088
+ }
1089
+ }
1090
+ _applyProgressivePrefix(e, t) {
1091
+ if (!(t.settled || this._destroyed)) {
1092
+ if (this._preflight = e, this._availableSlideCount = e.slides.length, !t.published && e.slides.length === e.slideCount) {
1093
+ t.published = !0, t.deferred = !1;
1094
+ return;
1095
+ }
1096
+ if (this._layoutLifecycle.begin(), this._wakeLayoutWaiters(), this._layoutObservers.notify("onLayoutProgress", t.onProgress, { committedUnits: this._availableSlideCount }), q(this, {
1097
+ availableSlides: this._availableSlideCount,
1098
+ slideCount: this.slideCount,
1099
+ exact: !1,
1100
+ complete: !1
1101
+ }), !t.published) {
1102
+ t.published = !0, t.deferred = e.slides.length < e.slideCount, t.firstPublication.resolve();
1103
+ return;
1104
+ }
1105
+ this._layoutObservers.notify("onLayoutPartial", t.onPartial, {
1106
+ availableUnits: this._availableSlideCount,
1107
+ totalUnits: this.slideCount,
1108
+ exact: !1
1109
+ });
1110
+ }
1111
+ }
1112
+ _finishProgressiveLayout(e, t) {
1113
+ t.settled || this._destroyed || (t.settled = !0, this._clearProgressiveWatchdog(), this._preflight = e, this._bootstrap ??= e, this._availableSlideCount = e.slideCount, this._layoutLifecycle.succeed(), this._wakeLayoutWaiters(), t.firstPublication.resolve(), q(this, {
1114
+ availableSlides: this._availableSlideCount,
1115
+ slideCount: this.slideCount,
1116
+ exact: !0,
1117
+ complete: !0
1118
+ }), t.deferred && this._layoutObservers.notify("onLayoutComplete", t.onComplete));
1119
+ }
1120
+ _failProgressiveLayout(e, t) {
1121
+ if (t.settled || (t.settled = !0, this._clearProgressiveWatchdog(), this._destroyed)) return;
1122
+ if (!t.published) {
1123
+ t.firstPublication.reject(e);
1124
+ return;
1125
+ }
1126
+ let n = this._layoutLifecycle.fail(e);
1127
+ this._wakeLayoutWaiters(), q(this, {
1128
+ availableSlides: this._availableSlideCount,
1129
+ slideCount: this.slideCount,
1130
+ exact: !1,
1131
+ complete: !1,
1132
+ error: n
1133
+ }), this._layoutObservers.notify("onLayoutComplete", t.onComplete, n);
1134
+ }
1135
+ _wakeLayoutWaiters() {
1136
+ for (let e of this._layoutWaiters) e();
1137
+ this._layoutWaiters.clear();
1138
+ }
1139
+ _rearmProgressiveWatchdog() {
1140
+ this._progressiveWatchdogMs !== void 0 && (clearTimeout(this._progressiveWatchdog), this._progressiveWatchdog = setTimeout(() => {
1141
+ let e = this._progressive, t = this._progressiveWatchdogMs;
1142
+ if (!e || e.settled || t === void 0 || this._destroyed) return;
1143
+ let n = /* @__PURE__ */ Error(`worker layout produced no progress for ${t}ms`);
1144
+ this._failProgressiveLayout(n, e), this._bridge.terminate();
1145
+ }, this._progressiveWatchdogMs));
1146
+ }
1147
+ _clearProgressiveWatchdog() {
1148
+ clearTimeout(this._progressiveWatchdog), this._progressiveWatchdog = void 0, this._progressiveWatchdogMs = void 0;
1149
+ }
1150
+ async _waitForSlide(e) {
1151
+ for (; !this._destroyed && e >= this._availableSlideCount && !this._layoutLifecycle.settled;) await new Promise((e) => this._layoutWaiters.add(e));
1152
+ e >= this._availableSlideCount && await this.waitUntilLayoutComplete();
1153
+ }
1154
+ _assertSlideIndex(e) {
1155
+ if (!Number.isInteger(e) || e < 0 || e >= this.slideCount) throw Error(`Slide index ${e} out of range (count: ${this.slideCount})`);
1156
+ }
1157
+ get slideCount() {
1158
+ return this._bootstrap?.slideCount ?? this._preflight?.slideCount ?? 0;
1159
+ }
1160
+ get availableSlideCount() {
1161
+ return this._availableSlideCount;
1162
+ }
1163
+ get layoutComplete() {
1164
+ return this._layoutLifecycle.complete;
1165
+ }
1166
+ async waitUntilLayoutComplete() {
1167
+ this._layoutCompletion && await this._layoutCompletion, this._layoutLifecycle.throwIfFailed();
1168
+ }
1169
+ get slideWidth() {
1170
+ return this._bootstrap?.slideWidth ?? this._preflight?.slideWidth ?? 0;
1171
+ }
1172
+ get slideHeight() {
1173
+ return this._bootstrap?.slideHeight ?? this._preflight?.slideHeight ?? 0;
1174
+ }
1175
+ get mode() {
1176
+ return this._mode;
1177
+ }
1178
+ getNotes(e) {
1179
+ return Number.isInteger(e) ? this._preflight?.slides[e]?.notes ?? null : null;
1180
+ }
1181
+ getComments(e) {
1182
+ return Number.isInteger(e) ? this._preflight?.slides[e]?.comments ?? [] : [];
1183
+ }
1184
+ isHidden(e) {
1185
+ return Number.isInteger(e) ? this._preflight?.slides[e]?.hidden ?? !1 : !1;
1186
+ }
1187
+ _partNames() {
1188
+ return (this._bootstrap?.slides ?? this._preflight?.slides ?? []).map((e) => e.partName);
1189
+ }
1190
+ _partIndex() {
1191
+ return this._slidePartIndex ||= ot(this._partNames()), this._slidePartIndex;
1192
+ }
1193
+ getSlideIndexByPartName(e) {
1194
+ return this._partIndex().get(e);
1195
+ }
1196
+ resolveInternalTarget(e, t = 0) {
1197
+ return ct(e, this._partIndex(), t);
1198
+ }
1199
+ async renderSlide(e, t, n = {}) {
1200
+ this._assertResourceHealthy();
1201
+ try {
1202
+ if (this._mode === "worker") throw Error("renderSlide(canvas) is unavailable in mode: 'worker'; use renderSlideToBitmap() and paint it via an ImageBitmapRenderingContext");
1203
+ this._assertSlideIndex(t), await this._waitForSlide(t);
1204
+ let i = this._preflight, a = this._slides;
1205
+ if (!i || !a) throw Error("Presentation not loaded");
1206
+ let o = n.dpr ?? S(), s = n.width ?? ((ee(e) ? e.offsetWidth : 0) || 960);
1207
+ await a.withSlide(t, (t) => (this._assertResourceHealthy(), r(e, t, i.slideWidth, i.slideHeight, {
1208
+ width: s,
1209
+ dpr: o,
1210
+ defaultTextColor: i.defaultTextColor,
1211
+ majorFont: i.majorFont,
1212
+ minorFont: i.minorFont,
1213
+ hlinkColor: i.hlinkColor,
1214
+ embeddedFontAliases: this._embeddedFontAliases,
1215
+ embeddedFontAuthoredFamilies: this._embeddedFontAuthoredFamilies,
1216
+ fetchMedia: this._fetchMedia,
1217
+ fetchImage: this._fetchImage,
1218
+ skipMediaControls: n.skipMediaControls,
1219
+ dim: n.dim,
1220
+ math: this._math,
1221
+ threeD: this._threeD,
1222
+ regionMap: this._regionMap,
1223
+ chartEx: this._chartEx
1224
+ }, n.onTextRun)));
1225
+ } catch (e) {
1226
+ this._rethrowWithResourceFailure(e);
1227
+ }
1228
+ }
1229
+ async renderSlideToBitmap(e, t = {}) {
1230
+ this._assertResourceHealthy();
1231
+ try {
1232
+ this._assertSlideIndex(e), await this._waitForSlide(e);
1233
+ let n = t.width ?? 960, r = t.dpr ?? S();
1234
+ if (this._mode === "worker") {
1235
+ let i = await this._bridge.request((i) => ({
1236
+ kind: "renderSlide",
1237
+ id: i,
1238
+ slideIndex: e,
1239
+ width: n,
1240
+ dpr: r,
1241
+ skipMediaControls: t.skipMediaControls,
1242
+ dim: t.dim
1243
+ }));
1244
+ if (t.onTextRun) for (let e of i.runs) t.onTextRun(e);
1245
+ return i.bitmap;
1246
+ }
1247
+ let i = new OffscreenCanvas(1, 1);
1248
+ return await this.renderSlide(i, e, {
1249
+ width: n,
1250
+ dpr: r,
1251
+ skipMediaControls: t.skipMediaControls,
1252
+ dim: t.dim,
1253
+ onTextRun: t.onTextRun
1254
+ }), i.transferToImageBitmap();
1255
+ } catch (e) {
1256
+ this._rethrowWithResourceFailure(e);
1257
+ }
1258
+ }
1259
+ async collectSlideRuns(e, t = 960) {
1260
+ this._assertResourceHealthy();
1261
+ try {
1262
+ if (this._assertSlideIndex(e), await this._waitForSlide(e), this._mode === "worker") return (await this._bridge.request((n) => ({
1263
+ kind: "collectRuns",
1264
+ id: n,
1265
+ slideIndex: e,
1266
+ width: t
1267
+ }))).runs;
1268
+ let n = [], r = new OffscreenCanvas(1, 1);
1269
+ return await this.renderSlide(r, e, {
1270
+ width: t,
1271
+ onTextRun: (e) => n.push(e)
1272
+ }), n;
1273
+ } catch (e) {
1274
+ this._rethrowWithResourceFailure(e);
1275
+ }
1276
+ }
1277
+ async getElementContextAt(e, t, n = {}) {
1278
+ this._assertResourceHealthy(), this._assertSlideIndex(e);
1279
+ try {
1280
+ if (await this._waitForSlide(e), this._mode === "worker") return (await this._bridge.request((r) => ({
1281
+ kind: "hitTestElement",
1282
+ id: r,
1283
+ slideIndex: e,
1284
+ point: t,
1285
+ options: n
1286
+ }))).context;
1287
+ if (!this._slides) throw Error("Presentation not loaded");
1288
+ return await this._slides.withSlide(e, (r) => Ot(e, r, t, n));
1289
+ } catch (e) {
1290
+ this._rethrowWithResourceFailure(e);
1291
+ }
1292
+ }
1293
+ async getElementBoundsByIds(e, t) {
1294
+ this._assertResourceHealthy(), this._assertSlideIndex(e);
1295
+ let n = Object.freeze(t.filter((e) => typeof e == "string" && e.length > 0));
1296
+ if (n.length === 0) return Object.freeze([]);
1297
+ try {
1298
+ if (await this._waitForSlide(e), this._mode === "worker") return (await this._bridge.request((t) => ({
1299
+ kind: "resolveElementBounds",
1300
+ id: t,
1301
+ slideIndex: e,
1302
+ elementIds: n
1303
+ }))).bounds;
1304
+ if (!this._slides) throw Error("Presentation not loaded");
1305
+ return await this._slides.withSlide(e, (e) => kt(e, n));
1306
+ } catch (e) {
1307
+ this._rethrowWithResourceFailure(e);
1308
+ }
1309
+ }
1310
+ async getMedia(e) {
1311
+ this._assertResourceHealthy();
1312
+ try {
1313
+ let t = this._findMimeTypeForPath(e);
1314
+ return await this._rawParts.get(e, t, async () => {
1315
+ let n = (await this._bridge.request((t) => ({
1316
+ kind: "extractMedia",
1317
+ id: t,
1318
+ path: e
1319
+ }))).bytes;
1320
+ return new Blob([n], { type: t });
1321
+ });
1322
+ } catch (e) {
1323
+ this._rethrowWithResourceFailure(e);
1324
+ }
1325
+ }
1326
+ _findMimeTypeForPath(e) {
1327
+ return this._preflight ? a(this._preflight, e) : "";
1328
+ }
1329
+ async getImage(e, t) {
1330
+ this._assertResourceHealthy();
1331
+ try {
1332
+ return await this._rawParts.get(e, t, async () => {
1333
+ let n = (await this._bridge.request((t) => ({
1334
+ kind: "extractImage",
1335
+ id: t,
1336
+ path: e
1337
+ }))).bytes;
1338
+ return new Blob([n], { type: t });
1339
+ });
1340
+ } catch (e) {
1341
+ this._rethrowWithResourceFailure(e);
1342
+ }
1343
+ }
1344
+ async getFontBytes(e) {
1345
+ this._assertResourceHealthy();
1346
+ try {
1347
+ let t = await this._bridge.request((t) => ({
1348
+ kind: "extractFont",
1349
+ id: t,
1350
+ path: e
1351
+ }));
1352
+ return new Uint8Array(t.bytes);
1353
+ } catch (e) {
1354
+ this._rethrowWithResourceFailure(e);
1355
+ }
1356
+ }
1357
+ async getResourceMetrics() {
1358
+ let e = this._metrics;
1359
+ if (!e) throw Error("Presentation not loaded");
1360
+ return te(e, async (e) => (await this._bridge.request((e) => ({
1361
+ kind: "resourceUsage",
1362
+ id: e
1363
+ }), void 0, { timeoutMs: e })).usage);
1364
+ }
1365
+ async toMarkdown() {
1366
+ this._assertResourceHealthy();
1367
+ try {
1368
+ return (await this._bridge.request((e) => ({
1369
+ kind: "toMarkdown",
1370
+ id: e
1371
+ }))).markdown;
1372
+ } catch (e) {
1373
+ this._rethrowWithResourceFailure(e);
1374
+ }
1375
+ }
1376
+ async presentSlide(e, t, n = {}) {
1377
+ this._assertResourceHealthy();
1378
+ try {
1379
+ if (this._assertSlideIndex(t), await this._waitForSlide(t), !this._preflight) throw Error("Presentation not loaded");
1380
+ let r = n.dpr ?? S(), i = n.width ?? (e.offsetWidth || 960), a = this._mode === "worker" ? async () => {
1381
+ let a = await this.renderSlideToBitmap(t, {
1382
+ width: i,
1383
+ dpr: r,
1384
+ skipMediaControls: !0,
1385
+ dim: n.dim,
1386
+ onTextRun: n.onTextRun
1387
+ });
1388
+ e.width = a.width, e.height = a.height, e.style.width = `${Math.round(a.width / r)}px`, e.style.display || (e.style.display = "block");
1389
+ let o = e.getContext("2d");
1390
+ if (!o) throw Error("2D context not available");
1391
+ o.drawImage(a, 0, 0), a.close();
1392
+ } : () => this.renderSlide(e, t, {
1393
+ width: i,
1394
+ dpr: r,
1395
+ skipMediaControls: !0,
1396
+ dim: n.dim,
1397
+ onTextRun: n.onTextRun
1398
+ });
1399
+ return await Ge(e, this._preflight.slides[t]?.mediaElements ?? [], {
1400
+ width: i,
1401
+ dpr: r,
1402
+ slideWidthEmu: this.slideWidth,
1403
+ fetchMedia: this._fetchMedia,
1404
+ fetchImage: this._fetchImage,
1405
+ drawBase: a,
1406
+ onError: n.onError
1407
+ });
1408
+ } catch (e) {
1409
+ this._rethrowWithResourceFailure(e);
1410
+ }
1411
+ }
1412
+ destroy() {
1413
+ this._destroyed = !0, this._clearProgressiveWatchdog(), this._slidePullClient?.cancelAll(), this._bridge.terminate(), this._slides?.clear(), this._slides = null, this._slidePullClient = null, this._bootstrap = null, this._preflight = null, this._availableSlideCount = 0, this._layoutLifecycle.succeed(), this._layoutCompletion = null, this._progressive = null, this._parseRequestId = null, this._wakeLayoutWaiters(), this._resourceFailure = null, this._slidePartIndex = null, this._rawParts.clear(), this._googleFontFaces.length > 0 && (Se(this._googleFontFaces), this._googleFontFaces = []), this._embeddedFontFaces.length > 0 && (j(this._embeddedFontFaces), this._embeddedFontFaces = []), this._embeddedFontAliases = /* @__PURE__ */ new Map(), this._embeddedFontAuthoredFamilies = /* @__PURE__ */ new Map(), C(this._fetchImage), w(this._fetchImage);
1414
+ }
1415
+ };
1416
+ //#endregion
1417
+ //#region packages/pptx/src/selection-context.ts
1418
+ function Mt(e, t, n, r, i = {}) {
1419
+ let a = Oe({
1420
+ id: e.id,
1421
+ author: e.author,
1422
+ date: e.date,
1423
+ text: e.text,
1424
+ status: e.status ?? "active"
1425
+ }, (e.replies ?? []).map((e) => ({
1426
+ id: e.id,
1427
+ author: e.author,
1428
+ date: e.date,
1429
+ text: e.text,
1430
+ status: e.status ?? "active"
1431
+ })), i.maxTextCharacters);
1432
+ return Object.freeze({
1433
+ format: "pptx",
1434
+ kind: "comment",
1435
+ slideIndex: t,
1436
+ commentIndex: n,
1437
+ occurrenceId: r,
1438
+ ...e.id ? { commentId: e.id } : {},
1439
+ ...Number.isFinite(e.x) && Number.isFinite(e.y) ? { point: Object.freeze({
1440
+ x: e.x,
1441
+ y: e.y
1442
+ }) } : {},
1443
+ thread: a.thread,
1444
+ truncated: a.truncated,
1445
+ truncationReasons: a.truncated ? ["text"] : [],
1446
+ textCharacters: a.textCharacters,
1447
+ maxTextCharacters: a.maxTextCharacters
1448
+ });
1449
+ }
1450
+ function X(e) {
1451
+ if (e === void 0 || !/^\d+$/.test(e)) return null;
1452
+ let t = Number(e);
1453
+ return Number.isSafeInteger(t) ? t : null;
1454
+ }
1455
+ function Nt(e) {
1456
+ for (let t = e; t; t = t.parentElement) {
1457
+ let e = X(t.dataset.slideIndex);
1458
+ if (e !== null) return e;
1459
+ }
1460
+ return null;
1461
+ }
1462
+ function Z(e, t, n = {}) {
1463
+ let r = ge(e, t, (e) => {
1464
+ let t = Nt(e), n = X(e.dataset.runIndex);
1465
+ if (t === null || n === null) return null;
1466
+ let r = X(e.dataset.elementIndex), i = e.dataset.elementOrigin, a = r !== null && (i === "master" || i === "layout" || i === "slide");
1467
+ return {
1468
+ slideIndex: t,
1469
+ runIndex: n,
1470
+ ...e.dataset.shapeId === void 0 ? {} : { shapeId: e.dataset.shapeId },
1471
+ ...a ? {
1472
+ elementIndex: r,
1473
+ origin: i
1474
+ } : {}
1475
+ };
1476
+ }, {
1477
+ maxChars: n.maxTextCharacters,
1478
+ maxLocators: n.maxRunLocators
1479
+ });
1480
+ if (!r) return null;
1481
+ let i = [...r.locators].sort((e, t) => e.slideIndex - t.slideIndex || e.runIndex - t.runIndex);
1482
+ return {
1483
+ format: "pptx",
1484
+ kind: "text",
1485
+ text: r.text,
1486
+ slideIndexes: [...new Set(i.map((e) => e.slideIndex))],
1487
+ shapeIds: [...new Set(i.flatMap((e) => e.shapeId ? [e.shapeId] : []))],
1488
+ runs: i,
1489
+ truncated: r.truncated,
1490
+ truncationReasons: r.truncationReasons,
1491
+ textCharacters: r.textCharacters,
1492
+ maxTextCharacters: r.maxTextCharacters,
1493
+ maxRunLocators: r.maxLocators
1494
+ };
1495
+ }
1496
+ //#endregion
1497
+ //#region packages/pptx/src/focused-view-runtime.ts
1498
+ function Q(e, t, n, r, i) {
1499
+ return r === "worker" ? e.renderSlideToBitmap(n, i) : e.renderSlide(t, n, i);
1500
+ }
1501
+ //#endregion
1502
+ //#region packages/pptx/src/viewer.ts
1503
+ var Pt = Symbol("PptxViewer.borrowedPresentation"), Ft = {
1504
+ color: "#ffffff",
1505
+ opacity: .6
1506
+ }, It = class e {
1507
+ canvas;
1508
+ wrapper;
1509
+ canvasMount;
1510
+ _scale = null;
1511
+ textLayer = null;
1512
+ highlightLayer = null;
1513
+ elementLayer = null;
1514
+ _find;
1515
+ _findGeneration = 0;
1516
+ _measureCtx = null;
1517
+ presentationOwner;
1518
+ get engine() {
1519
+ return this.presentationOwner.current;
1520
+ }
1521
+ borrowed;
1522
+ hostWindow;
1523
+ opts;
1524
+ currentSlide = 0;
1525
+ _renderedSlide = -1;
1526
+ _hiddenMode;
1527
+ handle = null;
1528
+ _mode;
1529
+ renderDispatcher;
1530
+ errorRouter;
1531
+ destroyed = !1;
1532
+ selectionChangeListener = null;
1533
+ selectionContextKey = "null";
1534
+ elementClickListener = null;
1535
+ contextMenuListener = null;
1536
+ elementContext = null;
1537
+ elementHitGeneration = 0;
1538
+ elementHitTolerance;
1539
+ _loadingLayer;
1540
+ _layoutUnsubscribe = null;
1541
+ _layoutWaiters = /* @__PURE__ */ new Set();
1542
+ _layoutFailed = !1;
1543
+ _navigationGeneration = 0;
1544
+ _renderProgressGeneration = 0;
1545
+ _lastReportedSlide = -1;
1546
+ _lastReportedTotal = -1;
1547
+ _lastReportedAvailable = -1;
1548
+ _lastReportedLayoutComplete = null;
1549
+ static fromPresentation(t, n, r = {}) {
1550
+ return new e(t, {
1551
+ ...r,
1552
+ [Pt]: n
1553
+ });
1554
+ }
1555
+ constructor(e, t = {}) {
1556
+ this.opts = t, this.canvas = e;
1557
+ let n = t[Pt];
1558
+ this.borrowed = n !== void 0, this._mode = k("PptxViewer", t.mode, n), this.presentationOwner = new E("PptxViewer", n ?? null, !1);
1559
+ let r = e.ownerDocument?.defaultView ?? (typeof window < "u" ? window : null);
1560
+ if (!r) throw Error("PptxViewer requires a canvas with an active Window");
1561
+ this.hostWindow = r;
1562
+ let i = t.elementHitTolerance ?? 6;
1563
+ if (!Number.isFinite(i) || i < 0) throw RangeError("elementHitTolerance must be a finite non-negative number.");
1564
+ this.elementHitTolerance = i, this._hiddenMode = t.hiddenSlideMode ?? "show", this.canvasMount = new _e(e, {
1565
+ wrapperCssText: "position:relative;display:inline-block;vertical-align:top;",
1566
+ forceDisplayBlock: !0
1567
+ }), this.wrapper = this.canvasMount.wrapper, this.renderDispatcher = new O(e, this._mode === "worker" && !t.enableMediaPlayback), this.errorRouter = new he("PptxViewer", t.onError);
1568
+ let a = new fe(this.wrapper, t.enableTextSelection === !0, t.enableElementSelection === !0);
1569
+ this.textLayer = a.textLayer, this.highlightLayer = a.highlightLayer, this.elementLayer = a.elementLayer, this._loadingLayer = this.wrapper.ownerDocument.createElement("span"), this._loadingLayer.style.cssText = [
1570
+ "position:absolute",
1571
+ "inset:0",
1572
+ "display:none",
1573
+ "align-items:center",
1574
+ "justify-content:center",
1575
+ "background:rgba(255,255,255,0.72)",
1576
+ "pointer-events:none",
1577
+ "z-index:4"
1578
+ ].join(";"), this._loadingLayer.setAttribute("role", "status"), this._loadingLayer.setAttribute("aria-live", "polite"), this._loadingLayer.setAttribute("aria-label", "Loading slide");
1579
+ let o = this.wrapper.ownerDocument.createElement("progress");
1580
+ o.setAttribute("aria-hidden", "true"), this._loadingLayer.appendChild(o), this.wrapper.insertBefore(this._loadingLayer, this.elementLayer), this.textLayer && (t.onSelectionContextChange || t.enableElementSelection) && (this.selectionChangeListener = () => this._emitSelectionContextChange(), this.wrapper.ownerDocument.addEventListener("selectionchange", this.selectionChangeListener)), t.enableElementSelection && (this.elementClickListener = (e) => {
1581
+ this._onElementClick(e).catch((e) => this._reportRenderError(e));
1582
+ }, this.wrapper.addEventListener("click", this.elementClickListener)), t.onContextMenu && (this.contextMenuListener = (e) => this._onContextMenu(e), this.wrapper.addEventListener("contextmenu", this.contextMenuListener)), this._find = new Be(() => this.slideCount, (e) => this._collectSlideRuns(e)), n && this._bindLayoutPresentation(n);
1583
+ }
1584
+ async load(e) {
1585
+ if (this.destroyed) throw Error("PptxViewer is destroyed");
1586
+ if (this.borrowed) throw Error("PptxViewer.load() is unsupported on a Viewer created by fromPresentation(); the borrowed presentation is already loaded.");
1587
+ let t = !1;
1588
+ try {
1589
+ let n = await this.presentationOwner.replace(() => Y.load(e, {
1590
+ password: this.opts.password,
1591
+ useGoogleFonts: this.opts.useGoogleFonts,
1592
+ maxZipEntryBytes: this.opts.maxZipEntryBytes,
1593
+ resourceLimits: this.opts.resourceLimits,
1594
+ debug: this.opts.debug,
1595
+ onResourceMetrics: this.opts.onResourceMetrics,
1596
+ workerTimeoutMs: this.opts.workerTimeoutMs,
1597
+ wasmUrl: this.opts.wasmUrl,
1598
+ math: this.opts.math,
1599
+ threeD: this.opts.threeD,
1600
+ regionMap: this.opts.regionMap,
1601
+ chartEx: this.opts.chartEx,
1602
+ mode: this._mode,
1603
+ progressiveLayout: this.opts.progressiveLayout,
1604
+ onLayoutProgress: this.opts.onLayoutProgress,
1605
+ onLayoutPartial: this.opts.onLayoutPartial,
1606
+ onLayoutComplete: this.opts.onLayoutComplete
1607
+ }), () => {
1608
+ this._invalidateElementSelection(!1), t = !0, this.renderDispatcher.begin(), this._invalidateFind(), this.handle?.destroy(), this.handle = null, this._unbindLayoutPresentation();
1609
+ });
1610
+ if (!n) return;
1611
+ if (this.destroyed) throw Error("PptxViewer is destroyed");
1612
+ this._bindLayoutPresentation(n);
1613
+ let r = this._beginNavigation();
1614
+ if (this.currentSlide = await this._initialSlide(r), r !== this._navigationGeneration || n !== this.engine) return;
1615
+ this._renderedSlide = -1, this._invalidateFind(), await this.renderCurrentSlide();
1616
+ } catch (e) {
1617
+ throw this.destroyed ? Error("PptxViewer is destroyed") : e instanceof Error ? e : Error(String(e));
1618
+ }
1619
+ t && !this.destroyed && this._emitSelectionContextChange();
1620
+ }
1621
+ async goToSlide(e) {
1622
+ let t = this._beginNavigation();
1623
+ await this._goToSlide(e, t);
1624
+ }
1625
+ async _goToSlide(e, t) {
1626
+ if (t !== this._navigationGeneration || !this.engine || this.slideCount === 0) return;
1627
+ let n = Math.max(0, Math.min(e, this.slideCount - 1)), r = n !== this.currentSlide;
1628
+ r && this._invalidateElementSelection(!1), this.currentSlide = n, await this.renderCurrentSlide(), r && !this.destroyed && this._emitSelectionContextChange();
1629
+ }
1630
+ async nextSlide() {
1631
+ let e = this._beginNavigation(), t = await this._step(1, e);
1632
+ await this._goToSlide(t, e);
1633
+ }
1634
+ async prevSlide() {
1635
+ let e = this._beginNavigation(), t = await this._step(-1, e);
1636
+ await this._goToSlide(t, e);
1637
+ }
1638
+ async _step(e, t) {
1639
+ let n = this.engine, r = this.currentSlide;
1640
+ if (this._hiddenMode !== "skip" || !n) return r + e;
1641
+ for (let i = r + e; i >= 0 && i < this.slideCount; i += e) {
1642
+ if (i >= n.availableSlideCount && (n.layoutComplete || this._setLoading(!0), !await this._waitForSlide(n, i, () => t === this._navigationGeneration))) return r;
1643
+ if (!n.isHidden(i)) return i;
1644
+ }
1645
+ return r;
1646
+ }
1647
+ async _initialSlide(e) {
1648
+ let t = this.engine;
1649
+ if (this._hiddenMode !== "skip" || !t || this.slideCount === 0 || t.availableSlideCount === 0 && !await this._waitForSlide(t, 0, () => e === this._navigationGeneration) || !t.isHidden(0)) return 0;
1650
+ let n = await this._step(1, e);
1651
+ return n === 0 ? 0 : n;
1652
+ }
1653
+ _dim() {
1654
+ return {
1655
+ color: this.opts.hiddenSlideDim?.color ?? Ft.color,
1656
+ opacity: this.opts.hiddenSlideDim?.opacity ?? Ft.opacity
1657
+ };
1658
+ }
1659
+ async setHiddenSlideMode(e) {
1660
+ let t = this._beginNavigation();
1661
+ this._hiddenMode = e;
1662
+ let n = this.currentSlide;
1663
+ if (e === "skip" && this.engine) {
1664
+ let e = this.engine;
1665
+ if (this.currentSlide >= e.availableSlideCount && !await this._waitForSlide(e, this.currentSlide, () => t === this._navigationGeneration)) return;
1666
+ e.isHidden(this.currentSlide) && (n = await this._step(1, t), n === this.currentSlide && (n = await this._step(-1, t)));
1667
+ }
1668
+ if (t !== this._navigationGeneration) return;
1669
+ let r = n !== this.currentSlide;
1670
+ r && this._invalidateElementSelection(!1), this.currentSlide = n, await this.renderCurrentSlide(), r && !this.destroyed && this._emitSelectionContextChange();
1671
+ }
1672
+ get hiddenSlideMode() {
1673
+ return this._hiddenMode;
1674
+ }
1675
+ get visibleSlideCount() {
1676
+ if (!this.engine) return 0;
1677
+ let e = this.engine;
1678
+ return Fe((t) => e.isHidden(t), this.slideCount);
1679
+ }
1680
+ get slideIndex() {
1681
+ return this.currentSlide;
1682
+ }
1683
+ get slideCount() {
1684
+ return this.engine?.slideCount ?? 0;
1685
+ }
1686
+ get availableSlideCount() {
1687
+ return this.engine?.availableSlideCount ?? this.slideCount;
1688
+ }
1689
+ get layoutComplete() {
1690
+ return this.engine?.layoutComplete ?? !0;
1691
+ }
1692
+ async waitUntilLayoutComplete() {
1693
+ await this.errorRouter.ownBackgroundLifecycle(async () => {
1694
+ await this.engine?.waitUntilLayoutComplete?.();
1695
+ });
1696
+ }
1697
+ getNotes(e) {
1698
+ return this.engine?.getNotes(e) ?? null;
1699
+ }
1700
+ get canvasElement() {
1701
+ return this.canvas;
1702
+ }
1703
+ _naturalWidthPx() {
1704
+ let e = this.engine?.slideWidth ?? 0;
1705
+ return e > 0 ? e / M : 0;
1706
+ }
1707
+ _targetWidth() {
1708
+ if (this._scale === null) return this.opts.width ?? (this.canvas.offsetWidth || 960);
1709
+ let e = this._naturalWidthPx();
1710
+ return e <= 0 ? this.opts.width ?? (this.canvas.offsetWidth || 960) : Math.round(e * this._scale);
1711
+ }
1712
+ getScale() {
1713
+ if (this._scale !== null) return this._scale;
1714
+ let e = this._naturalWidthPx();
1715
+ return e <= 0 ? 1 : this._targetWidth() / e;
1716
+ }
1717
+ _zoomMin() {
1718
+ return this.opts.zoomMin ?? .1;
1719
+ }
1720
+ _zoomMax() {
1721
+ return this.opts.zoomMax ?? 4;
1722
+ }
1723
+ async setScale(e) {
1724
+ let t = le(e, this._zoomMin(), this._zoomMax()), n = t !== this.getScale();
1725
+ this._scale = t, await this.renderCurrentSlide(), n && this.opts.onScaleChange?.(t);
1726
+ }
1727
+ async zoomIn() {
1728
+ await this.setScale(ve(this.getScale()));
1729
+ }
1730
+ async zoomOut() {
1731
+ await this.setScale(xe(this.getScale()));
1732
+ }
1733
+ async fitWidth() {
1734
+ await this._fit("width");
1735
+ }
1736
+ async fitPage() {
1737
+ await this._fit("page");
1738
+ }
1739
+ async _fit(e) {
1740
+ if (!this.engine) return;
1741
+ let t = this.wrapper.parentElement;
1742
+ if (!t) return;
1743
+ let n = T({
1744
+ contentWidth: this.engine.slideWidth / M,
1745
+ contentHeight: this.engine.slideHeight / M,
1746
+ containerWidth: t.clientWidth,
1747
+ containerHeight: t.clientHeight
1748
+ }, e);
1749
+ n <= 0 || await this.setScale(n);
1750
+ }
1751
+ async renderCurrentSlide() {
1752
+ let e = this.engine;
1753
+ if (!e) return;
1754
+ let t = this.currentSlide, n = ++this._renderProgressGeneration;
1755
+ this._setLoading(t >= this.availableSlideCount && !this.layoutComplete);
1756
+ let r = this.renderDispatcher.begin();
1757
+ try {
1758
+ if (t >= e.availableSlideCount && !await this._waitForSlide(e, t, () => n === this._renderProgressGeneration && this.renderDispatcher.isCurrent(r) && e === this.engine && t === this.currentSlide)) return;
1759
+ let i = this._hiddenMode === "dim" && e.isHidden(t) ? this._dim() : void 0, a = this._targetWidth(), o = this.opts.dpr ?? (window.devicePixelRatio || 1), s = a / e.slideWidth, c = Math.round(e.slideHeight * s);
1760
+ this.canvas.style.width = `${a}px`, this.canvas.style.height = `${c}px`, this.handle?.destroy(), this.handle = null;
1761
+ let l = this._mode === "worker", u = [], d = (e) => u.push(e);
1762
+ if (this.opts.enableMediaPlayback) {
1763
+ let n = await e.presentSlide(this.canvas, t, {
1764
+ width: a,
1765
+ dpr: o,
1766
+ dim: i,
1767
+ onTextRun: d,
1768
+ onError: (e) => {
1769
+ this.renderDispatcher.isCurrent(r) && this._reportRenderError(e);
1770
+ }
1771
+ });
1772
+ if (!this.renderDispatcher.isCurrent(r)) {
1773
+ n.destroy();
1774
+ return;
1775
+ }
1776
+ this.handle = n;
1777
+ } else if (l) {
1778
+ let e = await Q(this.engine, this.canvas, t, "worker", {
1779
+ width: a,
1780
+ dpr: o,
1781
+ dim: i,
1782
+ onTextRun: d
1783
+ });
1784
+ if (!this.renderDispatcher.commitBitmap(r, e)) return;
1785
+ } else if (await Q(this.engine, this.canvas, t, "main", {
1786
+ width: a,
1787
+ dpr: o,
1788
+ onTextRun: d,
1789
+ dim: i
1790
+ }), !this.renderDispatcher.isCurrent(r)) return;
1791
+ this._renderedSlide = t, this._emitSlideChange(!0), this.textLayer && this._buildTextLayer(this.textLayer, u, a, c), this._find.setSlideRuns(t, u), this._buildHighlightLayer(u, a, c);
1792
+ } catch (t) {
1793
+ if (!this.renderDispatcher.isCurrent(r) && !(e === this.engine && this._layoutFailed)) return;
1794
+ throw t;
1795
+ } finally {
1796
+ n === this._renderProgressGeneration && this._setLoading(!1);
1797
+ }
1798
+ }
1799
+ _bindLayoutPresentation(e) {
1800
+ this._unbindLayoutPresentation(), this._layoutFailed = !1;
1801
+ let t = !0;
1802
+ this._layoutUnsubscribe = At(e, () => ({
1803
+ availableSlides: e.availableSlideCount,
1804
+ slideCount: e.slideCount,
1805
+ exact: e.layoutComplete,
1806
+ complete: e.layoutComplete
1807
+ }), (n) => {
1808
+ if (t) {
1809
+ t = !1;
1810
+ return;
1811
+ }
1812
+ this._onLayoutPublication(e, n);
1813
+ }, (e) => this._reportRenderError(e));
1814
+ }
1815
+ _unbindLayoutPresentation() {
1816
+ this._layoutUnsubscribe?.(), this._layoutUnsubscribe = null, this._layoutFailed = !1, this._navigationGeneration++, this._renderProgressGeneration++, this._wakeLayoutWaiters(), this._setLoading(!1);
1817
+ }
1818
+ _beginNavigation() {
1819
+ let e = ++this._navigationGeneration;
1820
+ return this._wakeLayoutWaiters(), e;
1821
+ }
1822
+ _onLayoutPublication(e, t) {
1823
+ if (!(this.destroyed || e !== this.engine)) {
1824
+ if (this._wakeLayoutWaiters(), t.error !== void 0) {
1825
+ this._layoutFailed = !0, this.errorRouter.reportBackground(t.error, this.opts.onLayoutComplete !== void 0);
1826
+ return;
1827
+ }
1828
+ this._renderedSlide === this.currentSlide && this._emitSlideChange();
1829
+ }
1830
+ }
1831
+ async _waitForSlide(e, t, n) {
1832
+ return await this.errorRouter.ownBackgroundLifecycle(async () => {
1833
+ for (; !this.destroyed && n() && e === this.engine && t >= e.availableSlideCount && !e.layoutComplete && !this._layoutFailed;) await new Promise((e) => this._layoutWaiters.add(e));
1834
+ return this.destroyed || e !== this.engine || ((e.layoutComplete || this._layoutFailed) && await e.waitUntilLayoutComplete?.(), !n()) ? !1 : t < e.availableSlideCount;
1835
+ });
1836
+ }
1837
+ _wakeLayoutWaiters() {
1838
+ for (let e of this._layoutWaiters) e();
1839
+ this._layoutWaiters.clear();
1840
+ }
1841
+ _emitSlideChange(e = !1) {
1842
+ let t = this.slideCount, n = this.availableSlideCount, r = this.layoutComplete;
1843
+ !e && this.currentSlide === this._lastReportedSlide && t === this._lastReportedTotal && n === this._lastReportedAvailable && r === this._lastReportedLayoutComplete || (this._lastReportedSlide = this.currentSlide, this._lastReportedTotal = t, this._lastReportedAvailable = n, this._lastReportedLayoutComplete = r, this.opts.onSlideChange?.(this.currentSlide, t, r));
1844
+ }
1845
+ _setLoading(e) {
1846
+ this._loadingLayer.style.display = e ? "flex" : "none";
1847
+ }
1848
+ _buildHighlightLayer(e, t, n) {
1849
+ let r = this.highlightLayer;
1850
+ r && L(r, e, this._find.slideHighlights(this.currentSlide), t, n, (e) => this._measureForFont(e), this.opts.findHighlightColors);
1851
+ }
1852
+ _measureForFont(e) {
1853
+ this._measureCtx ||= document.createElement("canvas").getContext("2d");
1854
+ let t = this._measureCtx;
1855
+ return t ? (t.font = e, (e) => t.measureText(e).width) : (e) => e.length;
1856
+ }
1857
+ async _collectSlideRuns(e) {
1858
+ return this.engine ? this.engine.collectSlideRuns(e, this._targetWidth()) : [];
1859
+ }
1860
+ async findText(e, t = {}) {
1861
+ let n = this.engine;
1862
+ if (!n) return [];
1863
+ let r = ++this._findGeneration;
1864
+ if (e.length === 0) return this._find.invalidate(), this._redrawHighlights(), [];
1865
+ if (n.layoutComplete || await this.errorRouter.ownBackgroundLifecycle(() => n.waitUntilLayoutComplete()), this.destroyed || r !== this._findGeneration || n !== this.engine) return [];
1866
+ let i = await this.errorRouter.ownAwaitable(() => this._find.find(e, t));
1867
+ return this.destroyed || r !== this._findGeneration || n !== this.engine ? [] : (this._redrawHighlights(), i);
1868
+ }
1869
+ async findNext() {
1870
+ return this._activateMatch(this._find.next());
1871
+ }
1872
+ async findPrev() {
1873
+ return this._activateMatch(this._find.prev());
1874
+ }
1875
+ clearFind() {
1876
+ this._invalidateFind(), this._redrawHighlights();
1877
+ }
1878
+ _invalidateFind() {
1879
+ this._findGeneration++, this._find.invalidate();
1880
+ }
1881
+ async _activateMatch(e) {
1882
+ return e ? (e.location.slide === this.currentSlide ? this._redrawHighlights() : await this.goToSlide(e.location.slide), e) : (this._redrawHighlights(), null);
1883
+ }
1884
+ _redrawHighlights() {
1885
+ let e = this._find.slideRuns(this.currentSlide) ?? [], t = this._targetWidth(), n = this.engine ? Math.round(this.engine.slideHeight * (t / this.engine.slideWidth)) : 0;
1886
+ this._buildHighlightLayer(e, t, n);
1887
+ }
1888
+ _buildTextLayer(e, t, n, r) {
1889
+ I(e, t, n, r, this._hyperlinkHandler(), this.currentSlide);
1890
+ }
1891
+ _hyperlinkHandler() {
1892
+ if (this.opts.enableHyperlinks !== !1) return (e) => this._onHyperlinkClick(e);
1893
+ }
1894
+ _onHyperlinkClick(e) {
1895
+ let t = this._resolveInternalSlideIndex(e);
1896
+ if (this.opts.onHyperlinkClick) {
1897
+ this.opts.onHyperlinkClick(t);
1898
+ return;
1899
+ }
1900
+ if (t.kind === "external") {
1901
+ x(t.url, void 0, this.hostWindow);
1902
+ return;
1903
+ }
1904
+ t.slideIndex !== void 0 && this.goToSlide(t.slideIndex).catch((e) => this._reportRenderError(e));
1905
+ }
1906
+ _resolveInternalSlideIndex(e) {
1907
+ if (e.kind !== "internal" || e.slideIndex !== void 0) return e;
1908
+ let t = this.engine?.resolveInternalTarget(e.ref, this.currentSlide);
1909
+ return t === void 0 ? e : {
1910
+ ...e,
1911
+ slideIndex: t
1912
+ };
1913
+ }
1914
+ _reportRenderError(e) {
1915
+ this.errorRouter.report(e);
1916
+ }
1917
+ async getResourceMetrics() {
1918
+ if (!this.engine) throw Error("Presentation not loaded");
1919
+ return await this.engine.getResourceMetrics();
1920
+ }
1921
+ getSelectionContext(e = {}) {
1922
+ if (this.destroyed) throw Error("PptxViewer is destroyed");
1923
+ return (this.textLayer ? Z(this.wrapper, this.wrapper.ownerDocument?.getSelection?.() ?? null, e) : null) ?? (this.elementContext ? Et(this.elementContext, e.maxTextCharacters) : null);
1924
+ }
1925
+ _emitSelectionContextChange() {
1926
+ let e = this.getSelectionContext();
1927
+ e?.kind === "text" && (this.elementHitGeneration++, this.elementContext = null, this._redrawElementOutline());
1928
+ let t = JSON.stringify(e);
1929
+ t !== this.selectionContextKey && (this.selectionContextKey = t, this.opts.onSelectionContextChange?.(e ? structuredClone(e) : null));
1930
+ }
1931
+ _setElementContext(e) {
1932
+ this.elementContext = e ? structuredClone(e) : null, this._redrawElementOutline(), this._emitSelectionContextChange();
1933
+ }
1934
+ _invalidateElementSelection(e = !0) {
1935
+ this.elementHitGeneration++, this.elementContext = null, this._redrawElementOutline(), e && this._emitSelectionContextChange();
1936
+ }
1937
+ _redrawElementOutline() {
1938
+ let e = this.elementContext, t = this.engine;
1939
+ if (!e || !t || e.slideIndex !== this.currentSlide) {
1940
+ D(this.elementLayer, null);
1941
+ return;
1942
+ }
1943
+ D(this.elementLayer, {
1944
+ x: e.bounds.x / t.slideWidth,
1945
+ y: e.bounds.y / t.slideHeight,
1946
+ width: e.bounds.width / t.slideWidth,
1947
+ height: e.bounds.height / t.slideHeight,
1948
+ rotation: e.bounds.rotation
1949
+ });
1950
+ }
1951
+ async _onElementClick(e) {
1952
+ this.destroyed || e.defaultPrevented || e.button !== 0 || await this._resolveContextAt(e);
1953
+ }
1954
+ _onContextMenu(e) {
1955
+ let t;
1956
+ this.opts.onContextMenu?.({
1957
+ originalEvent: e,
1958
+ getContext: () => t ??= this._resolveContextAt(e)
1959
+ });
1960
+ }
1961
+ async _resolveContextAt(e) {
1962
+ let t = this.engine;
1963
+ if (this.destroyed || !t) return null;
1964
+ if (this.textLayer && Z(this.wrapper, this.wrapper.ownerDocument?.getSelection?.() ?? null)) return this._emitSelectionContextChange(), this.destroyed ? null : this.getSelectionContext();
1965
+ if (!this.opts.enableElementSelection) return this.getSelectionContext();
1966
+ let n = this.canvas.getBoundingClientRect();
1967
+ if (n.width <= 0 || n.height <= 0) return this._invalidateElementSelection(), null;
1968
+ let r = e.clientX - n.left, i = e.clientY - n.top;
1969
+ if (r < 0 || i < 0 || r > n.width || i > n.height) return this._invalidateElementSelection(), null;
1970
+ let a = ++this.elementHitGeneration, o = this.currentSlide, s = {
1971
+ x: r / n.width * t.slideWidth,
1972
+ y: i / n.height * t.slideHeight
1973
+ }, c;
1974
+ try {
1975
+ c = await t.getElementContextAt(o, s, {
1976
+ tolerance: this.elementHitTolerance / n.width * t.slideWidth,
1977
+ maxTextCharacters: G
1978
+ });
1979
+ } catch (e) {
1980
+ if (this.destroyed || a !== this.elementHitGeneration || o !== this.currentSlide || t !== this.engine) return null;
1981
+ throw e;
1982
+ }
1983
+ return this.destroyed || a !== this.elementHitGeneration || o !== this.currentSlide || t !== this.engine ? null : (this._setElementContext(c), this.destroyed ? null : this.getSelectionContext());
1984
+ }
1985
+ destroy() {
1986
+ this.destroyed || (this.destroyed = !0, this.errorRouter.close(), this.renderDispatcher.destroy(), o(this.canvas), this.handle?.destroy(), this.handle = null, this._unbindLayoutPresentation(), this.presentationOwner.close(), this._invalidateFind(), this.selectionChangeListener &&= (this.wrapper.ownerDocument.removeEventListener("selectionchange", this.selectionChangeListener), null), this.elementHitGeneration++, this.elementClickListener &&= (this.wrapper.removeEventListener("click", this.elementClickListener), null), this.contextMenuListener &&= (this.wrapper.removeEventListener("contextmenu", this.contextMenuListener), null), this.elementContext = null, this.canvasMount.restore());
1987
+ }
1988
+ }, Lt = 150, Rt = "0 1px 3px rgba(0,0,0,0.2)", zt = 12, Bt;
1989
+ function Vt() {
1990
+ return Bt ??= import("./comment-ui-runtime-BelHJt73.js");
1991
+ }
1992
+ var $ = 440, Ht = 20, Ut = Symbol("PptxScrollViewer.borrowedPresentation"), Wt = class e {
1993
+ _presentationOwner;
1994
+ get _pres() {
1995
+ return this._presentationOwner.current;
1996
+ }
1997
+ _borrowed;
1998
+ _opts;
1999
+ _errorRouter;
2000
+ _container;
2001
+ _wrapper;
2002
+ _scrollHost;
2003
+ _spacer;
2004
+ _mode;
2005
+ _scale = 1;
2006
+ _scaleEstablished = !1;
2007
+ _pendingScale = null;
2008
+ _slots = /* @__PURE__ */ new Map();
2009
+ _free = [];
2010
+ _uniformSlideHeight = 0;
2011
+ _lastRange = null;
2012
+ _lastTopIndex = -1;
2013
+ _lastReportedTotal = -1;
2014
+ _lastReportedLayoutComplete = null;
2015
+ _layoutUnsubscribe = null;
2016
+ _scrollListener = null;
2017
+ _selectionChangeListener = null;
2018
+ _selectionContextKey = "null";
2019
+ _elementClickListener = null;
2020
+ _contextMenuListener = null;
2021
+ _commentOutsidePointerListener = null;
2022
+ _elementContext = null;
2023
+ _activeCommentId = null;
2024
+ _activeCommentSlide = null;
2025
+ _commentNavigationGeneration = 0;
2026
+ _commentUi = null;
2027
+ _commentGeometryScheduled = !1;
2028
+ _commentGeometryFrame = null;
2029
+ _pendingCommentGeometry = /* @__PURE__ */ new Map();
2030
+ _hasComments = !1;
2031
+ _reviewOriginPx = 0;
2032
+ _commentScanFrontier = 0;
2033
+ _layoutWaiters = /* @__PURE__ */ new Set();
2034
+ _layoutFailed = !1;
2035
+ _elementHitGeneration = 0;
2036
+ _elementHitTolerance;
2037
+ _destroyed = !1;
2038
+ _slideInFlight = /* @__PURE__ */ new Set();
2039
+ _renderEpoch = 0;
2040
+ _settleTimer = null;
2041
+ _wheelListener = null;
2042
+ _pendingZoomAnchor = null;
2043
+ _resizeObserver = null;
2044
+ _prevBase = 0;
2045
+ _lastFitWidth = 0;
2046
+ _pageShadow;
2047
+ _find = new Be(() => this.slideCount, (e) => this._collectSlideRuns(e));
2048
+ _findGeneration = 0;
2049
+ _findActive = !1;
2050
+ _findMeasureCtx;
2051
+ static fromPresentation(t, n, r = {}) {
2052
+ return new e(t, {
2053
+ ...r,
2054
+ [Ut]: n
2055
+ });
2056
+ }
2057
+ constructor(e, t = {}) {
2058
+ 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.");
2059
+ this._container = e, this._opts = t, this._errorRouter = new he("PptxScrollViewer", t.onError);
2060
+ let n = t.elementHitTolerance ?? 6;
2061
+ if (!Number.isFinite(n) || n < 0) throw RangeError("elementHitTolerance must be a finite non-negative number.");
2062
+ this._elementHitTolerance = n, this._pageShadow = t.pageShadow ?? Rt;
2063
+ let r = t[Ut];
2064
+ this._borrowed = r !== void 0, r ? (this._presentationOwner = new E("PptxScrollViewer", r, !1), this._mode = k("PptxScrollViewer", t.mode, r), this._scanAvailableComments(r, !1)) : (this._presentationOwner = new E("PptxScrollViewer"), this._mode = k("PptxScrollViewer", t.mode, void 0)), 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._commentsEnabled() && Vt().then((e) => {
2065
+ if (!this._destroyed) {
2066
+ this._commentUi = e;
2067
+ for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
2068
+ }
2069
+ }).catch((e) => this._reportRenderError(e)), t.enableTextSelection && (t.onSelectionContextChange || t.enableElementSelection) && (this._selectionChangeListener = () => this._emitSelectionContextChange(), this._wrapper.ownerDocument.addEventListener("selectionchange", this._selectionChangeListener)), t.enableElementSelection && (this._elementClickListener = (e) => {
2070
+ this._onElementClick(e).catch((e) => this._reportRenderError(e));
2071
+ }, this._scrollHost.addEventListener("click", this._elementClickListener)), t.onContextMenu && (this._contextMenuListener = (e) => this._onContextMenu(e), this._scrollHost.addEventListener("contextmenu", this._contextMenuListener)), this._scrollListener = () => this._onScroll(), this._scrollHost.addEventListener("scroll", this._scrollListener), t.comments && (this._commentOutsidePointerListener = (e) => {
2072
+ if (!Ae(e, this._wrapper, "ooxmlCommentId") && this._activeCommentId !== null) {
2073
+ this._activeCommentId = null, this._activeCommentSlide = null;
2074
+ for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
2075
+ this._emitSelectionContextChange();
2076
+ }
2077
+ }, this._wrapper.ownerDocument.addEventListener("pointerdown", this._commentOutsidePointerListener)), this._opts.enableZoom !== !1 && (this._wheelListener = (e) => {
2078
+ if (!(e.ctrlKey || e.metaKey) || (e.preventDefault(), e.deltaY === 0)) return;
2079
+ let t = this._scrollHost.getBoundingClientRect(), n = e.clientX - t.left, r = e.clientY - t.top;
2080
+ this._pendingZoomAnchor = Number.isFinite(n) && Number.isFinite(r) ? {
2081
+ x: n,
2082
+ y: r
2083
+ } : null, this.setScale(be(this._scale, e.deltaY));
2084
+ }, this._scrollHost.addEventListener("wheel", this._wheelListener, { passive: !1 })), typeof ResizeObserver < "u" && (this._resizeObserver = new ResizeObserver(() => this._onResize()), this._resizeObserver.observe(this._container)), this._borrowed && (this._bindLayoutPresentation(r), this.relayout());
2085
+ }
2086
+ async load(e) {
2087
+ if (this._destroyed) throw Error("PptxScrollViewer is destroyed");
2088
+ if (this._borrowed) throw Error("PptxScrollViewer.load() is unsupported on a Viewer created by fromPresentation(); the borrowed presentation is already loaded.");
2089
+ let t = !1;
2090
+ try {
2091
+ let n = await this._presentationOwner.replace(() => Y.load(e, {
2092
+ password: this._opts.password,
2093
+ useGoogleFonts: this._opts.useGoogleFonts,
2094
+ maxZipEntryBytes: this._opts.maxZipEntryBytes,
2095
+ resourceLimits: this._opts.resourceLimits,
2096
+ debug: this._opts.debug,
2097
+ onResourceMetrics: this._opts.onResourceMetrics,
2098
+ workerTimeoutMs: this._opts.workerTimeoutMs,
2099
+ wasmUrl: this._opts.wasmUrl,
2100
+ math: this._opts.math,
2101
+ threeD: this._opts.threeD,
2102
+ regionMap: this._opts.regionMap,
2103
+ chartEx: this._opts.chartEx,
2104
+ mode: this._mode,
2105
+ progressiveLayout: this._opts.progressiveLayout,
2106
+ onLayoutProgress: this._opts.onLayoutProgress,
2107
+ onLayoutPartial: this._opts.onLayoutPartial,
2108
+ onLayoutComplete: this._opts.onLayoutComplete
2109
+ }), (e) => {
2110
+ if (this._invalidateElementSelection(!1), t = !0, this._invalidateFind(), this._findActive = !1, this._activeCommentId = null, this._activeCommentSlide = null, this._hasComments = !1, this._commentScanFrontier = 0, this._beginCommentNavigation(), this._unbindLayoutPresentation(), e) {
2111
+ for (let [e, t] of [...this._slots]) this._recycleSlot(e, t);
2112
+ this._lastTopIndex = -1;
2113
+ }
2114
+ });
2115
+ if (!n) return;
2116
+ if (this._destroyed) throw Error("PptxScrollViewer is destroyed");
2117
+ this._invalidateFind(), this._findActive = !1, this._activeCommentId = null, this._activeCommentSlide = null, this._hasComments = !1, this._commentScanFrontier = 0, this._scanAvailableComments(n, !1), this._bindLayoutPresentation(n);
2118
+ let r = [];
2119
+ this._relayout(r), await Promise.all(r);
2120
+ } catch (e) {
2121
+ throw this._destroyed ? Error("PptxScrollViewer is destroyed") : e instanceof Error ? e : Error(String(e));
2122
+ }
2123
+ t && !this._destroyed && this._emitSelectionContextChange();
2124
+ }
2125
+ get slideCount() {
2126
+ return this._pres?.slideCount ?? 0;
2127
+ }
2128
+ get availableSlideCount() {
2129
+ return this._pres?.availableSlideCount ?? this.slideCount;
2130
+ }
2131
+ get layoutComplete() {
2132
+ return this._pres?.layoutComplete ?? !0;
2133
+ }
2134
+ async waitUntilLayoutComplete() {
2135
+ await this._errorRouter.ownBackgroundLifecycle(async () => {
2136
+ await this._pres?.waitUntilLayoutComplete?.();
2137
+ });
2138
+ }
2139
+ _slideWidthPx() {
2140
+ return this._pres.slideWidth / M * this._scale;
2141
+ }
2142
+ _slideHeightPx() {
2143
+ return this._pres.slideHeight / M * this._scale;
2144
+ }
2145
+ _fitWidthPx() {
2146
+ if (this._opts.width && this._opts.width > 0) return this._opts.width;
2147
+ let e = this._scrollHost.clientWidth || this._container.clientWidth;
2148
+ if (e <= 0) return 0;
2149
+ let { left: t, right: n } = this._padH(), r = e - t - n;
2150
+ return r <= 0 ? 0 : r;
2151
+ }
2152
+ _commentMarginExtent() {
2153
+ return this._hasCommentMargin() ? (zt + $) * this._commentZoom() : 0;
2154
+ }
2155
+ _hasCommentMargin() {
2156
+ return this._commentsEnabled() && this._hasComments && this._commentsOptions()?.cards !== !1;
2157
+ }
2158
+ _commentZoom() {
2159
+ return this._scaleEstablished ? this._scale : 1;
2160
+ }
2161
+ _commentsEnabled() {
2162
+ return this._opts.comments === !0 || typeof this._opts.comments == "object";
2163
+ }
2164
+ _commentsOptions() {
2165
+ return typeof this._opts.comments == "object" ? this._opts.comments : void 0;
2166
+ }
2167
+ _commentSide() {
2168
+ let e = this._commentsOptions()?.side;
2169
+ return e === "left" || e === "right" ? e : (this._container.ownerDocument.defaultView?.getComputedStyle?.(this._container).direction || this._container.dir || this._container.style.direction) === "rtl" ? "left" : "right";
2170
+ }
2171
+ _syncCommentMarginGeometry(e) {
2172
+ if (!e) return;
2173
+ let t = this._commentZoom(), n = `calc(100% + ${zt * t}px)`;
2174
+ e.style.left = this._commentSide() === "right" ? n : "", e.style.right = this._commentSide() === "left" ? n : "", e.style.width = `${$ * t}px`, e.style.fontSize = `${Ht}px`, e.dataset.ooxmlCommentZoom = String(t);
2175
+ }
2176
+ _scanAvailableComments(e, t) {
2177
+ if (!this._commentsEnabled() || this._hasComments) return;
2178
+ let n = this._commentsOptions()?.includeResolved === !0, r = Math.min(e.availableSlideCount, e.slideCount);
2179
+ for (let i = this._commentScanFrontier; i < r; i++) if (e.getComments(i).some((e) => n || e.status !== "resolved" && e.status !== "closed")) {
2180
+ this._commentScanFrontier = r, this._hasComments = !0, t && this._refreshDiscoveredComments();
2181
+ return;
2182
+ }
2183
+ this._commentScanFrontier = Math.max(this._commentScanFrontier, r);
2184
+ }
2185
+ _refreshDiscoveredComments() {
2186
+ this._syncSpacerWidth();
2187
+ for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
2188
+ }
2189
+ _baseScale() {
2190
+ if (!this._pres || this._pres.slideCount === 0) return 0;
2191
+ let e = this._fitWidthPx(), t = this._pres.slideWidth / M;
2192
+ return e <= 0 || t <= 0 ? 0 : e / t;
2193
+ }
2194
+ relayout() {
2195
+ this._relayout();
2196
+ }
2197
+ _relayout(e) {
2198
+ if (this._pres) {
2199
+ if (!this._scaleEstablished) {
2200
+ let e = this._baseScale();
2201
+ if (e > 0) {
2202
+ if (this._scale = e, this._prevBase = e, this._lastFitWidth = this._fitWidthPx(), this._scaleEstablished = !0, this._pendingScale !== null) {
2203
+ let e = this._pendingScale;
2204
+ this._pendingScale = null, e !== this._scale && (this._scale = e, this._opts.onScaleChange?.(e));
2205
+ }
2206
+ } else return;
2207
+ }
2208
+ this._recomputeHeights(), this._syncSpacer(), this._mountVisible(e);
2209
+ }
2210
+ }
2211
+ _recomputeHeights() {
2212
+ this._uniformSlideHeight = this._slideHeightPx();
2213
+ }
2214
+ _gap() {
2215
+ return this._opts.gap ?? 16;
2216
+ }
2217
+ _overscan() {
2218
+ return this._opts.overscan ?? 1;
2219
+ }
2220
+ _mediaOverscan() {
2221
+ return this._opts.mediaOverscan ?? 1;
2222
+ }
2223
+ _pad() {
2224
+ let e = this._gap();
2225
+ return {
2226
+ leading: this._opts.paddingTop ?? e,
2227
+ trailing: this._opts.paddingBottom ?? e
2228
+ };
2229
+ }
2230
+ _padH() {
2231
+ let e = this._gap();
2232
+ return {
2233
+ left: this._opts.paddingLeft ?? e,
2234
+ right: this._opts.paddingRight ?? e
2235
+ };
2236
+ }
2237
+ _slideOffset(e) {
2238
+ return this._pad().leading + e * (this._uniformSlideHeight + this._gap());
2239
+ }
2240
+ _slideIndexAtOffset(e) {
2241
+ return A(this._pres?.slideCount ?? 0, this._uniformSlideHeight, this._gap(), e, 0, 0, this._pad()).topIndex;
2242
+ }
2243
+ _rangeAt(e, t) {
2244
+ return A(this._pres?.slideCount ?? 0, this._uniformSlideHeight, this._gap(), e, this._scrollHost.clientHeight, t, this._pad());
2245
+ }
2246
+ _range() {
2247
+ return this._rangeAt(this._scrollHost.scrollTop, this._overscan());
2248
+ }
2249
+ _mediaRange() {
2250
+ return this._rangeAt(this._scrollHost.scrollTop, this._mediaOverscan());
2251
+ }
2252
+ _rangeContains(e, t) {
2253
+ return t >= e.start && t <= e.end;
2254
+ }
2255
+ _syncSpacer() {
2256
+ let e = this._range();
2257
+ this._lastRange = e, this._spacer.style.height = `${e.totalHeight}px`, this._syncSpacerWidth();
2258
+ }
2259
+ _syncSpacerWidth() {
2260
+ let { left: e, right: t } = this._padH(), n = this._commentMarginExtent(), r = this._commentSide() === "left" ? n : 0, i = r - this._reviewOriginPx, a = Math.max(0, this._scrollHost.scrollLeft + i);
2261
+ this._spacer.style.width = `${this._slideWidthPx() + n + e + t}px`, i !== 0 && (this._reviewOriginPx = r, this._scrollHost.style["--ooxml-review-origin-x"] = `${r}px`, this._scrollHost.scrollLeft = a);
2262
+ }
2263
+ _onScroll() {
2264
+ !this._pres || !this._scaleEstablished || this._mountVisible(void 0, !1);
2265
+ }
2266
+ _mountVisible(e, t = !0) {
2267
+ if (!this._pres || this._pres.slideCount === 0) return;
2268
+ let n = this._range(), r = this._opts.enableMediaPlayback ? this._mediaRange() : null;
2269
+ this._lastRange = n;
2270
+ for (let [e, t] of [...this._slots]) (e < n.start || e > n.end) && this._recycleSlot(e, t);
2271
+ for (let i = n.start; i <= n.end; i++) if (this._slots.has(i)) t && this._positionSlot(this._slots.get(i), i, n);
2272
+ else {
2273
+ let t = this._acquireSlot();
2274
+ this._positionSlot(t, i, n), this._slots.set(i, t), this._redrawSlotComments(i, t);
2275
+ let a = this._renderSlot(i, t, !!r && this._rangeContains(r, i), e === void 0);
2276
+ e && a && i < this.availableSlideCount && e.push(a);
2277
+ }
2278
+ r && this._syncMediaPlayback(r), this._emitVisibleSlideChange(n);
2279
+ }
2280
+ _applyPageShadow(e) {
2281
+ this._pageShadow !== !1 && (e.style.boxShadow = this._pageShadow);
2282
+ }
2283
+ _acquireSlot() {
2284
+ let e = this._free.pop();
2285
+ if (e) return this._scrollHost.appendChild(e.wrapper), e;
2286
+ let t = document.createElement("div");
2287
+ t.style.cssText = "position:absolute;";
2288
+ let n = document.createElement("canvas");
2289
+ n.style.cssText = "display:block;background:#fff;", this._applyPageShadow(n), t.appendChild(n);
2290
+ let r = null;
2291
+ 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));
2292
+ let i = document.createElement("div");
2293
+ i.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;overflow:hidden;pointer-events:none;", t.appendChild(i);
2294
+ let a = document.createElement("span");
2295
+ a.style.cssText = [
2296
+ "position:absolute",
2297
+ "top:0",
2298
+ "right:0",
2299
+ "bottom:0",
2300
+ "left:0",
2301
+ "display:none",
2302
+ "align-items:center",
2303
+ "justify-content:center",
2304
+ "background:rgba(255,255,255,0.72)",
2305
+ "pointer-events:none",
2306
+ "z-index:4"
2307
+ ].join(";"), a.setAttribute("role", "status"), a.setAttribute("aria-live", "polite"), a.setAttribute("aria-label", "Loading slide");
2308
+ let o = document.createElement("progress");
2309
+ o.setAttribute("aria-hidden", "true"), a.appendChild(o), t.appendChild(a);
2310
+ let s = null, c = null, l = null;
2311
+ this._commentsEnabled() && (s = document.createElement("div"), s.style.cssText = "position:absolute;inset:0;overflow:hidden;pointer-events:none;", t.appendChild(s), this._commentsOptions()?.cards !== !1 && (c = document.createElement("div"), c.style.cssText = "position:absolute;top:0;height:100%;box-sizing:border-box;overflow-x:hidden;overflow-y:auto;pointer-events:auto;", this._syncCommentMarginGeometry(c), this._commentsOptions()?.connectors !== void 0 && (l = document.createElement("div"), l.style.cssText = "position:absolute;top:0;left:0;overflow:visible;pointer-events:none;", t.appendChild(l)), t.appendChild(c)));
2312
+ let u = pe(t, this._opts.enableElementSelection === !0);
2313
+ return this._scrollHost.appendChild(t), {
2314
+ wrapper: t,
2315
+ canvas: n,
2316
+ textLayer: r,
2317
+ highlightLayer: i,
2318
+ elementLayer: u,
2319
+ loadingLayer: a,
2320
+ commentMarkerLayer: s,
2321
+ commentMargin: c,
2322
+ commentDecorationLayer: l,
2323
+ commentElementBounds: Object.freeze([]),
2324
+ commentGeometry: null,
2325
+ commentAnchorSlide: -1,
2326
+ commentAnchorGeneration: 0,
2327
+ renderedSlide: -1,
2328
+ renderedScale: -1,
2329
+ dispatcher: new O(n, this._mode === "worker" && !this._opts.enableMediaPlayback),
2330
+ presentationHandle: null,
2331
+ mediaInteractive: !1,
2332
+ renderGeneration: 0,
2333
+ presentationGeneration: 0
2334
+ };
2335
+ }
2336
+ _recycleSlot(e, t) {
2337
+ this._slots.delete(e), t.renderGeneration++, t.presentationGeneration++, t.presentationHandle?.destroy(), t.presentationHandle = null, t.mediaInteractive = !1, t.dispatcher.destroy(), this._destroyed || (t.dispatcher = new O(t.canvas, this._mode === "worker" && !this._opts.enableMediaPlayback)), 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.loadingLayer.style.display = "none", t.commentMarkerLayer && (t.commentMarkerLayer.replaceChildren(), t.commentMarkerLayer.style.visibility = ""), t.commentMargin && (this._commentUi?.disposeReadOnlyCommentMargin(t.commentMargin), this._commentUi || t.commentMargin.replaceChildren(), t.commentMargin.style.visibility = ""), t.commentDecorationLayer && (this._commentUi?.disposeReadOnlyCommentDecoration(t.commentDecorationLayer), this._commentUi || t.commentDecorationLayer.replaceChildren(), t.commentDecorationLayer.style.visibility = ""), t.commentElementBounds = Object.freeze([]), t.commentGeometry = null, t.commentAnchorSlide = -1, t.commentAnchorGeneration++, D(t.elementLayer, null), t.canvas.style.height = "", t.renderedSlide = -1, t.renderedScale = -1, t.wrapper.remove(), this._free.push(t);
2338
+ }
2339
+ _positionSlot(e, t, n) {
2340
+ e.wrapper.dataset.slideIndex = String(t), e.wrapper.style.top = `${this._slideOffset(t)}px`;
2341
+ let r = this._slideWidthPx();
2342
+ if (e.wrapper.style.width = `${r}px`, e.wrapper.style.height = `${this._slideHeightPx()}px`, this._syncCommentMarginGeometry(e.commentMargin), e.commentDecorationLayer) {
2343
+ let t = this._commentMarginExtent();
2344
+ e.commentDecorationLayer.style.left = this._commentSide() === "left" ? `${-t}px` : "0px", e.commentDecorationLayer.style.width = `${r + t}px`, e.commentDecorationLayer.style.height = `${this._slideHeightPx()}px`;
2345
+ }
2346
+ this._redrawElementOutlineForSlot(t, e);
2347
+ let { left: i } = this._padH(), a = Math.max(i, (this._scrollHost.clientWidth - r) / 2);
2348
+ e.wrapper.style.left = this._commentSide() === "left" && this._commentsEnabled() ? `calc(${a}px + var(--ooxml-review-origin-x, 0px))` : `${a}px`;
2349
+ }
2350
+ _dpr() {
2351
+ return this._opts.dpr ?? (typeof window < "u" && window.devicePixelRatio || 1);
2352
+ }
2353
+ _renderSlot(e, t, n = !1, r = !0) {
2354
+ if (!this._pres || t.renderedSlide === e) return null;
2355
+ if (e >= this.availableSlideCount && !this.layoutComplete) return t.renderedSlide = -1, t.mediaInteractive = !1, t.loadingLayer.style.display = "flex", null;
2356
+ t.renderedSlide = e;
2357
+ let i = ++t.renderGeneration;
2358
+ t.loadingLayer.style.display = e >= this.availableSlideCount && !this.layoutComplete ? "flex" : "none";
2359
+ let a = this._dpr(), o = this._slideWidthPx(), s = this._renderEpoch, c = this._scale, l = t.dispatcher, u = l.begin();
2360
+ if (this._opts.enableMediaPlayback && n) return t.mediaInteractive = !0, this._trackSlotLoading(e, t, i, this._renderInteractiveSlot(e, t, o, a, c, s, r));
2361
+ if (t.mediaInteractive = !1, this._mode === "worker") return this._trackSlotLoading(e, t, i, this._renderSlotBitmap(e, t, o, a, c, i, l, u, r));
2362
+ let d = [], f = !!this._opts.enableTextSelection && !!t.textLayer, p = f || this._findActive, m = p ? (e) => d.push(e) : void 0, h = t.canvas;
2363
+ return this._trackSlotLoading(e, t, i, Q(this._pres, h, e, "main", {
2364
+ width: o,
2365
+ dpr: a,
2366
+ onTextRun: m
2367
+ }).then(() => {
2368
+ i !== t.renderGeneration || !l.isCurrent(u) || h !== t.canvas || s !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e || (t.renderedScale = c, f && t.textLayer && I(t.textLayer, d, Math.round(o), Math.round(this._slideHeightPx()), this._hyperlinkHandler(), e), p && this._refreshFindRuns(e, d), this._commitSlotComments(e, t), this._redrawSlotHighlights(e, t));
2369
+ }).catch((n) => {
2370
+ if (i === t.renderGeneration && l.isCurrent(u) && h === t.canvas && s === this._renderEpoch && this._slots.get(e) === t && t.renderedSlide === e) if (r) this._reportRenderError(n);
2371
+ else throw n;
2372
+ }));
2373
+ }
2374
+ async _trackSlotLoading(e, t, n, r) {
2375
+ try {
2376
+ await r;
2377
+ } finally {
2378
+ n === t.renderGeneration && this._slots.get(e) === t && t.renderedSlide === e && (t.loadingLayer.style.display = "none");
2379
+ }
2380
+ }
2381
+ _bindLayoutPresentation(e) {
2382
+ this._unbindLayoutPresentation();
2383
+ let t = !0;
2384
+ this._layoutUnsubscribe = At(e, () => ({
2385
+ availableSlides: e.availableSlideCount,
2386
+ slideCount: e.slideCount,
2387
+ exact: e.layoutComplete,
2388
+ complete: e.layoutComplete
2389
+ }), (n) => {
2390
+ if (t) {
2391
+ t = !1;
2392
+ return;
2393
+ }
2394
+ this._onLayoutPublication(e, n);
2395
+ }, (e) => this._reportRenderError(e));
2396
+ }
2397
+ _unbindLayoutPresentation() {
2398
+ this._layoutUnsubscribe?.(), this._layoutUnsubscribe = null, this._layoutFailed = !1, this._wakeLayoutWaiters();
2399
+ }
2400
+ _onLayoutPublication(e, t) {
2401
+ if (this._destroyed || e !== this._pres) return;
2402
+ if (this._wakeLayoutWaiters(), t.error !== void 0) {
2403
+ this._layoutFailed = !0, this._errorRouter.reportBackground(t.error, this._opts.onLayoutComplete !== void 0);
2404
+ return;
2405
+ }
2406
+ this._scanAvailableComments(e, !0);
2407
+ let n = this._opts.enableMediaPlayback ? this._mediaRange() : null;
2408
+ for (let [t, r] of this._slots) t >= e.availableSlideCount || r.renderedSlide === t || this._renderSlot(t, r, !!n && this._rangeContains(n, t));
2409
+ this._lastRange && this._emitVisibleSlideChange(this._lastRange);
2410
+ }
2411
+ _wakeLayoutWaiters() {
2412
+ for (let e of this._layoutWaiters) e();
2413
+ this._layoutWaiters.clear();
2414
+ }
2415
+ _beginCommentNavigation() {
2416
+ let e = ++this._commentNavigationGeneration;
2417
+ return this._wakeLayoutWaiters(), e;
2418
+ }
2419
+ async _waitForSlideMetadata(e, t, n) {
2420
+ return await this._errorRouter.ownBackgroundLifecycle(async () => {
2421
+ for (; !this._destroyed && n === this._commentNavigationGeneration && e === this._pres && t >= e.availableSlideCount && !e.layoutComplete && !this._layoutFailed;) await new Promise((e) => this._layoutWaiters.add(e));
2422
+ return this._destroyed || e !== this._pres || ((e.layoutComplete || this._layoutFailed) && await e.waitUntilLayoutComplete?.(), n !== this._commentNavigationGeneration) ? !1 : t < e.availableSlideCount;
2423
+ });
2424
+ }
2425
+ _emitVisibleSlideChange(e) {
2426
+ if (!this._pres) return;
2427
+ let t = this._pres.slideCount, n = this.layoutComplete;
2428
+ e.topIndex === this._lastTopIndex && t === this._lastReportedTotal && n === this._lastReportedLayoutComplete || (this._lastTopIndex = e.topIndex, this._lastReportedTotal = t, this._lastReportedLayoutComplete = n, this._opts.onVisibleSlideChange?.(e.topIndex, t, n));
2429
+ }
2430
+ _renderInteractiveSlot(e, t, n, r, i, a, o = !0) {
2431
+ if (!this._pres) return Promise.resolve();
2432
+ let s = ++t.presentationGeneration;
2433
+ t.presentationHandle?.destroy(), t.presentationHandle = null;
2434
+ let c = [], l = !!this._opts.enableTextSelection && !!t.textLayer, u = l || this._findActive, d = u ? (e) => c.push(e) : void 0;
2435
+ return this._pres.presentSlide(t.canvas, e, {
2436
+ width: n,
2437
+ dpr: r,
2438
+ onTextRun: d,
2439
+ onError: (e) => {
2440
+ s === t.presentationGeneration && this._reportRenderError(e);
2441
+ }
2442
+ }).then((r) => {
2443
+ if (s !== t.presentationGeneration || !t.mediaInteractive || a !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e) {
2444
+ r.destroy();
2445
+ return;
2446
+ }
2447
+ t.presentationHandle = r, t.renderedScale = i, l && t.textLayer && I(t.textLayer, c, Math.round(n), Math.round(this._slideHeightPx()), this._hyperlinkHandler(), e), u && this._refreshFindRuns(e, c), this._commitSlotComments(e, t), this._redrawSlotHighlights(e, t);
2448
+ }).catch((e) => {
2449
+ if (s === t.presentationGeneration) if (o) this._reportRenderError(e);
2450
+ else throw e;
2451
+ });
2452
+ }
2453
+ _syncMediaPlayback(e = this._mediaRange()) {
2454
+ if (this._opts.enableMediaPlayback) for (let [t, n] of this._slots) {
2455
+ let r = this._rangeContains(e, t);
2456
+ 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));
2457
+ }
2458
+ }
2459
+ _reportRenderError(e) {
2460
+ this._errorRouter.report(e);
2461
+ }
2462
+ async _renderSlotBitmap(e, t, n, r, i, a = ++t.renderGeneration, o = t.dispatcher, s = o.begin(), c = !0) {
2463
+ if (this._slideInFlight.has(e) || this._slots.get(e) !== t) return;
2464
+ let l = this._renderEpoch;
2465
+ this._slideInFlight.add(e);
2466
+ let u = t.canvas, d = !1, f = !!this._opts.enableTextSelection && !!t.textLayer, p = f || this._findActive, m = [];
2467
+ try {
2468
+ let c = await Q(this._pres, u, e, "worker", {
2469
+ width: n,
2470
+ dpr: r,
2471
+ onTextRun: p ? (e) => m.push(e) : void 0
2472
+ });
2473
+ if (a !== t.renderGeneration || !o.isCurrent(s) || u !== t.canvas || l !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e) {
2474
+ c.close();
2475
+ return;
2476
+ }
2477
+ let h = {
2478
+ cssWidth: Math.round(c.width / r),
2479
+ cssHeight: Math.round(c.height / r)
2480
+ };
2481
+ if (!(this._opts.enableMediaPlayback ? o.commitBitmapTo2d(s, c, h) : o.commitBitmap(s, c, h))) return;
2482
+ t.renderedScale = i, t.textLayer && (t.textLayer.style.transform = "", t.textLayer.style.transformOrigin = "", f && I(t.textLayer, m, Math.round(n), Math.round(this._slideHeightPx()), this._hyperlinkHandler(), e)), p && this._refreshFindRuns(e, m), this._commitSlotComments(e, t), this._redrawSlotHighlights(e, t), d = !0;
2483
+ } catch (n) {
2484
+ if (a === t.renderGeneration && o.isCurrent(s) && u === t.canvas && l === this._renderEpoch && this._slots.get(e) === t && t.renderedSlide === e) if (c) this._reportRenderError(n);
2485
+ else throw n;
2486
+ } finally {
2487
+ this._slideInFlight.delete(e);
2488
+ let n = this._slots.get(e);
2489
+ !d && n && (n !== t || l !== this._renderEpoch || a !== n.renderGeneration || !o.isCurrent(s)) && !this._slideInFlight.has(e) && !this._destroyed && !(this._opts.enableMediaPlayback && n.mediaInteractive) && this._renderSlotBitmap(e, n, this._slideWidthPx(), this._dpr(), this._scale);
2490
+ }
2491
+ }
2492
+ setScale(e) {
2493
+ let t = this._opts.zoomMin ?? .1, n = this._opts.zoomMax ?? 4, r = Math.min(n, Math.max(t, e)), i = this._pendingZoomAnchor;
2494
+ if (this._pendingZoomAnchor = null, !this._pres || this._pres.slideCount === 0 || !this._scaleEstablished) {
2495
+ this._pendingScale = r;
2496
+ return;
2497
+ }
2498
+ if (r === this._scale) return;
2499
+ let a = this._scale, o = i ? i.y : 0, s = this._scrollHost.scrollTop, c = s + o, l = this._slideIndexAtOffset(c), u = this._uniformSlideHeight, d = u > 0 ? (c - this._slideOffset(l)) / u : 0;
2500
+ d = Math.min(1, Math.max(0, d));
2501
+ let f = this._padH().left, p = this._scrollHost.scrollLeft || 0;
2502
+ this._renderEpoch++, this._scale = r, this._recomputeHeights();
2503
+ let m = this._rangeAt(0, this._overscan());
2504
+ this._spacer.style.height = `${m.totalHeight}px`, this._syncSpacerWidth();
2505
+ let h = Math.max(0, m.totalHeight - this._scrollHost.clientHeight), g = this._slideOffset(l) + d * this._uniformSlideHeight, _ = c < this._slideOffset(0) ? s : g - o;
2506
+ if (this._scrollHost.scrollTop = Math.min(h, Math.max(0, _)), i) {
2507
+ let e = Math.max(0, (this._spacer.offsetWidth || 0) - this._scrollHost.clientWidth);
2508
+ this._scrollHost.scrollLeft = oe(p, i.x - f, a, r, { maxScroll: e });
2509
+ }
2510
+ this._previewVisible(), this._scheduleSettle(), this._opts.onScaleChange?.(r);
2511
+ }
2512
+ getScale() {
2513
+ return this._scaleEstablished ? this._scale : this._pendingScale ?? 1;
2514
+ }
2515
+ zoomIn() {
2516
+ this.setScale(ve(this.getScale()));
2517
+ }
2518
+ zoomOut() {
2519
+ this.setScale(xe(this.getScale()));
2520
+ }
2521
+ fitWidth() {
2522
+ this._fit("width");
2523
+ }
2524
+ fitPage() {
2525
+ this._fit("page");
2526
+ }
2527
+ _fit(e) {
2528
+ if (!this._pres || this._pres.slideCount === 0) return;
2529
+ let t = T({
2530
+ contentWidth: this._pres.slideWidth / M,
2531
+ contentHeight: this._pres.slideHeight / M,
2532
+ containerWidth: this._fitWidthPx(),
2533
+ containerHeight: this._scrollHost.clientHeight
2534
+ }, e);
2535
+ t <= 0 || this.setScale(t);
2536
+ }
2537
+ _previewVisible() {
2538
+ if (!this._pres || this._pres.slideCount === 0) return;
2539
+ let e = this._range(), t = this._opts.enableMediaPlayback ? this._mediaRange() : null;
2540
+ this._lastRange = e;
2541
+ for (let [t, n] of [...this._slots]) (t < e.start || t > e.end) && this._recycleSlot(t, n);
2542
+ for (let n = e.start; n <= e.end; n++) {
2543
+ let r = this._slots.get(n);
2544
+ if (r) this._previewSlot(r, n, e);
2545
+ else {
2546
+ let r = this._acquireSlot();
2547
+ this._positionSlot(r, n, e), this._slots.set(n, r), this._redrawSlotComments(n, r), this._renderSlot(n, r, !!t && this._rangeContains(t, n));
2548
+ }
2549
+ }
2550
+ t && this._syncMediaPlayback(t), this._emitVisibleSlideChange(e);
2551
+ }
2552
+ _previewSlot(e, t, n) {
2553
+ 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) {
2554
+ let t = this._scale / e.renderedScale;
2555
+ e.textLayer.style.transformOrigin = "0 0", e.textLayer.style.transform = `scale(${t})`;
2556
+ }
2557
+ if (e.renderedScale > 0) {
2558
+ let t = this._scale / e.renderedScale, n = Math.round(t * 1e6) / 1e6;
2559
+ e.commentMargin && this._commentUi?.previewReadOnlyCommentMargin(e.commentMargin, t);
2560
+ for (let t of e.commentMarkerLayer?.children ?? []) t.dataset.ooxmlCommentMarker !== void 0 && (t.style.transform = `translate(-50%,-50%) scale(${n})`);
2561
+ e.commentMarkerLayer && (e.commentMarkerLayer.style.visibility = ""), e.commentMargin && (e.commentMargin.style.visibility = ""), e.commentDecorationLayer && (e.commentDecorationLayer.style.visibility = "");
2562
+ return;
2563
+ }
2564
+ e.commentMarkerLayer && (e.commentMarkerLayer.style.visibility = "hidden"), e.commentMargin && (e.commentMargin.style.visibility = "hidden"), e.commentDecorationLayer && (e.commentDecorationLayer.style.visibility = "hidden");
2565
+ }
2566
+ _scheduleSettle() {
2567
+ this._settleTimer !== null && clearTimeout(this._settleTimer), this._settleTimer = setTimeout(() => {
2568
+ this._settleTimer = null, this._settleRender();
2569
+ }, Lt);
2570
+ }
2571
+ _settleRender() {
2572
+ if (this._destroyed || !this._pres || this._pres.slideCount === 0) return;
2573
+ let e = this._opts.enableMediaPlayback ? this._mediaRange() : null;
2574
+ for (let [t, n] of [...this._slots]) e && !this._rangeContains(e, t) || n.renderedScale !== this._scale && this._settleSlot(t, n);
2575
+ }
2576
+ _settleSlot(e, t) {
2577
+ if (!this._pres) return;
2578
+ let n = this._dpr(), r = this._slideWidthPx(), i = this._scale, a = this._renderEpoch;
2579
+ if (this._opts.enableMediaPlayback && t.mediaInteractive) {
2580
+ this._settleInteractiveSlot(e, t, r, n, i, a);
2581
+ return;
2582
+ }
2583
+ if (this._opts.enableMediaPlayback) return;
2584
+ if (this._mode === "worker") {
2585
+ this._renderSlotBitmap(e, t, r, n, i);
2586
+ return;
2587
+ }
2588
+ let o = document.createElement("canvas"), s = ++t.renderGeneration;
2589
+ o.style.cssText = "display:block;background:#fff;", this._applyPageShadow(o);
2590
+ let c = new O(o, !1), l = c.begin(), u = [], d = !!this._opts.enableTextSelection && !!t.textLayer, f = d || this._findActive, p = f ? (e) => u.push(e) : void 0;
2591
+ Q(this._pres, o, e, "main", {
2592
+ width: r,
2593
+ dpr: n,
2594
+ onTextRun: p
2595
+ }).then(() => {
2596
+ if (s !== t.renderGeneration || !c.isCurrent(l) || a !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e) {
2597
+ c.destroy();
2598
+ return;
2599
+ }
2600
+ let n = t.canvas;
2601
+ t.dispatcher.destroy(), t.wrapper.insertBefore(o, n), n.remove(), t.canvas = o, t.dispatcher = c, t.renderedScale = i, t.textLayer && (t.textLayer.style.transform = "", t.textLayer.style.transformOrigin = "", d && I(t.textLayer, u, Math.round(r), Math.round(this._slideHeightPx()), this._hyperlinkHandler(), e)), f && this._refreshFindRuns(e, u), this._commitSlotComments(e, t), this._redrawSlotHighlights(e, t);
2602
+ }).catch((n) => {
2603
+ s === t.renderGeneration && c.isCurrent(l) && a === this._renderEpoch && this._slots.get(e) === t && t.renderedSlide === e && this._reportRenderError(n), c.destroy();
2604
+ });
2605
+ }
2606
+ _settleInteractiveSlot(e, t, n, r, i, a) {
2607
+ if (!this._pres) return;
2608
+ let o = ++t.presentationGeneration, s = document.createElement("canvas");
2609
+ s.style.cssText = "display:block;background:#fff;", this._applyPageShadow(s);
2610
+ let c = [], l = !!this._opts.enableTextSelection && !!t.textLayer, u = l || this._findActive, d = u ? (e) => c.push(e) : void 0;
2611
+ this._pres.presentSlide(s, e, {
2612
+ width: n,
2613
+ dpr: r,
2614
+ onTextRun: d,
2615
+ onError: (e) => {
2616
+ o === t.presentationGeneration && this._reportRenderError(e);
2617
+ }
2618
+ }).then((r) => {
2619
+ if (o !== t.presentationGeneration || !t.mediaInteractive || a !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e) {
2620
+ r.destroy();
2621
+ return;
2622
+ }
2623
+ let d = t.canvas, f = t.presentationHandle;
2624
+ t.dispatcher.destroy(), t.wrapper.insertBefore(s, d), d.remove(), t.canvas = s, t.dispatcher = new O(s, !1), t.presentationHandle = r, t.renderedScale = i, f?.destroy(), t.textLayer && (t.textLayer.style.transform = "", t.textLayer.style.transformOrigin = "", l && I(t.textLayer, c, Math.round(n), Math.round(this._slideHeightPx()), this._hyperlinkHandler(), e)), u && this._refreshFindRuns(e, c), this._commitSlotComments(e, t), this._redrawSlotHighlights(e, t);
2625
+ }).catch((e) => {
2626
+ o === t.presentationGeneration && this._reportRenderError(e);
2627
+ });
2628
+ }
2629
+ scrollToSlide(e, t) {
2630
+ if (!this._pres || this._pres.slideCount === 0 || !this._scaleEstablished) return;
2631
+ let n = Math.max(0, Math.min(e, this._pres.slideCount - 1)), r = this._rangeAt(0, this._overscan()), i = this._slideOffset(n), a = Math.max(0, r.totalHeight - this._scrollHost.clientHeight), o = Math.min(a, Math.max(0, i)), s = this._scrollHost;
2632
+ typeof s.scrollTo == "function" ? s.scrollTo({
2633
+ top: o,
2634
+ behavior: t?.behavior ?? "auto"
2635
+ }) : this._scrollHost.scrollTop = o, this._mountVisible();
2636
+ }
2637
+ _scrollToSlideCommentTarget(e, t, n, r) {
2638
+ if (!this._pres) return !1;
2639
+ let i = this._slots.get(e), a = new Map((i?.commentElementBounds ?? []).map((e) => [e.elementId, e.bounds])), o = r ?? (t.anchors ?? []).flatMap((e) => {
2640
+ if (e.type !== "drawingElement" && e.type !== "textRange" || !e.elementId) return [];
2641
+ let t = a.get(e.elementId);
2642
+ return t ? [t] : [];
2643
+ })[0], s = t.anchors ?? [], c = Number.isFinite(t.x) && Number.isFinite(t.y) && (s.length === 0 || s.some((e) => e.type === "slide"));
2644
+ if (!o && !c) return !1;
2645
+ let l = o ? o.x + (c ? t.x : o.width) : t.x, u = o ? o.y + (c ? t.y : 0) : t.y, d = this._slideWidthPx(), { left: f } = this._padH(), p = Math.max(f, (this._scrollHost.clientWidth - d) / 2) + this._reviewOriginPx, m = this._rangeAt(0, this._overscan()), h = Math.max(0, m.totalHeight - this._scrollHost.clientHeight), g = this._spacer.offsetWidth || Number.parseFloat(this._spacer.style.width) || 0, _ = Math.max(0, g - this._scrollHost.clientWidth), v = l / M * this._scale, y = u / M * this._scale, b = Math.min(h, Math.max(0, this._slideOffset(e) + y - this._scrollHost.clientHeight / 2)), x = Math.min(_, Math.max(0, p + v - this._scrollHost.clientWidth / 2)), S = this._scrollHost;
2646
+ return typeof S.scrollTo == "function" ? S.scrollTo({
2647
+ top: b,
2648
+ left: x,
2649
+ behavior: n?.behavior ?? "auto"
2650
+ }) : (this._scrollHost.scrollTop = b, this._scrollHost.scrollLeft = x), this._mountVisible(), !0;
2651
+ }
2652
+ async _resolveSlideCommentElementBounds(e, t) {
2653
+ let n = this._pres;
2654
+ if (!n) return;
2655
+ let r = (t.anchors ?? []).flatMap((e) => (e.type === "drawingElement" || e.type === "textRange") && e.elementId ? [e.elementId] : []);
2656
+ if (r.length === 0) return;
2657
+ let i = new Map((this._slots.get(e)?.commentElementBounds ?? []).map((e) => [e.elementId, e.bounds])), a = r.flatMap((e) => {
2658
+ let t = i.get(e);
2659
+ return t ? [t] : [];
2660
+ })[0];
2661
+ if (a) return a;
2662
+ let o = await n.getElementBoundsByIds(e, r);
2663
+ return r.flatMap((e) => {
2664
+ let t = o.find((t) => t.elementId === e);
2665
+ return t ? [t.bounds] : [];
2666
+ })[0];
2667
+ }
2668
+ async goToComment(e, t, n) {
2669
+ if (this._destroyed) throw Error("PptxScrollViewer is destroyed");
2670
+ let r = this._pres;
2671
+ if (!r || !Number.isInteger(e) || !Number.isInteger(t) || e < 0 || e >= r.slideCount || t < 0) return !1;
2672
+ let i = this._beginCommentNavigation();
2673
+ if (e >= r.availableSlideCount && !r.layoutComplete && !await this._waitForSlideMetadata(r, e, i)) return !1;
2674
+ if (this._destroyed) throw Error("PptxScrollViewer is destroyed");
2675
+ if (i !== this._commentNavigationGeneration || r !== this._pres) return !1;
2676
+ let a = r.getComments(e)[t];
2677
+ if (!a) return !1;
2678
+ let o = await this._resolveSlideCommentElementBounds(e, a);
2679
+ if (this._destroyed) throw Error("PptxScrollViewer is destroyed");
2680
+ if (i !== this._commentNavigationGeneration || r !== this._pres) return !1;
2681
+ let s = a.anchors ?? [], c = Number.isFinite(a.x) && Number.isFinite(a.y) && (s.length === 0 || s.some((e) => e.type === "slide"));
2682
+ if (!o && !c || (this.scrollToSlide(e, n), !this._scrollToSlideCommentTarget(e, a, n, o))) return !1;
2683
+ this._activeCommentId = P(a, t, e), this._activeCommentSlide = e, this._elementContext = null;
2684
+ for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
2685
+ return this._emitSelectionContextChange(), !0;
2686
+ }
2687
+ async findText(e, t = {}) {
2688
+ let n = this._pres;
2689
+ if (!n) return [];
2690
+ let r = ++this._findGeneration;
2691
+ if (this._findActive = e.length > 0, e.length === 0) return this._find.invalidate(), this._redrawHighlights(), [];
2692
+ if (n.layoutComplete || await this._errorRouter.ownBackgroundLifecycle(() => n.waitUntilLayoutComplete()), this._destroyed || r !== this._findGeneration || n !== this._pres) return [];
2693
+ let i = await this._errorRouter.ownAwaitable(() => this._find.find(e, t));
2694
+ return this._destroyed || r !== this._findGeneration || n !== this._pres ? [] : (this._redrawHighlights(), i);
2695
+ }
2696
+ async findNext() {
2697
+ return this._activateMatch(this._find.next());
2698
+ }
2699
+ async findPrev() {
2700
+ return this._activateMatch(this._find.prev());
2701
+ }
2702
+ clearFind() {
2703
+ this._findActive = !1, this._invalidateFind(), this._redrawHighlights();
2704
+ }
2705
+ _invalidateFind() {
2706
+ this._findGeneration++, this._find.invalidate();
2707
+ }
2708
+ async _activateMatch(e) {
2709
+ return e && this.scrollToSlide(e.location.slide), this._redrawHighlights(), e;
2710
+ }
2711
+ async _collectSlideRuns(e) {
2712
+ return this._pres ? this._pres.collectSlideRuns(e, this._slideWidthPx()) : [];
2713
+ }
2714
+ _redrawHighlights() {
2715
+ for (let [e, t] of this._slots) this._redrawSlotHighlights(e, t);
2716
+ }
2717
+ _refreshFindRuns(e, t) {
2718
+ this._findActive && this._find.setSlideRuns(e, t);
2719
+ }
2720
+ _redrawSlotComments(e, t) {
2721
+ if (!this._pres || !t.commentMarkerLayer) return;
2722
+ let n = this._commentUi;
2723
+ if (!n) {
2724
+ t.commentMarkerLayer.replaceChildren(), t.commentMargin?.replaceChildren(), t.commentDecorationLayer?.replaceChildren(), t.commentGeometry = null;
2725
+ return;
2726
+ }
2727
+ t.commentGeometry = n.buildPptxCommentMargin(t.commentMarkerLayer, t.commentMargin, this._pres.getComments(e), t.commentElementBounds, e, this._pres.slideWidth, this._pres.slideHeight, this._activeCommentId, (t, n) => {
2728
+ let r = n ? t : this._activeCommentId === t ? null : this._activeCommentId;
2729
+ if (r !== this._activeCommentId) {
2730
+ this._activeCommentId = r, this._activeCommentSlide = r ? e : null, this._elementContext = null;
2731
+ for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
2732
+ this._emitSelectionContextChange();
2733
+ }
2734
+ }, this._commentZoom(), $, this._commentsOptions()?.markers !== !1, this._commentsOptions()?.includeResolved === !0, t.commentDecorationLayer ? () => this._scheduleCommentGeometry(e, t, !1) : void 0, t.commentDecorationLayer ? () => this._scheduleCommentGeometry(e, t, !0) : void 0), this._redrawSlotCommentConnectors(e, t);
2735
+ }
2736
+ _redrawSlotCommentConnectors(e, t) {
2737
+ let n = t.commentDecorationLayer, r = t.commentMargin, i = t.commentGeometry, a = this._commentsOptions()?.connectors;
2738
+ if (!n || !r || !i || !a) return;
2739
+ let o = this._slideWidthPx(), s = this._slideHeightPx(), c = this._commentSide(), l = this._commentMarginExtent(), u = this._commentUi;
2740
+ u && u.buildReadOnlyCommentDecoration(n, Object.freeze({
2741
+ surfaceBounds: Object.freeze({
2742
+ x: c === "left" ? -l : 0,
2743
+ y: 0,
2744
+ width: o + l,
2745
+ height: s
2746
+ }),
2747
+ contentBounds: Object.freeze({
2748
+ x: 0,
2749
+ y: 0,
2750
+ width: o,
2751
+ height: s
2752
+ }),
2753
+ side: c,
2754
+ threads: u.projectReadOnlyCommentMarginScroll(i, r.scrollTop)
2755
+ }), {
2756
+ route: a.route ?? "bezier",
2757
+ stroke: a.stroke ?? "solid",
2758
+ color: a.color,
2759
+ activeColor: a.activeColor
2760
+ });
2761
+ }
2762
+ _commitSlotComments(e, t) {
2763
+ this._ensureSlotCommentAnchors(e, t), this._redrawSlotComments(e, t), t.commentMarkerLayer && (t.commentMarkerLayer.style.visibility = ""), t.commentMargin && (t.commentMargin.style.visibility = ""), t.commentDecorationLayer && (t.commentDecorationLayer.style.visibility = "");
2764
+ }
2765
+ _ensureSlotCommentAnchors(e, t) {
2766
+ let n = this._pres;
2767
+ if (!n || t.commentAnchorSlide === e) return;
2768
+ t.commentAnchorSlide = e, t.commentElementBounds = Object.freeze([]);
2769
+ let r = [...new Set(n.getComments(e).flatMap((e) => (e.anchors ?? []).flatMap((e) => (e.type === "drawingElement" || e.type === "textRange") && e.elementId ? [e.elementId] : [])))];
2770
+ if (r.length === 0) return;
2771
+ let i = ++t.commentAnchorGeneration;
2772
+ n.getElementBoundsByIds(e, r).then((r) => {
2773
+ if (this._destroyed || i !== t.commentAnchorGeneration || n !== this._pres || this._slots.get(e) !== t || t.commentAnchorSlide !== e) return;
2774
+ t.commentElementBounds = r, this._redrawSlotComments(e, t);
2775
+ let a = n.getComments(e).find((t, n) => P(t, n, e) === this._activeCommentId);
2776
+ a && this._scrollToSlideCommentTarget(e, a);
2777
+ }).catch((e) => {
2778
+ !this._destroyed && i === t.commentAnchorGeneration && this._reportRenderError(e);
2779
+ });
2780
+ }
2781
+ _scheduleCommentGeometry(e, t, n = !1) {
2782
+ let r = this._pendingCommentGeometry.get(e);
2783
+ if (this._pendingCommentGeometry.set(e, {
2784
+ slot: t,
2785
+ connectorsOnly: r?.slot === t ? r.connectorsOnly && n : n
2786
+ }), this._commentGeometryScheduled) return;
2787
+ this._commentGeometryScheduled = !0;
2788
+ let i = () => {
2789
+ this._commentGeometryScheduled = !1, this._commentGeometryFrame = null;
2790
+ let e = [...this._pendingCommentGeometry];
2791
+ if (this._pendingCommentGeometry.clear(), !this._destroyed) for (let [t, n] of e) {
2792
+ let { slot: e, connectorsOnly: r } = n;
2793
+ this._slots.get(t) === e && e.renderedScale === this._scale && (r ? this._redrawSlotCommentConnectors(t, e) : this._redrawSlotComments(t, e));
2794
+ }
2795
+ }, a = this._wrapper.ownerDocument.defaultView;
2796
+ a?.requestAnimationFrame ? this._commentGeometryFrame = a.requestAnimationFrame(i) : queueMicrotask(i);
2797
+ }
2798
+ _redrawSlotHighlights(e, t) {
2799
+ if (!this._findActive) {
2800
+ t.highlightLayer.innerHTML = "";
2801
+ return;
2802
+ }
2803
+ let n = this._find.slideRuns(e);
2804
+ if (!n) {
2805
+ t.highlightLayer.innerHTML = "";
2806
+ return;
2807
+ }
2808
+ L(t.highlightLayer, n, this._find.slideHighlights(e), this._slideWidthPx(), this._slideHeightPx(), (e) => this._measureForFind(e), this._opts.findHighlightColors);
2809
+ }
2810
+ _measureForFind(e) {
2811
+ this._findMeasureCtx === void 0 && (this._findMeasureCtx = document.createElement("canvas").getContext("2d"));
2812
+ let t = this._findMeasureCtx;
2813
+ return !t || typeof t.measureText != "function" ? (e) => e.length : (t.font = e, (e) => t.measureText(e).width);
2814
+ }
2815
+ _hyperlinkHandler() {
2816
+ if (this._opts.enableHyperlinks !== !1) return (e) => this._onHyperlinkClick(e);
2817
+ }
2818
+ _onHyperlinkClick(e) {
2819
+ let t = this._resolveInternalSlideIndex(e);
2820
+ if (this._opts.onHyperlinkClick) {
2821
+ this._opts.onHyperlinkClick(t);
2822
+ return;
2823
+ }
2824
+ if (t.kind === "external") {
2825
+ x(t.url);
2826
+ return;
2827
+ }
2828
+ t.slideIndex !== void 0 && this.scrollToSlide(t.slideIndex);
2829
+ }
2830
+ _resolveInternalSlideIndex(e) {
2831
+ if (e.kind !== "internal" || e.slideIndex !== void 0) return e;
2832
+ let t = this._pres?.resolveInternalTarget(e.ref, this._range().topIndex);
2833
+ return t === void 0 ? e : {
2834
+ ...e,
2835
+ slideIndex: t
2836
+ };
2837
+ }
2838
+ _onResize() {
2839
+ if (!this._pres || this._pres.slideCount === 0) return;
2840
+ if (!this._scaleEstablished) {
2841
+ this.relayout();
2842
+ return;
2843
+ }
2844
+ if (this._opts.refitOnResize === !1) {
2845
+ this._lastFitWidth = this._fitWidthPx(), this._mountVisible();
2846
+ return;
2847
+ }
2848
+ let e = this._baseScale();
2849
+ if (e <= 0) return;
2850
+ let t = this._fitWidthPx();
2851
+ if (t === this._lastFitWidth) {
2852
+ this._mountVisible();
2853
+ return;
2854
+ }
2855
+ this._lastFitWidth = t;
2856
+ let n = this._prevBase > 0 ? this._scale / this._prevBase : 1;
2857
+ this._prevBase = e, this.setScale(e * n), this._mountVisible();
2858
+ }
2859
+ get topVisibleSlide() {
2860
+ return this._lastRange?.topIndex ?? 0;
2861
+ }
2862
+ mountedSlideIndicesForTest() {
2863
+ return [...this._slots.keys()];
2864
+ }
2865
+ interactiveSlideIndicesForTest() {
2866
+ return [...this._slots].filter(([, e]) => e.mediaInteractive).map(([e]) => e);
2867
+ }
2868
+ scaleForTest() {
2869
+ return this._scale;
2870
+ }
2871
+ baseScaleForTest() {
2872
+ return this._baseScale();
2873
+ }
2874
+ renderEpochForTest() {
2875
+ return this._renderEpoch;
2876
+ }
2877
+ resizeForTest() {
2878
+ this._onResize();
2879
+ }
2880
+ contentAtViewportYForTest(e) {
2881
+ let t = this._scrollHost.scrollTop + e, n = this._slideIndexAtOffset(t), r = this._uniformSlideHeight;
2882
+ return {
2883
+ slide: n,
2884
+ frac: r > 0 ? Math.min(1, Math.max(0, (t - this._slideOffset(n)) / r)) : 0
2885
+ };
2886
+ }
2887
+ viewportYOfForTest(e, t) {
2888
+ return this._slideOffset(e) + t * this._uniformSlideHeight - this._scrollHost.scrollTop;
2889
+ }
2890
+ async getResourceMetrics() {
2891
+ if (!this._pres) throw Error("Presentation not loaded");
2892
+ return await this._pres.getResourceMetrics();
2893
+ }
2894
+ getSelectionContext(e = {}) {
2895
+ if (this._destroyed) throw Error("PptxScrollViewer is destroyed");
2896
+ if (this._pres && this._activeCommentId !== null && this._activeCommentSlide !== null) {
2897
+ let t = this._pres.getComments(this._activeCommentSlide), n = t.findIndex((e, t) => P(e, t, this._activeCommentSlide) === this._activeCommentId), r = t[n];
2898
+ if (r && n >= 0) return Mt(r, this._activeCommentSlide, n, this._activeCommentId, e);
2899
+ }
2900
+ return (this._opts.enableTextSelection ? Z(this._wrapper, this._wrapper.ownerDocument?.getSelection?.() ?? null, e) : null) ?? (this._elementContext ? Et(this._elementContext, e.maxTextCharacters) : null);
2901
+ }
2902
+ _emitSelectionContextChange() {
2903
+ let e = this.getSelectionContext();
2904
+ e?.kind === "text" && (this._elementHitGeneration++, this._elementContext = null, this._redrawElementOutlines());
2905
+ let t = JSON.stringify(e);
2906
+ t !== this._selectionContextKey && (this._selectionContextKey = t, this._opts.onSelectionContextChange?.(e ? structuredClone(e) : null));
2907
+ }
2908
+ _setElementContext(e) {
2909
+ this._elementContext = e ? structuredClone(e) : null, this._redrawElementOutlines(), this._emitSelectionContextChange();
2910
+ }
2911
+ _invalidateElementSelection(e = !0) {
2912
+ this._elementHitGeneration++, this._elementContext = null, this._redrawElementOutlines(), e && this._emitSelectionContextChange();
2913
+ }
2914
+ _redrawElementOutlines() {
2915
+ for (let [e, t] of this._slots) this._redrawElementOutlineForSlot(e, t);
2916
+ }
2917
+ _redrawElementOutlineForSlot(e, t) {
2918
+ let n = this._elementContext, r = this._pres;
2919
+ if (!n || !r || n.slideIndex !== e) {
2920
+ D(t.elementLayer, null);
2921
+ return;
2922
+ }
2923
+ D(t.elementLayer, {
2924
+ x: n.bounds.x / r.slideWidth,
2925
+ y: n.bounds.y / r.slideHeight,
2926
+ width: n.bounds.width / r.slideWidth,
2927
+ height: n.bounds.height / r.slideHeight,
2928
+ rotation: n.bounds.rotation
2929
+ });
2930
+ }
2931
+ async _onElementClick(e) {
2932
+ this._destroyed || e.defaultPrevented || e.button !== 0 || await this._resolveContextAt(e);
2933
+ }
2934
+ _onContextMenu(e) {
2935
+ let t;
2936
+ this._opts.onContextMenu?.({
2937
+ originalEvent: e,
2938
+ getContext: () => t ??= this._resolveContextAt(e)
2939
+ });
2940
+ }
2941
+ async _resolveContextAt(e) {
2942
+ let t = this._pres;
2943
+ if (this._destroyed || !t) return null;
2944
+ if (this._opts.enableTextSelection && Z(this._wrapper, this._wrapper.ownerDocument?.getSelection?.() ?? null)) return this._emitSelectionContextChange(), this._destroyed ? null : this.getSelectionContext();
2945
+ if (!this._opts.enableElementSelection) return this.getSelectionContext();
2946
+ let n = e.target, r = [...this._slots].find(([, e]) => n !== null && e.wrapper.contains(n));
2947
+ if (!r) return this._invalidateElementSelection(), null;
2948
+ let [i, a] = r, o = a.canvas.getBoundingClientRect();
2949
+ if (o.width <= 0 || o.height <= 0) return this._invalidateElementSelection(), null;
2950
+ let s = e.clientX - o.left, c = e.clientY - o.top;
2951
+ if (s < 0 || c < 0 || s > o.width || c > o.height) return this._invalidateElementSelection(), null;
2952
+ let l = ++this._elementHitGeneration, u = {
2953
+ x: s / o.width * t.slideWidth,
2954
+ y: c / o.height * t.slideHeight
2955
+ }, d;
2956
+ try {
2957
+ d = await t.getElementContextAt(i, u, {
2958
+ tolerance: this._elementHitTolerance / o.width * t.slideWidth,
2959
+ maxTextCharacters: G
2960
+ });
2961
+ } catch (e) {
2962
+ if (this._destroyed || l !== this._elementHitGeneration || t !== this._pres) return null;
2963
+ throw e;
2964
+ }
2965
+ return this._destroyed || l !== this._elementHitGeneration || t !== this._pres ? null : (this._setElementContext(d), this._destroyed ? null : this.getSelectionContext());
2966
+ }
2967
+ destroy() {
2968
+ if (!this._destroyed) {
2969
+ this._destroyed = !0, this._beginCommentNavigation(), this._errorRouter.close(), this._invalidateFind(), this._findActive = !1, this._unbindLayoutPresentation(), this._selectionChangeListener &&= (this._wrapper.ownerDocument.removeEventListener("selectionchange", this._selectionChangeListener), null), this._elementHitGeneration++, this._elementClickListener &&= (this._scrollHost.removeEventListener("click", this._elementClickListener), null), this._contextMenuListener &&= (this._scrollHost.removeEventListener("contextmenu", this._contextMenuListener), null), this._commentOutsidePointerListener &&= (this._wrapper.ownerDocument.removeEventListener("pointerdown", this._commentOutsidePointerListener), null), this._commentGeometryFrame !== null && (this._wrapper.ownerDocument.defaultView?.cancelAnimationFrame?.(this._commentGeometryFrame), this._commentGeometryFrame = null), this._commentGeometryScheduled = !1, this._pendingCommentGeometry.clear(), this._elementContext = null, 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);
2970
+ for (let [e, t] of [...this._slots]) this._recycleSlot(e, t);
2971
+ this._free.length = 0, this._presentationOwner.close(), this._wrapper.remove();
2972
+ }
2973
+ }
2974
+ }, Gt = /* @__PURE__ */ e({
2975
+ OoxmlDecodedImageLimitError: () => je,
2976
+ OoxmlError: () => b,
2977
+ OoxmlResourceLimitError: () => h,
2978
+ PptxPresentation: () => Y,
2979
+ PptxScrollViewer: () => Wt,
2980
+ PptxViewer: () => It,
2981
+ autoResize: () => ye,
2982
+ buildPptxHighlightLayer: () => L,
2983
+ buildPptxTextLayer: () => I,
2984
+ isOoxmlDecodedImageLimitError: () => Me,
2985
+ openExternalHyperlink: () => x,
2986
+ readPptxTextSelectionContext: () => Z,
2987
+ renderSlide: () => f
2988
+ });
2989
+ //#endregion
2990
+ export { Y as a, Z as i, Wt as n, L as o, It as r, I as s, Gt as t };