ooxml-core 1.6.0 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{PptxHandler-DDEJ6CKU.mjs → PptxHandler-BL4B7CZO.mjs} +2 -2
- package/dist/automation/index.cjs +1 -1
- package/dist/automation/index.mjs +1 -1
- package/dist/chart/gradient-definition.d.ts +2 -0
- package/dist/chart/gradient-definition.d.ts.map +1 -1
- package/dist/chart/index.cjs +1 -1
- package/dist/chart/index.mjs +1 -1
- package/dist/{chunk-5L4DHJV3.mjs → chunk-GAGSCAR3.mjs} +46 -43
- package/dist/{chunk-QXZJOUW4.mjs → chunk-NIHPA63A.mjs} +1 -1
- package/dist/{chunk-UQQGC6O3.mjs → chunk-TTPZITQN.mjs} +841 -614
- package/dist/{chunk-Q52O7SXQ.mjs → chunk-Z7IQR4S4.mjs} +3 -3
- package/dist/{chunk-EPNLABIU.mjs → chunk-ZAP5WLEN.mjs} +1 -1
- package/dist/crypto/index.cjs +281 -109
- package/dist/crypto/index.mjs +281 -109
- package/dist/diagram/engine/text-measure.d.ts +1 -1
- package/dist/diagram/layout/smartart-font-table.d.ts +1 -1
- package/dist/diagram/layout/smartart-layout-interpreter-linear-content-size.d.ts +1 -1
- package/dist/diagram/layout/smartart-layout-item-font-size.d.ts +1 -1
- package/dist/diagram/layout/smartart-layout-item-font-tier-fit.d.ts +1 -1
- package/dist/diagram/layout/smartart-line-pitch.d.ts +1 -1
- package/dist/diagram/layout/smartart-text-wrap-fit.d.ts +1 -1
- package/dist/docx/index.cjs +1 -1
- package/dist/docx/index.mjs +1 -1
- package/dist/docx/layout/index.cjs +1 -1
- package/dist/docx/layout/index.mjs +1 -1
- package/dist/docx/load/index.cjs +481 -254
- package/dist/docx/load/index.mjs +481 -254
- package/dist/docx/ui/index.cjs +1 -1
- package/dist/docx/ui/index.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/pptx/automation/index.cjs +1391 -1154
- package/dist/pptx/automation/index.d.ts +3 -3
- package/dist/pptx/automation/index.mjs +5 -5
- package/dist/pptx/chunks/{index-JNv7AJx5.d.ts → index-CKIUurnd.d.ts} +2 -2
- package/dist/pptx/chunks/{index-JNv7AJx5.d.ts.map → index-CKIUurnd.d.ts.map} +1 -1
- package/dist/pptx/chunks/{index-EZJZ7USt.d.ts → index-Cn-GzYGp.d.ts} +64 -15
- package/dist/pptx/chunks/{index-EZJZ7USt.d.ts.map → index-Cn-GzYGp.d.ts.map} +1 -1
- package/dist/pptx/chunks/{text-operations-DtCxXrMh.d.ts → text-operations-BHfAm5K9.d.ts} +8 -1
- package/dist/pptx/chunks/text-operations-BHfAm5K9.d.ts.map +1 -0
- package/dist/pptx/cli/index.cjs +1270 -1088
- package/dist/pptx/cli/index.d.ts +1 -1
- package/dist/pptx/cli/index.mjs +4 -4
- package/dist/pptx/converter/index.d.ts +1 -1
- package/dist/pptx/converter/index.mjs +2 -2
- package/dist/pptx/index.cjs +1411 -1174
- package/dist/pptx/index.d.ts +3 -3
- package/dist/pptx/index.mjs +5 -5
- package/dist/text/font-metrics/font-advance-widths-aptos-display.generated.d.ts +1 -1
- package/dist/text/font-metrics/font-advance-widths-aptos.generated.d.ts +1 -1
- package/dist/text/font-metrics/font-advance-widths-arial.generated.d.ts +1 -1
- package/dist/text/font-metrics/font-advance-widths-calibri-light.generated.d.ts +1 -1
- package/dist/text/font-metrics/font-advance-widths-calibri.generated.d.ts +1 -1
- package/dist/text/font-metrics/font-advance-widths-segoe-ui.generated.d.ts +1 -1
- package/dist/text/font-metrics/font-advance-widths-times-new-roman.generated.d.ts +1 -1
- package/dist/visio/index.cjs +482 -232
- package/dist/visio/index.mjs +482 -232
- package/dist/visio/ui/data-graphic-rules.d.ts +2 -2
- package/dist/xlsx/formula/test-helpers.d.ts +9 -9
- package/dist/xlsx/index.cjs +1 -1
- package/dist/xlsx/index.mjs +1 -1
- package/dist/xlsx/load/index.cjs +415 -188
- package/dist/xlsx/load/index.mjs +415 -188
- package/package.json +5 -5
- package/dist/pptx/chunks/text-operations-DtCxXrMh.d.ts.map +0 -1
package/dist/docx/load/index.mjs
CHANGED
|
@@ -29,7 +29,7 @@ function isOoxmlCryptoError(error) {
|
|
|
29
29
|
return code === "password-required" || code === "incorrect-password" || code === "data-integrity";
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
32
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-parser-types.js
|
|
33
33
|
var OLE_MAGIC = new Uint8Array([208, 207, 17, 224, 161, 177, 26, 225]);
|
|
34
34
|
var ENDOFCHAIN = 4294967294;
|
|
35
35
|
var FREESECT = 4294967295;
|
|
@@ -37,7 +37,9 @@ var FATSECT = 4294967293;
|
|
|
37
37
|
var DIFSECT = 4294967292;
|
|
38
38
|
var MAXREGSECT = 4294967290;
|
|
39
39
|
var ENTRY_TYPE_EMPTY = 0;
|
|
40
|
+
var ENTRY_TYPE_STORAGE = 1;
|
|
40
41
|
var ENTRY_TYPE_STREAM = 2;
|
|
42
|
+
var NOSTREAM = 4294967295;
|
|
41
43
|
var ENTRY_TYPE_ROOT = 5;
|
|
42
44
|
var DIR_ENTRY_SIZE = 128;
|
|
43
45
|
var Ole2ParseError = class extends Error {
|
|
@@ -47,10 +49,174 @@ var Ole2ParseError = class extends Error {
|
|
|
47
49
|
}
|
|
48
50
|
};
|
|
49
51
|
|
|
50
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
52
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-directory.js
|
|
53
|
+
var FILETIME_UNIX_EPOCH = 116444736000000000n;
|
|
54
|
+
function readFileTime(view, offset) {
|
|
55
|
+
const ticks = view.getBigUint64(offset, true);
|
|
56
|
+
if (ticks === 0n)
|
|
57
|
+
return void 0;
|
|
58
|
+
const ms = Number((ticks - FILETIME_UNIX_EPOCH) / 10000n);
|
|
59
|
+
const date = new Date(ms);
|
|
60
|
+
return Number.isNaN(date.getTime()) ? void 0 : date;
|
|
61
|
+
}
|
|
62
|
+
function decodeSlot(dir, id, majorVersion, warnings) {
|
|
63
|
+
const view = new DataView(dir.buffer, dir.byteOffset + id * DIR_ENTRY_SIZE, DIR_ENTRY_SIZE);
|
|
64
|
+
const nameLen = view.getUint16(64, true);
|
|
65
|
+
const type = view.getUint8(66);
|
|
66
|
+
const nameValid = nameLen >= 2 && nameLen <= 64 && nameLen % 2 === 0 && view.getUint16(nameLen - 2, true) === 0;
|
|
67
|
+
let name = "";
|
|
68
|
+
if (nameValid)
|
|
69
|
+
for (let j = 0; j < nameLen - 2; j += 2)
|
|
70
|
+
name += String.fromCharCode(view.getUint16(j, true));
|
|
71
|
+
const link = (offset) => {
|
|
72
|
+
const value = view.getUint32(offset, true);
|
|
73
|
+
return value === NOSTREAM ? -1 : value;
|
|
74
|
+
};
|
|
75
|
+
const sizeLow = view.getUint32(120, true);
|
|
76
|
+
const sizeHigh = view.getUint32(124, true);
|
|
77
|
+
let size = sizeLow;
|
|
78
|
+
if (majorVersion === 4)
|
|
79
|
+
size = sizeLow + sizeHigh * 4294967296;
|
|
80
|
+
else if (sizeHigh !== 0 && type !== ENTRY_TYPE_EMPTY) {
|
|
81
|
+
warnings.push({ code: "size-high-bits", message: `Ignored v3 stream-size high bits on directory entry ${id}` });
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
id,
|
|
85
|
+
type,
|
|
86
|
+
nameValid,
|
|
87
|
+
entry: {
|
|
88
|
+
id,
|
|
89
|
+
name,
|
|
90
|
+
type,
|
|
91
|
+
color: view.getUint8(67),
|
|
92
|
+
leftSiblingId: link(68),
|
|
93
|
+
rightSiblingId: link(72),
|
|
94
|
+
childId: link(76),
|
|
95
|
+
clsid: new Uint8Array(view.buffer.slice(view.byteOffset + 80, view.byteOffset + 96)),
|
|
96
|
+
stateBits: view.getUint32(96, true),
|
|
97
|
+
created: readFileTime(view, 100),
|
|
98
|
+
modified: readFileTime(view, 108),
|
|
99
|
+
startSector: view.getUint32(116, true),
|
|
100
|
+
size,
|
|
101
|
+
parentId: -1
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function readDirectory(dir, majorVersion, strict, warnings) {
|
|
106
|
+
const count = Math.floor(dir.length / DIR_ENTRY_SIZE);
|
|
107
|
+
const slots = [];
|
|
108
|
+
for (let id = 0; id < count; id++)
|
|
109
|
+
slots.push(decodeSlot(dir, id, majorVersion, warnings));
|
|
110
|
+
const roots = slots.filter((slot2) => slot2.type === ENTRY_TYPE_ROOT);
|
|
111
|
+
if (roots.length !== 1 || !roots[0].nameValid)
|
|
112
|
+
throw new Ole2ParseError("Invalid root directory entry");
|
|
113
|
+
const root = roots[0];
|
|
114
|
+
root.entry.path = [];
|
|
115
|
+
const reached = /* @__PURE__ */ new Set([root.id]);
|
|
116
|
+
const fail = (message) => {
|
|
117
|
+
if (strict)
|
|
118
|
+
throw new Ole2ParseError(message);
|
|
119
|
+
warnings.push({ code: "directory-link", message });
|
|
120
|
+
};
|
|
121
|
+
const pending = [];
|
|
122
|
+
const push = (id, parent, from) => {
|
|
123
|
+
if (id === -1)
|
|
124
|
+
return;
|
|
125
|
+
const target = slots[id];
|
|
126
|
+
if (!target || target.type === ENTRY_TYPE_EMPTY || target.type === ENTRY_TYPE_ROOT) {
|
|
127
|
+
fail(`Directory entry ${from} links to invalid entry ${id}`);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (reached.has(id)) {
|
|
131
|
+
fail(`Cyclic directory tree at entry ${id}`);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
reached.add(id);
|
|
135
|
+
pending.push({ id, parent });
|
|
136
|
+
};
|
|
137
|
+
push(root.entry.childId, root, root.id);
|
|
138
|
+
while (pending.length) {
|
|
139
|
+
const { id, parent } = pending.pop();
|
|
140
|
+
const slot2 = slots[id];
|
|
141
|
+
if (!slot2.nameValid)
|
|
142
|
+
throw new Ole2ParseError("Invalid directory entry name");
|
|
143
|
+
slot2.entry.parentId = parent.id;
|
|
144
|
+
slot2.entry.path = [...parent.entry.path, slot2.entry.name];
|
|
145
|
+
push(slot2.entry.leftSiblingId, parent, id);
|
|
146
|
+
push(slot2.entry.rightSiblingId, parent, id);
|
|
147
|
+
if (slot2.type === ENTRY_TYPE_STORAGE)
|
|
148
|
+
push(slot2.entry.childId, slot2, id);
|
|
149
|
+
}
|
|
150
|
+
const entries = [];
|
|
151
|
+
for (const slot2 of slots) {
|
|
152
|
+
if (slot2.type === ENTRY_TYPE_EMPTY)
|
|
153
|
+
continue;
|
|
154
|
+
if (!reached.has(slot2.id)) {
|
|
155
|
+
if (!slot2.nameValid) {
|
|
156
|
+
if (strict)
|
|
157
|
+
throw new Ole2ParseError("Invalid directory entry name");
|
|
158
|
+
warnings.push({ code: "invalid-unreachable-entry", message: `Skipped undecodable stale directory entry ${slot2.id}` });
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (strict)
|
|
162
|
+
throw new Ole2ParseError(`Directory entry ${slot2.id} is not reachable from the root`);
|
|
163
|
+
warnings.push({ code: "unreachable-entry", message: `Directory entry ${slot2.id} (${slot2.entry.name}) is not reachable from the root` });
|
|
164
|
+
}
|
|
165
|
+
entries.push(slot2.entry);
|
|
166
|
+
}
|
|
167
|
+
return entries;
|
|
168
|
+
}
|
|
169
|
+
function sameName(a2, b) {
|
|
170
|
+
return a2.length === b.length && a2.toUpperCase() === b.toUpperCase();
|
|
171
|
+
}
|
|
172
|
+
function bareName(name) {
|
|
173
|
+
return name.replace(/^[\u0001-\u0006]/, "");
|
|
174
|
+
}
|
|
175
|
+
function normalizePath(path2, rootName) {
|
|
176
|
+
const parts = typeof path2 === "string" ? path2.split("/").filter((part) => part !== "") : [...path2];
|
|
177
|
+
if (parts.length && sameName(parts[0], rootName) && typeof path2 === "string")
|
|
178
|
+
parts.shift();
|
|
179
|
+
return parts;
|
|
180
|
+
}
|
|
181
|
+
function child(entries, parentId, name) {
|
|
182
|
+
const children3 = entries.filter((entry2) => entry2.parentId === parentId && entry2.path !== void 0);
|
|
183
|
+
const pick2 = (matches) => matches.length === 1 ? matches[0] : void 0;
|
|
184
|
+
const exact = children3.filter((entry2) => entry2.name === name);
|
|
185
|
+
if (exact.length)
|
|
186
|
+
return pick2(exact);
|
|
187
|
+
const folded = children3.filter((entry2) => sameName(entry2.name, name));
|
|
188
|
+
if (folded.length)
|
|
189
|
+
return pick2(folded);
|
|
190
|
+
return pick2(children3.filter((entry2) => sameName(bareName(entry2.name), bareName(name))));
|
|
191
|
+
}
|
|
192
|
+
function findDirectoryEntry(entries, path2) {
|
|
193
|
+
const root = entries.find((entry2) => entry2.type === ENTRY_TYPE_ROOT);
|
|
194
|
+
if (!root)
|
|
195
|
+
return void 0;
|
|
196
|
+
let current = root;
|
|
197
|
+
for (const name of normalizePath(path2, root.name)) {
|
|
198
|
+
if (current.type !== ENTRY_TYPE_ROOT && current.type !== ENTRY_TYPE_STORAGE)
|
|
199
|
+
return void 0;
|
|
200
|
+
current = child(entries, current.id, name);
|
|
201
|
+
if (!current)
|
|
202
|
+
return void 0;
|
|
203
|
+
}
|
|
204
|
+
return current;
|
|
205
|
+
}
|
|
206
|
+
function findStreamByName(entries, name, isReadable) {
|
|
207
|
+
const root = entries.find((entry2) => entry2.type === ENTRY_TYPE_ROOT);
|
|
208
|
+
if (root && root.name === name)
|
|
209
|
+
return root;
|
|
210
|
+
const top = entries.filter((entry2) => entry2.parentId === root?.id && isReadable(entry2));
|
|
211
|
+
return top.find((entry2) => entry2.name === name) ?? top.find((entry2) => sameName(entry2.name, name)) ?? entries.find((entry2) => entry2.name === name && isReadable(entry2));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-parser-read.js
|
|
215
|
+
function parseOle2(buffer, options = {}) {
|
|
216
|
+
const strict = options.strict === true;
|
|
217
|
+
const data = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
218
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
219
|
+
const warnings = [];
|
|
54
220
|
if (data.length < 512) {
|
|
55
221
|
throw new Ole2ParseError("Truncated OLE2 compound file header");
|
|
56
222
|
}
|
|
@@ -59,11 +225,12 @@ function parseOle2(buffer) {
|
|
|
59
225
|
throw new Ole2ParseError("Not a valid OLE2 compound file");
|
|
60
226
|
}
|
|
61
227
|
}
|
|
62
|
-
view.getUint16(24, true);
|
|
63
228
|
const majorVersion = view.getUint16(26, true);
|
|
64
229
|
const byteOrder = view.getUint16(28, true);
|
|
65
230
|
if (byteOrder !== 65534) {
|
|
66
|
-
|
|
231
|
+
if (strict)
|
|
232
|
+
throw new Ole2ParseError("Invalid byte order mark");
|
|
233
|
+
warnings.push({ code: "byte-order", message: `Ignored byte order mark 0x${byteOrder.toString(16)}` });
|
|
67
234
|
}
|
|
68
235
|
const sectorSizePower = view.getUint16(30, true);
|
|
69
236
|
const miniSectorSizePower = view.getUint16(32, true);
|
|
@@ -72,10 +239,14 @@ function parseOle2(buffer) {
|
|
|
72
239
|
}
|
|
73
240
|
const sectorSize = 1 << sectorSizePower;
|
|
74
241
|
const miniSectorSize = 1 << miniSectorSizePower;
|
|
75
|
-
if (data.length < sectorSize
|
|
242
|
+
if (data.length < sectorSize)
|
|
76
243
|
throw new Ole2ParseError("Truncated OLE2 sector");
|
|
244
|
+
if (data.length % sectorSize !== 0) {
|
|
245
|
+
if (strict)
|
|
246
|
+
throw new Ole2ParseError("Truncated OLE2 sector");
|
|
247
|
+
warnings.push({ code: "unaligned-length", message: `File length ${data.length} is not a multiple of ${sectorSize}` });
|
|
77
248
|
}
|
|
78
|
-
const sectorCount = data.length / sectorSize - 1;
|
|
249
|
+
const sectorCount = Math.ceil(data.length / sectorSize) - 1;
|
|
79
250
|
const totalFATSectors = view.getUint32(44, true);
|
|
80
251
|
const firstDirectorySector = view.getUint32(48, true);
|
|
81
252
|
const miniStreamCutoff = view.getUint32(56, true);
|
|
@@ -96,6 +267,13 @@ function parseOle2(buffer) {
|
|
|
96
267
|
}
|
|
97
268
|
return data.subarray(offset, offset + sectorSize);
|
|
98
269
|
}
|
|
270
|
+
function copySector(sector, target, at, want) {
|
|
271
|
+
const offset = sectorOffset(sector);
|
|
272
|
+
if (sector >= sectorCount || offset + want > data.length) {
|
|
273
|
+
throw new Ole2ParseError(`Sector ${sector} at offset ${offset} exceeds file size ${data.length}`);
|
|
274
|
+
}
|
|
275
|
+
target.set(data.subarray(offset, offset + want), at);
|
|
276
|
+
}
|
|
99
277
|
const fatSectors = [];
|
|
100
278
|
for (let i2 = 0; i2 < 109 && fatSectors.length < totalFATSectors; i2++) {
|
|
101
279
|
const sector = view.getUint32(76 + i2 * 4, true);
|
|
@@ -131,29 +309,36 @@ function parseOle2(buffer) {
|
|
|
131
309
|
fatEntries.push(fatView.getUint32(i2 * 4, true));
|
|
132
310
|
}
|
|
133
311
|
}
|
|
134
|
-
function
|
|
135
|
-
const
|
|
136
|
-
let current = startSector;
|
|
312
|
+
function followChain(table, start, label, needed) {
|
|
313
|
+
const ids = [];
|
|
137
314
|
const visited = /* @__PURE__ */ new Set();
|
|
315
|
+
let current = start;
|
|
138
316
|
while (current <= MAXREGSECT) {
|
|
317
|
+
if (!strict && needed !== void 0 && ids.length >= needed)
|
|
318
|
+
return ids;
|
|
139
319
|
if (visited.has(current)) {
|
|
140
|
-
throw new Ole2ParseError(`Circular reference in
|
|
320
|
+
throw new Ole2ParseError(`Circular reference in ${label} chain at sector ${current}`);
|
|
141
321
|
}
|
|
142
322
|
visited.add(current);
|
|
143
|
-
|
|
144
|
-
if (
|
|
145
|
-
throw new Ole2ParseError(
|
|
146
|
-
current =
|
|
147
|
-
}
|
|
148
|
-
if (current !== ENDOFCHAIN)
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
for (const sector of sectors) {
|
|
154
|
-
result.set(sector, offset);
|
|
155
|
-
offset += sectorSize;
|
|
323
|
+
ids.push(current);
|
|
324
|
+
if (table[current] === void 0)
|
|
325
|
+
throw new Ole2ParseError(`Missing ${label} chain entry`);
|
|
326
|
+
current = table[current];
|
|
327
|
+
}
|
|
328
|
+
if (current !== ENDOFCHAIN) {
|
|
329
|
+
if (strict || needed === void 0 || ids.length < needed) {
|
|
330
|
+
throw new Ole2ParseError(`Invalid ${label} chain terminator`);
|
|
331
|
+
}
|
|
332
|
+
warnings.push({ code: "chain-terminator", message: `Accepted ${label} chain ending in 0x${current.toString(16)}` });
|
|
156
333
|
}
|
|
334
|
+
return ids;
|
|
335
|
+
}
|
|
336
|
+
function readMetadataChain(startSector, label) {
|
|
337
|
+
if (startSector > MAXREGSECT)
|
|
338
|
+
return new Uint8Array(0);
|
|
339
|
+
const ids = followChain(fatEntries, startSector, label === "directory" ? "FAT" : label);
|
|
340
|
+
const result = new Uint8Array(ids.length * sectorSize);
|
|
341
|
+
ids.forEach((id, i2) => result.set(readSector(id), i2 * sectorSize));
|
|
157
342
|
return result;
|
|
158
343
|
}
|
|
159
344
|
function readStream(startSector, size) {
|
|
@@ -161,68 +346,44 @@ function parseOle2(buffer) {
|
|
|
161
346
|
return new Uint8Array(0);
|
|
162
347
|
if (size > sectorCount * sectorSize)
|
|
163
348
|
throw new Ole2ParseError("Stream size exceeds file size");
|
|
164
|
-
const
|
|
165
|
-
|
|
349
|
+
const needed = Math.ceil(size / sectorSize);
|
|
350
|
+
const ids = followChain(fatEntries, startSector, "FAT", needed);
|
|
351
|
+
if (ids.length < needed)
|
|
166
352
|
throw new Ole2ParseError("Truncated stream sector chain");
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const numEntries = Math.floor(dirRaw.length / DIR_ENTRY_SIZE);
|
|
171
|
-
const entries = [];
|
|
172
|
-
for (let i2 = 0; i2 < numEntries; i2++) {
|
|
173
|
-
const entryOffset = i2 * DIR_ENTRY_SIZE;
|
|
174
|
-
const entryView = new DataView(dirRaw.buffer, dirRaw.byteOffset + entryOffset, DIR_ENTRY_SIZE);
|
|
175
|
-
const nameLen = entryView.getUint16(64, true);
|
|
176
|
-
const objectType = entryView.getUint8(66);
|
|
177
|
-
if (objectType === ENTRY_TYPE_EMPTY) {
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
if (nameLen < 2 || nameLen > 64 || nameLen % 2 !== 0 || entryView.getUint16(nameLen - 2, true) !== 0) {
|
|
181
|
-
throw new Ole2ParseError("Invalid directory entry name");
|
|
353
|
+
const result = new Uint8Array(size);
|
|
354
|
+
for (let i2 = 0; i2 < needed; i2++) {
|
|
355
|
+
copySector(ids[i2], result, i2 * sectorSize, Math.min(sectorSize, size - i2 * sectorSize));
|
|
182
356
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const clsid = new Uint8Array(entryView.buffer.slice(entryView.byteOffset + 80, entryView.byteOffset + 96));
|
|
192
|
-
const startSector = entryView.getUint32(116, true);
|
|
193
|
-
const sizeLow = entryView.getUint32(120, true);
|
|
194
|
-
let size = sizeLow;
|
|
195
|
-
if (majorVersion === 4) {
|
|
196
|
-
const sizeHigh = entryView.getUint32(124, true);
|
|
197
|
-
size = sizeLow + sizeHigh * 4294967296;
|
|
198
|
-
if (!Number.isSafeInteger(size) || size > sectorCount * sectorSize) {
|
|
199
|
-
throw new Ole2ParseError("Stream size exceeds supported file bounds");
|
|
200
|
-
}
|
|
357
|
+
return result;
|
|
358
|
+
}
|
|
359
|
+
if (firstDirectorySector > MAXREGSECT)
|
|
360
|
+
throw new Ole2ParseError("Missing directory chain");
|
|
361
|
+
const entries = readDirectory(readMetadataChain(firstDirectorySector, "directory"), majorVersion, strict, warnings);
|
|
362
|
+
for (const entry2 of entries) {
|
|
363
|
+
if (majorVersion === 4 && (!Number.isSafeInteger(entry2.size) || entry2.size > sectorCount * sectorSize)) {
|
|
364
|
+
throw new Ole2ParseError("Stream size exceeds supported file bounds");
|
|
201
365
|
}
|
|
202
|
-
entries.push({
|
|
203
|
-
name,
|
|
204
|
-
type: objectType,
|
|
205
|
-
startSector,
|
|
206
|
-
size,
|
|
207
|
-
childId: childId === 4294967295 ? -1 : childId,
|
|
208
|
-
leftSiblingId: leftSiblingId === 4294967295 ? -1 : leftSiblingId,
|
|
209
|
-
rightSiblingId: rightSiblingId === 4294967295 ? -1 : rightSiblingId,
|
|
210
|
-
clsid
|
|
211
|
-
});
|
|
212
366
|
}
|
|
213
367
|
const rootEntry = entries.find((e) => e.type === ENTRY_TYPE_ROOT);
|
|
214
|
-
if (!rootEntry || entries.filter((e) => e.type === ENTRY_TYPE_ROOT).length !== 1) {
|
|
215
|
-
throw new Ole2ParseError("Invalid root directory entry");
|
|
216
|
-
}
|
|
217
368
|
let miniStreamData;
|
|
218
|
-
if (rootEntry
|
|
369
|
+
if (rootEntry.startSector <= MAXREGSECT) {
|
|
219
370
|
miniStreamData = readStream(rootEntry.startSector, rootEntry.size);
|
|
220
371
|
}
|
|
221
372
|
const miniFatEntries = [];
|
|
222
|
-
if (firstMiniFATSector
|
|
223
|
-
|
|
224
|
-
if (miniFatRaw.length !== totalMiniFATSectors * sectorSize) {
|
|
373
|
+
if (firstMiniFATSector > MAXREGSECT && totalMiniFATSectors > 0) {
|
|
374
|
+
if (strict)
|
|
225
375
|
throw new Ole2ParseError("Unexpected mini FAT chain length");
|
|
376
|
+
warnings.push({ code: "mini-fat-count", message: `Header lists ${totalMiniFATSectors} mini FAT sectors but no chain` });
|
|
377
|
+
}
|
|
378
|
+
if (firstMiniFATSector <= MAXREGSECT && (totalMiniFATSectors > 0 || !strict)) {
|
|
379
|
+
const miniFatRaw = readMetadataChain(firstMiniFATSector, "mini FAT");
|
|
380
|
+
if (miniFatRaw.length !== totalMiniFATSectors * sectorSize) {
|
|
381
|
+
if (strict)
|
|
382
|
+
throw new Ole2ParseError("Unexpected mini FAT chain length");
|
|
383
|
+
warnings.push({
|
|
384
|
+
code: "mini-fat-count",
|
|
385
|
+
message: `Header lists ${totalMiniFATSectors} mini FAT sectors; chain has ${miniFatRaw.length / sectorSize}`
|
|
386
|
+
});
|
|
226
387
|
}
|
|
227
388
|
const miniFatView = new DataView(miniFatRaw.buffer, miniFatRaw.byteOffset, miniFatRaw.byteLength);
|
|
228
389
|
const miniCapacity = Math.floor((miniStreamData?.length ?? 0) / miniSectorSize);
|
|
@@ -236,48 +397,59 @@ function parseOle2(buffer) {
|
|
|
236
397
|
if (!miniStreamData) {
|
|
237
398
|
throw new Ole2ParseError("Mini stream container not found");
|
|
238
399
|
}
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
400
|
+
const needed = Math.ceil(size / miniSectorSize);
|
|
401
|
+
const capacity = miniStreamData.length / miniSectorSize;
|
|
402
|
+
let ids;
|
|
403
|
+
try {
|
|
404
|
+
ids = followChain(miniFatEntries, startSector, "mini FAT", needed);
|
|
405
|
+
} catch (error) {
|
|
406
|
+
if (error instanceof Ole2ParseError && /Missing mini FAT/.test(error.message)) {
|
|
407
|
+
throw new Ole2ParseError("Mini stream sector exceeds allocation bounds");
|
|
245
408
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
409
|
+
throw error;
|
|
410
|
+
}
|
|
411
|
+
const result = new Uint8Array(size);
|
|
412
|
+
for (let i2 = 0; i2 < ids.length && i2 < needed; i2++) {
|
|
413
|
+
const id = ids[i2];
|
|
414
|
+
if (id >= capacity || (id + 1) * miniSectorSize > miniStreamData.length) {
|
|
249
415
|
throw new Ole2ParseError("Mini stream sector exceeds allocation bounds");
|
|
250
416
|
}
|
|
251
|
-
|
|
252
|
-
|
|
417
|
+
const want = Math.min(miniSectorSize, size - i2 * miniSectorSize);
|
|
418
|
+
result.set(miniStreamData.subarray(id * miniSectorSize, id * miniSectorSize + want), i2 * miniSectorSize);
|
|
253
419
|
}
|
|
254
|
-
if (
|
|
255
|
-
throw new Ole2ParseError("Invalid mini FAT chain terminator");
|
|
256
|
-
const totalLength = sectors.length * miniSectorSize;
|
|
257
|
-
if (totalLength < size)
|
|
420
|
+
if (ids.length < needed)
|
|
258
421
|
throw new Ole2ParseError("Truncated mini stream sector chain");
|
|
259
|
-
|
|
260
|
-
let offset = 0;
|
|
261
|
-
for (const sector of sectors) {
|
|
262
|
-
result.set(sector, offset);
|
|
263
|
-
offset += miniSectorSize;
|
|
264
|
-
}
|
|
265
|
-
return result.subarray(0, size);
|
|
422
|
+
return result;
|
|
266
423
|
}
|
|
267
|
-
function
|
|
268
|
-
const entry2 = entries.find((e) => (e.type === ENTRY_TYPE_STREAM || e.type === ENTRY_TYPE_ROOT) && e.name === name);
|
|
269
|
-
if (!entry2) {
|
|
270
|
-
return void 0;
|
|
271
|
-
}
|
|
424
|
+
function readEntry(entry2) {
|
|
272
425
|
if (entry2.size < miniStreamCutoff && entry2.type !== ENTRY_TYPE_ROOT) {
|
|
273
426
|
return readMiniStream(entry2.startSector, entry2.size);
|
|
274
427
|
}
|
|
275
428
|
return readStream(entry2.startSector, entry2.size);
|
|
276
429
|
}
|
|
277
|
-
|
|
430
|
+
const readable = (entry2) => entry2.type === ENTRY_TYPE_STREAM || entry2.type === ENTRY_TYPE_ROOT;
|
|
431
|
+
return {
|
|
432
|
+
entries,
|
|
433
|
+
warnings,
|
|
434
|
+
getStream(name) {
|
|
435
|
+
const entry2 = findStreamByName(entries, name, readable);
|
|
436
|
+
return entry2 ? readEntry(entry2) : void 0;
|
|
437
|
+
},
|
|
438
|
+
getStreamByPath(path2) {
|
|
439
|
+
const entry2 = findDirectoryEntry(entries, path2);
|
|
440
|
+
return entry2 && entry2.type === ENTRY_TYPE_STREAM ? readEntry(entry2) : void 0;
|
|
441
|
+
},
|
|
442
|
+
getStreamById(id) {
|
|
443
|
+
const entry2 = entries.find((candidate) => candidate.id === id);
|
|
444
|
+
return entry2 && readable(entry2) ? readEntry(entry2) : void 0;
|
|
445
|
+
},
|
|
446
|
+
findEntry(path2) {
|
|
447
|
+
return findDirectoryEntry(entries, path2);
|
|
448
|
+
}
|
|
449
|
+
};
|
|
278
450
|
}
|
|
279
451
|
|
|
280
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
452
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/utils/ooxml-crypto-primitives.js
|
|
281
453
|
function getSubtle() {
|
|
282
454
|
if (typeof globalThis.crypto !== "undefined" && globalThis.crypto.subtle) {
|
|
283
455
|
return globalThis.crypto.subtle;
|
|
@@ -2385,7 +2557,7 @@ function isEncryptedOoxmlPackage(input) {
|
|
|
2385
2557
|
}
|
|
2386
2558
|
}
|
|
2387
2559
|
|
|
2388
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
2560
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-helpers.js
|
|
2389
2561
|
function compareDirEntryNames(a2, b) {
|
|
2390
2562
|
const ua = a2.toUpperCase();
|
|
2391
2563
|
const ub = b.toUpperCase();
|
|
@@ -2452,7 +2624,7 @@ function writeInt32Sectors(outBytes, int32Data, firstSector, numSectors, sectorS
|
|
|
2452
2624
|
}
|
|
2453
2625
|
}
|
|
2454
2626
|
|
|
2455
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
2627
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-serialize.js
|
|
2456
2628
|
function writeHeader(outView, outBytes, params) {
|
|
2457
2629
|
outBytes.set(OLE_MAGIC, 0);
|
|
2458
2630
|
outView.setUint16(24, 62, true);
|
|
@@ -2545,7 +2717,7 @@ function writeStreamSectors(outBytes, streamData, chain2, sectorSize) {
|
|
|
2545
2717
|
}
|
|
2546
2718
|
}
|
|
2547
2719
|
|
|
2548
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
2720
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-parser-write.js
|
|
2549
2721
|
function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
|
|
2550
2722
|
const sectorSize = 512;
|
|
2551
2723
|
const miniSectorSize = 64;
|
|
@@ -3277,7 +3449,7 @@ var getR = (element, local) => relAttr(element, local);
|
|
|
3277
3449
|
var makeW = (doc, local) => doc.createElementNS(WORD_NS, `w:${local}`);
|
|
3278
3450
|
|
|
3279
3451
|
// docx/core-properties.ts
|
|
3280
|
-
var
|
|
3452
|
+
var child2 = (parent, local) => elements(parent).find((element) => element.localName === local);
|
|
3281
3453
|
var PROPERTY_FIELDS = [
|
|
3282
3454
|
"title",
|
|
3283
3455
|
"subject",
|
|
@@ -3303,7 +3475,7 @@ function parseCoreProperties(xml) {
|
|
|
3303
3475
|
const root = parseXml2(xml).documentElement;
|
|
3304
3476
|
const result = {};
|
|
3305
3477
|
for (const field of PROPERTY_FIELDS) {
|
|
3306
|
-
const element =
|
|
3478
|
+
const element = child2(root, field);
|
|
3307
3479
|
const value = element ? textContent(element).trim() : "";
|
|
3308
3480
|
if (value) result[field] = value;
|
|
3309
3481
|
}
|
|
@@ -3320,7 +3492,7 @@ async function applyCoreProperties(zip, next, prior) {
|
|
|
3320
3492
|
for (const field of PROPERTY_FIELDS) {
|
|
3321
3493
|
if ((next?.[field] ?? "") === (prior?.[field] ?? "")) continue;
|
|
3322
3494
|
const [prefix, ns] = PREFIX[field];
|
|
3323
|
-
let element =
|
|
3495
|
+
let element = child2(root, field);
|
|
3324
3496
|
const value = next?.[field] ?? "";
|
|
3325
3497
|
if (!value) {
|
|
3326
3498
|
if (element) root.removeChild(element);
|
|
@@ -4682,7 +4854,7 @@ var WRITABLE = /* @__PURE__ */ new Set([
|
|
|
4682
4854
|
function setW5(element, name, value) {
|
|
4683
4855
|
element.setAttributeNS(WORD_NS, `w:${name}`, value);
|
|
4684
4856
|
}
|
|
4685
|
-
function
|
|
4857
|
+
function child3(doc, parent, name, before) {
|
|
4686
4858
|
const existing = first2(parent, name);
|
|
4687
4859
|
if (existing) return existing;
|
|
4688
4860
|
const element = makeW(doc, name);
|
|
@@ -4735,13 +4907,13 @@ var AFTER_TYPE = ["pgSz", ...AFTER_PGSZ];
|
|
|
4735
4907
|
function writeSectionProperties(doc, sectPr, section, base) {
|
|
4736
4908
|
if (section.type === "nextPage")
|
|
4737
4909
|
for (const type of children2(sectPr, "type")) sectPr.removeChild(type);
|
|
4738
|
-
else setW5(
|
|
4739
|
-
const size =
|
|
4910
|
+
else setW5(child3(doc, sectPr, "type", AFTER_TYPE), "val", section.type);
|
|
4911
|
+
const size = child3(doc, sectPr, "pgSz", AFTER_PGSZ);
|
|
4740
4912
|
setW5(size, "w", String(section.pageWidthTwips));
|
|
4741
4913
|
setW5(size, "h", String(section.pageHeightTwips));
|
|
4742
4914
|
if (section.orientation === "landscape") setW5(size, "orient", "landscape");
|
|
4743
4915
|
else size.removeAttributeNS(WORD_NS, "orient");
|
|
4744
|
-
const margins =
|
|
4916
|
+
const margins = child3(doc, sectPr, "pgMar", AFTER_PGSZ.slice(1));
|
|
4745
4917
|
setW5(margins, "top", String(section.marginTopTwips));
|
|
4746
4918
|
setW5(margins, "right", String(section.marginRightTwips));
|
|
4747
4919
|
setW5(margins, "bottom", String(section.marginBottomTwips));
|
|
@@ -4749,7 +4921,7 @@ function writeSectionProperties(doc, sectPr, section, base) {
|
|
|
4749
4921
|
setW5(margins, "header", String(section.headerDistanceTwips ?? 720));
|
|
4750
4922
|
setW5(margins, "footer", String(section.footerDistanceTwips ?? 720));
|
|
4751
4923
|
setW5(margins, "gutter", String(section.gutterTwips ?? 0));
|
|
4752
|
-
const columns =
|
|
4924
|
+
const columns = child3(doc, sectPr, "cols", AFTER_COLS);
|
|
4753
4925
|
setW5(columns, "num", String(section.columns.count));
|
|
4754
4926
|
setW5(columns, "space", String(section.columns.spacingTwips ?? 720));
|
|
4755
4927
|
if (section.columns.equalWidth || !section.columns.widths?.length) {
|
|
@@ -4771,17 +4943,17 @@ function writeSectionProperties(doc, sectPr, section, base) {
|
|
|
4771
4943
|
else columns.removeAttributeNS(WORD_NS, "sep");
|
|
4772
4944
|
if (section.verticalAlign && section.verticalAlign !== "top")
|
|
4773
4945
|
setW5(
|
|
4774
|
-
|
|
4946
|
+
child3(doc, sectPr, "vAlign", ["noEndnote", "titlePg", ...AFTER_TITLEPG]),
|
|
4775
4947
|
"val",
|
|
4776
4948
|
section.verticalAlign
|
|
4777
4949
|
);
|
|
4778
4950
|
else for (const vAlign of children2(sectPr, "vAlign")) sectPr.removeChild(vAlign);
|
|
4779
4951
|
if (section.titlePage)
|
|
4780
|
-
|
|
4952
|
+
child3(doc, sectPr, "titlePg", AFTER_TITLEPG).removeAttributeNS(WORD_NS, "val");
|
|
4781
4953
|
else for (const titlePg of children2(sectPr, "titlePg")) sectPr.removeChild(titlePg);
|
|
4782
4954
|
const line = section.lineNumberSettings;
|
|
4783
4955
|
if (line) {
|
|
4784
|
-
const lnNum =
|
|
4956
|
+
const lnNum = child3(doc, sectPr, "lnNumType", AFTER_LNNUM);
|
|
4785
4957
|
if (line.countBy > 1) setW5(lnNum, "countBy", String(line.countBy));
|
|
4786
4958
|
else lnNum.removeAttributeNS(WORD_NS, "countBy");
|
|
4787
4959
|
if (line.start !== 1) setW5(lnNum, "start", String(line.start - 1));
|
|
@@ -4797,11 +4969,11 @@ function writeSectionProperties(doc, sectPr, section, base) {
|
|
|
4797
4969
|
sectPr,
|
|
4798
4970
|
section.pageBorders,
|
|
4799
4971
|
base?.pageBorders,
|
|
4800
|
-
(d, parent, name) =>
|
|
4972
|
+
(d, parent, name) => child3(d, parent, name, AFTER_PGBORDERS)
|
|
4801
4973
|
);
|
|
4802
4974
|
const numbering = section.pageNumbering;
|
|
4803
4975
|
if (numbering?.format || numbering?.start !== void 0) {
|
|
4804
|
-
const pgNumType =
|
|
4976
|
+
const pgNumType = child3(doc, sectPr, "pgNumType", AFTER_PGNUMTYPE);
|
|
4805
4977
|
if (numbering.format && numbering.format !== "decimal")
|
|
4806
4978
|
setW5(pgNumType, "fmt", numbering.format);
|
|
4807
4979
|
else pgNumType.removeAttributeNS(WORD_NS, "fmt");
|
|
@@ -5152,7 +5324,7 @@ function setAttribute4(element, local, value) {
|
|
|
5152
5324
|
element.setAttributeNS(WORD_NS, `w:${local}`, value);
|
|
5153
5325
|
}
|
|
5154
5326
|
function removeChildren(element, local) {
|
|
5155
|
-
for (const
|
|
5327
|
+
for (const child4 of children2(element, local)) element.removeChild(child4);
|
|
5156
5328
|
}
|
|
5157
5329
|
function writeRevisionMetadata(element, revision) {
|
|
5158
5330
|
setAttribute4(element, "id", revision.id);
|
|
@@ -5457,7 +5629,7 @@ function runPropertiesHaveUnknownContent(properties) {
|
|
|
5457
5629
|
const property = node;
|
|
5458
5630
|
if (property.namespaceURI === WORD_NS && property.localName === "rPrChange") {
|
|
5459
5631
|
if (hasUnexpectedAttributes(property, ["id", "author", "date"], true) || Array.from(property.childNodes).some(
|
|
5460
|
-
(
|
|
5632
|
+
(child4) => child4.nodeType === 3 && child4.textContent?.trim()
|
|
5461
5633
|
) || elements(property).length !== 1 || !first2(property, "rPr") || !getW(property, "id") || !getW(property, "author"))
|
|
5462
5634
|
return true;
|
|
5463
5635
|
continue;
|
|
@@ -5635,7 +5807,7 @@ function setAttribute5(element, local, value) {
|
|
|
5635
5807
|
element.setAttributeNS(WORD_NS, `w:${local}`, value);
|
|
5636
5808
|
}
|
|
5637
5809
|
function removeChildren2(element, local) {
|
|
5638
|
-
for (const
|
|
5810
|
+
for (const child4 of children2(element, local)) element.removeChild(child4);
|
|
5639
5811
|
}
|
|
5640
5812
|
function setToggle(doc, props, local, value) {
|
|
5641
5813
|
removeChildren2(props, local);
|
|
@@ -5819,7 +5991,7 @@ function buildWatermarkRun(doc, spec, uniqueId) {
|
|
|
5819
5991
|
lock.setAttributeNS(VML_NS, "v:ext", "edit");
|
|
5820
5992
|
lock.setAttribute("text", "t");
|
|
5821
5993
|
lock.setAttribute("shapetype", "t");
|
|
5822
|
-
for (const
|
|
5994
|
+
for (const child4 of [formulas, path2, typePath, handles, lock]) type.appendChild(child4);
|
|
5823
5995
|
const size = watermarkSizePt(spec);
|
|
5824
5996
|
const shape = v("shape");
|
|
5825
5997
|
shape.setAttribute("id", `${WATERMARK_PREFIX}${uniqueId}`);
|
|
@@ -5840,7 +6012,7 @@ function buildWatermarkRun(doc, spec, uniqueId) {
|
|
|
5840
6012
|
const wrap = makeNS(doc, WORD10_NS, "w10:wrap");
|
|
5841
6013
|
wrap.setAttribute("anchorx", "margin");
|
|
5842
6014
|
wrap.setAttribute("anchory", "margin");
|
|
5843
|
-
for (const
|
|
6015
|
+
for (const child4 of [fill, text, wrap]) shape.appendChild(child4);
|
|
5844
6016
|
pict.appendChild(type);
|
|
5845
6017
|
pict.appendChild(shape);
|
|
5846
6018
|
run.appendChild(pict);
|
|
@@ -5953,7 +6125,7 @@ function isSimpleTextBox(graphicData, anchored) {
|
|
|
5953
6125
|
if (!graphicData || anchored) return false;
|
|
5954
6126
|
const content = descendants(graphicData, W_NS, "txbxContent")[0];
|
|
5955
6127
|
if (!content) return false;
|
|
5956
|
-
const plain = (node, allowed) => Array.from(node.childNodes).filter(isElement).every((
|
|
6128
|
+
const plain = (node, allowed) => Array.from(node.childNodes).filter(isElement).every((child4) => child4.namespaceURI === W_NS && allowed.includes(child4.localName));
|
|
5957
6129
|
return plain(content, ["p"]) && descendants(content, W_NS, "p").every(
|
|
5958
6130
|
(paragraph) => plain(paragraph, ["r"]) && descendants(paragraph, W_NS, "r").every((run) => plain(run, ["t"]))
|
|
5959
6131
|
);
|
|
@@ -5977,7 +6149,7 @@ function patchTextBox(doc, drawing, image, base) {
|
|
|
5977
6149
|
if (JSON.stringify(image.textBoxText) !== JSON.stringify(base.textBoxText)) {
|
|
5978
6150
|
const content = descendants(drawing, W_NS, "txbxContent")[0];
|
|
5979
6151
|
if (content) {
|
|
5980
|
-
for (const
|
|
6152
|
+
for (const child4 of Array.from(content.childNodes)) content.removeChild(child4);
|
|
5981
6153
|
add(content, ...paragraphsFor(doc, image.textBoxText ?? []));
|
|
5982
6154
|
}
|
|
5983
6155
|
}
|
|
@@ -6176,10 +6348,10 @@ function booleanAttribute(element, name) {
|
|
|
6176
6348
|
function descendants2(root, local) {
|
|
6177
6349
|
const result = [];
|
|
6178
6350
|
const visit = (node) => {
|
|
6179
|
-
for (const
|
|
6180
|
-
if (!isElement(
|
|
6181
|
-
if (
|
|
6182
|
-
visit(
|
|
6351
|
+
for (const child4 of Array.from(node.childNodes)) {
|
|
6352
|
+
if (!isElement(child4)) continue;
|
|
6353
|
+
if (child4.localName === local) result.push(child4);
|
|
6354
|
+
visit(child4);
|
|
6183
6355
|
}
|
|
6184
6356
|
};
|
|
6185
6357
|
visit(root);
|
|
@@ -6331,9 +6503,9 @@ function parseDrawingColor(element) {
|
|
|
6331
6503
|
const color = {
|
|
6332
6504
|
kind,
|
|
6333
6505
|
value: colorValue(kind, element),
|
|
6334
|
-
transforms: elements(element).map((
|
|
6335
|
-
name:
|
|
6336
|
-
value:
|
|
6506
|
+
transforms: elements(element).map((child4) => ({
|
|
6507
|
+
name: child4.localName,
|
|
6508
|
+
value: child4.getAttribute("val") ?? ""
|
|
6337
6509
|
}))
|
|
6338
6510
|
};
|
|
6339
6511
|
const fallback = kind === "system" ? element.getAttribute("lastClr") : null;
|
|
@@ -6569,9 +6741,9 @@ function parseRun(run) {
|
|
|
6569
6741
|
}
|
|
6570
6742
|
function parseParagraph(paragraph) {
|
|
6571
6743
|
const runs = [];
|
|
6572
|
-
for (const
|
|
6573
|
-
if (
|
|
6574
|
-
runs.push(parseRun(
|
|
6744
|
+
for (const child4 of elements(paragraph))
|
|
6745
|
+
if (child4.namespaceURI === NS.a && ["r", "fld", "br"].includes(child4.localName))
|
|
6746
|
+
runs.push(parseRun(child4));
|
|
6575
6747
|
const properties = first(paragraph, "pPr", NS.a);
|
|
6576
6748
|
const align = properties?.getAttribute("algn");
|
|
6577
6749
|
const defaults = parseProperties(first(properties, "defRPr", NS.a));
|
|
@@ -6793,9 +6965,9 @@ function parseDiagramDrawing(source, part) {
|
|
|
6793
6965
|
const tree = root.localName === "spTree" ? root : first(root, "spTree", NS.dsp);
|
|
6794
6966
|
let counter = 0;
|
|
6795
6967
|
const visit = (container2, group) => {
|
|
6796
|
-
for (const
|
|
6797
|
-
if (
|
|
6798
|
-
const element =
|
|
6968
|
+
for (const child4 of Array.from(container2.childNodes)) {
|
|
6969
|
+
if (child4.nodeType !== 1) continue;
|
|
6970
|
+
const element = child4;
|
|
6799
6971
|
if (element.localName === "sp") {
|
|
6800
6972
|
const shape = parseShape(element, counter++, group, issues);
|
|
6801
6973
|
if (shape) shapes.push(shape);
|
|
@@ -7263,11 +7435,11 @@ function cNumber(context, parent, local) {
|
|
|
7263
7435
|
return void 0;
|
|
7264
7436
|
}
|
|
7265
7437
|
function reportUnmodelled(context, element, handled) {
|
|
7266
|
-
for (const
|
|
7267
|
-
if (handled.has(
|
|
7438
|
+
for (const child4 of elements(element)) {
|
|
7439
|
+
if (handled.has(child4.localName)) continue;
|
|
7268
7440
|
context.issues.push({
|
|
7269
7441
|
code: "CHART_ELEMENT_NOT_MODELLED",
|
|
7270
|
-
message: `${path(
|
|
7442
|
+
message: `${path(child4)} is not modelled; it is kept only in the source part.`
|
|
7271
7443
|
});
|
|
7272
7444
|
}
|
|
7273
7445
|
}
|
|
@@ -7834,15 +8006,15 @@ function parsePlotArea(context, element) {
|
|
|
7834
8006
|
return plotArea;
|
|
7835
8007
|
}
|
|
7836
8008
|
const handled = new Set(PLOT_AREA);
|
|
7837
|
-
for (const
|
|
7838
|
-
if (CHART_GROUP_ELEMENTS[
|
|
7839
|
-
plotArea.groups.push(parseGroup(context,
|
|
7840
|
-
handled.add(
|
|
8009
|
+
for (const child4 of elements(element)) {
|
|
8010
|
+
if (CHART_GROUP_ELEMENTS[child4.localName]) {
|
|
8011
|
+
plotArea.groups.push(parseGroup(context, child4));
|
|
8012
|
+
handled.add(child4.localName);
|
|
7841
8013
|
}
|
|
7842
|
-
const axis = AXIS_ELEMENTS[
|
|
8014
|
+
const axis = AXIS_ELEMENTS[child4.localName];
|
|
7843
8015
|
if (axis) {
|
|
7844
|
-
plotArea.axes.push(parseAxis(context,
|
|
7845
|
-
handled.add(
|
|
8016
|
+
plotArea.axes.push(parseAxis(context, child4, axis));
|
|
8017
|
+
handled.add(child4.localName);
|
|
7846
8018
|
}
|
|
7847
8019
|
}
|
|
7848
8020
|
reportUnmodelled(context, element, handled);
|
|
@@ -8288,8 +8460,8 @@ var W_NS2 = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
|
8288
8460
|
var PICTURE_GRAPHIC_URI = "http://schemas.openxmlformats.org/drawingml/2006/picture";
|
|
8289
8461
|
function firstNS(parent, ns, local) {
|
|
8290
8462
|
if (!parent) return void 0;
|
|
8291
|
-
for (const
|
|
8292
|
-
if (isElement(
|
|
8463
|
+
for (const child4 of Array.from(parent.childNodes))
|
|
8464
|
+
if (isElement(child4) && child4.namespaceURI === ns && child4.localName === local) return child4;
|
|
8293
8465
|
return void 0;
|
|
8294
8466
|
}
|
|
8295
8467
|
function descendantNS(parent, ns, local) {
|
|
@@ -8297,10 +8469,10 @@ function descendantNS(parent, ns, local) {
|
|
|
8297
8469
|
const stack = [parent];
|
|
8298
8470
|
while (stack.length) {
|
|
8299
8471
|
const node = stack.shift();
|
|
8300
|
-
for (const
|
|
8301
|
-
if (!isElement(
|
|
8302
|
-
if (
|
|
8303
|
-
stack.push(
|
|
8472
|
+
for (const child4 of Array.from(node.childNodes)) {
|
|
8473
|
+
if (!isElement(child4)) continue;
|
|
8474
|
+
if (child4.namespaceURI === ns && child4.localName === local) return child4;
|
|
8475
|
+
stack.push(child4);
|
|
8304
8476
|
}
|
|
8305
8477
|
}
|
|
8306
8478
|
return void 0;
|
|
@@ -8347,13 +8519,13 @@ function textBoxParagraphs(graphicData) {
|
|
|
8347
8519
|
if (!content) return void 0;
|
|
8348
8520
|
const paragraphs = [];
|
|
8349
8521
|
const visit = (node) => {
|
|
8350
|
-
for (const
|
|
8351
|
-
if (!isElement(
|
|
8352
|
-
if (
|
|
8522
|
+
for (const child4 of Array.from(node.childNodes)) {
|
|
8523
|
+
if (!isElement(child4)) continue;
|
|
8524
|
+
if (child4.namespaceURI === W_NS2 && child4.localName === "p")
|
|
8353
8525
|
paragraphs.push(
|
|
8354
|
-
Array.from(
|
|
8526
|
+
Array.from(child4.getElementsByTagNameNS(W_NS2, "t")).map((t) => t.textContent ?? "").join("")
|
|
8355
8527
|
);
|
|
8356
|
-
else visit(
|
|
8528
|
+
else visit(child4);
|
|
8357
8529
|
}
|
|
8358
8530
|
};
|
|
8359
8531
|
visit(content);
|
|
@@ -8481,8 +8653,8 @@ var PIC_NS = "http://schemas.openxmlformats.org/drawingml/2006/picture";
|
|
|
8481
8653
|
var PICTURE_GRAPHIC_URI2 = "http://schemas.openxmlformats.org/drawingml/2006/picture";
|
|
8482
8654
|
function findDrawingChild(run) {
|
|
8483
8655
|
if (!run) return void 0;
|
|
8484
|
-
for (const
|
|
8485
|
-
if (isElement(
|
|
8656
|
+
for (const child4 of Array.from(run.childNodes))
|
|
8657
|
+
if (isElement(child4) && (named2(child4, "drawing") || named2(child4, "pict"))) return child4;
|
|
8486
8658
|
return void 0;
|
|
8487
8659
|
}
|
|
8488
8660
|
function sameUnderlyingImage(a2, b) {
|
|
@@ -8493,7 +8665,7 @@ function walk(root, visit) {
|
|
|
8493
8665
|
while (stack.length) {
|
|
8494
8666
|
const node = stack.shift();
|
|
8495
8667
|
visit(node);
|
|
8496
|
-
for (const
|
|
8668
|
+
for (const child4 of Array.from(node.childNodes)) if (isElement(child4)) stack.push(child4);
|
|
8497
8669
|
}
|
|
8498
8670
|
}
|
|
8499
8671
|
function updateExtent(drawing, widthPx, heightPx) {
|
|
@@ -8593,9 +8765,9 @@ function buildInlineDrawing(doc, image, relId, docPrId, svgRelId) {
|
|
|
8593
8765
|
return drawing;
|
|
8594
8766
|
}
|
|
8595
8767
|
function clearNonProperties(node, keep) {
|
|
8596
|
-
for (const
|
|
8597
|
-
if (isElement(
|
|
8598
|
-
node.removeChild(
|
|
8768
|
+
for (const child4 of Array.from(node.childNodes)) {
|
|
8769
|
+
if (isElement(child4) && (named2(child4, "rPr") || child4 === keep)) continue;
|
|
8770
|
+
node.removeChild(child4);
|
|
8599
8771
|
}
|
|
8600
8772
|
}
|
|
8601
8773
|
function createImageRun(doc, image, base, old, allocator) {
|
|
@@ -8675,7 +8847,7 @@ function setAttribute6(element, local, value) {
|
|
|
8675
8847
|
element.setAttributeNS(WORD_NS, `w:${local}`, value);
|
|
8676
8848
|
}
|
|
8677
8849
|
function removeChildren3(element, local) {
|
|
8678
|
-
for (const
|
|
8850
|
+
for (const child4 of children2(element, local)) element.removeChild(child4);
|
|
8679
8851
|
}
|
|
8680
8852
|
function setToggle2(doc, props, local, value) {
|
|
8681
8853
|
removeChildren3(props, local);
|
|
@@ -8844,8 +9016,8 @@ function createRun(doc, run, base, old, allocator) {
|
|
|
8844
9016
|
}
|
|
8845
9017
|
setRunProperties(doc, node, run, base);
|
|
8846
9018
|
if (run.image) return node;
|
|
8847
|
-
for (const
|
|
8848
|
-
if (
|
|
9019
|
+
for (const child4 of Array.from(node.childNodes))
|
|
9020
|
+
if (child4.nodeType !== 1 || child4.localName !== "rPr") node.removeChild(child4);
|
|
8849
9021
|
if (run.break) {
|
|
8850
9022
|
const br = makeW(doc, "br");
|
|
8851
9023
|
setAttribute6(br, "type", run.break);
|
|
@@ -8994,9 +9166,9 @@ function trackMoveRange(item, moves) {
|
|
|
8994
9166
|
}
|
|
8995
9167
|
function isCommentReferenceRun(run) {
|
|
8996
9168
|
const content = Array.from(run.childNodes).filter(
|
|
8997
|
-
(
|
|
9169
|
+
(child4) => isElement(child4) && !named2(child4, "rPr")
|
|
8998
9170
|
);
|
|
8999
|
-
return content.length > 0 && content.every((
|
|
9171
|
+
return content.length > 0 && content.every((child4) => named2(child4, "commentReference"));
|
|
9000
9172
|
}
|
|
9001
9173
|
function revisionFrom(node, kind) {
|
|
9002
9174
|
const revision = {
|
|
@@ -9046,8 +9218,8 @@ function collectParagraphRuns(node, parseRun3, parseOther, resolveLink, active =
|
|
|
9046
9218
|
if (!isCommentReferenceRun(item)) push(parseRun3(item));
|
|
9047
9219
|
} else if (named2(item, "hyperlink")) {
|
|
9048
9220
|
const link = resolveLink?.(item);
|
|
9049
|
-
for (const
|
|
9050
|
-
for (const parsed of named2(
|
|
9221
|
+
for (const child4 of Array.from(item.childNodes).filter(isElement)) {
|
|
9222
|
+
for (const parsed of named2(child4, "r") ? [parseRun3(child4)] : parseOther?.(child4) ?? []) {
|
|
9051
9223
|
if (link) parsed.link = link;
|
|
9052
9224
|
push(parsed);
|
|
9053
9225
|
}
|
|
@@ -9061,8 +9233,8 @@ function collectParagraphRuns(node, parseRun3, parseOther, resolveLink, active =
|
|
|
9061
9233
|
const revision = revisionFrom(item, kind);
|
|
9062
9234
|
const range = kind === "moveFrom" || kind === "moveTo" ? moves[kind].at(-1) : void 0;
|
|
9063
9235
|
if (range) revision.move = { name: range.name, rangeId: range.id };
|
|
9064
|
-
for (const
|
|
9065
|
-
for (const parsed of named2(
|
|
9236
|
+
for (const child4 of Array.from(item.childNodes).filter(isElement)) {
|
|
9237
|
+
for (const parsed of named2(child4, "r") ? [parseRun3(child4, revision)] : parseOther?.(child4) ?? []) {
|
|
9066
9238
|
parsed.revision = revision;
|
|
9067
9239
|
push(parsed);
|
|
9068
9240
|
}
|
|
@@ -9086,7 +9258,7 @@ function collectParagraphRuns(node, parseRun3, parseOther, resolveLink, active =
|
|
|
9086
9258
|
// docx/write-inline.ts
|
|
9087
9259
|
function runIsSafe(run) {
|
|
9088
9260
|
const content = Array.from(run.childNodes).filter(
|
|
9089
|
-
(
|
|
9261
|
+
(child4) => isElement(child4) && !named2(child4, "rPr") && !isCachedPageBreak(child4)
|
|
9090
9262
|
);
|
|
9091
9263
|
const only = content.length === 1 ? content[0] : void 0;
|
|
9092
9264
|
if (only && named2(only, "br") && isModeledBreak(only)) return true;
|
|
@@ -9108,56 +9280,56 @@ function runIsSafe(run) {
|
|
|
9108
9280
|
return !((kinds.has("drawing") || kinds.has("pict")) && kinds.size > 1);
|
|
9109
9281
|
}
|
|
9110
9282
|
function runsOf(parent, container2, slots) {
|
|
9111
|
-
for (const
|
|
9112
|
-
if (!isElement(
|
|
9113
|
-
if (
|
|
9283
|
+
for (const child4 of Array.from(parent.childNodes)) {
|
|
9284
|
+
if (!isElement(child4)) {
|
|
9285
|
+
if (child4.nodeType === 3 && child4.textContent?.trim()) return false;
|
|
9114
9286
|
continue;
|
|
9115
9287
|
}
|
|
9116
|
-
if (isEquationElement(
|
|
9117
|
-
slots.push({ element:
|
|
9118
|
-
} else if (named2(
|
|
9119
|
-
if (isCommentReferenceRun(
|
|
9120
|
-
if (!runIsSafe(
|
|
9121
|
-
slots.push({ element:
|
|
9122
|
-
} else if (isRevisionWrapperElement(
|
|
9123
|
-
if (!runsOf(
|
|
9124
|
-
} else if ((named2(
|
|
9288
|
+
if (isEquationElement(child4)) {
|
|
9289
|
+
slots.push({ element: child4, ...container2 && { container: container2 } });
|
|
9290
|
+
} else if (named2(child4, "r")) {
|
|
9291
|
+
if (isCommentReferenceRun(child4)) continue;
|
|
9292
|
+
if (!runIsSafe(child4)) return false;
|
|
9293
|
+
slots.push({ element: child4, ...container2 && { container: container2 } });
|
|
9294
|
+
} else if (isRevisionWrapperElement(child4) && !container2) {
|
|
9295
|
+
if (!runsOf(child4, void 0, slots)) return false;
|
|
9296
|
+
} else if ((named2(child4, "hyperlink") || named2(child4, "fldSimple")) && !container2) {
|
|
9125
9297
|
const before = slots.length;
|
|
9126
|
-
if (!runsOf(
|
|
9127
|
-
if (named2(
|
|
9128
|
-
} else if (isCommentAnchorElement(
|
|
9298
|
+
if (!runsOf(child4, child4, slots)) return false;
|
|
9299
|
+
if (named2(child4, "fldSimple") && slots.length === before) slots.push({ container: child4 });
|
|
9300
|
+
} else if (isCommentAnchorElement(child4) && !container2) continue;
|
|
9129
9301
|
else return false;
|
|
9130
9302
|
}
|
|
9131
9303
|
return true;
|
|
9132
9304
|
}
|
|
9133
9305
|
function collectInlineSlots(paragraph) {
|
|
9134
9306
|
const slots = [];
|
|
9135
|
-
for (const
|
|
9136
|
-
if (isElement(
|
|
9307
|
+
for (const child4 of Array.from(paragraph.childNodes)) {
|
|
9308
|
+
if (isElement(child4) && (named2(child4, "pPr") || named2(child4, "bookmarkStart") || named2(child4, "bookmarkEnd")))
|
|
9137
9309
|
continue;
|
|
9138
|
-
if (!isElement(
|
|
9139
|
-
if (
|
|
9310
|
+
if (!isElement(child4)) {
|
|
9311
|
+
if (child4.nodeType === 3 && child4.textContent?.trim()) return void 0;
|
|
9140
9312
|
continue;
|
|
9141
9313
|
}
|
|
9142
|
-
if (isEquationElement(
|
|
9143
|
-
slots.push({ element:
|
|
9144
|
-
} else if (named2(
|
|
9145
|
-
if (isCommentReferenceRun(
|
|
9146
|
-
if (!runIsSafe(
|
|
9147
|
-
slots.push({ element:
|
|
9148
|
-
} else if (isRevisionWrapperElement(
|
|
9149
|
-
if (!runsOf(
|
|
9150
|
-
} else if (named2(
|
|
9314
|
+
if (isEquationElement(child4)) {
|
|
9315
|
+
slots.push({ element: child4 });
|
|
9316
|
+
} else if (named2(child4, "r")) {
|
|
9317
|
+
if (isCommentReferenceRun(child4)) continue;
|
|
9318
|
+
if (!runIsSafe(child4)) return void 0;
|
|
9319
|
+
slots.push({ element: child4 });
|
|
9320
|
+
} else if (isRevisionWrapperElement(child4)) {
|
|
9321
|
+
if (!runsOf(child4, void 0, slots)) return void 0;
|
|
9322
|
+
} else if (named2(child4, "hyperlink") || named2(child4, "fldSimple")) {
|
|
9151
9323
|
const before = slots.length;
|
|
9152
|
-
if (!runsOf(
|
|
9153
|
-
if (named2(
|
|
9154
|
-
} else if (!isCommentAnchorElement(
|
|
9324
|
+
if (!runsOf(child4, child4, slots)) return void 0;
|
|
9325
|
+
if (named2(child4, "fldSimple") && slots.length === before) slots.push({ container: child4 });
|
|
9326
|
+
} else if (!isCommentAnchorElement(child4)) return void 0;
|
|
9155
9327
|
}
|
|
9156
9328
|
return slots;
|
|
9157
9329
|
}
|
|
9158
9330
|
function replaceableInlineChildren(paragraph) {
|
|
9159
9331
|
return Array.from(paragraph.childNodes).filter(
|
|
9160
|
-
(
|
|
9332
|
+
(child4) => isElement(child4) && (isEquationElement(child4) || named2(child4, "r") || named2(child4, "hyperlink") || named2(child4, "fldSimple") || isRevisionWrapperElement(child4) || isCommentAnchorElement(child4))
|
|
9161
9333
|
);
|
|
9162
9334
|
}
|
|
9163
9335
|
function sameLink(a2, b) {
|
|
@@ -9227,7 +9399,7 @@ function buildInlineContent(doc, runs, base, slots, allocator, ranges) {
|
|
|
9227
9399
|
let container2;
|
|
9228
9400
|
if (reusable) {
|
|
9229
9401
|
container2 = onlyContainer;
|
|
9230
|
-
for (const
|
|
9402
|
+
for (const child4 of Array.from(container2.childNodes)) container2.removeChild(child4);
|
|
9231
9403
|
} else if (group.kind === "link") container2 = newHyperlink(doc, group.link, allocator);
|
|
9232
9404
|
else {
|
|
9233
9405
|
container2 = makeW(doc, "fldSimple");
|
|
@@ -9451,7 +9623,7 @@ function setAttribute7(element, local, value) {
|
|
|
9451
9623
|
element.setAttributeNS(WORD_NS, `w:${local}`, value);
|
|
9452
9624
|
}
|
|
9453
9625
|
function removeChildren4(element, local) {
|
|
9454
|
-
for (const
|
|
9626
|
+
for (const child4 of children2(element, local)) element.removeChild(child4);
|
|
9455
9627
|
}
|
|
9456
9628
|
function rejectUnsafeRunSegmentation(paragraph, base, oldRuns) {
|
|
9457
9629
|
if (!base || !oldRuns.some(runHasUnknownProperties)) return;
|
|
@@ -9606,7 +9778,7 @@ function scanUsedRelationshipIds(doc) {
|
|
|
9606
9778
|
const visit = (node) => {
|
|
9607
9779
|
for (const attribute2 of Array.from(node.attributes))
|
|
9608
9780
|
if (attribute2.namespaceURI === REL_NS) used.add(attribute2.value);
|
|
9609
|
-
for (const
|
|
9781
|
+
for (const child4 of Array.from(node.childNodes)) if (isElement(child4)) visit(child4);
|
|
9610
9782
|
};
|
|
9611
9783
|
if (doc.documentElement) visit(doc.documentElement);
|
|
9612
9784
|
return used;
|
|
@@ -10654,7 +10826,7 @@ function setNumPr(style, numbering) {
|
|
|
10654
10826
|
if (!numbering && !pPr) return;
|
|
10655
10827
|
if (!pPr) {
|
|
10656
10828
|
pPr = makeW(doc, "pPr");
|
|
10657
|
-
const anchor = elementsOf(style).find((
|
|
10829
|
+
const anchor = elementsOf(style).find((child4) => AFTER_PPR.includes(child4.localName)) ?? null;
|
|
10658
10830
|
style.insertBefore(pPr, anchor);
|
|
10659
10831
|
}
|
|
10660
10832
|
for (const existing of children2(pPr, "numPr")) pPr.removeChild(existing);
|
|
@@ -11632,12 +11804,12 @@ function createFieldTracker() {
|
|
|
11632
11804
|
return (element, run) => {
|
|
11633
11805
|
let resultInstr;
|
|
11634
11806
|
let resultLocked;
|
|
11635
|
-
for (const
|
|
11636
|
-
if (!isElement(
|
|
11637
|
-
if (named2(
|
|
11638
|
-
const type = getW(
|
|
11807
|
+
for (const child4 of Array.from(element.childNodes)) {
|
|
11808
|
+
if (!isElement(child4)) continue;
|
|
11809
|
+
if (named2(child4, "fldChar")) {
|
|
11810
|
+
const type = getW(child4, "fldCharType");
|
|
11639
11811
|
if (type === "begin") {
|
|
11640
|
-
const locked = parseFieldFlags(
|
|
11812
|
+
const locked = parseFieldFlags(child4)?.locked;
|
|
11641
11813
|
stack.push({ instr: "", inResult: false, ...locked !== void 0 && { locked } });
|
|
11642
11814
|
} else if (type === "separate") {
|
|
11643
11815
|
const top = stack.at(-1);
|
|
@@ -11645,8 +11817,8 @@ function createFieldTracker() {
|
|
|
11645
11817
|
} else if (type === "end") stack.pop();
|
|
11646
11818
|
} else {
|
|
11647
11819
|
const top = stack.at(-1);
|
|
11648
|
-
if (named2(
|
|
11649
|
-
else if ((named2(
|
|
11820
|
+
if (named2(child4, "instrText") && top && !top.inResult) top.instr += textContent(child4);
|
|
11821
|
+
else if ((named2(child4, "t") || named2(child4, "delText")) && top?.inResult) {
|
|
11650
11822
|
resultInstr = top.instr.trim();
|
|
11651
11823
|
resultLocked = top.locked;
|
|
11652
11824
|
}
|
|
@@ -11673,7 +11845,7 @@ function storyFieldResults(container2) {
|
|
|
11673
11845
|
});
|
|
11674
11846
|
return;
|
|
11675
11847
|
}
|
|
11676
|
-
for (const
|
|
11848
|
+
for (const child4 of Array.from(element.childNodes)) if (isElement(child4)) visit(child4);
|
|
11677
11849
|
};
|
|
11678
11850
|
visit(container2);
|
|
11679
11851
|
return metadata;
|
|
@@ -11695,13 +11867,13 @@ var activeContext;
|
|
|
11695
11867
|
var openComments;
|
|
11696
11868
|
var openMoves;
|
|
11697
11869
|
function runContent(node) {
|
|
11698
|
-
return Array.from(node.childNodes).filter(isElement).filter((
|
|
11870
|
+
return Array.from(node.childNodes).filter(isElement).filter((child4) => child4.localName !== "rPr" && !isCachedPageBreak(child4));
|
|
11699
11871
|
}
|
|
11700
11872
|
function findDrawing(content) {
|
|
11701
|
-
for (const
|
|
11702
|
-
if (named2(
|
|
11703
|
-
if (
|
|
11704
|
-
const choice = Array.from(
|
|
11873
|
+
for (const child4 of content) {
|
|
11874
|
+
if (named2(child4, "drawing") || named2(child4, "pict")) return child4;
|
|
11875
|
+
if (child4.localName !== "AlternateContent") continue;
|
|
11876
|
+
const choice = Array.from(child4.childNodes).filter(isElement).find((node) => node.localName === "Choice");
|
|
11705
11877
|
const found = choice && findDrawing(Array.from(choice.childNodes).filter(isElement));
|
|
11706
11878
|
if (found) return found;
|
|
11707
11879
|
}
|
|
@@ -11731,7 +11903,7 @@ function parseRun2(node, revision) {
|
|
|
11731
11903
|
let noteReference;
|
|
11732
11904
|
let noteMark;
|
|
11733
11905
|
let fieldChar;
|
|
11734
|
-
const fieldCode = content.length > 0 && content.every((
|
|
11906
|
+
const fieldCode = content.length > 0 && content.every((child4) => named2(child4, "instrText")) ? content.map((child4) => textContent(child4)).join("") : void 0;
|
|
11735
11907
|
const only = content.length === 1 ? content[0] : void 0;
|
|
11736
11908
|
if (only) {
|
|
11737
11909
|
if (named2(only, "br")) {
|
|
@@ -11750,11 +11922,11 @@ function parseRun2(node, revision) {
|
|
|
11750
11922
|
if (type === "begin" || type === "separate" || type === "end") fieldChar = type;
|
|
11751
11923
|
}
|
|
11752
11924
|
}
|
|
11753
|
-
const text = breakKind || noteReference || noteMark || fieldChar || fieldCode !== void 0 ? "" : content.map((
|
|
11754
|
-
if (named2(
|
|
11755
|
-
if (named2(
|
|
11756
|
-
if (named2(
|
|
11757
|
-
if (named2(
|
|
11925
|
+
const text = breakKind || noteReference || noteMark || fieldChar || fieldCode !== void 0 ? "" : content.map((child4) => {
|
|
11926
|
+
if (named2(child4, "t") || named2(child4, "delText")) return textContent(child4);
|
|
11927
|
+
if (named2(child4, "tab")) return " ";
|
|
11928
|
+
if (named2(child4, "br") || named2(child4, "cr")) return "\n";
|
|
11929
|
+
if (named2(child4, "noBreakHyphen")) return "\u2011";
|
|
11758
11930
|
return "";
|
|
11759
11931
|
}).join("");
|
|
11760
11932
|
const run = { text, ...parseDirectRunProperties(props) };
|
|
@@ -11801,8 +11973,8 @@ function parseParagraph2(node, id, fields) {
|
|
|
11801
11973
|
const { runs: results } = collectParagraphRuns(
|
|
11802
11974
|
item,
|
|
11803
11975
|
parseRun2,
|
|
11804
|
-
(
|
|
11805
|
-
const equation2 = parseEquation(
|
|
11976
|
+
(child4) => {
|
|
11977
|
+
const equation2 = parseEquation(child4);
|
|
11806
11978
|
return equation2 ? [equation2] : void 0;
|
|
11807
11979
|
},
|
|
11808
11980
|
void 0,
|
|
@@ -12461,7 +12633,7 @@ function createDocument() {
|
|
|
12461
12633
|
};
|
|
12462
12634
|
}
|
|
12463
12635
|
|
|
12464
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
12636
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fib.js
|
|
12465
12637
|
var FC_LCB_INDEX = {
|
|
12466
12638
|
plcfbteChpx: 12,
|
|
12467
12639
|
plcfbtePapx: 13,
|
|
@@ -12557,7 +12729,7 @@ function patchDocFib(wordDoc, fib, patch) {
|
|
|
12557
12729
|
view.setUint32(papxOff + 4, patch.plcfbtePapx.lcb, true);
|
|
12558
12730
|
}
|
|
12559
12731
|
|
|
12560
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
12732
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-stream-edit.js
|
|
12561
12733
|
var END = 4294967294;
|
|
12562
12734
|
var MAX = 4294967290;
|
|
12563
12735
|
var NIL = 4294967295;
|
|
@@ -12592,6 +12764,58 @@ function chainToEnd(table, start, max) {
|
|
|
12592
12764
|
}
|
|
12593
12765
|
return out;
|
|
12594
12766
|
}
|
|
12767
|
+
function chainPrefix(table, start, needed) {
|
|
12768
|
+
const out = [], seen = /* @__PURE__ */ new Set();
|
|
12769
|
+
let id = start;
|
|
12770
|
+
while (out.length < needed) {
|
|
12771
|
+
if (id > MAX || id >= table.length || seen.has(id))
|
|
12772
|
+
throw new Error("Invalid CFB chain");
|
|
12773
|
+
seen.add(id);
|
|
12774
|
+
out.push(id);
|
|
12775
|
+
id = table[id];
|
|
12776
|
+
}
|
|
12777
|
+
return out;
|
|
12778
|
+
}
|
|
12779
|
+
function readTarget(input, target, root, fat, sector, sectorCount, sectorSize, miniSize, read32) {
|
|
12780
|
+
const size = target.size;
|
|
12781
|
+
if (size === 0)
|
|
12782
|
+
return new Uint8Array(0);
|
|
12783
|
+
const out = new Uint8Array(size);
|
|
12784
|
+
const copyPhysical = (at, want, into) => {
|
|
12785
|
+
if (at + want > input.length)
|
|
12786
|
+
throw new Error("Stream data exceeds file size");
|
|
12787
|
+
out.set(input.subarray(at, at + want), into);
|
|
12788
|
+
};
|
|
12789
|
+
if (size >= read32(56)) {
|
|
12790
|
+
if (size > sectorCount * sectorSize)
|
|
12791
|
+
throw new Error("Stream size exceeds file size");
|
|
12792
|
+
chainPrefix(fat, target.start, Math.ceil(size / sectorSize)).forEach((id, i2) => {
|
|
12793
|
+
if (id >= sectorCount)
|
|
12794
|
+
throw new Error("Invalid sector");
|
|
12795
|
+
copyPhysical((id + 1) * sectorSize, Math.min(sectorSize, size - i2 * sectorSize), i2 * sectorSize);
|
|
12796
|
+
});
|
|
12797
|
+
return out;
|
|
12798
|
+
}
|
|
12799
|
+
const miniFatSectors = chainToEnd(fat, read32(60), sectorCount);
|
|
12800
|
+
const miniCapacity = Math.floor(Math.min(root.size, sectorCount * sectorSize) / miniSize);
|
|
12801
|
+
const miniFat = [];
|
|
12802
|
+
for (const id of miniFatSectors) {
|
|
12803
|
+
const bytes = sector(id), dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
12804
|
+
for (let j = 0; j < sectorSize / 4 && miniFat.length < miniCapacity; j++)
|
|
12805
|
+
miniFat.push(dv.getUint32(j * 4, true));
|
|
12806
|
+
}
|
|
12807
|
+
const rootSectors = chainPrefix(fat, root.start, Math.ceil(root.size / sectorSize));
|
|
12808
|
+
chainPrefix(miniFat, target.start, Math.ceil(size / miniSize)).forEach((id, i2) => {
|
|
12809
|
+
const start = id * miniSize, want = Math.min(miniSize, size - i2 * miniSize);
|
|
12810
|
+
if (start + want > root.size)
|
|
12811
|
+
throw new Error("Mini stream out of bounds");
|
|
12812
|
+
const rootSector = rootSectors[Math.floor(start / sectorSize)];
|
|
12813
|
+
if (rootSector >= sectorCount)
|
|
12814
|
+
throw new Error("Invalid sector");
|
|
12815
|
+
copyPhysical((rootSector + 1) * sectorSize + start % sectorSize, want, i2 * miniSize);
|
|
12816
|
+
});
|
|
12817
|
+
return out;
|
|
12818
|
+
}
|
|
12595
12819
|
function processCompoundFileStream(input, path2, replacement) {
|
|
12596
12820
|
const reject = () => replacement ? input : void 0;
|
|
12597
12821
|
try {
|
|
@@ -12599,18 +12823,19 @@ function processCompoundFileStream(input, path2, replacement) {
|
|
|
12599
12823
|
return reject();
|
|
12600
12824
|
const view = new DataView(input.buffer, input.byteOffset, input.byteLength);
|
|
12601
12825
|
const read32 = (offset2) => view.getUint32(offset2, true);
|
|
12602
|
-
if (input[0] !== 208 || input[1] !== 207 || input[2] !== 17 || input[3] !== 224 || input[4] !== 161 || input[5] !== 177 || input[6] !== 26 || input[7] !== 225 ||
|
|
12826
|
+
if (input[0] !== 208 || input[1] !== 207 || input[2] !== 17 || input[3] !== 224 || input[4] !== 161 || input[5] !== 177 || input[6] !== 26 || input[7] !== 225 || // Readers tolerate a non-canonical byte-order mark; edits do not.
|
|
12827
|
+
replacement && view.getUint16(28, true) !== 65534)
|
|
12603
12828
|
return reject();
|
|
12604
12829
|
const major = view.getUint16(26, true), shift = view.getUint16(30, true), miniShift = view.getUint16(32, true);
|
|
12605
12830
|
if (major !== 3 && major !== 4 || shift !== (major === 3 ? 9 : 12) || miniShift !== 6)
|
|
12606
12831
|
return reject();
|
|
12607
12832
|
const sectorSize = 1 << shift, miniSize = 1 << miniShift;
|
|
12608
|
-
if (input.length % sectorSize !== 0)
|
|
12833
|
+
if (input.length < sectorSize || replacement && input.length % sectorSize !== 0)
|
|
12609
12834
|
return reject();
|
|
12610
|
-
const sectorCount = input.length / sectorSize - 1;
|
|
12835
|
+
const sectorCount = Math.ceil(input.length / sectorSize) - 1;
|
|
12611
12836
|
const offset = (id) => (id + 1) * sectorSize;
|
|
12612
12837
|
const sector = (id) => {
|
|
12613
|
-
if (id > MAX || id >= sectorCount)
|
|
12838
|
+
if (id > MAX || id >= sectorCount || offset(id) + sectorSize > input.length)
|
|
12614
12839
|
throw new Error("Invalid sector");
|
|
12615
12840
|
return input.subarray(offset(id), offset(id) + sectorSize);
|
|
12616
12841
|
};
|
|
@@ -12660,7 +12885,7 @@ function processCompoundFileStream(input, path2, replacement) {
|
|
|
12660
12885
|
for (let i2 = 0; i2 < nameLength - 2; i2 += 2)
|
|
12661
12886
|
name += String.fromCharCode(dvDir.getUint16(p + i2, true));
|
|
12662
12887
|
const sizeLow = dvDir.getUint32(p + 120, true), sizeHigh = dvDir.getUint32(p + 124, true);
|
|
12663
|
-
if (sizeHigh !== 0)
|
|
12888
|
+
if (sizeHigh !== 0 && (replacement || major === 4))
|
|
12664
12889
|
return reject();
|
|
12665
12890
|
entries.push({
|
|
12666
12891
|
id,
|
|
@@ -12707,6 +12932,8 @@ function processCompoundFileStream(input, path2, replacement) {
|
|
|
12707
12932
|
}
|
|
12708
12933
|
if (!target)
|
|
12709
12934
|
return reject();
|
|
12935
|
+
if (!replacement)
|
|
12936
|
+
return readTarget(input, target, root, fat, sector, sectorCount, sectorSize, miniSize, read32);
|
|
12710
12937
|
const names = entries.map((e) => e.name.toLowerCase());
|
|
12711
12938
|
if (replacement && (names.includes("encryptioninfo") || names.includes("encryptedpackage")))
|
|
12712
12939
|
return reject();
|
|
@@ -12830,7 +13057,7 @@ function replaceCompoundFileStream(input, path2, replacement) {
|
|
|
12830
13057
|
return processCompoundFileStream(input, path2, replacement) ?? input;
|
|
12831
13058
|
}
|
|
12832
13059
|
|
|
12833
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
13060
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-v4.js
|
|
12834
13061
|
var END2 = 4294967294;
|
|
12835
13062
|
var FREE = 4294967295;
|
|
12836
13063
|
var FAT = 4294967293;
|
|
@@ -13018,7 +13245,7 @@ function resizeCompoundFileStreamV4(input, path2, replacement) {
|
|
|
13018
13245
|
}
|
|
13019
13246
|
}
|
|
13020
13247
|
|
|
13021
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
13248
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-allocation.js
|
|
13022
13249
|
function appendCompoundAllocations(input, existingFatIds, payloads, sectorSize = 512) {
|
|
13023
13250
|
const sectorCount = input.length / sectorSize - 1;
|
|
13024
13251
|
const entriesPerFat = sectorSize / 4;
|
|
@@ -13065,7 +13292,7 @@ function followCompoundAllocation(table, start) {
|
|
|
13065
13292
|
return ids;
|
|
13066
13293
|
}
|
|
13067
13294
|
|
|
13068
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
13295
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-mini.js
|
|
13069
13296
|
var END3 = 4294967294;
|
|
13070
13297
|
var FREE2 = 4294967295;
|
|
13071
13298
|
var SECTOR = 512;
|
|
@@ -13137,7 +13364,7 @@ function resizeMiniCompoundStream(input, fat, fatIds, root, target, replacement,
|
|
|
13137
13364
|
return output.bytes;
|
|
13138
13365
|
}
|
|
13139
13366
|
|
|
13140
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
13367
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize.js
|
|
13141
13368
|
var END4 = 4294967294;
|
|
13142
13369
|
var FREE3 = 4294967295;
|
|
13143
13370
|
var FAT2 = 4294967293;
|
|
@@ -13302,7 +13529,7 @@ function resizeCompoundFileStream(input, path2, replacement) {
|
|
|
13302
13529
|
}
|
|
13303
13530
|
}
|
|
13304
13531
|
|
|
13305
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
13532
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cfb.js
|
|
13306
13533
|
var DocCfbRewriteError = class extends Error {
|
|
13307
13534
|
constructor(message) {
|
|
13308
13535
|
super(message);
|
|
@@ -13357,7 +13584,7 @@ function unwrapDocBytes(bytes) {
|
|
|
13357
13584
|
}
|
|
13358
13585
|
}
|
|
13359
13586
|
|
|
13360
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
13587
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fkp.js
|
|
13361
13588
|
var PAGE_SIZE = 512;
|
|
13362
13589
|
function parseBteTable(tableStream, at) {
|
|
13363
13590
|
const view = new DataView(tableStream.buffer, tableStream.byteOffset, tableStream.byteLength);
|
|
@@ -13498,7 +13725,7 @@ function buildSingleRunChpxPage(fcStart, fcEnd, blob) {
|
|
|
13498
13725
|
return page;
|
|
13499
13726
|
}
|
|
13500
13727
|
|
|
13501
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
13728
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cp1252.js
|
|
13502
13729
|
var CP1252_HIGH_BLOCK = [
|
|
13503
13730
|
8364,
|
|
13504
13731
|
129,
|
|
@@ -13566,7 +13793,7 @@ function encodeCp1252(text) {
|
|
|
13566
13793
|
return Uint8Array.from(bytes);
|
|
13567
13794
|
}
|
|
13568
13795
|
|
|
13569
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
13796
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole-document-doc-pieces.js
|
|
13570
13797
|
var CLXT_PRC = 1;
|
|
13571
13798
|
var CLXT_PCDT = 2;
|
|
13572
13799
|
var DocResourceLimitError = class extends Error {
|
|
@@ -13778,7 +14005,7 @@ function buildClxBytes(pieces, prcBytes = new Uint8Array()) {
|
|
|
13778
14005
|
return result;
|
|
13779
14006
|
}
|
|
13780
14007
|
|
|
13781
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
14008
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fields.js
|
|
13782
14009
|
var UnsupportedDocFieldEditError = class extends Error {
|
|
13783
14010
|
constructor(message) {
|
|
13784
14011
|
super(message);
|
|
@@ -13862,7 +14089,7 @@ function shiftDocMainFieldCps(table, at, body, editStart, editEnd, delta, maxFie
|
|
|
13862
14089
|
return result;
|
|
13863
14090
|
}
|
|
13864
14091
|
|
|
13865
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
14092
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole-document-doc-editor.js
|
|
13866
14093
|
var RISKY_PLCF_INDICES = [2, 3, 4, 5, 17, 18, 19, 20, 40, 41, 42, 43, 46, 47, 48, 54, 55, 56, 57, 58, 59, 75, 76, 89, 90];
|
|
13867
14094
|
var RISKY_STTB_INDICES = [21, 22, 23];
|
|
13868
14095
|
var SAFE_EXTENDED_FC_LCB_INDICES = /* @__PURE__ */ new Set([93, 94, 113, 181, 182]);
|