ooxml-core 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20935,10 +20935,10 @@ var init_ole_utils = __esm({
20935
20935
  }
20936
20936
  });
20937
20937
 
20938
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-types.js
20938
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-types.js
20939
20939
  var OLE_MAGIC, ENDOFCHAIN, FREESECT, FATSECT, DIFSECT, MAXREGSECT, ENTRY_TYPE_EMPTY, ENTRY_TYPE_STREAM, ENTRY_TYPE_ROOT, DIR_ENTRY_SIZE, Ole2ParseError;
20940
20940
  var init_ole2_parser_types = __esm({
20941
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-types.js"() {
20941
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-types.js"() {
20942
20942
  OLE_MAGIC = new Uint8Array([208, 207, 17, 224, 161, 177, 26, 225]);
20943
20943
  ENDOFCHAIN = 4294967294;
20944
20944
  FREESECT = 4294967295;
@@ -20958,10 +20958,13 @@ var init_ole2_parser_types = __esm({
20958
20958
  }
20959
20959
  });
20960
20960
 
20961
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-read.js
20961
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-read.js
20962
20962
  function parseOle2(buffer) {
20963
20963
  const data = new Uint8Array(buffer);
20964
20964
  const view = new DataView(buffer);
20965
+ if (data.length < 512) {
20966
+ throw new Ole2ParseError("Truncated OLE2 compound file header");
20967
+ }
20965
20968
  for (let i2 = 0; i2 < OLE_MAGIC.length; i2++) {
20966
20969
  if (data[i2] !== OLE_MAGIC[i2]) {
20967
20970
  throw new Ole2ParseError("Not a valid OLE2 compound file");
@@ -20975,8 +20978,15 @@ function parseOle2(buffer) {
20975
20978
  }
20976
20979
  const sectorSizePower = view.getUint16(30, true);
20977
20980
  const miniSectorSizePower = view.getUint16(32, true);
20981
+ if (majorVersion !== 3 && majorVersion !== 4 || sectorSizePower !== (majorVersion === 3 ? 9 : 12) || miniSectorSizePower !== 6) {
20982
+ throw new Ole2ParseError("Unsupported OLE2 version or sector size");
20983
+ }
20978
20984
  const sectorSize = 1 << sectorSizePower;
20979
20985
  const miniSectorSize = 1 << miniSectorSizePower;
20986
+ if (data.length < sectorSize || data.length % sectorSize !== 0) {
20987
+ throw new Ole2ParseError("Truncated OLE2 sector");
20988
+ }
20989
+ const sectorCount = data.length / sectorSize - 1;
20980
20990
  const totalFATSectors = view.getUint32(44, true);
20981
20991
  const firstDirectorySector = view.getUint32(48, true);
20982
20992
  const miniStreamCutoff = view.getUint32(56, true);
@@ -20984,6 +20994,9 @@ function parseOle2(buffer) {
20984
20994
  const totalMiniFATSectors = view.getUint32(64, true);
20985
20995
  const firstDIFATSector = view.getUint32(68, true);
20986
20996
  const totalDIFATSectors = view.getUint32(72, true);
20997
+ if (totalFATSectors > sectorCount || totalMiniFATSectors > sectorCount || totalDIFATSectors > sectorCount) {
20998
+ throw new Ole2ParseError("Allocation table count exceeds file size");
20999
+ }
20987
21000
  function sectorOffset(sector) {
20988
21001
  return (sector + 1) * sectorSize;
20989
21002
  }
@@ -21002,7 +21015,11 @@ function parseOle2(buffer) {
21002
21015
  }
21003
21016
  }
21004
21017
  let difatSector = firstDIFATSector;
21018
+ const difatSeen = /* @__PURE__ */ new Set();
21005
21019
  for (let d = 0; d < totalDIFATSectors && difatSector <= MAXREGSECT; d++) {
21020
+ if (difatSeen.has(difatSector))
21021
+ throw new Ole2ParseError("Circular DIFAT chain");
21022
+ difatSeen.add(difatSector);
21006
21023
  const difatData = readSector(difatSector);
21007
21024
  const difatView = new DataView(difatData.buffer, difatData.byteOffset, difatData.byteLength);
21008
21025
  const entriesPerSector = (sectorSize - 4) / 4;
@@ -21014,11 +21031,14 @@ function parseOle2(buffer) {
21014
21031
  }
21015
21032
  difatSector = difatView.getUint32(sectorSize - 4, true);
21016
21033
  }
21034
+ if (difatSeen.size !== totalDIFATSectors || fatSectors.length !== totalFATSectors || new Set(fatSectors).size !== fatSectors.length || fatSectors.some((id) => difatSeen.has(id))) {
21035
+ throw new Ole2ParseError("Invalid DIFAT allocation table");
21036
+ }
21017
21037
  const fatEntries = [];
21018
21038
  for (const fatSector of fatSectors) {
21019
21039
  const fatData = readSector(fatSector);
21020
21040
  const fatView = new DataView(fatData.buffer, fatData.byteOffset, fatData.byteLength);
21021
- for (let i2 = 0; i2 < sectorSize / 4; i2++) {
21041
+ for (let i2 = 0; i2 < sectorSize / 4 && fatEntries.length < sectorCount; i2++) {
21022
21042
  fatEntries.push(fatView.getUint32(i2 * 4, true));
21023
21043
  }
21024
21044
  }
@@ -21032,8 +21052,12 @@ function parseOle2(buffer) {
21032
21052
  }
21033
21053
  visited.add(current);
21034
21054
  sectors.push(readSector(current));
21035
- current = fatEntries[current] ?? ENDOFCHAIN;
21055
+ if (fatEntries[current] === void 0)
21056
+ throw new Ole2ParseError("Missing FAT chain entry");
21057
+ current = fatEntries[current];
21036
21058
  }
21059
+ if (current !== ENDOFCHAIN)
21060
+ throw new Ole2ParseError("Invalid FAT chain terminator");
21037
21061
  const totalLength = sectors.length * sectorSize;
21038
21062
  const result = new Uint8Array(totalLength);
21039
21063
  let offset = 0;
@@ -21044,16 +21068,14 @@ function parseOle2(buffer) {
21044
21068
  return result;
21045
21069
  }
21046
21070
  function readStream(startSector, size) {
21071
+ if (size === 0)
21072
+ return new Uint8Array(0);
21073
+ if (size > sectorCount * sectorSize)
21074
+ throw new Ole2ParseError("Stream size exceeds file size");
21047
21075
  const raw = readSectorChain(startSector);
21048
- return raw.subarray(0, Math.min(size, raw.length));
21049
- }
21050
- const miniFatEntries = [];
21051
- if (firstMiniFATSector <= MAXREGSECT && totalMiniFATSectors > 0) {
21052
- const miniFatRaw = readSectorChain(firstMiniFATSector);
21053
- const miniFatView = new DataView(miniFatRaw.buffer, miniFatRaw.byteOffset, miniFatRaw.byteLength);
21054
- for (let i2 = 0; i2 < miniFatRaw.length / 4; i2++) {
21055
- miniFatEntries.push(miniFatView.getUint32(i2 * 4, true));
21056
- }
21076
+ if (raw.length < size)
21077
+ throw new Ole2ParseError("Truncated stream sector chain");
21078
+ return raw.subarray(0, size);
21057
21079
  }
21058
21080
  const dirRaw = readSectorChain(firstDirectorySector);
21059
21081
  const numEntries = Math.floor(dirRaw.length / DIR_ENTRY_SIZE);
@@ -21066,6 +21088,9 @@ function parseOle2(buffer) {
21066
21088
  if (objectType === ENTRY_TYPE_EMPTY) {
21067
21089
  continue;
21068
21090
  }
21091
+ if (nameLen < 2 || nameLen > 64 || nameLen % 2 !== 0 || entryView.getUint16(nameLen - 2, true) !== 0) {
21092
+ throw new Ole2ParseError("Invalid directory entry name");
21093
+ }
21069
21094
  const nameBytes = Math.max(0, nameLen - 2);
21070
21095
  let name = "";
21071
21096
  for (let j = 0; j < nameBytes; j += 2) {
@@ -21079,8 +21104,11 @@ function parseOle2(buffer) {
21079
21104
  const sizeLow = entryView.getUint32(120, true);
21080
21105
  let size = sizeLow;
21081
21106
  if (majorVersion === 4) {
21082
- entryView.getUint32(124, true);
21083
- size = sizeLow;
21107
+ const sizeHigh = entryView.getUint32(124, true);
21108
+ size = sizeLow + sizeHigh * 4294967296;
21109
+ if (!Number.isSafeInteger(size) || size > sectorCount * sectorSize) {
21110
+ throw new Ole2ParseError("Stream size exceeds supported file bounds");
21111
+ }
21084
21112
  }
21085
21113
  entries.push({
21086
21114
  name,
@@ -21094,11 +21122,28 @@ function parseOle2(buffer) {
21094
21122
  });
21095
21123
  }
21096
21124
  const rootEntry = entries.find((e) => e.type === ENTRY_TYPE_ROOT);
21125
+ if (!rootEntry || entries.filter((e) => e.type === ENTRY_TYPE_ROOT).length !== 1) {
21126
+ throw new Ole2ParseError("Invalid root directory entry");
21127
+ }
21097
21128
  let miniStreamData;
21098
21129
  if (rootEntry && rootEntry.startSector <= MAXREGSECT) {
21099
- miniStreamData = readSectorChain(rootEntry.startSector);
21130
+ miniStreamData = readStream(rootEntry.startSector, rootEntry.size);
21131
+ }
21132
+ const miniFatEntries = [];
21133
+ if (firstMiniFATSector <= MAXREGSECT && totalMiniFATSectors > 0) {
21134
+ const miniFatRaw = readSectorChain(firstMiniFATSector);
21135
+ if (miniFatRaw.length !== totalMiniFATSectors * sectorSize) {
21136
+ throw new Ole2ParseError("Unexpected mini FAT chain length");
21137
+ }
21138
+ const miniFatView = new DataView(miniFatRaw.buffer, miniFatRaw.byteOffset, miniFatRaw.byteLength);
21139
+ const miniCapacity = Math.floor((miniStreamData?.length ?? 0) / miniSectorSize);
21140
+ for (let i2 = 0; i2 < miniFatRaw.length / 4 && i2 < miniCapacity; i2++) {
21141
+ miniFatEntries.push(miniFatView.getUint32(i2 * 4, true));
21142
+ }
21100
21143
  }
21101
21144
  function readMiniStream(startSector, size) {
21145
+ if (size === 0)
21146
+ return new Uint8Array(0);
21102
21147
  if (!miniStreamData) {
21103
21148
  throw new Ole2ParseError("Mini stream container not found");
21104
21149
  }
@@ -21111,17 +21156,24 @@ function parseOle2(buffer) {
21111
21156
  }
21112
21157
  visited.add(current);
21113
21158
  const offset2 = current * miniSectorSize;
21159
+ if (offset2 + miniSectorSize > miniStreamData.length || miniFatEntries[current] === void 0) {
21160
+ throw new Ole2ParseError("Mini stream sector exceeds allocation bounds");
21161
+ }
21114
21162
  sectors.push(miniStreamData.subarray(offset2, offset2 + miniSectorSize));
21115
- current = miniFatEntries[current] ?? ENDOFCHAIN;
21163
+ current = miniFatEntries[current];
21116
21164
  }
21165
+ if (current !== ENDOFCHAIN)
21166
+ throw new Ole2ParseError("Invalid mini FAT chain terminator");
21117
21167
  const totalLength = sectors.length * miniSectorSize;
21168
+ if (totalLength < size)
21169
+ throw new Ole2ParseError("Truncated mini stream sector chain");
21118
21170
  const result = new Uint8Array(totalLength);
21119
21171
  let offset = 0;
21120
21172
  for (const sector of sectors) {
21121
21173
  result.set(sector, offset);
21122
21174
  offset += miniSectorSize;
21123
21175
  }
21124
- return result.subarray(0, Math.min(size, result.length));
21176
+ return result.subarray(0, size);
21125
21177
  }
21126
21178
  function getStream(name) {
21127
21179
  const entry = entries.find((e) => (e.type === ENTRY_TYPE_STREAM || e.type === ENTRY_TYPE_ROOT) && e.name === name);
@@ -21136,7 +21188,7 @@ function parseOle2(buffer) {
21136
21188
  return { entries, getStream };
21137
21189
  }
21138
21190
  var init_ole2_parser_read = __esm({
21139
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-read.js"() {
21191
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-read.js"() {
21140
21192
  init_ole2_parser_types();
21141
21193
  }
21142
21194
  });
@@ -21276,13 +21328,16 @@ var init_ole_embedded_extract = __esm({
21276
21328
  }
21277
21329
  });
21278
21330
 
21279
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-helpers.js
21331
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-helpers.js
21280
21332
  function compareDirEntryNames(a, b) {
21333
+ const ua = a.toUpperCase();
21334
+ const ub = b.toUpperCase();
21335
+ if (ua.length !== a.length || ub.length !== b.length) {
21336
+ throw new Error("CFB stream names with expanding uppercase mappings are unsupported");
21337
+ }
21281
21338
  if (a.length !== b.length) {
21282
21339
  return a.length - b.length;
21283
21340
  }
21284
- const ua = a.toUpperCase();
21285
- const ub = b.toUpperCase();
21286
21341
  for (let i2 = 0; i2 < ua.length; i2++) {
21287
21342
  const diff = ua.charCodeAt(i2) - ub.charCodeAt(i2);
21288
21343
  if (diff !== 0) {
@@ -21299,6 +21354,24 @@ function encodeName(name) {
21299
21354
  }
21300
21355
  return bytes;
21301
21356
  }
21357
+ function buildDirectoryTree(entryCount) {
21358
+ const links = /* @__PURE__ */ new Map();
21359
+ let redLevel = 0;
21360
+ for (let remaining = entryCount - 2; remaining >= 0; remaining = Math.floor(remaining / 2) - 1)
21361
+ redLevel++;
21362
+ const build = (low, high, level2) => {
21363
+ if (low > high)
21364
+ return 4294967295;
21365
+ const id = Math.floor((low + high) / 2);
21366
+ links.set(id, {
21367
+ left: build(low, id - 1, level2 + 1),
21368
+ right: build(id + 1, high, level2 + 1),
21369
+ color: level2 === redLevel ? 0 : 1
21370
+ });
21371
+ return id;
21372
+ };
21373
+ return { root: build(1, entryCount - 1, 0), links };
21374
+ }
21302
21375
  function writeFatChain(fat, chain2) {
21303
21376
  for (let i2 = 0; i2 < chain2.sectors.length; i2++) {
21304
21377
  fat[chain2.sectors[i2]] = i2 < chain2.sectors.length - 1 ? chain2.sectors[i2 + 1] : ENDOFCHAIN;
@@ -21322,12 +21395,12 @@ function writeInt32Sectors(outBytes, int32Data, firstSector, numSectors, sectorS
21322
21395
  }
21323
21396
  }
21324
21397
  var init_ole2_parser_write_helpers = __esm({
21325
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-helpers.js"() {
21398
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-helpers.js"() {
21326
21399
  init_ole2_parser_types();
21327
21400
  }
21328
21401
  });
21329
21402
 
21330
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-serialize.js
21403
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-serialize.js
21331
21404
  function writeHeader(outView, outBytes, params) {
21332
21405
  outBytes.set(OLE_MAGIC, 0);
21333
21406
  outView.setUint16(24, 62, true);
@@ -21384,6 +21457,7 @@ function writeDifatSectors(outView, params) {
21384
21457
  function serializeDirectoryEntries(dirEntries, numDirSectors, sectorSize) {
21385
21458
  const dirData = new Uint8Array(numDirSectors * sectorSize);
21386
21459
  const dirView = new DataView(dirData.buffer);
21460
+ const tree = buildDirectoryTree(dirEntries.length);
21387
21461
  for (let i2 = 0; i2 < dirEntries.length; i2++) {
21388
21462
  const entry = dirEntries[i2];
21389
21463
  const entryOffset = i2 * DIR_ENTRY_SIZE;
@@ -21391,17 +21465,17 @@ function serializeDirectoryEntries(dirEntries, numDirSectors, sectorSize) {
21391
21465
  dirData.set(nameBytes.subarray(0, Math.min(nameBytes.length, 64)), entryOffset);
21392
21466
  dirView.setUint16(entryOffset + 64, Math.min((entry.name.length + 1) * 2, 64), true);
21393
21467
  dirData[entryOffset + 66] = entry.type;
21394
- dirData[entryOffset + 67] = 1;
21468
+ dirData[entryOffset + 67] = i2 === 0 ? 1 : tree.links.get(i2).color;
21395
21469
  if (entry.clsid) {
21396
21470
  dirData.set(entry.clsid.subarray(0, 16), entryOffset + 80);
21397
21471
  }
21398
21472
  if (i2 === 0) {
21399
21473
  dirView.setUint32(entryOffset + 68, 4294967295, true);
21400
21474
  dirView.setUint32(entryOffset + 72, 4294967295, true);
21401
- dirView.setUint32(entryOffset + 76, dirEntries.length > 1 ? 1 : 4294967295, true);
21475
+ dirView.setUint32(entryOffset + 76, tree.root, true);
21402
21476
  } else {
21403
- dirView.setUint32(entryOffset + 68, 4294967295, true);
21404
- dirView.setUint32(entryOffset + 72, i2 + 1 < dirEntries.length ? i2 + 1 : 4294967295, true);
21477
+ dirView.setUint32(entryOffset + 68, tree.links.get(i2).left, true);
21478
+ dirView.setUint32(entryOffset + 72, tree.links.get(i2).right, true);
21405
21479
  dirView.setUint32(entryOffset + 76, 4294967295, true);
21406
21480
  }
21407
21481
  dirView.setUint32(entryOffset + 116, entry.startSector, true);
@@ -21419,17 +21493,32 @@ function writeStreamSectors(outBytes, streamData, chain2, sectorSize) {
21419
21493
  }
21420
21494
  var HEADER_DIFAT_ENTRIES;
21421
21495
  var init_ole2_parser_write_serialize = __esm({
21422
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-serialize.js"() {
21496
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-serialize.js"() {
21423
21497
  init_ole2_parser_types();
21424
21498
  init_ole2_parser_write_helpers();
21425
21499
  HEADER_DIFAT_ENTRIES = 109;
21426
21500
  }
21427
21501
  });
21428
21502
 
21429
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-write.js
21503
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-write.js
21430
21504
  function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
21431
21505
  const sectorSize = 512;
21432
21506
  const miniSectorSize = 64;
21507
+ if (rootClsid && rootClsid.length !== 16)
21508
+ throw new Error("Root CLSID must contain 16 bytes");
21509
+ const names = [...streams2.keys()].sort(compareDirEntryNames);
21510
+ for (let i2 = 0; i2 < names.length; i2++) {
21511
+ const name = names[i2];
21512
+ if (name.toUpperCase().length !== name.length) {
21513
+ throw new Error("CFB stream names with expanding uppercase mappings are unsupported");
21514
+ }
21515
+ if (!name.length || name.length > 31 || /[\x00\\/:!]/.test(name)) {
21516
+ throw new Error("CFB stream names must be 1-31 UTF-16 code units without NUL, \\, /, :, or !");
21517
+ }
21518
+ if (i2 > 0 && compareDirEntryNames(names[i2 - 1], name) === 0) {
21519
+ throw new Error("Duplicate CFB stream names");
21520
+ }
21521
+ }
21433
21522
  const regularStreams = [];
21434
21523
  const miniStreams = [];
21435
21524
  for (const [name, data] of streams2) {
@@ -21447,7 +21536,7 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
21447
21536
  for (let i2 = 0; i2 < numSectors; i2++) {
21448
21537
  sectors.push(nextSector++);
21449
21538
  }
21450
- fatChains.set(stream.name, { start: sectors[0] ?? 0, sectors });
21539
+ fatChains.set(stream.name, { start: sectors[0] ?? ENDOFCHAIN, sectors });
21451
21540
  }
21452
21541
  let miniStreamContainer = new Uint8Array(0);
21453
21542
  const miniFatChains = /* @__PURE__ */ new Map();
@@ -21470,7 +21559,7 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
21470
21559
  miniOffset += miniSectorSize;
21471
21560
  }
21472
21561
  miniFatChains.set(stream.name, {
21473
- start: miniSectors[0] ?? 0,
21562
+ start: miniSectors[0] ?? ENDOFCHAIN,
21474
21563
  sectors: miniSectors
21475
21564
  });
21476
21565
  }
@@ -21518,7 +21607,7 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
21518
21607
  nextSector += numDirSectors;
21519
21608
  let firstMiniFATSector = ENDOFCHAIN;
21520
21609
  let numMiniFATSectors = 0;
21521
- if (miniStreams.length > 0) {
21610
+ if (nextMiniSector > 0) {
21522
21611
  numMiniFATSectors = Math.ceil(nextMiniSector * 4 / sectorSize);
21523
21612
  firstMiniFATSector = nextSector;
21524
21613
  nextSector += numMiniFATSectors;
@@ -21592,7 +21681,7 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
21592
21681
  return output;
21593
21682
  }
21594
21683
  var init_ole2_parser_write = __esm({
21595
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-write.js"() {
21684
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-write.js"() {
21596
21685
  init_ole2_parser_types();
21597
21686
  init_ole2_parser_write_helpers();
21598
21687
  init_ole2_parser_write_serialize();
@@ -22308,7 +22397,7 @@ var init_ole_sheet_xlsx_editor = __esm({
22308
22397
  }
22309
22398
  });
22310
22399
 
22311
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-stream-edit.js
22400
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-edit.js
22312
22401
  function chain(table, start, limit) {
22313
22402
  if (start === END && limit === 0)
22314
22403
  return [];
@@ -22387,7 +22476,7 @@ function processCompoundFileStream(input, path, replacement) {
22387
22476
  const fat = [];
22388
22477
  for (const id of fatIds) {
22389
22478
  const bytes = sector(id), dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
22390
- for (let j = 0; j < sectorSize / 4; j++)
22479
+ for (let j = 0; j < sectorSize / 4 && fat.length < sectorCount; j++)
22391
22480
  fat.push(dv.getUint32(j * 4, true));
22392
22481
  }
22393
22482
  const exactChain = (table, start, bytes, unit) => chain(table, start, Math.ceil(bytes / unit));
@@ -22484,9 +22573,10 @@ function processCompoundFileStream(input, path, replacement) {
22484
22573
  if (new Set(metadataSectors).size !== metadataSectors.length)
22485
22574
  return reject();
22486
22575
  const miniFat = [];
22576
+ const miniCapacity = Math.floor(Math.min(root.size, sectorCount * sectorSize) / miniSize);
22487
22577
  for (const id of miniFatSectors) {
22488
22578
  const bytes = sector(id), dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
22489
- for (let j = 0; j < sectorSize / 4; j++)
22579
+ for (let j = 0; j < sectorSize / 4 && miniFat.length < miniCapacity; j++)
22490
22580
  miniFat.push(dv.getUint32(j * 4, true));
22491
22581
  }
22492
22582
  const reserved = /* @__PURE__ */ new Set([...fatIds, ...difatIds, ...dirSectors, ...miniFatSectors]);
@@ -22510,7 +22600,7 @@ function processCompoundFileStream(input, path, replacement) {
22510
22600
  continue;
22511
22601
  const ids = exactChain(miniFat, entry.start, entry.size, miniSize);
22512
22602
  for (const id of ids) {
22513
- if (id * miniSize >= rootMini.size || miniUsed.has(id))
22603
+ if ((id + 1) * miniSize > rootMini.size || miniUsed.has(id))
22514
22604
  return reject();
22515
22605
  miniUsed.add(id);
22516
22606
  }
@@ -22535,6 +22625,8 @@ function processCompoundFileStream(input, path, replacement) {
22535
22625
  });
22536
22626
  return result.slice(0, target.size);
22537
22627
  }
22628
+ if (replacement.length === 0)
22629
+ return input.slice();
22538
22630
  const output = input.slice();
22539
22631
  if (target.size >= miniCutoff) {
22540
22632
  const sectors = exactChain(fat, target.start, target.size, sectorSize);
@@ -22575,7 +22667,7 @@ function replaceCompoundFileStream(input, path, replacement) {
22575
22667
  }
22576
22668
  var END, MAX, NIL, SIZE;
22577
22669
  var init_ole2_stream_edit = __esm({
22578
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-stream-edit.js"() {
22670
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-edit.js"() {
22579
22671
  END = 4294967294;
22580
22672
  MAX = 4294967290;
22581
22673
  NIL = 4294967295;
@@ -22583,7 +22675,7 @@ var init_ole2_stream_edit = __esm({
22583
22675
  }
22584
22676
  });
22585
22677
 
22586
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-cfb.js
22678
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-cfb.js
22587
22679
  function unwrapXlsBytes(bytes) {
22588
22680
  if (!isCfb(bytes)) {
22589
22681
  return { workbookBytes: bytes };
@@ -22650,7 +22742,7 @@ function isCfb(bytes) {
22650
22742
  }
22651
22743
  var WORKBOOK_STREAM_NAMES;
22652
22744
  var init_legacy_excel_cfb = __esm({
22653
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-cfb.js"() {
22745
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-cfb.js"() {
22654
22746
  init_ole2_parser_read();
22655
22747
  init_ole2_parser_types();
22656
22748
  init_ole2_parser_write();
@@ -22659,7 +22751,178 @@ var init_legacy_excel_cfb = __esm({
22659
22751
  }
22660
22752
  });
22661
22753
 
22662
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8.js
22754
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-edit.js
22755
+ function encodeRkExact(value) {
22756
+ if (!Number.isFinite(value))
22757
+ return void 0;
22758
+ for (const scale of [1, 100]) {
22759
+ const scaled = value * scale;
22760
+ if (Number.isInteger(scaled) && scaled >= -536870912 && scaled < 536870912) {
22761
+ const rk2 = (scaled << 2 | 2 | (scale === 100 ? 1 : 0)) >>> 0;
22762
+ if (Object.is(decodeRk(rk2), value))
22763
+ return rk2;
22764
+ }
22765
+ const view = new DataView(new ArrayBuffer(8));
22766
+ view.setFloat64(0, scaled, true);
22767
+ const rk = (view.getUint32(4, true) & 4294967292 | (scale === 100 ? 1 : 0)) >>> 0;
22768
+ if (Object.is(decodeRk(rk), value))
22769
+ return rk;
22770
+ }
22771
+ return void 0;
22772
+ }
22773
+ function worksheetRanges(bytes) {
22774
+ const records = readRecords(bytes, 0, bytes.length);
22775
+ const last = records.at(-1);
22776
+ if (!last || bytes.subarray(last.dataOffset + last.length).some((b) => b !== 0))
22777
+ return void 0;
22778
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
22779
+ const ranges = [];
22780
+ let depth = 0;
22781
+ let start;
22782
+ for (const record2 of records) {
22783
+ if (record2.opcode === 2057) {
22784
+ if (record2.length < 4 || view.getUint16(record2.dataOffset, true) !== 1536 || depth >= 64)
22785
+ return void 0;
22786
+ if (depth === 0 && view.getUint16(record2.dataOffset + 2, true) === 16)
22787
+ start = record2.headerOffset;
22788
+ depth++;
22789
+ } else if (record2.opcode === 10) {
22790
+ if (depth === 0 || record2.length !== 0)
22791
+ return void 0;
22792
+ depth--;
22793
+ if (depth === 0 && start !== void 0) {
22794
+ ranges.push({ start, end: record2.dataOffset });
22795
+ start = void 0;
22796
+ }
22797
+ }
22798
+ }
22799
+ if (depth !== 0)
22800
+ return void 0;
22801
+ const globalsEnd = records.find((r) => r.opcode === 10)?.headerOffset ?? 0;
22802
+ const bounds = records.filter((r) => r.opcode === 133 && r.headerOffset < globalsEnd);
22803
+ if (bounds.length === 0)
22804
+ return ranges;
22805
+ const ordered4 = [];
22806
+ const used = /* @__PURE__ */ new Set();
22807
+ for (const bound of bounds) {
22808
+ if (bound.length < 8)
22809
+ return void 0;
22810
+ const p = bound.dataOffset;
22811
+ const nameLength = view.getUint8(p + 6);
22812
+ const width = view.getUint8(p + 7) & 1 ? 2 : 1;
22813
+ if (nameLength < 1 || nameLength > 31 || bound.length !== 8 + nameLength * width)
22814
+ return void 0;
22815
+ const kind = view.getUint8(p + 5);
22816
+ if (![0, 1, 2, 6].includes(kind))
22817
+ return void 0;
22818
+ if (kind !== 0)
22819
+ continue;
22820
+ const offset = view.getUint32(p, true);
22821
+ const range = ranges.find((r) => r.start === offset);
22822
+ if (!range || used.has(offset))
22823
+ return void 0;
22824
+ used.add(offset);
22825
+ ordered4.push(range);
22826
+ }
22827
+ return ordered4.length === ranges.length ? ordered4 : void 0;
22828
+ }
22829
+ function editXlsNumericCell(input, edit) {
22830
+ const unchanged2 = (reason) => ({ status: "unchanged", bytes: input, reason });
22831
+ const sheet = edit.worksheetIndex ?? 0;
22832
+ if (!Number.isInteger(edit.row) || edit.row < 0 || edit.row > 65535 || !Number.isInteger(edit.col) || edit.col < 0 || edit.col > 255 || !Number.isInteger(sheet) || sheet < 0 || !Number.isFinite(edit.value))
22833
+ return unchanged2("invalid-edit");
22834
+ try {
22835
+ const { workbookBytes: bytes, rewrap } = unwrapXlsBytes(input);
22836
+ if (!isSupportedBiff8Workbook(bytes))
22837
+ return unchanged2("unsupported-workbook");
22838
+ const ranges = worksheetRanges(bytes);
22839
+ if (!ranges)
22840
+ return unchanged2("malformed-records");
22841
+ const range = ranges[sheet];
22842
+ if (!range)
22843
+ return unchanged2("sheet-not-found");
22844
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
22845
+ let payload;
22846
+ let packed = false;
22847
+ let depth = 0;
22848
+ let matches = 0;
22849
+ for (const record2 of readRecords(bytes, range.start, range.end)) {
22850
+ if (record2.opcode === 2057) {
22851
+ depth++;
22852
+ continue;
22853
+ }
22854
+ if (record2.opcode === 10) {
22855
+ depth--;
22856
+ continue;
22857
+ }
22858
+ if (depth !== 1)
22859
+ continue;
22860
+ const p = record2.dataOffset;
22861
+ if (record2.opcode === 189) {
22862
+ if (record2.length < 12 || (record2.length - 6) % 6 !== 0)
22863
+ return unchanged2("malformed-records");
22864
+ const first = view.getUint16(p + 2, true);
22865
+ const lastCol = view.getUint16(p + record2.length - 2, true);
22866
+ if (lastCol > 255 || lastCol < first || lastCol - first + 1 !== (record2.length - 6) / 6)
22867
+ return unchanged2("malformed-records");
22868
+ if (view.getUint16(p, true) === edit.row && edit.col >= first && edit.col <= lastCol) {
22869
+ if (++matches > 1)
22870
+ return unchanged2("ambiguous-cell");
22871
+ payload = p + 6 + (edit.col - first) * 6;
22872
+ packed = true;
22873
+ }
22874
+ } else if (record2.opcode === 515 || record2.opcode === 638) {
22875
+ if (record2.length !== (record2.opcode === 515 ? 14 : 10))
22876
+ return unchanged2("malformed-records");
22877
+ if (view.getUint16(p, true) === edit.row && view.getUint16(p + 2, true) === edit.col) {
22878
+ if (++matches > 1)
22879
+ return unchanged2("ambiguous-cell");
22880
+ payload = p + 6;
22881
+ packed = record2.opcode === 638;
22882
+ }
22883
+ } else if ([6, 513, 516, 517, 253, 214].includes(record2.opcode)) {
22884
+ if (record2.length < 6)
22885
+ return unchanged2("malformed-records");
22886
+ if (view.getUint16(p, true) === edit.row && view.getUint16(p + 2, true) === edit.col && ++matches > 1)
22887
+ return unchanged2("ambiguous-cell");
22888
+ } else if (record2.opcode === 190) {
22889
+ if (record2.length < 8 || (record2.length - 6) % 2 !== 0)
22890
+ return unchanged2("malformed-records");
22891
+ const first = view.getUint16(p + 2, true);
22892
+ const lastCol = view.getUint16(p + record2.length - 2, true);
22893
+ if (lastCol > 255 || lastCol < first || lastCol - first + 1 !== (record2.length - 6) / 2)
22894
+ return unchanged2("malformed-records");
22895
+ if (view.getUint16(p, true) === edit.row && edit.col >= first && edit.col <= lastCol && ++matches > 1)
22896
+ return unchanged2("ambiguous-cell");
22897
+ }
22898
+ }
22899
+ if (payload === void 0)
22900
+ return unchanged2("cell-not-supported");
22901
+ const rk = packed ? encodeRkExact(edit.value) : void 0;
22902
+ if (packed && rk === void 0)
22903
+ return unchanged2("inexact-rk");
22904
+ const out = bytes.slice();
22905
+ const outView = new DataView(out.buffer, out.byteOffset, out.byteLength);
22906
+ if (packed)
22907
+ outView.setUint32(payload, rk, true);
22908
+ else
22909
+ outView.setFloat64(payload, edit.value, true);
22910
+ const result = rewrap ? rewrap(out) : out;
22911
+ if (result === input)
22912
+ return unchanged2("container-not-writable");
22913
+ return { status: "edited", bytes: result, recalculationRequired: true };
22914
+ } catch {
22915
+ return unchanged2("malformed-records");
22916
+ }
22917
+ }
22918
+ var init_legacy_excel_biff8_edit = __esm({
22919
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-edit.js"() {
22920
+ init_legacy_excel_biff8();
22921
+ init_legacy_excel_cfb();
22922
+ }
22923
+ });
22924
+
22925
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8.js
22663
22926
  function readRecords(bytes, start, end) {
22664
22927
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
22665
22928
  const records = [];
@@ -22713,7 +22976,7 @@ function findFirstWorksheetRange(bytes) {
22713
22976
  function parseSstSingleRecord(bytes) {
22714
22977
  const records = readRecords(bytes, 0, bytes.length);
22715
22978
  const sst = records.find((r) => r.opcode === OPCODE_SST);
22716
- if (!sst) {
22979
+ if (!sst || sst.length < 8) {
22717
22980
  return [];
22718
22981
  }
22719
22982
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
@@ -22721,7 +22984,8 @@ function parseSstSingleRecord(bytes) {
22721
22984
  let offset = sst.dataOffset + 8;
22722
22985
  const end = sst.dataOffset + sst.length;
22723
22986
  try {
22724
- while (offset + 3 <= end) {
22987
+ const unique = view.getUint32(sst.dataOffset + 4, true);
22988
+ while (strings2.length < unique && offset + 3 <= end) {
22725
22989
  const charCount = view.getUint16(offset, true);
22726
22990
  const flags = view.getUint8(offset + 2);
22727
22991
  offset += 3;
@@ -22731,13 +22995,19 @@ function parseSstSingleRecord(bytes) {
22731
22995
  let richRuns = 0;
22732
22996
  let extLen = 0;
22733
22997
  if (isRich) {
22998
+ if (offset + 2 > end)
22999
+ break;
22734
23000
  richRuns = view.getUint16(offset, true);
22735
23001
  offset += 2;
22736
23002
  }
22737
23003
  if (hasExt) {
23004
+ if (offset + 4 > end)
23005
+ break;
22738
23006
  extLen = view.getUint32(offset, true);
22739
23007
  offset += 4;
22740
23008
  }
23009
+ if (offset + charCount * (isWide ? 2 : 1) + richRuns * 4 + extLen > end)
23010
+ break;
22741
23011
  let text2 = "";
22742
23012
  for (let i2 = 0; i2 < charCount; i2++) {
22743
23013
  if (isWide) {
@@ -22818,52 +23088,13 @@ function decodeRk(rk) {
22818
23088
  }
22819
23089
  return isDiv100 ? value / 100 : value;
22820
23090
  }
22821
- function encodeRk(value) {
22822
- if (Number.isInteger(value) && Math.abs(value) < 536870912) {
22823
- return (value << 2 | 2) >>> 0;
22824
- }
22825
- const buffer = new ArrayBuffer(8);
22826
- const view = new DataView(buffer);
22827
- view.setFloat64(0, value, false);
22828
- const high32 = view.getUint32(0, false);
22829
- return high32 & 4294967292;
22830
- }
22831
23091
  function writeOleXlsNumericCellEdit(inputBytes, edit) {
22832
- if (!Number.isFinite(edit.value)) {
22833
- return inputBytes;
22834
- }
22835
- const { workbookBytes: xlsBytes, rewrap } = unwrapXlsBytes(inputBytes);
22836
- if (!isSupportedBiff8Workbook(xlsBytes))
22837
- return inputBytes;
22838
- const range = findFirstWorksheetRange(xlsBytes);
22839
- if (!range) {
22840
- return inputBytes;
22841
- }
22842
- const out = new Uint8Array(xlsBytes);
22843
- const view = new DataView(out.buffer, out.byteOffset, out.byteLength);
22844
- for (const record2 of readRecords(out, range.start, range.end)) {
22845
- if (record2.length < 6) {
22846
- continue;
22847
- }
22848
- const row = view.getUint16(record2.dataOffset, true);
22849
- const col = view.getUint16(record2.dataOffset + 2, true);
22850
- if (row !== edit.row || col !== edit.col) {
22851
- continue;
22852
- }
22853
- if (record2.opcode === OPCODE_NUMBER && record2.length >= 14) {
22854
- view.setFloat64(record2.dataOffset + 6, edit.value, true);
22855
- return rewrap ? rewrap(out) : out;
22856
- }
22857
- if (record2.opcode === OPCODE_RK && record2.length >= 10) {
22858
- view.setInt32(record2.dataOffset + 6, encodeRk(edit.value), true);
22859
- return rewrap ? rewrap(out) : out;
22860
- }
22861
- }
22862
- return inputBytes;
23092
+ return editXlsNumericCell(inputBytes, edit).bytes;
22863
23093
  }
22864
23094
  var OPCODE_BOF, OPCODE_EOF, OPCODE_FILEPASS, OPCODE_NUMBER, OPCODE_RK, OPCODE_LABELSST, OPCODE_LABEL, OPCODE_SST, OPCODE_EXTSST, OPCODE_ROW, OPCODE_DBCELL, OPCODE_DIMENSIONS, OPCODE_BLANK, OPCODE_BOUNDSHEET, WORKSHEET_DT, DEFAULT_MAX_ROWS2, DEFAULT_MAX_COLS2;
22865
23095
  var init_legacy_excel_biff8 = __esm({
22866
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8.js"() {
23096
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8.js"() {
23097
+ init_legacy_excel_biff8_edit();
22867
23098
  init_legacy_excel_cfb();
22868
23099
  OPCODE_BOF = 2057;
22869
23100
  OPCODE_EOF = 10;
@@ -22892,7 +23123,7 @@ var init_ole_sheet_xls_biff8 = __esm({
22892
23123
  }
22893
23124
  });
22894
23125
 
22895
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-grid.js
23126
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-grid.js
22896
23127
  function biffRecord(opcode, data) {
22897
23128
  return [
22898
23129
  opcode & 255,
@@ -22965,7 +23196,7 @@ function buildXlsRowCellRegion(grid) {
22965
23196
  const colFirst = cols[0] ?? 0;
22966
23197
  const colLast = cols.length > 0 ? cols[cols.length - 1] + 1 : 0;
22967
23198
  rowRecordOffsets.push(bytesOut.length);
22968
- const extra = row.extraRowBytes ?? [255, 0, 0, 0, 0, 1, 15, 0];
23199
+ const extra = row.extraRowBytes ?? [255, 0, 0, 0, 0, 1, 15, 0, 0, 0];
22969
23200
  bytesOut.push(...biffRecord(OPCODE_ROW, [...u16le(r), ...u16le(colFirst), ...u16le(colLast), ...extra]));
22970
23201
  }
22971
23202
  for (const r of rows) {
@@ -23000,8 +23231,12 @@ function buildXlsRowCellRegion(grid) {
23000
23231
  if (rows.length > 0) {
23001
23232
  const dbCellOffset = bytesOut.length;
23002
23233
  const dbData = [0, 0, 0, 0];
23003
- for (const off of firstCellOffsetPerRow) {
23004
- dbData.push(...u16le(dbCellOffset - off));
23234
+ for (let i2 = 0; i2 < firstCellOffsetPerRow.length; i2++) {
23235
+ const base = i2 === 0 ? rowRecordOffsets[0] + 20 : firstCellOffsetPerRow[i2 - 1];
23236
+ const offset = firstCellOffsetPerRow[i2] - base;
23237
+ if (offset < 0 || offset > 65535)
23238
+ throw new Error("DBCELL offset exceeds UInt16");
23239
+ dbData.push(...u16le(offset));
23005
23240
  }
23006
23241
  const backToFirstRow = dbCellOffset - rowRecordOffsets[0];
23007
23242
  dbData[0] = backToFirstRow & 255;
@@ -23013,28 +23248,39 @@ function buildXlsRowCellRegion(grid) {
23013
23248
  return Uint8Array.from(bytesOut);
23014
23249
  }
23015
23250
  var init_legacy_excel_biff8_grid = __esm({
23016
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-grid.js"() {
23251
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-grid.js"() {
23017
23252
  init_legacy_excel_biff8();
23018
23253
  }
23019
23254
  });
23020
23255
 
23021
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-writer.js
23022
- function resolveSstIndex(sharedStrings, value) {
23256
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-writer.js
23257
+ function resolveSstIndex(sharedStrings, value, bytes) {
23023
23258
  const existing = sharedStrings.indexOf(value);
23024
- if (existing !== -1) {
23259
+ if (existing !== -1)
23025
23260
  return { index: existing };
23026
- }
23027
- const next = [...sharedStrings, value];
23028
- const data = [];
23029
- data.push(...u16le(next.length & 65535), 0, 0);
23030
- data.push(...u16le(next.length & 65535), 0, 0);
23031
- for (const s of next) {
23032
- data.push(...u16le(s.length), 0);
23033
- for (const ch of s) {
23034
- data.push(ch.charCodeAt(0) & 255);
23035
- }
23036
- }
23037
- return { index: next.length - 1, rebuilt: biffRecord(OPCODE_SST, data) };
23261
+ const records = readRecords(bytes, 0, bytes.length);
23262
+ const sst = records.find((r) => r.opcode === OPCODE_SST);
23263
+ if (!sst || sst.length < 8 || value.length > 32767)
23264
+ throw new Error("Unsupported SST");
23265
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
23266
+ const unique = view.getUint32(sst.dataOffset + 4, true);
23267
+ if (unique !== sharedStrings.length || records[records.indexOf(sst) + 1]?.opcode === 60)
23268
+ throw new Error("Continued or incomplete SST");
23269
+ const data = Array.from(bytes.subarray(sst.dataOffset, sst.dataOffset + sst.length));
23270
+ const wide = Array.from({ length: value.length }, (_, i2) => value.charCodeAt(i2)).some((c) => c > 255);
23271
+ data.push(...u16le(value.length), wide ? 1 : 0);
23272
+ for (let i2 = 0; i2 < value.length; i2++) {
23273
+ const c = value.charCodeAt(i2);
23274
+ data.push(c & 255);
23275
+ if (wide)
23276
+ data.push(c >> 8);
23277
+ }
23278
+ if (data.length > 8224)
23279
+ throw new Error("SST continuation required");
23280
+ const counts = new DataView(new Uint8Array(data).buffer);
23281
+ counts.setUint32(0, view.getUint32(sst.dataOffset, true) + 1, true);
23282
+ counts.setUint32(4, unique + 1, true);
23283
+ return { index: unique, rebuilt: biffRecord(OPCODE_SST, Array.from(new Uint8Array(counts.buffer))) };
23038
23284
  }
23039
23285
  function tryInPlaceStringEdit(bytes, range, edit, sstIndex) {
23040
23286
  const out = new Uint8Array(bytes);
@@ -23081,18 +23327,27 @@ function patchBoundsheetOffsets(bytes, delta2) {
23081
23327
  return out;
23082
23328
  }
23083
23329
  function writeOleXlsStringCellEdit(inputBytes, edit) {
23330
+ if (!Number.isInteger(edit.row) || edit.row < 0 || edit.row > 65535 || !Number.isInteger(edit.col) || edit.col < 0 || edit.col > 255 || edit.value.length > 32767)
23331
+ return inputBytes;
23084
23332
  try {
23085
23333
  const { workbookBytes: xlsBytes, rewrap } = unwrapXlsBytes(inputBytes);
23086
23334
  if (!isSupportedBiff8Workbook(xlsBytes))
23087
23335
  return inputBytes;
23088
- const finish2 = (result) => rewrap ? rewrap(result) : result;
23336
+ const finish2 = (result2) => {
23337
+ const records = readRecords(result2, 0, result2.length);
23338
+ const sst = records.find((r) => r.opcode === OPCODE_SST);
23339
+ if (sst && sst.length >= 8) {
23340
+ new DataView(result2.buffer, result2.byteOffset, result2.byteLength).setUint32(sst.dataOffset, records.filter((r) => r.opcode === OPCODE_LABELSST).length, true);
23341
+ }
23342
+ return rewrap ? rewrap(result2) : result2;
23343
+ };
23089
23344
  const ranges = findAllWorksheetRanges(xlsBytes);
23090
23345
  const target = ranges[0];
23091
23346
  if (!target) {
23092
23347
  return inputBytes;
23093
23348
  }
23094
23349
  const sharedStrings = parseSstSingleRecord(xlsBytes);
23095
- const { index: sstIndex, rebuilt: newSstRecord } = resolveSstIndex(sharedStrings, edit.value);
23350
+ const { index: sstIndex, rebuilt: newSstRecord } = resolveSstIndex(sharedStrings, edit.value, xlsBytes);
23096
23351
  if (!newSstRecord) {
23097
23352
  const inPlace = tryInPlaceStringEdit(xlsBytes, target, edit, sstIndex);
23098
23353
  if (inPlace) {
@@ -23105,10 +23360,22 @@ function writeOleXlsStringCellEdit(inputBytes, edit) {
23105
23360
  const allRecords = readRecords(xlsBytes, 0, xlsBytes.length);
23106
23361
  const sstRecord = allRecords.find((r) => r.opcode === OPCODE_SST);
23107
23362
  const extSstRecord = allRecords.find((r) => r.opcode === OPCODE_EXTSST);
23363
+ if (allRecords.filter((r) => r.opcode === OPCODE_BOUNDSHEET).length > 1)
23364
+ return inputBytes;
23365
+ if (sstRecord && extSstRecord && extSstRecord.headerOffset !== sstRecord.dataOffset + sstRecord.length)
23366
+ return inputBytes;
23108
23367
  if (!sstRecord) {
23109
23368
  return inputBytes;
23110
23369
  }
23370
+ const region = findRowCellRegion(xlsBytes, target);
23371
+ const sheetRecords = readRecords(xlsBytes, target.start, target.end);
23372
+ if (sheetRecords.some((r) => [523, 6, 517, 189, 190, OPCODE_LABEL, 214].includes(r.opcode)) || sheetRecords.filter((r) => r.opcode === 2057).length !== 1)
23373
+ return inputBytes;
23374
+ if (readRecords(xlsBytes, region.start, region.end).some((r) => !(r.opcode === OPCODE_ROW || r.opcode === OPCODE_DBCELL || r.opcode === OPCODE_NUMBER || r.opcode === OPCODE_RK || r.opcode === OPCODE_LABELSST || r.opcode === OPCODE_BLANK)))
23375
+ return inputBytes;
23111
23376
  const grid = parseXlsGrid(xlsBytes, target);
23377
+ if ((/* @__PURE__ */ new Set([...grid.keys(), edit.row])).size > 32)
23378
+ return inputBytes;
23112
23379
  const row = grid.get(edit.row) ?? { cells: /* @__PURE__ */ new Map() };
23113
23380
  row.cells.set(edit.col, {
23114
23381
  ixfe: row.cells.get(edit.col)?.ixfe ?? 15,
@@ -23117,8 +23384,7 @@ function writeOleXlsStringCellEdit(inputBytes, edit) {
23117
23384
  });
23118
23385
  grid.set(edit.row, row);
23119
23386
  const newRegion = buildXlsRowCellRegion(grid);
23120
- const region = findRowCellRegion(xlsBytes, target);
23121
- const sstEnd = extSstRecord ? extSstRecord.dataOffset + extSstRecord.length : sstRecord.dataOffset + sstRecord.length;
23387
+ const sstEnd = extSstRecord && extSstRecord.headerOffset === sstRecord.dataOffset + sstRecord.length ? extSstRecord.dataOffset + extSstRecord.length : sstRecord.dataOffset + sstRecord.length;
23122
23388
  const oldSstSpanLength = sstEnd - sstRecord.headerOffset;
23123
23389
  const newSstSpanLength = newSstRecord ? newSstRecord.length : oldSstSpanLength;
23124
23390
  const patchedXlsBytes = patchBoundsheetOffsets(xlsBytes, newSstSpanLength - oldSstSpanLength);
@@ -23130,13 +23396,26 @@ function writeOleXlsStringCellEdit(inputBytes, edit) {
23130
23396
  ...newRegion,
23131
23397
  ...patchedXlsBytes.subarray(region.end)
23132
23398
  ];
23133
- return finish2(Uint8Array.from(out));
23399
+ const result = Uint8Array.from(out);
23400
+ const dimensions = readRecords(result, 0, result.length).find((r) => r.opcode === OPCODE_DIMENSIONS);
23401
+ if (dimensions) {
23402
+ if (dimensions.length !== 14)
23403
+ return inputBytes;
23404
+ const view = new DataView(result.buffer);
23405
+ const rows = [...grid.keys()];
23406
+ const cols = [...grid.values()].flatMap((row2) => [...row2.cells.keys()]);
23407
+ view.setUint32(dimensions.dataOffset, Math.min(...rows), true);
23408
+ view.setUint32(dimensions.dataOffset + 4, Math.max(...rows) + 1, true);
23409
+ view.setUint16(dimensions.dataOffset + 8, Math.min(...cols), true);
23410
+ view.setUint16(dimensions.dataOffset + 10, Math.max(...cols) + 1, true);
23411
+ }
23412
+ return finish2(result);
23134
23413
  } catch {
23135
23414
  return inputBytes;
23136
23415
  }
23137
23416
  }
23138
23417
  var init_legacy_excel_biff8_writer = __esm({
23139
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-writer.js"() {
23418
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-writer.js"() {
23140
23419
  init_legacy_excel_biff8();
23141
23420
  init_legacy_excel_biff8_grid();
23142
23421
  init_legacy_excel_cfb();
@@ -23242,15 +23521,20 @@ var init_ole_document_docx_editor = __esm({
23242
23521
  }
23243
23522
  });
23244
23523
 
23245
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fib.js
23524
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fib.js
23246
23525
  function readDocFib(wordDoc) {
23247
23526
  const view = new DataView(wordDoc.buffer, wordDoc.byteOffset, wordDoc.byteLength);
23248
23527
  const wIdent = view.getUint16(0, true);
23249
23528
  if (wIdent !== 42476) {
23250
23529
  throw new Error("Not a WordDocument FIB (bad wIdent)");
23251
23530
  }
23531
+ const nFibBase = view.getUint16(2, true);
23532
+ if (![193, 217, 257, 268, 274].includes(nFibBase))
23533
+ throw new Error("Unsupported Word FIB version");
23252
23534
  const flags1Offset = 10;
23253
23535
  const flags1 = view.getUint16(flags1Offset, true);
23536
+ if ((flags1 & 33024) !== 0)
23537
+ throw new Error("Encrypted or obfuscated Word document");
23254
23538
  const fWhichTblStm = flags1 >> 9 & 1;
23255
23539
  const csw = view.getUint16(32, true);
23256
23540
  const fibRgW97Offset = 34;
@@ -23259,6 +23543,21 @@ function readDocFib(wordDoc) {
23259
23543
  const fibRgLw97Offset = cslwOffset + 2;
23260
23544
  const cbRgFcLcbCountOffset = fibRgLw97Offset + cslw * 4;
23261
23545
  const fibRgFcLcbOffset = cbRgFcLcbCountOffset + 2;
23546
+ const fibRgFcLcbCount = view.getUint16(cbRgFcLcbCountOffset, true);
23547
+ if (csw !== 14 || cslw !== 22 || fibRgFcLcbOffset + fibRgFcLcbCount * 8 + 2 > wordDoc.length)
23548
+ throw new Error("Truncated Word FIB arrays");
23549
+ const cswNewOffset = fibRgFcLcbOffset + fibRgFcLcbCount * 8;
23550
+ const cswNew = view.getUint16(cswNewOffset, true);
23551
+ if (cswNewOffset + 2 + cswNew * 2 > wordDoc.length)
23552
+ throw new Error("Truncated Word FIB extension");
23553
+ const nFib = cswNew === 0 ? nFibBase : view.getUint16(cswNewOffset + 2, true);
23554
+ const expectedCounts = /* @__PURE__ */ new Map([[193, 93], [217, 108], [257, 136], [268, 164], [274, 183]]);
23555
+ if (expectedCounts.get(nFib) !== fibRgFcLcbCount || cswNew !== 0 && cswNew !== (nFib === 274 ? 5 : 2))
23556
+ throw new Error("Word FIB version and array counts disagree");
23557
+ const ccpText = view.getInt32(fibRgLw97Offset + 12, true);
23558
+ const otherStories = [4, 5, 7, 8, 9, 10].map((i2) => view.getInt32(fibRgLw97Offset + i2 * 4, true));
23559
+ if (ccpText < 0 || otherStories.some((cp) => cp < 0))
23560
+ throw new Error("Negative Word story length");
23262
23561
  function fcLcbPair(index) {
23263
23562
  const off = fibRgFcLcbOffset + index * 8;
23264
23563
  return { fc: view.getUint32(off, true), lcb: view.getUint32(off + 4, true) };
@@ -23266,18 +23565,22 @@ function readDocFib(wordDoc) {
23266
23565
  const cbMacOffset = fibRgLw97Offset + 0;
23267
23566
  const ccpTextOffset = fibRgLw97Offset + 12;
23268
23567
  return {
23568
+ nFib,
23569
+ nFibBase,
23269
23570
  flags1Offset,
23270
23571
  flags1,
23271
23572
  tableStreamName: fWhichTblStm ? "1Table" : "0Table",
23272
23573
  cbMacOffset,
23273
23574
  cbMac: view.getUint32(cbMacOffset, true),
23274
23575
  ccpTextOffset,
23275
- ccpText: view.getInt32(ccpTextOffset, true),
23576
+ ccpText,
23577
+ ccpOtherStories: otherStories.reduce((sum, cp) => sum + cp, 0),
23276
23578
  plcfbteChpx: fcLcbPair(FC_LCB_INDEX.plcfbteChpx),
23277
23579
  plcfbtePapx: fcLcbPair(FC_LCB_INDEX.plcfbtePapx),
23278
23580
  sed: fcLcbPair(FC_LCB_INDEX.sed),
23279
23581
  clx: fcLcbPair(FC_LCB_INDEX.clx),
23280
- fibRgFcLcbOffset
23582
+ fibRgFcLcbOffset,
23583
+ fibRgFcLcbCount
23281
23584
  };
23282
23585
  }
23283
23586
  function fcLcbFieldOffset(fib, key2) {
@@ -23285,6 +23588,9 @@ function fcLcbFieldOffset(fib, key2) {
23285
23588
  }
23286
23589
  function readFcLcbAt(wordDoc, fib, index) {
23287
23590
  const view = new DataView(wordDoc.buffer, wordDoc.byteOffset, wordDoc.byteLength);
23591
+ const count = view.getUint16(fib.fibRgFcLcbOffset - 2, true);
23592
+ if (!Number.isInteger(index) || index < 0 || index >= count || fib.fibRgFcLcbCount !== void 0 && fib.fibRgFcLcbCount !== count)
23593
+ throw new Error("FIB fc/lcb index outside declared array");
23288
23594
  const off = fib.fibRgFcLcbOffset + index * 8;
23289
23595
  return { fc: view.getUint32(off, true), lcb: view.getUint32(off + 4, true) };
23290
23596
  }
@@ -23305,7 +23611,7 @@ function patchDocFib(wordDoc, fib, patch) {
23305
23611
  }
23306
23612
  var FC_LCB_INDEX, F_COMPLEX_BIT;
23307
23613
  var init_ole_document_doc_fib = __esm({
23308
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fib.js"() {
23614
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fib.js"() {
23309
23615
  FC_LCB_INDEX = {
23310
23616
  plcfbteChpx: 12,
23311
23617
  plcfbtePapx: 13,
@@ -23316,62 +23622,578 @@ var init_ole_document_doc_fib = __esm({
23316
23622
  }
23317
23623
  });
23318
23624
 
23319
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cfb.js
23625
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-v4.js
23626
+ function follow(table, start) {
23627
+ const ids = [], seen = /* @__PURE__ */ new Set();
23628
+ for (let id = start; id !== END2; id = table[id]) {
23629
+ if (id >= table.length || seen.has(id))
23630
+ throw new Error("Invalid allocation chain");
23631
+ seen.add(id);
23632
+ ids.push(id);
23633
+ }
23634
+ return ids;
23635
+ }
23636
+ function findSlot(slots, path) {
23637
+ let parent = slots.get(0);
23638
+ if (!parent || parent.type !== 5)
23639
+ throw new Error("Invalid root");
23640
+ const parents = /* @__PURE__ */ new Set();
23641
+ for (let part = 0; part < path.length; part++) {
23642
+ if (parents.has(parent.id))
23643
+ throw new Error("Cyclic storage hierarchy");
23644
+ parents.add(parent.id);
23645
+ const stack = [parent.child], seen = /* @__PURE__ */ new Set(), matches = [];
23646
+ while (stack.length) {
23647
+ const id = stack.pop();
23648
+ if (id === FREE)
23649
+ continue;
23650
+ if (seen.has(id))
23651
+ throw new Error("Invalid directory tree");
23652
+ seen.add(id);
23653
+ const slot = slots.get(id);
23654
+ if (!slot)
23655
+ throw new Error("Missing directory slot");
23656
+ if (slot.name.toLocaleLowerCase() === path[part].toLocaleLowerCase())
23657
+ matches.push(slot);
23658
+ stack.push(slot.left, slot.right);
23659
+ }
23660
+ if (matches.length !== 1)
23661
+ throw new Error("Missing or ambiguous stream");
23662
+ parent = matches[0];
23663
+ if (parent.type !== (part === path.length - 1 ? 2 : 1))
23664
+ throw new Error("Invalid storage path");
23665
+ }
23666
+ return parent;
23667
+ }
23668
+ function validateHierarchy(slots) {
23669
+ const owners = /* @__PURE__ */ new Set(), storages = [0];
23670
+ while (storages.length) {
23671
+ const storage = slots.get(storages.pop());
23672
+ const stack = [storage.child], names = /* @__PURE__ */ new Set();
23673
+ while (stack.length) {
23674
+ const id = stack.pop();
23675
+ if (id === FREE)
23676
+ continue;
23677
+ const slot = slots.get(id);
23678
+ if (!slot || slot.type !== 1 && slot.type !== 2 || owners.has(id))
23679
+ throw new Error("Ambiguous directory ownership");
23680
+ const name = slot.name.toLocaleLowerCase();
23681
+ if (names.has(name))
23682
+ throw new Error("Duplicate sibling name");
23683
+ names.add(name);
23684
+ owners.add(id);
23685
+ stack.push(slot.left, slot.right);
23686
+ if (slot.type === 1)
23687
+ storages.push(id);
23688
+ }
23689
+ }
23690
+ if (owners.size !== slots.size - 1)
23691
+ throw new Error("Unreachable directory entries");
23692
+ }
23693
+ function resizeCompoundFileStreamV4(input, path, replacement) {
23694
+ const fail2 = (reason) => ({ ok: false, bytes: input, reason });
23695
+ try {
23696
+ if (input.length < 512 || !path.length || path.some((part) => !part))
23697
+ return fail2("invalid-or-missing-stream");
23698
+ const view = new DataView(input.buffer, input.byteOffset, input.byteLength);
23699
+ const read = (offset) => view.getUint32(offset, true);
23700
+ const version = view.getUint16(26, true);
23701
+ if (version !== 4)
23702
+ return fail2("unsupported-version");
23703
+ const SECTOR3 = 4096, FAT_ENTRIES2 = SECTOR3 / 4, DIRECTORY_ENTRIES = SECTOR3 / 128;
23704
+ if (read(72) !== 0 || read(44) > 109)
23705
+ return fail2("unsupported-difat");
23706
+ const cutoff = read(56);
23707
+ if (cutoff !== 0 && cutoff !== 4096)
23708
+ return fail2("unsupported-layout");
23709
+ const original = readCompoundFileStream(input, path);
23710
+ if (!original)
23711
+ return fail2("invalid-or-missing-stream");
23712
+ const name = path[path.length - 1].toLocaleLowerCase();
23713
+ if (name === "worddocument" && original.length >= 12 && (original[10] | original[11] << 8) & 33024)
23714
+ return fail2("unsafe-edit");
23715
+ if (name === "book" || name === "workbook") {
23716
+ for (let offset = 0; offset + 4 <= original.length; ) {
23717
+ const record2 = original[offset] | original[offset + 1] << 8;
23718
+ const length = original[offset + 2] | original[offset + 3] << 8;
23719
+ if (record2 === 47)
23720
+ return fail2("unsafe-edit");
23721
+ if (record2 === 10 || offset + 4 + length > original.length)
23722
+ break;
23723
+ offset += 4 + length;
23724
+ }
23725
+ }
23726
+ const validated = replaceCompoundFileStream(input, path, original);
23727
+ if (validated === input)
23728
+ return fail2("unsafe-edit");
23729
+ const sameLength = replacement.length === original.length;
23730
+ if (!sameLength && original.length < cutoff)
23731
+ return fail2("unsupported-mini-stream");
23732
+ if (!sameLength && replacement.length < cutoff)
23733
+ return fail2("unsupported-mini-transition");
23734
+ const sectorCount = input.length / SECTOR3 - 1, fatCount = read(44);
23735
+ if (sectorCount > fatCount * FAT_ENTRIES2)
23736
+ return fail2("unsafe-edit");
23737
+ const fatIds = Array.from({ length: fatCount }, (_, i2) => read(76 + 4 * i2));
23738
+ const fat = [];
23739
+ for (const id of fatIds) {
23740
+ for (let i2 = 0; i2 < FAT_ENTRIES2 && fat.length < sectorCount; i2++)
23741
+ fat.push(read((id + 1) * SECTOR3 + i2 * 4));
23742
+ }
23743
+ if (fatIds.some((id) => fat[id] !== FAT))
23744
+ return fail2("unsafe-edit");
23745
+ const slots = /* @__PURE__ */ new Map();
23746
+ const directoryChain = follow(fat, read(48));
23747
+ if (read(40) !== directoryChain.length)
23748
+ return fail2("unsafe-edit");
23749
+ for (const [block, sector] of directoryChain.entries()) {
23750
+ for (let entry = 0; entry < DIRECTORY_ENTRIES; entry++) {
23751
+ const offset = (sector + 1) * SECTOR3 + entry * 128, type = view.getUint8(offset + 66);
23752
+ if (!type)
23753
+ continue;
23754
+ const nameLength = view.getUint16(offset + 64, true);
23755
+ if (![1, 2, 5].includes(type) || nameLength < 2 || nameLength > 64 || nameLength % 2 || view.getUint16(offset + nameLength - 2, true))
23756
+ return fail2("unsafe-edit");
23757
+ let name2 = "";
23758
+ for (let i2 = 0; i2 < nameLength - 2; i2 += 2)
23759
+ name2 += String.fromCharCode(view.getUint16(offset + i2, true));
23760
+ if (read(offset + 124) !== 0)
23761
+ return fail2("unsafe-edit");
23762
+ const id = block * DIRECTORY_ENTRIES + entry;
23763
+ slots.set(id, { id, name: name2, type, left: read(offset + 68), right: read(offset + 72), child: read(offset + 76), start: read(offset + 116), size: read(offset + 120), offset });
23764
+ }
23765
+ }
23766
+ if ([...slots.values()].filter((slot) => slot.type === 5).length !== 1)
23767
+ return fail2("unsafe-edit");
23768
+ const target = findSlot(slots, path);
23769
+ validateHierarchy(slots);
23770
+ if (sameLength) {
23771
+ const bytes = replaceCompoundFileStream(input, path, replacement);
23772
+ return bytes === input ? fail2("unsafe-edit") : { ok: true, bytes };
23773
+ }
23774
+ const oldChain = follow(fat, target.start);
23775
+ if (target.size !== original.length || oldChain.length !== Math.ceil(target.size / SECTOR3))
23776
+ return fail2("unsafe-edit");
23777
+ const payloadSectors = Math.ceil(replacement.length / SECTOR3);
23778
+ let newFatCount = fatCount;
23779
+ while (sectorCount + payloadSectors + newFatCount - fatCount > newFatCount * FAT_ENTRIES2)
23780
+ newFatCount++;
23781
+ if (newFatCount > 109)
23782
+ return fail2("allocation-limit");
23783
+ const totalSectors = sectorCount + payloadSectors + newFatCount - fatCount;
23784
+ const output = new Uint8Array((totalSectors + 1) * SECTOR3);
23785
+ output.set(input);
23786
+ output.set(replacement, (sectorCount + 1) * SECTOR3);
23787
+ const outView = new DataView(output.buffer);
23788
+ for (let i2 = fatCount; i2 < newFatCount; i2++) {
23789
+ const id = sectorCount + payloadSectors + i2 - fatCount;
23790
+ fatIds.push(id);
23791
+ output.fill(255, (id + 1) * SECTOR3, (id + 2) * SECTOR3);
23792
+ outView.setUint32(76 + i2 * 4, id, true);
23793
+ }
23794
+ outView.setUint32(44, newFatCount, true);
23795
+ const writeFat = (id, value) => outView.setUint32((fatIds[Math.floor(id / FAT_ENTRIES2)] + 1) * SECTOR3 + id % FAT_ENTRIES2 * 4, value, true);
23796
+ for (const id of oldChain)
23797
+ writeFat(id, FREE);
23798
+ for (let i2 = 0; i2 < payloadSectors; i2++)
23799
+ writeFat(sectorCount + i2, i2 + 1 === payloadSectors ? END2 : sectorCount + i2 + 1);
23800
+ for (const id of fatIds)
23801
+ writeFat(id, FAT);
23802
+ outView.setUint32(target.offset + 116, payloadSectors ? sectorCount : END2, true);
23803
+ outView.setUint32(target.offset + 120, replacement.length, true);
23804
+ return { ok: true, bytes: output };
23805
+ } catch {
23806
+ return fail2("unsafe-edit");
23807
+ }
23808
+ }
23809
+ var END2, FREE, FAT;
23810
+ var init_ole2_stream_resize_v4 = __esm({
23811
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-v4.js"() {
23812
+ init_ole2_stream_edit();
23813
+ END2 = 4294967294;
23814
+ FREE = 4294967295;
23815
+ FAT = 4294967293;
23816
+ }
23817
+ });
23818
+
23819
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-allocation.js
23820
+ function appendCompoundAllocations(input, existingFatIds, payloads, sectorSize = 512) {
23821
+ const sectorCount = input.length / sectorSize - 1;
23822
+ const entriesPerFat = sectorSize / 4;
23823
+ const counts = payloads.map((payload) => Math.ceil(payload.length / sectorSize));
23824
+ const payloadSectors = counts.reduce((sum, count) => sum + count, 0);
23825
+ let fatCount = existingFatIds.length;
23826
+ while (sectorCount + payloadSectors + fatCount - existingFatIds.length > fatCount * entriesPerFat)
23827
+ fatCount++;
23828
+ if (fatCount > 109)
23829
+ return void 0;
23830
+ const totalSectors = sectorCount + payloadSectors + fatCount - existingFatIds.length;
23831
+ const bytes = new Uint8Array((totalSectors + 1) * sectorSize);
23832
+ bytes.set(input);
23833
+ const view = new DataView(bytes.buffer), fatIds = [...existingFatIds];
23834
+ for (let i2 = existingFatIds.length; i2 < fatCount; i2++) {
23835
+ const id = sectorCount + payloadSectors + i2 - existingFatIds.length;
23836
+ fatIds.push(id);
23837
+ bytes.fill(255, (id + 1) * sectorSize, (id + 2) * sectorSize);
23838
+ view.setUint32(76 + i2 * 4, id, true);
23839
+ }
23840
+ view.setUint32(44, fatCount, true);
23841
+ const writeFat = (id, value) => view.setUint32((fatIds[Math.floor(id / entriesPerFat)] + 1) * sectorSize + id % entriesPerFat * 4, value, true);
23842
+ const chains = [];
23843
+ let next = sectorCount;
23844
+ for (let payload = 0; payload < payloads.length; payload++) {
23845
+ bytes.set(payloads[payload], (next + 1) * sectorSize);
23846
+ const chain2 = Array.from({ length: counts[payload] }, (_, i2) => next + i2);
23847
+ chain2.forEach((id, i2) => writeFat(id, chain2[i2 + 1] ?? 4294967294));
23848
+ chains.push(chain2);
23849
+ next += counts[payload];
23850
+ }
23851
+ for (const id of fatIds)
23852
+ writeFat(id, 4294967293);
23853
+ return { bytes, view, chains, writeFat };
23854
+ }
23855
+ function followCompoundAllocation(table, start) {
23856
+ const ids = [], seen = /* @__PURE__ */ new Set();
23857
+ for (let id = start; id !== 4294967294; id = table[id]) {
23858
+ if (id >= table.length || seen.has(id))
23859
+ throw new Error("Invalid allocation chain");
23860
+ seen.add(id);
23861
+ ids.push(id);
23862
+ }
23863
+ return ids;
23864
+ }
23865
+ var init_ole2_stream_resize_allocation = __esm({
23866
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-allocation.js"() {
23867
+ }
23868
+ });
23869
+
23870
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-mini.js
23871
+ function resizeMiniCompoundStream(input, fat, fatIds, root, target, replacement, cutoff) {
23872
+ const inputView = new DataView(input.buffer, input.byteOffset, input.byteLength);
23873
+ const miniFatCount = inputView.getUint32(64, true);
23874
+ const miniFatSectors = miniFatCount ? followCompoundAllocation(fat, inputView.getUint32(60, true)) : [];
23875
+ if (miniFatSectors.length !== miniFatCount)
23876
+ throw new Error("Invalid mini FAT count");
23877
+ const rootSectors = root.size ? followCompoundAllocation(fat, root.start) : [];
23878
+ if (rootSectors.length !== Math.ceil(root.size / SECTOR))
23879
+ throw new Error("Invalid root mini stream");
23880
+ const miniCapacity = Math.floor(root.size / MINI), miniFat = [];
23881
+ for (const id of miniFatSectors) {
23882
+ for (let slot = 0; slot < SECTOR / 4 && miniFat.length < miniCapacity; slot++)
23883
+ miniFat.push(inputView.getUint32((id + 1) * SECTOR + slot * 4, true));
23884
+ }
23885
+ const wasMini = target.size < cutoff;
23886
+ const oldChain = followCompoundAllocation(wasMini ? miniFat : fat, target.start);
23887
+ if (oldChain.length !== Math.ceil(target.size / (wasMini ? MINI : SECTOR)))
23888
+ throw new Error("Invalid stream allocation");
23889
+ if (!replacement.length) {
23890
+ const bytes = input.slice(), view = new DataView(bytes.buffer);
23891
+ for (const id of oldChain) {
23892
+ const table = wasMini ? miniFatSectors : fatIds;
23893
+ view.setUint32((table[Math.floor(id / 128)] + 1) * SECTOR + id % 128 * 4, FREE2, true);
23894
+ }
23895
+ view.setUint32(target.offset + 116, END3, true);
23896
+ view.setUint32(target.offset + 120, 0, true);
23897
+ return bytes;
23898
+ }
23899
+ if (replacement.length >= cutoff) {
23900
+ const output2 = appendCompoundAllocations(input, fatIds, [replacement]);
23901
+ if (!output2)
23902
+ return void 0;
23903
+ for (const id of oldChain)
23904
+ output2.view.setUint32((miniFatSectors[Math.floor(id / 128)] + 1) * SECTOR + id % 128 * 4, FREE2, true);
23905
+ output2.view.setUint32(target.offset + 116, output2.chains[0][0] ?? END3, true);
23906
+ output2.view.setUint32(target.offset + 120, replacement.length, true);
23907
+ return output2.bytes;
23908
+ }
23909
+ const firstMini = Math.ceil(root.size / MINI), count = Math.ceil(replacement.length / MINI);
23910
+ const newRootSize = count ? (firstMini + count) * MINI : root.size;
23911
+ const newRoot = new Uint8Array(newRootSize);
23912
+ rootSectors.forEach((id, i2) => newRoot.set(input.subarray((id + 1) * SECTOR, (id + 1) * SECTOR + Math.min(SECTOR, root.size - i2 * SECTOR)), i2 * SECTOR));
23913
+ if (count)
23914
+ newRoot.set(replacement, firstMini * MINI);
23915
+ const newMiniFatCount = Math.max(miniFatCount, Math.ceil((firstMini + count) / 128));
23916
+ const newMiniFat = new Uint8Array(newMiniFatCount * SECTOR).fill(255);
23917
+ miniFatSectors.forEach((id, i2) => newMiniFat.set(input.subarray((id + 1) * SECTOR, (id + 2) * SECTOR), i2 * SECTOR));
23918
+ const miniView = new DataView(newMiniFat.buffer);
23919
+ if (wasMini)
23920
+ for (const id of oldChain)
23921
+ miniView.setUint32(id * 4, FREE2, true);
23922
+ for (let i2 = 0; i2 < count; i2++)
23923
+ miniView.setUint32((firstMini + i2) * 4, i2 + 1 === count ? END3 : firstMini + i2 + 1, true);
23924
+ const output = appendCompoundAllocations(input, fatIds, [newRoot, newMiniFat]);
23925
+ if (!output)
23926
+ return void 0;
23927
+ for (const id of [...rootSectors, ...miniFatSectors, ...wasMini ? [] : oldChain])
23928
+ output.writeFat(id, FREE2);
23929
+ output.view.setUint32(root.offset + 116, output.chains[0][0] ?? END3, true);
23930
+ output.view.setUint32(root.offset + 120, newRootSize, true);
23931
+ output.view.setUint32(60, output.chains[1][0] ?? END3, true);
23932
+ output.view.setUint32(64, newMiniFatCount, true);
23933
+ output.view.setUint32(target.offset + 116, count ? firstMini : END3, true);
23934
+ output.view.setUint32(target.offset + 120, replacement.length, true);
23935
+ return output.bytes;
23936
+ }
23937
+ var END3, FREE2, SECTOR, MINI;
23938
+ var init_ole2_stream_resize_mini = __esm({
23939
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-mini.js"() {
23940
+ init_ole2_stream_resize_allocation();
23941
+ END3 = 4294967294;
23942
+ FREE2 = 4294967295;
23943
+ SECTOR = 512;
23944
+ MINI = 64;
23945
+ }
23946
+ });
23947
+
23948
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize.js
23949
+ function follow2(table, start) {
23950
+ const ids = [], seen = /* @__PURE__ */ new Set();
23951
+ for (let id = start; id !== END4; id = table[id]) {
23952
+ if (id >= table.length || seen.has(id))
23953
+ throw new Error("Invalid allocation chain");
23954
+ seen.add(id);
23955
+ ids.push(id);
23956
+ }
23957
+ return ids;
23958
+ }
23959
+ function findSlot2(slots, path) {
23960
+ let parent = slots.get(0);
23961
+ if (!parent || parent.type !== 5)
23962
+ throw new Error("Invalid root");
23963
+ const parents = /* @__PURE__ */ new Set();
23964
+ for (let part = 0; part < path.length; part++) {
23965
+ if (parents.has(parent.id))
23966
+ throw new Error("Cyclic storage hierarchy");
23967
+ parents.add(parent.id);
23968
+ const stack = [parent.child], seen = /* @__PURE__ */ new Set(), matches = [];
23969
+ while (stack.length) {
23970
+ const id = stack.pop();
23971
+ if (id === FREE3)
23972
+ continue;
23973
+ if (seen.has(id))
23974
+ throw new Error("Invalid directory tree");
23975
+ seen.add(id);
23976
+ const slot = slots.get(id);
23977
+ if (!slot)
23978
+ throw new Error("Missing directory slot");
23979
+ if (slot.name.toLocaleLowerCase() === path[part].toLocaleLowerCase())
23980
+ matches.push(slot);
23981
+ stack.push(slot.left, slot.right);
23982
+ }
23983
+ if (matches.length !== 1)
23984
+ throw new Error("Missing or ambiguous stream");
23985
+ parent = matches[0];
23986
+ if (parent.type !== (part === path.length - 1 ? 2 : 1))
23987
+ throw new Error("Invalid storage path");
23988
+ }
23989
+ return parent;
23990
+ }
23991
+ function validateHierarchy2(slots) {
23992
+ const owners = /* @__PURE__ */ new Set(), storages = [0];
23993
+ while (storages.length) {
23994
+ const storage = slots.get(storages.pop());
23995
+ const stack = [storage.child], names = /* @__PURE__ */ new Set();
23996
+ while (stack.length) {
23997
+ const id = stack.pop();
23998
+ if (id === FREE3)
23999
+ continue;
24000
+ const slot = slots.get(id);
24001
+ if (!slot || slot.type !== 1 && slot.type !== 2 || owners.has(id))
24002
+ throw new Error("Ambiguous directory ownership");
24003
+ const name = slot.name.toLocaleLowerCase();
24004
+ if (names.has(name))
24005
+ throw new Error("Duplicate sibling name");
24006
+ names.add(name);
24007
+ owners.add(id);
24008
+ stack.push(slot.left, slot.right);
24009
+ if (slot.type === 1)
24010
+ storages.push(id);
24011
+ }
24012
+ }
24013
+ if (owners.size !== slots.size - 1)
24014
+ throw new Error("Unreachable directory entries");
24015
+ }
24016
+ function resizeCompoundFileStream(input, path, replacement) {
24017
+ if (input.length >= 512 && new DataView(input.buffer, input.byteOffset, input.byteLength).getUint16(26, true) === 4)
24018
+ return resizeCompoundFileStreamV4(input, path, replacement);
24019
+ const fail2 = (reason) => ({ ok: false, bytes: input, reason });
24020
+ try {
24021
+ if (input.length < SECTOR2 || !path.length || path.some((part) => !part))
24022
+ return fail2("invalid-or-missing-stream");
24023
+ const view = new DataView(input.buffer, input.byteOffset, input.byteLength);
24024
+ const read = (offset) => view.getUint32(offset, true);
24025
+ if (view.getUint16(26, true) !== 3)
24026
+ return fail2("unsupported-version");
24027
+ if (read(72) !== 0 || read(44) > 109)
24028
+ return fail2("unsupported-difat");
24029
+ const cutoff = read(56);
24030
+ if (cutoff !== 0 && cutoff !== 4096)
24031
+ return fail2("unsupported-layout");
24032
+ const original = readCompoundFileStream(input, path);
24033
+ if (!original)
24034
+ return fail2("invalid-or-missing-stream");
24035
+ const name = path[path.length - 1].toLocaleLowerCase();
24036
+ if (name === "worddocument" && original.length >= 12 && (original[10] | original[11] << 8) & 33024)
24037
+ return fail2("unsafe-edit");
24038
+ if (name === "book" || name === "workbook") {
24039
+ for (let offset = 0; offset + 4 <= original.length; ) {
24040
+ const record2 = original[offset] | original[offset + 1] << 8;
24041
+ const length = original[offset + 2] | original[offset + 3] << 8;
24042
+ if (record2 === 47)
24043
+ return fail2("unsafe-edit");
24044
+ if (record2 === 10 || offset + 4 + length > original.length)
24045
+ break;
24046
+ offset += 4 + length;
24047
+ }
24048
+ }
24049
+ const validated = replaceCompoundFileStream(input, path, original);
24050
+ if (validated === input)
24051
+ return fail2("unsafe-edit");
24052
+ const sameLength = replacement.length === original.length;
24053
+ const sectorCount = input.length / SECTOR2 - 1, fatCount = read(44);
24054
+ if (sectorCount > fatCount * FAT_ENTRIES)
24055
+ return fail2("unsafe-edit");
24056
+ const fatIds = Array.from({ length: fatCount }, (_, i2) => read(76 + 4 * i2));
24057
+ const fat = [];
24058
+ for (const id of fatIds) {
24059
+ for (let i2 = 0; i2 < FAT_ENTRIES && fat.length < sectorCount; i2++)
24060
+ fat.push(read((id + 1) * SECTOR2 + i2 * 4));
24061
+ }
24062
+ if (fatIds.some((id) => fat[id] !== FAT2))
24063
+ return fail2("unsafe-edit");
24064
+ const slots = /* @__PURE__ */ new Map();
24065
+ for (const [block, sector] of follow2(fat, read(48)).entries()) {
24066
+ for (let entry = 0; entry < 4; entry++) {
24067
+ const offset = (sector + 1) * SECTOR2 + entry * 128, type = view.getUint8(offset + 66);
24068
+ if (!type)
24069
+ continue;
24070
+ const nameLength = view.getUint16(offset + 64, true);
24071
+ if (![1, 2, 5].includes(type) || nameLength < 2 || nameLength > 64 || nameLength % 2 || view.getUint16(offset + nameLength - 2, true))
24072
+ return fail2("unsafe-edit");
24073
+ let name2 = "";
24074
+ for (let i2 = 0; i2 < nameLength - 2; i2 += 2)
24075
+ name2 += String.fromCharCode(view.getUint16(offset + i2, true));
24076
+ const id = block * 4 + entry;
24077
+ slots.set(id, { id, name: name2, type, left: read(offset + 68), right: read(offset + 72), child: read(offset + 76), start: read(offset + 116), size: read(offset + 120), offset });
24078
+ }
24079
+ }
24080
+ if ([...slots.values()].filter((slot) => slot.type === 5).length !== 1)
24081
+ return fail2("unsafe-edit");
24082
+ const target = findSlot2(slots, path);
24083
+ validateHierarchy2(slots);
24084
+ if (sameLength) {
24085
+ const bytes = replaceCompoundFileStream(input, path, replacement);
24086
+ return bytes === input ? fail2("unsafe-edit") : { ok: true, bytes };
24087
+ }
24088
+ if (original.length < cutoff || replacement.length < cutoff) {
24089
+ const bytes = resizeMiniCompoundStream(input, fat, fatIds, slots.get(0), target, replacement, cutoff);
24090
+ return bytes ? { ok: true, bytes } : fail2("allocation-limit");
24091
+ }
24092
+ const oldChain = follow2(fat, target.start);
24093
+ if (target.size !== original.length || oldChain.length !== Math.ceil(target.size / SECTOR2))
24094
+ return fail2("unsafe-edit");
24095
+ const output = appendCompoundAllocations(input, fatIds, [replacement]);
24096
+ if (!output)
24097
+ return fail2("allocation-limit");
24098
+ for (const id of oldChain)
24099
+ output.writeFat(id, FREE3);
24100
+ output.view.setUint32(target.offset + 116, output.chains[0][0] ?? END4, true);
24101
+ output.view.setUint32(target.offset + 120, replacement.length, true);
24102
+ return { ok: true, bytes: output.bytes };
24103
+ } catch {
24104
+ return fail2("unsafe-edit");
24105
+ }
24106
+ }
24107
+ var END4, FREE3, FAT2, SECTOR2, FAT_ENTRIES;
24108
+ var init_ole2_stream_resize = __esm({
24109
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize.js"() {
24110
+ init_ole2_stream_edit();
24111
+ init_ole2_stream_resize_v4();
24112
+ init_ole2_stream_resize_allocation();
24113
+ init_ole2_stream_resize_mini();
24114
+ END4 = 4294967294;
24115
+ FREE3 = 4294967295;
24116
+ FAT2 = 4294967293;
24117
+ SECTOR2 = 512;
24118
+ FAT_ENTRIES = SECTOR2 / 4;
24119
+ }
24120
+ });
24121
+
24122
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cfb.js
23320
24123
  function unwrapDocBytes(bytes) {
23321
24124
  if (bytes.length < 8 || bytes[0] !== 208 || bytes[1] !== 207 || bytes[2] !== 17 || bytes[3] !== 224 || bytes[4] !== 161 || bytes[5] !== 177 || bytes[6] !== 26 || bytes[7] !== 225) {
23322
24125
  return void 0;
23323
24126
  }
23324
24127
  try {
23325
- const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
23326
- const ole = parseOle2(buffer);
23327
- const wordDocBytes = ole.getStream("WordDocument");
24128
+ const wordDocBytes = readCompoundFileStream(bytes, ["WordDocument"]);
23328
24129
  if (!wordDocBytes) {
23329
24130
  return void 0;
23330
24131
  }
23331
24132
  const fib = readDocFib(wordDocBytes);
23332
- const tableBytes = ole.getStream(fib.tableStreamName);
24133
+ const tableBytes = readCompoundFileStream(bytes, [fib.tableStreamName]);
23333
24134
  if (!tableBytes) {
23334
24135
  return void 0;
23335
24136
  }
23336
- const rootClsid = ole.entries.find((e) => e.type === ENTRY_TYPE_ROOT)?.clsid;
24137
+ const header = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
24138
+ const cutoff = header.getUint32(56, true);
24139
+ const canRewrite = header.getUint16(26, true) === 3 && header.getUint32(72, true) === 0 && header.getUint32(44, true) <= 109 && (cutoff === 0 || cutoff === 4096) && wordDocBytes.length >= cutoff && tableBytes.length >= cutoff;
23337
24140
  return {
23338
24141
  wordDocBytes,
23339
24142
  tableStreamName: fib.tableStreamName,
23340
24143
  tableBytes,
24144
+ canRewrite,
23341
24145
  rewrap: (editedWordDocBytes, editedTableBytes) => {
23342
- const streams2 = /* @__PURE__ */ new Map();
23343
- for (const entry of ole.entries) {
23344
- if (entry.type !== ENTRY_TYPE_STREAM) {
23345
- continue;
23346
- }
23347
- const data = entry.name === "WordDocument" ? editedWordDocBytes : entry.name === fib.tableStreamName ? editedTableBytes : ole.getStream(entry.name);
23348
- if (data) {
23349
- streams2.set(entry.name, data);
23350
- }
23351
- }
23352
- return new Uint8Array(buildOle2(streams2, rootClsid));
24146
+ if (editedWordDocBytes.length === wordDocBytes.length && editedTableBytes.length === tableBytes.length) {
24147
+ const patchedWord = replaceCompoundFileStream(bytes, ["WordDocument"], editedWordDocBytes);
24148
+ if (patchedWord === bytes)
24149
+ throw new DocCfbRewriteError("Cannot safely patch WordDocument");
24150
+ if (editedTableBytes.every((value, i2) => value === tableBytes[i2]))
24151
+ return patchedWord;
24152
+ const patchedTable = replaceCompoundFileStream(patchedWord, [fib.tableStreamName], editedTableBytes);
24153
+ if (patchedTable === patchedWord)
24154
+ throw new DocCfbRewriteError("Cannot safely patch DOC table stream");
24155
+ return patchedTable;
24156
+ }
24157
+ const word = resizeCompoundFileStream(bytes, ["WordDocument"], editedWordDocBytes);
24158
+ if (!word.ok)
24159
+ throw new DocCfbRewriteError(`Cannot resize WordDocument: ${word.reason}`);
24160
+ const table = resizeCompoundFileStream(word.bytes, [fib.tableStreamName], editedTableBytes);
24161
+ if (!table.ok)
24162
+ throw new DocCfbRewriteError(`Cannot resize DOC table stream: ${table.reason}`);
24163
+ return table.bytes;
23353
24164
  }
23354
24165
  };
23355
24166
  } catch {
23356
24167
  return void 0;
23357
24168
  }
23358
24169
  }
24170
+ var DocCfbRewriteError;
23359
24171
  var init_ole_document_doc_cfb = __esm({
23360
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cfb.js"() {
24172
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cfb.js"() {
23361
24173
  init_ole_document_doc_fib();
23362
- init_ole2_parser_read();
23363
- init_ole2_parser_types();
23364
- init_ole2_parser_write();
24174
+ init_ole2_stream_edit();
24175
+ init_ole2_stream_resize();
24176
+ DocCfbRewriteError = class extends Error {
24177
+ constructor(message) {
24178
+ super(message);
24179
+ this.name = "DocCfbRewriteError";
24180
+ }
24181
+ };
23365
24182
  }
23366
24183
  });
23367
24184
 
23368
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fkp.js
24185
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fkp.js
23369
24186
  function parseBteTable(tableStream, at2) {
23370
24187
  const view = new DataView(tableStream.buffer, tableStream.byteOffset, tableStream.byteLength);
23371
- const n = Math.floor((at2.lcb - 4) / (4 + 4));
24188
+ if (!Number.isInteger(at2.fc) || !Number.isInteger(at2.lcb) || at2.fc < 0 || at2.lcb < 4 || (at2.lcb - 4) % 8 !== 0 || at2.fc > tableStream.length - at2.lcb)
24189
+ throw new Error("Invalid BTE table bounds");
24190
+ const n = (at2.lcb - 4) / 8;
23372
24191
  const fcs = [];
23373
24192
  for (let i2 = 0; i2 <= n; i2++) {
23374
- fcs.push(view.getInt32(at2.fc + i2 * 4, true));
24193
+ const fc = view.getInt32(at2.fc + i2 * 4, true);
24194
+ if (fc < 0 || i2 > 0 && fc <= fcs[i2 - 1])
24195
+ throw new Error("Invalid BTE FC boundaries");
24196
+ fcs.push(fc);
23375
24197
  }
23376
24198
  const pns = [];
23377
24199
  for (let i2 = 0; i2 < n; i2++) {
@@ -23392,10 +24214,17 @@ function buildBteTableBytes(table) {
23392
24214
  return bytes;
23393
24215
  }
23394
24216
  function findBteRangeIndex(table, fc) {
23395
- for (let i2 = 0; i2 < table.pns.length; i2++) {
23396
- if (fc >= table.fcs[i2] && fc < table.fcs[i2 + 1]) {
23397
- return i2;
23398
- }
24217
+ let low = 0, high = table.pns.length;
24218
+ while (low < high) {
24219
+ const middle = low + Math.floor((high - low) / 2);
24220
+ if (fc < table.fcs[middle])
24221
+ high = middle;
24222
+ else if (fc >= table.fcs[middle + 1])
24223
+ low = middle + 1;
24224
+ else if (fc >= table.fcs[middle])
24225
+ return middle;
24226
+ else
24227
+ break;
23399
24228
  }
23400
24229
  throw new Error(`FC ${fc} is not covered by any BTE range`);
23401
24230
  }
@@ -23411,7 +24240,11 @@ function extractPapxBlob(wordDoc, papxBte, fc) {
23411
24240
  const rangeIndex = findBteRangeIndex(papxBte, fc);
23412
24241
  const pageOffset = papxBte.pns[rangeIndex] * PAGE_SIZE;
23413
24242
  const page = wordDoc.subarray(pageOffset, pageOffset + PAGE_SIZE);
24243
+ if (page.length !== PAGE_SIZE)
24244
+ throw new Error("Truncated PAPX page");
23414
24245
  const crun = page[PAGE_SIZE - 1];
24246
+ if (crun === 0 || (crun + 1) * 4 + crun * 13 > 511)
24247
+ throw new Error("Invalid PAPX run count");
23415
24248
  const pageView = new DataView(page.buffer, page.byteOffset, page.byteLength);
23416
24249
  const rgbxOffset = (crun + 1) * 4;
23417
24250
  for (let i2 = 0; i2 < crun; i2++) {
@@ -23419,8 +24252,13 @@ function extractPapxBlob(wordDoc, papxBte, fc) {
23419
24252
  const runFcEnd = pageView.getInt32((i2 + 1) * 4, true);
23420
24253
  if (fc >= runFcStart && fc < runFcEnd) {
23421
24254
  const bOffsetWord = page[rgbxOffset + i2 * 13];
24255
+ if (bOffsetWord === 0)
24256
+ return new Uint8Array();
23422
24257
  const blobOffset = bOffsetWord * 2;
23423
- return page.slice(blobOffset, blobOffset + papxBlobLength(page, blobOffset));
24258
+ const blobLength = papxBlobLength(page, blobOffset);
24259
+ if (blobOffset < rgbxOffset + crun * 13 || !Number.isInteger(blobLength) || blobOffset + blobLength > 511)
24260
+ throw new Error("Invalid PAPX blob bounds");
24261
+ return page.slice(blobOffset, blobOffset + blobLength);
23424
24262
  }
23425
24263
  }
23426
24264
  throw new Error(`FC ${fc} is not covered by any run in PAPX page ${papxBte.pns[rangeIndex]}`);
@@ -23429,7 +24267,11 @@ function extractChpxBlob(wordDoc, chpxBte, fc) {
23429
24267
  const rangeIndex = findBteRangeIndex(chpxBte, fc);
23430
24268
  const pageOffset = chpxBte.pns[rangeIndex] * PAGE_SIZE;
23431
24269
  const page = wordDoc.subarray(pageOffset, pageOffset + PAGE_SIZE);
24270
+ if (page.length !== PAGE_SIZE)
24271
+ throw new Error("Truncated CHPX page");
23432
24272
  const crun = page[PAGE_SIZE - 1];
24273
+ if (crun === 0 || (crun + 1) * 4 + crun > 511)
24274
+ throw new Error("Invalid CHPX run count");
23433
24275
  const pageView = new DataView(page.buffer, page.byteOffset, page.byteLength);
23434
24276
  const rgbOffset = (crun + 1) * 4;
23435
24277
  for (let i2 = 0; i2 < crun; i2++) {
@@ -23442,6 +24284,8 @@ function extractChpxBlob(wordDoc, chpxBte, fc) {
23442
24284
  }
23443
24285
  const blobOffset = bOffsetWord * 2;
23444
24286
  const cb = page[blobOffset];
24287
+ if (blobOffset < rgbOffset + crun || blobOffset + 1 + cb > 511)
24288
+ throw new Error("Invalid CHPX blob bounds");
23445
24289
  return page.slice(blobOffset, blobOffset + 1 + cb);
23446
24290
  }
23447
24291
  }
@@ -23453,8 +24297,12 @@ function buildSingleRunPapxPage(fcStart, fcEnd, blob) {
23453
24297
  view.setInt32(0, fcStart, true);
23454
24298
  view.setInt32(4, fcEnd, true);
23455
24299
  const blobByteOffset = 22;
23456
- page[8] = blobByteOffset / 2;
23457
- page.set(blob, blobByteOffset);
24300
+ if (blob.length > 511 - blobByteOffset)
24301
+ throw new Error("PAPX blob exceeds page capacity");
24302
+ if (blob.length > 0) {
24303
+ page[8] = blobByteOffset / 2;
24304
+ page.set(blob, blobByteOffset);
24305
+ }
23458
24306
  page[PAGE_SIZE - 1] = 1;
23459
24307
  return page;
23460
24308
  }
@@ -23465,6 +24313,8 @@ function buildSingleRunChpxPage(fcStart, fcEnd, blob) {
23465
24313
  view.setInt32(4, fcEnd, true);
23466
24314
  if (blob.length > 0) {
23467
24315
  const blobByteOffset = 10;
24316
+ if (blob.length > 511 - blobByteOffset)
24317
+ throw new Error("CHPX blob exceeds page capacity");
23468
24318
  page[8] = blobByteOffset / 2;
23469
24319
  page.set(blob, blobByteOffset);
23470
24320
  }
@@ -23473,12 +24323,12 @@ function buildSingleRunChpxPage(fcStart, fcEnd, blob) {
23473
24323
  }
23474
24324
  var PAGE_SIZE;
23475
24325
  var init_ole_document_doc_fkp = __esm({
23476
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fkp.js"() {
24326
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fkp.js"() {
23477
24327
  PAGE_SIZE = 512;
23478
24328
  }
23479
24329
  });
23480
24330
 
23481
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cp1252.js
24331
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cp1252.js
23482
24332
  function decodeCp1252Byte(byte) {
23483
24333
  if (byte >= 128 && byte <= 159) {
23484
24334
  return CP1252_HIGH_BLOCK[byte - 128];
@@ -23512,7 +24362,7 @@ function encodeCp1252(text2) {
23512
24362
  }
23513
24363
  var CP1252_HIGH_BLOCK, CP1252_HIGH_BLOCK_REVERSE;
23514
24364
  var init_ole_document_doc_cp1252 = __esm({
23515
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cp1252.js"() {
24365
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cp1252.js"() {
23516
24366
  CP1252_HIGH_BLOCK = [
23517
24367
  8364,
23518
24368
  129,
@@ -23551,21 +24401,42 @@ var init_ole_document_doc_cp1252 = __esm({
23551
24401
  }
23552
24402
  });
23553
24403
 
23554
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-pieces.js
23555
- function parsePieceTable(tableStream, clx) {
24404
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-pieces.js
24405
+ function parseDocClx(tableStream, clx, maxPieces) {
24406
+ if (maxPieces !== void 0 && (!Number.isSafeInteger(maxPieces) || maxPieces < 0))
24407
+ throw new Error("Invalid DOC piece limit");
23556
24408
  const view = new DataView(tableStream.buffer, tableStream.byteOffset, tableStream.byteLength);
24409
+ if (!Number.isInteger(clx.fc) || !Number.isInteger(clx.lcb) || clx.fc < 0 || clx.lcb < 5 || clx.fc > tableStream.length - clx.lcb)
24410
+ throw new Error("Clx is outside the table stream");
23557
24411
  let off = clx.fc;
23558
24412
  const end = clx.fc + clx.lcb;
24413
+ let prcCount = 0;
23559
24414
  while (off < end) {
23560
24415
  const clxt = view.getUint8(off);
23561
24416
  if (clxt === CLXT_PRC) {
24417
+ if (off + 3 > end)
24418
+ throw new Error("Truncated Prc header");
23562
24419
  const cb = view.getUint16(off + 1, true);
24420
+ if (cb > end - off - 3)
24421
+ throw new Error("Prc extends beyond Clx");
23563
24422
  off += 1 + 2 + cb;
24423
+ prcCount++;
23564
24424
  continue;
23565
24425
  }
23566
24426
  if (clxt === CLXT_PCDT) {
24427
+ if (off + 5 > end)
24428
+ throw new Error("Truncated Pcdt header");
23567
24429
  const lcb = view.getInt32(off + 1, true);
23568
- return parsePlcPcd(view, off + 1 + 4, lcb);
24430
+ if (lcb < 4 || (lcb - 4) % 12 !== 0 || lcb !== end - off - 5)
24431
+ throw new Error("Invalid PlcPcd length");
24432
+ if (maxPieces !== void 0 && (lcb - 4) / 12 > maxPieces)
24433
+ throw new DocResourceLimitError("DOC piece count exceeds the processing limit");
24434
+ const pieces = parsePlcPcd(view, off + 5, lcb);
24435
+ for (const piece of pieces) {
24436
+ if ((piece.prm & 1) !== 0 && piece.prm >>> 1 >= prcCount)
24437
+ throw new Error("Prm1 references a missing Prc");
24438
+ }
24439
+ return { pieces, prcBytes: tableStream.slice(clx.fc, off) };
23569
24440
  }
23570
24441
  throw new Error(`Unrecognised Clx entry type ${clxt} at ${off}`);
23571
24442
  }
@@ -23575,7 +24446,10 @@ function parsePlcPcd(view, plcStart, lcb) {
23575
24446
  const n = Math.floor((lcb - 4) / (4 + 8));
23576
24447
  const cps = [];
23577
24448
  for (let i2 = 0; i2 <= n; i2++) {
23578
- cps.push(view.getInt32(plcStart + i2 * 4, true));
24449
+ const cp = view.getInt32(plcStart + i2 * 4, true);
24450
+ if (i2 === 0 && cp !== 0 || i2 > 0 && cp <= cps[i2 - 1])
24451
+ throw new Error("Piece CPs must start at zero and increase");
24452
+ cps.push(cp);
23579
24453
  }
23580
24454
  const pcdStart = plcStart + (n + 1) * 4;
23581
24455
  const pieces = [];
@@ -23583,6 +24457,8 @@ function parsePlcPcd(view, plcStart, lcb) {
23583
24457
  const pOff = pcdStart + i2 * 8;
23584
24458
  const flagsWord = view.getUint16(pOff, true);
23585
24459
  const fcRaw = view.getUint32(pOff + 2, true);
24460
+ if ((fcRaw & 2147483648) !== 0)
24461
+ throw new Error("Reserved FcCompressed bit is set");
23586
24462
  const prm = view.getUint16(pOff + 6, true);
23587
24463
  const compressed = (fcRaw >>> 30 & 1) === 1;
23588
24464
  const fcField = fcRaw & 1073741823;
@@ -23599,6 +24475,9 @@ function parsePlcPcd(view, plcStart, lcb) {
23599
24475
  }
23600
24476
  function decodePieceText(wordDoc, piece) {
23601
24477
  const charLen = piece.cpEnd - piece.cpStart;
24478
+ const byteLen = charLen * (piece.compressed ? 1 : 2);
24479
+ if (!Number.isInteger(charLen) || charLen < 0 || !Number.isInteger(piece.fc) || piece.fc < 0 || piece.fc > wordDoc.length - byteLen)
24480
+ throw new Error("Piece text is outside WordDocument");
23602
24481
  if (piece.compressed) {
23603
24482
  return decodeCp1252(wordDoc.subarray(piece.fc, piece.fc + charLen));
23604
24483
  }
@@ -23609,8 +24488,19 @@ function decodePieceText(wordDoc, piece) {
23609
24488
  }
23610
24489
  return out;
23611
24490
  }
23612
- function decodePiecesText(wordDoc, pieces) {
23613
- return pieces.map((piece) => decodePieceText(wordDoc, piece)).join("");
24491
+ function decodePiecesText(wordDoc, pieces, maxChars) {
24492
+ if (maxChars !== void 0 && (!Number.isInteger(maxChars) || maxChars < 0))
24493
+ throw new Error("Invalid text character limit");
24494
+ const out = [];
24495
+ for (const piece of pieces) {
24496
+ const bytes = (piece.cpEnd - piece.cpStart) * (piece.compressed ? 1 : 2);
24497
+ if (piece.cpEnd < piece.cpStart || piece.fc < 0 || piece.fc > wordDoc.length - bytes)
24498
+ throw new Error("Piece text is outside WordDocument");
24499
+ const end = Math.min(piece.cpEnd, maxChars ?? piece.cpEnd);
24500
+ if (end > piece.cpStart)
24501
+ out.push(decodePieceText(wordDoc, { ...piece, cpEnd: end }));
24502
+ }
24503
+ return out.join("");
23614
24504
  }
23615
24505
  function encodePieceText(text2) {
23616
24506
  const compressedBytes = encodeCp1252(text2);
@@ -23648,7 +24538,7 @@ function replacePieceRange(pieces, cpStart, cpEnd, newPiece) {
23648
24538
  fc: newPiece.fc,
23649
24539
  compressed: newPiece.compressed,
23650
24540
  flagsWord: newPiece.flagsWord,
23651
- prm: 0,
24541
+ prm: newPiece.prm ?? 0,
23652
24542
  charLength: newPiece.charLength
23653
24543
  });
23654
24544
  inserted = true;
@@ -23669,7 +24559,7 @@ function replacePieceRange(pieces, cpStart, cpEnd, newPiece) {
23669
24559
  fc: newPiece.fc,
23670
24560
  compressed: newPiece.compressed,
23671
24561
  flagsWord: newPiece.flagsWord,
23672
- prm: 0,
24562
+ prm: newPiece.prm ?? 0,
23673
24563
  charLength: newPiece.charLength
23674
24564
  });
23675
24565
  }
@@ -23687,7 +24577,7 @@ function replacePieceRange(pieces, cpStart, cpEnd, newPiece) {
23687
24577
  };
23688
24578
  });
23689
24579
  }
23690
- function buildClxBytes(pieces) {
24580
+ function buildClxBytes(pieces, prcBytes = new Uint8Array()) {
23691
24581
  const n = pieces.length;
23692
24582
  const plcLcb = (n + 1) * 4 + n * 8;
23693
24583
  const bytes = new Uint8Array(1 + 4 + plcLcb);
@@ -23708,20 +24598,138 @@ function buildClxBytes(pieces) {
23708
24598
  view.setUint16(off + 6, piece.prm, true);
23709
24599
  off += 8;
23710
24600
  }
23711
- return bytes;
24601
+ const result = new Uint8Array(prcBytes.length + bytes.length);
24602
+ result.set(prcBytes);
24603
+ result.set(bytes, prcBytes.length);
24604
+ parseDocClx(result, { fc: 0, lcb: result.length });
24605
+ return result;
23712
24606
  }
23713
- var CLXT_PRC, CLXT_PCDT;
24607
+ var CLXT_PRC, CLXT_PCDT, DocResourceLimitError;
23714
24608
  var init_ole_document_doc_pieces = __esm({
23715
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-pieces.js"() {
24609
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-pieces.js"() {
23716
24610
  init_ole_document_doc_cp1252();
23717
24611
  CLXT_PRC = 1;
23718
24612
  CLXT_PCDT = 2;
24613
+ DocResourceLimitError = class extends Error {
24614
+ constructor(message) {
24615
+ super(message);
24616
+ this.name = "DocResourceLimitError";
24617
+ }
24618
+ };
23719
24619
  }
23720
24620
  });
23721
24621
 
23722
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-editor.js
24622
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fields.js
24623
+ function checkFieldRanges(markers, editStart, editEnd, maxDepth2) {
24624
+ const stack = [];
24625
+ for (const { cp, ch } of markers) {
24626
+ if (ch === 19) {
24627
+ if (stack.length >= maxDepth2)
24628
+ throw new DocResourceLimitError("DOC field nesting exceeds the processing limit");
24629
+ stack.push({ start: cp, separated: false });
24630
+ } else if (ch === 20) {
24631
+ const field = stack.at(-1);
24632
+ if (!field || field.separated)
24633
+ throw new Error("Invalid DOC field separator nesting");
24634
+ field.separated = true;
24635
+ } else if (ch === 21) {
24636
+ const field = stack.pop();
24637
+ if (!field)
24638
+ throw new Error("Unmatched DOC field end");
24639
+ if (field.start < editEnd && cp + 1 > editStart)
24640
+ throw new UnsupportedDocFieldEditError("Paragraph overlaps a field code/result range");
24641
+ }
24642
+ }
24643
+ if (stack.length)
24644
+ throw new Error("Unterminated DOC field");
24645
+ }
24646
+ function* bodyMarkers(body) {
24647
+ for (let cp = 0; cp < body.length; cp++) {
24648
+ const ch = body.charCodeAt(cp);
24649
+ if (ch >= 19 && ch <= 21)
24650
+ yield { cp, ch };
24651
+ }
24652
+ }
24653
+ function shiftDocMainFieldCps(table, at2, body, editStart, editEnd, delta2, maxFields) {
24654
+ if (![editStart, editEnd, delta2, maxFields].every(Number.isSafeInteger) || editStart < 0 || editEnd <= editStart || editEnd > body.length || maxFields < 0 || body.length + delta2 < 0)
24655
+ throw new Error("Invalid field edit bounds or budget");
24656
+ checkFieldRanges(bodyMarkers(body), editStart, editEnd, maxFields);
24657
+ if (at2.lcb === 0)
24658
+ return void 0;
24659
+ if (!Number.isSafeInteger(at2.fc) || at2.fc < 0 || at2.lcb < 4 || (at2.lcb - 4) % 6 !== 0 || at2.fc > table.length - at2.lcb)
24660
+ throw new Error("Invalid main-story field PLC bounds");
24661
+ const n = (at2.lcb - 4) / 6;
24662
+ if (n > maxFields)
24663
+ throw new DocResourceLimitError("DOC field count exceeds the processing limit");
24664
+ const source = table.subarray(at2.fc, at2.fc + at2.lcb);
24665
+ const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
24666
+ const markers = [];
24667
+ let previous = -1;
24668
+ for (let i2 = 0; i2 < n; i2++) {
24669
+ const cp = view.getInt32(i2 * 4, true);
24670
+ const ch = source[(n + 1) * 4 + i2 * 2] & 31;
24671
+ if (cp <= previous || cp >= body.length || ![19, 20, 21].includes(ch) || body.charCodeAt(cp) !== ch)
24672
+ throw new Error("Invalid main-story field marker");
24673
+ markers.push({ cp, ch });
24674
+ previous = cp;
24675
+ }
24676
+ checkFieldRanges(markers, editStart, editEnd, maxFields);
24677
+ const sentinel = view.getInt32(n * 4, true);
24678
+ if (sentinel < 0 || sentinel <= previous)
24679
+ throw new Error("Invalid field PLC sentinel");
24680
+ const result = source.slice();
24681
+ const out = new DataView(result.buffer);
24682
+ let shiftedLast = -1;
24683
+ for (let i2 = 0; i2 < n; i2++) {
24684
+ const cp = markers[i2].cp;
24685
+ const shifted = cp >= editEnd ? cp + delta2 : cp;
24686
+ if (shifted < 0 || shifted >= body.length + delta2 || shifted <= shiftedLast)
24687
+ throw new Error("Field position shifts outside the main story");
24688
+ out.setInt32(i2 * 4, shifted, true);
24689
+ shiftedLast = shifted;
24690
+ }
24691
+ let shiftedSentinel = sentinel >= editEnd ? sentinel + delta2 : sentinel;
24692
+ if (shiftedSentinel > 2147483647 || shiftedSentinel <= shiftedLast)
24693
+ shiftedSentinel = sentinel;
24694
+ if (shiftedSentinel <= shiftedLast)
24695
+ throw new Error("No representable field PLC sentinel");
24696
+ out.setInt32(n * 4, shiftedSentinel, true);
24697
+ return result;
24698
+ }
24699
+ var UnsupportedDocFieldEditError;
24700
+ var init_ole_document_doc_fields = __esm({
24701
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fields.js"() {
24702
+ init_ole_document_doc_pieces();
24703
+ UnsupportedDocFieldEditError = class extends Error {
24704
+ constructor(message) {
24705
+ super(message);
24706
+ this.name = "UnsupportedDocFieldEditError";
24707
+ }
24708
+ };
24709
+ }
24710
+ });
24711
+
24712
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-editor.js
24713
+ function processingLimits(limits) {
24714
+ const resolved = {
24715
+ maxCharacters: limits?.maxCharacters ?? DEFAULT_OLE_DOC_PROCESSING_LIMITS.maxCharacters,
24716
+ maxPieces: limits?.maxPieces ?? DEFAULT_OLE_DOC_PROCESSING_LIMITS.maxPieces,
24717
+ maxFieldRecords: limits?.maxFieldRecords ?? DEFAULT_OLE_DOC_PROCESSING_LIMITS.maxFieldRecords
24718
+ };
24719
+ if (!Number.isSafeInteger(resolved.maxCharacters) || resolved.maxCharacters < 0 || !Number.isSafeInteger(resolved.maxPieces) || resolved.maxPieces < 0 || !Number.isSafeInteger(resolved.maxFieldRecords) || resolved.maxFieldRecords < 0)
24720
+ throw new Error("DOC processing limits must be nonnegative safe integers");
24721
+ return resolved;
24722
+ }
23723
24723
  function hasUnsupportedFeatures(wordDoc, fib) {
24724
+ if (fib.ccpOtherStories > 0)
24725
+ return true;
24726
+ for (let index = 93; index < fib.fibRgFcLcbCount; index++) {
24727
+ if (!SAFE_EXTENDED_FC_LCB_INDICES.has(index) && readFcLcbAt(wordDoc, fib, index).lcb !== 0)
24728
+ return true;
24729
+ }
23724
24730
  for (const index of RISKY_PLCF_INDICES) {
24731
+ if (index >= fib.fibRgFcLcbCount)
24732
+ continue;
23725
24733
  if (readFcLcbAt(wordDoc, fib, index).lcb > 4) {
23726
24734
  return true;
23727
24735
  }
@@ -23754,15 +24762,30 @@ function paragraphBoundaries(bodyText) {
23754
24762
  }
23755
24763
  return boundaries;
23756
24764
  }
23757
- function readOleDocParagraphs(docBytes) {
24765
+ function encodePieceTextUtf16(text2) {
24766
+ const bytes = new Uint8Array(text2.length * 2);
24767
+ const view = new DataView(bytes.buffer);
24768
+ for (let i2 = 0; i2 < text2.length; i2++)
24769
+ view.setUint16(i2 * 2, text2.charCodeAt(i2), true);
24770
+ return bytes;
24771
+ }
24772
+ function readOleDocParagraphs(docBytes, limits) {
23758
24773
  try {
24774
+ const budget = processingLimits(limits);
23759
24775
  const cfb = unwrapDocBytes(docBytes);
23760
24776
  if (!cfb) {
23761
24777
  return void 0;
23762
24778
  }
23763
24779
  const fib = readDocFib(cfb.wordDocBytes);
23764
- const pieces = parsePieceTable(cfb.tableBytes, fib.clx);
23765
- const fullText = decodePiecesText(cfb.wordDocBytes, pieces);
24780
+ if (fib.ccpText > budget.maxCharacters)
24781
+ return void 0;
24782
+ const pieces = parseDocClx(cfb.tableBytes, fib.clx, budget.maxPieces).pieces;
24783
+ const totalCp = pieces.at(-1)?.cpEnd ?? 0;
24784
+ if (totalCp > fib.ccpText + fib.ccpOtherStories + 1)
24785
+ return void 0;
24786
+ const fullText = decodePiecesText(cfb.wordDocBytes, pieces, fib.ccpText);
24787
+ if (fullText.length < fib.ccpText)
24788
+ return void 0;
23766
24789
  const bodyText = fullText.slice(0, fib.ccpText);
23767
24790
  const boundaries = paragraphBoundaries(bodyText);
23768
24791
  let start = 0;
@@ -23779,7 +24802,9 @@ function readOleDocParagraphs(docBytes) {
23779
24802
  }
23780
24803
  function shiftSectionTableCps(tableBytes, sed, editEndCp, delta2) {
23781
24804
  const view = new DataView(tableBytes.buffer, tableBytes.byteOffset, tableBytes.byteLength);
23782
- const n = Math.floor((sed.lcb - 4) / (4 + 12));
24805
+ if (sed.lcb < 4 || (sed.lcb - 4) % 16 !== 0 || sed.fc > tableBytes.length - sed.lcb)
24806
+ throw new Error("Invalid section table");
24807
+ const n = (sed.lcb - 4) / 16;
23783
24808
  for (let i2 = 0; i2 <= n; i2++) {
23784
24809
  const off = sed.fc + i2 * 4;
23785
24810
  const cp = view.getInt32(off, true);
@@ -23788,31 +24813,101 @@ function shiftSectionTableCps(tableBytes, sed, editEndCp, delta2) {
23788
24813
  }
23789
24814
  }
23790
24815
  }
23791
- function writeOleDocParagraphEdit(docBytes, paragraphIndex, text2) {
24816
+ function writeOleDocParagraphEdit(docBytes, paragraphIndex, text2, limits) {
24817
+ return tryWriteOleDocParagraphEdit(docBytes, paragraphIndex, text2, limits).bytes;
24818
+ }
24819
+ function tryWriteOleDocParagraphEdit(docBytes, paragraphIndex, text2, limits) {
24820
+ const rejected = (reason) => ({ status: "rejected", bytes: docBytes, reason });
24821
+ let budget;
24822
+ try {
24823
+ budget = processingLimits(limits);
24824
+ } catch {
24825
+ return rejected("invalid-limits");
24826
+ }
24827
+ if (text2.length > budget.maxCharacters)
24828
+ return rejected("resource-limit");
24829
+ if (!Number.isInteger(paragraphIndex) || paragraphIndex < 0)
24830
+ return rejected("invalid-paragraph-index");
24831
+ if (/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/u.test(text2))
24832
+ return rejected("invalid-text");
23792
24833
  try {
23793
24834
  const cfb = unwrapDocBytes(docBytes);
23794
24835
  if (!cfb) {
23795
- return docBytes;
24836
+ return rejected("invalid-payload");
23796
24837
  }
23797
24838
  const fib = readDocFib(cfb.wordDocBytes);
23798
- if (hasUnsupportedFeatures(cfb.wordDocBytes, fib)) {
23799
- return docBytes;
23800
- }
23801
- const pieces = parsePieceTable(cfb.tableBytes, fib.clx);
23802
- const fullText = decodePiecesText(cfb.wordDocBytes, pieces);
24839
+ if (fib.ccpText > budget.maxCharacters)
24840
+ return rejected("resource-limit");
24841
+ const { pieces, prcBytes } = parseDocClx(cfb.tableBytes, fib.clx, budget.maxPieces);
24842
+ const totalCp = pieces.at(-1)?.cpEnd ?? 0;
24843
+ if (totalCp > fib.ccpText + fib.ccpOtherStories + 1)
24844
+ return rejected("invalid-document");
24845
+ const fullText = decodePiecesText(cfb.wordDocBytes, pieces, fib.ccpText);
24846
+ if (fullText.length < fib.ccpText)
24847
+ return rejected("invalid-document");
23803
24848
  const bodyText = fullText.slice(0, fib.ccpText);
23804
24849
  const boundaries = paragraphBoundaries(bodyText);
23805
24850
  const paragraphEndCp = boundaries[paragraphIndex];
23806
24851
  if (paragraphEndCp === void 0) {
23807
- return docBytes;
24852
+ return rejected("invalid-paragraph-index");
23808
24853
  }
23809
24854
  const paragraphStartCp = paragraphIndex === 0 ? 0 : boundaries[paragraphIndex - 1];
24855
+ if (/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/u.test(bodyText.slice(paragraphStartCp, paragraphEndCp)))
24856
+ return rejected("unsupported-features");
24857
+ const sanitizedText = text2.replaceAll(/[\r\n]+/gu, " ");
24858
+ if (fib.ccpText - (paragraphEndCp - paragraphStartCp) + sanitizedText.length + 1 > budget.maxCharacters)
24859
+ return rejected("resource-limit");
24860
+ if (sanitizedText.length + 1 === paragraphEndCp - paragraphStartCp && bodyText[paragraphEndCp - 1] === "\r") {
24861
+ const replacement = `${sanitizedText}\r`;
24862
+ const patched = cfb.wordDocBytes.slice();
24863
+ let canPatch = true;
24864
+ for (const piece of pieces) {
24865
+ const start = Math.max(paragraphStartCp, piece.cpStart);
24866
+ const end = Math.min(paragraphEndCp, piece.cpEnd);
24867
+ if (start >= end)
24868
+ continue;
24869
+ const part = replacement.slice(start - paragraphStartCp, end - paragraphStartCp);
24870
+ const unit = piece.compressed ? 1 : 2;
24871
+ const fc = piece.fc + (start - piece.cpStart) * unit;
24872
+ const fcEnd = fc + part.length * unit;
24873
+ if (pieces.some((other) => other !== piece && other.fc < fcEnd && other.fc + (other.cpEnd - other.cpStart) * (other.compressed ? 1 : 2) > fc)) {
24874
+ canPatch = false;
24875
+ break;
24876
+ }
24877
+ const encoded = piece.compressed ? encodeCp1252(part) : encodePieceTextUtf16(part);
24878
+ if (!encoded) {
24879
+ canPatch = false;
24880
+ break;
24881
+ }
24882
+ patched.set(encoded, fc);
24883
+ }
24884
+ if (canPatch)
24885
+ return { status: "edited", strategy: "preserved-runs", bytes: cfb.rewrap(patched, cfb.tableBytes) };
24886
+ }
24887
+ if (!cfb.canRewrite)
24888
+ return rejected("unsupported-container");
24889
+ if (hasUnsupportedFeatures(cfb.wordDocBytes, fib))
24890
+ return rejected("unsupported-features");
24891
+ const delta2 = sanitizedText.length + 1 - (paragraphEndCp - paragraphStartCp);
24892
+ const mainFields = readFcLcbAt(cfb.wordDocBytes, fib, 16);
24893
+ if (mainFields.lcb > 0) {
24894
+ for (let index = 0; index < fib.fibRgFcLcbCount; index++) {
24895
+ if (index === 16 || index === 87)
24896
+ continue;
24897
+ const other = readFcLcbAt(cfb.wordDocBytes, fib, index);
24898
+ if (other.lcb > 0 && other.fc < mainFields.fc + mainFields.lcb && other.fc + other.lcb > mainFields.fc)
24899
+ return rejected("invalid-document");
24900
+ }
24901
+ }
24902
+ const shiftedFields = shiftDocMainFieldCps(cfb.tableBytes, mainFields, bodyText, paragraphStartCp, paragraphEndCp, delta2, budget.maxFieldRecords);
23810
24903
  const { piece: startPiece, fc: startFc } = pieceAndFcAtCp(pieces, paragraphStartCp);
24904
+ if (pieces.some((piece) => piece.cpStart < paragraphEndCp && piece.cpEnd > paragraphStartCp && piece.prm !== startPiece.prm))
24905
+ return rejected("unsupported-features");
24906
+ const { fc: paragraphMarkFc } = pieceAndFcAtCp(pieces, paragraphEndCp - 1);
23811
24907
  const papxBte = parseBteTable(cfb.tableBytes, fib.plcfbtePapx);
23812
24908
  const chpxBte = parseBteTable(cfb.tableBytes, fib.plcfbteChpx);
23813
- const papxBlob = extractPapxBlob(cfb.wordDocBytes, papxBte, startFc);
24909
+ const papxBlob = extractPapxBlob(cfb.wordDocBytes, papxBte, paragraphMarkFc);
23814
24910
  const chpxBlob = extractChpxBlob(cfb.wordDocBytes, chpxBte, startFc);
23815
- const sanitizedText = text2.replaceAll(/[\r\n]+/gu, " ");
23816
24911
  const { bytes: textBytes, compressed } = encodePieceText(`${sanitizedText}\r`);
23817
24912
  const originalLen = cfb.wordDocBytes.length;
23818
24913
  const newTextFc = originalLen;
@@ -23840,15 +24935,19 @@ function writeOleDocParagraphEdit(docBytes, paragraphIndex, text2) {
23840
24935
  fc: newTextFc,
23841
24936
  compressed,
23842
24937
  charLength: sanitizedText.length + 1,
23843
- flagsWord: startPiece.flagsWord
24938
+ flagsWord: startPiece.flagsWord,
24939
+ prm: startPiece.prm
23844
24940
  });
23845
- const delta2 = sanitizedText.length + 1 - (paragraphEndCp - paragraphStartCp);
24941
+ if (newPieces.length > budget.maxPieces)
24942
+ return rejected("resource-limit");
23846
24943
  const newCcpText = fib.ccpText + delta2;
23847
- const clxBytes = buildClxBytes(newPieces);
24944
+ const clxBytes = buildClxBytes(newPieces, prcBytes);
23848
24945
  const papxBteBytes = buildBteTableBytes(newPapxBte);
23849
24946
  const chpxBteBytes = buildBteTableBytes(newChpxBte);
23850
24947
  const newTableBytes = new Uint8Array(cfb.tableBytes.length + clxBytes.length + papxBteBytes.length + chpxBteBytes.length);
23851
24948
  newTableBytes.set(cfb.tableBytes, 0);
24949
+ if (shiftedFields)
24950
+ newTableBytes.set(shiftedFields, mainFields.fc);
23852
24951
  let tableOff = cfb.tableBytes.length;
23853
24952
  const newClx = { fc: tableOff, lcb: clxBytes.length };
23854
24953
  newTableBytes.set(clxBytes, tableOff);
@@ -23866,20 +24965,30 @@ function writeOleDocParagraphEdit(docBytes, paragraphIndex, text2) {
23866
24965
  plcfbteChpx: newChpxBteFcLcb,
23867
24966
  plcfbtePapx: newPapxBteFcLcb
23868
24967
  });
23869
- return cfb.rewrap(newWordDoc, newTableBytes);
23870
- } catch {
23871
- return docBytes;
24968
+ return { status: "edited", strategy: "piece-append", bytes: cfb.rewrap(newWordDoc, newTableBytes) };
24969
+ } catch (error) {
24970
+ if (error instanceof UnsupportedDocFieldEditError)
24971
+ return rejected("unsupported-features");
24972
+ if (error instanceof DocResourceLimitError)
24973
+ return rejected("resource-limit");
24974
+ if (error instanceof DocCfbRewriteError)
24975
+ return rejected("unsupported-container");
24976
+ return rejected("invalid-document");
23872
24977
  }
23873
24978
  }
23874
- var RISKY_PLCF_INDICES, RISKY_STTB_INDICES;
24979
+ var RISKY_PLCF_INDICES, RISKY_STTB_INDICES, SAFE_EXTENDED_FC_LCB_INDICES, DEFAULT_OLE_DOC_PROCESSING_LIMITS;
23875
24980
  var init_ole_document_doc_editor = __esm({
23876
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-editor.js"() {
24981
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-editor.js"() {
23877
24982
  init_ole_document_doc_cfb();
23878
24983
  init_ole_document_doc_fib();
23879
24984
  init_ole_document_doc_fkp();
23880
24985
  init_ole_document_doc_pieces();
23881
- RISKY_PLCF_INDICES = [3, 4, 5, 16, 17, 18, 19, 20];
24986
+ init_ole_document_doc_cp1252();
24987
+ init_ole_document_doc_fields();
24988
+ 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];
23882
24989
  RISKY_STTB_INDICES = [21, 22, 23];
24990
+ SAFE_EXTENDED_FC_LCB_INDICES = /* @__PURE__ */ new Set([93, 94, 113, 181, 182]);
24991
+ DEFAULT_OLE_DOC_PROCESSING_LIMITS = Object.freeze({ maxCharacters: 16777216, maxPieces: 65536, maxFieldRecords: 65536 });
23883
24992
  }
23884
24993
  });
23885
24994
 
@@ -23973,7 +25082,7 @@ var init_ole_nested_deck_editor = __esm({
23973
25082
  }
23974
25083
  });
23975
25084
 
23976
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/png-encoder.js
25085
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/png-encoder.js
23977
25086
  function crc32(bytes) {
23978
25087
  let crc = 4294967295;
23979
25088
  for (let i2 = 0; i2 < bytes.length; i2++) {
@@ -24083,7 +25192,7 @@ function decodePngDimensions(png) {
24083
25192
  }
24084
25193
  var CRC_TABLE, PNG_SIGNATURE;
24085
25194
  var init_png_encoder = __esm({
24086
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/png-encoder.js"() {
25195
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/png-encoder.js"() {
24087
25196
  CRC_TABLE = (() => {
24088
25197
  const table = new Uint32Array(256);
24089
25198
  for (let n = 0; n < 256; n++) {
@@ -44741,7 +45850,7 @@ var init_encryption_detection = __esm({
44741
45850
  }
44742
45851
  });
44743
45852
 
44744
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/ooxml-crypto-primitives.js
45853
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/ooxml-crypto-primitives.js
44745
45854
  function getSubtle() {
44746
45855
  if (typeof globalThis.crypto !== "undefined" && globalThis.crypto.subtle) {
44747
45856
  return globalThis.crypto.subtle;
@@ -44859,7 +45968,7 @@ async function hmac(algorithm, key2, data) {
44859
45968
  return new Uint8Array(result);
44860
45969
  }
44861
45970
  var init_ooxml_crypto_primitives = __esm({
44862
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/ooxml-crypto-primitives.js"() {
45971
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/ooxml-crypto-primitives.js"() {
44863
45972
  }
44864
45973
  });
44865
45974
 
@@ -46402,7 +47511,7 @@ var init_md2 = __esm({
46402
47511
  }
46403
47512
  });
46404
47513
 
46405
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/digests/bit-ops.js
47514
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/digests/bit-ops.js
46406
47515
  function rotl32(x, n) {
46407
47516
  return (x << n | x >>> 32 - n) >>> 0;
46408
47517
  }
@@ -46462,11 +47571,11 @@ function mdStyleDigest(message, initialState, transform6) {
46462
47571
  return out;
46463
47572
  }
46464
47573
  var init_bit_ops = __esm({
46465
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/digests/bit-ops.js"() {
47574
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/digests/bit-ops.js"() {
46466
47575
  }
46467
47576
  });
46468
47577
 
46469
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/digests/md4.js
47578
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/digests/md4.js
46470
47579
  function f1(x, y, z) {
46471
47580
  return x & y | ~x & z;
46472
47581
  }
@@ -46490,7 +47599,7 @@ function md4(message) {
46490
47599
  }
46491
47600
  var INITIAL_STATE, K22, K3, ROUND1, ROUND2, ROUND3;
46492
47601
  var init_md4 = __esm({
46493
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/digests/md4.js"() {
47602
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/digests/md4.js"() {
46494
47603
  init_bit_ops();
46495
47604
  INITIAL_STATE = [1732584193, 4023233417, 2562383102, 271733878];
46496
47605
  K22 = 1518500249;
@@ -108820,7 +109929,7 @@ var init_metro_blob_collect = __esm({
108820
109929
  }
108821
109930
  });
108822
109931
 
108823
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/byte-writer.js
109932
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/byte-writer.js
108824
109933
  function record(recType, data, recInstance = 0, isContainer2 = false, recVer = 0) {
108825
109934
  const header = new Uint8Array(8);
108826
109935
  const view = new DataView(header.buffer);
@@ -108835,7 +109944,7 @@ function record(recType, data, recInstance = 0, isContainer2 = false, recVer = 0
108835
109944
  }
108836
109945
  var ByteWriter;
108837
109946
  var init_byte_writer = __esm({
108838
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/byte-writer.js"() {
109947
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/byte-writer.js"() {
108839
109948
  ByteWriter = class {
108840
109949
  chunks = [];
108841
109950
  length = 0;
@@ -108918,13 +110027,13 @@ var init_byte_writer = __esm({
108918
110027
  }
108919
110028
  });
108920
110029
 
108921
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-types.js
110030
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-types.js
108922
110031
  function masterToEmu(mu) {
108923
110032
  return Math.round(mu * EMU_PER_MASTER);
108924
110033
  }
108925
110034
  var RT, OA, TEXT_TYPE, HEADER_TOKEN_PLAIN, HEADER_TOKEN_ENCRYPTED, EMU_PER_MASTER;
108926
110035
  var init_legacy_ppt_record_types = __esm({
108927
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-types.js"() {
110036
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-types.js"() {
108928
110037
  RT = {
108929
110038
  Document: 1e3,
108930
110039
  DocumentAtom: 1001,
@@ -109053,14 +110162,14 @@ var init_legacy_ppt_record_types = __esm({
109053
110162
  }
109054
110163
  });
109055
110164
 
109056
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/record-types.js
110165
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/record-types.js
109057
110166
  var init_record_types = __esm({
109058
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/record-types.js"() {
110167
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/record-types.js"() {
109059
110168
  init_legacy_ppt_record_types();
109060
110169
  }
109061
110170
  });
109062
110171
 
109063
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/current-user-writer.js
110172
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/current-user-writer.js
109064
110173
  function buildCurrentUserStream(offsetToCurrentEdit, encrypted) {
109065
110174
  const nameBytes = new ByteWriter().ansi(USER_NAME).toBytes();
109066
110175
  const data = new ByteWriter().u32(20).u32(encrypted ? HEADER_TOKEN_ENCRYPTED : HEADER_TOKEN_PLAIN).u32(offsetToCurrentEdit).u16(nameBytes.length).u16(1012).u8(3).u8(0).bytes(new Uint8Array(2)).bytes(nameBytes).u32(8).toBytes();
@@ -109074,7 +110183,7 @@ function buildCurrentUserStream(offsetToCurrentEdit, encrypted) {
109074
110183
  }
109075
110184
  var USER_NAME, CURRENT_USER_STREAM_SIZE;
109076
110185
  var init_current_user_writer = __esm({
109077
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/current-user-writer.js"() {
110186
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/current-user-writer.js"() {
109078
110187
  init_record_types();
109079
110188
  init_byte_writer();
109080
110189
  USER_NAME = "pptx-viewer";
@@ -109082,7 +110191,7 @@ var init_current_user_writer = __esm({
109082
110191
  }
109083
110192
  });
109084
110193
 
109085
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/blip-writer.js
110194
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/blip-writer.js
109086
110195
  function pictureUid(picture) {
109087
110196
  return md4(picture.bytes);
109088
110197
  }
@@ -109105,7 +110214,7 @@ function buildFbse(picture, uid, foDelay, size) {
109105
110214
  }
109106
110215
  var MSOBLIP_PICT, BLIP_INFO;
109107
110216
  var init_blip_writer = __esm({
109108
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/blip-writer.js"() {
110217
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/blip-writer.js"() {
109109
110218
  init_md4();
109110
110219
  init_png_encoder();
109111
110220
  init_record_types();
@@ -109121,7 +110230,7 @@ var init_blip_writer = __esm({
109121
110230
  }
109122
110231
  });
109123
110232
 
109124
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/fopt-writer.js
110233
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/fopt-writer.js
109125
110234
  function boolPropValue(flag, bit, useBit) {
109126
110235
  return useBit | (flag ? bit : 0);
109127
110236
  }
@@ -109157,7 +110266,7 @@ function buildMetroBlobTertiaryFopt(metroBlob) {
109157
110266
  }
109158
110267
  var OPT, FBID_FLAG, METRO_BLOB_OPID;
109159
110268
  var init_fopt_writer = __esm({
109160
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/fopt-writer.js"() {
110269
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/fopt-writer.js"() {
109161
110270
  init_record_types();
109162
110271
  init_byte_writer();
109163
110272
  OPT = {
@@ -109185,7 +110294,7 @@ var init_fopt_writer = __esm({
109185
110294
  }
109186
110295
  });
109187
110296
 
109188
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/bstore-writer.js
110297
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/bstore-writer.js
109189
110298
  function buildDggDefaultProperties() {
109190
110299
  return buildFopt([
109191
110300
  { id: 385, value: 134217732 },
@@ -109243,7 +110352,7 @@ function buildPictureStore(pictures, shapesPerDrawing) {
109243
110352
  }
109244
110353
  var SHAPE_ID_CLUSTER_SIZE;
109245
110354
  var init_bstore_writer = __esm({
109246
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/bstore-writer.js"() {
110355
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/bstore-writer.js"() {
109247
110356
  init_record_types();
109248
110357
  init_blip_writer();
109249
110358
  init_byte_writer();
@@ -109252,7 +110361,7 @@ var init_bstore_writer = __esm({
109252
110361
  }
109253
110362
  });
109254
110363
 
109255
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/font-collection-writer.js
110364
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/font-collection-writer.js
109256
110365
  function buildFontEntityAtom(name, index) {
109257
110366
  const nameBytes = new ByteWriter().utf16(name.slice(0, 31)).u16(0).toBytes();
109258
110367
  const padded = new Uint8Array(LF_FACE_NAME_BYTES);
@@ -109280,14 +110389,14 @@ function buildEnvironment(fonts, otherTextStyle) {
109280
110389
  }
109281
110390
  var LF_FACE_NAME_BYTES;
109282
110391
  var init_font_collection_writer = __esm({
109283
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/font-collection-writer.js"() {
110392
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/font-collection-writer.js"() {
109284
110393
  init_record_types();
109285
110394
  init_byte_writer();
109286
110395
  LF_FACE_NAME_BYTES = 64;
109287
110396
  }
109288
110397
  });
109289
110398
 
109290
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-writer.js
110399
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-writer.js
109291
110400
  function emuToMaster(emu2) {
109292
110401
  return Math.round(emu2 / EMU_PER_MASTER);
109293
110402
  }
@@ -109343,7 +110452,7 @@ function buildDocumentContainer(input) {
109343
110452
  }
109344
110453
  var MASTER_SLIDE_ID_SENTINEL, RT_CSTRING, RT_BINARY_TAG_DATA_BLOB;
109345
110454
  var init_document_writer = __esm({
109346
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-writer.js"() {
110455
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-writer.js"() {
109347
110456
  init_record_types();
109348
110457
  init_byte_writer();
109349
110458
  init_font_collection_writer();
@@ -109353,7 +110462,7 @@ var init_document_writer = __esm({
109353
110462
  }
109354
110463
  });
109355
110464
 
109356
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/hyperlink-writer.js
110465
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/hyperlink-writer.js
109357
110466
  function buildCString(text2, recInstance) {
109358
110467
  return record(RT.CString, new ByteWriter().utf16(text2).toBytes(), recInstance, false, 0);
109359
110468
  }
@@ -109489,7 +110598,7 @@ function buildTextInteractiveInfoAtom(beginChar, endChar) {
109489
110598
  }
109490
110599
  var II_ACTION, II_JUMP, LT, FLAG_CUSTOM_SHOW_RETURN, HyperlinkCollector;
109491
110600
  var init_hyperlink_writer = __esm({
109492
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/hyperlink-writer.js"() {
110601
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/hyperlink-writer.js"() {
109493
110602
  init_record_types();
109494
110603
  init_byte_writer();
109495
110604
  II_ACTION = {
@@ -109552,7 +110661,7 @@ var init_hyperlink_writer = __esm({
109552
110661
  }
109553
110662
  });
109554
110663
 
109555
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/media-writer.js
110664
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/media-writer.js
109556
110665
  function buildCString2(text2, recInstance) {
109557
110666
  return record(RT.CString, new ByteWriter().utf16(text2).toBytes(), recInstance, false, 0);
109558
110667
  }
@@ -109588,7 +110697,7 @@ function buildMediaExObjEntries(media) {
109588
110697
  }
109589
110698
  var MediaCollector, SOUND_EXTENSION_WAV, SOUND_LENGTH_UNKNOWN;
109590
110699
  var init_media_writer = __esm({
109591
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/media-writer.js"() {
110700
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/media-writer.js"() {
109592
110701
  init_record_types();
109593
110702
  init_byte_writer();
109594
110703
  MediaCollector = class {
@@ -109624,7 +110733,7 @@ var init_media_writer = __esm({
109624
110733
  }
109625
110734
  });
109626
110735
 
109627
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/ole-writer.js
110736
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/ole-writer.js
109628
110737
  function hexToBytes(hex3) {
109629
110738
  const out = new Uint8Array(hex3.length / 2);
109630
110739
  for (let i2 = 0; i2 < out.length; i2++) {
@@ -109686,7 +110795,7 @@ function buildExObjRefAtom(exObjId) {
109686
110795
  }
109687
110796
  var PACKAGE_ROOT_CLSID, COMP_OBJ_HEX, EX_OLE_EMBEDDED, DV_ASPECT_ICON, EX_OLE_SUB_DEFAULT, PACKAGER_MENU_NAME, OleCollector;
109688
110797
  var init_ole_writer = __esm({
109689
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/ole-writer.js"() {
110798
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/ole-writer.js"() {
109690
110799
  init_ole2_parser_write();
109691
110800
  init_record_types();
109692
110801
  init_byte_writer();
@@ -109746,7 +110855,7 @@ var init_ole_writer = __esm({
109746
110855
  }
109747
110856
  });
109748
110857
 
109749
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/ex-obj-list-writer.js
110858
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/ex-obj-list-writer.js
109750
110859
  function buildExObjList(hyperlinks, ole, media) {
109751
110860
  const oleEntries = ole?.all ?? [];
109752
110861
  const mediaEntries = media?.all ?? [];
@@ -109773,7 +110882,7 @@ function buildExObjList(hyperlinks, ole, media) {
109773
110882
  return record(RT.ExternalObjectList, w.toBytes(), 0, true);
109774
110883
  }
109775
110884
  var init_ex_obj_list_writer = __esm({
109776
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/ex-obj-list-writer.js"() {
110885
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/ex-obj-list-writer.js"() {
109777
110886
  init_record_types();
109778
110887
  init_byte_writer();
109779
110888
  init_hyperlink_writer();
@@ -109782,7 +110891,7 @@ var init_ex_obj_list_writer = __esm({
109782
110891
  }
109783
110892
  });
109784
110893
 
109785
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/anchor-writer.js
110894
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/anchor-writer.js
109786
110895
  function emuToMaster2(emu2) {
109787
110896
  return Math.round(emu2 / EMU_PER_MASTER);
109788
110897
  }
@@ -109827,7 +110936,7 @@ function buildChildAnchor(rect2) {
109827
110936
  }
109828
110937
  var INT16_MIN, INT16_MAX;
109829
110938
  var init_anchor_writer = __esm({
109830
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/anchor-writer.js"() {
110939
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/anchor-writer.js"() {
109831
110940
  init_record_types();
109832
110941
  init_byte_writer();
109833
110942
  INT16_MIN = -32768;
@@ -109835,7 +110944,7 @@ var init_anchor_writer = __esm({
109835
110944
  }
109836
110945
  });
109837
110946
 
109838
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/colors.js
110947
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/colors.js
109839
110948
  function parseHex(rgb2) {
109840
110949
  const hex3 = (rgb2 ?? DEFAULT_RGB).replace(/^#/u, "");
109841
110950
  if (!/^[0-9a-fA-F]{6}$/u.test(hex3)) {
@@ -109857,12 +110966,12 @@ function encodeColorIndex(rgb2) {
109857
110966
  }
109858
110967
  var DEFAULT_RGB;
109859
110968
  var init_colors = __esm({
109860
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/colors.js"() {
110969
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/colors.js"() {
109861
110970
  DEFAULT_RGB = "000000";
109862
110971
  }
109863
110972
  });
109864
110973
 
109865
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-exception-writer.js
110974
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-exception-writer.js
109866
110975
  function writePfException(w, para) {
109867
110976
  let mask = 0;
109868
110977
  if (para.hasBullet !== void 0) {
@@ -109952,7 +111061,7 @@ function writeCfException(w, run, fontIndex) {
109952
111061
  }
109953
111062
  var ALIGN_CODE, EMU_PER_MASTER_UNIT;
109954
111063
  var init_text_exception_writer = __esm({
109955
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-exception-writer.js"() {
111064
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-exception-writer.js"() {
109956
111065
  init_colors();
109957
111066
  ALIGN_CODE = {
109958
111067
  l: 0,
@@ -109964,7 +111073,7 @@ var init_text_exception_writer = __esm({
109964
111073
  }
109965
111074
  });
109966
111075
 
109967
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-atom-writer.js
111076
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-atom-writer.js
109968
111077
  function joinParagraphText(body) {
109969
111078
  return body.paragraphs.map((p) => p.runs.map((r) => r.text).join("")).join("\r");
109970
111079
  }
@@ -110025,7 +111134,7 @@ function buildTextAtoms(body, fonts, hyperlinks) {
110025
111134
  return new ByteWriter().bytes(buildTextHeaderAtom(body.textType)).bytes(buildTextCharsAtom(text2)).bytes(buildStyleTextPropAtom(body, fontIndex)).bytes(buildRunHyperlinks(body, hyperlinks)).toBytes();
110026
111135
  }
110027
111136
  var init_text_atom_writer = __esm({
110028
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-atom-writer.js"() {
111137
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-atom-writer.js"() {
110029
111138
  init_record_types();
110030
111139
  init_byte_writer();
110031
111140
  init_hyperlink_writer();
@@ -110033,7 +111142,7 @@ var init_text_atom_writer = __esm({
110033
111142
  }
110034
111143
  });
110035
111144
 
110036
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-placeholders-writer.js
111145
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-placeholders-writer.js
110037
111146
  function utf16z(text2) {
110038
111147
  return new ByteWriter().utf16(text2).u16(0).toBytes();
110039
111148
  }
@@ -110130,7 +111239,7 @@ function buildMasterPlaceholders(placeholders, allocator, fieldFontIndex) {
110130
111239
  }
110131
111240
  var FSP_FLAGS, RECTANGLE_SPT, TEXT_TYPE_TITLE, TEXT_TYPE_BODY, TEXT_TYPE_OTHER, SPECS, MASTER_PLACEHOLDER_ORDER, TITLE_PROMPT, BODY_PROMPT, DEFAULT_FRAMES;
110132
111241
  var init_master_placeholders_writer = __esm({
110133
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-placeholders-writer.js"() {
111242
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-placeholders-writer.js"() {
110134
111243
  init_record_types();
110135
111244
  init_anchor_writer();
110136
111245
  init_byte_writer();
@@ -110197,18 +111306,18 @@ var init_master_placeholders_writer = __esm({
110197
111306
  }
110198
111307
  });
110199
111308
 
110200
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-style-fonts.js
111309
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-style-fonts.js
110201
111310
  function masterStyleFonts(styles) {
110202
111311
  if (!styles)
110203
111312
  return [];
110204
111313
  return [styles.title, styles.body, styles.other].flatMap((levels) => levels ?? []).map((level2) => level2.run.fontName).filter((name) => Boolean(name));
110205
111314
  }
110206
111315
  var init_master_style_fonts = __esm({
110207
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-style-fonts.js"() {
111316
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-style-fonts.js"() {
110208
111317
  }
110209
111318
  });
110210
111319
 
110211
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-text-styles-writer.js
111320
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-text-styles-writer.js
110212
111321
  function buildMasterStyleAtom(recInstance, levels, fontIndex) {
110213
111322
  const w = new ByteWriter().u16(levels.length);
110214
111323
  for (const level2 of levels) {
@@ -110239,7 +111348,7 @@ function buildMasterTextStyles(styles, fontIndex) {
110239
111348
  }
110240
111349
  var EMPTY_LEVELS, FIXED_INSTANCE_DATA;
110241
111350
  var init_master_text_styles_writer = __esm({
110242
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-text-styles-writer.js"() {
111351
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-text-styles-writer.js"() {
110243
111352
  init_record_types();
110244
111353
  init_byte_writer();
110245
111354
  init_text_exception_writer();
@@ -110255,7 +111364,7 @@ var init_master_text_styles_writer = __esm({
110255
111364
  }
110256
111365
  });
110257
111366
 
110258
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-props-writer.js
111367
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-props-writer.js
110259
111368
  function fillEntries(fill) {
110260
111369
  if (!fill || fill.kind === "none") {
110261
111370
  return [{ id: OPT.fNoFillHitTest, value: boolPropValue(false, 16, 1048576) }];
@@ -110310,7 +111419,7 @@ function buildShapeFoptProps(input) {
110310
111419
  }
110311
111420
  var DASH_CODE;
110312
111421
  var init_shape_props_writer = __esm({
110313
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-props-writer.js"() {
111422
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-props-writer.js"() {
110314
111423
  init_colors();
110315
111424
  init_fopt_writer();
110316
111425
  DASH_CODE = {
@@ -110325,7 +111434,7 @@ var init_shape_props_writer = __esm({
110325
111434
  }
110326
111435
  });
110327
111436
 
110328
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-writer.js
111437
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-writer.js
110329
111438
  function buildShapeAnchor(rect2, inGroup) {
110330
111439
  return inGroup ? buildChildAnchor(rect2) : buildClientAnchor(rect2);
110331
111440
  }
@@ -110427,7 +111536,7 @@ function buildMediaShapeContainer(media, allocator, hyperlinks, mediaEmbeds, inG
110427
111536
  }
110428
111537
  var FSP_FLAG_FLIPH, FSP_FLAG_FLIPV, FSP_FLAG_OLE_SHAPE, FSP_FLAG_CHILD, PLACEHOLDER_ID;
110429
111538
  var init_shape_writer = __esm({
110430
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-writer.js"() {
111539
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-writer.js"() {
110431
111540
  init_record_types();
110432
111541
  init_anchor_writer();
110433
111542
  init_byte_writer();
@@ -110449,7 +111558,7 @@ var init_shape_writer = __esm({
110449
111558
  }
110450
111559
  });
110451
111560
 
110452
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/group-writer.js
111561
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/group-writer.js
110453
111562
  function buildFspgr(childRect) {
110454
111563
  return record(OA.FSPGR, buildChildAnchorData(childRect), 0, false, 1);
110455
111564
  }
@@ -110490,7 +111599,7 @@ function buildGroupContainer(group, fonts, allocator, hyperlinks, oleEmbeds, med
110490
111599
  }
110491
111600
  var FSP_FLAG_GROUP, FSP_FLAG_PATRIARCH, FSP_FLAG_HAVE_ANCHOR, ZERO_RECT;
110492
111601
  var init_group_writer = __esm({
110493
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/group-writer.js"() {
111602
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/group-writer.js"() {
110494
111603
  init_record_types();
110495
111604
  init_anchor_writer();
110496
111605
  init_byte_writer();
@@ -110502,10 +111611,10 @@ var init_group_writer = __esm({
110502
111611
  }
110503
111612
  });
110504
111613
 
110505
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-id-allocator.js
111614
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-id-allocator.js
110506
111615
  var ShapeIdAllocator2;
110507
111616
  var init_shape_id_allocator = __esm({
110508
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-id-allocator.js"() {
111617
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-id-allocator.js"() {
110509
111618
  ShapeIdAllocator2 = class {
110510
111619
  current;
110511
111620
  constructor(drawingId, clusterSize) {
@@ -110531,7 +111640,7 @@ var init_shape_id_allocator = __esm({
110531
111640
  }
110532
111641
  });
110533
111642
 
110534
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/drawing-writer.js
111643
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/drawing-writer.js
110535
111644
  function buildDg(drawingId, shapeCount, lastShapeId) {
110536
111645
  const data = new ByteWriter().u32(shapeCount + 1).u32(lastShapeId).toBytes();
110537
111646
  return record(OA.Dg, data, drawingId, false, 0);
@@ -110562,7 +111671,7 @@ function buildDrawing(canvasRect, shapes, backgroundRgb, fonts, drawingId, hyper
110562
111671
  }
110563
111672
  var FSP_FLAG_BACKGROUND, BACKGROUND_RECT_SPT, SHAPE_ID_CLUSTER_SIZE2;
110564
111673
  var init_drawing_writer = __esm({
110565
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/drawing-writer.js"() {
111674
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/drawing-writer.js"() {
110566
111675
  init_record_types();
110567
111676
  init_byte_writer();
110568
111677
  init_colors();
@@ -110575,7 +111684,7 @@ var init_drawing_writer = __esm({
110575
111684
  }
110576
111685
  });
110577
111686
 
110578
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/notes-writer.js
111687
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/notes-writer.js
110579
111688
  function buildNotesAtom(slidePersistIdRef) {
110580
111689
  const data = new ByteWriter().i32(slidePersistIdRef).u16(0).u16(0).toBytes();
110581
111690
  return record(RT.NotesAtom, data, 0, false, 1);
@@ -110593,16 +111702,16 @@ function buildNotesContainer(paragraphs, notesRect, slidePersistIdRef, fonts, dr
110593
111702
  return record(RT.Notes, data, 0, true);
110594
111703
  }
110595
111704
  var init_notes_writer = __esm({
110596
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/notes-writer.js"() {
111705
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/notes-writer.js"() {
110597
111706
  init_record_types();
110598
111707
  init_byte_writer();
110599
111708
  init_drawing_writer();
110600
111709
  }
110601
111710
  });
110602
111711
 
110603
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-stream.js
111712
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-stream.js
110604
111713
  function readRecord(view, offset) {
110605
- if (offset < 0 || offset + RECORD_HEADER_SIZE > view.byteLength) {
111714
+ if (!Number.isSafeInteger(offset) || offset < 0 || offset + RECORD_HEADER_SIZE > view.byteLength) {
110606
111715
  return void 0;
110607
111716
  }
110608
111717
  const verAndInstance = view.getUint16(offset, true);
@@ -110630,6 +111739,9 @@ function isContainer(rec) {
110630
111739
  return rec.recVer === 15;
110631
111740
  }
110632
111741
  function* iterateRecords(view, start, end) {
111742
+ if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 0 || end < start) {
111743
+ return;
111744
+ }
110633
111745
  let offset = start;
110634
111746
  const limit = Math.min(end, view.byteLength);
110635
111747
  while (offset + RECORD_HEADER_SIZE <= limit) {
@@ -110656,16 +111768,19 @@ function findChild4(view, container2, recType, recInstance) {
110656
111768
  return void 0;
110657
111769
  }
110658
111770
  function findDescendant(view, container2, recType, recInstance) {
110659
- for (const child27 of iterateChildren(view, container2)) {
111771
+ const stack = [iterateChildren(view, container2)];
111772
+ while (stack.length > 0) {
111773
+ const next = stack[stack.length - 1].next();
111774
+ if (next.done) {
111775
+ stack.pop();
111776
+ continue;
111777
+ }
111778
+ const child27 = next.value;
110660
111779
  if (child27.recType === recType && (recInstance === void 0)) {
110661
111780
  return child27;
110662
111781
  }
110663
- if (isContainer(child27)) {
110664
- const found = findDescendant(view, child27, recType, recInstance);
110665
- if (found) {
110666
- return found;
110667
- }
110668
- }
111782
+ if (isContainer(child27))
111783
+ stack.push(iterateChildren(view, child27));
110669
111784
  }
110670
111785
  return void 0;
110671
111786
  }
@@ -110674,7 +111789,7 @@ function recordBytes(data, rec) {
110674
111789
  }
110675
111790
  var PptParseError, RECORD_HEADER_SIZE;
110676
111791
  var init_legacy_ppt_record_stream = __esm({
110677
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-stream.js"() {
111792
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-stream.js"() {
110678
111793
  PptParseError = class extends Error {
110679
111794
  constructor(message) {
110680
111795
  super(message);
@@ -110685,14 +111800,14 @@ var init_legacy_ppt_record_stream = __esm({
110685
111800
  }
110686
111801
  });
110687
111802
 
110688
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/record-stream.js
111803
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/record-stream.js
110689
111804
  var init_record_stream = __esm({
110690
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/record-stream.js"() {
111805
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/record-stream.js"() {
110691
111806
  init_legacy_ppt_record_stream();
110692
111807
  }
110693
111808
  });
110694
111809
 
110695
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/color-scheme.js
111810
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/color-scheme.js
110696
111811
  function toHex3(r, g2, b) {
110697
111812
  return [r, g2, b].map((v) => (v & 255).toString(16).padStart(2, "0").toUpperCase()).join("");
110698
111813
  }
@@ -110743,7 +111858,7 @@ function resolveEscherColor(colorRef, scheme) {
110743
111858
  }
110744
111859
  var SCHEME, DEFAULT_SCHEME;
110745
111860
  var init_color_scheme = __esm({
110746
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/color-scheme.js"() {
111861
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/color-scheme.js"() {
110747
111862
  init_record_stream();
110748
111863
  init_record_types();
110749
111864
  SCHEME = {
@@ -110769,7 +111884,7 @@ var init_color_scheme = __esm({
110769
111884
  }
110770
111885
  });
110771
111886
 
110772
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/color-scheme-writer.js
111887
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/color-scheme-writer.js
110773
111888
  function buildColorSchemeAtom(recInstance = 1, colors) {
110774
111889
  const w = new ByteWriter();
110775
111890
  for (const rgb2 of colors?.length === 8 ? colors : DEFAULT_SCHEME) {
@@ -110778,7 +111893,7 @@ function buildColorSchemeAtom(recInstance = 1, colors) {
110778
111893
  return record(RT.ColorSchemeAtom, w.toBytes(), recInstance, false, 0);
110779
111894
  }
110780
111895
  var init_color_scheme_writer = __esm({
110781
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/color-scheme-writer.js"() {
111896
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/color-scheme-writer.js"() {
110782
111897
  init_color_scheme();
110783
111898
  init_record_types();
110784
111899
  init_byte_writer();
@@ -110786,7 +111901,7 @@ var init_color_scheme_writer = __esm({
110786
111901
  }
110787
111902
  });
110788
111903
 
110789
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/slide-writer.js
111904
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/slide-writer.js
110790
111905
  function buildSlideAtomRaw(geom, masterIdRef, notesIdRef, flags) {
110791
111906
  const data = new ByteWriter().i32(geom).bytes(new Uint8Array(8)).u32(masterIdRef).i32(notesIdRef).u16(flags).u16(0).toBytes();
110792
111907
  return record(RT.SlideAtom, data, 0, false, 2);
@@ -110823,7 +111938,7 @@ function buildMainMasterContainer(slideRect, drawingId, hyperlinks, oleEmbeds, m
110823
111938
  }
110824
111939
  var SLIDE_FLAG_MASTER_OBJECTS, SLIDE_FLAG_MASTER_SCHEME, SLIDE_FLAG_MASTER_BACKGROUND, SLIDE_MASTER_ID_SENTINEL, MASTER_FIRST_COLOR_SCHEME_INSTANCE;
110825
111940
  var init_slide_writer = __esm({
110826
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/slide-writer.js"() {
111941
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/slide-writer.js"() {
110827
111942
  init_record_types();
110828
111943
  init_byte_writer();
110829
111944
  init_color_scheme_writer();
@@ -110838,7 +111953,7 @@ var init_slide_writer = __esm({
110838
111953
  }
110839
111954
  });
110840
111955
 
110841
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-stream-layout.js
111956
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-stream-layout.js
110842
111957
  function masterSlideId(index) {
110843
111958
  return MASTER_SLIDE_ID_SENTINEL + index;
110844
111959
  }
@@ -110962,7 +112077,7 @@ function ensureMinimumDocumentStreamSize(contentSizeWithoutPadding, maxPersistId
110962
112077
  }
110963
112078
  var DOC_ID, MASTER_ID;
110964
112079
  var init_document_stream_layout = __esm({
110965
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-stream-layout.js"() {
112080
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-stream-layout.js"() {
110966
112081
  init_bstore_writer();
110967
112082
  init_byte_writer();
110968
112083
  init_document_writer();
@@ -110980,15 +112095,15 @@ var init_document_stream_layout = __esm({
110980
112095
  }
110981
112096
  });
110982
112097
 
110983
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/crypto-constants.js
112098
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/crypto-constants.js
110984
112099
  var RC4_ALG_ID2;
110985
112100
  var init_crypto_constants = __esm({
110986
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/crypto-constants.js"() {
112101
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/crypto-constants.js"() {
110987
112102
  RC4_ALG_ID2 = 26625;
110988
112103
  }
110989
112104
  });
110990
112105
 
110991
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/rc4-cipher.js
112106
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/rc4-cipher.js
110992
112107
  function rc4Cipher(key2, data) {
110993
112108
  if (key2.length === 0) {
110994
112109
  throw new Error("RC4 key must not be empty.");
@@ -111019,11 +112134,11 @@ function rc4Cipher(key2, data) {
111019
112134
  return out;
111020
112135
  }
111021
112136
  var init_rc4_cipher = __esm({
111022
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/rc4-cipher.js"() {
112137
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/rc4-cipher.js"() {
111023
112138
  }
111024
112139
  });
111025
112140
 
111026
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-key.js
112141
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-key.js
111027
112142
  async function rc4CryptoApiKeyBase(password, salt) {
111028
112143
  return hash("SHA-1", concatArrays(salt, encodePasswordUtf16LE(password)));
111029
112144
  }
@@ -111064,14 +112179,14 @@ async function rc4CryptoApiEncryptVerifier(key0, verifier) {
111064
112179
  }
111065
112180
  var PADDED_40_BIT_KEY_BYTES;
111066
112181
  var init_rc4_cryptoapi_key = __esm({
111067
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-key.js"() {
112182
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-key.js"() {
111068
112183
  init_ooxml_crypto_primitives();
111069
112184
  init_rc4_cipher();
111070
112185
  PADDED_40_BIT_KEY_BYTES = 16;
111071
112186
  }
111072
112187
  });
111073
112188
 
111074
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-streams.js
112189
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-streams.js
111075
112190
  function readHeader(bytes) {
111076
112191
  const view = new DataView(bytes.buffer, bytes.byteOffset, RECORD_HEADER_SIZE);
111077
112192
  return {
@@ -111140,7 +112255,7 @@ async function cipherPicturesStream(stream, keyFor3, mode) {
111140
112255
  }
111141
112256
  var UID_SIZE, METAFILE_HEADER_SIZE, BITMAP_TAG_SIZE, METAFILE_BLIPS, BITMAP_BLIPS;
111142
112257
  var init_rc4_cryptoapi_streams = __esm({
111143
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-streams.js"() {
112258
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-streams.js"() {
111144
112259
  init_rc4_cipher();
111145
112260
  init_record_stream();
111146
112261
  UID_SIZE = 16;
@@ -111151,7 +112266,7 @@ var init_rc4_cryptoapi_streams = __esm({
111151
112266
  }
111152
112267
  });
111153
112268
 
111154
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/encrypt-writer.js
112269
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/encrypt-writer.js
111155
112270
  async function buildCryptSession(password) {
111156
112271
  const salt = new Uint8Array(SALT_SIZE);
111157
112272
  crypto.getRandomValues(salt);
@@ -111179,7 +112294,7 @@ async function encryptPicturesStream(stream, ctx) {
111179
112294
  }
111180
112295
  var CSP_NAME, KEY_SIZE_BITS, SALT_SIZE, VERIFIER_SIZE, VERIFIER_HASH_SIZE, ENCRYPTION_FLAGS;
111181
112296
  var init_encrypt_writer = __esm({
111182
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/encrypt-writer.js"() {
112297
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/encrypt-writer.js"() {
111183
112298
  init_crypto_constants();
111184
112299
  init_rc4_cryptoapi_key();
111185
112300
  init_rc4_cryptoapi_streams();
@@ -111194,7 +112309,7 @@ var init_encrypt_writer = __esm({
111194
112309
  }
111195
112310
  });
111196
112311
 
111197
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-relative-runs.js
112312
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-relative-runs.js
111198
112313
  function levelsFor(styles, textType) {
111199
112314
  switch (textType) {
111200
112315
  case 0:
@@ -111260,12 +112375,12 @@ function withMasterRelativeRunStyles(deck) {
111260
112375
  }
111261
112376
  var STYLE_KEYS;
111262
112377
  var init_master_relative_runs = __esm({
111263
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-relative-runs.js"() {
112378
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-relative-runs.js"() {
111264
112379
  STYLE_KEYS = ["bold", "italic", "underline"];
111265
112380
  }
111266
112381
  });
111267
112382
 
111268
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/persist-writer.js
112383
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/persist-writer.js
111269
112384
  function buildPersistDirectoryAtom(entries) {
111270
112385
  const sorted = [...entries].sort((a, b) => a[0] - b[0]);
111271
112386
  const w = new ByteWriter();
@@ -111295,17 +112410,17 @@ function buildEncryptedUserEditAtom(input) {
111295
112410
  }
111296
112411
  var MAX_RUN;
111297
112412
  var init_persist_writer = __esm({
111298
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/persist-writer.js"() {
112413
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/persist-writer.js"() {
111299
112414
  init_record_types();
111300
112415
  init_byte_writer();
111301
112416
  MAX_RUN = 4095;
111302
112417
  }
111303
112418
  });
111304
112419
 
111305
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/ppt-clsid.js
112420
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/ppt-clsid.js
111306
112421
  var PPT_STORAGE_CLSID;
111307
112422
  var init_ppt_clsid = __esm({
111308
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/ppt-clsid.js"() {
112423
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/ppt-clsid.js"() {
111309
112424
  PPT_STORAGE_CLSID = new Uint8Array([
111310
112425
  16,
111311
112426
  141,
@@ -111327,7 +112442,7 @@ var init_ppt_clsid = __esm({
111327
112442
  }
111328
112443
  });
111329
112444
 
111330
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/write-ppt.js
112445
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/write-ppt.js
111331
112446
  async function finishUnencrypted(layout, lastSlideId) {
111332
112447
  const w = new ByteWriter().append(layout.bytes);
111333
112448
  const dirAtom = buildPersistDirectoryAtom(layout.offsets);
@@ -111381,7 +112496,7 @@ async function buildPptFile(deck, options = {}) {
111381
112496
  return new Uint8Array(buildOle2(streams2, PPT_STORAGE_CLSID, 0));
111382
112497
  }
111383
112498
  var init_write_ppt = __esm({
111384
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/write-ppt.js"() {
112499
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/write-ppt.js"() {
111385
112500
  init_ole2_parser_write();
111386
112501
  init_byte_writer();
111387
112502
  init_current_user_writer();
@@ -111393,9 +112508,9 @@ var init_write_ppt = __esm({
111393
112508
  }
111394
112509
  });
111395
112510
 
111396
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-ppt-writer.js
112511
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-ppt-writer.js
111397
112512
  var init_legacy_ppt_writer = __esm({
111398
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-ppt-writer.js"() {
112513
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-ppt-writer.js"() {
111399
112514
  init_write_ppt();
111400
112515
  init_master_style_fonts();
111401
112516
  }
@@ -151278,61 +152393,115 @@ var init_deflate_utils = __esm({
151278
152393
  }
151279
152394
  });
151280
152395
 
151281
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/persist-directory.js
151282
- function parseUserEditAtom(view, offset) {
152396
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/persist-directory.js
152397
+ function checkedLimit(value) {
152398
+ if (!Number.isSafeInteger(value) || value < 1)
152399
+ throw new PptParseError("Invalid persist directory resource limit");
152400
+ return value;
152401
+ }
152402
+ function boundedAtom(view, offset, type) {
151283
152403
  const rec = readRecordOrThrow(view, offset);
151284
- if (rec.recType !== RT.UserEditAtom) {
151285
- throw new PptParseError(`Expected UserEditAtom at offset ${offset}, found recType 0x${rec.recType.toString(16)}`);
152404
+ if (rec.recType !== type || rec.recVer !== 0 || rec.recInstance !== 0) {
152405
+ throw new PptParseError(`Invalid persist atom header at offset ${offset}`);
152406
+ }
152407
+ if (rec.recLen > view.byteLength - rec.dataOffset) {
152408
+ throw new PptParseError(`Persist atom payload out of bounds at offset ${offset}`);
151286
152409
  }
152410
+ return rec;
152411
+ }
152412
+ function parseUserEditAtom(view, offset) {
152413
+ const rec = boundedAtom(view, offset, RT.UserEditAtom);
151287
152414
  if (rec.recLen !== 28 && rec.recLen !== 32) {
151288
152415
  throw new PptParseError(`UserEditAtom has invalid length ${rec.recLen}`);
151289
152416
  }
151290
152417
  const d = rec.dataOffset;
151291
- return {
152418
+ const edit = {
151292
152419
  offsetLastEdit: view.getUint32(d + 8, true),
151293
152420
  offsetPersistDirectory: view.getUint32(d + 12, true),
151294
152421
  docPersistIdRef: view.getUint32(d + 16, true),
151295
152422
  encryptSessionPersistIdRef: rec.recLen === 32 ? view.getUint32(d + 28, true) : void 0
151296
152423
  };
151297
- }
151298
- function parsePersistDirectoryAtom(view, offset) {
151299
- const rec = readRecordOrThrow(view, offset);
151300
- if (rec.recType !== RT.PersistDirectoryAtom) {
151301
- throw new PptParseError(`Expected PersistDirectoryAtom at offset ${offset}, found recType 0x${rec.recType.toString(16)}`);
152424
+ if (view.getUint8(d + 6) !== 0 || view.getUint8(d + 7) !== 3) {
152425
+ throw new PptParseError("Unsupported UserEditAtom storage version");
152426
+ }
152427
+ if (edit.offsetLastEdit >= offset || edit.offsetPersistDirectory <= edit.offsetLastEdit || edit.offsetPersistDirectory >= offset) {
152428
+ throw new PptParseError("Invalid UserEditAtom save history offsets");
151302
152429
  }
152430
+ if (edit.docPersistIdRef !== 1)
152431
+ throw new PptParseError("Invalid document persist identifier");
152432
+ return edit;
152433
+ }
152434
+ function parsePersistDirectoryAtom(view, offset, maxEntries = DEFAULT_MAX_ENTRIES) {
152435
+ checkedLimit(maxEntries);
152436
+ const rec = boundedAtom(view, offset, RT.PersistDirectoryAtom);
151303
152437
  const pairs = [];
151304
152438
  let pos2 = rec.dataOffset;
151305
152439
  const end = rec.dataOffset + rec.recLen;
151306
- while (pos2 + 4 <= end) {
152440
+ const seen = /* @__PURE__ */ new Set();
152441
+ while (pos2 < end) {
152442
+ if (end - pos2 < 4)
152443
+ throw new PptParseError("Truncated persist directory entry");
151307
152444
  const packed = view.getUint32(pos2, true);
151308
152445
  const persistId = packed & 1048575;
151309
152446
  const cPersist = packed >>> 20 & 4095;
151310
152447
  pos2 += 4;
151311
- for (let i2 = 0; i2 < cPersist && pos2 + 4 <= end; i2++, pos2 += 4) {
151312
- pairs.push([persistId + i2, view.getUint32(pos2, true)]);
152448
+ if (persistId > 1048574 || cPersist === 0 || persistId + cPersist - 1 > 1048575) {
152449
+ throw new PptParseError("Invalid persist identifier run");
152450
+ }
152451
+ if (cPersist * 4 > end - pos2)
152452
+ throw new PptParseError("Truncated persist offset run");
152453
+ if (pairs.length + cPersist > maxEntries)
152454
+ throw new PptParseError("Persist directory entry limit exceeded");
152455
+ for (let i2 = 0; i2 < cPersist; i2++, pos2 += 4) {
152456
+ const id = persistId + i2;
152457
+ if (seen.has(id))
152458
+ throw new PptParseError("Duplicate persist identifier");
152459
+ seen.add(id);
152460
+ const objectOffset = view.getUint32(pos2, true);
152461
+ if (objectOffset >= offset || objectOffset + 8 > view.byteLength)
152462
+ throw new PptParseError("Persist object offset out of bounds");
152463
+ pairs.push([id, objectOffset]);
151313
152464
  }
151314
152465
  }
151315
152466
  return pairs;
151316
152467
  }
151317
- function buildPersistDirectory(view, offsetToCurrentEdit) {
152468
+ function buildPersistDirectory(view, offsetToCurrentEdit, limits = {}) {
152469
+ const maxEdits = checkedLimit(limits.maxEdits ?? DEFAULT_MAX_EDITS);
152470
+ const maxEntries = checkedLimit(limits.maxEntries ?? DEFAULT_MAX_ENTRIES);
151318
152471
  const edits = [];
152472
+ const editOffsets = [];
151319
152473
  const seen = /* @__PURE__ */ new Set();
151320
152474
  let offset = offsetToCurrentEdit;
151321
152475
  while (offset !== 0) {
152476
+ if (edits.length >= maxEdits)
152477
+ throw new PptParseError("User edit chain limit exceeded");
151322
152478
  if (seen.has(offset)) {
151323
152479
  throw new PptParseError(`Circular UserEditAtom chain at offset ${offset}`);
151324
152480
  }
151325
152481
  seen.add(offset);
151326
152482
  const edit = parseUserEditAtom(view, offset);
151327
152483
  edits.push(edit);
152484
+ editOffsets.push(offset);
151328
152485
  offset = edit.offsetLastEdit;
151329
152486
  }
151330
152487
  if (edits.length === 0) {
151331
152488
  throw new PptParseError("No UserEditAtom found");
151332
152489
  }
151333
152490
  const directory = /* @__PURE__ */ new Map();
152491
+ let entryCount = 0;
151334
152492
  for (let i2 = edits.length - 1; i2 >= 0; i2--) {
151335
- for (const [id, off] of parsePersistDirectoryAtom(view, edits[i2].offsetPersistDirectory)) {
152493
+ const edit = edits[i2];
152494
+ const dirAtom = boundedAtom(view, edit.offsetPersistDirectory, RT.PersistDirectoryAtom);
152495
+ const editOffset = editOffsets[i2];
152496
+ if (dirAtom.dataOffset + dirAtom.recLen > editOffset)
152497
+ throw new PptParseError("Persist directory overlaps user edit");
152498
+ const entries = parsePersistDirectoryAtom(view, edit.offsetPersistDirectory, maxEntries);
152499
+ entryCount += entries.length;
152500
+ if (entryCount > maxEntries)
152501
+ throw new PptParseError("Save history persist entry limit exceeded");
152502
+ for (const [id, off] of entries) {
152503
+ if (off < edit.offsetLastEdit)
152504
+ throw new PptParseError("Persist object precedes corresponding user edit");
151336
152505
  directory.set(id, off);
151337
152506
  }
151338
152507
  }
@@ -151343,12 +152512,18 @@ function readPersistRecord(view, directory, persistId) {
151343
152512
  if (offset === void 0) {
151344
152513
  return void 0;
151345
152514
  }
151346
- return readRecordOrThrow(view, offset);
152515
+ const rec = readRecordOrThrow(view, offset);
152516
+ if (rec.recLen > view.byteLength - rec.dataOffset)
152517
+ throw new PptParseError("Persist object payload out of bounds");
152518
+ return rec;
151347
152519
  }
152520
+ var DEFAULT_MAX_EDITS, DEFAULT_MAX_ENTRIES;
151348
152521
  var init_persist_directory = __esm({
151349
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/persist-directory.js"() {
152522
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/persist-directory.js"() {
151350
152523
  init_record_stream();
151351
152524
  init_record_types();
152525
+ DEFAULT_MAX_EDITS = 1e4;
152526
+ DEFAULT_MAX_ENTRIES = 1e6;
151352
152527
  }
151353
152528
  });
151354
152529