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.
Files changed (65) hide show
  1. package/dist/{PptxHandler-DDEJ6CKU.mjs → PptxHandler-BL4B7CZO.mjs} +2 -2
  2. package/dist/automation/index.cjs +1 -1
  3. package/dist/automation/index.mjs +1 -1
  4. package/dist/chart/gradient-definition.d.ts +2 -0
  5. package/dist/chart/gradient-definition.d.ts.map +1 -1
  6. package/dist/chart/index.cjs +1 -1
  7. package/dist/chart/index.mjs +1 -1
  8. package/dist/{chunk-5L4DHJV3.mjs → chunk-GAGSCAR3.mjs} +46 -43
  9. package/dist/{chunk-QXZJOUW4.mjs → chunk-NIHPA63A.mjs} +1 -1
  10. package/dist/{chunk-UQQGC6O3.mjs → chunk-TTPZITQN.mjs} +841 -614
  11. package/dist/{chunk-Q52O7SXQ.mjs → chunk-Z7IQR4S4.mjs} +3 -3
  12. package/dist/{chunk-EPNLABIU.mjs → chunk-ZAP5WLEN.mjs} +1 -1
  13. package/dist/crypto/index.cjs +281 -109
  14. package/dist/crypto/index.mjs +281 -109
  15. package/dist/diagram/engine/text-measure.d.ts +1 -1
  16. package/dist/diagram/layout/smartart-font-table.d.ts +1 -1
  17. package/dist/diagram/layout/smartart-layout-interpreter-linear-content-size.d.ts +1 -1
  18. package/dist/diagram/layout/smartart-layout-item-font-size.d.ts +1 -1
  19. package/dist/diagram/layout/smartart-layout-item-font-tier-fit.d.ts +1 -1
  20. package/dist/diagram/layout/smartart-line-pitch.d.ts +1 -1
  21. package/dist/diagram/layout/smartart-text-wrap-fit.d.ts +1 -1
  22. package/dist/docx/index.cjs +1 -1
  23. package/dist/docx/index.mjs +1 -1
  24. package/dist/docx/layout/index.cjs +1 -1
  25. package/dist/docx/layout/index.mjs +1 -1
  26. package/dist/docx/load/index.cjs +481 -254
  27. package/dist/docx/load/index.mjs +481 -254
  28. package/dist/docx/ui/index.cjs +1 -1
  29. package/dist/docx/ui/index.mjs +1 -1
  30. package/dist/index.cjs +1 -1
  31. package/dist/index.mjs +1 -1
  32. package/dist/pptx/automation/index.cjs +1391 -1154
  33. package/dist/pptx/automation/index.d.ts +3 -3
  34. package/dist/pptx/automation/index.mjs +5 -5
  35. package/dist/pptx/chunks/{index-JNv7AJx5.d.ts → index-CKIUurnd.d.ts} +2 -2
  36. package/dist/pptx/chunks/{index-JNv7AJx5.d.ts.map → index-CKIUurnd.d.ts.map} +1 -1
  37. package/dist/pptx/chunks/{index-EZJZ7USt.d.ts → index-Cn-GzYGp.d.ts} +64 -15
  38. package/dist/pptx/chunks/{index-EZJZ7USt.d.ts.map → index-Cn-GzYGp.d.ts.map} +1 -1
  39. package/dist/pptx/chunks/{text-operations-DtCxXrMh.d.ts → text-operations-BHfAm5K9.d.ts} +8 -1
  40. package/dist/pptx/chunks/text-operations-BHfAm5K9.d.ts.map +1 -0
  41. package/dist/pptx/cli/index.cjs +1270 -1088
  42. package/dist/pptx/cli/index.d.ts +1 -1
  43. package/dist/pptx/cli/index.mjs +4 -4
  44. package/dist/pptx/converter/index.d.ts +1 -1
  45. package/dist/pptx/converter/index.mjs +2 -2
  46. package/dist/pptx/index.cjs +1411 -1174
  47. package/dist/pptx/index.d.ts +3 -3
  48. package/dist/pptx/index.mjs +5 -5
  49. package/dist/text/font-metrics/font-advance-widths-aptos-display.generated.d.ts +1 -1
  50. package/dist/text/font-metrics/font-advance-widths-aptos.generated.d.ts +1 -1
  51. package/dist/text/font-metrics/font-advance-widths-arial.generated.d.ts +1 -1
  52. package/dist/text/font-metrics/font-advance-widths-calibri-light.generated.d.ts +1 -1
  53. package/dist/text/font-metrics/font-advance-widths-calibri.generated.d.ts +1 -1
  54. package/dist/text/font-metrics/font-advance-widths-segoe-ui.generated.d.ts +1 -1
  55. package/dist/text/font-metrics/font-advance-widths-times-new-roman.generated.d.ts +1 -1
  56. package/dist/visio/index.cjs +482 -232
  57. package/dist/visio/index.mjs +482 -232
  58. package/dist/visio/ui/data-graphic-rules.d.ts +2 -2
  59. package/dist/xlsx/formula/test-helpers.d.ts +9 -9
  60. package/dist/xlsx/index.cjs +1 -1
  61. package/dist/xlsx/index.mjs +1 -1
  62. package/dist/xlsx/load/index.cjs +415 -188
  63. package/dist/xlsx/load/index.mjs +415 -188
  64. package/package.json +5 -5
  65. package/dist/pptx/chunks/text-operations-DtCxXrMh.d.ts.map +0 -1
@@ -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.12.0/node_modules/@christophervr/ole2/dist/ole2-parser-types.js
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.12.0/node_modules/@christophervr/ole2/dist/ole2-parser-read.js
57
- function parseOle2(buffer) {
58
- const data = new Uint8Array(buffer);
59
- const view = new DataView(buffer);
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
- throw new Ole2ParseError("Invalid byte order mark");
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 || data.length % sectorSize !== 0) {
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 readSectorChain(startSector) {
141
- const sectors = [];
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 FAT chain at sector ${current}`);
326
+ throw new Ole2ParseError(`Circular reference in ${label} chain at sector ${current}`);
147
327
  }
148
328
  visited.add(current);
149
- sectors.push(readSector(current));
150
- if (fatEntries[current] === void 0)
151
- throw new Ole2ParseError("Missing FAT chain entry");
152
- current = fatEntries[current];
153
- }
154
- if (current !== ENDOFCHAIN)
155
- throw new Ole2ParseError("Invalid FAT chain terminator");
156
- const totalLength = sectors.length * sectorSize;
157
- const result = new Uint8Array(totalLength);
158
- let offset = 0;
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 raw = readSectorChain(startSector);
171
- if (raw.length < size)
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
- return raw.subarray(0, size);
174
- }
175
- const dirRaw = readSectorChain(firstDirectorySector);
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
- const nameBytes = Math.max(0, nameLen - 2);
190
- let name = "";
191
- for (let j = 0; j < nameBytes; j += 2) {
192
- name += String.fromCharCode(entryView.getUint16(j, true));
193
- }
194
- const leftSiblingId = entryView.getUint32(68, true);
195
- const rightSiblingId = entryView.getUint32(72, true);
196
- const childId = entryView.getUint32(76, true);
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 && rootEntry.startSector <= MAXREGSECT) {
375
+ if (rootEntry.startSector <= MAXREGSECT) {
225
376
  miniStreamData = readStream(rootEntry.startSector, rootEntry.size);
226
377
  }
227
378
  const miniFatEntries = [];
228
- if (firstMiniFATSector <= MAXREGSECT && totalMiniFATSectors > 0) {
229
- const miniFatRaw = readSectorChain(firstMiniFATSector);
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 sectors = [];
246
- let current = startSector;
247
- const visited = /* @__PURE__ */ new Set();
248
- while (current <= MAXREGSECT) {
249
- if (visited.has(current)) {
250
- throw new Ole2ParseError(`Circular reference in mini FAT chain at sector ${current}`);
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
- visited.add(current);
253
- const offset2 = current * miniSectorSize;
254
- if (offset2 + miniSectorSize > miniStreamData.length || miniFatEntries[current] === void 0) {
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
- sectors.push(miniStreamData.subarray(offset2, offset2 + miniSectorSize));
258
- current = miniFatEntries[current];
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 (current !== ENDOFCHAIN)
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
- const result = new Uint8Array(totalLength);
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 getStream(name) {
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
- return { entries, getStream };
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.12.0/node_modules/@christophervr/ole2/dist/utils/ooxml-crypto-primitives.js
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.12.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-helpers.js
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.12.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-serialize.js
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.12.0/node_modules/@christophervr/ole2/dist/ole2-parser-write.js
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 child = (parent, local) => elements(parent).find((element) => element.localName === local);
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 = child(root, field);
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 = child(root, field);
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 child2(doc, parent, name, before) {
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(child2(doc, sectPr, "type", AFTER_TYPE), "val", section.type);
4745
- const size = child2(doc, sectPr, "pgSz", AFTER_PGSZ);
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 = child2(doc, sectPr, "pgMar", AFTER_PGSZ.slice(1));
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 = child2(doc, sectPr, "cols", AFTER_COLS);
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
- child2(doc, sectPr, "vAlign", ["noEndnote", "titlePg", ...AFTER_TITLEPG]),
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
- child2(doc, sectPr, "titlePg", AFTER_TITLEPG).removeAttributeNS(WORD_NS, "val");
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 = child2(doc, sectPr, "lnNumType", AFTER_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) => child2(d, parent, name, AFTER_PGBORDERS)
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 = child2(doc, sectPr, "pgNumType", AFTER_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 child3 of children2(element, local)) element.removeChild(child3);
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
- (child3) => child3.nodeType === 3 && child3.textContent?.trim()
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 child3 of children2(element, local)) element.removeChild(child3);
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 child3 of [formulas, path2, typePath, handles, lock]) type.appendChild(child3);
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 child3 of [fill, text, wrap]) shape.appendChild(child3);
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((child3) => child3.namespaceURI === W_NS && allowed.includes(child3.localName));
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 child3 of Array.from(content.childNodes)) content.removeChild(child3);
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 child3 of Array.from(node.childNodes)) {
6186
- if (!isElement(child3)) continue;
6187
- if (child3.localName === local) result.push(child3);
6188
- visit(child3);
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((child3) => ({
6341
- name: child3.localName,
6342
- value: child3.getAttribute("val") ?? ""
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 child3 of elements(paragraph))
6579
- if (child3.namespaceURI === NS.a && ["r", "fld", "br"].includes(child3.localName))
6580
- runs.push(parseRun(child3));
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 child3 of Array.from(container2.childNodes)) {
6803
- if (child3.nodeType !== 1) continue;
6804
- const element = child3;
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 child3 of elements(element)) {
7273
- if (handled.has(child3.localName)) continue;
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(child3)} is not modelled; it is kept only in the source part.`
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 child3 of elements(element)) {
7844
- if (CHART_GROUP_ELEMENTS[child3.localName]) {
7845
- plotArea.groups.push(parseGroup(context, child3));
7846
- handled.add(child3.localName);
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[child3.localName];
8020
+ const axis = AXIS_ELEMENTS[child4.localName];
7849
8021
  if (axis) {
7850
- plotArea.axes.push(parseAxis(context, child3, axis));
7851
- handled.add(child3.localName);
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 child3 of Array.from(parent.childNodes))
8298
- if (isElement(child3) && child3.namespaceURI === ns && child3.localName === local) return child3;
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 child3 of Array.from(node.childNodes)) {
8307
- if (!isElement(child3)) continue;
8308
- if (child3.namespaceURI === ns && child3.localName === local) return child3;
8309
- stack.push(child3);
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 child3 of Array.from(node.childNodes)) {
8357
- if (!isElement(child3)) continue;
8358
- if (child3.namespaceURI === W_NS2 && child3.localName === "p")
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(child3.getElementsByTagNameNS(W_NS2, "t")).map((t) => t.textContent ?? "").join("")
8532
+ Array.from(child4.getElementsByTagNameNS(W_NS2, "t")).map((t) => t.textContent ?? "").join("")
8361
8533
  );
8362
- else visit(child3);
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 child3 of Array.from(run.childNodes))
8491
- if (isElement(child3) && (named2(child3, "drawing") || named2(child3, "pict"))) return child3;
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 child3 of Array.from(node.childNodes)) if (isElement(child3)) stack.push(child3);
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 child3 of Array.from(node.childNodes)) {
8603
- if (isElement(child3) && (named2(child3, "rPr") || child3 === keep)) continue;
8604
- node.removeChild(child3);
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 child3 of children2(element, local)) element.removeChild(child3);
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 child3 of Array.from(node.childNodes))
8854
- if (child3.nodeType !== 1 || child3.localName !== "rPr") node.removeChild(child3);
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
- (child3) => isElement(child3) && !named2(child3, "rPr")
9175
+ (child4) => isElement(child4) && !named2(child4, "rPr")
9004
9176
  );
9005
- return content.length > 0 && content.every((child3) => named2(child3, "commentReference"));
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 child3 of Array.from(item.childNodes).filter(isElement)) {
9056
- for (const parsed of named2(child3, "r") ? [parseRun3(child3)] : parseOther?.(child3) ?? []) {
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 child3 of Array.from(item.childNodes).filter(isElement)) {
9071
- for (const parsed of named2(child3, "r") ? [parseRun3(child3, revision)] : parseOther?.(child3) ?? []) {
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
- (child3) => isElement(child3) && !named2(child3, "rPr") && !isCachedPageBreak(child3)
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 child3 of Array.from(parent.childNodes)) {
9118
- if (!isElement(child3)) {
9119
- if (child3.nodeType === 3 && child3.textContent?.trim()) return false;
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(child3)) {
9123
- slots.push({ element: child3, ...container2 && { container: container2 } });
9124
- } else if (named2(child3, "r")) {
9125
- if (isCommentReferenceRun(child3)) continue;
9126
- if (!runIsSafe(child3)) return false;
9127
- slots.push({ element: child3, ...container2 && { container: container2 } });
9128
- } else if (isRevisionWrapperElement(child3) && !container2) {
9129
- if (!runsOf(child3, void 0, slots)) return false;
9130
- } else if ((named2(child3, "hyperlink") || named2(child3, "fldSimple")) && !container2) {
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(child3, child3, slots)) return false;
9133
- if (named2(child3, "fldSimple") && slots.length === before) slots.push({ container: child3 });
9134
- } else if (isCommentAnchorElement(child3) && !container2) continue;
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 child3 of Array.from(paragraph.childNodes)) {
9142
- if (isElement(child3) && (named2(child3, "pPr") || named2(child3, "bookmarkStart") || named2(child3, "bookmarkEnd")))
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(child3)) {
9145
- if (child3.nodeType === 3 && child3.textContent?.trim()) return void 0;
9316
+ if (!isElement(child4)) {
9317
+ if (child4.nodeType === 3 && child4.textContent?.trim()) return void 0;
9146
9318
  continue;
9147
9319
  }
9148
- if (isEquationElement(child3)) {
9149
- slots.push({ element: child3 });
9150
- } else if (named2(child3, "r")) {
9151
- if (isCommentReferenceRun(child3)) continue;
9152
- if (!runIsSafe(child3)) return void 0;
9153
- slots.push({ element: child3 });
9154
- } else if (isRevisionWrapperElement(child3)) {
9155
- if (!runsOf(child3, void 0, slots)) return void 0;
9156
- } else if (named2(child3, "hyperlink") || named2(child3, "fldSimple")) {
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(child3, child3, slots)) return void 0;
9159
- if (named2(child3, "fldSimple") && slots.length === before) slots.push({ container: child3 });
9160
- } else if (!isCommentAnchorElement(child3)) return void 0;
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
- (child3) => isElement(child3) && (isEquationElement(child3) || named2(child3, "r") || named2(child3, "hyperlink") || named2(child3, "fldSimple") || isRevisionWrapperElement(child3) || isCommentAnchorElement(child3))
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 child3 of Array.from(container2.childNodes)) container2.removeChild(child3);
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 child3 of children2(element, local)) element.removeChild(child3);
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 child3 of Array.from(node.childNodes)) if (isElement(child3)) visit(child3);
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((child3) => AFTER_PPR.includes(child3.localName)) ?? null;
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 child3 of Array.from(element.childNodes)) {
11642
- if (!isElement(child3)) continue;
11643
- if (named2(child3, "fldChar")) {
11644
- const type = getW(child3, "fldCharType");
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(child3)?.locked;
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(child3, "instrText") && top && !top.inResult) top.instr += textContent(child3);
11655
- else if ((named2(child3, "t") || named2(child3, "delText")) && top?.inResult) {
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 child3 of Array.from(element.childNodes)) if (isElement(child3)) visit(child3);
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((child3) => child3.localName !== "rPr" && !isCachedPageBreak(child3));
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 child3 of content) {
11708
- if (named2(child3, "drawing") || named2(child3, "pict")) return child3;
11709
- if (child3.localName !== "AlternateContent") continue;
11710
- const choice = Array.from(child3.childNodes).filter(isElement).find((node) => node.localName === "Choice");
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((child3) => named2(child3, "instrText")) ? content.map((child3) => textContent(child3)).join("") : void 0;
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((child3) => {
11760
- if (named2(child3, "t") || named2(child3, "delText")) return textContent(child3);
11761
- if (named2(child3, "tab")) return " ";
11762
- if (named2(child3, "br") || named2(child3, "cr")) return "\n";
11763
- if (named2(child3, "noBreakHyphen")) return "\u2011";
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
- (child3) => {
11811
- const equation2 = parseEquation(child3);
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.12.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fib.js
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.12.0/node_modules/@christophervr/ole2/dist/ole2-stream-edit.js
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 || view.getUint16(28, true) !== 65534)
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.12.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-v4.js
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.12.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-allocation.js
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.12.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-mini.js
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.12.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize.js
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.12.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cfb.js
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.12.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fkp.js
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.12.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cp1252.js
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.12.0/node_modules/@christophervr/ole2/dist/ole-document-doc-pieces.js
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.12.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fields.js
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.12.0/node_modules/@christophervr/ole2/dist/ole-document-doc-editor.js
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]);