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