@silurus/ooxml 0.88.0 → 0.89.1

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