@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.
- package/dist/index.cjs +7 -24649
- package/dist/index.js +10505 -17629
- package/dist/index.umd.js +7 -24653
- package/dist/js-worker.js +9702 -16453
- package/dist/pdf-worker.js +849 -1152
- package/dist/wasm-worker.js +515 -707
- package/package.json +2 -2
package/dist/pdf-worker.js
CHANGED
|
@@ -1,107 +1,86 @@
|
|
|
1
|
+
//#endregion
|
|
1
2
|
//#region src/latin1.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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(
|
|
20
|
+
function fileUrl(e) {
|
|
27
21
|
try {
|
|
28
|
-
|
|
29
|
-
return
|
|
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(
|
|
35
|
-
|
|
36
|
-
|
|
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(
|
|
40
|
-
|
|
41
|
-
if (!
|
|
42
|
-
|
|
43
|
-
return
|
|
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(
|
|
46
|
-
|
|
47
|
-
if (
|
|
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(
|
|
50
|
-
let
|
|
42
|
+
async function fetchWasmBytes(e, t) {
|
|
43
|
+
let n;
|
|
51
44
|
try {
|
|
52
|
-
|
|
53
|
-
} catch (
|
|
54
|
-
|
|
55
|
-
if (!
|
|
56
|
-
|
|
57
|
-
assertWasmBytes(
|
|
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 (!
|
|
61
|
-
|
|
62
|
-
assertWasmBytes(
|
|
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
|
|
68
|
-
if (typeof document
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
|
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
|
|
194
|
-
var
|
|
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
|
-
|
|
204
|
-
var
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
var
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
var
|
|
211
|
-
for (var i = 0;
|
|
212
|
-
var
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
|
|
227
|
-
var
|
|
228
|
-
for (
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return
|
|
239
|
-
})
|
|
240
|
-
var
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
return
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
var
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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 (!
|
|
312
|
-
|
|
313
|
-
var
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
var
|
|
329
|
-
|
|
330
|
-
var
|
|
331
|
-
|
|
332
|
-
for (var
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
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
|
|
343
|
-
|
|
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
|
|
350
|
-
|
|
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 (
|
|
356
|
-
|
|
276
|
+
if (g > w) {
|
|
277
|
+
m && err(0);
|
|
357
278
|
break;
|
|
358
279
|
}
|
|
359
280
|
}
|
|
360
|
-
|
|
361
|
-
var
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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 (
|
|
371
|
-
if (
|
|
372
|
-
|
|
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
|
|
377
|
-
if (
|
|
378
|
-
var
|
|
379
|
-
|
|
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
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
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 (
|
|
391
|
-
|
|
305
|
+
if (g > w) {
|
|
306
|
+
m && err(0);
|
|
392
307
|
break;
|
|
393
308
|
}
|
|
394
|
-
|
|
395
|
-
var
|
|
396
|
-
if (
|
|
397
|
-
var
|
|
398
|
-
|
|
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 (;
|
|
315
|
+
for (; y < Z; ++y) r[y] = r[y - H];
|
|
402
316
|
}
|
|
403
317
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
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
|
-
|
|
417
|
-
return
|
|
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
|
|
331
|
+
var x = typeof TextDecoder < "u" && /*#__PURE__*/ new TextDecoder();
|
|
423
332
|
try {
|
|
424
|
-
|
|
425
|
-
} catch
|
|
426
|
-
var dutf8 = function(
|
|
427
|
-
for (var
|
|
428
|
-
var
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
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
|
-
|
|
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
|
-
|
|
442
|
-
|
|
443
|
-
|
|
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
|
|
460
|
-
return
|
|
461
|
-
}
|
|
462
|
-
var
|
|
463
|
-
|
|
464
|
-
|
|
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(
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
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
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
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
|
-
|
|
375
|
+
r < 2 && err(13);
|
|
485
376
|
}
|
|
486
377
|
return [
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
378
|
+
i,
|
|
379
|
+
a,
|
|
380
|
+
o,
|
|
490
381
|
0
|
|
491
382
|
];
|
|
492
383
|
};
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
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
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
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
|
|
402
|
+
return r;
|
|
532
403
|
}
|
|
533
404
|
//#endregion
|
|
534
405
|
//#region src/resource-policy.generated.ts
|
|
535
|
-
const
|
|
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(
|
|
621
|
-
super(`${
|
|
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(
|
|
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:
|
|
635
|
-
commercialUpgradeApplicable:
|
|
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(
|
|
639
|
-
|
|
640
|
-
}
|
|
641
|
-
function checkBrowserOutput(
|
|
642
|
-
|
|
643
|
-
}
|
|
644
|
-
function checkBrowserElapsed(
|
|
645
|
-
checkBrowserElapsedMs(Math.max(0, Math.ceil(performance.now() -
|
|
646
|
-
}
|
|
647
|
-
function checkBrowserElapsedMs(
|
|
648
|
-
|
|
649
|
-
}
|
|
650
|
-
function isResourcePolicyError(
|
|
651
|
-
return
|
|
652
|
-
}
|
|
653
|
-
function resourcePolicyErrorFromDetails(
|
|
654
|
-
if (!
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
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(
|
|
669
|
-
|
|
670
|
-
let
|
|
671
|
-
for (
|
|
672
|
-
|
|
673
|
-
|
|
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
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
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(
|
|
704
|
-
|
|
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(
|
|
709
|
-
this.observeNode(
|
|
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(
|
|
714
|
-
|
|
715
|
-
return
|
|
716
|
-
}
|
|
717
|
-
function looksLikeXmlPayload(
|
|
718
|
-
let
|
|
719
|
-
|
|
720
|
-
if (
|
|
721
|
-
|
|
722
|
-
return
|
|
723
|
-
}
|
|
724
|
-
function checkBrowserXmlParts(
|
|
725
|
-
|
|
726
|
-
for (
|
|
727
|
-
}
|
|
728
|
-
const ascii = (
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
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
|
|
757
|
-
}
|
|
758
|
-
function skipDoctype(
|
|
759
|
-
let
|
|
760
|
-
let
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
if (
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
else if (
|
|
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
|
|
771
|
-
}
|
|
772
|
-
function isSpace(
|
|
773
|
-
return
|
|
774
|
-
}
|
|
775
|
-
function scanXml(
|
|
776
|
-
let
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
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(
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
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(
|
|
792
|
-
|
|
793
|
-
|
|
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(
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
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(
|
|
805
|
-
|
|
643
|
+
if (matchesAt(e, r, A) || matchesAt(e, r, j)) {
|
|
644
|
+
r = skipDoctype(e, r + 2);
|
|
806
645
|
continue;
|
|
807
646
|
}
|
|
808
|
-
if (
|
|
809
|
-
|
|
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 (
|
|
814
|
-
|
|
651
|
+
if (r + 1 < e.length && e[r + 1] === 33) {
|
|
652
|
+
r = findTagEnd(e, r + 2);
|
|
815
653
|
continue;
|
|
816
654
|
}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
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(
|
|
828
|
-
return
|
|
661
|
+
function readU16BE(e, t) {
|
|
662
|
+
return e[t] * 256 + e[t + 1];
|
|
829
663
|
}
|
|
830
|
-
function readU16LE(
|
|
831
|
-
return
|
|
664
|
+
function readU16LE(e, t) {
|
|
665
|
+
return e[t] + e[t + 1] * 256;
|
|
832
666
|
}
|
|
833
|
-
function readU24LE(
|
|
834
|
-
return
|
|
667
|
+
function readU24LE(e, t) {
|
|
668
|
+
return e[t] + e[t + 1] * 256 + e[t + 2] * 65536;
|
|
835
669
|
}
|
|
836
|
-
function readU32BE(
|
|
837
|
-
return
|
|
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(
|
|
840
|
-
return
|
|
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(
|
|
843
|
-
|
|
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(
|
|
847
|
-
if (
|
|
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(
|
|
689
|
+
]) && bytesEqual(e, 12, [
|
|
857
690
|
73,
|
|
858
691
|
72,
|
|
859
692
|
68,
|
|
860
693
|
82
|
|
861
694
|
])) return {
|
|
862
|
-
width: readU32BE(
|
|
863
|
-
height: readU32BE(
|
|
695
|
+
width: readU32BE(e, 16),
|
|
696
|
+
height: readU32BE(e, 20)
|
|
864
697
|
};
|
|
865
|
-
if (
|
|
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(
|
|
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(
|
|
881
|
-
height: readU16LE(
|
|
713
|
+
width: readU16LE(e, 6),
|
|
714
|
+
height: readU16LE(e, 8)
|
|
882
715
|
};
|
|
883
|
-
if (
|
|
884
|
-
|
|
885
|
-
if (
|
|
886
|
-
width: readU16LE(
|
|
887
|
-
height: readU16LE(
|
|
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 (
|
|
890
|
-
|
|
722
|
+
if (t >= 40) {
|
|
723
|
+
let t = new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
891
724
|
return {
|
|
892
|
-
width: Math.abs(
|
|
893
|
-
height: Math.abs(
|
|
725
|
+
width: Math.abs(t.getInt32(18, !0)),
|
|
726
|
+
height: Math.abs(t.getInt32(22, !0))
|
|
894
727
|
};
|
|
895
728
|
}
|
|
896
729
|
}
|
|
897
|
-
if (
|
|
730
|
+
if (e.length >= 30 && bytesEqual(e, 0, [
|
|
898
731
|
82,
|
|
899
732
|
73,
|
|
900
733
|
70,
|
|
901
734
|
70
|
|
902
|
-
]) && bytesEqual(
|
|
735
|
+
]) && bytesEqual(e, 8, [
|
|
903
736
|
87,
|
|
904
737
|
69,
|
|
905
738
|
66,
|
|
906
739
|
80
|
|
907
740
|
])) {
|
|
908
|
-
if (bytesEqual(
|
|
741
|
+
if (bytesEqual(e, 12, [
|
|
909
742
|
86,
|
|
910
743
|
80,
|
|
911
744
|
56,
|
|
912
745
|
88
|
|
913
746
|
])) return {
|
|
914
|
-
width: 1 + readU24LE(
|
|
915
|
-
height: 1 + readU24LE(
|
|
747
|
+
width: 1 + readU24LE(e, 24),
|
|
748
|
+
height: 1 + readU24LE(e, 27)
|
|
916
749
|
};
|
|
917
|
-
if (bytesEqual(
|
|
750
|
+
if (bytesEqual(e, 12, [
|
|
918
751
|
86,
|
|
919
752
|
80,
|
|
920
753
|
56,
|
|
921
754
|
76
|
|
922
|
-
]) &&
|
|
923
|
-
width: 1 + (
|
|
924
|
-
height: 1 + (
|
|
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(
|
|
759
|
+
if (bytesEqual(e, 12, [
|
|
927
760
|
86,
|
|
928
761
|
80,
|
|
929
762
|
56,
|
|
930
763
|
32
|
|
931
|
-
]) && bytesEqual(
|
|
764
|
+
]) && bytesEqual(e, 23, [
|
|
932
765
|
157,
|
|
933
766
|
1,
|
|
934
767
|
42
|
|
935
768
|
])) return {
|
|
936
|
-
width: (
|
|
937
|
-
height: (
|
|
769
|
+
width: (e[26] | e[27] << 8) & 16383,
|
|
770
|
+
height: (e[28] | e[29] << 8) & 16383
|
|
938
771
|
};
|
|
939
772
|
}
|
|
940
|
-
if (
|
|
941
|
-
let
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
if (
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
if (
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
if (
|
|
952
|
-
|
|
953
|
-
|
|
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
|
-
|
|
788
|
+
t += r;
|
|
957
789
|
}
|
|
958
790
|
}
|
|
959
|
-
return probeTiff(
|
|
791
|
+
return probeTiff(e);
|
|
960
792
|
}
|
|
961
|
-
function checkBrowserImagePayload(
|
|
962
|
-
|
|
963
|
-
|
|
793
|
+
function checkBrowserImagePayload(e, t = "image") {
|
|
794
|
+
let n = probeImageDimensions(e);
|
|
795
|
+
n && checkImageDimensions(n.width, n.height, t);
|
|
964
796
|
}
|
|
965
|
-
function probeTiff(
|
|
966
|
-
if (
|
|
967
|
-
|
|
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 (!
|
|
805
|
+
if (!t && !bytesEqual(e, 0, [
|
|
974
806
|
77,
|
|
975
807
|
77,
|
|
976
808
|
0,
|
|
977
809
|
42
|
|
978
810
|
])) return null;
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
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
|
|
997
|
-
width,
|
|
998
|
-
height
|
|
823
|
+
return a && o ? {
|
|
824
|
+
width: a,
|
|
825
|
+
height: o
|
|
999
826
|
} : null;
|
|
1000
827
|
}
|
|
1001
|
-
function checkImageDimensions(
|
|
1002
|
-
if (
|
|
1003
|
-
|
|
1004
|
-
|
|
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(
|
|
835
|
+
function property(e, t) {
|
|
1009
836
|
try {
|
|
1010
|
-
return
|
|
837
|
+
return e && typeof e == "object" ? e[t] : void 0;
|
|
1011
838
|
} catch {
|
|
1012
839
|
return;
|
|
1013
840
|
}
|
|
1014
841
|
}
|
|
1015
|
-
function cloneFact(
|
|
842
|
+
function cloneFact(e) {
|
|
1016
843
|
try {
|
|
1017
|
-
return structuredClone(
|
|
844
|
+
return structuredClone(e);
|
|
1018
845
|
} catch {
|
|
1019
846
|
return;
|
|
1020
847
|
}
|
|
1021
848
|
}
|
|
1022
|
-
function serializeWorkerError(
|
|
1023
|
-
|
|
1024
|
-
if (
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
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
|
-
|
|
1032
|
-
name: typeof
|
|
1033
|
-
message: typeof
|
|
856
|
+
let o = {
|
|
857
|
+
name: typeof r == "string" ? r : "Error",
|
|
858
|
+
message: typeof i == "string" ? i : a
|
|
1034
859
|
};
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
if (
|
|
1042
|
-
if (
|
|
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(
|
|
869
|
+
error: serializeWorkerError(l, t)
|
|
1045
870
|
};
|
|
1046
871
|
else {
|
|
1047
|
-
|
|
1048
|
-
|
|
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
|
|
879
|
+
return o;
|
|
1055
880
|
}
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
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: (...
|
|
1074
|
-
console.log(...
|
|
887
|
+
console: { log: (...e) => {
|
|
888
|
+
console.log(...e);
|
|
1075
889
|
} }
|
|
1076
890
|
};
|
|
1077
891
|
}
|
|
1078
|
-
function bytesToArrayBuffer(
|
|
1079
|
-
return
|
|
892
|
+
function bytesToArrayBuffer(e) {
|
|
893
|
+
return e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
|
|
1080
894
|
}
|
|
1081
|
-
function hasBufferedPdfBridge(
|
|
1082
|
-
return typeof
|
|
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(
|
|
1085
|
-
if (!hasBufferedPdfBridge(
|
|
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(
|
|
1088
|
-
return new TextEncoder().encode(
|
|
901
|
+
function utf8Bytes(e) {
|
|
902
|
+
return new TextEncoder().encode(e);
|
|
1089
903
|
}
|
|
1090
|
-
function writePdfBridgeInput(
|
|
1091
|
-
|
|
1092
|
-
let
|
|
1093
|
-
for (
|
|
1094
|
-
|
|
1095
|
-
let
|
|
1096
|
-
|
|
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(
|
|
913
|
+
function readPdfBridgeOutput(e, t) {
|
|
1102
914
|
try {
|
|
1103
|
-
|
|
1104
|
-
if (!Number.isSafeInteger(
|
|
1105
|
-
checkBrowserOutput(
|
|
1106
|
-
|
|
1107
|
-
for (let
|
|
1108
|
-
|
|
1109
|
-
if (!Number.isInteger(
|
|
1110
|
-
for (let
|
|
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
|
|
924
|
+
return r;
|
|
1113
925
|
} finally {
|
|
1114
|
-
|
|
926
|
+
e.clear_pdf_bridge_output();
|
|
1115
927
|
}
|
|
1116
928
|
}
|
|
1117
|
-
function decodeXmlEntities(
|
|
1118
|
-
|
|
1119
|
-
return str.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, "\"").replace(/'/g, "'").replace(/&#x([0-9a-fA-F]+);/g, (_, hex) => String.fromCodePoint(parseInt(hex, 16))).replace(/&#(\d+);/g, (_, dec) => String.fromCodePoint(parseInt(dec, 10))).replace(/&/g, "&");
|
|
929
|
+
function decodeXmlEntities(e) {
|
|
930
|
+
return e.includes("&") ? e.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, "\"").replace(/'/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(/&/g, "&") : e;
|
|
1120
931
|
}
|
|
1121
|
-
function containsNonLatinCodepoint(
|
|
1122
|
-
for (
|
|
1123
|
-
return
|
|
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(
|
|
1126
|
-
return
|
|
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(
|
|
1129
|
-
|
|
1130
|
-
return (
|
|
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(
|
|
1133
|
-
|
|
943
|
+
function collectEmojiBitmapFallbackCodepoints(e) {
|
|
944
|
+
let t = /* @__PURE__ */ new Set();
|
|
1134
945
|
try {
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
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 (
|
|
1152
|
-
if (isResourcePolicyError(
|
|
958
|
+
} catch (e) {
|
|
959
|
+
if (isResourcePolicyError(e)) throw e;
|
|
1153
960
|
return [];
|
|
1154
961
|
}
|
|
1155
|
-
return [...
|
|
962
|
+
return [...t].sort((e, t) => e - t);
|
|
1156
963
|
}
|
|
1157
|
-
function pptxHasUnicodeText(
|
|
964
|
+
function pptxHasUnicodeText(e) {
|
|
1158
965
|
try {
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
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 (
|
|
1169
|
-
if (isResourcePolicyError(
|
|
1170
|
-
return
|
|
972
|
+
} catch (e) {
|
|
973
|
+
if (isResourcePolicyError(e)) throw e;
|
|
974
|
+
return !1;
|
|
1171
975
|
}
|
|
1172
|
-
return
|
|
1173
|
-
}
|
|
1174
|
-
async function resolveUnicodeFallbackFont(
|
|
1175
|
-
|
|
1176
|
-
if (!
|
|
1177
|
-
if (
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
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 (!
|
|
1186
|
-
|
|
1187
|
-
|
|
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
|
-
|
|
1194
|
-
|
|
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
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
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(
|
|
1208
|
-
|
|
1209
|
-
if (!
|
|
1210
|
-
if (
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
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 (!
|
|
1219
|
-
|
|
1220
|
-
|
|
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
|
-
|
|
1227
|
-
|
|
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
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
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(
|
|
1241
|
-
|
|
1030
|
+
async function instantiatePdfWasm(e) {
|
|
1031
|
+
let t = {
|
|
1242
1032
|
builtins: ["js-string"],
|
|
1243
1033
|
importedStringConstants: "_"
|
|
1244
|
-
};
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
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
|
-
|
|
1252
|
-
|
|
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(
|
|
1263
|
-
if (
|
|
1264
|
-
|
|
1265
|
-
|
|
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
|
-
|
|
1270
|
-
if (
|
|
1271
|
-
if (
|
|
1272
|
-
if (
|
|
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
|
|
1059
|
+
await F;
|
|
1275
1060
|
} catch {}
|
|
1276
|
-
return loadPdfWasm(
|
|
1061
|
+
return loadPdfWasm(e);
|
|
1277
1062
|
}
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
...
|
|
1281
|
-
wasmUrl:
|
|
1063
|
+
let n = (async () => {
|
|
1064
|
+
let n = (await instantiatePdfWasm({
|
|
1065
|
+
...e,
|
|
1066
|
+
wasmUrl: t
|
|
1282
1067
|
})).instance.exports;
|
|
1283
|
-
|
|
1284
|
-
assertPdfWasmApi(exports);
|
|
1285
|
-
return exports;
|
|
1068
|
+
return n._start(), assertPdfWasmApi(n), n;
|
|
1286
1069
|
})();
|
|
1287
|
-
|
|
1288
|
-
pdfWasmLoadPromise = pending;
|
|
1070
|
+
P = t, F = n;
|
|
1289
1071
|
try {
|
|
1290
|
-
|
|
1291
|
-
|
|
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
|
-
|
|
1298
|
-
pdfWasmLoadSource = null;
|
|
1299
|
-
pdfWasmLoadPromise = null;
|
|
1300
|
-
}
|
|
1075
|
+
F === n && (P = null, F = null);
|
|
1301
1076
|
}
|
|
1302
1077
|
}
|
|
1303
|
-
async function serializePdfWasmConversion(
|
|
1304
|
-
|
|
1305
|
-
|
|
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
|
|
1082
|
+
return await n;
|
|
1309
1083
|
} finally {
|
|
1310
|
-
|
|
1084
|
+
I.get(e) === r && I.delete(e);
|
|
1311
1085
|
}
|
|
1312
1086
|
}
|
|
1313
|
-
function createBufferedPdfBridge(
|
|
1087
|
+
function createBufferedPdfBridge(e) {
|
|
1314
1088
|
return {
|
|
1315
|
-
supportsRegularFonts: typeof
|
|
1316
|
-
supportsEmojiBitmaps: typeof
|
|
1317
|
-
supportsMathFallback: typeof
|
|
1318
|
-
clearRegularFonts: () =>
|
|
1319
|
-
clearEmojiBitmaps: () =>
|
|
1320
|
-
clearMathFallback: () =>
|
|
1321
|
-
registerRegularFont: (
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
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: (
|
|
1334
|
-
|
|
1335
|
-
writePdfBridgeInput(
|
|
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: (
|
|
1339
|
-
|
|
1340
|
-
writePdfBridgeInput(
|
|
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: (
|
|
1344
|
-
convert: ({ buffer, fallbackFont, licensePayload, runtimePayload, watermarkPayload }) => {
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
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
|
-
|
|
1360
|
-
if (!Number.isSafeInteger(
|
|
1361
|
-
return readPdfBridgeOutput(
|
|
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(
|
|
1366
|
-
|
|
1367
|
-
if (!
|
|
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
|
|
1370
|
-
supportsEmojiBitmaps: typeof
|
|
1371
|
-
supportsMathFallback: typeof
|
|
1372
|
-
clearRegularFonts: () =>
|
|
1373
|
-
clearEmojiBitmaps: () =>
|
|
1374
|
-
clearMathFallback: () =>
|
|
1375
|
-
registerRegularFont: (
|
|
1376
|
-
|
|
1377
|
-
|
|
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: (
|
|
1381
|
-
registerMathFallback: (
|
|
1382
|
-
setOfficeFontFallbacks: (
|
|
1383
|
-
convert: ({ buffer, fallbackFont, licensePayload, runtimePayload, watermarkPayload }) => {
|
|
1384
|
-
|
|
1385
|
-
if (
|
|
1386
|
-
|
|
1387
|
-
|
|
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
|
-
|
|
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(
|
|
1399
|
-
return hasBufferedPdfBridge(
|
|
1400
|
-
}
|
|
1401
|
-
function resetPdfBridgeState(
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
typeface
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
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(
|
|
1426
|
-
return
|
|
1427
|
-
}
|
|
1428
|
-
function emojiBitmapFallbackFont(
|
|
1429
|
-
return (typeof
|
|
1430
|
-
}
|
|
1431
|
-
function emojiBitmapFallbackPixelSize(
|
|
1432
|
-
|
|
1433
|
-
return Number.isFinite(
|
|
1434
|
-
}
|
|
1435
|
-
function emojiPresentationText(
|
|
1436
|
-
|
|
1437
|
-
return
|
|
1438
|
-
}
|
|
1439
|
-
function canvasToBlob(
|
|
1440
|
-
return new Promise((
|
|
1441
|
-
}
|
|
1442
|
-
function cropTransparentCanvas(
|
|
1443
|
-
|
|
1444
|
-
if (!
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
let
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
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:
|
|
1489
|
-
height:
|
|
1490
|
-
data: new Uint8Array(await
|
|
1214
|
+
width: a.width,
|
|
1215
|
+
height: a.height,
|
|
1216
|
+
data: new Uint8Array(await o.arrayBuffer())
|
|
1491
1217
|
};
|
|
1492
1218
|
}
|
|
1493
|
-
async function registerEmojiBitmapFallbacks(
|
|
1494
|
-
if (!emojiBitmapFallbackEnabled(
|
|
1495
|
-
|
|
1496
|
-
if (
|
|
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
|
-
|
|
1499
|
-
for (
|
|
1500
|
-
|
|
1501
|
-
|
|
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 (
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
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 (
|
|
1517
|
-
|
|
1518
|
-
if (
|
|
1519
|
-
|
|
1520
|
-
if (
|
|
1521
|
-
family:
|
|
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
|
-
|
|
1527
|
-
|
|
1528
|
-
family:
|
|
1529
|
-
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(
|
|
1534
|
-
if (!
|
|
1535
|
-
|
|
1536
|
-
|
|
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(
|
|
1539
|
-
return
|
|
1262
|
+
function watermarksJson(e) {
|
|
1263
|
+
return e?.watermarks?.length ? JSON.stringify(e.watermarks) : "";
|
|
1540
1264
|
}
|
|
1541
|
-
function licenseJson(
|
|
1542
|
-
|
|
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
|
|
1269
|
+
return typeof location < "u" ? location.origin : "";
|
|
1547
1270
|
}
|
|
1548
1271
|
function runtimeHostname() {
|
|
1549
|
-
return typeof location
|
|
1272
|
+
return typeof location < "u" ? location.hostname : "";
|
|
1550
1273
|
}
|
|
1551
|
-
function licenseRuntimeJson(
|
|
1274
|
+
function licenseRuntimeJson(e) {
|
|
1552
1275
|
return JSON.stringify({
|
|
1553
1276
|
feature: "pdf-export",
|
|
1554
|
-
nowUnixMs:
|
|
1555
|
-
origin:
|
|
1556
|
-
hostname:
|
|
1557
|
-
deploymentId:
|
|
1558
|
-
sdkVersion:
|
|
1559
|
-
inputBytes:
|
|
1560
|
-
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
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
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(
|
|
1578
|
-
await
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
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(
|
|
1307
|
+
resetPdfBridgeState(a);
|
|
1596
1308
|
}
|
|
1597
|
-
|
|
1598
|
-
if (
|
|
1599
|
-
|
|
1600
|
-
|
|
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 (
|
|
1605
|
-
|
|
1606
|
-
throw
|
|
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
|
-
|
|
1609
|
-
checkBrowserOutput(
|
|
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
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
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
|
-
}, [
|
|
1634
|
-
} catch (
|
|
1635
|
-
if (
|
|
1636
|
-
|
|
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(
|
|
1343
|
+
error: serializeWorkerError(e)
|
|
1640
1344
|
});
|
|
1641
1345
|
} finally {
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
id,
|
|
1346
|
+
U.delete(n), a.signal.aborted && V.postMessage({
|
|
1347
|
+
id: n,
|
|
1645
1348
|
status: "error",
|
|
1646
|
-
error: serializeWorkerError(
|
|
1349
|
+
error: serializeWorkerError(a.signal.reason)
|
|
1647
1350
|
});
|
|
1648
1351
|
}
|
|
1649
1352
|
}
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
if (
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
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(
|
|
1360
|
+
error: serializeWorkerError(e.signal.reason)
|
|
1660
1361
|
});
|
|
1661
1362
|
return;
|
|
1662
1363
|
}
|
|
1663
|
-
if (
|
|
1664
|
-
|
|
1364
|
+
if (t.kind === "convert") {
|
|
1365
|
+
U.set(t.id, new AbortController());
|
|
1665
1366
|
try {
|
|
1666
|
-
|
|
1667
|
-
if (
|
|
1668
|
-
|
|
1669
|
-
|
|
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(
|
|
1677
|
-
} catch (
|
|
1678
|
-
|
|
1679
|
-
|
|
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(
|
|
1381
|
+
error: serializeWorkerError(e)
|
|
1683
1382
|
});
|
|
1684
1383
|
}
|
|
1685
1384
|
return;
|
|
1686
1385
|
}
|
|
1687
|
-
|
|
1688
|
-
|
|
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
|