@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
@@ -1,2134 +0,0 @@
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-m2blvngt.js";
3
- import { B as u, G as d, Ot as f, R as p, Rt as m, a as h, at as g, cn as _, ht as v, it as y, jt as b, ln as x, mt as S, q as C, z as w, zt as ee } from "./line-metrics-DdEJYxjx.js";
4
- import { C as te, E as ne, S as re, T as ie, _ as T, a as E, b as ae, c as D, d as oe, f as se, g as ce, h as le, i as O, l as k, m as ue, n as de, o as fe, p as pe, r as me, s as he, t as ge, v as A, w as _e, x as ve, y as j } from "./canvas-viewer-mechanics-D-r6wHY_.js";
5
- import { a as ye, i as be, n as xe, t as Se } from "./bounded-raw-part-cache-C6ro6Ezf.js";
6
- import { M } from "./three-d-C28kqDym.js";
7
- import { n as Ce } from "./resource-measurement-CgMubiAI.js";
8
- import { n as we } from "./renderer-module-contract-BNGz8HvO.js";
9
- import { n as Te, r as N, t as Ee } from "./visible-index-BjesVGhg.js";
10
- import { n as De, r as P, t as F } from "./highlight-rect-BuX5rWP4.js";
11
- //#region packages/core/src/nav/internal-target.ts
12
- function Oe(e, t) {
13
- let n = t.startsWith("/") ? [] : e.split("/").filter((e) => e !== "");
14
- for (let e of t.split("/")) if (e === "..") n.pop();
15
- else if (e === "." || e === "") continue;
16
- else n.push(e);
17
- return n.join("/");
18
- }
19
- function ke(e) {
20
- let t = /[?&]jump=([a-zA-Z]+)/.exec(e);
21
- if (!t) return null;
22
- let n = t[1].toLowerCase();
23
- return n === "firstslide" || n === "lastslide" || n === "nextslide" || n === "previousslide" ? n : null;
24
- }
25
- function Ae(e, t, n) {
26
- if (!(n <= 0)) switch (e) {
27
- case "firstslide": return 0;
28
- case "lastslide": return n - 1;
29
- case "nextslide": return Math.min(t + 1, n - 1);
30
- case "previousslide": return Math.max(t - 1, 0);
31
- }
32
- }
33
- //#endregion
34
- //#region packages/pptx/src/text-layer.ts
35
- function I(e, t, n) {
36
- 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);
37
- }
38
- function L(e, t, n, r, i, a) {
39
- e.innerHTML = "", I(e, "ooxmlSelectionSurface", "pptx"), I(e, "slideIndex", a === void 0 ? void 0 : String(a));
40
- let o = /* @__PURE__ */ new Map(), s = e.ownerDocument ?? document;
41
- for (let [a, c] of t.entries()) {
42
- let t = c.rotation + (c.textBodyRotation ?? 0), l = `${c.shapeX},${c.shapeY},${c.shapeW},${c.shapeH},${t}`;
43
- if (!o.has(l)) {
44
- let i = s.createElement("div");
45
- i.style.cssText = `position:absolute;left:${F(c.shapeX, n)};top:${F(c.shapeY, r)};width:${F(c.shapeW, n)};height:${F(c.shapeH, r)};pointer-events:all;overflow:hidden;`, t !== 0 && (i.style.transformOrigin = "center center", i.style.transform = `rotate(${t}deg)`), o.set(l, {
46
- div: i,
47
- x: c.shapeX,
48
- y: c.shapeY,
49
- w: c.shapeW,
50
- h: c.shapeH,
51
- rot: t
52
- }), e.appendChild(i);
53
- }
54
- let u = o.get(l), d = s.createElement("span");
55
- I(d, "ooxmlSelectionRun", "pptx"), I(d, "runIndex", String(a)), c.shapeId !== void 0 && I(d, "shapeId", c.shapeId), c.elementIndex !== void 0 && I(d, "elementIndex", String(c.elementIndex)), c.origin !== void 0 && I(d, "elementOrigin", c.origin), d.textContent = c.text;
56
- let f = i ? c.hyperlink : void 0;
57
- d.style.cssText = `position:absolute;left:${F(c.inShapeX, u.w)};top:${F(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) => {
58
- e.preventDefault(), i(f);
59
- })), u.div.appendChild(d);
60
- }
61
- }
62
- function R(e, t, n, r, i, a, o = {}) {
63
- e.innerHTML = "";
64
- 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) => {
65
- let n = t.rotation + (t.textBodyRotation ?? 0), a = `${t.shapeX},${t.shapeY},${t.shapeW},${t.shapeH},${n}`, o = l.get(a);
66
- if (!o) {
67
- let s = document.createElement("div");
68
- s.style.cssText = `position:absolute;left:${F(t.shapeX, r)};top:${F(t.shapeY, i)};width:${F(t.shapeW, r)};height:${F(t.shapeH, i)};pointer-events:none;overflow:hidden;`, n !== 0 && (s.style.transformOrigin = "center center", s.style.transform = `rotate(${n}deg)`), o = {
69
- div: s,
70
- w: t.shapeW,
71
- h: t.shapeH
72
- }, l.set(a, o), e.appendChild(s);
73
- }
74
- return o;
75
- };
76
- for (let e of n) {
77
- let n = e.active ? c : s;
78
- for (let r of e.slices) {
79
- let e = t[r.runIndex];
80
- if (!e) continue;
81
- let i = a(e.font), { x: o, width: s } = De(e.text, r.start, r.end, i);
82
- if (s <= 0) continue;
83
- let c = u(e), l = document.createElement("div");
84
- l.style.cssText = `position:absolute;left:${F(e.inShapeX + o, c.w)};top:${F(e.inShapeY, c.h)};width:${F(s, c.w)};height:${F(e.h, c.h)};background:${n};pointer-events:none;`, c.div.appendChild(l);
85
- }
86
- }
87
- }
88
- //#endregion
89
- //#region packages/pptx/src/find.ts
90
- var z = class {
91
- _slideRuns = /* @__PURE__ */ new Map();
92
- _matches = [];
93
- _active = -1;
94
- _generation = 0;
95
- _runsRevision = 0;
96
- constructor(e, t) {
97
- this._slideCount = e, this._collectSlideRuns = t;
98
- }
99
- invalidate() {
100
- this._generation++, this._runsRevision++, this._slideRuns.clear(), this._matches = [], this._active = -1;
101
- }
102
- slideRuns(e) {
103
- return this._slideRuns.get(e);
104
- }
105
- setSlideRuns(e, t) {
106
- this._runsRevision++, this._slideRuns.set(e, t);
107
- }
108
- slideHighlights(e) {
109
- let t = [];
110
- for (let n = 0; n < this._matches.length; n++) {
111
- let r = this._matches[n];
112
- r.slide === e && t.push({
113
- slices: r.slices,
114
- active: n === this._active
115
- });
116
- }
117
- return t;
118
- }
119
- activeSlide() {
120
- let e = this._matches[this._active];
121
- return e ? e.slide : null;
122
- }
123
- matches() {
124
- return this._matches.map((e, t) => ({
125
- matchIndex: t,
126
- text: e.text,
127
- location: { slide: e.slide }
128
- }));
129
- }
130
- async find(e, t = {}) {
131
- let n = ++this._generation;
132
- if (e.length === 0) return this._runsRevision++, this._slideRuns.clear(), this._matches = [], this._active = -1, [];
133
- let r = this._runsRevision, i = new Map(this._slideRuns), a = this._slideCount();
134
- for (let e = 0; e < a; e++) {
135
- let t = i.get(e);
136
- if (!t) {
137
- try {
138
- t = await this._collectSlideRuns(e);
139
- } catch (e) {
140
- if (n !== this._generation) return [];
141
- throw e;
142
- }
143
- if (n !== this._generation) return [];
144
- i.set(e, t);
145
- }
146
- }
147
- if (n !== this._generation) return [];
148
- let o = r === this._runsRevision ? i : new Map([...i, ...this._slideRuns]), s = [];
149
- for (let n = 0; n < a; n++) {
150
- let r = o.get(n) ?? [], i = ue(r);
151
- for (let a of le(i, e, t)) {
152
- let e = a.slices.map((e) => r[e.runIndex].text.slice(e.start, e.end)).join("");
153
- s.push({
154
- slide: n,
155
- text: e,
156
- slices: a.slices
157
- });
158
- }
159
- }
160
- return this._runsRevision++, this._slideRuns = o, this._matches = s, this._active = -1, this.matches();
161
- }
162
- next() {
163
- return this._active = se(this._active, this._matches.length), this._activePublic();
164
- }
165
- prev() {
166
- return this._active = pe(this._active, this._matches.length), this._activePublic();
167
- }
168
- _activePublic() {
169
- let e = this._matches[this._active];
170
- return e ? {
171
- matchIndex: this._active,
172
- text: e.text,
173
- location: { slide: e.slide }
174
- } : null;
175
- }
176
- }, B = (e) => e >= "0" && e <= "9";
177
- function je(e) {
178
- let t = 0;
179
- for (let n = 0; n < 10; n++) t = Math.max(t, e.measureText(String(n)).width);
180
- return t;
181
- }
182
- function V(e, t, n) {
183
- let r = 0;
184
- for (let i of t) r += B(i) ? n : e.measureText(i).width;
185
- return r;
186
- }
187
- function H(e, t, n, r, i) {
188
- let a = e.textAlign;
189
- e.textAlign = "left";
190
- let o = n;
191
- for (let n of t) if (B(n)) {
192
- let t = e.measureText(n).width;
193
- e.fillText(n, o + (i - t) / 2, r), o += i;
194
- } else e.fillText(n, o, r), o += e.measureText(n).width;
195
- e.textAlign = a;
196
- }
197
- //#endregion
198
- //#region packages/pptx/src/presentation-handle.ts
199
- var U = (e, t) => e / M * t;
200
- async function Me(e, t, n) {
201
- let r = e.getContext("2d");
202
- if (!r) throw Error("2D context not available");
203
- let a = n.width / (n.slideWidthEmu / M);
204
- await n.drawBase();
205
- let o = document.createElement("canvas");
206
- o.width = e.width, o.height = e.height;
207
- let s = o.getContext("2d");
208
- if (!s) throw Error("base 2D context not available");
209
- s.drawImage(e, 0, 0);
210
- let c = [], l = !1, u = () => {
211
- for (let e of c) {
212
- e.detachListeners(), e.media.pause(), e.media.removeAttribute("src");
213
- try {
214
- e.media.load();
215
- } catch {}
216
- URL.revokeObjectURL(e.objectUrl);
217
- }
218
- c.length = 0;
219
- }, d = (e) => {
220
- l || (n.onError ? n.onError(e) : console.error("[ooxml] PPTX embedded media failed:", e));
221
- };
222
- for (let e of t) {
223
- let t;
224
- try {
225
- t = await n.fetchMedia(e.mediaPath);
226
- } catch (t) {
227
- throw u(), Fe(e, t);
228
- }
229
- 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");
230
- s.src = o, s.preload = "metadata", e.mediaKind === "video" && (s.playsInline = !0);
231
- let f = Ne(e, a), p = {
232
- el: e,
233
- rect: e.mediaKind === "audio" ? {
234
- x: f.x + f.w / 2 - Math.max(f.w, 260) / 2,
235
- y: f.y,
236
- w: Math.max(f.w, 260),
237
- h: f.h + 36
238
- } : f,
239
- posterRect: f,
240
- media: s,
241
- objectUrl: o,
242
- loadState: "loading",
243
- detachListeners: () => {}
244
- }, m = () => {
245
- l || (p.loadState = "metadata");
246
- }, h = () => {
247
- l || (p.loadState = "ready");
248
- }, g = () => {
249
- l || (p.loadState = "error", d(W(e, s, "decode")));
250
- };
251
- s.addEventListener("loadedmetadata", m), s.addEventListener("canplay", h), s.addEventListener("error", g), p.detachListeners = () => {
252
- s.removeEventListener("loadedmetadata", m), s.removeEventListener("canplay", h), s.removeEventListener("error", g);
253
- }, c.push(p);
254
- try {
255
- s.load();
256
- } catch (t) {
257
- let n = W(e, s, "load", t);
258
- throw u(), n;
259
- }
260
- }
261
- let f = null, p = null, m = () => {
262
- r.setTransform(n.dpr, 0, 0, n.dpr, 0, 0);
263
- let t = e.width / n.dpr, a = e.height / n.dpr;
264
- r.drawImage(o, 0, 0, e.width, e.height, 0, 0, t, a);
265
- for (let e of c) {
266
- let t = e.media;
267
- if (e.loadState !== "loading") {
268
- if (e.loadState === "error") {
269
- Pe(r, e.posterRect, "Media unavailable");
270
- continue;
271
- }
272
- if (e.el.mediaKind === "video" && t.readyState >= 2) {
273
- let { x: n, y: i, w: a, h: o } = e.posterRect;
274
- r.drawImage(t, n, i, a, o);
275
- }
276
- if (e === p || v?.state === e) Be(r, e, t);
277
- else if (t.paused) {
278
- let { x: t, y: n, w: a, h: o } = e.posterRect;
279
- i(r, t + a / 2, n + o / 2, a, o, "paused");
280
- }
281
- }
282
- }
283
- }, h = () => {
284
- l || (m(), f = requestAnimationFrame(h));
285
- }, g = (t, r) => {
286
- let i = e.getBoundingClientRect(), a = e.width / n.dpr, o = e.height / n.dpr;
287
- return {
288
- x: (t - i.left) / i.width * a,
289
- y: (r - i.top) / i.height * o
290
- };
291
- }, _ = (e, t) => {
292
- for (let n of c) {
293
- let { x: r, y: i, w: a, h: o } = n.rect;
294
- if (e < r || e > r + a || t < i || t > i + o) continue;
295
- let s = q(n), c = s.y - 12, l = s.y + s.h + 8;
296
- return (Number.isFinite(n.media.duration) ? n.media.duration : 0) > 0 && e >= s.x && e <= s.x + s.w && t >= c && t <= l ? {
297
- kind: "seek",
298
- state: n,
299
- fraction: Math.max(0, Math.min(1, (e - s.x) / s.w))
300
- } : {
301
- kind: "toggle",
302
- state: n
303
- };
304
- }
305
- return null;
306
- }, v = null, y = (e, t) => {
307
- let n = Number.isFinite(e.media.duration) ? e.media.duration : 0;
308
- n <= 0 || (e.media.currentTime = n * t);
309
- }, b = (e) => {
310
- try {
311
- e.media.play().catch((t) => {
312
- d(W(e.el, e.media, "play", t));
313
- });
314
- } catch (t) {
315
- d(W(e.el, e.media, "play", t));
316
- }
317
- }, x = (t) => {
318
- let { x: n, y: r } = g(t.clientX, t.clientY), i = _(n, r);
319
- i && (i.kind === "seek" ? (v = {
320
- state: i.state,
321
- wasPlaying: !i.state.media.paused
322
- }, 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());
323
- }, S = (e) => {
324
- let { x: t, y: n } = g(e.clientX, e.clientY);
325
- p = null;
326
- for (let e of c) {
327
- let { x: r, y: i, w: a, h: o } = e.rect;
328
- if (t >= r && t <= r + a && n >= i && n <= i + o) {
329
- p = e;
330
- break;
331
- }
332
- }
333
- if (v) {
334
- let e = q(v.state), n = Math.max(0, Math.min(1, (t - e.x) / e.w));
335
- y(v.state, n);
336
- }
337
- }, C = () => {
338
- p = null;
339
- }, w = (t) => {
340
- if (!v) return;
341
- let { wasPlaying: n, state: r } = v;
342
- v = null, e.releasePointerCapture(t.pointerId), n && b(r);
343
- };
344
- 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()), {
345
- play(e) {
346
- for (let t of c) (!e || t.el.mediaPath === e) && b(t);
347
- },
348
- pause(e) {
349
- for (let t of c) (!e || t.el.mediaPath === e) && t.media.pause();
350
- },
351
- destroy() {
352
- 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());
353
- }
354
- };
355
- }
356
- function Ne(e, t) {
357
- return {
358
- x: U(e.x, t),
359
- y: U(e.y, t),
360
- w: U(e.width, t),
361
- h: U(e.height, t)
362
- };
363
- }
364
- function Pe(e, t, n) {
365
- let r = Math.max(10, Math.min(14, t.h * .12));
366
- e.save(), e.font = `500 ${r}px system-ui, -apple-system, sans-serif`, e.textAlign = "center", e.textBaseline = "middle";
367
- let i = r + 12, a = Math.min(t.w, Math.max(100, e.measureText(n).width + 24));
368
- J(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();
369
- }
370
- function Fe(e, t) {
371
- return /* @__PURE__ */ Error(`Embedded ${e.mediaKind} fetch failed for "${e.mediaPath}" (mime=${e.mimeType || "unknown"}): ${Ie(t)}`);
372
- }
373
- function W(e, t, n, r) {
374
- let i = "";
375
- try {
376
- i = e.mimeType ? t.canPlayType(e.mimeType) : "";
377
- } catch {}
378
- let a = t.error, o = [
379
- `mime=${e.mimeType || "unknown"}`,
380
- `canPlayType=${i || "no"}`,
381
- `readyState=${t.readyState}`,
382
- `networkState=${t.networkState}`
383
- ];
384
- a && o.push(`mediaError=${a.code}${a.message ? ` ${a.message}` : ""}`);
385
- let s = r === void 0 ? "" : `: ${Ie(r)}`;
386
- return /* @__PURE__ */ Error(`Embedded ${e.mediaKind} ${n} failed for "${e.mediaPath}" (${o.join("; ")})${s}`);
387
- }
388
- function Ie(e) {
389
- return e instanceof Error ? `${e.name || "Error"}${e.message ? `: ${e.message}` : ""}` : String(e);
390
- }
391
- var Le = 28, G = 14, Re = 72, ze = 10, K = 3;
392
- function Be(e, t, n) {
393
- let r = Number.isFinite(n.duration) ? n.duration : 0, a = r > 0 ? Math.min(1, n.currentTime / r) : 0, o = t.posterRect;
394
- i(e, o.x + o.w / 2, o.y + o.h / 2, o.w, o.h, n.paused ? "paused" : "playing"), t.el.mediaKind === "audio" ? He(e, t, n, r, a) : Ve(e, t, n, r, a);
395
- }
396
- function Ve(e, t, n, r, i) {
397
- let { x: a, y: o, w: s, h: c } = t.rect, l = Math.max(28, Math.min(56, c * .22)), u = o + c - l;
398
- e.save();
399
- let d = e.createLinearGradient(0, u, 0, o + c);
400
- 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();
401
- let f = q(t);
402
- We(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)", Ue(e, n.currentTime, r, f.x, f.y - 10, "bottom"), e.restore();
403
- }
404
- function He(e, t, n, r, i) {
405
- let a = Ge(t.rect);
406
- e.save(), J(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)", Ue(e, n.currentTime, r, a.x + G, a.y + a.h / 2, "middle"), e.restore(), We(e, q(t), i, r > 0);
407
- }
408
- function Ue(e, t, n, r, i, a) {
409
- let o = Ke(t), s = Ke(n), c = je(e), l = V(e, o, c), u = V(e, s, c), d = e.measureText(" / ").width, f = Math.max(l, u);
410
- H(e, o, r + f - l, i, c);
411
- let p = e.textAlign;
412
- e.textAlign = "left", e.fillText(" / ", r + f, i), e.textAlign = p, H(e, s, r + f + d, i, c);
413
- }
414
- function We(e, t, n, r) {
415
- let i = t.h / 2;
416
- if (e.save(), J(e, t.x, t.y, t.w, t.h, i), e.fillStyle = "rgba(255, 255, 255, 0.35)", e.fill(), n > 0 && (J(e, t.x, t.y, t.w * n, t.h, i), e.fillStyle = "#fff", e.fill()), r) {
417
- let r = Math.max(t.x + 5, Math.min(t.x + t.w - 5, t.x + t.w * n));
418
- 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();
419
- }
420
- e.restore();
421
- }
422
- function Ge(e) {
423
- let t = Math.max(220, e.w - 24);
424
- return {
425
- x: e.x + e.w / 2 - t / 2,
426
- y: e.y + e.h - Le - 4,
427
- w: t,
428
- h: Le
429
- };
430
- }
431
- function q(e) {
432
- if (e.el.mediaKind === "audio") {
433
- let t = Ge(e.rect), n = t.x + G + Re + ze, r = Math.max(40, t.x + t.w - G - n);
434
- return {
435
- x: n,
436
- y: t.y + (t.h - K) / 2,
437
- w: r,
438
- h: K
439
- };
440
- }
441
- let t = e.rect, n = Math.max(12, t.w * .025), r = Math.max(12, Math.min(18, t.h * .05));
442
- return {
443
- x: t.x + n,
444
- y: t.y + t.h - K - r,
445
- w: t.w - n * 2,
446
- h: K
447
- };
448
- }
449
- function J(e, t, n, r, i, a) {
450
- let o = Math.min(a, i / 2, r / 2);
451
- 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();
452
- }
453
- function Ke(e) {
454
- if (!Number.isFinite(e) || e < 0) return "0:00";
455
- let t = Math.floor(e);
456
- return `${Math.floor(t / 60)}:${(t % 60).toString().padStart(2, "0")}`;
457
- }
458
- //#endregion
459
- //#region packages/pptx/src/slide-nav.ts
460
- function qe(e) {
461
- let t = /* @__PURE__ */ new Map();
462
- for (let n = 0; n < e.length; n++) {
463
- let r = e[n];
464
- r !== void 0 && r !== "" && !t.has(r) && t.set(r, n);
465
- }
466
- return t;
467
- }
468
- function Je(e, t) {
469
- if (e === "") return;
470
- let n = Oe("ppt/slides", e);
471
- return t.get(n);
472
- }
473
- function Ye(e, t, n) {
474
- let r = ke(e);
475
- return r === null ? Je(e, t) : Ae(r, n, t.size);
476
- }
477
- //#endregion
478
- //#region packages/pptx/src/slide-repository.ts
479
- var Xe = class {
480
- #e;
481
- #t;
482
- #n;
483
- #r = 0;
484
- #i = Promise.resolve();
485
- #a;
486
- #o;
487
- constructor(e) {
488
- if (!Number.isSafeInteger(e.slideCount) || e.slideCount < 0) throw TypeError("slideCount must be a non-negative safe integer");
489
- this.#e = e.slideCount, this.#t = e.loadSlide, this.#n = new xe({
490
- maxEntries: e.maxCachedSlides,
491
- maxWeight: e.maxCachedStructuralBytes,
492
- measure: (e) => Ce(e).jsonBytes
493
- });
494
- }
495
- get slideCount() {
496
- return this.#e;
497
- }
498
- get usage() {
499
- return this.#n.usage;
500
- }
501
- withSlide(e, t) {
502
- this.#c(e);
503
- let n = this.#r, r = this.#i.then(async () => {
504
- if (n !== this.#r) throw this.#a ? this.#a : Error("PPTX slide repository generation is stale");
505
- if (this.#a) throw this.#a;
506
- let r = await this.#s(e, n);
507
- try {
508
- return await t(r);
509
- } catch (e) {
510
- let t = Ze(e);
511
- throw t ? (this.#l(t, n), this.#o === n ? this.#a ?? t : t) : e;
512
- }
513
- });
514
- return this.#i = r.then(() => void 0, () => void 0), r;
515
- }
516
- async #s(e, t) {
517
- return this.#n.getOrLoad(e, async () => {
518
- let n;
519
- try {
520
- n = await this.#t(e);
521
- } catch (e) {
522
- let n = Ze(e);
523
- throw n ? (this.#l(n, t), this.#o === t ? this.#a ?? n : n) : e;
524
- }
525
- if (this.#o === t && this.#a) throw this.#a;
526
- return n;
527
- });
528
- }
529
- clear() {
530
- this.#r += 1, this.#a = void 0, this.#o = void 0, this.#n.clear();
531
- }
532
- #c(e) {
533
- if (!Number.isSafeInteger(e) || e < 0 || e >= this.#e) throw RangeError(`Slide index ${e} out of range (count: ${this.#e})`);
534
- }
535
- #l(e, t) {
536
- t !== this.#r || this.#a || (this.#a = e, this.#o = t, this.#r += 1, this.#n.clear());
537
- }
538
- };
539
- function Ze(e) {
540
- return e instanceof x ? e : g(e);
541
- }
542
- //#endregion
543
- //#region packages/pptx/src/worker.ts?worker&inline
544
- var Qe = "var e=class e extends Error{code;constructor(t,n){super(n),this.name=`OoxmlError`,this.code=t,Object.setPrototypeOf(this,e.prototype)}},t=class e extends Error{code=`ooxml-resource-limit`;details;constructor(t,n){super(t),this.name=`OoxmlResourceLimitError`;let r=n.violation,i=Object.freeze({format:r.format,operation:r.operation,resource:r.resource,metric:r.metric,...r.part===void 0?{}:{part:r.part},limit:r.limit,observed:r.observed,configurable:r.configurable,usage:Object.freeze({archiveEntryCount:r.usage.archiveEntryCount,declaredInflatedBytes:r.usage.declaredInflatedBytes,...r.usage.largestInflatedEntryBytes===void 0?{}:{largestInflatedEntryBytes:r.usage.largestInflatedEntryBytes},distinctInflatedBytes:r.usage.distinctInflatedBytes,operationInflatedBytes:r.usage.operationInflatedBytes})});this.details=Object.freeze({stage:n.stage,violation:i}),Object.setPrototypeOf(this,e.prototype)}};const n=`https://fonts.googleapis.com/css2?family=Noto+Naskh+Arabic:wght@400;700&display=swap`,r=`https://fonts.googleapis.com/css2?family=Noto+Sans+Arabic:wght@400;700&display=swap`,i=`https://fonts.googleapis.com/css2?family=Libre+Franklin:ital,wght@0,400;0,600;0,700;1,400;1,600;1,700&display=swap`,a={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:i,loadFamily:`Libre Franklin`},\"franklin gothic medium\":{url:i,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:n,loadFamily:`Noto Naskh Arabic`},\"traditional arabic\":{url:n,loadFamily:`Noto Naskh Arabic`},\"simplified arabic\":{url:n,loadFamily:`Noto Naskh Arabic`},\"arabic typesetting\":{url:n,loadFamily:`Noto Naskh Arabic`},\"univers next arabic\":{url:r,loadFamily:`Noto Sans Arabic`},\"noto naskh arabic\":{url:n,loadFamily:`Noto Naskh Arabic`},\"noto sans arabic\":{url:r,loadFamily:`Noto Sans Arabic`}};function o(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 s=e=>`https://fonts.googleapis.com/css2?family=${e}:wght@400;700&display=swap`,ee={\"noto sans kr\":{url:s(`Noto+Sans+KR`)},\"noto sans sc\":{url:s(`Noto+Sans+SC`)},\"noto sans tc\":{url:s(`Noto+Sans+TC`)},\"noto sans jp\":{url:s(`Noto+Sans+JP`)},\"noto serif kr\":{url:s(`Noto+Serif+KR`)},\"noto serif sc\":{url:s(`Noto+Serif+SC`)},\"noto serif tc\":{url:s(`Noto+Serif+TC`)},\"noto serif jp\":{url:s(`Noto+Serif+JP`)},\"noto sans\":{url:s(`Noto+Sans`)},\"noto serif\":{url:s(`Noto+Serif`)},\"noto sans devanagari\":{url:s(`Noto+Sans+Devanagari`)},\"noto sans thai\":{url:s(`Noto+Sans+Thai`)},\"noto sans hebrew\":{url:s(`Noto+Sans+Hebrew`)},\"noto serif hebrew\":{url:s(`Noto+Serif+Hebrew`)}};var c=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}},l=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 u(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 d=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`)}},te=class e extends Error{code=`parser-crashed`;constructor(t){super(t),this.name=`WasmTrapError`,Object.setPrototypeOf(this,e.prototype)}};function ne(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 re(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 ie(e,t){return e({module_or_path:t})}var ae=class{runtime;wasmInput=null;currentArchive=null;constructor(e,t={}){this.init=e,this.options=t,this.runtime=new d(()=>this.invokeConfigured(this.init),()=>this.invokeConfigured(this.options.reinit??this.init),oe),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 te(`WASM parser was recycled`))}invokeConfigured(e){return this.wasmInput===null?Promise.reject(Error(`WasmParserHost: setWasmInput was never called`)):ie(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,re(e)}};function oe(e){return ne(e)?new te(`WASM parser trapped and was recycled: ${e instanceof Error?e.message:String(e)}`):null}function se(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>0}function ce(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return se(t.requiredBytes)&&se(t.offeredBytes)&&t.requiredBytes>t.offeredBytes}var f=class e extends RangeError{code=`ooxml-insufficient-credit`;requiredBytes;offeredBytes;constructor(t){super(`Pull unit requires ${t.requiredBytes} bytes but credit is ${t.offeredBytes}`),this.name=`PullSessionInsufficientCreditError`,this.requiredBytes=t.requiredBytes,this.offeredBytes=t.offeredBytes,Object.setPrototypeOf(this,e.prototype)}};function le(e){if(e instanceof f)return e;let t=e instanceof Error?e.message:String(e);if(!t.startsWith(`OOXML_INSUFFICIENT_CREDIT:`))return;let n;try{n=JSON.parse(t.slice(26))}catch{return}if(!n||typeof n!=`object`||Array.isArray(n))return;let r=n;if(!(r.code!==`ooxml-insufficient-credit`||!ce(r)))return new f(r)}function ue(e,t,n){let r=le(e);if(!(!r||r.offeredBytes!==t||r.requiredBytes>n))return r}const de=`OOXML_RESOURCE_LIMIT:`;function p(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function fe(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return p(t.archiveEntryCount)&&p(t.declaredInflatedBytes)&&(t.largestInflatedEntryBytes===void 0||p(t.largestInflatedEntryBytes))&&p(t.distinctInflatedBytes)&&p(t.operationInflatedBytes)}function pe(e){let t;try{t=JSON.parse(new TextDecoder().decode(e))}catch{throw TypeError(`OOXML resource usage checkpoint is not valid JSON`)}if(!fe(t))throw TypeError(`OOXML resource usage checkpoint is invalid`);return t}function me(e){return e===`docx`||e===`xlsx`||e===`pptx`}function he(e){return e===`container`||e===`decompression`||e===`parsing`||e===`serialization`||e===`layout`||e===`rendering`||e===`worker`}function m(e,t){return typeof e==`string`&&e.length>0&&e.length<=t&&!/[\\u0000-\\u001f\\u007f]/u.test(e)}function h(e){return m(e,128)&&/^[a-z0-9][a-z0-9-]*$/u.test(e)}function ge(e){return!m(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 g=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}]]),_e=new Set([...g.keys()].map(e=>e.slice(0,e.indexOf(`:`)))),ve=new Set([...g.keys()].map(e=>e.slice(e.indexOf(`:`)+1)));function ye(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return!me(t.format)||!m(t.operation,256)||!h(t.resource)||!h(t.metric)||!p(t.limit)||!p(t.observed)||typeof t.configurable!=`boolean`||!fe(t.usage)?!1:!(`part`in t)||ge(t.part)}function _(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;if(!he(t.stage)||!ye(t.violation))return!1;let n=t.violation,r=g.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:!(_e.has(n.resource)&&ve.has(n.metric))}function be(e){return{archiveEntryCount:e.archiveEntryCount,declaredInflatedBytes:e.declaredInflatedBytes,...e.largestInflatedEntryBytes===void 0?{}:{largestInflatedEntryBytes:e.largestInflatedEntryBytes},distinctInflatedBytes:e.distinctInflatedBytes,operationInflatedBytes:e.operationInflatedBytes}}function xe(e){if(!_(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:be(t.usage)}};return _(n)?n:void 0}function v(e){let t=e.violation;return`OOXML resource limit exceeded${t.part?` for ${t.part}`:``}: ${t.metric} ${t.observed} > ${t.limit}`}function Se(e){let n=e instanceof Error?e.message:String(e);if(!n.startsWith(de))return;let r;try{r=JSON.parse(n.slice(21))}catch{return}if(!r||typeof r!=`object`)return;let i=r;if(!(i.code!==`ooxml-resource-limit`||!_(i.details)))return new t(v(i.details),i.details)}function Ce(n){if(n instanceof l)return{message:n.message,errorName:n.name,code:n.code,decodedImage:{metric:n.metric,limit:n.limit,observed:n.observed}};let r=le(n);if(r)return{message:r.message,errorName:r.name,code:r.code,insufficientCredit:{requiredBytes:r.requiredBytes,offeredBytes:r.offeredBytes}};let i=n instanceof e||n instanceof t?n:Se(n);if(i instanceof t){let e=xe(i.details);return e?{message:typeof i.message==`string`?i.message:v(e),errorName:`OoxmlResourceLimitError`,code:`ooxml-resource-limit`,resourceLimit:e}:{message:`Invalid OOXML resource-limit error payload`,errorName:`Error`}}if(i instanceof e)return{message:typeof i.message==`string`?i.message:String(i.message),errorName:m(i.name,128)?i.name:`OoxmlError`,...h(i.code)?{code:i.code}:{}};let a=n instanceof Error?n.message:String(n);if(typeof a==`string`&&a.startsWith(de))return{message:`Invalid OOXML resource-limit payload`,errorName:`Error`};let o=n instanceof Error?n:Error(a),s=o;return{message:typeof o.message==`string`?o.message:String(o.message),errorName:m(o.name,128)?o.name:`Error`,...typeof s.code==`string`?{code:s.code}:{}}}function y(e){try{return Ce(e)}catch{return{message:`Worker operation failed with an unreadable error`,errorName:`Error`}}}const we=new Set([`encrypted`,`invalid-password`,`unsupported-encryption`,`legacy-binary-format`,`not-ooxml`]);function Te(n){if(n.code===`ooxml-decoded-image-limit`&&n.decodedImage&&(n.decodedImage.metric===`image-pixels`||n.decodedImage.metric===`active-decoded-bytes`)&&p(n.decodedImage.limit)&&p(n.decodedImage.observed)&&n.decodedImage.observed>n.decodedImage.limit)return new l(n.decodedImage.metric,n.decodedImage.limit,n.decodedImage.observed);if(n.code===`ooxml-insufficient-credit`&&ce(n.insufficientCredit))return new f(n.insufficientCredit);if(n.code===`ooxml-resource-limit`&&_(n.resourceLimit))return new t(n.message,n.resourceLimit);if(n.code&&we.has(n.code))return new e(n.code,n.message);let r=n.errorName===`TypeError`?TypeError(n.message):n.errorName===`RangeError`?RangeError(n.message):Error(n.message);return n.errorName&&(r.name=n.errorName),n.code!==void 0&&Object.assign(r,{code:n.code}),r}function Ee(e){return e.byteOffset===0&&e.byteLength===e.buffer.byteLength&&e.buffer instanceof ArrayBuffer?e.buffer:e.slice().buffer}const De=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 b=`ooxml-pull-v1`;function x(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 S=class{owner;queue=Promise.resolve();leases=new Map;retainedBytes=0;retainedCount=0;maxRetainedBytes;maxRetainedCount;cleanups=new Set;pendingFatalCleanups=[];poisonRunning=!1;fatal;constructor(e){this.maxRetainedBytes=e?.maxRetainedBytes??64*1024*1024,this.maxRetainedCount=e?.maxRetainedCount??256,x(this.maxRetainedBytes,`max retained lease bytes`),x(this.maxRetainedCount,`max retained lease count`)}enqueue(e){let t=this.queue.then(e,e);return this.queue=t.then(()=>void 0,()=>void 0),t}acquire(e){return this.owner===void 0?(this.owner=e,!0):this.owner===e}release(e){this.owner===e&&(this.owner=void 0)}retainLease(e,t,n){if(!Number.isSafeInteger(n)||n<0)throw RangeError(`retained lease bytes are invalid`);let r=this.leases.get(e)??new Map;if(r.has(t))throw Error(`driver returned a duplicate lease id`);if(this.retainedCount+1>this.maxRetainedCount)throw RangeError(`retained lease count exceeds limit`);if(this.retainedBytes+n>this.maxRetainedBytes)throw RangeError(`retained lease bytes exceed limit`);r.set(t,n),this.leases.set(e,r),this.retainedCount++,this.retainedBytes+=n}releaseLease(e,t){let n=this.leases.get(e),r=n?.get(t);r!==void 0&&(n?.delete(t),n?.size===0&&this.leases.delete(e),this.retainedCount--,this.retainedBytes-=r)}registerCleanup(e){return this.fatal?(this.poisonRunning?this.pendingFatalCleanups.push(e):this.enqueue(e).catch(()=>void 0),()=>void 0):(this.cleanups.add(e),()=>this.cleanups.delete(e))}get fatalError(){return this.fatal}get registeredHostCount(){return this.cleanups.size}async poison(e){if(this.fatal??=e,this.poisonRunning)return this.fatal;this.poisonRunning=!0,this.pendingFatalCleanups.push(...this.cleanups);try{let e;for(;(e=this.pendingFatalCleanups.shift())!==void 0;)await e().catch(()=>void 0)}finally{this.poisonRunning=!1}return this.fatal}},Ae=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),x(e.operationId,`operation id`),x(e.generation,`generation`),x(e.maxByteCredit,`max byte credit`),e.wireLeaseIdStart!==void 0&&x(e.wireLeaseIdStart,`wire lease id start`),this.options=e,this.coordinator=e.coordinator,this.nextWireLeaseId=e.wireLeaseIdStart??1,this.unregisterCleanup=this.coordinator.registerCleanup(()=>this.forceFatalCleanup())}dispatch(e,t){return this.coordinator.enqueue(async()=>{let n=await this.execute(e);try{t(n.response,n.transfer)}catch(e){throw await this.rollbackFailedPost(n),e}})}async rollbackFailedPost(e){let t=e.response;if(t.kind===`chunk`){let n=t.leaseId===void 0?void 0:this.leases.get(t.leaseId);try{await this.options.driver.disposeInvalidChunk?.({payload:t.payload,byteLength:t.byteLength,done:t.done,leaseId:n?.driverLeaseId,retainedBytes:n?.retainedBytes,transfer:e.transfer})}catch{}}this.unacked=void 0,this.coordinator.release(this.coordinatorOwner);for(let[e,t]of[...this.leases])try{await this.options.driver.releaseLease?.(t.driverLeaseId)}catch{}finally{this.leases.delete(e),this.activeDriverLeases.delete(t.driverLeaseId),this.coordinator.releaseLease(this.coordinatorOwner,e)}if(this.cancelRequested=!0,!this.driverCancelComplete)try{await this.options.driver.cancel?.(),this.driverCancelComplete=!0}catch{}this.unregisterCleanup()}async execute(e){try{if(this.isStaleLifecycle(e)){let t=e.kind===`cancel`?`cancel`:`close`;return this.sameOperationIdentity(e)?{response:this.accepted(e,t,!0)}:{response:this.errorResponse(e,{message:`stale lifecycle targets another session or operation`,errorName:`PullSessionProtocolError`,code:`ooxml-stale-lifecycle`})}}this.validateCommandIdentity(e);let t=this.coordinator.fatalError;if(t)return e.kind===`pull`?{response:this.errorResponse(e,t)}:(e.kind===`cancel`?await this.cancel():e.kind===`close`?await this.close():e.kind===`release`&&await this.release(e.leaseId),{response:this.accepted(e,e.kind)});switch(e.kind){case`pull`:return await this.pull(e);case`ack`:return await this.ack(e.sequence),{response:this.accepted(e,`ack`)};case`release`:return await this.release(e.leaseId),{response:this.accepted(e,`release`)};case`cancel`:return await this.cancel(),{response:this.accepted(e,`cancel`)};case`close`:return await this.close(),{response:this.accepted(e,`close`)}}}catch(t){let n=y(t);return n.code===`ooxml-resource-limit`&&(n=await this.coordinator.poison(n)),{response:this.errorResponse(e,n)}}}async pull(e){if(this.closeRequested||this.cancelRequested||this.completed)throw Error(`pull session is closed`);if(this.unacked)throw Error(`previous chunk is not acknowledged`);if(!Number.isSafeInteger(e.sequence)||e.sequence<0||e.sequence!==this.sequence)throw Error(`pull command sequence mismatch`);if(this.validateHostCredit(e.byteCredit),!this.coordinator.acquire(this.coordinatorOwner))throw Error(`another operation has an unacknowledged package chunk`);let t;try{t=await this.options.driver.pull(e.byteCredit)}catch(e){throw this.coordinator.release(this.coordinatorOwner),e}let n=!1,r=!1,i,a;try{let o=this.options.driver.measureChunk(t),s=this.arrayBufferTransferBytes(t.transfer);if(o<s)throw RangeError(`measured chunk bytes are below ArrayBuffer transfer bytes`);if(a=Math.max(o,s),t.leaseId!==void 0){if(x(t.leaseId,`lease id`),t.retainedBytes===void 0)throw Error(`retained lease bytes are required`);if(this.activeDriverLeases.has(t.leaseId))throw r=!0,Error(`driver returned an active duplicate lease id`);i=this.allocateWireLeaseId(),this.coordinator.retainLease(this.coordinatorOwner,i,t.retainedBytes),this.leases.set(i,{driverLeaseId:t.leaseId,retainedBytes:t.retainedBytes}),this.activeDriverLeases.add(t.leaseId),n=!0}else if(t.retainedBytes!==void 0)throw Error(`retained lease bytes require a lease id`);if(!Number.isSafeInteger(a)||a<0)throw RangeError(`host chunk byte length must be a non-negative safe integer`);if(a>e.byteCredit)throw RangeError(`host chunk exceeds byte credit`)}catch(e){let a;try{await this.options.driver.disposeInvalidChunk?.(t)}catch(e){a=e}if(n&&i!==void 0)try{await this.release(i)}catch(e){a??=e}else if(t.leaseId!==void 0&&!r)try{await this.options.driver.releaseLease?.(t.leaseId)}catch(e){a??=e}if(r)try{await this.cancel()}catch(e){a??=e}throw this.coordinator.release(this.coordinatorOwner),a||e}return this.unacked={sequence:this.sequence,done:t.done},{response:{kind:`chunk`,protocol:b,...this.identity(),requestId:e.requestId,sequence:this.sequence,byteLength:a,done:t.done,payload:t.payload,leaseId:i,usage:this.resourceUsage()},transfer:t.transfer}}async ack(e){if(!Number.isSafeInteger(e)||e<0)throw RangeError(`invalid ack sequence`);if(e<this.sequence)return;if(!this.unacked||e!==this.sequence)throw Error(`ack sequence mismatch`);let t=this.unacked.done;await this.options.driver.acknowledge?.(e),this.unacked=void 0,this.coordinator.release(this.coordinatorOwner),this.sequence++,t&&(this.completed=!0,this.maybeUnregisterCompleted())}async release(e){x(e,`wire lease id`);let t=this.leases.get(e);t&&(await this.options.driver.releaseLease?.(t.driverLeaseId),this.leases.delete(e),this.activeDriverLeases.delete(t.driverLeaseId),this.coordinator.releaseLease(this.coordinatorOwner,e),this.maybeUnregisterCompleted())}async cancel(){if(this.cancelComplete)return;this.cancelRequested=!0,this.unacked=void 0,this.coordinator.release(this.coordinatorOwner);let e;try{await this.releaseAllLeases()}catch(t){e=t}if(!this.driverCancelComplete)try{await this.options.driver.cancel?.(),this.driverCancelComplete=!0}catch(t){e??=t}if(e)throw e;this.cancelComplete=!0,this.unregisterCleanup()}async close(){if(this.closeComplete)return;this.closeRequested=!0,this.unacked=void 0,this.coordinator.release(this.coordinatorOwner);let e;try{await this.releaseAllLeases()}catch(t){e=t}if(!this.driverCloseComplete)try{await this.options.driver.close?.(),this.driverCloseComplete=!0}catch(t){e??=t}if(e)throw e;this.closeComplete=!0,this.unregisterCleanup()}async releaseAllLeases(){let e;for(let t of[...this.leases.keys()])try{await this.release(t)}catch(t){e??=t}if(e)throw e}validateCommandIdentity(e){if(e.protocol!==`ooxml-pull-v1`||e.sessionId!==this.options.sessionId||e.operationId!==this.options.operationId||e.generation!==this.options.generation||!Number.isSafeInteger(e.requestId)||e.requestId<=0)throw Error(`stale or mismatched pull session command`)}validateHostCredit(e){if(x(e,`byte credit`),e>this.options.maxByteCredit)throw RangeError(`byte credit exceeds host maximum`)}accepted(e,t,n=!1){return{kind:`accepted`,protocol:b,...n?{sessionId:e.sessionId,operationId:e.operationId,generation:e.generation}:this.identity(),requestId:e.requestId,command:t,usage:this.resourceUsage()}}identity(){return{sessionId:this.options.sessionId,operationId:this.options.operationId,generation:this.options.generation}}isStaleLifecycle(e){return(e.kind===`cancel`||e.kind===`close`)&&e.protocol===`ooxml-pull-v1`&&Number.isSafeInteger(e.requestId)&&e.requestId>0&&Number.isSafeInteger(e.generation)&&e.generation>0&&e.generation<this.options.generation}sameOperationIdentity(e){return e.sessionId===this.options.sessionId&&e.operationId===this.options.operationId}errorResponse(e,t){return{kind:`error`,protocol:b,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:t,usage:this.errorResourceUsage()}}async forceFatalCleanup(){this.cancelRequested=!0,this.unacked=void 0,this.coordinator.release(this.coordinatorOwner);let e;for(let t of[...this.leases.keys()])try{await this.release(t)}catch(t){e??=t}if(!this.driverCancelComplete)try{await this.options.driver.cancel?.(),this.driverCancelComplete=!0}catch(t){e??=t}if(e)throw e;this.unregisterCleanup()}allocateWireLeaseId(){if(!Number.isSafeInteger(this.nextWireLeaseId)||this.nextWireLeaseId<=0)throw RangeError(`wire lease id space exhausted`);return this.nextWireLeaseId++}arrayBufferTransferBytes(e){let t=0;for(let n of e??[])if(n instanceof ArrayBuffer&&(t+=n.byteLength,!Number.isSafeInteger(t)))throw RangeError(`ArrayBuffer transfer bytes overflow`);return t}maybeUnregisterCompleted(){this.completed&&this.leases.size===0&&this.unregisterCleanup()}resourceUsage(){return this.options.driver.resourceUsage?.()}errorResourceUsage(){try{return this.resourceUsage()}catch{return}}};function C(e,t){if(!Number.isSafeInteger(e)||e<0)throw Error(`${t} must be a non-negative safe integer`)}function w(e,t,n){return C(e,`resource measurement`),C(t,`resource measurement`),C(n,`resource measurement limit`),e>n||t>n||t>n-e?n===2**53-1?n:n+1:e+t}function je(e,t=2**53-1){C(t,`resource measurement limit`);let n=0;for(let r=0;r<e.length;r+=1){let i=e.charCodeAt(r),a;if(i<=127)a=1;else if(i<=2047)a=2;else if(i>=55296&&i<=56319&&r+1<e.length){let t=e.charCodeAt(r+1);t>=56320&&t<=57343?(a=4,r+=1):a=3}else a=3;if(n=w(n,a,t),n>t)return n}return n}function T(e,t=2**53-1){C(t,`resource measurement limit`);let n=w(0,2,t);if(n>t)return n;for(let r=0;r<e.length;r+=1){let i=e.charCodeAt(r),a;if(i===34||i===92||i===8||i===9||i===10||i===12||i===13)a=2;else if(i<=31)a=6;else if(i<=127)a=1;else if(i<=2047)a=2;else if(i>=55296&&i<=56319&&r+1<e.length){let t=e.charCodeAt(r+1);t>=56320&&t<=57343?(a=4,r+=1):a=6}else a=i>=55296&&i<=57343?6:3;if(n=w(n,a,t),n>t)return n}return n}function E(e,t){return w(0,e,t)}function D(e,t=2**53-1,n=!1){if(C(t,`resource measurement limit`),e===null)return{jsonBytes:E(4,t),stringValueUtf8Bytes:0};if(typeof e==`string`)return{jsonBytes:T(e,t),stringValueUtf8Bytes:je(e,t)};if(typeof e==`boolean`)return{jsonBytes:E(e?4:5,t),stringValueUtf8Bytes:0};if(typeof e==`number`)return{jsonBytes:E((Number.isFinite(e)?String(Object.is(e,-0)?0:e):`null`).length,t),stringValueUtf8Bytes:0};if(typeof e==`bigint`)throw TypeError(`BigInt values cannot be serialized to JSON`);if(Array.isArray(e)){let n=E(2,t),r=0;for(let i=0;i<e.length;i+=1){i!==0&&(n=w(n,1,t));let a=D(e[i],t,!0);n=w(n,a.jsonBytes,t),r=w(r,a.stringValueUtf8Bytes,t)}return{jsonBytes:n,stringValueUtf8Bytes:r}}if(typeof e==`object`){let n=E(2,t),r=0,i=0;for(let[a,o]of Object.entries(e)){if(o===void 0||typeof o==`function`||typeof o==`symbol`)continue;i++!==0&&(n=w(n,1,t)),n=w(n,T(a,t),t),n=w(n,1,t);let e=D(o,t);n=w(n,e.jsonBytes,t),r=w(r,e.stringValueUtf8Bytes,t)}return{jsonBytes:n,stringValueUtf8Bytes:r}}return{jsonBytes:n?E(4,t):0,stringValueUtf8Bytes:0}}({...a,...ee});function*O(e){for(let t of e?.paragraphs??[])for(let e of t.runs)e.type===`text`&&(yield e.text)}function*k(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*Me(e){for(let t of e.elements)if(t.type===`shape`)yield*O(t.textBody);else if(t.type===`table`)for(let e of t.rows)for(let t of e.cells)yield*O(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 Ne=class e{scripts;families;constructor(e,t,n,r){this.majorFont=e,this.minorFont=t;let i=o(e)??o(t)??null;this.scripts=n??new c(i),this.families=r??new Set,e&&this.families.add(e),t&&this.families.add(t)}addSlide(e){this.scripts.addText(Me(e));for(let t of e.elements)if(t.type===`shape`)for(let e of k(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 k(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 A=Object.freeze({archiveEntryCount:0,declaredInflatedBytes:0,distinctInflatedBytes:0,operationInflatedBytes:0}),j=67108864;function M(e,t){if(e!==null&&typeof e!=`string`)throw Error(`invalid PPTX presentation bootstrap ${t}`)}function Pe(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 Fe(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 M(t.defaultTextColor,`defaultTextColor`),M(t.majorFont,`majorFont`),M(t.minorFont,`minorFont`),M(t.hlinkColor,`hlinkColor`),M(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(Pe))})}function Ie(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 Le(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(Ie))})}function N(e,n,r){if(!(e<=n))throw new t(`PPTX presentation preflight exceeded its hard limit of ${n} projected bytes`,{stage:`parsing`,violation:{format:`pptx`,operation:`presentation-preflight`,resource:`presentation-preflight`,metric:`projected-bytes`,limit:n,observed:Math.min(e,n+1),configurable:!1,usage:r}})}var Re=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=Fe(e),r=t.hardLimitForTesting??j;if(!Number.isSafeInteger(r)||r<=0||r>j)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 Ne(this.majorFontValue,this.minorFontValue),this.fontPreloadNames=Object.freeze(this.fonts.names()),this.fontProjectionBytes=D(this.fontPreloadNames,this.limit).jsonBytes,this.projectionBytesValue=D({slideCount:this.slideCountValue,slideWidth:this.slideWidthValue,slideHeight:this.slideHeightValue,defaultTextColor:this.defaultTextColorValue,majorFont:this.majorFontValue,minorFont:this.minorFontValue,hlinkColor:this.hlinkColorValue,folHlinkColor:this.folHlinkColorValue,remainingSlides:this.descriptors,slides:[],fontPreloadNames:this.fontPreloadNames},this.limit).jsonBytes,N(this.projectionBytesValue,this.limit,A)}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=A){this.prepareSlide(e,t).commit()}prepareSlide(e,t=A){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=Le(e,r),a=this.fonts.withSlide(e),o=Object.freeze(a.names()),s=D(o,this.limit).jsonBytes,ee=D(i,this.limit).jsonBytes,c=this.projectionBytesValue-this.fontProjectionBytes-D(r,this.limit).jsonBytes+4;c=w(c,s,this.limit),c=w(c,ee,this.limit),this.slides.length!==0&&(c=w(c,1,this.limit));let l=D({slide:i,fontPreloadNames:o},this.limit).jsonBytes,u=w(this.projectionBytesValue,l,this.limit);N(Math.max(u,c),this.limit,t);let d={state:`prepared`,fact:i,fonts:a,fontNames:o,fontBytes:s,committedBytes:c};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=D(this.finished,this.limit).jsonBytes,this.finished}};function ze(e){try{return pe(e(e=>e.slide_cursor_resource_usage()))}catch(e){if(String(e).includes(`slide cursor usage is unavailable`))return;throw e}}function Be(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,ze(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 Ve=class{coordinatorGeneration=new S;sessions=new Map;pendingOpens=new Map;operationTail=Promise.resolve();resourceFailure;lifecycleState=`ready`;resetBarrier;resetIdentities=new Map;constructor(e,t,n=e=>e(this.requireArchive())){this.archive=e,this.acceptSlide=t,this.executeArchive=n}get coordinator(){return this.coordinatorGeneration}reserveOpen(e){if(this.assertReady(),Ue(e),this.pendingOpens.has(e.sessionId)||this.sessions.has(e.sessionId))throw Error(`slide pull session id is already reserved`);this.pendingOpens.set(e.sessionId,{identity:e,canceled:!1})}abandonOpen(e){this.pendingOpens.delete(e)}get pendingOpenCount(){return this.pendingOpens.size}async open(e,t){if(this.assertReady(),this.resourceFailure)throw this.resourceFailure;if(!Number.isSafeInteger(e)||e<0)throw RangeError(`slide index must be a non-negative safe integer`);let n=this.pendingOpens.get(t.sessionId);if(!n||!P(n.identity,t))throw Error(`slide pull session open reservation is stale or missing`);let r,i=new Promise(e=>{r=e}),a=this.operationTail.then(()=>this.coordinator.enqueue(async()=>{if(n.canceled)throw Error(`slide pull session open was canceled`);let i,a=!1,o=new Ae({...t,maxByteCredit:De,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 ue(e,n,De)||(this.latchResourceFailure(e),e)}let o=Ee(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{Be(this.executeArchive,t,e,i,this.acceptSlide)}catch(e){throw this.latchResourceFailure(e),e}a=!1,i=void 0,this.sessions.delete(t.sessionId),r()},cancel:async()=>{try{this.archive()&&await this.executeArchive(e=>e.cancel_slide())}finally{i=void 0,a=!1,this.sessions.delete(t.sessionId),r()}},close:async()=>{try{this.archive()&&await this.executeArchive(e=>e.cancel_slide())}finally{i=void 0,a=!1,this.sessions.delete(t.sessionId),r()}},resourceUsage:()=>{try{return this.readResourceUsage()}catch(e){throw this.latchResourceFailure(e),e}}}});this.sessions.set(t.sessionId,{host:o,identity:t}),this.pendingOpens.delete(t.sessionId)}));this.operationTail=a.then(()=>i,()=>void 0);try{await a}catch(e){throw this.pendingOpens.delete(t.sessionId),r(),e}}async postOpenedSafely(e,t,n){if(this.lifecycleState!==`ready`){try{n(this.lifecycleError())}catch{}return}try{t()}catch(t){await this.closeIdentity(e);try{n(t)}catch{}}}dispatch(e,t){if(this.lifecycleState!==`ready`)return t(this.responseDuringReset(e)),Promise.resolve();let n=this.sessions.get(e.sessionId);if(n)return n.host.dispatch(e,t);let r=this.pendingOpens.get(e.sessionId);if(r&&(e.kind===`cancel`||e.kind===`close`)){let n=P(r.identity,e);return n&&(r.canceled=!0),t(n?{protocol:b,kind:`accepted`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,command:e.kind}:this.staleLifecycleResponse(e)),Promise.resolve()}return e.kind===`cancel`||e.kind===`close`?(t({protocol:b,kind:`accepted`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,command:e.kind}),Promise.resolve()):(t({protocol:b,kind:`error`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:y(Error(`slide pull session is not open`))}),Promise.resolve())}async dispatchSafely(e,t){try{await this.dispatch(e,t)}catch(n){try{t({protocol:b,kind:`error`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:y(n)})}catch{}}}run(e){if(this.lifecycleState!==`ready`)return Promise.reject(this.lifecycleError());let t=this.operationTail.then(()=>this.coordinator.enqueue(async()=>{if(this.resourceFailure)throw this.resourceFailure;return e()})).catch(e=>{throw this.latchResourceFailure(e),e});return this.operationTail=t.then(()=>void 0,()=>void 0),t}reset(){if(this.resetBarrier)return this.resetBarrier;this.lifecycleState=`resetting`,this.captureResetIdentities();let e=this.performReset().then(()=>{this.resetIdentities.clear(),this.lifecycleState=`ready`},e=>{throw this.lifecycleState=`reset-failed`,e}).finally(()=>{this.resetBarrier===e&&(this.resetBarrier=void 0)});return this.resetBarrier=e,e}async performReset(){for(let e of this.pendingOpens.values())e.canceled=!0;let e=1;for(let{host:t,identity:n}of[...this.sessions.values()]){let r;if(await t.dispatch({protocol:b,kind:`close`,...n,requestId:e++},e=>{e.kind===`error`&&(r=Te(e.error))}),r)throw r}this.sessions.clear(),await this.operationTail,this.pendingOpens.clear(),this.archive()&&await this.executeArchive(e=>e.close_presentation_session()),this.coordinatorGeneration=new S,this.resourceFailure=void 0}assertReady(){if(this.lifecycleState!==`ready`)throw this.lifecycleError()}lifecycleError(){let e=this.lifecycleState===`reset-failed`,t=Error(e?`slide pull worker reset failed; retry reset before new work`:`slide pull worker reset is in progress`);return t.name=`PullSessionLifecycleError`,Object.assign(t,{code:e?`ooxml-pull-reset-failed`:`ooxml-pull-resetting`})}captureResetIdentities(){for(let{identity:e}of this.sessions.values())this.resetIdentities.set(e.sessionId,e);for(let{identity:e}of this.pendingOpens.values())this.resetIdentities.set(e.sessionId,e)}responseDuringReset(e){if(e.kind===`cancel`||e.kind===`close`){let t=this.resetIdentities.get(e.sessionId);return t&&!P(t,e)?this.staleLifecycleResponse(e):{protocol:b,kind:`accepted`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,command:e.kind}}return{protocol:b,kind:`error`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:y(this.lifecycleError())}}requireArchive(){let e=this.archive();if(!e)throw Error(`Presentation not loaded`);return e}async closeIdentity(e){if(this.lifecycleState!==`ready`)return;let t=this.sessions.get(e.sessionId);if(t){await t.host.dispatch({protocol:b,kind:`close`,...e,requestId:1},()=>void 0);return}let n=this.pendingOpens.get(e.sessionId);n&&P(n.identity,e)&&(n.canceled=!0)}readResourceUsage(){return ze(this.executeArchive)}latchResourceFailure(e){let n=e instanceof t?e:Se(e);n&&(this.resourceFailure??=n)}staleLifecycleResponse(e){return{protocol:b,kind:`error`,sessionId:e.sessionId,operationId:e.operationId,generation:e.generation,requestId:e.requestId,error:{message:`stale lifecycle targets another slide operation`,errorName:`PullSessionProtocolError`,code:`ooxml-stale-lifecycle`}}}};function He(e){return!!e&&typeof e==`object`&&e.protocol===`ooxml-pull-v1`}function Ue(e){if(!Number.isSafeInteger(e.sessionId)||e.sessionId<=0)throw RangeError(`session id must be a positive safe integer`);if(!Number.isSafeInteger(e.operationId)||e.operationId<=0)throw RangeError(`operation id must be a positive safe integer`);if(!Number.isSafeInteger(e.generation)||e.generation<=0)throw RangeError(`generation must be a positive safe integer`)}function P(e,t){return e.sessionId===t.sessionId&&e.operationId===t.operationId&&e.generation===t.generation}var F=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,Ge.unregister(this),e}free(){let e=this.__destroy_into_raw();J.__wbg_pptxarchive_free(e,0)}acknowledge_slide(e,t){let n=J.pptxarchive_acknowledge_slide(this.__wbg_ptr,e,t);if(n[1])throw U(n[0])}assert_healthy(){let e=J.pptxarchive_assert_healthy(this.__wbg_ptr);if(e[1])throw U(e[0])}cancel_slide(){J.pptxarchive_cancel_slide(this.__wbg_ptr)}close_presentation_session(){J.pptxarchive_close_presentation_session(this.__wbg_ptr)}extract_image(e){let t=H(e,J.__wbindgen_malloc,J.__wbindgen_realloc),n=q,r=J.pptxarchive_extract_image(this.__wbg_ptr,t,n);if(r[3])throw U(r[2]);var i=I(r[0],r[1]).slice();return J.__wbindgen_free(r[0],r[1]*1,1),i}extract_media(e){let t=H(e,J.__wbindgen_malloc,J.__wbindgen_realloc),n=q,r=J.pptxarchive_extract_media(this.__wbg_ptr,t,n);if(r[3])throw U(r[2]);var i=I(r[0],r[1]).slice();return J.__wbindgen_free(r[0],r[1]*1,1),i}constructor(e,t,n,r){let i=qe(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,Ge.register(this,this.__wbg_ptr,this),this}parse(){let e=J.pptxarchive_parse(this.__wbg_ptr);if(e[3])throw U(e[2]);var t=I(e[0],e[1]).slice();return J.__wbindgen_free(e[0],e[1]*1,1),t}presentation_bootstrap(){let e=J.pptxarchive_presentation_bootstrap(this.__wbg_ptr);if(e[3])throw U(e[2]);var t=I(e[0],e[1]).slice();return J.__wbindgen_free(e[0],e[1]*1,1),t}pull_slide(e,t,n,r){let i=J.pptxarchive_pull_slide(this.__wbg_ptr,e,t,n,r);if(i[3])throw U(i[2]);var a=I(i[0],i[1]).slice();return J.__wbindgen_free(i[0],i[1]*1,1),a}resource_usage(){let e=J.pptxarchive_resource_usage(this.__wbg_ptr);if(e[3])throw U(e[2]);var t=I(e[0],e[1]).slice();return J.__wbindgen_free(e[0],e[1]*1,1),t}slide_cursor_resource_usage(){let e=J.pptxarchive_slide_cursor_resource_usage(this.__wbg_ptr);if(e[3])throw U(e[2]);var t=I(e[0],e[1]).slice();return J.__wbindgen_free(e[0],e[1]*1,1),t}to_markdown(){let e,t;try{let i=J.pptxarchive_to_markdown(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,U(i[2]);return e=n,t=r,R(n,r)}finally{J.__wbindgen_free(e,t,1)}}};Symbol.dispose&&(F.prototype[Symbol.dispose]=F.prototype.free);function We(){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;Ke().setInt32(e+4,i,!0),Ke().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 Ge=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>J.__wbg_pptxarchive_free(e>>>0,1));function I(e,t){return e>>>=0,B().subarray(e/1,e/1+t)}let L=null;function Ke(){return(L===null||L.buffer.detached===!0||L.buffer.detached===void 0&&L.buffer!==J.memory.buffer)&&(L=new DataView(J.memory.buffer)),L}function R(e,t){return e>>>=0,Je(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 qe(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 Je(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 Ye(e,t){return J=e.exports,L=null,z=null,J.__wbindgen_start(),J}async function Xe(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 Ze(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=We();(typeof e==`string`||typeof Request==`function`&&e instanceof Request||typeof URL==`function`&&e instanceof URL)&&(e=fetch(e));let{instance:n,module:r}=await Xe(await e,t);return Ye(n,r)}async function Qe(e){return J=void 0,L=null,z=null,Ze(e)}const Y=new ae(Ze,{freeArchive:e=>e.free(),reinit:Qe});let X=null,Z=`empty`;function $e(){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 Ve(()=>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(He(t)){await Q.dispatchSafely(t,$);return}if(t.kind===`init`){Y.setWasmInput(u(t.wasmUrl)??t.wasmUrl);return}let n=t.id,r=!1;try{if(t.kind===`openSlideSession`&&Q.reserveOpen(t),t.kind===`parse`&&($e(),r=!0),t.kind===`openSlideSession`){await Y.ensureReady(),await Q.open(t.slideIndex,t),await Q.postOpenedSafely(t,()=>$({kind:`slideSessionOpened`,id:n,sessionId:t.sessionId,operationId:t.operationId,generation:t.generation}),e=>$({kind:`error`,id:n,...y(e)}));return}t.kind===`parse`&&await Q.reset(),await Q.run(async()=>{if(await Y.ensureReady(),t.kind!==`parse`&&Y.archive){let e=Y.archive;Y.run(()=>e.assert_healthy())}if(t.kind===`parse`){X=null;let[e,r,i]=Oe(t.resourcePolicy),a=Y.run(()=>{let n=new F(new Uint8Array(t.buffer),e,r,i);return Y.setArchive(n),JSON.parse(new TextDecoder().decode(n.presentation_bootstrap()))});X=new Re(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:pe(Y.run(()=>e.resource_usage()))});return}t.kind===`toMarkdown`&&$({kind:`markdownRendered`,id:n,markdown:Y.run(()=>e.to_markdown())})})}catch(e){r&&(Z=`failed`),t.kind===`openSlideSession`&&Q.abandonOpen(t.sessionId);try{$({kind:`error`,id:n,...y(e)})}catch{}}};", $e = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", Qe], { type: "text/javascript;charset=utf-8" });
545
- function et(e) {
546
- let t;
547
- try {
548
- if (t = $e && (self.URL || self.webkitURL).createObjectURL($e), !t) throw "";
549
- let n = new Worker(t, {
550
- type: "module",
551
- name: e?.name
552
- });
553
- return n.addEventListener("error", () => {
554
- (self.URL || self.webkitURL).revokeObjectURL(t);
555
- }), n;
556
- } catch {
557
- return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(Qe), {
558
- type: "module",
559
- name: e?.name
560
- });
561
- }
562
- }
563
- //#endregion
564
- //#region packages/pptx/src/wasm/pptx_parser_bg.wasm?url
565
- var tt = new URL("pptx_parser_bg.wasm", import.meta.url).href, Y = 65536, nt = 16384, rt = new Set(["line", "straightconnector1"]);
566
- function it(e, t) {
567
- 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;
568
- return e.flipH && (l = 2 * n - l), e.flipV && (u = 2 * r - u), {
569
- x: l,
570
- y: u
571
- };
572
- }
573
- function at(e, t, n) {
574
- let r = n.x - t.x, i = n.y - t.y, a = r * r + i * i;
575
- if (a === 0) return Math.hypot(e.x - t.x, e.y - t.y);
576
- let o = Math.max(0, Math.min(1, ((e.x - t.x) * r + (e.y - t.y) * i) / a));
577
- return Math.hypot(e.x - (t.x + o * r), e.y - (t.y + o * i));
578
- }
579
- function ot(e, t, n = 0) {
580
- if (!Number.isFinite(t.x) || !Number.isFinite(t.y)) return !1;
581
- let r = it(e, t), i = Number.isFinite(n) && n > 0 ? n : 0;
582
- if (e.type === "shape" && (rt.has(e.geometry.toLowerCase()) || e.width === 0 || e.height === 0)) return at(r, {
583
- x: e.x,
584
- y: e.y
585
- }, {
586
- x: e.x + e.width,
587
- y: e.y + e.height
588
- }) <= i;
589
- 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);
590
- return r.x >= a && r.x <= o && r.y >= s && r.y <= c;
591
- }
592
- function* st(e) {
593
- if (e) for (let t of e.paragraphs) {
594
- let e = !0;
595
- for (let n of t.runs) {
596
- let t = n.type === "text" ? n.text : n.type === "break" ? "\n" : "[equation]";
597
- t && (yield {
598
- text: t,
599
- beginsPart: e
600
- }, e = !1);
601
- }
602
- }
603
- }
604
- function* ct(e) {
605
- if (e.type === "shape") {
606
- yield* st(e.textBody);
607
- return;
608
- }
609
- if (e.type === "table") {
610
- for (let t of e.rows) for (let e of t.cells) yield* st(e.textBody);
611
- return;
612
- }
613
- }
614
- function lt(e, t) {
615
- let n = Math.min(e.length, t);
616
- if (n > 0 && n < e.length) {
617
- let t = e.charCodeAt(n - 1), r = e.charCodeAt(n);
618
- t >= 55296 && t <= 56319 && r >= 56320 && r <= 57343 && n--;
619
- }
620
- return e.slice(0, n);
621
- }
622
- function ut(e, t = nt) {
623
- if (!Number.isFinite(t) || t < 0) throw RangeError("maxTextCharacters must be a finite non-negative number.");
624
- let n = Math.min(Y, Math.floor(t)), r = e.text, i = r === void 0 ? void 0 : lt(r, n), a = r !== void 0 && i.length < r.length;
625
- return {
626
- ...structuredClone(e),
627
- ...i === void 0 ? {} : { text: i },
628
- truncated: e.truncated || a,
629
- truncationReasons: e.truncated || a ? ["text"] : [],
630
- textCharacters: i?.length ?? 0,
631
- maxTextCharacters: n
632
- };
633
- }
634
- function dt(e, t) {
635
- let n = [], r = 0, i = !1, a = !1;
636
- for (let o of e) {
637
- if (a = !0, o.beginsPart && n.length > 0) {
638
- if (r >= t) {
639
- i = !0;
640
- break;
641
- }
642
- n.push("\n"), r++;
643
- }
644
- let e = Math.max(0, t - r), s = lt(o.text, e);
645
- if (n.push(s), r += s.length, s.length < o.text.length) {
646
- i = !0;
647
- break;
648
- }
649
- }
650
- return a ? {
651
- text: n.join(""),
652
- truncated: i,
653
- textCharacters: r
654
- } : {
655
- truncated: !1,
656
- textCharacters: 0
657
- };
658
- }
659
- function ft(e, t, n, r = {}) {
660
- if (!Number.isFinite(n.x) || !Number.isFinite(n.y)) throw RangeError("PPTX hit-test point must contain finite coordinates.");
661
- let i = r.maxTextCharacters ?? nt;
662
- if (!Number.isFinite(i) || i < 0) throw RangeError("maxTextCharacters must be a finite non-negative number.");
663
- let a = Math.min(Y, Math.floor(i)), o = r.tolerance ?? 0;
664
- if (!Number.isFinite(o) || o < 0) throw RangeError("tolerance must be a finite non-negative number.");
665
- for (let r = t.elements.length - 1; r >= 0; r--) {
666
- let i = t.elements[r];
667
- if (!ot(i, n, o)) continue;
668
- let s = i.type === "chart" ? oe(i.chart, a) : dt(ct(i), a);
669
- return {
670
- format: "pptx",
671
- kind: "element",
672
- slideIndex: e,
673
- elementIndex: r,
674
- origin: t.elementSources?.[r]?.origin ?? "unknown",
675
- elementType: i.type,
676
- point: { ...n },
677
- bounds: {
678
- x: i.x,
679
- y: i.y,
680
- width: i.width,
681
- height: i.height,
682
- rotation: i.rotation,
683
- flipH: i.flipH,
684
- flipV: i.flipV
685
- },
686
- ...i.type === "shape" ? {
687
- ...i.id === void 0 ? {} : { shapeId: i.id },
688
- ...i.name === void 0 ? {} : { name: i.name },
689
- geometry: i.geometry
690
- } : {},
691
- ...s.text === void 0 ? {} : { text: s.text },
692
- ...i.type === "picture" ? { mimeType: i.mimeType } : {},
693
- ...i.type === "media" ? {
694
- mimeType: i.mimeType,
695
- mediaKind: i.mediaKind
696
- } : {},
697
- ...i.type === "table" ? {
698
- rowCount: i.rows.length,
699
- columnCount: i.cols.length
700
- } : {},
701
- ...i.type === "chart" ? { seriesCount: i.chart.series.length } : {},
702
- truncated: s.truncated,
703
- truncationReasons: s.truncated ? ["text"] : [],
704
- textCharacters: s.textCharacters,
705
- maxTextCharacters: a
706
- };
707
- }
708
- return null;
709
- }
710
- //#endregion
711
- //#region packages/pptx/src/presentation.ts
712
- var X = class e {
713
- _metrics = null;
714
- _worker;
715
- _bridge;
716
- _mode = "main";
717
- _preflight = null;
718
- _slides = null;
719
- _slidePullClient = null;
720
- _resourceFailure = null;
721
- _slidePartIndex = null;
722
- _rawParts = new Se({
723
- maxEntries: 64,
724
- maxBytes: C
725
- });
726
- _googleFontFaces = [];
727
- _fetchImage = (e, t) => this.getImage(e, t);
728
- _fetchMedia = (e) => this.getMedia(e);
729
- _math;
730
- _threeD;
731
- _regionMap;
732
- constructor(e, t, n) {
733
- this._worker = e, this._mode = t, this._bridge = new te(this._worker, {
734
- correlate: (e) => "protocol" in e && e.protocol === "ooxml-pull-v1" ? e.requestId : "id" in e ? e.id : void 0,
735
- toError: (e) => !("protocol" in e) && e.kind === "error" ? y(e) : void 0
736
- });
737
- let r = new URL(n ?? tt, location.href).href;
738
- this._bridge.post({
739
- kind: "init",
740
- wasmUrl: r
741
- });
742
- }
743
- _assertResourceHealthy() {
744
- if (this._resourceFailure) throw this._resourceFailure;
745
- }
746
- _rethrowWithResourceFailure(e) {
747
- let t = e instanceof x ? e : g(e);
748
- throw t ? (this._resourceFailure ??= t, this._resourceFailure) : e;
749
- }
750
- static async load(t, n = {}) {
751
- let r = u(n), i = n.mode ?? "main", a = new p({
752
- enabled: !0,
753
- format: "pptx",
754
- mode: i,
755
- policy: r.policy,
756
- onMetrics: r.onResourceMetrics,
757
- emitToConsole: r.debug
758
- });
759
- try {
760
- if (i === "worker" && (typeof Worker > "u" || typeof OffscreenCanvas > "u")) throw Error("mode: 'worker' requires Worker and OffscreenCanvas support");
761
- let s;
762
- if (typeof t == "string") {
763
- let e = await fetch(t);
764
- if (!e.ok) throw Error(`Failed to fetch: ${e.status} ${e.statusText}`);
765
- s = await e.arrayBuffer();
766
- } else s = t;
767
- s = ne(await ie(s, n.password)), a.setSourceBytes(s.byteLength), a.checkpoint("container ready");
768
- let c = i === "worker" ? (await import("./render-worker-host-CYPhmBtX.js")).createRenderWorker() : new et(), l = i === "worker" ? we(n) : void 0, u;
769
- try {
770
- 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, 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 be(u._preflight.fontPreloadNames, o)), a.succeed({ slides: u.slideCount }), u;
771
- } catch (e) {
772
- let t = u;
773
- throw re(c, t ? () => t.destroy() : void 0), e;
774
- }
775
- } catch (e) {
776
- throw a.fail(e), e;
777
- }
778
- }
779
- async _parse(e, n, i = !1, o, s, c) {
780
- let u = await this._bridge.request((t) => this._mode === "worker" ? {
781
- kind: "parse",
782
- id: t,
783
- buffer: e,
784
- resourcePolicy: n,
785
- useGoogleFonts: i,
786
- renderers: c
787
- } : {
788
- kind: "parse",
789
- id: t,
790
- buffer: e,
791
- resourcePolicy: n
792
- }, [e], { timeoutMs: o });
793
- if (this._mode === "worker") {
794
- let e = u;
795
- e.usage && s?.(e.usage), this._preflight = t(u.preflight);
796
- return;
797
- }
798
- let f = r(u.bootstrap);
799
- this._slidePullClient = new l({
800
- slideCount: f.slideCount,
801
- transport: this._bridge.transport(a),
802
- open: async (e, t, n) => {
803
- await this._bridge.request((n) => ({
804
- kind: "openSlideSession",
805
- id: n,
806
- slideIndex: e,
807
- ...t
808
- }), void 0, { timeoutMs: n });
809
- },
810
- onUsage: s
811
- });
812
- for (let e = 0; e < f.slideCount; e += 1) await this._slidePullClient.load(e, !1, o);
813
- this._preflight = t((await this._bridge.request((e) => ({
814
- kind: "finishPresentationPreflight",
815
- id: e
816
- }), void 0, { timeoutMs: o })).preflight), this._slides = new Xe({
817
- slideCount: this._preflight.slideCount,
818
- maxCachedSlides: 8,
819
- maxCachedStructuralBytes: d,
820
- loadSlide: async (e) => {
821
- let t = await this._slidePullClient?.load(e, !0);
822
- if (!t) throw Error("PPTX slide pull client is unavailable");
823
- return t;
824
- }
825
- });
826
- }
827
- get slideCount() {
828
- return this._preflight?.slideCount ?? 0;
829
- }
830
- get slideWidth() {
831
- return this._preflight?.slideWidth ?? 0;
832
- }
833
- get slideHeight() {
834
- return this._preflight?.slideHeight ?? 0;
835
- }
836
- get mode() {
837
- return this._mode;
838
- }
839
- getNotes(e) {
840
- return Number.isInteger(e) ? this._preflight?.slides[e]?.notes ?? null : null;
841
- }
842
- isHidden(e) {
843
- return Number.isInteger(e) ? this._preflight?.slides[e]?.hidden ?? !1 : !1;
844
- }
845
- _partNames() {
846
- return (this._preflight?.slides ?? []).map((e) => e.partName);
847
- }
848
- _partIndex() {
849
- return this._slidePartIndex ||= qe(this._partNames()), this._slidePartIndex;
850
- }
851
- getSlideIndexByPartName(e) {
852
- return this._partIndex().get(e);
853
- }
854
- resolveInternalTarget(e, t = 0) {
855
- return Ye(e, this._partIndex(), t);
856
- }
857
- async renderSlide(e, t, r = {}) {
858
- this._assertResourceHealthy();
859
- try {
860
- if (this._mode === "worker") throw Error("renderSlide(canvas) is unavailable in mode: 'worker'; use renderSlideToBitmap() and paint it via an ImageBitmapRenderingContext");
861
- let i = this._preflight, a = this._slides;
862
- if (!i || !a) throw Error("Presentation not loaded");
863
- let o = r.dpr ?? S(), s = r.width ?? ((v(e) ? e.offsetWidth : 0) || 960);
864
- await a.withSlide(t, (t) => (this._assertResourceHealthy(), n(e, t, i.slideWidth, i.slideHeight, {
865
- width: s,
866
- dpr: o,
867
- defaultTextColor: i.defaultTextColor,
868
- majorFont: i.majorFont,
869
- minorFont: i.minorFont,
870
- hlinkColor: i.hlinkColor,
871
- fetchMedia: this._fetchMedia,
872
- fetchImage: this._fetchImage,
873
- skipMediaControls: r.skipMediaControls,
874
- dim: r.dim,
875
- math: this._math,
876
- threeD: this._threeD,
877
- regionMap: this._regionMap
878
- }, r.onTextRun)));
879
- } catch (e) {
880
- this._rethrowWithResourceFailure(e);
881
- }
882
- }
883
- async renderSlideToBitmap(e, t = {}) {
884
- this._assertResourceHealthy();
885
- try {
886
- let n = t.width ?? 960, r = t.dpr ?? S();
887
- if (this._mode === "worker") {
888
- if (!Number.isInteger(e) || e < 0 || e >= this.slideCount) throw Error(`Slide index ${e} out of range (count: ${this.slideCount})`);
889
- let i = await this._bridge.request((i) => ({
890
- kind: "renderSlide",
891
- id: i,
892
- slideIndex: e,
893
- width: n,
894
- dpr: r,
895
- skipMediaControls: t.skipMediaControls,
896
- dim: t.dim
897
- }));
898
- if (t.onTextRun) for (let e of i.runs) t.onTextRun(e);
899
- return i.bitmap;
900
- }
901
- let i = new OffscreenCanvas(1, 1);
902
- return await this.renderSlide(i, e, {
903
- width: n,
904
- dpr: r,
905
- skipMediaControls: t.skipMediaControls,
906
- dim: t.dim,
907
- onTextRun: t.onTextRun
908
- }), i.transferToImageBitmap();
909
- } catch (e) {
910
- this._rethrowWithResourceFailure(e);
911
- }
912
- }
913
- async collectSlideRuns(e, t = 960) {
914
- this._assertResourceHealthy();
915
- try {
916
- if (this._mode === "worker") {
917
- if (!Number.isInteger(e) || e < 0 || e >= this.slideCount) throw Error(`Slide index ${e} out of range (count: ${this.slideCount})`);
918
- return (await this._bridge.request((n) => ({
919
- kind: "collectRuns",
920
- id: n,
921
- slideIndex: e,
922
- width: t
923
- }))).runs;
924
- }
925
- let n = [], r = new OffscreenCanvas(1, 1);
926
- return await this.renderSlide(r, e, {
927
- width: t,
928
- onTextRun: (e) => n.push(e)
929
- }), n;
930
- } catch (e) {
931
- this._rethrowWithResourceFailure(e);
932
- }
933
- }
934
- async getElementContextAt(e, t, n = {}) {
935
- if (this._assertResourceHealthy(), !Number.isInteger(e) || e < 0 || e >= this.slideCount) throw Error(`Slide index ${e} out of range (count: ${this.slideCount})`);
936
- try {
937
- if (this._mode === "worker") return (await this._bridge.request((r) => ({
938
- kind: "hitTestElement",
939
- id: r,
940
- slideIndex: e,
941
- point: t,
942
- options: n
943
- }))).context;
944
- if (!this._slides) throw Error("Presentation not loaded");
945
- return await this._slides.withSlide(e, (r) => ft(e, r, t, n));
946
- } catch (e) {
947
- this._rethrowWithResourceFailure(e);
948
- }
949
- }
950
- async getMedia(e) {
951
- this._assertResourceHealthy();
952
- try {
953
- let t = this._findMimeTypeForPath(e);
954
- return await this._rawParts.get(e, t, async () => {
955
- let n = (await this._bridge.request((t) => ({
956
- kind: "extractMedia",
957
- id: t,
958
- path: e
959
- }))).bytes;
960
- return new Blob([n], { type: t });
961
- });
962
- } catch (e) {
963
- this._rethrowWithResourceFailure(e);
964
- }
965
- }
966
- _findMimeTypeForPath(e) {
967
- return this._preflight ? s(this._preflight, e) : "";
968
- }
969
- async getImage(e, t) {
970
- this._assertResourceHealthy();
971
- try {
972
- return await this._rawParts.get(e, t, async () => {
973
- let n = (await this._bridge.request((t) => ({
974
- kind: "extractImage",
975
- id: t,
976
- path: e
977
- }))).bytes;
978
- return new Blob([n], { type: t });
979
- });
980
- } catch (e) {
981
- this._rethrowWithResourceFailure(e);
982
- }
983
- }
984
- async getResourceMetrics() {
985
- let e = this._metrics;
986
- if (!e) throw Error("Presentation not loaded");
987
- return w(e, async (e) => (await this._bridge.request((e) => ({
988
- kind: "resourceUsage",
989
- id: e
990
- }), void 0, { timeoutMs: e })).usage);
991
- }
992
- async toMarkdown() {
993
- this._assertResourceHealthy();
994
- try {
995
- return (await this._bridge.request((e) => ({
996
- kind: "toMarkdown",
997
- id: e
998
- }))).markdown;
999
- } catch (e) {
1000
- this._rethrowWithResourceFailure(e);
1001
- }
1002
- }
1003
- async presentSlide(e, t, n = {}) {
1004
- this._assertResourceHealthy();
1005
- try {
1006
- if (!this._preflight) throw Error("Presentation not loaded");
1007
- if (!Number.isInteger(t) || t < 0 || t >= this.slideCount) throw Error(`Slide index ${t} out of range (count: ${this.slideCount})`);
1008
- let r = n.dpr ?? S(), i = n.width ?? (e.offsetWidth || 960), a = this._mode === "worker" ? async () => {
1009
- let a = await this.renderSlideToBitmap(t, {
1010
- width: i,
1011
- dpr: r,
1012
- skipMediaControls: !0,
1013
- dim: n.dim,
1014
- onTextRun: n.onTextRun
1015
- });
1016
- e.width = a.width, e.height = a.height, e.style.width = `${Math.round(a.width / r)}px`, e.style.display || (e.style.display = "block");
1017
- let o = e.getContext("2d");
1018
- if (!o) throw Error("2D context not available");
1019
- o.drawImage(a, 0, 0), a.close();
1020
- } : () => this.renderSlide(e, t, {
1021
- width: i,
1022
- dpr: r,
1023
- skipMediaControls: !0,
1024
- dim: n.dim,
1025
- onTextRun: n.onTextRun
1026
- });
1027
- return await Me(e, this._preflight.slides[t]?.mediaElements ?? [], {
1028
- width: i,
1029
- dpr: r,
1030
- slideWidthEmu: this.slideWidth,
1031
- fetchMedia: this._fetchMedia,
1032
- fetchImage: this._fetchImage,
1033
- drawBase: a,
1034
- onError: n.onError
1035
- });
1036
- } catch (e) {
1037
- this._rethrowWithResourceFailure(e);
1038
- }
1039
- }
1040
- destroy() {
1041
- 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 && (ye(this._googleFontFaces), this._googleFontFaces = []), b(this._fetchImage), f(this._fetchImage);
1042
- }
1043
- };
1044
- //#endregion
1045
- //#region packages/pptx/src/selection-context.ts
1046
- function Z(e) {
1047
- if (e === void 0 || !/^\d+$/.test(e)) return null;
1048
- let t = Number(e);
1049
- return Number.isSafeInteger(t) ? t : null;
1050
- }
1051
- function pt(e) {
1052
- for (let t = e; t; t = t.parentElement) {
1053
- let e = Z(t.dataset.slideIndex);
1054
- if (e !== null) return e;
1055
- }
1056
- return null;
1057
- }
1058
- function Q(e, t, n = {}) {
1059
- let r = he(e, t, (e) => {
1060
- let t = pt(e), n = Z(e.dataset.runIndex);
1061
- if (t === null || n === null) return null;
1062
- let r = Z(e.dataset.elementIndex), i = e.dataset.elementOrigin, a = r !== null && (i === "master" || i === "layout" || i === "slide");
1063
- return {
1064
- slideIndex: t,
1065
- runIndex: n,
1066
- ...e.dataset.shapeId === void 0 ? {} : { shapeId: e.dataset.shapeId },
1067
- ...a ? {
1068
- elementIndex: r,
1069
- origin: i
1070
- } : {}
1071
- };
1072
- }, {
1073
- maxChars: n.maxTextCharacters,
1074
- maxLocators: n.maxRunLocators
1075
- });
1076
- if (!r) return null;
1077
- let i = [...r.locators].sort((e, t) => e.slideIndex - t.slideIndex || e.runIndex - t.runIndex);
1078
- return {
1079
- format: "pptx",
1080
- kind: "text",
1081
- text: r.text,
1082
- slideIndexes: [...new Set(i.map((e) => e.slideIndex))],
1083
- shapeIds: [...new Set(i.flatMap((e) => e.shapeId ? [e.shapeId] : []))],
1084
- runs: i,
1085
- truncated: r.truncated,
1086
- truncationReasons: r.truncationReasons,
1087
- textCharacters: r.textCharacters,
1088
- maxTextCharacters: r.maxTextCharacters,
1089
- maxRunLocators: r.maxLocators
1090
- };
1091
- }
1092
- //#endregion
1093
- //#region packages/pptx/src/viewer.ts
1094
- var mt = Symbol("PptxViewer.borrowedPresentation"), ht = {
1095
- color: "#ffffff",
1096
- opacity: .6
1097
- }, gt = class e {
1098
- canvas;
1099
- wrapper;
1100
- canvasMount;
1101
- _scale = null;
1102
- textLayer = null;
1103
- highlightLayer = null;
1104
- elementLayer = null;
1105
- _find;
1106
- _measureCtx = null;
1107
- presentationOwner;
1108
- get engine() {
1109
- return this.presentationOwner.current;
1110
- }
1111
- borrowed;
1112
- hostWindow;
1113
- opts;
1114
- currentSlide = 0;
1115
- _hiddenMode;
1116
- handle = null;
1117
- _mode;
1118
- renderDispatcher;
1119
- errorRouter;
1120
- destroyed = !1;
1121
- selectionChangeListener = null;
1122
- selectionContextKey = "null";
1123
- elementClickListener = null;
1124
- contextMenuListener = null;
1125
- elementContext = null;
1126
- elementHitGeneration = 0;
1127
- elementHitTolerance;
1128
- static fromPresentation(t, n, r = {}) {
1129
- return new e(t, {
1130
- ...r,
1131
- [mt]: n
1132
- });
1133
- }
1134
- constructor(e, t = {}) {
1135
- this.opts = t, this.canvas = e;
1136
- let n = t[mt];
1137
- this.borrowed = n !== void 0, this._mode = k("PptxViewer", t.mode, n), this.presentationOwner = new E("PptxViewer", n ?? null, !1);
1138
- let r = e.ownerDocument?.defaultView ?? (typeof window < "u" ? window : null);
1139
- if (!r) throw Error("PptxViewer requires a canvas with an active Window");
1140
- this.hostWindow = r;
1141
- let i = t.elementHitTolerance ?? 6;
1142
- if (!Number.isFinite(i) || i < 0) throw RangeError("elementHitTolerance must be a finite non-negative number.");
1143
- this.elementHitTolerance = i, this._hiddenMode = t.hiddenSlideMode ?? "show", this.canvasMount = new ge(e, {
1144
- wrapperCssText: "position:relative;display:inline-block;vertical-align:top;",
1145
- forceDisplayBlock: !0
1146
- }), this.wrapper = this.canvasMount.wrapper, this.renderDispatcher = new O(e, this._mode === "worker" && !t.enableMediaPlayback), this.errorRouter = new me("PptxViewer", t.onError);
1147
- let a = new de(this.wrapper, t.enableTextSelection === !0, t.enableElementSelection === !0);
1148
- 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) => {
1149
- this._onElementClick(e).catch((e) => this._reportRenderError(e));
1150
- }, this.wrapper.addEventListener("click", this.elementClickListener)), t.onContextMenu && (this.contextMenuListener = (e) => this._onContextMenu(e), this.wrapper.addEventListener("contextmenu", this.contextMenuListener)), this._find = new z(() => this.slideCount, (e) => this._collectSlideRuns(e));
1151
- }
1152
- async load(e) {
1153
- if (this.destroyed) throw Error("PptxViewer is destroyed");
1154
- if (this.borrowed) throw Error("PptxViewer.load() is unsupported on a Viewer created by fromPresentation(); the borrowed presentation is already loaded.");
1155
- let t = !1;
1156
- try {
1157
- if (!await this.presentationOwner.replace(() => X.load(e, {
1158
- password: this.opts.password,
1159
- useGoogleFonts: this.opts.useGoogleFonts,
1160
- maxZipEntryBytes: this.opts.maxZipEntryBytes,
1161
- resourceLimits: this.opts.resourceLimits,
1162
- debug: this.opts.debug,
1163
- onResourceMetrics: this.opts.onResourceMetrics,
1164
- workerTimeoutMs: this.opts.workerTimeoutMs,
1165
- wasmUrl: this.opts.wasmUrl,
1166
- math: this.opts.math,
1167
- threeD: this.opts.threeD,
1168
- regionMap: this.opts.regionMap,
1169
- mode: this._mode
1170
- }), () => {
1171
- this._invalidateElementSelection(!1), t = !0, this.renderDispatcher.begin(), this._find.invalidate(), this.handle?.destroy(), this.handle = null;
1172
- })) return;
1173
- if (this.destroyed) throw Error("PptxViewer is destroyed");
1174
- this.currentSlide = this._initialSlide(), this._find.invalidate(), await this.renderCurrentSlide();
1175
- } catch (e) {
1176
- throw this.destroyed ? Error("PptxViewer is destroyed") : e instanceof Error ? e : Error(String(e));
1177
- }
1178
- t && !this.destroyed && this._emitSelectionContextChange();
1179
- }
1180
- async goToSlide(e) {
1181
- if (!this.engine || this.slideCount === 0) return;
1182
- let t = Math.max(0, Math.min(e, this.slideCount - 1)), n = t !== this.currentSlide;
1183
- n && this._invalidateElementSelection(!1), this.currentSlide = t, await this.renderCurrentSlide(), n && !this.destroyed && this._emitSelectionContextChange();
1184
- }
1185
- async nextSlide() {
1186
- await this.goToSlide(this._step(1));
1187
- }
1188
- async prevSlide() {
1189
- await this.goToSlide(this._step(-1));
1190
- }
1191
- _step(e) {
1192
- return this._hiddenMode === "skip" && this.engine ? Te(this.currentSlide, e, (e) => this.engine.isHidden(e), this.slideCount) : this.currentSlide + e;
1193
- }
1194
- _initialSlide() {
1195
- return this._hiddenMode === "skip" && this.engine ? N(0, (e) => this.engine.isHidden(e), this.slideCount) : 0;
1196
- }
1197
- _dim() {
1198
- return {
1199
- color: this.opts.hiddenSlideDim?.color ?? ht.color,
1200
- opacity: this.opts.hiddenSlideDim?.opacity ?? ht.opacity
1201
- };
1202
- }
1203
- async setHiddenSlideMode(e) {
1204
- this._hiddenMode = e;
1205
- let t = this.currentSlide;
1206
- e === "skip" && this.engine && (t = N(this.currentSlide, (e) => this.engine.isHidden(e), this.slideCount));
1207
- let n = t !== this.currentSlide;
1208
- n && this._invalidateElementSelection(!1), this.currentSlide = t, await this.renderCurrentSlide(), n && !this.destroyed && this._emitSelectionContextChange();
1209
- }
1210
- get hiddenSlideMode() {
1211
- return this._hiddenMode;
1212
- }
1213
- get visibleSlideCount() {
1214
- if (!this.engine) return 0;
1215
- let e = this.engine;
1216
- return Ee((t) => e.isHidden(t), this.slideCount);
1217
- }
1218
- get slideIndex() {
1219
- return this.currentSlide;
1220
- }
1221
- get slideCount() {
1222
- return this.engine?.slideCount ?? 0;
1223
- }
1224
- getNotes(e) {
1225
- return this.engine?.getNotes(e) ?? null;
1226
- }
1227
- get canvasElement() {
1228
- return this.canvas;
1229
- }
1230
- _naturalWidthPx() {
1231
- let e = this.engine?.slideWidth ?? 0;
1232
- return e > 0 ? e / M : 0;
1233
- }
1234
- _targetWidth() {
1235
- if (this._scale === null) return this.opts.width ?? (this.canvas.offsetWidth || 960);
1236
- let e = this._naturalWidthPx();
1237
- return e <= 0 ? this.opts.width ?? (this.canvas.offsetWidth || 960) : Math.round(e * this._scale);
1238
- }
1239
- getScale() {
1240
- if (this._scale !== null) return this._scale;
1241
- let e = this._naturalWidthPx();
1242
- return e <= 0 ? 1 : this._targetWidth() / e;
1243
- }
1244
- _zoomMin() {
1245
- return this.opts.zoomMin ?? .1;
1246
- }
1247
- _zoomMax() {
1248
- return this.opts.zoomMax ?? 4;
1249
- }
1250
- async setScale(e) {
1251
- let t = ce(e, this._zoomMin(), this._zoomMax()), n = t !== this.getScale();
1252
- this._scale = t, await this.renderCurrentSlide(), n && this.opts.onScaleChange?.(t);
1253
- }
1254
- async zoomIn() {
1255
- await this.setScale(A(this.getScale()));
1256
- }
1257
- async zoomOut() {
1258
- await this.setScale(j(this.getScale()));
1259
- }
1260
- async fitWidth() {
1261
- await this._fit("width");
1262
- }
1263
- async fitPage() {
1264
- await this._fit("page");
1265
- }
1266
- async _fit(e) {
1267
- if (!this.engine) return;
1268
- let t = this.wrapper.parentElement;
1269
- if (!t) return;
1270
- let n = T({
1271
- contentWidth: this.engine.slideWidth / M,
1272
- contentHeight: this.engine.slideHeight / M,
1273
- containerWidth: t.clientWidth,
1274
- containerHeight: t.clientHeight
1275
- }, e);
1276
- n <= 0 || await this.setScale(n);
1277
- }
1278
- async renderCurrentSlide() {
1279
- if (!this.engine) return;
1280
- 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);
1281
- this.canvas.style.width = `${n}px`, this.canvas.style.height = `${a}px`, this.handle?.destroy(), this.handle = null;
1282
- let o = this._mode === "worker", s = [], c = (e) => s.push(e);
1283
- try {
1284
- if (this.opts.enableMediaPlayback) {
1285
- let i = await this.engine.presentSlide(this.canvas, this.currentSlide, {
1286
- width: n,
1287
- dpr: r,
1288
- dim: t,
1289
- onTextRun: c,
1290
- onError: (t) => {
1291
- this.renderDispatcher.isCurrent(e) && this._reportRenderError(t);
1292
- }
1293
- });
1294
- if (!this.renderDispatcher.isCurrent(e)) {
1295
- i.destroy();
1296
- return;
1297
- }
1298
- this.handle = i;
1299
- } else if (o) {
1300
- let i = await this.engine.renderSlideToBitmap(this.currentSlide, {
1301
- width: n,
1302
- dpr: r,
1303
- dim: t,
1304
- onTextRun: c
1305
- });
1306
- if (!this.renderDispatcher.commitBitmap(e, i)) return;
1307
- } else if (await this.engine.renderSlide(this.canvas, this.currentSlide, {
1308
- width: n,
1309
- dpr: r,
1310
- onTextRun: c,
1311
- dim: t
1312
- }), !this.renderDispatcher.isCurrent(e)) return;
1313
- this.opts.onSlideChange?.(this.currentSlide, this.slideCount);
1314
- } catch (t) {
1315
- if (!this.renderDispatcher.isCurrent(e)) return;
1316
- throw t;
1317
- }
1318
- this.textLayer && this._buildTextLayer(this.textLayer, s, n, a), this._find.setSlideRuns(this.currentSlide, s), this._buildHighlightLayer(s, n, a);
1319
- }
1320
- _buildHighlightLayer(e, t, n) {
1321
- let r = this.highlightLayer;
1322
- r && R(r, e, this._find.slideHighlights(this.currentSlide), t, n, (e) => this._measureForFont(e), this.opts.findHighlightColors);
1323
- }
1324
- _measureForFont(e) {
1325
- this._measureCtx ||= document.createElement("canvas").getContext("2d");
1326
- let t = this._measureCtx;
1327
- return t ? (t.font = e, (e) => t.measureText(e).width) : (e) => e.length;
1328
- }
1329
- async _collectSlideRuns(e) {
1330
- return this.engine ? this.engine.collectSlideRuns(e, this._targetWidth()) : [];
1331
- }
1332
- async findText(e, t = {}) {
1333
- if (!this.engine) return [];
1334
- let n = await this._find.find(e, t);
1335
- return this._redrawHighlights(), n;
1336
- }
1337
- async findNext() {
1338
- return this._activateMatch(this._find.next());
1339
- }
1340
- async findPrev() {
1341
- return this._activateMatch(this._find.prev());
1342
- }
1343
- clearFind() {
1344
- this._find.invalidate(), this._redrawHighlights();
1345
- }
1346
- async _activateMatch(e) {
1347
- return e ? (e.location.slide === this.currentSlide ? this._redrawHighlights() : await this.goToSlide(e.location.slide), e) : (this._redrawHighlights(), null);
1348
- }
1349
- _redrawHighlights() {
1350
- let e = this._find.slideRuns(this.currentSlide) ?? [], t = this._targetWidth(), n = this.engine ? Math.round(this.engine.slideHeight * (t / this.engine.slideWidth)) : 0;
1351
- this._buildHighlightLayer(e, t, n);
1352
- }
1353
- _buildTextLayer(e, t, n, r) {
1354
- L(e, t, n, r, this._hyperlinkHandler(), this.currentSlide);
1355
- }
1356
- _hyperlinkHandler() {
1357
- if (this.opts.enableHyperlinks !== !1) return (e) => this._onHyperlinkClick(e);
1358
- }
1359
- _onHyperlinkClick(e) {
1360
- let t = this._resolveInternalSlideIndex(e);
1361
- if (this.opts.onHyperlinkClick) {
1362
- this.opts.onHyperlinkClick(t);
1363
- return;
1364
- }
1365
- if (t.kind === "external") {
1366
- h(t.url, void 0, this.hostWindow);
1367
- return;
1368
- }
1369
- t.slideIndex !== void 0 && this.goToSlide(t.slideIndex).catch((e) => this._reportRenderError(e));
1370
- }
1371
- _resolveInternalSlideIndex(e) {
1372
- if (e.kind !== "internal" || e.slideIndex !== void 0) return e;
1373
- let t = this.engine?.resolveInternalTarget(e.ref, this.currentSlide);
1374
- return t === void 0 ? e : {
1375
- ...e,
1376
- slideIndex: t
1377
- };
1378
- }
1379
- _reportRenderError(e) {
1380
- this.errorRouter.report(e);
1381
- }
1382
- async getResourceMetrics() {
1383
- if (!this.engine) throw Error("Presentation not loaded");
1384
- return await this.engine.getResourceMetrics();
1385
- }
1386
- getSelectionContext(e = {}) {
1387
- if (this.destroyed) throw Error("PptxViewer is destroyed");
1388
- return (this.textLayer ? Q(this.wrapper, this.wrapper.ownerDocument?.getSelection?.() ?? null, e) : null) ?? (this.elementContext ? ut(this.elementContext, e.maxTextCharacters) : null);
1389
- }
1390
- _emitSelectionContextChange() {
1391
- let e = this.getSelectionContext();
1392
- e?.kind === "text" && (this.elementHitGeneration++, this.elementContext = null, this._redrawElementOutline());
1393
- let t = JSON.stringify(e);
1394
- t !== this.selectionContextKey && (this.selectionContextKey = t, this.opts.onSelectionContextChange?.(e ? structuredClone(e) : null));
1395
- }
1396
- _setElementContext(e) {
1397
- this.elementContext = e ? structuredClone(e) : null, this._redrawElementOutline(), this._emitSelectionContextChange();
1398
- }
1399
- _invalidateElementSelection(e = !0) {
1400
- this.elementHitGeneration++, this.elementContext = null, this._redrawElementOutline(), e && this._emitSelectionContextChange();
1401
- }
1402
- _redrawElementOutline() {
1403
- let e = this.elementContext, t = this.engine;
1404
- if (!e || !t || e.slideIndex !== this.currentSlide) {
1405
- D(this.elementLayer, null);
1406
- return;
1407
- }
1408
- D(this.elementLayer, {
1409
- x: e.bounds.x / t.slideWidth,
1410
- y: e.bounds.y / t.slideHeight,
1411
- width: e.bounds.width / t.slideWidth,
1412
- height: e.bounds.height / t.slideHeight,
1413
- rotation: e.bounds.rotation
1414
- });
1415
- }
1416
- async _onElementClick(e) {
1417
- this.destroyed || e.defaultPrevented || e.button !== 0 || await this._resolveContextAt(e);
1418
- }
1419
- _onContextMenu(e) {
1420
- let t;
1421
- this.opts.onContextMenu?.({
1422
- originalEvent: e,
1423
- getContext: () => t ??= this._resolveContextAt(e)
1424
- });
1425
- }
1426
- async _resolveContextAt(e) {
1427
- let t = this.engine;
1428
- if (this.destroyed || !t) return null;
1429
- if (this.textLayer && Q(this.wrapper, this.wrapper.ownerDocument?.getSelection?.() ?? null)) return this._emitSelectionContextChange(), this.destroyed ? null : this.getSelectionContext();
1430
- if (!this.opts.enableElementSelection) return this.getSelectionContext();
1431
- let n = this.canvas.getBoundingClientRect();
1432
- if (n.width <= 0 || n.height <= 0) return this._invalidateElementSelection(), null;
1433
- let r = e.clientX - n.left, i = e.clientY - n.top;
1434
- if (r < 0 || i < 0 || r > n.width || i > n.height) return this._invalidateElementSelection(), null;
1435
- let a = ++this.elementHitGeneration, o = this.currentSlide, s = {
1436
- x: r / n.width * t.slideWidth,
1437
- y: i / n.height * t.slideHeight
1438
- }, c;
1439
- try {
1440
- c = await t.getElementContextAt(o, s, {
1441
- tolerance: this.elementHitTolerance / n.width * t.slideWidth,
1442
- maxTextCharacters: Y
1443
- });
1444
- } catch (e) {
1445
- if (this.destroyed || a !== this.elementHitGeneration || o !== this.currentSlide || t !== this.engine) return null;
1446
- throw e;
1447
- }
1448
- return this.destroyed || a !== this.elementHitGeneration || o !== this.currentSlide || t !== this.engine ? null : (this._setElementContext(c), this.destroyed ? null : this.getSelectionContext());
1449
- }
1450
- destroy() {
1451
- 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());
1452
- }
1453
- }, _t = 150, vt = "0 1px 3px rgba(0,0,0,0.2)", $ = Symbol("PptxScrollViewer.borrowedPresentation"), yt = class e {
1454
- _presentationOwner;
1455
- get _pres() {
1456
- return this._presentationOwner.current;
1457
- }
1458
- _borrowed;
1459
- _opts;
1460
- _container;
1461
- _wrapper;
1462
- _scrollHost;
1463
- _spacer;
1464
- _mode;
1465
- _scale = 1;
1466
- _scaleEstablished = !1;
1467
- _pendingScale = null;
1468
- _slots = /* @__PURE__ */ new Map();
1469
- _free = [];
1470
- _heights = [];
1471
- _lastRange = null;
1472
- _lastTopIndex = -1;
1473
- _scrollListener = null;
1474
- _selectionChangeListener = null;
1475
- _selectionContextKey = "null";
1476
- _elementClickListener = null;
1477
- _contextMenuListener = null;
1478
- _elementContext = null;
1479
- _elementHitGeneration = 0;
1480
- _elementHitTolerance;
1481
- _destroyed = !1;
1482
- _slideInFlight = /* @__PURE__ */ new Set();
1483
- _renderEpoch = 0;
1484
- _settleTimer = null;
1485
- _wheelListener = null;
1486
- _pendingZoomAnchor = null;
1487
- _resizeObserver = null;
1488
- _prevBase = 0;
1489
- _lastFitWidth = 0;
1490
- _pageShadow;
1491
- _find = new z(() => this.slideCount, (e) => this._collectSlideRuns(e));
1492
- _findActive = !1;
1493
- _findMeasureCtx;
1494
- static fromPresentation(t, n, r = {}) {
1495
- return new e(t, {
1496
- ...r,
1497
- [$]: n
1498
- });
1499
- }
1500
- constructor(e, t = {}) {
1501
- 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.");
1502
- this._container = e, this._opts = t;
1503
- let n = t.elementHitTolerance ?? 6;
1504
- if (!Number.isFinite(n) || n < 0) throw RangeError("elementHitTolerance must be a finite non-negative number.");
1505
- this._elementHitTolerance = n, this._pageShadow = t.pageShadow ?? vt;
1506
- let r = t[$];
1507
- this._borrowed = r !== void 0, r ? (this._presentationOwner = new E("PptxScrollViewer", r, !1), this._mode = k("PptxScrollViewer", t.mode, r)) : (this._presentationOwner = new E("PptxScrollViewer"), this._mode = k("PptxScrollViewer", t.mode, void 0)), this._wrapper = document.createElement("div"), this._wrapper.style.cssText = "position:relative;width:100%;height:100%;overflow:hidden;", this._scrollHost = document.createElement("div"), this._scrollHost.style.cssText = "position:absolute;inset:0;overflow:auto;", this._scrollHost.style.scrollbarGutter = "stable", t.background && (this._scrollHost.style.background = t.background), this._spacer = document.createElement("div"), this._spacer.style.cssText = "position:absolute;top:0;left:0;width:1px;height:0;pointer-events:none;", this._scrollHost.appendChild(this._spacer), this._wrapper.appendChild(this._scrollHost), this._container.appendChild(this._wrapper), t.enableTextSelection && (t.onSelectionContextChange || t.enableElementSelection) && (this._selectionChangeListener = () => this._emitSelectionContextChange(), this._wrapper.ownerDocument.addEventListener("selectionchange", this._selectionChangeListener)), t.enableElementSelection && (this._elementClickListener = (e) => {
1508
- this._onElementClick(e).catch((e) => this._reportRenderError(e));
1509
- }, 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), this._opts.enableZoom !== !1 && (this._wheelListener = (e) => {
1510
- if (!(e.ctrlKey || e.metaKey) || (e.preventDefault(), e.deltaY === 0)) return;
1511
- let t = this._scrollHost.getBoundingClientRect(), n = e.clientX - t.left, r = e.clientY - t.top;
1512
- this._pendingZoomAnchor = Number.isFinite(n) && Number.isFinite(r) ? {
1513
- x: n,
1514
- y: r
1515
- } : null, this.setScale(ve(this._scale, e.deltaY));
1516
- }, 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();
1517
- }
1518
- async load(e) {
1519
- if (this._destroyed) throw Error("PptxScrollViewer is destroyed");
1520
- if (this._borrowed) throw Error("PptxScrollViewer.load() is unsupported on a Viewer created by fromPresentation(); the borrowed presentation is already loaded.");
1521
- let t = !1;
1522
- try {
1523
- if (!await this._presentationOwner.replace(() => X.load(e, {
1524
- password: this._opts.password,
1525
- useGoogleFonts: this._opts.useGoogleFonts,
1526
- maxZipEntryBytes: this._opts.maxZipEntryBytes,
1527
- resourceLimits: this._opts.resourceLimits,
1528
- debug: this._opts.debug,
1529
- onResourceMetrics: this._opts.onResourceMetrics,
1530
- workerTimeoutMs: this._opts.workerTimeoutMs,
1531
- wasmUrl: this._opts.wasmUrl,
1532
- math: this._opts.math,
1533
- threeD: this._opts.threeD,
1534
- regionMap: this._opts.regionMap,
1535
- mode: this._mode
1536
- }), (e) => {
1537
- if (this._invalidateElementSelection(!1), t = !0, this._find.invalidate(), this._findActive = !1, e) {
1538
- for (let [e, t] of [...this._slots]) this._recycleSlot(e, t);
1539
- this._lastTopIndex = -1;
1540
- }
1541
- })) return;
1542
- if (this._destroyed) throw Error("PptxScrollViewer is destroyed");
1543
- this._find.invalidate(), this._findActive = !1;
1544
- let n = [];
1545
- this._relayout(n), await Promise.all(n);
1546
- } catch (e) {
1547
- throw this._destroyed ? Error("PptxScrollViewer is destroyed") : e instanceof Error ? e : Error(String(e));
1548
- }
1549
- t && !this._destroyed && this._emitSelectionContextChange();
1550
- }
1551
- get slideCount() {
1552
- return this._pres?.slideCount ?? 0;
1553
- }
1554
- _slideWidthPx() {
1555
- return this._pres.slideWidth / M * this._scale;
1556
- }
1557
- _slideHeightPx() {
1558
- return this._pres.slideHeight / M * this._scale;
1559
- }
1560
- _fitWidthPx() {
1561
- if (this._opts.width && this._opts.width > 0) return this._opts.width;
1562
- let e = this._scrollHost.clientWidth || this._container.clientWidth;
1563
- if (e <= 0) return 0;
1564
- let { left: t, right: n } = this._padH(), r = e - t - n;
1565
- return r > 0 ? r : 0;
1566
- }
1567
- _baseScale() {
1568
- if (!this._pres || this._pres.slideCount === 0) return 0;
1569
- let e = this._fitWidthPx(), t = this._pres.slideWidth / M;
1570
- return e <= 0 || t <= 0 ? 0 : e / t;
1571
- }
1572
- relayout() {
1573
- this._relayout();
1574
- }
1575
- _relayout(e) {
1576
- if (this._pres) {
1577
- if (!this._scaleEstablished) {
1578
- let e = this._baseScale();
1579
- if (e > 0) {
1580
- if (this._scale = e, this._prevBase = e, this._lastFitWidth = this._fitWidthPx(), this._scaleEstablished = !0, this._pendingScale !== null) {
1581
- let e = this._pendingScale;
1582
- this._pendingScale = null, e !== this._scale && (this._scale = e, this._opts.onScaleChange?.(e));
1583
- }
1584
- } else return;
1585
- }
1586
- this._recomputeHeights(), this._syncSpacer(), this._mountVisible(e);
1587
- }
1588
- }
1589
- _recomputeHeights() {
1590
- let e = this._pres.slideCount, t = this._slideHeightPx();
1591
- this._heights = Array(e).fill(t);
1592
- }
1593
- _gap() {
1594
- return this._opts.gap ?? 16;
1595
- }
1596
- _overscan() {
1597
- return this._opts.overscan ?? 1;
1598
- }
1599
- _mediaOverscan() {
1600
- return this._opts.mediaOverscan ?? 1;
1601
- }
1602
- _pad() {
1603
- let e = this._gap();
1604
- return {
1605
- leading: this._opts.paddingTop ?? e,
1606
- trailing: this._opts.paddingBottom ?? e
1607
- };
1608
- }
1609
- _padH() {
1610
- let e = this._gap();
1611
- return {
1612
- left: this._opts.paddingLeft ?? e,
1613
- right: this._opts.paddingRight ?? e
1614
- };
1615
- }
1616
- _slideIndexAtOffset(e, t) {
1617
- let { offsets: n } = e, r = 0, i = n.length - 1, a = 0;
1618
- for (; r <= i;) {
1619
- let e = r + i >> 1;
1620
- n[e] <= t ? (a = e, r = e + 1) : i = e - 1;
1621
- }
1622
- return a;
1623
- }
1624
- _range() {
1625
- return P(this._heights, this._gap(), this._scrollHost.scrollTop, this._scrollHost.clientHeight, this._overscan(), this._pad());
1626
- }
1627
- _mediaRange() {
1628
- return P(this._heights, this._gap(), this._scrollHost.scrollTop, this._scrollHost.clientHeight, this._mediaOverscan(), this._pad());
1629
- }
1630
- _rangeContains(e, t) {
1631
- return t >= e.start && t <= e.end;
1632
- }
1633
- _syncSpacer() {
1634
- let e = this._range();
1635
- this._lastRange = e, this._spacer.style.height = `${e.totalHeight}px`, this._syncSpacerWidth();
1636
- }
1637
- _syncSpacerWidth() {
1638
- let { left: e, right: t } = this._padH();
1639
- this._spacer.style.width = `${this._slideWidthPx() + e + t}px`;
1640
- }
1641
- _onScroll() {
1642
- !this._pres || !this._scaleEstablished || this._mountVisible();
1643
- }
1644
- _mountVisible(e) {
1645
- if (!this._pres || this._pres.slideCount === 0) return;
1646
- let t = this._range(), n = this._opts.enableMediaPlayback ? this._mediaRange() : null;
1647
- this._lastRange = t;
1648
- for (let [e, n] of [...this._slots]) (e < t.start || e > t.end) && this._recycleSlot(e, n);
1649
- for (let r = t.start; r <= t.end; r++) if (this._slots.has(r)) this._positionSlot(this._slots.get(r), r, t);
1650
- else {
1651
- let i = this._acquireSlot();
1652
- this._positionSlot(i, r, t), this._slots.set(r, i);
1653
- let a = this._renderSlot(r, i, !!n && this._rangeContains(n, r), e === void 0);
1654
- e && a && e.push(a);
1655
- }
1656
- n && this._syncMediaPlayback(n), t.topIndex !== this._lastTopIndex && (this._lastTopIndex = t.topIndex, this._opts.onVisibleSlideChange?.(t.topIndex, this._pres.slideCount));
1657
- }
1658
- _applyPageShadow(e) {
1659
- this._pageShadow !== !1 && (e.style.boxShadow = this._pageShadow);
1660
- }
1661
- _acquireSlot() {
1662
- let e = this._free.pop();
1663
- if (e) return this._scrollHost.appendChild(e.wrapper), e;
1664
- let t = document.createElement("div");
1665
- t.style.cssText = "position:absolute;";
1666
- let n = document.createElement("canvas");
1667
- n.style.cssText = "display:block;background:#fff;", this._applyPageShadow(n), t.appendChild(n);
1668
- let r = null;
1669
- 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));
1670
- let i = document.createElement("div");
1671
- i.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;overflow:hidden;pointer-events:none;", t.appendChild(i);
1672
- let a = fe(t, this._opts.enableElementSelection === !0);
1673
- return this._scrollHost.appendChild(t), {
1674
- wrapper: t,
1675
- canvas: n,
1676
- textLayer: r,
1677
- highlightLayer: i,
1678
- elementLayer: a,
1679
- renderedSlide: -1,
1680
- renderedScale: -1,
1681
- dispatcher: new O(n, this._mode === "worker"),
1682
- presentationHandle: null,
1683
- mediaInteractive: !1,
1684
- renderGeneration: 0,
1685
- presentationGeneration: 0
1686
- };
1687
- }
1688
- _recycleSlot(e, t) {
1689
- this._slots.delete(e), t.renderGeneration++, t.presentationGeneration++, t.presentationHandle?.destroy(), t.presentationHandle = null, t.mediaInteractive = !1, t.dispatcher.destroy(), this._destroyed || (t.dispatcher = new O(t.canvas, this._mode === "worker")), t.textLayer && (t.textLayer.innerHTML = "", t.textLayer.style.transform = "", t.textLayer.style.transformOrigin = ""), t.highlightLayer.innerHTML = "", t.highlightLayer.style.transform = "", t.highlightLayer.style.transformOrigin = "", D(t.elementLayer, null), t.canvas.style.height = "", t.renderedSlide = -1, t.renderedScale = -1, t.wrapper.remove(), this._free.push(t);
1690
- }
1691
- _positionSlot(e, t, n) {
1692
- e.wrapper.dataset.slideIndex = String(t), e.wrapper.style.top = `${n.offsets[t]}px`;
1693
- let r = this._slideWidthPx();
1694
- e.wrapper.style.width = `${r}px`, e.wrapper.style.height = `${this._slideHeightPx()}px`, this._redrawElementOutlineForSlot(t, e);
1695
- let { left: i } = this._padH(), a = this._scrollHost.clientWidth;
1696
- e.wrapper.style.left = `${Math.max(i, (a - r) / 2)}px`;
1697
- }
1698
- _dpr() {
1699
- return this._opts.dpr ?? (typeof window < "u" && window.devicePixelRatio || 1);
1700
- }
1701
- _renderSlot(e, t, n = !1, r = !0) {
1702
- if (!this._pres || t.renderedSlide === e) return null;
1703
- t.renderedSlide = e;
1704
- let i = ++t.renderGeneration, a = this._dpr(), o = this._slideWidthPx(), s = this._renderEpoch, c = this._scale, l = t.dispatcher, u = l.begin();
1705
- if (this._opts.enableMediaPlayback && n) return t.mediaInteractive = !0, this._renderInteractiveSlot(e, t, o, a, c, s, r);
1706
- if (t.mediaInteractive = !1, this._mode === "worker") return this._renderSlotBitmap(e, t, o, a, c, i, l, u, r);
1707
- let d = [], f = !!this._opts.enableTextSelection && !!t.textLayer, p = f || this._findActive, m = p ? (e) => d.push(e) : void 0, h = t.canvas;
1708
- return this._pres.renderSlide(h, e, {
1709
- width: o,
1710
- dpr: a,
1711
- onTextRun: m
1712
- }).then(() => {
1713
- 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 && L(t.textLayer, d, Math.round(o), Math.round(this._slideHeightPx()), this._hyperlinkHandler(), e), p && this._refreshFindRuns(e, d), this._redrawSlotHighlights(e, t));
1714
- }).catch((n) => {
1715
- 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);
1716
- else throw n;
1717
- });
1718
- }
1719
- _renderInteractiveSlot(e, t, n, r, i, a, o = !0) {
1720
- if (!this._pres) return Promise.resolve();
1721
- let s = ++t.presentationGeneration;
1722
- t.presentationHandle?.destroy(), t.presentationHandle = null;
1723
- let c = [], l = !!this._opts.enableTextSelection && !!t.textLayer, u = l || this._findActive, d = u ? (e) => c.push(e) : void 0;
1724
- return this._pres.presentSlide(t.canvas, e, {
1725
- width: n,
1726
- dpr: r,
1727
- onTextRun: d,
1728
- onError: (e) => {
1729
- s === t.presentationGeneration && this._reportRenderError(e);
1730
- }
1731
- }).then((r) => {
1732
- if (s !== t.presentationGeneration || !t.mediaInteractive || a !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e) {
1733
- r.destroy();
1734
- return;
1735
- }
1736
- t.presentationHandle = r, t.renderedScale = i, l && t.textLayer && L(t.textLayer, c, Math.round(n), Math.round(this._slideHeightPx()), this._hyperlinkHandler(), e), u && this._refreshFindRuns(e, c), this._redrawSlotHighlights(e, t);
1737
- }).catch((e) => {
1738
- if (s === t.presentationGeneration) if (o) this._reportRenderError(e);
1739
- else throw e;
1740
- });
1741
- }
1742
- _syncMediaPlayback(e = this._mediaRange()) {
1743
- if (this._opts.enableMediaPlayback) for (let [t, n] of this._slots) {
1744
- let r = this._rangeContains(e, t);
1745
- 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));
1746
- }
1747
- }
1748
- _reportRenderError(e) {
1749
- if (this._destroyed) return;
1750
- let t = e instanceof Error ? e : Error(String(e));
1751
- this._opts.onError ? this._opts.onError(t) : console.error("[ooxml] PptxScrollViewer render failed:", t);
1752
- }
1753
- async _renderSlotBitmap(e, t, n, r, i, a = ++t.renderGeneration, o = t.dispatcher, s = o.begin(), c = !0) {
1754
- if (this._slideInFlight.has(e) || this._slots.get(e) !== t) return;
1755
- let l = this._renderEpoch;
1756
- this._slideInFlight.add(e);
1757
- let u = t.canvas, d = !1, f = !!this._opts.enableTextSelection && !!t.textLayer, p = f || this._findActive, m = [];
1758
- try {
1759
- let c = await this._pres.renderSlideToBitmap(e, {
1760
- width: n,
1761
- dpr: r,
1762
- onTextRun: p ? (e) => m.push(e) : void 0
1763
- });
1764
- if (a !== t.renderGeneration || !o.isCurrent(s) || u !== t.canvas || l !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e) {
1765
- c.close();
1766
- return;
1767
- }
1768
- if (!o.commitBitmap(s, c, {
1769
- cssWidth: Math.round(c.width / r),
1770
- cssHeight: Math.round(c.height / r)
1771
- })) return;
1772
- t.renderedScale = i, t.textLayer && (t.textLayer.style.transform = "", t.textLayer.style.transformOrigin = "", f && L(t.textLayer, m, Math.round(n), Math.round(this._slideHeightPx()), this._hyperlinkHandler(), e)), p && this._refreshFindRuns(e, m), this._redrawSlotHighlights(e, t), d = !0;
1773
- } catch (n) {
1774
- 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);
1775
- else throw n;
1776
- } finally {
1777
- this._slideInFlight.delete(e);
1778
- let n = this._slots.get(e);
1779
- !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);
1780
- }
1781
- }
1782
- setScale(e) {
1783
- let t = this._opts.zoomMin ?? .1, n = this._opts.zoomMax ?? 4, r = Math.min(n, Math.max(t, e)), i = this._pendingZoomAnchor;
1784
- if (this._pendingZoomAnchor = null, !this._pres || this._pres.slideCount === 0 || !this._scaleEstablished) {
1785
- this._pendingScale = r;
1786
- return;
1787
- }
1788
- if (r === this._scale) return;
1789
- let a = this._scale, o = i ? i.y : 0, s = this._range(), c = this._scrollHost.scrollTop, l = c + o, u = this._slideIndexAtOffset(s, l), d = this._heights[u] || 0, f = d > 0 ? (l - s.offsets[u]) / d : 0;
1790
- f = Math.min(1, Math.max(0, f));
1791
- let p = this._padH().left, m = this._scrollHost.scrollLeft || 0;
1792
- this._renderEpoch++, this._scale = r, this._recomputeHeights();
1793
- let h = P(this._heights, this._gap(), 0, this._scrollHost.clientHeight, this._overscan(), this._pad());
1794
- this._spacer.style.height = `${h.totalHeight}px`, this._syncSpacerWidth();
1795
- let g = Math.max(0, h.totalHeight - this._scrollHost.clientHeight), _ = (h.offsets[u] ?? 0) + f * (this._heights[u] || 0), v = l < (s.offsets[0] ?? 0) ? c : _ - o;
1796
- if (this._scrollHost.scrollTop = Math.min(g, Math.max(0, v)), i) {
1797
- let e = Math.max(0, (this._spacer.offsetWidth || 0) - this._scrollHost.clientWidth);
1798
- this._scrollHost.scrollLeft = ae(m, i.x - p, a, r, { maxScroll: e });
1799
- }
1800
- this._previewVisible(), this._scheduleSettle(), this._opts.onScaleChange?.(r);
1801
- }
1802
- getScale() {
1803
- return this._scaleEstablished ? this._scale : this._pendingScale ?? 1;
1804
- }
1805
- zoomIn() {
1806
- this.setScale(A(this.getScale()));
1807
- }
1808
- zoomOut() {
1809
- this.setScale(j(this.getScale()));
1810
- }
1811
- fitWidth() {
1812
- this._fit("width");
1813
- }
1814
- fitPage() {
1815
- this._fit("page");
1816
- }
1817
- _fit(e) {
1818
- if (!this._pres || this._pres.slideCount === 0) return;
1819
- let t = T({
1820
- contentWidth: this._pres.slideWidth / M,
1821
- contentHeight: this._pres.slideHeight / M,
1822
- containerWidth: this._fitWidthPx(),
1823
- containerHeight: this._scrollHost.clientHeight
1824
- }, e);
1825
- t <= 0 || this.setScale(t);
1826
- }
1827
- _previewVisible() {
1828
- if (!this._pres || this._pres.slideCount === 0) return;
1829
- let e = this._range(), t = this._opts.enableMediaPlayback ? this._mediaRange() : null;
1830
- this._lastRange = e;
1831
- for (let [t, n] of [...this._slots]) (t < e.start || t > e.end) && this._recycleSlot(t, n);
1832
- for (let n = e.start; n <= e.end; n++) {
1833
- let r = this._slots.get(n);
1834
- if (r) this._previewSlot(r, n, e);
1835
- else {
1836
- let r = this._acquireSlot();
1837
- this._positionSlot(r, n, e), this._slots.set(n, r), this._renderSlot(n, r, !!t && this._rangeContains(t, n));
1838
- }
1839
- }
1840
- t && this._syncMediaPlayback(t), e.topIndex !== this._lastTopIndex && (this._lastTopIndex = e.topIndex, this._opts.onVisibleSlideChange?.(e.topIndex, this._pres.slideCount));
1841
- }
1842
- _previewSlot(e, t, n) {
1843
- 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) {
1844
- let t = this._scale / e.renderedScale;
1845
- e.textLayer.style.transformOrigin = "0 0", e.textLayer.style.transform = `scale(${t})`;
1846
- }
1847
- }
1848
- _scheduleSettle() {
1849
- this._settleTimer !== null && clearTimeout(this._settleTimer), this._settleTimer = setTimeout(() => {
1850
- this._settleTimer = null, this._settleRender();
1851
- }, _t);
1852
- }
1853
- _settleRender() {
1854
- if (this._destroyed || !this._pres || this._pres.slideCount === 0) return;
1855
- let e = this._opts.enableMediaPlayback ? this._mediaRange() : null;
1856
- for (let [t, n] of [...this._slots]) e && !this._rangeContains(e, t) || n.renderedScale !== this._scale && this._settleSlot(t, n);
1857
- }
1858
- _settleSlot(e, t) {
1859
- if (!this._pres) return;
1860
- let n = this._dpr(), r = this._slideWidthPx(), i = this._scale, a = this._renderEpoch;
1861
- if (this._opts.enableMediaPlayback && t.mediaInteractive) {
1862
- this._settleInteractiveSlot(e, t, r, n, i, a);
1863
- return;
1864
- }
1865
- if (this._opts.enableMediaPlayback) return;
1866
- if (this._mode === "worker") {
1867
- this._renderSlotBitmap(e, t, r, n, i);
1868
- return;
1869
- }
1870
- let o = document.createElement("canvas"), s = ++t.renderGeneration;
1871
- o.style.cssText = "display:block;background:#fff;", this._applyPageShadow(o);
1872
- let c = new O(o, !1), l = c.begin(), u = [], d = !!this._opts.enableTextSelection && !!t.textLayer, f = d || this._findActive, p = f ? (e) => u.push(e) : void 0;
1873
- this._pres.renderSlide(o, e, {
1874
- width: r,
1875
- dpr: n,
1876
- onTextRun: p
1877
- }).then(() => {
1878
- if (s !== t.renderGeneration || !c.isCurrent(l) || a !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e) {
1879
- c.destroy();
1880
- return;
1881
- }
1882
- let n = t.canvas;
1883
- 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 && L(t.textLayer, u, Math.round(r), Math.round(this._slideHeightPx()), this._hyperlinkHandler(), e)), f && this._refreshFindRuns(e, u), this._redrawSlotHighlights(e, t);
1884
- }).catch((n) => {
1885
- s === t.renderGeneration && c.isCurrent(l) && a === this._renderEpoch && this._slots.get(e) === t && t.renderedSlide === e && this._reportRenderError(n), c.destroy();
1886
- });
1887
- }
1888
- _settleInteractiveSlot(e, t, n, r, i, a) {
1889
- if (!this._pres) return;
1890
- let o = ++t.presentationGeneration, s = document.createElement("canvas");
1891
- s.style.cssText = "display:block;background:#fff;", this._applyPageShadow(s);
1892
- let c = [], l = !!this._opts.enableTextSelection && !!t.textLayer, u = l || this._findActive, d = u ? (e) => c.push(e) : void 0;
1893
- this._pres.presentSlide(s, e, {
1894
- width: n,
1895
- dpr: r,
1896
- onTextRun: d,
1897
- onError: (e) => {
1898
- o === t.presentationGeneration && this._reportRenderError(e);
1899
- }
1900
- }).then((r) => {
1901
- if (o !== t.presentationGeneration || !t.mediaInteractive || a !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e) {
1902
- r.destroy();
1903
- return;
1904
- }
1905
- let d = t.canvas, f = t.presentationHandle;
1906
- t.dispatcher.destroy(), t.wrapper.insertBefore(s, d), d.remove(), t.canvas = s, t.dispatcher = new O(s, !1), t.presentationHandle = r, t.renderedScale = i, f?.destroy(), t.textLayer && (t.textLayer.style.transform = "", t.textLayer.style.transformOrigin = "", l && L(t.textLayer, c, Math.round(n), Math.round(this._slideHeightPx()), this._hyperlinkHandler(), e)), u && this._refreshFindRuns(e, c), this._redrawSlotHighlights(e, t);
1907
- }).catch((e) => {
1908
- o === t.presentationGeneration && this._reportRenderError(e);
1909
- });
1910
- }
1911
- scrollToSlide(e, t) {
1912
- if (!this._pres || this._pres.slideCount === 0 || !this._scaleEstablished) return;
1913
- let n = Math.max(0, Math.min(e, this._pres.slideCount - 1)), r = P(this._heights, this._gap(), 0, this._scrollHost.clientHeight, this._overscan(), this._pad()), i = r.offsets[n] ?? 0, a = Math.max(0, r.totalHeight - this._scrollHost.clientHeight), o = Math.min(a, Math.max(0, i)), s = this._scrollHost;
1914
- typeof s.scrollTo == "function" ? s.scrollTo({
1915
- top: o,
1916
- behavior: t?.behavior ?? "auto"
1917
- }) : this._scrollHost.scrollTop = o, this._mountVisible();
1918
- }
1919
- async findText(e, t = {}) {
1920
- if (!this._pres) return [];
1921
- this._findActive = e.length > 0;
1922
- let n = await this._find.find(e, t);
1923
- return this._redrawHighlights(), n;
1924
- }
1925
- async findNext() {
1926
- return this._activateMatch(this._find.next());
1927
- }
1928
- async findPrev() {
1929
- return this._activateMatch(this._find.prev());
1930
- }
1931
- clearFind() {
1932
- this._findActive = !1, this._find.invalidate(), this._redrawHighlights();
1933
- }
1934
- async _activateMatch(e) {
1935
- return e && this.scrollToSlide(e.location.slide), this._redrawHighlights(), e;
1936
- }
1937
- async _collectSlideRuns(e) {
1938
- return this._pres ? this._pres.collectSlideRuns(e, this._slideWidthPx()) : [];
1939
- }
1940
- _redrawHighlights() {
1941
- for (let [e, t] of this._slots) this._redrawSlotHighlights(e, t);
1942
- }
1943
- _refreshFindRuns(e, t) {
1944
- this._findActive && this._find.setSlideRuns(e, t);
1945
- }
1946
- _redrawSlotHighlights(e, t) {
1947
- if (!this._findActive) {
1948
- t.highlightLayer.innerHTML = "";
1949
- return;
1950
- }
1951
- let n = this._find.slideRuns(e);
1952
- if (!n) {
1953
- t.highlightLayer.innerHTML = "";
1954
- return;
1955
- }
1956
- R(t.highlightLayer, n, this._find.slideHighlights(e), this._slideWidthPx(), this._slideHeightPx(), (e) => this._measureForFind(e), this._opts.findHighlightColors);
1957
- }
1958
- _measureForFind(e) {
1959
- this._findMeasureCtx === void 0 && (this._findMeasureCtx = document.createElement("canvas").getContext("2d"));
1960
- let t = this._findMeasureCtx;
1961
- return !t || typeof t.measureText != "function" ? (e) => e.length : (t.font = e, (e) => t.measureText(e).width);
1962
- }
1963
- _hyperlinkHandler() {
1964
- if (this._opts.enableHyperlinks !== !1) return (e) => this._onHyperlinkClick(e);
1965
- }
1966
- _onHyperlinkClick(e) {
1967
- let t = this._resolveInternalSlideIndex(e);
1968
- if (this._opts.onHyperlinkClick) {
1969
- this._opts.onHyperlinkClick(t);
1970
- return;
1971
- }
1972
- if (t.kind === "external") {
1973
- h(t.url);
1974
- return;
1975
- }
1976
- t.slideIndex !== void 0 && this.scrollToSlide(t.slideIndex);
1977
- }
1978
- _resolveInternalSlideIndex(e) {
1979
- if (e.kind !== "internal" || e.slideIndex !== void 0) return e;
1980
- let t = this._pres?.resolveInternalTarget(e.ref, this._range().topIndex);
1981
- return t === void 0 ? e : {
1982
- ...e,
1983
- slideIndex: t
1984
- };
1985
- }
1986
- _onResize() {
1987
- if (!this._pres || this._pres.slideCount === 0) return;
1988
- if (!this._scaleEstablished) {
1989
- this.relayout();
1990
- return;
1991
- }
1992
- if (this._opts.refitOnResize === !1) {
1993
- this._lastFitWidth = this._fitWidthPx(), this._mountVisible();
1994
- return;
1995
- }
1996
- let e = this._baseScale();
1997
- if (e <= 0) return;
1998
- let t = this._fitWidthPx();
1999
- if (t === this._lastFitWidth) {
2000
- this._mountVisible();
2001
- return;
2002
- }
2003
- this._lastFitWidth = t;
2004
- let n = this._prevBase > 0 ? this._scale / this._prevBase : 1;
2005
- this._prevBase = e, this.setScale(e * n), this._mountVisible();
2006
- }
2007
- get topVisibleSlide() {
2008
- return this._lastRange?.topIndex ?? 0;
2009
- }
2010
- mountedSlideIndicesForTest() {
2011
- return [...this._slots.keys()];
2012
- }
2013
- interactiveSlideIndicesForTest() {
2014
- return [...this._slots].filter(([, e]) => e.mediaInteractive).map(([e]) => e);
2015
- }
2016
- scaleForTest() {
2017
- return this._scale;
2018
- }
2019
- baseScaleForTest() {
2020
- return this._baseScale();
2021
- }
2022
- renderEpochForTest() {
2023
- return this._renderEpoch;
2024
- }
2025
- resizeForTest() {
2026
- this._onResize();
2027
- }
2028
- contentAtViewportYForTest(e) {
2029
- let t = this._range(), n = this._scrollHost.scrollTop + e, r = this._slideIndexAtOffset(t, n), i = this._heights[r] || 0;
2030
- return {
2031
- slide: r,
2032
- frac: i > 0 ? Math.min(1, Math.max(0, (n - t.offsets[r]) / i)) : 0
2033
- };
2034
- }
2035
- viewportYOfForTest(e, t) {
2036
- return (this._range().offsets[e] ?? 0) + t * (this._heights[e] || 0) - this._scrollHost.scrollTop;
2037
- }
2038
- async getResourceMetrics() {
2039
- if (!this._pres) throw Error("Presentation not loaded");
2040
- return await this._pres.getResourceMetrics();
2041
- }
2042
- getSelectionContext(e = {}) {
2043
- if (this._destroyed) throw Error("PptxScrollViewer is destroyed");
2044
- return (this._opts.enableTextSelection ? Q(this._wrapper, this._wrapper.ownerDocument?.getSelection?.() ?? null, e) : null) ?? (this._elementContext ? ut(this._elementContext, e.maxTextCharacters) : null);
2045
- }
2046
- _emitSelectionContextChange() {
2047
- let e = this.getSelectionContext();
2048
- e?.kind === "text" && (this._elementHitGeneration++, this._elementContext = null, this._redrawElementOutlines());
2049
- let t = JSON.stringify(e);
2050
- t !== this._selectionContextKey && (this._selectionContextKey = t, this._opts.onSelectionContextChange?.(e ? structuredClone(e) : null));
2051
- }
2052
- _setElementContext(e) {
2053
- this._elementContext = e ? structuredClone(e) : null, this._redrawElementOutlines(), this._emitSelectionContextChange();
2054
- }
2055
- _invalidateElementSelection(e = !0) {
2056
- this._elementHitGeneration++, this._elementContext = null, this._redrawElementOutlines(), e && this._emitSelectionContextChange();
2057
- }
2058
- _redrawElementOutlines() {
2059
- for (let [e, t] of this._slots) this._redrawElementOutlineForSlot(e, t);
2060
- }
2061
- _redrawElementOutlineForSlot(e, t) {
2062
- let n = this._elementContext, r = this._pres;
2063
- if (!n || !r || n.slideIndex !== e) {
2064
- D(t.elementLayer, null);
2065
- return;
2066
- }
2067
- D(t.elementLayer, {
2068
- x: n.bounds.x / r.slideWidth,
2069
- y: n.bounds.y / r.slideHeight,
2070
- width: n.bounds.width / r.slideWidth,
2071
- height: n.bounds.height / r.slideHeight,
2072
- rotation: n.bounds.rotation
2073
- });
2074
- }
2075
- async _onElementClick(e) {
2076
- this._destroyed || e.defaultPrevented || e.button !== 0 || await this._resolveContextAt(e);
2077
- }
2078
- _onContextMenu(e) {
2079
- let t;
2080
- this._opts.onContextMenu?.({
2081
- originalEvent: e,
2082
- getContext: () => t ??= this._resolveContextAt(e)
2083
- });
2084
- }
2085
- async _resolveContextAt(e) {
2086
- let t = this._pres;
2087
- if (this._destroyed || !t) return null;
2088
- if (this._opts.enableTextSelection && Q(this._wrapper, this._wrapper.ownerDocument?.getSelection?.() ?? null)) return this._emitSelectionContextChange(), this._destroyed ? null : this.getSelectionContext();
2089
- if (!this._opts.enableElementSelection) return this.getSelectionContext();
2090
- let n = e.target, r = [...this._slots].find(([, e]) => n !== null && e.wrapper.contains(n));
2091
- if (!r) return this._invalidateElementSelection(), null;
2092
- let [i, a] = r, o = a.canvas.getBoundingClientRect();
2093
- if (o.width <= 0 || o.height <= 0) return this._invalidateElementSelection(), null;
2094
- let s = e.clientX - o.left, c = e.clientY - o.top;
2095
- if (s < 0 || c < 0 || s > o.width || c > o.height) return this._invalidateElementSelection(), null;
2096
- let l = ++this._elementHitGeneration, u = {
2097
- x: s / o.width * t.slideWidth,
2098
- y: c / o.height * t.slideHeight
2099
- }, d;
2100
- try {
2101
- d = await t.getElementContextAt(i, u, {
2102
- tolerance: this._elementHitTolerance / o.width * t.slideWidth,
2103
- maxTextCharacters: Y
2104
- });
2105
- } catch (e) {
2106
- if (this._destroyed || l !== this._elementHitGeneration || t !== this._pres) return null;
2107
- throw e;
2108
- }
2109
- return this._destroyed || l !== this._elementHitGeneration || t !== this._pres ? null : (this._setElementContext(d), this._destroyed ? null : this.getSelectionContext());
2110
- }
2111
- destroy() {
2112
- if (!this._destroyed) {
2113
- 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._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);
2114
- for (let [e, t] of [...this._slots]) this._recycleSlot(e, t);
2115
- this._free.length = 0, this._presentationOwner.close(), this._wrapper.remove();
2116
- }
2117
- }
2118
- }, bt = /* @__PURE__ */ e({
2119
- OoxmlDecodedImageLimitError: () => m,
2120
- OoxmlError: () => _,
2121
- OoxmlResourceLimitError: () => x,
2122
- PptxPresentation: () => X,
2123
- PptxScrollViewer: () => yt,
2124
- PptxViewer: () => gt,
2125
- autoResize: () => _e,
2126
- buildPptxHighlightLayer: () => R,
2127
- buildPptxTextLayer: () => L,
2128
- isOoxmlDecodedImageLimitError: () => ee,
2129
- openExternalHyperlink: () => h,
2130
- readPptxTextSelectionContext: () => Q,
2131
- renderSlide: () => n
2132
- });
2133
- //#endregion
2134
- export { X as a, Q as i, yt as n, R as o, gt as r, L as s, bt as t };