@silurus/ooxml 0.80.3 → 0.82.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 (67) hide show
  1. package/README.md +61 -85
  2. package/dist/assets/render-worker-7-Zr7fSw.js +10 -0
  3. package/dist/assets/render-worker-B5gsW6b5.js +11 -0
  4. package/dist/assets/render-worker-Dw_wQRIh.js +24 -0
  5. package/dist/{canvas-viewer-mechanics-D-r6wHY_.js → canvas-viewer-mechanics-CS_qbr6T.js} +1 -1
  6. package/dist/chart-ex.mjs +1017 -0
  7. package/dist/comment-occurrence-C34fWs_F.js +6 -0
  8. package/dist/comment-ui-runtime-BAe30Ct9.js +112 -0
  9. package/dist/comment-ui-runtime-BUCj4hWn.js +171 -0
  10. package/dist/comment-ui-runtime-F4a3te6p.js +2 -0
  11. package/dist/comments-Cf9W7r3M.js +241 -0
  12. package/dist/{document-pull-client-vxk-Aomu.js → document-pull-client-BCgmytqI.js} +4682 -4541
  13. package/dist/docx-wokGKYfi.js +2162 -0
  14. package/dist/docx.mjs +6 -4
  15. package/dist/docx_parser_bg.wasm +0 -0
  16. package/dist/dom-interaction-boundary-C8F6HO5x.js +119 -0
  17. package/dist/highlight-rect-MaCt0om0.js +13 -0
  18. package/dist/index.mjs +3 -3
  19. package/dist/{line-distribute-Bvtp0Gt6.js → line-distribute-iXsUCIH-.js} +17 -16
  20. package/dist/{line-metrics-DdEJYxjx.js → line-metrics-B3syvDn2.js} +667 -7492
  21. package/dist/math.mjs +2 -2
  22. package/dist/node.mjs +248 -247
  23. package/dist/plot-area-frame-DHV02PJU.js +3670 -0
  24. package/dist/pptx-DU8L8I2T.js +2432 -0
  25. package/dist/pptx.mjs +6 -5
  26. package/dist/pptx_parser_bg.wasm +0 -0
  27. package/dist/read-only-comment-decoration-DcFevX_Q.js +96 -0
  28. package/dist/read-only-comment-margin-Dn2y55W6.js +189 -0
  29. package/dist/region-map.mjs +102 -97
  30. package/dist/{render-CoqMHcbF.js → render-CenWM4g1.js} +1 -1
  31. package/dist/{render-worker-host-IuQFpoJM.js → render-worker-host-BNENN3qP.js} +1 -1
  32. package/dist/{render-worker-host-CYPhmBtX.js → render-worker-host-BmH3kGSj.js} +1 -1
  33. package/dist/{render-worker-host-GlLR1rtF.js → render-worker-host-CmPBviYJ.js} +1 -1
  34. package/dist/renderer-CYr9YTXM.js +5856 -0
  35. package/dist/{renderer-module-contract-BNGz8HvO.js → renderer-module-contract-DLbb7zY0.js} +4 -3
  36. package/dist/{resource-measurement-CgMubiAI.js → resource-measurement-CsW4_eYt.js} +12 -11
  37. package/dist/{session-DkPblDiq.js → session-Cky_swUj.js} +8 -8
  38. package/dist/{slide-pull-client-m2blvngt.js → slide-pull-client-CqTVFb3W.js} +1004 -1091
  39. package/dist/source-key-BklvnEyQ.js +42 -0
  40. package/dist/three-d-7MaVzQuZ.js +1346 -0
  41. package/dist/three-d.mjs +1238 -797
  42. package/dist/types/chart-ex.d.ts +949 -0
  43. package/dist/types/docx.d.ts +497 -28
  44. package/dist/types/index.d.ts +649 -39
  45. package/dist/types/math.d.ts +1 -1
  46. package/dist/types/node.d.ts +385 -22
  47. package/dist/types/pptx.d.ts +435 -24
  48. package/dist/types/region-map.d.ts +318 -6
  49. package/dist/types/three-d.d.ts +318 -6
  50. package/dist/types/xlsx.d.ts +384 -19
  51. package/dist/units-BzZ0gAxs.js +4 -0
  52. package/dist/{worksheet-pull-client-BntP6RiO.js → worksheet-pull-client-CYtwXP5D.js} +19 -19
  53. package/dist/{xlsx-DqMe7J2C.js → xlsx-DlV37-0j.js} +1594 -1349
  54. package/dist/xlsx.mjs +6 -5
  55. package/dist/xlsx_parser_bg.wasm +0 -0
  56. package/package.json +7 -1
  57. package/dist/assets/render-worker-CRaEOHkw.js +0 -9
  58. package/dist/assets/render-worker-DQGLj5Zv.js +0 -22
  59. package/dist/assets/render-worker-rnrSLmqL.js +0 -8
  60. package/dist/chart-number-format-qLhnk6hj.js +0 -475
  61. package/dist/docx-DN0PRx2f.js +0 -1733
  62. package/dist/highlight-rect-BuX5rWP4.js +0 -48
  63. package/dist/pptx-B-Laftl1.js +0 -2134
  64. package/dist/three-d-C28kqDym.js +0 -1086
  65. /package/dist/{mathjax-DgAl7Yi5.js → mathjax-DwIrafQ6.js} +0 -0
  66. /package/dist/{transfer-CKZ79zFw.js → transfer-R6NjgBKD.js} +0 -0
  67. /package/dist/{visible-index-BjesVGhg.js → visible-index-BFE3PWiY.js} +0 -0
@@ -0,0 +1,2432 @@
1
+ import { t as e } from "./chunk-DmhlhrBa.js";
2
+ import { a as t, c as n, i as r, l as i, n as a, o, r as s, s as c, t as l } from "./slide-pull-client-CqTVFb3W.js";
3
+ import { B as u, Ct as d, Et as f, G as p, Jt as m, R as h, Yt as g, a as _, at as v, ht as y, it as b, mt as x, q as S, z as C } from "./line-metrics-B3syvDn2.js";
4
+ import { C as w, E as ee, S as te, T as ne, _ as re, a as T, b as ie, c as E, d as ae, f as oe, g as se, h as ce, i as D, l as O, m as le, n as ue, o as de, p as fe, r as pe, s as me, t as he, v as ge, w as _e, x as ve, y as ye } from "./canvas-viewer-mechanics-CS_qbr6T.js";
5
+ import { a as be, i as xe, n as Se, t as Ce } from "./bounded-raw-part-cache-C6ro6Ezf.js";
6
+ import { cn as we, ln as Te } from "./plot-area-frame-DHV02PJU.js";
7
+ import { i as k } from "./units-BzZ0gAxs.js";
8
+ import { n as Ee } from "./resource-measurement-CsW4_eYt.js";
9
+ import { n as De } from "./renderer-module-contract-DLbb7zY0.js";
10
+ import { n as Oe, r as ke, t as Ae } from "./visible-index-BFE3PWiY.js";
11
+ import { n as je, r as Me, t as Ne } from "./dom-interaction-boundary-C8F6HO5x.js";
12
+ import { n as Pe, t as A } from "./highlight-rect-MaCt0om0.js";
13
+ import { t as j } from "./comment-occurrence-C34fWs_F.js";
14
+ //#region packages/core/src/nav/internal-target.ts
15
+ function Fe(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 Ie(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 Le(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 M(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 N(e, t, n, r, i, a) {
42
+ e.innerHTML = "", M(e, "ooxmlSelectionSurface", "pptx"), M(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:${A(c.shapeX, n)};top:${A(c.shapeY, r)};width:${A(c.shapeW, n)};height:${A(c.shapeH, r)};pointer-events:all;overflow:hidden;`, 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
+ M(d, "ooxmlSelectionRun", "pptx"), M(d, "runIndex", String(a)), c.shapeId !== void 0 && M(d, "shapeId", c.shapeId), c.elementIndex !== void 0 && M(d, "elementIndex", String(c.elementIndex)), c.origin !== void 0 && M(d, "elementOrigin", c.origin), d.textContent = c.text;
59
+ let f = i ? c.hyperlink : void 0;
60
+ d.style.cssText = `position:absolute;left:${A(c.inShapeX, u.w)};top:${A(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 P(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:${A(t.shapeX, r)};top:${A(t.shapeY, i)};width:${A(t.shapeW, r)};height:${A(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 } = Pe(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:${A(e.inShapeX + o, c.w)};top:${A(e.inShapeY, c.h)};width:${A(s, c.w)};height:${A(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 Re = 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 = le(r);
154
+ for (let a of ce(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 = oe(this._active, this._matches.length), this._activePublic();
167
+ }
168
+ prev() {
169
+ return this._active = fe(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
+ }, ze = (e) => e >= "0" && e <= "9";
180
+ function Be(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 F(e, t, n) {
186
+ let r = 0;
187
+ for (let i of t) r += ze(i) ? n : e.measureText(i).width;
188
+ return r;
189
+ }
190
+ function I(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 (ze(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 L = (e, t) => e / k * t;
203
+ async function Ve(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 / k);
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(), We(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 = He(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(R(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 = R(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
+ Ue(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) Ye(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 = W(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(R(e.el, e.media, "play", t));
316
+ });
317
+ } catch (t) {
318
+ d(R(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 = W(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 He(e, t) {
360
+ return {
361
+ x: L(e.x, t),
362
+ y: L(e.y, t),
363
+ w: L(e.width, t),
364
+ h: L(e.height, t)
365
+ };
366
+ }
367
+ function Ue(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
+ G(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 We(e, t) {
374
+ return /* @__PURE__ */ Error(`Embedded ${e.mediaKind} fetch failed for "${e.mediaPath}" (mime=${e.mimeType || "unknown"}): ${Ge(t)}`);
375
+ }
376
+ function R(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 ? "" : `: ${Ge(r)}`;
389
+ return /* @__PURE__ */ Error(`Embedded ${e.mediaKind} ${n} failed for "${e.mediaPath}" (${o.join("; ")})${s}`);
390
+ }
391
+ function Ge(e) {
392
+ return e instanceof Error ? `${e.name || "Error"}${e.message ? `: ${e.message}` : ""}` : String(e);
393
+ }
394
+ var Ke = 28, z = 14, qe = 72, Je = 10, B = 3;
395
+ function Ye(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" ? Ze(e, t, n, r, a) : Xe(e, t, n, r, a);
398
+ }
399
+ function Xe(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 = W(t);
405
+ H(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)", V(e, n.currentTime, r, f.x, f.y - 10, "bottom"), e.restore();
406
+ }
407
+ function Ze(e, t, n, r, i) {
408
+ let a = U(t.rect);
409
+ e.save(), G(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)", V(e, n.currentTime, r, a.x + z, a.y + a.h / 2, "middle"), e.restore(), H(e, W(t), i, r > 0);
410
+ }
411
+ function V(e, t, n, r, i, a) {
412
+ let o = Qe(t), s = Qe(n), c = Be(e), l = F(e, o, c), u = F(e, s, c), d = e.measureText(" / ").width, f = Math.max(l, u);
413
+ I(e, o, r + f - l, i, c);
414
+ let p = e.textAlign;
415
+ e.textAlign = "left", e.fillText(" / ", r + f, i), e.textAlign = p, I(e, s, r + f + d, i, c);
416
+ }
417
+ function H(e, t, n, r) {
418
+ let i = t.h / 2;
419
+ if (e.save(), G(e, t.x, t.y, t.w, t.h, i), e.fillStyle = "rgba(255, 255, 255, 0.35)", e.fill(), n > 0 && (G(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 U(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 - Ke - 4,
430
+ w: t,
431
+ h: Ke
432
+ };
433
+ }
434
+ function W(e) {
435
+ if (e.el.mediaKind === "audio") {
436
+ let t = U(e.rect), n = t.x + z + qe + Je, r = Math.max(40, t.x + t.w - z - n);
437
+ return {
438
+ x: n,
439
+ y: t.y + (t.h - B) / 2,
440
+ w: r,
441
+ h: B
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 - B - r,
448
+ w: t.w - n * 2,
449
+ h: B
450
+ };
451
+ }
452
+ function G(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 Qe(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 $e(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 et(e, t) {
472
+ if (e === "") return;
473
+ let n = Fe("ppt/slides", e);
474
+ return t.get(n);
475
+ }
476
+ function tt(e, t, n) {
477
+ let r = Ie(e);
478
+ return r === null ? et(e, t) : Le(r, n, t.size);
479
+ }
480
+ //#endregion
481
+ //#region packages/pptx/src/slide-repository.ts
482
+ var nt = 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 Se({
493
+ maxEntries: e.maxCachedSlides,
494
+ maxWeight: e.maxCachedStructuralBytes,
495
+ measure: (e) => Ee(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 = rt(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 = rt(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 rt(e) {
543
+ return e instanceof g ? e : v(e);
544
+ }
545
+ //#endregion
546
+ //#region packages/pptx/src/worker.ts?worker&inline
547
+ var it = "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=`https://fonts.googleapis.com/css2?family=Noto+Naskh+Arabic:wght@400;700&display=swap`,i=`https://fonts.googleapis.com/css2?family=Noto+Sans+Arabic:wght@400;700&display=swap`,a=`https://fonts.googleapis.com/css2?family=Libre+Franklin:ital,wght@0,400;0,600;0,700;1,400;1,600;1,700&display=swap`,o={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:a,loadFamily:`Libre Franklin`},\"franklin gothic medium\":{url:a,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:r,loadFamily:`Noto Naskh Arabic`},\"traditional arabic\":{url:r,loadFamily:`Noto Naskh Arabic`},\"simplified arabic\":{url:r,loadFamily:`Noto Naskh Arabic`},\"arabic typesetting\":{url:r,loadFamily:`Noto Naskh Arabic`},\"univers next arabic\":{url:i,loadFamily:`Noto Sans Arabic`},\"noto naskh arabic\":{url:r,loadFamily:`Noto Naskh Arabic`},\"noto sans arabic\":{url:i,loadFamily:`Noto Sans Arabic`}};function s(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 c=e=>`https://fonts.googleapis.com/css2?family=${e}:wght@400;700&display=swap`,l={\"noto sans kr\":{url:c(`Noto+Sans+KR`)},\"noto sans sc\":{url:c(`Noto+Sans+SC`)},\"noto sans tc\":{url:c(`Noto+Sans+TC`)},\"noto sans jp\":{url:c(`Noto+Sans+JP`)},\"noto serif kr\":{url:c(`Noto+Serif+KR`)},\"noto serif sc\":{url:c(`Noto+Serif+SC`)},\"noto serif tc\":{url:c(`Noto+Serif+TC`)},\"noto serif jp\":{url:c(`Noto+Serif+JP`)},\"noto sans\":{url:c(`Noto+Sans`)},\"noto serif\":{url:c(`Noto+Serif`)},\"noto sans devanagari\":{url:c(`Noto+Sans+Devanagari`)},\"noto sans thai\":{url:c(`Noto+Sans+Thai`)},\"noto sans hebrew\":{url:c(`Noto+Sans+Hebrew`)},\"noto serif hebrew\":{url:c(`Noto+Serif+Hebrew`)}};var ee=class e{hasHan=!1;hasHangul=!1;hasKana=!1;hasArabic=!1;hasThai=!1;hasHebrew=!1;hasDevanagari=!1;hasCyrGreek=!1;constructor(e){this.cjkLang=e}clone(){let t=new e(this.cjkLang);return t.hasHan=this.hasHan,t.hasHangul=this.hasHangul,t.hasKana=this.hasKana,t.hasArabic=this.hasArabic,t.hasThai=this.hasThai,t.hasHebrew=this.hasHebrew,t.hasDevanagari=this.hasDevanagari,t.hasCyrGreek=this.hasCyrGreek,t}addText(e){let t=()=>this.hasHan&&this.hasHangul&&this.hasKana&&this.hasArabic&&this.hasThai&&this.hasHebrew&&this.hasDevanagari&&this.hasCyrGreek;outer:for(let n of e)if(n)for(let e of n){let n=e.codePointAt(0);if(n!==void 0&&!(n<=591)&&(n>=4352&&n<=4607||n>=12592&&n<=12687||n>=44032&&n<=55215?this.hasHangul=!0:n>=12352&&n<=12543?this.hasKana=!0:n>=13312&&n<=19903||n>=19968&&n<=40959||n>=63744&&n<=64255||n>=131072&&n<=195103?this.hasHan=!0:n>=1536&&n<=1791||n>=1872&&n<=1919||n>=2208&&n<=2303||n>=64336&&n<=65023||n>=65136&&n<=65279?this.hasArabic=!0:n>=3584&&n<=3711?this.hasThai=!0:n>=1424&&n<=1535||n>=64285&&n<=64335?this.hasHebrew=!0:n>=2304&&n<=2431?this.hasDevanagari=!0:(n>=1024&&n<=1279||n>=880&&n<=1023)&&(this.hasCyrGreek=!0),t()))break outer}}names(){let e=[],t=new Set;this.hasHangul&&t.add(`kr`),this.hasKana&&t.add(`jp`),this.hasHan&&t.size===0&&t.add(this.cjkLang??`jp`);for(let n of[`kr`,`sc`,`tc`,`jp`])if(t.has(n)){let t={kr:`KR`,sc:`SC`,tc:`TC`,jp:`JP`}[n];e.push(`Noto Sans ${t}`,`Noto Serif ${t}`)}return this.hasCyrGreek&&e.push(`Noto Sans`,`Noto Serif`),this.hasArabic&&e.push(`Noto Naskh Arabic`,`Noto Sans Arabic`),this.hasThai&&e.push(`Noto Sans Thai`),this.hasHebrew&&e.push(`Noto Sans Hebrew`,`Noto Serif Hebrew`),this.hasDevanagari&&e.push(`Noto Sans Devanagari`),e}},u,d,te=e((()=>{u=1<<25,u*4,d=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 f(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>0}function ue(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return f(t.requiredBytes)&&f(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 de(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`||!ue(r)))return new p(r)}function fe(e,t,n){let r=de(e);if(!(!r||r.offeredBytes!==t||r.requiredBytes>n))return r}te();const pe=`OOXML_RESOURCE_LIMIT:`;function m(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function me(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 h(e){let t;try{t=JSON.parse(new TextDecoder().decode(e))}catch{throw TypeError(`OOXML resource usage checkpoint is not valid JSON`)}if(!me(t))throw TypeError(`OOXML resource usage checkpoint is invalid`);return t}function he(e){return e===`docx`||e===`xlsx`||e===`pptx`}function ge(e){return e===`container`||e===`decompression`||e===`parsing`||e===`serialization`||e===`layout`||e===`rendering`||e===`worker`}function g(e,t){return typeof e==`string`&&e.length>0&&e.length<=t&&!/[\\u0000-\\u001f\\u007f]/u.test(e)}function _(e){return g(e,128)&&/^[a-z0-9][a-z0-9-]*$/u.test(e)}function _e(e){return!g(e,4096)||e.startsWith(`/`)||e.startsWith(`\\\\`)||e.includes(`\\\\`)||e.includes(`?`)||e.includes(`#`)||e.includes(`://`)||/^[a-z]:/iu.test(e)?!1:e.split(`/`).every(e=>e!==``&&e!==`.`&&e!==`..`)}const v=new Map([[`archive-entry:declared-inflated-bytes`,{stage:`container`,part:`required`}],[`archive-entry:actual-inflated-bytes`,{stage:`decompression`,part:`required`}],[`archive:entry-count`,{stage:`container`,part:`forbidden`}],[`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}]]),ve=new Set([...v.keys()].map(e=>e.slice(0,e.indexOf(`:`)))),ye=new Set([...v.keys()].map(e=>e.slice(e.indexOf(`:`)+1)));function be(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return!he(t.format)||!g(t.operation,256)||!_(t.resource)||!_(t.metric)||!m(t.limit)||!m(t.observed)||typeof t.configurable!=`boolean`||!me(t.usage)?!1:!(`part`in t)||_e(t.part)}function y(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;if(!ge(t.stage)||!be(t.violation))return!1;let n=t.violation,r=v.get(`${n.resource}:${n.metric}`);return r?t.stage!==r.stage||r.configurable===!1&&n.configurable!==!1?!1:r.part===`required`?n.part!==void 0:r.part===`forbidden`?n.part===void 0:!0:!(ve.has(n.resource)&&ye.has(n.metric))}function xe(e){return{archiveEntryCount:e.archiveEntryCount,declaredInflatedBytes:e.declaredInflatedBytes,...e.largestInflatedEntryBytes===void 0?{}:{largestInflatedEntryBytes:e.largestInflatedEntryBytes},distinctInflatedBytes:e.distinctInflatedBytes,operationInflatedBytes:e.operationInflatedBytes}}function Se(e){if(!y(e))return;let t=e.violation,n={stage:e.stage,violation:{format:t.format,operation:t.operation,resource:t.resource,metric:t.metric,...t.part===void 0?{}:{part:t.part},limit:t.limit,observed:t.observed,configurable:t.configurable,usage:xe(t.usage)}};return y(n)?n:void 0}function Ce(e){let t=e.violation;return`OOXML resource limit exceeded${t.part?` for ${t.part}`:``}: ${t.metric} ${t.observed} > ${t.limit}`}function b(e){let t=e instanceof Error?e.message:String(e);if(!t.startsWith(pe))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`||!y(i.details)))return new n(Ce(i.details),i.details)}function we(e){if(e instanceof d)return{message:e.message,errorName:e.name,code:e.code,decodedImage:{metric:e.metric,limit:e.limit,observed:e.observed}};let r=de(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:b(e);if(i instanceof n){let e=Se(i.details);return e?{message:typeof i.message==`string`?i.message:Ce(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:g(i.name,128)?i.name:`OoxmlError`,..._(i.code)?{code:i.code}:{}};let a=e instanceof Error?e.message:String(e);if(typeof a==`string`&&a.startsWith(pe))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:g(o.name,128)?o.name:`Error`,...typeof s.code==`string`?{code:s.code}:{}}}function x(e){try{return we(e)}catch{return{message:`Worker operation failed with an unreadable error`,errorName:`Error`}}}const Te=new Set([`encrypted`,`invalid-password`,`unsupported-encryption`,`legacy-binary-format`,`not-ooxml`]);function Ee(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 d(e.decodedImage.metric,e.decodedImage.limit,e.decodedImage.observed);if(e.code===`ooxml-insufficient-credit`&&ue(e.insufficientCredit))return new p(e.insufficientCredit);if(e.code===`ooxml-resource-limit`&&y(e.resourceLimit))return new n(e.message,e.resourceLimit);if(e.code&&Te.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 De(e){return e.byteOffset===0&&e.byteLength===e.buffer.byteLength&&e.buffer instanceof ArrayBuffer?e.buffer:e.slice().buffer}const S=67108864;Object.freeze({maxArchiveEntryBytes:134217728,maxTotalInflatedBytes:268435456,maxArchiveEntries:4096});function Oe(e){return[e.maxArchiveEntryBytes===null?0n:BigInt(e.maxArchiveEntryBytes),e.maxTotalInflatedBytes===null?0n:BigInt(e.maxTotalInflatedBytes),e.maxArchiveEntries===null?0n:BigInt(e.maxArchiveEntries)]}const C=`ooxml-pull-v1`;function w(e,t){if(!Number.isSafeInteger(e)||e<=0)throw RangeError(`${t} must be a positive safe integer`)}function ke(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 Ae=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,w(this.maxRetainedBytes,`max retained lease bytes`),w(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}},je=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){ke(e.sessionId),w(e.operationId,`operation id`),w(e.generation,`generation`),w(e.maxByteCredit,`max byte credit`),e.wireLeaseIdStart!==void 0&&w(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=x(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(w(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:C,...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){w(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(w(e,`byte credit`),e>this.options.maxByteCredit)throw RangeError(`byte credit exceeds host maximum`)}accepted(e,t,n=!1){return{kind:`accepted`,protocol:C,...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:C,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:t,usage:this.errorResourceUsage()}}async forceFatalCleanup(){this.cancelRequested=!0,this.unacked=void 0,this.coordinator.release(this.coordinatorOwner);let e;for(let t of[...this.leases.keys()])try{await this.release(t)}catch(t){e??=t}if(!this.driverCancelComplete)try{await this.options.driver.cancel?.(),this.driverCancelComplete=!0}catch(t){e??=t}if(e)throw e;this.unregisterCleanup()}allocateWireLeaseId(){if(!Number.isSafeInteger(this.nextWireLeaseId)||this.nextWireLeaseId<=0)throw RangeError(`wire lease id space exhausted`);return this.nextWireLeaseId++}arrayBufferTransferBytes(e){let t=0;for(let n of e??[])if(n instanceof ArrayBuffer&&(t+=n.byteLength,!Number.isSafeInteger(t)))throw RangeError(`ArrayBuffer transfer bytes overflow`);return t}maybeUnregisterCompleted(){this.completed&&this.leases.size===0&&this.unregisterCleanup()}resourceUsage(){return this.options.driver.resourceUsage?.()}errorResourceUsage(){try{return this.resourceUsage()}catch{return}}};function T(e,t){if(!Number.isSafeInteger(e)||e<0)throw Error(`${t} must be a non-negative safe integer`)}function E(e,t,n){return T(e,`resource measurement`),T(t,`resource measurement`),T(n,`resource measurement limit`),e>n||t>n||t>n-e?n===2**53-1?n:n+1:e+t}function Me(e,t=2**53-1){T(t,`resource measurement limit`);let n=0;for(let r=0;r<e.length;r+=1){let i=e.charCodeAt(r),a;if(i<=127)a=1;else if(i<=2047)a=2;else if(i>=55296&&i<=56319&&r+1<e.length){let t=e.charCodeAt(r+1);t>=56320&&t<=57343?(a=4,r+=1):a=3}else a=3;if(n=E(n,a,t),n>t)return n}return n}function Ne(e,t=2**53-1){T(t,`resource measurement limit`);let n=E(0,2,t);if(n>t)return n;for(let r=0;r<e.length;r+=1){let i=e.charCodeAt(r),a;if(i===34||i===92||i===8||i===9||i===10||i===12||i===13)a=2;else if(i<=31)a=6;else if(i<=127)a=1;else if(i<=2047)a=2;else if(i>=55296&&i<=56319&&r+1<e.length){let t=e.charCodeAt(r+1);t>=56320&&t<=57343?(a=4,r+=1):a=6}else a=i>=55296&&i<=57343?6:3;if(n=E(n,a,t),n>t)return n}return n}function D(e,t){return E(0,e,t)}function O(e,t=2**53-1,n=!1){if(T(t,`resource measurement limit`),e===null)return{jsonBytes:D(4,t),stringValueUtf8Bytes:0};if(typeof e==`string`)return{jsonBytes:Ne(e,t),stringValueUtf8Bytes:Me(e,t)};if(typeof e==`boolean`)return{jsonBytes:D(e?4:5,t),stringValueUtf8Bytes:0};if(typeof e==`number`)return{jsonBytes:D((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=D(2,t),r=0;for(let i=0;i<e.length;i+=1){i!==0&&(n=E(n,1,t));let a=O(e[i],t,!0);n=E(n,a.jsonBytes,t),r=E(r,a.stringValueUtf8Bytes,t)}return{jsonBytes:n,stringValueUtf8Bytes:r}}if(typeof e==`object`){let n=D(2,t),r=0,i=0;for(let[a,o]of Object.entries(e)){if(o===void 0||typeof o==`function`||typeof o==`symbol`)continue;i++!==0&&(n=E(n,1,t)),n=E(n,Ne(a,t),t),n=E(n,1,t);let e=O(o,t);n=E(n,e.jsonBytes,t),r=E(r,e.stringValueUtf8Bytes,t)}return{jsonBytes:n,stringValueUtf8Bytes:r}}return{jsonBytes:n?D(4,t):0,stringValueUtf8Bytes:0}}({...o,...l});function*Pe(e){for(let t of e?.paragraphs??[])for(let e of t.runs)e.type===`text`&&(yield e.text)}function*Fe(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*Ie(e){for(let t of e.elements)if(t.type===`shape`)yield*Pe(t.textBody);else if(t.type===`table`)for(let e of t.rows)for(let t of e.cells)yield*Pe(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 Le=class e{scripts;families;constructor(e,t,n,r){this.majorFont=e,this.minorFont=t;let i=s(e)??s(t)??null;this.scripts=n??new ee(i),this.families=r??new Set,e&&this.families.add(e),t&&this.families.add(t)}addSlide(e){this.scripts.addText(Ie(e));for(let t of e.elements)if(t.type===`shape`)for(let e of Fe(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 Fe(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 k=Object.freeze({archiveEntryCount:0,declaredInflatedBytes:0,distinctInflatedBytes:0,operationInflatedBytes:0}),Re=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){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`invalid PPTX presentation bootstrap payload`);let t=e;if(!Number.isSafeInteger(t.slideCount)||(t.slideCount??-1)<0||!Number.isSafeInteger(t.slideWidth)||(t.slideWidth??0)<=0||!Number.isSafeInteger(t.slideHeight)||(t.slideHeight??0)<=0||!Array.isArray(t.slides)||t.slides.length!==t.slideCount)throw Error(`invalid PPTX presentation bootstrap dimensions or slide count`);return 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,slides:Object.freeze(t.slides.map(ze))})}function Ve(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 He(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 Ue(e){return Object.freeze({...e})}function We(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(Ue))}:{},...e.status===void 0?{}:{status:e.status},text:e.text,...e.replies?.length?{replies:Object.freeze(e.replies.map(He))}:{}})}function Ge(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(Ve)),...e.comments?.length?{comments:Object.freeze(e.comments.map(We))}:{}})}function Ke(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;descriptors;slides=[];fonts;fontPreloadNames;fontProjectionBytes;projectionBytesValue;limit;pending=null;finished=null;constructor(e,t={}){let n=Be(e),r=t.hardLimitForTesting??Re;if(!Number.isSafeInteger(r)||r<=0||r>Re)throw Error(`invalid PPTX presentation preflight test limit`);this.limit=r,this.slideCountValue=n.slideCount,this.slideWidthValue=n.slideWidth,this.slideHeightValue=n.slideHeight,this.defaultTextColorValue=n.defaultTextColor,this.majorFontValue=n.majorFont,this.minorFontValue=n.minorFont,this.hlinkColorValue=n.hlinkColor,this.folHlinkColorValue=n.folHlinkColor,this.descriptors=[...n.slides],this.fonts=new Le(this.majorFontValue,this.minorFontValue),this.fontPreloadNames=Object.freeze(this.fonts.names()),this.fontProjectionBytes=O(this.fontPreloadNames,this.limit).jsonBytes,this.projectionBytesValue=O({slideCount:this.slideCountValue,slideWidth:this.slideWidthValue,slideHeight:this.slideHeightValue,defaultTextColor:this.defaultTextColorValue,majorFont:this.majorFontValue,minorFont:this.minorFontValue,hlinkColor:this.hlinkColorValue,folHlinkColor:this.folHlinkColorValue,remainingSlides:this.descriptors,slides:[],fontPreloadNames:this.fontPreloadNames},this.limit).jsonBytes,Ke(this.projectionBytesValue,this.limit,k)}get acceptedSlideCount(){return this.finished?.slideCount??this.slides.length}get projectedBytes(){return this.projectionBytesValue}get remainingDescriptorCount(){return this.descriptors.reduce((e,t)=>e+Number(t!==void 0),0)}addSlide(e,t=k){this.prepareSlide(e,t).commit()}prepareSlide(e,t=k){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=Ge(e,r),a=this.fonts.withSlide(e),o=Object.freeze(a.names()),s=O(o,this.limit).jsonBytes,c=O(i,this.limit).jsonBytes,l=this.projectionBytesValue-this.fontProjectionBytes-O(r,this.limit).jsonBytes+4;l=E(l,s,this.limit),l=E(l,c,this.limit),this.slides.length!==0&&(l=E(l,1,this.limit));let ee=O({slide:i,fontPreloadNames:o},this.limit).jsonBytes,u=E(this.projectionBytesValue,ee,this.limit);Ke(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,slides:Object.freeze([...this.slides]),fontPreloadNames:this.fontPreloadNames}),this.descriptors=[],this.slides=[],this.projectionBytesValue=O(this.finished,this.limit).jsonBytes,this.finished}};function j(e){try{return h(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,j(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 Ae;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||!M(n.identity,t))throw Error(`slide pull session open reservation is stale or missing`);let r,i=new Promise(e=>{r=e}),a=this.operationTail.then(()=>this.coordinator.enqueue(async()=>{if(n.canceled)throw Error(`slide pull session open was canceled`);let i,a=!1,o=new je({...t,maxByteCredit:S,coordinator:this.coordinator,driver:{pull:n=>{let r;try{r=this.executeArchive(r=>r.pull_slide(e,t.operationId,t.generation,n))}catch(e){throw fe(e,n,S)||(this.latchResourceFailure(e),e)}let o=De(r);return this.acceptSlide&&(i=JSON.parse(new TextDecoder().decode(new Uint8Array(o)))),a=!0,{payload:o,byteLength:o.byteLength,done:!0,transfer:[o]}},measureChunk:({payload:e})=>e.byteLength,acknowledge:()=>{if(!a)throw Error(`slide unit is not awaiting acknowledgement`);try{Je(this.executeArchive,t,e,i,this.acceptSlide)}catch(e){throw this.latchResourceFailure(e),e}a=!1,i=void 0,this.sessions.delete(t.sessionId),r()},cancel:async()=>{try{this.archive()&&await this.executeArchive(e=>e.cancel_slide())}finally{i=void 0,a=!1,this.sessions.delete(t.sessionId),r()}},close:async()=>{try{this.archive()&&await this.executeArchive(e=>e.cancel_slide())}finally{i=void 0,a=!1,this.sessions.delete(t.sessionId),r()}},resourceUsage:()=>{try{return this.readResourceUsage()}catch(e){throw this.latchResourceFailure(e),e}}}});this.sessions.set(t.sessionId,{host:o,identity:t}),this.pendingOpens.delete(t.sessionId)}));this.operationTail=a.then(()=>i,()=>void 0);try{await a}catch(e){throw this.pendingOpens.delete(t.sessionId),r(),e}}async postOpenedSafely(e,t,n){if(this.lifecycleState!==`ready`){try{n(this.lifecycleError())}catch{}return}try{t()}catch(t){await this.closeIdentity(e);try{n(t)}catch{}}}dispatch(e,t){if(this.lifecycleState!==`ready`)return t(this.responseDuringReset(e)),Promise.resolve();let n=this.sessions.get(e.sessionId);if(n)return n.host.dispatch(e,t);let r=this.pendingOpens.get(e.sessionId);if(r&&(e.kind===`cancel`||e.kind===`close`)){let n=M(r.identity,e);return n&&(r.canceled=!0),t(n?{protocol:C,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:C,kind:`accepted`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,command:e.kind}),Promise.resolve()):(t({protocol:C,kind:`error`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:x(Error(`slide pull session is not open`))}),Promise.resolve())}async dispatchSafely(e,t){try{await this.dispatch(e,t)}catch(n){try{t({protocol:C,kind:`error`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:x(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:C,kind:`close`,...n,requestId:e++},e=>{e.kind===`error`&&(r=Ee(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 Ae,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&&!M(t,e)?this.staleLifecycleResponse(e):{protocol:C,kind:`accepted`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,command:e.kind}}return{protocol:C,kind:`error`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:x(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:C,kind:`close`,...e,requestId:1},()=>void 0);return}let n=this.pendingOpens.get(e.sessionId);n&&M(n.identity,e)&&(n.canceled=!0)}readResourceUsage(){return j(this.executeArchive)}latchResourceFailure(e){let t=e instanceof n?e:b(e);t&&(this.resourceFailure??=t)}staleLifecycleResponse(e){return{protocol:C,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 M(e,t){return e.sessionId===t.sessionId&&e.operationId===t.operationId&&e.generation===t.generation}var N=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,P.unregister(this),e}free(){let e=this.__destroy_into_raw();J.__wbg_pptxarchive_free(e,0)}acknowledge_slide(e,t){let n=J.pptxarchive_acknowledge_slide(this.__wbg_ptr,e,t);if(n[1])throw U(n[0])}assert_healthy(){let e=J.pptxarchive_assert_healthy(this.__wbg_ptr);if(e[1])throw U(e[0])}cancel_slide(){J.pptxarchive_cancel_slide(this.__wbg_ptr)}close_presentation_session(){J.pptxarchive_close_presentation_session(this.__wbg_ptr)}extract_image(e){let t=H(e,J.__wbindgen_malloc,J.__wbindgen_realloc),n=q,r=J.pptxarchive_extract_image(this.__wbg_ptr,t,n);if(r[3])throw U(r[2]);var i=F(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=F(r[0],r[1]).slice();return J.__wbindgen_free(r[0],r[1]*1,1),i}constructor(e,t,n,r){let i=$e(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,P.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=F(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=F(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=F(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=F(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=F(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&&(N.prototype[Symbol.dispose]=N.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;L().setInt32(e+4,i,!0),L().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 P=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>J.__wbg_pptxarchive_free(e>>>0,1));function F(e,t){return e>>>=0,B().subarray(e/1,e/1+t)}let I=null;function L(){return(I===null||I.buffer.detached===!0||I.buffer.detached===void 0&&I.buffer!==J.memory.buffer)&&(I=new DataView(J.memory.buffer)),I}function R(e,t){return e>>>=0,et(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 $e(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 et(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 tt(e,t){return J=e.exports,I=null,z=null,J.__wbindgen_start(),J}async function nt(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 rt(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 nt(await e,t);return tt(n,r)}async function it(e){return J=void 0,I=null,z=null,rt(e)}const Y=new ce(rt,{freeArchive:e=>e.free(),reinit:it});let X=null,Z=`empty`;function at(){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`&&(at(),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,...x(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]=Oe(t.resourcePolicy),a=Y.run(()=>{let n=new N(new Uint8Array(t.buffer),e,r,i);return Y.setArchive(n),JSON.parse(new TextDecoder().decode(n.presentation_bootstrap()))});X=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===`resourceUsage`){$({kind:`resourceUsage`,id:n,usage:h(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,...x(e)})}catch{}}};", at = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", it], { type: "text/javascript;charset=utf-8" });
548
+ function ot(e) {
549
+ let t;
550
+ try {
551
+ if (t = at && (self.URL || self.webkitURL).createObjectURL(at), !t) throw "";
552
+ let n = new Worker(t, {
553
+ type: "module",
554
+ name: e?.name
555
+ });
556
+ return n.addEventListener("error", () => {
557
+ (self.URL || self.webkitURL).revokeObjectURL(t);
558
+ }), n;
559
+ } catch {
560
+ return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(it), {
561
+ type: "module",
562
+ name: e?.name
563
+ });
564
+ }
565
+ }
566
+ //#endregion
567
+ //#region packages/pptx/src/wasm/pptx_parser_bg.wasm?url
568
+ var st = new URL("pptx_parser_bg.wasm", import.meta.url).href, K = 65536, ct = 16384, lt = new Set(["line", "straightconnector1"]);
569
+ function ut(e, t) {
570
+ 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;
571
+ return e.flipH && (l = 2 * n - l), e.flipV && (u = 2 * r - u), {
572
+ x: l,
573
+ y: u
574
+ };
575
+ }
576
+ function dt(e, t, n) {
577
+ let r = n.x - t.x, i = n.y - t.y, a = r * r + i * i;
578
+ if (a === 0) return Math.hypot(e.x - t.x, e.y - t.y);
579
+ let o = Math.max(0, Math.min(1, ((e.x - t.x) * r + (e.y - t.y) * i) / a));
580
+ return Math.hypot(e.x - (t.x + o * r), e.y - (t.y + o * i));
581
+ }
582
+ function ft(e, t, n = 0) {
583
+ if (!Number.isFinite(t.x) || !Number.isFinite(t.y)) return !1;
584
+ let r = ut(e, t), i = Number.isFinite(n) && n > 0 ? n : 0;
585
+ if (e.type === "shape" && (lt.has(e.geometry.toLowerCase()) || e.width === 0 || e.height === 0)) return dt(r, {
586
+ x: e.x,
587
+ y: e.y
588
+ }, {
589
+ x: e.x + e.width,
590
+ y: e.y + e.height
591
+ }) <= i;
592
+ 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);
593
+ return r.x >= a && r.x <= o && r.y >= s && r.y <= c;
594
+ }
595
+ function* pt(e) {
596
+ if (e) for (let t of e.paragraphs) {
597
+ let e = !0;
598
+ for (let n of t.runs) {
599
+ let t = n.type === "text" ? n.text : n.type === "break" ? "\n" : "[equation]";
600
+ t && (yield {
601
+ text: t,
602
+ beginsPart: e
603
+ }, e = !1);
604
+ }
605
+ }
606
+ }
607
+ function* mt(e) {
608
+ if (e.type === "shape") {
609
+ yield* pt(e.textBody);
610
+ return;
611
+ }
612
+ if (e.type === "table") {
613
+ for (let t of e.rows) for (let e of t.cells) yield* pt(e.textBody);
614
+ return;
615
+ }
616
+ }
617
+ function ht(e, t) {
618
+ let n = Math.min(e.length, t);
619
+ if (n > 0 && n < e.length) {
620
+ let t = e.charCodeAt(n - 1), r = e.charCodeAt(n);
621
+ t >= 55296 && t <= 56319 && r >= 56320 && r <= 57343 && n--;
622
+ }
623
+ return e.slice(0, n);
624
+ }
625
+ function gt(e, t = ct) {
626
+ if (!Number.isFinite(t) || t < 0) throw RangeError("maxTextCharacters must be a finite non-negative number.");
627
+ let n = Math.min(K, Math.floor(t)), r = e.text, i = r === void 0 ? void 0 : ht(r, n), a = r !== void 0 && i.length < r.length;
628
+ return {
629
+ ...structuredClone(e),
630
+ ...i === void 0 ? {} : { text: i },
631
+ truncated: e.truncated || a,
632
+ truncationReasons: e.truncated || a ? ["text"] : [],
633
+ textCharacters: i?.length ?? 0,
634
+ maxTextCharacters: n
635
+ };
636
+ }
637
+ function _t(e, t) {
638
+ let n = [], r = 0, i = !1, a = !1;
639
+ for (let o of e) {
640
+ if (a = !0, o.beginsPart && n.length > 0) {
641
+ if (r >= t) {
642
+ i = !0;
643
+ break;
644
+ }
645
+ n.push("\n"), r++;
646
+ }
647
+ let e = Math.max(0, t - r), s = ht(o.text, e);
648
+ if (n.push(s), r += s.length, s.length < o.text.length) {
649
+ i = !0;
650
+ break;
651
+ }
652
+ }
653
+ return a ? {
654
+ text: n.join(""),
655
+ truncated: i,
656
+ textCharacters: r
657
+ } : {
658
+ truncated: !1,
659
+ textCharacters: 0
660
+ };
661
+ }
662
+ function vt(e, t, n, r = {}) {
663
+ if (!Number.isFinite(n.x) || !Number.isFinite(n.y)) throw RangeError("PPTX hit-test point must contain finite coordinates.");
664
+ let i = r.maxTextCharacters ?? ct;
665
+ if (!Number.isFinite(i) || i < 0) throw RangeError("maxTextCharacters must be a finite non-negative number.");
666
+ let a = Math.min(K, Math.floor(i)), o = r.tolerance ?? 0;
667
+ if (!Number.isFinite(o) || o < 0) throw RangeError("tolerance must be a finite non-negative number.");
668
+ for (let r = t.elements.length - 1; r >= 0; r--) {
669
+ let i = t.elements[r];
670
+ if (!ft(i, n, o)) continue;
671
+ let s = i.type === "chart" ? ae(i.chart, a) : _t(mt(i), a);
672
+ return {
673
+ format: "pptx",
674
+ kind: "element",
675
+ slideIndex: e,
676
+ elementIndex: r,
677
+ origin: t.elementSources?.[r]?.origin ?? "unknown",
678
+ elementType: i.type,
679
+ point: { ...n },
680
+ bounds: {
681
+ x: i.x,
682
+ y: i.y,
683
+ width: i.width,
684
+ height: i.height,
685
+ rotation: i.rotation,
686
+ flipH: i.flipH,
687
+ flipV: i.flipV
688
+ },
689
+ ...i.type === "shape" ? {
690
+ ...i.id === void 0 ? {} : { shapeId: i.id },
691
+ ...i.name === void 0 ? {} : { name: i.name },
692
+ geometry: i.geometry
693
+ } : {},
694
+ ...s.text === void 0 ? {} : { text: s.text },
695
+ ...i.type === "picture" ? { mimeType: i.mimeType } : {},
696
+ ...i.type === "media" ? {
697
+ mimeType: i.mimeType,
698
+ mediaKind: i.mediaKind
699
+ } : {},
700
+ ...i.type === "table" ? {
701
+ rowCount: i.rows.length,
702
+ columnCount: i.cols.length
703
+ } : {},
704
+ ...i.type === "chart" ? { seriesCount: i.chart.series.length } : {},
705
+ truncated: s.truncated,
706
+ truncationReasons: s.truncated ? ["text"] : [],
707
+ textCharacters: s.textCharacters,
708
+ maxTextCharacters: a
709
+ };
710
+ }
711
+ return null;
712
+ }
713
+ function yt(e, t) {
714
+ let n = new Set(t.filter((e) => e.length > 0));
715
+ if (n.size === 0) return Object.freeze([]);
716
+ let r = /* @__PURE__ */ new Map();
717
+ for (let [t, i] of e.elements.entries()) {
718
+ let a = i.id;
719
+ if (!a || !n.has(a)) continue;
720
+ 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");
721
+ c && l > s || r.set(a, Object.freeze({
722
+ elementId: a,
723
+ elementIndex: t,
724
+ origin: o,
725
+ elementType: i.type,
726
+ bounds: Object.freeze({
727
+ x: i.x,
728
+ y: i.y,
729
+ width: i.width,
730
+ height: i.height,
731
+ rotation: i.rotation,
732
+ flipH: i.flipH,
733
+ flipV: i.flipV
734
+ })
735
+ }));
736
+ }
737
+ return Object.freeze(t.flatMap((e) => {
738
+ let t = r.get(e);
739
+ return t ? [t] : [];
740
+ }));
741
+ }
742
+ //#endregion
743
+ //#region packages/pptx/src/presentation.ts
744
+ var q = class e {
745
+ _metrics = null;
746
+ _worker;
747
+ _bridge;
748
+ _mode = "main";
749
+ _preflight = null;
750
+ _slides = null;
751
+ _slidePullClient = null;
752
+ _resourceFailure = null;
753
+ _slidePartIndex = null;
754
+ _rawParts = new Ce({
755
+ maxEntries: 64,
756
+ maxBytes: S
757
+ });
758
+ _googleFontFaces = [];
759
+ _fetchImage = (e, t) => this.getImage(e, t);
760
+ _fetchMedia = (e) => this.getMedia(e);
761
+ _math;
762
+ _threeD;
763
+ _regionMap;
764
+ _chartEx;
765
+ constructor(e, t, n) {
766
+ this._worker = e, this._mode = t, this._bridge = new w(this._worker, {
767
+ correlate: (e) => "protocol" in e && e.protocol === "ooxml-pull-v1" ? e.requestId : "id" in e ? e.id : void 0,
768
+ toError: (e) => !("protocol" in e) && e.kind === "error" ? b(e) : void 0
769
+ });
770
+ let r = new URL(n ?? st, location.href).href;
771
+ this._bridge.post({
772
+ kind: "init",
773
+ wasmUrl: r
774
+ });
775
+ }
776
+ _assertResourceHealthy() {
777
+ if (this._resourceFailure) throw this._resourceFailure;
778
+ }
779
+ _rethrowWithResourceFailure(e) {
780
+ let t = e instanceof g ? e : v(e);
781
+ throw t ? (this._resourceFailure ??= t, this._resourceFailure) : e;
782
+ }
783
+ static async load(t, n = {}) {
784
+ let r = u(n), i = n.mode ?? "main", a = new h({
785
+ enabled: !0,
786
+ format: "pptx",
787
+ mode: i,
788
+ policy: r.policy,
789
+ onMetrics: r.onResourceMetrics,
790
+ emitToConsole: r.debug
791
+ });
792
+ try {
793
+ if (i === "worker" && (typeof Worker > "u" || typeof OffscreenCanvas > "u")) throw Error("mode: 'worker' requires Worker and OffscreenCanvas support");
794
+ let s;
795
+ if (typeof t == "string") {
796
+ let e = await fetch(t);
797
+ if (!e.ok) throw Error(`Failed to fetch: ${e.status} ${e.statusText}`);
798
+ s = await e.arrayBuffer();
799
+ } else s = t;
800
+ s = ee(await ne(s, n.password)), a.setSourceBytes(s.byteLength), a.checkpoint("container ready");
801
+ let c = i === "worker" ? (await import("./render-worker-host-BmH3kGSj.js")).createRenderWorker() : new ot(), l = i === "worker" ? De(n) : void 0, u;
802
+ try {
803
+ return u = new e(c, i, n.wasmUrl), u._metrics = a, n.math && i === "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."), n.threeD && i === "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 = i === "worker" ? void 0 : n.math, u._threeD = i === "worker" ? void 0 : n.threeD, n.regionMap && i === "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 = i === "worker" ? void 0 : n.regionMap, n.chartEx && i === "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 = i === "worker" ? void 0 : n.chartEx, await u._parse(s, r.policy, i === "worker" ? !!n.useGoogleFonts : !1, n.workerTimeoutMs, (e) => a.observeUsage(e), l), a.checkpoint("presentation preflight ready"), i === "main" && n.useGoogleFonts && u._preflight && (u._googleFontFaces = await xe(u._preflight.fontPreloadNames, o)), a.succeed({ slides: u.slideCount }), u;
804
+ } catch (e) {
805
+ let t = u;
806
+ throw te(c, t ? () => t.destroy() : void 0), e;
807
+ }
808
+ } catch (e) {
809
+ throw a.fail(e), e;
810
+ }
811
+ }
812
+ async _parse(e, n, i = !1, o, s, c) {
813
+ let u = await this._bridge.request((t) => this._mode === "worker" ? {
814
+ kind: "parse",
815
+ id: t,
816
+ buffer: e,
817
+ resourcePolicy: n,
818
+ useGoogleFonts: i,
819
+ renderers: c
820
+ } : {
821
+ kind: "parse",
822
+ id: t,
823
+ buffer: e,
824
+ resourcePolicy: n
825
+ }, [e], { timeoutMs: o });
826
+ if (this._mode === "worker") {
827
+ let e = u;
828
+ e.usage && s?.(e.usage), this._preflight = t(u.preflight);
829
+ return;
830
+ }
831
+ let d = r(u.bootstrap);
832
+ this._slidePullClient = new l({
833
+ slideCount: d.slideCount,
834
+ transport: this._bridge.transport(a),
835
+ open: async (e, t, n) => {
836
+ await this._bridge.request((n) => ({
837
+ kind: "openSlideSession",
838
+ id: n,
839
+ slideIndex: e,
840
+ ...t
841
+ }), void 0, { timeoutMs: n });
842
+ },
843
+ onUsage: s
844
+ });
845
+ for (let e = 0; e < d.slideCount; e += 1) await this._slidePullClient.load(e, !1, o);
846
+ this._preflight = t((await this._bridge.request((e) => ({
847
+ kind: "finishPresentationPreflight",
848
+ id: e
849
+ }), void 0, { timeoutMs: o })).preflight), this._slides = new nt({
850
+ slideCount: this._preflight.slideCount,
851
+ maxCachedSlides: 8,
852
+ maxCachedStructuralBytes: p,
853
+ loadSlide: async (e) => {
854
+ let t = await this._slidePullClient?.load(e, !0);
855
+ if (!t) throw Error("PPTX slide pull client is unavailable");
856
+ return t;
857
+ }
858
+ });
859
+ }
860
+ get slideCount() {
861
+ return this._preflight?.slideCount ?? 0;
862
+ }
863
+ get slideWidth() {
864
+ return this._preflight?.slideWidth ?? 0;
865
+ }
866
+ get slideHeight() {
867
+ return this._preflight?.slideHeight ?? 0;
868
+ }
869
+ get mode() {
870
+ return this._mode;
871
+ }
872
+ getNotes(e) {
873
+ return Number.isInteger(e) ? this._preflight?.slides[e]?.notes ?? null : null;
874
+ }
875
+ getComments(e) {
876
+ return Number.isInteger(e) ? this._preflight?.slides[e]?.comments ?? [] : [];
877
+ }
878
+ isHidden(e) {
879
+ return Number.isInteger(e) ? this._preflight?.slides[e]?.hidden ?? !1 : !1;
880
+ }
881
+ _partNames() {
882
+ return (this._preflight?.slides ?? []).map((e) => e.partName);
883
+ }
884
+ _partIndex() {
885
+ return this._slidePartIndex ||= $e(this._partNames()), this._slidePartIndex;
886
+ }
887
+ getSlideIndexByPartName(e) {
888
+ return this._partIndex().get(e);
889
+ }
890
+ resolveInternalTarget(e, t = 0) {
891
+ return tt(e, this._partIndex(), t);
892
+ }
893
+ async renderSlide(e, t, r = {}) {
894
+ this._assertResourceHealthy();
895
+ try {
896
+ if (this._mode === "worker") throw Error("renderSlide(canvas) is unavailable in mode: 'worker'; use renderSlideToBitmap() and paint it via an ImageBitmapRenderingContext");
897
+ let i = this._preflight, a = this._slides;
898
+ if (!i || !a) throw Error("Presentation not loaded");
899
+ let o = r.dpr ?? x(), s = r.width ?? ((y(e) ? e.offsetWidth : 0) || 960);
900
+ await a.withSlide(t, (t) => (this._assertResourceHealthy(), n(e, t, i.slideWidth, i.slideHeight, {
901
+ width: s,
902
+ dpr: o,
903
+ defaultTextColor: i.defaultTextColor,
904
+ majorFont: i.majorFont,
905
+ minorFont: i.minorFont,
906
+ hlinkColor: i.hlinkColor,
907
+ fetchMedia: this._fetchMedia,
908
+ fetchImage: this._fetchImage,
909
+ skipMediaControls: r.skipMediaControls,
910
+ dim: r.dim,
911
+ math: this._math,
912
+ threeD: this._threeD,
913
+ regionMap: this._regionMap,
914
+ chartEx: this._chartEx
915
+ }, r.onTextRun)));
916
+ } catch (e) {
917
+ this._rethrowWithResourceFailure(e);
918
+ }
919
+ }
920
+ async renderSlideToBitmap(e, t = {}) {
921
+ this._assertResourceHealthy();
922
+ try {
923
+ let n = t.width ?? 960, r = t.dpr ?? x();
924
+ if (this._mode === "worker") {
925
+ if (!Number.isInteger(e) || e < 0 || e >= this.slideCount) throw Error(`Slide index ${e} out of range (count: ${this.slideCount})`);
926
+ let i = await this._bridge.request((i) => ({
927
+ kind: "renderSlide",
928
+ id: i,
929
+ slideIndex: e,
930
+ width: n,
931
+ dpr: r,
932
+ skipMediaControls: t.skipMediaControls,
933
+ dim: t.dim
934
+ }));
935
+ if (t.onTextRun) for (let e of i.runs) t.onTextRun(e);
936
+ return i.bitmap;
937
+ }
938
+ let i = new OffscreenCanvas(1, 1);
939
+ return await this.renderSlide(i, e, {
940
+ width: n,
941
+ dpr: r,
942
+ skipMediaControls: t.skipMediaControls,
943
+ dim: t.dim,
944
+ onTextRun: t.onTextRun
945
+ }), i.transferToImageBitmap();
946
+ } catch (e) {
947
+ this._rethrowWithResourceFailure(e);
948
+ }
949
+ }
950
+ async collectSlideRuns(e, t = 960) {
951
+ this._assertResourceHealthy();
952
+ try {
953
+ if (this._mode === "worker") {
954
+ if (!Number.isInteger(e) || e < 0 || e >= this.slideCount) throw Error(`Slide index ${e} out of range (count: ${this.slideCount})`);
955
+ return (await this._bridge.request((n) => ({
956
+ kind: "collectRuns",
957
+ id: n,
958
+ slideIndex: e,
959
+ width: t
960
+ }))).runs;
961
+ }
962
+ let n = [], r = new OffscreenCanvas(1, 1);
963
+ return await this.renderSlide(r, e, {
964
+ width: t,
965
+ onTextRun: (e) => n.push(e)
966
+ }), n;
967
+ } catch (e) {
968
+ this._rethrowWithResourceFailure(e);
969
+ }
970
+ }
971
+ async getElementContextAt(e, t, n = {}) {
972
+ if (this._assertResourceHealthy(), !Number.isInteger(e) || e < 0 || e >= this.slideCount) throw Error(`Slide index ${e} out of range (count: ${this.slideCount})`);
973
+ try {
974
+ if (this._mode === "worker") return (await this._bridge.request((r) => ({
975
+ kind: "hitTestElement",
976
+ id: r,
977
+ slideIndex: e,
978
+ point: t,
979
+ options: n
980
+ }))).context;
981
+ if (!this._slides) throw Error("Presentation not loaded");
982
+ return await this._slides.withSlide(e, (r) => vt(e, r, t, n));
983
+ } catch (e) {
984
+ this._rethrowWithResourceFailure(e);
985
+ }
986
+ }
987
+ async getElementBoundsByIds(e, t) {
988
+ if (this._assertResourceHealthy(), !Number.isInteger(e) || e < 0 || e >= this.slideCount) throw Error(`Slide index ${e} out of range (count: ${this.slideCount})`);
989
+ let n = Object.freeze(t.filter((e) => typeof e == "string" && e.length > 0));
990
+ if (n.length === 0) return Object.freeze([]);
991
+ try {
992
+ if (this._mode === "worker") return (await this._bridge.request((t) => ({
993
+ kind: "resolveElementBounds",
994
+ id: t,
995
+ slideIndex: e,
996
+ elementIds: n
997
+ }))).bounds;
998
+ if (!this._slides) throw Error("Presentation not loaded");
999
+ return await this._slides.withSlide(e, (e) => yt(e, n));
1000
+ } catch (e) {
1001
+ this._rethrowWithResourceFailure(e);
1002
+ }
1003
+ }
1004
+ async getMedia(e) {
1005
+ this._assertResourceHealthy();
1006
+ try {
1007
+ let t = this._findMimeTypeForPath(e);
1008
+ return await this._rawParts.get(e, t, async () => {
1009
+ let n = (await this._bridge.request((t) => ({
1010
+ kind: "extractMedia",
1011
+ id: t,
1012
+ path: e
1013
+ }))).bytes;
1014
+ return new Blob([n], { type: t });
1015
+ });
1016
+ } catch (e) {
1017
+ this._rethrowWithResourceFailure(e);
1018
+ }
1019
+ }
1020
+ _findMimeTypeForPath(e) {
1021
+ return this._preflight ? s(this._preflight, e) : "";
1022
+ }
1023
+ async getImage(e, t) {
1024
+ this._assertResourceHealthy();
1025
+ try {
1026
+ return await this._rawParts.get(e, t, async () => {
1027
+ let n = (await this._bridge.request((t) => ({
1028
+ kind: "extractImage",
1029
+ id: t,
1030
+ path: e
1031
+ }))).bytes;
1032
+ return new Blob([n], { type: t });
1033
+ });
1034
+ } catch (e) {
1035
+ this._rethrowWithResourceFailure(e);
1036
+ }
1037
+ }
1038
+ async getResourceMetrics() {
1039
+ let e = this._metrics;
1040
+ if (!e) throw Error("Presentation not loaded");
1041
+ return C(e, async (e) => (await this._bridge.request((e) => ({
1042
+ kind: "resourceUsage",
1043
+ id: e
1044
+ }), void 0, { timeoutMs: e })).usage);
1045
+ }
1046
+ async toMarkdown() {
1047
+ this._assertResourceHealthy();
1048
+ try {
1049
+ return (await this._bridge.request((e) => ({
1050
+ kind: "toMarkdown",
1051
+ id: e
1052
+ }))).markdown;
1053
+ } catch (e) {
1054
+ this._rethrowWithResourceFailure(e);
1055
+ }
1056
+ }
1057
+ async presentSlide(e, t, n = {}) {
1058
+ this._assertResourceHealthy();
1059
+ try {
1060
+ if (!this._preflight) throw Error("Presentation not loaded");
1061
+ if (!Number.isInteger(t) || t < 0 || t >= this.slideCount) throw Error(`Slide index ${t} out of range (count: ${this.slideCount})`);
1062
+ let r = n.dpr ?? x(), i = n.width ?? (e.offsetWidth || 960), a = this._mode === "worker" ? async () => {
1063
+ let a = await this.renderSlideToBitmap(t, {
1064
+ width: i,
1065
+ dpr: r,
1066
+ skipMediaControls: !0,
1067
+ dim: n.dim,
1068
+ onTextRun: n.onTextRun
1069
+ });
1070
+ e.width = a.width, e.height = a.height, e.style.width = `${Math.round(a.width / r)}px`, e.style.display || (e.style.display = "block");
1071
+ let o = e.getContext("2d");
1072
+ if (!o) throw Error("2D context not available");
1073
+ o.drawImage(a, 0, 0), a.close();
1074
+ } : () => this.renderSlide(e, t, {
1075
+ width: i,
1076
+ dpr: r,
1077
+ skipMediaControls: !0,
1078
+ dim: n.dim,
1079
+ onTextRun: n.onTextRun
1080
+ });
1081
+ return await Ve(e, this._preflight.slides[t]?.mediaElements ?? [], {
1082
+ width: i,
1083
+ dpr: r,
1084
+ slideWidthEmu: this.slideWidth,
1085
+ fetchMedia: this._fetchMedia,
1086
+ fetchImage: this._fetchImage,
1087
+ drawBase: a,
1088
+ onError: n.onError
1089
+ });
1090
+ } catch (e) {
1091
+ this._rethrowWithResourceFailure(e);
1092
+ }
1093
+ }
1094
+ destroy() {
1095
+ this._slidePullClient?.cancelAll(), this._bridge.terminate(), this._slides?.clear(), this._slides = null, this._slidePullClient = null, this._preflight = null, this._resourceFailure = null, this._slidePartIndex = null, this._rawParts.clear(), this._googleFontFaces.length > 0 && (be(this._googleFontFaces), this._googleFontFaces = []), f(this._fetchImage), d(this._fetchImage);
1096
+ }
1097
+ };
1098
+ //#endregion
1099
+ //#region packages/pptx/src/selection-context.ts
1100
+ function bt(e, t, n, r, i = {}) {
1101
+ let a = je({
1102
+ id: e.id,
1103
+ author: e.author,
1104
+ date: e.date,
1105
+ text: e.text,
1106
+ status: e.status ?? "active"
1107
+ }, (e.replies ?? []).map((e) => ({
1108
+ id: e.id,
1109
+ author: e.author,
1110
+ date: e.date,
1111
+ text: e.text,
1112
+ status: e.status ?? "active"
1113
+ })), i.maxTextCharacters);
1114
+ return Object.freeze({
1115
+ format: "pptx",
1116
+ kind: "comment",
1117
+ slideIndex: t,
1118
+ commentIndex: n,
1119
+ occurrenceId: r,
1120
+ ...e.id ? { commentId: e.id } : {},
1121
+ ...Number.isFinite(e.x) && Number.isFinite(e.y) ? { point: Object.freeze({
1122
+ x: e.x,
1123
+ y: e.y
1124
+ }) } : {},
1125
+ thread: a.thread,
1126
+ truncated: a.truncated,
1127
+ truncationReasons: a.truncated ? ["text"] : [],
1128
+ textCharacters: a.textCharacters,
1129
+ maxTextCharacters: a.maxTextCharacters
1130
+ });
1131
+ }
1132
+ function J(e) {
1133
+ if (e === void 0 || !/^\d+$/.test(e)) return null;
1134
+ let t = Number(e);
1135
+ return Number.isSafeInteger(t) ? t : null;
1136
+ }
1137
+ function xt(e) {
1138
+ for (let t = e; t; t = t.parentElement) {
1139
+ let e = J(t.dataset.slideIndex);
1140
+ if (e !== null) return e;
1141
+ }
1142
+ return null;
1143
+ }
1144
+ function Y(e, t, n = {}) {
1145
+ let r = me(e, t, (e) => {
1146
+ let t = xt(e), n = J(e.dataset.runIndex);
1147
+ if (t === null || n === null) return null;
1148
+ let r = J(e.dataset.elementIndex), i = e.dataset.elementOrigin, a = r !== null && (i === "master" || i === "layout" || i === "slide");
1149
+ return {
1150
+ slideIndex: t,
1151
+ runIndex: n,
1152
+ ...e.dataset.shapeId === void 0 ? {} : { shapeId: e.dataset.shapeId },
1153
+ ...a ? {
1154
+ elementIndex: r,
1155
+ origin: i
1156
+ } : {}
1157
+ };
1158
+ }, {
1159
+ maxChars: n.maxTextCharacters,
1160
+ maxLocators: n.maxRunLocators
1161
+ });
1162
+ if (!r) return null;
1163
+ let i = [...r.locators].sort((e, t) => e.slideIndex - t.slideIndex || e.runIndex - t.runIndex);
1164
+ return {
1165
+ format: "pptx",
1166
+ kind: "text",
1167
+ text: r.text,
1168
+ slideIndexes: [...new Set(i.map((e) => e.slideIndex))],
1169
+ shapeIds: [...new Set(i.flatMap((e) => e.shapeId ? [e.shapeId] : []))],
1170
+ runs: i,
1171
+ truncated: r.truncated,
1172
+ truncationReasons: r.truncationReasons,
1173
+ textCharacters: r.textCharacters,
1174
+ maxTextCharacters: r.maxTextCharacters,
1175
+ maxRunLocators: r.maxLocators
1176
+ };
1177
+ }
1178
+ //#endregion
1179
+ //#region packages/pptx/src/focused-view-runtime.ts
1180
+ function X(e, t, n, r, i) {
1181
+ return r === "worker" ? e.renderSlideToBitmap(n, i) : e.renderSlide(t, n, i);
1182
+ }
1183
+ //#endregion
1184
+ //#region packages/pptx/src/viewer.ts
1185
+ var St = Symbol("PptxViewer.borrowedPresentation"), Z = {
1186
+ color: "#ffffff",
1187
+ opacity: .6
1188
+ }, Ct = class e {
1189
+ canvas;
1190
+ wrapper;
1191
+ canvasMount;
1192
+ _scale = null;
1193
+ textLayer = null;
1194
+ highlightLayer = null;
1195
+ elementLayer = null;
1196
+ _find;
1197
+ _measureCtx = null;
1198
+ presentationOwner;
1199
+ get engine() {
1200
+ return this.presentationOwner.current;
1201
+ }
1202
+ borrowed;
1203
+ hostWindow;
1204
+ opts;
1205
+ currentSlide = 0;
1206
+ _hiddenMode;
1207
+ handle = null;
1208
+ _mode;
1209
+ renderDispatcher;
1210
+ errorRouter;
1211
+ destroyed = !1;
1212
+ selectionChangeListener = null;
1213
+ selectionContextKey = "null";
1214
+ elementClickListener = null;
1215
+ contextMenuListener = null;
1216
+ elementContext = null;
1217
+ elementHitGeneration = 0;
1218
+ elementHitTolerance;
1219
+ static fromPresentation(t, n, r = {}) {
1220
+ return new e(t, {
1221
+ ...r,
1222
+ [St]: n
1223
+ });
1224
+ }
1225
+ constructor(e, t = {}) {
1226
+ this.opts = t, this.canvas = e;
1227
+ let n = t[St];
1228
+ this.borrowed = n !== void 0, this._mode = O("PptxViewer", t.mode, n), this.presentationOwner = new T("PptxViewer", n ?? null, !1);
1229
+ let r = e.ownerDocument?.defaultView ?? (typeof window < "u" ? window : null);
1230
+ if (!r) throw Error("PptxViewer requires a canvas with an active Window");
1231
+ this.hostWindow = r;
1232
+ let i = t.elementHitTolerance ?? 6;
1233
+ if (!Number.isFinite(i) || i < 0) throw RangeError("elementHitTolerance must be a finite non-negative number.");
1234
+ this.elementHitTolerance = i, this._hiddenMode = t.hiddenSlideMode ?? "show", this.canvasMount = new he(e, {
1235
+ wrapperCssText: "position:relative;display:inline-block;vertical-align:top;",
1236
+ forceDisplayBlock: !0
1237
+ }), this.wrapper = this.canvasMount.wrapper, this.renderDispatcher = new D(e, this._mode === "worker" && !t.enableMediaPlayback), this.errorRouter = new pe("PptxViewer", t.onError);
1238
+ let a = new ue(this.wrapper, t.enableTextSelection === !0, t.enableElementSelection === !0);
1239
+ this.textLayer = a.textLayer, this.highlightLayer = a.highlightLayer, this.elementLayer = a.elementLayer, this.textLayer && (t.onSelectionContextChange || t.enableElementSelection) && (this.selectionChangeListener = () => this._emitSelectionContextChange(), this.wrapper.ownerDocument.addEventListener("selectionchange", this.selectionChangeListener)), t.enableElementSelection && (this.elementClickListener = (e) => {
1240
+ this._onElementClick(e).catch((e) => this._reportRenderError(e));
1241
+ }, this.wrapper.addEventListener("click", this.elementClickListener)), t.onContextMenu && (this.contextMenuListener = (e) => this._onContextMenu(e), this.wrapper.addEventListener("contextmenu", this.contextMenuListener)), this._find = new Re(() => this.slideCount, (e) => this._collectSlideRuns(e));
1242
+ }
1243
+ async load(e) {
1244
+ if (this.destroyed) throw Error("PptxViewer is destroyed");
1245
+ if (this.borrowed) throw Error("PptxViewer.load() is unsupported on a Viewer created by fromPresentation(); the borrowed presentation is already loaded.");
1246
+ let t = !1;
1247
+ try {
1248
+ if (!await this.presentationOwner.replace(() => q.load(e, {
1249
+ password: this.opts.password,
1250
+ useGoogleFonts: this.opts.useGoogleFonts,
1251
+ maxZipEntryBytes: this.opts.maxZipEntryBytes,
1252
+ resourceLimits: this.opts.resourceLimits,
1253
+ debug: this.opts.debug,
1254
+ onResourceMetrics: this.opts.onResourceMetrics,
1255
+ workerTimeoutMs: this.opts.workerTimeoutMs,
1256
+ wasmUrl: this.opts.wasmUrl,
1257
+ math: this.opts.math,
1258
+ threeD: this.opts.threeD,
1259
+ regionMap: this.opts.regionMap,
1260
+ chartEx: this.opts.chartEx,
1261
+ mode: this._mode
1262
+ }), () => {
1263
+ this._invalidateElementSelection(!1), t = !0, this.renderDispatcher.begin(), this._find.invalidate(), this.handle?.destroy(), this.handle = null;
1264
+ })) return;
1265
+ if (this.destroyed) throw Error("PptxViewer is destroyed");
1266
+ this.currentSlide = this._initialSlide(), this._find.invalidate(), await this.renderCurrentSlide();
1267
+ } catch (e) {
1268
+ throw this.destroyed ? Error("PptxViewer is destroyed") : e instanceof Error ? e : Error(String(e));
1269
+ }
1270
+ t && !this.destroyed && this._emitSelectionContextChange();
1271
+ }
1272
+ async goToSlide(e) {
1273
+ if (!this.engine || this.slideCount === 0) return;
1274
+ let t = Math.max(0, Math.min(e, this.slideCount - 1)), n = t !== this.currentSlide;
1275
+ n && this._invalidateElementSelection(!1), this.currentSlide = t, await this.renderCurrentSlide(), n && !this.destroyed && this._emitSelectionContextChange();
1276
+ }
1277
+ async nextSlide() {
1278
+ await this.goToSlide(this._step(1));
1279
+ }
1280
+ async prevSlide() {
1281
+ await this.goToSlide(this._step(-1));
1282
+ }
1283
+ _step(e) {
1284
+ return this._hiddenMode === "skip" && this.engine ? Oe(this.currentSlide, e, (e) => this.engine.isHidden(e), this.slideCount) : this.currentSlide + e;
1285
+ }
1286
+ _initialSlide() {
1287
+ return this._hiddenMode === "skip" && this.engine ? ke(0, (e) => this.engine.isHidden(e), this.slideCount) : 0;
1288
+ }
1289
+ _dim() {
1290
+ return {
1291
+ color: this.opts.hiddenSlideDim?.color ?? Z.color,
1292
+ opacity: this.opts.hiddenSlideDim?.opacity ?? Z.opacity
1293
+ };
1294
+ }
1295
+ async setHiddenSlideMode(e) {
1296
+ this._hiddenMode = e;
1297
+ let t = this.currentSlide;
1298
+ e === "skip" && this.engine && (t = ke(this.currentSlide, (e) => this.engine.isHidden(e), this.slideCount));
1299
+ let n = t !== this.currentSlide;
1300
+ n && this._invalidateElementSelection(!1), this.currentSlide = t, await this.renderCurrentSlide(), n && !this.destroyed && this._emitSelectionContextChange();
1301
+ }
1302
+ get hiddenSlideMode() {
1303
+ return this._hiddenMode;
1304
+ }
1305
+ get visibleSlideCount() {
1306
+ if (!this.engine) return 0;
1307
+ let e = this.engine;
1308
+ return Ae((t) => e.isHidden(t), this.slideCount);
1309
+ }
1310
+ get slideIndex() {
1311
+ return this.currentSlide;
1312
+ }
1313
+ get slideCount() {
1314
+ return this.engine?.slideCount ?? 0;
1315
+ }
1316
+ getNotes(e) {
1317
+ return this.engine?.getNotes(e) ?? null;
1318
+ }
1319
+ get canvasElement() {
1320
+ return this.canvas;
1321
+ }
1322
+ _naturalWidthPx() {
1323
+ let e = this.engine?.slideWidth ?? 0;
1324
+ return e > 0 ? e / k : 0;
1325
+ }
1326
+ _targetWidth() {
1327
+ if (this._scale === null) return this.opts.width ?? (this.canvas.offsetWidth || 960);
1328
+ let e = this._naturalWidthPx();
1329
+ return e <= 0 ? this.opts.width ?? (this.canvas.offsetWidth || 960) : Math.round(e * this._scale);
1330
+ }
1331
+ getScale() {
1332
+ if (this._scale !== null) return this._scale;
1333
+ let e = this._naturalWidthPx();
1334
+ return e <= 0 ? 1 : this._targetWidth() / e;
1335
+ }
1336
+ _zoomMin() {
1337
+ return this.opts.zoomMin ?? .1;
1338
+ }
1339
+ _zoomMax() {
1340
+ return this.opts.zoomMax ?? 4;
1341
+ }
1342
+ async setScale(e) {
1343
+ let t = se(e, this._zoomMin(), this._zoomMax()), n = t !== this.getScale();
1344
+ this._scale = t, await this.renderCurrentSlide(), n && this.opts.onScaleChange?.(t);
1345
+ }
1346
+ async zoomIn() {
1347
+ await this.setScale(ge(this.getScale()));
1348
+ }
1349
+ async zoomOut() {
1350
+ await this.setScale(ye(this.getScale()));
1351
+ }
1352
+ async fitWidth() {
1353
+ await this._fit("width");
1354
+ }
1355
+ async fitPage() {
1356
+ await this._fit("page");
1357
+ }
1358
+ async _fit(e) {
1359
+ if (!this.engine) return;
1360
+ let t = this.wrapper.parentElement;
1361
+ if (!t) return;
1362
+ let n = re({
1363
+ contentWidth: this.engine.slideWidth / k,
1364
+ contentHeight: this.engine.slideHeight / k,
1365
+ containerWidth: t.clientWidth,
1366
+ containerHeight: t.clientHeight
1367
+ }, e);
1368
+ n <= 0 || await this.setScale(n);
1369
+ }
1370
+ async renderCurrentSlide() {
1371
+ if (!this.engine) return;
1372
+ let e = this.renderDispatcher.begin(), t = this._hiddenMode === "dim" && this.engine.isHidden(this.currentSlide) ? this._dim() : void 0, n = this._targetWidth(), r = this.opts.dpr ?? (window.devicePixelRatio || 1), i = n / this.engine.slideWidth, a = Math.round(this.engine.slideHeight * i);
1373
+ this.canvas.style.width = `${n}px`, this.canvas.style.height = `${a}px`, this.handle?.destroy(), this.handle = null;
1374
+ let o = this._mode === "worker", s = [], c = (e) => s.push(e);
1375
+ try {
1376
+ if (this.opts.enableMediaPlayback) {
1377
+ let i = await this.engine.presentSlide(this.canvas, this.currentSlide, {
1378
+ width: n,
1379
+ dpr: r,
1380
+ dim: t,
1381
+ onTextRun: c,
1382
+ onError: (t) => {
1383
+ this.renderDispatcher.isCurrent(e) && this._reportRenderError(t);
1384
+ }
1385
+ });
1386
+ if (!this.renderDispatcher.isCurrent(e)) {
1387
+ i.destroy();
1388
+ return;
1389
+ }
1390
+ this.handle = i;
1391
+ } else if (o) {
1392
+ let i = await X(this.engine, this.canvas, this.currentSlide, "worker", {
1393
+ width: n,
1394
+ dpr: r,
1395
+ dim: t,
1396
+ onTextRun: c
1397
+ });
1398
+ if (!this.renderDispatcher.commitBitmap(e, i)) return;
1399
+ } else if (await X(this.engine, this.canvas, this.currentSlide, "main", {
1400
+ width: n,
1401
+ dpr: r,
1402
+ onTextRun: c,
1403
+ dim: t
1404
+ }), !this.renderDispatcher.isCurrent(e)) return;
1405
+ this.opts.onSlideChange?.(this.currentSlide, this.slideCount);
1406
+ } catch (t) {
1407
+ if (!this.renderDispatcher.isCurrent(e)) return;
1408
+ throw t;
1409
+ }
1410
+ this.textLayer && this._buildTextLayer(this.textLayer, s, n, a), this._find.setSlideRuns(this.currentSlide, s), this._buildHighlightLayer(s, n, a);
1411
+ }
1412
+ _buildHighlightLayer(e, t, n) {
1413
+ let r = this.highlightLayer;
1414
+ r && P(r, e, this._find.slideHighlights(this.currentSlide), t, n, (e) => this._measureForFont(e), this.opts.findHighlightColors);
1415
+ }
1416
+ _measureForFont(e) {
1417
+ this._measureCtx ||= document.createElement("canvas").getContext("2d");
1418
+ let t = this._measureCtx;
1419
+ return t ? (t.font = e, (e) => t.measureText(e).width) : (e) => e.length;
1420
+ }
1421
+ async _collectSlideRuns(e) {
1422
+ return this.engine ? this.engine.collectSlideRuns(e, this._targetWidth()) : [];
1423
+ }
1424
+ async findText(e, t = {}) {
1425
+ if (!this.engine) return [];
1426
+ let n = await this._find.find(e, t);
1427
+ return this._redrawHighlights(), n;
1428
+ }
1429
+ async findNext() {
1430
+ return this._activateMatch(this._find.next());
1431
+ }
1432
+ async findPrev() {
1433
+ return this._activateMatch(this._find.prev());
1434
+ }
1435
+ clearFind() {
1436
+ this._find.invalidate(), this._redrawHighlights();
1437
+ }
1438
+ async _activateMatch(e) {
1439
+ return e ? (e.location.slide === this.currentSlide ? this._redrawHighlights() : await this.goToSlide(e.location.slide), e) : (this._redrawHighlights(), null);
1440
+ }
1441
+ _redrawHighlights() {
1442
+ let e = this._find.slideRuns(this.currentSlide) ?? [], t = this._targetWidth(), n = this.engine ? Math.round(this.engine.slideHeight * (t / this.engine.slideWidth)) : 0;
1443
+ this._buildHighlightLayer(e, t, n);
1444
+ }
1445
+ _buildTextLayer(e, t, n, r) {
1446
+ N(e, t, n, r, this._hyperlinkHandler(), this.currentSlide);
1447
+ }
1448
+ _hyperlinkHandler() {
1449
+ if (this.opts.enableHyperlinks !== !1) return (e) => this._onHyperlinkClick(e);
1450
+ }
1451
+ _onHyperlinkClick(e) {
1452
+ let t = this._resolveInternalSlideIndex(e);
1453
+ if (this.opts.onHyperlinkClick) {
1454
+ this.opts.onHyperlinkClick(t);
1455
+ return;
1456
+ }
1457
+ if (t.kind === "external") {
1458
+ _(t.url, void 0, this.hostWindow);
1459
+ return;
1460
+ }
1461
+ t.slideIndex !== void 0 && this.goToSlide(t.slideIndex).catch((e) => this._reportRenderError(e));
1462
+ }
1463
+ _resolveInternalSlideIndex(e) {
1464
+ if (e.kind !== "internal" || e.slideIndex !== void 0) return e;
1465
+ let t = this.engine?.resolveInternalTarget(e.ref, this.currentSlide);
1466
+ return t === void 0 ? e : {
1467
+ ...e,
1468
+ slideIndex: t
1469
+ };
1470
+ }
1471
+ _reportRenderError(e) {
1472
+ this.errorRouter.report(e);
1473
+ }
1474
+ async getResourceMetrics() {
1475
+ if (!this.engine) throw Error("Presentation not loaded");
1476
+ return await this.engine.getResourceMetrics();
1477
+ }
1478
+ getSelectionContext(e = {}) {
1479
+ if (this.destroyed) throw Error("PptxViewer is destroyed");
1480
+ return (this.textLayer ? Y(this.wrapper, this.wrapper.ownerDocument?.getSelection?.() ?? null, e) : null) ?? (this.elementContext ? gt(this.elementContext, e.maxTextCharacters) : null);
1481
+ }
1482
+ _emitSelectionContextChange() {
1483
+ let e = this.getSelectionContext();
1484
+ e?.kind === "text" && (this.elementHitGeneration++, this.elementContext = null, this._redrawElementOutline());
1485
+ let t = JSON.stringify(e);
1486
+ t !== this.selectionContextKey && (this.selectionContextKey = t, this.opts.onSelectionContextChange?.(e ? structuredClone(e) : null));
1487
+ }
1488
+ _setElementContext(e) {
1489
+ this.elementContext = e ? structuredClone(e) : null, this._redrawElementOutline(), this._emitSelectionContextChange();
1490
+ }
1491
+ _invalidateElementSelection(e = !0) {
1492
+ this.elementHitGeneration++, this.elementContext = null, this._redrawElementOutline(), e && this._emitSelectionContextChange();
1493
+ }
1494
+ _redrawElementOutline() {
1495
+ let e = this.elementContext, t = this.engine;
1496
+ if (!e || !t || e.slideIndex !== this.currentSlide) {
1497
+ E(this.elementLayer, null);
1498
+ return;
1499
+ }
1500
+ E(this.elementLayer, {
1501
+ x: e.bounds.x / t.slideWidth,
1502
+ y: e.bounds.y / t.slideHeight,
1503
+ width: e.bounds.width / t.slideWidth,
1504
+ height: e.bounds.height / t.slideHeight,
1505
+ rotation: e.bounds.rotation
1506
+ });
1507
+ }
1508
+ async _onElementClick(e) {
1509
+ this.destroyed || e.defaultPrevented || e.button !== 0 || await this._resolveContextAt(e);
1510
+ }
1511
+ _onContextMenu(e) {
1512
+ let t;
1513
+ this.opts.onContextMenu?.({
1514
+ originalEvent: e,
1515
+ getContext: () => t ??= this._resolveContextAt(e)
1516
+ });
1517
+ }
1518
+ async _resolveContextAt(e) {
1519
+ let t = this.engine;
1520
+ if (this.destroyed || !t) return null;
1521
+ if (this.textLayer && Y(this.wrapper, this.wrapper.ownerDocument?.getSelection?.() ?? null)) return this._emitSelectionContextChange(), this.destroyed ? null : this.getSelectionContext();
1522
+ if (!this.opts.enableElementSelection) return this.getSelectionContext();
1523
+ let n = this.canvas.getBoundingClientRect();
1524
+ if (n.width <= 0 || n.height <= 0) return this._invalidateElementSelection(), null;
1525
+ let r = e.clientX - n.left, i = e.clientY - n.top;
1526
+ if (r < 0 || i < 0 || r > n.width || i > n.height) return this._invalidateElementSelection(), null;
1527
+ let a = ++this.elementHitGeneration, o = this.currentSlide, s = {
1528
+ x: r / n.width * t.slideWidth,
1529
+ y: i / n.height * t.slideHeight
1530
+ }, c;
1531
+ try {
1532
+ c = await t.getElementContextAt(o, s, {
1533
+ tolerance: this.elementHitTolerance / n.width * t.slideWidth,
1534
+ maxTextCharacters: K
1535
+ });
1536
+ } catch (e) {
1537
+ if (this.destroyed || a !== this.elementHitGeneration || o !== this.currentSlide || t !== this.engine) return null;
1538
+ throw e;
1539
+ }
1540
+ return this.destroyed || a !== this.elementHitGeneration || o !== this.currentSlide || t !== this.engine ? null : (this._setElementContext(c), this.destroyed ? null : this.getSelectionContext());
1541
+ }
1542
+ destroy() {
1543
+ this.destroyed || (this.destroyed = !0, this.errorRouter.close(), this.renderDispatcher.destroy(), c(this.canvas), this.handle?.destroy(), this.handle = null, this.presentationOwner.close(), this._find.invalidate(), 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());
1544
+ }
1545
+ }, wt = 150, Tt = "0 1px 3px rgba(0,0,0,0.2)", Q = 12, Et;
1546
+ function Dt() {
1547
+ return Et ??= import("./comment-ui-runtime-BAe30Ct9.js");
1548
+ }
1549
+ var $ = 440, Ot = 20, kt = Symbol("PptxScrollViewer.borrowedPresentation"), At = class e {
1550
+ _presentationOwner;
1551
+ get _pres() {
1552
+ return this._presentationOwner.current;
1553
+ }
1554
+ _borrowed;
1555
+ _opts;
1556
+ _container;
1557
+ _wrapper;
1558
+ _scrollHost;
1559
+ _spacer;
1560
+ _mode;
1561
+ _scale = 1;
1562
+ _scaleEstablished = !1;
1563
+ _pendingScale = null;
1564
+ _slots = /* @__PURE__ */ new Map();
1565
+ _free = [];
1566
+ _uniformSlideHeight = 0;
1567
+ _lastRange = null;
1568
+ _lastTopIndex = -1;
1569
+ _scrollListener = null;
1570
+ _selectionChangeListener = null;
1571
+ _selectionContextKey = "null";
1572
+ _elementClickListener = null;
1573
+ _contextMenuListener = null;
1574
+ _commentOutsidePointerListener = null;
1575
+ _elementContext = null;
1576
+ _activeCommentId = null;
1577
+ _activeCommentSlide = null;
1578
+ _commentNavigationGeneration = 0;
1579
+ _commentUi = null;
1580
+ _commentGeometryScheduled = !1;
1581
+ _commentGeometryFrame = null;
1582
+ _pendingCommentGeometry = /* @__PURE__ */ new Map();
1583
+ _hasComments = !1;
1584
+ _elementHitGeneration = 0;
1585
+ _elementHitTolerance;
1586
+ _destroyed = !1;
1587
+ _slideInFlight = /* @__PURE__ */ new Set();
1588
+ _renderEpoch = 0;
1589
+ _settleTimer = null;
1590
+ _wheelListener = null;
1591
+ _pendingZoomAnchor = null;
1592
+ _resizeObserver = null;
1593
+ _prevBase = 0;
1594
+ _lastFitWidth = 0;
1595
+ _pageShadow;
1596
+ _find = new Re(() => this.slideCount, (e) => this._collectSlideRuns(e));
1597
+ _findActive = !1;
1598
+ _findMeasureCtx;
1599
+ static fromPresentation(t, n, r = {}) {
1600
+ return new e(t, {
1601
+ ...r,
1602
+ [kt]: n
1603
+ });
1604
+ }
1605
+ constructor(e, t = {}) {
1606
+ 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.");
1607
+ this._container = e, this._opts = t;
1608
+ let n = t.elementHitTolerance ?? 6;
1609
+ if (!Number.isFinite(n) || n < 0) throw RangeError("elementHitTolerance must be a finite non-negative number.");
1610
+ this._elementHitTolerance = n, this._pageShadow = t.pageShadow ?? Tt;
1611
+ let r = t[kt];
1612
+ this._borrowed = r !== void 0, r ? (this._presentationOwner = new T("PptxScrollViewer", r, !1), this._mode = O("PptxScrollViewer", t.mode, r), this._hasComments = (t.comments === !0 || typeof t.comments == "object") && this._presentationHasComments(r)) : (this._presentationOwner = new T("PptxScrollViewer"), this._mode = O("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() && Dt().then((e) => {
1613
+ if (!this._destroyed) {
1614
+ this._commentUi = e;
1615
+ for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
1616
+ }
1617
+ }).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) => {
1618
+ this._onElementClick(e).catch((e) => this._reportRenderError(e));
1619
+ }, 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) => {
1620
+ if (!Ne(e, this._wrapper, "ooxmlCommentId") && this._activeCommentId !== null) {
1621
+ this._activeCommentId = null, this._activeCommentSlide = null;
1622
+ for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
1623
+ this._emitSelectionContextChange();
1624
+ }
1625
+ }, this._wrapper.ownerDocument.addEventListener("pointerdown", this._commentOutsidePointerListener)), this._opts.enableZoom !== !1 && (this._wheelListener = (e) => {
1626
+ if (!(e.ctrlKey || e.metaKey) || (e.preventDefault(), e.deltaY === 0)) return;
1627
+ let t = this._scrollHost.getBoundingClientRect(), n = e.clientX - t.left, r = e.clientY - t.top;
1628
+ this._pendingZoomAnchor = Number.isFinite(n) && Number.isFinite(r) ? {
1629
+ x: n,
1630
+ y: r
1631
+ } : null, this.setScale(ve(this._scale, e.deltaY));
1632
+ }, 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.relayout();
1633
+ }
1634
+ async load(e) {
1635
+ if (this._destroyed) throw Error("PptxScrollViewer is destroyed");
1636
+ if (this._borrowed) throw Error("PptxScrollViewer.load() is unsupported on a Viewer created by fromPresentation(); the borrowed presentation is already loaded.");
1637
+ let t = !1;
1638
+ try {
1639
+ let n = await this._presentationOwner.replace(() => q.load(e, {
1640
+ password: this._opts.password,
1641
+ useGoogleFonts: this._opts.useGoogleFonts,
1642
+ maxZipEntryBytes: this._opts.maxZipEntryBytes,
1643
+ resourceLimits: this._opts.resourceLimits,
1644
+ debug: this._opts.debug,
1645
+ onResourceMetrics: this._opts.onResourceMetrics,
1646
+ workerTimeoutMs: this._opts.workerTimeoutMs,
1647
+ wasmUrl: this._opts.wasmUrl,
1648
+ math: this._opts.math,
1649
+ threeD: this._opts.threeD,
1650
+ regionMap: this._opts.regionMap,
1651
+ chartEx: this._opts.chartEx,
1652
+ mode: this._mode
1653
+ }), (e) => {
1654
+ if (this._invalidateElementSelection(!1), t = !0, this._find.invalidate(), this._findActive = !1, this._activeCommentId = null, this._activeCommentSlide = null, this._hasComments = !1, e) {
1655
+ for (let [e, t] of [...this._slots]) this._recycleSlot(e, t);
1656
+ this._lastTopIndex = -1;
1657
+ }
1658
+ });
1659
+ if (!n) return;
1660
+ if (this._destroyed) throw Error("PptxScrollViewer is destroyed");
1661
+ this._find.invalidate(), this._findActive = !1, this._activeCommentId = null, this._activeCommentSlide = null, this._hasComments = this._commentsEnabled() && this._presentationHasComments(n);
1662
+ let r = [];
1663
+ this._relayout(r), await Promise.all(r);
1664
+ } catch (e) {
1665
+ throw this._destroyed ? Error("PptxScrollViewer is destroyed") : e instanceof Error ? e : Error(String(e));
1666
+ }
1667
+ t && !this._destroyed && this._emitSelectionContextChange();
1668
+ }
1669
+ get slideCount() {
1670
+ return this._pres?.slideCount ?? 0;
1671
+ }
1672
+ _slideWidthPx() {
1673
+ return this._pres.slideWidth / k * this._scale;
1674
+ }
1675
+ _slideHeightPx() {
1676
+ return this._pres.slideHeight / k * this._scale;
1677
+ }
1678
+ _fitWidthPx() {
1679
+ if (this._opts.width && this._opts.width > 0) return this._opts.width;
1680
+ let e = this._scrollHost.clientWidth || this._container.clientWidth;
1681
+ if (e <= 0) return 0;
1682
+ let { left: t, right: n } = this._padH(), r = e - t - n;
1683
+ if (r <= 0) return 0;
1684
+ let i = this._pres ? this._pres.slideWidth / k : 0, a = this._hasCommentMargin() && i > 0 ? r * i / (i + Q + $) : r;
1685
+ return a > 0 ? a : 0;
1686
+ }
1687
+ _commentMarginExtent() {
1688
+ return this._hasCommentMargin() ? (Q + $) * this._commentZoom() : 0;
1689
+ }
1690
+ _hasCommentMargin() {
1691
+ return this._commentsEnabled() && this._hasComments && this._commentsOptions()?.cards !== !1;
1692
+ }
1693
+ _commentZoom() {
1694
+ return this._scaleEstablished ? this._scale : 1;
1695
+ }
1696
+ _commentsEnabled() {
1697
+ return this._opts.comments === !0 || typeof this._opts.comments == "object";
1698
+ }
1699
+ _commentsOptions() {
1700
+ return typeof this._opts.comments == "object" ? this._opts.comments : void 0;
1701
+ }
1702
+ _commentSide() {
1703
+ let e = this._commentsOptions()?.side;
1704
+ return e === "left" || e === "right" ? e : (this._container.ownerDocument.defaultView?.getComputedStyle?.(this._container).direction || this._container.dir || this._container.style.direction) === "rtl" ? "left" : "right";
1705
+ }
1706
+ _syncCommentMarginGeometry(e) {
1707
+ if (!e) return;
1708
+ let t = this._commentZoom(), n = `calc(100% + ${Q * t}px)`;
1709
+ e.style.left = this._commentSide() === "right" ? n : "", e.style.right = this._commentSide() === "left" ? n : "", e.style.width = `${$ * t}px`, e.style.fontSize = `${Ot}px`, e.dataset.ooxmlCommentZoom = String(t);
1710
+ }
1711
+ _presentationHasComments(e) {
1712
+ let t = this._commentsOptions()?.includeResolved === !0;
1713
+ for (let n = 0; n < e.slideCount; n++) if (e.getComments(n).some((e) => t || e.status !== "resolved" && e.status !== "closed")) return !0;
1714
+ return !1;
1715
+ }
1716
+ _baseScale() {
1717
+ if (!this._pres || this._pres.slideCount === 0) return 0;
1718
+ let e = this._fitWidthPx(), t = this._pres.slideWidth / k;
1719
+ return e <= 0 || t <= 0 ? 0 : e / t;
1720
+ }
1721
+ relayout() {
1722
+ this._relayout();
1723
+ }
1724
+ _relayout(e) {
1725
+ if (this._pres) {
1726
+ if (!this._scaleEstablished) {
1727
+ let e = this._baseScale();
1728
+ if (e > 0) {
1729
+ if (this._scale = e, this._prevBase = e, this._lastFitWidth = this._fitWidthPx(), this._scaleEstablished = !0, this._pendingScale !== null) {
1730
+ let e = this._pendingScale;
1731
+ this._pendingScale = null, e !== this._scale && (this._scale = e, this._opts.onScaleChange?.(e));
1732
+ }
1733
+ } else return;
1734
+ }
1735
+ this._recomputeHeights(), this._syncSpacer(), this._mountVisible(e);
1736
+ }
1737
+ }
1738
+ _recomputeHeights() {
1739
+ this._uniformSlideHeight = this._slideHeightPx();
1740
+ }
1741
+ _gap() {
1742
+ return this._opts.gap ?? 16;
1743
+ }
1744
+ _overscan() {
1745
+ return this._opts.overscan ?? 1;
1746
+ }
1747
+ _mediaOverscan() {
1748
+ return this._opts.mediaOverscan ?? 1;
1749
+ }
1750
+ _pad() {
1751
+ let e = this._gap();
1752
+ return {
1753
+ leading: this._opts.paddingTop ?? e,
1754
+ trailing: this._opts.paddingBottom ?? e
1755
+ };
1756
+ }
1757
+ _padH() {
1758
+ let e = this._gap();
1759
+ return {
1760
+ left: this._opts.paddingLeft ?? e,
1761
+ right: this._opts.paddingRight ?? e
1762
+ };
1763
+ }
1764
+ _slideOffset(e) {
1765
+ return this._pad().leading + e * (this._uniformSlideHeight + this._gap());
1766
+ }
1767
+ _slideIndexAtOffset(e) {
1768
+ return Me(this._pres?.slideCount ?? 0, this._uniformSlideHeight, this._gap(), e, 0, 0, this._pad()).topIndex;
1769
+ }
1770
+ _rangeAt(e, t) {
1771
+ return Me(this._pres?.slideCount ?? 0, this._uniformSlideHeight, this._gap(), e, this._scrollHost.clientHeight, t, this._pad());
1772
+ }
1773
+ _range() {
1774
+ return this._rangeAt(this._scrollHost.scrollTop, this._overscan());
1775
+ }
1776
+ _mediaRange() {
1777
+ return this._rangeAt(this._scrollHost.scrollTop, this._mediaOverscan());
1778
+ }
1779
+ _rangeContains(e, t) {
1780
+ return t >= e.start && t <= e.end;
1781
+ }
1782
+ _syncSpacer() {
1783
+ let e = this._range();
1784
+ this._lastRange = e, this._spacer.style.height = `${e.totalHeight}px`, this._syncSpacerWidth();
1785
+ }
1786
+ _syncSpacerWidth() {
1787
+ let { left: e, right: t } = this._padH();
1788
+ this._spacer.style.width = `${this._slideWidthPx() + this._commentMarginExtent() + e + t}px`;
1789
+ }
1790
+ _onScroll() {
1791
+ !this._pres || !this._scaleEstablished || this._mountVisible(void 0, !1);
1792
+ }
1793
+ _mountVisible(e, t = !0) {
1794
+ if (!this._pres || this._pres.slideCount === 0) return;
1795
+ let n = this._range(), r = this._opts.enableMediaPlayback ? this._mediaRange() : null;
1796
+ this._lastRange = n;
1797
+ for (let [e, t] of [...this._slots]) (e < n.start || e > n.end) && this._recycleSlot(e, t);
1798
+ for (let i = n.start; i <= n.end; i++) if (this._slots.has(i)) t && this._positionSlot(this._slots.get(i), i, n);
1799
+ else {
1800
+ let t = this._acquireSlot();
1801
+ this._positionSlot(t, i, n), this._slots.set(i, t), this._redrawSlotComments(i, t);
1802
+ let a = this._renderSlot(i, t, !!r && this._rangeContains(r, i), e === void 0);
1803
+ e && a && e.push(a);
1804
+ }
1805
+ r && this._syncMediaPlayback(r), n.topIndex !== this._lastTopIndex && (this._lastTopIndex = n.topIndex, this._opts.onVisibleSlideChange?.(n.topIndex, this._pres.slideCount));
1806
+ }
1807
+ _applyPageShadow(e) {
1808
+ this._pageShadow !== !1 && (e.style.boxShadow = this._pageShadow);
1809
+ }
1810
+ _acquireSlot() {
1811
+ let e = this._free.pop();
1812
+ if (e) return this._scrollHost.appendChild(e.wrapper), e;
1813
+ let t = document.createElement("div");
1814
+ t.style.cssText = "position:absolute;";
1815
+ let n = document.createElement("canvas");
1816
+ n.style.cssText = "display:block;background:#fff;", this._applyPageShadow(n), t.appendChild(n);
1817
+ let r = null;
1818
+ 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));
1819
+ let i = document.createElement("div");
1820
+ i.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;overflow:hidden;pointer-events:none;", t.appendChild(i);
1821
+ let a = null, o = null, s = null;
1822
+ this._commentsEnabled() && this._hasComments && (a = document.createElement("div"), a.style.cssText = "position:absolute;inset:0;overflow:hidden;pointer-events:none;", t.appendChild(a), this._hasCommentMargin() && (o = document.createElement("div"), o.style.cssText = "position:absolute;top:0;height:100%;box-sizing:border-box;overflow-x:hidden;overflow-y:auto;pointer-events:auto;", this._syncCommentMarginGeometry(o), this._commentsOptions()?.connectors !== void 0 && (s = document.createElement("div"), s.style.cssText = "position:absolute;top:0;left:0;overflow:visible;pointer-events:none;", t.appendChild(s)), t.appendChild(o)));
1823
+ let c = de(t, this._opts.enableElementSelection === !0);
1824
+ return this._scrollHost.appendChild(t), {
1825
+ wrapper: t,
1826
+ canvas: n,
1827
+ textLayer: r,
1828
+ highlightLayer: i,
1829
+ elementLayer: c,
1830
+ commentMarkerLayer: a,
1831
+ commentMargin: o,
1832
+ commentDecorationLayer: s,
1833
+ commentElementBounds: Object.freeze([]),
1834
+ commentGeometry: null,
1835
+ commentAnchorSlide: -1,
1836
+ commentAnchorGeneration: 0,
1837
+ renderedSlide: -1,
1838
+ renderedScale: -1,
1839
+ dispatcher: new D(n, this._mode === "worker"),
1840
+ presentationHandle: null,
1841
+ mediaInteractive: !1,
1842
+ renderGeneration: 0,
1843
+ presentationGeneration: 0
1844
+ };
1845
+ }
1846
+ _recycleSlot(e, t) {
1847
+ 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 D(t.canvas, this._mode === "worker")), 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.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++, E(t.elementLayer, null), t.canvas.style.height = "", t.renderedSlide = -1, t.renderedScale = -1, t.wrapper.remove(), this._free.push(t);
1848
+ }
1849
+ _positionSlot(e, t, n) {
1850
+ e.wrapper.dataset.slideIndex = String(t), e.wrapper.style.top = `${this._slideOffset(t)}px`;
1851
+ let r = this._slideWidthPx();
1852
+ if (e.wrapper.style.width = `${r}px`, e.wrapper.style.height = `${this._slideHeightPx()}px`, this._syncCommentMarginGeometry(e.commentMargin), e.commentDecorationLayer) {
1853
+ let t = this._commentMarginExtent();
1854
+ e.commentDecorationLayer.style.left = this._commentSide() === "left" ? `${-t}px` : "0px", e.commentDecorationLayer.style.width = `${r + t}px`, e.commentDecorationLayer.style.height = `${this._slideHeightPx()}px`;
1855
+ }
1856
+ this._redrawElementOutlineForSlot(t, e);
1857
+ let { left: i } = this._padH(), a = this._scrollHost.clientWidth, o = this._commentMarginExtent(), s = r + o, c = Math.max(i, (a - s) / 2);
1858
+ e.wrapper.style.left = `${c + (this._commentSide() === "left" ? o : 0)}px`;
1859
+ }
1860
+ _dpr() {
1861
+ return this._opts.dpr ?? (typeof window < "u" && window.devicePixelRatio || 1);
1862
+ }
1863
+ _renderSlot(e, t, n = !1, r = !0) {
1864
+ if (!this._pres || t.renderedSlide === e) return null;
1865
+ t.renderedSlide = e;
1866
+ let i = ++t.renderGeneration, a = this._dpr(), o = this._slideWidthPx(), s = this._renderEpoch, c = this._scale, l = t.dispatcher, u = l.begin();
1867
+ if (this._opts.enableMediaPlayback && n) return t.mediaInteractive = !0, this._renderInteractiveSlot(e, t, o, a, c, s, r);
1868
+ if (t.mediaInteractive = !1, this._mode === "worker") return this._renderSlotBitmap(e, t, o, a, c, i, l, u, r);
1869
+ let d = [], f = !!this._opts.enableTextSelection && !!t.textLayer, p = f || this._findActive, m = p ? (e) => d.push(e) : void 0, h = t.canvas;
1870
+ return X(this._pres, h, e, "main", {
1871
+ width: o,
1872
+ dpr: a,
1873
+ onTextRun: m
1874
+ }).then(() => {
1875
+ 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 && N(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));
1876
+ }).catch((n) => {
1877
+ 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);
1878
+ else throw n;
1879
+ });
1880
+ }
1881
+ _renderInteractiveSlot(e, t, n, r, i, a, o = !0) {
1882
+ if (!this._pres) return Promise.resolve();
1883
+ let s = ++t.presentationGeneration;
1884
+ t.presentationHandle?.destroy(), t.presentationHandle = null;
1885
+ let c = [], l = !!this._opts.enableTextSelection && !!t.textLayer, u = l || this._findActive, d = u ? (e) => c.push(e) : void 0;
1886
+ return this._pres.presentSlide(t.canvas, e, {
1887
+ width: n,
1888
+ dpr: r,
1889
+ onTextRun: d,
1890
+ onError: (e) => {
1891
+ s === t.presentationGeneration && this._reportRenderError(e);
1892
+ }
1893
+ }).then((r) => {
1894
+ if (s !== t.presentationGeneration || !t.mediaInteractive || a !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e) {
1895
+ r.destroy();
1896
+ return;
1897
+ }
1898
+ t.presentationHandle = r, t.renderedScale = i, l && t.textLayer && N(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);
1899
+ }).catch((e) => {
1900
+ if (s === t.presentationGeneration) if (o) this._reportRenderError(e);
1901
+ else throw e;
1902
+ });
1903
+ }
1904
+ _syncMediaPlayback(e = this._mediaRange()) {
1905
+ if (this._opts.enableMediaPlayback) for (let [t, n] of this._slots) {
1906
+ let r = this._rangeContains(e, t);
1907
+ 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));
1908
+ }
1909
+ }
1910
+ _reportRenderError(e) {
1911
+ if (this._destroyed) return;
1912
+ let t = e instanceof Error ? e : Error(String(e));
1913
+ this._opts.onError ? this._opts.onError(t) : console.error("[ooxml] PptxScrollViewer render failed:", t);
1914
+ }
1915
+ async _renderSlotBitmap(e, t, n, r, i, a = ++t.renderGeneration, o = t.dispatcher, s = o.begin(), c = !0) {
1916
+ if (this._slideInFlight.has(e) || this._slots.get(e) !== t) return;
1917
+ let l = this._renderEpoch;
1918
+ this._slideInFlight.add(e);
1919
+ let u = t.canvas, d = !1, f = !!this._opts.enableTextSelection && !!t.textLayer, p = f || this._findActive, m = [];
1920
+ try {
1921
+ let c = await X(this._pres, u, e, "worker", {
1922
+ width: n,
1923
+ dpr: r,
1924
+ onTextRun: p ? (e) => m.push(e) : void 0
1925
+ });
1926
+ if (a !== t.renderGeneration || !o.isCurrent(s) || u !== t.canvas || l !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e) {
1927
+ c.close();
1928
+ return;
1929
+ }
1930
+ if (!o.commitBitmap(s, c, {
1931
+ cssWidth: Math.round(c.width / r),
1932
+ cssHeight: Math.round(c.height / r)
1933
+ })) return;
1934
+ t.renderedScale = i, t.textLayer && (t.textLayer.style.transform = "", t.textLayer.style.transformOrigin = "", f && N(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;
1935
+ } catch (n) {
1936
+ 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);
1937
+ else throw n;
1938
+ } finally {
1939
+ this._slideInFlight.delete(e);
1940
+ let n = this._slots.get(e);
1941
+ !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);
1942
+ }
1943
+ }
1944
+ setScale(e) {
1945
+ let t = this._opts.zoomMin ?? .1, n = this._opts.zoomMax ?? 4, r = Math.min(n, Math.max(t, e)), i = this._pendingZoomAnchor;
1946
+ if (this._pendingZoomAnchor = null, !this._pres || this._pres.slideCount === 0 || !this._scaleEstablished) {
1947
+ this._pendingScale = r;
1948
+ return;
1949
+ }
1950
+ if (r === this._scale) return;
1951
+ 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;
1952
+ d = Math.min(1, Math.max(0, d));
1953
+ let f = this._padH().left, p = this._scrollHost.scrollLeft || 0;
1954
+ this._renderEpoch++, this._scale = r, this._recomputeHeights();
1955
+ let m = this._rangeAt(0, this._overscan());
1956
+ this._spacer.style.height = `${m.totalHeight}px`, this._syncSpacerWidth();
1957
+ let h = Math.max(0, m.totalHeight - this._scrollHost.clientHeight), g = this._slideOffset(l) + d * this._uniformSlideHeight, _ = c < this._slideOffset(0) ? s : g - o;
1958
+ if (this._scrollHost.scrollTop = Math.min(h, Math.max(0, _)), i) {
1959
+ let e = Math.max(0, (this._spacer.offsetWidth || 0) - this._scrollHost.clientWidth);
1960
+ this._scrollHost.scrollLeft = ie(p, i.x - f, a, r, { maxScroll: e });
1961
+ }
1962
+ this._previewVisible(), this._scheduleSettle(), this._opts.onScaleChange?.(r);
1963
+ }
1964
+ getScale() {
1965
+ return this._scaleEstablished ? this._scale : this._pendingScale ?? 1;
1966
+ }
1967
+ zoomIn() {
1968
+ this.setScale(ge(this.getScale()));
1969
+ }
1970
+ zoomOut() {
1971
+ this.setScale(ye(this.getScale()));
1972
+ }
1973
+ fitWidth() {
1974
+ this._fit("width");
1975
+ }
1976
+ fitPage() {
1977
+ this._fit("page");
1978
+ }
1979
+ _fit(e) {
1980
+ if (!this._pres || this._pres.slideCount === 0) return;
1981
+ let t = re({
1982
+ contentWidth: this._pres.slideWidth / k,
1983
+ contentHeight: this._pres.slideHeight / k,
1984
+ containerWidth: this._fitWidthPx(),
1985
+ containerHeight: this._scrollHost.clientHeight
1986
+ }, e);
1987
+ t <= 0 || this.setScale(t);
1988
+ }
1989
+ _previewVisible() {
1990
+ if (!this._pres || this._pres.slideCount === 0) return;
1991
+ let e = this._range(), t = this._opts.enableMediaPlayback ? this._mediaRange() : null;
1992
+ this._lastRange = e;
1993
+ for (let [t, n] of [...this._slots]) (t < e.start || t > e.end) && this._recycleSlot(t, n);
1994
+ for (let n = e.start; n <= e.end; n++) {
1995
+ let r = this._slots.get(n);
1996
+ if (r) this._previewSlot(r, n, e);
1997
+ else {
1998
+ let r = this._acquireSlot();
1999
+ this._positionSlot(r, n, e), this._slots.set(n, r), this._redrawSlotComments(n, r), this._renderSlot(n, r, !!t && this._rangeContains(t, n));
2000
+ }
2001
+ }
2002
+ t && this._syncMediaPlayback(t), e.topIndex !== this._lastTopIndex && (this._lastTopIndex = e.topIndex, this._opts.onVisibleSlideChange?.(e.topIndex, this._pres.slideCount));
2003
+ }
2004
+ _previewSlot(e, t, n) {
2005
+ 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) {
2006
+ let t = this._scale / e.renderedScale;
2007
+ e.textLayer.style.transformOrigin = "0 0", e.textLayer.style.transform = `scale(${t})`;
2008
+ }
2009
+ if (e.renderedScale > 0) {
2010
+ let t = this._scale / e.renderedScale, n = Math.round(t * 1e6) / 1e6;
2011
+ e.commentMargin && this._commentUi?.previewReadOnlyCommentMargin(e.commentMargin, t);
2012
+ for (let t of e.commentMarkerLayer?.children ?? []) t.dataset.ooxmlCommentMarker !== void 0 && (t.style.transform = `translate(-50%,-50%) scale(${n})`);
2013
+ e.commentMarkerLayer && (e.commentMarkerLayer.style.visibility = ""), e.commentMargin && (e.commentMargin.style.visibility = ""), e.commentDecorationLayer && (e.commentDecorationLayer.style.visibility = "");
2014
+ return;
2015
+ }
2016
+ e.commentMarkerLayer && (e.commentMarkerLayer.style.visibility = "hidden"), e.commentMargin && (e.commentMargin.style.visibility = "hidden"), e.commentDecorationLayer && (e.commentDecorationLayer.style.visibility = "hidden");
2017
+ }
2018
+ _scheduleSettle() {
2019
+ this._settleTimer !== null && clearTimeout(this._settleTimer), this._settleTimer = setTimeout(() => {
2020
+ this._settleTimer = null, this._settleRender();
2021
+ }, wt);
2022
+ }
2023
+ _settleRender() {
2024
+ if (this._destroyed || !this._pres || this._pres.slideCount === 0) return;
2025
+ let e = this._opts.enableMediaPlayback ? this._mediaRange() : null;
2026
+ for (let [t, n] of [...this._slots]) e && !this._rangeContains(e, t) || n.renderedScale !== this._scale && this._settleSlot(t, n);
2027
+ }
2028
+ _settleSlot(e, t) {
2029
+ if (!this._pres) return;
2030
+ let n = this._dpr(), r = this._slideWidthPx(), i = this._scale, a = this._renderEpoch;
2031
+ if (this._opts.enableMediaPlayback && t.mediaInteractive) {
2032
+ this._settleInteractiveSlot(e, t, r, n, i, a);
2033
+ return;
2034
+ }
2035
+ if (this._opts.enableMediaPlayback) return;
2036
+ if (this._mode === "worker") {
2037
+ this._renderSlotBitmap(e, t, r, n, i);
2038
+ return;
2039
+ }
2040
+ let o = document.createElement("canvas"), s = ++t.renderGeneration;
2041
+ o.style.cssText = "display:block;background:#fff;", this._applyPageShadow(o);
2042
+ let c = new D(o, !1), l = c.begin(), u = [], d = !!this._opts.enableTextSelection && !!t.textLayer, f = d || this._findActive, p = f ? (e) => u.push(e) : void 0;
2043
+ X(this._pres, o, e, "main", {
2044
+ width: r,
2045
+ dpr: n,
2046
+ onTextRun: p
2047
+ }).then(() => {
2048
+ if (s !== t.renderGeneration || !c.isCurrent(l) || a !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e) {
2049
+ c.destroy();
2050
+ return;
2051
+ }
2052
+ let n = t.canvas;
2053
+ 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 && N(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);
2054
+ }).catch((n) => {
2055
+ s === t.renderGeneration && c.isCurrent(l) && a === this._renderEpoch && this._slots.get(e) === t && t.renderedSlide === e && this._reportRenderError(n), c.destroy();
2056
+ });
2057
+ }
2058
+ _settleInteractiveSlot(e, t, n, r, i, a) {
2059
+ if (!this._pres) return;
2060
+ let o = ++t.presentationGeneration, s = document.createElement("canvas");
2061
+ s.style.cssText = "display:block;background:#fff;", this._applyPageShadow(s);
2062
+ let c = [], l = !!this._opts.enableTextSelection && !!t.textLayer, u = l || this._findActive, d = u ? (e) => c.push(e) : void 0;
2063
+ this._pres.presentSlide(s, e, {
2064
+ width: n,
2065
+ dpr: r,
2066
+ onTextRun: d,
2067
+ onError: (e) => {
2068
+ o === t.presentationGeneration && this._reportRenderError(e);
2069
+ }
2070
+ }).then((r) => {
2071
+ if (o !== t.presentationGeneration || !t.mediaInteractive || a !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e) {
2072
+ r.destroy();
2073
+ return;
2074
+ }
2075
+ let d = t.canvas, f = t.presentationHandle;
2076
+ t.dispatcher.destroy(), t.wrapper.insertBefore(s, d), d.remove(), t.canvas = s, t.dispatcher = new D(s, !1), t.presentationHandle = r, t.renderedScale = i, f?.destroy(), t.textLayer && (t.textLayer.style.transform = "", t.textLayer.style.transformOrigin = "", l && N(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);
2077
+ }).catch((e) => {
2078
+ o === t.presentationGeneration && this._reportRenderError(e);
2079
+ });
2080
+ }
2081
+ scrollToSlide(e, t) {
2082
+ if (!this._pres || this._pres.slideCount === 0 || !this._scaleEstablished) return;
2083
+ 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;
2084
+ typeof s.scrollTo == "function" ? s.scrollTo({
2085
+ top: o,
2086
+ behavior: t?.behavior ?? "auto"
2087
+ }) : this._scrollHost.scrollTop = o, this._mountVisible();
2088
+ }
2089
+ _scrollToSlideCommentTarget(e, t, n, r) {
2090
+ if (!this._pres) return !1;
2091
+ let i = this._slots.get(e), a = new Map((i?.commentElementBounds ?? []).map((e) => [e.elementId, e.bounds])), o = r ?? (t.anchors ?? []).flatMap((e) => {
2092
+ if (e.type !== "drawingElement" && e.type !== "textRange" || !e.elementId) return [];
2093
+ let t = a.get(e.elementId);
2094
+ return t ? [t] : [];
2095
+ })[0], s = t.anchors ?? [], c = Number.isFinite(t.x) && Number.isFinite(t.y) && (s.length === 0 || s.some((e) => e.type === "slide"));
2096
+ if (!o && !c) return !1;
2097
+ 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(), f = this._commentMarginExtent(), { left: p } = this._padH(), m = Math.max(p, (this._scrollHost.clientWidth - d - f) / 2) + (this._commentSide() === "left" ? f : 0), h = this._rangeAt(0, this._overscan()), g = Math.max(0, h.totalHeight - this._scrollHost.clientHeight), _ = this._spacer.offsetWidth || Number.parseFloat(this._spacer.style.width) || 0, v = Math.max(0, _ - this._scrollHost.clientWidth), y = l / k * this._scale, b = u / k * this._scale, x = Math.min(g, Math.max(0, this._slideOffset(e) + b - this._scrollHost.clientHeight / 2)), S = Math.min(v, Math.max(0, m + y - this._scrollHost.clientWidth / 2)), C = this._scrollHost;
2098
+ return typeof C.scrollTo == "function" ? C.scrollTo({
2099
+ top: x,
2100
+ left: S,
2101
+ behavior: n?.behavior ?? "auto"
2102
+ }) : (this._scrollHost.scrollTop = x, this._scrollHost.scrollLeft = S), this._mountVisible(), !0;
2103
+ }
2104
+ async _resolveSlideCommentElementBounds(e, t) {
2105
+ let n = this._pres;
2106
+ if (!n) return;
2107
+ let r = (t.anchors ?? []).flatMap((e) => (e.type === "drawingElement" || e.type === "textRange") && e.elementId ? [e.elementId] : []);
2108
+ if (r.length === 0) return;
2109
+ let i = new Map((this._slots.get(e)?.commentElementBounds ?? []).map((e) => [e.elementId, e.bounds])), a = r.flatMap((e) => {
2110
+ let t = i.get(e);
2111
+ return t ? [t] : [];
2112
+ })[0];
2113
+ if (a) return a;
2114
+ let o = await n.getElementBoundsByIds(e, r);
2115
+ return r.flatMap((e) => {
2116
+ let t = o.find((t) => t.elementId === e);
2117
+ return t ? [t.bounds] : [];
2118
+ })[0];
2119
+ }
2120
+ async goToComment(e, t, n) {
2121
+ if (this._destroyed) throw Error("PptxScrollViewer is destroyed");
2122
+ let r = this._pres;
2123
+ if (!r || !Number.isInteger(e) || !Number.isInteger(t) || e < 0 || e >= r.slideCount) return !1;
2124
+ let i = r.getComments(e)[t];
2125
+ if (!i) return !1;
2126
+ let a = ++this._commentNavigationGeneration, o = await this._resolveSlideCommentElementBounds(e, i);
2127
+ if (this._destroyed) throw Error("PptxScrollViewer is destroyed");
2128
+ if (a !== this._commentNavigationGeneration || r !== this._pres) return !1;
2129
+ let s = i.anchors ?? [], c = Number.isFinite(i.x) && Number.isFinite(i.y) && (s.length === 0 || s.some((e) => e.type === "slide"));
2130
+ if (!o && !c || (this.scrollToSlide(e, n), !this._scrollToSlideCommentTarget(e, i, n, o))) return !1;
2131
+ this._activeCommentId = j(i, t, e), this._activeCommentSlide = e, this._elementContext = null;
2132
+ for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
2133
+ return this._emitSelectionContextChange(), !0;
2134
+ }
2135
+ async findText(e, t = {}) {
2136
+ if (!this._pres) return [];
2137
+ this._findActive = e.length > 0;
2138
+ let n = await this._find.find(e, t);
2139
+ return this._redrawHighlights(), n;
2140
+ }
2141
+ async findNext() {
2142
+ return this._activateMatch(this._find.next());
2143
+ }
2144
+ async findPrev() {
2145
+ return this._activateMatch(this._find.prev());
2146
+ }
2147
+ clearFind() {
2148
+ this._findActive = !1, this._find.invalidate(), this._redrawHighlights();
2149
+ }
2150
+ async _activateMatch(e) {
2151
+ return e && this.scrollToSlide(e.location.slide), this._redrawHighlights(), e;
2152
+ }
2153
+ async _collectSlideRuns(e) {
2154
+ return this._pres ? this._pres.collectSlideRuns(e, this._slideWidthPx()) : [];
2155
+ }
2156
+ _redrawHighlights() {
2157
+ for (let [e, t] of this._slots) this._redrawSlotHighlights(e, t);
2158
+ }
2159
+ _refreshFindRuns(e, t) {
2160
+ this._findActive && this._find.setSlideRuns(e, t);
2161
+ }
2162
+ _redrawSlotComments(e, t) {
2163
+ if (!this._pres || !t.commentMarkerLayer) return;
2164
+ let n = this._commentUi;
2165
+ if (!n) {
2166
+ t.commentMarkerLayer.replaceChildren(), t.commentMargin?.replaceChildren(), t.commentDecorationLayer?.replaceChildren(), t.commentGeometry = null;
2167
+ return;
2168
+ }
2169
+ 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) => {
2170
+ let r = n ? t : this._activeCommentId === t ? null : this._activeCommentId;
2171
+ if (r !== this._activeCommentId) {
2172
+ this._activeCommentId = r, this._activeCommentSlide = r ? e : null, this._elementContext = null;
2173
+ for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
2174
+ this._emitSelectionContextChange();
2175
+ }
2176
+ }, 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);
2177
+ }
2178
+ _redrawSlotCommentConnectors(e, t) {
2179
+ let n = t.commentDecorationLayer, r = t.commentMargin, i = t.commentGeometry, a = this._commentsOptions()?.connectors;
2180
+ if (!n || !r || !i || !a) return;
2181
+ let o = this._slideWidthPx(), s = this._slideHeightPx(), c = this._commentSide(), l = this._commentMarginExtent(), u = this._commentUi;
2182
+ u && u.buildReadOnlyCommentDecoration(n, Object.freeze({
2183
+ surfaceBounds: Object.freeze({
2184
+ x: c === "left" ? -l : 0,
2185
+ y: 0,
2186
+ width: o + l,
2187
+ height: s
2188
+ }),
2189
+ contentBounds: Object.freeze({
2190
+ x: 0,
2191
+ y: 0,
2192
+ width: o,
2193
+ height: s
2194
+ }),
2195
+ side: c,
2196
+ threads: u.projectReadOnlyCommentMarginScroll(i, r.scrollTop)
2197
+ }), {
2198
+ route: a.route ?? "bezier",
2199
+ stroke: a.stroke ?? "solid",
2200
+ color: a.color,
2201
+ activeColor: a.activeColor
2202
+ });
2203
+ }
2204
+ _commitSlotComments(e, t) {
2205
+ 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 = "");
2206
+ }
2207
+ _ensureSlotCommentAnchors(e, t) {
2208
+ let n = this._pres;
2209
+ if (!n || t.commentAnchorSlide === e) return;
2210
+ t.commentAnchorSlide = e, t.commentElementBounds = Object.freeze([]);
2211
+ let r = [...new Set(n.getComments(e).flatMap((e) => (e.anchors ?? []).flatMap((e) => (e.type === "drawingElement" || e.type === "textRange") && e.elementId ? [e.elementId] : [])))];
2212
+ if (r.length === 0) return;
2213
+ let i = ++t.commentAnchorGeneration;
2214
+ n.getElementBoundsByIds(e, r).then((r) => {
2215
+ if (this._destroyed || i !== t.commentAnchorGeneration || n !== this._pres || this._slots.get(e) !== t || t.commentAnchorSlide !== e) return;
2216
+ t.commentElementBounds = r, this._redrawSlotComments(e, t);
2217
+ let a = n.getComments(e).find((t, n) => j(t, n, e) === this._activeCommentId);
2218
+ a && this._scrollToSlideCommentTarget(e, a);
2219
+ }).catch((e) => {
2220
+ !this._destroyed && i === t.commentAnchorGeneration && this._reportRenderError(e);
2221
+ });
2222
+ }
2223
+ _scheduleCommentGeometry(e, t, n = !1) {
2224
+ let r = this._pendingCommentGeometry.get(e);
2225
+ if (this._pendingCommentGeometry.set(e, {
2226
+ slot: t,
2227
+ connectorsOnly: r?.slot === t ? r.connectorsOnly && n : n
2228
+ }), this._commentGeometryScheduled) return;
2229
+ this._commentGeometryScheduled = !0;
2230
+ let i = () => {
2231
+ this._commentGeometryScheduled = !1, this._commentGeometryFrame = null;
2232
+ let e = [...this._pendingCommentGeometry];
2233
+ if (this._pendingCommentGeometry.clear(), !this._destroyed) for (let [t, n] of e) {
2234
+ let { slot: e, connectorsOnly: r } = n;
2235
+ this._slots.get(t) === e && e.renderedScale === this._scale && (r ? this._redrawSlotCommentConnectors(t, e) : this._redrawSlotComments(t, e));
2236
+ }
2237
+ }, a = this._wrapper.ownerDocument.defaultView;
2238
+ a?.requestAnimationFrame ? this._commentGeometryFrame = a.requestAnimationFrame(i) : queueMicrotask(i);
2239
+ }
2240
+ _redrawSlotHighlights(e, t) {
2241
+ if (!this._findActive) {
2242
+ t.highlightLayer.innerHTML = "";
2243
+ return;
2244
+ }
2245
+ let n = this._find.slideRuns(e);
2246
+ if (!n) {
2247
+ t.highlightLayer.innerHTML = "";
2248
+ return;
2249
+ }
2250
+ P(t.highlightLayer, n, this._find.slideHighlights(e), this._slideWidthPx(), this._slideHeightPx(), (e) => this._measureForFind(e), this._opts.findHighlightColors);
2251
+ }
2252
+ _measureForFind(e) {
2253
+ this._findMeasureCtx === void 0 && (this._findMeasureCtx = document.createElement("canvas").getContext("2d"));
2254
+ let t = this._findMeasureCtx;
2255
+ return !t || typeof t.measureText != "function" ? (e) => e.length : (t.font = e, (e) => t.measureText(e).width);
2256
+ }
2257
+ _hyperlinkHandler() {
2258
+ if (this._opts.enableHyperlinks !== !1) return (e) => this._onHyperlinkClick(e);
2259
+ }
2260
+ _onHyperlinkClick(e) {
2261
+ let t = this._resolveInternalSlideIndex(e);
2262
+ if (this._opts.onHyperlinkClick) {
2263
+ this._opts.onHyperlinkClick(t);
2264
+ return;
2265
+ }
2266
+ if (t.kind === "external") {
2267
+ _(t.url);
2268
+ return;
2269
+ }
2270
+ t.slideIndex !== void 0 && this.scrollToSlide(t.slideIndex);
2271
+ }
2272
+ _resolveInternalSlideIndex(e) {
2273
+ if (e.kind !== "internal" || e.slideIndex !== void 0) return e;
2274
+ let t = this._pres?.resolveInternalTarget(e.ref, this._range().topIndex);
2275
+ return t === void 0 ? e : {
2276
+ ...e,
2277
+ slideIndex: t
2278
+ };
2279
+ }
2280
+ _onResize() {
2281
+ if (!this._pres || this._pres.slideCount === 0) return;
2282
+ if (!this._scaleEstablished) {
2283
+ this.relayout();
2284
+ return;
2285
+ }
2286
+ if (this._opts.refitOnResize === !1) {
2287
+ this._lastFitWidth = this._fitWidthPx(), this._mountVisible();
2288
+ return;
2289
+ }
2290
+ let e = this._baseScale();
2291
+ if (e <= 0) return;
2292
+ let t = this._fitWidthPx();
2293
+ if (t === this._lastFitWidth) {
2294
+ this._mountVisible();
2295
+ return;
2296
+ }
2297
+ this._lastFitWidth = t;
2298
+ let n = this._prevBase > 0 ? this._scale / this._prevBase : 1;
2299
+ this._prevBase = e, this.setScale(e * n), this._mountVisible();
2300
+ }
2301
+ get topVisibleSlide() {
2302
+ return this._lastRange?.topIndex ?? 0;
2303
+ }
2304
+ mountedSlideIndicesForTest() {
2305
+ return [...this._slots.keys()];
2306
+ }
2307
+ interactiveSlideIndicesForTest() {
2308
+ return [...this._slots].filter(([, e]) => e.mediaInteractive).map(([e]) => e);
2309
+ }
2310
+ scaleForTest() {
2311
+ return this._scale;
2312
+ }
2313
+ baseScaleForTest() {
2314
+ return this._baseScale();
2315
+ }
2316
+ renderEpochForTest() {
2317
+ return this._renderEpoch;
2318
+ }
2319
+ resizeForTest() {
2320
+ this._onResize();
2321
+ }
2322
+ contentAtViewportYForTest(e) {
2323
+ let t = this._scrollHost.scrollTop + e, n = this._slideIndexAtOffset(t), r = this._uniformSlideHeight;
2324
+ return {
2325
+ slide: n,
2326
+ frac: r > 0 ? Math.min(1, Math.max(0, (t - this._slideOffset(n)) / r)) : 0
2327
+ };
2328
+ }
2329
+ viewportYOfForTest(e, t) {
2330
+ return this._slideOffset(e) + t * this._uniformSlideHeight - this._scrollHost.scrollTop;
2331
+ }
2332
+ async getResourceMetrics() {
2333
+ if (!this._pres) throw Error("Presentation not loaded");
2334
+ return await this._pres.getResourceMetrics();
2335
+ }
2336
+ getSelectionContext(e = {}) {
2337
+ if (this._destroyed) throw Error("PptxScrollViewer is destroyed");
2338
+ if (this._pres && this._activeCommentId !== null && this._activeCommentSlide !== null) {
2339
+ let t = this._pres.getComments(this._activeCommentSlide), n = t.findIndex((e, t) => j(e, t, this._activeCommentSlide) === this._activeCommentId), r = t[n];
2340
+ if (r && n >= 0) return bt(r, this._activeCommentSlide, n, this._activeCommentId, e);
2341
+ }
2342
+ return (this._opts.enableTextSelection ? Y(this._wrapper, this._wrapper.ownerDocument?.getSelection?.() ?? null, e) : null) ?? (this._elementContext ? gt(this._elementContext, e.maxTextCharacters) : null);
2343
+ }
2344
+ _emitSelectionContextChange() {
2345
+ let e = this.getSelectionContext();
2346
+ e?.kind === "text" && (this._elementHitGeneration++, this._elementContext = null, this._redrawElementOutlines());
2347
+ let t = JSON.stringify(e);
2348
+ t !== this._selectionContextKey && (this._selectionContextKey = t, this._opts.onSelectionContextChange?.(e ? structuredClone(e) : null));
2349
+ }
2350
+ _setElementContext(e) {
2351
+ this._elementContext = e ? structuredClone(e) : null, this._redrawElementOutlines(), this._emitSelectionContextChange();
2352
+ }
2353
+ _invalidateElementSelection(e = !0) {
2354
+ this._elementHitGeneration++, this._elementContext = null, this._redrawElementOutlines(), e && this._emitSelectionContextChange();
2355
+ }
2356
+ _redrawElementOutlines() {
2357
+ for (let [e, t] of this._slots) this._redrawElementOutlineForSlot(e, t);
2358
+ }
2359
+ _redrawElementOutlineForSlot(e, t) {
2360
+ let n = this._elementContext, r = this._pres;
2361
+ if (!n || !r || n.slideIndex !== e) {
2362
+ E(t.elementLayer, null);
2363
+ return;
2364
+ }
2365
+ E(t.elementLayer, {
2366
+ x: n.bounds.x / r.slideWidth,
2367
+ y: n.bounds.y / r.slideHeight,
2368
+ width: n.bounds.width / r.slideWidth,
2369
+ height: n.bounds.height / r.slideHeight,
2370
+ rotation: n.bounds.rotation
2371
+ });
2372
+ }
2373
+ async _onElementClick(e) {
2374
+ this._destroyed || e.defaultPrevented || e.button !== 0 || await this._resolveContextAt(e);
2375
+ }
2376
+ _onContextMenu(e) {
2377
+ let t;
2378
+ this._opts.onContextMenu?.({
2379
+ originalEvent: e,
2380
+ getContext: () => t ??= this._resolveContextAt(e)
2381
+ });
2382
+ }
2383
+ async _resolveContextAt(e) {
2384
+ let t = this._pres;
2385
+ if (this._destroyed || !t) return null;
2386
+ if (this._opts.enableTextSelection && Y(this._wrapper, this._wrapper.ownerDocument?.getSelection?.() ?? null)) return this._emitSelectionContextChange(), this._destroyed ? null : this.getSelectionContext();
2387
+ if (!this._opts.enableElementSelection) return this.getSelectionContext();
2388
+ let n = e.target, r = [...this._slots].find(([, e]) => n !== null && e.wrapper.contains(n));
2389
+ if (!r) return this._invalidateElementSelection(), null;
2390
+ let [i, a] = r, o = a.canvas.getBoundingClientRect();
2391
+ if (o.width <= 0 || o.height <= 0) return this._invalidateElementSelection(), null;
2392
+ let s = e.clientX - o.left, c = e.clientY - o.top;
2393
+ if (s < 0 || c < 0 || s > o.width || c > o.height) return this._invalidateElementSelection(), null;
2394
+ let l = ++this._elementHitGeneration, u = {
2395
+ x: s / o.width * t.slideWidth,
2396
+ y: c / o.height * t.slideHeight
2397
+ }, d;
2398
+ try {
2399
+ d = await t.getElementContextAt(i, u, {
2400
+ tolerance: this._elementHitTolerance / o.width * t.slideWidth,
2401
+ maxTextCharacters: K
2402
+ });
2403
+ } catch (e) {
2404
+ if (this._destroyed || l !== this._elementHitGeneration || t !== this._pres) return null;
2405
+ throw e;
2406
+ }
2407
+ return this._destroyed || l !== this._elementHitGeneration || t !== this._pres ? null : (this._setElementContext(d), this._destroyed ? null : this.getSelectionContext());
2408
+ }
2409
+ destroy() {
2410
+ if (!this._destroyed) {
2411
+ this._destroyed = !0, this._find.invalidate(), this._findActive = !1, 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);
2412
+ for (let [e, t] of [...this._slots]) this._recycleSlot(e, t);
2413
+ this._free.length = 0, this._presentationOwner.close(), this._wrapper.remove();
2414
+ }
2415
+ }
2416
+ }, jt = /* @__PURE__ */ e({
2417
+ OoxmlDecodedImageLimitError: () => we,
2418
+ OoxmlError: () => m,
2419
+ OoxmlResourceLimitError: () => g,
2420
+ PptxPresentation: () => q,
2421
+ PptxScrollViewer: () => At,
2422
+ PptxViewer: () => Ct,
2423
+ autoResize: () => _e,
2424
+ buildPptxHighlightLayer: () => P,
2425
+ buildPptxTextLayer: () => N,
2426
+ isOoxmlDecodedImageLimitError: () => Te,
2427
+ openExternalHyperlink: () => _,
2428
+ readPptxTextSelectionContext: () => Y,
2429
+ renderSlide: () => n
2430
+ });
2431
+ //#endregion
2432
+ export { q as a, Y as i, At as n, P as o, Ct as r, N as s, jt as t };