ooxml-core 1.6.1 → 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.
@@ -29,7 +29,7 @@ function isOoxmlCryptoError(error) {
29
29
  return code === "password-required" || code === "incorrect-password" || code === "data-integrity";
30
30
  }
31
31
 
32
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/ole2-parser-types.js
32
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-parser-types.js
33
33
  var OLE_MAGIC = new Uint8Array([208, 207, 17, 224, 161, 177, 26, 225]);
34
34
  var ENDOFCHAIN = 4294967294;
35
35
  var FREESECT = 4294967295;
@@ -37,7 +37,9 @@ var FATSECT = 4294967293;
37
37
  var DIFSECT = 4294967292;
38
38
  var MAXREGSECT = 4294967290;
39
39
  var ENTRY_TYPE_EMPTY = 0;
40
+ var ENTRY_TYPE_STORAGE = 1;
40
41
  var ENTRY_TYPE_STREAM = 2;
42
+ var NOSTREAM = 4294967295;
41
43
  var ENTRY_TYPE_ROOT = 5;
42
44
  var DIR_ENTRY_SIZE = 128;
43
45
  var Ole2ParseError = class extends Error {
@@ -47,10 +49,174 @@ var Ole2ParseError = class extends Error {
47
49
  }
48
50
  };
49
51
 
50
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/ole2-parser-read.js
51
- function parseOle2(buffer) {
52
- const data = new Uint8Array(buffer);
53
- const view = new DataView(buffer);
52
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-directory.js
53
+ var FILETIME_UNIX_EPOCH = 116444736000000000n;
54
+ function readFileTime(view, offset2) {
55
+ const ticks = view.getBigUint64(offset2, true);
56
+ if (ticks === 0n)
57
+ return void 0;
58
+ const ms = Number((ticks - FILETIME_UNIX_EPOCH) / 10000n);
59
+ const date = new Date(ms);
60
+ return Number.isNaN(date.getTime()) ? void 0 : date;
61
+ }
62
+ function decodeSlot(dir, id, majorVersion, warnings) {
63
+ const view = new DataView(dir.buffer, dir.byteOffset + id * DIR_ENTRY_SIZE, DIR_ENTRY_SIZE);
64
+ const nameLen = view.getUint16(64, true);
65
+ const type = view.getUint8(66);
66
+ const nameValid = nameLen >= 2 && nameLen <= 64 && nameLen % 2 === 0 && view.getUint16(nameLen - 2, true) === 0;
67
+ let name = "";
68
+ if (nameValid)
69
+ for (let j = 0; j < nameLen - 2; j += 2)
70
+ name += String.fromCharCode(view.getUint16(j, true));
71
+ const link = (offset2) => {
72
+ const value = view.getUint32(offset2, true);
73
+ return value === NOSTREAM ? -1 : value;
74
+ };
75
+ const sizeLow = view.getUint32(120, true);
76
+ const sizeHigh = view.getUint32(124, true);
77
+ let size = sizeLow;
78
+ if (majorVersion === 4)
79
+ size = sizeLow + sizeHigh * 4294967296;
80
+ else if (sizeHigh !== 0 && type !== ENTRY_TYPE_EMPTY) {
81
+ warnings.push({ code: "size-high-bits", message: `Ignored v3 stream-size high bits on directory entry ${id}` });
82
+ }
83
+ return {
84
+ id,
85
+ type,
86
+ nameValid,
87
+ entry: {
88
+ id,
89
+ name,
90
+ type,
91
+ color: view.getUint8(67),
92
+ leftSiblingId: link(68),
93
+ rightSiblingId: link(72),
94
+ childId: link(76),
95
+ clsid: new Uint8Array(view.buffer.slice(view.byteOffset + 80, view.byteOffset + 96)),
96
+ stateBits: view.getUint32(96, true),
97
+ created: readFileTime(view, 100),
98
+ modified: readFileTime(view, 108),
99
+ startSector: view.getUint32(116, true),
100
+ size,
101
+ parentId: -1
102
+ }
103
+ };
104
+ }
105
+ function readDirectory(dir, majorVersion, strict, warnings) {
106
+ const count2 = Math.floor(dir.length / DIR_ENTRY_SIZE);
107
+ const slots = [];
108
+ for (let id = 0; id < count2; id++)
109
+ slots.push(decodeSlot(dir, id, majorVersion, warnings));
110
+ const roots = slots.filter((slot2) => slot2.type === ENTRY_TYPE_ROOT);
111
+ if (roots.length !== 1 || !roots[0].nameValid)
112
+ throw new Ole2ParseError("Invalid root directory entry");
113
+ const root = roots[0];
114
+ root.entry.path = [];
115
+ const reached = /* @__PURE__ */ new Set([root.id]);
116
+ const fail2 = (message) => {
117
+ if (strict)
118
+ throw new Ole2ParseError(message);
119
+ warnings.push({ code: "directory-link", message });
120
+ };
121
+ const pending2 = [];
122
+ const push = (id, parent, from) => {
123
+ if (id === -1)
124
+ return;
125
+ const target = slots[id];
126
+ if (!target || target.type === ENTRY_TYPE_EMPTY || target.type === ENTRY_TYPE_ROOT) {
127
+ fail2(`Directory entry ${from} links to invalid entry ${id}`);
128
+ return;
129
+ }
130
+ if (reached.has(id)) {
131
+ fail2(`Cyclic directory tree at entry ${id}`);
132
+ return;
133
+ }
134
+ reached.add(id);
135
+ pending2.push({ id, parent });
136
+ };
137
+ push(root.entry.childId, root, root.id);
138
+ while (pending2.length) {
139
+ const { id, parent } = pending2.pop();
140
+ const slot2 = slots[id];
141
+ if (!slot2.nameValid)
142
+ throw new Ole2ParseError("Invalid directory entry name");
143
+ slot2.entry.parentId = parent.id;
144
+ slot2.entry.path = [...parent.entry.path, slot2.entry.name];
145
+ push(slot2.entry.leftSiblingId, parent, id);
146
+ push(slot2.entry.rightSiblingId, parent, id);
147
+ if (slot2.type === ENTRY_TYPE_STORAGE)
148
+ push(slot2.entry.childId, slot2, id);
149
+ }
150
+ const entries = [];
151
+ for (const slot2 of slots) {
152
+ if (slot2.type === ENTRY_TYPE_EMPTY)
153
+ continue;
154
+ if (!reached.has(slot2.id)) {
155
+ if (!slot2.nameValid) {
156
+ if (strict)
157
+ throw new Ole2ParseError("Invalid directory entry name");
158
+ warnings.push({ code: "invalid-unreachable-entry", message: `Skipped undecodable stale directory entry ${slot2.id}` });
159
+ continue;
160
+ }
161
+ if (strict)
162
+ throw new Ole2ParseError(`Directory entry ${slot2.id} is not reachable from the root`);
163
+ warnings.push({ code: "unreachable-entry", message: `Directory entry ${slot2.id} (${slot2.entry.name}) is not reachable from the root` });
164
+ }
165
+ entries.push(slot2.entry);
166
+ }
167
+ return entries;
168
+ }
169
+ function sameName(a2, b) {
170
+ return a2.length === b.length && a2.toUpperCase() === b.toUpperCase();
171
+ }
172
+ function bareName(name) {
173
+ return name.replace(/^[\u0001-\u0006]/, "");
174
+ }
175
+ function normalizePath(path2, rootName2) {
176
+ const parts = typeof path2 === "string" ? path2.split("/").filter((part) => part !== "") : [...path2];
177
+ if (parts.length && sameName(parts[0], rootName2) && typeof path2 === "string")
178
+ parts.shift();
179
+ return parts;
180
+ }
181
+ function child(entries, parentId, name) {
182
+ const children2 = entries.filter((entry3) => entry3.parentId === parentId && entry3.path !== void 0);
183
+ const pick2 = (matches2) => matches2.length === 1 ? matches2[0] : void 0;
184
+ const exact = children2.filter((entry3) => entry3.name === name);
185
+ if (exact.length)
186
+ return pick2(exact);
187
+ const folded = children2.filter((entry3) => sameName(entry3.name, name));
188
+ if (folded.length)
189
+ return pick2(folded);
190
+ return pick2(children2.filter((entry3) => sameName(bareName(entry3.name), bareName(name))));
191
+ }
192
+ function findDirectoryEntry(entries, path2) {
193
+ const root = entries.find((entry3) => entry3.type === ENTRY_TYPE_ROOT);
194
+ if (!root)
195
+ return void 0;
196
+ let current = root;
197
+ for (const name of normalizePath(path2, root.name)) {
198
+ if (current.type !== ENTRY_TYPE_ROOT && current.type !== ENTRY_TYPE_STORAGE)
199
+ return void 0;
200
+ current = child(entries, current.id, name);
201
+ if (!current)
202
+ return void 0;
203
+ }
204
+ return current;
205
+ }
206
+ function findStreamByName(entries, name, isReadable) {
207
+ const root = entries.find((entry3) => entry3.type === ENTRY_TYPE_ROOT);
208
+ if (root && root.name === name)
209
+ return root;
210
+ const top = entries.filter((entry3) => entry3.parentId === root?.id && isReadable(entry3));
211
+ return top.find((entry3) => entry3.name === name) ?? top.find((entry3) => sameName(entry3.name, name)) ?? entries.find((entry3) => entry3.name === name && isReadable(entry3));
212
+ }
213
+
214
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-parser-read.js
215
+ function parseOle2(buffer, options = {}) {
216
+ const strict = options.strict === true;
217
+ const data = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
218
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
219
+ const warnings = [];
54
220
  if (data.length < 512) {
55
221
  throw new Ole2ParseError("Truncated OLE2 compound file header");
56
222
  }
@@ -59,11 +225,12 @@ function parseOle2(buffer) {
59
225
  throw new Ole2ParseError("Not a valid OLE2 compound file");
60
226
  }
61
227
  }
62
- view.getUint16(24, true);
63
228
  const majorVersion = view.getUint16(26, true);
64
229
  const byteOrder = view.getUint16(28, true);
65
230
  if (byteOrder !== 65534) {
66
- throw new Ole2ParseError("Invalid byte order mark");
231
+ if (strict)
232
+ throw new Ole2ParseError("Invalid byte order mark");
233
+ warnings.push({ code: "byte-order", message: `Ignored byte order mark 0x${byteOrder.toString(16)}` });
67
234
  }
68
235
  const sectorSizePower = view.getUint16(30, true);
69
236
  const miniSectorSizePower = view.getUint16(32, true);
@@ -72,10 +239,14 @@ function parseOle2(buffer) {
72
239
  }
73
240
  const sectorSize = 1 << sectorSizePower;
74
241
  const miniSectorSize = 1 << miniSectorSizePower;
75
- if (data.length < sectorSize || data.length % sectorSize !== 0) {
242
+ if (data.length < sectorSize)
76
243
  throw new Ole2ParseError("Truncated OLE2 sector");
244
+ if (data.length % sectorSize !== 0) {
245
+ if (strict)
246
+ throw new Ole2ParseError("Truncated OLE2 sector");
247
+ warnings.push({ code: "unaligned-length", message: `File length ${data.length} is not a multiple of ${sectorSize}` });
77
248
  }
78
- const sectorCount = data.length / sectorSize - 1;
249
+ const sectorCount = Math.ceil(data.length / sectorSize) - 1;
79
250
  const totalFATSectors = view.getUint32(44, true);
80
251
  const firstDirectorySector = view.getUint32(48, true);
81
252
  const miniStreamCutoff = view.getUint32(56, true);
@@ -96,6 +267,13 @@ function parseOle2(buffer) {
96
267
  }
97
268
  return data.subarray(offset2, offset2 + sectorSize);
98
269
  }
270
+ function copySector(sector, target, at, want) {
271
+ const offset2 = sectorOffset(sector);
272
+ if (sector >= sectorCount || offset2 + want > data.length) {
273
+ throw new Ole2ParseError(`Sector ${sector} at offset ${offset2} exceeds file size ${data.length}`);
274
+ }
275
+ target.set(data.subarray(offset2, offset2 + want), at);
276
+ }
99
277
  const fatSectors = [];
100
278
  for (let i2 = 0; i2 < 109 && fatSectors.length < totalFATSectors; i2++) {
101
279
  const sector = view.getUint32(76 + i2 * 4, true);
@@ -131,29 +309,36 @@ function parseOle2(buffer) {
131
309
  fatEntries.push(fatView.getUint32(i2 * 4, true));
132
310
  }
133
311
  }
134
- function readSectorChain(startSector) {
135
- const sectors = [];
136
- let current = startSector;
312
+ function followChain(table2, start, label2, needed) {
313
+ const ids = [];
137
314
  const visited = /* @__PURE__ */ new Set();
315
+ let current = start;
138
316
  while (current <= MAXREGSECT) {
317
+ if (!strict && needed !== void 0 && ids.length >= needed)
318
+ return ids;
139
319
  if (visited.has(current)) {
140
- throw new Ole2ParseError(`Circular reference in FAT chain at sector ${current}`);
320
+ throw new Ole2ParseError(`Circular reference in ${label2} chain at sector ${current}`);
141
321
  }
142
322
  visited.add(current);
143
- sectors.push(readSector(current));
144
- if (fatEntries[current] === void 0)
145
- throw new Ole2ParseError("Missing FAT chain entry");
146
- current = fatEntries[current];
147
- }
148
- if (current !== ENDOFCHAIN)
149
- throw new Ole2ParseError("Invalid FAT chain terminator");
150
- const totalLength = sectors.length * sectorSize;
151
- const result2 = new Uint8Array(totalLength);
152
- let offset2 = 0;
153
- for (const sector of sectors) {
154
- result2.set(sector, offset2);
155
- offset2 += sectorSize;
323
+ ids.push(current);
324
+ if (table2[current] === void 0)
325
+ throw new Ole2ParseError(`Missing ${label2} chain entry`);
326
+ current = table2[current];
327
+ }
328
+ if (current !== ENDOFCHAIN) {
329
+ if (strict || needed === void 0 || ids.length < needed) {
330
+ throw new Ole2ParseError(`Invalid ${label2} chain terminator`);
331
+ }
332
+ warnings.push({ code: "chain-terminator", message: `Accepted ${label2} chain ending in 0x${current.toString(16)}` });
156
333
  }
334
+ return ids;
335
+ }
336
+ function readMetadataChain(startSector, label2) {
337
+ if (startSector > MAXREGSECT)
338
+ return new Uint8Array(0);
339
+ const ids = followChain(fatEntries, startSector, label2 === "directory" ? "FAT" : label2);
340
+ const result2 = new Uint8Array(ids.length * sectorSize);
341
+ ids.forEach((id, i2) => result2.set(readSector(id), i2 * sectorSize));
157
342
  return result2;
158
343
  }
159
344
  function readStream(startSector, size) {
@@ -161,68 +346,44 @@ function parseOle2(buffer) {
161
346
  return new Uint8Array(0);
162
347
  if (size > sectorCount * sectorSize)
163
348
  throw new Ole2ParseError("Stream size exceeds file size");
164
- const raw2 = readSectorChain(startSector);
165
- if (raw2.length < size)
349
+ const needed = Math.ceil(size / sectorSize);
350
+ const ids = followChain(fatEntries, startSector, "FAT", needed);
351
+ if (ids.length < needed)
166
352
  throw new Ole2ParseError("Truncated stream sector chain");
167
- return raw2.subarray(0, size);
168
- }
169
- const dirRaw = readSectorChain(firstDirectorySector);
170
- const numEntries = Math.floor(dirRaw.length / DIR_ENTRY_SIZE);
171
- const entries = [];
172
- for (let i2 = 0; i2 < numEntries; i2++) {
173
- const entryOffset = i2 * DIR_ENTRY_SIZE;
174
- const entryView = new DataView(dirRaw.buffer, dirRaw.byteOffset + entryOffset, DIR_ENTRY_SIZE);
175
- const nameLen = entryView.getUint16(64, true);
176
- const objectType = entryView.getUint8(66);
177
- if (objectType === ENTRY_TYPE_EMPTY) {
178
- continue;
353
+ const result2 = new Uint8Array(size);
354
+ for (let i2 = 0; i2 < needed; i2++) {
355
+ copySector(ids[i2], result2, i2 * sectorSize, Math.min(sectorSize, size - i2 * sectorSize));
179
356
  }
180
- if (nameLen < 2 || nameLen > 64 || nameLen % 2 !== 0 || entryView.getUint16(nameLen - 2, true) !== 0) {
181
- throw new Ole2ParseError("Invalid directory entry name");
182
- }
183
- const nameBytes = Math.max(0, nameLen - 2);
184
- let name = "";
185
- for (let j = 0; j < nameBytes; j += 2) {
186
- name += String.fromCharCode(entryView.getUint16(j, true));
187
- }
188
- const leftSiblingId = entryView.getUint32(68, true);
189
- const rightSiblingId = entryView.getUint32(72, true);
190
- const childId = entryView.getUint32(76, true);
191
- const clsid = new Uint8Array(entryView.buffer.slice(entryView.byteOffset + 80, entryView.byteOffset + 96));
192
- const startSector = entryView.getUint32(116, true);
193
- const sizeLow = entryView.getUint32(120, true);
194
- let size = sizeLow;
195
- if (majorVersion === 4) {
196
- const sizeHigh = entryView.getUint32(124, true);
197
- size = sizeLow + sizeHigh * 4294967296;
198
- if (!Number.isSafeInteger(size) || size > sectorCount * sectorSize) {
199
- throw new Ole2ParseError("Stream size exceeds supported file bounds");
200
- }
357
+ return result2;
358
+ }
359
+ if (firstDirectorySector > MAXREGSECT)
360
+ throw new Ole2ParseError("Missing directory chain");
361
+ const entries = readDirectory(readMetadataChain(firstDirectorySector, "directory"), majorVersion, strict, warnings);
362
+ for (const entry3 of entries) {
363
+ if (majorVersion === 4 && (!Number.isSafeInteger(entry3.size) || entry3.size > sectorCount * sectorSize)) {
364
+ throw new Ole2ParseError("Stream size exceeds supported file bounds");
201
365
  }
202
- entries.push({
203
- name,
204
- type: objectType,
205
- startSector,
206
- size,
207
- childId: childId === 4294967295 ? -1 : childId,
208
- leftSiblingId: leftSiblingId === 4294967295 ? -1 : leftSiblingId,
209
- rightSiblingId: rightSiblingId === 4294967295 ? -1 : rightSiblingId,
210
- clsid
211
- });
212
366
  }
213
367
  const rootEntry = entries.find((e) => e.type === ENTRY_TYPE_ROOT);
214
- if (!rootEntry || entries.filter((e) => e.type === ENTRY_TYPE_ROOT).length !== 1) {
215
- throw new Ole2ParseError("Invalid root directory entry");
216
- }
217
368
  let miniStreamData;
218
- if (rootEntry && rootEntry.startSector <= MAXREGSECT) {
369
+ if (rootEntry.startSector <= MAXREGSECT) {
219
370
  miniStreamData = readStream(rootEntry.startSector, rootEntry.size);
220
371
  }
221
372
  const miniFatEntries = [];
222
- if (firstMiniFATSector <= MAXREGSECT && totalMiniFATSectors > 0) {
223
- const miniFatRaw = readSectorChain(firstMiniFATSector);
224
- if (miniFatRaw.length !== totalMiniFATSectors * sectorSize) {
373
+ if (firstMiniFATSector > MAXREGSECT && totalMiniFATSectors > 0) {
374
+ if (strict)
225
375
  throw new Ole2ParseError("Unexpected mini FAT chain length");
376
+ warnings.push({ code: "mini-fat-count", message: `Header lists ${totalMiniFATSectors} mini FAT sectors but no chain` });
377
+ }
378
+ if (firstMiniFATSector <= MAXREGSECT && (totalMiniFATSectors > 0 || !strict)) {
379
+ const miniFatRaw = readMetadataChain(firstMiniFATSector, "mini FAT");
380
+ if (miniFatRaw.length !== totalMiniFATSectors * sectorSize) {
381
+ if (strict)
382
+ throw new Ole2ParseError("Unexpected mini FAT chain length");
383
+ warnings.push({
384
+ code: "mini-fat-count",
385
+ message: `Header lists ${totalMiniFATSectors} mini FAT sectors; chain has ${miniFatRaw.length / sectorSize}`
386
+ });
226
387
  }
227
388
  const miniFatView = new DataView(miniFatRaw.buffer, miniFatRaw.byteOffset, miniFatRaw.byteLength);
228
389
  const miniCapacity = Math.floor((miniStreamData?.length ?? 0) / miniSectorSize);
@@ -236,48 +397,59 @@ function parseOle2(buffer) {
236
397
  if (!miniStreamData) {
237
398
  throw new Ole2ParseError("Mini stream container not found");
238
399
  }
239
- const sectors = [];
240
- let current = startSector;
241
- const visited = /* @__PURE__ */ new Set();
242
- while (current <= MAXREGSECT) {
243
- if (visited.has(current)) {
244
- throw new Ole2ParseError(`Circular reference in mini FAT chain at sector ${current}`);
400
+ const needed = Math.ceil(size / miniSectorSize);
401
+ const capacity = miniStreamData.length / miniSectorSize;
402
+ let ids;
403
+ try {
404
+ ids = followChain(miniFatEntries, startSector, "mini FAT", needed);
405
+ } catch (error) {
406
+ if (error instanceof Ole2ParseError && /Missing mini FAT/.test(error.message)) {
407
+ throw new Ole2ParseError("Mini stream sector exceeds allocation bounds");
245
408
  }
246
- visited.add(current);
247
- const offset3 = current * miniSectorSize;
248
- if (offset3 + miniSectorSize > miniStreamData.length || miniFatEntries[current] === void 0) {
409
+ throw error;
410
+ }
411
+ const result2 = new Uint8Array(size);
412
+ for (let i2 = 0; i2 < ids.length && i2 < needed; i2++) {
413
+ const id = ids[i2];
414
+ if (id >= capacity || (id + 1) * miniSectorSize > miniStreamData.length) {
249
415
  throw new Ole2ParseError("Mini stream sector exceeds allocation bounds");
250
416
  }
251
- sectors.push(miniStreamData.subarray(offset3, offset3 + miniSectorSize));
252
- current = miniFatEntries[current];
417
+ const want = Math.min(miniSectorSize, size - i2 * miniSectorSize);
418
+ result2.set(miniStreamData.subarray(id * miniSectorSize, id * miniSectorSize + want), i2 * miniSectorSize);
253
419
  }
254
- if (current !== ENDOFCHAIN)
255
- throw new Ole2ParseError("Invalid mini FAT chain terminator");
256
- const totalLength = sectors.length * miniSectorSize;
257
- if (totalLength < size)
420
+ if (ids.length < needed)
258
421
  throw new Ole2ParseError("Truncated mini stream sector chain");
259
- const result2 = new Uint8Array(totalLength);
260
- let offset2 = 0;
261
- for (const sector of sectors) {
262
- result2.set(sector, offset2);
263
- offset2 += miniSectorSize;
264
- }
265
- return result2.subarray(0, size);
422
+ return result2;
266
423
  }
267
- function getStream(name) {
268
- const entry3 = entries.find((e) => (e.type === ENTRY_TYPE_STREAM || e.type === ENTRY_TYPE_ROOT) && e.name === name);
269
- if (!entry3) {
270
- return void 0;
271
- }
424
+ function readEntry(entry3) {
272
425
  if (entry3.size < miniStreamCutoff && entry3.type !== ENTRY_TYPE_ROOT) {
273
426
  return readMiniStream(entry3.startSector, entry3.size);
274
427
  }
275
428
  return readStream(entry3.startSector, entry3.size);
276
429
  }
277
- return { entries, getStream };
430
+ const readable = (entry3) => entry3.type === ENTRY_TYPE_STREAM || entry3.type === ENTRY_TYPE_ROOT;
431
+ return {
432
+ entries,
433
+ warnings,
434
+ getStream(name) {
435
+ const entry3 = findStreamByName(entries, name, readable);
436
+ return entry3 ? readEntry(entry3) : void 0;
437
+ },
438
+ getStreamByPath(path2) {
439
+ const entry3 = findDirectoryEntry(entries, path2);
440
+ return entry3 && entry3.type === ENTRY_TYPE_STREAM ? readEntry(entry3) : void 0;
441
+ },
442
+ getStreamById(id) {
443
+ const entry3 = entries.find((candidate) => candidate.id === id);
444
+ return entry3 && readable(entry3) ? readEntry(entry3) : void 0;
445
+ },
446
+ findEntry(path2) {
447
+ return findDirectoryEntry(entries, path2);
448
+ }
449
+ };
278
450
  }
279
451
 
280
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/utils/ooxml-crypto-primitives.js
452
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/utils/ooxml-crypto-primitives.js
281
453
  function getSubtle() {
282
454
  if (typeof globalThis.crypto !== "undefined" && globalThis.crypto.subtle) {
283
455
  return globalThis.crypto.subtle;
@@ -2385,7 +2557,7 @@ function isEncryptedOoxmlPackage(input) {
2385
2557
  }
2386
2558
  }
2387
2559
 
2388
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-helpers.js
2560
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-helpers.js
2389
2561
  function compareDirEntryNames(a2, b) {
2390
2562
  const ua = a2.toUpperCase();
2391
2563
  const ub = b.toUpperCase();
@@ -2452,7 +2624,7 @@ function writeInt32Sectors(outBytes, int32Data, firstSector, numSectors, sectorS
2452
2624
  }
2453
2625
  }
2454
2626
 
2455
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-serialize.js
2627
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-serialize.js
2456
2628
  function writeHeader(outView, outBytes, params) {
2457
2629
  outBytes.set(OLE_MAGIC, 0);
2458
2630
  outView.setUint16(24, 62, true);
@@ -2545,7 +2717,7 @@ function writeStreamSectors(outBytes, streamData, chain2, sectorSize) {
2545
2717
  }
2546
2718
  }
2547
2719
 
2548
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/ole2-parser-write.js
2720
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-parser-write.js
2549
2721
  function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
2550
2722
  const sectorSize = 512;
2551
2723
  const miniSectorSize = 64;
@@ -3481,7 +3653,7 @@ function scan(xml) {
3481
3653
  }
3482
3654
  const children2 = [];
3483
3655
  let depth = 0;
3484
- let child3;
3656
+ let child4;
3485
3657
  i2 = openEnd;
3486
3658
  for (; ; ) {
3487
3659
  const lt = xml.indexOf("<", i2);
@@ -3499,13 +3671,13 @@ function scan(xml) {
3499
3671
  return { root, children: children2 };
3500
3672
  }
3501
3673
  depth--;
3502
- if (depth === 0 && child3)
3503
- children2.push({ ...child3, closeStart: lt, end, selfClosing: false });
3674
+ if (depth === 0 && child4)
3675
+ children2.push({ ...child4, closeStart: lt, end, selfClosing: false });
3504
3676
  } else if (xml[end - 2] === "/") {
3505
3677
  if (depth === 0)
3506
3678
  children2.push({ start: lt, openEnd: end, closeStart: end, end, selfClosing: true });
3507
3679
  } else {
3508
- if (depth === 0) child3 = { start: lt, openEnd: end };
3680
+ if (depth === 0) child4 = { start: lt, openEnd: end };
3509
3681
  depth++;
3510
3682
  }
3511
3683
  }
@@ -5493,7 +5665,7 @@ function selfContainedXml(element2) {
5493
5665
  clone.setAttribute(`xmlns:${prefix}`, uri);
5494
5666
  }
5495
5667
  }
5496
- for (const child3 of elements(node)) visit(child3);
5668
+ for (const child4 of elements(node)) visit(child4);
5497
5669
  };
5498
5670
  visit(element2);
5499
5671
  return outerXml(clone);
@@ -5754,8 +5926,8 @@ function parseDynamicArrayMetadata(xml) {
5754
5926
  }
5755
5927
  if (!root) return out;
5756
5928
  const top = /* @__PURE__ */ new Map();
5757
- for (const child3 of elements(root))
5758
- top.set(child3.localName, [...top.get(child3.localName) ?? [], child3]);
5929
+ for (const child4 of elements(root))
5930
+ top.set(child4.localName, [...top.get(child4.localName) ?? [], child4]);
5759
5931
  const types = childrenNamed(top.get("metadataTypes")?.[0], "metadataType").map(
5760
5932
  (t) => att(t, "name") ?? ""
5761
5933
  );
@@ -6099,10 +6271,10 @@ function booleanAttribute(element2, name) {
6099
6271
  function descendants2(root, local) {
6100
6272
  const result2 = [];
6101
6273
  const visit = (node) => {
6102
- for (const child3 of Array.from(node.childNodes)) {
6103
- if (!isElement(child3)) continue;
6104
- if (child3.localName === local) result2.push(child3);
6105
- visit(child3);
6274
+ for (const child4 of Array.from(node.childNodes)) {
6275
+ if (!isElement(child4)) continue;
6276
+ if (child4.localName === local) result2.push(child4);
6277
+ visit(child4);
6106
6278
  }
6107
6279
  };
6108
6280
  visit(root);
@@ -6139,9 +6311,9 @@ function parseDrawingColor(element2) {
6139
6311
  const color = {
6140
6312
  kind,
6141
6313
  value: colorValue(kind, element2),
6142
- transforms: elements(element2).map((child3) => ({
6143
- name: child3.localName,
6144
- value: child3.getAttribute("val") ?? ""
6314
+ transforms: elements(element2).map((child4) => ({
6315
+ name: child4.localName,
6316
+ value: child4.getAttribute("val") ?? ""
6145
6317
  }))
6146
6318
  };
6147
6319
  const fallback = kind === "system" ? element2.getAttribute("lastClr") : null;
@@ -7571,9 +7743,9 @@ function parseRun(run2) {
7571
7743
  }
7572
7744
  function parseParagraph(paragraph2) {
7573
7745
  const runs = [];
7574
- for (const child3 of elements(paragraph2))
7575
- if (child3.namespaceURI === NS.a && ["r", "fld", "br"].includes(child3.localName))
7576
- runs.push(parseRun(child3));
7746
+ for (const child4 of elements(paragraph2))
7747
+ if (child4.namespaceURI === NS.a && ["r", "fld", "br"].includes(child4.localName))
7748
+ runs.push(parseRun(child4));
7577
7749
  const properties2 = first(paragraph2, "pPr", NS.a);
7578
7750
  const align = properties2?.getAttribute("algn");
7579
7751
  const defaults = parseProperties(first(properties2, "defRPr", NS.a));
@@ -7795,9 +7967,9 @@ function parseDiagramDrawing(source2, part) {
7795
7967
  const tree = root.localName === "spTree" ? root : first(root, "spTree", NS.dsp);
7796
7968
  let counter = 0;
7797
7969
  const visit = (container2, group) => {
7798
- for (const child3 of Array.from(container2.childNodes)) {
7799
- if (child3.nodeType !== 1) continue;
7800
- const element2 = child3;
7970
+ for (const child4 of Array.from(container2.childNodes)) {
7971
+ if (child4.nodeType !== 1) continue;
7972
+ const element2 = child4;
7801
7973
  if (element2.localName === "sp") {
7802
7974
  const shape2 = parseShape(element2, counter++, group, issues);
7803
7975
  if (shape2) shapes.push(shape2);
@@ -8252,8 +8424,8 @@ function readHeaderFooter(node) {
8252
8424
  if (value !== void 0) out[key] = value;
8253
8425
  }
8254
8426
  for (const [key, local] of Object.entries(HEADER_FOOTER_TEXT)) {
8255
- const child3 = xFirst(node, local);
8256
- if (child3) out[key] = xText(child3);
8427
+ const child4 = xFirst(node, local);
8428
+ if (child4) out[key] = xText(child4);
8257
8429
  }
8258
8430
  return out;
8259
8431
  }
@@ -8852,11 +9024,11 @@ function cNumber(context, parent, local) {
8852
9024
  return void 0;
8853
9025
  }
8854
9026
  function reportUnmodelled(context, element2, handled) {
8855
- for (const child3 of elements(element2)) {
8856
- if (handled.has(child3.localName)) continue;
9027
+ for (const child4 of elements(element2)) {
9028
+ if (handled.has(child4.localName)) continue;
8857
9029
  context.issues.push({
8858
9030
  code: "CHART_ELEMENT_NOT_MODELLED",
8859
- message: `${path(child3)} is not modelled; it is kept only in the source part.`
9031
+ message: `${path(child4)} is not modelled; it is kept only in the source part.`
8860
9032
  });
8861
9033
  }
8862
9034
  }
@@ -9423,15 +9595,15 @@ function parsePlotArea(context, element2) {
9423
9595
  return plotArea;
9424
9596
  }
9425
9597
  const handled = new Set(PLOT_AREA);
9426
- for (const child3 of elements(element2)) {
9427
- if (CHART_GROUP_ELEMENTS[child3.localName]) {
9428
- plotArea.groups.push(parseGroup(context, child3));
9429
- handled.add(child3.localName);
9598
+ for (const child4 of elements(element2)) {
9599
+ if (CHART_GROUP_ELEMENTS[child4.localName]) {
9600
+ plotArea.groups.push(parseGroup(context, child4));
9601
+ handled.add(child4.localName);
9430
9602
  }
9431
- const axis = AXIS_ELEMENTS[child3.localName];
9603
+ const axis = AXIS_ELEMENTS[child4.localName];
9432
9604
  if (axis) {
9433
- plotArea.axes.push(parseAxis(context, child3, axis));
9434
- handled.add(child3.localName);
9605
+ plotArea.axes.push(parseAxis(context, child4, axis));
9606
+ handled.add(child4.localName);
9435
9607
  }
9436
9608
  }
9437
9609
  reportUnmodelled(context, element2, handled);
@@ -9757,13 +9929,13 @@ function chartColorStyleXml(palette, source2) {
9757
9929
  const root = doc.documentElement;
9758
9930
  if (root.localName !== "colorStyle" || root.namespaceURI !== CHART_COLOR_STYLE_NS)
9759
9931
  return buildXml(fresh);
9760
- for (const child3 of elements(root)) {
9761
- if (child3.namespaceURI === NS.a || child3.namespaceURI === CHART_COLOR_STYLE_NS && child3.localName === "variation")
9762
- root.removeChild(child3);
9932
+ for (const child4 of elements(root)) {
9933
+ if (child4.namespaceURI === NS.a || child4.namespaceURI === CHART_COLOR_STYLE_NS && child4.localName === "variation")
9934
+ root.removeChild(child4);
9763
9935
  }
9764
- for (const child3 of elements(fresh.documentElement))
9936
+ for (const child4 of elements(fresh.documentElement))
9765
9937
  root.insertBefore(
9766
- doc.importNode(child3, true),
9938
+ doc.importNode(child4, true),
9767
9939
  elements(root).find(
9768
9940
  (node) => node.namespaceURI === CHART_COLOR_STYLE_NS && node.localName === "extLst"
9769
9941
  ) ?? null
@@ -9774,7 +9946,7 @@ function chartColorStyleXml(palette, source2) {
9774
9946
  }
9775
9947
 
9776
9948
  // chart/read-style.ts
9777
- var child = (parent, name) => first(parent, name, CHART_COLOR_STYLE_NS);
9949
+ var child2 = (parent, name) => first(parent, name, CHART_COLOR_STYLE_NS);
9778
9950
  function reference(node) {
9779
9951
  if (!node) return void 0;
9780
9952
  const out = { index: node.getAttribute("idx") ?? "" };
@@ -9785,10 +9957,10 @@ function reference(node) {
9785
9957
  function entry2(node) {
9786
9958
  const out = {
9787
9959
  sourceXml: buildXml(node),
9788
- ...readChartAppearance(child(node, "defRPr"), child(node, "spPr"))
9960
+ ...readChartAppearance(child2(node, "defRPr"), child2(node, "spPr"))
9789
9961
  };
9790
9962
  for (const key of ["fontRef", "lineRef", "fillRef", "effectRef"]) {
9791
- const ref = reference(child(node, key === "lineRef" ? "lnRef" : key));
9963
+ const ref = reference(child2(node, key === "lineRef" ? "lnRef" : key));
9792
9964
  if (ref) out[key] = ref;
9793
9965
  }
9794
9966
  return out;
@@ -10692,7 +10864,7 @@ function writeChartAxisFormatting(root, formatting) {
10692
10864
  if (!node) {
10693
10865
  node = root.ownerDocument.createElementNS(NS.c, "c:" + name);
10694
10866
  const before = elements(axis).find(
10695
- (child3) => child3.namespaceURI === NS.c && successors.includes(child3.localName)
10867
+ (child4) => child4.namespaceURI === NS.c && successors.includes(child4.localName)
10696
10868
  );
10697
10869
  axis.insertBefore(node, before ?? null);
10698
10870
  }
@@ -10736,7 +10908,7 @@ function writeChartFillFormatting(root, formatting) {
10736
10908
  node.insertBefore(
10737
10909
  properties2,
10738
10910
  elements(node).find(
10739
- (child3) => child3.namespaceURI === NS.c && successors.includes(child3.localName)
10911
+ (child4) => child4.namespaceURI === NS.c && successors.includes(child4.localName)
10740
10912
  ) ?? null
10741
10913
  );
10742
10914
  }
@@ -10765,12 +10937,12 @@ function writeChartLayoutFormatting(root, formatting) {
10765
10937
  target.insertBefore(
10766
10938
  clone,
10767
10939
  elements(target).find(
10768
- (child3) => child3.namespaceURI === NS.c && ![
10940
+ (child4) => child4.namespaceURI === NS.c && ![
10769
10941
  "tx",
10770
10942
  "legendPos",
10771
10943
  "legendEntry",
10772
10944
  ...name === "overlay" ? ["layout"] : []
10773
- ].includes(child3.localName)
10945
+ ].includes(child4.localName)
10774
10946
  ) ?? null
10775
10947
  );
10776
10948
  changed = true;
@@ -10783,7 +10955,7 @@ function writeChartLayoutFormatting(root, formatting) {
10783
10955
  var FILLS = /* @__PURE__ */ new Set(["noFill", "solidFill", "gradFill", "pattFill"]);
10784
10956
  function dropDrawingDeclarations(element2) {
10785
10957
  if (element2.getAttribute("xmlns:a") === NS.a) element2.removeAttribute("xmlns:a");
10786
- for (const child3 of elements(element2)) dropDrawingDeclarations(child3);
10958
+ for (const child4 of elements(element2)) dropDrawingDeclarations(child4);
10787
10959
  }
10788
10960
  function patchDrawingLine(ln2, line2) {
10789
10961
  if (line2.widthEmu === void 0) ln2.removeAttribute("w");
@@ -11260,8 +11432,8 @@ function writeChartTextFormatting(root, formatting) {
11260
11432
  node.insertBefore(
11261
11433
  clone,
11262
11434
  elements(node).find(
11263
- (child3) => child3.namespaceURI === NS.c && ["crossAx", "externalData", "printSettings", "userShapes", "extLst"].includes(
11264
- child3.localName
11435
+ (child4) => child4.namespaceURI === NS.c && ["crossAx", "externalData", "printSettings", "userShapes", "extLst"].includes(
11436
+ child4.localName
11265
11437
  )
11266
11438
  ) ?? null
11267
11439
  );
@@ -12100,8 +12272,8 @@ function reanchor(xml, anchor) {
12100
12272
  rowOff: Math.round(m.rowOffset)
12101
12273
  };
12102
12274
  for (const [local, value] of Object.entries(values2)) {
12103
- const child3 = first(node, local, NS.xdr);
12104
- if (child3) child3.textContent = String(value);
12275
+ const child4 = first(node, local, NS.xdr);
12276
+ if (child4) child4.textContent = String(value);
12105
12277
  }
12106
12278
  };
12107
12279
  set("from", anchor.from);
@@ -21116,7 +21288,7 @@ var ORDER = [
21116
21288
  "extLst"
21117
21289
  ];
21118
21290
  var kids = (parent, local) => elements(parent).filter((e) => e.localName === local);
21119
- function child2(doc, root, local) {
21291
+ function child3(doc, root, local) {
21120
21292
  const existing = kids(root, local)[0];
21121
21293
  if (existing) return existing;
21122
21294
  const node = doc.createElementNS(NS.x, local);
@@ -21135,7 +21307,7 @@ function mergeDynamicArray(xml) {
21135
21307
  }
21136
21308
  const root = doc.documentElement;
21137
21309
  if (root.localName !== "metadata") return void 0;
21138
- const types = child2(doc, root, "metadataTypes");
21310
+ const types = child3(doc, root, "metadataTypes");
21139
21311
  let typeIndex = kids(types, "metadataType").findIndex(
21140
21312
  (t) => t.getAttribute("name") === DYNAMIC_ARRAY_TYPE
21141
21313
  );
@@ -21174,7 +21346,7 @@ function mergeDynamicArray(xml) {
21174
21346
  bk.appendChild(extLst);
21175
21347
  future.appendChild(bk);
21176
21348
  setCount(future, "bk");
21177
- const cells = child2(doc, root, "cellMetadata");
21349
+ const cells = child3(doc, root, "cellMetadata");
21178
21350
  const cellBk = doc.createElementNS(NS.x, "bk");
21179
21351
  const rc = doc.createElementNS(NS.x, "rc");
21180
21352
  rc.setAttribute("t", String(typeIndex + 1));
@@ -21481,7 +21653,7 @@ function themePart(theme, sourceXml) {
21481
21653
  const scheme = first(themeElements, "clrScheme", NS.a);
21482
21654
  if (!scheme) return defaultThemeXml(theme);
21483
21655
  for (const slot2 of elements(scheme)) {
21484
- for (const child3 of elements(slot2)) slot2.removeChild(child3);
21656
+ for (const child4 of elements(slot2)) slot2.removeChild(child4);
21485
21657
  const color = doc.createElementNS(NS.a, "a:srgbClr");
21486
21658
  color.setAttribute("val", colorOf(theme, slot2.localName ?? ""));
21487
21659
  slot2.appendChild(color);
@@ -22138,9 +22310,9 @@ function setOrRemove(element2, name, value) {
22138
22310
  else element2.setAttribute(name, value);
22139
22311
  }
22140
22312
  var flag = (value, fallback) => value ?? fallback ? "1" : "0";
22141
- function insertBefore(parent, child3, before) {
22313
+ function insertBefore(parent, child4, before) {
22142
22314
  const next = elements(parent).find((e) => before.includes(e.localName));
22143
- parent.insertBefore(child3, next ?? null);
22315
+ parent.insertBefore(child4, next ?? null);
22144
22316
  }
22145
22317
  function setChildText(doc, parent, local, text, before) {
22146
22318
  const existing = xKid(parent, local);
@@ -23154,7 +23326,7 @@ var xlsbUnsupported = () => new UnsupportedWorkbookError(
23154
23326
  "Excel Binary Workbook (.xlsb) files are not supported; save as .xlsx in Excel."
23155
23327
  );
23156
23328
 
23157
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/ole2-stream-edit.js
23329
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole2-stream-edit.js
23158
23330
  var END = 4294967294;
23159
23331
  var MAX = 4294967290;
23160
23332
  var NIL = 4294967295;
@@ -23189,6 +23361,58 @@ function chainToEnd(table2, start, max) {
23189
23361
  }
23190
23362
  return out;
23191
23363
  }
23364
+ function chainPrefix(table2, start, needed) {
23365
+ const out = [], seen = /* @__PURE__ */ new Set();
23366
+ let id = start;
23367
+ while (out.length < needed) {
23368
+ if (id > MAX || id >= table2.length || seen.has(id))
23369
+ throw new Error("Invalid CFB chain");
23370
+ seen.add(id);
23371
+ out.push(id);
23372
+ id = table2[id];
23373
+ }
23374
+ return out;
23375
+ }
23376
+ function readTarget(input, target, root, fat, sector, sectorCount, sectorSize, miniSize, read32) {
23377
+ const size = target.size;
23378
+ if (size === 0)
23379
+ return new Uint8Array(0);
23380
+ const out = new Uint8Array(size);
23381
+ const copyPhysical = (at, want, into) => {
23382
+ if (at + want > input.length)
23383
+ throw new Error("Stream data exceeds file size");
23384
+ out.set(input.subarray(at, at + want), into);
23385
+ };
23386
+ if (size >= read32(56)) {
23387
+ if (size > sectorCount * sectorSize)
23388
+ throw new Error("Stream size exceeds file size");
23389
+ chainPrefix(fat, target.start, Math.ceil(size / sectorSize)).forEach((id, i2) => {
23390
+ if (id >= sectorCount)
23391
+ throw new Error("Invalid sector");
23392
+ copyPhysical((id + 1) * sectorSize, Math.min(sectorSize, size - i2 * sectorSize), i2 * sectorSize);
23393
+ });
23394
+ return out;
23395
+ }
23396
+ const miniFatSectors = chainToEnd(fat, read32(60), sectorCount);
23397
+ const miniCapacity = Math.floor(Math.min(root.size, sectorCount * sectorSize) / miniSize);
23398
+ const miniFat = [];
23399
+ for (const id of miniFatSectors) {
23400
+ const bytes = sector(id), dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
23401
+ for (let j = 0; j < sectorSize / 4 && miniFat.length < miniCapacity; j++)
23402
+ miniFat.push(dv.getUint32(j * 4, true));
23403
+ }
23404
+ const rootSectors = chainPrefix(fat, root.start, Math.ceil(root.size / sectorSize));
23405
+ chainPrefix(miniFat, target.start, Math.ceil(size / miniSize)).forEach((id, i2) => {
23406
+ const start = id * miniSize, want = Math.min(miniSize, size - i2 * miniSize);
23407
+ if (start + want > root.size)
23408
+ throw new Error("Mini stream out of bounds");
23409
+ const rootSector = rootSectors[Math.floor(start / sectorSize)];
23410
+ if (rootSector >= sectorCount)
23411
+ throw new Error("Invalid sector");
23412
+ copyPhysical((rootSector + 1) * sectorSize + start % sectorSize, want, i2 * miniSize);
23413
+ });
23414
+ return out;
23415
+ }
23192
23416
  function processCompoundFileStream(input, path2, replacement) {
23193
23417
  const reject = () => replacement ? input : void 0;
23194
23418
  try {
@@ -23196,18 +23420,19 @@ function processCompoundFileStream(input, path2, replacement) {
23196
23420
  return reject();
23197
23421
  const view = new DataView(input.buffer, input.byteOffset, input.byteLength);
23198
23422
  const read32 = (offset3) => view.getUint32(offset3, true);
23199
- 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)
23423
+ 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.
23424
+ replacement && view.getUint16(28, true) !== 65534)
23200
23425
  return reject();
23201
23426
  const major = view.getUint16(26, true), shift2 = view.getUint16(30, true), miniShift = view.getUint16(32, true);
23202
23427
  if (major !== 3 && major !== 4 || shift2 !== (major === 3 ? 9 : 12) || miniShift !== 6)
23203
23428
  return reject();
23204
23429
  const sectorSize = 1 << shift2, miniSize = 1 << miniShift;
23205
- if (input.length % sectorSize !== 0)
23430
+ if (input.length < sectorSize || replacement && input.length % sectorSize !== 0)
23206
23431
  return reject();
23207
- const sectorCount = input.length / sectorSize - 1;
23432
+ const sectorCount = Math.ceil(input.length / sectorSize) - 1;
23208
23433
  const offset2 = (id) => (id + 1) * sectorSize;
23209
23434
  const sector = (id) => {
23210
- if (id > MAX || id >= sectorCount)
23435
+ if (id > MAX || id >= sectorCount || offset2(id) + sectorSize > input.length)
23211
23436
  throw new Error("Invalid sector");
23212
23437
  return input.subarray(offset2(id), offset2(id) + sectorSize);
23213
23438
  };
@@ -23257,7 +23482,7 @@ function processCompoundFileStream(input, path2, replacement) {
23257
23482
  for (let i2 = 0; i2 < nameLength - 2; i2 += 2)
23258
23483
  name += String.fromCharCode(dvDir.getUint16(p + i2, true));
23259
23484
  const sizeLow = dvDir.getUint32(p + 120, true), sizeHigh = dvDir.getUint32(p + 124, true);
23260
- if (sizeHigh !== 0)
23485
+ if (sizeHigh !== 0 && (replacement || major === 4))
23261
23486
  return reject();
23262
23487
  entries.push({
23263
23488
  id,
@@ -23304,6 +23529,8 @@ function processCompoundFileStream(input, path2, replacement) {
23304
23529
  }
23305
23530
  if (!target)
23306
23531
  return reject();
23532
+ if (!replacement)
23533
+ return readTarget(input, target, root, fat, sector, sectorCount, sectorSize, miniSize, read32);
23307
23534
  const names = entries.map((e) => e.name.toLowerCase());
23308
23535
  if (replacement && (names.includes("encryptioninfo") || names.includes("encryptedpackage")))
23309
23536
  return reject();
@@ -23427,7 +23654,7 @@ function replaceCompoundFileStream(input, path2, replacement) {
23427
23654
  return processCompoundFileStream(input, path2, replacement) ?? input;
23428
23655
  }
23429
23656
 
23430
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/legacy-excel-cfb.js
23657
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/legacy-excel-cfb.js
23431
23658
  var WORKBOOK_STREAM_NAMES = ["workbook", "book"];
23432
23659
  function unwrapXlsBytes(bytes) {
23433
23660
  if (!isCfb(bytes)) {
@@ -23494,7 +23721,7 @@ function isCfb(bytes) {
23494
23721
  return OLE_MAGIC.every((value, index2) => bytes[index2] === value);
23495
23722
  }
23496
23723
 
23497
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-functions.js
23724
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-functions.js
23498
23725
  var TABLE = `0 COUNT -1|1 IF -1|2 ISNA 1|3 ISERROR 1|4 SUM -1|5 AVERAGE -1|6 MIN -1|7 MAX -1|8 ROW -1|9 COLUMN -1|10 NA 0|11 NPV -1|12 STDEV -1|13 DOLLAR -1|14 FIXED -1|15 SIN 1|16 COS 1|17 TAN 1|18 ATAN 1|19 PI 0|20 SQRT 1|21 EXP 1|22 LN 1|23 LOG10 1|24 ABS 1|25 INT 1|26 SIGN 1|27 ROUND 2|28 LOOKUP -1|29 INDEX -1|30 REPT 2|31 MID 3|32 LEN 1|33 VALUE 1|34 TRUE 0|35 FALSE 0|36 AND -1|37 OR -1|38 NOT 1|39 MOD 2|40 DCOUNT 3|41 DSUM 3|42 DAVERAGE 3|43 DMIN 3|44 DMAX 3|45 DSTDEV 3|46 VAR -1|47 DVAR 3|48 TEXT 2|49 LINEST -1|50 TREND -1|51 LOGEST -1|52 GROWTH -1|56 PV -1|57 FV -1|58 NPER -1|59 PMT -1|60 RATE -1|61 MIRR 3|62 IRR -1|63 RAND 0|64 MATCH -1|65 DATE 3|66 TIME 3|67 DAY 1|68 MONTH 1|69 YEAR 1|70 WEEKDAY -1|71 HOUR 1|72 MINUTE 1|73 SECOND 1|74 NOW 0|75 AREAS 1|76 ROWS 1|77 COLUMNS 1|78 OFFSET -1|82 SEARCH -1|83 TRANSPOSE 1|86 TYPE 1|97 ATAN2 2|98 ASIN 1|99 ACOS 1|100 CHOOSE -1|101 HLOOKUP -1|102 VLOOKUP -1|105 ISREF 1|109 LOG -1|111 CHAR 1|112 LOWER 1|113 UPPER 1|114 PROPER 1|115 LEFT -1|116 RIGHT -1|117 EXACT 2|118 TRIM 1|119 REPLACE 4|120 SUBSTITUTE -1|121 CODE 1|124 FIND -1|125 CELL -1|126 ISERR 1|127 ISTEXT 1|128 ISNUMBER 1|129 ISBLANK 1|130 T 1|131 N 1|140 DATEVALUE 1|141 TIMEVALUE 1|142 SLN 3|143 SYD 4|144 DDB -1|148 INDIRECT -1|150 CALL -1|162 CLEAN 1|163 MDETERM 1|164 MINVERSE 1|165 MMULT 2|167 IPMT -1|168 PPMT -1|169 COUNTA -1|183 PRODUCT -1|184 FACT 1|189 DPRODUCT 3|190 ISNONTEXT 1|193 STDEVP -1|194 VARP -1|195 DSTDEVP 3|196 DVARP 3|197 TRUNC -1|198 ISLOGICAL 1|199 DCOUNTA 3|204 USDOLLAR -1|205 FINDB -1|206 SEARCHB -1|207 REPLACEB 4|208 LEFTB -1|209 RIGHTB -1|210 MIDB 3|211 LENB 1|212 ROUNDUP 2|213 ROUNDDOWN 2|214 ASC 1|215 DBCS 1|216 RANK -1|219 ADDRESS -1|220 DAYS360 -1|221 TODAY 0|222 VDB -1|227 MEDIAN -1|228 SUMPRODUCT -1|229 SINH 1|230 COSH 1|231 TANH 1|232 ASINH 1|233 ACOSH 1|234 ATANH 1|235 DGET 3|244 INFO 1|247 DB -1|252 FREQUENCY 2|261 ERROR.TYPE 1|269 AVEDEV -1|270 BETADIST -1|271 GAMMALN 1|272 BETAINV -1|273 BINOMDIST 4|274 CHIDIST 2|275 CHIINV 2|276 COMBIN 2|277 CONFIDENCE 3|278 CRITBINOM 3|279 EVEN 1|280 EXPONDIST 3|281 FDIST 3|282 FINV 3|283 FISHER 1|284 FISHERINV 1|285 FLOOR 2|286 GAMMADIST 4|287 GAMMAINV 3|288 CEILING 2|289 HYPGEOMDIST 4|290 LOGNORMDIST 3|291 LOGINV 3|292 NEGBINOMDIST 3|293 NORMDIST 4|294 NORMSDIST 1|295 NORMINV 3|296 NORMSINV 1|297 STANDARDIZE 3|298 ODD 1|299 PERMUT 2|300 POISSON 3|301 TDIST 3|302 WEIBULL 4|303 SUMXMY2 2|304 SUMX2MY2 2|305 SUMX2PY2 2|306 CHITEST 2|307 CORREL 2|308 COVAR 2|309 FORECAST 3|310 FTEST 2|311 INTERCEPT 2|312 PEARSON 2|313 RSQ 2|314 STEYX 2|315 SLOPE 2|316 TTEST 4|317 PROB -1|318 DEVSQ -1|319 GEOMEAN -1|320 HARMEAN -1|321 SUMSQ -1|322 KURT -1|323 SKEW -1|324 ZTEST -1|325 LARGE 2|326 SMALL 2|327 QUARTILE 2|328 PERCENTILE 2|329 PERCENTRANK -1|330 MODE -1|331 TRIMMEAN 2|332 TINV 2|336 CONCATENATE -1|337 POWER 2|342 RADIANS 1|343 DEGREES 1|344 SUBTOTAL -1|345 SUMIF -1|346 COUNTIF 2|347 COUNTBLANK 1|350 ISPMT 4|351 DATEDIF 3|352 DATESTRING 1|353 NUMBERSTRING 2|354 ROMAN -1|358 GETPIVOTDATA -1|359 HYPERLINK -1|360 PHONETIC 1|361 AVERAGEA -1|362 MAXA -1|363 MINA -1|364 STDEVPA -1|365 VARPA -1|366 STDEVA -1|367 VARA -1|368 BAHTTEXT 1`;
23499
23726
  var XLS_FUNCTIONS = new Map(TABLE.split("|").map((entry3) => {
23500
23727
  const [id, name, argc] = entry3.split(" ");
@@ -23502,7 +23729,7 @@ var XLS_FUNCTIONS = new Map(TABLE.split("|").map((entry3) => {
23502
23729
  }));
23503
23730
  var XLS_USER_FUNCTION_ID = 255;
23504
23731
 
23505
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-ptg-text.js
23732
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-ptg-text.js
23506
23733
  var BIFF_ERRORS = {
23507
23734
  0: "#NULL!",
23508
23735
  7: "#DIV/0!",
@@ -23597,7 +23824,7 @@ function readArrayConstant(extra) {
23597
23824
  return `{${lines.join(";")}}`;
23598
23825
  }
23599
23826
 
23600
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-records.js
23827
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-records.js
23601
23828
  var RT_CONTINUE = 60;
23602
23829
  function readXlsRecords(bytes, start = 0, end = bytes.length) {
23603
23830
  const records = [];
@@ -23763,7 +23990,7 @@ function joinedData(record) {
23763
23990
  return out;
23764
23991
  }
23765
23992
 
23766
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-ptg.js
23993
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-ptg.js
23767
23994
  function decodeFormula(rgce, extra, context, options) {
23768
23995
  try {
23769
23996
  return decode2(rgce, new ByteReader(extra), context, options);
@@ -23994,7 +24221,7 @@ function readAttr(reader, stack2, whitespace) {
23994
24221
  }
23995
24222
  }
23996
24223
 
23997
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-sst.js
24224
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-sst.js
23998
24225
  function parseSharedStrings2(record) {
23999
24226
  const reader = SegmentReader.of(record);
24000
24227
  reader.u32();
@@ -24011,7 +24238,7 @@ function parseSharedStrings2(record) {
24011
24238
  return strings;
24012
24239
  }
24013
24240
 
24014
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-styles.js
24241
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-styles.js
24015
24242
  var DEFAULT_XLS_PALETTE = "000000 FFFFFF FF0000 00FF00 0000FF FFFF00 FF00FF 00FFFF 000000 FFFFFF FF0000 00FF00 0000FF FFFF00 FF00FF 00FFFF 800000 008000 000080 808000 800080 008080 C0C0C0 808080 9999FF 993366 FFFFCC CCFFFF 660066 FF8080 0066CC CCCCFF 000080 FF00FF FFFF00 00FFFF 800080 800000 008080 0000FF 00CCFF CCFFFF CCFFCC FFFF99 99CCFF FF99CC CC99FF FFCC99 3366FF 33CCCC 99CC00 FFCC00 FF9900 FF6600 666699 969696 003366 339966 003300 333300 993300 993366 333399 333333".split(" ");
24016
24243
  var XLS_BUILTIN_FORMATS = {
24017
24244
  0: "General",
@@ -24268,7 +24495,7 @@ function applyXfExt(data, xfs, palette) {
24268
24495
  }
24269
24496
  }
24270
24497
 
24271
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-types.js
24498
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-types.js
24272
24499
  var XlsReadError = class extends Error {
24273
24500
  code;
24274
24501
  constructor(code, message) {
@@ -24278,7 +24505,7 @@ var XlsReadError = class extends Error {
24278
24505
  }
24279
24506
  };
24280
24507
 
24281
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-globals.js
24508
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-globals.js
24282
24509
  var RT = {
24283
24510
  BOF: 2057,
24284
24511
  EOF: 10,
@@ -24516,7 +24743,7 @@ function parseGlobals(records) {
24516
24743
  return out;
24517
24744
  }
24518
24745
 
24519
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8.js
24746
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8.js
24520
24747
  function decodeRk(rk) {
24521
24748
  const isInt = (rk & 2) !== 0;
24522
24749
  const isDiv100 = (rk & 1) !== 0;
@@ -24533,7 +24760,7 @@ function decodeRk(rk) {
24533
24760
  return isDiv100 ? value / 100 : value;
24534
24761
  }
24535
24762
 
24536
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-formulas.js
24763
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-formulas.js
24537
24764
  function readRefU(r) {
24538
24765
  return { firstRow: r.u16(), lastRow: r.u16(), firstCol: r.u8(), lastCol: r.u8() };
24539
24766
  }
@@ -24591,7 +24818,7 @@ function resolveFormulas(formulas, shared, arrays, globals) {
24591
24818
  }
24592
24819
  }
24593
24820
 
24594
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-sheet-extras.js
24821
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-sheet-extras.js
24595
24822
  function parseMergedCells(data) {
24596
24823
  const r = new ByteReader(data);
24597
24824
  const count2 = r.u16();
@@ -24786,7 +25013,7 @@ function parseNote(data) {
24786
25013
  return { row: row2, col, visible: (flags & 2) !== 0, id, author: r.xlString() };
24787
25014
  }
24788
25015
 
24789
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-sheet.js
25016
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-sheet.js
24790
25017
  var UNSUPPORTED = {
24791
25018
  432: "conditional formatting",
24792
25019
  2169: "conditional formatting",
@@ -25042,7 +25269,7 @@ function parseSheet(bound, records, start, globals) {
25042
25269
  return sheet;
25043
25270
  }
25044
25271
 
25045
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook.js
25272
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook.js
25046
25273
  function compoundStreamNames(bytes) {
25047
25274
  if (!OLE_MAGIC.every((value, index2) => bytes[index2] === value))
25048
25275
  return [];
@@ -25112,7 +25339,7 @@ function readXlsWorkbook(bytes) {
25112
25339
  };
25113
25340
  }
25114
25341
 
25115
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cp1252.js
25342
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cp1252.js
25116
25343
  var CP1252_HIGH_BLOCK = [
25117
25344
  8364,
25118
25345
  129,
@@ -25162,7 +25389,7 @@ function decodeCp1252(bytes) {
25162
25389
  return out;
25163
25390
  }
25164
25391
 
25165
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/ole-summary-properties.js
25392
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/ole-summary-properties.js
25166
25393
  var SUMMARY_STREAM_NAME = "SummaryInformation";
25167
25394
  var SUMMARY_TEXT_PROPERTIES = {
25168
25395
  title: 2,
@@ -25277,7 +25504,7 @@ function readSummaryProperties(bytes) {
25277
25504
  return result2;
25278
25505
  }
25279
25506
 
25280
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/legacy-office-metadata.js
25507
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/legacy-office-metadata.js
25281
25508
  function summaryStream(bytes) {
25282
25509
  return readCompoundFileStream(bytes, [SUMMARY_STREAM_NAME]);
25283
25510
  }