ooxml-core 1.6.1 → 1.7.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/dist/{PptxHandler-BTXB54UC.mjs → PptxHandler-BL4B7CZO.mjs} +2 -2
- package/dist/automation/index.cjs +482 -232
- package/dist/automation/index.mjs +482 -232
- package/dist/{chunk-CS7HRNHL.mjs → chunk-GAGSCAR3.mjs} +43 -43
- package/dist/{chunk-5CJRDY7Q.mjs → chunk-NIHPA63A.mjs} +1 -1
- package/dist/{chunk-Q5LESLDA.mjs → chunk-TTPZITQN.mjs} +841 -614
- package/dist/{chunk-4L4UB3RQ.mjs → chunk-Z7IQR4S4.mjs} +3 -3
- package/dist/{chunk-RIFVZP2S.mjs → chunk-ZAP5WLEN.mjs} +1 -1
- package/dist/crypto/index.cjs +281 -109
- package/dist/crypto/index.mjs +281 -109
- package/dist/docx/load/index.cjs +481 -254
- package/dist/docx/load/index.mjs +481 -254
- package/dist/geometry/index.cjs +25 -0
- package/dist/geometry/index.d.ts +1 -0
- package/dist/geometry/index.d.ts.map +1 -1
- package/dist/geometry/index.mjs +24 -1
- package/dist/geometry/nudge.d.ts +12 -0
- package/dist/geometry/nudge.d.ts.map +1 -0
- package/dist/geometry/rotation-drag.d.ts +6 -0
- package/dist/geometry/rotation-drag.d.ts.map +1 -1
- package/dist/index.cjs +25 -0
- package/dist/index.mjs +25 -0
- package/dist/pptx/automation/index.cjs +1395 -1156
- package/dist/pptx/automation/index.d.ts +1 -1
- package/dist/pptx/automation/index.mjs +5 -5
- package/dist/pptx/chunks/{index-DkHgeV1p.d.ts → index-Cn-GzYGp.d.ts} +62 -13
- package/dist/pptx/chunks/{index-DkHgeV1p.d.ts.map → index-Cn-GzYGp.d.ts.map} +1 -1
- package/dist/pptx/cli/index.cjs +1274 -1090
- package/dist/pptx/cli/index.mjs +4 -4
- package/dist/pptx/converter/index.cjs +7 -2
- package/dist/pptx/converter/index.mjs +2 -2
- package/dist/pptx/index.cjs +1415 -1176
- package/dist/pptx/index.d.ts +1 -1
- package/dist/pptx/index.mjs +5 -5
- package/dist/teams/index.cjs +7 -2
- package/dist/teams/index.mjs +7 -2
- package/dist/visio/edit-commands.d.ts +3 -1
- package/dist/visio/edit-commands.d.ts.map +1 -1
- package/dist/visio/edit-layer-properties.d.ts +22 -0
- package/dist/visio/edit-layer-properties.d.ts.map +1 -0
- package/dist/visio/edit-text-instance.d.ts +21 -0
- package/dist/visio/edit-text-instance.d.ts.map +1 -0
- package/dist/visio/edit-text-ranges.d.ts.map +1 -1
- package/dist/visio/edit-text-scope.d.ts +6 -1
- package/dist/visio/edit-text-scope.d.ts.map +1 -1
- package/dist/visio/edit-text-target.d.ts +11 -1
- package/dist/visio/edit-text-target.d.ts.map +1 -1
- package/dist/visio/edit-text.d.ts +2 -1
- package/dist/visio/edit-text.d.ts.map +1 -1
- package/dist/visio/edit.d.ts +1 -1
- package/dist/visio/edit.d.ts.map +1 -1
- package/dist/visio/index.cjs +1038 -538
- package/dist/visio/index.d.ts +1 -1
- package/dist/visio/index.d.ts.map +1 -1
- package/dist/visio/index.mjs +1038 -538
- package/dist/visio/text-fields.d.ts.map +1 -1
- package/dist/visio/ui/edit-commands.d.ts.map +1 -1
- package/dist/visio/ui/edit-error.d.ts +4 -1
- package/dist/visio/ui/edit-error.d.ts.map +1 -1
- package/dist/visio/ui/guides.d.ts +5 -0
- package/dist/visio/ui/guides.d.ts.map +1 -1
- package/dist/visio/ui/index.cjs +19768 -1874
- package/dist/visio/ui/index.d.ts +1 -0
- package/dist/visio/ui/index.d.ts.map +1 -1
- package/dist/visio/ui/index.mjs +19765 -1877
- package/dist/visio/ui/sample-drawing.d.ts +8 -0
- package/dist/visio/ui/sample-drawing.d.ts.map +1 -0
- package/dist/visio/ui/shape-move.d.ts +6 -0
- package/dist/visio/ui/shape-move.d.ts.map +1 -1
- package/dist/xlsx/load/index.cjs +415 -188
- package/dist/xlsx/load/index.mjs +415 -188
- package/package.json +6 -5
package/dist/docx/load/index.cjs
CHANGED
|
@@ -35,7 +35,7 @@ function isOoxmlCryptoError(error) {
|
|
|
35
35
|
return code === "password-required" || code === "incorrect-password" || code === "data-integrity";
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
38
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-parser-types.js
|
|
39
39
|
var OLE_MAGIC = new Uint8Array([208, 207, 17, 224, 161, 177, 26, 225]);
|
|
40
40
|
var ENDOFCHAIN = 4294967294;
|
|
41
41
|
var FREESECT = 4294967295;
|
|
@@ -43,7 +43,9 @@ var FATSECT = 4294967293;
|
|
|
43
43
|
var DIFSECT = 4294967292;
|
|
44
44
|
var MAXREGSECT = 4294967290;
|
|
45
45
|
var ENTRY_TYPE_EMPTY = 0;
|
|
46
|
+
var ENTRY_TYPE_STORAGE = 1;
|
|
46
47
|
var ENTRY_TYPE_STREAM = 2;
|
|
48
|
+
var NOSTREAM = 4294967295;
|
|
47
49
|
var ENTRY_TYPE_ROOT = 5;
|
|
48
50
|
var DIR_ENTRY_SIZE = 128;
|
|
49
51
|
var Ole2ParseError = class extends Error {
|
|
@@ -53,10 +55,174 @@ var Ole2ParseError = class extends Error {
|
|
|
53
55
|
}
|
|
54
56
|
};
|
|
55
57
|
|
|
56
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
58
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-directory.js
|
|
59
|
+
var FILETIME_UNIX_EPOCH = 116444736000000000n;
|
|
60
|
+
function readFileTime(view, offset) {
|
|
61
|
+
const ticks = view.getBigUint64(offset, true);
|
|
62
|
+
if (ticks === 0n)
|
|
63
|
+
return void 0;
|
|
64
|
+
const ms = Number((ticks - FILETIME_UNIX_EPOCH) / 10000n);
|
|
65
|
+
const date = new Date(ms);
|
|
66
|
+
return Number.isNaN(date.getTime()) ? void 0 : date;
|
|
67
|
+
}
|
|
68
|
+
function decodeSlot(dir, id, majorVersion, warnings) {
|
|
69
|
+
const view = new DataView(dir.buffer, dir.byteOffset + id * DIR_ENTRY_SIZE, DIR_ENTRY_SIZE);
|
|
70
|
+
const nameLen = view.getUint16(64, true);
|
|
71
|
+
const type = view.getUint8(66);
|
|
72
|
+
const nameValid = nameLen >= 2 && nameLen <= 64 && nameLen % 2 === 0 && view.getUint16(nameLen - 2, true) === 0;
|
|
73
|
+
let name = "";
|
|
74
|
+
if (nameValid)
|
|
75
|
+
for (let j = 0; j < nameLen - 2; j += 2)
|
|
76
|
+
name += String.fromCharCode(view.getUint16(j, true));
|
|
77
|
+
const link = (offset) => {
|
|
78
|
+
const value = view.getUint32(offset, true);
|
|
79
|
+
return value === NOSTREAM ? -1 : value;
|
|
80
|
+
};
|
|
81
|
+
const sizeLow = view.getUint32(120, true);
|
|
82
|
+
const sizeHigh = view.getUint32(124, true);
|
|
83
|
+
let size = sizeLow;
|
|
84
|
+
if (majorVersion === 4)
|
|
85
|
+
size = sizeLow + sizeHigh * 4294967296;
|
|
86
|
+
else if (sizeHigh !== 0 && type !== ENTRY_TYPE_EMPTY) {
|
|
87
|
+
warnings.push({ code: "size-high-bits", message: `Ignored v3 stream-size high bits on directory entry ${id}` });
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
id,
|
|
91
|
+
type,
|
|
92
|
+
nameValid,
|
|
93
|
+
entry: {
|
|
94
|
+
id,
|
|
95
|
+
name,
|
|
96
|
+
type,
|
|
97
|
+
color: view.getUint8(67),
|
|
98
|
+
leftSiblingId: link(68),
|
|
99
|
+
rightSiblingId: link(72),
|
|
100
|
+
childId: link(76),
|
|
101
|
+
clsid: new Uint8Array(view.buffer.slice(view.byteOffset + 80, view.byteOffset + 96)),
|
|
102
|
+
stateBits: view.getUint32(96, true),
|
|
103
|
+
created: readFileTime(view, 100),
|
|
104
|
+
modified: readFileTime(view, 108),
|
|
105
|
+
startSector: view.getUint32(116, true),
|
|
106
|
+
size,
|
|
107
|
+
parentId: -1
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function readDirectory(dir, majorVersion, strict, warnings) {
|
|
112
|
+
const count = Math.floor(dir.length / DIR_ENTRY_SIZE);
|
|
113
|
+
const slots = [];
|
|
114
|
+
for (let id = 0; id < count; id++)
|
|
115
|
+
slots.push(decodeSlot(dir, id, majorVersion, warnings));
|
|
116
|
+
const roots = slots.filter((slot2) => slot2.type === ENTRY_TYPE_ROOT);
|
|
117
|
+
if (roots.length !== 1 || !roots[0].nameValid)
|
|
118
|
+
throw new Ole2ParseError("Invalid root directory entry");
|
|
119
|
+
const root = roots[0];
|
|
120
|
+
root.entry.path = [];
|
|
121
|
+
const reached = /* @__PURE__ */ new Set([root.id]);
|
|
122
|
+
const fail = (message) => {
|
|
123
|
+
if (strict)
|
|
124
|
+
throw new Ole2ParseError(message);
|
|
125
|
+
warnings.push({ code: "directory-link", message });
|
|
126
|
+
};
|
|
127
|
+
const pending = [];
|
|
128
|
+
const push = (id, parent, from) => {
|
|
129
|
+
if (id === -1)
|
|
130
|
+
return;
|
|
131
|
+
const target = slots[id];
|
|
132
|
+
if (!target || target.type === ENTRY_TYPE_EMPTY || target.type === ENTRY_TYPE_ROOT) {
|
|
133
|
+
fail(`Directory entry ${from} links to invalid entry ${id}`);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (reached.has(id)) {
|
|
137
|
+
fail(`Cyclic directory tree at entry ${id}`);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
reached.add(id);
|
|
141
|
+
pending.push({ id, parent });
|
|
142
|
+
};
|
|
143
|
+
push(root.entry.childId, root, root.id);
|
|
144
|
+
while (pending.length) {
|
|
145
|
+
const { id, parent } = pending.pop();
|
|
146
|
+
const slot2 = slots[id];
|
|
147
|
+
if (!slot2.nameValid)
|
|
148
|
+
throw new Ole2ParseError("Invalid directory entry name");
|
|
149
|
+
slot2.entry.parentId = parent.id;
|
|
150
|
+
slot2.entry.path = [...parent.entry.path, slot2.entry.name];
|
|
151
|
+
push(slot2.entry.leftSiblingId, parent, id);
|
|
152
|
+
push(slot2.entry.rightSiblingId, parent, id);
|
|
153
|
+
if (slot2.type === ENTRY_TYPE_STORAGE)
|
|
154
|
+
push(slot2.entry.childId, slot2, id);
|
|
155
|
+
}
|
|
156
|
+
const entries = [];
|
|
157
|
+
for (const slot2 of slots) {
|
|
158
|
+
if (slot2.type === ENTRY_TYPE_EMPTY)
|
|
159
|
+
continue;
|
|
160
|
+
if (!reached.has(slot2.id)) {
|
|
161
|
+
if (!slot2.nameValid) {
|
|
162
|
+
if (strict)
|
|
163
|
+
throw new Ole2ParseError("Invalid directory entry name");
|
|
164
|
+
warnings.push({ code: "invalid-unreachable-entry", message: `Skipped undecodable stale directory entry ${slot2.id}` });
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (strict)
|
|
168
|
+
throw new Ole2ParseError(`Directory entry ${slot2.id} is not reachable from the root`);
|
|
169
|
+
warnings.push({ code: "unreachable-entry", message: `Directory entry ${slot2.id} (${slot2.entry.name}) is not reachable from the root` });
|
|
170
|
+
}
|
|
171
|
+
entries.push(slot2.entry);
|
|
172
|
+
}
|
|
173
|
+
return entries;
|
|
174
|
+
}
|
|
175
|
+
function sameName(a2, b) {
|
|
176
|
+
return a2.length === b.length && a2.toUpperCase() === b.toUpperCase();
|
|
177
|
+
}
|
|
178
|
+
function bareName(name) {
|
|
179
|
+
return name.replace(/^[\u0001-\u0006]/, "");
|
|
180
|
+
}
|
|
181
|
+
function normalizePath(path2, rootName) {
|
|
182
|
+
const parts = typeof path2 === "string" ? path2.split("/").filter((part) => part !== "") : [...path2];
|
|
183
|
+
if (parts.length && sameName(parts[0], rootName) && typeof path2 === "string")
|
|
184
|
+
parts.shift();
|
|
185
|
+
return parts;
|
|
186
|
+
}
|
|
187
|
+
function child(entries, parentId, name) {
|
|
188
|
+
const children3 = entries.filter((entry2) => entry2.parentId === parentId && entry2.path !== void 0);
|
|
189
|
+
const pick2 = (matches) => matches.length === 1 ? matches[0] : void 0;
|
|
190
|
+
const exact = children3.filter((entry2) => entry2.name === name);
|
|
191
|
+
if (exact.length)
|
|
192
|
+
return pick2(exact);
|
|
193
|
+
const folded = children3.filter((entry2) => sameName(entry2.name, name));
|
|
194
|
+
if (folded.length)
|
|
195
|
+
return pick2(folded);
|
|
196
|
+
return pick2(children3.filter((entry2) => sameName(bareName(entry2.name), bareName(name))));
|
|
197
|
+
}
|
|
198
|
+
function findDirectoryEntry(entries, path2) {
|
|
199
|
+
const root = entries.find((entry2) => entry2.type === ENTRY_TYPE_ROOT);
|
|
200
|
+
if (!root)
|
|
201
|
+
return void 0;
|
|
202
|
+
let current = root;
|
|
203
|
+
for (const name of normalizePath(path2, root.name)) {
|
|
204
|
+
if (current.type !== ENTRY_TYPE_ROOT && current.type !== ENTRY_TYPE_STORAGE)
|
|
205
|
+
return void 0;
|
|
206
|
+
current = child(entries, current.id, name);
|
|
207
|
+
if (!current)
|
|
208
|
+
return void 0;
|
|
209
|
+
}
|
|
210
|
+
return current;
|
|
211
|
+
}
|
|
212
|
+
function findStreamByName(entries, name, isReadable) {
|
|
213
|
+
const root = entries.find((entry2) => entry2.type === ENTRY_TYPE_ROOT);
|
|
214
|
+
if (root && root.name === name)
|
|
215
|
+
return root;
|
|
216
|
+
const top = entries.filter((entry2) => entry2.parentId === root?.id && isReadable(entry2));
|
|
217
|
+
return top.find((entry2) => entry2.name === name) ?? top.find((entry2) => sameName(entry2.name, name)) ?? entries.find((entry2) => entry2.name === name && isReadable(entry2));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-parser-read.js
|
|
221
|
+
function parseOle2(buffer, options = {}) {
|
|
222
|
+
const strict = options.strict === true;
|
|
223
|
+
const data = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
224
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
225
|
+
const warnings = [];
|
|
60
226
|
if (data.length < 512) {
|
|
61
227
|
throw new Ole2ParseError("Truncated OLE2 compound file header");
|
|
62
228
|
}
|
|
@@ -65,11 +231,12 @@ function parseOle2(buffer) {
|
|
|
65
231
|
throw new Ole2ParseError("Not a valid OLE2 compound file");
|
|
66
232
|
}
|
|
67
233
|
}
|
|
68
|
-
view.getUint16(24, true);
|
|
69
234
|
const majorVersion = view.getUint16(26, true);
|
|
70
235
|
const byteOrder = view.getUint16(28, true);
|
|
71
236
|
if (byteOrder !== 65534) {
|
|
72
|
-
|
|
237
|
+
if (strict)
|
|
238
|
+
throw new Ole2ParseError("Invalid byte order mark");
|
|
239
|
+
warnings.push({ code: "byte-order", message: `Ignored byte order mark 0x${byteOrder.toString(16)}` });
|
|
73
240
|
}
|
|
74
241
|
const sectorSizePower = view.getUint16(30, true);
|
|
75
242
|
const miniSectorSizePower = view.getUint16(32, true);
|
|
@@ -78,10 +245,14 @@ function parseOle2(buffer) {
|
|
|
78
245
|
}
|
|
79
246
|
const sectorSize = 1 << sectorSizePower;
|
|
80
247
|
const miniSectorSize = 1 << miniSectorSizePower;
|
|
81
|
-
if (data.length < sectorSize
|
|
248
|
+
if (data.length < sectorSize)
|
|
82
249
|
throw new Ole2ParseError("Truncated OLE2 sector");
|
|
250
|
+
if (data.length % sectorSize !== 0) {
|
|
251
|
+
if (strict)
|
|
252
|
+
throw new Ole2ParseError("Truncated OLE2 sector");
|
|
253
|
+
warnings.push({ code: "unaligned-length", message: `File length ${data.length} is not a multiple of ${sectorSize}` });
|
|
83
254
|
}
|
|
84
|
-
const sectorCount = data.length / sectorSize - 1;
|
|
255
|
+
const sectorCount = Math.ceil(data.length / sectorSize) - 1;
|
|
85
256
|
const totalFATSectors = view.getUint32(44, true);
|
|
86
257
|
const firstDirectorySector = view.getUint32(48, true);
|
|
87
258
|
const miniStreamCutoff = view.getUint32(56, true);
|
|
@@ -102,6 +273,13 @@ function parseOle2(buffer) {
|
|
|
102
273
|
}
|
|
103
274
|
return data.subarray(offset, offset + sectorSize);
|
|
104
275
|
}
|
|
276
|
+
function copySector(sector, target, at, want) {
|
|
277
|
+
const offset = sectorOffset(sector);
|
|
278
|
+
if (sector >= sectorCount || offset + want > data.length) {
|
|
279
|
+
throw new Ole2ParseError(`Sector ${sector} at offset ${offset} exceeds file size ${data.length}`);
|
|
280
|
+
}
|
|
281
|
+
target.set(data.subarray(offset, offset + want), at);
|
|
282
|
+
}
|
|
105
283
|
const fatSectors = [];
|
|
106
284
|
for (let i2 = 0; i2 < 109 && fatSectors.length < totalFATSectors; i2++) {
|
|
107
285
|
const sector = view.getUint32(76 + i2 * 4, true);
|
|
@@ -137,29 +315,36 @@ function parseOle2(buffer) {
|
|
|
137
315
|
fatEntries.push(fatView.getUint32(i2 * 4, true));
|
|
138
316
|
}
|
|
139
317
|
}
|
|
140
|
-
function
|
|
141
|
-
const
|
|
142
|
-
let current = startSector;
|
|
318
|
+
function followChain(table, start, label, needed) {
|
|
319
|
+
const ids = [];
|
|
143
320
|
const visited = /* @__PURE__ */ new Set();
|
|
321
|
+
let current = start;
|
|
144
322
|
while (current <= MAXREGSECT) {
|
|
323
|
+
if (!strict && needed !== void 0 && ids.length >= needed)
|
|
324
|
+
return ids;
|
|
145
325
|
if (visited.has(current)) {
|
|
146
|
-
throw new Ole2ParseError(`Circular reference in
|
|
326
|
+
throw new Ole2ParseError(`Circular reference in ${label} chain at sector ${current}`);
|
|
147
327
|
}
|
|
148
328
|
visited.add(current);
|
|
149
|
-
|
|
150
|
-
if (
|
|
151
|
-
throw new Ole2ParseError(
|
|
152
|
-
current =
|
|
153
|
-
}
|
|
154
|
-
if (current !== ENDOFCHAIN)
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
for (const sector of sectors) {
|
|
160
|
-
result.set(sector, offset);
|
|
161
|
-
offset += sectorSize;
|
|
329
|
+
ids.push(current);
|
|
330
|
+
if (table[current] === void 0)
|
|
331
|
+
throw new Ole2ParseError(`Missing ${label} chain entry`);
|
|
332
|
+
current = table[current];
|
|
333
|
+
}
|
|
334
|
+
if (current !== ENDOFCHAIN) {
|
|
335
|
+
if (strict || needed === void 0 || ids.length < needed) {
|
|
336
|
+
throw new Ole2ParseError(`Invalid ${label} chain terminator`);
|
|
337
|
+
}
|
|
338
|
+
warnings.push({ code: "chain-terminator", message: `Accepted ${label} chain ending in 0x${current.toString(16)}` });
|
|
162
339
|
}
|
|
340
|
+
return ids;
|
|
341
|
+
}
|
|
342
|
+
function readMetadataChain(startSector, label) {
|
|
343
|
+
if (startSector > MAXREGSECT)
|
|
344
|
+
return new Uint8Array(0);
|
|
345
|
+
const ids = followChain(fatEntries, startSector, label === "directory" ? "FAT" : label);
|
|
346
|
+
const result = new Uint8Array(ids.length * sectorSize);
|
|
347
|
+
ids.forEach((id, i2) => result.set(readSector(id), i2 * sectorSize));
|
|
163
348
|
return result;
|
|
164
349
|
}
|
|
165
350
|
function readStream(startSector, size) {
|
|
@@ -167,68 +352,44 @@ function parseOle2(buffer) {
|
|
|
167
352
|
return new Uint8Array(0);
|
|
168
353
|
if (size > sectorCount * sectorSize)
|
|
169
354
|
throw new Ole2ParseError("Stream size exceeds file size");
|
|
170
|
-
const
|
|
171
|
-
|
|
355
|
+
const needed = Math.ceil(size / sectorSize);
|
|
356
|
+
const ids = followChain(fatEntries, startSector, "FAT", needed);
|
|
357
|
+
if (ids.length < needed)
|
|
172
358
|
throw new Ole2ParseError("Truncated stream sector chain");
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const numEntries = Math.floor(dirRaw.length / DIR_ENTRY_SIZE);
|
|
177
|
-
const entries = [];
|
|
178
|
-
for (let i2 = 0; i2 < numEntries; i2++) {
|
|
179
|
-
const entryOffset = i2 * DIR_ENTRY_SIZE;
|
|
180
|
-
const entryView = new DataView(dirRaw.buffer, dirRaw.byteOffset + entryOffset, DIR_ENTRY_SIZE);
|
|
181
|
-
const nameLen = entryView.getUint16(64, true);
|
|
182
|
-
const objectType = entryView.getUint8(66);
|
|
183
|
-
if (objectType === ENTRY_TYPE_EMPTY) {
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
if (nameLen < 2 || nameLen > 64 || nameLen % 2 !== 0 || entryView.getUint16(nameLen - 2, true) !== 0) {
|
|
187
|
-
throw new Ole2ParseError("Invalid directory entry name");
|
|
359
|
+
const result = new Uint8Array(size);
|
|
360
|
+
for (let i2 = 0; i2 < needed; i2++) {
|
|
361
|
+
copySector(ids[i2], result, i2 * sectorSize, Math.min(sectorSize, size - i2 * sectorSize));
|
|
188
362
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const clsid = new Uint8Array(entryView.buffer.slice(entryView.byteOffset + 80, entryView.byteOffset + 96));
|
|
198
|
-
const startSector = entryView.getUint32(116, true);
|
|
199
|
-
const sizeLow = entryView.getUint32(120, true);
|
|
200
|
-
let size = sizeLow;
|
|
201
|
-
if (majorVersion === 4) {
|
|
202
|
-
const sizeHigh = entryView.getUint32(124, true);
|
|
203
|
-
size = sizeLow + sizeHigh * 4294967296;
|
|
204
|
-
if (!Number.isSafeInteger(size) || size > sectorCount * sectorSize) {
|
|
205
|
-
throw new Ole2ParseError("Stream size exceeds supported file bounds");
|
|
206
|
-
}
|
|
363
|
+
return result;
|
|
364
|
+
}
|
|
365
|
+
if (firstDirectorySector > MAXREGSECT)
|
|
366
|
+
throw new Ole2ParseError("Missing directory chain");
|
|
367
|
+
const entries = readDirectory(readMetadataChain(firstDirectorySector, "directory"), majorVersion, strict, warnings);
|
|
368
|
+
for (const entry2 of entries) {
|
|
369
|
+
if (majorVersion === 4 && (!Number.isSafeInteger(entry2.size) || entry2.size > sectorCount * sectorSize)) {
|
|
370
|
+
throw new Ole2ParseError("Stream size exceeds supported file bounds");
|
|
207
371
|
}
|
|
208
|
-
entries.push({
|
|
209
|
-
name,
|
|
210
|
-
type: objectType,
|
|
211
|
-
startSector,
|
|
212
|
-
size,
|
|
213
|
-
childId: childId === 4294967295 ? -1 : childId,
|
|
214
|
-
leftSiblingId: leftSiblingId === 4294967295 ? -1 : leftSiblingId,
|
|
215
|
-
rightSiblingId: rightSiblingId === 4294967295 ? -1 : rightSiblingId,
|
|
216
|
-
clsid
|
|
217
|
-
});
|
|
218
372
|
}
|
|
219
373
|
const rootEntry = entries.find((e) => e.type === ENTRY_TYPE_ROOT);
|
|
220
|
-
if (!rootEntry || entries.filter((e) => e.type === ENTRY_TYPE_ROOT).length !== 1) {
|
|
221
|
-
throw new Ole2ParseError("Invalid root directory entry");
|
|
222
|
-
}
|
|
223
374
|
let miniStreamData;
|
|
224
|
-
if (rootEntry
|
|
375
|
+
if (rootEntry.startSector <= MAXREGSECT) {
|
|
225
376
|
miniStreamData = readStream(rootEntry.startSector, rootEntry.size);
|
|
226
377
|
}
|
|
227
378
|
const miniFatEntries = [];
|
|
228
|
-
if (firstMiniFATSector
|
|
229
|
-
|
|
230
|
-
if (miniFatRaw.length !== totalMiniFATSectors * sectorSize) {
|
|
379
|
+
if (firstMiniFATSector > MAXREGSECT && totalMiniFATSectors > 0) {
|
|
380
|
+
if (strict)
|
|
231
381
|
throw new Ole2ParseError("Unexpected mini FAT chain length");
|
|
382
|
+
warnings.push({ code: "mini-fat-count", message: `Header lists ${totalMiniFATSectors} mini FAT sectors but no chain` });
|
|
383
|
+
}
|
|
384
|
+
if (firstMiniFATSector <= MAXREGSECT && (totalMiniFATSectors > 0 || !strict)) {
|
|
385
|
+
const miniFatRaw = readMetadataChain(firstMiniFATSector, "mini FAT");
|
|
386
|
+
if (miniFatRaw.length !== totalMiniFATSectors * sectorSize) {
|
|
387
|
+
if (strict)
|
|
388
|
+
throw new Ole2ParseError("Unexpected mini FAT chain length");
|
|
389
|
+
warnings.push({
|
|
390
|
+
code: "mini-fat-count",
|
|
391
|
+
message: `Header lists ${totalMiniFATSectors} mini FAT sectors; chain has ${miniFatRaw.length / sectorSize}`
|
|
392
|
+
});
|
|
232
393
|
}
|
|
233
394
|
const miniFatView = new DataView(miniFatRaw.buffer, miniFatRaw.byteOffset, miniFatRaw.byteLength);
|
|
234
395
|
const miniCapacity = Math.floor((miniStreamData?.length ?? 0) / miniSectorSize);
|
|
@@ -242,48 +403,59 @@ function parseOle2(buffer) {
|
|
|
242
403
|
if (!miniStreamData) {
|
|
243
404
|
throw new Ole2ParseError("Mini stream container not found");
|
|
244
405
|
}
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
406
|
+
const needed = Math.ceil(size / miniSectorSize);
|
|
407
|
+
const capacity = miniStreamData.length / miniSectorSize;
|
|
408
|
+
let ids;
|
|
409
|
+
try {
|
|
410
|
+
ids = followChain(miniFatEntries, startSector, "mini FAT", needed);
|
|
411
|
+
} catch (error) {
|
|
412
|
+
if (error instanceof Ole2ParseError && /Missing mini FAT/.test(error.message)) {
|
|
413
|
+
throw new Ole2ParseError("Mini stream sector exceeds allocation bounds");
|
|
251
414
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
415
|
+
throw error;
|
|
416
|
+
}
|
|
417
|
+
const result = new Uint8Array(size);
|
|
418
|
+
for (let i2 = 0; i2 < ids.length && i2 < needed; i2++) {
|
|
419
|
+
const id = ids[i2];
|
|
420
|
+
if (id >= capacity || (id + 1) * miniSectorSize > miniStreamData.length) {
|
|
255
421
|
throw new Ole2ParseError("Mini stream sector exceeds allocation bounds");
|
|
256
422
|
}
|
|
257
|
-
|
|
258
|
-
|
|
423
|
+
const want = Math.min(miniSectorSize, size - i2 * miniSectorSize);
|
|
424
|
+
result.set(miniStreamData.subarray(id * miniSectorSize, id * miniSectorSize + want), i2 * miniSectorSize);
|
|
259
425
|
}
|
|
260
|
-
if (
|
|
261
|
-
throw new Ole2ParseError("Invalid mini FAT chain terminator");
|
|
262
|
-
const totalLength = sectors.length * miniSectorSize;
|
|
263
|
-
if (totalLength < size)
|
|
426
|
+
if (ids.length < needed)
|
|
264
427
|
throw new Ole2ParseError("Truncated mini stream sector chain");
|
|
265
|
-
|
|
266
|
-
let offset = 0;
|
|
267
|
-
for (const sector of sectors) {
|
|
268
|
-
result.set(sector, offset);
|
|
269
|
-
offset += miniSectorSize;
|
|
270
|
-
}
|
|
271
|
-
return result.subarray(0, size);
|
|
428
|
+
return result;
|
|
272
429
|
}
|
|
273
|
-
function
|
|
274
|
-
const entry2 = entries.find((e) => (e.type === ENTRY_TYPE_STREAM || e.type === ENTRY_TYPE_ROOT) && e.name === name);
|
|
275
|
-
if (!entry2) {
|
|
276
|
-
return void 0;
|
|
277
|
-
}
|
|
430
|
+
function readEntry(entry2) {
|
|
278
431
|
if (entry2.size < miniStreamCutoff && entry2.type !== ENTRY_TYPE_ROOT) {
|
|
279
432
|
return readMiniStream(entry2.startSector, entry2.size);
|
|
280
433
|
}
|
|
281
434
|
return readStream(entry2.startSector, entry2.size);
|
|
282
435
|
}
|
|
283
|
-
|
|
436
|
+
const readable = (entry2) => entry2.type === ENTRY_TYPE_STREAM || entry2.type === ENTRY_TYPE_ROOT;
|
|
437
|
+
return {
|
|
438
|
+
entries,
|
|
439
|
+
warnings,
|
|
440
|
+
getStream(name) {
|
|
441
|
+
const entry2 = findStreamByName(entries, name, readable);
|
|
442
|
+
return entry2 ? readEntry(entry2) : void 0;
|
|
443
|
+
},
|
|
444
|
+
getStreamByPath(path2) {
|
|
445
|
+
const entry2 = findDirectoryEntry(entries, path2);
|
|
446
|
+
return entry2 && entry2.type === ENTRY_TYPE_STREAM ? readEntry(entry2) : void 0;
|
|
447
|
+
},
|
|
448
|
+
getStreamById(id) {
|
|
449
|
+
const entry2 = entries.find((candidate) => candidate.id === id);
|
|
450
|
+
return entry2 && readable(entry2) ? readEntry(entry2) : void 0;
|
|
451
|
+
},
|
|
452
|
+
findEntry(path2) {
|
|
453
|
+
return findDirectoryEntry(entries, path2);
|
|
454
|
+
}
|
|
455
|
+
};
|
|
284
456
|
}
|
|
285
457
|
|
|
286
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
458
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/utils/ooxml-crypto-primitives.js
|
|
287
459
|
function getSubtle() {
|
|
288
460
|
if (typeof globalThis.crypto !== "undefined" && globalThis.crypto.subtle) {
|
|
289
461
|
return globalThis.crypto.subtle;
|
|
@@ -2391,7 +2563,7 @@ function isEncryptedOoxmlPackage(input) {
|
|
|
2391
2563
|
}
|
|
2392
2564
|
}
|
|
2393
2565
|
|
|
2394
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
2566
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-helpers.js
|
|
2395
2567
|
function compareDirEntryNames(a2, b) {
|
|
2396
2568
|
const ua = a2.toUpperCase();
|
|
2397
2569
|
const ub = b.toUpperCase();
|
|
@@ -2458,7 +2630,7 @@ function writeInt32Sectors(outBytes, int32Data, firstSector, numSectors, sectorS
|
|
|
2458
2630
|
}
|
|
2459
2631
|
}
|
|
2460
2632
|
|
|
2461
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
2633
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-serialize.js
|
|
2462
2634
|
function writeHeader(outView, outBytes, params) {
|
|
2463
2635
|
outBytes.set(OLE_MAGIC, 0);
|
|
2464
2636
|
outView.setUint16(24, 62, true);
|
|
@@ -2551,7 +2723,7 @@ function writeStreamSectors(outBytes, streamData, chain2, sectorSize) {
|
|
|
2551
2723
|
}
|
|
2552
2724
|
}
|
|
2553
2725
|
|
|
2554
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
2726
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-parser-write.js
|
|
2555
2727
|
function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
|
|
2556
2728
|
const sectorSize = 512;
|
|
2557
2729
|
const miniSectorSize = 64;
|
|
@@ -3283,7 +3455,7 @@ var getR = (element, local) => relAttr(element, local);
|
|
|
3283
3455
|
var makeW = (doc, local) => doc.createElementNS(WORD_NS, `w:${local}`);
|
|
3284
3456
|
|
|
3285
3457
|
// docx/core-properties.ts
|
|
3286
|
-
var
|
|
3458
|
+
var child2 = (parent, local) => elements(parent).find((element) => element.localName === local);
|
|
3287
3459
|
var PROPERTY_FIELDS = [
|
|
3288
3460
|
"title",
|
|
3289
3461
|
"subject",
|
|
@@ -3309,7 +3481,7 @@ function parseCoreProperties(xml) {
|
|
|
3309
3481
|
const root = parseXml2(xml).documentElement;
|
|
3310
3482
|
const result = {};
|
|
3311
3483
|
for (const field of PROPERTY_FIELDS) {
|
|
3312
|
-
const element =
|
|
3484
|
+
const element = child2(root, field);
|
|
3313
3485
|
const value = element ? textContent(element).trim() : "";
|
|
3314
3486
|
if (value) result[field] = value;
|
|
3315
3487
|
}
|
|
@@ -3326,7 +3498,7 @@ async function applyCoreProperties(zip, next, prior) {
|
|
|
3326
3498
|
for (const field of PROPERTY_FIELDS) {
|
|
3327
3499
|
if ((next?.[field] ?? "") === (prior?.[field] ?? "")) continue;
|
|
3328
3500
|
const [prefix, ns] = PREFIX[field];
|
|
3329
|
-
let element =
|
|
3501
|
+
let element = child2(root, field);
|
|
3330
3502
|
const value = next?.[field] ?? "";
|
|
3331
3503
|
if (!value) {
|
|
3332
3504
|
if (element) root.removeChild(element);
|
|
@@ -4688,7 +4860,7 @@ var WRITABLE = /* @__PURE__ */ new Set([
|
|
|
4688
4860
|
function setW5(element, name, value) {
|
|
4689
4861
|
element.setAttributeNS(WORD_NS, `w:${name}`, value);
|
|
4690
4862
|
}
|
|
4691
|
-
function
|
|
4863
|
+
function child3(doc, parent, name, before) {
|
|
4692
4864
|
const existing = first2(parent, name);
|
|
4693
4865
|
if (existing) return existing;
|
|
4694
4866
|
const element = makeW(doc, name);
|
|
@@ -4741,13 +4913,13 @@ var AFTER_TYPE = ["pgSz", ...AFTER_PGSZ];
|
|
|
4741
4913
|
function writeSectionProperties(doc, sectPr, section, base) {
|
|
4742
4914
|
if (section.type === "nextPage")
|
|
4743
4915
|
for (const type of children2(sectPr, "type")) sectPr.removeChild(type);
|
|
4744
|
-
else setW5(
|
|
4745
|
-
const size =
|
|
4916
|
+
else setW5(child3(doc, sectPr, "type", AFTER_TYPE), "val", section.type);
|
|
4917
|
+
const size = child3(doc, sectPr, "pgSz", AFTER_PGSZ);
|
|
4746
4918
|
setW5(size, "w", String(section.pageWidthTwips));
|
|
4747
4919
|
setW5(size, "h", String(section.pageHeightTwips));
|
|
4748
4920
|
if (section.orientation === "landscape") setW5(size, "orient", "landscape");
|
|
4749
4921
|
else size.removeAttributeNS(WORD_NS, "orient");
|
|
4750
|
-
const margins =
|
|
4922
|
+
const margins = child3(doc, sectPr, "pgMar", AFTER_PGSZ.slice(1));
|
|
4751
4923
|
setW5(margins, "top", String(section.marginTopTwips));
|
|
4752
4924
|
setW5(margins, "right", String(section.marginRightTwips));
|
|
4753
4925
|
setW5(margins, "bottom", String(section.marginBottomTwips));
|
|
@@ -4755,7 +4927,7 @@ function writeSectionProperties(doc, sectPr, section, base) {
|
|
|
4755
4927
|
setW5(margins, "header", String(section.headerDistanceTwips ?? 720));
|
|
4756
4928
|
setW5(margins, "footer", String(section.footerDistanceTwips ?? 720));
|
|
4757
4929
|
setW5(margins, "gutter", String(section.gutterTwips ?? 0));
|
|
4758
|
-
const columns =
|
|
4930
|
+
const columns = child3(doc, sectPr, "cols", AFTER_COLS);
|
|
4759
4931
|
setW5(columns, "num", String(section.columns.count));
|
|
4760
4932
|
setW5(columns, "space", String(section.columns.spacingTwips ?? 720));
|
|
4761
4933
|
if (section.columns.equalWidth || !section.columns.widths?.length) {
|
|
@@ -4777,17 +4949,17 @@ function writeSectionProperties(doc, sectPr, section, base) {
|
|
|
4777
4949
|
else columns.removeAttributeNS(WORD_NS, "sep");
|
|
4778
4950
|
if (section.verticalAlign && section.verticalAlign !== "top")
|
|
4779
4951
|
setW5(
|
|
4780
|
-
|
|
4952
|
+
child3(doc, sectPr, "vAlign", ["noEndnote", "titlePg", ...AFTER_TITLEPG]),
|
|
4781
4953
|
"val",
|
|
4782
4954
|
section.verticalAlign
|
|
4783
4955
|
);
|
|
4784
4956
|
else for (const vAlign of children2(sectPr, "vAlign")) sectPr.removeChild(vAlign);
|
|
4785
4957
|
if (section.titlePage)
|
|
4786
|
-
|
|
4958
|
+
child3(doc, sectPr, "titlePg", AFTER_TITLEPG).removeAttributeNS(WORD_NS, "val");
|
|
4787
4959
|
else for (const titlePg of children2(sectPr, "titlePg")) sectPr.removeChild(titlePg);
|
|
4788
4960
|
const line = section.lineNumberSettings;
|
|
4789
4961
|
if (line) {
|
|
4790
|
-
const lnNum =
|
|
4962
|
+
const lnNum = child3(doc, sectPr, "lnNumType", AFTER_LNNUM);
|
|
4791
4963
|
if (line.countBy > 1) setW5(lnNum, "countBy", String(line.countBy));
|
|
4792
4964
|
else lnNum.removeAttributeNS(WORD_NS, "countBy");
|
|
4793
4965
|
if (line.start !== 1) setW5(lnNum, "start", String(line.start - 1));
|
|
@@ -4803,11 +4975,11 @@ function writeSectionProperties(doc, sectPr, section, base) {
|
|
|
4803
4975
|
sectPr,
|
|
4804
4976
|
section.pageBorders,
|
|
4805
4977
|
base?.pageBorders,
|
|
4806
|
-
(d, parent, name) =>
|
|
4978
|
+
(d, parent, name) => child3(d, parent, name, AFTER_PGBORDERS)
|
|
4807
4979
|
);
|
|
4808
4980
|
const numbering = section.pageNumbering;
|
|
4809
4981
|
if (numbering?.format || numbering?.start !== void 0) {
|
|
4810
|
-
const pgNumType =
|
|
4982
|
+
const pgNumType = child3(doc, sectPr, "pgNumType", AFTER_PGNUMTYPE);
|
|
4811
4983
|
if (numbering.format && numbering.format !== "decimal")
|
|
4812
4984
|
setW5(pgNumType, "fmt", numbering.format);
|
|
4813
4985
|
else pgNumType.removeAttributeNS(WORD_NS, "fmt");
|
|
@@ -5158,7 +5330,7 @@ function setAttribute4(element, local, value) {
|
|
|
5158
5330
|
element.setAttributeNS(WORD_NS, `w:${local}`, value);
|
|
5159
5331
|
}
|
|
5160
5332
|
function removeChildren(element, local) {
|
|
5161
|
-
for (const
|
|
5333
|
+
for (const child4 of children2(element, local)) element.removeChild(child4);
|
|
5162
5334
|
}
|
|
5163
5335
|
function writeRevisionMetadata(element, revision) {
|
|
5164
5336
|
setAttribute4(element, "id", revision.id);
|
|
@@ -5463,7 +5635,7 @@ function runPropertiesHaveUnknownContent(properties) {
|
|
|
5463
5635
|
const property = node;
|
|
5464
5636
|
if (property.namespaceURI === WORD_NS && property.localName === "rPrChange") {
|
|
5465
5637
|
if (hasUnexpectedAttributes(property, ["id", "author", "date"], true) || Array.from(property.childNodes).some(
|
|
5466
|
-
(
|
|
5638
|
+
(child4) => child4.nodeType === 3 && child4.textContent?.trim()
|
|
5467
5639
|
) || elements(property).length !== 1 || !first2(property, "rPr") || !getW(property, "id") || !getW(property, "author"))
|
|
5468
5640
|
return true;
|
|
5469
5641
|
continue;
|
|
@@ -5641,7 +5813,7 @@ function setAttribute5(element, local, value) {
|
|
|
5641
5813
|
element.setAttributeNS(WORD_NS, `w:${local}`, value);
|
|
5642
5814
|
}
|
|
5643
5815
|
function removeChildren2(element, local) {
|
|
5644
|
-
for (const
|
|
5816
|
+
for (const child4 of children2(element, local)) element.removeChild(child4);
|
|
5645
5817
|
}
|
|
5646
5818
|
function setToggle(doc, props, local, value) {
|
|
5647
5819
|
removeChildren2(props, local);
|
|
@@ -5825,7 +5997,7 @@ function buildWatermarkRun(doc, spec, uniqueId) {
|
|
|
5825
5997
|
lock.setAttributeNS(VML_NS, "v:ext", "edit");
|
|
5826
5998
|
lock.setAttribute("text", "t");
|
|
5827
5999
|
lock.setAttribute("shapetype", "t");
|
|
5828
|
-
for (const
|
|
6000
|
+
for (const child4 of [formulas, path2, typePath, handles, lock]) type.appendChild(child4);
|
|
5829
6001
|
const size = watermarkSizePt(spec);
|
|
5830
6002
|
const shape = v("shape");
|
|
5831
6003
|
shape.setAttribute("id", `${WATERMARK_PREFIX}${uniqueId}`);
|
|
@@ -5846,7 +6018,7 @@ function buildWatermarkRun(doc, spec, uniqueId) {
|
|
|
5846
6018
|
const wrap = makeNS(doc, WORD10_NS, "w10:wrap");
|
|
5847
6019
|
wrap.setAttribute("anchorx", "margin");
|
|
5848
6020
|
wrap.setAttribute("anchory", "margin");
|
|
5849
|
-
for (const
|
|
6021
|
+
for (const child4 of [fill, text, wrap]) shape.appendChild(child4);
|
|
5850
6022
|
pict.appendChild(type);
|
|
5851
6023
|
pict.appendChild(shape);
|
|
5852
6024
|
run.appendChild(pict);
|
|
@@ -5959,7 +6131,7 @@ function isSimpleTextBox(graphicData, anchored) {
|
|
|
5959
6131
|
if (!graphicData || anchored) return false;
|
|
5960
6132
|
const content = descendants(graphicData, W_NS, "txbxContent")[0];
|
|
5961
6133
|
if (!content) return false;
|
|
5962
|
-
const plain = (node, allowed) => Array.from(node.childNodes).filter(isElement).every((
|
|
6134
|
+
const plain = (node, allowed) => Array.from(node.childNodes).filter(isElement).every((child4) => child4.namespaceURI === W_NS && allowed.includes(child4.localName));
|
|
5963
6135
|
return plain(content, ["p"]) && descendants(content, W_NS, "p").every(
|
|
5964
6136
|
(paragraph) => plain(paragraph, ["r"]) && descendants(paragraph, W_NS, "r").every((run) => plain(run, ["t"]))
|
|
5965
6137
|
);
|
|
@@ -5983,7 +6155,7 @@ function patchTextBox(doc, drawing, image, base) {
|
|
|
5983
6155
|
if (JSON.stringify(image.textBoxText) !== JSON.stringify(base.textBoxText)) {
|
|
5984
6156
|
const content = descendants(drawing, W_NS, "txbxContent")[0];
|
|
5985
6157
|
if (content) {
|
|
5986
|
-
for (const
|
|
6158
|
+
for (const child4 of Array.from(content.childNodes)) content.removeChild(child4);
|
|
5987
6159
|
add(content, ...paragraphsFor(doc, image.textBoxText ?? []));
|
|
5988
6160
|
}
|
|
5989
6161
|
}
|
|
@@ -6182,10 +6354,10 @@ function booleanAttribute(element, name) {
|
|
|
6182
6354
|
function descendants2(root, local) {
|
|
6183
6355
|
const result = [];
|
|
6184
6356
|
const visit = (node) => {
|
|
6185
|
-
for (const
|
|
6186
|
-
if (!isElement(
|
|
6187
|
-
if (
|
|
6188
|
-
visit(
|
|
6357
|
+
for (const child4 of Array.from(node.childNodes)) {
|
|
6358
|
+
if (!isElement(child4)) continue;
|
|
6359
|
+
if (child4.localName === local) result.push(child4);
|
|
6360
|
+
visit(child4);
|
|
6189
6361
|
}
|
|
6190
6362
|
};
|
|
6191
6363
|
visit(root);
|
|
@@ -6337,9 +6509,9 @@ function parseDrawingColor(element) {
|
|
|
6337
6509
|
const color = {
|
|
6338
6510
|
kind,
|
|
6339
6511
|
value: colorValue(kind, element),
|
|
6340
|
-
transforms: elements(element).map((
|
|
6341
|
-
name:
|
|
6342
|
-
value:
|
|
6512
|
+
transforms: elements(element).map((child4) => ({
|
|
6513
|
+
name: child4.localName,
|
|
6514
|
+
value: child4.getAttribute("val") ?? ""
|
|
6343
6515
|
}))
|
|
6344
6516
|
};
|
|
6345
6517
|
const fallback = kind === "system" ? element.getAttribute("lastClr") : null;
|
|
@@ -6575,9 +6747,9 @@ function parseRun(run) {
|
|
|
6575
6747
|
}
|
|
6576
6748
|
function parseParagraph(paragraph) {
|
|
6577
6749
|
const runs = [];
|
|
6578
|
-
for (const
|
|
6579
|
-
if (
|
|
6580
|
-
runs.push(parseRun(
|
|
6750
|
+
for (const child4 of elements(paragraph))
|
|
6751
|
+
if (child4.namespaceURI === NS.a && ["r", "fld", "br"].includes(child4.localName))
|
|
6752
|
+
runs.push(parseRun(child4));
|
|
6581
6753
|
const properties = first(paragraph, "pPr", NS.a);
|
|
6582
6754
|
const align = properties?.getAttribute("algn");
|
|
6583
6755
|
const defaults = parseProperties(first(properties, "defRPr", NS.a));
|
|
@@ -6799,9 +6971,9 @@ function parseDiagramDrawing(source, part) {
|
|
|
6799
6971
|
const tree = root.localName === "spTree" ? root : first(root, "spTree", NS.dsp);
|
|
6800
6972
|
let counter = 0;
|
|
6801
6973
|
const visit = (container2, group) => {
|
|
6802
|
-
for (const
|
|
6803
|
-
if (
|
|
6804
|
-
const element =
|
|
6974
|
+
for (const child4 of Array.from(container2.childNodes)) {
|
|
6975
|
+
if (child4.nodeType !== 1) continue;
|
|
6976
|
+
const element = child4;
|
|
6805
6977
|
if (element.localName === "sp") {
|
|
6806
6978
|
const shape = parseShape(element, counter++, group, issues);
|
|
6807
6979
|
if (shape) shapes.push(shape);
|
|
@@ -7269,11 +7441,11 @@ function cNumber(context, parent, local) {
|
|
|
7269
7441
|
return void 0;
|
|
7270
7442
|
}
|
|
7271
7443
|
function reportUnmodelled(context, element, handled) {
|
|
7272
|
-
for (const
|
|
7273
|
-
if (handled.has(
|
|
7444
|
+
for (const child4 of elements(element)) {
|
|
7445
|
+
if (handled.has(child4.localName)) continue;
|
|
7274
7446
|
context.issues.push({
|
|
7275
7447
|
code: "CHART_ELEMENT_NOT_MODELLED",
|
|
7276
|
-
message: `${path(
|
|
7448
|
+
message: `${path(child4)} is not modelled; it is kept only in the source part.`
|
|
7277
7449
|
});
|
|
7278
7450
|
}
|
|
7279
7451
|
}
|
|
@@ -7840,15 +8012,15 @@ function parsePlotArea(context, element) {
|
|
|
7840
8012
|
return plotArea;
|
|
7841
8013
|
}
|
|
7842
8014
|
const handled = new Set(PLOT_AREA);
|
|
7843
|
-
for (const
|
|
7844
|
-
if (CHART_GROUP_ELEMENTS[
|
|
7845
|
-
plotArea.groups.push(parseGroup(context,
|
|
7846
|
-
handled.add(
|
|
8015
|
+
for (const child4 of elements(element)) {
|
|
8016
|
+
if (CHART_GROUP_ELEMENTS[child4.localName]) {
|
|
8017
|
+
plotArea.groups.push(parseGroup(context, child4));
|
|
8018
|
+
handled.add(child4.localName);
|
|
7847
8019
|
}
|
|
7848
|
-
const axis = AXIS_ELEMENTS[
|
|
8020
|
+
const axis = AXIS_ELEMENTS[child4.localName];
|
|
7849
8021
|
if (axis) {
|
|
7850
|
-
plotArea.axes.push(parseAxis(context,
|
|
7851
|
-
handled.add(
|
|
8022
|
+
plotArea.axes.push(parseAxis(context, child4, axis));
|
|
8023
|
+
handled.add(child4.localName);
|
|
7852
8024
|
}
|
|
7853
8025
|
}
|
|
7854
8026
|
reportUnmodelled(context, element, handled);
|
|
@@ -8294,8 +8466,8 @@ var W_NS2 = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
|
8294
8466
|
var PICTURE_GRAPHIC_URI = "http://schemas.openxmlformats.org/drawingml/2006/picture";
|
|
8295
8467
|
function firstNS(parent, ns, local) {
|
|
8296
8468
|
if (!parent) return void 0;
|
|
8297
|
-
for (const
|
|
8298
|
-
if (isElement(
|
|
8469
|
+
for (const child4 of Array.from(parent.childNodes))
|
|
8470
|
+
if (isElement(child4) && child4.namespaceURI === ns && child4.localName === local) return child4;
|
|
8299
8471
|
return void 0;
|
|
8300
8472
|
}
|
|
8301
8473
|
function descendantNS(parent, ns, local) {
|
|
@@ -8303,10 +8475,10 @@ function descendantNS(parent, ns, local) {
|
|
|
8303
8475
|
const stack = [parent];
|
|
8304
8476
|
while (stack.length) {
|
|
8305
8477
|
const node = stack.shift();
|
|
8306
|
-
for (const
|
|
8307
|
-
if (!isElement(
|
|
8308
|
-
if (
|
|
8309
|
-
stack.push(
|
|
8478
|
+
for (const child4 of Array.from(node.childNodes)) {
|
|
8479
|
+
if (!isElement(child4)) continue;
|
|
8480
|
+
if (child4.namespaceURI === ns && child4.localName === local) return child4;
|
|
8481
|
+
stack.push(child4);
|
|
8310
8482
|
}
|
|
8311
8483
|
}
|
|
8312
8484
|
return void 0;
|
|
@@ -8353,13 +8525,13 @@ function textBoxParagraphs(graphicData) {
|
|
|
8353
8525
|
if (!content) return void 0;
|
|
8354
8526
|
const paragraphs = [];
|
|
8355
8527
|
const visit = (node) => {
|
|
8356
|
-
for (const
|
|
8357
|
-
if (!isElement(
|
|
8358
|
-
if (
|
|
8528
|
+
for (const child4 of Array.from(node.childNodes)) {
|
|
8529
|
+
if (!isElement(child4)) continue;
|
|
8530
|
+
if (child4.namespaceURI === W_NS2 && child4.localName === "p")
|
|
8359
8531
|
paragraphs.push(
|
|
8360
|
-
Array.from(
|
|
8532
|
+
Array.from(child4.getElementsByTagNameNS(W_NS2, "t")).map((t) => t.textContent ?? "").join("")
|
|
8361
8533
|
);
|
|
8362
|
-
else visit(
|
|
8534
|
+
else visit(child4);
|
|
8363
8535
|
}
|
|
8364
8536
|
};
|
|
8365
8537
|
visit(content);
|
|
@@ -8487,8 +8659,8 @@ var PIC_NS = "http://schemas.openxmlformats.org/drawingml/2006/picture";
|
|
|
8487
8659
|
var PICTURE_GRAPHIC_URI2 = "http://schemas.openxmlformats.org/drawingml/2006/picture";
|
|
8488
8660
|
function findDrawingChild(run) {
|
|
8489
8661
|
if (!run) return void 0;
|
|
8490
|
-
for (const
|
|
8491
|
-
if (isElement(
|
|
8662
|
+
for (const child4 of Array.from(run.childNodes))
|
|
8663
|
+
if (isElement(child4) && (named2(child4, "drawing") || named2(child4, "pict"))) return child4;
|
|
8492
8664
|
return void 0;
|
|
8493
8665
|
}
|
|
8494
8666
|
function sameUnderlyingImage(a2, b) {
|
|
@@ -8499,7 +8671,7 @@ function walk(root, visit) {
|
|
|
8499
8671
|
while (stack.length) {
|
|
8500
8672
|
const node = stack.shift();
|
|
8501
8673
|
visit(node);
|
|
8502
|
-
for (const
|
|
8674
|
+
for (const child4 of Array.from(node.childNodes)) if (isElement(child4)) stack.push(child4);
|
|
8503
8675
|
}
|
|
8504
8676
|
}
|
|
8505
8677
|
function updateExtent(drawing, widthPx, heightPx) {
|
|
@@ -8599,9 +8771,9 @@ function buildInlineDrawing(doc, image, relId, docPrId, svgRelId) {
|
|
|
8599
8771
|
return drawing;
|
|
8600
8772
|
}
|
|
8601
8773
|
function clearNonProperties(node, keep) {
|
|
8602
|
-
for (const
|
|
8603
|
-
if (isElement(
|
|
8604
|
-
node.removeChild(
|
|
8774
|
+
for (const child4 of Array.from(node.childNodes)) {
|
|
8775
|
+
if (isElement(child4) && (named2(child4, "rPr") || child4 === keep)) continue;
|
|
8776
|
+
node.removeChild(child4);
|
|
8605
8777
|
}
|
|
8606
8778
|
}
|
|
8607
8779
|
function createImageRun(doc, image, base, old, allocator) {
|
|
@@ -8681,7 +8853,7 @@ function setAttribute6(element, local, value) {
|
|
|
8681
8853
|
element.setAttributeNS(WORD_NS, `w:${local}`, value);
|
|
8682
8854
|
}
|
|
8683
8855
|
function removeChildren3(element, local) {
|
|
8684
|
-
for (const
|
|
8856
|
+
for (const child4 of children2(element, local)) element.removeChild(child4);
|
|
8685
8857
|
}
|
|
8686
8858
|
function setToggle2(doc, props, local, value) {
|
|
8687
8859
|
removeChildren3(props, local);
|
|
@@ -8850,8 +9022,8 @@ function createRun(doc, run, base, old, allocator) {
|
|
|
8850
9022
|
}
|
|
8851
9023
|
setRunProperties(doc, node, run, base);
|
|
8852
9024
|
if (run.image) return node;
|
|
8853
|
-
for (const
|
|
8854
|
-
if (
|
|
9025
|
+
for (const child4 of Array.from(node.childNodes))
|
|
9026
|
+
if (child4.nodeType !== 1 || child4.localName !== "rPr") node.removeChild(child4);
|
|
8855
9027
|
if (run.break) {
|
|
8856
9028
|
const br = makeW(doc, "br");
|
|
8857
9029
|
setAttribute6(br, "type", run.break);
|
|
@@ -9000,9 +9172,9 @@ function trackMoveRange(item, moves) {
|
|
|
9000
9172
|
}
|
|
9001
9173
|
function isCommentReferenceRun(run) {
|
|
9002
9174
|
const content = Array.from(run.childNodes).filter(
|
|
9003
|
-
(
|
|
9175
|
+
(child4) => isElement(child4) && !named2(child4, "rPr")
|
|
9004
9176
|
);
|
|
9005
|
-
return content.length > 0 && content.every((
|
|
9177
|
+
return content.length > 0 && content.every((child4) => named2(child4, "commentReference"));
|
|
9006
9178
|
}
|
|
9007
9179
|
function revisionFrom(node, kind) {
|
|
9008
9180
|
const revision = {
|
|
@@ -9052,8 +9224,8 @@ function collectParagraphRuns(node, parseRun3, parseOther, resolveLink, active =
|
|
|
9052
9224
|
if (!isCommentReferenceRun(item)) push(parseRun3(item));
|
|
9053
9225
|
} else if (named2(item, "hyperlink")) {
|
|
9054
9226
|
const link = resolveLink?.(item);
|
|
9055
|
-
for (const
|
|
9056
|
-
for (const parsed of named2(
|
|
9227
|
+
for (const child4 of Array.from(item.childNodes).filter(isElement)) {
|
|
9228
|
+
for (const parsed of named2(child4, "r") ? [parseRun3(child4)] : parseOther?.(child4) ?? []) {
|
|
9057
9229
|
if (link) parsed.link = link;
|
|
9058
9230
|
push(parsed);
|
|
9059
9231
|
}
|
|
@@ -9067,8 +9239,8 @@ function collectParagraphRuns(node, parseRun3, parseOther, resolveLink, active =
|
|
|
9067
9239
|
const revision = revisionFrom(item, kind);
|
|
9068
9240
|
const range = kind === "moveFrom" || kind === "moveTo" ? moves[kind].at(-1) : void 0;
|
|
9069
9241
|
if (range) revision.move = { name: range.name, rangeId: range.id };
|
|
9070
|
-
for (const
|
|
9071
|
-
for (const parsed of named2(
|
|
9242
|
+
for (const child4 of Array.from(item.childNodes).filter(isElement)) {
|
|
9243
|
+
for (const parsed of named2(child4, "r") ? [parseRun3(child4, revision)] : parseOther?.(child4) ?? []) {
|
|
9072
9244
|
parsed.revision = revision;
|
|
9073
9245
|
push(parsed);
|
|
9074
9246
|
}
|
|
@@ -9092,7 +9264,7 @@ function collectParagraphRuns(node, parseRun3, parseOther, resolveLink, active =
|
|
|
9092
9264
|
// docx/write-inline.ts
|
|
9093
9265
|
function runIsSafe(run) {
|
|
9094
9266
|
const content = Array.from(run.childNodes).filter(
|
|
9095
|
-
(
|
|
9267
|
+
(child4) => isElement(child4) && !named2(child4, "rPr") && !isCachedPageBreak(child4)
|
|
9096
9268
|
);
|
|
9097
9269
|
const only = content.length === 1 ? content[0] : void 0;
|
|
9098
9270
|
if (only && named2(only, "br") && isModeledBreak(only)) return true;
|
|
@@ -9114,56 +9286,56 @@ function runIsSafe(run) {
|
|
|
9114
9286
|
return !((kinds.has("drawing") || kinds.has("pict")) && kinds.size > 1);
|
|
9115
9287
|
}
|
|
9116
9288
|
function runsOf(parent, container2, slots) {
|
|
9117
|
-
for (const
|
|
9118
|
-
if (!isElement(
|
|
9119
|
-
if (
|
|
9289
|
+
for (const child4 of Array.from(parent.childNodes)) {
|
|
9290
|
+
if (!isElement(child4)) {
|
|
9291
|
+
if (child4.nodeType === 3 && child4.textContent?.trim()) return false;
|
|
9120
9292
|
continue;
|
|
9121
9293
|
}
|
|
9122
|
-
if (isEquationElement(
|
|
9123
|
-
slots.push({ element:
|
|
9124
|
-
} else if (named2(
|
|
9125
|
-
if (isCommentReferenceRun(
|
|
9126
|
-
if (!runIsSafe(
|
|
9127
|
-
slots.push({ element:
|
|
9128
|
-
} else if (isRevisionWrapperElement(
|
|
9129
|
-
if (!runsOf(
|
|
9130
|
-
} else if ((named2(
|
|
9294
|
+
if (isEquationElement(child4)) {
|
|
9295
|
+
slots.push({ element: child4, ...container2 && { container: container2 } });
|
|
9296
|
+
} else if (named2(child4, "r")) {
|
|
9297
|
+
if (isCommentReferenceRun(child4)) continue;
|
|
9298
|
+
if (!runIsSafe(child4)) return false;
|
|
9299
|
+
slots.push({ element: child4, ...container2 && { container: container2 } });
|
|
9300
|
+
} else if (isRevisionWrapperElement(child4) && !container2) {
|
|
9301
|
+
if (!runsOf(child4, void 0, slots)) return false;
|
|
9302
|
+
} else if ((named2(child4, "hyperlink") || named2(child4, "fldSimple")) && !container2) {
|
|
9131
9303
|
const before = slots.length;
|
|
9132
|
-
if (!runsOf(
|
|
9133
|
-
if (named2(
|
|
9134
|
-
} else if (isCommentAnchorElement(
|
|
9304
|
+
if (!runsOf(child4, child4, slots)) return false;
|
|
9305
|
+
if (named2(child4, "fldSimple") && slots.length === before) slots.push({ container: child4 });
|
|
9306
|
+
} else if (isCommentAnchorElement(child4) && !container2) continue;
|
|
9135
9307
|
else return false;
|
|
9136
9308
|
}
|
|
9137
9309
|
return true;
|
|
9138
9310
|
}
|
|
9139
9311
|
function collectInlineSlots(paragraph) {
|
|
9140
9312
|
const slots = [];
|
|
9141
|
-
for (const
|
|
9142
|
-
if (isElement(
|
|
9313
|
+
for (const child4 of Array.from(paragraph.childNodes)) {
|
|
9314
|
+
if (isElement(child4) && (named2(child4, "pPr") || named2(child4, "bookmarkStart") || named2(child4, "bookmarkEnd")))
|
|
9143
9315
|
continue;
|
|
9144
|
-
if (!isElement(
|
|
9145
|
-
if (
|
|
9316
|
+
if (!isElement(child4)) {
|
|
9317
|
+
if (child4.nodeType === 3 && child4.textContent?.trim()) return void 0;
|
|
9146
9318
|
continue;
|
|
9147
9319
|
}
|
|
9148
|
-
if (isEquationElement(
|
|
9149
|
-
slots.push({ element:
|
|
9150
|
-
} else if (named2(
|
|
9151
|
-
if (isCommentReferenceRun(
|
|
9152
|
-
if (!runIsSafe(
|
|
9153
|
-
slots.push({ element:
|
|
9154
|
-
} else if (isRevisionWrapperElement(
|
|
9155
|
-
if (!runsOf(
|
|
9156
|
-
} else if (named2(
|
|
9320
|
+
if (isEquationElement(child4)) {
|
|
9321
|
+
slots.push({ element: child4 });
|
|
9322
|
+
} else if (named2(child4, "r")) {
|
|
9323
|
+
if (isCommentReferenceRun(child4)) continue;
|
|
9324
|
+
if (!runIsSafe(child4)) return void 0;
|
|
9325
|
+
slots.push({ element: child4 });
|
|
9326
|
+
} else if (isRevisionWrapperElement(child4)) {
|
|
9327
|
+
if (!runsOf(child4, void 0, slots)) return void 0;
|
|
9328
|
+
} else if (named2(child4, "hyperlink") || named2(child4, "fldSimple")) {
|
|
9157
9329
|
const before = slots.length;
|
|
9158
|
-
if (!runsOf(
|
|
9159
|
-
if (named2(
|
|
9160
|
-
} else if (!isCommentAnchorElement(
|
|
9330
|
+
if (!runsOf(child4, child4, slots)) return void 0;
|
|
9331
|
+
if (named2(child4, "fldSimple") && slots.length === before) slots.push({ container: child4 });
|
|
9332
|
+
} else if (!isCommentAnchorElement(child4)) return void 0;
|
|
9161
9333
|
}
|
|
9162
9334
|
return slots;
|
|
9163
9335
|
}
|
|
9164
9336
|
function replaceableInlineChildren(paragraph) {
|
|
9165
9337
|
return Array.from(paragraph.childNodes).filter(
|
|
9166
|
-
(
|
|
9338
|
+
(child4) => isElement(child4) && (isEquationElement(child4) || named2(child4, "r") || named2(child4, "hyperlink") || named2(child4, "fldSimple") || isRevisionWrapperElement(child4) || isCommentAnchorElement(child4))
|
|
9167
9339
|
);
|
|
9168
9340
|
}
|
|
9169
9341
|
function sameLink(a2, b) {
|
|
@@ -9233,7 +9405,7 @@ function buildInlineContent(doc, runs, base, slots, allocator, ranges) {
|
|
|
9233
9405
|
let container2;
|
|
9234
9406
|
if (reusable) {
|
|
9235
9407
|
container2 = onlyContainer;
|
|
9236
|
-
for (const
|
|
9408
|
+
for (const child4 of Array.from(container2.childNodes)) container2.removeChild(child4);
|
|
9237
9409
|
} else if (group.kind === "link") container2 = newHyperlink(doc, group.link, allocator);
|
|
9238
9410
|
else {
|
|
9239
9411
|
container2 = makeW(doc, "fldSimple");
|
|
@@ -9457,7 +9629,7 @@ function setAttribute7(element, local, value) {
|
|
|
9457
9629
|
element.setAttributeNS(WORD_NS, `w:${local}`, value);
|
|
9458
9630
|
}
|
|
9459
9631
|
function removeChildren4(element, local) {
|
|
9460
|
-
for (const
|
|
9632
|
+
for (const child4 of children2(element, local)) element.removeChild(child4);
|
|
9461
9633
|
}
|
|
9462
9634
|
function rejectUnsafeRunSegmentation(paragraph, base, oldRuns) {
|
|
9463
9635
|
if (!base || !oldRuns.some(runHasUnknownProperties)) return;
|
|
@@ -9612,7 +9784,7 @@ function scanUsedRelationshipIds(doc) {
|
|
|
9612
9784
|
const visit = (node) => {
|
|
9613
9785
|
for (const attribute2 of Array.from(node.attributes))
|
|
9614
9786
|
if (attribute2.namespaceURI === REL_NS) used.add(attribute2.value);
|
|
9615
|
-
for (const
|
|
9787
|
+
for (const child4 of Array.from(node.childNodes)) if (isElement(child4)) visit(child4);
|
|
9616
9788
|
};
|
|
9617
9789
|
if (doc.documentElement) visit(doc.documentElement);
|
|
9618
9790
|
return used;
|
|
@@ -10660,7 +10832,7 @@ function setNumPr(style, numbering) {
|
|
|
10660
10832
|
if (!numbering && !pPr) return;
|
|
10661
10833
|
if (!pPr) {
|
|
10662
10834
|
pPr = makeW(doc, "pPr");
|
|
10663
|
-
const anchor = elementsOf(style).find((
|
|
10835
|
+
const anchor = elementsOf(style).find((child4) => AFTER_PPR.includes(child4.localName)) ?? null;
|
|
10664
10836
|
style.insertBefore(pPr, anchor);
|
|
10665
10837
|
}
|
|
10666
10838
|
for (const existing of children2(pPr, "numPr")) pPr.removeChild(existing);
|
|
@@ -11638,12 +11810,12 @@ function createFieldTracker() {
|
|
|
11638
11810
|
return (element, run) => {
|
|
11639
11811
|
let resultInstr;
|
|
11640
11812
|
let resultLocked;
|
|
11641
|
-
for (const
|
|
11642
|
-
if (!isElement(
|
|
11643
|
-
if (named2(
|
|
11644
|
-
const type = getW(
|
|
11813
|
+
for (const child4 of Array.from(element.childNodes)) {
|
|
11814
|
+
if (!isElement(child4)) continue;
|
|
11815
|
+
if (named2(child4, "fldChar")) {
|
|
11816
|
+
const type = getW(child4, "fldCharType");
|
|
11645
11817
|
if (type === "begin") {
|
|
11646
|
-
const locked = parseFieldFlags(
|
|
11818
|
+
const locked = parseFieldFlags(child4)?.locked;
|
|
11647
11819
|
stack.push({ instr: "", inResult: false, ...locked !== void 0 && { locked } });
|
|
11648
11820
|
} else if (type === "separate") {
|
|
11649
11821
|
const top = stack.at(-1);
|
|
@@ -11651,8 +11823,8 @@ function createFieldTracker() {
|
|
|
11651
11823
|
} else if (type === "end") stack.pop();
|
|
11652
11824
|
} else {
|
|
11653
11825
|
const top = stack.at(-1);
|
|
11654
|
-
if (named2(
|
|
11655
|
-
else if ((named2(
|
|
11826
|
+
if (named2(child4, "instrText") && top && !top.inResult) top.instr += textContent(child4);
|
|
11827
|
+
else if ((named2(child4, "t") || named2(child4, "delText")) && top?.inResult) {
|
|
11656
11828
|
resultInstr = top.instr.trim();
|
|
11657
11829
|
resultLocked = top.locked;
|
|
11658
11830
|
}
|
|
@@ -11679,7 +11851,7 @@ function storyFieldResults(container2) {
|
|
|
11679
11851
|
});
|
|
11680
11852
|
return;
|
|
11681
11853
|
}
|
|
11682
|
-
for (const
|
|
11854
|
+
for (const child4 of Array.from(element.childNodes)) if (isElement(child4)) visit(child4);
|
|
11683
11855
|
};
|
|
11684
11856
|
visit(container2);
|
|
11685
11857
|
return metadata;
|
|
@@ -11701,13 +11873,13 @@ var activeContext;
|
|
|
11701
11873
|
var openComments;
|
|
11702
11874
|
var openMoves;
|
|
11703
11875
|
function runContent(node) {
|
|
11704
|
-
return Array.from(node.childNodes).filter(isElement).filter((
|
|
11876
|
+
return Array.from(node.childNodes).filter(isElement).filter((child4) => child4.localName !== "rPr" && !isCachedPageBreak(child4));
|
|
11705
11877
|
}
|
|
11706
11878
|
function findDrawing(content) {
|
|
11707
|
-
for (const
|
|
11708
|
-
if (named2(
|
|
11709
|
-
if (
|
|
11710
|
-
const choice = Array.from(
|
|
11879
|
+
for (const child4 of content) {
|
|
11880
|
+
if (named2(child4, "drawing") || named2(child4, "pict")) return child4;
|
|
11881
|
+
if (child4.localName !== "AlternateContent") continue;
|
|
11882
|
+
const choice = Array.from(child4.childNodes).filter(isElement).find((node) => node.localName === "Choice");
|
|
11711
11883
|
const found = choice && findDrawing(Array.from(choice.childNodes).filter(isElement));
|
|
11712
11884
|
if (found) return found;
|
|
11713
11885
|
}
|
|
@@ -11737,7 +11909,7 @@ function parseRun2(node, revision) {
|
|
|
11737
11909
|
let noteReference;
|
|
11738
11910
|
let noteMark;
|
|
11739
11911
|
let fieldChar;
|
|
11740
|
-
const fieldCode = content.length > 0 && content.every((
|
|
11912
|
+
const fieldCode = content.length > 0 && content.every((child4) => named2(child4, "instrText")) ? content.map((child4) => textContent(child4)).join("") : void 0;
|
|
11741
11913
|
const only = content.length === 1 ? content[0] : void 0;
|
|
11742
11914
|
if (only) {
|
|
11743
11915
|
if (named2(only, "br")) {
|
|
@@ -11756,11 +11928,11 @@ function parseRun2(node, revision) {
|
|
|
11756
11928
|
if (type === "begin" || type === "separate" || type === "end") fieldChar = type;
|
|
11757
11929
|
}
|
|
11758
11930
|
}
|
|
11759
|
-
const text = breakKind || noteReference || noteMark || fieldChar || fieldCode !== void 0 ? "" : content.map((
|
|
11760
|
-
if (named2(
|
|
11761
|
-
if (named2(
|
|
11762
|
-
if (named2(
|
|
11763
|
-
if (named2(
|
|
11931
|
+
const text = breakKind || noteReference || noteMark || fieldChar || fieldCode !== void 0 ? "" : content.map((child4) => {
|
|
11932
|
+
if (named2(child4, "t") || named2(child4, "delText")) return textContent(child4);
|
|
11933
|
+
if (named2(child4, "tab")) return " ";
|
|
11934
|
+
if (named2(child4, "br") || named2(child4, "cr")) return "\n";
|
|
11935
|
+
if (named2(child4, "noBreakHyphen")) return "\u2011";
|
|
11764
11936
|
return "";
|
|
11765
11937
|
}).join("");
|
|
11766
11938
|
const run = { text, ...parseDirectRunProperties(props) };
|
|
@@ -11807,8 +11979,8 @@ function parseParagraph2(node, id, fields) {
|
|
|
11807
11979
|
const { runs: results } = collectParagraphRuns(
|
|
11808
11980
|
item,
|
|
11809
11981
|
parseRun2,
|
|
11810
|
-
(
|
|
11811
|
-
const equation2 = parseEquation(
|
|
11982
|
+
(child4) => {
|
|
11983
|
+
const equation2 = parseEquation(child4);
|
|
11812
11984
|
return equation2 ? [equation2] : void 0;
|
|
11813
11985
|
},
|
|
11814
11986
|
void 0,
|
|
@@ -12467,7 +12639,7 @@ function createDocument() {
|
|
|
12467
12639
|
};
|
|
12468
12640
|
}
|
|
12469
12641
|
|
|
12470
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
12642
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fib.js
|
|
12471
12643
|
var FC_LCB_INDEX = {
|
|
12472
12644
|
plcfbteChpx: 12,
|
|
12473
12645
|
plcfbtePapx: 13,
|
|
@@ -12563,7 +12735,7 @@ function patchDocFib(wordDoc, fib, patch) {
|
|
|
12563
12735
|
view.setUint32(papxOff + 4, patch.plcfbtePapx.lcb, true);
|
|
12564
12736
|
}
|
|
12565
12737
|
|
|
12566
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
12738
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-stream-edit.js
|
|
12567
12739
|
var END = 4294967294;
|
|
12568
12740
|
var MAX = 4294967290;
|
|
12569
12741
|
var NIL = 4294967295;
|
|
@@ -12598,6 +12770,58 @@ function chainToEnd(table, start, max) {
|
|
|
12598
12770
|
}
|
|
12599
12771
|
return out;
|
|
12600
12772
|
}
|
|
12773
|
+
function chainPrefix(table, start, needed) {
|
|
12774
|
+
const out = [], seen = /* @__PURE__ */ new Set();
|
|
12775
|
+
let id = start;
|
|
12776
|
+
while (out.length < needed) {
|
|
12777
|
+
if (id > MAX || id >= table.length || seen.has(id))
|
|
12778
|
+
throw new Error("Invalid CFB chain");
|
|
12779
|
+
seen.add(id);
|
|
12780
|
+
out.push(id);
|
|
12781
|
+
id = table[id];
|
|
12782
|
+
}
|
|
12783
|
+
return out;
|
|
12784
|
+
}
|
|
12785
|
+
function readTarget(input, target, root, fat, sector, sectorCount, sectorSize, miniSize, read32) {
|
|
12786
|
+
const size = target.size;
|
|
12787
|
+
if (size === 0)
|
|
12788
|
+
return new Uint8Array(0);
|
|
12789
|
+
const out = new Uint8Array(size);
|
|
12790
|
+
const copyPhysical = (at, want, into) => {
|
|
12791
|
+
if (at + want > input.length)
|
|
12792
|
+
throw new Error("Stream data exceeds file size");
|
|
12793
|
+
out.set(input.subarray(at, at + want), into);
|
|
12794
|
+
};
|
|
12795
|
+
if (size >= read32(56)) {
|
|
12796
|
+
if (size > sectorCount * sectorSize)
|
|
12797
|
+
throw new Error("Stream size exceeds file size");
|
|
12798
|
+
chainPrefix(fat, target.start, Math.ceil(size / sectorSize)).forEach((id, i2) => {
|
|
12799
|
+
if (id >= sectorCount)
|
|
12800
|
+
throw new Error("Invalid sector");
|
|
12801
|
+
copyPhysical((id + 1) * sectorSize, Math.min(sectorSize, size - i2 * sectorSize), i2 * sectorSize);
|
|
12802
|
+
});
|
|
12803
|
+
return out;
|
|
12804
|
+
}
|
|
12805
|
+
const miniFatSectors = chainToEnd(fat, read32(60), sectorCount);
|
|
12806
|
+
const miniCapacity = Math.floor(Math.min(root.size, sectorCount * sectorSize) / miniSize);
|
|
12807
|
+
const miniFat = [];
|
|
12808
|
+
for (const id of miniFatSectors) {
|
|
12809
|
+
const bytes = sector(id), dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
12810
|
+
for (let j = 0; j < sectorSize / 4 && miniFat.length < miniCapacity; j++)
|
|
12811
|
+
miniFat.push(dv.getUint32(j * 4, true));
|
|
12812
|
+
}
|
|
12813
|
+
const rootSectors = chainPrefix(fat, root.start, Math.ceil(root.size / sectorSize));
|
|
12814
|
+
chainPrefix(miniFat, target.start, Math.ceil(size / miniSize)).forEach((id, i2) => {
|
|
12815
|
+
const start = id * miniSize, want = Math.min(miniSize, size - i2 * miniSize);
|
|
12816
|
+
if (start + want > root.size)
|
|
12817
|
+
throw new Error("Mini stream out of bounds");
|
|
12818
|
+
const rootSector = rootSectors[Math.floor(start / sectorSize)];
|
|
12819
|
+
if (rootSector >= sectorCount)
|
|
12820
|
+
throw new Error("Invalid sector");
|
|
12821
|
+
copyPhysical((rootSector + 1) * sectorSize + start % sectorSize, want, i2 * miniSize);
|
|
12822
|
+
});
|
|
12823
|
+
return out;
|
|
12824
|
+
}
|
|
12601
12825
|
function processCompoundFileStream(input, path2, replacement) {
|
|
12602
12826
|
const reject = () => replacement ? input : void 0;
|
|
12603
12827
|
try {
|
|
@@ -12605,18 +12829,19 @@ function processCompoundFileStream(input, path2, replacement) {
|
|
|
12605
12829
|
return reject();
|
|
12606
12830
|
const view = new DataView(input.buffer, input.byteOffset, input.byteLength);
|
|
12607
12831
|
const read32 = (offset2) => view.getUint32(offset2, true);
|
|
12608
|
-
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 ||
|
|
12832
|
+
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.
|
|
12833
|
+
replacement && view.getUint16(28, true) !== 65534)
|
|
12609
12834
|
return reject();
|
|
12610
12835
|
const major = view.getUint16(26, true), shift = view.getUint16(30, true), miniShift = view.getUint16(32, true);
|
|
12611
12836
|
if (major !== 3 && major !== 4 || shift !== (major === 3 ? 9 : 12) || miniShift !== 6)
|
|
12612
12837
|
return reject();
|
|
12613
12838
|
const sectorSize = 1 << shift, miniSize = 1 << miniShift;
|
|
12614
|
-
if (input.length % sectorSize !== 0)
|
|
12839
|
+
if (input.length < sectorSize || replacement && input.length % sectorSize !== 0)
|
|
12615
12840
|
return reject();
|
|
12616
|
-
const sectorCount = input.length / sectorSize - 1;
|
|
12841
|
+
const sectorCount = Math.ceil(input.length / sectorSize) - 1;
|
|
12617
12842
|
const offset = (id) => (id + 1) * sectorSize;
|
|
12618
12843
|
const sector = (id) => {
|
|
12619
|
-
if (id > MAX || id >= sectorCount)
|
|
12844
|
+
if (id > MAX || id >= sectorCount || offset(id) + sectorSize > input.length)
|
|
12620
12845
|
throw new Error("Invalid sector");
|
|
12621
12846
|
return input.subarray(offset(id), offset(id) + sectorSize);
|
|
12622
12847
|
};
|
|
@@ -12666,7 +12891,7 @@ function processCompoundFileStream(input, path2, replacement) {
|
|
|
12666
12891
|
for (let i2 = 0; i2 < nameLength - 2; i2 += 2)
|
|
12667
12892
|
name += String.fromCharCode(dvDir.getUint16(p + i2, true));
|
|
12668
12893
|
const sizeLow = dvDir.getUint32(p + 120, true), sizeHigh = dvDir.getUint32(p + 124, true);
|
|
12669
|
-
if (sizeHigh !== 0)
|
|
12894
|
+
if (sizeHigh !== 0 && (replacement || major === 4))
|
|
12670
12895
|
return reject();
|
|
12671
12896
|
entries.push({
|
|
12672
12897
|
id,
|
|
@@ -12713,6 +12938,8 @@ function processCompoundFileStream(input, path2, replacement) {
|
|
|
12713
12938
|
}
|
|
12714
12939
|
if (!target)
|
|
12715
12940
|
return reject();
|
|
12941
|
+
if (!replacement)
|
|
12942
|
+
return readTarget(input, target, root, fat, sector, sectorCount, sectorSize, miniSize, read32);
|
|
12716
12943
|
const names = entries.map((e) => e.name.toLowerCase());
|
|
12717
12944
|
if (replacement && (names.includes("encryptioninfo") || names.includes("encryptedpackage")))
|
|
12718
12945
|
return reject();
|
|
@@ -12836,7 +13063,7 @@ function replaceCompoundFileStream(input, path2, replacement) {
|
|
|
12836
13063
|
return processCompoundFileStream(input, path2, replacement) ?? input;
|
|
12837
13064
|
}
|
|
12838
13065
|
|
|
12839
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
13066
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-v4.js
|
|
12840
13067
|
var END2 = 4294967294;
|
|
12841
13068
|
var FREE = 4294967295;
|
|
12842
13069
|
var FAT = 4294967293;
|
|
@@ -13024,7 +13251,7 @@ function resizeCompoundFileStreamV4(input, path2, replacement) {
|
|
|
13024
13251
|
}
|
|
13025
13252
|
}
|
|
13026
13253
|
|
|
13027
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
13254
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-allocation.js
|
|
13028
13255
|
function appendCompoundAllocations(input, existingFatIds, payloads, sectorSize = 512) {
|
|
13029
13256
|
const sectorCount = input.length / sectorSize - 1;
|
|
13030
13257
|
const entriesPerFat = sectorSize / 4;
|
|
@@ -13071,7 +13298,7 @@ function followCompoundAllocation(table, start) {
|
|
|
13071
13298
|
return ids;
|
|
13072
13299
|
}
|
|
13073
13300
|
|
|
13074
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
13301
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-mini.js
|
|
13075
13302
|
var END3 = 4294967294;
|
|
13076
13303
|
var FREE2 = 4294967295;
|
|
13077
13304
|
var SECTOR = 512;
|
|
@@ -13143,7 +13370,7 @@ function resizeMiniCompoundStream(input, fat, fatIds, root, target, replacement,
|
|
|
13143
13370
|
return output.bytes;
|
|
13144
13371
|
}
|
|
13145
13372
|
|
|
13146
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
13373
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize.js
|
|
13147
13374
|
var END4 = 4294967294;
|
|
13148
13375
|
var FREE3 = 4294967295;
|
|
13149
13376
|
var FAT2 = 4294967293;
|
|
@@ -13308,7 +13535,7 @@ function resizeCompoundFileStream(input, path2, replacement) {
|
|
|
13308
13535
|
}
|
|
13309
13536
|
}
|
|
13310
13537
|
|
|
13311
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
13538
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cfb.js
|
|
13312
13539
|
var DocCfbRewriteError = class extends Error {
|
|
13313
13540
|
constructor(message) {
|
|
13314
13541
|
super(message);
|
|
@@ -13363,7 +13590,7 @@ function unwrapDocBytes(bytes) {
|
|
|
13363
13590
|
}
|
|
13364
13591
|
}
|
|
13365
13592
|
|
|
13366
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
13593
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fkp.js
|
|
13367
13594
|
var PAGE_SIZE = 512;
|
|
13368
13595
|
function parseBteTable(tableStream, at) {
|
|
13369
13596
|
const view = new DataView(tableStream.buffer, tableStream.byteOffset, tableStream.byteLength);
|
|
@@ -13504,7 +13731,7 @@ function buildSingleRunChpxPage(fcStart, fcEnd, blob) {
|
|
|
13504
13731
|
return page;
|
|
13505
13732
|
}
|
|
13506
13733
|
|
|
13507
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
13734
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cp1252.js
|
|
13508
13735
|
var CP1252_HIGH_BLOCK = [
|
|
13509
13736
|
8364,
|
|
13510
13737
|
129,
|
|
@@ -13572,7 +13799,7 @@ function encodeCp1252(text) {
|
|
|
13572
13799
|
return Uint8Array.from(bytes);
|
|
13573
13800
|
}
|
|
13574
13801
|
|
|
13575
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
13802
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole-document-doc-pieces.js
|
|
13576
13803
|
var CLXT_PRC = 1;
|
|
13577
13804
|
var CLXT_PCDT = 2;
|
|
13578
13805
|
var DocResourceLimitError = class extends Error {
|
|
@@ -13784,7 +14011,7 @@ function buildClxBytes(pieces, prcBytes = new Uint8Array()) {
|
|
|
13784
14011
|
return result;
|
|
13785
14012
|
}
|
|
13786
14013
|
|
|
13787
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
14014
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fields.js
|
|
13788
14015
|
var UnsupportedDocFieldEditError = class extends Error {
|
|
13789
14016
|
constructor(message) {
|
|
13790
14017
|
super(message);
|
|
@@ -13868,7 +14095,7 @@ function shiftDocMainFieldCps(table, at, body, editStart, editEnd, delta, maxFie
|
|
|
13868
14095
|
return result;
|
|
13869
14096
|
}
|
|
13870
14097
|
|
|
13871
|
-
// ../../node_modules/.bun/@christophervr+ole2@0.
|
|
14098
|
+
// ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole-document-doc-editor.js
|
|
13872
14099
|
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];
|
|
13873
14100
|
var RISKY_STTB_INDICES = [21, 22, 23];
|
|
13874
14101
|
var SAFE_EXTENDED_FC_LCB_INDICES = /* @__PURE__ */ new Set([93, 94, 113, 181, 182]);
|