@s8fy/pptx-parser 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,107 +1,86 @@
1
+ //#endregion
1
2
  //#region src/latin1.ts
2
- /**
3
- * Convert raw bytes to a Latin-1 string where each char code maps 1:1 to a byte.
4
- * NOTE: Do not use TextDecoder('latin1') for binary transport; browsers alias it
5
- * to Windows-1252 and remap bytes 0x80-0x9F to different code points.
6
- */
7
- function uint8ArrayToLatin1(bytes) {
8
- const len = bytes.length;
9
- if (len === 0) return "";
10
- const chunks = [];
11
- const CHUNK = 8192;
12
- for (let i = 0; i < len; i += CHUNK) chunks.push(String.fromCharCode.apply(null, bytes.subarray(i, i + CHUNK)));
13
- return chunks.join("");
14
- }
15
- function arrayBufferToLatin1(buffer) {
16
- return uint8ArrayToLatin1(new Uint8Array(buffer));
17
- }
18
- function latin1ToUint8Array(latin1) {
19
- const len = latin1.length;
20
- const bytes = new Uint8Array(len);
21
- for (let i = 0; i < len; i++) bytes[i] = latin1.charCodeAt(i) & 255;
22
- return bytes;
3
+ function uint8ArrayToLatin1(e) {
4
+ let t = e.length;
5
+ if (t === 0) return "";
6
+ let n = [], r = 8192;
7
+ for (let i = 0; i < t; i += r) n.push(String.fromCharCode.apply(null, e.subarray(i, i + r)));
8
+ return n.join("");
9
+ }
10
+ function arrayBufferToLatin1(e) {
11
+ return uint8ArrayToLatin1(new Uint8Array(e));
12
+ }
13
+ function latin1ToUint8Array(e) {
14
+ let t = e.length, n = new Uint8Array(t);
15
+ for (let r = 0; r < t; r++) n[r] = e.charCodeAt(r) & 255;
16
+ return n;
23
17
  }
24
18
  //#endregion
25
19
  //#region src/wasm-loader.ts
26
- function fileUrl(url) {
20
+ function fileUrl(e) {
27
21
  try {
28
- const parsed = url instanceof URL ? url : new URL(url);
29
- return parsed.protocol === "file:" ? parsed : void 0;
22
+ let t = e instanceof URL ? e : new URL(e);
23
+ return t.protocol === "file:" ? t : void 0;
30
24
  } catch {
31
25
  return;
32
26
  }
33
27
  }
34
- function isUnsupportedNodeFileFetch(error) {
35
- const cause = error?.cause;
36
- const detail = cause instanceof Error ? cause.message : "";
37
- return error instanceof TypeError && error.message === "fetch failed" && detail.includes("not implemented");
28
+ function isUnsupportedNodeFileFetch(e) {
29
+ let t = e?.cause, n = t instanceof Error ? t.message : "";
30
+ return e instanceof TypeError && e.message === "fetch failed" && n.includes("not implemented");
38
31
  }
39
- async function readNodeFile(url) {
40
- const fs = globalThis.process?.getBuiltinModule?.("node:fs")?.promises;
41
- if (!fs) throw new Error(`Node.js file loading is unavailable for ${url.href}`);
42
- const bytes = await fs.readFile(url);
43
- return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
32
+ async function readNodeFile(e) {
33
+ let t = globalThis.process?.getBuiltinModule?.("node:fs")?.promises;
34
+ if (!t) throw Error(`Node.js file loading is unavailable for ${e.href}`);
35
+ let n = await t.readFile(e);
36
+ return n.buffer.slice(n.byteOffset, n.byteOffset + n.byteLength);
44
37
  }
45
- function assertWasmBytes(bytes, url, label, contentType) {
46
- const magic = new Uint8Array(bytes, 0, Math.min(bytes.byteLength, 4));
47
- if (!(magic.length === 4 && magic[0] === 0 && magic[1] === 97 && magic[2] === 115 && magic[3] === 109)) throw new Error(`[${label}] Invalid WASM response from ${String(url)}: content-type=${contentType}, bytes=${bytes.byteLength}. Check that the WASM asset exists and is served by the app.`);
38
+ function assertWasmBytes(e, t, n, r) {
39
+ let i = new Uint8Array(e, 0, Math.min(e.byteLength, 4));
40
+ if (i.length !== 4 || i[0] !== 0 || i[1] !== 97 || i[2] !== 115 || i[3] !== 109) throw Error(`[${n}] Invalid WASM response from ${String(t)}: content-type=${r}, bytes=${e.byteLength}. Check that the WASM asset exists and is served by the app.`);
48
41
  }
49
- async function fetchWasmBytes(url, label) {
50
- let response;
42
+ async function fetchWasmBytes(e, t) {
43
+ let n;
51
44
  try {
52
- response = await fetch(url);
53
- } catch (error) {
54
- const localFile = fileUrl(url);
55
- if (!localFile || !isUnsupportedNodeFileFetch(error)) throw error;
56
- const bytes = await readNodeFile(localFile);
57
- assertWasmBytes(bytes, url, label, "application/wasm");
58
- return bytes;
45
+ n = await fetch(e);
46
+ } catch (n) {
47
+ let r = fileUrl(e);
48
+ if (!r || !isUnsupportedNodeFileFetch(n)) throw n;
49
+ let i = await readNodeFile(r);
50
+ return assertWasmBytes(i, e, t, "application/wasm"), i;
59
51
  }
60
- if (!response.ok) throw new Error(`[${label}] Failed to load WASM ${String(url)}: ${response.status} ${response.statusText}`);
61
- const bytes = await response.arrayBuffer();
62
- assertWasmBytes(bytes, url, label, response.headers.get("content-type") || "unknown");
63
- return bytes;
52
+ if (!n.ok) throw Error(`[${t}] Failed to load WASM ${String(e)}: ${n.status} ${n.statusText}`);
53
+ let r = await n.arrayBuffer();
54
+ return assertWasmBytes(r, e, t, n.headers.get("content-type") || "unknown"), r;
64
55
  }
65
56
  //#endregion
66
57
  //#region src/runtime-module-url.ts
67
- const classicScriptUrl = (() => {
68
- if (typeof document === "undefined" || typeof HTMLScriptElement === "undefined") return void 0;
69
- return document.currentScript instanceof HTMLScriptElement && document.currentScript.src ? document.currentScript.src : void 0;
58
+ const e = (() => {
59
+ if (!(typeof document > "u" || typeof HTMLScriptElement > "u")) return document.currentScript instanceof HTMLScriptElement && document.currentScript.src ? document.currentScript.src : void 0;
70
60
  })();
71
- /** @internal Convert a Node CJS filename to a URL without losing a UNC authority. */
72
- function fileNameUrl(fileName) {
73
- const normalized = fileName.replaceAll("\\", "/");
74
- if (normalized.startsWith("//")) {
75
- const shareSeparator = normalized.indexOf("/", 2);
76
- if (shareSeparator > 2) {
77
- const url = new URL("file://localhost/");
78
- url.hostname = normalized.slice(2, shareSeparator);
79
- url.pathname = normalized.slice(shareSeparator);
80
- return url.href;
61
+ function fileNameUrl(e) {
62
+ let t = e.replaceAll("\\", "/");
63
+ if (t.startsWith("//")) {
64
+ let e = t.indexOf("/", 2);
65
+ if (e > 2) {
66
+ let n = new URL("file://localhost/");
67
+ return n.hostname = t.slice(2, e), n.pathname = t.slice(e), n.href;
81
68
  }
82
69
  }
83
- const url = new URL("file:///");
84
- url.pathname = normalized.startsWith("/") ? normalized : `/${normalized}`;
85
- return url.href;
86
- }
87
- /** Resolve the current bundle URL in ESM, Node CJS, or a classic UMD script. */
88
- function runtimeModuleUrl(importMetaUrl) {
89
- if (typeof importMetaUrl === "string" && importMetaUrl) return importMetaUrl;
90
- if (typeof __filename === "string" && __filename) return fileNameUrl(__filename);
91
- return classicScriptUrl;
92
- }
93
- /** Resolve a package-relative runtime asset in ESM, Node CJS, or a classic UMD script. */
94
- function runtimeAssetUrl(asset, importMetaUrl) {
95
- const moduleUrl = runtimeModuleUrl(importMetaUrl);
96
- if (!moduleUrl) throw new Error(`Unable to resolve runtime asset URL: ${asset}`);
97
- return new URL(asset, moduleUrl);
70
+ let n = new URL("file:///");
71
+ return n.pathname = t.startsWith("/") ? t : `/${t}`, n.href;
72
+ }
73
+ function runtimeModuleUrl(t) {
74
+ return typeof t == "string" && t ? t : typeof __filename == "string" && __filename ? fileNameUrl(__filename) : e;
75
+ }
76
+ function runtimeAssetUrl(e, t) {
77
+ let n = runtimeModuleUrl(t);
78
+ if (!n) throw Error(`Unable to resolve runtime asset URL: ${e}`);
79
+ return new URL(e, n);
98
80
  }
99
81
  //#endregion
100
82
  //#region ../../node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/browser.js
101
- var u8 = Uint8Array;
102
- var u16 = Uint16Array;
103
- var i32 = Int32Array;
104
- var fleb = new u8([
83
+ var t = Uint8Array, n = Uint16Array, r = Int32Array, i = new t([
105
84
  0,
106
85
  0,
107
86
  0,
@@ -134,8 +113,7 @@ var fleb = new u8([
134
113
  0,
135
114
  0,
136
115
  0
137
- ]);
138
- var fdeb = new u8([
116
+ ]), a = new t([
139
117
  0,
140
118
  0,
141
119
  0,
@@ -168,8 +146,7 @@ var fdeb = new u8([
168
146
  13,
169
147
  0,
170
148
  0
171
- ]);
172
- var clim = new u8([
149
+ ]), o = new t([
173
150
  16,
174
151
  17,
175
152
  18,
@@ -189,85 +166,51 @@ var clim = new u8([
189
166
  14,
190
167
  1,
191
168
  15
192
- ]);
193
- var freb = function(eb, start) {
194
- var b = new u16(31);
195
- for (var i = 0; i < 31; ++i) b[i] = start += 1 << eb[i - 1];
196
- var r = new i32(b[30]);
197
- for (var i = 1; i < 30; ++i) for (var j = b[i]; j < b[i + 1]; ++j) r[j] = j - b[i] << 5 | i;
169
+ ]), freb = function(e, t) {
170
+ for (var i = new n(31), a = 0; a < 31; ++a) i[a] = t += 1 << e[a - 1];
171
+ for (var o = new r(i[30]), a = 1; a < 30; ++a) for (var s = i[a]; s < i[a + 1]; ++s) o[s] = s - i[a] << 5 | a;
198
172
  return {
199
- b,
200
- r
173
+ b: i,
174
+ r: o
201
175
  };
202
- };
203
- var _a = freb(fleb, 2);
204
- var fl = _a.b;
205
- var revfl = _a.r;
206
- fl[28] = 258, revfl[258] = 28;
207
- var _b = freb(fdeb, 0);
208
- var fd = _b.b;
209
- _b.r;
210
- var rev = new u16(32768);
211
- for (var i = 0; i < 32768; ++i) {
212
- var x = (i & 43690) >> 1 | (i & 21845) << 1;
213
- x = (x & 52428) >> 2 | (x & 13107) << 2;
214
- x = (x & 61680) >> 4 | (x & 3855) << 4;
215
- rev[i] = ((x & 65280) >> 8 | (x & 255) << 8) >> 1;
216
- }
217
- var hMap = (function(cd, mb, r) {
218
- var s = cd.length;
219
- var i = 0;
220
- var l = new u16(mb);
221
- for (; i < s; ++i) if (cd[i]) ++l[cd[i] - 1];
222
- var le = new u16(mb);
223
- for (i = 1; i < mb; ++i) le[i] = le[i - 1] + l[i - 1] << 1;
224
- var co;
176
+ }, s = freb(i, 2), c = s.b, l = s.r;
177
+ c[28] = 258, l[258] = 28;
178
+ var u = freb(a, 0), d = u.b;
179
+ u.r;
180
+ for (var f = new n(32768), p = 0; p < 32768; ++p) {
181
+ var m = (p & 43690) >> 1 | (p & 21845) << 1;
182
+ m = (m & 52428) >> 2 | (m & 13107) << 2, m = (m & 61680) >> 4 | (m & 3855) << 4, f[p] = ((m & 65280) >> 8 | (m & 255) << 8) >> 1;
183
+ }
184
+ for (var hMap = (function(e, t, r) {
185
+ for (var i = e.length, a = 0, o = new n(t); a < i; ++a) e[a] && ++o[e[a] - 1];
186
+ var s = new n(t);
187
+ for (a = 1; a < t; ++a) s[a] = s[a - 1] + o[a - 1] << 1;
188
+ var c;
225
189
  if (r) {
226
- co = new u16(1 << mb);
227
- var rvb = 15 - mb;
228
- for (i = 0; i < s; ++i) if (cd[i]) {
229
- var sv = i << 4 | cd[i];
230
- var r_1 = mb - cd[i];
231
- var v = le[cd[i] - 1]++ << r_1;
232
- for (var m = v | (1 << r_1) - 1; v <= m; ++v) co[rev[v] >> rvb] = sv;
233
- }
234
- } else {
235
- co = new u16(s);
236
- for (i = 0; i < s; ++i) if (cd[i]) co[i] = rev[le[cd[i] - 1]++] >> 15 - cd[i];
237
- }
238
- return co;
239
- });
240
- var flt = new u8(288);
241
- for (var i = 0; i < 144; ++i) flt[i] = 8;
242
- for (var i = 144; i < 256; ++i) flt[i] = 9;
243
- for (var i = 256; i < 280; ++i) flt[i] = 7;
244
- for (var i = 280; i < 288; ++i) flt[i] = 8;
245
- var fdt = new u8(32);
246
- for (var i = 0; i < 32; ++i) fdt[i] = 5;
247
- var flrm = /*#__PURE__*/ hMap(flt, 9, 1);
248
- var fdrm = /*#__PURE__*/ hMap(fdt, 5, 1);
249
- var max = function(a) {
250
- var m = a[0];
251
- for (var i = 1; i < a.length; ++i) if (a[i] > m) m = a[i];
252
- return m;
253
- };
254
- var bits = function(d, p, m) {
255
- var o = p / 8 | 0;
256
- return (d[o] | d[o + 1] << 8) >> (p & 7) & m;
257
- };
258
- var bits16 = function(d, p) {
259
- var o = p / 8 | 0;
260
- return (d[o] | d[o + 1] << 8 | d[o + 2] << 16) >> (p & 7);
261
- };
262
- var shft = function(p) {
263
- return (p + 7) / 8 | 0;
264
- };
265
- var slc = function(v, s, e) {
266
- if (s == null || s < 0) s = 0;
267
- if (e == null || e > v.length) e = v.length;
268
- return new u8(v.subarray(s, e));
269
- };
270
- var ec = [
190
+ c = new n(1 << t);
191
+ var l = 15 - t;
192
+ for (a = 0; a < i; ++a) if (e[a]) for (var u = a << 4 | e[a], d = t - e[a], p = s[e[a] - 1]++ << d, m = p | (1 << d) - 1; p <= m; ++p) c[f[p] >> l] = u;
193
+ } else for (c = new n(i), a = 0; a < i; ++a) e[a] && (c[a] = f[s[e[a] - 1]++] >> 15 - e[a]);
194
+ return c;
195
+ }), h = new t(288), p = 0; p < 144; ++p) h[p] = 8;
196
+ for (var p = 144; p < 256; ++p) h[p] = 9;
197
+ for (var p = 256; p < 280; ++p) h[p] = 7;
198
+ for (var p = 280; p < 288; ++p) h[p] = 8;
199
+ for (var g = new t(32), p = 0; p < 32; ++p) g[p] = 5;
200
+ var _ = /*#__PURE__*/ hMap(h, 9, 1), v = /*#__PURE__*/ hMap(g, 5, 1), max = function(e) {
201
+ for (var t = e[0], n = 1; n < e.length; ++n) e[n] > t && (t = e[n]);
202
+ return t;
203
+ }, bits = function(e, t, n) {
204
+ var r = t / 8 | 0;
205
+ return (e[r] | e[r + 1] << 8) >> (t & 7) & n;
206
+ }, bits16 = function(e, t) {
207
+ var n = t / 8 | 0;
208
+ return (e[n] | e[n + 1] << 8 | e[n + 2] << 16) >> (t & 7);
209
+ }, shft = function(e) {
210
+ return (e + 7) / 8 | 0;
211
+ }, slc = function(e, n, r) {
212
+ return (n == null || n < 0) && (n = 0), (r == null || r > e.length) && (r = e.length), new t(e.subarray(n, r));
213
+ }, y = [
271
214
  "unexpected EOF",
272
215
  "invalid block type",
273
216
  "invalid length/literal",
@@ -282,257 +225,185 @@ var ec = [
282
225
  "filename too long",
283
226
  "stream finishing",
284
227
  "invalid zip data"
285
- ];
286
- var err = function(ind, msg, nt) {
287
- var e = new Error(msg || ec[ind]);
288
- e.code = ind;
289
- if (Error.captureStackTrace) Error.captureStackTrace(e, err);
290
- if (!nt) throw e;
291
- return e;
292
- };
293
- var inflt = function(dat, st, buf, dict) {
294
- var sl = dat.length, dl = dict ? dict.length : 0;
295
- if (!sl || st.f && !st.l) return buf || new u8(0);
296
- var noBuf = !buf;
297
- var resize = noBuf || st.i != 2;
298
- var noSt = st.i;
299
- if (noBuf) buf = new u8(sl * 3);
300
- var cbuf = function(l) {
301
- var bl = buf.length;
302
- if (l > bl) {
303
- var nbuf = new u8(Math.max(bl * 2, l));
304
- nbuf.set(buf);
305
- buf = nbuf;
228
+ ], err = function(e, t, n) {
229
+ var r = Error(t || y[e]);
230
+ if (r.code = e, Error.captureStackTrace && Error.captureStackTrace(r, err), !n) throw r;
231
+ return r;
232
+ }, inflt = function(e, n, r, s) {
233
+ var l = e.length, u = s ? s.length : 0;
234
+ if (!l || n.f && !n.l) return r || new t(0);
235
+ var f = !r, p = f || n.i != 2, m = n.i;
236
+ f && (r = new t(l * 3));
237
+ var cbuf = function(e) {
238
+ var n = r.length;
239
+ if (e > n) {
240
+ var i = new t(Math.max(n * 2, e));
241
+ i.set(r), r = i;
306
242
  }
307
- };
308
- var final = st.f || 0, pos = st.p || 0, bt = st.b || 0, lm = st.l, dm = st.d, lbt = st.m, dbt = st.n;
309
- var tbts = sl * 8;
243
+ }, h = n.f || 0, g = n.p || 0, y = n.b || 0, b = n.l, x = n.d, S = n.m, C = n.n, w = l * 8;
310
244
  do {
311
- if (!lm) {
312
- final = bits(dat, pos, 1);
313
- var type = bits(dat, pos + 1, 3);
314
- pos += 3;
315
- if (!type) {
316
- var s = shft(pos) + 4, l = dat[s - 4] | dat[s - 3] << 8, t = s + l;
317
- if (t > sl) {
318
- if (noSt) err(0);
245
+ if (!b) {
246
+ h = bits(e, g, 1);
247
+ var T = bits(e, g + 1, 3);
248
+ if (g += 3, !T) {
249
+ var E = shft(g) + 4, D = e[E - 4] | e[E - 3] << 8, O = E + D;
250
+ if (O > l) {
251
+ m && err(0);
319
252
  break;
320
253
  }
321
- if (resize) cbuf(bt + l);
322
- buf.set(dat.subarray(s, t), bt);
323
- st.b = bt += l, st.p = pos = t * 8, st.f = final;
254
+ p && cbuf(y + D), r.set(e.subarray(E, O), y), n.b = y += D, n.p = g = O * 8, n.f = h;
324
255
  continue;
325
- } else if (type == 1) lm = flrm, dm = fdrm, lbt = 9, dbt = 5;
326
- else if (type == 2) {
327
- var hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;
328
- var tl = hLit + bits(dat, pos + 5, 31) + 1;
329
- pos += 14;
330
- var ldt = new u8(tl);
331
- var clt = new u8(19);
332
- for (var i = 0; i < hcLen; ++i) clt[clim[i]] = bits(dat, pos + i * 3, 7);
333
- pos += hcLen * 3;
334
- var clb = max(clt), clbmsk = (1 << clb) - 1;
335
- var clm = hMap(clt, clb, 1);
336
- for (var i = 0; i < tl;) {
337
- var r = clm[bits(dat, pos, clbmsk)];
338
- pos += r & 15;
339
- var s = r >> 4;
340
- if (s < 16) ldt[i++] = s;
256
+ }
257
+ if (T == 1) b = _, x = v, S = 9, C = 5;
258
+ else if (T == 2) {
259
+ var k = bits(e, g, 31) + 257, A = bits(e, g + 10, 15) + 4, j = k + bits(e, g + 5, 31) + 1;
260
+ g += 14;
261
+ for (var M = new t(j), N = new t(19), P = 0; P < A; ++P) N[o[P]] = bits(e, g + P * 3, 7);
262
+ g += A * 3;
263
+ for (var F = max(N), I = (1 << F) - 1, L = hMap(N, F, 1), P = 0; P < j;) {
264
+ var R = L[bits(e, g, I)];
265
+ g += R & 15;
266
+ var E = R >> 4;
267
+ if (E < 16) M[P++] = E;
341
268
  else {
342
- var c = 0, n = 0;
343
- if (s == 16) n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i - 1];
344
- else if (s == 17) n = 3 + bits(dat, pos, 7), pos += 3;
345
- else if (s == 18) n = 11 + bits(dat, pos, 127), pos += 7;
346
- while (n--) ldt[i++] = c;
269
+ var z = 0, B = 0;
270
+ for (E == 16 ? (B = 3 + bits(e, g, 3), g += 2, z = M[P - 1]) : E == 17 ? (B = 3 + bits(e, g, 7), g += 3) : E == 18 && (B = 11 + bits(e, g, 127), g += 7); B--;) M[P++] = z;
347
271
  }
348
272
  }
349
- var lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);
350
- lbt = max(lt);
351
- dbt = max(dt);
352
- lm = hMap(lt, lbt, 1);
353
- dm = hMap(dt, dbt, 1);
273
+ var V = M.subarray(0, k), H = M.subarray(k);
274
+ S = max(V), C = max(H), b = hMap(V, S, 1), x = hMap(H, C, 1);
354
275
  } else err(1);
355
- if (pos > tbts) {
356
- if (noSt) err(0);
276
+ if (g > w) {
277
+ m && err(0);
357
278
  break;
358
279
  }
359
280
  }
360
- if (resize) cbuf(bt + 131072);
361
- var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;
362
- var lpos = pos;
363
- for (;; lpos = pos) {
364
- var c = lm[bits16(dat, pos) & lms], sym = c >> 4;
365
- pos += c & 15;
366
- if (pos > tbts) {
367
- if (noSt) err(0);
281
+ p && cbuf(y + 131072);
282
+ for (var U = (1 << S) - 1, W = (1 << C) - 1, G = g;; G = g) {
283
+ var z = b[bits16(e, g) & U], K = z >> 4;
284
+ if (g += z & 15, g > w) {
285
+ m && err(0);
368
286
  break;
369
287
  }
370
- if (!c) err(2);
371
- if (sym < 256) buf[bt++] = sym;
372
- else if (sym == 256) {
373
- lpos = pos, lm = null;
288
+ if (z || err(2), K < 256) r[y++] = K;
289
+ else if (K == 256) {
290
+ G = g, b = null;
374
291
  break;
375
292
  } else {
376
- var add = sym - 254;
377
- if (sym > 264) {
378
- var i = sym - 257, b = fleb[i];
379
- add = bits(dat, pos, (1 << b) - 1) + fl[i];
380
- pos += b;
293
+ var q = K - 254;
294
+ if (K > 264) {
295
+ var P = K - 257, J = i[P];
296
+ q = bits(e, g, (1 << J) - 1) + c[P], g += J;
381
297
  }
382
- var d = dm[bits16(dat, pos) & dms], dsym = d >> 4;
383
- if (!d) err(3);
384
- pos += d & 15;
385
- var dt = fd[dsym];
386
- if (dsym > 3) {
387
- var b = fdeb[dsym];
388
- dt += bits16(dat, pos) & (1 << b) - 1, pos += b;
298
+ var Y = x[bits16(e, g) & W], X = Y >> 4;
299
+ Y || err(3), g += Y & 15;
300
+ var H = d[X];
301
+ if (X > 3) {
302
+ var J = a[X];
303
+ H += bits16(e, g) & (1 << J) - 1, g += J;
389
304
  }
390
- if (pos > tbts) {
391
- if (noSt) err(0);
305
+ if (g > w) {
306
+ m && err(0);
392
307
  break;
393
308
  }
394
- if (resize) cbuf(bt + 131072);
395
- var end = bt + add;
396
- if (bt < dt) {
397
- var shift = dl - dt, dend = Math.min(dt, end);
398
- if (shift + bt < 0) err(3);
399
- for (; bt < dend; ++bt) buf[bt] = dict[shift + bt];
309
+ p && cbuf(y + 131072);
310
+ var Z = y + q;
311
+ if (y < H) {
312
+ var Q = u - H, $ = Math.min(H, Z);
313
+ for (Q + y < 0 && err(3); y < $; ++y) r[y] = s[Q + y];
400
314
  }
401
- for (; bt < end; ++bt) buf[bt] = buf[bt - dt];
315
+ for (; y < Z; ++y) r[y] = r[y - H];
402
316
  }
403
317
  }
404
- st.l = lm, st.p = lpos, st.b = bt, st.f = final;
405
- if (lm) final = 1, st.m = lbt, st.d = dm, st.n = dbt;
406
- } while (!final);
407
- return bt != buf.length && noBuf ? slc(buf, 0, bt) : buf.subarray(0, bt);
408
- };
409
- var et = /*#__PURE__*/ new u8(0);
410
- var b2 = function(d, b) {
411
- return d[b] | d[b + 1] << 8;
412
- };
413
- var b4 = function(d, b) {
414
- return (d[b] | d[b + 1] << 8 | d[b + 2] << 16 | d[b + 3] << 24) >>> 0;
318
+ n.l = b, n.p = G, n.b = y, n.f = h, b && (h = 1, n.m = S, n.d = x, n.n = C);
319
+ } while (!h);
320
+ return y != r.length && f ? slc(r, 0, y) : r.subarray(0, y);
321
+ }, b = /*#__PURE__*/ new t(0), b2 = function(e, t) {
322
+ return e[t] | e[t + 1] << 8;
323
+ }, b4 = function(e, t) {
324
+ return (e[t] | e[t + 1] << 8 | e[t + 2] << 16 | e[t + 3] << 24) >>> 0;
325
+ }, b8 = function(e, t) {
326
+ return b4(e, t) + b4(e, t + 4) * 4294967296;
415
327
  };
416
- var b8 = function(d, b) {
417
- return b4(d, b) + b4(d, b + 4) * 4294967296;
418
- };
419
- function inflateSync(data, opts) {
420
- return inflt(data, { i: 2 }, opts && opts.out, opts && opts.dictionary);
328
+ function inflateSync(e, t) {
329
+ return inflt(e, { i: 2 }, t && t.out, t && t.dictionary);
421
330
  }
422
- var td = typeof TextDecoder != "undefined" && /*#__PURE__*/ new TextDecoder();
331
+ var x = typeof TextDecoder < "u" && /*#__PURE__*/ new TextDecoder();
423
332
  try {
424
- td.decode(et, { stream: true });
425
- } catch (e) {}
426
- var dutf8 = function(d) {
427
- for (var r = "", i = 0;;) {
428
- var c = d[i++];
429
- var eb = (c > 127) + (c > 223) + (c > 239);
430
- if (i + eb > d.length) return {
431
- s: r,
432
- r: slc(d, i - 1)
333
+ x.decode(b, { stream: !0 });
334
+ } catch {}
335
+ var dutf8 = function(e) {
336
+ for (var t = "", n = 0;;) {
337
+ var r = e[n++], i = (r > 127) + (r > 223) + (r > 239);
338
+ if (n + i > e.length) return {
339
+ s: t,
340
+ r: slc(e, n - 1)
433
341
  };
434
- if (!eb) r += String.fromCharCode(c);
435
- else if (eb == 3) c = ((c & 15) << 18 | (d[i++] & 63) << 12 | (d[i++] & 63) << 6 | d[i++] & 63) - 65536, r += String.fromCharCode(55296 | c >> 10, 56320 | c & 1023);
436
- else if (eb & 1) r += String.fromCharCode((c & 31) << 6 | d[i++] & 63);
437
- else r += String.fromCharCode((c & 15) << 12 | (d[i++] & 63) << 6 | d[i++] & 63);
342
+ i ? i == 3 ? (r = ((r & 15) << 18 | (e[n++] & 63) << 12 | (e[n++] & 63) << 6 | e[n++] & 63) - 65536, t += String.fromCharCode(55296 | r >> 10, 56320 | r & 1023)) : i & 1 ? t += String.fromCharCode((r & 31) << 6 | e[n++] & 63) : t += String.fromCharCode((r & 15) << 12 | (e[n++] & 63) << 6 | e[n++] & 63) : t += String.fromCharCode(r);
438
343
  }
439
344
  };
440
- /**
441
- * Converts a Uint8Array to a string
442
- * @param dat The data to decode to string
443
- * @param latin1 Whether or not to interpret the data as Latin-1. This should
444
- * not need to be true unless encoding to binary string.
445
- * @returns The original UTF-8/Latin-1 string
446
- */
447
- function strFromU8(dat, latin1) {
448
- if (latin1) {
449
- var r = "";
450
- for (var i = 0; i < dat.length; i += 16384) r += String.fromCharCode.apply(null, dat.subarray(i, i + 16384));
451
- return r;
452
- } else if (td) return td.decode(dat);
453
- else {
454
- var _a = dutf8(dat), s = _a.s, r = _a.r;
455
- if (r.length) err(8);
456
- return s;
345
+ function strFromU8(e, t) {
346
+ if (t) {
347
+ for (var n = "", r = 0; r < e.length; r += 16384) n += String.fromCharCode.apply(null, e.subarray(r, r + 16384));
348
+ return n;
457
349
  }
458
- }
459
- var slzh = function(d, b) {
460
- return b + 30 + b2(d, b + 26) + b2(d, b + 28);
461
- };
462
- var zh = function(d, b, z) {
463
- var fnl = b2(d, b + 28), efl = b2(d, b + 30), fn = strFromU8(d.subarray(b + 46, b + 46 + fnl), !(b2(d, b + 8) & 2048)), es = b + 46 + fnl;
464
- var _a = z64hs(d, es, efl, z, b4(d, b + 20), b4(d, b + 24), b4(d, b + 42)), sc = _a[0], su = _a[1], off = _a[2];
350
+ if (x) return x.decode(e);
351
+ var i = dutf8(e), a = i.s, n = i.r;
352
+ return n.length && err(8), a;
353
+ }
354
+ var slzh = function(e, t) {
355
+ return t + 30 + b2(e, t + 26) + b2(e, t + 28);
356
+ }, zh = function(e, t, n) {
357
+ var r = b2(e, t + 28), i = b2(e, t + 30), a = strFromU8(e.subarray(t + 46, t + 46 + r), !(b2(e, t + 8) & 2048)), o = t + 46 + r, s = z64hs(e, o, i, n, b4(e, t + 20), b4(e, t + 24), b4(e, t + 42)), c = s[0], l = s[1], u = s[2];
465
358
  return [
466
- b2(d, b + 10),
467
- sc,
468
- su,
469
- fn,
470
- es + efl + b2(d, b + 32),
471
- off
359
+ b2(e, t + 10),
360
+ c,
361
+ l,
362
+ a,
363
+ o + i + b2(e, t + 32),
364
+ u
472
365
  ];
473
- };
474
- var z64hs = function(d, b, l, z, sc, su, off) {
475
- var nsc = sc == 4294967295, nsu = su == 4294967295, noff = off == 4294967295, e = b + l;
476
- var nf = nsc + nsu + noff;
477
- if (z && nf) {
478
- for (; b + 4 < e; b += 4 + b2(d, b + 2)) if (b2(d, b) == 1) return [
479
- nsc ? b8(d, b + 4 + 8 * nsu) : sc,
480
- nsu ? b8(d, b + 4) : su,
481
- noff ? b8(d, b + 4 + 8 * (nsu + nsc)) : off,
366
+ }, z64hs = function(e, t, n, r, i, a, o) {
367
+ var s = i == 4294967295, c = a == 4294967295, l = o == 4294967295, u = t + n, d = s + c + l;
368
+ if (r && d) {
369
+ for (; t + 4 < u; t += 4 + b2(e, t + 2)) if (b2(e, t) == 1) return [
370
+ s ? b8(e, t + 4 + 8 * c) : i,
371
+ c ? b8(e, t + 4) : a,
372
+ l ? b8(e, t + 4 + 8 * (c + s)) : o,
482
373
  1
483
374
  ];
484
- if (z < 2) err(13);
375
+ r < 2 && err(13);
485
376
  }
486
377
  return [
487
- sc,
488
- su,
489
- off,
378
+ i,
379
+ a,
380
+ o,
490
381
  0
491
382
  ];
492
383
  };
493
- /**
494
- * Synchronously decompresses a ZIP archive. Prefer using `unzip` for better
495
- * performance with more than one file.
496
- * @param data The raw compressed ZIP file
497
- * @param opts The ZIP extraction options
498
- * @returns The decompressed files
499
- */
500
- function unzipSync(data, opts) {
501
- var files = {};
502
- var e = data.length - 22;
503
- for (; b4(data, e) != 101010256; --e) if (!e || data.length - e > 65558) err(13);
504
- var c = b2(data, e + 8);
505
- if (!c) return {};
506
- var o = b4(data, e + 16);
507
- var z = b4(data, e - 20) == 117853008;
508
- if (z) {
509
- var ze = b4(data, e - 12);
510
- z = b4(data, ze) == 101075792;
511
- if (z) {
512
- c = b4(data, ze + 32);
513
- o = b4(data, ze + 48);
514
- }
384
+ function unzipSync(e, n) {
385
+ for (var r = {}, i = e.length - 22; b4(e, i) != 101010256; --i) (!i || e.length - i > 65558) && err(13);
386
+ var a = b2(e, i + 8);
387
+ if (!a) return {};
388
+ var o = b4(e, i + 16), s = b4(e, i - 20) == 117853008;
389
+ if (s) {
390
+ var c = b4(e, i - 12);
391
+ s = b4(e, c) == 101075792, s && (a = b4(e, c + 32), o = b4(e, c + 48));
515
392
  }
516
- var fltr = opts && opts.filter;
517
- for (var i = 0; i < c; ++i) {
518
- var _a = zh(data, o, z), c_2 = _a[0], sc = _a[1], su = _a[2], fn = _a[3], no = _a[4], off = _a[5], b = slzh(data, off);
519
- o = no;
520
- if (!fltr || fltr({
521
- name: fn,
522
- size: sc,
523
- originalSize: su,
524
- compression: c_2
525
- })) {
526
- if (!c_2) files[fn] = slc(data, b, b + sc);
527
- else if (c_2 == 8) files[fn] = inflateSync(data.subarray(b, b + sc), { out: new u8(su) });
528
- else err(14, "unknown compression type " + c_2);
529
- }
393
+ for (var l = n && n.filter, u = 0; u < a; ++u) {
394
+ var d = zh(e, o, s), f = d[0], p = d[1], m = d[2], h = d[3], g = d[4], _ = d[5], v = slzh(e, _);
395
+ o = g, (!l || l({
396
+ name: h,
397
+ size: p,
398
+ originalSize: m,
399
+ compression: f
400
+ })) && (f ? f == 8 ? r[h] = inflateSync(e.subarray(v, v + p), { out: new t(m) }) : err(14, "unknown compression type " + f) : r[h] = slc(e, v, v + p));
530
401
  }
531
- return files;
402
+ return r;
532
403
  }
533
404
  //#endregion
534
405
  //#region src/resource-policy.generated.ts
535
- const RESOURCE_POLICY_CONTRACT = {
406
+ const S = {
536
407
  schemaVersion: "xdoc-resource-policy-registry/v1",
537
408
  policyVersion: "2026.08",
538
409
  profiles: [{
@@ -597,8 +468,7 @@ const RESOURCE_POLICY_CONTRACT = {
597
468
  "task-budgets",
598
469
  "output"
599
470
  ]
600
- };
601
- const BROWSER_RESOURCE_LIMITS = {
471
+ }, C = {
602
472
  id: "browser-viewer",
603
473
  inputBytes: 104857600,
604
474
  zipEntries: 1e4,
@@ -617,234 +487,197 @@ const BROWSER_RESOURCE_LIMITS = {
617
487
  //#endregion
618
488
  //#region src/resource-policy.ts
619
489
  var ResourcePolicyError = class extends Error {
620
- constructor(details) {
621
- super(`${details.reason}: ${details.subject} observed ${details.observed} ${details.unit}; policy limit is ${details.limit} ${details.unit}. This is an engineering safety limit, not a plan entitlement; reduce or split the input.`);
622
- this.name = "ResourcePolicyError";
623
- this.details = details;
490
+ constructor(e) {
491
+ super(`${e.reason}: ${e.subject} observed ${e.observed} ${e.unit}; policy limit is ${e.limit} ${e.unit}. This is an engineering safety limit, not a plan entitlement; reduce or split the input.`), this.name = "ResourcePolicyError", this.details = e;
624
492
  }
625
493
  };
626
- function fail(reason, stage, subject, limit, observed, unit) {
494
+ function fail(e, t, n, r, i, a) {
627
495
  throw new ResourcePolicyError({
628
- reason,
629
- stage,
630
- subject,
631
- limit,
632
- observed,
633
- unit,
634
- policyVersion: RESOURCE_POLICY_CONTRACT.policyVersion,
635
- commercialUpgradeApplicable: false
496
+ reason: e,
497
+ stage: t,
498
+ subject: n,
499
+ limit: r,
500
+ observed: i,
501
+ unit: a,
502
+ policyVersion: S.policyVersion,
503
+ commercialUpgradeApplicable: !1
636
504
  });
637
505
  }
638
- function checkBrowserInput(bytes, subject = "PPTX input") {
639
- if (bytes > BROWSER_RESOURCE_LIMITS.inputBytes) fail("resource_input_too_large", "input", subject, BROWSER_RESOURCE_LIMITS.inputBytes, bytes, "bytes");
640
- }
641
- function checkBrowserOutput(bytes, subject = "output") {
642
- if (bytes > BROWSER_RESOURCE_LIMITS.outputBytes) fail("resource_output_too_large", "output", subject, BROWSER_RESOURCE_LIMITS.outputBytes, bytes, "bytes");
643
- }
644
- function checkBrowserElapsed(startedAt, subject = "parse wall clock") {
645
- checkBrowserElapsedMs(Math.max(0, Math.ceil(performance.now() - startedAt)), subject);
646
- }
647
- function checkBrowserElapsedMs(elapsed, subject = "parse wall clock") {
648
- if (elapsed > BROWSER_RESOURCE_LIMITS.wallClockMs) fail("resource_timeout", "runtime", subject, BROWSER_RESOURCE_LIMITS.wallClockMs, elapsed, "milliseconds");
649
- }
650
- function isResourcePolicyError(error) {
651
- return error instanceof ResourcePolicyError;
652
- }
653
- function resourcePolicyErrorFromDetails(value) {
654
- if (!value || typeof value !== "object") return null;
655
- const details = value;
656
- if (typeof details.reason !== "string" || !RESOURCE_POLICY_CONTRACT.stableReasons.includes(details.reason) || typeof details.stage !== "string" || typeof details.subject !== "string" || !Number.isSafeInteger(details.limit) || (details.limit ?? -1) < 0 || !Number.isSafeInteger(details.observed) || (details.observed ?? -1) < 0 || typeof details.unit !== "string" || details.policyVersion !== RESOURCE_POLICY_CONTRACT.policyVersion || details.commercialUpgradeApplicable !== false) return null;
657
- return new ResourcePolicyError({
658
- reason: details.reason,
659
- stage: details.stage,
660
- subject: details.subject,
661
- limit: details.limit,
662
- observed: details.observed,
663
- unit: details.unit,
664
- policyVersion: details.policyVersion,
665
- commercialUpgradeApplicable: false
506
+ function checkBrowserInput(e, t = "PPTX input") {
507
+ e > C.inputBytes && fail("resource_input_too_large", "input", t, C.inputBytes, e, "bytes");
508
+ }
509
+ function checkBrowserOutput(e, t = "output") {
510
+ e > C.outputBytes && fail("resource_output_too_large", "output", t, C.outputBytes, e, "bytes");
511
+ }
512
+ function checkBrowserElapsed(e, t = "parse wall clock") {
513
+ checkBrowserElapsedMs(Math.max(0, Math.ceil(performance.now() - e)), t);
514
+ }
515
+ function checkBrowserElapsedMs(e, t = "parse wall clock") {
516
+ e > C.wallClockMs && fail("resource_timeout", "runtime", t, C.wallClockMs, e, "milliseconds");
517
+ }
518
+ function isResourcePolicyError(e) {
519
+ return e instanceof ResourcePolicyError;
520
+ }
521
+ function resourcePolicyErrorFromDetails(e) {
522
+ if (!e || typeof e != "object") return null;
523
+ let t = e;
524
+ return typeof t.reason != "string" || !S.stableReasons.includes(t.reason) || typeof t.stage != "string" || typeof t.subject != "string" || !Number.isSafeInteger(t.limit) || (t.limit ?? -1) < 0 || !Number.isSafeInteger(t.observed) || (t.observed ?? -1) < 0 || typeof t.unit != "string" || t.policyVersion !== S.policyVersion || t.commercialUpgradeApplicable !== !1 ? null : new ResourcePolicyError({
525
+ reason: t.reason,
526
+ stage: t.stage,
527
+ subject: t.subject,
528
+ limit: t.limit,
529
+ observed: t.observed,
530
+ unit: t.unit,
531
+ policyVersion: t.policyVersion,
532
+ commercialUpgradeApplicable: !1
666
533
  });
667
534
  }
668
- function checkBrowserZipEntries(entries) {
669
- if (entries.length > BROWSER_RESOURCE_LIMITS.zipEntries) fail("resource_zip_entries_exceeded", "zip", "ZIP entry count", BROWSER_RESOURCE_LIMITS.zipEntries, entries.length, "entries");
670
- let expandedTotal = 0;
671
- for (const entry of entries) {
672
- const expanded = Math.max(0, entry.originalSize);
673
- const compressed = Math.max(0, entry.size);
674
- if (expanded > BROWSER_RESOURCE_LIMITS.zipEntryBytes) fail("resource_zip_entry_too_large", "zip", entry.name, BROWSER_RESOURCE_LIMITS.zipEntryBytes, expanded, "bytes");
675
- expandedTotal = Math.min(Number.MAX_SAFE_INTEGER, expandedTotal + expanded);
676
- if (expandedTotal > BROWSER_RESOURCE_LIMITS.zipExpansionBytes) fail("resource_zip_expansion_exceeded", "zip", `cumulative ZIP expansion at ${entry.name}`, BROWSER_RESOURCE_LIMITS.zipExpansionBytes, expandedTotal, "bytes");
677
- if (expanded > BROWSER_RESOURCE_LIMITS.zipRatioThresholdBytes && (compressed <= 0 || expanded / compressed > BROWSER_RESOURCE_LIMITS.zipRatioMax)) fail("resource_zip_ratio_exceeded", "zip", entry.name, BROWSER_RESOURCE_LIMITS.zipRatioMax, compressed <= 0 ? expanded : Math.ceil(expanded / compressed), "ratio");
535
+ function checkBrowserZipEntries(e) {
536
+ e.length > C.zipEntries && fail("resource_zip_entries_exceeded", "zip", "ZIP entry count", C.zipEntries, e.length, "entries");
537
+ let t = 0;
538
+ for (let n of e) {
539
+ let e = Math.max(0, n.originalSize), r = Math.max(0, n.size);
540
+ e > C.zipEntryBytes && fail("resource_zip_entry_too_large", "zip", n.name, C.zipEntryBytes, e, "bytes"), t = Math.min(2 ** 53 - 1, t + e), t > C.zipExpansionBytes && fail("resource_zip_expansion_exceeded", "zip", `cumulative ZIP expansion at ${n.name}`, C.zipExpansionBytes, t, "bytes"), e > C.zipRatioThresholdBytes && (r <= 0 || e / r > C.zipRatioMax) && fail("resource_zip_ratio_exceeded", "zip", n.name, C.zipRatioMax, r <= 0 ? e : Math.ceil(e / r), "ratio");
678
541
  }
679
542
  }
680
- /**
681
- * Decompress a browser PPTX only after fflate exposes each central-directory
682
- * record to the policy filter. XML and image checks run before any parser or
683
- * renderer consumes the expanded payloads.
684
- */
685
- function unzipBrowserPptx(data) {
686
- const input = data instanceof Uint8Array ? data : new Uint8Array(data);
687
- checkBrowserInput(input.byteLength);
688
- const entries = [];
689
- unzipSync(input, { filter(info) {
690
- entries.push(info);
691
- return false;
692
- } });
693
- checkBrowserZipEntries(entries);
694
- const files = unzipSync(input);
695
- checkBrowserXmlParts(Object.entries(files));
696
- for (const [name, bytes] of Object.entries(files)) checkBrowserImagePayload(bytes, name);
697
- return files;
543
+ function unzipBrowserPptx(e) {
544
+ let t = e instanceof Uint8Array ? e : new Uint8Array(e);
545
+ checkBrowserInput(t.byteLength);
546
+ let n = [];
547
+ unzipSync(t, { filter(e) {
548
+ return n.push(e), !1;
549
+ } }), checkBrowserZipEntries(n);
550
+ let r = unzipSync(t);
551
+ checkBrowserXmlParts(Object.entries(r));
552
+ for (let [e, t] of Object.entries(r)) checkBrowserImagePayload(t, e);
553
+ return r;
698
554
  }
699
555
  var XmlBudget = class {
700
556
  constructor() {
701
557
  this.nodes = 0;
702
558
  }
703
- observeNode(depth, subject) {
704
- if (depth > BROWSER_RESOURCE_LIMITS.xmlDepth) fail("resource_xml_depth_exceeded", "xml", subject, BROWSER_RESOURCE_LIMITS.xmlDepth, depth, "levels");
705
- this.nodes += 1;
706
- if (this.nodes > BROWSER_RESOURCE_LIMITS.xmlNodes) fail("resource_xml_nodes_exceeded", "xml", subject, BROWSER_RESOURCE_LIMITS.xmlNodes, this.nodes, "nodes");
559
+ observeNode(e, t) {
560
+ e > C.xmlDepth && fail("resource_xml_depth_exceeded", "xml", t, C.xmlDepth, e, "levels"), this.nodes += 1, this.nodes > C.xmlNodes && fail("resource_xml_nodes_exceeded", "xml", t, C.xmlNodes, this.nodes, "nodes");
707
561
  }
708
- observeText(depth, bytes, subject) {
709
- this.observeNode(depth, subject);
710
- if (bytes > BROWSER_RESOURCE_LIMITS.textNodeBytes) fail("resource_text_node_too_large", "xml", subject, BROWSER_RESOURCE_LIMITS.textNodeBytes, bytes, "bytes");
562
+ observeText(e, t, n) {
563
+ this.observeNode(e, n), t > C.textNodeBytes && fail("resource_text_node_too_large", "xml", n, C.textNodeBytes, t, "bytes");
711
564
  }
712
565
  };
713
- function isXmlPart(name) {
714
- const normalized = name.toLowerCase();
715
- return normalized.endsWith(".xml") || normalized.endsWith(".rels") || normalized.endsWith(".svg") || normalized.endsWith(".vml");
716
- }
717
- function looksLikeXmlPayload(input) {
718
- let position = input.length >= 3 && input[0] === 239 && input[1] === 187 && input[2] === 191 ? 3 : 0;
719
- while (position < input.length && isSpace(input[position])) position += 1;
720
- if (position + 1 >= input.length || input[position] !== 60) return false;
721
- const next = input[position + 1];
722
- return next === 63 || next === 33 || next === 95 || next === 58 || next >= 65 && next <= 90 || next >= 97 && next <= 122 || next >= 128;
723
- }
724
- function checkBrowserXmlParts(parts) {
725
- const budget = new XmlBudget();
726
- for (const [name, bytes] of parts) if (isXmlPart(name) || looksLikeXmlPayload(bytes)) scanXml(bytes, budget, name);
727
- }
728
- const ascii = (value) => new TextEncoder().encode(value);
729
- const COMMENT = ascii("<!--");
730
- const COMMENT_END = ascii("-->");
731
- const CDATA = ascii("<![CDATA[");
732
- const CDATA_END = ascii("]]>");
733
- const PROCESSING = ascii("<?");
734
- const PROCESSING_END = ascii("?>");
735
- const DOCTYPE_UPPER = ascii("<!DOCTYPE");
736
- const DOCTYPE_LOWER = ascii("<!doctype");
737
- function matchesAt(input, start, expected) {
738
- if (start < 0 || start + expected.length > input.length) return false;
739
- for (let index = 0; index < expected.length; index += 1) if (input[start + index] !== expected[index]) return false;
740
- return true;
741
- }
742
- function findTerminator(input, start, expected) {
743
- const last = input.length - expected.length;
744
- for (let index = start; index <= last; index += 1) if (matchesAt(input, index, expected)) return index;
745
- return input.length;
746
- }
747
- function findTagEnd(input, start) {
748
- let quote = 0;
749
- for (let index = start; index < input.length; index += 1) {
750
- const value = input[index];
751
- if (quote !== 0) {
752
- if (value === quote) quote = 0;
753
- } else if (value === 34 || value === 39) quote = value;
754
- else if (value === 62) return index + 1;
566
+ function isXmlPart(e) {
567
+ let t = e.toLowerCase();
568
+ return t.endsWith(".xml") || t.endsWith(".rels") || t.endsWith(".svg") || t.endsWith(".vml");
569
+ }
570
+ function looksLikeXmlPayload(e) {
571
+ let t = e.length >= 3 && e[0] === 239 && e[1] === 187 && e[2] === 191 ? 3 : 0;
572
+ for (; t < e.length && isSpace(e[t]);) t += 1;
573
+ if (t + 1 >= e.length || e[t] !== 60) return !1;
574
+ let n = e[t + 1];
575
+ return n === 63 || n === 33 || n === 95 || n === 58 || n >= 65 && n <= 90 || n >= 97 && n <= 122 || n >= 128;
576
+ }
577
+ function checkBrowserXmlParts(e) {
578
+ let t = new XmlBudget();
579
+ for (let [n, r] of e) (isXmlPart(n) || looksLikeXmlPayload(r)) && scanXml(r, t, n);
580
+ }
581
+ const ascii = (e) => new TextEncoder().encode(e), w = ascii("<!--"), T = ascii("-->"), E = ascii("<![CDATA["), D = ascii("]]>"), O = ascii("<?"), k = ascii("?>"), A = ascii("<!DOCTYPE"), j = ascii("<!doctype");
582
+ function matchesAt(e, t, n) {
583
+ if (t < 0 || t + n.length > e.length) return !1;
584
+ for (let r = 0; r < n.length; r += 1) if (e[t + r] !== n[r]) return !1;
585
+ return !0;
586
+ }
587
+ function findTerminator(e, t, n) {
588
+ let r = e.length - n.length;
589
+ for (let i = t; i <= r; i += 1) if (matchesAt(e, i, n)) return i;
590
+ return e.length;
591
+ }
592
+ function findTagEnd(e, t) {
593
+ let n = 0;
594
+ for (let r = t; r < e.length; r += 1) {
595
+ let t = e[r];
596
+ if (n !== 0) t === n && (n = 0);
597
+ else if (t === 34 || t === 39) n = t;
598
+ else if (t === 62) return r + 1;
755
599
  }
756
- return input.length;
757
- }
758
- function skipDoctype(input, start) {
759
- let quote = 0;
760
- let subsetDepth = 0;
761
- for (let index = start; index < input.length; index += 1) {
762
- const value = input[index];
763
- if (quote !== 0) {
764
- if (value === quote) quote = 0;
765
- } else if (value === 34 || value === 39) quote = value;
766
- else if (value === 91) subsetDepth += 1;
767
- else if (value === 93 && subsetDepth > 0) subsetDepth -= 1;
768
- else if (value === 62 && subsetDepth === 0) return index + 1;
600
+ return e.length;
601
+ }
602
+ function skipDoctype(e, t) {
603
+ let n = 0, r = 0;
604
+ for (let i = t; i < e.length; i += 1) {
605
+ let t = e[i];
606
+ if (n !== 0) t === n && (n = 0);
607
+ else if (t === 34 || t === 39) n = t;
608
+ else if (t === 91) r += 1;
609
+ else if (t === 93 && r > 0) --r;
610
+ else if (t === 62 && r === 0) return i + 1;
769
611
  }
770
- return input.length;
771
- }
772
- function isSpace(value) {
773
- return value === 32 || value === 9 || value === 10 || value === 13;
774
- }
775
- function scanXml(input, budget, subject) {
776
- let position = 0;
777
- let depth = 0;
778
- while (position < input.length) {
779
- if (input[position] !== 60) {
780
- const start = position;
781
- while (position < input.length && input[position] !== 60) position += 1;
782
- if (position > start) budget.observeText(depth, position - start, `${subject} text`);
612
+ return e.length;
613
+ }
614
+ function isSpace(e) {
615
+ return e === 32 || e === 9 || e === 10 || e === 13;
616
+ }
617
+ function scanXml(e, t, n) {
618
+ let r = 0, i = 0;
619
+ for (; r < e.length;) {
620
+ if (e[r] !== 60) {
621
+ let a = r;
622
+ for (; r < e.length && e[r] !== 60;) r += 1;
623
+ r > a && t.observeText(i, r - a, `${n} text`);
783
624
  continue;
784
625
  }
785
- if (matchesAt(input, position, COMMENT)) {
786
- budget.observeNode(depth, `${subject} comment`);
787
- const end = findTerminator(input, position + COMMENT.length, COMMENT_END);
788
- position = end === input.length ? end : end + COMMENT_END.length;
626
+ if (matchesAt(e, r, w)) {
627
+ t.observeNode(i, `${n} comment`);
628
+ let a = findTerminator(e, r + w.length, T);
629
+ r = a === e.length ? a : a + T.length;
789
630
  continue;
790
631
  }
791
- if (matchesAt(input, position, CDATA)) {
792
- const start = position + CDATA.length;
793
- const end = findTerminator(input, start, CDATA_END);
794
- budget.observeText(depth, end - start, `${subject} CDATA`);
795
- position = end === input.length ? end : end + CDATA_END.length;
632
+ if (matchesAt(e, r, E)) {
633
+ let a = r + E.length, o = findTerminator(e, a, D);
634
+ t.observeText(i, o - a, `${n} CDATA`), r = o === e.length ? o : o + D.length;
796
635
  continue;
797
636
  }
798
- if (matchesAt(input, position, PROCESSING)) {
799
- budget.observeNode(depth, `${subject} processing instruction`);
800
- const end = findTerminator(input, position + PROCESSING.length, PROCESSING_END);
801
- position = end === input.length ? end : end + PROCESSING_END.length;
637
+ if (matchesAt(e, r, O)) {
638
+ t.observeNode(i, `${n} processing instruction`);
639
+ let a = findTerminator(e, r + O.length, k);
640
+ r = a === e.length ? a : a + k.length;
802
641
  continue;
803
642
  }
804
- if (matchesAt(input, position, DOCTYPE_UPPER) || matchesAt(input, position, DOCTYPE_LOWER)) {
805
- position = skipDoctype(input, position + 2);
643
+ if (matchesAt(e, r, A) || matchesAt(e, r, j)) {
644
+ r = skipDoctype(e, r + 2);
806
645
  continue;
807
646
  }
808
- if (position + 1 < input.length && input[position + 1] === 47) {
809
- position = findTagEnd(input, position + 2);
810
- if (depth > 0) depth -= 1;
647
+ if (r + 1 < e.length && e[r + 1] === 47) {
648
+ r = findTagEnd(e, r + 2), i > 0 && --i;
811
649
  continue;
812
650
  }
813
- if (position + 1 < input.length && input[position + 1] === 33) {
814
- position = findTagEnd(input, position + 2);
651
+ if (r + 1 < e.length && e[r + 1] === 33) {
652
+ r = findTagEnd(e, r + 2);
815
653
  continue;
816
654
  }
817
- const end = findTagEnd(input, position + 1);
818
- let tail = end - 2;
819
- while (tail > position && isSpace(input[tail])) tail -= 1;
820
- const selfClosing = tail > position && input[tail] === 47;
821
- depth += 1;
822
- budget.observeNode(depth, subject);
823
- if (selfClosing) depth -= 1;
824
- position = end;
655
+ let a = findTagEnd(e, r + 1), o = a - 2;
656
+ for (; o > r && isSpace(e[o]);) --o;
657
+ let s = o > r && e[o] === 47;
658
+ i += 1, t.observeNode(i, n), s && --i, r = a;
825
659
  }
826
660
  }
827
- function readU16BE(data, offset) {
828
- return data[offset] * 256 + data[offset + 1];
661
+ function readU16BE(e, t) {
662
+ return e[t] * 256 + e[t + 1];
829
663
  }
830
- function readU16LE(data, offset) {
831
- return data[offset] + data[offset + 1] * 256;
664
+ function readU16LE(e, t) {
665
+ return e[t] + e[t + 1] * 256;
832
666
  }
833
- function readU24LE(data, offset) {
834
- return data[offset] + data[offset + 1] * 256 + data[offset + 2] * 65536;
667
+ function readU24LE(e, t) {
668
+ return e[t] + e[t + 1] * 256 + e[t + 2] * 65536;
835
669
  }
836
- function readU32BE(data, offset) {
837
- return data[offset] * 16777216 + data[offset + 1] * 65536 + data[offset + 2] * 256 + data[offset + 3];
670
+ function readU32BE(e, t) {
671
+ return e[t] * 16777216 + e[t + 1] * 65536 + e[t + 2] * 256 + e[t + 3];
838
672
  }
839
- function readU32LE(data, offset) {
840
- return data[offset] + data[offset + 1] * 256 + data[offset + 2] * 65536 + data[offset + 3] * 16777216;
673
+ function readU32LE(e, t) {
674
+ return e[t] + e[t + 1] * 256 + e[t + 2] * 65536 + e[t + 3] * 16777216;
841
675
  }
842
- function bytesEqual(data, offset, expected) {
843
- if (offset < 0 || offset + expected.length > data.length) return false;
844
- return expected.every((value, index) => data[offset + index] === value);
676
+ function bytesEqual(e, t, n) {
677
+ return t < 0 || t + n.length > e.length ? !1 : n.every((n, r) => e[t + r] === n);
845
678
  }
846
- function probeImageDimensions(data) {
847
- if (data.length >= 24 && bytesEqual(data, 0, [
679
+ function probeImageDimensions(e) {
680
+ if (e.length >= 24 && bytesEqual(e, 0, [
848
681
  137,
849
682
  80,
850
683
  78,
@@ -853,23 +686,23 @@ function probeImageDimensions(data) {
853
686
  10,
854
687
  26,
855
688
  10
856
- ]) && bytesEqual(data, 12, [
689
+ ]) && bytesEqual(e, 12, [
857
690
  73,
858
691
  72,
859
692
  68,
860
693
  82
861
694
  ])) return {
862
- width: readU32BE(data, 16),
863
- height: readU32BE(data, 20)
695
+ width: readU32BE(e, 16),
696
+ height: readU32BE(e, 20)
864
697
  };
865
- if (data.length >= 10 && (bytesEqual(data, 0, [
698
+ if (e.length >= 10 && (bytesEqual(e, 0, [
866
699
  71,
867
700
  73,
868
701
  70,
869
702
  56,
870
703
  55,
871
704
  97
872
- ]) || bytesEqual(data, 0, [
705
+ ]) || bytesEqual(e, 0, [
873
706
  71,
874
707
  73,
875
708
  70,
@@ -877,380 +710,334 @@ function probeImageDimensions(data) {
877
710
  57,
878
711
  97
879
712
  ]))) return {
880
- width: readU16LE(data, 6),
881
- height: readU16LE(data, 8)
713
+ width: readU16LE(e, 6),
714
+ height: readU16LE(e, 8)
882
715
  };
883
- if (data.length >= 26 && bytesEqual(data, 0, [66, 77])) {
884
- const dib = readU32LE(data, 14);
885
- if (dib === 12) return {
886
- width: readU16LE(data, 18),
887
- height: readU16LE(data, 20)
716
+ if (e.length >= 26 && bytesEqual(e, 0, [66, 77])) {
717
+ let t = readU32LE(e, 14);
718
+ if (t === 12) return {
719
+ width: readU16LE(e, 18),
720
+ height: readU16LE(e, 20)
888
721
  };
889
- if (dib >= 40) {
890
- const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
722
+ if (t >= 40) {
723
+ let t = new DataView(e.buffer, e.byteOffset, e.byteLength);
891
724
  return {
892
- width: Math.abs(view.getInt32(18, true)),
893
- height: Math.abs(view.getInt32(22, true))
725
+ width: Math.abs(t.getInt32(18, !0)),
726
+ height: Math.abs(t.getInt32(22, !0))
894
727
  };
895
728
  }
896
729
  }
897
- if (data.length >= 30 && bytesEqual(data, 0, [
730
+ if (e.length >= 30 && bytesEqual(e, 0, [
898
731
  82,
899
732
  73,
900
733
  70,
901
734
  70
902
- ]) && bytesEqual(data, 8, [
735
+ ]) && bytesEqual(e, 8, [
903
736
  87,
904
737
  69,
905
738
  66,
906
739
  80
907
740
  ])) {
908
- if (bytesEqual(data, 12, [
741
+ if (bytesEqual(e, 12, [
909
742
  86,
910
743
  80,
911
744
  56,
912
745
  88
913
746
  ])) return {
914
- width: 1 + readU24LE(data, 24),
915
- height: 1 + readU24LE(data, 27)
747
+ width: 1 + readU24LE(e, 24),
748
+ height: 1 + readU24LE(e, 27)
916
749
  };
917
- if (bytesEqual(data, 12, [
750
+ if (bytesEqual(e, 12, [
918
751
  86,
919
752
  80,
920
753
  56,
921
754
  76
922
- ]) && data[20] === 47) return {
923
- width: 1 + (data[21] | (data[22] & 63) << 8),
924
- height: 1 + (data[22] >> 6 | data[23] << 2 | (data[24] & 15) << 10)
755
+ ]) && e[20] === 47) return {
756
+ width: 1 + (e[21] | (e[22] & 63) << 8),
757
+ height: 1 + (e[22] >> 6 | e[23] << 2 | (e[24] & 15) << 10)
925
758
  };
926
- if (bytesEqual(data, 12, [
759
+ if (bytesEqual(e, 12, [
927
760
  86,
928
761
  80,
929
762
  56,
930
763
  32
931
- ]) && bytesEqual(data, 23, [
764
+ ]) && bytesEqual(e, 23, [
932
765
  157,
933
766
  1,
934
767
  42
935
768
  ])) return {
936
- width: (data[26] | data[27] << 8) & 16383,
937
- height: (data[28] | data[29] << 8) & 16383
769
+ width: (e[26] | e[27] << 8) & 16383,
770
+ height: (e[28] | e[29] << 8) & 16383
938
771
  };
939
772
  }
940
- if (data.length >= 4 && data[0] === 255 && data[1] === 216) {
941
- let position = 2;
942
- while (position + 3 < data.length) {
943
- while (position < data.length && data[position] !== 255) position += 1;
944
- while (position < data.length && data[position] === 255) position += 1;
945
- if (position >= data.length) break;
946
- const marker = data[position];
947
- position += 1;
948
- if (marker === 1 || marker === 216 || marker === 217 || marker >= 208 && marker <= 215) continue;
949
- if (position + 1 >= data.length) break;
950
- const length = readU16BE(data, position);
951
- if (length < 2 || position + length > data.length) break;
952
- if ((marker >= 192 && marker <= 195 || marker >= 197 && marker <= 199 || marker >= 201 && marker <= 203 || marker >= 205 && marker <= 207) && length >= 7) return {
953
- width: readU16BE(data, position + 5),
954
- height: readU16BE(data, position + 3)
773
+ if (e.length >= 4 && e[0] === 255 && e[1] === 216) {
774
+ let t = 2;
775
+ for (; t + 3 < e.length;) {
776
+ for (; t < e.length && e[t] !== 255;) t += 1;
777
+ for (; t < e.length && e[t] === 255;) t += 1;
778
+ if (t >= e.length) break;
779
+ let n = e[t];
780
+ if (t += 1, n === 1 || n === 216 || n === 217 || n >= 208 && n <= 215) continue;
781
+ if (t + 1 >= e.length) break;
782
+ let r = readU16BE(e, t);
783
+ if (r < 2 || t + r > e.length) break;
784
+ if ((n >= 192 && n <= 195 || n >= 197 && n <= 199 || n >= 201 && n <= 203 || n >= 205 && n <= 207) && r >= 7) return {
785
+ width: readU16BE(e, t + 5),
786
+ height: readU16BE(e, t + 3)
955
787
  };
956
- position += length;
788
+ t += r;
957
789
  }
958
790
  }
959
- return probeTiff(data);
791
+ return probeTiff(e);
960
792
  }
961
- function checkBrowserImagePayload(data, subject = "image") {
962
- const dimensions = probeImageDimensions(data);
963
- if (dimensions) checkImageDimensions(dimensions.width, dimensions.height, subject);
793
+ function checkBrowserImagePayload(e, t = "image") {
794
+ let n = probeImageDimensions(e);
795
+ n && checkImageDimensions(n.width, n.height, t);
964
796
  }
965
- function probeTiff(data) {
966
- if (data.length < 8) return null;
967
- const little = bytesEqual(data, 0, [
797
+ function probeTiff(e) {
798
+ if (e.length < 8) return null;
799
+ let t = bytesEqual(e, 0, [
968
800
  73,
969
801
  73,
970
802
  42,
971
803
  0
972
804
  ]);
973
- if (!little && !bytesEqual(data, 0, [
805
+ if (!t && !bytesEqual(e, 0, [
974
806
  77,
975
807
  77,
976
808
  0,
977
809
  42
978
810
  ])) return null;
979
- const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
980
- const offset = view.getUint32(4, little);
981
- if (offset + 2 > data.length) return null;
982
- const count = view.getUint16(offset, little);
983
- let width = null;
984
- let height = null;
985
- for (let index = 0; index < count; index += 1) {
986
- const entry = offset + 2 + index * 12;
987
- if (entry + 12 > data.length) return null;
988
- const tag = view.getUint16(entry, little);
989
- if ((tag === 256 || tag === 257) && view.getUint32(entry + 4, little) === 1) {
990
- const type = view.getUint16(entry + 2, little);
991
- const value = type === 3 ? view.getUint16(entry + 8, little) : type === 4 ? view.getUint32(entry + 8, little) : 0;
992
- if (tag === 256) width = value;
993
- else height = value;
811
+ let n = new DataView(e.buffer, e.byteOffset, e.byteLength), r = n.getUint32(4, t);
812
+ if (r + 2 > e.length) return null;
813
+ let i = n.getUint16(r, t), a = null, o = null;
814
+ for (let s = 0; s < i; s += 1) {
815
+ let i = r + 2 + s * 12;
816
+ if (i + 12 > e.length) return null;
817
+ let c = n.getUint16(i, t);
818
+ if ((c === 256 || c === 257) && n.getUint32(i + 4, t) === 1) {
819
+ let e = n.getUint16(i + 2, t), r = e === 3 ? n.getUint16(i + 8, t) : e === 4 ? n.getUint32(i + 8, t) : 0;
820
+ c === 256 ? a = r : o = r;
994
821
  }
995
822
  }
996
- return width && height ? {
997
- width,
998
- height
823
+ return a && o ? {
824
+ width: a,
825
+ height: o
999
826
  } : null;
1000
827
  }
1001
- function checkImageDimensions(width, height, subject) {
1002
- if (width <= 0 || height <= 0) return;
1003
- const observed = width * height;
1004
- if (!Number.isSafeInteger(observed) || observed > BROWSER_RESOURCE_LIMITS.imagePixels) fail("resource_image_pixels_exceeded", "image", subject, BROWSER_RESOURCE_LIMITS.imagePixels, Number.isSafeInteger(observed) ? observed : Number.MAX_SAFE_INTEGER, "pixels");
828
+ function checkImageDimensions(e, t, n) {
829
+ if (e <= 0 || t <= 0) return;
830
+ let r = e * t;
831
+ (!Number.isSafeInteger(r) || r > C.imagePixels) && fail("resource_image_pixels_exceeded", "image", n, C.imagePixels, Number.isSafeInteger(r) ? r : 2 ** 53 - 1, "pixels");
1005
832
  }
1006
833
  //#endregion
1007
834
  //#region src/worker-error.ts
1008
- function property(value, key) {
835
+ function property(e, t) {
1009
836
  try {
1010
- return value && typeof value === "object" ? value[key] : void 0;
837
+ return e && typeof e == "object" ? e[t] : void 0;
1011
838
  } catch {
1012
839
  return;
1013
840
  }
1014
841
  }
1015
- function cloneFact(value) {
842
+ function cloneFact(e) {
1016
843
  try {
1017
- return structuredClone(value);
844
+ return structuredClone(e);
1018
845
  } catch {
1019
846
  return;
1020
847
  }
1021
848
  }
1022
- function serializeWorkerError(error, seen = /* @__PURE__ */ new Map()) {
1023
- const previous = seen.get(error);
1024
- if (previous) return previous;
1025
- const name = property(error, "name");
1026
- const message = property(error, "message");
1027
- let fallback = "Worker operation failed";
1028
- if (typeof message !== "string") try {
1029
- fallback = String(error);
849
+ function serializeWorkerError(e, t = /* @__PURE__ */ new Map()) {
850
+ let n = t.get(e);
851
+ if (n) return n;
852
+ let r = property(e, "name"), i = property(e, "message"), a = "Worker operation failed";
853
+ if (typeof i != "string") try {
854
+ a = String(e);
1030
855
  } catch {}
1031
- const result = {
1032
- name: typeof name === "string" ? name : "Error",
1033
- message: typeof message === "string" ? message : fallback
856
+ let o = {
857
+ name: typeof r == "string" ? r : "Error",
858
+ message: typeof i == "string" ? i : a
1034
859
  };
1035
- seen.set(error, result);
1036
- const code = property(error, "code");
1037
- if (typeof code === "string" || typeof code === "number") result.code = code;
1038
- const details = cloneFact(property(error, "details"));
1039
- if (details !== void 0) result.details = details;
1040
- const cause = property(error, "cause");
1041
- if (cause !== void 0) {
1042
- if (cause instanceof Error || typeof property(cause, "message") === "string") result.cause = {
860
+ t.set(e, o);
861
+ let s = property(e, "code");
862
+ (typeof s == "string" || typeof s == "number") && (o.code = s);
863
+ let c = cloneFact(property(e, "details"));
864
+ c !== void 0 && (o.details = c);
865
+ let l = property(e, "cause");
866
+ if (l !== void 0) {
867
+ if (l instanceof Error || typeof property(l, "message") == "string") o.cause = {
1043
868
  kind: "error",
1044
- error: serializeWorkerError(cause, seen)
869
+ error: serializeWorkerError(l, t)
1045
870
  };
1046
871
  else {
1047
- const value = cloneFact(cause);
1048
- if (value !== void 0) result.cause = {
872
+ let e = cloneFact(l);
873
+ e !== void 0 && (o.cause = {
1049
874
  kind: "value",
1050
- value
1051
- };
875
+ value: e
876
+ });
1052
877
  }
1053
878
  }
1054
- return result;
879
+ return o;
1055
880
  }
1056
- //#endregion
1057
- //#region src/pdf-converter.ts
1058
- const officeFontFallbacksBridgeTypeface = "__xdoc_office_font_fallbacks__";
1059
- const PDF_EMOJI_FALLBACK_TYPEFACE = "__pdf_emoji_fallback__";
1060
- const PDF_BRIDGE_WORD_BYTES = 4;
1061
- let pdfWasmSource = null;
1062
- let pdfWasmInstance = null;
1063
- let pdfWasmLoadSource = null;
1064
- let pdfWasmLoadPromise = null;
1065
- const conversionTailsByInstance = /* @__PURE__ */ new WeakMap();
1066
- let unicodeFallbackFontCacheKey = null;
1067
- let unicodeFallbackFontPromise = null;
1068
- let emojiFallbackFontCacheKey = null;
1069
- let emojiFallbackFontPromise = null;
881
+ let M = null, N = null, P = null, F = null;
882
+ const I = /* @__PURE__ */ new WeakMap();
883
+ let L = null, R = null, z = null, B = null;
1070
884
  function createPdfWasmImports() {
1071
885
  return {
1072
886
  __moonbit_time_unstable: { now: () => BigInt(Date.now()) },
1073
- console: { log: (...args) => {
1074
- console.log(...args);
887
+ console: { log: (...e) => {
888
+ console.log(...e);
1075
889
  } }
1076
890
  };
1077
891
  }
1078
- function bytesToArrayBuffer(bytes) {
1079
- return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
892
+ function bytesToArrayBuffer(e) {
893
+ return e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
1080
894
  }
1081
- function hasBufferedPdfBridge(mod) {
1082
- return typeof mod.reset_pdf_bridge_input === "function" && typeof mod.push_pdf_bridge_input_word === "function" && typeof mod.register_pdf_font_buffered === "function" && typeof mod.register_pdf_emoji_bitmap_buffered === "function" && typeof mod.register_pdf_math_fallback_buffered === "function" && typeof mod.set_pdf_office_font_fallbacks === "function" && typeof mod.run_pdf_conversion_buffered === "function" && typeof mod.pdf_bridge_output_len === "function" && typeof mod.pdf_bridge_output_word === "function" && typeof mod.clear_pdf_bridge_output === "function";
895
+ function hasBufferedPdfBridge(e) {
896
+ return typeof e.reset_pdf_bridge_input == "function" && typeof e.push_pdf_bridge_input_word == "function" && typeof e.register_pdf_font_buffered == "function" && typeof e.register_pdf_emoji_bitmap_buffered == "function" && typeof e.register_pdf_math_fallback_buffered == "function" && typeof e.set_pdf_office_font_fallbacks == "function" && typeof e.run_pdf_conversion_buffered == "function" && typeof e.pdf_bridge_output_len == "function" && typeof e.pdf_bridge_output_word == "function" && typeof e.clear_pdf_bridge_output == "function";
1083
897
  }
1084
- function assertPdfWasmApi(mod) {
1085
- if (!hasBufferedPdfBridge(mod) && typeof mod.convert_pptx_to_pdf_from_string !== "function") throw new Error("PDF converter WASM does not expose a supported host bridge");
898
+ function assertPdfWasmApi(e) {
899
+ if (!hasBufferedPdfBridge(e) && typeof e.convert_pptx_to_pdf_from_string != "function") throw Error("PDF converter WASM does not expose a supported host bridge");
1086
900
  }
1087
- function utf8Bytes(value) {
1088
- return new TextEncoder().encode(value);
901
+ function utf8Bytes(e) {
902
+ return new TextEncoder().encode(e);
1089
903
  }
1090
- function writePdfBridgeInput(mod, chunks) {
1091
- mod.reset_pdf_bridge_input();
1092
- let written = 0;
1093
- for (const chunk of chunks) for (let offset = 0; offset < chunk.byteLength; offset += PDF_BRIDGE_WORD_BYTES) {
1094
- const byteCount = Math.min(PDF_BRIDGE_WORD_BYTES, chunk.byteLength - offset);
1095
- let word = 0;
1096
- for (let index = 0; index < byteCount; index += 1) word |= (chunk[offset + index] ?? 0) << index * 8;
1097
- written += byteCount;
1098
- if (mod.push_pdf_bridge_input_word(word, byteCount) !== written) throw new Error("PDF converter WASM rejected buffered input");
904
+ function writePdfBridgeInput(e, t) {
905
+ e.reset_pdf_bridge_input();
906
+ let n = 0;
907
+ for (let r of t) for (let t = 0; t < r.byteLength; t += 4) {
908
+ let i = Math.min(4, r.byteLength - t), a = 0;
909
+ for (let e = 0; e < i; e += 1) a |= (r[t + e] ?? 0) << e * 8;
910
+ if (n += i, e.push_pdf_bridge_input_word(a, i) !== n) throw Error("PDF converter WASM rejected buffered input");
1099
911
  }
1100
912
  }
1101
- function readPdfBridgeOutput(mod, reportedLength) {
913
+ function readPdfBridgeOutput(e, t) {
1102
914
  try {
1103
- const length = mod.pdf_bridge_output_len();
1104
- if (!Number.isSafeInteger(length) || length !== reportedLength || length < 0) throw new Error("PDF converter WASM returned an invalid buffered output length");
1105
- checkBrowserOutput(length, "PDF output");
1106
- const output = new Uint8Array(length);
1107
- for (let offset = 0; offset < length; offset += PDF_BRIDGE_WORD_BYTES) {
1108
- const word = mod.pdf_bridge_output_word(offset / PDF_BRIDGE_WORD_BYTES);
1109
- if (!Number.isInteger(word)) throw new Error("PDF converter WASM returned an invalid buffered output word");
1110
- for (let index = 0; index < PDF_BRIDGE_WORD_BYTES && offset + index < length; index += 1) output[offset + index] = word >>> index * 8 & 255;
915
+ let n = e.pdf_bridge_output_len();
916
+ if (!Number.isSafeInteger(n) || n !== t || n < 0) throw Error("PDF converter WASM returned an invalid buffered output length");
917
+ checkBrowserOutput(n, "PDF output");
918
+ let r = new Uint8Array(n);
919
+ for (let t = 0; t < n; t += 4) {
920
+ let i = e.pdf_bridge_output_word(t / 4);
921
+ if (!Number.isInteger(i)) throw Error("PDF converter WASM returned an invalid buffered output word");
922
+ for (let e = 0; e < 4 && t + e < n; e += 1) r[t + e] = i >>> e * 8 & 255;
1111
923
  }
1112
- return output;
924
+ return r;
1113
925
  } finally {
1114
- mod.clear_pdf_bridge_output();
926
+ e.clear_pdf_bridge_output();
1115
927
  }
1116
928
  }
1117
- function decodeXmlEntities(str) {
1118
- if (!str.includes("&")) return str;
1119
- return str.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, "\"").replace(/&apos;/g, "'").replace(/&#x([0-9a-fA-F]+);/g, (_, hex) => String.fromCodePoint(parseInt(hex, 16))).replace(/&#(\d+);/g, (_, dec) => String.fromCodePoint(parseInt(dec, 10))).replace(/&amp;/g, "&");
929
+ function decodeXmlEntities(e) {
930
+ return e.includes("&") ? e.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, "\"").replace(/&apos;/g, "'").replace(/&#x([0-9a-fA-F]+);/g, (e, t) => String.fromCodePoint(parseInt(t, 16))).replace(/&#(\d+);/g, (e, t) => String.fromCodePoint(parseInt(t, 10))).replace(/&amp;/g, "&") : e;
1120
931
  }
1121
- function containsNonLatinCodepoint(text) {
1122
- for (const char of text) if ((char.codePointAt(0) ?? 0) > 255) return true;
1123
- return false;
932
+ function containsNonLatinCodepoint(e) {
933
+ for (let t of e) if ((t.codePointAt(0) ?? 0) > 255) return !0;
934
+ return !1;
1124
935
  }
1125
- function isDefaultEmojiPresentationCodepoint(codepoint) {
1126
- return codepoint >= 126976 && codepoint <= 129791 || codepoint === 169 || codepoint === 174 || codepoint === 8252 || codepoint === 8265 || codepoint === 8482 || codepoint === 8505 || codepoint === 8986 || codepoint === 8987 || codepoint === 9167 || codepoint >= 9193 && codepoint <= 9199 || codepoint === 9200 || codepoint === 9203 || codepoint >= 9208 && codepoint <= 9210 || codepoint === 9410 || codepoint >= 9725 && codepoint <= 9726 || codepoint >= 9748 && codepoint <= 9749 || codepoint >= 9800 && codepoint <= 9811 || codepoint === 9855 || codepoint === 9875 || codepoint === 9889 || codepoint >= 9898 && codepoint <= 9899 || codepoint >= 9917 && codepoint <= 9918 || codepoint >= 9924 && codepoint <= 9925 || codepoint === 9934 || codepoint === 9940 || codepoint === 9962 || codepoint >= 9970 && codepoint <= 9971 || codepoint === 9973 || codepoint === 9978 || codepoint === 9981 || codepoint === 9989 || codepoint >= 9994 && codepoint <= 9995 || codepoint === 10024 || codepoint === 10060 || codepoint === 10062 || codepoint >= 10067 && codepoint <= 10069 || codepoint === 10071 || codepoint >= 10133 && codepoint <= 10135 || codepoint === 10160 || codepoint === 10175 || codepoint >= 10548 && codepoint <= 10549 || codepoint >= 11013 && codepoint <= 11015 || codepoint >= 11035 && codepoint <= 11036 || codepoint === 11088 || codepoint === 11093 || codepoint === 12336 || codepoint === 12349 || codepoint === 12951 || codepoint === 12953;
936
+ function isDefaultEmojiPresentationCodepoint(e) {
937
+ return e >= 126976 && e <= 129791 || e === 169 || e === 174 || e === 8252 || e === 8265 || e === 8482 || e === 8505 || e === 8986 || e === 8987 || e === 9167 || e >= 9193 && e <= 9199 || e === 9200 || e === 9203 || e >= 9208 && e <= 9210 || e === 9410 || e >= 9725 && e <= 9726 || e >= 9748 && e <= 9749 || e >= 9800 && e <= 9811 || e === 9855 || e === 9875 || e === 9889 || e >= 9898 && e <= 9899 || e >= 9917 && e <= 9918 || e >= 9924 && e <= 9925 || e === 9934 || e === 9940 || e === 9962 || e >= 9970 && e <= 9971 || e === 9973 || e === 9978 || e === 9981 || e === 9989 || e >= 9994 && e <= 9995 || e === 10024 || e === 10060 || e === 10062 || e >= 10067 && e <= 10069 || e === 10071 || e >= 10133 && e <= 10135 || e === 10160 || e === 10175 || e >= 10548 && e <= 10549 || e >= 11013 && e <= 11015 || e >= 11035 && e <= 11036 || e === 11088 || e === 11093 || e === 12336 || e === 12349 || e === 12951 || e === 12953;
1127
938
  }
1128
- function codepointHasExplicitEmojiPresentation(text, index) {
1129
- const codepoint = text.codePointAt(index) ?? 0;
1130
- return (text.codePointAt(index + (codepoint > 65535 ? 2 : 1)) ?? 0) === 65039;
939
+ function codepointHasExplicitEmojiPresentation(e, t) {
940
+ let n = e.codePointAt(t) ?? 0;
941
+ return (e.codePointAt(t + (n > 65535 ? 2 : 1)) ?? 0) === 65039;
1131
942
  }
1132
- function collectEmojiBitmapFallbackCodepoints(buffer) {
1133
- const codepoints = /* @__PURE__ */ new Set();
943
+ function collectEmojiBitmapFallbackCodepoints(e) {
944
+ let t = /* @__PURE__ */ new Set();
1134
945
  try {
1135
- const files = unzipBrowserPptx(buffer);
1136
- const decoder = new TextDecoder();
1137
- const textRegex = /<a:t(?:\s[^>]*)?>([\s\S]*?)<\/a:t>/gu;
1138
- for (const [filename, bytes] of Object.entries(files)) {
1139
- if (!filename.endsWith(".xml")) continue;
1140
- if (!filename.startsWith("ppt/slides/") && !filename.startsWith("ppt/slideLayouts/") && !filename.startsWith("ppt/notesSlides/")) continue;
1141
- const xml = decoder.decode(bytes);
1142
- for (const match of xml.matchAll(textRegex)) {
1143
- const text = decodeXmlEntities(match[1] ?? "");
1144
- for (let i = 0; i < text.length; i += 1) {
1145
- const codepoint = text.codePointAt(i) ?? 0;
1146
- if (isDefaultEmojiPresentationCodepoint(codepoint) || codepointHasExplicitEmojiPresentation(text, i)) codepoints.add(codepoint);
1147
- if (codepoint > 65535) i += 1;
946
+ let n = unzipBrowserPptx(e), r = new TextDecoder(), i = /<a:t(?:\s[^>]*)?>([\s\S]*?)<\/a:t>/gu;
947
+ for (let [e, a] of Object.entries(n)) {
948
+ if (!e.endsWith(".xml") || !e.startsWith("ppt/slides/") && !e.startsWith("ppt/slideLayouts/") && !e.startsWith("ppt/notesSlides/")) continue;
949
+ let n = r.decode(a);
950
+ for (let e of n.matchAll(i)) {
951
+ let n = decodeXmlEntities(e[1] ?? "");
952
+ for (let e = 0; e < n.length; e += 1) {
953
+ let r = n.codePointAt(e) ?? 0;
954
+ (isDefaultEmojiPresentationCodepoint(r) || codepointHasExplicitEmojiPresentation(n, e)) && t.add(r), r > 65535 && (e += 1);
1148
955
  }
1149
956
  }
1150
957
  }
1151
- } catch (error) {
1152
- if (isResourcePolicyError(error)) throw error;
958
+ } catch (e) {
959
+ if (isResourcePolicyError(e)) throw e;
1153
960
  return [];
1154
961
  }
1155
- return [...codepoints].sort((a, b) => a - b);
962
+ return [...t].sort((e, t) => e - t);
1156
963
  }
1157
- function pptxHasUnicodeText(buffer) {
964
+ function pptxHasUnicodeText(e) {
1158
965
  try {
1159
- const files = unzipBrowserPptx(buffer);
1160
- const decoder = new TextDecoder();
1161
- const textRegex = /<a:t(?:\s[^>]*)?>([\s\S]*?)<\/a:t>/gu;
1162
- for (const [filename, bytes] of Object.entries(files)) {
1163
- if (!filename.endsWith(".xml")) continue;
1164
- if (!filename.startsWith("ppt/slides/") && !filename.startsWith("ppt/slideLayouts/") && !filename.startsWith("ppt/notesSlides/")) continue;
1165
- const xml = decoder.decode(bytes);
1166
- for (const match of xml.matchAll(textRegex)) if (containsNonLatinCodepoint(decodeXmlEntities(match[1] ?? ""))) return true;
966
+ let t = unzipBrowserPptx(e), n = new TextDecoder(), r = /<a:t(?:\s[^>]*)?>([\s\S]*?)<\/a:t>/gu;
967
+ for (let [e, i] of Object.entries(t)) {
968
+ if (!e.endsWith(".xml") || !e.startsWith("ppt/slides/") && !e.startsWith("ppt/slideLayouts/") && !e.startsWith("ppt/notesSlides/")) continue;
969
+ let t = n.decode(i);
970
+ for (let e of t.matchAll(r)) if (containsNonLatinCodepoint(decodeXmlEntities(e[1] ?? ""))) return !0;
1167
971
  }
1168
- } catch (error) {
1169
- if (isResourcePolicyError(error)) throw error;
1170
- return false;
972
+ } catch (e) {
973
+ if (isResourcePolicyError(e)) throw e;
974
+ return !1;
1171
975
  }
1172
- return false;
1173
- }
1174
- async function resolveUnicodeFallbackFont(options) {
1175
- const font = options?.unicodeFallbackFont;
1176
- if (!font) return null;
1177
- if (font.data) {
1178
- const data = font.data instanceof Uint8Array ? font.data : new Uint8Array(font.data);
1179
- if (data.byteLength === 0) return null;
1180
- return {
1181
- path: font.path ?? "unicode-fallback.ttf",
1182
- data
976
+ return !1;
977
+ }
978
+ async function resolveUnicodeFallbackFont(e) {
979
+ let t = e?.unicodeFallbackFont;
980
+ if (!t) return null;
981
+ if (t.data) {
982
+ let e = t.data instanceof Uint8Array ? t.data : new Uint8Array(t.data);
983
+ return e.byteLength === 0 ? null : {
984
+ path: t.path ?? "unicode-fallback.ttf",
985
+ data: e
1183
986
  };
1184
987
  }
1185
- if (!font.url) return null;
1186
- const cacheKey = `${font.path ?? "unicode-fallback.ttf"}|${String(font.url)}`;
1187
- if (unicodeFallbackFontCacheKey !== cacheKey) {
1188
- unicodeFallbackFontCacheKey = cacheKey;
1189
- unicodeFallbackFontPromise = null;
1190
- }
1191
- unicodeFallbackFontPromise ??= (async () => {
988
+ if (!t.url) return null;
989
+ let n = `${t.path ?? "unicode-fallback.ttf"}|${String(t.url)}`;
990
+ L !== n && (L = n, R = null), R ??= (async () => {
1192
991
  try {
1193
- const response = await fetch(font.url);
1194
- if (!response.ok) return null;
1195
- return new Uint8Array(await response.arrayBuffer());
992
+ let e = await fetch(t.url);
993
+ return e.ok ? new Uint8Array(await e.arrayBuffer()) : null;
1196
994
  } catch {
1197
995
  return null;
1198
996
  }
1199
997
  })();
1200
- const data = await unicodeFallbackFontPromise;
1201
- if (!data || data.byteLength === 0) return null;
1202
- return {
1203
- path: font.path ?? "unicode-fallback.ttf",
1204
- data
998
+ let r = await R;
999
+ return !r || r.byteLength === 0 ? null : {
1000
+ path: t.path ?? "unicode-fallback.ttf",
1001
+ data: r
1205
1002
  };
1206
1003
  }
1207
- async function resolveEmojiFallbackFont(options) {
1208
- const font = options?.emojiFallbackFont;
1209
- if (!font) return null;
1210
- if (font.data) {
1211
- const data = font.data instanceof Uint8Array ? font.data : new Uint8Array(font.data);
1212
- if (data.byteLength === 0) return null;
1213
- return {
1214
- path: font.path ?? "emoji-fallback.ttf",
1215
- data
1004
+ async function resolveEmojiFallbackFont(e) {
1005
+ let t = e?.emojiFallbackFont;
1006
+ if (!t) return null;
1007
+ if (t.data) {
1008
+ let e = t.data instanceof Uint8Array ? t.data : new Uint8Array(t.data);
1009
+ return e.byteLength === 0 ? null : {
1010
+ path: t.path ?? "emoji-fallback.ttf",
1011
+ data: e
1216
1012
  };
1217
1013
  }
1218
- if (!font.url) return null;
1219
- const cacheKey = `${font.path ?? "emoji-fallback.ttf"}|${String(font.url)}`;
1220
- if (emojiFallbackFontCacheKey !== cacheKey) {
1221
- emojiFallbackFontCacheKey = cacheKey;
1222
- emojiFallbackFontPromise = null;
1223
- }
1224
- emojiFallbackFontPromise ??= (async () => {
1014
+ if (!t.url) return null;
1015
+ let n = `${t.path ?? "emoji-fallback.ttf"}|${String(t.url)}`;
1016
+ z !== n && (z = n, B = null), B ??= (async () => {
1225
1017
  try {
1226
- const response = await fetch(font.url);
1227
- if (!response.ok) return null;
1228
- return new Uint8Array(await response.arrayBuffer());
1018
+ let e = await fetch(t.url);
1019
+ return e.ok ? new Uint8Array(await e.arrayBuffer()) : null;
1229
1020
  } catch {
1230
1021
  return null;
1231
1022
  }
1232
1023
  })();
1233
- const data = await emojiFallbackFontPromise;
1234
- if (!data || data.byteLength === 0) return null;
1235
- return {
1236
- path: font.path ?? "emoji-fallback.ttf",
1237
- data
1024
+ let r = await B;
1025
+ return !r || r.byteLength === 0 ? null : {
1026
+ path: t.path ?? "emoji-fallback.ttf",
1027
+ data: r
1238
1028
  };
1239
1029
  }
1240
- async function instantiatePdfWasm(options) {
1241
- const wasmOpts = {
1030
+ async function instantiatePdfWasm(e) {
1031
+ let t = {
1242
1032
  builtins: ["js-string"],
1243
1033
  importedStringConstants: "_"
1244
- };
1245
- const imports = createPdfWasmImports();
1246
- const wasmBytes = options?.wasmBytes;
1247
- if (wasmBytes) {
1248
- const source = wasmBytes instanceof Uint8Array ? wasmBytes : new Uint8Array(wasmBytes);
1249
- return WebAssembly.instantiate(source, imports, wasmOpts);
1034
+ }, n = createPdfWasmImports(), r = e?.wasmBytes;
1035
+ if (r) {
1036
+ let e = r instanceof Uint8Array ? r : new Uint8Array(r);
1037
+ return WebAssembly.instantiate(e, n, t);
1250
1038
  }
1251
- const wasmUrl = options?.wasmUrl ?? defaultPdfWasmUrl();
1252
- const source = new Uint8Array(await fetchWasmBytes(wasmUrl, "pdf-converter"));
1253
- return WebAssembly.instantiate(source, imports, wasmOpts);
1039
+ let i = e?.wasmUrl ?? defaultPdfWasmUrl(), a = new Uint8Array(await fetchWasmBytes(i, "pdf-converter"));
1040
+ return WebAssembly.instantiate(a, n, t);
1254
1041
  }
1255
1042
  function defaultPdfWasmUrl() {
1256
1043
  try {
@@ -1259,434 +1046,344 @@ function defaultPdfWasmUrl() {
1259
1046
  return runtimeAssetUrl("./mbt/pdf-converter.wasm", import.meta.url);
1260
1047
  }
1261
1048
  }
1262
- async function loadPdfWasm(options) {
1263
- if (options?.wasmBytes) {
1264
- const exports = (await instantiatePdfWasm(options)).instance.exports;
1265
- exports._start();
1266
- assertPdfWasmApi(exports);
1267
- return exports;
1049
+ async function loadPdfWasm(e) {
1050
+ if (e?.wasmBytes) {
1051
+ let t = (await instantiatePdfWasm(e)).instance.exports;
1052
+ return t._start(), assertPdfWasmApi(t), t;
1268
1053
  }
1269
- const source = String(options?.wasmUrl ?? defaultPdfWasmUrl());
1270
- if (pdfWasmSource === source && pdfWasmInstance) return pdfWasmInstance;
1271
- if (pdfWasmLoadPromise) {
1272
- if (pdfWasmLoadSource === source) return pdfWasmLoadPromise;
1054
+ let t = String(e?.wasmUrl ?? defaultPdfWasmUrl());
1055
+ if (M === t && N) return N;
1056
+ if (F) {
1057
+ if (P === t) return F;
1273
1058
  try {
1274
- await pdfWasmLoadPromise;
1059
+ await F;
1275
1060
  } catch {}
1276
- return loadPdfWasm(options);
1061
+ return loadPdfWasm(e);
1277
1062
  }
1278
- const pending = (async () => {
1279
- const exports = (await instantiatePdfWasm({
1280
- ...options,
1281
- wasmUrl: source
1063
+ let n = (async () => {
1064
+ let n = (await instantiatePdfWasm({
1065
+ ...e,
1066
+ wasmUrl: t
1282
1067
  })).instance.exports;
1283
- exports._start();
1284
- assertPdfWasmApi(exports);
1285
- return exports;
1068
+ return n._start(), assertPdfWasmApi(n), n;
1286
1069
  })();
1287
- pdfWasmLoadSource = source;
1288
- pdfWasmLoadPromise = pending;
1070
+ P = t, F = n;
1289
1071
  try {
1290
- const exports = await pending;
1291
- if (pdfWasmLoadPromise === pending) {
1292
- pdfWasmSource = source;
1293
- pdfWasmInstance = exports;
1294
- }
1295
- return exports;
1072
+ let e = await n;
1073
+ return F === n && (M = t, N = e), e;
1296
1074
  } finally {
1297
- if (pdfWasmLoadPromise === pending) {
1298
- pdfWasmLoadSource = null;
1299
- pdfWasmLoadPromise = null;
1300
- }
1075
+ F === n && (P = null, F = null);
1301
1076
  }
1302
1077
  }
1303
- async function serializePdfWasmConversion(mod, convert) {
1304
- const current = (conversionTailsByInstance.get(mod) ?? Promise.resolve()).then(convert);
1305
- const tail = current.then(() => void 0, () => void 0);
1306
- conversionTailsByInstance.set(mod, tail);
1078
+ async function serializePdfWasmConversion(e, t) {
1079
+ let n = (I.get(e) ?? Promise.resolve()).then(t), r = n.then(() => void 0, () => void 0);
1080
+ I.set(e, r);
1307
1081
  try {
1308
- return await current;
1082
+ return await n;
1309
1083
  } finally {
1310
- if (conversionTailsByInstance.get(mod) === tail) conversionTailsByInstance.delete(mod);
1084
+ I.get(e) === r && I.delete(e);
1311
1085
  }
1312
1086
  }
1313
- function createBufferedPdfBridge(mod) {
1087
+ function createBufferedPdfBridge(e) {
1314
1088
  return {
1315
- supportsRegularFonts: typeof mod.clear_registered_regular_fonts === "function",
1316
- supportsEmojiBitmaps: typeof mod.clear_registered_emoji_bitmap_glyphs === "function",
1317
- supportsMathFallback: typeof mod.clear_math_fallback_fonts === "function",
1318
- clearRegularFonts: () => mod.clear_registered_regular_fonts?.(),
1319
- clearEmojiBitmaps: () => mod.clear_registered_emoji_bitmap_glyphs?.(),
1320
- clearMathFallback: () => mod.clear_math_fallback_fonts?.(),
1321
- registerRegularFont: (typeface, style, path, data) => {
1322
- const encodedTypeface = utf8Bytes(typeface);
1323
- const encodedStyle = utf8Bytes(style);
1324
- const encodedPath = utf8Bytes(path);
1325
- writePdfBridgeInput(mod, [
1326
- encodedTypeface,
1327
- encodedStyle,
1328
- encodedPath,
1329
- data
1330
- ]);
1331
- if (mod.register_pdf_font_buffered(encodedTypeface.length, encodedStyle.length, encodedPath.length) !== 1) throw new Error("PDF converter WASM rejected a buffered regular font");
1089
+ supportsRegularFonts: typeof e.clear_registered_regular_fonts == "function",
1090
+ supportsEmojiBitmaps: typeof e.clear_registered_emoji_bitmap_glyphs == "function",
1091
+ supportsMathFallback: typeof e.clear_math_fallback_fonts == "function",
1092
+ clearRegularFonts: () => e.clear_registered_regular_fonts?.(),
1093
+ clearEmojiBitmaps: () => e.clear_registered_emoji_bitmap_glyphs?.(),
1094
+ clearMathFallback: () => e.clear_math_fallback_fonts?.(),
1095
+ registerRegularFont: (t, n, r, i) => {
1096
+ let a = utf8Bytes(t), o = utf8Bytes(n), s = utf8Bytes(r);
1097
+ if (writePdfBridgeInput(e, [
1098
+ a,
1099
+ o,
1100
+ s,
1101
+ i
1102
+ ]), e.register_pdf_font_buffered(a.length, o.length, s.length) !== 1) throw Error("PDF converter WASM rejected a buffered regular font");
1332
1103
  },
1333
- registerEmojiBitmap: (bitmap) => {
1334
- const mime = utf8Bytes(bitmap.mime);
1335
- writePdfBridgeInput(mod, [mime, bitmap.data]);
1336
- if (mod.register_pdf_emoji_bitmap_buffered(bitmap.codepoint, mime.length, bitmap.width, bitmap.height) !== 1) throw new Error("PDF converter WASM rejected a buffered emoji bitmap");
1104
+ registerEmojiBitmap: (t) => {
1105
+ let n = utf8Bytes(t.mime);
1106
+ if (writePdfBridgeInput(e, [n, t.data]), e.register_pdf_emoji_bitmap_buffered(t.codepoint, n.length, t.width, t.height) !== 1) throw Error("PDF converter WASM rejected a buffered emoji bitmap");
1337
1107
  },
1338
- registerMathFallback: (family, data) => {
1339
- const encodedFamily = utf8Bytes(family);
1340
- writePdfBridgeInput(mod, [encodedFamily, data]);
1341
- if (mod.register_pdf_math_fallback_buffered(encodedFamily.length) !== 1) throw new Error("PDF converter WASM rejected a buffered math fallback font");
1108
+ registerMathFallback: (t, n) => {
1109
+ let r = utf8Bytes(t);
1110
+ if (writePdfBridgeInput(e, [r, n]), e.register_pdf_math_fallback_buffered(r.length) !== 1) throw Error("PDF converter WASM rejected a buffered math fallback font");
1342
1111
  },
1343
- setOfficeFontFallbacks: (enabled) => mod.set_pdf_office_font_fallbacks(enabled ? 1 : 0),
1344
- convert: ({ buffer, fallbackFont, licensePayload, runtimePayload, watermarkPayload }) => {
1345
- const pptx = new Uint8Array(buffer);
1346
- const fallbackPath = utf8Bytes(fallbackFont?.path ?? "");
1347
- const fallbackData = fallbackFont?.data ?? /* @__PURE__ */ new Uint8Array();
1348
- const license = utf8Bytes(licensePayload);
1349
- const runtime = utf8Bytes(runtimePayload);
1350
- const watermarks = utf8Bytes(watermarkPayload);
1351
- writePdfBridgeInput(mod, [
1352
- pptx,
1353
- fallbackPath,
1354
- fallbackData,
1355
- license,
1356
- runtime,
1357
- watermarks
1112
+ setOfficeFontFallbacks: (t) => e.set_pdf_office_font_fallbacks(+!!t),
1113
+ convert: ({ buffer: t, fallbackFont: n, licensePayload: r, runtimePayload: i, watermarkPayload: a }) => {
1114
+ let o = new Uint8Array(t), s = utf8Bytes(n?.path ?? ""), c = n?.data ?? /* @__PURE__ */ new Uint8Array(), l = utf8Bytes(r), u = utf8Bytes(i), d = utf8Bytes(a);
1115
+ writePdfBridgeInput(e, [
1116
+ o,
1117
+ s,
1118
+ c,
1119
+ l,
1120
+ u,
1121
+ d
1358
1122
  ]);
1359
- const outputLength = mod.run_pdf_conversion_buffered(pptx.length, fallbackPath.length, fallbackData.length, license.length, runtime.length, watermarks.length);
1360
- if (!Number.isSafeInteger(outputLength) || outputLength < 0) throw new Error("PDF converter WASM rejected the buffered conversion request");
1361
- return readPdfBridgeOutput(mod, outputLength);
1123
+ let f = e.run_pdf_conversion_buffered(o.length, s.length, c.length, l.length, u.length, d.length);
1124
+ if (!Number.isSafeInteger(f) || f < 0) throw Error("PDF converter WASM rejected the buffered conversion request");
1125
+ return readPdfBridgeOutput(e, f);
1362
1126
  }
1363
1127
  };
1364
1128
  }
1365
- function createDirectPdfBridge(mod) {
1366
- const convertFromString = mod.convert_pptx_to_pdf_from_string;
1367
- if (!convertFromString) throw new Error("PDF converter WASM does not expose a supported host bridge");
1129
+ function createDirectPdfBridge(e) {
1130
+ let t = e.convert_pptx_to_pdf_from_string;
1131
+ if (!t) throw Error("PDF converter WASM does not expose a supported host bridge");
1368
1132
  return {
1369
- supportsRegularFonts: typeof mod.clear_registered_regular_fonts === "function" && (typeof mod.register_font_style_from_string === "function" || typeof mod.register_regular_font_from_string === "function"),
1370
- supportsEmojiBitmaps: typeof mod.clear_registered_emoji_bitmap_glyphs === "function" && typeof mod.register_emoji_bitmap_glyph_from_string === "function",
1371
- supportsMathFallback: typeof mod.clear_math_fallback_fonts === "function" && typeof mod.register_math_fallback_font_from_string === "function",
1372
- clearRegularFonts: () => mod.clear_registered_regular_fonts?.(),
1373
- clearEmojiBitmaps: () => mod.clear_registered_emoji_bitmap_glyphs?.(),
1374
- clearMathFallback: () => mod.clear_math_fallback_fonts?.(),
1375
- registerRegularFont: (typeface, style, path, data) => {
1376
- const latin1 = arrayBufferToLatin1(bytesToArrayBuffer(data));
1377
- if (mod.register_font_style_from_string) mod.register_font_style_from_string(typeface, style, path, latin1);
1378
- else if (style === "regular") mod.register_regular_font_from_string?.(typeface, path, latin1);
1133
+ supportsRegularFonts: typeof e.clear_registered_regular_fonts == "function" && (typeof e.register_font_style_from_string == "function" || typeof e.register_regular_font_from_string == "function"),
1134
+ supportsEmojiBitmaps: typeof e.clear_registered_emoji_bitmap_glyphs == "function" && typeof e.register_emoji_bitmap_glyph_from_string == "function",
1135
+ supportsMathFallback: typeof e.clear_math_fallback_fonts == "function" && typeof e.register_math_fallback_font_from_string == "function",
1136
+ clearRegularFonts: () => e.clear_registered_regular_fonts?.(),
1137
+ clearEmojiBitmaps: () => e.clear_registered_emoji_bitmap_glyphs?.(),
1138
+ clearMathFallback: () => e.clear_math_fallback_fonts?.(),
1139
+ registerRegularFont: (t, n, r, i) => {
1140
+ let a = arrayBufferToLatin1(bytesToArrayBuffer(i));
1141
+ e.register_font_style_from_string ? e.register_font_style_from_string(t, n, r, a) : n === "regular" && e.register_regular_font_from_string?.(t, r, a);
1379
1142
  },
1380
- registerEmojiBitmap: (bitmap) => mod.register_emoji_bitmap_glyph_from_string?.(bitmap.codepoint, bitmap.mime, bitmap.width, bitmap.height, arrayBufferToLatin1(bytesToArrayBuffer(bitmap.data))),
1381
- registerMathFallback: (family, data) => mod.register_math_fallback_font_from_string?.(family, arrayBufferToLatin1(bytesToArrayBuffer(data))),
1382
- setOfficeFontFallbacks: (enabled) => mod.register_regular_font_from_string?.(officeFontFallbacksBridgeTypeface, enabled ? "true" : "false", "x"),
1383
- convert: ({ buffer, fallbackFont, licensePayload, runtimePayload, watermarkPayload }) => {
1384
- const pptxLatin1 = arrayBufferToLatin1(buffer);
1385
- if (fallbackFont?.data) {
1386
- const fallbackData = arrayBufferToLatin1(bytesToArrayBuffer(fallbackFont.data));
1387
- if (mod.convert_pptx_to_pdf_with_unicode_fallback_license_and_watermarks_from_string) return mod.convert_pptx_to_pdf_with_unicode_fallback_license_and_watermarks_from_string(pptxLatin1, fallbackFont.path, fallbackData, licensePayload, runtimePayload, watermarkPayload);
1388
- if (watermarkPayload && mod.convert_pptx_to_pdf_with_unicode_fallback_and_watermarks_from_string) return mod.convert_pptx_to_pdf_with_unicode_fallback_and_watermarks_from_string(pptxLatin1, fallbackFont.path, fallbackData, watermarkPayload);
1389
- if (mod.convert_pptx_to_pdf_with_unicode_fallback_from_string) return mod.convert_pptx_to_pdf_with_unicode_fallback_from_string(pptxLatin1, fallbackFont.path, fallbackData);
1390
- return convertFromString(pptxLatin1);
1143
+ registerEmojiBitmap: (t) => e.register_emoji_bitmap_glyph_from_string?.(t.codepoint, t.mime, t.width, t.height, arrayBufferToLatin1(bytesToArrayBuffer(t.data))),
1144
+ registerMathFallback: (t, n) => e.register_math_fallback_font_from_string?.(t, arrayBufferToLatin1(bytesToArrayBuffer(n))),
1145
+ setOfficeFontFallbacks: (t) => e.register_regular_font_from_string?.("__xdoc_office_font_fallbacks__", t ? "true" : "false", "x"),
1146
+ convert: ({ buffer: n, fallbackFont: r, licensePayload: i, runtimePayload: a, watermarkPayload: o }) => {
1147
+ let s = arrayBufferToLatin1(n);
1148
+ if (r?.data) {
1149
+ let n = arrayBufferToLatin1(bytesToArrayBuffer(r.data));
1150
+ return e.convert_pptx_to_pdf_with_unicode_fallback_license_and_watermarks_from_string ? e.convert_pptx_to_pdf_with_unicode_fallback_license_and_watermarks_from_string(s, r.path, n, i, a, o) : o && e.convert_pptx_to_pdf_with_unicode_fallback_and_watermarks_from_string ? e.convert_pptx_to_pdf_with_unicode_fallback_and_watermarks_from_string(s, r.path, n, o) : e.convert_pptx_to_pdf_with_unicode_fallback_from_string ? e.convert_pptx_to_pdf_with_unicode_fallback_from_string(s, r.path, n) : t(s);
1391
1151
  }
1392
- if (mod.convert_pptx_to_pdf_with_license_from_string) return mod.convert_pptx_to_pdf_with_license_from_string(pptxLatin1, licensePayload, runtimePayload, watermarkPayload);
1393
- if (watermarkPayload && mod.convert_pptx_to_pdf_with_watermarks_from_string) return mod.convert_pptx_to_pdf_with_watermarks_from_string(pptxLatin1, watermarkPayload);
1394
- return convertFromString(pptxLatin1);
1152
+ return e.convert_pptx_to_pdf_with_license_from_string ? e.convert_pptx_to_pdf_with_license_from_string(s, i, a, o) : o && e.convert_pptx_to_pdf_with_watermarks_from_string ? e.convert_pptx_to_pdf_with_watermarks_from_string(s, o) : t(s);
1395
1153
  }
1396
1154
  };
1397
1155
  }
1398
- function createPdfBridge(mod) {
1399
- return hasBufferedPdfBridge(mod) ? createBufferedPdfBridge(mod) : createDirectPdfBridge(mod);
1400
- }
1401
- function resetPdfBridgeState(bridge) {
1402
- bridge.clearRegularFonts();
1403
- bridge.clearEmojiBitmaps();
1404
- bridge.clearMathFallback();
1405
- bridge.setOfficeFontFallbacks(false);
1406
- }
1407
- async function registerRegularFonts(bridge, options) {
1408
- const fonts = [...options?.regularFonts ?? []];
1409
- const emojiFallback = await resolveEmojiFallbackFont(options);
1410
- if (emojiFallback) fonts.push({
1411
- typeface: PDF_EMOJI_FALLBACK_TYPEFACE,
1412
- path: emojiFallback.path,
1413
- data: emojiFallback.data
1414
- });
1415
- if (!fonts.length || !bridge.supportsRegularFonts) return;
1416
- for (const font of fonts) {
1417
- if (!font?.typeface || !font.data) continue;
1418
- const data = font.data instanceof Uint8Array ? font.data : new Uint8Array(font.data);
1419
- if (data.byteLength === 0) continue;
1420
- const style = font.style ?? "regular";
1421
- const path = font.path ?? `${font.typeface}-${style}.ttf`;
1422
- bridge.registerRegularFont(font.typeface, style, path, data);
1156
+ function createPdfBridge(e) {
1157
+ return hasBufferedPdfBridge(e) ? createBufferedPdfBridge(e) : createDirectPdfBridge(e);
1158
+ }
1159
+ function resetPdfBridgeState(e) {
1160
+ e.clearRegularFonts(), e.clearEmojiBitmaps(), e.clearMathFallback(), e.setOfficeFontFallbacks(!1);
1161
+ }
1162
+ async function registerRegularFonts(e, t) {
1163
+ let n = [...t?.regularFonts ?? []], r = await resolveEmojiFallbackFont(t);
1164
+ if (r && n.push({
1165
+ typeface: "__pdf_emoji_fallback__",
1166
+ path: r.path,
1167
+ data: r.data
1168
+ }), n.length && e.supportsRegularFonts) for (let t of n) {
1169
+ if (!t?.typeface || !t.data) continue;
1170
+ let n = t.data instanceof Uint8Array ? t.data : new Uint8Array(t.data);
1171
+ if (n.byteLength === 0) continue;
1172
+ let r = t.style ?? "regular", i = t.path ?? `${t.typeface}-${r}.ttf`;
1173
+ e.registerRegularFont(t.typeface, r, i, n);
1423
1174
  }
1424
1175
  }
1425
- function emojiBitmapFallbackEnabled(options) {
1426
- return options?.emojiBitmapFallback !== false;
1427
- }
1428
- function emojiBitmapFallbackFont(options) {
1429
- return (typeof options?.emojiBitmapFallback === "object" ? options.emojiBitmapFallback.fontFamily : "") || "\"Apple Color Emoji\", \"Segoe UI Emoji\", \"Noto Color Emoji\", \"Twemoji Mozilla\", sans-serif";
1430
- }
1431
- function emojiBitmapFallbackPixelSize(options) {
1432
- const configured = typeof options?.emojiBitmapFallback === "object" ? options.emojiBitmapFallback.pixelSize : 0;
1433
- return Number.isFinite(configured) && configured >= 64 && configured <= 256 ? configured : 128;
1434
- }
1435
- function emojiPresentationText(codepoint) {
1436
- const text = String.fromCodePoint(codepoint);
1437
- return codepoint >= 8960 && codepoint <= 10175 ? `${text}\ufe0f` : text;
1438
- }
1439
- function canvasToBlob(canvas) {
1440
- return new Promise((resolve) => canvas.toBlob(resolve, "image/png"));
1441
- }
1442
- function cropTransparentCanvas(source, padding) {
1443
- const ctx = source.getContext("2d");
1444
- if (!ctx) return source;
1445
- const { width, height } = source;
1446
- const data = ctx.getImageData(0, 0, width, height).data;
1447
- let minX = width;
1448
- let minY = height;
1449
- let maxX = -1;
1450
- let maxY = -1;
1451
- for (let y = 0; y < height; y += 1) for (let x = 0; x < width; x += 1) {
1452
- if (data[(y * width + x) * 4 + 3] === 0) continue;
1453
- if (x < minX) minX = x;
1454
- if (y < minY) minY = y;
1455
- if (x > maxX) maxX = x;
1456
- if (y > maxY) maxY = y;
1457
- }
1458
- if (maxX < minX || maxY < minY) return source;
1459
- minX = Math.max(0, minX - padding);
1460
- minY = Math.max(0, minY - padding);
1461
- maxX = Math.min(width - 1, maxX + padding);
1462
- maxY = Math.min(height - 1, maxY + padding);
1463
- const cropped = document.createElement("canvas");
1464
- cropped.width = maxX - minX + 1;
1465
- cropped.height = maxY - minY + 1;
1466
- cropped.getContext("2d")?.drawImage(source, minX, minY, cropped.width, cropped.height, 0, 0, cropped.width, cropped.height);
1467
- return cropped;
1468
- }
1469
- async function renderEmojiBitmapFallback(codepoint, options) {
1470
- if (typeof document === "undefined") return null;
1471
- const canvas = document.createElement("canvas");
1472
- const size = emojiBitmapFallbackPixelSize(options);
1473
- canvas.width = size;
1474
- canvas.height = size;
1475
- const ctx = canvas.getContext("2d");
1476
- if (!ctx) return null;
1477
- ctx.clearRect(0, 0, size, size);
1478
- ctx.font = `${Math.round(size * .78)}px ${emojiBitmapFallbackFont(options)}`;
1479
- ctx.textAlign = "center";
1480
- ctx.textBaseline = "middle";
1481
- ctx.fillText(emojiPresentationText(codepoint), size / 2, size / 2);
1482
- const cropped = cropTransparentCanvas(canvas, Math.max(2, Math.round(size * .03)));
1483
- const blob = await canvasToBlob(cropped);
1484
- if (!blob || blob.size === 0) return null;
1485
- return {
1486
- codepoint,
1176
+ function emojiBitmapFallbackEnabled(e) {
1177
+ return e?.emojiBitmapFallback !== !1;
1178
+ }
1179
+ function emojiBitmapFallbackFont(e) {
1180
+ return (typeof e?.emojiBitmapFallback == "object" ? e.emojiBitmapFallback.fontFamily : "") || "\"Apple Color Emoji\", \"Segoe UI Emoji\", \"Noto Color Emoji\", \"Twemoji Mozilla\", sans-serif";
1181
+ }
1182
+ function emojiBitmapFallbackPixelSize(e) {
1183
+ let t = typeof e?.emojiBitmapFallback == "object" ? e.emojiBitmapFallback.pixelSize : 0;
1184
+ return Number.isFinite(t) && t >= 64 && t <= 256 ? t : 128;
1185
+ }
1186
+ function emojiPresentationText(e) {
1187
+ let t = String.fromCodePoint(e);
1188
+ return e >= 8960 && e <= 10175 ? `${t}\ufe0f` : t;
1189
+ }
1190
+ function canvasToBlob(e) {
1191
+ return new Promise((t) => e.toBlob(t, "image/png"));
1192
+ }
1193
+ function cropTransparentCanvas(e, t) {
1194
+ let n = e.getContext("2d");
1195
+ if (!n) return e;
1196
+ let { width: r, height: i } = e, a = n.getImageData(0, 0, r, i).data, o = r, s = i, c = -1, l = -1;
1197
+ for (let e = 0; e < i; e += 1) for (let t = 0; t < r; t += 1) a[(e * r + t) * 4 + 3] !== 0 && (t < o && (o = t), e < s && (s = e), t > c && (c = t), e > l && (l = e));
1198
+ if (c < o || l < s) return e;
1199
+ o = Math.max(0, o - t), s = Math.max(0, s - t), c = Math.min(r - 1, c + t), l = Math.min(i - 1, l + t);
1200
+ let u = document.createElement("canvas");
1201
+ return u.width = c - o + 1, u.height = l - s + 1, u.getContext("2d")?.drawImage(e, o, s, u.width, u.height, 0, 0, u.width, u.height), u;
1202
+ }
1203
+ async function renderEmojiBitmapFallback(e, t) {
1204
+ if (typeof document > "u") return null;
1205
+ let n = document.createElement("canvas"), r = emojiBitmapFallbackPixelSize(t);
1206
+ n.width = r, n.height = r;
1207
+ let i = n.getContext("2d");
1208
+ if (!i) return null;
1209
+ i.clearRect(0, 0, r, r), i.font = `${Math.round(r * .78)}px ${emojiBitmapFallbackFont(t)}`, i.textAlign = "center", i.textBaseline = "middle", i.fillText(emojiPresentationText(e), r / 2, r / 2);
1210
+ let a = cropTransparentCanvas(n, Math.max(2, Math.round(r * .03))), o = await canvasToBlob(a);
1211
+ return !o || o.size === 0 ? null : {
1212
+ codepoint: e,
1487
1213
  mime: "image/png",
1488
- width: cropped.width,
1489
- height: cropped.height,
1490
- data: new Uint8Array(await blob.arrayBuffer())
1214
+ width: a.width,
1215
+ height: a.height,
1216
+ data: new Uint8Array(await o.arrayBuffer())
1491
1217
  };
1492
1218
  }
1493
- async function registerEmojiBitmapFallbacks(bridge, buffer, options, prepared) {
1494
- if (!emojiBitmapFallbackEnabled(options) || !bridge.supportsEmojiBitmaps || prepared === void 0 && typeof document === "undefined") return;
1495
- const bitmaps = [];
1496
- if (prepared) bitmaps.push(...prepared);
1219
+ async function registerEmojiBitmapFallbacks(e, t, n, r) {
1220
+ if (!emojiBitmapFallbackEnabled(n) || !e.supportsEmojiBitmaps || r === void 0 && typeof document > "u") return;
1221
+ let i = [];
1222
+ if (r) i.push(...r);
1497
1223
  else {
1498
- const codepoints = collectEmojiBitmapFallbackCodepoints(buffer);
1499
- for (const codepoint of codepoints) {
1500
- const bitmap = await renderEmojiBitmapFallback(codepoint, options);
1501
- if (bitmap) bitmaps.push(bitmap);
1224
+ let e = collectEmojiBitmapFallbackCodepoints(t);
1225
+ for (let t of e) {
1226
+ let e = await renderEmojiBitmapFallback(t, n);
1227
+ e && i.push(e);
1502
1228
  }
1503
1229
  }
1504
- if (bitmaps.length === 0) return;
1505
- for (const bitmap of bitmaps) bridge.registerEmojiBitmap(bitmap);
1506
- }
1507
- async function resolveMathFallbackBytes(options) {
1508
- const explicit = options?.mathFallbackFont;
1509
- if (explicit?.data) {
1510
- const data = explicit.data instanceof Uint8Array ? explicit.data : new Uint8Array(explicit.data);
1511
- if (data.byteLength > 0) return {
1512
- family: explicit.family ?? "math-fallback",
1513
- data
1230
+ if (i.length !== 0) for (let t of i) e.registerEmojiBitmap(t);
1231
+ }
1232
+ async function resolveMathFallbackBytes(e) {
1233
+ let t = e?.mathFallbackFont;
1234
+ if (t?.data) {
1235
+ let e = t.data instanceof Uint8Array ? t.data : new Uint8Array(t.data);
1236
+ if (e.byteLength > 0) return {
1237
+ family: t.family ?? "math-fallback",
1238
+ data: e
1514
1239
  };
1515
1240
  }
1516
- if (explicit?.url) try {
1517
- const response = await fetch(explicit.url);
1518
- if (response.ok) {
1519
- const data = new Uint8Array(await response.arrayBuffer());
1520
- if (data.byteLength > 0) return {
1521
- family: explicit.family ?? "math-fallback",
1522
- data
1241
+ if (t?.url) try {
1242
+ let e = await fetch(t.url);
1243
+ if (e.ok) {
1244
+ let n = new Uint8Array(await e.arrayBuffer());
1245
+ if (n.byteLength > 0) return {
1246
+ family: t.family ?? "math-fallback",
1247
+ data: n
1523
1248
  };
1524
1249
  }
1525
1250
  } catch {}
1526
- const shared = await resolveUnicodeFallbackFont(options);
1527
- if (shared) return {
1528
- family: shared.path,
1529
- data: shared.data
1530
- };
1531
- return null;
1251
+ let n = await resolveUnicodeFallbackFont(e);
1252
+ return n ? {
1253
+ family: n.path,
1254
+ data: n.data
1255
+ } : null;
1532
1256
  }
1533
- async function registerMathFallback(bridge, options) {
1534
- if (!bridge.supportsMathFallback) return;
1535
- const resolved = await resolveMathFallbackBytes(options);
1536
- if (resolved) bridge.registerMathFallback(resolved.family, resolved.data);
1257
+ async function registerMathFallback(e, t) {
1258
+ if (!e.supportsMathFallback) return;
1259
+ let n = await resolveMathFallbackBytes(t);
1260
+ n && e.registerMathFallback(n.family, n.data);
1537
1261
  }
1538
- function watermarksJson(options) {
1539
- return options?.watermarks?.length ? JSON.stringify(options.watermarks) : "";
1262
+ function watermarksJson(e) {
1263
+ return e?.watermarks?.length ? JSON.stringify(e.watermarks) : "";
1540
1264
  }
1541
- function licenseJson(options) {
1542
- if (options?.license === void 0 || options.license === null) return "";
1543
- return typeof options.license === "string" ? options.license : JSON.stringify(options.license);
1265
+ function licenseJson(e) {
1266
+ return e?.license === void 0 || e.license === null ? "" : typeof e.license == "string" ? e.license : JSON.stringify(e.license);
1544
1267
  }
1545
1268
  function runtimeOrigin() {
1546
- return typeof location !== "undefined" ? location.origin : "";
1269
+ return typeof location < "u" ? location.origin : "";
1547
1270
  }
1548
1271
  function runtimeHostname() {
1549
- return typeof location !== "undefined" ? location.hostname : "";
1272
+ return typeof location < "u" ? location.hostname : "";
1550
1273
  }
1551
- function licenseRuntimeJson(options) {
1274
+ function licenseRuntimeJson(e) {
1552
1275
  return JSON.stringify({
1553
1276
  feature: "pdf-export",
1554
- nowUnixMs: options?.licenseRuntime?.now ?? Date.now(),
1555
- origin: options?.licenseRuntime?.origin ?? runtimeOrigin(),
1556
- hostname: options?.licenseRuntime?.hostname ?? runtimeHostname(),
1557
- deploymentId: options?.licenseRuntime?.deploymentId ?? "",
1558
- sdkVersion: options?.licenseRuntime?.sdkVersion ?? "",
1559
- inputBytes: options?.licenseRuntime?.inputBytes,
1560
- restrictionPolicySnapshot: options?.licenseRuntime?.restrictionPolicySnapshot
1277
+ nowUnixMs: e?.licenseRuntime?.now ?? Date.now(),
1278
+ origin: e?.licenseRuntime?.origin ?? runtimeOrigin(),
1279
+ hostname: e?.licenseRuntime?.hostname ?? runtimeHostname(),
1280
+ deploymentId: e?.licenseRuntime?.deploymentId ?? "",
1281
+ sdkVersion: e?.licenseRuntime?.sdkVersion ?? "",
1282
+ inputBytes: e?.licenseRuntime?.inputBytes,
1283
+ restrictionPolicySnapshot: e?.licenseRuntime?.restrictionPolicySnapshot
1561
1284
  });
1562
1285
  }
1563
- /** @internal Worker entry; browser callers should use pptxToPdf(). */
1564
- async function pptxToPdfOnCurrentThread(buffer, options, preparedEmojiBitmaps) {
1565
- options?.signal?.throwIfAborted();
1566
- const resourceStarted = performance.now();
1567
- checkBrowserInput(buffer.byteLength);
1568
- const mod = await loadPdfWasm(options);
1569
- options?.signal?.throwIfAborted();
1570
- return serializePdfWasmConversion(mod, () => convertPptxWithPdfWasm(mod, buffer, resourceStarted, options, preparedEmojiBitmaps));
1571
- }
1572
- async function convertPptxWithPdfWasm(mod, buffer, resourceStarted, options, preparedEmojiBitmaps) {
1573
- options?.signal?.throwIfAborted();
1574
- const bridge = createPdfBridge(mod);
1575
- let pdfResult;
1286
+ async function pptxToPdfOnCurrentThread(e, t, n) {
1287
+ t?.signal?.throwIfAborted();
1288
+ let r = performance.now();
1289
+ checkBrowserInput(e.byteLength);
1290
+ let i = await loadPdfWasm(t);
1291
+ return t?.signal?.throwIfAborted(), serializePdfWasmConversion(i, () => convertPptxWithPdfWasm(i, e, r, t, n));
1292
+ }
1293
+ async function convertPptxWithPdfWasm(e, t, n, r, i) {
1294
+ r?.signal?.throwIfAborted();
1295
+ let a = createPdfBridge(e), o;
1576
1296
  try {
1577
- resetPdfBridgeState(bridge);
1578
- await registerRegularFonts(bridge, options);
1579
- options?.signal?.throwIfAborted();
1580
- await registerEmojiBitmapFallbacks(bridge, buffer, options, preparedEmojiBitmaps);
1581
- options?.signal?.throwIfAborted();
1582
- await registerMathFallback(bridge, options);
1583
- options?.signal?.throwIfAborted();
1584
- const fallbackFont = pptxHasUnicodeText(buffer) ? await resolveUnicodeFallbackFont(options) : null;
1585
- bridge.setOfficeFontFallbacks(options?.officeFontFallbacks === true);
1586
- options?.signal?.throwIfAborted();
1587
- pdfResult = bridge.convert({
1588
- buffer,
1589
- fallbackFont,
1590
- licensePayload: licenseJson(options),
1591
- runtimePayload: licenseRuntimeJson(options),
1592
- watermarkPayload: watermarksJson(options)
1297
+ resetPdfBridgeState(a), await registerRegularFonts(a, r), r?.signal?.throwIfAborted(), await registerEmojiBitmapFallbacks(a, t, r, i), r?.signal?.throwIfAborted(), await registerMathFallback(a, r), r?.signal?.throwIfAborted();
1298
+ let e = pptxHasUnicodeText(t) ? await resolveUnicodeFallbackFont(r) : null;
1299
+ a.setOfficeFontFallbacks(r?.officeFontFallbacks === !0), r?.signal?.throwIfAborted(), o = a.convert({
1300
+ buffer: t,
1301
+ fallbackFont: e,
1302
+ licensePayload: licenseJson(r),
1303
+ runtimePayload: licenseRuntimeJson(r),
1304
+ watermarkPayload: watermarksJson(r)
1593
1305
  });
1594
1306
  } finally {
1595
- resetPdfBridgeState(bridge);
1307
+ resetPdfBridgeState(a);
1596
1308
  }
1597
- const errorPrefix = typeof pdfResult === "string" ? pdfResult : uint8ArrayToLatin1(pdfResult.subarray(0, 15));
1598
- if (errorPrefix.startsWith("ERROR_RESOURCE:")) {
1599
- const rawDetails = (typeof pdfResult === "string" ? pdfResult : new TextDecoder().decode(pdfResult)).slice(15);
1600
- const violation = resourcePolicyErrorFromDetails(JSON.parse(rawDetails));
1601
- if (violation) throw violation;
1602
- throw new Error("PDF conversion returned an invalid Resource Policy failure");
1309
+ let s = typeof o == "string" ? o : uint8ArrayToLatin1(o.subarray(0, 15));
1310
+ if (s.startsWith("ERROR_RESOURCE:")) {
1311
+ let e = (typeof o == "string" ? o : new TextDecoder().decode(o)).slice(15);
1312
+ throw resourcePolicyErrorFromDetails(JSON.parse(e)) || Error("PDF conversion returned an invalid Resource Policy failure");
1603
1313
  }
1604
- if (errorPrefix.startsWith("ERROR:")) {
1605
- const errorResult = typeof pdfResult === "string" ? pdfResult : new TextDecoder().decode(pdfResult);
1606
- throw new Error(errorResult.slice(6) || "Unknown PDF conversion error");
1314
+ if (s.startsWith("ERROR:")) {
1315
+ let e = typeof o == "string" ? o : new TextDecoder().decode(o);
1316
+ throw Error(e.slice(6) || "Unknown PDF conversion error");
1607
1317
  }
1608
- const pdf = typeof pdfResult === "string" ? latin1ToUint8Array(pdfResult) : pdfResult;
1609
- checkBrowserOutput(pdf.byteLength, "PDF output");
1610
- checkBrowserElapsed(resourceStarted, "PDF conversion wall clock");
1611
- return pdf;
1318
+ let c = typeof o == "string" ? latin1ToUint8Array(o) : o;
1319
+ return checkBrowserOutput(c.byteLength, "PDF output"), checkBrowserElapsed(n, "PDF conversion wall clock"), c;
1612
1320
  }
1613
1321
  //#endregion
1614
1322
  //#region src/pdf-worker.ts
1615
- const ctx = self;
1616
- const waitingForEmoji = /* @__PURE__ */ new Map();
1617
- const active = /* @__PURE__ */ new Map();
1618
- async function handlePdfRequest(request, emojiBitmaps) {
1619
- const { id, buffer, options } = request;
1620
- const abort = active.get(id);
1621
- if (!abort) return;
1622
- try {
1623
- const bytes = await pptxToPdfOnCurrentThread(buffer, {
1624
- ...options,
1625
- signal: abort.signal
1626
- }, emojiBitmaps);
1627
- if (abort.signal.aborted) return;
1628
- const data = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
1629
- ctx.postMessage({
1630
- id,
1323
+ const V = self, H = /* @__PURE__ */ new Map(), U = /* @__PURE__ */ new Map();
1324
+ async function handlePdfRequest(e, t) {
1325
+ let { id: n, buffer: r, options: i } = e, a = U.get(n);
1326
+ if (a) try {
1327
+ let e = await pptxToPdfOnCurrentThread(r, {
1328
+ ...i,
1329
+ signal: a.signal
1330
+ }, t);
1331
+ if (a.signal.aborted) return;
1332
+ let o = e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
1333
+ V.postMessage({
1334
+ id: n,
1631
1335
  status: "success",
1632
- data
1633
- }, [data]);
1634
- } catch (error) {
1635
- if (abort.signal.aborted) return;
1636
- ctx.postMessage({
1637
- id,
1336
+ data: o
1337
+ }, [o]);
1338
+ } catch (e) {
1339
+ if (a.signal.aborted) return;
1340
+ V.postMessage({
1341
+ id: n,
1638
1342
  status: "error",
1639
- error: serializeWorkerError(error)
1343
+ error: serializeWorkerError(e)
1640
1344
  });
1641
1345
  } finally {
1642
- active.delete(id);
1643
- if (abort.signal.aborted) ctx.postMessage({
1644
- id,
1346
+ U.delete(n), a.signal.aborted && V.postMessage({
1347
+ id: n,
1645
1348
  status: "error",
1646
- error: serializeWorkerError(abort.signal.reason)
1349
+ error: serializeWorkerError(a.signal.reason)
1647
1350
  });
1648
1351
  }
1649
1352
  }
1650
- ctx.onmessage = (event) => {
1651
- const request = event.data;
1652
- if (request.kind === "cancel") {
1653
- const abort = active.get(request.id);
1654
- abort?.abort();
1655
- active.delete(request.id);
1656
- if (waitingForEmoji.delete(request.id) && abort) ctx.postMessage({
1657
- id: request.id,
1353
+ V.onmessage = (e) => {
1354
+ let t = e.data;
1355
+ if (t.kind === "cancel") {
1356
+ let e = U.get(t.id);
1357
+ e?.abort(), U.delete(t.id), H.delete(t.id) && e && V.postMessage({
1358
+ id: t.id,
1658
1359
  status: "error",
1659
- error: serializeWorkerError(abort.signal.reason)
1360
+ error: serializeWorkerError(e.signal.reason)
1660
1361
  });
1661
1362
  return;
1662
1363
  }
1663
- if (request.kind === "convert") {
1664
- active.set(request.id, new AbortController());
1364
+ if (t.kind === "convert") {
1365
+ U.set(t.id, new AbortController());
1665
1366
  try {
1666
- const codepoints = request.options?.emojiBitmapFallback === false ? [] : collectEmojiBitmapFallbackCodepoints(request.buffer);
1667
- if (codepoints.length > 0) {
1668
- waitingForEmoji.set(request.id, request);
1669
- ctx.postMessage({
1670
- id: request.id,
1367
+ let e = t.options?.emojiBitmapFallback === !1 ? [] : collectEmojiBitmapFallbackCodepoints(t.buffer);
1368
+ if (e.length > 0) {
1369
+ H.set(t.id, t), V.postMessage({
1370
+ id: t.id,
1671
1371
  status: "emoji-codepoints",
1672
- codepoints
1372
+ codepoints: e
1673
1373
  });
1674
1374
  return;
1675
1375
  }
1676
- handlePdfRequest(request, []);
1677
- } catch (error) {
1678
- active.delete(request.id);
1679
- ctx.postMessage({
1680
- id: request.id,
1376
+ handlePdfRequest(t, []);
1377
+ } catch (e) {
1378
+ U.delete(t.id), V.postMessage({
1379
+ id: t.id,
1681
1380
  status: "error",
1682
- error: serializeWorkerError(error)
1381
+ error: serializeWorkerError(e)
1683
1382
  });
1684
1383
  }
1685
1384
  return;
1686
1385
  }
1687
- const pending = waitingForEmoji.get(request.id);
1688
- if (!pending) return;
1689
- waitingForEmoji.delete(request.id);
1690
- handlePdfRequest(pending, request.emojiBitmaps);
1386
+ let n = H.get(t.id);
1387
+ n && (H.delete(t.id), handlePdfRequest(n, t.emojiBitmaps));
1691
1388
  };
1692
1389
  //#endregion