ooxml-core 1.37.1 → 1.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/automation/index.cjs +207 -207
- package/dist/automation/index.mjs +207 -207
- package/dist/{chunk-M2DFN3SP.mjs → chunk-XBIZIBTJ.mjs} +507 -10
- package/dist/collab/merge-values.d.ts +14 -0
- package/dist/collab/merge-values.d.ts.map +1 -0
- package/dist/docx/embedded.cjs +476 -474
- package/dist/docx/embedded.mjs +476 -474
- package/dist/docx/index.cjs +1075 -719
- package/dist/docx/index.d.ts +1 -0
- package/dist/docx/index.d.ts.map +1 -1
- package/dist/docx/index.mjs +1075 -720
- package/dist/docx/layout/index.cjs +4 -0
- package/dist/docx/layout/index.mjs +4 -0
- package/dist/docx/load/index.cjs +164 -164
- package/dist/docx/load/index.mjs +164 -164
- package/dist/docx/merge-snapshots.d.ts +9 -0
- package/dist/docx/merge-snapshots.d.ts.map +1 -0
- package/dist/docx/ui/index.cjs +155 -155
- package/dist/docx/ui/index.mjs +155 -155
- package/dist/embedding/index.cjs +207 -0
- package/dist/embedding/index.d.ts +3 -0
- package/dist/embedding/index.d.ts.map +1 -1
- package/dist/embedding/index.mjs +205 -1
- package/dist/embedding/onedrive/client.d.ts +4 -0
- package/dist/embedding/onedrive/client.d.ts.map +1 -0
- package/dist/embedding/onedrive/index.cjs +617 -0
- package/dist/embedding/onedrive/index.d.ts +6 -0
- package/dist/embedding/onedrive/index.d.ts.map +1 -0
- package/dist/embedding/onedrive/index.mjs +611 -0
- package/dist/embedding/onedrive/metadata.d.ts +6 -0
- package/dist/embedding/onedrive/metadata.d.ts.map +1 -0
- package/dist/embedding/onedrive/requests.d.ts +8 -0
- package/dist/embedding/onedrive/requests.d.ts.map +1 -0
- package/dist/embedding/onedrive/session.d.ts +4 -0
- package/dist/embedding/onedrive/session.d.ts.map +1 -0
- package/dist/embedding/onedrive/transport.d.ts +9 -0
- package/dist/embedding/onedrive/transport.d.ts.map +1 -0
- package/dist/embedding/onedrive/types.d.ts +86 -0
- package/dist/embedding/onedrive/types.d.ts.map +1 -0
- package/dist/embedding/onedrive/upload.d.ts +3 -0
- package/dist/embedding/onedrive/upload.d.ts.map +1 -0
- package/dist/embedding/storage-merge.d.ts +8 -0
- package/dist/embedding/storage-merge.d.ts.map +1 -0
- package/dist/embedding/storage-session.d.ts +7 -0
- package/dist/embedding/storage-session.d.ts.map +1 -0
- package/dist/embedding/versioned-storage.d.ts +67 -0
- package/dist/embedding/versioned-storage.d.ts.map +1 -0
- package/dist/index.cjs +1013 -340
- package/dist/index.mjs +1013 -340
- package/dist/opc/index.cjs +680 -216
- package/dist/opc/index.d.ts +1 -0
- package/dist/opc/index.d.ts.map +1 -1
- package/dist/opc/index.mjs +680 -217
- package/dist/opc/merge-snapshots.d.ts +26 -0
- package/dist/opc/merge-snapshots.d.ts.map +1 -0
- package/dist/pptx/automation/index.cjs +20 -6
- package/dist/pptx/automation/index.d.ts +1 -1
- package/dist/pptx/automation/index.mjs +1 -1
- package/dist/pptx/chunks/{index-DC5m1m_8.d.ts → index-bgj0Ztnq.d.ts} +16 -2
- package/dist/pptx/chunks/index-bgj0Ztnq.d.ts.map +1 -0
- package/dist/pptx/cli/index.cjs +20 -6
- package/dist/pptx/converter/index.cjs +7 -0
- package/dist/pptx/editor/render/find-replace.d.ts +1 -1
- package/dist/pptx/index.cjs +1687 -1159
- package/dist/pptx/index.d.ts +2 -2
- package/dist/pptx/index.mjs +1 -1
- package/dist/teams/index.cjs +215 -201
- package/dist/teams/index.mjs +215 -201
- package/dist/text/index.cjs +193 -0
- package/dist/text/index.d.ts +1 -0
- package/dist/text/index.d.ts.map +1 -1
- package/dist/text/index.mjs +193 -1
- package/dist/text/merge-three-way.d.ts +9 -0
- package/dist/text/merge-three-way.d.ts.map +1 -0
- package/dist/visio/collab/index.cjs +226 -7
- package/dist/visio/collab/index.d.ts +1 -0
- package/dist/visio/collab/index.d.ts.map +1 -1
- package/dist/visio/collab/index.mjs +225 -7
- package/dist/visio/collab/merge-snapshots.d.ts +14 -0
- package/dist/visio/collab/merge-snapshots.d.ts.map +1 -0
- package/dist/visio/index.cjs +9 -9
- package/dist/visio/index.mjs +9 -9
- package/dist/visio/ui/index.cjs +9 -9
- package/dist/visio/ui/index.mjs +9 -9
- package/dist/xlsx/collab/index.cjs +49966 -507
- package/dist/xlsx/collab/index.d.ts +1 -0
- package/dist/xlsx/collab/index.d.ts.map +1 -1
- package/dist/xlsx/collab/index.mjs +49961 -507
- package/dist/xlsx/collab/merge-residual.d.ts +16 -0
- package/dist/xlsx/collab/merge-residual.d.ts.map +1 -0
- package/dist/xlsx/collab/merge-snapshots.d.ts +8 -0
- package/dist/xlsx/collab/merge-snapshots.d.ts.map +1 -0
- package/dist/xlsx/index.cjs +202 -202
- package/dist/xlsx/index.mjs +202 -202
- package/dist/xlsx/load/index.cjs +155 -155
- package/dist/xlsx/load/index.mjs +155 -155
- package/dist/xlsx/ui/index.cjs +202 -202
- package/dist/xlsx/ui/index.mjs +202 -202
- package/dist/xml/index.cjs +390 -22
- package/dist/xml/index.d.ts +1 -0
- package/dist/xml/index.d.ts.map +1 -1
- package/dist/xml/index.mjs +390 -23
- package/dist/xml/merge-three-way.d.ts +16 -0
- package/dist/xml/merge-three-way.d.ts.map +1 -0
- package/package.json +6 -1
- package/dist/pptx/chunks/index-DC5m1m_8.d.ts.map +0 -1
package/dist/docx/embedded.mjs
CHANGED
|
@@ -1,6 +1,161 @@
|
|
|
1
1
|
import { XMLSerializer, DOMParser } from '@xmldom/xmldom';
|
|
2
2
|
import JSZip from 'jszip';
|
|
3
3
|
|
|
4
|
+
// text/text-diff.ts
|
|
5
|
+
var isLowSurrogate = (text, at) => {
|
|
6
|
+
const code = text.charCodeAt(at);
|
|
7
|
+
return code >= 56320 && code <= 57343;
|
|
8
|
+
};
|
|
9
|
+
function shortestEdit(n, m, same6, maxEdits) {
|
|
10
|
+
const max = Math.min(n + m, maxEdits);
|
|
11
|
+
const offset = max + 1;
|
|
12
|
+
const v = new Int32Array(2 * max + 3);
|
|
13
|
+
const trace = [];
|
|
14
|
+
for (let d = 0; d <= max; d++) {
|
|
15
|
+
for (let k = -d; k <= d; k += 2) {
|
|
16
|
+
const down = k === -d || k !== d && v[offset + k - 1] < v[offset + k + 1];
|
|
17
|
+
let x = down ? v[offset + k + 1] : v[offset + k - 1] + 1;
|
|
18
|
+
let y = x - k;
|
|
19
|
+
while (x < n && y < m && same6(x, y)) {
|
|
20
|
+
x++;
|
|
21
|
+
y++;
|
|
22
|
+
}
|
|
23
|
+
v[offset + k] = x;
|
|
24
|
+
if (x >= n && y >= m) return backtrack(trace, n, m, d);
|
|
25
|
+
}
|
|
26
|
+
trace.push(v.slice(offset - d, offset + d + 1));
|
|
27
|
+
}
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
function backtrack(trace, n, m, d) {
|
|
31
|
+
const edits = [];
|
|
32
|
+
let x = n;
|
|
33
|
+
let y = m;
|
|
34
|
+
for (let step = d; step > 0; step--) {
|
|
35
|
+
const previous = trace[step - 1];
|
|
36
|
+
const at = (k2) => previous[k2 + step - 1];
|
|
37
|
+
const k = x - y;
|
|
38
|
+
const down = k === -step || k !== step && at(k - 1) < at(k + 1);
|
|
39
|
+
const before = down ? k + 1 : k - 1;
|
|
40
|
+
const startX = at(before);
|
|
41
|
+
const startY = startX - before;
|
|
42
|
+
edits.push(down ? [startX, startY, true] : [startX, startY, false]);
|
|
43
|
+
x = startX;
|
|
44
|
+
y = startY;
|
|
45
|
+
}
|
|
46
|
+
return edits.reverse();
|
|
47
|
+
}
|
|
48
|
+
function changesOf(edits) {
|
|
49
|
+
const changes = [];
|
|
50
|
+
for (const [x, y, inserts] of edits) {
|
|
51
|
+
const last = changes.at(-1);
|
|
52
|
+
if (last && last.fromEnd === x && last.toEnd === y) {
|
|
53
|
+
if (inserts) last.toEnd++;
|
|
54
|
+
else last.fromEnd++;
|
|
55
|
+
} else
|
|
56
|
+
changes.push({
|
|
57
|
+
fromStart: x,
|
|
58
|
+
fromEnd: inserts ? x : x + 1,
|
|
59
|
+
toStart: y,
|
|
60
|
+
toEnd: inserts ? y + 1 : y
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return changes;
|
|
64
|
+
}
|
|
65
|
+
function characterChanges(a2, b, maxEdits) {
|
|
66
|
+
const edits = shortestEdit(
|
|
67
|
+
a2.length,
|
|
68
|
+
b.length,
|
|
69
|
+
(x, y) => a2.charCodeAt(x) === b.charCodeAt(y),
|
|
70
|
+
maxEdits
|
|
71
|
+
);
|
|
72
|
+
return edits && changesOf(edits);
|
|
73
|
+
}
|
|
74
|
+
var TOKEN = /[\p{L}\p{N}\p{M}]+|\s+|[\s\S]/gu;
|
|
75
|
+
function tokensOf(text, ids) {
|
|
76
|
+
const tokens = [];
|
|
77
|
+
const starts = [];
|
|
78
|
+
for (const match of text.matchAll(TOKEN)) {
|
|
79
|
+
let id = ids.get(match[0]);
|
|
80
|
+
if (id === void 0) ids.set(match[0], id = ids.size);
|
|
81
|
+
tokens.push(id);
|
|
82
|
+
starts.push(match.index);
|
|
83
|
+
}
|
|
84
|
+
starts.push(text.length);
|
|
85
|
+
return { tokens, starts };
|
|
86
|
+
}
|
|
87
|
+
function tokenChanges(a2, b, maxEdits) {
|
|
88
|
+
const ids = /* @__PURE__ */ new Map();
|
|
89
|
+
const from = tokensOf(a2, ids);
|
|
90
|
+
const to = tokensOf(b, ids);
|
|
91
|
+
const edits = shortestEdit(
|
|
92
|
+
from.tokens.length,
|
|
93
|
+
to.tokens.length,
|
|
94
|
+
(x, y) => from.tokens[x] === to.tokens[y],
|
|
95
|
+
maxEdits
|
|
96
|
+
);
|
|
97
|
+
if (!edits) return void 0;
|
|
98
|
+
let budget = maxEdits;
|
|
99
|
+
return changesOf(edits).flatMap((stretch) => {
|
|
100
|
+
const change = {
|
|
101
|
+
fromStart: from.starts[stretch.fromStart],
|
|
102
|
+
fromEnd: from.starts[stretch.fromEnd],
|
|
103
|
+
toStart: to.starts[stretch.toStart],
|
|
104
|
+
toEnd: to.starts[stretch.toEnd]
|
|
105
|
+
};
|
|
106
|
+
const inner = change.fromEnd > change.fromStart && change.toEnd > change.toStart ? characterChanges(
|
|
107
|
+
a2.slice(change.fromStart, change.fromEnd),
|
|
108
|
+
b.slice(change.toStart, change.toEnd),
|
|
109
|
+
budget
|
|
110
|
+
) : void 0;
|
|
111
|
+
if (!inner) return [change];
|
|
112
|
+
for (const found of inner)
|
|
113
|
+
budget -= found.fromEnd - found.fromStart + found.toEnd - found.toStart;
|
|
114
|
+
return inner.map((found) => ({
|
|
115
|
+
fromStart: found.fromStart + change.fromStart,
|
|
116
|
+
fromEnd: found.fromEnd + change.fromStart,
|
|
117
|
+
toStart: found.toStart + change.toStart,
|
|
118
|
+
toEnd: found.toEnd + change.toStart
|
|
119
|
+
}));
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function diffText(from, to, maxEdits = 500) {
|
|
123
|
+
let start = 0;
|
|
124
|
+
while (start < from.length && start < to.length && from.charCodeAt(start) === to.charCodeAt(start))
|
|
125
|
+
start++;
|
|
126
|
+
let end = 0;
|
|
127
|
+
while (end < from.length - start && end < to.length - start && from.charCodeAt(from.length - 1 - end) === to.charCodeAt(to.length - 1 - end))
|
|
128
|
+
end++;
|
|
129
|
+
const a2 = from.slice(start, from.length - end);
|
|
130
|
+
const b = to.slice(start, to.length - end);
|
|
131
|
+
if (!a2.length && !b.length) return [];
|
|
132
|
+
const found = a2.length && b.length ? characterChanges(a2, b, maxEdits) ?? tokenChanges(a2, b, maxEdits) : void 0;
|
|
133
|
+
const changes = found ?? [{ fromStart: 0, fromEnd: a2.length, toStart: 0, toEnd: b.length }];
|
|
134
|
+
const result = [];
|
|
135
|
+
for (const change of changes) {
|
|
136
|
+
const placed = {
|
|
137
|
+
fromStart: change.fromStart + start,
|
|
138
|
+
fromEnd: change.fromEnd + start,
|
|
139
|
+
toStart: change.toStart + start,
|
|
140
|
+
toEnd: change.toEnd + start
|
|
141
|
+
};
|
|
142
|
+
if (placed.fromStart > 0 && placed.toStart > 0 && (isLowSurrogate(from, placed.fromStart) || isLowSurrogate(to, placed.toStart))) {
|
|
143
|
+
placed.fromStart--;
|
|
144
|
+
placed.toStart--;
|
|
145
|
+
}
|
|
146
|
+
if (isLowSurrogate(from, placed.fromEnd) || isLowSurrogate(to, placed.toEnd)) {
|
|
147
|
+
placed.fromEnd++;
|
|
148
|
+
placed.toEnd++;
|
|
149
|
+
}
|
|
150
|
+
const last = result.at(-1);
|
|
151
|
+
if (last && placed.fromStart <= last.fromEnd) {
|
|
152
|
+
last.fromEnd = Math.max(last.fromEnd, placed.fromEnd);
|
|
153
|
+
last.toEnd = Math.max(last.toEnd, placed.toEnd);
|
|
154
|
+
} else result.push(placed);
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
|
|
4
159
|
// xml/namespaces.ts
|
|
5
160
|
var NS = {
|
|
6
161
|
/** WordprocessingML main. */
|
|
@@ -70,6 +225,8 @@ var NS = {
|
|
|
70
225
|
/** XML itself (`xml:space`). */
|
|
71
226
|
xml: "http://www.w3.org/XML/1998/namespace"
|
|
72
227
|
};
|
|
228
|
+
|
|
229
|
+
// xml/xml.ts
|
|
73
230
|
var DEFAULT_XML_LIMITS = {
|
|
74
231
|
maxDepth: 512,
|
|
75
232
|
maxNodes: 5e6
|
|
@@ -155,29 +312,299 @@ function parseXml(xml, options = {}) {
|
|
|
155
312
|
{ cause: error }
|
|
156
313
|
);
|
|
157
314
|
}
|
|
158
|
-
if (parseError || !parsed.documentElement)
|
|
159
|
-
throw new Error(`Invalid ${label} XML: ${parseError || "missing root element"}`);
|
|
160
|
-
if (CRLF_DECLARATION.test(xml)) crlfDeclarations.add(parsed);
|
|
161
|
-
return parsed;
|
|
315
|
+
if (parseError || !parsed.documentElement)
|
|
316
|
+
throw new Error(`Invalid ${label} XML: ${parseError || "missing root element"}`);
|
|
317
|
+
if (CRLF_DECLARATION.test(xml)) crlfDeclarations.add(parsed);
|
|
318
|
+
return parsed;
|
|
319
|
+
}
|
|
320
|
+
var buildXml = (node) => {
|
|
321
|
+
const xml = new XMLSerializer().serializeToString(node);
|
|
322
|
+
return crlfDeclarations.has(node) ? xml.replace(/^(<\?xml[^>]*\?>)\n/, "$1\r\n") : xml;
|
|
323
|
+
};
|
|
324
|
+
var isElement = (node) => node.nodeType === 1;
|
|
325
|
+
var elements = (parent) => Array.from(parent.childNodes).filter(isElement);
|
|
326
|
+
var textContent = (element4) => element4.textContent ?? "";
|
|
327
|
+
var makeNS = (doc, ns, qualified) => doc.createElementNS(ns, qualified);
|
|
328
|
+
function named(element4, local, ns, lenient = true) {
|
|
329
|
+
if (!element4 || element4.localName !== local) return false;
|
|
330
|
+
return element4.namespaceURI === ns || lenient && !element4.namespaceURI;
|
|
331
|
+
}
|
|
332
|
+
var children = (parent, local, ns, lenient = true) => elements(parent).filter((element4) => named(element4, local, ns, lenient));
|
|
333
|
+
var first = (parent, local, ns, lenient = true) => parent ? children(parent, local, ns, lenient)[0] : void 0;
|
|
334
|
+
function attr(element4, local, ns, prefix2) {
|
|
335
|
+
return element4?.getAttributeNS(ns, local) ?? element4?.getAttribute(`${prefix2}:${local}`) ?? void 0;
|
|
336
|
+
}
|
|
337
|
+
var relAttr = (element4, local) => attr(element4, local, NS.r, "r");
|
|
338
|
+
var DEFAULT_ZIP_LIMITS = {
|
|
339
|
+
maxInputBytes: 100 * 1024 * 1024,
|
|
340
|
+
maxEntries: 1e4,
|
|
341
|
+
maxEntryBytes: 100 * 1024 * 1024,
|
|
342
|
+
maxTotalBytes: 100 * 1024 * 1024
|
|
343
|
+
};
|
|
344
|
+
var ZipLimitError = class extends Error {
|
|
345
|
+
code = "ZIP_BOMB";
|
|
346
|
+
limit;
|
|
347
|
+
/** The check that failed (absent when the error was built without one). */
|
|
348
|
+
kind;
|
|
349
|
+
/** The observed value, when known (a lower bound for a size found while inflating). */
|
|
350
|
+
actual;
|
|
351
|
+
constructor(message, details) {
|
|
352
|
+
super(message);
|
|
353
|
+
this.name = "ZipLimitError";
|
|
354
|
+
this.limit = details.limit;
|
|
355
|
+
this.kind = details.kind;
|
|
356
|
+
this.actual = details.actual;
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
var mib = (bytes) => Math.round(bytes / 1048576);
|
|
360
|
+
function isSafePartName(name) {
|
|
361
|
+
if (name.includes("\0") || name.includes("\\")) return false;
|
|
362
|
+
if (/^[A-Za-z]:/u.test(name)) return false;
|
|
363
|
+
const body = name.startsWith("/") ? name.slice(1) : name;
|
|
364
|
+
if (body.startsWith("/")) return false;
|
|
365
|
+
return !body.split("/").some((segment) => segment === "..");
|
|
366
|
+
}
|
|
367
|
+
function declaredEntrySize(entry2) {
|
|
368
|
+
const data = entry2._data;
|
|
369
|
+
const size = Number(data?.uncompressedSize ?? 0);
|
|
370
|
+
return Number.isFinite(size) && size > 0 ? size : 0;
|
|
371
|
+
}
|
|
372
|
+
function resolveLimits(limits) {
|
|
373
|
+
const create2 = limits.createError;
|
|
374
|
+
return {
|
|
375
|
+
maxEntries: limits.maxEntries ?? DEFAULT_ZIP_LIMITS.maxEntries,
|
|
376
|
+
maxEntryBytes: limits.maxEntryBytes ?? DEFAULT_ZIP_LIMITS.maxEntryBytes,
|
|
377
|
+
maxTotalBytes: limits.maxTotalBytes ?? DEFAULT_ZIP_LIMITS.maxTotalBytes,
|
|
378
|
+
label: limits.label ?? "ZIP",
|
|
379
|
+
fail: (message, limit, kind, actual) => create2 ? create2(message, { limit, kind, actual }) : new ZipLimitError(message, { limit, kind, actual })
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
async function inflateEntryGuarded(entry2, alreadyRead, limits) {
|
|
383
|
+
const chunks = [];
|
|
384
|
+
let size = 0;
|
|
385
|
+
for await (const chunk of streamEntryGuarded(entry2, alreadyRead, limits)) {
|
|
386
|
+
chunks.push(chunk);
|
|
387
|
+
size += chunk.byteLength;
|
|
388
|
+
}
|
|
389
|
+
if (chunks.length === 1 && chunks[0]) return chunks[0];
|
|
390
|
+
const out = new Uint8Array(size);
|
|
391
|
+
let offset = 0;
|
|
392
|
+
for (const chunk of chunks) {
|
|
393
|
+
out.set(chunk, offset);
|
|
394
|
+
offset += chunk.byteLength;
|
|
395
|
+
}
|
|
396
|
+
return out;
|
|
397
|
+
}
|
|
398
|
+
var AHEAD = 8;
|
|
399
|
+
async function* streamEntryGuarded(entry2, alreadyRead, limits) {
|
|
400
|
+
const r = resolveLimits(limits);
|
|
401
|
+
const declared = declaredEntrySize(entry2);
|
|
402
|
+
const stream = entry2.internalStream("uint8array");
|
|
403
|
+
const queue = [];
|
|
404
|
+
let size = 0;
|
|
405
|
+
let ended = false;
|
|
406
|
+
let stopped = false;
|
|
407
|
+
let failure;
|
|
408
|
+
let paused = false;
|
|
409
|
+
let wake;
|
|
410
|
+
const pause = () => {
|
|
411
|
+
paused = true;
|
|
412
|
+
stream.pause();
|
|
413
|
+
};
|
|
414
|
+
const resume = () => {
|
|
415
|
+
if (!paused || stopped) return;
|
|
416
|
+
paused = false;
|
|
417
|
+
stream.resume();
|
|
418
|
+
};
|
|
419
|
+
const fail = (error) => {
|
|
420
|
+
failure ??= error;
|
|
421
|
+
stopped = true;
|
|
422
|
+
queue.length = 0;
|
|
423
|
+
pause();
|
|
424
|
+
wake?.();
|
|
425
|
+
};
|
|
426
|
+
stream.on("data", (chunk) => {
|
|
427
|
+
if (stopped) return pause();
|
|
428
|
+
size += chunk.byteLength;
|
|
429
|
+
if (size > declared || size > r.maxEntryBytes)
|
|
430
|
+
return fail(
|
|
431
|
+
r.fail(
|
|
432
|
+
`${r.label} part ${entry2.name} inflates past its declared size`,
|
|
433
|
+
r.maxEntryBytes,
|
|
434
|
+
size > declared ? "declaredSize" : "maxEntryBytes",
|
|
435
|
+
size
|
|
436
|
+
)
|
|
437
|
+
);
|
|
438
|
+
if (alreadyRead + size > r.maxTotalBytes)
|
|
439
|
+
return fail(
|
|
440
|
+
r.fail(
|
|
441
|
+
`${r.label} package exceeds the ${mib(r.maxTotalBytes)} MiB uncompressed content limit`,
|
|
442
|
+
r.maxTotalBytes,
|
|
443
|
+
"maxTotalBytes",
|
|
444
|
+
alreadyRead + size
|
|
445
|
+
)
|
|
446
|
+
);
|
|
447
|
+
queue.push(chunk);
|
|
448
|
+
if (queue.length >= AHEAD) pause();
|
|
449
|
+
wake?.();
|
|
450
|
+
});
|
|
451
|
+
stream.on("error", (error) => fail(error));
|
|
452
|
+
stream.on("end", () => {
|
|
453
|
+
ended = true;
|
|
454
|
+
wake?.();
|
|
455
|
+
});
|
|
456
|
+
stream.resume();
|
|
457
|
+
try {
|
|
458
|
+
for (; ; ) {
|
|
459
|
+
if (failure) throw failure;
|
|
460
|
+
const chunk = queue.shift();
|
|
461
|
+
if (chunk) {
|
|
462
|
+
if (queue.length < AHEAD / 2) resume();
|
|
463
|
+
yield chunk;
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
if (ended) return;
|
|
467
|
+
await new Promise((resolve) => {
|
|
468
|
+
wake = resolve;
|
|
469
|
+
resume();
|
|
470
|
+
});
|
|
471
|
+
wake = void 0;
|
|
472
|
+
}
|
|
473
|
+
} finally {
|
|
474
|
+
stopped = true;
|
|
475
|
+
if (!ended) pause();
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
function toBase64(bytes) {
|
|
479
|
+
let binary = "";
|
|
480
|
+
for (let i = 0; i < bytes.length; i += 32768)
|
|
481
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + 32768));
|
|
482
|
+
return btoa(binary);
|
|
483
|
+
}
|
|
484
|
+
function guardZip(zip, limits = {}) {
|
|
485
|
+
const r = resolveLimits(limits);
|
|
486
|
+
const entries = Object.values(zip.files);
|
|
487
|
+
if (entries.length > r.maxEntries)
|
|
488
|
+
throw r.fail(
|
|
489
|
+
`${r.label} package exceeds the ${r.maxEntries.toLocaleString("en-US")} part limit`,
|
|
490
|
+
r.maxEntries,
|
|
491
|
+
"maxEntries",
|
|
492
|
+
entries.length
|
|
493
|
+
);
|
|
494
|
+
let declared = 0;
|
|
495
|
+
for (const entry2 of entries) {
|
|
496
|
+
const original = entry2.unsafeOriginalName;
|
|
497
|
+
if (!isSafePartName(entry2.name) || original !== void 0 && !isSafePartName(original))
|
|
498
|
+
throw r.fail(`${r.label} package has an unsafe part name`, r.maxEntries, "partName");
|
|
499
|
+
if (entry2.dir) continue;
|
|
500
|
+
const size = declaredEntrySize(entry2);
|
|
501
|
+
if (size > r.maxEntryBytes)
|
|
502
|
+
throw r.fail(
|
|
503
|
+
`${r.label} part ${entry2.name} exceeds the uncompressed part size limit`,
|
|
504
|
+
r.maxEntryBytes,
|
|
505
|
+
"maxEntryBytes",
|
|
506
|
+
size
|
|
507
|
+
);
|
|
508
|
+
declared += size;
|
|
509
|
+
}
|
|
510
|
+
if (declared > r.maxTotalBytes)
|
|
511
|
+
throw r.fail(
|
|
512
|
+
`${r.label} package exceeds the ${mib(r.maxTotalBytes)} MiB uncompressed content limit`,
|
|
513
|
+
r.maxTotalBytes,
|
|
514
|
+
"maxTotalBytes",
|
|
515
|
+
declared
|
|
516
|
+
);
|
|
517
|
+
const produced = /* @__PURE__ */ new Map();
|
|
518
|
+
let total = 0;
|
|
519
|
+
for (const entry2 of entries) {
|
|
520
|
+
if (entry2.dir) continue;
|
|
521
|
+
const inflateOriginal = entry2.async.bind(entry2);
|
|
522
|
+
entry2.async = async (type, onUpdate) => {
|
|
523
|
+
const previous = produced.get(entry2.name) ?? 0;
|
|
524
|
+
const bytes = await inflateEntryGuarded(entry2, total - previous, limits);
|
|
525
|
+
if (bytes.byteLength > previous) {
|
|
526
|
+
total += bytes.byteLength - previous;
|
|
527
|
+
produced.set(entry2.name, bytes.byteLength);
|
|
528
|
+
}
|
|
529
|
+
switch (type) {
|
|
530
|
+
case "uint8array":
|
|
531
|
+
return bytes;
|
|
532
|
+
case "string":
|
|
533
|
+
case "text":
|
|
534
|
+
return new TextDecoder("utf-8", { ignoreBOM: true }).decode(bytes);
|
|
535
|
+
case "arraybuffer":
|
|
536
|
+
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
537
|
+
case "base64":
|
|
538
|
+
return toBase64(bytes);
|
|
539
|
+
default:
|
|
540
|
+
return inflateOriginal(type, onUpdate);
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
return zip;
|
|
545
|
+
}
|
|
546
|
+
async function openZip(input, limits = {}) {
|
|
547
|
+
const r = resolveLimits(limits);
|
|
548
|
+
const maxInput = limits.maxInputBytes ?? DEFAULT_ZIP_LIMITS.maxInputBytes;
|
|
549
|
+
const bytes = input instanceof Uint8Array ? input : new Uint8Array(input);
|
|
550
|
+
if (bytes.byteLength > maxInput)
|
|
551
|
+
throw r.fail(
|
|
552
|
+
`${r.label} package exceeds the ${mib(maxInput)} MiB compressed input limit`,
|
|
553
|
+
maxInput,
|
|
554
|
+
"maxInputBytes",
|
|
555
|
+
bytes.byteLength
|
|
556
|
+
);
|
|
557
|
+
return guardZip(await JSZip.loadAsync(bytes), limits);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
// opc/relationships.ts
|
|
561
|
+
function parseRelationships(xml) {
|
|
562
|
+
const map = /* @__PURE__ */ new Map();
|
|
563
|
+
if (!xml) return map;
|
|
564
|
+
const root = parseXml(xml).documentElement;
|
|
565
|
+
for (const node of elements(root)) {
|
|
566
|
+
if (node.localName !== "Relationship") continue;
|
|
567
|
+
const id = node.getAttribute("Id");
|
|
568
|
+
const target = node.getAttribute("Target");
|
|
569
|
+
if (!id || target == null) continue;
|
|
570
|
+
map.set(id, {
|
|
571
|
+
id,
|
|
572
|
+
type: node.getAttribute("Type") ?? "",
|
|
573
|
+
target,
|
|
574
|
+
mode: node.getAttribute("TargetMode") === "External" ? "External" : "Internal"
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
return map;
|
|
578
|
+
}
|
|
579
|
+
var escapeAttr = (value) => value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
580
|
+
function buildRelationshipsXml(relationships) {
|
|
581
|
+
const items = Array.from(relationships).map(([id, rel]) => {
|
|
582
|
+
const mode = rel.mode === "External" ? ' TargetMode="External"' : "";
|
|
583
|
+
return `<Relationship Id="${escapeAttr(id)}" Type="${escapeAttr(rel.type)}" Target="${escapeAttr(rel.target)}"${mode}/>`;
|
|
584
|
+
}).join("");
|
|
585
|
+
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="${NS.rels}">${items}</Relationships>`;
|
|
586
|
+
}
|
|
587
|
+
function resolvePartPath(basePart, target) {
|
|
588
|
+
if (target.startsWith("/")) return target.slice(1);
|
|
589
|
+
const baseDir = basePart.slice(0, basePart.lastIndexOf("/") + 1);
|
|
590
|
+
const resolved = [];
|
|
591
|
+
for (const segment of `${baseDir}${target}`.split("/")) {
|
|
592
|
+
if (segment === "." || segment === "") continue;
|
|
593
|
+
if (segment === "..") resolved.pop();
|
|
594
|
+
else resolved.push(segment);
|
|
595
|
+
}
|
|
596
|
+
return resolved.join("/");
|
|
162
597
|
}
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
return
|
|
166
|
-
};
|
|
167
|
-
var isElement = (node) => node.nodeType === 1;
|
|
168
|
-
var elements = (parent) => Array.from(parent.childNodes).filter(isElement);
|
|
169
|
-
var textContent = (element4) => element4.textContent ?? "";
|
|
170
|
-
var makeNS = (doc, ns, qualified) => doc.createElementNS(ns, qualified);
|
|
171
|
-
function named(element4, local, ns, lenient = true) {
|
|
172
|
-
if (!element4 || element4.localName !== local) return false;
|
|
173
|
-
return element4.namespaceURI === ns || lenient && !element4.namespaceURI;
|
|
598
|
+
function relationshipsPartFor(partName) {
|
|
599
|
+
const slash = partName.lastIndexOf("/");
|
|
600
|
+
return `${partName.slice(0, slash + 1)}_rels/${partName.slice(slash + 1)}.rels`;
|
|
174
601
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return
|
|
602
|
+
function nextRelationshipId(used) {
|
|
603
|
+
let index = 1;
|
|
604
|
+
while (used.has(`rId${index}`)) index++;
|
|
605
|
+
return `rId${index}`;
|
|
179
606
|
}
|
|
180
|
-
var
|
|
607
|
+
var getRelationshipId = (element4) => relAttr(element4, "id") || void 0;
|
|
181
608
|
|
|
182
609
|
// docx/xml.ts
|
|
183
610
|
var WORD_NS = NS.w;
|
|
@@ -2998,55 +3425,6 @@ var RELATIONSHIP_TYPES = {
|
|
|
2998
3425
|
diagramColors: `${BASE}/diagramColors`,
|
|
2999
3426
|
diagramDrawing: "http://schemas.microsoft.com/office/2007/relationships/diagramDrawing"};
|
|
3000
3427
|
|
|
3001
|
-
// opc/relationships.ts
|
|
3002
|
-
function parseRelationships(xml) {
|
|
3003
|
-
const map = /* @__PURE__ */ new Map();
|
|
3004
|
-
if (!xml) return map;
|
|
3005
|
-
const root = parseXml(xml).documentElement;
|
|
3006
|
-
for (const node of elements(root)) {
|
|
3007
|
-
if (node.localName !== "Relationship") continue;
|
|
3008
|
-
const id = node.getAttribute("Id");
|
|
3009
|
-
const target = node.getAttribute("Target");
|
|
3010
|
-
if (!id || target == null) continue;
|
|
3011
|
-
map.set(id, {
|
|
3012
|
-
id,
|
|
3013
|
-
type: node.getAttribute("Type") ?? "",
|
|
3014
|
-
target,
|
|
3015
|
-
mode: node.getAttribute("TargetMode") === "External" ? "External" : "Internal"
|
|
3016
|
-
});
|
|
3017
|
-
}
|
|
3018
|
-
return map;
|
|
3019
|
-
}
|
|
3020
|
-
var escapeAttr = (value) => value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
3021
|
-
function buildRelationshipsXml(relationships) {
|
|
3022
|
-
const items = Array.from(relationships).map(([id, rel]) => {
|
|
3023
|
-
const mode = rel.mode === "External" ? ' TargetMode="External"' : "";
|
|
3024
|
-
return `<Relationship Id="${escapeAttr(id)}" Type="${escapeAttr(rel.type)}" Target="${escapeAttr(rel.target)}"${mode}/>`;
|
|
3025
|
-
}).join("");
|
|
3026
|
-
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="${NS.rels}">${items}</Relationships>`;
|
|
3027
|
-
}
|
|
3028
|
-
function resolvePartPath(basePart, target) {
|
|
3029
|
-
if (target.startsWith("/")) return target.slice(1);
|
|
3030
|
-
const baseDir = basePart.slice(0, basePart.lastIndexOf("/") + 1);
|
|
3031
|
-
const resolved = [];
|
|
3032
|
-
for (const segment of `${baseDir}${target}`.split("/")) {
|
|
3033
|
-
if (segment === "." || segment === "") continue;
|
|
3034
|
-
if (segment === "..") resolved.pop();
|
|
3035
|
-
else resolved.push(segment);
|
|
3036
|
-
}
|
|
3037
|
-
return resolved.join("/");
|
|
3038
|
-
}
|
|
3039
|
-
function relationshipsPartFor(partName) {
|
|
3040
|
-
const slash = partName.lastIndexOf("/");
|
|
3041
|
-
return `${partName.slice(0, slash + 1)}_rels/${partName.slice(slash + 1)}.rels`;
|
|
3042
|
-
}
|
|
3043
|
-
function nextRelationshipId(used) {
|
|
3044
|
-
let index = 1;
|
|
3045
|
-
while (used.has(`rId${index}`)) index++;
|
|
3046
|
-
return `rId${index}`;
|
|
3047
|
-
}
|
|
3048
|
-
var getRelationshipId = (element4) => relAttr(element4, "id") || void 0;
|
|
3049
|
-
|
|
3050
3428
|
// opc/content-types.ts
|
|
3051
3429
|
var escapeAttr2 = (value) => value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
3052
3430
|
function parseContentTypes(xml) {
|
|
@@ -3110,260 +3488,39 @@ async function ensureContentTypeOverride(zip, partName, contentType) {
|
|
|
3110
3488
|
async function removeContentTypeOverride(zip, partName) {
|
|
3111
3489
|
const xml = await zip.file(CONTENT_TYPES_PATH)?.async("string");
|
|
3112
3490
|
if (!xml) return;
|
|
3113
|
-
const target = `/${partName}`;
|
|
3114
|
-
const tag = (xml.match(/<Override\b[^>]*\/>/g) ?? []).find(
|
|
3115
|
-
(candidate) => attr2(candidate, "PartName") === target
|
|
3116
|
-
);
|
|
3117
|
-
if (tag) zip.file(CONTENT_TYPES_PATH, xml.replace(tag, ""));
|
|
3118
|
-
}
|
|
3119
|
-
async function ensureRelationship(zip, relsPath, type, target) {
|
|
3120
|
-
const xml = await zip.file(relsPath)?.async("string") ?? EMPTY_RELS;
|
|
3121
|
-
const used = /* @__PURE__ */ new Set();
|
|
3122
|
-
for (const tag of xml.match(/<Relationship\b[^>]*\/>/g) ?? []) {
|
|
3123
|
-
const id2 = attr2(tag, "Id");
|
|
3124
|
-
if (id2) used.add(id2);
|
|
3125
|
-
if (id2 && attr2(tag, "Type") === type && attr2(tag, "Target") === target) return id2;
|
|
3126
|
-
}
|
|
3127
|
-
const highest = Math.max(
|
|
3128
|
-
0,
|
|
3129
|
-
...[...used].map((id2) => Number(id2.replace(/^rId/, ""))).filter(Number.isFinite)
|
|
3130
|
-
);
|
|
3131
|
-
let id = `rId${highest + 1}`;
|
|
3132
|
-
if (used.has(id)) id = nextRelationshipId(used);
|
|
3133
|
-
const insertion = `<Relationship Id="${id}" Type="${type}" Target="${target}"/>`;
|
|
3134
|
-
zip.file(relsPath, xml.replace("</Relationships>", `${insertion}</Relationships>`));
|
|
3135
|
-
return id;
|
|
3136
|
-
}
|
|
3137
|
-
|
|
3138
|
-
// opc/safe-href.ts
|
|
3139
|
-
var SAFE_SCHEMES = /* @__PURE__ */ new Set(["http:", "https:", "mailto:"]);
|
|
3140
|
-
function isSafeHyperlinkHref(href) {
|
|
3141
|
-
const scheme2 = /^([a-z][a-z0-9+.-]*:)/i.exec(href.trim())?.[1];
|
|
3142
|
-
return scheme2 !== void 0 && SAFE_SCHEMES.has(scheme2.toLowerCase());
|
|
3143
|
-
}
|
|
3144
|
-
var OPEN_SCHEMES = /* @__PURE__ */ new Set(["http", "https", "mailto"]);
|
|
3145
|
-
/* @__PURE__ */ new Set([...OPEN_SCHEMES, "ftp", "file"]);
|
|
3146
|
-
var DEFAULT_ZIP_LIMITS = {
|
|
3147
|
-
maxInputBytes: 100 * 1024 * 1024,
|
|
3148
|
-
maxEntries: 1e4,
|
|
3149
|
-
maxEntryBytes: 100 * 1024 * 1024,
|
|
3150
|
-
maxTotalBytes: 100 * 1024 * 1024
|
|
3151
|
-
};
|
|
3152
|
-
var ZipLimitError = class extends Error {
|
|
3153
|
-
code = "ZIP_BOMB";
|
|
3154
|
-
limit;
|
|
3155
|
-
/** The check that failed (absent when the error was built without one). */
|
|
3156
|
-
kind;
|
|
3157
|
-
/** The observed value, when known (a lower bound for a size found while inflating). */
|
|
3158
|
-
actual;
|
|
3159
|
-
constructor(message, details) {
|
|
3160
|
-
super(message);
|
|
3161
|
-
this.name = "ZipLimitError";
|
|
3162
|
-
this.limit = details.limit;
|
|
3163
|
-
this.kind = details.kind;
|
|
3164
|
-
this.actual = details.actual;
|
|
3165
|
-
}
|
|
3166
|
-
};
|
|
3167
|
-
var mib = (bytes) => Math.round(bytes / 1048576);
|
|
3168
|
-
function isSafePartName(name) {
|
|
3169
|
-
if (name.includes("\0") || name.includes("\\")) return false;
|
|
3170
|
-
if (/^[A-Za-z]:/u.test(name)) return false;
|
|
3171
|
-
const body = name.startsWith("/") ? name.slice(1) : name;
|
|
3172
|
-
if (body.startsWith("/")) return false;
|
|
3173
|
-
return !body.split("/").some((segment) => segment === "..");
|
|
3174
|
-
}
|
|
3175
|
-
function declaredEntrySize(entry2) {
|
|
3176
|
-
const data = entry2._data;
|
|
3177
|
-
const size = Number(data?.uncompressedSize ?? 0);
|
|
3178
|
-
return Number.isFinite(size) && size > 0 ? size : 0;
|
|
3179
|
-
}
|
|
3180
|
-
function resolveLimits(limits) {
|
|
3181
|
-
const create2 = limits.createError;
|
|
3182
|
-
return {
|
|
3183
|
-
maxEntries: limits.maxEntries ?? DEFAULT_ZIP_LIMITS.maxEntries,
|
|
3184
|
-
maxEntryBytes: limits.maxEntryBytes ?? DEFAULT_ZIP_LIMITS.maxEntryBytes,
|
|
3185
|
-
maxTotalBytes: limits.maxTotalBytes ?? DEFAULT_ZIP_LIMITS.maxTotalBytes,
|
|
3186
|
-
label: limits.label ?? "ZIP",
|
|
3187
|
-
fail: (message, limit, kind, actual) => create2 ? create2(message, { limit, kind, actual }) : new ZipLimitError(message, { limit, kind, actual })
|
|
3188
|
-
};
|
|
3189
|
-
}
|
|
3190
|
-
async function inflateEntryGuarded(entry2, alreadyRead, limits) {
|
|
3191
|
-
const chunks = [];
|
|
3192
|
-
let size = 0;
|
|
3193
|
-
for await (const chunk of streamEntryGuarded(entry2, alreadyRead, limits)) {
|
|
3194
|
-
chunks.push(chunk);
|
|
3195
|
-
size += chunk.byteLength;
|
|
3196
|
-
}
|
|
3197
|
-
if (chunks.length === 1 && chunks[0]) return chunks[0];
|
|
3198
|
-
const out = new Uint8Array(size);
|
|
3199
|
-
let offset = 0;
|
|
3200
|
-
for (const chunk of chunks) {
|
|
3201
|
-
out.set(chunk, offset);
|
|
3202
|
-
offset += chunk.byteLength;
|
|
3203
|
-
}
|
|
3204
|
-
return out;
|
|
3205
|
-
}
|
|
3206
|
-
var AHEAD = 8;
|
|
3207
|
-
async function* streamEntryGuarded(entry2, alreadyRead, limits) {
|
|
3208
|
-
const r = resolveLimits(limits);
|
|
3209
|
-
const declared = declaredEntrySize(entry2);
|
|
3210
|
-
const stream = entry2.internalStream("uint8array");
|
|
3211
|
-
const queue = [];
|
|
3212
|
-
let size = 0;
|
|
3213
|
-
let ended = false;
|
|
3214
|
-
let stopped = false;
|
|
3215
|
-
let failure;
|
|
3216
|
-
let paused = false;
|
|
3217
|
-
let wake;
|
|
3218
|
-
const pause = () => {
|
|
3219
|
-
paused = true;
|
|
3220
|
-
stream.pause();
|
|
3221
|
-
};
|
|
3222
|
-
const resume = () => {
|
|
3223
|
-
if (!paused || stopped) return;
|
|
3224
|
-
paused = false;
|
|
3225
|
-
stream.resume();
|
|
3226
|
-
};
|
|
3227
|
-
const fail = (error) => {
|
|
3228
|
-
failure ??= error;
|
|
3229
|
-
stopped = true;
|
|
3230
|
-
queue.length = 0;
|
|
3231
|
-
pause();
|
|
3232
|
-
wake?.();
|
|
3233
|
-
};
|
|
3234
|
-
stream.on("data", (chunk) => {
|
|
3235
|
-
if (stopped) return pause();
|
|
3236
|
-
size += chunk.byteLength;
|
|
3237
|
-
if (size > declared || size > r.maxEntryBytes)
|
|
3238
|
-
return fail(
|
|
3239
|
-
r.fail(
|
|
3240
|
-
`${r.label} part ${entry2.name} inflates past its declared size`,
|
|
3241
|
-
r.maxEntryBytes,
|
|
3242
|
-
size > declared ? "declaredSize" : "maxEntryBytes",
|
|
3243
|
-
size
|
|
3244
|
-
)
|
|
3245
|
-
);
|
|
3246
|
-
if (alreadyRead + size > r.maxTotalBytes)
|
|
3247
|
-
return fail(
|
|
3248
|
-
r.fail(
|
|
3249
|
-
`${r.label} package exceeds the ${mib(r.maxTotalBytes)} MiB uncompressed content limit`,
|
|
3250
|
-
r.maxTotalBytes,
|
|
3251
|
-
"maxTotalBytes",
|
|
3252
|
-
alreadyRead + size
|
|
3253
|
-
)
|
|
3254
|
-
);
|
|
3255
|
-
queue.push(chunk);
|
|
3256
|
-
if (queue.length >= AHEAD) pause();
|
|
3257
|
-
wake?.();
|
|
3258
|
-
});
|
|
3259
|
-
stream.on("error", (error) => fail(error));
|
|
3260
|
-
stream.on("end", () => {
|
|
3261
|
-
ended = true;
|
|
3262
|
-
wake?.();
|
|
3263
|
-
});
|
|
3264
|
-
stream.resume();
|
|
3265
|
-
try {
|
|
3266
|
-
for (; ; ) {
|
|
3267
|
-
if (failure) throw failure;
|
|
3268
|
-
const chunk = queue.shift();
|
|
3269
|
-
if (chunk) {
|
|
3270
|
-
if (queue.length < AHEAD / 2) resume();
|
|
3271
|
-
yield chunk;
|
|
3272
|
-
continue;
|
|
3273
|
-
}
|
|
3274
|
-
if (ended) return;
|
|
3275
|
-
await new Promise((resolve) => {
|
|
3276
|
-
wake = resolve;
|
|
3277
|
-
resume();
|
|
3278
|
-
});
|
|
3279
|
-
wake = void 0;
|
|
3280
|
-
}
|
|
3281
|
-
} finally {
|
|
3282
|
-
stopped = true;
|
|
3283
|
-
if (!ended) pause();
|
|
3284
|
-
}
|
|
3285
|
-
}
|
|
3286
|
-
function toBase64(bytes) {
|
|
3287
|
-
let binary = "";
|
|
3288
|
-
for (let i = 0; i < bytes.length; i += 32768)
|
|
3289
|
-
binary += String.fromCharCode(...bytes.subarray(i, i + 32768));
|
|
3290
|
-
return btoa(binary);
|
|
3491
|
+
const target = `/${partName}`;
|
|
3492
|
+
const tag = (xml.match(/<Override\b[^>]*\/>/g) ?? []).find(
|
|
3493
|
+
(candidate) => attr2(candidate, "PartName") === target
|
|
3494
|
+
);
|
|
3495
|
+
if (tag) zip.file(CONTENT_TYPES_PATH, xml.replace(tag, ""));
|
|
3291
3496
|
}
|
|
3292
|
-
function
|
|
3293
|
-
const
|
|
3294
|
-
const
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
"maxEntries",
|
|
3300
|
-
entries.length
|
|
3301
|
-
);
|
|
3302
|
-
let declared = 0;
|
|
3303
|
-
for (const entry2 of entries) {
|
|
3304
|
-
const original = entry2.unsafeOriginalName;
|
|
3305
|
-
if (!isSafePartName(entry2.name) || original !== void 0 && !isSafePartName(original))
|
|
3306
|
-
throw r.fail(`${r.label} package has an unsafe part name`, r.maxEntries, "partName");
|
|
3307
|
-
if (entry2.dir) continue;
|
|
3308
|
-
const size = declaredEntrySize(entry2);
|
|
3309
|
-
if (size > r.maxEntryBytes)
|
|
3310
|
-
throw r.fail(
|
|
3311
|
-
`${r.label} part ${entry2.name} exceeds the uncompressed part size limit`,
|
|
3312
|
-
r.maxEntryBytes,
|
|
3313
|
-
"maxEntryBytes",
|
|
3314
|
-
size
|
|
3315
|
-
);
|
|
3316
|
-
declared += size;
|
|
3317
|
-
}
|
|
3318
|
-
if (declared > r.maxTotalBytes)
|
|
3319
|
-
throw r.fail(
|
|
3320
|
-
`${r.label} package exceeds the ${mib(r.maxTotalBytes)} MiB uncompressed content limit`,
|
|
3321
|
-
r.maxTotalBytes,
|
|
3322
|
-
"maxTotalBytes",
|
|
3323
|
-
declared
|
|
3324
|
-
);
|
|
3325
|
-
const produced = /* @__PURE__ */ new Map();
|
|
3326
|
-
let total = 0;
|
|
3327
|
-
for (const entry2 of entries) {
|
|
3328
|
-
if (entry2.dir) continue;
|
|
3329
|
-
const inflateOriginal = entry2.async.bind(entry2);
|
|
3330
|
-
entry2.async = async (type, onUpdate) => {
|
|
3331
|
-
const previous = produced.get(entry2.name) ?? 0;
|
|
3332
|
-
const bytes = await inflateEntryGuarded(entry2, total - previous, limits);
|
|
3333
|
-
if (bytes.byteLength > previous) {
|
|
3334
|
-
total += bytes.byteLength - previous;
|
|
3335
|
-
produced.set(entry2.name, bytes.byteLength);
|
|
3336
|
-
}
|
|
3337
|
-
switch (type) {
|
|
3338
|
-
case "uint8array":
|
|
3339
|
-
return bytes;
|
|
3340
|
-
case "string":
|
|
3341
|
-
case "text":
|
|
3342
|
-
return new TextDecoder("utf-8", { ignoreBOM: true }).decode(bytes);
|
|
3343
|
-
case "arraybuffer":
|
|
3344
|
-
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
3345
|
-
case "base64":
|
|
3346
|
-
return toBase64(bytes);
|
|
3347
|
-
default:
|
|
3348
|
-
return inflateOriginal(type, onUpdate);
|
|
3349
|
-
}
|
|
3350
|
-
};
|
|
3497
|
+
async function ensureRelationship(zip, relsPath, type, target) {
|
|
3498
|
+
const xml = await zip.file(relsPath)?.async("string") ?? EMPTY_RELS;
|
|
3499
|
+
const used = /* @__PURE__ */ new Set();
|
|
3500
|
+
for (const tag of xml.match(/<Relationship\b[^>]*\/>/g) ?? []) {
|
|
3501
|
+
const id2 = attr2(tag, "Id");
|
|
3502
|
+
if (id2) used.add(id2);
|
|
3503
|
+
if (id2 && attr2(tag, "Type") === type && attr2(tag, "Target") === target) return id2;
|
|
3351
3504
|
}
|
|
3352
|
-
|
|
3505
|
+
const highest = Math.max(
|
|
3506
|
+
0,
|
|
3507
|
+
...[...used].map((id2) => Number(id2.replace(/^rId/, ""))).filter(Number.isFinite)
|
|
3508
|
+
);
|
|
3509
|
+
let id = `rId${highest + 1}`;
|
|
3510
|
+
if (used.has(id)) id = nextRelationshipId(used);
|
|
3511
|
+
const insertion = `<Relationship Id="${id}" Type="${type}" Target="${target}"/>`;
|
|
3512
|
+
zip.file(relsPath, xml.replace("</Relationships>", `${insertion}</Relationships>`));
|
|
3513
|
+
return id;
|
|
3353
3514
|
}
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
`${r.label} package exceeds the ${mib(maxInput)} MiB compressed input limit`,
|
|
3361
|
-
maxInput,
|
|
3362
|
-
"maxInputBytes",
|
|
3363
|
-
bytes.byteLength
|
|
3364
|
-
);
|
|
3365
|
-
return guardZip(await JSZip.loadAsync(bytes), limits);
|
|
3515
|
+
|
|
3516
|
+
// opc/safe-href.ts
|
|
3517
|
+
var SAFE_SCHEMES = /* @__PURE__ */ new Set(["http:", "https:", "mailto:"]);
|
|
3518
|
+
function isSafeHyperlinkHref(href) {
|
|
3519
|
+
const scheme2 = /^([a-z][a-z0-9+.-]*:)/i.exec(href.trim())?.[1];
|
|
3520
|
+
return scheme2 !== void 0 && SAFE_SCHEMES.has(scheme2.toLowerCase());
|
|
3366
3521
|
}
|
|
3522
|
+
var OPEN_SCHEMES = /* @__PURE__ */ new Set(["http", "https", "mailto"]);
|
|
3523
|
+
/* @__PURE__ */ new Set([...OPEN_SCHEMES, "ftp", "file"]);
|
|
3367
3524
|
|
|
3368
3525
|
// opc/properties/patch.ts
|
|
3369
3526
|
var XMLNS3 = "http://www.w3.org/2000/xmlns/";
|
|
@@ -5418,161 +5575,6 @@ function patchCommentMetadata(parts, identities) {
|
|
|
5418
5575
|
return result;
|
|
5419
5576
|
}
|
|
5420
5577
|
|
|
5421
|
-
// text/text-diff.ts
|
|
5422
|
-
var isLowSurrogate = (text, at) => {
|
|
5423
|
-
const code = text.charCodeAt(at);
|
|
5424
|
-
return code >= 56320 && code <= 57343;
|
|
5425
|
-
};
|
|
5426
|
-
function shortestEdit(n, m, same6, maxEdits) {
|
|
5427
|
-
const max = Math.min(n + m, maxEdits);
|
|
5428
|
-
const offset = max + 1;
|
|
5429
|
-
const v = new Int32Array(2 * max + 3);
|
|
5430
|
-
const trace = [];
|
|
5431
|
-
for (let d = 0; d <= max; d++) {
|
|
5432
|
-
for (let k = -d; k <= d; k += 2) {
|
|
5433
|
-
const down = k === -d || k !== d && v[offset + k - 1] < v[offset + k + 1];
|
|
5434
|
-
let x = down ? v[offset + k + 1] : v[offset + k - 1] + 1;
|
|
5435
|
-
let y = x - k;
|
|
5436
|
-
while (x < n && y < m && same6(x, y)) {
|
|
5437
|
-
x++;
|
|
5438
|
-
y++;
|
|
5439
|
-
}
|
|
5440
|
-
v[offset + k] = x;
|
|
5441
|
-
if (x >= n && y >= m) return backtrack(trace, n, m, d);
|
|
5442
|
-
}
|
|
5443
|
-
trace.push(v.slice(offset - d, offset + d + 1));
|
|
5444
|
-
}
|
|
5445
|
-
return void 0;
|
|
5446
|
-
}
|
|
5447
|
-
function backtrack(trace, n, m, d) {
|
|
5448
|
-
const edits = [];
|
|
5449
|
-
let x = n;
|
|
5450
|
-
let y = m;
|
|
5451
|
-
for (let step = d; step > 0; step--) {
|
|
5452
|
-
const previous = trace[step - 1];
|
|
5453
|
-
const at = (k2) => previous[k2 + step - 1];
|
|
5454
|
-
const k = x - y;
|
|
5455
|
-
const down = k === -step || k !== step && at(k - 1) < at(k + 1);
|
|
5456
|
-
const before = down ? k + 1 : k - 1;
|
|
5457
|
-
const startX = at(before);
|
|
5458
|
-
const startY = startX - before;
|
|
5459
|
-
edits.push(down ? [startX, startY, true] : [startX, startY, false]);
|
|
5460
|
-
x = startX;
|
|
5461
|
-
y = startY;
|
|
5462
|
-
}
|
|
5463
|
-
return edits.reverse();
|
|
5464
|
-
}
|
|
5465
|
-
function changesOf(edits) {
|
|
5466
|
-
const changes = [];
|
|
5467
|
-
for (const [x, y, inserts] of edits) {
|
|
5468
|
-
const last = changes.at(-1);
|
|
5469
|
-
if (last && last.fromEnd === x && last.toEnd === y) {
|
|
5470
|
-
if (inserts) last.toEnd++;
|
|
5471
|
-
else last.fromEnd++;
|
|
5472
|
-
} else
|
|
5473
|
-
changes.push({
|
|
5474
|
-
fromStart: x,
|
|
5475
|
-
fromEnd: inserts ? x : x + 1,
|
|
5476
|
-
toStart: y,
|
|
5477
|
-
toEnd: inserts ? y + 1 : y
|
|
5478
|
-
});
|
|
5479
|
-
}
|
|
5480
|
-
return changes;
|
|
5481
|
-
}
|
|
5482
|
-
function characterChanges(a2, b, maxEdits) {
|
|
5483
|
-
const edits = shortestEdit(
|
|
5484
|
-
a2.length,
|
|
5485
|
-
b.length,
|
|
5486
|
-
(x, y) => a2.charCodeAt(x) === b.charCodeAt(y),
|
|
5487
|
-
maxEdits
|
|
5488
|
-
);
|
|
5489
|
-
return edits && changesOf(edits);
|
|
5490
|
-
}
|
|
5491
|
-
var TOKEN = /[\p{L}\p{N}\p{M}]+|\s+|[\s\S]/gu;
|
|
5492
|
-
function tokensOf(text, ids) {
|
|
5493
|
-
const tokens = [];
|
|
5494
|
-
const starts = [];
|
|
5495
|
-
for (const match of text.matchAll(TOKEN)) {
|
|
5496
|
-
let id = ids.get(match[0]);
|
|
5497
|
-
if (id === void 0) ids.set(match[0], id = ids.size);
|
|
5498
|
-
tokens.push(id);
|
|
5499
|
-
starts.push(match.index);
|
|
5500
|
-
}
|
|
5501
|
-
starts.push(text.length);
|
|
5502
|
-
return { tokens, starts };
|
|
5503
|
-
}
|
|
5504
|
-
function tokenChanges(a2, b, maxEdits) {
|
|
5505
|
-
const ids = /* @__PURE__ */ new Map();
|
|
5506
|
-
const from = tokensOf(a2, ids);
|
|
5507
|
-
const to = tokensOf(b, ids);
|
|
5508
|
-
const edits = shortestEdit(
|
|
5509
|
-
from.tokens.length,
|
|
5510
|
-
to.tokens.length,
|
|
5511
|
-
(x, y) => from.tokens[x] === to.tokens[y],
|
|
5512
|
-
maxEdits
|
|
5513
|
-
);
|
|
5514
|
-
if (!edits) return void 0;
|
|
5515
|
-
let budget = maxEdits;
|
|
5516
|
-
return changesOf(edits).flatMap((stretch) => {
|
|
5517
|
-
const change = {
|
|
5518
|
-
fromStart: from.starts[stretch.fromStart],
|
|
5519
|
-
fromEnd: from.starts[stretch.fromEnd],
|
|
5520
|
-
toStart: to.starts[stretch.toStart],
|
|
5521
|
-
toEnd: to.starts[stretch.toEnd]
|
|
5522
|
-
};
|
|
5523
|
-
const inner = change.fromEnd > change.fromStart && change.toEnd > change.toStart ? characterChanges(
|
|
5524
|
-
a2.slice(change.fromStart, change.fromEnd),
|
|
5525
|
-
b.slice(change.toStart, change.toEnd),
|
|
5526
|
-
budget
|
|
5527
|
-
) : void 0;
|
|
5528
|
-
if (!inner) return [change];
|
|
5529
|
-
for (const found of inner)
|
|
5530
|
-
budget -= found.fromEnd - found.fromStart + found.toEnd - found.toStart;
|
|
5531
|
-
return inner.map((found) => ({
|
|
5532
|
-
fromStart: found.fromStart + change.fromStart,
|
|
5533
|
-
fromEnd: found.fromEnd + change.fromStart,
|
|
5534
|
-
toStart: found.toStart + change.toStart,
|
|
5535
|
-
toEnd: found.toEnd + change.toStart
|
|
5536
|
-
}));
|
|
5537
|
-
});
|
|
5538
|
-
}
|
|
5539
|
-
function diffText(from, to, maxEdits = 500) {
|
|
5540
|
-
let start = 0;
|
|
5541
|
-
while (start < from.length && start < to.length && from.charCodeAt(start) === to.charCodeAt(start))
|
|
5542
|
-
start++;
|
|
5543
|
-
let end = 0;
|
|
5544
|
-
while (end < from.length - start && end < to.length - start && from.charCodeAt(from.length - 1 - end) === to.charCodeAt(to.length - 1 - end))
|
|
5545
|
-
end++;
|
|
5546
|
-
const a2 = from.slice(start, from.length - end);
|
|
5547
|
-
const b = to.slice(start, to.length - end);
|
|
5548
|
-
if (!a2.length && !b.length) return [];
|
|
5549
|
-
const found = a2.length && b.length ? characterChanges(a2, b, maxEdits) ?? tokenChanges(a2, b, maxEdits) : void 0;
|
|
5550
|
-
const changes = found ?? [{ fromStart: 0, fromEnd: a2.length, toStart: 0, toEnd: b.length }];
|
|
5551
|
-
const result = [];
|
|
5552
|
-
for (const change of changes) {
|
|
5553
|
-
const placed = {
|
|
5554
|
-
fromStart: change.fromStart + start,
|
|
5555
|
-
fromEnd: change.fromEnd + start,
|
|
5556
|
-
toStart: change.toStart + start,
|
|
5557
|
-
toEnd: change.toEnd + start
|
|
5558
|
-
};
|
|
5559
|
-
if (placed.fromStart > 0 && placed.toStart > 0 && (isLowSurrogate(from, placed.fromStart) || isLowSurrogate(to, placed.toStart))) {
|
|
5560
|
-
placed.fromStart--;
|
|
5561
|
-
placed.toStart--;
|
|
5562
|
-
}
|
|
5563
|
-
if (isLowSurrogate(from, placed.fromEnd) || isLowSurrogate(to, placed.toEnd)) {
|
|
5564
|
-
placed.fromEnd++;
|
|
5565
|
-
placed.toEnd++;
|
|
5566
|
-
}
|
|
5567
|
-
const last = result.at(-1);
|
|
5568
|
-
if (last && placed.fromStart <= last.fromEnd) {
|
|
5569
|
-
last.fromEnd = Math.max(last.fromEnd, placed.fromEnd);
|
|
5570
|
-
last.toEnd = Math.max(last.toEnd, placed.toEnd);
|
|
5571
|
-
} else result.push(placed);
|
|
5572
|
-
}
|
|
5573
|
-
return result;
|
|
5574
|
-
}
|
|
5575
|
-
|
|
5576
5578
|
// docx/write-run-extra.ts
|
|
5577
5579
|
function setAttribute2(element4, local, value) {
|
|
5578
5580
|
element4.setAttributeNS(WORD_NS, `w:${local}`, value);
|