@silurus/ooxml 0.87.0 → 0.89.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/README.md +118 -23
  2. package/THIRD_PARTY_NOTICES.md +7 -6
  3. package/dist/abort-VrnK7mdP.js +10 -0
  4. package/dist/assets/render-worker-CUOU6mL2.js +16 -0
  5. package/dist/assets/render-worker-DOqrFhSU.js +15 -0
  6. package/dist/assets/render-worker-DvWUdZUN.js +35 -0
  7. package/dist/bounded-raw-part-cache-B7JoC1CD.js +64586 -0
  8. package/dist/bundled-asset-url-E2nXURF9.js +15 -0
  9. package/dist/canvas-viewer-mechanics-DfQqRKkD.js +675 -0
  10. package/dist/cfb-guard-9QTRTg7f.js +528 -0
  11. package/dist/chart-ex.mjs +708 -739
  12. package/dist/comment-overlay-controller-B5_zGgG5.js +994 -0
  13. package/dist/comment-ui-runtime-B7ZvovcS.js +2 -0
  14. package/dist/{comment-ui-runtime-DcJOYlw-.js → comment-ui-runtime-D_sb2K6s.js} +5 -5
  15. package/dist/{comment-ui-runtime-BfE7MJZn.js → comment-ui-runtime-Jy-3goA9.js} +5 -5
  16. package/dist/delimited-text-worker-host-CikWU6_m.js +27 -0
  17. package/dist/document-model-source-BKNrXjAL.js +249 -0
  18. package/dist/document-pull-client-CxONDGbk.js +37833 -0
  19. package/dist/document-pull-worker-AMyXYpPq.js +104 -0
  20. package/dist/docx-D91ER1_S.js +495 -0
  21. package/dist/docx-DhDnKEI6.js +3563 -0
  22. package/dist/docx-model-source-CdrSt3hF.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-ChcGZNd8.js +310 -0
  27. package/dist/duotone-ekYik4ix.js +126 -0
  28. package/dist/emf-UT6I8rVi.js +1790 -0
  29. package/dist/font-preload-demand-CdJZUMCT.js +2058 -0
  30. package/dist/grid-geometry-uQOgViJU.js +384 -0
  31. package/dist/host-layout-DVMw8hDY.js +56 -0
  32. package/dist/host-layout-measure-CCEgaC_v.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-CPOV6csk.js +2716 -0
  37. package/dist/math.mjs +2 -2
  38. package/dist/mathjax-stix2.js +10 -10
  39. package/dist/model-source-DJGzDtGb.js +61 -0
  40. package/dist/model-source-kz_NkZqT.js +179 -0
  41. package/dist/model-source-session-Bu9CHFHc.js +71 -0
  42. package/dist/model-source-session-CDuijwv1.js +85 -0
  43. package/dist/model-source-session-sKpNiIJI.js +58 -0
  44. package/dist/node.mjs +7 -1327
  45. package/dist/{pixel-budget-Dgjw269h.js → pixel-budget-BpTYrepD.js} +13 -10
  46. package/dist/plot-area-frame-CaJFvZ7p.js +8502 -0
  47. package/dist/pptx-CDP9dZHe.js +2936 -0
  48. package/dist/pptx-C_uxLVKB.js +183 -0
  49. package/dist/pptx-model-source-O7LhpOjz.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-tmROzteR.js +77 -0
  54. package/dist/raster-target-YQ4G6rxo.js +42 -0
  55. package/dist/region-map.mjs +114 -150
  56. package/dist/{render-8Zo7dnds.js → render-CJVglUHl.js} +3 -3
  57. package/dist/{render-worker-host-BfbnEChF.js → render-worker-host-BseIaVvm.js} +1 -1
  58. package/dist/{render-worker-host-DNL9dWRh.js → render-worker-host-CyxPU4JU.js} +1 -1
  59. package/dist/{render-worker-host-IkHrYOci.js → render-worker-host-aF6aWkC0.js} +1 -1
  60. package/dist/renderer-CkGLj0CC.js +5170 -0
  61. package/dist/renderer-Czw1cCC7.js +5823 -0
  62. package/dist/resource-measurement-mXw-WjMF.js +771 -0
  63. package/dist/session-Csv9maad.js +656 -0
  64. package/dist/slide-pull-client-DRZYwBTu.js +6515 -0
  65. package/dist/three-d-BK5siJgJ.js +878 -0
  66. package/dist/three-d.mjs +871 -764
  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 +289 -4
  70. package/dist/types/docx.d.ts +473 -98
  71. package/dist/types/index.d.ts +674 -303
  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 +530 -11
  75. package/dist/types/pptx.d.ts +410 -97
  76. package/dist/types/region-map.d.ts +289 -4
  77. package/dist/types/three-d.d.ts +289 -4
  78. package/dist/types/tiff.d.ts +1 -1
  79. package/dist/types/xlsx.d.ts +483 -134
  80. package/dist/wasm-loader-rlgHmcSv.js +35 -0
  81. package/dist/wasm-runtime-generation-DX4y0Ecl.js +97 -0
  82. package/dist/workbook-model-source-BTC4ISTS.js +94 -0
  83. package/dist/worker-source-I1cIYBel.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-CkHgbtyM.js +579 -0
  87. package/dist/xlsx-CpSDPAEU.js +5809 -0
  88. package/dist/xlsx-D5569TPf.js +534 -0
  89. package/dist/xlsx-model-source-DPSkjFic.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-CeK_iqK3.js +0 -10
  95. package/dist/assets/render-worker-DusrDhPk.js +0 -11
  96. package/dist/assets/render-worker-n2ZG0lrQ.js +0 -31
  97. package/dist/bounded-raw-part-cache-Cg1BsSZQ.js +0 -119
  98. package/dist/canvas-viewer-mechanics-Cpk0YFvM.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-yKxI8aDH.js +0 -27251
  105. package/dist/docx-BkSRiy07.js +0 -2995
  106. package/dist/dom-interaction-boundary-CBUQJsIM.js +0 -223
  107. package/dist/highlight-rect-C5hkRqUr.js +0 -13
  108. package/dist/hyperlink-ArrU3ArU.js +0 -36447
  109. package/dist/line-distribute-Dtudnqhs.js +0 -1023
  110. package/dist/line-metrics-B60C86uh.js +0 -60
  111. package/dist/plot-area-frame-D5hEOgkJ.js +0 -2903
  112. package/dist/pptx-62MmVbYB.js +0 -3063
  113. package/dist/renderer-XFSCOT6m.js +0 -5857
  114. package/dist/resource-measurement-CJsgolre.js +0 -150
  115. package/dist/session-CrU8f8DI.js +0 -743
  116. package/dist/slide-pull-client-B9KA8bU6.js +0 -6253
  117. package/dist/source-key-DIJG8BA0.js +0 -42
  118. package/dist/three-d-YYghQndN.js +0 -1346
  119. package/dist/transfer-p6iCC2R7.js +0 -6
  120. package/dist/units-EJdC96r6.js +0 -4
  121. package/dist/worksheet-pull-client-eIcQ-xlD.js +0 -458
  122. package/dist/xlsx-CRcSzZNq.js +0 -8482
  123. /package/dist/{chunk-DmhlhrBa.js → chunk-Dy4uBu1J.js} +0 -0
  124. /package/dist/{mathjax-DoyWZbSp.js → mathjax-BhwN6ilc.js} +0 -0
  125. /package/dist/{read-only-comment-decoration-Dz7eTQ4d.js → read-only-comment-decoration-PidH0wnP.js} +0 -0
  126. /package/dist/{read-only-comment-margin-DkgzASAl.js → read-only-comment-margin-B52rDVKo.js} +0 -0
  127. /package/dist/{renderer-module-contract-D91rkYHH.js → renderer-module-contract-CWM7jv6d.js} +0 -0
  128. /package/dist/{visible-index-BgiHEc1z.js → visible-index-FeVA0mGE.js} +0 -0
@@ -1,3063 +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-ArrU3ArU.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-Cpk0YFvM.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-CBUQJsIM.js";
5
- import { n as Ce } from "./cjk-fallback-bLI3z70h.js";
6
- import { l as we, s as Te } from "./pixel-budget-Dgjw269h.js";
7
- import { i as k } from "./units-EJdC96r6.js";
8
- import { i as Ee, s as De } from "./raster-target-ojDdQizC.js";
9
- import { n as Oe } from "./resource-measurement-CJsgolre.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-B9KA8bU6.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),$({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-DNL9dWRh.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
- }, [e], { timeoutMs: r });
974
- if (this._mode === "worker") {
975
- let e = c;
976
- e.usage && i?.(e.usage), this._preflight = M(c.preflight), this._bootstrap = this._preflight, this._availableSlideCount = this._preflight.slideCount;
977
- return;
978
- }
979
- let l = A(c.bootstrap);
980
- this._bootstrap = l;
981
- let u = St(l.embeddedFonts, (e) => this.getFontBytes(e)).then((e) => {
982
- this._destroyed ? O(e.faces) : (this._embeddedFontFaces = e.faces, this._embeddedFontAliases = e.aliases, this._embeddedFontAuthoredFamilies = e.authoredFamilies);
983
- });
984
- this._slidePullClient = new Ie({
985
- slideCount: l.slideCount,
986
- transport: this._bridge.transport(Ne),
987
- open: async (e, t, n) => {
988
- await this._bridge.request((n) => ({
989
- kind: "openSlideSession",
990
- id: n,
991
- slideIndex: e,
992
- ...t
993
- }), void 0, { timeoutMs: n });
994
- },
995
- onUsage: i
996
- });
997
- let d;
998
- try {
999
- for (let e = 0; e < l.slideCount; e += 1) await this._slidePullClient.load(e, !1, r);
1000
- d = await this._bridge.request((e) => ({
1001
- kind: "finishPresentationPreflight",
1002
- id: e
1003
- }), void 0, { timeoutMs: r }), await u;
1004
- } catch (e) {
1005
- throw u.catch(() => void 0), e;
1006
- }
1007
- this._preflight = M(d.preflight), this._availableSlideCount = this._preflight.slideCount, this._slides = new yt({
1008
- slideCount: this._preflight.slideCount,
1009
- maxCachedSlides: 8,
1010
- maxCachedStructuralBytes: s,
1011
- loadSlide: async (e) => {
1012
- let t = await this._slidePullClient?.load(e, !0, r);
1013
- if (!t) throw Error("PPTX slide pull client is unavailable");
1014
- return t;
1015
- }
1016
- });
1017
- }
1018
- async _parseMainProgressively(e, t, n, r, i, a) {
1019
- let o = A((await this._bridge.request((n) => ({
1020
- kind: "parse",
1021
- id: n,
1022
- buffer: e,
1023
- resourcePolicy: t,
1024
- progressiveLayout: !0
1025
- }), [e], { timeoutMs: r })).bootstrap);
1026
- this._bootstrap = o;
1027
- let c = St(o.embeddedFonts, (e) => this.getFontBytes(e)).then((e) => {
1028
- this._destroyed ? O(e.faces) : (this._embeddedFontFaces = e.faces, this._embeddedFontAliases = e.aliases, this._embeddedFontAuthoredFamilies = e.authoredFamilies);
1029
- });
1030
- this._slidePullClient = this._createSlidePullClient(o.slideCount, r, i), this._slides = new yt({
1031
- slideCount: o.slideCount,
1032
- maxCachedSlides: 8,
1033
- maxCachedStructuralBytes: s,
1034
- loadSlide: async (e) => {
1035
- let t = await this._slidePullClient?.load(e, !0, r);
1036
- if (!t) throw Error("PPTX slide pull client is unavailable");
1037
- return t;
1038
- }
1039
- });
1040
- let l = new Pe(o, { cjkFallback: this._cjkFallback }), u = /* @__PURE__ */ new Set(), d = async () => {
1041
- if (await c, !n) return;
1042
- let e = Ct(l.currentFontPreloadNames, this._embeddedFontAliases).filter((e) => !!e && !u.has(e));
1043
- if (e.length !== 0) {
1044
- for (let t of e) u.add(t);
1045
- this._googleFontFaces.push(...await _(e, Ae));
1046
- }
1047
- };
1048
- this._layoutCompletion = (async () => {
1049
- for (let e = 0; e < o.slideCount; e += 1) await this._slides.withSlide(e, (e) => {
1050
- l.addSlide(e);
1051
- }), await d(), this._applyProgressivePrefix(l.snapshot(), a), e === 0 && a.deferred && await Vt();
1052
- await c, this._finishProgressiveLayout(l.finish(), a);
1053
- })().then(() => void 0, (e) => this._failProgressiveLayout(e, a)), await a.firstPublication.promise;
1054
- }
1055
- async _parseWorkerProgressively(e, t, n, r, i, a, o) {
1056
- this._progressiveWatchdogMs = r;
1057
- let s = this._bridge.request((r) => (this._parseRequestId = r, {
1058
- kind: "parse",
1059
- id: r,
1060
- buffer: e,
1061
- resourcePolicy: t,
1062
- useGoogleFonts: n,
1063
- cjkFallback: this._cjkFallback,
1064
- renderers: a,
1065
- progressiveLayout: !0
1066
- }), [e], { timeoutMs: !1 });
1067
- this._rearmProgressiveWatchdog(), this._layoutCompletion = s.then((e) => {
1068
- this._parseRequestId = null;
1069
- let t = e;
1070
- t.usage && i?.(t.usage), this._finishProgressiveLayout(M(t.preflight), o);
1071
- }, (e) => {
1072
- this._parseRequestId = null, this._failProgressiveLayout(e, o);
1073
- }), await o.firstPublication.promise;
1074
- }
1075
- _createSlidePullClient(e, t, n) {
1076
- return new Ie({
1077
- slideCount: e,
1078
- transport: this._bridge.transport(Ne),
1079
- open: async (e, n, r) => {
1080
- await this._bridge.request((t) => ({
1081
- kind: "openSlideSession",
1082
- id: t,
1083
- slideIndex: e,
1084
- ...n
1085
- }), void 0, { timeoutMs: r ?? t });
1086
- },
1087
- onUsage: n
1088
- });
1089
- }
1090
- _onWorkerLayoutPush(e) {
1091
- if (!x((e, t) => this._worker.postMessage(e, t), e) && !(!("kind" in e) || e.kind !== "presentationLayoutPartial" || e.forId !== this._parseRequestId || !this._progressive)) try {
1092
- this._rearmProgressiveWatchdog(), e.usage && this._metrics?.observeUsage(e.usage), e.bootstrap && (this._bootstrap = A(e.bootstrap));
1093
- let t = this._bootstrap;
1094
- if (!t) throw Error("PPTX progressive worker published before bootstrap");
1095
- let n = this._preflight?.slides ?? [];
1096
- if (e.availableSlides !== n.length + 1 || e.slide.index !== n.length) throw Error("PPTX progressive worker published a non-sequential slide");
1097
- this._applyProgressivePrefix(Fe({
1098
- ...t,
1099
- slides: [...n, e.slide],
1100
- fontPreloadNames: e.fontPreloadNames
1101
- }), this._progressive), Vt().then(() => {
1102
- this._destroyed || this._parseRequestId !== e.forId || this._bridge.post({
1103
- kind: "continuePresentationPreflight",
1104
- forId: e.forId,
1105
- availableSlides: e.availableSlides
1106
- });
1107
- }).catch((t) => {
1108
- this._destroyed || this._parseRequestId !== e.forId || !this._progressive || (this._failProgressiveLayout(t, this._progressive), this._bridge.terminate());
1109
- });
1110
- } catch (e) {
1111
- this._failProgressiveLayout(e, this._progressive), this._bridge.terminate();
1112
- }
1113
- }
1114
- _applyProgressivePrefix(e, t) {
1115
- if (!(t.settled || this._destroyed)) {
1116
- if (this._preflight = e, this._availableSlideCount = e.slides.length, !t.published && e.slides.length === e.slideCount) {
1117
- t.published = !0, t.deferred = !1;
1118
- return;
1119
- }
1120
- if (this._layoutLifecycle.begin(), this._wakeLayoutWaiters(), this._layoutObservers.notify("onLayoutProgress", t.onProgress, { committedUnits: this._availableSlideCount }), q(this, {
1121
- availableSlides: this._availableSlideCount,
1122
- slideCount: this.slideCount,
1123
- exact: !1,
1124
- complete: !1
1125
- }), !t.published) {
1126
- t.published = !0, t.deferred = e.slides.length < e.slideCount, t.firstPublication.resolve();
1127
- return;
1128
- }
1129
- this._layoutObservers.notify("onLayoutPartial", t.onPartial, {
1130
- availableUnits: this._availableSlideCount,
1131
- totalUnits: this.slideCount,
1132
- exact: !1
1133
- });
1134
- }
1135
- }
1136
- _finishProgressiveLayout(e, t) {
1137
- 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, {
1138
- availableSlides: this._availableSlideCount,
1139
- slideCount: this.slideCount,
1140
- exact: !0,
1141
- complete: !0
1142
- }), this._layoutObservers.notify("onLayoutComplete", t.onComplete));
1143
- }
1144
- _failProgressiveLayout(e, t) {
1145
- if (t.settled || (t.settled = !0, this._clearProgressiveWatchdog(), this._destroyed)) return;
1146
- if (!t.deferred) {
1147
- t.firstPublication.reject(e);
1148
- return;
1149
- }
1150
- let n = this._layoutLifecycle.fail(e);
1151
- this._wakeLayoutWaiters(), q(this, {
1152
- availableSlides: this._availableSlideCount,
1153
- slideCount: this.slideCount,
1154
- exact: !1,
1155
- complete: !1,
1156
- error: n
1157
- }), this._layoutObservers.notify("onLayoutComplete", t.onComplete, n);
1158
- }
1159
- _wakeLayoutWaiters() {
1160
- for (let e of this._layoutWaiters) e();
1161
- this._layoutWaiters.clear();
1162
- }
1163
- _rearmProgressiveWatchdog() {
1164
- this._progressiveWatchdogMs !== void 0 && (clearTimeout(this._progressiveWatchdog), this._progressiveWatchdog = setTimeout(() => {
1165
- let e = this._progressive, t = this._progressiveWatchdogMs;
1166
- if (!e || e.settled || t === void 0 || this._destroyed) return;
1167
- let n = /* @__PURE__ */ Error(`worker layout produced no progress for ${t}ms`);
1168
- this._failProgressiveLayout(n, e), this._bridge.terminate();
1169
- }, this._progressiveWatchdogMs));
1170
- }
1171
- _clearProgressiveWatchdog() {
1172
- clearTimeout(this._progressiveWatchdog), this._progressiveWatchdog = void 0, this._progressiveWatchdogMs = void 0;
1173
- }
1174
- async _waitForSlide(e) {
1175
- for (; !this._destroyed && e >= this._availableSlideCount && !this._layoutLifecycle.settled;) await new Promise((e) => this._layoutWaiters.add(e));
1176
- e >= this._availableSlideCount && await this.waitUntilLayoutComplete();
1177
- }
1178
- _assertSlideIndex(e) {
1179
- if (!Number.isInteger(e) || e < 0 || e >= this.slideCount) throw Error(`Slide index ${e} out of range (count: ${this.slideCount})`);
1180
- }
1181
- get slideCount() {
1182
- return this._bootstrap?.slideCount ?? this._preflight?.slideCount ?? 0;
1183
- }
1184
- get availableSlideCount() {
1185
- return this._availableSlideCount;
1186
- }
1187
- get layoutComplete() {
1188
- return this._layoutLifecycle.complete;
1189
- }
1190
- async waitUntilLayoutComplete() {
1191
- this._layoutCompletion && await this._layoutCompletion, this._layoutLifecycle.throwIfFailed();
1192
- }
1193
- get slideWidth() {
1194
- return this._bootstrap?.slideWidth ?? this._preflight?.slideWidth ?? 0;
1195
- }
1196
- get slideHeight() {
1197
- return this._bootstrap?.slideHeight ?? this._preflight?.slideHeight ?? 0;
1198
- }
1199
- get mode() {
1200
- return this._mode;
1201
- }
1202
- getNotes(e) {
1203
- return Number.isInteger(e) ? this._preflight?.slides[e]?.notes ?? null : null;
1204
- }
1205
- getComments(e) {
1206
- return Number.isInteger(e) ? this._preflight?.slides[e]?.comments ?? [] : [];
1207
- }
1208
- isHidden(e) {
1209
- return Number.isInteger(e) ? this._preflight?.slides[e]?.hidden ?? !1 : !1;
1210
- }
1211
- _partNames() {
1212
- return (this._bootstrap?.slides ?? this._preflight?.slides ?? []).map((e) => e.partName);
1213
- }
1214
- _partIndex() {
1215
- return this._slidePartIndex ||= gt(this._partNames()), this._slidePartIndex;
1216
- }
1217
- getSlideIndexByPartName(e) {
1218
- return this._partIndex().get(e);
1219
- }
1220
- resolveInternalTarget(e, t = 0) {
1221
- return vt(e, this._partIndex(), t);
1222
- }
1223
- async renderSlide(e, n, r = {}) {
1224
- this._assertResourceHealthy();
1225
- try {
1226
- if (this._mode === "worker") throw Error("renderSlide(canvas) is unavailable in mode: 'worker'; use renderSlideToBitmap() and paint it via an ImageBitmapRenderingContext");
1227
- this._assertSlideIndex(n), await this._waitForSlide(n);
1228
- let i = this._preflight, a = this._slides;
1229
- if (!i || !a) throw Error("Presentation not loaded");
1230
- let o = r.dpr ?? t(), s = r.width ?? ((l(e) ? e.offsetWidth : 0) || 960);
1231
- await a.withSlide(n, (t) => (this._assertResourceHealthy(), Le(e, t, i.slideWidth, i.slideHeight, {
1232
- width: s,
1233
- dpr: o,
1234
- defaultTextColor: i.defaultTextColor,
1235
- cjkFallback: this._cjkFallback,
1236
- majorFont: i.majorFont,
1237
- minorFont: i.minorFont,
1238
- hlinkColor: i.hlinkColor,
1239
- embeddedFontAliases: this._embeddedFontAliases,
1240
- embeddedFontAuthoredFamilies: this._embeddedFontAuthoredFamilies,
1241
- fetchMedia: this._fetchMedia,
1242
- fetchImage: this._fetchImage,
1243
- skipMediaControls: r.skipMediaControls,
1244
- dim: r.dim,
1245
- math: this._math,
1246
- threeD: this._threeD,
1247
- regionMap: this._regionMap,
1248
- chartEx: this._chartEx,
1249
- tiff: this._tiff,
1250
- imageResources: r.imageResources
1251
- }, r.onTextRun)));
1252
- } catch (e) {
1253
- this._rethrowWithResourceFailure(e);
1254
- }
1255
- }
1256
- async renderSlideToBitmap(e, n = {}) {
1257
- this._assertResourceHealthy();
1258
- try {
1259
- this._assertSlideIndex(e), await this._waitForSlide(e);
1260
- let r = n.width ?? 960, i = n.dpr ?? t();
1261
- if (this._mode === "worker") {
1262
- let t = await this._bridge.request((t) => ({
1263
- kind: "renderSlide",
1264
- id: t,
1265
- slideIndex: e,
1266
- width: r,
1267
- dpr: i,
1268
- imageResources: n.imageResources,
1269
- skipMediaControls: n.skipMediaControls,
1270
- dim: n.dim
1271
- }));
1272
- try {
1273
- if (n.onTextRun) for (let e of t.runs) n.onTextRun(e);
1274
- } catch (e) {
1275
- throw c(t.bitmap), e;
1276
- }
1277
- return t.bitmap;
1278
- }
1279
- let a = new OffscreenCanvas(1, 1);
1280
- return await this.renderSlide(a, e, {
1281
- width: r,
1282
- dpr: i,
1283
- imageResources: n.imageResources,
1284
- skipMediaControls: n.skipMediaControls,
1285
- dim: n.dim,
1286
- onTextRun: n.onTextRun
1287
- }), a.transferToImageBitmap();
1288
- } catch (e) {
1289
- this._rethrowWithResourceFailure(e);
1290
- }
1291
- }
1292
- async collectSlideRuns(e, t = 960) {
1293
- this._assertResourceHealthy();
1294
- try {
1295
- if (this._assertSlideIndex(e), await this._waitForSlide(e), this._mode === "worker") return (await this._bridge.request((n) => ({
1296
- kind: "collectRuns",
1297
- id: n,
1298
- slideIndex: e,
1299
- width: t
1300
- }))).runs;
1301
- let n = [], r = new OffscreenCanvas(1, 1);
1302
- return await this.renderSlide(r, e, {
1303
- width: t,
1304
- onTextRun: (e) => n.push(e)
1305
- }), n;
1306
- } catch (e) {
1307
- this._rethrowWithResourceFailure(e);
1308
- }
1309
- }
1310
- async getElementContextAt(e, t, n = {}) {
1311
- this._assertResourceHealthy(), this._assertSlideIndex(e);
1312
- try {
1313
- if (await this._waitForSlide(e), this._mode === "worker") return (await this._bridge.request((r) => ({
1314
- kind: "hitTestElement",
1315
- id: r,
1316
- slideIndex: e,
1317
- point: t,
1318
- options: n
1319
- }))).context;
1320
- if (!this._slides) throw Error("Presentation not loaded");
1321
- return await this._slides.withSlide(e, (r) => Rt(e, r, t, n));
1322
- } catch (e) {
1323
- this._rethrowWithResourceFailure(e);
1324
- }
1325
- }
1326
- async getElementBoundsByIds(e, t) {
1327
- this._assertResourceHealthy(), this._assertSlideIndex(e);
1328
- let n = Object.freeze(t.filter((e) => typeof e == "string" && e.length > 0));
1329
- if (n.length === 0) return Object.freeze([]);
1330
- try {
1331
- if (await this._waitForSlide(e), this._mode === "worker") return (await this._bridge.request((t) => ({
1332
- kind: "resolveElementBounds",
1333
- id: t,
1334
- slideIndex: e,
1335
- elementIds: n
1336
- }))).bounds;
1337
- if (!this._slides) throw Error("Presentation not loaded");
1338
- return await this._slides.withSlide(e, (e) => zt(e, n));
1339
- } catch (e) {
1340
- this._rethrowWithResourceFailure(e);
1341
- }
1342
- }
1343
- async getMedia(e) {
1344
- this._assertResourceHealthy();
1345
- try {
1346
- let t = this._findMimeTypeForPath(e);
1347
- return await this._rawParts.get(e, t, async () => {
1348
- let n = (await this._bridge.request((t) => ({
1349
- kind: "extractMedia",
1350
- id: t,
1351
- path: e
1352
- }))).bytes;
1353
- return new Blob([n], { type: t });
1354
- });
1355
- } catch (e) {
1356
- this._rethrowWithResourceFailure(e);
1357
- }
1358
- }
1359
- _findMimeTypeForPath(e) {
1360
- return this._preflight ? je(this._preflight, e) : "";
1361
- }
1362
- async getImage(e, t) {
1363
- this._assertResourceHealthy();
1364
- try {
1365
- return await this._rawParts.get(e, t, async () => {
1366
- let n = (await this._bridge.request((t) => ({
1367
- kind: "extractImage",
1368
- id: t,
1369
- path: e
1370
- }))).bytes;
1371
- return new Blob([n], { type: t });
1372
- });
1373
- } catch (e) {
1374
- this._rethrowWithResourceFailure(e);
1375
- }
1376
- }
1377
- async getFontBytes(e) {
1378
- this._assertResourceHealthy();
1379
- try {
1380
- let t = await this._bridge.request((t) => ({
1381
- kind: "extractFont",
1382
- id: t,
1383
- path: e
1384
- }));
1385
- return new Uint8Array(t.bytes);
1386
- } catch (e) {
1387
- this._rethrowWithResourceFailure(e);
1388
- }
1389
- }
1390
- async getResourceMetrics() {
1391
- let e = this._metrics;
1392
- if (!e) throw Error("Presentation not loaded");
1393
- return i(e, async (e) => (await this._bridge.request((e) => ({
1394
- kind: "resourceUsage",
1395
- id: e
1396
- }), void 0, { timeoutMs: e })).usage);
1397
- }
1398
- async toMarkdown() {
1399
- this._assertResourceHealthy();
1400
- try {
1401
- return (await this._bridge.request((e) => ({
1402
- kind: "toMarkdown",
1403
- id: e
1404
- }))).markdown;
1405
- } catch (e) {
1406
- this._rethrowWithResourceFailure(e);
1407
- }
1408
- }
1409
- async presentSlide(e, n, r = {}) {
1410
- this._assertResourceHealthy();
1411
- try {
1412
- if (this._assertSlideIndex(n), await this._waitForSlide(n), !this._preflight) throw Error("Presentation not loaded");
1413
- let i = r.dpr ?? t(), a = r.width ?? (e.offsetWidth || 960), o = this.slideWidth > 0 ? a * this.slideHeight / this.slideWidth : 0;
1414
- e.style.width = `${Math.round(a)}px`, e.style.height = `${Math.round(o)}px`, e.style.display || (e.style.display = "block");
1415
- let s = this._mode === "worker" ? async () => {
1416
- let t = await this.renderSlideToBitmap(n, {
1417
- width: a,
1418
- dpr: i,
1419
- imageResources: r.imageResources,
1420
- skipMediaControls: !0,
1421
- dim: r.dim,
1422
- onTextRun: r.onTextRun
1423
- });
1424
- try {
1425
- e.width = t.width, e.height = t.height;
1426
- let n = e.getContext("2d");
1427
- if (!n) throw Error("2D context not available");
1428
- n.drawImage(t, 0, 0);
1429
- } finally {
1430
- c(t);
1431
- }
1432
- } : () => this.renderSlide(e, n, {
1433
- width: a,
1434
- dpr: i,
1435
- imageResources: r.imageResources,
1436
- skipMediaControls: !0,
1437
- dim: r.dim,
1438
- onTextRun: r.onTextRun
1439
- });
1440
- return await tt(e, this._preflight.slides[n]?.mediaElements ?? [], {
1441
- width: a,
1442
- height: o,
1443
- slideWidthEmu: this.slideWidth,
1444
- fetchMedia: this._fetchMedia,
1445
- fetchImage: this._fetchImage,
1446
- drawBase: s,
1447
- onError: r.onError
1448
- });
1449
- } catch (e) {
1450
- this._rethrowWithResourceFailure(e);
1451
- }
1452
- }
1453
- destroy() {
1454
- 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);
1455
- }
1456
- };
1457
- //#endregion
1458
- //#region packages/pptx/src/selection-context.ts
1459
- function Ut(e, t, n, r, i = {}) {
1460
- let a = be({
1461
- id: e.id,
1462
- author: e.author,
1463
- date: e.date,
1464
- text: e.text,
1465
- status: e.status ?? "active"
1466
- }, (e.replies ?? []).map((e) => ({
1467
- id: e.id,
1468
- author: e.author,
1469
- date: e.date,
1470
- text: e.text,
1471
- status: e.status ?? "active"
1472
- })), i.maxTextCharacters);
1473
- return Object.freeze({
1474
- format: "pptx",
1475
- kind: "comment",
1476
- slideIndex: t,
1477
- commentIndex: n,
1478
- occurrenceId: r,
1479
- ...e.id ? { commentId: e.id } : {},
1480
- ...Number.isFinite(e.x) && Number.isFinite(e.y) ? { point: Object.freeze({
1481
- x: e.x,
1482
- y: e.y
1483
- }) } : {},
1484
- thread: a.thread,
1485
- truncated: a.truncated,
1486
- truncationReasons: a.truncated ? ["text"] : [],
1487
- textCharacters: a.textCharacters,
1488
- maxTextCharacters: a.maxTextCharacters
1489
- });
1490
- }
1491
- function Y(e) {
1492
- if (e === void 0 || !/^\d+$/.test(e)) return null;
1493
- let t = Number(e);
1494
- return Number.isSafeInteger(t) ? t : null;
1495
- }
1496
- function Wt(e) {
1497
- for (let t = e; t; t = t.parentElement) {
1498
- let e = Y(t.dataset.slideIndex);
1499
- if (e !== null) return e;
1500
- }
1501
- return null;
1502
- }
1503
- function X(e, t, n = {}) {
1504
- let r = ue(e, t, (e) => {
1505
- let t = Wt(e), n = Y(e.dataset.runIndex);
1506
- if (t === null || n === null) return null;
1507
- let r = Y(e.dataset.elementIndex), i = e.dataset.elementOrigin, a = r !== null && (i === "master" || i === "layout" || i === "slide");
1508
- return {
1509
- slideIndex: t,
1510
- runIndex: n,
1511
- ...e.dataset.shapeId === void 0 ? {} : { shapeId: e.dataset.shapeId },
1512
- ...a ? {
1513
- elementIndex: r,
1514
- origin: i
1515
- } : {}
1516
- };
1517
- }, {
1518
- maxChars: n.maxTextCharacters,
1519
- maxLocators: n.maxRunLocators
1520
- });
1521
- if (!r) return null;
1522
- let i = [...r.locators].sort((e, t) => e.slideIndex - t.slideIndex || e.runIndex - t.runIndex);
1523
- return {
1524
- format: "pptx",
1525
- kind: "text",
1526
- text: r.text,
1527
- slideIndexes: [...new Set(i.map((e) => e.slideIndex))],
1528
- shapeIds: [...new Set(i.flatMap((e) => e.shapeId ? [e.shapeId] : []))],
1529
- runs: i,
1530
- truncated: r.truncated,
1531
- truncationReasons: r.truncationReasons,
1532
- textCharacters: r.textCharacters,
1533
- maxTextCharacters: r.maxTextCharacters,
1534
- maxRunLocators: r.maxLocators
1535
- };
1536
- }
1537
- //#endregion
1538
- //#region packages/pptx/src/focused-view-runtime.ts
1539
- function Z(e, t, n, r, i) {
1540
- return r === "worker" ? e.renderSlideToBitmap(n, i) : e.renderSlide(t, n, i);
1541
- }
1542
- //#endregion
1543
- //#region packages/pptx/src/loading-indicator.ts
1544
- function Gt(e) {
1545
- let t = e.createElement("span");
1546
- t.style.cssText = [
1547
- "position:absolute",
1548
- "top:0",
1549
- "right:0",
1550
- "bottom:0",
1551
- "left:0",
1552
- "display:none",
1553
- "align-items:center",
1554
- "justify-content:center",
1555
- "background:rgba(255,255,255,0.72)",
1556
- "backdrop-filter:blur(2px)",
1557
- "pointer-events:none",
1558
- "z-index:4"
1559
- ].join(";"), t.setAttribute("role", "status"), t.setAttribute("aria-live", "polite"), t.setAttribute("aria-label", "Loading slide");
1560
- let n = e.createElement("span");
1561
- return n.className = "ooxml-pptx-progress-circle", n.style.cssText = [
1562
- "width:34px",
1563
- "height:34px",
1564
- "box-sizing:border-box",
1565
- "border-radius:50%",
1566
- "border:3px solid var(--border-bright, rgba(100,116,139,0.28))",
1567
- "border-top-color:var(--signal, #12bfd8)",
1568
- "box-shadow:0 2px 10px rgba(15,23,42,0.08)"
1569
- ].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)" }], {
1570
- duration: 800,
1571
- iterations: Infinity,
1572
- easing: "linear"
1573
- }), t;
1574
- }
1575
- //#endregion
1576
- //#region packages/pptx/src/viewer.ts
1577
- var Kt = Symbol("PptxViewer.borrowedPresentation"), qt = {
1578
- color: "#ffffff",
1579
- opacity: .6
1580
- }, Q = class e {
1581
- canvas;
1582
- wrapper;
1583
- canvasMount;
1584
- _scale = null;
1585
- textLayer = null;
1586
- highlightLayer = null;
1587
- elementLayer = null;
1588
- _find;
1589
- _findGeneration = 0;
1590
- _measureCtx = null;
1591
- presentationOwner;
1592
- get engine() {
1593
- return this.presentationOwner.current;
1594
- }
1595
- borrowed;
1596
- hostWindow;
1597
- opts;
1598
- currentSlide = 0;
1599
- _renderedSlide = -1;
1600
- _hiddenMode;
1601
- handle = null;
1602
- _mode;
1603
- renderDispatcher;
1604
- errorRouter;
1605
- destroyed = !1;
1606
- selectionChangeListener = null;
1607
- selectionContextKey = "null";
1608
- elementClickListener = null;
1609
- contextMenuListener = null;
1610
- elementContext = null;
1611
- elementHitGeneration = 0;
1612
- elementHitTolerance;
1613
- _loadingLayer;
1614
- _layoutUnsubscribe = null;
1615
- _layoutWaiters = /* @__PURE__ */ new Set();
1616
- _layoutFailed = !1;
1617
- _navigationGeneration = 0;
1618
- _renderProgressGeneration = 0;
1619
- _lastReportedSlide = -1;
1620
- _lastReportedTotal = -1;
1621
- _lastReportedAvailable = -1;
1622
- _lastReportedLayoutComplete = null;
1623
- static fromPresentation(t, n, r = {}) {
1624
- return new e(t, {
1625
- ...r,
1626
- [Kt]: n
1627
- });
1628
- }
1629
- constructor(e, t = {}) {
1630
- this.opts = t, this.canvas = e;
1631
- let n = t[Kt];
1632
- this.borrowed = n !== void 0, this._mode = D("PptxViewer", t.mode, n), this.presentationOwner = new w("PptxViewer", n ?? null, !1);
1633
- let r = e.ownerDocument?.defaultView ?? (typeof window < "u" ? window : null);
1634
- if (!r) throw Error("PptxViewer requires a canvas with an active Window");
1635
- this.hostWindow = r;
1636
- let i = t.elementHitTolerance ?? 6;
1637
- if (!Number.isFinite(i) || i < 0) throw RangeError("elementHitTolerance must be a finite non-negative number.");
1638
- this.elementHitTolerance = i, this._hiddenMode = t.hiddenSlideMode ?? "show", this.canvasMount = new de(e, {
1639
- wrapperCssText: "position:relative;display:inline-block;vertical-align:top;",
1640
- forceDisplayBlock: !0
1641
- }), this.wrapper = this.canvasMount.wrapper, this.renderDispatcher = new E(e, this._mode === "worker" && !t.enableMediaPlayback), this.errorRouter = new le("PptxViewer", t.onError);
1642
- let a = new oe(this.wrapper, t.enableTextSelection === !0, t.enableElementSelection === !0);
1643
- 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) => {
1644
- this._onElementClick(e).catch((e) => this._reportRenderError(e));
1645
- }, 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);
1646
- }
1647
- async load(e) {
1648
- if (this.destroyed) throw Error("PptxViewer is destroyed");
1649
- if (this.borrowed) throw Error("PptxViewer.load() is unsupported on a Viewer created by fromPresentation(); the borrowed presentation is already loaded.");
1650
- let t = !1;
1651
- try {
1652
- let n = await this.presentationOwner.replace(() => J.load(e, {
1653
- password: this.opts.password,
1654
- useGoogleFonts: this.opts.useGoogleFonts,
1655
- cjkFallback: this.opts.cjkFallback,
1656
- maxZipEntryBytes: this.opts.maxZipEntryBytes,
1657
- resourceLimits: this.opts.resourceLimits,
1658
- debug: this.opts.debug,
1659
- onResourceMetrics: this.opts.onResourceMetrics,
1660
- workerTimeoutMs: this.opts.workerTimeoutMs,
1661
- wasmUrl: this.opts.wasmUrl,
1662
- math: this.opts.math,
1663
- threeD: this.opts.threeD,
1664
- regionMap: this.opts.regionMap,
1665
- chartEx: this.opts.chartEx,
1666
- tiff: this.opts.tiff,
1667
- mode: this._mode,
1668
- progressiveLayout: this.opts.progressiveLayout,
1669
- onLayoutProgress: this.opts.onLayoutProgress,
1670
- onLayoutPartial: this.opts.onLayoutPartial,
1671
- onLayoutComplete: this.opts.onLayoutComplete
1672
- }), () => {
1673
- this._invalidateElementSelection(!1), t = !0, this.renderDispatcher.begin(), this._invalidateFind(), this.handle?.destroy(), this.handle = null, this._unbindLayoutPresentation();
1674
- });
1675
- if (!n) return;
1676
- if (this.destroyed) throw Error("PptxViewer is destroyed");
1677
- this._bindLayoutPresentation(n);
1678
- let r = this._beginNavigation();
1679
- if (this.currentSlide = await this._initialSlide(r), r !== this._navigationGeneration || n !== this.engine) return;
1680
- this._renderedSlide = -1, this._invalidateFind(), await this.renderCurrentSlide();
1681
- } catch (e) {
1682
- throw this.destroyed ? Error("PptxViewer is destroyed") : e instanceof Error ? e : Error(String(e));
1683
- }
1684
- t && !this.destroyed && this._emitSelectionContextChange();
1685
- }
1686
- async goToSlide(e) {
1687
- let t = this._beginNavigation();
1688
- await this._goToSlide(e, t);
1689
- }
1690
- async _goToSlide(e, t) {
1691
- if (t !== this._navigationGeneration || !this.engine || this.slideCount === 0) return;
1692
- let n = Math.max(0, Math.min(e, this.slideCount - 1)), r = n !== this.currentSlide;
1693
- r && this._invalidateElementSelection(!1), this.currentSlide = n, await this.renderCurrentSlide(), r && !this.destroyed && this._emitSelectionContextChange();
1694
- }
1695
- async nextSlide() {
1696
- let e = this._beginNavigation(), t = await this._step(1, e);
1697
- await this._goToSlide(t, e);
1698
- }
1699
- async prevSlide() {
1700
- let e = this._beginNavigation(), t = await this._step(-1, e);
1701
- await this._goToSlide(t, e);
1702
- }
1703
- async _step(e, t) {
1704
- let n = this.engine, r = this.currentSlide;
1705
- if (this._hiddenMode !== "skip" || !n) return r + e;
1706
- for (let i = r + e; i >= 0 && i < this.slideCount; i += e) {
1707
- if (i >= n.availableSlideCount && (n.layoutComplete || this._setLoading(!0), !await this._waitForSlide(n, i, () => t === this._navigationGeneration))) return r;
1708
- if (!n.isHidden(i)) return i;
1709
- }
1710
- return r;
1711
- }
1712
- async _initialSlide(e) {
1713
- let t = this.engine;
1714
- if (this._hiddenMode !== "skip" || !t || this.slideCount === 0 || t.availableSlideCount === 0 && !await this._waitForSlide(t, 0, () => e === this._navigationGeneration) || !t.isHidden(0)) return 0;
1715
- let n = await this._step(1, e);
1716
- return n === 0 ? 0 : n;
1717
- }
1718
- _dim() {
1719
- return {
1720
- color: this.opts.hiddenSlideDim?.color ?? qt.color,
1721
- opacity: this.opts.hiddenSlideDim?.opacity ?? qt.opacity
1722
- };
1723
- }
1724
- async setHiddenSlideMode(e) {
1725
- let t = this._beginNavigation();
1726
- this._hiddenMode = e;
1727
- let n = this.currentSlide;
1728
- if (e === "skip" && this.engine) {
1729
- let e = this.engine;
1730
- if (this.currentSlide >= e.availableSlideCount && !await this._waitForSlide(e, this.currentSlide, () => t === this._navigationGeneration)) return;
1731
- e.isHidden(this.currentSlide) && (n = await this._step(1, t), n === this.currentSlide && (n = await this._step(-1, t)));
1732
- }
1733
- if (t !== this._navigationGeneration) return;
1734
- let r = n !== this.currentSlide;
1735
- r && this._invalidateElementSelection(!1), this.currentSlide = n, await this.renderCurrentSlide(), r && !this.destroyed && this._emitSelectionContextChange();
1736
- }
1737
- get hiddenSlideMode() {
1738
- return this._hiddenMode;
1739
- }
1740
- get visibleSlideCount() {
1741
- if (!this.engine) return 0;
1742
- let e = this.engine;
1743
- return ze((t) => e.isHidden(t), this.slideCount);
1744
- }
1745
- get slideIndex() {
1746
- return this.currentSlide;
1747
- }
1748
- get slideCount() {
1749
- return this.engine?.slideCount ?? 0;
1750
- }
1751
- get availableSlideCount() {
1752
- return this.engine?.availableSlideCount ?? this.slideCount;
1753
- }
1754
- get layoutComplete() {
1755
- return this.engine?.layoutComplete ?? !0;
1756
- }
1757
- async waitUntilLayoutComplete() {
1758
- await this.errorRouter.ownBackgroundLifecycle(async () => {
1759
- await this.engine?.waitUntilLayoutComplete?.();
1760
- });
1761
- }
1762
- getNotes(e) {
1763
- return this.engine?.getNotes(e) ?? null;
1764
- }
1765
- get canvasElement() {
1766
- return this.canvas;
1767
- }
1768
- _naturalWidthPx() {
1769
- let e = this.engine?.slideWidth ?? 0;
1770
- return e > 0 ? e / k : 0;
1771
- }
1772
- _targetWidth() {
1773
- if (this._scale === null) return this.opts.width ?? (this.canvas.offsetWidth || 960);
1774
- let e = this._naturalWidthPx();
1775
- return e <= 0 ? this.opts.width ?? (this.canvas.offsetWidth || 960) : Math.round(e * this._scale);
1776
- }
1777
- getScale() {
1778
- if (this._scale !== null) return this._scale;
1779
- let e = this._naturalWidthPx();
1780
- return e <= 0 ? 1 : this._targetWidth() / e;
1781
- }
1782
- _zoomMin() {
1783
- return this.opts.zoomMin ?? .1;
1784
- }
1785
- _zoomMax() {
1786
- return this.opts.zoomMax ?? 4;
1787
- }
1788
- async setScale(e) {
1789
- let t = re(e, this._zoomMin(), this._zoomMax()), n = t !== this.getScale();
1790
- this._scale = t, await this.renderCurrentSlide(), n && this.opts.onScaleChange?.(t);
1791
- }
1792
- async zoomIn() {
1793
- await this.setScale(fe(this.getScale()));
1794
- }
1795
- async zoomOut() {
1796
- await this.setScale(he(this.getScale()));
1797
- }
1798
- async fitWidth() {
1799
- await this._fit("width");
1800
- }
1801
- async fitPage() {
1802
- await this._fit("page");
1803
- }
1804
- async _fit(e) {
1805
- if (!this.engine) return;
1806
- let t = this.wrapper.parentElement;
1807
- if (!t) return;
1808
- let n = C({
1809
- contentWidth: this.engine.slideWidth / k,
1810
- contentHeight: this.engine.slideHeight / k,
1811
- containerWidth: t.clientWidth,
1812
- containerHeight: t.clientHeight
1813
- }, e);
1814
- n <= 0 || await this.setScale(n);
1815
- }
1816
- async renderCurrentSlide() {
1817
- let e = this.engine;
1818
- if (!e) return;
1819
- let t = this.currentSlide, n = ++this._renderProgressGeneration;
1820
- this._setLoading(t >= this.availableSlideCount && !this.layoutComplete);
1821
- let r = this.renderDispatcher.begin();
1822
- try {
1823
- if (t >= e.availableSlideCount && !await this._waitForSlide(e, t, () => n === this._renderProgressGeneration && this.renderDispatcher.isCurrent(r) && e === this.engine && t === this.currentSlide)) return;
1824
- 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);
1825
- this.canvas.style.width = `${a}px`, this.canvas.style.height = `${c}px`, this.handle?.destroy(), this.handle = null;
1826
- let l = this._mode === "worker", u = [], d = (e) => u.push(e);
1827
- if (this.opts.enableMediaPlayback) {
1828
- let n = await e.presentSlide(this.canvas, t, {
1829
- width: a,
1830
- dpr: o,
1831
- imageResources: this.opts.imageResources,
1832
- dim: i,
1833
- onTextRun: d,
1834
- onError: (e) => {
1835
- this.renderDispatcher.isCurrent(r) && this._reportRenderError(e);
1836
- }
1837
- });
1838
- if (!this.renderDispatcher.isCurrent(r)) {
1839
- n.destroy();
1840
- return;
1841
- }
1842
- this.handle = n;
1843
- } else if (l) {
1844
- let e = await Z(this.engine, this.canvas, t, "worker", {
1845
- width: a,
1846
- dpr: o,
1847
- imageResources: this.opts.imageResources,
1848
- dim: i,
1849
- onTextRun: d
1850
- });
1851
- if (!this.renderDispatcher.commitBitmap(r, e)) return;
1852
- } else if (await Z(this.engine, this.canvas, t, "main", {
1853
- width: a,
1854
- dpr: o,
1855
- imageResources: this.opts.imageResources,
1856
- onTextRun: d,
1857
- dim: i
1858
- }), !this.renderDispatcher.isCurrent(r)) return;
1859
- 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);
1860
- } catch (t) {
1861
- if (!this.renderDispatcher.isCurrent(r) && !(e === this.engine && this._layoutFailed)) return;
1862
- throw t;
1863
- } finally {
1864
- n === this._renderProgressGeneration && this._setLoading(!1);
1865
- }
1866
- }
1867
- _bindLayoutPresentation(e) {
1868
- this._unbindLayoutPresentation(), this._layoutFailed = !1;
1869
- let t = !0;
1870
- this._layoutUnsubscribe = Bt(e, () => ({
1871
- availableSlides: e.availableSlideCount,
1872
- slideCount: e.slideCount,
1873
- exact: e.layoutComplete,
1874
- complete: e.layoutComplete
1875
- }), (n) => {
1876
- if (t) {
1877
- t = !1;
1878
- return;
1879
- }
1880
- this._onLayoutPublication(e, n);
1881
- }, (e) => this._reportRenderError(e));
1882
- }
1883
- _unbindLayoutPresentation() {
1884
- this._layoutUnsubscribe?.(), this._layoutUnsubscribe = null, this._layoutFailed = !1, this._navigationGeneration++, this._renderProgressGeneration++, this._wakeLayoutWaiters(), this._setLoading(!1);
1885
- }
1886
- _beginNavigation() {
1887
- let e = ++this._navigationGeneration;
1888
- return this._wakeLayoutWaiters(), e;
1889
- }
1890
- _onLayoutPublication(e, t) {
1891
- if (!(this.destroyed || e !== this.engine)) {
1892
- if (this._wakeLayoutWaiters(), t.error !== void 0) {
1893
- this._layoutFailed = !0, this.errorRouter.reportBackground(t.error, this.opts.onLayoutComplete !== void 0);
1894
- return;
1895
- }
1896
- this._renderedSlide === this.currentSlide && this._emitSlideChange();
1897
- }
1898
- }
1899
- async _waitForSlide(e, t, n) {
1900
- return await this.errorRouter.ownBackgroundLifecycle(async () => {
1901
- for (; !this.destroyed && n() && e === this.engine && t >= e.availableSlideCount && !e.layoutComplete && !this._layoutFailed;) await new Promise((e) => this._layoutWaiters.add(e));
1902
- return this.destroyed || e !== this.engine || ((e.layoutComplete || this._layoutFailed) && await e.waitUntilLayoutComplete?.(), !n()) ? !1 : t < e.availableSlideCount;
1903
- });
1904
- }
1905
- _wakeLayoutWaiters() {
1906
- for (let e of this._layoutWaiters) e();
1907
- this._layoutWaiters.clear();
1908
- }
1909
- _emitSlideChange(e = !1) {
1910
- let t = this.slideCount, n = this.availableSlideCount, r = this.layoutComplete;
1911
- !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));
1912
- }
1913
- _setLoading(e) {
1914
- this._loadingLayer.style.display = e ? "flex" : "none";
1915
- }
1916
- _buildHighlightLayer(e, t, n) {
1917
- let r = this.highlightLayer;
1918
- r && L(r, e, this._find.slideHighlights(this.currentSlide), t, n, (e) => this._measureForFont(e), this.opts.findHighlightColors);
1919
- }
1920
- _measureForFont(e) {
1921
- this._measureCtx ||= document.createElement("canvas").getContext("2d");
1922
- let t = this._measureCtx;
1923
- return t ? (t.font = e, (e) => t.measureText(e).width) : (e) => e.length;
1924
- }
1925
- async _collectSlideRuns(e) {
1926
- return this.engine ? this.engine.collectSlideRuns(e, this._targetWidth()) : [];
1927
- }
1928
- async findText(e, t = {}) {
1929
- let n = this.engine;
1930
- if (!n) return [];
1931
- let r = ++this._findGeneration;
1932
- if (e.length === 0) return this._find.invalidate(), this._redrawHighlights(), [];
1933
- if (n.layoutComplete || await this.errorRouter.ownBackgroundLifecycle(() => n.waitUntilLayoutComplete()), this.destroyed || r !== this._findGeneration || n !== this.engine) return [];
1934
- let i = await this.errorRouter.ownAwaitable(() => this._find.find(e, t));
1935
- return this.destroyed || r !== this._findGeneration || n !== this.engine ? [] : (this._redrawHighlights(), i);
1936
- }
1937
- async findNext() {
1938
- return this._activateMatch(this._find.next());
1939
- }
1940
- async findPrev() {
1941
- return this._activateMatch(this._find.prev());
1942
- }
1943
- clearFind() {
1944
- this._invalidateFind(), this._redrawHighlights();
1945
- }
1946
- _invalidateFind() {
1947
- this._findGeneration++, this._find.invalidate();
1948
- }
1949
- async _activateMatch(e) {
1950
- return e ? (e.location.slide === this.currentSlide ? this._redrawHighlights() : await this.goToSlide(e.location.slide), e) : (this._redrawHighlights(), null);
1951
- }
1952
- _redrawHighlights() {
1953
- let e = this._find.slideRuns(this.currentSlide) ?? [], t = this._targetWidth(), n = this.engine ? Math.round(this.engine.slideHeight * (t / this.engine.slideWidth)) : 0;
1954
- this._buildHighlightLayer(e, t, n);
1955
- }
1956
- _buildTextLayer(e, t, n, r) {
1957
- I(e, t, n, r, this._hyperlinkHandler(), this.currentSlide);
1958
- }
1959
- _hyperlinkHandler() {
1960
- if (this.opts.enableHyperlinks !== !1) return (e) => this._onHyperlinkClick(e);
1961
- }
1962
- _onHyperlinkClick(e) {
1963
- let t = this._resolveInternalSlideIndex(e);
1964
- if (this.opts.onHyperlinkClick) {
1965
- this.opts.onHyperlinkClick(t);
1966
- return;
1967
- }
1968
- if (t.kind === "external") {
1969
- p(t.url, void 0, this.hostWindow);
1970
- return;
1971
- }
1972
- t.slideIndex !== void 0 && this.goToSlide(t.slideIndex).catch((e) => this._reportRenderError(e));
1973
- }
1974
- _resolveInternalSlideIndex(e) {
1975
- if (e.kind !== "internal" || e.slideIndex !== void 0) return e;
1976
- let t = this.engine?.resolveInternalTarget(e.ref, this.currentSlide);
1977
- return t === void 0 ? e : {
1978
- ...e,
1979
- slideIndex: t
1980
- };
1981
- }
1982
- _reportRenderError(e) {
1983
- this.errorRouter.report(e);
1984
- }
1985
- async getResourceMetrics() {
1986
- if (!this.engine) throw Error("Presentation not loaded");
1987
- return await this.engine.getResourceMetrics();
1988
- }
1989
- getSelectionContext(e = {}) {
1990
- if (this.destroyed) throw Error("PptxViewer is destroyed");
1991
- return (this.textLayer ? X(this.wrapper, this.wrapper.ownerDocument?.getSelection?.() ?? null, e) : null) ?? (this.elementContext ? It(this.elementContext, e.maxTextCharacters) : null);
1992
- }
1993
- _emitSelectionContextChange() {
1994
- let e = this.getSelectionContext();
1995
- e?.kind === "text" && (this.elementHitGeneration++, this.elementContext = null, this._redrawElementOutline());
1996
- let t = JSON.stringify(e);
1997
- t !== this.selectionContextKey && (this.selectionContextKey = t, this.opts.onSelectionContextChange?.(e ? structuredClone(e) : null));
1998
- }
1999
- _setElementContext(e) {
2000
- this.elementContext = e ? structuredClone(e) : null, this._redrawElementOutline(), this._emitSelectionContextChange();
2001
- }
2002
- _invalidateElementSelection(e = !0) {
2003
- this.elementHitGeneration++, this.elementContext = null, this._redrawElementOutline(), e && this._emitSelectionContextChange();
2004
- }
2005
- _redrawElementOutline() {
2006
- let e = this.elementContext, t = this.engine;
2007
- if (!e || !t || e.slideIndex !== this.currentSlide) {
2008
- T(this.elementLayer, null);
2009
- return;
2010
- }
2011
- T(this.elementLayer, {
2012
- x: e.bounds.x / t.slideWidth,
2013
- y: e.bounds.y / t.slideHeight,
2014
- width: e.bounds.width / t.slideWidth,
2015
- height: e.bounds.height / t.slideHeight,
2016
- rotation: e.bounds.rotation
2017
- });
2018
- }
2019
- async _onElementClick(e) {
2020
- this.destroyed || e.defaultPrevented || e.button !== 0 || await this._resolveContextAt(e);
2021
- }
2022
- _onContextMenu(e) {
2023
- let t;
2024
- this.opts.onContextMenu?.({
2025
- originalEvent: e,
2026
- getContext: () => t ??= this._resolveContextAt(e)
2027
- });
2028
- }
2029
- async _resolveContextAt(e) {
2030
- let t = this.engine;
2031
- if (this.destroyed || !t) return null;
2032
- if (this.textLayer && X(this.wrapper, this.wrapper.ownerDocument?.getSelection?.() ?? null)) return this._emitSelectionContextChange(), this.destroyed ? null : this.getSelectionContext();
2033
- if (!this.opts.enableElementSelection) return this.getSelectionContext();
2034
- let n = this.canvas.getBoundingClientRect();
2035
- if (n.width <= 0 || n.height <= 0) return this._invalidateElementSelection(), null;
2036
- let r = e.clientX - n.left, i = e.clientY - n.top;
2037
- if (r < 0 || i < 0 || r > n.width || i > n.height) return this._invalidateElementSelection(), null;
2038
- let a = ++this.elementHitGeneration, o = this.currentSlide, s = {
2039
- x: r / n.width * t.slideWidth,
2040
- y: i / n.height * t.slideHeight
2041
- }, c;
2042
- try {
2043
- c = await t.getElementContextAt(o, s, {
2044
- tolerance: this.elementHitTolerance / n.width * t.slideWidth,
2045
- maxTextCharacters: G
2046
- });
2047
- } catch (e) {
2048
- if (this.destroyed || a !== this.elementHitGeneration || o !== this.currentSlide || t !== this.engine) return null;
2049
- throw e;
2050
- }
2051
- return this.destroyed || a !== this.elementHitGeneration || o !== this.currentSlide || t !== this.engine ? null : (this._setElementContext(c), this.destroyed ? null : this.getSelectionContext());
2052
- }
2053
- destroy() {
2054
- 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());
2055
- }
2056
- }, Jt = 150, Yt = "0 1px 3px rgba(0,0,0,0.2)", Xt = 12, Zt;
2057
- function Qt() {
2058
- return Zt ??= import("./comment-ui-runtime-BfE7MJZn.js");
2059
- }
2060
- var $ = 440, $t = 20, en = Symbol("PptxScrollViewer.borrowedPresentation"), tn = class e {
2061
- _presentationOwner;
2062
- get _pres() {
2063
- return this._presentationOwner.current;
2064
- }
2065
- _borrowed;
2066
- _opts;
2067
- _errorRouter;
2068
- _container;
2069
- _wrapper;
2070
- _scrollHost;
2071
- _spacer;
2072
- _mode;
2073
- _scale = 1;
2074
- _scaleEstablished = !1;
2075
- _pendingScale = null;
2076
- _slots = /* @__PURE__ */ new Map();
2077
- _free = [];
2078
- _uniformSlideHeight = 0;
2079
- _lastRange = null;
2080
- _lastTopIndex = -1;
2081
- _lastReportedTotal = -1;
2082
- _lastReportedLayoutComplete = null;
2083
- _layoutUnsubscribe = null;
2084
- _scrollListener = null;
2085
- _selectionChangeListener = null;
2086
- _selectionContextKey = "null";
2087
- _elementClickListener = null;
2088
- _contextMenuListener = null;
2089
- _commentOutsidePointerListener = null;
2090
- _elementContext = null;
2091
- _activeCommentId = null;
2092
- _activeCommentSlide = null;
2093
- _commentNavigationGeneration = 0;
2094
- _commentUi = null;
2095
- _commentGeometryScheduled = !1;
2096
- _commentGeometryFrame = null;
2097
- _pendingCommentGeometry = /* @__PURE__ */ new Map();
2098
- _hasComments = !1;
2099
- _reviewOriginPx = 0;
2100
- _commentScanFrontier = 0;
2101
- _layoutWaiters = /* @__PURE__ */ new Set();
2102
- _layoutFailed = !1;
2103
- _elementHitGeneration = 0;
2104
- _elementHitTolerance;
2105
- _destroyed = !1;
2106
- _slideInFlight = /* @__PURE__ */ new Set();
2107
- _renderEpoch = 0;
2108
- _settleTimer = null;
2109
- _wheelListener = null;
2110
- _pendingZoomAnchor = null;
2111
- _resizeObserver = null;
2112
- _prevBase = 0;
2113
- _lastFitWidth = 0;
2114
- _pageShadow;
2115
- _find = new Xe(() => this.slideCount, (e) => this._collectSlideRuns(e));
2116
- _findGeneration = 0;
2117
- _findActive = !1;
2118
- _findMeasureCtx;
2119
- static fromPresentation(t, n, r = {}) {
2120
- return new e(t, {
2121
- ...r,
2122
- [en]: n
2123
- });
2124
- }
2125
- constructor(e, t = {}) {
2126
- 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.");
2127
- this._container = e, this._opts = t, this._errorRouter = new le("PptxScrollViewer", t.onError);
2128
- let n = t.elementHitTolerance ?? 6;
2129
- if (!Number.isFinite(n) || n < 0) throw RangeError("elementHitTolerance must be a finite non-negative number.");
2130
- this._elementHitTolerance = n, this._pageShadow = t.pageShadow ?? Yt;
2131
- let r = t[en];
2132
- 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) => {
2133
- if (!this._destroyed) {
2134
- this._commentUi = e;
2135
- for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
2136
- }
2137
- }).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) => {
2138
- this._onElementClick(e).catch((e) => this._reportRenderError(e));
2139
- }, 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) => {
2140
- if (!Se(e, this._wrapper, "ooxmlCommentId") && this._activeCommentId !== null) {
2141
- this._activeCommentId = null, this._activeCommentSlide = null;
2142
- for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
2143
- this._emitSelectionContextChange();
2144
- }
2145
- }, this._wrapper.ownerDocument.addEventListener("pointerdown", this._commentOutsidePointerListener)), this._opts.enableZoom !== !1 && (this._wheelListener = (e) => {
2146
- if (!(e.ctrlKey || e.metaKey) || (e.preventDefault(), e.deltaY === 0)) return;
2147
- let t = this._scrollHost.getBoundingClientRect(), n = e.clientX - t.left, r = e.clientY - t.top;
2148
- this._pendingZoomAnchor = Number.isFinite(n) && Number.isFinite(r) ? {
2149
- x: n,
2150
- y: r
2151
- } : null, this.setScale(me(this._scale, e.deltaY, e.deltaMode));
2152
- }, 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());
2153
- }
2154
- async load(e) {
2155
- if (this._destroyed) throw Error("PptxScrollViewer is destroyed");
2156
- if (this._borrowed) throw Error("PptxScrollViewer.load() is unsupported on a Viewer created by fromPresentation(); the borrowed presentation is already loaded.");
2157
- let t = !1;
2158
- try {
2159
- let n = await this._presentationOwner.replace(() => J.load(e, {
2160
- password: this._opts.password,
2161
- useGoogleFonts: this._opts.useGoogleFonts,
2162
- cjkFallback: this._opts.cjkFallback,
2163
- maxZipEntryBytes: this._opts.maxZipEntryBytes,
2164
- resourceLimits: this._opts.resourceLimits,
2165
- debug: this._opts.debug,
2166
- onResourceMetrics: this._opts.onResourceMetrics,
2167
- workerTimeoutMs: this._opts.workerTimeoutMs,
2168
- wasmUrl: this._opts.wasmUrl,
2169
- math: this._opts.math,
2170
- threeD: this._opts.threeD,
2171
- regionMap: this._opts.regionMap,
2172
- chartEx: this._opts.chartEx,
2173
- tiff: this._opts.tiff,
2174
- mode: this._mode,
2175
- progressiveLayout: this._opts.progressiveLayout,
2176
- onLayoutProgress: this._opts.onLayoutProgress,
2177
- onLayoutPartial: this._opts.onLayoutPartial,
2178
- onLayoutComplete: this._opts.onLayoutComplete
2179
- }), (e) => {
2180
- 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) {
2181
- for (let [e, t] of [...this._slots]) this._recycleSlot(e, t);
2182
- this._lastTopIndex = -1;
2183
- }
2184
- });
2185
- if (!n) return;
2186
- if (this._destroyed) throw Error("PptxScrollViewer is destroyed");
2187
- this._invalidateFind(), this._findActive = !1, this._activeCommentId = null, this._activeCommentSlide = null, this._hasComments = !1, this._commentScanFrontier = 0, this._scanAvailableComments(n, !1), this._bindLayoutPresentation(n);
2188
- let r = [];
2189
- this._relayout(r), await Promise.all(r);
2190
- } catch (e) {
2191
- throw this._destroyed ? Error("PptxScrollViewer is destroyed") : e instanceof Error ? e : Error(String(e));
2192
- }
2193
- t && !this._destroyed && this._emitSelectionContextChange();
2194
- }
2195
- get slideCount() {
2196
- return this._pres?.slideCount ?? 0;
2197
- }
2198
- get availableSlideCount() {
2199
- return this._pres?.availableSlideCount ?? this.slideCount;
2200
- }
2201
- get layoutComplete() {
2202
- return this._pres?.layoutComplete ?? !0;
2203
- }
2204
- async waitUntilLayoutComplete() {
2205
- await this._errorRouter.ownBackgroundLifecycle(async () => {
2206
- await this._pres?.waitUntilLayoutComplete?.();
2207
- });
2208
- }
2209
- _slideWidthPx() {
2210
- return this._pres.slideWidth / k * this._scale;
2211
- }
2212
- _slideHeightPx() {
2213
- return this._pres.slideHeight / k * this._scale;
2214
- }
2215
- _fitWidthPx() {
2216
- if (this._opts.width && this._opts.width > 0) return this._opts.width;
2217
- let e = this._scrollHost.clientWidth || this._container.clientWidth;
2218
- if (e <= 0) return 0;
2219
- let { left: t, right: n } = this._padH(), r = e - t - n;
2220
- return r <= 0 ? 0 : r;
2221
- }
2222
- _commentMarginExtent() {
2223
- return this._hasCommentMargin() ? (Xt + $) * this._commentZoom() : 0;
2224
- }
2225
- _hasCommentMargin() {
2226
- return this._commentsEnabled() && this._hasComments && this._commentsOptions()?.cards !== !1;
2227
- }
2228
- _commentZoom() {
2229
- return this._scaleEstablished ? this._scale : 1;
2230
- }
2231
- _commentsEnabled() {
2232
- return this._opts.comments === !0 || typeof this._opts.comments == "object";
2233
- }
2234
- _commentsOptions() {
2235
- return typeof this._opts.comments == "object" ? this._opts.comments : void 0;
2236
- }
2237
- _commentSide() {
2238
- let e = this._commentsOptions()?.side;
2239
- return e === "left" || e === "right" ? e : (this._container.ownerDocument.defaultView?.getComputedStyle?.(this._container).direction || this._container.dir || this._container.style.direction) === "rtl" ? "left" : "right";
2240
- }
2241
- _syncCommentMarginGeometry(e) {
2242
- if (!e) return;
2243
- e.style.display = this._hasCommentMargin() ? "" : "none";
2244
- let t = this._commentZoom(), n = `calc(100% + ${Xt * t}px)`;
2245
- 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);
2246
- }
2247
- _scanAvailableComments(e, t) {
2248
- if (!this._commentsEnabled() || this._hasComments) return;
2249
- let n = this._commentsOptions()?.includeResolved === !0, r = Math.min(e.availableSlideCount, e.slideCount);
2250
- for (let i = this._commentScanFrontier; i < r; i++) if (e.getComments(i).some((e) => n || e.status !== "resolved" && e.status !== "closed")) {
2251
- this._commentScanFrontier = r, this._hasComments = !0, t && this._refreshDiscoveredComments();
2252
- return;
2253
- }
2254
- this._commentScanFrontier = Math.max(this._commentScanFrontier, r);
2255
- }
2256
- _refreshDiscoveredComments() {
2257
- this._syncSpacerWidth();
2258
- for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
2259
- }
2260
- _baseScale() {
2261
- if (!this._pres || this._pres.slideCount === 0) return 0;
2262
- let e = this._fitWidthPx(), t = this._pres.slideWidth / k;
2263
- return e <= 0 || t <= 0 ? 0 : e / t;
2264
- }
2265
- relayout() {
2266
- this._relayout();
2267
- }
2268
- _relayout(e) {
2269
- if (this._pres) {
2270
- if (!this._scaleEstablished) {
2271
- let e = this._baseScale();
2272
- if (e > 0) {
2273
- if (this._scale = e, this._prevBase = e, this._lastFitWidth = this._fitWidthPx(), this._scaleEstablished = !0, this._pendingScale !== null) {
2274
- let e = this._pendingScale;
2275
- this._pendingScale = null, e !== this._scale && (this._scale = e, this._opts.onScaleChange?.(e));
2276
- }
2277
- } else return;
2278
- }
2279
- this._recomputeHeights(), this._syncSpacer(), this._mountVisible(e);
2280
- }
2281
- }
2282
- _recomputeHeights() {
2283
- this._uniformSlideHeight = this._slideHeightPx();
2284
- }
2285
- _gap() {
2286
- return this._opts.gap ?? 16;
2287
- }
2288
- _overscan() {
2289
- return this._opts.overscan ?? 1;
2290
- }
2291
- _mediaOverscan() {
2292
- return this._opts.mediaOverscan ?? 1;
2293
- }
2294
- _pad() {
2295
- let e = this._gap();
2296
- return {
2297
- leading: this._opts.paddingTop ?? e,
2298
- trailing: this._opts.paddingBottom ?? e
2299
- };
2300
- }
2301
- _padH() {
2302
- let e = this._gap();
2303
- return {
2304
- left: this._opts.paddingLeft ?? e,
2305
- right: this._opts.paddingRight ?? e
2306
- };
2307
- }
2308
- _slideOffset(e) {
2309
- return this._pad().leading + e * (this._uniformSlideHeight + this._gap());
2310
- }
2311
- _slideIndexAtOffset(e) {
2312
- return ge(this._pres?.slideCount ?? 0, this._uniformSlideHeight, this._gap(), e, 0, 0, this._pad()).topIndex;
2313
- }
2314
- _rangeAt(e, t) {
2315
- return ge(this._pres?.slideCount ?? 0, this._uniformSlideHeight, this._gap(), e, this._scrollHost.clientHeight, t, this._pad());
2316
- }
2317
- _range() {
2318
- return this._rangeAt(this._scrollHost.scrollTop, this._overscan());
2319
- }
2320
- _mediaRange() {
2321
- return this._rangeAt(this._scrollHost.scrollTop, this._mediaOverscan());
2322
- }
2323
- _rangeContains(e, t) {
2324
- return t >= e.start && t <= e.end;
2325
- }
2326
- _syncSpacer() {
2327
- let e = this._range();
2328
- this._lastRange = e, this._spacer.style.height = `${e.totalHeight}px`, this._syncSpacerWidth();
2329
- }
2330
- _syncSpacerWidth() {
2331
- 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);
2332
- 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);
2333
- }
2334
- _onScroll() {
2335
- !this._pres || !this._scaleEstablished || this._mountVisible(void 0, !1);
2336
- }
2337
- _mountVisible(e, t = !0) {
2338
- if (!this._pres || this._pres.slideCount === 0) return;
2339
- let n = this._range(), r = this._opts.enableMediaPlayback ? this._mediaRange() : null;
2340
- this._lastRange = n;
2341
- for (let [e, t] of [...this._slots]) (e < n.start || e > n.end) && this._recycleSlot(e, t);
2342
- for (let i = n.start; i <= n.end; i++) if (this._slots.has(i)) t && this._positionSlot(this._slots.get(i), i, n);
2343
- else {
2344
- let t = this._acquireSlot();
2345
- this._positionSlot(t, i, n), this._slots.set(i, t), this._redrawSlotComments(i, t);
2346
- let a = this._renderSlot(i, t, !!r && this._rangeContains(r, i), e === void 0);
2347
- e && a && i < this.availableSlideCount && e.push(a);
2348
- }
2349
- r && this._syncMediaPlayback(r), this._emitVisibleSlideChange(n);
2350
- }
2351
- _applyPageShadow(e) {
2352
- this._pageShadow !== !1 && (e.style.boxShadow = this._pageShadow);
2353
- }
2354
- _acquireSlot() {
2355
- let e = this._free.pop();
2356
- if (e) return this._scrollHost.appendChild(e.wrapper), e;
2357
- let t = document.createElement("div");
2358
- t.style.cssText = "position:absolute;";
2359
- let n = document.createElement("canvas");
2360
- n.style.cssText = "display:block;background:#fff;", this._applyPageShadow(n), t.appendChild(n);
2361
- let r = null;
2362
- 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));
2363
- let i = document.createElement("div");
2364
- i.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;overflow:hidden;pointer-events:none;", t.appendChild(i);
2365
- let a = Gt(document);
2366
- t.appendChild(a);
2367
- let o = null, s = null, c = null;
2368
- 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)));
2369
- let l = se(t, this._opts.enableElementSelection === !0);
2370
- return this._scrollHost.appendChild(t), {
2371
- wrapper: t,
2372
- canvas: n,
2373
- textLayer: r,
2374
- highlightLayer: i,
2375
- elementLayer: l,
2376
- loadingLayer: a,
2377
- commentMarkerLayer: o,
2378
- commentMargin: s,
2379
- commentDecorationLayer: c,
2380
- commentElementBounds: Object.freeze([]),
2381
- commentGeometry: null,
2382
- commentAnchorSlide: -1,
2383
- commentAnchorGeneration: 0,
2384
- renderedSlide: -1,
2385
- renderedScale: -1,
2386
- dispatcher: new E(n, this._mode === "worker" && !this._opts.enableMediaPlayback),
2387
- presentationHandle: null,
2388
- mediaInteractive: !1,
2389
- renderGeneration: 0,
2390
- presentationGeneration: 0
2391
- };
2392
- }
2393
- _recycleSlot(e, t) {
2394
- 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);
2395
- }
2396
- _positionSlot(e, t, n) {
2397
- e.wrapper.dataset.slideIndex = String(t), e.wrapper.style.top = `${this._slideOffset(t)}px`;
2398
- let r = this._slideWidthPx();
2399
- if (e.wrapper.style.width = `${r}px`, e.wrapper.style.height = `${this._slideHeightPx()}px`, this._syncCommentMarginGeometry(e.commentMargin), e.commentDecorationLayer) {
2400
- let t = this._commentMarginExtent();
2401
- e.commentDecorationLayer.style.left = this._commentSide() === "left" ? `${-t}px` : "0px", e.commentDecorationLayer.style.width = `${r + t}px`, e.commentDecorationLayer.style.height = `${this._slideHeightPx()}px`;
2402
- }
2403
- this._redrawElementOutlineForSlot(t, e);
2404
- let { left: i } = this._padH(), a = Math.max(i, (this._scrollHost.clientWidth - r) / 2);
2405
- e.wrapper.style.left = this._commentSide() === "left" && this._commentsEnabled() ? `calc(${a}px + var(--ooxml-review-origin-x, 0px))` : `${a}px`;
2406
- }
2407
- _dpr() {
2408
- return this._opts.dpr ?? (typeof window < "u" && window.devicePixelRatio || 1);
2409
- }
2410
- _renderSlot(e, t, n = !1, r = !0) {
2411
- if (!this._pres || t.renderedSlide === e) return null;
2412
- if (e >= this.availableSlideCount && !this.layoutComplete) return t.renderedSlide = -1, t.mediaInteractive = !1, t.loadingLayer.style.display = "flex", null;
2413
- t.renderedSlide = e;
2414
- let i = ++t.renderGeneration;
2415
- t.loadingLayer.style.display = e >= this.availableSlideCount && !this.layoutComplete ? "flex" : "none";
2416
- let a = this._dpr(), o = this._slideWidthPx(), s = this._renderEpoch, c = this._scale, l = t.dispatcher, u = l.begin();
2417
- if (this._opts.enableMediaPlayback && n) return t.mediaInteractive = !0, this._trackSlotLoading(e, t, i, this._renderInteractiveSlot(e, t, o, a, c, s, r));
2418
- if (t.mediaInteractive = !1, this._mode === "worker") return this._trackSlotLoading(e, t, i, this._renderSlotBitmap(e, t, o, a, c, i, l, u, r));
2419
- let d = [], f = !!this._opts.enableTextSelection && !!t.textLayer, p = f || this._findActive, m = p ? (e) => d.push(e) : void 0, h = t.canvas;
2420
- return this._trackSlotLoading(e, t, i, Z(this._pres, h, e, "main", {
2421
- width: o,
2422
- dpr: a,
2423
- imageResources: this._opts.imageResources,
2424
- onTextRun: m
2425
- }).then(() => {
2426
- 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));
2427
- }).catch((n) => {
2428
- 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);
2429
- else throw n;
2430
- }));
2431
- }
2432
- async _trackSlotLoading(e, t, n, r) {
2433
- try {
2434
- await r;
2435
- } finally {
2436
- n === t.renderGeneration && this._slots.get(e) === t && t.renderedSlide === e && (t.loadingLayer.style.display = "none");
2437
- }
2438
- }
2439
- _bindLayoutPresentation(e) {
2440
- this._unbindLayoutPresentation();
2441
- let t = !0;
2442
- this._layoutUnsubscribe = Bt(e, () => ({
2443
- availableSlides: e.availableSlideCount,
2444
- slideCount: e.slideCount,
2445
- exact: e.layoutComplete,
2446
- complete: e.layoutComplete
2447
- }), (n) => {
2448
- if (t) {
2449
- t = !1;
2450
- return;
2451
- }
2452
- this._onLayoutPublication(e, n);
2453
- }, (e) => this._reportRenderError(e));
2454
- }
2455
- _unbindLayoutPresentation() {
2456
- this._layoutUnsubscribe?.(), this._layoutUnsubscribe = null, this._layoutFailed = !1, this._wakeLayoutWaiters();
2457
- }
2458
- _onLayoutPublication(e, t) {
2459
- if (this._destroyed || e !== this._pres) return;
2460
- if (this._wakeLayoutWaiters(), t.error !== void 0) {
2461
- this._layoutFailed = !0, this._errorRouter.reportBackground(t.error, this._opts.onLayoutComplete !== void 0);
2462
- return;
2463
- }
2464
- this._scanAvailableComments(e, !0);
2465
- let n = this._opts.enableMediaPlayback ? this._mediaRange() : null;
2466
- for (let [t, r] of this._slots) t >= e.availableSlideCount || r.renderedSlide === t || this._renderSlot(t, r, !!n && this._rangeContains(n, t));
2467
- this._lastRange && this._emitVisibleSlideChange(this._lastRange);
2468
- }
2469
- _wakeLayoutWaiters() {
2470
- for (let e of this._layoutWaiters) e();
2471
- this._layoutWaiters.clear();
2472
- }
2473
- _beginCommentNavigation() {
2474
- let e = ++this._commentNavigationGeneration;
2475
- return this._wakeLayoutWaiters(), e;
2476
- }
2477
- async _waitForSlideMetadata(e, t, n) {
2478
- return await this._errorRouter.ownBackgroundLifecycle(async () => {
2479
- for (; !this._destroyed && n === this._commentNavigationGeneration && e === this._pres && t >= e.availableSlideCount && !e.layoutComplete && !this._layoutFailed;) await new Promise((e) => this._layoutWaiters.add(e));
2480
- return this._destroyed || e !== this._pres || ((e.layoutComplete || this._layoutFailed) && await e.waitUntilLayoutComplete?.(), n !== this._commentNavigationGeneration) ? !1 : t < e.availableSlideCount;
2481
- });
2482
- }
2483
- _emitVisibleSlideChange(e) {
2484
- if (!this._pres) return;
2485
- let t = this._pres.slideCount, n = this.layoutComplete;
2486
- 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));
2487
- }
2488
- _renderInteractiveSlot(e, t, n, r, i, a, o = !0) {
2489
- if (!this._pres) return Promise.resolve();
2490
- let s = ++t.presentationGeneration;
2491
- t.presentationHandle?.destroy(), t.presentationHandle = null;
2492
- let c = [], l = !!this._opts.enableTextSelection && !!t.textLayer, u = l || this._findActive, d = u ? (e) => c.push(e) : void 0;
2493
- return this._pres.presentSlide(t.canvas, e, {
2494
- width: n,
2495
- dpr: r,
2496
- imageResources: this._opts.imageResources,
2497
- onTextRun: d,
2498
- onError: (e) => {
2499
- s === t.presentationGeneration && this._reportRenderError(e);
2500
- }
2501
- }).then((r) => {
2502
- if (s !== t.presentationGeneration || !t.mediaInteractive || a !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e) {
2503
- r.destroy();
2504
- return;
2505
- }
2506
- 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);
2507
- }).catch((e) => {
2508
- if (s === t.presentationGeneration) if (o) this._reportRenderError(e);
2509
- else throw e;
2510
- });
2511
- }
2512
- _syncMediaPlayback(e = this._mediaRange()) {
2513
- if (this._opts.enableMediaPlayback) for (let [t, n] of this._slots) {
2514
- let r = this._rangeContains(e, t);
2515
- 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));
2516
- }
2517
- }
2518
- _reportRenderError(e) {
2519
- this._errorRouter.report(e);
2520
- }
2521
- async _renderSlotBitmap(e, t, n, r, i, a = ++t.renderGeneration, o = t.dispatcher, s = o.begin(), c = !0) {
2522
- if (this._slideInFlight.has(e) || this._slots.get(e) !== t) return;
2523
- let l = this._renderEpoch;
2524
- this._slideInFlight.add(e);
2525
- let u = t.canvas, d = !1, f = !!this._opts.enableTextSelection && !!t.textLayer, p = f || this._findActive, m = [];
2526
- try {
2527
- let c = await Z(this._pres, u, e, "worker", {
2528
- width: n,
2529
- dpr: r,
2530
- imageResources: this._opts.imageResources,
2531
- onTextRun: p ? (e) => m.push(e) : void 0
2532
- });
2533
- if (a !== t.renderGeneration || !o.isCurrent(s) || u !== t.canvas || l !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e) {
2534
- c.close();
2535
- return;
2536
- }
2537
- let h = {
2538
- cssWidth: Math.round(n),
2539
- cssHeight: Math.round(this._slideHeightPx())
2540
- };
2541
- if (!(this._opts.enableMediaPlayback ? o.commitBitmapTo2d(s, c, h) : o.commitBitmap(s, c, h))) return;
2542
- 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;
2543
- } catch (n) {
2544
- 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);
2545
- else throw n;
2546
- } finally {
2547
- this._slideInFlight.delete(e);
2548
- let n = this._slots.get(e);
2549
- 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)) {
2550
- let t = n.dispatcher;
2551
- await this._renderSlotBitmap(e, n, this._slideWidthPx(), this._dpr(), this._scale, ++n.renderGeneration, t, t.begin(), c);
2552
- }
2553
- }
2554
- }
2555
- setScale(e) {
2556
- let t = this._effectiveZoomMin(), n = this._opts.zoomMax ?? 4, r = Math.min(n, Math.max(t, e)), i = this._pendingZoomAnchor;
2557
- if (this._pendingZoomAnchor = null, !this._pres || this._pres.slideCount === 0 || !this._scaleEstablished) {
2558
- this._pendingScale = r;
2559
- return;
2560
- }
2561
- if (r === this._scale) return;
2562
- 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;
2563
- d = Math.min(1, Math.max(0, d));
2564
- let f = this._padH().left, p = this._scrollHost.scrollLeft || 0;
2565
- this._renderEpoch++, this._scale = r, this._recomputeHeights();
2566
- let m = this._rangeAt(0, this._overscan());
2567
- this._spacer.style.height = `${m.totalHeight}px`, this._syncSpacerWidth();
2568
- let h = Math.max(0, m.totalHeight - this._scrollHost.clientHeight), g = this._slideOffset(l) + d * this._uniformSlideHeight, _ = c < this._slideOffset(0) ? s : g - o;
2569
- if (this._scrollHost.scrollTop = Math.min(h, Math.max(0, _)), i) {
2570
- let e = Math.max(0, (this._spacer.offsetWidth || 0) - this._scrollHost.clientWidth);
2571
- this._scrollHost.scrollLeft = ee(p, i.x - f, a, r, { maxScroll: e });
2572
- }
2573
- this._previewVisible(), this._scheduleSettle(), this._opts.onScaleChange?.(r);
2574
- }
2575
- getScale() {
2576
- return this._scaleEstablished ? this._scale : this._pendingScale ?? 1;
2577
- }
2578
- zoomIn() {
2579
- this.setScale(fe(this.getScale()));
2580
- }
2581
- zoomOut() {
2582
- this.setScale(he(this.getScale(), this._effectiveZoomMin()));
2583
- }
2584
- _effectiveZoomMin() {
2585
- let e = this._opts.zoomMin ?? .1;
2586
- return this._scaleEstablished && this._prevBase > 0 ? Math.min(e, this._prevBase) : e;
2587
- }
2588
- fitWidth() {
2589
- this._fit("width");
2590
- }
2591
- fitPage() {
2592
- this._fit("page");
2593
- }
2594
- _fit(e) {
2595
- if (!this._pres || this._pres.slideCount === 0) return;
2596
- let t = C({
2597
- contentWidth: this._pres.slideWidth / k,
2598
- contentHeight: this._pres.slideHeight / k,
2599
- containerWidth: this._fitWidthPx(),
2600
- containerHeight: this._scrollHost.clientHeight
2601
- }, e);
2602
- t <= 0 || this.setScale(t);
2603
- }
2604
- _previewVisible() {
2605
- if (!this._pres || this._pres.slideCount === 0) return;
2606
- let e = this._range(), t = this._opts.enableMediaPlayback ? this._mediaRange() : null;
2607
- this._lastRange = e;
2608
- for (let [t, n] of [...this._slots]) (t < e.start || t > e.end) && this._recycleSlot(t, n);
2609
- for (let n = e.start; n <= e.end; n++) {
2610
- let r = this._slots.get(n);
2611
- if (r) this._previewSlot(r, n, e);
2612
- else {
2613
- let r = this._acquireSlot();
2614
- this._positionSlot(r, n, e), this._slots.set(n, r), this._redrawSlotComments(n, r), this._renderSlot(n, r, !!t && this._rangeContains(t, n));
2615
- }
2616
- }
2617
- t && this._syncMediaPlayback(t), this._emitVisibleSlideChange(e);
2618
- }
2619
- _previewSlot(e, t, n) {
2620
- 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) {
2621
- let t = this._scale / e.renderedScale;
2622
- 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})`;
2623
- }
2624
- if (e.renderedScale > 0) {
2625
- let t = this._scale / e.renderedScale, n = Math.round(t * 1e6) / 1e6;
2626
- e.commentMargin && this._commentUi?.previewReadOnlyCommentMargin(e.commentMargin, t);
2627
- for (let t of e.commentMarkerLayer?.children ?? []) t.dataset.ooxmlCommentMarker !== void 0 && (t.style.transform = `translate(-50%,-50%) scale(${n})`);
2628
- e.commentMarkerLayer && (e.commentMarkerLayer.style.visibility = ""), e.commentMargin && (e.commentMargin.style.visibility = ""), e.commentDecorationLayer && (e.commentDecorationLayer.style.visibility = "");
2629
- return;
2630
- }
2631
- e.commentMarkerLayer && (e.commentMarkerLayer.style.visibility = "hidden"), e.commentMargin && (e.commentMargin.style.visibility = "hidden"), e.commentDecorationLayer && (e.commentDecorationLayer.style.visibility = "hidden");
2632
- }
2633
- _clearTextLayerPreview(e) {
2634
- e.style.transform = "", e.style.transformOrigin = "", e.style.width = "100%", e.style.height = "100%";
2635
- }
2636
- _scheduleSettle() {
2637
- this._settleTimer !== null && clearTimeout(this._settleTimer), this._settleTimer = setTimeout(() => {
2638
- this._settleTimer = null, this._settleRender();
2639
- }, Jt);
2640
- }
2641
- _settleRender() {
2642
- if (this._destroyed || !this._pres || this._pres.slideCount === 0) return;
2643
- let e = this._opts.enableMediaPlayback ? this._mediaRange() : null;
2644
- for (let [t, n] of [...this._slots]) e && !this._rangeContains(e, t) || n.renderedScale !== this._scale && this._settleSlot(t, n);
2645
- }
2646
- _settleSlot(e, t) {
2647
- if (!this._pres) return;
2648
- let n = this._dpr(), r = this._slideWidthPx(), i = this._scale, a = this._renderEpoch;
2649
- if (this._opts.enableMediaPlayback && t.mediaInteractive) {
2650
- this._settleInteractiveSlot(e, t, r, n, i, a);
2651
- return;
2652
- }
2653
- if (this._opts.enableMediaPlayback) return;
2654
- if (this._mode === "worker") {
2655
- this._renderSlotBitmap(e, t, r, n, i);
2656
- return;
2657
- }
2658
- let o = document.createElement("canvas"), s = ++t.renderGeneration;
2659
- o.style.cssText = "display:block;background:#fff;", this._applyPageShadow(o);
2660
- 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;
2661
- Z(this._pres, o, e, "main", {
2662
- width: r,
2663
- dpr: n,
2664
- onTextRun: p
2665
- }).then(() => {
2666
- if (s !== t.renderGeneration || !c.isCurrent(l) || a !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e) {
2667
- c.destroy();
2668
- return;
2669
- }
2670
- let n = t.canvas;
2671
- 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);
2672
- }).catch((n) => {
2673
- s === t.renderGeneration && c.isCurrent(l) && a === this._renderEpoch && this._slots.get(e) === t && t.renderedSlide === e && this._reportRenderError(n), c.destroy();
2674
- });
2675
- }
2676
- _settleInteractiveSlot(e, t, n, r, i, a) {
2677
- if (!this._pres) return;
2678
- let o = ++t.presentationGeneration, s = document.createElement("canvas");
2679
- s.style.cssText = "display:block;background:#fff;", this._applyPageShadow(s);
2680
- let c = [], l = !!this._opts.enableTextSelection && !!t.textLayer, u = l || this._findActive, d = u ? (e) => c.push(e) : void 0;
2681
- this._pres.presentSlide(s, e, {
2682
- width: n,
2683
- dpr: r,
2684
- onTextRun: d,
2685
- onError: (e) => {
2686
- o === t.presentationGeneration && this._reportRenderError(e);
2687
- }
2688
- }).then((r) => {
2689
- if (o !== t.presentationGeneration || !t.mediaInteractive || a !== this._renderEpoch || this._slots.get(e) !== t || t.renderedSlide !== e) {
2690
- r.destroy();
2691
- return;
2692
- }
2693
- let d = t.canvas, f = t.presentationHandle;
2694
- 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);
2695
- }).catch((e) => {
2696
- o === t.presentationGeneration && this._reportRenderError(e);
2697
- });
2698
- }
2699
- scrollToSlide(e, t) {
2700
- if (!this._pres || this._pres.slideCount === 0 || !this._scaleEstablished) return;
2701
- 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;
2702
- typeof a.scrollTo == "function" ? a.scrollTo({
2703
- top: i,
2704
- behavior: t?.behavior ?? "auto"
2705
- }) : this._scrollHost.scrollTop = i, this._mountVisible();
2706
- }
2707
- _scrollToSlideCommentTarget(e, t, n, r) {
2708
- if (!this._pres) return !1;
2709
- let i = this._slots.get(e), a = new Map((i?.commentElementBounds ?? []).map((e) => [e.elementId, e.bounds])), o = r ?? (t.anchors ?? []).flatMap((e) => {
2710
- if (e.type !== "drawingElement" && e.type !== "textRange" || !e.elementId) return [];
2711
- let t = a.get(e.elementId);
2712
- return t ? [t] : [];
2713
- })[0], s = t.anchors ?? [], c = Number.isFinite(t.x) && Number.isFinite(t.y) && (s.length === 0 || s.some((e) => e.type === "slide"));
2714
- if (!o && !c) return !1;
2715
- 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;
2716
- return typeof S.scrollTo == "function" ? S.scrollTo({
2717
- top: b,
2718
- left: x,
2719
- behavior: n?.behavior ?? "auto"
2720
- }) : (this._scrollHost.scrollTop = b, this._scrollHost.scrollLeft = x), this._mountVisible(), !0;
2721
- }
2722
- async _resolveSlideCommentElementBounds(e, t) {
2723
- let n = this._pres;
2724
- if (!n) return;
2725
- let r = (t.anchors ?? []).flatMap((e) => (e.type === "drawingElement" || e.type === "textRange") && e.elementId ? [e.elementId] : []);
2726
- if (r.length === 0) return;
2727
- let i = new Map((this._slots.get(e)?.commentElementBounds ?? []).map((e) => [e.elementId, e.bounds])), a = r.flatMap((e) => {
2728
- let t = i.get(e);
2729
- return t ? [t] : [];
2730
- })[0];
2731
- if (a) return a;
2732
- let o = await n.getElementBoundsByIds(e, r);
2733
- return r.flatMap((e) => {
2734
- let t = o.find((t) => t.elementId === e);
2735
- return t ? [t.bounds] : [];
2736
- })[0];
2737
- }
2738
- async goToComment(e, t, n) {
2739
- if (this._destroyed) throw Error("PptxScrollViewer is destroyed");
2740
- let r = this._pres;
2741
- if (!r || !Number.isInteger(e) || !Number.isInteger(t) || e < 0 || e >= r.slideCount || t < 0) return !1;
2742
- let i = this._beginCommentNavigation();
2743
- if (e >= r.availableSlideCount && !r.layoutComplete && !await this._waitForSlideMetadata(r, e, i)) return !1;
2744
- if (this._destroyed) throw Error("PptxScrollViewer is destroyed");
2745
- if (i !== this._commentNavigationGeneration || r !== this._pres) return !1;
2746
- let a = r.getComments(e)[t];
2747
- if (!a) return !1;
2748
- let o = await this._resolveSlideCommentElementBounds(e, a);
2749
- if (this._destroyed) throw Error("PptxScrollViewer is destroyed");
2750
- if (i !== this._commentNavigationGeneration || r !== this._pres) return !1;
2751
- let s = a.anchors ?? [], c = Number.isFinite(a.x) && Number.isFinite(a.y) && (s.length === 0 || s.some((e) => e.type === "slide"));
2752
- if (!o && !c || (this.scrollToSlide(e, n), !this._scrollToSlideCommentTarget(e, a, n, o))) return !1;
2753
- this._activeCommentId = P(a, t, e), this._activeCommentSlide = e, this._elementContext = null;
2754
- for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
2755
- return this._emitSelectionContextChange(), !0;
2756
- }
2757
- async findText(e, t = {}) {
2758
- let n = this._pres;
2759
- if (!n) return [];
2760
- let r = ++this._findGeneration;
2761
- if (this._findActive = e.length > 0, e.length === 0) return this._find.invalidate(), this._redrawHighlights(), [];
2762
- if (n.layoutComplete || await this._errorRouter.ownBackgroundLifecycle(() => n.waitUntilLayoutComplete()), this._destroyed || r !== this._findGeneration || n !== this._pres) return [];
2763
- let i = await this._errorRouter.ownAwaitable(() => this._find.find(e, t));
2764
- return this._destroyed || r !== this._findGeneration || n !== this._pres ? [] : (this._redrawHighlights(), i);
2765
- }
2766
- async findNext() {
2767
- return this._activateMatch(this._find.next());
2768
- }
2769
- async findPrev() {
2770
- return this._activateMatch(this._find.prev());
2771
- }
2772
- clearFind() {
2773
- this._findActive = !1, this._invalidateFind(), this._redrawHighlights();
2774
- }
2775
- _invalidateFind() {
2776
- this._findGeneration++, this._find.invalidate();
2777
- }
2778
- async _activateMatch(e) {
2779
- return e && this.scrollToSlide(e.location.slide), this._redrawHighlights(), e;
2780
- }
2781
- async _collectSlideRuns(e) {
2782
- return this._pres ? this._pres.collectSlideRuns(e, this._slideWidthPx()) : [];
2783
- }
2784
- _redrawHighlights() {
2785
- for (let [e, t] of this._slots) this._redrawSlotHighlights(e, t);
2786
- }
2787
- _refreshFindRuns(e, t) {
2788
- this._findActive && this._find.setSlideRuns(e, t);
2789
- }
2790
- _redrawSlotComments(e, t) {
2791
- if (!this._pres || !t.commentMarkerLayer) return;
2792
- this._syncCommentMarginGeometry(t.commentMargin);
2793
- let n = this._commentUi;
2794
- if (!n) {
2795
- t.commentMarkerLayer.replaceChildren(), t.commentMargin?.replaceChildren(), t.commentDecorationLayer?.replaceChildren(), t.commentGeometry = null;
2796
- return;
2797
- }
2798
- 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) => {
2799
- let r = n ? t : this._activeCommentId === t ? null : this._activeCommentId;
2800
- if (r !== this._activeCommentId) {
2801
- this._activeCommentId = r, this._activeCommentSlide = r ? e : null, this._elementContext = null;
2802
- for (let [e, t] of this._slots) this._redrawSlotComments(e, t);
2803
- this._emitSelectionContextChange();
2804
- }
2805
- }, 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);
2806
- }
2807
- _redrawSlotCommentConnectors(e, t) {
2808
- let n = t.commentDecorationLayer, r = t.commentMargin, i = t.commentGeometry, a = this._commentsOptions()?.connectors;
2809
- if (!n || !r || !i || !a) return;
2810
- let o = this._slideWidthPx(), s = this._slideHeightPx(), c = this._commentSide(), l = this._commentMarginExtent(), u = this._commentUi;
2811
- u && u.buildReadOnlyCommentDecoration(n, Object.freeze({
2812
- surfaceBounds: Object.freeze({
2813
- x: c === "left" ? -l : 0,
2814
- y: 0,
2815
- width: o + l,
2816
- height: s
2817
- }),
2818
- contentBounds: Object.freeze({
2819
- x: 0,
2820
- y: 0,
2821
- width: o,
2822
- height: s
2823
- }),
2824
- side: c,
2825
- threads: u.projectReadOnlyCommentMarginScroll(i, r.scrollTop)
2826
- }), {
2827
- route: a.route ?? "bezier",
2828
- stroke: a.stroke ?? "solid",
2829
- color: a.color,
2830
- activeColor: a.activeColor
2831
- });
2832
- }
2833
- _commitSlotComments(e, t) {
2834
- 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 = "");
2835
- }
2836
- _ensureSlotCommentAnchors(e, t) {
2837
- let n = this._pres;
2838
- if (!n || t.commentAnchorSlide === e) return;
2839
- t.commentAnchorSlide = e, t.commentElementBounds = Object.freeze([]);
2840
- let r = [...new Set(n.getComments(e).flatMap((e) => (e.anchors ?? []).flatMap((e) => (e.type === "drawingElement" || e.type === "textRange") && e.elementId ? [e.elementId] : [])))];
2841
- if (r.length === 0) return;
2842
- let i = ++t.commentAnchorGeneration;
2843
- n.getElementBoundsByIds(e, r).then((r) => {
2844
- if (this._destroyed || i !== t.commentAnchorGeneration || n !== this._pres || this._slots.get(e) !== t || t.commentAnchorSlide !== e) return;
2845
- t.commentElementBounds = r, this._redrawSlotComments(e, t);
2846
- let a = n.getComments(e).find((t, n) => P(t, n, e) === this._activeCommentId);
2847
- a && this._scrollToSlideCommentTarget(e, a);
2848
- }).catch((e) => {
2849
- !this._destroyed && i === t.commentAnchorGeneration && this._reportRenderError(e);
2850
- });
2851
- }
2852
- _scheduleCommentGeometry(e, t, n = !1) {
2853
- let r = this._pendingCommentGeometry.get(e);
2854
- if (this._pendingCommentGeometry.set(e, {
2855
- slot: t,
2856
- connectorsOnly: r?.slot === t ? r.connectorsOnly && n : n
2857
- }), this._commentGeometryScheduled) return;
2858
- this._commentGeometryScheduled = !0;
2859
- let i = () => {
2860
- this._commentGeometryScheduled = !1, this._commentGeometryFrame = null;
2861
- let e = [...this._pendingCommentGeometry];
2862
- if (this._pendingCommentGeometry.clear(), !this._destroyed) for (let [t, n] of e) {
2863
- let { slot: e, connectorsOnly: r } = n;
2864
- this._slots.get(t) === e && e.renderedScale === this._scale && (r ? this._redrawSlotCommentConnectors(t, e) : this._redrawSlotComments(t, e));
2865
- }
2866
- }, a = this._wrapper.ownerDocument.defaultView;
2867
- a?.requestAnimationFrame ? this._commentGeometryFrame = a.requestAnimationFrame(i) : queueMicrotask(i);
2868
- }
2869
- _redrawSlotHighlights(e, t) {
2870
- if (!this._findActive) {
2871
- t.highlightLayer.innerHTML = "";
2872
- return;
2873
- }
2874
- let n = this._find.slideRuns(e);
2875
- if (!n) {
2876
- t.highlightLayer.innerHTML = "";
2877
- return;
2878
- }
2879
- L(t.highlightLayer, n, this._find.slideHighlights(e), this._slideWidthPx(), this._slideHeightPx(), (e) => this._measureForFind(e), this._opts.findHighlightColors);
2880
- }
2881
- _measureForFind(e) {
2882
- this._findMeasureCtx === void 0 && (this._findMeasureCtx = document.createElement("canvas").getContext("2d"));
2883
- let t = this._findMeasureCtx;
2884
- return !t || typeof t.measureText != "function" ? (e) => e.length : (t.font = e, (e) => t.measureText(e).width);
2885
- }
2886
- _hyperlinkHandler() {
2887
- if (this._opts.enableHyperlinks !== !1) return (e) => this._onHyperlinkClick(e);
2888
- }
2889
- _onHyperlinkClick(e) {
2890
- let t = this._resolveInternalSlideIndex(e);
2891
- if (this._opts.onHyperlinkClick) {
2892
- this._opts.onHyperlinkClick(t);
2893
- return;
2894
- }
2895
- if (t.kind === "external") {
2896
- p(t.url);
2897
- return;
2898
- }
2899
- t.slideIndex !== void 0 && this.scrollToSlide(t.slideIndex);
2900
- }
2901
- _resolveInternalSlideIndex(e) {
2902
- if (e.kind !== "internal" || e.slideIndex !== void 0) return e;
2903
- let t = this._pres?.resolveInternalTarget(e.ref, this._range().topIndex);
2904
- return t === void 0 ? e : {
2905
- ...e,
2906
- slideIndex: t
2907
- };
2908
- }
2909
- _onResize() {
2910
- if (!this._pres || this._pres.slideCount === 0) return;
2911
- if (!this._scaleEstablished) {
2912
- this.relayout();
2913
- return;
2914
- }
2915
- if (this._opts.refitOnResize === !1) {
2916
- this._lastFitWidth = this._fitWidthPx(), this._mountVisible();
2917
- return;
2918
- }
2919
- let e = this._baseScale();
2920
- if (e <= 0) return;
2921
- let t = this._fitWidthPx();
2922
- if (t === this._lastFitWidth) {
2923
- this._mountVisible();
2924
- return;
2925
- }
2926
- this._lastFitWidth = t;
2927
- let n = this._prevBase > 0 ? this._scale / this._prevBase : 1;
2928
- this._prevBase = e, this.setScale(e * n), this._mountVisible();
2929
- }
2930
- get topVisibleSlide() {
2931
- return this._lastRange?.topIndex ?? 0;
2932
- }
2933
- mountedSlideIndicesForTest() {
2934
- return [...this._slots.keys()];
2935
- }
2936
- interactiveSlideIndicesForTest() {
2937
- return [...this._slots].filter(([, e]) => e.mediaInteractive).map(([e]) => e);
2938
- }
2939
- scaleForTest() {
2940
- return this._scale;
2941
- }
2942
- baseScaleForTest() {
2943
- return this._baseScale();
2944
- }
2945
- renderEpochForTest() {
2946
- return this._renderEpoch;
2947
- }
2948
- resizeForTest() {
2949
- this._onResize();
2950
- }
2951
- contentAtViewportYForTest(e) {
2952
- let t = this._scrollHost.scrollTop + e, n = this._slideIndexAtOffset(t), r = this._uniformSlideHeight;
2953
- return {
2954
- slide: n,
2955
- frac: r > 0 ? Math.min(1, Math.max(0, (t - this._slideOffset(n)) / r)) : 0
2956
- };
2957
- }
2958
- viewportYOfForTest(e, t) {
2959
- return this._slideOffset(e) + t * this._uniformSlideHeight - this._scrollHost.scrollTop;
2960
- }
2961
- async getResourceMetrics() {
2962
- if (!this._pres) throw Error("Presentation not loaded");
2963
- return await this._pres.getResourceMetrics();
2964
- }
2965
- getSelectionContext(e = {}) {
2966
- if (this._destroyed) throw Error("PptxScrollViewer is destroyed");
2967
- if (this._pres && this._activeCommentId !== null && this._activeCommentSlide !== null) {
2968
- let t = this._pres.getComments(this._activeCommentSlide), n = t.findIndex((e, t) => P(e, t, this._activeCommentSlide) === this._activeCommentId), r = t[n];
2969
- if (r && n >= 0) return Ut(r, this._activeCommentSlide, n, this._activeCommentId, e);
2970
- }
2971
- return (this._opts.enableTextSelection ? X(this._wrapper, this._wrapper.ownerDocument?.getSelection?.() ?? null, e) : null) ?? (this._elementContext ? It(this._elementContext, e.maxTextCharacters) : null);
2972
- }
2973
- _emitSelectionContextChange() {
2974
- let e = this.getSelectionContext();
2975
- e?.kind === "text" && (this._elementHitGeneration++, this._elementContext = null, this._redrawElementOutlines());
2976
- let t = JSON.stringify(e);
2977
- t !== this._selectionContextKey && (this._selectionContextKey = t, this._opts.onSelectionContextChange?.(e ? structuredClone(e) : null));
2978
- }
2979
- _setElementContext(e) {
2980
- this._elementContext = e ? structuredClone(e) : null, this._redrawElementOutlines(), this._emitSelectionContextChange();
2981
- }
2982
- _invalidateElementSelection(e = !0) {
2983
- this._elementHitGeneration++, this._elementContext = null, this._redrawElementOutlines(), e && this._emitSelectionContextChange();
2984
- }
2985
- _redrawElementOutlines() {
2986
- for (let [e, t] of this._slots) this._redrawElementOutlineForSlot(e, t);
2987
- }
2988
- _redrawElementOutlineForSlot(e, t) {
2989
- let n = this._elementContext, r = this._pres;
2990
- if (!n || !r || n.slideIndex !== e) {
2991
- T(t.elementLayer, null);
2992
- return;
2993
- }
2994
- T(t.elementLayer, {
2995
- x: n.bounds.x / r.slideWidth,
2996
- y: n.bounds.y / r.slideHeight,
2997
- width: n.bounds.width / r.slideWidth,
2998
- height: n.bounds.height / r.slideHeight,
2999
- rotation: n.bounds.rotation
3000
- });
3001
- }
3002
- async _onElementClick(e) {
3003
- this._destroyed || e.defaultPrevented || e.button !== 0 || await this._resolveContextAt(e);
3004
- }
3005
- _onContextMenu(e) {
3006
- let t;
3007
- this._opts.onContextMenu?.({
3008
- originalEvent: e,
3009
- getContext: () => t ??= this._resolveContextAt(e)
3010
- });
3011
- }
3012
- async _resolveContextAt(e) {
3013
- let t = this._pres;
3014
- if (this._destroyed || !t) return null;
3015
- if (this._opts.enableTextSelection && X(this._wrapper, this._wrapper.ownerDocument?.getSelection?.() ?? null)) return this._emitSelectionContextChange(), this._destroyed ? null : this.getSelectionContext();
3016
- if (!this._opts.enableElementSelection) return this.getSelectionContext();
3017
- let n = e.target, r = [...this._slots].find(([, e]) => n !== null && e.wrapper.contains(n));
3018
- if (!r) return this._invalidateElementSelection(), null;
3019
- let [i, a] = r, o = a.canvas.getBoundingClientRect();
3020
- if (o.width <= 0 || o.height <= 0) return this._invalidateElementSelection(), null;
3021
- let s = e.clientX - o.left, c = e.clientY - o.top;
3022
- if (s < 0 || c < 0 || s > o.width || c > o.height) return this._invalidateElementSelection(), null;
3023
- let l = ++this._elementHitGeneration, u = {
3024
- x: s / o.width * t.slideWidth,
3025
- y: c / o.height * t.slideHeight
3026
- }, d;
3027
- try {
3028
- d = await t.getElementContextAt(i, u, {
3029
- tolerance: this._elementHitTolerance / o.width * t.slideWidth,
3030
- maxTextCharacters: G
3031
- });
3032
- } catch (e) {
3033
- if (this._destroyed || l !== this._elementHitGeneration || t !== this._pres) return null;
3034
- throw e;
3035
- }
3036
- return this._destroyed || l !== this._elementHitGeneration || t !== this._pres ? null : (this._setElementContext(d), this._destroyed ? null : this.getSelectionContext());
3037
- }
3038
- destroy() {
3039
- if (!this._destroyed) {
3040
- 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);
3041
- for (let [e, t] of [...this._slots]) this._recycleSlot(e, t);
3042
- this._free.length = 0, this._presentationOwner.close(), this._wrapper.remove();
3043
- }
3044
- }
3045
- }, nn = /* @__PURE__ */ e({
3046
- OoxmlDecodedImageLimitError: () => Te,
3047
- OoxmlError: () => d,
3048
- OoxmlResourceLimitError: () => m,
3049
- PptxPresentation: () => J,
3050
- PptxScrollViewer: () => tn,
3051
- PptxViewer: () => Q,
3052
- TiffDecodeError: () => Ee,
3053
- autoResize: () => S,
3054
- buildPptxHighlightLayer: () => L,
3055
- buildPptxTextLayer: () => I,
3056
- isOoxmlDecodedImageLimitError: () => we,
3057
- isTiffDecodeError: () => De,
3058
- openExternalHyperlink: () => p,
3059
- readPptxTextSelectionContext: () => X,
3060
- renderSlide: () => Me
3061
- });
3062
- //#endregion
3063
- export { J as a, X as i, tn as n, L as o, Q as r, I as s, nn as t };