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.
@@ -20940,10 +20940,10 @@ var init_ole_utils = __esm({
20940
20940
  }
20941
20941
  });
20942
20942
 
20943
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-types.js
20943
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-types.js
20944
20944
  var OLE_MAGIC, ENDOFCHAIN, FREESECT, FATSECT, DIFSECT, MAXREGSECT, ENTRY_TYPE_EMPTY, ENTRY_TYPE_STREAM, ENTRY_TYPE_ROOT, DIR_ENTRY_SIZE; exports.Ole2ParseError = void 0;
20945
20945
  var init_ole2_parser_types = __esm({
20946
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-types.js"() {
20946
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-types.js"() {
20947
20947
  OLE_MAGIC = new Uint8Array([208, 207, 17, 224, 161, 177, 26, 225]);
20948
20948
  ENDOFCHAIN = 4294967294;
20949
20949
  FREESECT = 4294967295;
@@ -20963,10 +20963,13 @@ var init_ole2_parser_types = __esm({
20963
20963
  }
20964
20964
  });
20965
20965
 
20966
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-read.js
20966
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-read.js
20967
20967
  function parseOle2(buffer) {
20968
20968
  const data = new Uint8Array(buffer);
20969
20969
  const view = new DataView(buffer);
20970
+ if (data.length < 512) {
20971
+ throw new exports.Ole2ParseError("Truncated OLE2 compound file header");
20972
+ }
20970
20973
  for (let i2 = 0; i2 < OLE_MAGIC.length; i2++) {
20971
20974
  if (data[i2] !== OLE_MAGIC[i2]) {
20972
20975
  throw new exports.Ole2ParseError("Not a valid OLE2 compound file");
@@ -20980,8 +20983,15 @@ function parseOle2(buffer) {
20980
20983
  }
20981
20984
  const sectorSizePower = view.getUint16(30, true);
20982
20985
  const miniSectorSizePower = view.getUint16(32, true);
20986
+ if (majorVersion !== 3 && majorVersion !== 4 || sectorSizePower !== (majorVersion === 3 ? 9 : 12) || miniSectorSizePower !== 6) {
20987
+ throw new exports.Ole2ParseError("Unsupported OLE2 version or sector size");
20988
+ }
20983
20989
  const sectorSize = 1 << sectorSizePower;
20984
20990
  const miniSectorSize = 1 << miniSectorSizePower;
20991
+ if (data.length < sectorSize || data.length % sectorSize !== 0) {
20992
+ throw new exports.Ole2ParseError("Truncated OLE2 sector");
20993
+ }
20994
+ const sectorCount = data.length / sectorSize - 1;
20985
20995
  const totalFATSectors = view.getUint32(44, true);
20986
20996
  const firstDirectorySector = view.getUint32(48, true);
20987
20997
  const miniStreamCutoff = view.getUint32(56, true);
@@ -20989,6 +20999,9 @@ function parseOle2(buffer) {
20989
20999
  const totalMiniFATSectors = view.getUint32(64, true);
20990
21000
  const firstDIFATSector = view.getUint32(68, true);
20991
21001
  const totalDIFATSectors = view.getUint32(72, true);
21002
+ if (totalFATSectors > sectorCount || totalMiniFATSectors > sectorCount || totalDIFATSectors > sectorCount) {
21003
+ throw new exports.Ole2ParseError("Allocation table count exceeds file size");
21004
+ }
20992
21005
  function sectorOffset(sector) {
20993
21006
  return (sector + 1) * sectorSize;
20994
21007
  }
@@ -21007,7 +21020,11 @@ function parseOle2(buffer) {
21007
21020
  }
21008
21021
  }
21009
21022
  let difatSector = firstDIFATSector;
21023
+ const difatSeen = /* @__PURE__ */ new Set();
21010
21024
  for (let d = 0; d < totalDIFATSectors && difatSector <= MAXREGSECT; d++) {
21025
+ if (difatSeen.has(difatSector))
21026
+ throw new exports.Ole2ParseError("Circular DIFAT chain");
21027
+ difatSeen.add(difatSector);
21011
21028
  const difatData = readSector(difatSector);
21012
21029
  const difatView = new DataView(difatData.buffer, difatData.byteOffset, difatData.byteLength);
21013
21030
  const entriesPerSector = (sectorSize - 4) / 4;
@@ -21019,11 +21036,14 @@ function parseOle2(buffer) {
21019
21036
  }
21020
21037
  difatSector = difatView.getUint32(sectorSize - 4, true);
21021
21038
  }
21039
+ if (difatSeen.size !== totalDIFATSectors || fatSectors.length !== totalFATSectors || new Set(fatSectors).size !== fatSectors.length || fatSectors.some((id) => difatSeen.has(id))) {
21040
+ throw new exports.Ole2ParseError("Invalid DIFAT allocation table");
21041
+ }
21022
21042
  const fatEntries = [];
21023
21043
  for (const fatSector of fatSectors) {
21024
21044
  const fatData = readSector(fatSector);
21025
21045
  const fatView = new DataView(fatData.buffer, fatData.byteOffset, fatData.byteLength);
21026
- for (let i2 = 0; i2 < sectorSize / 4; i2++) {
21046
+ for (let i2 = 0; i2 < sectorSize / 4 && fatEntries.length < sectorCount; i2++) {
21027
21047
  fatEntries.push(fatView.getUint32(i2 * 4, true));
21028
21048
  }
21029
21049
  }
@@ -21037,8 +21057,12 @@ function parseOle2(buffer) {
21037
21057
  }
21038
21058
  visited.add(current);
21039
21059
  sectors.push(readSector(current));
21040
- current = fatEntries[current] ?? ENDOFCHAIN;
21060
+ if (fatEntries[current] === void 0)
21061
+ throw new exports.Ole2ParseError("Missing FAT chain entry");
21062
+ current = fatEntries[current];
21041
21063
  }
21064
+ if (current !== ENDOFCHAIN)
21065
+ throw new exports.Ole2ParseError("Invalid FAT chain terminator");
21042
21066
  const totalLength = sectors.length * sectorSize;
21043
21067
  const result = new Uint8Array(totalLength);
21044
21068
  let offset = 0;
@@ -21049,16 +21073,14 @@ function parseOle2(buffer) {
21049
21073
  return result;
21050
21074
  }
21051
21075
  function readStream(startSector, size) {
21076
+ if (size === 0)
21077
+ return new Uint8Array(0);
21078
+ if (size > sectorCount * sectorSize)
21079
+ throw new exports.Ole2ParseError("Stream size exceeds file size");
21052
21080
  const raw = readSectorChain(startSector);
21053
- return raw.subarray(0, Math.min(size, raw.length));
21054
- }
21055
- const miniFatEntries = [];
21056
- if (firstMiniFATSector <= MAXREGSECT && totalMiniFATSectors > 0) {
21057
- const miniFatRaw = readSectorChain(firstMiniFATSector);
21058
- const miniFatView = new DataView(miniFatRaw.buffer, miniFatRaw.byteOffset, miniFatRaw.byteLength);
21059
- for (let i2 = 0; i2 < miniFatRaw.length / 4; i2++) {
21060
- miniFatEntries.push(miniFatView.getUint32(i2 * 4, true));
21061
- }
21081
+ if (raw.length < size)
21082
+ throw new exports.Ole2ParseError("Truncated stream sector chain");
21083
+ return raw.subarray(0, size);
21062
21084
  }
21063
21085
  const dirRaw = readSectorChain(firstDirectorySector);
21064
21086
  const numEntries = Math.floor(dirRaw.length / DIR_ENTRY_SIZE);
@@ -21071,6 +21093,9 @@ function parseOle2(buffer) {
21071
21093
  if (objectType === ENTRY_TYPE_EMPTY) {
21072
21094
  continue;
21073
21095
  }
21096
+ if (nameLen < 2 || nameLen > 64 || nameLen % 2 !== 0 || entryView.getUint16(nameLen - 2, true) !== 0) {
21097
+ throw new exports.Ole2ParseError("Invalid directory entry name");
21098
+ }
21074
21099
  const nameBytes = Math.max(0, nameLen - 2);
21075
21100
  let name = "";
21076
21101
  for (let j = 0; j < nameBytes; j += 2) {
@@ -21084,8 +21109,11 @@ function parseOle2(buffer) {
21084
21109
  const sizeLow = entryView.getUint32(120, true);
21085
21110
  let size = sizeLow;
21086
21111
  if (majorVersion === 4) {
21087
- entryView.getUint32(124, true);
21088
- size = sizeLow;
21112
+ const sizeHigh = entryView.getUint32(124, true);
21113
+ size = sizeLow + sizeHigh * 4294967296;
21114
+ if (!Number.isSafeInteger(size) || size > sectorCount * sectorSize) {
21115
+ throw new exports.Ole2ParseError("Stream size exceeds supported file bounds");
21116
+ }
21089
21117
  }
21090
21118
  entries.push({
21091
21119
  name,
@@ -21099,11 +21127,28 @@ function parseOle2(buffer) {
21099
21127
  });
21100
21128
  }
21101
21129
  const rootEntry = entries.find((e) => e.type === ENTRY_TYPE_ROOT);
21130
+ if (!rootEntry || entries.filter((e) => e.type === ENTRY_TYPE_ROOT).length !== 1) {
21131
+ throw new exports.Ole2ParseError("Invalid root directory entry");
21132
+ }
21102
21133
  let miniStreamData;
21103
21134
  if (rootEntry && rootEntry.startSector <= MAXREGSECT) {
21104
- miniStreamData = readSectorChain(rootEntry.startSector);
21135
+ miniStreamData = readStream(rootEntry.startSector, rootEntry.size);
21136
+ }
21137
+ const miniFatEntries = [];
21138
+ if (firstMiniFATSector <= MAXREGSECT && totalMiniFATSectors > 0) {
21139
+ const miniFatRaw = readSectorChain(firstMiniFATSector);
21140
+ if (miniFatRaw.length !== totalMiniFATSectors * sectorSize) {
21141
+ throw new exports.Ole2ParseError("Unexpected mini FAT chain length");
21142
+ }
21143
+ const miniFatView = new DataView(miniFatRaw.buffer, miniFatRaw.byteOffset, miniFatRaw.byteLength);
21144
+ const miniCapacity = Math.floor((miniStreamData?.length ?? 0) / miniSectorSize);
21145
+ for (let i2 = 0; i2 < miniFatRaw.length / 4 && i2 < miniCapacity; i2++) {
21146
+ miniFatEntries.push(miniFatView.getUint32(i2 * 4, true));
21147
+ }
21105
21148
  }
21106
21149
  function readMiniStream(startSector, size) {
21150
+ if (size === 0)
21151
+ return new Uint8Array(0);
21107
21152
  if (!miniStreamData) {
21108
21153
  throw new exports.Ole2ParseError("Mini stream container not found");
21109
21154
  }
@@ -21116,17 +21161,24 @@ function parseOle2(buffer) {
21116
21161
  }
21117
21162
  visited.add(current);
21118
21163
  const offset2 = current * miniSectorSize;
21164
+ if (offset2 + miniSectorSize > miniStreamData.length || miniFatEntries[current] === void 0) {
21165
+ throw new exports.Ole2ParseError("Mini stream sector exceeds allocation bounds");
21166
+ }
21119
21167
  sectors.push(miniStreamData.subarray(offset2, offset2 + miniSectorSize));
21120
- current = miniFatEntries[current] ?? ENDOFCHAIN;
21168
+ current = miniFatEntries[current];
21121
21169
  }
21170
+ if (current !== ENDOFCHAIN)
21171
+ throw new exports.Ole2ParseError("Invalid mini FAT chain terminator");
21122
21172
  const totalLength = sectors.length * miniSectorSize;
21173
+ if (totalLength < size)
21174
+ throw new exports.Ole2ParseError("Truncated mini stream sector chain");
21123
21175
  const result = new Uint8Array(totalLength);
21124
21176
  let offset = 0;
21125
21177
  for (const sector of sectors) {
21126
21178
  result.set(sector, offset);
21127
21179
  offset += miniSectorSize;
21128
21180
  }
21129
- return result.subarray(0, Math.min(size, result.length));
21181
+ return result.subarray(0, size);
21130
21182
  }
21131
21183
  function getStream(name) {
21132
21184
  const entry = entries.find((e) => (e.type === ENTRY_TYPE_STREAM || e.type === ENTRY_TYPE_ROOT) && e.name === name);
@@ -21141,7 +21193,7 @@ function parseOle2(buffer) {
21141
21193
  return { entries, getStream };
21142
21194
  }
21143
21195
  var init_ole2_parser_read = __esm({
21144
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-read.js"() {
21196
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-read.js"() {
21145
21197
  init_ole2_parser_types();
21146
21198
  }
21147
21199
  });
@@ -21281,13 +21333,16 @@ var init_ole_embedded_extract = __esm({
21281
21333
  }
21282
21334
  });
21283
21335
 
21284
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-helpers.js
21336
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-helpers.js
21285
21337
  function compareDirEntryNames(a, b) {
21338
+ const ua = a.toUpperCase();
21339
+ const ub = b.toUpperCase();
21340
+ if (ua.length !== a.length || ub.length !== b.length) {
21341
+ throw new Error("CFB stream names with expanding uppercase mappings are unsupported");
21342
+ }
21286
21343
  if (a.length !== b.length) {
21287
21344
  return a.length - b.length;
21288
21345
  }
21289
- const ua = a.toUpperCase();
21290
- const ub = b.toUpperCase();
21291
21346
  for (let i2 = 0; i2 < ua.length; i2++) {
21292
21347
  const diff = ua.charCodeAt(i2) - ub.charCodeAt(i2);
21293
21348
  if (diff !== 0) {
@@ -21304,6 +21359,24 @@ function encodeName(name) {
21304
21359
  }
21305
21360
  return bytes;
21306
21361
  }
21362
+ function buildDirectoryTree(entryCount) {
21363
+ const links = /* @__PURE__ */ new Map();
21364
+ let redLevel = 0;
21365
+ for (let remaining = entryCount - 2; remaining >= 0; remaining = Math.floor(remaining / 2) - 1)
21366
+ redLevel++;
21367
+ const build = (low, high, level2) => {
21368
+ if (low > high)
21369
+ return 4294967295;
21370
+ const id = Math.floor((low + high) / 2);
21371
+ links.set(id, {
21372
+ left: build(low, id - 1, level2 + 1),
21373
+ right: build(id + 1, high, level2 + 1),
21374
+ color: level2 === redLevel ? 0 : 1
21375
+ });
21376
+ return id;
21377
+ };
21378
+ return { root: build(1, entryCount - 1, 0), links };
21379
+ }
21307
21380
  function writeFatChain(fat, chain2) {
21308
21381
  for (let i2 = 0; i2 < chain2.sectors.length; i2++) {
21309
21382
  fat[chain2.sectors[i2]] = i2 < chain2.sectors.length - 1 ? chain2.sectors[i2 + 1] : ENDOFCHAIN;
@@ -21327,12 +21400,12 @@ function writeInt32Sectors(outBytes, int32Data, firstSector, numSectors, sectorS
21327
21400
  }
21328
21401
  }
21329
21402
  var init_ole2_parser_write_helpers = __esm({
21330
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-helpers.js"() {
21403
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-helpers.js"() {
21331
21404
  init_ole2_parser_types();
21332
21405
  }
21333
21406
  });
21334
21407
 
21335
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-serialize.js
21408
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-serialize.js
21336
21409
  function writeHeader(outView, outBytes, params) {
21337
21410
  outBytes.set(OLE_MAGIC, 0);
21338
21411
  outView.setUint16(24, 62, true);
@@ -21389,6 +21462,7 @@ function writeDifatSectors(outView, params) {
21389
21462
  function serializeDirectoryEntries(dirEntries, numDirSectors, sectorSize) {
21390
21463
  const dirData = new Uint8Array(numDirSectors * sectorSize);
21391
21464
  const dirView = new DataView(dirData.buffer);
21465
+ const tree = buildDirectoryTree(dirEntries.length);
21392
21466
  for (let i2 = 0; i2 < dirEntries.length; i2++) {
21393
21467
  const entry = dirEntries[i2];
21394
21468
  const entryOffset = i2 * DIR_ENTRY_SIZE;
@@ -21396,17 +21470,17 @@ function serializeDirectoryEntries(dirEntries, numDirSectors, sectorSize) {
21396
21470
  dirData.set(nameBytes.subarray(0, Math.min(nameBytes.length, 64)), entryOffset);
21397
21471
  dirView.setUint16(entryOffset + 64, Math.min((entry.name.length + 1) * 2, 64), true);
21398
21472
  dirData[entryOffset + 66] = entry.type;
21399
- dirData[entryOffset + 67] = 1;
21473
+ dirData[entryOffset + 67] = i2 === 0 ? 1 : tree.links.get(i2).color;
21400
21474
  if (entry.clsid) {
21401
21475
  dirData.set(entry.clsid.subarray(0, 16), entryOffset + 80);
21402
21476
  }
21403
21477
  if (i2 === 0) {
21404
21478
  dirView.setUint32(entryOffset + 68, 4294967295, true);
21405
21479
  dirView.setUint32(entryOffset + 72, 4294967295, true);
21406
- dirView.setUint32(entryOffset + 76, dirEntries.length > 1 ? 1 : 4294967295, true);
21480
+ dirView.setUint32(entryOffset + 76, tree.root, true);
21407
21481
  } else {
21408
- dirView.setUint32(entryOffset + 68, 4294967295, true);
21409
- dirView.setUint32(entryOffset + 72, i2 + 1 < dirEntries.length ? i2 + 1 : 4294967295, true);
21482
+ dirView.setUint32(entryOffset + 68, tree.links.get(i2).left, true);
21483
+ dirView.setUint32(entryOffset + 72, tree.links.get(i2).right, true);
21410
21484
  dirView.setUint32(entryOffset + 76, 4294967295, true);
21411
21485
  }
21412
21486
  dirView.setUint32(entryOffset + 116, entry.startSector, true);
@@ -21424,17 +21498,32 @@ function writeStreamSectors(outBytes, streamData, chain2, sectorSize) {
21424
21498
  }
21425
21499
  var HEADER_DIFAT_ENTRIES;
21426
21500
  var init_ole2_parser_write_serialize = __esm({
21427
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-serialize.js"() {
21501
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-serialize.js"() {
21428
21502
  init_ole2_parser_types();
21429
21503
  init_ole2_parser_write_helpers();
21430
21504
  HEADER_DIFAT_ENTRIES = 109;
21431
21505
  }
21432
21506
  });
21433
21507
 
21434
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-write.js
21508
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-write.js
21435
21509
  function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
21436
21510
  const sectorSize = 512;
21437
21511
  const miniSectorSize = 64;
21512
+ if (rootClsid && rootClsid.length !== 16)
21513
+ throw new Error("Root CLSID must contain 16 bytes");
21514
+ const names = [...streams2.keys()].sort(compareDirEntryNames);
21515
+ for (let i2 = 0; i2 < names.length; i2++) {
21516
+ const name = names[i2];
21517
+ if (name.toUpperCase().length !== name.length) {
21518
+ throw new Error("CFB stream names with expanding uppercase mappings are unsupported");
21519
+ }
21520
+ if (!name.length || name.length > 31 || /[\x00\\/:!]/.test(name)) {
21521
+ throw new Error("CFB stream names must be 1-31 UTF-16 code units without NUL, \\, /, :, or !");
21522
+ }
21523
+ if (i2 > 0 && compareDirEntryNames(names[i2 - 1], name) === 0) {
21524
+ throw new Error("Duplicate CFB stream names");
21525
+ }
21526
+ }
21438
21527
  const regularStreams = [];
21439
21528
  const miniStreams = [];
21440
21529
  for (const [name, data] of streams2) {
@@ -21452,7 +21541,7 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
21452
21541
  for (let i2 = 0; i2 < numSectors; i2++) {
21453
21542
  sectors.push(nextSector++);
21454
21543
  }
21455
- fatChains.set(stream.name, { start: sectors[0] ?? 0, sectors });
21544
+ fatChains.set(stream.name, { start: sectors[0] ?? ENDOFCHAIN, sectors });
21456
21545
  }
21457
21546
  let miniStreamContainer = new Uint8Array(0);
21458
21547
  const miniFatChains = /* @__PURE__ */ new Map();
@@ -21475,7 +21564,7 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
21475
21564
  miniOffset += miniSectorSize;
21476
21565
  }
21477
21566
  miniFatChains.set(stream.name, {
21478
- start: miniSectors[0] ?? 0,
21567
+ start: miniSectors[0] ?? ENDOFCHAIN,
21479
21568
  sectors: miniSectors
21480
21569
  });
21481
21570
  }
@@ -21523,7 +21612,7 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
21523
21612
  nextSector += numDirSectors;
21524
21613
  let firstMiniFATSector = ENDOFCHAIN;
21525
21614
  let numMiniFATSectors = 0;
21526
- if (miniStreams.length > 0) {
21615
+ if (nextMiniSector > 0) {
21527
21616
  numMiniFATSectors = Math.ceil(nextMiniSector * 4 / sectorSize);
21528
21617
  firstMiniFATSector = nextSector;
21529
21618
  nextSector += numMiniFATSectors;
@@ -21597,7 +21686,7 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
21597
21686
  return output;
21598
21687
  }
21599
21688
  var init_ole2_parser_write = __esm({
21600
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-write.js"() {
21689
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-write.js"() {
21601
21690
  init_ole2_parser_types();
21602
21691
  init_ole2_parser_write_helpers();
21603
21692
  init_ole2_parser_write_serialize();
@@ -22313,7 +22402,7 @@ var init_ole_sheet_xlsx_editor = __esm({
22313
22402
  }
22314
22403
  });
22315
22404
 
22316
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-stream-edit.js
22405
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-edit.js
22317
22406
  function chain(table, start, limit) {
22318
22407
  if (start === END && limit === 0)
22319
22408
  return [];
@@ -22392,7 +22481,7 @@ function processCompoundFileStream(input, path, replacement) {
22392
22481
  const fat = [];
22393
22482
  for (const id of fatIds) {
22394
22483
  const bytes = sector(id), dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
22395
- for (let j = 0; j < sectorSize / 4; j++)
22484
+ for (let j = 0; j < sectorSize / 4 && fat.length < sectorCount; j++)
22396
22485
  fat.push(dv.getUint32(j * 4, true));
22397
22486
  }
22398
22487
  const exactChain = (table, start, bytes, unit) => chain(table, start, Math.ceil(bytes / unit));
@@ -22489,9 +22578,10 @@ function processCompoundFileStream(input, path, replacement) {
22489
22578
  if (new Set(metadataSectors).size !== metadataSectors.length)
22490
22579
  return reject();
22491
22580
  const miniFat = [];
22581
+ const miniCapacity = Math.floor(Math.min(root.size, sectorCount * sectorSize) / miniSize);
22492
22582
  for (const id of miniFatSectors) {
22493
22583
  const bytes = sector(id), dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
22494
- for (let j = 0; j < sectorSize / 4; j++)
22584
+ for (let j = 0; j < sectorSize / 4 && miniFat.length < miniCapacity; j++)
22495
22585
  miniFat.push(dv.getUint32(j * 4, true));
22496
22586
  }
22497
22587
  const reserved = /* @__PURE__ */ new Set([...fatIds, ...difatIds, ...dirSectors, ...miniFatSectors]);
@@ -22515,7 +22605,7 @@ function processCompoundFileStream(input, path, replacement) {
22515
22605
  continue;
22516
22606
  const ids = exactChain(miniFat, entry.start, entry.size, miniSize);
22517
22607
  for (const id of ids) {
22518
- if (id * miniSize >= rootMini.size || miniUsed.has(id))
22608
+ if ((id + 1) * miniSize > rootMini.size || miniUsed.has(id))
22519
22609
  return reject();
22520
22610
  miniUsed.add(id);
22521
22611
  }
@@ -22540,6 +22630,8 @@ function processCompoundFileStream(input, path, replacement) {
22540
22630
  });
22541
22631
  return result.slice(0, target.size);
22542
22632
  }
22633
+ if (replacement.length === 0)
22634
+ return input.slice();
22543
22635
  const output = input.slice();
22544
22636
  if (target.size >= miniCutoff) {
22545
22637
  const sectors = exactChain(fat, target.start, target.size, sectorSize);
@@ -22580,7 +22672,7 @@ function replaceCompoundFileStream(input, path, replacement) {
22580
22672
  }
22581
22673
  var END, MAX, NIL, SIZE;
22582
22674
  var init_ole2_stream_edit = __esm({
22583
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-stream-edit.js"() {
22675
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-edit.js"() {
22584
22676
  END = 4294967294;
22585
22677
  MAX = 4294967290;
22586
22678
  NIL = 4294967295;
@@ -22588,7 +22680,7 @@ var init_ole2_stream_edit = __esm({
22588
22680
  }
22589
22681
  });
22590
22682
 
22591
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-cfb.js
22683
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-cfb.js
22592
22684
  function unwrapXlsBytes(bytes) {
22593
22685
  if (!isCfb(bytes)) {
22594
22686
  return { workbookBytes: bytes };
@@ -22655,7 +22747,7 @@ function isCfb(bytes) {
22655
22747
  }
22656
22748
  var WORKBOOK_STREAM_NAMES;
22657
22749
  var init_legacy_excel_cfb = __esm({
22658
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-cfb.js"() {
22750
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-cfb.js"() {
22659
22751
  init_ole2_parser_read();
22660
22752
  init_ole2_parser_types();
22661
22753
  init_ole2_parser_write();
@@ -22664,7 +22756,178 @@ var init_legacy_excel_cfb = __esm({
22664
22756
  }
22665
22757
  });
22666
22758
 
22667
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8.js
22759
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-edit.js
22760
+ function encodeRkExact(value) {
22761
+ if (!Number.isFinite(value))
22762
+ return void 0;
22763
+ for (const scale of [1, 100]) {
22764
+ const scaled = value * scale;
22765
+ if (Number.isInteger(scaled) && scaled >= -536870912 && scaled < 536870912) {
22766
+ const rk2 = (scaled << 2 | 2 | (scale === 100 ? 1 : 0)) >>> 0;
22767
+ if (Object.is(decodeRk(rk2), value))
22768
+ return rk2;
22769
+ }
22770
+ const view = new DataView(new ArrayBuffer(8));
22771
+ view.setFloat64(0, scaled, true);
22772
+ const rk = (view.getUint32(4, true) & 4294967292 | (scale === 100 ? 1 : 0)) >>> 0;
22773
+ if (Object.is(decodeRk(rk), value))
22774
+ return rk;
22775
+ }
22776
+ return void 0;
22777
+ }
22778
+ function worksheetRanges(bytes) {
22779
+ const records = readRecords(bytes, 0, bytes.length);
22780
+ const last = records.at(-1);
22781
+ if (!last || bytes.subarray(last.dataOffset + last.length).some((b) => b !== 0))
22782
+ return void 0;
22783
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
22784
+ const ranges = [];
22785
+ let depth = 0;
22786
+ let start;
22787
+ for (const record2 of records) {
22788
+ if (record2.opcode === 2057) {
22789
+ if (record2.length < 4 || view.getUint16(record2.dataOffset, true) !== 1536 || depth >= 64)
22790
+ return void 0;
22791
+ if (depth === 0 && view.getUint16(record2.dataOffset + 2, true) === 16)
22792
+ start = record2.headerOffset;
22793
+ depth++;
22794
+ } else if (record2.opcode === 10) {
22795
+ if (depth === 0 || record2.length !== 0)
22796
+ return void 0;
22797
+ depth--;
22798
+ if (depth === 0 && start !== void 0) {
22799
+ ranges.push({ start, end: record2.dataOffset });
22800
+ start = void 0;
22801
+ }
22802
+ }
22803
+ }
22804
+ if (depth !== 0)
22805
+ return void 0;
22806
+ const globalsEnd = records.find((r) => r.opcode === 10)?.headerOffset ?? 0;
22807
+ const bounds = records.filter((r) => r.opcode === 133 && r.headerOffset < globalsEnd);
22808
+ if (bounds.length === 0)
22809
+ return ranges;
22810
+ const ordered4 = [];
22811
+ const used = /* @__PURE__ */ new Set();
22812
+ for (const bound of bounds) {
22813
+ if (bound.length < 8)
22814
+ return void 0;
22815
+ const p = bound.dataOffset;
22816
+ const nameLength = view.getUint8(p + 6);
22817
+ const width = view.getUint8(p + 7) & 1 ? 2 : 1;
22818
+ if (nameLength < 1 || nameLength > 31 || bound.length !== 8 + nameLength * width)
22819
+ return void 0;
22820
+ const kind = view.getUint8(p + 5);
22821
+ if (![0, 1, 2, 6].includes(kind))
22822
+ return void 0;
22823
+ if (kind !== 0)
22824
+ continue;
22825
+ const offset = view.getUint32(p, true);
22826
+ const range = ranges.find((r) => r.start === offset);
22827
+ if (!range || used.has(offset))
22828
+ return void 0;
22829
+ used.add(offset);
22830
+ ordered4.push(range);
22831
+ }
22832
+ return ordered4.length === ranges.length ? ordered4 : void 0;
22833
+ }
22834
+ function editXlsNumericCell(input, edit) {
22835
+ const unchanged2 = (reason) => ({ status: "unchanged", bytes: input, reason });
22836
+ const sheet = edit.worksheetIndex ?? 0;
22837
+ 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))
22838
+ return unchanged2("invalid-edit");
22839
+ try {
22840
+ const { workbookBytes: bytes, rewrap } = unwrapXlsBytes(input);
22841
+ if (!isSupportedBiff8Workbook(bytes))
22842
+ return unchanged2("unsupported-workbook");
22843
+ const ranges = worksheetRanges(bytes);
22844
+ if (!ranges)
22845
+ return unchanged2("malformed-records");
22846
+ const range = ranges[sheet];
22847
+ if (!range)
22848
+ return unchanged2("sheet-not-found");
22849
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
22850
+ let payload;
22851
+ let packed = false;
22852
+ let depth = 0;
22853
+ let matches = 0;
22854
+ for (const record2 of readRecords(bytes, range.start, range.end)) {
22855
+ if (record2.opcode === 2057) {
22856
+ depth++;
22857
+ continue;
22858
+ }
22859
+ if (record2.opcode === 10) {
22860
+ depth--;
22861
+ continue;
22862
+ }
22863
+ if (depth !== 1)
22864
+ continue;
22865
+ const p = record2.dataOffset;
22866
+ if (record2.opcode === 189) {
22867
+ if (record2.length < 12 || (record2.length - 6) % 6 !== 0)
22868
+ return unchanged2("malformed-records");
22869
+ const first = view.getUint16(p + 2, true);
22870
+ const lastCol = view.getUint16(p + record2.length - 2, true);
22871
+ if (lastCol > 255 || lastCol < first || lastCol - first + 1 !== (record2.length - 6) / 6)
22872
+ return unchanged2("malformed-records");
22873
+ if (view.getUint16(p, true) === edit.row && edit.col >= first && edit.col <= lastCol) {
22874
+ if (++matches > 1)
22875
+ return unchanged2("ambiguous-cell");
22876
+ payload = p + 6 + (edit.col - first) * 6;
22877
+ packed = true;
22878
+ }
22879
+ } else if (record2.opcode === 515 || record2.opcode === 638) {
22880
+ if (record2.length !== (record2.opcode === 515 ? 14 : 10))
22881
+ return unchanged2("malformed-records");
22882
+ if (view.getUint16(p, true) === edit.row && view.getUint16(p + 2, true) === edit.col) {
22883
+ if (++matches > 1)
22884
+ return unchanged2("ambiguous-cell");
22885
+ payload = p + 6;
22886
+ packed = record2.opcode === 638;
22887
+ }
22888
+ } else if ([6, 513, 516, 517, 253, 214].includes(record2.opcode)) {
22889
+ if (record2.length < 6)
22890
+ return unchanged2("malformed-records");
22891
+ if (view.getUint16(p, true) === edit.row && view.getUint16(p + 2, true) === edit.col && ++matches > 1)
22892
+ return unchanged2("ambiguous-cell");
22893
+ } else if (record2.opcode === 190) {
22894
+ if (record2.length < 8 || (record2.length - 6) % 2 !== 0)
22895
+ return unchanged2("malformed-records");
22896
+ const first = view.getUint16(p + 2, true);
22897
+ const lastCol = view.getUint16(p + record2.length - 2, true);
22898
+ if (lastCol > 255 || lastCol < first || lastCol - first + 1 !== (record2.length - 6) / 2)
22899
+ return unchanged2("malformed-records");
22900
+ if (view.getUint16(p, true) === edit.row && edit.col >= first && edit.col <= lastCol && ++matches > 1)
22901
+ return unchanged2("ambiguous-cell");
22902
+ }
22903
+ }
22904
+ if (payload === void 0)
22905
+ return unchanged2("cell-not-supported");
22906
+ const rk = packed ? encodeRkExact(edit.value) : void 0;
22907
+ if (packed && rk === void 0)
22908
+ return unchanged2("inexact-rk");
22909
+ const out = bytes.slice();
22910
+ const outView = new DataView(out.buffer, out.byteOffset, out.byteLength);
22911
+ if (packed)
22912
+ outView.setUint32(payload, rk, true);
22913
+ else
22914
+ outView.setFloat64(payload, edit.value, true);
22915
+ const result = rewrap ? rewrap(out) : out;
22916
+ if (result === input)
22917
+ return unchanged2("container-not-writable");
22918
+ return { status: "edited", bytes: result, recalculationRequired: true };
22919
+ } catch {
22920
+ return unchanged2("malformed-records");
22921
+ }
22922
+ }
22923
+ var init_legacy_excel_biff8_edit = __esm({
22924
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-edit.js"() {
22925
+ init_legacy_excel_biff8();
22926
+ init_legacy_excel_cfb();
22927
+ }
22928
+ });
22929
+
22930
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8.js
22668
22931
  function readRecords(bytes, start, end) {
22669
22932
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
22670
22933
  const records = [];
@@ -22718,7 +22981,7 @@ function findFirstWorksheetRange(bytes) {
22718
22981
  function parseSstSingleRecord(bytes) {
22719
22982
  const records = readRecords(bytes, 0, bytes.length);
22720
22983
  const sst = records.find((r) => r.opcode === OPCODE_SST);
22721
- if (!sst) {
22984
+ if (!sst || sst.length < 8) {
22722
22985
  return [];
22723
22986
  }
22724
22987
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
@@ -22726,7 +22989,8 @@ function parseSstSingleRecord(bytes) {
22726
22989
  let offset = sst.dataOffset + 8;
22727
22990
  const end = sst.dataOffset + sst.length;
22728
22991
  try {
22729
- while (offset + 3 <= end) {
22992
+ const unique = view.getUint32(sst.dataOffset + 4, true);
22993
+ while (strings2.length < unique && offset + 3 <= end) {
22730
22994
  const charCount = view.getUint16(offset, true);
22731
22995
  const flags = view.getUint8(offset + 2);
22732
22996
  offset += 3;
@@ -22736,13 +23000,19 @@ function parseSstSingleRecord(bytes) {
22736
23000
  let richRuns = 0;
22737
23001
  let extLen = 0;
22738
23002
  if (isRich) {
23003
+ if (offset + 2 > end)
23004
+ break;
22739
23005
  richRuns = view.getUint16(offset, true);
22740
23006
  offset += 2;
22741
23007
  }
22742
23008
  if (hasExt) {
23009
+ if (offset + 4 > end)
23010
+ break;
22743
23011
  extLen = view.getUint32(offset, true);
22744
23012
  offset += 4;
22745
23013
  }
23014
+ if (offset + charCount * (isWide ? 2 : 1) + richRuns * 4 + extLen > end)
23015
+ break;
22746
23016
  let text2 = "";
22747
23017
  for (let i2 = 0; i2 < charCount; i2++) {
22748
23018
  if (isWide) {
@@ -22823,52 +23093,13 @@ function decodeRk(rk) {
22823
23093
  }
22824
23094
  return isDiv100 ? value / 100 : value;
22825
23095
  }
22826
- function encodeRk(value) {
22827
- if (Number.isInteger(value) && Math.abs(value) < 536870912) {
22828
- return (value << 2 | 2) >>> 0;
22829
- }
22830
- const buffer = new ArrayBuffer(8);
22831
- const view = new DataView(buffer);
22832
- view.setFloat64(0, value, false);
22833
- const high32 = view.getUint32(0, false);
22834
- return high32 & 4294967292;
22835
- }
22836
23096
  function writeOleXlsNumericCellEdit(inputBytes, edit) {
22837
- if (!Number.isFinite(edit.value)) {
22838
- return inputBytes;
22839
- }
22840
- const { workbookBytes: xlsBytes, rewrap } = unwrapXlsBytes(inputBytes);
22841
- if (!isSupportedBiff8Workbook(xlsBytes))
22842
- return inputBytes;
22843
- const range = findFirstWorksheetRange(xlsBytes);
22844
- if (!range) {
22845
- return inputBytes;
22846
- }
22847
- const out = new Uint8Array(xlsBytes);
22848
- const view = new DataView(out.buffer, out.byteOffset, out.byteLength);
22849
- for (const record2 of readRecords(out, range.start, range.end)) {
22850
- if (record2.length < 6) {
22851
- continue;
22852
- }
22853
- const row = view.getUint16(record2.dataOffset, true);
22854
- const col = view.getUint16(record2.dataOffset + 2, true);
22855
- if (row !== edit.row || col !== edit.col) {
22856
- continue;
22857
- }
22858
- if (record2.opcode === OPCODE_NUMBER && record2.length >= 14) {
22859
- view.setFloat64(record2.dataOffset + 6, edit.value, true);
22860
- return rewrap ? rewrap(out) : out;
22861
- }
22862
- if (record2.opcode === OPCODE_RK && record2.length >= 10) {
22863
- view.setInt32(record2.dataOffset + 6, encodeRk(edit.value), true);
22864
- return rewrap ? rewrap(out) : out;
22865
- }
22866
- }
22867
- return inputBytes;
23097
+ return editXlsNumericCell(inputBytes, edit).bytes;
22868
23098
  }
22869
23099
  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;
22870
23100
  var init_legacy_excel_biff8 = __esm({
22871
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8.js"() {
23101
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8.js"() {
23102
+ init_legacy_excel_biff8_edit();
22872
23103
  init_legacy_excel_cfb();
22873
23104
  OPCODE_BOF = 2057;
22874
23105
  OPCODE_EOF = 10;
@@ -22897,7 +23128,7 @@ var init_ole_sheet_xls_biff8 = __esm({
22897
23128
  }
22898
23129
  });
22899
23130
 
22900
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-grid.js
23131
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-grid.js
22901
23132
  function biffRecord(opcode, data) {
22902
23133
  return [
22903
23134
  opcode & 255,
@@ -22970,7 +23201,7 @@ function buildXlsRowCellRegion(grid) {
22970
23201
  const colFirst = cols[0] ?? 0;
22971
23202
  const colLast = cols.length > 0 ? cols[cols.length - 1] + 1 : 0;
22972
23203
  rowRecordOffsets.push(bytesOut.length);
22973
- const extra = row.extraRowBytes ?? [255, 0, 0, 0, 0, 1, 15, 0];
23204
+ const extra = row.extraRowBytes ?? [255, 0, 0, 0, 0, 1, 15, 0, 0, 0];
22974
23205
  bytesOut.push(...biffRecord(OPCODE_ROW, [...u16le(r), ...u16le(colFirst), ...u16le(colLast), ...extra]));
22975
23206
  }
22976
23207
  for (const r of rows) {
@@ -23005,8 +23236,12 @@ function buildXlsRowCellRegion(grid) {
23005
23236
  if (rows.length > 0) {
23006
23237
  const dbCellOffset = bytesOut.length;
23007
23238
  const dbData = [0, 0, 0, 0];
23008
- for (const off of firstCellOffsetPerRow) {
23009
- dbData.push(...u16le(dbCellOffset - off));
23239
+ for (let i2 = 0; i2 < firstCellOffsetPerRow.length; i2++) {
23240
+ const base = i2 === 0 ? rowRecordOffsets[0] + 20 : firstCellOffsetPerRow[i2 - 1];
23241
+ const offset = firstCellOffsetPerRow[i2] - base;
23242
+ if (offset < 0 || offset > 65535)
23243
+ throw new Error("DBCELL offset exceeds UInt16");
23244
+ dbData.push(...u16le(offset));
23010
23245
  }
23011
23246
  const backToFirstRow = dbCellOffset - rowRecordOffsets[0];
23012
23247
  dbData[0] = backToFirstRow & 255;
@@ -23018,28 +23253,39 @@ function buildXlsRowCellRegion(grid) {
23018
23253
  return Uint8Array.from(bytesOut);
23019
23254
  }
23020
23255
  var init_legacy_excel_biff8_grid = __esm({
23021
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-grid.js"() {
23256
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-grid.js"() {
23022
23257
  init_legacy_excel_biff8();
23023
23258
  }
23024
23259
  });
23025
23260
 
23026
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-writer.js
23027
- function resolveSstIndex(sharedStrings, value) {
23261
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-writer.js
23262
+ function resolveSstIndex(sharedStrings, value, bytes) {
23028
23263
  const existing = sharedStrings.indexOf(value);
23029
- if (existing !== -1) {
23264
+ if (existing !== -1)
23030
23265
  return { index: existing };
23031
- }
23032
- const next = [...sharedStrings, value];
23033
- const data = [];
23034
- data.push(...u16le(next.length & 65535), 0, 0);
23035
- data.push(...u16le(next.length & 65535), 0, 0);
23036
- for (const s of next) {
23037
- data.push(...u16le(s.length), 0);
23038
- for (const ch of s) {
23039
- data.push(ch.charCodeAt(0) & 255);
23040
- }
23041
- }
23042
- return { index: next.length - 1, rebuilt: biffRecord(OPCODE_SST, data) };
23266
+ const records = readRecords(bytes, 0, bytes.length);
23267
+ const sst = records.find((r) => r.opcode === OPCODE_SST);
23268
+ if (!sst || sst.length < 8 || value.length > 32767)
23269
+ throw new Error("Unsupported SST");
23270
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
23271
+ const unique = view.getUint32(sst.dataOffset + 4, true);
23272
+ if (unique !== sharedStrings.length || records[records.indexOf(sst) + 1]?.opcode === 60)
23273
+ throw new Error("Continued or incomplete SST");
23274
+ const data = Array.from(bytes.subarray(sst.dataOffset, sst.dataOffset + sst.length));
23275
+ const wide = Array.from({ length: value.length }, (_, i2) => value.charCodeAt(i2)).some((c) => c > 255);
23276
+ data.push(...u16le(value.length), wide ? 1 : 0);
23277
+ for (let i2 = 0; i2 < value.length; i2++) {
23278
+ const c = value.charCodeAt(i2);
23279
+ data.push(c & 255);
23280
+ if (wide)
23281
+ data.push(c >> 8);
23282
+ }
23283
+ if (data.length > 8224)
23284
+ throw new Error("SST continuation required");
23285
+ const counts = new DataView(new Uint8Array(data).buffer);
23286
+ counts.setUint32(0, view.getUint32(sst.dataOffset, true) + 1, true);
23287
+ counts.setUint32(4, unique + 1, true);
23288
+ return { index: unique, rebuilt: biffRecord(OPCODE_SST, Array.from(new Uint8Array(counts.buffer))) };
23043
23289
  }
23044
23290
  function tryInPlaceStringEdit(bytes, range, edit, sstIndex) {
23045
23291
  const out = new Uint8Array(bytes);
@@ -23086,18 +23332,27 @@ function patchBoundsheetOffsets(bytes, delta2) {
23086
23332
  return out;
23087
23333
  }
23088
23334
  function writeOleXlsStringCellEdit(inputBytes, edit) {
23335
+ 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)
23336
+ return inputBytes;
23089
23337
  try {
23090
23338
  const { workbookBytes: xlsBytes, rewrap } = unwrapXlsBytes(inputBytes);
23091
23339
  if (!isSupportedBiff8Workbook(xlsBytes))
23092
23340
  return inputBytes;
23093
- const finish2 = (result) => rewrap ? rewrap(result) : result;
23341
+ const finish2 = (result2) => {
23342
+ const records = readRecords(result2, 0, result2.length);
23343
+ const sst = records.find((r) => r.opcode === OPCODE_SST);
23344
+ if (sst && sst.length >= 8) {
23345
+ new DataView(result2.buffer, result2.byteOffset, result2.byteLength).setUint32(sst.dataOffset, records.filter((r) => r.opcode === OPCODE_LABELSST).length, true);
23346
+ }
23347
+ return rewrap ? rewrap(result2) : result2;
23348
+ };
23094
23349
  const ranges = findAllWorksheetRanges(xlsBytes);
23095
23350
  const target = ranges[0];
23096
23351
  if (!target) {
23097
23352
  return inputBytes;
23098
23353
  }
23099
23354
  const sharedStrings = parseSstSingleRecord(xlsBytes);
23100
- const { index: sstIndex, rebuilt: newSstRecord } = resolveSstIndex(sharedStrings, edit.value);
23355
+ const { index: sstIndex, rebuilt: newSstRecord } = resolveSstIndex(sharedStrings, edit.value, xlsBytes);
23101
23356
  if (!newSstRecord) {
23102
23357
  const inPlace = tryInPlaceStringEdit(xlsBytes, target, edit, sstIndex);
23103
23358
  if (inPlace) {
@@ -23110,10 +23365,22 @@ function writeOleXlsStringCellEdit(inputBytes, edit) {
23110
23365
  const allRecords = readRecords(xlsBytes, 0, xlsBytes.length);
23111
23366
  const sstRecord = allRecords.find((r) => r.opcode === OPCODE_SST);
23112
23367
  const extSstRecord = allRecords.find((r) => r.opcode === OPCODE_EXTSST);
23368
+ if (allRecords.filter((r) => r.opcode === OPCODE_BOUNDSHEET).length > 1)
23369
+ return inputBytes;
23370
+ if (sstRecord && extSstRecord && extSstRecord.headerOffset !== sstRecord.dataOffset + sstRecord.length)
23371
+ return inputBytes;
23113
23372
  if (!sstRecord) {
23114
23373
  return inputBytes;
23115
23374
  }
23375
+ const region = findRowCellRegion(xlsBytes, target);
23376
+ const sheetRecords = readRecords(xlsBytes, target.start, target.end);
23377
+ if (sheetRecords.some((r) => [523, 6, 517, 189, 190, OPCODE_LABEL, 214].includes(r.opcode)) || sheetRecords.filter((r) => r.opcode === 2057).length !== 1)
23378
+ return inputBytes;
23379
+ 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)))
23380
+ return inputBytes;
23116
23381
  const grid = parseXlsGrid(xlsBytes, target);
23382
+ if ((/* @__PURE__ */ new Set([...grid.keys(), edit.row])).size > 32)
23383
+ return inputBytes;
23117
23384
  const row = grid.get(edit.row) ?? { cells: /* @__PURE__ */ new Map() };
23118
23385
  row.cells.set(edit.col, {
23119
23386
  ixfe: row.cells.get(edit.col)?.ixfe ?? 15,
@@ -23122,8 +23389,7 @@ function writeOleXlsStringCellEdit(inputBytes, edit) {
23122
23389
  });
23123
23390
  grid.set(edit.row, row);
23124
23391
  const newRegion = buildXlsRowCellRegion(grid);
23125
- const region = findRowCellRegion(xlsBytes, target);
23126
- const sstEnd = extSstRecord ? extSstRecord.dataOffset + extSstRecord.length : sstRecord.dataOffset + sstRecord.length;
23392
+ const sstEnd = extSstRecord && extSstRecord.headerOffset === sstRecord.dataOffset + sstRecord.length ? extSstRecord.dataOffset + extSstRecord.length : sstRecord.dataOffset + sstRecord.length;
23127
23393
  const oldSstSpanLength = sstEnd - sstRecord.headerOffset;
23128
23394
  const newSstSpanLength = newSstRecord ? newSstRecord.length : oldSstSpanLength;
23129
23395
  const patchedXlsBytes = patchBoundsheetOffsets(xlsBytes, newSstSpanLength - oldSstSpanLength);
@@ -23135,13 +23401,26 @@ function writeOleXlsStringCellEdit(inputBytes, edit) {
23135
23401
  ...newRegion,
23136
23402
  ...patchedXlsBytes.subarray(region.end)
23137
23403
  ];
23138
- return finish2(Uint8Array.from(out));
23404
+ const result = Uint8Array.from(out);
23405
+ const dimensions = readRecords(result, 0, result.length).find((r) => r.opcode === OPCODE_DIMENSIONS);
23406
+ if (dimensions) {
23407
+ if (dimensions.length !== 14)
23408
+ return inputBytes;
23409
+ const view = new DataView(result.buffer);
23410
+ const rows = [...grid.keys()];
23411
+ const cols = [...grid.values()].flatMap((row2) => [...row2.cells.keys()]);
23412
+ view.setUint32(dimensions.dataOffset, Math.min(...rows), true);
23413
+ view.setUint32(dimensions.dataOffset + 4, Math.max(...rows) + 1, true);
23414
+ view.setUint16(dimensions.dataOffset + 8, Math.min(...cols), true);
23415
+ view.setUint16(dimensions.dataOffset + 10, Math.max(...cols) + 1, true);
23416
+ }
23417
+ return finish2(result);
23139
23418
  } catch {
23140
23419
  return inputBytes;
23141
23420
  }
23142
23421
  }
23143
23422
  var init_legacy_excel_biff8_writer = __esm({
23144
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-writer.js"() {
23423
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-writer.js"() {
23145
23424
  init_legacy_excel_biff8();
23146
23425
  init_legacy_excel_biff8_grid();
23147
23426
  init_legacy_excel_cfb();
@@ -23247,15 +23526,20 @@ var init_ole_document_docx_editor = __esm({
23247
23526
  }
23248
23527
  });
23249
23528
 
23250
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fib.js
23529
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fib.js
23251
23530
  function readDocFib(wordDoc) {
23252
23531
  const view = new DataView(wordDoc.buffer, wordDoc.byteOffset, wordDoc.byteLength);
23253
23532
  const wIdent = view.getUint16(0, true);
23254
23533
  if (wIdent !== 42476) {
23255
23534
  throw new Error("Not a WordDocument FIB (bad wIdent)");
23256
23535
  }
23536
+ const nFibBase = view.getUint16(2, true);
23537
+ if (![193, 217, 257, 268, 274].includes(nFibBase))
23538
+ throw new Error("Unsupported Word FIB version");
23257
23539
  const flags1Offset = 10;
23258
23540
  const flags1 = view.getUint16(flags1Offset, true);
23541
+ if ((flags1 & 33024) !== 0)
23542
+ throw new Error("Encrypted or obfuscated Word document");
23259
23543
  const fWhichTblStm = flags1 >> 9 & 1;
23260
23544
  const csw = view.getUint16(32, true);
23261
23545
  const fibRgW97Offset = 34;
@@ -23264,6 +23548,21 @@ function readDocFib(wordDoc) {
23264
23548
  const fibRgLw97Offset = cslwOffset + 2;
23265
23549
  const cbRgFcLcbCountOffset = fibRgLw97Offset + cslw * 4;
23266
23550
  const fibRgFcLcbOffset = cbRgFcLcbCountOffset + 2;
23551
+ const fibRgFcLcbCount = view.getUint16(cbRgFcLcbCountOffset, true);
23552
+ if (csw !== 14 || cslw !== 22 || fibRgFcLcbOffset + fibRgFcLcbCount * 8 + 2 > wordDoc.length)
23553
+ throw new Error("Truncated Word FIB arrays");
23554
+ const cswNewOffset = fibRgFcLcbOffset + fibRgFcLcbCount * 8;
23555
+ const cswNew = view.getUint16(cswNewOffset, true);
23556
+ if (cswNewOffset + 2 + cswNew * 2 > wordDoc.length)
23557
+ throw new Error("Truncated Word FIB extension");
23558
+ const nFib = cswNew === 0 ? nFibBase : view.getUint16(cswNewOffset + 2, true);
23559
+ const expectedCounts = /* @__PURE__ */ new Map([[193, 93], [217, 108], [257, 136], [268, 164], [274, 183]]);
23560
+ if (expectedCounts.get(nFib) !== fibRgFcLcbCount || cswNew !== 0 && cswNew !== (nFib === 274 ? 5 : 2))
23561
+ throw new Error("Word FIB version and array counts disagree");
23562
+ const ccpText = view.getInt32(fibRgLw97Offset + 12, true);
23563
+ const otherStories = [4, 5, 7, 8, 9, 10].map((i2) => view.getInt32(fibRgLw97Offset + i2 * 4, true));
23564
+ if (ccpText < 0 || otherStories.some((cp) => cp < 0))
23565
+ throw new Error("Negative Word story length");
23267
23566
  function fcLcbPair(index) {
23268
23567
  const off = fibRgFcLcbOffset + index * 8;
23269
23568
  return { fc: view.getUint32(off, true), lcb: view.getUint32(off + 4, true) };
@@ -23271,18 +23570,22 @@ function readDocFib(wordDoc) {
23271
23570
  const cbMacOffset = fibRgLw97Offset + 0;
23272
23571
  const ccpTextOffset = fibRgLw97Offset + 12;
23273
23572
  return {
23573
+ nFib,
23574
+ nFibBase,
23274
23575
  flags1Offset,
23275
23576
  flags1,
23276
23577
  tableStreamName: fWhichTblStm ? "1Table" : "0Table",
23277
23578
  cbMacOffset,
23278
23579
  cbMac: view.getUint32(cbMacOffset, true),
23279
23580
  ccpTextOffset,
23280
- ccpText: view.getInt32(ccpTextOffset, true),
23581
+ ccpText,
23582
+ ccpOtherStories: otherStories.reduce((sum, cp) => sum + cp, 0),
23281
23583
  plcfbteChpx: fcLcbPair(FC_LCB_INDEX.plcfbteChpx),
23282
23584
  plcfbtePapx: fcLcbPair(FC_LCB_INDEX.plcfbtePapx),
23283
23585
  sed: fcLcbPair(FC_LCB_INDEX.sed),
23284
23586
  clx: fcLcbPair(FC_LCB_INDEX.clx),
23285
- fibRgFcLcbOffset
23587
+ fibRgFcLcbOffset,
23588
+ fibRgFcLcbCount
23286
23589
  };
23287
23590
  }
23288
23591
  function fcLcbFieldOffset(fib, key2) {
@@ -23290,6 +23593,9 @@ function fcLcbFieldOffset(fib, key2) {
23290
23593
  }
23291
23594
  function readFcLcbAt(wordDoc, fib, index) {
23292
23595
  const view = new DataView(wordDoc.buffer, wordDoc.byteOffset, wordDoc.byteLength);
23596
+ const count = view.getUint16(fib.fibRgFcLcbOffset - 2, true);
23597
+ if (!Number.isInteger(index) || index < 0 || index >= count || fib.fibRgFcLcbCount !== void 0 && fib.fibRgFcLcbCount !== count)
23598
+ throw new Error("FIB fc/lcb index outside declared array");
23293
23599
  const off = fib.fibRgFcLcbOffset + index * 8;
23294
23600
  return { fc: view.getUint32(off, true), lcb: view.getUint32(off + 4, true) };
23295
23601
  }
@@ -23310,7 +23616,7 @@ function patchDocFib(wordDoc, fib, patch) {
23310
23616
  }
23311
23617
  var FC_LCB_INDEX, F_COMPLEX_BIT;
23312
23618
  var init_ole_document_doc_fib = __esm({
23313
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fib.js"() {
23619
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fib.js"() {
23314
23620
  FC_LCB_INDEX = {
23315
23621
  plcfbteChpx: 12,
23316
23622
  plcfbtePapx: 13,
@@ -23321,62 +23627,578 @@ var init_ole_document_doc_fib = __esm({
23321
23627
  }
23322
23628
  });
23323
23629
 
23324
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cfb.js
23630
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-v4.js
23631
+ function follow(table, start) {
23632
+ const ids = [], seen = /* @__PURE__ */ new Set();
23633
+ for (let id = start; id !== END2; id = table[id]) {
23634
+ if (id >= table.length || seen.has(id))
23635
+ throw new Error("Invalid allocation chain");
23636
+ seen.add(id);
23637
+ ids.push(id);
23638
+ }
23639
+ return ids;
23640
+ }
23641
+ function findSlot(slots, path) {
23642
+ let parent = slots.get(0);
23643
+ if (!parent || parent.type !== 5)
23644
+ throw new Error("Invalid root");
23645
+ const parents = /* @__PURE__ */ new Set();
23646
+ for (let part = 0; part < path.length; part++) {
23647
+ if (parents.has(parent.id))
23648
+ throw new Error("Cyclic storage hierarchy");
23649
+ parents.add(parent.id);
23650
+ const stack = [parent.child], seen = /* @__PURE__ */ new Set(), matches = [];
23651
+ while (stack.length) {
23652
+ const id = stack.pop();
23653
+ if (id === FREE)
23654
+ continue;
23655
+ if (seen.has(id))
23656
+ throw new Error("Invalid directory tree");
23657
+ seen.add(id);
23658
+ const slot = slots.get(id);
23659
+ if (!slot)
23660
+ throw new Error("Missing directory slot");
23661
+ if (slot.name.toLocaleLowerCase() === path[part].toLocaleLowerCase())
23662
+ matches.push(slot);
23663
+ stack.push(slot.left, slot.right);
23664
+ }
23665
+ if (matches.length !== 1)
23666
+ throw new Error("Missing or ambiguous stream");
23667
+ parent = matches[0];
23668
+ if (parent.type !== (part === path.length - 1 ? 2 : 1))
23669
+ throw new Error("Invalid storage path");
23670
+ }
23671
+ return parent;
23672
+ }
23673
+ function validateHierarchy(slots) {
23674
+ const owners = /* @__PURE__ */ new Set(), storages = [0];
23675
+ while (storages.length) {
23676
+ const storage = slots.get(storages.pop());
23677
+ const stack = [storage.child], names = /* @__PURE__ */ new Set();
23678
+ while (stack.length) {
23679
+ const id = stack.pop();
23680
+ if (id === FREE)
23681
+ continue;
23682
+ const slot = slots.get(id);
23683
+ if (!slot || slot.type !== 1 && slot.type !== 2 || owners.has(id))
23684
+ throw new Error("Ambiguous directory ownership");
23685
+ const name = slot.name.toLocaleLowerCase();
23686
+ if (names.has(name))
23687
+ throw new Error("Duplicate sibling name");
23688
+ names.add(name);
23689
+ owners.add(id);
23690
+ stack.push(slot.left, slot.right);
23691
+ if (slot.type === 1)
23692
+ storages.push(id);
23693
+ }
23694
+ }
23695
+ if (owners.size !== slots.size - 1)
23696
+ throw new Error("Unreachable directory entries");
23697
+ }
23698
+ function resizeCompoundFileStreamV4(input, path, replacement) {
23699
+ const fail2 = (reason) => ({ ok: false, bytes: input, reason });
23700
+ try {
23701
+ if (input.length < 512 || !path.length || path.some((part) => !part))
23702
+ return fail2("invalid-or-missing-stream");
23703
+ const view = new DataView(input.buffer, input.byteOffset, input.byteLength);
23704
+ const read = (offset) => view.getUint32(offset, true);
23705
+ const version = view.getUint16(26, true);
23706
+ if (version !== 4)
23707
+ return fail2("unsupported-version");
23708
+ const SECTOR3 = 4096, FAT_ENTRIES2 = SECTOR3 / 4, DIRECTORY_ENTRIES = SECTOR3 / 128;
23709
+ if (read(72) !== 0 || read(44) > 109)
23710
+ return fail2("unsupported-difat");
23711
+ const cutoff = read(56);
23712
+ if (cutoff !== 0 && cutoff !== 4096)
23713
+ return fail2("unsupported-layout");
23714
+ const original = readCompoundFileStream(input, path);
23715
+ if (!original)
23716
+ return fail2("invalid-or-missing-stream");
23717
+ const name = path[path.length - 1].toLocaleLowerCase();
23718
+ if (name === "worddocument" && original.length >= 12 && (original[10] | original[11] << 8) & 33024)
23719
+ return fail2("unsafe-edit");
23720
+ if (name === "book" || name === "workbook") {
23721
+ for (let offset = 0; offset + 4 <= original.length; ) {
23722
+ const record2 = original[offset] | original[offset + 1] << 8;
23723
+ const length = original[offset + 2] | original[offset + 3] << 8;
23724
+ if (record2 === 47)
23725
+ return fail2("unsafe-edit");
23726
+ if (record2 === 10 || offset + 4 + length > original.length)
23727
+ break;
23728
+ offset += 4 + length;
23729
+ }
23730
+ }
23731
+ const validated = replaceCompoundFileStream(input, path, original);
23732
+ if (validated === input)
23733
+ return fail2("unsafe-edit");
23734
+ const sameLength = replacement.length === original.length;
23735
+ if (!sameLength && original.length < cutoff)
23736
+ return fail2("unsupported-mini-stream");
23737
+ if (!sameLength && replacement.length < cutoff)
23738
+ return fail2("unsupported-mini-transition");
23739
+ const sectorCount = input.length / SECTOR3 - 1, fatCount = read(44);
23740
+ if (sectorCount > fatCount * FAT_ENTRIES2)
23741
+ return fail2("unsafe-edit");
23742
+ const fatIds = Array.from({ length: fatCount }, (_, i2) => read(76 + 4 * i2));
23743
+ const fat = [];
23744
+ for (const id of fatIds) {
23745
+ for (let i2 = 0; i2 < FAT_ENTRIES2 && fat.length < sectorCount; i2++)
23746
+ fat.push(read((id + 1) * SECTOR3 + i2 * 4));
23747
+ }
23748
+ if (fatIds.some((id) => fat[id] !== FAT))
23749
+ return fail2("unsafe-edit");
23750
+ const slots = /* @__PURE__ */ new Map();
23751
+ const directoryChain = follow(fat, read(48));
23752
+ if (read(40) !== directoryChain.length)
23753
+ return fail2("unsafe-edit");
23754
+ for (const [block, sector] of directoryChain.entries()) {
23755
+ for (let entry = 0; entry < DIRECTORY_ENTRIES; entry++) {
23756
+ const offset = (sector + 1) * SECTOR3 + entry * 128, type = view.getUint8(offset + 66);
23757
+ if (!type)
23758
+ continue;
23759
+ const nameLength = view.getUint16(offset + 64, true);
23760
+ if (![1, 2, 5].includes(type) || nameLength < 2 || nameLength > 64 || nameLength % 2 || view.getUint16(offset + nameLength - 2, true))
23761
+ return fail2("unsafe-edit");
23762
+ let name2 = "";
23763
+ for (let i2 = 0; i2 < nameLength - 2; i2 += 2)
23764
+ name2 += String.fromCharCode(view.getUint16(offset + i2, true));
23765
+ if (read(offset + 124) !== 0)
23766
+ return fail2("unsafe-edit");
23767
+ const id = block * DIRECTORY_ENTRIES + entry;
23768
+ 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 });
23769
+ }
23770
+ }
23771
+ if ([...slots.values()].filter((slot) => slot.type === 5).length !== 1)
23772
+ return fail2("unsafe-edit");
23773
+ const target = findSlot(slots, path);
23774
+ validateHierarchy(slots);
23775
+ if (sameLength) {
23776
+ const bytes = replaceCompoundFileStream(input, path, replacement);
23777
+ return bytes === input ? fail2("unsafe-edit") : { ok: true, bytes };
23778
+ }
23779
+ const oldChain = follow(fat, target.start);
23780
+ if (target.size !== original.length || oldChain.length !== Math.ceil(target.size / SECTOR3))
23781
+ return fail2("unsafe-edit");
23782
+ const payloadSectors = Math.ceil(replacement.length / SECTOR3);
23783
+ let newFatCount = fatCount;
23784
+ while (sectorCount + payloadSectors + newFatCount - fatCount > newFatCount * FAT_ENTRIES2)
23785
+ newFatCount++;
23786
+ if (newFatCount > 109)
23787
+ return fail2("allocation-limit");
23788
+ const totalSectors = sectorCount + payloadSectors + newFatCount - fatCount;
23789
+ const output = new Uint8Array((totalSectors + 1) * SECTOR3);
23790
+ output.set(input);
23791
+ output.set(replacement, (sectorCount + 1) * SECTOR3);
23792
+ const outView = new DataView(output.buffer);
23793
+ for (let i2 = fatCount; i2 < newFatCount; i2++) {
23794
+ const id = sectorCount + payloadSectors + i2 - fatCount;
23795
+ fatIds.push(id);
23796
+ output.fill(255, (id + 1) * SECTOR3, (id + 2) * SECTOR3);
23797
+ outView.setUint32(76 + i2 * 4, id, true);
23798
+ }
23799
+ outView.setUint32(44, newFatCount, true);
23800
+ const writeFat = (id, value) => outView.setUint32((fatIds[Math.floor(id / FAT_ENTRIES2)] + 1) * SECTOR3 + id % FAT_ENTRIES2 * 4, value, true);
23801
+ for (const id of oldChain)
23802
+ writeFat(id, FREE);
23803
+ for (let i2 = 0; i2 < payloadSectors; i2++)
23804
+ writeFat(sectorCount + i2, i2 + 1 === payloadSectors ? END2 : sectorCount + i2 + 1);
23805
+ for (const id of fatIds)
23806
+ writeFat(id, FAT);
23807
+ outView.setUint32(target.offset + 116, payloadSectors ? sectorCount : END2, true);
23808
+ outView.setUint32(target.offset + 120, replacement.length, true);
23809
+ return { ok: true, bytes: output };
23810
+ } catch {
23811
+ return fail2("unsafe-edit");
23812
+ }
23813
+ }
23814
+ var END2, FREE, FAT;
23815
+ var init_ole2_stream_resize_v4 = __esm({
23816
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-v4.js"() {
23817
+ init_ole2_stream_edit();
23818
+ END2 = 4294967294;
23819
+ FREE = 4294967295;
23820
+ FAT = 4294967293;
23821
+ }
23822
+ });
23823
+
23824
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-allocation.js
23825
+ function appendCompoundAllocations(input, existingFatIds, payloads, sectorSize = 512) {
23826
+ const sectorCount = input.length / sectorSize - 1;
23827
+ const entriesPerFat = sectorSize / 4;
23828
+ const counts = payloads.map((payload) => Math.ceil(payload.length / sectorSize));
23829
+ const payloadSectors = counts.reduce((sum, count) => sum + count, 0);
23830
+ let fatCount = existingFatIds.length;
23831
+ while (sectorCount + payloadSectors + fatCount - existingFatIds.length > fatCount * entriesPerFat)
23832
+ fatCount++;
23833
+ if (fatCount > 109)
23834
+ return void 0;
23835
+ const totalSectors = sectorCount + payloadSectors + fatCount - existingFatIds.length;
23836
+ const bytes = new Uint8Array((totalSectors + 1) * sectorSize);
23837
+ bytes.set(input);
23838
+ const view = new DataView(bytes.buffer), fatIds = [...existingFatIds];
23839
+ for (let i2 = existingFatIds.length; i2 < fatCount; i2++) {
23840
+ const id = sectorCount + payloadSectors + i2 - existingFatIds.length;
23841
+ fatIds.push(id);
23842
+ bytes.fill(255, (id + 1) * sectorSize, (id + 2) * sectorSize);
23843
+ view.setUint32(76 + i2 * 4, id, true);
23844
+ }
23845
+ view.setUint32(44, fatCount, true);
23846
+ const writeFat = (id, value) => view.setUint32((fatIds[Math.floor(id / entriesPerFat)] + 1) * sectorSize + id % entriesPerFat * 4, value, true);
23847
+ const chains = [];
23848
+ let next = sectorCount;
23849
+ for (let payload = 0; payload < payloads.length; payload++) {
23850
+ bytes.set(payloads[payload], (next + 1) * sectorSize);
23851
+ const chain2 = Array.from({ length: counts[payload] }, (_, i2) => next + i2);
23852
+ chain2.forEach((id, i2) => writeFat(id, chain2[i2 + 1] ?? 4294967294));
23853
+ chains.push(chain2);
23854
+ next += counts[payload];
23855
+ }
23856
+ for (const id of fatIds)
23857
+ writeFat(id, 4294967293);
23858
+ return { bytes, view, chains, writeFat };
23859
+ }
23860
+ function followCompoundAllocation(table, start) {
23861
+ const ids = [], seen = /* @__PURE__ */ new Set();
23862
+ for (let id = start; id !== 4294967294; id = table[id]) {
23863
+ if (id >= table.length || seen.has(id))
23864
+ throw new Error("Invalid allocation chain");
23865
+ seen.add(id);
23866
+ ids.push(id);
23867
+ }
23868
+ return ids;
23869
+ }
23870
+ var init_ole2_stream_resize_allocation = __esm({
23871
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-allocation.js"() {
23872
+ }
23873
+ });
23874
+
23875
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-mini.js
23876
+ function resizeMiniCompoundStream(input, fat, fatIds, root, target, replacement, cutoff) {
23877
+ const inputView = new DataView(input.buffer, input.byteOffset, input.byteLength);
23878
+ const miniFatCount = inputView.getUint32(64, true);
23879
+ const miniFatSectors = miniFatCount ? followCompoundAllocation(fat, inputView.getUint32(60, true)) : [];
23880
+ if (miniFatSectors.length !== miniFatCount)
23881
+ throw new Error("Invalid mini FAT count");
23882
+ const rootSectors = root.size ? followCompoundAllocation(fat, root.start) : [];
23883
+ if (rootSectors.length !== Math.ceil(root.size / SECTOR))
23884
+ throw new Error("Invalid root mini stream");
23885
+ const miniCapacity = Math.floor(root.size / MINI), miniFat = [];
23886
+ for (const id of miniFatSectors) {
23887
+ for (let slot = 0; slot < SECTOR / 4 && miniFat.length < miniCapacity; slot++)
23888
+ miniFat.push(inputView.getUint32((id + 1) * SECTOR + slot * 4, true));
23889
+ }
23890
+ const wasMini = target.size < cutoff;
23891
+ const oldChain = followCompoundAllocation(wasMini ? miniFat : fat, target.start);
23892
+ if (oldChain.length !== Math.ceil(target.size / (wasMini ? MINI : SECTOR)))
23893
+ throw new Error("Invalid stream allocation");
23894
+ if (!replacement.length) {
23895
+ const bytes = input.slice(), view = new DataView(bytes.buffer);
23896
+ for (const id of oldChain) {
23897
+ const table = wasMini ? miniFatSectors : fatIds;
23898
+ view.setUint32((table[Math.floor(id / 128)] + 1) * SECTOR + id % 128 * 4, FREE2, true);
23899
+ }
23900
+ view.setUint32(target.offset + 116, END3, true);
23901
+ view.setUint32(target.offset + 120, 0, true);
23902
+ return bytes;
23903
+ }
23904
+ if (replacement.length >= cutoff) {
23905
+ const output2 = appendCompoundAllocations(input, fatIds, [replacement]);
23906
+ if (!output2)
23907
+ return void 0;
23908
+ for (const id of oldChain)
23909
+ output2.view.setUint32((miniFatSectors[Math.floor(id / 128)] + 1) * SECTOR + id % 128 * 4, FREE2, true);
23910
+ output2.view.setUint32(target.offset + 116, output2.chains[0][0] ?? END3, true);
23911
+ output2.view.setUint32(target.offset + 120, replacement.length, true);
23912
+ return output2.bytes;
23913
+ }
23914
+ const firstMini = Math.ceil(root.size / MINI), count = Math.ceil(replacement.length / MINI);
23915
+ const newRootSize = count ? (firstMini + count) * MINI : root.size;
23916
+ const newRoot = new Uint8Array(newRootSize);
23917
+ rootSectors.forEach((id, i2) => newRoot.set(input.subarray((id + 1) * SECTOR, (id + 1) * SECTOR + Math.min(SECTOR, root.size - i2 * SECTOR)), i2 * SECTOR));
23918
+ if (count)
23919
+ newRoot.set(replacement, firstMini * MINI);
23920
+ const newMiniFatCount = Math.max(miniFatCount, Math.ceil((firstMini + count) / 128));
23921
+ const newMiniFat = new Uint8Array(newMiniFatCount * SECTOR).fill(255);
23922
+ miniFatSectors.forEach((id, i2) => newMiniFat.set(input.subarray((id + 1) * SECTOR, (id + 2) * SECTOR), i2 * SECTOR));
23923
+ const miniView = new DataView(newMiniFat.buffer);
23924
+ if (wasMini)
23925
+ for (const id of oldChain)
23926
+ miniView.setUint32(id * 4, FREE2, true);
23927
+ for (let i2 = 0; i2 < count; i2++)
23928
+ miniView.setUint32((firstMini + i2) * 4, i2 + 1 === count ? END3 : firstMini + i2 + 1, true);
23929
+ const output = appendCompoundAllocations(input, fatIds, [newRoot, newMiniFat]);
23930
+ if (!output)
23931
+ return void 0;
23932
+ for (const id of [...rootSectors, ...miniFatSectors, ...wasMini ? [] : oldChain])
23933
+ output.writeFat(id, FREE2);
23934
+ output.view.setUint32(root.offset + 116, output.chains[0][0] ?? END3, true);
23935
+ output.view.setUint32(root.offset + 120, newRootSize, true);
23936
+ output.view.setUint32(60, output.chains[1][0] ?? END3, true);
23937
+ output.view.setUint32(64, newMiniFatCount, true);
23938
+ output.view.setUint32(target.offset + 116, count ? firstMini : END3, true);
23939
+ output.view.setUint32(target.offset + 120, replacement.length, true);
23940
+ return output.bytes;
23941
+ }
23942
+ var END3, FREE2, SECTOR, MINI;
23943
+ var init_ole2_stream_resize_mini = __esm({
23944
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-mini.js"() {
23945
+ init_ole2_stream_resize_allocation();
23946
+ END3 = 4294967294;
23947
+ FREE2 = 4294967295;
23948
+ SECTOR = 512;
23949
+ MINI = 64;
23950
+ }
23951
+ });
23952
+
23953
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize.js
23954
+ function follow2(table, start) {
23955
+ const ids = [], seen = /* @__PURE__ */ new Set();
23956
+ for (let id = start; id !== END4; id = table[id]) {
23957
+ if (id >= table.length || seen.has(id))
23958
+ throw new Error("Invalid allocation chain");
23959
+ seen.add(id);
23960
+ ids.push(id);
23961
+ }
23962
+ return ids;
23963
+ }
23964
+ function findSlot2(slots, path) {
23965
+ let parent = slots.get(0);
23966
+ if (!parent || parent.type !== 5)
23967
+ throw new Error("Invalid root");
23968
+ const parents = /* @__PURE__ */ new Set();
23969
+ for (let part = 0; part < path.length; part++) {
23970
+ if (parents.has(parent.id))
23971
+ throw new Error("Cyclic storage hierarchy");
23972
+ parents.add(parent.id);
23973
+ const stack = [parent.child], seen = /* @__PURE__ */ new Set(), matches = [];
23974
+ while (stack.length) {
23975
+ const id = stack.pop();
23976
+ if (id === FREE3)
23977
+ continue;
23978
+ if (seen.has(id))
23979
+ throw new Error("Invalid directory tree");
23980
+ seen.add(id);
23981
+ const slot = slots.get(id);
23982
+ if (!slot)
23983
+ throw new Error("Missing directory slot");
23984
+ if (slot.name.toLocaleLowerCase() === path[part].toLocaleLowerCase())
23985
+ matches.push(slot);
23986
+ stack.push(slot.left, slot.right);
23987
+ }
23988
+ if (matches.length !== 1)
23989
+ throw new Error("Missing or ambiguous stream");
23990
+ parent = matches[0];
23991
+ if (parent.type !== (part === path.length - 1 ? 2 : 1))
23992
+ throw new Error("Invalid storage path");
23993
+ }
23994
+ return parent;
23995
+ }
23996
+ function validateHierarchy2(slots) {
23997
+ const owners = /* @__PURE__ */ new Set(), storages = [0];
23998
+ while (storages.length) {
23999
+ const storage = slots.get(storages.pop());
24000
+ const stack = [storage.child], names = /* @__PURE__ */ new Set();
24001
+ while (stack.length) {
24002
+ const id = stack.pop();
24003
+ if (id === FREE3)
24004
+ continue;
24005
+ const slot = slots.get(id);
24006
+ if (!slot || slot.type !== 1 && slot.type !== 2 || owners.has(id))
24007
+ throw new Error("Ambiguous directory ownership");
24008
+ const name = slot.name.toLocaleLowerCase();
24009
+ if (names.has(name))
24010
+ throw new Error("Duplicate sibling name");
24011
+ names.add(name);
24012
+ owners.add(id);
24013
+ stack.push(slot.left, slot.right);
24014
+ if (slot.type === 1)
24015
+ storages.push(id);
24016
+ }
24017
+ }
24018
+ if (owners.size !== slots.size - 1)
24019
+ throw new Error("Unreachable directory entries");
24020
+ }
24021
+ function resizeCompoundFileStream(input, path, replacement) {
24022
+ if (input.length >= 512 && new DataView(input.buffer, input.byteOffset, input.byteLength).getUint16(26, true) === 4)
24023
+ return resizeCompoundFileStreamV4(input, path, replacement);
24024
+ const fail2 = (reason) => ({ ok: false, bytes: input, reason });
24025
+ try {
24026
+ if (input.length < SECTOR2 || !path.length || path.some((part) => !part))
24027
+ return fail2("invalid-or-missing-stream");
24028
+ const view = new DataView(input.buffer, input.byteOffset, input.byteLength);
24029
+ const read = (offset) => view.getUint32(offset, true);
24030
+ if (view.getUint16(26, true) !== 3)
24031
+ return fail2("unsupported-version");
24032
+ if (read(72) !== 0 || read(44) > 109)
24033
+ return fail2("unsupported-difat");
24034
+ const cutoff = read(56);
24035
+ if (cutoff !== 0 && cutoff !== 4096)
24036
+ return fail2("unsupported-layout");
24037
+ const original = readCompoundFileStream(input, path);
24038
+ if (!original)
24039
+ return fail2("invalid-or-missing-stream");
24040
+ const name = path[path.length - 1].toLocaleLowerCase();
24041
+ if (name === "worddocument" && original.length >= 12 && (original[10] | original[11] << 8) & 33024)
24042
+ return fail2("unsafe-edit");
24043
+ if (name === "book" || name === "workbook") {
24044
+ for (let offset = 0; offset + 4 <= original.length; ) {
24045
+ const record2 = original[offset] | original[offset + 1] << 8;
24046
+ const length = original[offset + 2] | original[offset + 3] << 8;
24047
+ if (record2 === 47)
24048
+ return fail2("unsafe-edit");
24049
+ if (record2 === 10 || offset + 4 + length > original.length)
24050
+ break;
24051
+ offset += 4 + length;
24052
+ }
24053
+ }
24054
+ const validated = replaceCompoundFileStream(input, path, original);
24055
+ if (validated === input)
24056
+ return fail2("unsafe-edit");
24057
+ const sameLength = replacement.length === original.length;
24058
+ const sectorCount = input.length / SECTOR2 - 1, fatCount = read(44);
24059
+ if (sectorCount > fatCount * FAT_ENTRIES)
24060
+ return fail2("unsafe-edit");
24061
+ const fatIds = Array.from({ length: fatCount }, (_, i2) => read(76 + 4 * i2));
24062
+ const fat = [];
24063
+ for (const id of fatIds) {
24064
+ for (let i2 = 0; i2 < FAT_ENTRIES && fat.length < sectorCount; i2++)
24065
+ fat.push(read((id + 1) * SECTOR2 + i2 * 4));
24066
+ }
24067
+ if (fatIds.some((id) => fat[id] !== FAT2))
24068
+ return fail2("unsafe-edit");
24069
+ const slots = /* @__PURE__ */ new Map();
24070
+ for (const [block, sector] of follow2(fat, read(48)).entries()) {
24071
+ for (let entry = 0; entry < 4; entry++) {
24072
+ const offset = (sector + 1) * SECTOR2 + entry * 128, type = view.getUint8(offset + 66);
24073
+ if (!type)
24074
+ continue;
24075
+ const nameLength = view.getUint16(offset + 64, true);
24076
+ if (![1, 2, 5].includes(type) || nameLength < 2 || nameLength > 64 || nameLength % 2 || view.getUint16(offset + nameLength - 2, true))
24077
+ return fail2("unsafe-edit");
24078
+ let name2 = "";
24079
+ for (let i2 = 0; i2 < nameLength - 2; i2 += 2)
24080
+ name2 += String.fromCharCode(view.getUint16(offset + i2, true));
24081
+ const id = block * 4 + entry;
24082
+ 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 });
24083
+ }
24084
+ }
24085
+ if ([...slots.values()].filter((slot) => slot.type === 5).length !== 1)
24086
+ return fail2("unsafe-edit");
24087
+ const target = findSlot2(slots, path);
24088
+ validateHierarchy2(slots);
24089
+ if (sameLength) {
24090
+ const bytes = replaceCompoundFileStream(input, path, replacement);
24091
+ return bytes === input ? fail2("unsafe-edit") : { ok: true, bytes };
24092
+ }
24093
+ if (original.length < cutoff || replacement.length < cutoff) {
24094
+ const bytes = resizeMiniCompoundStream(input, fat, fatIds, slots.get(0), target, replacement, cutoff);
24095
+ return bytes ? { ok: true, bytes } : fail2("allocation-limit");
24096
+ }
24097
+ const oldChain = follow2(fat, target.start);
24098
+ if (target.size !== original.length || oldChain.length !== Math.ceil(target.size / SECTOR2))
24099
+ return fail2("unsafe-edit");
24100
+ const output = appendCompoundAllocations(input, fatIds, [replacement]);
24101
+ if (!output)
24102
+ return fail2("allocation-limit");
24103
+ for (const id of oldChain)
24104
+ output.writeFat(id, FREE3);
24105
+ output.view.setUint32(target.offset + 116, output.chains[0][0] ?? END4, true);
24106
+ output.view.setUint32(target.offset + 120, replacement.length, true);
24107
+ return { ok: true, bytes: output.bytes };
24108
+ } catch {
24109
+ return fail2("unsafe-edit");
24110
+ }
24111
+ }
24112
+ var END4, FREE3, FAT2, SECTOR2, FAT_ENTRIES;
24113
+ var init_ole2_stream_resize = __esm({
24114
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize.js"() {
24115
+ init_ole2_stream_edit();
24116
+ init_ole2_stream_resize_v4();
24117
+ init_ole2_stream_resize_allocation();
24118
+ init_ole2_stream_resize_mini();
24119
+ END4 = 4294967294;
24120
+ FREE3 = 4294967295;
24121
+ FAT2 = 4294967293;
24122
+ SECTOR2 = 512;
24123
+ FAT_ENTRIES = SECTOR2 / 4;
24124
+ }
24125
+ });
24126
+
24127
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cfb.js
23325
24128
  function unwrapDocBytes(bytes) {
23326
24129
  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) {
23327
24130
  return void 0;
23328
24131
  }
23329
24132
  try {
23330
- const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
23331
- const ole = parseOle2(buffer);
23332
- const wordDocBytes = ole.getStream("WordDocument");
24133
+ const wordDocBytes = readCompoundFileStream(bytes, ["WordDocument"]);
23333
24134
  if (!wordDocBytes) {
23334
24135
  return void 0;
23335
24136
  }
23336
24137
  const fib = readDocFib(wordDocBytes);
23337
- const tableBytes = ole.getStream(fib.tableStreamName);
24138
+ const tableBytes = readCompoundFileStream(bytes, [fib.tableStreamName]);
23338
24139
  if (!tableBytes) {
23339
24140
  return void 0;
23340
24141
  }
23341
- const rootClsid = ole.entries.find((e) => e.type === ENTRY_TYPE_ROOT)?.clsid;
24142
+ const header = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
24143
+ const cutoff = header.getUint32(56, true);
24144
+ 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;
23342
24145
  return {
23343
24146
  wordDocBytes,
23344
24147
  tableStreamName: fib.tableStreamName,
23345
24148
  tableBytes,
24149
+ canRewrite,
23346
24150
  rewrap: (editedWordDocBytes, editedTableBytes) => {
23347
- const streams2 = /* @__PURE__ */ new Map();
23348
- for (const entry of ole.entries) {
23349
- if (entry.type !== ENTRY_TYPE_STREAM) {
23350
- continue;
23351
- }
23352
- const data = entry.name === "WordDocument" ? editedWordDocBytes : entry.name === fib.tableStreamName ? editedTableBytes : ole.getStream(entry.name);
23353
- if (data) {
23354
- streams2.set(entry.name, data);
23355
- }
23356
- }
23357
- return new Uint8Array(buildOle2(streams2, rootClsid));
24151
+ if (editedWordDocBytes.length === wordDocBytes.length && editedTableBytes.length === tableBytes.length) {
24152
+ const patchedWord = replaceCompoundFileStream(bytes, ["WordDocument"], editedWordDocBytes);
24153
+ if (patchedWord === bytes)
24154
+ throw new DocCfbRewriteError("Cannot safely patch WordDocument");
24155
+ if (editedTableBytes.every((value, i2) => value === tableBytes[i2]))
24156
+ return patchedWord;
24157
+ const patchedTable = replaceCompoundFileStream(patchedWord, [fib.tableStreamName], editedTableBytes);
24158
+ if (patchedTable === patchedWord)
24159
+ throw new DocCfbRewriteError("Cannot safely patch DOC table stream");
24160
+ return patchedTable;
24161
+ }
24162
+ const word = resizeCompoundFileStream(bytes, ["WordDocument"], editedWordDocBytes);
24163
+ if (!word.ok)
24164
+ throw new DocCfbRewriteError(`Cannot resize WordDocument: ${word.reason}`);
24165
+ const table = resizeCompoundFileStream(word.bytes, [fib.tableStreamName], editedTableBytes);
24166
+ if (!table.ok)
24167
+ throw new DocCfbRewriteError(`Cannot resize DOC table stream: ${table.reason}`);
24168
+ return table.bytes;
23358
24169
  }
23359
24170
  };
23360
24171
  } catch {
23361
24172
  return void 0;
23362
24173
  }
23363
24174
  }
24175
+ var DocCfbRewriteError;
23364
24176
  var init_ole_document_doc_cfb = __esm({
23365
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cfb.js"() {
24177
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cfb.js"() {
23366
24178
  init_ole_document_doc_fib();
23367
- init_ole2_parser_read();
23368
- init_ole2_parser_types();
23369
- init_ole2_parser_write();
24179
+ init_ole2_stream_edit();
24180
+ init_ole2_stream_resize();
24181
+ DocCfbRewriteError = class extends Error {
24182
+ constructor(message) {
24183
+ super(message);
24184
+ this.name = "DocCfbRewriteError";
24185
+ }
24186
+ };
23370
24187
  }
23371
24188
  });
23372
24189
 
23373
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fkp.js
24190
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fkp.js
23374
24191
  function parseBteTable(tableStream, at2) {
23375
24192
  const view = new DataView(tableStream.buffer, tableStream.byteOffset, tableStream.byteLength);
23376
- const n = Math.floor((at2.lcb - 4) / (4 + 4));
24193
+ 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)
24194
+ throw new Error("Invalid BTE table bounds");
24195
+ const n = (at2.lcb - 4) / 8;
23377
24196
  const fcs = [];
23378
24197
  for (let i2 = 0; i2 <= n; i2++) {
23379
- fcs.push(view.getInt32(at2.fc + i2 * 4, true));
24198
+ const fc = view.getInt32(at2.fc + i2 * 4, true);
24199
+ if (fc < 0 || i2 > 0 && fc <= fcs[i2 - 1])
24200
+ throw new Error("Invalid BTE FC boundaries");
24201
+ fcs.push(fc);
23380
24202
  }
23381
24203
  const pns = [];
23382
24204
  for (let i2 = 0; i2 < n; i2++) {
@@ -23397,10 +24219,17 @@ function buildBteTableBytes(table) {
23397
24219
  return bytes;
23398
24220
  }
23399
24221
  function findBteRangeIndex(table, fc) {
23400
- for (let i2 = 0; i2 < table.pns.length; i2++) {
23401
- if (fc >= table.fcs[i2] && fc < table.fcs[i2 + 1]) {
23402
- return i2;
23403
- }
24222
+ let low = 0, high = table.pns.length;
24223
+ while (low < high) {
24224
+ const middle = low + Math.floor((high - low) / 2);
24225
+ if (fc < table.fcs[middle])
24226
+ high = middle;
24227
+ else if (fc >= table.fcs[middle + 1])
24228
+ low = middle + 1;
24229
+ else if (fc >= table.fcs[middle])
24230
+ return middle;
24231
+ else
24232
+ break;
23404
24233
  }
23405
24234
  throw new Error(`FC ${fc} is not covered by any BTE range`);
23406
24235
  }
@@ -23416,7 +24245,11 @@ function extractPapxBlob(wordDoc, papxBte, fc) {
23416
24245
  const rangeIndex = findBteRangeIndex(papxBte, fc);
23417
24246
  const pageOffset = papxBte.pns[rangeIndex] * PAGE_SIZE;
23418
24247
  const page = wordDoc.subarray(pageOffset, pageOffset + PAGE_SIZE);
24248
+ if (page.length !== PAGE_SIZE)
24249
+ throw new Error("Truncated PAPX page");
23419
24250
  const crun = page[PAGE_SIZE - 1];
24251
+ if (crun === 0 || (crun + 1) * 4 + crun * 13 > 511)
24252
+ throw new Error("Invalid PAPX run count");
23420
24253
  const pageView = new DataView(page.buffer, page.byteOffset, page.byteLength);
23421
24254
  const rgbxOffset = (crun + 1) * 4;
23422
24255
  for (let i2 = 0; i2 < crun; i2++) {
@@ -23424,8 +24257,13 @@ function extractPapxBlob(wordDoc, papxBte, fc) {
23424
24257
  const runFcEnd = pageView.getInt32((i2 + 1) * 4, true);
23425
24258
  if (fc >= runFcStart && fc < runFcEnd) {
23426
24259
  const bOffsetWord = page[rgbxOffset + i2 * 13];
24260
+ if (bOffsetWord === 0)
24261
+ return new Uint8Array();
23427
24262
  const blobOffset = bOffsetWord * 2;
23428
- return page.slice(blobOffset, blobOffset + papxBlobLength(page, blobOffset));
24263
+ const blobLength = papxBlobLength(page, blobOffset);
24264
+ if (blobOffset < rgbxOffset + crun * 13 || !Number.isInteger(blobLength) || blobOffset + blobLength > 511)
24265
+ throw new Error("Invalid PAPX blob bounds");
24266
+ return page.slice(blobOffset, blobOffset + blobLength);
23429
24267
  }
23430
24268
  }
23431
24269
  throw new Error(`FC ${fc} is not covered by any run in PAPX page ${papxBte.pns[rangeIndex]}`);
@@ -23434,7 +24272,11 @@ function extractChpxBlob(wordDoc, chpxBte, fc) {
23434
24272
  const rangeIndex = findBteRangeIndex(chpxBte, fc);
23435
24273
  const pageOffset = chpxBte.pns[rangeIndex] * PAGE_SIZE;
23436
24274
  const page = wordDoc.subarray(pageOffset, pageOffset + PAGE_SIZE);
24275
+ if (page.length !== PAGE_SIZE)
24276
+ throw new Error("Truncated CHPX page");
23437
24277
  const crun = page[PAGE_SIZE - 1];
24278
+ if (crun === 0 || (crun + 1) * 4 + crun > 511)
24279
+ throw new Error("Invalid CHPX run count");
23438
24280
  const pageView = new DataView(page.buffer, page.byteOffset, page.byteLength);
23439
24281
  const rgbOffset = (crun + 1) * 4;
23440
24282
  for (let i2 = 0; i2 < crun; i2++) {
@@ -23447,6 +24289,8 @@ function extractChpxBlob(wordDoc, chpxBte, fc) {
23447
24289
  }
23448
24290
  const blobOffset = bOffsetWord * 2;
23449
24291
  const cb = page[blobOffset];
24292
+ if (blobOffset < rgbOffset + crun || blobOffset + 1 + cb > 511)
24293
+ throw new Error("Invalid CHPX blob bounds");
23450
24294
  return page.slice(blobOffset, blobOffset + 1 + cb);
23451
24295
  }
23452
24296
  }
@@ -23458,8 +24302,12 @@ function buildSingleRunPapxPage(fcStart, fcEnd, blob) {
23458
24302
  view.setInt32(0, fcStart, true);
23459
24303
  view.setInt32(4, fcEnd, true);
23460
24304
  const blobByteOffset = 22;
23461
- page[8] = blobByteOffset / 2;
23462
- page.set(blob, blobByteOffset);
24305
+ if (blob.length > 511 - blobByteOffset)
24306
+ throw new Error("PAPX blob exceeds page capacity");
24307
+ if (blob.length > 0) {
24308
+ page[8] = blobByteOffset / 2;
24309
+ page.set(blob, blobByteOffset);
24310
+ }
23463
24311
  page[PAGE_SIZE - 1] = 1;
23464
24312
  return page;
23465
24313
  }
@@ -23470,6 +24318,8 @@ function buildSingleRunChpxPage(fcStart, fcEnd, blob) {
23470
24318
  view.setInt32(4, fcEnd, true);
23471
24319
  if (blob.length > 0) {
23472
24320
  const blobByteOffset = 10;
24321
+ if (blob.length > 511 - blobByteOffset)
24322
+ throw new Error("CHPX blob exceeds page capacity");
23473
24323
  page[8] = blobByteOffset / 2;
23474
24324
  page.set(blob, blobByteOffset);
23475
24325
  }
@@ -23478,12 +24328,12 @@ function buildSingleRunChpxPage(fcStart, fcEnd, blob) {
23478
24328
  }
23479
24329
  var PAGE_SIZE;
23480
24330
  var init_ole_document_doc_fkp = __esm({
23481
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fkp.js"() {
24331
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fkp.js"() {
23482
24332
  PAGE_SIZE = 512;
23483
24333
  }
23484
24334
  });
23485
24335
 
23486
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cp1252.js
24336
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cp1252.js
23487
24337
  function decodeCp1252Byte(byte) {
23488
24338
  if (byte >= 128 && byte <= 159) {
23489
24339
  return CP1252_HIGH_BLOCK[byte - 128];
@@ -23517,7 +24367,7 @@ function encodeCp1252(text2) {
23517
24367
  }
23518
24368
  var CP1252_HIGH_BLOCK, CP1252_HIGH_BLOCK_REVERSE;
23519
24369
  var init_ole_document_doc_cp1252 = __esm({
23520
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cp1252.js"() {
24370
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cp1252.js"() {
23521
24371
  CP1252_HIGH_BLOCK = [
23522
24372
  8364,
23523
24373
  129,
@@ -23556,21 +24406,42 @@ var init_ole_document_doc_cp1252 = __esm({
23556
24406
  }
23557
24407
  });
23558
24408
 
23559
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-pieces.js
23560
- function parsePieceTable(tableStream, clx) {
24409
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-pieces.js
24410
+ function parseDocClx(tableStream, clx, maxPieces) {
24411
+ if (maxPieces !== void 0 && (!Number.isSafeInteger(maxPieces) || maxPieces < 0))
24412
+ throw new Error("Invalid DOC piece limit");
23561
24413
  const view = new DataView(tableStream.buffer, tableStream.byteOffset, tableStream.byteLength);
24414
+ if (!Number.isInteger(clx.fc) || !Number.isInteger(clx.lcb) || clx.fc < 0 || clx.lcb < 5 || clx.fc > tableStream.length - clx.lcb)
24415
+ throw new Error("Clx is outside the table stream");
23562
24416
  let off = clx.fc;
23563
24417
  const end = clx.fc + clx.lcb;
24418
+ let prcCount = 0;
23564
24419
  while (off < end) {
23565
24420
  const clxt = view.getUint8(off);
23566
24421
  if (clxt === CLXT_PRC) {
24422
+ if (off + 3 > end)
24423
+ throw new Error("Truncated Prc header");
23567
24424
  const cb = view.getUint16(off + 1, true);
24425
+ if (cb > end - off - 3)
24426
+ throw new Error("Prc extends beyond Clx");
23568
24427
  off += 1 + 2 + cb;
24428
+ prcCount++;
23569
24429
  continue;
23570
24430
  }
23571
24431
  if (clxt === CLXT_PCDT) {
24432
+ if (off + 5 > end)
24433
+ throw new Error("Truncated Pcdt header");
23572
24434
  const lcb = view.getInt32(off + 1, true);
23573
- return parsePlcPcd(view, off + 1 + 4, lcb);
24435
+ if (lcb < 4 || (lcb - 4) % 12 !== 0 || lcb !== end - off - 5)
24436
+ throw new Error("Invalid PlcPcd length");
24437
+ if (maxPieces !== void 0 && (lcb - 4) / 12 > maxPieces)
24438
+ throw new DocResourceLimitError("DOC piece count exceeds the processing limit");
24439
+ const pieces = parsePlcPcd(view, off + 5, lcb);
24440
+ for (const piece of pieces) {
24441
+ if ((piece.prm & 1) !== 0 && piece.prm >>> 1 >= prcCount)
24442
+ throw new Error("Prm1 references a missing Prc");
24443
+ }
24444
+ return { pieces, prcBytes: tableStream.slice(clx.fc, off) };
23574
24445
  }
23575
24446
  throw new Error(`Unrecognised Clx entry type ${clxt} at ${off}`);
23576
24447
  }
@@ -23580,7 +24451,10 @@ function parsePlcPcd(view, plcStart, lcb) {
23580
24451
  const n = Math.floor((lcb - 4) / (4 + 8));
23581
24452
  const cps = [];
23582
24453
  for (let i2 = 0; i2 <= n; i2++) {
23583
- cps.push(view.getInt32(plcStart + i2 * 4, true));
24454
+ const cp = view.getInt32(plcStart + i2 * 4, true);
24455
+ if (i2 === 0 && cp !== 0 || i2 > 0 && cp <= cps[i2 - 1])
24456
+ throw new Error("Piece CPs must start at zero and increase");
24457
+ cps.push(cp);
23584
24458
  }
23585
24459
  const pcdStart = plcStart + (n + 1) * 4;
23586
24460
  const pieces = [];
@@ -23588,6 +24462,8 @@ function parsePlcPcd(view, plcStart, lcb) {
23588
24462
  const pOff = pcdStart + i2 * 8;
23589
24463
  const flagsWord = view.getUint16(pOff, true);
23590
24464
  const fcRaw = view.getUint32(pOff + 2, true);
24465
+ if ((fcRaw & 2147483648) !== 0)
24466
+ throw new Error("Reserved FcCompressed bit is set");
23591
24467
  const prm = view.getUint16(pOff + 6, true);
23592
24468
  const compressed = (fcRaw >>> 30 & 1) === 1;
23593
24469
  const fcField = fcRaw & 1073741823;
@@ -23604,6 +24480,9 @@ function parsePlcPcd(view, plcStart, lcb) {
23604
24480
  }
23605
24481
  function decodePieceText(wordDoc, piece) {
23606
24482
  const charLen = piece.cpEnd - piece.cpStart;
24483
+ const byteLen = charLen * (piece.compressed ? 1 : 2);
24484
+ if (!Number.isInteger(charLen) || charLen < 0 || !Number.isInteger(piece.fc) || piece.fc < 0 || piece.fc > wordDoc.length - byteLen)
24485
+ throw new Error("Piece text is outside WordDocument");
23607
24486
  if (piece.compressed) {
23608
24487
  return decodeCp1252(wordDoc.subarray(piece.fc, piece.fc + charLen));
23609
24488
  }
@@ -23614,8 +24493,19 @@ function decodePieceText(wordDoc, piece) {
23614
24493
  }
23615
24494
  return out;
23616
24495
  }
23617
- function decodePiecesText(wordDoc, pieces) {
23618
- return pieces.map((piece) => decodePieceText(wordDoc, piece)).join("");
24496
+ function decodePiecesText(wordDoc, pieces, maxChars) {
24497
+ if (maxChars !== void 0 && (!Number.isInteger(maxChars) || maxChars < 0))
24498
+ throw new Error("Invalid text character limit");
24499
+ const out = [];
24500
+ for (const piece of pieces) {
24501
+ const bytes = (piece.cpEnd - piece.cpStart) * (piece.compressed ? 1 : 2);
24502
+ if (piece.cpEnd < piece.cpStart || piece.fc < 0 || piece.fc > wordDoc.length - bytes)
24503
+ throw new Error("Piece text is outside WordDocument");
24504
+ const end = Math.min(piece.cpEnd, maxChars ?? piece.cpEnd);
24505
+ if (end > piece.cpStart)
24506
+ out.push(decodePieceText(wordDoc, { ...piece, cpEnd: end }));
24507
+ }
24508
+ return out.join("");
23619
24509
  }
23620
24510
  function encodePieceText(text2) {
23621
24511
  const compressedBytes = encodeCp1252(text2);
@@ -23653,7 +24543,7 @@ function replacePieceRange(pieces, cpStart, cpEnd, newPiece) {
23653
24543
  fc: newPiece.fc,
23654
24544
  compressed: newPiece.compressed,
23655
24545
  flagsWord: newPiece.flagsWord,
23656
- prm: 0,
24546
+ prm: newPiece.prm ?? 0,
23657
24547
  charLength: newPiece.charLength
23658
24548
  });
23659
24549
  inserted = true;
@@ -23674,7 +24564,7 @@ function replacePieceRange(pieces, cpStart, cpEnd, newPiece) {
23674
24564
  fc: newPiece.fc,
23675
24565
  compressed: newPiece.compressed,
23676
24566
  flagsWord: newPiece.flagsWord,
23677
- prm: 0,
24567
+ prm: newPiece.prm ?? 0,
23678
24568
  charLength: newPiece.charLength
23679
24569
  });
23680
24570
  }
@@ -23692,7 +24582,7 @@ function replacePieceRange(pieces, cpStart, cpEnd, newPiece) {
23692
24582
  };
23693
24583
  });
23694
24584
  }
23695
- function buildClxBytes(pieces) {
24585
+ function buildClxBytes(pieces, prcBytes = new Uint8Array()) {
23696
24586
  const n = pieces.length;
23697
24587
  const plcLcb = (n + 1) * 4 + n * 8;
23698
24588
  const bytes = new Uint8Array(1 + 4 + plcLcb);
@@ -23713,20 +24603,138 @@ function buildClxBytes(pieces) {
23713
24603
  view.setUint16(off + 6, piece.prm, true);
23714
24604
  off += 8;
23715
24605
  }
23716
- return bytes;
24606
+ const result = new Uint8Array(prcBytes.length + bytes.length);
24607
+ result.set(prcBytes);
24608
+ result.set(bytes, prcBytes.length);
24609
+ parseDocClx(result, { fc: 0, lcb: result.length });
24610
+ return result;
23717
24611
  }
23718
- var CLXT_PRC, CLXT_PCDT;
24612
+ var CLXT_PRC, CLXT_PCDT, DocResourceLimitError;
23719
24613
  var init_ole_document_doc_pieces = __esm({
23720
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-pieces.js"() {
24614
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-pieces.js"() {
23721
24615
  init_ole_document_doc_cp1252();
23722
24616
  CLXT_PRC = 1;
23723
24617
  CLXT_PCDT = 2;
24618
+ DocResourceLimitError = class extends Error {
24619
+ constructor(message) {
24620
+ super(message);
24621
+ this.name = "DocResourceLimitError";
24622
+ }
24623
+ };
23724
24624
  }
23725
24625
  });
23726
24626
 
23727
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-editor.js
24627
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fields.js
24628
+ function checkFieldRanges(markers, editStart, editEnd, maxDepth2) {
24629
+ const stack = [];
24630
+ for (const { cp, ch } of markers) {
24631
+ if (ch === 19) {
24632
+ if (stack.length >= maxDepth2)
24633
+ throw new DocResourceLimitError("DOC field nesting exceeds the processing limit");
24634
+ stack.push({ start: cp, separated: false });
24635
+ } else if (ch === 20) {
24636
+ const field = stack.at(-1);
24637
+ if (!field || field.separated)
24638
+ throw new Error("Invalid DOC field separator nesting");
24639
+ field.separated = true;
24640
+ } else if (ch === 21) {
24641
+ const field = stack.pop();
24642
+ if (!field)
24643
+ throw new Error("Unmatched DOC field end");
24644
+ if (field.start < editEnd && cp + 1 > editStart)
24645
+ throw new UnsupportedDocFieldEditError("Paragraph overlaps a field code/result range");
24646
+ }
24647
+ }
24648
+ if (stack.length)
24649
+ throw new Error("Unterminated DOC field");
24650
+ }
24651
+ function* bodyMarkers(body) {
24652
+ for (let cp = 0; cp < body.length; cp++) {
24653
+ const ch = body.charCodeAt(cp);
24654
+ if (ch >= 19 && ch <= 21)
24655
+ yield { cp, ch };
24656
+ }
24657
+ }
24658
+ function shiftDocMainFieldCps(table, at2, body, editStart, editEnd, delta2, maxFields) {
24659
+ if (![editStart, editEnd, delta2, maxFields].every(Number.isSafeInteger) || editStart < 0 || editEnd <= editStart || editEnd > body.length || maxFields < 0 || body.length + delta2 < 0)
24660
+ throw new Error("Invalid field edit bounds or budget");
24661
+ checkFieldRanges(bodyMarkers(body), editStart, editEnd, maxFields);
24662
+ if (at2.lcb === 0)
24663
+ return void 0;
24664
+ if (!Number.isSafeInteger(at2.fc) || at2.fc < 0 || at2.lcb < 4 || (at2.lcb - 4) % 6 !== 0 || at2.fc > table.length - at2.lcb)
24665
+ throw new Error("Invalid main-story field PLC bounds");
24666
+ const n = (at2.lcb - 4) / 6;
24667
+ if (n > maxFields)
24668
+ throw new DocResourceLimitError("DOC field count exceeds the processing limit");
24669
+ const source = table.subarray(at2.fc, at2.fc + at2.lcb);
24670
+ const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
24671
+ const markers = [];
24672
+ let previous = -1;
24673
+ for (let i2 = 0; i2 < n; i2++) {
24674
+ const cp = view.getInt32(i2 * 4, true);
24675
+ const ch = source[(n + 1) * 4 + i2 * 2] & 31;
24676
+ if (cp <= previous || cp >= body.length || ![19, 20, 21].includes(ch) || body.charCodeAt(cp) !== ch)
24677
+ throw new Error("Invalid main-story field marker");
24678
+ markers.push({ cp, ch });
24679
+ previous = cp;
24680
+ }
24681
+ checkFieldRanges(markers, editStart, editEnd, maxFields);
24682
+ const sentinel = view.getInt32(n * 4, true);
24683
+ if (sentinel < 0 || sentinel <= previous)
24684
+ throw new Error("Invalid field PLC sentinel");
24685
+ const result = source.slice();
24686
+ const out = new DataView(result.buffer);
24687
+ let shiftedLast = -1;
24688
+ for (let i2 = 0; i2 < n; i2++) {
24689
+ const cp = markers[i2].cp;
24690
+ const shifted = cp >= editEnd ? cp + delta2 : cp;
24691
+ if (shifted < 0 || shifted >= body.length + delta2 || shifted <= shiftedLast)
24692
+ throw new Error("Field position shifts outside the main story");
24693
+ out.setInt32(i2 * 4, shifted, true);
24694
+ shiftedLast = shifted;
24695
+ }
24696
+ let shiftedSentinel = sentinel >= editEnd ? sentinel + delta2 : sentinel;
24697
+ if (shiftedSentinel > 2147483647 || shiftedSentinel <= shiftedLast)
24698
+ shiftedSentinel = sentinel;
24699
+ if (shiftedSentinel <= shiftedLast)
24700
+ throw new Error("No representable field PLC sentinel");
24701
+ out.setInt32(n * 4, shiftedSentinel, true);
24702
+ return result;
24703
+ }
24704
+ var UnsupportedDocFieldEditError;
24705
+ var init_ole_document_doc_fields = __esm({
24706
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fields.js"() {
24707
+ init_ole_document_doc_pieces();
24708
+ UnsupportedDocFieldEditError = class extends Error {
24709
+ constructor(message) {
24710
+ super(message);
24711
+ this.name = "UnsupportedDocFieldEditError";
24712
+ }
24713
+ };
24714
+ }
24715
+ });
24716
+
24717
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-editor.js
24718
+ function processingLimits(limits) {
24719
+ const resolved = {
24720
+ maxCharacters: limits?.maxCharacters ?? DEFAULT_OLE_DOC_PROCESSING_LIMITS.maxCharacters,
24721
+ maxPieces: limits?.maxPieces ?? DEFAULT_OLE_DOC_PROCESSING_LIMITS.maxPieces,
24722
+ maxFieldRecords: limits?.maxFieldRecords ?? DEFAULT_OLE_DOC_PROCESSING_LIMITS.maxFieldRecords
24723
+ };
24724
+ if (!Number.isSafeInteger(resolved.maxCharacters) || resolved.maxCharacters < 0 || !Number.isSafeInteger(resolved.maxPieces) || resolved.maxPieces < 0 || !Number.isSafeInteger(resolved.maxFieldRecords) || resolved.maxFieldRecords < 0)
24725
+ throw new Error("DOC processing limits must be nonnegative safe integers");
24726
+ return resolved;
24727
+ }
23728
24728
  function hasUnsupportedFeatures(wordDoc, fib) {
24729
+ if (fib.ccpOtherStories > 0)
24730
+ return true;
24731
+ for (let index = 93; index < fib.fibRgFcLcbCount; index++) {
24732
+ if (!SAFE_EXTENDED_FC_LCB_INDICES.has(index) && readFcLcbAt(wordDoc, fib, index).lcb !== 0)
24733
+ return true;
24734
+ }
23729
24735
  for (const index of RISKY_PLCF_INDICES) {
24736
+ if (index >= fib.fibRgFcLcbCount)
24737
+ continue;
23730
24738
  if (readFcLcbAt(wordDoc, fib, index).lcb > 4) {
23731
24739
  return true;
23732
24740
  }
@@ -23759,15 +24767,30 @@ function paragraphBoundaries(bodyText) {
23759
24767
  }
23760
24768
  return boundaries;
23761
24769
  }
23762
- function readOleDocParagraphs(docBytes) {
24770
+ function encodePieceTextUtf16(text2) {
24771
+ const bytes = new Uint8Array(text2.length * 2);
24772
+ const view = new DataView(bytes.buffer);
24773
+ for (let i2 = 0; i2 < text2.length; i2++)
24774
+ view.setUint16(i2 * 2, text2.charCodeAt(i2), true);
24775
+ return bytes;
24776
+ }
24777
+ function readOleDocParagraphs(docBytes, limits) {
23763
24778
  try {
24779
+ const budget = processingLimits(limits);
23764
24780
  const cfb = unwrapDocBytes(docBytes);
23765
24781
  if (!cfb) {
23766
24782
  return void 0;
23767
24783
  }
23768
24784
  const fib = readDocFib(cfb.wordDocBytes);
23769
- const pieces = parsePieceTable(cfb.tableBytes, fib.clx);
23770
- const fullText = decodePiecesText(cfb.wordDocBytes, pieces);
24785
+ if (fib.ccpText > budget.maxCharacters)
24786
+ return void 0;
24787
+ const pieces = parseDocClx(cfb.tableBytes, fib.clx, budget.maxPieces).pieces;
24788
+ const totalCp = pieces.at(-1)?.cpEnd ?? 0;
24789
+ if (totalCp > fib.ccpText + fib.ccpOtherStories + 1)
24790
+ return void 0;
24791
+ const fullText = decodePiecesText(cfb.wordDocBytes, pieces, fib.ccpText);
24792
+ if (fullText.length < fib.ccpText)
24793
+ return void 0;
23771
24794
  const bodyText = fullText.slice(0, fib.ccpText);
23772
24795
  const boundaries = paragraphBoundaries(bodyText);
23773
24796
  let start = 0;
@@ -23784,7 +24807,9 @@ function readOleDocParagraphs(docBytes) {
23784
24807
  }
23785
24808
  function shiftSectionTableCps(tableBytes, sed, editEndCp, delta2) {
23786
24809
  const view = new DataView(tableBytes.buffer, tableBytes.byteOffset, tableBytes.byteLength);
23787
- const n = Math.floor((sed.lcb - 4) / (4 + 12));
24810
+ if (sed.lcb < 4 || (sed.lcb - 4) % 16 !== 0 || sed.fc > tableBytes.length - sed.lcb)
24811
+ throw new Error("Invalid section table");
24812
+ const n = (sed.lcb - 4) / 16;
23788
24813
  for (let i2 = 0; i2 <= n; i2++) {
23789
24814
  const off = sed.fc + i2 * 4;
23790
24815
  const cp = view.getInt32(off, true);
@@ -23793,31 +24818,101 @@ function shiftSectionTableCps(tableBytes, sed, editEndCp, delta2) {
23793
24818
  }
23794
24819
  }
23795
24820
  }
23796
- function writeOleDocParagraphEdit(docBytes, paragraphIndex, text2) {
24821
+ function writeOleDocParagraphEdit(docBytes, paragraphIndex, text2, limits) {
24822
+ return tryWriteOleDocParagraphEdit(docBytes, paragraphIndex, text2, limits).bytes;
24823
+ }
24824
+ function tryWriteOleDocParagraphEdit(docBytes, paragraphIndex, text2, limits) {
24825
+ const rejected = (reason) => ({ status: "rejected", bytes: docBytes, reason });
24826
+ let budget;
24827
+ try {
24828
+ budget = processingLimits(limits);
24829
+ } catch {
24830
+ return rejected("invalid-limits");
24831
+ }
24832
+ if (text2.length > budget.maxCharacters)
24833
+ return rejected("resource-limit");
24834
+ if (!Number.isInteger(paragraphIndex) || paragraphIndex < 0)
24835
+ return rejected("invalid-paragraph-index");
24836
+ if (/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/u.test(text2))
24837
+ return rejected("invalid-text");
23797
24838
  try {
23798
24839
  const cfb = unwrapDocBytes(docBytes);
23799
24840
  if (!cfb) {
23800
- return docBytes;
24841
+ return rejected("invalid-payload");
23801
24842
  }
23802
24843
  const fib = readDocFib(cfb.wordDocBytes);
23803
- if (hasUnsupportedFeatures(cfb.wordDocBytes, fib)) {
23804
- return docBytes;
23805
- }
23806
- const pieces = parsePieceTable(cfb.tableBytes, fib.clx);
23807
- const fullText = decodePiecesText(cfb.wordDocBytes, pieces);
24844
+ if (fib.ccpText > budget.maxCharacters)
24845
+ return rejected("resource-limit");
24846
+ const { pieces, prcBytes } = parseDocClx(cfb.tableBytes, fib.clx, budget.maxPieces);
24847
+ const totalCp = pieces.at(-1)?.cpEnd ?? 0;
24848
+ if (totalCp > fib.ccpText + fib.ccpOtherStories + 1)
24849
+ return rejected("invalid-document");
24850
+ const fullText = decodePiecesText(cfb.wordDocBytes, pieces, fib.ccpText);
24851
+ if (fullText.length < fib.ccpText)
24852
+ return rejected("invalid-document");
23808
24853
  const bodyText = fullText.slice(0, fib.ccpText);
23809
24854
  const boundaries = paragraphBoundaries(bodyText);
23810
24855
  const paragraphEndCp = boundaries[paragraphIndex];
23811
24856
  if (paragraphEndCp === void 0) {
23812
- return docBytes;
24857
+ return rejected("invalid-paragraph-index");
23813
24858
  }
23814
24859
  const paragraphStartCp = paragraphIndex === 0 ? 0 : boundaries[paragraphIndex - 1];
24860
+ if (/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/u.test(bodyText.slice(paragraphStartCp, paragraphEndCp)))
24861
+ return rejected("unsupported-features");
24862
+ const sanitizedText = text2.replaceAll(/[\r\n]+/gu, " ");
24863
+ if (fib.ccpText - (paragraphEndCp - paragraphStartCp) + sanitizedText.length + 1 > budget.maxCharacters)
24864
+ return rejected("resource-limit");
24865
+ if (sanitizedText.length + 1 === paragraphEndCp - paragraphStartCp && bodyText[paragraphEndCp - 1] === "\r") {
24866
+ const replacement = `${sanitizedText}\r`;
24867
+ const patched = cfb.wordDocBytes.slice();
24868
+ let canPatch = true;
24869
+ for (const piece of pieces) {
24870
+ const start = Math.max(paragraphStartCp, piece.cpStart);
24871
+ const end = Math.min(paragraphEndCp, piece.cpEnd);
24872
+ if (start >= end)
24873
+ continue;
24874
+ const part = replacement.slice(start - paragraphStartCp, end - paragraphStartCp);
24875
+ const unit = piece.compressed ? 1 : 2;
24876
+ const fc = piece.fc + (start - piece.cpStart) * unit;
24877
+ const fcEnd = fc + part.length * unit;
24878
+ if (pieces.some((other) => other !== piece && other.fc < fcEnd && other.fc + (other.cpEnd - other.cpStart) * (other.compressed ? 1 : 2) > fc)) {
24879
+ canPatch = false;
24880
+ break;
24881
+ }
24882
+ const encoded = piece.compressed ? encodeCp1252(part) : encodePieceTextUtf16(part);
24883
+ if (!encoded) {
24884
+ canPatch = false;
24885
+ break;
24886
+ }
24887
+ patched.set(encoded, fc);
24888
+ }
24889
+ if (canPatch)
24890
+ return { status: "edited", strategy: "preserved-runs", bytes: cfb.rewrap(patched, cfb.tableBytes) };
24891
+ }
24892
+ if (!cfb.canRewrite)
24893
+ return rejected("unsupported-container");
24894
+ if (hasUnsupportedFeatures(cfb.wordDocBytes, fib))
24895
+ return rejected("unsupported-features");
24896
+ const delta2 = sanitizedText.length + 1 - (paragraphEndCp - paragraphStartCp);
24897
+ const mainFields = readFcLcbAt(cfb.wordDocBytes, fib, 16);
24898
+ if (mainFields.lcb > 0) {
24899
+ for (let index = 0; index < fib.fibRgFcLcbCount; index++) {
24900
+ if (index === 16 || index === 87)
24901
+ continue;
24902
+ const other = readFcLcbAt(cfb.wordDocBytes, fib, index);
24903
+ if (other.lcb > 0 && other.fc < mainFields.fc + mainFields.lcb && other.fc + other.lcb > mainFields.fc)
24904
+ return rejected("invalid-document");
24905
+ }
24906
+ }
24907
+ const shiftedFields = shiftDocMainFieldCps(cfb.tableBytes, mainFields, bodyText, paragraphStartCp, paragraphEndCp, delta2, budget.maxFieldRecords);
23815
24908
  const { piece: startPiece, fc: startFc } = pieceAndFcAtCp(pieces, paragraphStartCp);
24909
+ if (pieces.some((piece) => piece.cpStart < paragraphEndCp && piece.cpEnd > paragraphStartCp && piece.prm !== startPiece.prm))
24910
+ return rejected("unsupported-features");
24911
+ const { fc: paragraphMarkFc } = pieceAndFcAtCp(pieces, paragraphEndCp - 1);
23816
24912
  const papxBte = parseBteTable(cfb.tableBytes, fib.plcfbtePapx);
23817
24913
  const chpxBte = parseBteTable(cfb.tableBytes, fib.plcfbteChpx);
23818
- const papxBlob = extractPapxBlob(cfb.wordDocBytes, papxBte, startFc);
24914
+ const papxBlob = extractPapxBlob(cfb.wordDocBytes, papxBte, paragraphMarkFc);
23819
24915
  const chpxBlob = extractChpxBlob(cfb.wordDocBytes, chpxBte, startFc);
23820
- const sanitizedText = text2.replaceAll(/[\r\n]+/gu, " ");
23821
24916
  const { bytes: textBytes, compressed } = encodePieceText(`${sanitizedText}\r`);
23822
24917
  const originalLen = cfb.wordDocBytes.length;
23823
24918
  const newTextFc = originalLen;
@@ -23845,15 +24940,19 @@ function writeOleDocParagraphEdit(docBytes, paragraphIndex, text2) {
23845
24940
  fc: newTextFc,
23846
24941
  compressed,
23847
24942
  charLength: sanitizedText.length + 1,
23848
- flagsWord: startPiece.flagsWord
24943
+ flagsWord: startPiece.flagsWord,
24944
+ prm: startPiece.prm
23849
24945
  });
23850
- const delta2 = sanitizedText.length + 1 - (paragraphEndCp - paragraphStartCp);
24946
+ if (newPieces.length > budget.maxPieces)
24947
+ return rejected("resource-limit");
23851
24948
  const newCcpText = fib.ccpText + delta2;
23852
- const clxBytes = buildClxBytes(newPieces);
24949
+ const clxBytes = buildClxBytes(newPieces, prcBytes);
23853
24950
  const papxBteBytes = buildBteTableBytes(newPapxBte);
23854
24951
  const chpxBteBytes = buildBteTableBytes(newChpxBte);
23855
24952
  const newTableBytes = new Uint8Array(cfb.tableBytes.length + clxBytes.length + papxBteBytes.length + chpxBteBytes.length);
23856
24953
  newTableBytes.set(cfb.tableBytes, 0);
24954
+ if (shiftedFields)
24955
+ newTableBytes.set(shiftedFields, mainFields.fc);
23857
24956
  let tableOff = cfb.tableBytes.length;
23858
24957
  const newClx = { fc: tableOff, lcb: clxBytes.length };
23859
24958
  newTableBytes.set(clxBytes, tableOff);
@@ -23871,20 +24970,30 @@ function writeOleDocParagraphEdit(docBytes, paragraphIndex, text2) {
23871
24970
  plcfbteChpx: newChpxBteFcLcb,
23872
24971
  plcfbtePapx: newPapxBteFcLcb
23873
24972
  });
23874
- return cfb.rewrap(newWordDoc, newTableBytes);
23875
- } catch {
23876
- return docBytes;
24973
+ return { status: "edited", strategy: "piece-append", bytes: cfb.rewrap(newWordDoc, newTableBytes) };
24974
+ } catch (error) {
24975
+ if (error instanceof UnsupportedDocFieldEditError)
24976
+ return rejected("unsupported-features");
24977
+ if (error instanceof DocResourceLimitError)
24978
+ return rejected("resource-limit");
24979
+ if (error instanceof DocCfbRewriteError)
24980
+ return rejected("unsupported-container");
24981
+ return rejected("invalid-document");
23877
24982
  }
23878
24983
  }
23879
- var RISKY_PLCF_INDICES, RISKY_STTB_INDICES;
24984
+ var RISKY_PLCF_INDICES, RISKY_STTB_INDICES, SAFE_EXTENDED_FC_LCB_INDICES, DEFAULT_OLE_DOC_PROCESSING_LIMITS;
23880
24985
  var init_ole_document_doc_editor = __esm({
23881
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-editor.js"() {
24986
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-editor.js"() {
23882
24987
  init_ole_document_doc_cfb();
23883
24988
  init_ole_document_doc_fib();
23884
24989
  init_ole_document_doc_fkp();
23885
24990
  init_ole_document_doc_pieces();
23886
- RISKY_PLCF_INDICES = [3, 4, 5, 16, 17, 18, 19, 20];
24991
+ init_ole_document_doc_cp1252();
24992
+ init_ole_document_doc_fields();
24993
+ 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];
23887
24994
  RISKY_STTB_INDICES = [21, 22, 23];
24995
+ SAFE_EXTENDED_FC_LCB_INDICES = /* @__PURE__ */ new Set([93, 94, 113, 181, 182]);
24996
+ DEFAULT_OLE_DOC_PROCESSING_LIMITS = Object.freeze({ maxCharacters: 16777216, maxPieces: 65536, maxFieldRecords: 65536 });
23888
24997
  }
23889
24998
  });
23890
24999
 
@@ -23978,7 +25087,7 @@ var init_ole_nested_deck_editor = __esm({
23978
25087
  }
23979
25088
  });
23980
25089
 
23981
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/png-encoder.js
25090
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/png-encoder.js
23982
25091
  function crc32(bytes) {
23983
25092
  let crc = 4294967295;
23984
25093
  for (let i2 = 0; i2 < bytes.length; i2++) {
@@ -24088,7 +25197,7 @@ function decodePngDimensions(png) {
24088
25197
  }
24089
25198
  var CRC_TABLE, PNG_SIGNATURE;
24090
25199
  var init_png_encoder = __esm({
24091
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/png-encoder.js"() {
25200
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/png-encoder.js"() {
24092
25201
  CRC_TABLE = (() => {
24093
25202
  const table = new Uint32Array(256);
24094
25203
  for (let n = 0; n < 256; n++) {
@@ -44746,7 +45855,7 @@ var init_encryption_detection = __esm({
44746
45855
  }
44747
45856
  });
44748
45857
 
44749
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/ooxml-crypto-primitives.js
45858
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/ooxml-crypto-primitives.js
44750
45859
  function getSubtle() {
44751
45860
  if (typeof globalThis.crypto !== "undefined" && globalThis.crypto.subtle) {
44752
45861
  return globalThis.crypto.subtle;
@@ -44864,7 +45973,7 @@ async function hmac(algorithm, key2, data) {
44864
45973
  return new Uint8Array(result);
44865
45974
  }
44866
45975
  var init_ooxml_crypto_primitives = __esm({
44867
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/ooxml-crypto-primitives.js"() {
45976
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/ooxml-crypto-primitives.js"() {
44868
45977
  }
44869
45978
  });
44870
45979
 
@@ -46407,7 +47516,7 @@ var init_md2 = __esm({
46407
47516
  }
46408
47517
  });
46409
47518
 
46410
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/digests/bit-ops.js
47519
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/digests/bit-ops.js
46411
47520
  function rotl32(x, n) {
46412
47521
  return (x << n | x >>> 32 - n) >>> 0;
46413
47522
  }
@@ -46467,11 +47576,11 @@ function mdStyleDigest(message, initialState, transform6) {
46467
47576
  return out;
46468
47577
  }
46469
47578
  var init_bit_ops = __esm({
46470
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/digests/bit-ops.js"() {
47579
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/digests/bit-ops.js"() {
46471
47580
  }
46472
47581
  });
46473
47582
 
46474
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/digests/md4.js
47583
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/digests/md4.js
46475
47584
  function f1(x, y, z) {
46476
47585
  return x & y | ~x & z;
46477
47586
  }
@@ -46495,7 +47604,7 @@ function md4(message) {
46495
47604
  }
46496
47605
  var INITIAL_STATE, K22, K3, ROUND1, ROUND2, ROUND3;
46497
47606
  var init_md4 = __esm({
46498
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/digests/md4.js"() {
47607
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/digests/md4.js"() {
46499
47608
  init_bit_ops();
46500
47609
  INITIAL_STATE = [1732584193, 4023233417, 2562383102, 271733878];
46501
47610
  K22 = 1518500249;
@@ -108825,7 +109934,7 @@ var init_metro_blob_collect = __esm({
108825
109934
  }
108826
109935
  });
108827
109936
 
108828
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/byte-writer.js
109937
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/byte-writer.js
108829
109938
  function record(recType, data, recInstance = 0, isContainer2 = false, recVer = 0) {
108830
109939
  const header = new Uint8Array(8);
108831
109940
  const view = new DataView(header.buffer);
@@ -108840,7 +109949,7 @@ function record(recType, data, recInstance = 0, isContainer2 = false, recVer = 0
108840
109949
  }
108841
109950
  var ByteWriter;
108842
109951
  var init_byte_writer = __esm({
108843
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/byte-writer.js"() {
109952
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/byte-writer.js"() {
108844
109953
  ByteWriter = class {
108845
109954
  chunks = [];
108846
109955
  length = 0;
@@ -108923,13 +110032,13 @@ var init_byte_writer = __esm({
108923
110032
  }
108924
110033
  });
108925
110034
 
108926
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-types.js
110035
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-types.js
108927
110036
  function masterToEmu(mu) {
108928
110037
  return Math.round(mu * EMU_PER_MASTER);
108929
110038
  }
108930
110039
  var RT, OA, TEXT_TYPE, HEADER_TOKEN_PLAIN, HEADER_TOKEN_ENCRYPTED, EMU_PER_MASTER;
108931
110040
  var init_legacy_ppt_record_types = __esm({
108932
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-types.js"() {
110041
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-types.js"() {
108933
110042
  RT = {
108934
110043
  Document: 1e3,
108935
110044
  DocumentAtom: 1001,
@@ -109058,14 +110167,14 @@ var init_legacy_ppt_record_types = __esm({
109058
110167
  }
109059
110168
  });
109060
110169
 
109061
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/record-types.js
110170
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/record-types.js
109062
110171
  var init_record_types = __esm({
109063
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/record-types.js"() {
110172
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/record-types.js"() {
109064
110173
  init_legacy_ppt_record_types();
109065
110174
  }
109066
110175
  });
109067
110176
 
109068
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/current-user-writer.js
110177
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/current-user-writer.js
109069
110178
  function buildCurrentUserStream(offsetToCurrentEdit, encrypted) {
109070
110179
  const nameBytes = new ByteWriter().ansi(USER_NAME).toBytes();
109071
110180
  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();
@@ -109079,7 +110188,7 @@ function buildCurrentUserStream(offsetToCurrentEdit, encrypted) {
109079
110188
  }
109080
110189
  var USER_NAME, CURRENT_USER_STREAM_SIZE;
109081
110190
  var init_current_user_writer = __esm({
109082
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/current-user-writer.js"() {
110191
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/current-user-writer.js"() {
109083
110192
  init_record_types();
109084
110193
  init_byte_writer();
109085
110194
  USER_NAME = "pptx-viewer";
@@ -109087,7 +110196,7 @@ var init_current_user_writer = __esm({
109087
110196
  }
109088
110197
  });
109089
110198
 
109090
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/blip-writer.js
110199
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/blip-writer.js
109091
110200
  function pictureUid(picture) {
109092
110201
  return md4(picture.bytes);
109093
110202
  }
@@ -109110,7 +110219,7 @@ function buildFbse(picture, uid, foDelay, size) {
109110
110219
  }
109111
110220
  var MSOBLIP_PICT, BLIP_INFO;
109112
110221
  var init_blip_writer = __esm({
109113
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/blip-writer.js"() {
110222
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/blip-writer.js"() {
109114
110223
  init_md4();
109115
110224
  init_png_encoder();
109116
110225
  init_record_types();
@@ -109126,7 +110235,7 @@ var init_blip_writer = __esm({
109126
110235
  }
109127
110236
  });
109128
110237
 
109129
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/fopt-writer.js
110238
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/fopt-writer.js
109130
110239
  function boolPropValue(flag, bit, useBit) {
109131
110240
  return useBit | (flag ? bit : 0);
109132
110241
  }
@@ -109162,7 +110271,7 @@ function buildMetroBlobTertiaryFopt(metroBlob) {
109162
110271
  }
109163
110272
  var OPT, FBID_FLAG, METRO_BLOB_OPID;
109164
110273
  var init_fopt_writer = __esm({
109165
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/fopt-writer.js"() {
110274
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/fopt-writer.js"() {
109166
110275
  init_record_types();
109167
110276
  init_byte_writer();
109168
110277
  OPT = {
@@ -109190,7 +110299,7 @@ var init_fopt_writer = __esm({
109190
110299
  }
109191
110300
  });
109192
110301
 
109193
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/bstore-writer.js
110302
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/bstore-writer.js
109194
110303
  function buildDggDefaultProperties() {
109195
110304
  return buildFopt([
109196
110305
  { id: 385, value: 134217732 },
@@ -109248,7 +110357,7 @@ function buildPictureStore(pictures, shapesPerDrawing) {
109248
110357
  }
109249
110358
  var SHAPE_ID_CLUSTER_SIZE;
109250
110359
  var init_bstore_writer = __esm({
109251
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/bstore-writer.js"() {
110360
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/bstore-writer.js"() {
109252
110361
  init_record_types();
109253
110362
  init_blip_writer();
109254
110363
  init_byte_writer();
@@ -109257,7 +110366,7 @@ var init_bstore_writer = __esm({
109257
110366
  }
109258
110367
  });
109259
110368
 
109260
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/font-collection-writer.js
110369
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/font-collection-writer.js
109261
110370
  function buildFontEntityAtom(name, index) {
109262
110371
  const nameBytes = new ByteWriter().utf16(name.slice(0, 31)).u16(0).toBytes();
109263
110372
  const padded = new Uint8Array(LF_FACE_NAME_BYTES);
@@ -109285,14 +110394,14 @@ function buildEnvironment(fonts, otherTextStyle) {
109285
110394
  }
109286
110395
  var LF_FACE_NAME_BYTES;
109287
110396
  var init_font_collection_writer = __esm({
109288
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/font-collection-writer.js"() {
110397
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/font-collection-writer.js"() {
109289
110398
  init_record_types();
109290
110399
  init_byte_writer();
109291
110400
  LF_FACE_NAME_BYTES = 64;
109292
110401
  }
109293
110402
  });
109294
110403
 
109295
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-writer.js
110404
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-writer.js
109296
110405
  function emuToMaster(emu2) {
109297
110406
  return Math.round(emu2 / EMU_PER_MASTER);
109298
110407
  }
@@ -109348,7 +110457,7 @@ function buildDocumentContainer(input) {
109348
110457
  }
109349
110458
  var MASTER_SLIDE_ID_SENTINEL, RT_CSTRING, RT_BINARY_TAG_DATA_BLOB;
109350
110459
  var init_document_writer = __esm({
109351
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-writer.js"() {
110460
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-writer.js"() {
109352
110461
  init_record_types();
109353
110462
  init_byte_writer();
109354
110463
  init_font_collection_writer();
@@ -109358,7 +110467,7 @@ var init_document_writer = __esm({
109358
110467
  }
109359
110468
  });
109360
110469
 
109361
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/hyperlink-writer.js
110470
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/hyperlink-writer.js
109362
110471
  function buildCString(text2, recInstance) {
109363
110472
  return record(RT.CString, new ByteWriter().utf16(text2).toBytes(), recInstance, false, 0);
109364
110473
  }
@@ -109494,7 +110603,7 @@ function buildTextInteractiveInfoAtom(beginChar, endChar) {
109494
110603
  }
109495
110604
  var II_ACTION, II_JUMP, LT, FLAG_CUSTOM_SHOW_RETURN, HyperlinkCollector;
109496
110605
  var init_hyperlink_writer = __esm({
109497
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/hyperlink-writer.js"() {
110606
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/hyperlink-writer.js"() {
109498
110607
  init_record_types();
109499
110608
  init_byte_writer();
109500
110609
  II_ACTION = {
@@ -109557,7 +110666,7 @@ var init_hyperlink_writer = __esm({
109557
110666
  }
109558
110667
  });
109559
110668
 
109560
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/media-writer.js
110669
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/media-writer.js
109561
110670
  function buildCString2(text2, recInstance) {
109562
110671
  return record(RT.CString, new ByteWriter().utf16(text2).toBytes(), recInstance, false, 0);
109563
110672
  }
@@ -109593,7 +110702,7 @@ function buildMediaExObjEntries(media) {
109593
110702
  }
109594
110703
  var MediaCollector, SOUND_EXTENSION_WAV, SOUND_LENGTH_UNKNOWN;
109595
110704
  var init_media_writer = __esm({
109596
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/media-writer.js"() {
110705
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/media-writer.js"() {
109597
110706
  init_record_types();
109598
110707
  init_byte_writer();
109599
110708
  MediaCollector = class {
@@ -109629,7 +110738,7 @@ var init_media_writer = __esm({
109629
110738
  }
109630
110739
  });
109631
110740
 
109632
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/ole-writer.js
110741
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/ole-writer.js
109633
110742
  function hexToBytes(hex3) {
109634
110743
  const out = new Uint8Array(hex3.length / 2);
109635
110744
  for (let i2 = 0; i2 < out.length; i2++) {
@@ -109691,7 +110800,7 @@ function buildExObjRefAtom(exObjId) {
109691
110800
  }
109692
110801
  var PACKAGE_ROOT_CLSID, COMP_OBJ_HEX, EX_OLE_EMBEDDED, DV_ASPECT_ICON, EX_OLE_SUB_DEFAULT, PACKAGER_MENU_NAME, OleCollector;
109693
110802
  var init_ole_writer = __esm({
109694
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/ole-writer.js"() {
110803
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/ole-writer.js"() {
109695
110804
  init_ole2_parser_write();
109696
110805
  init_record_types();
109697
110806
  init_byte_writer();
@@ -109751,7 +110860,7 @@ var init_ole_writer = __esm({
109751
110860
  }
109752
110861
  });
109753
110862
 
109754
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/ex-obj-list-writer.js
110863
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/ex-obj-list-writer.js
109755
110864
  function buildExObjList(hyperlinks, ole, media) {
109756
110865
  const oleEntries = ole?.all ?? [];
109757
110866
  const mediaEntries = media?.all ?? [];
@@ -109778,7 +110887,7 @@ function buildExObjList(hyperlinks, ole, media) {
109778
110887
  return record(RT.ExternalObjectList, w.toBytes(), 0, true);
109779
110888
  }
109780
110889
  var init_ex_obj_list_writer = __esm({
109781
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/ex-obj-list-writer.js"() {
110890
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/ex-obj-list-writer.js"() {
109782
110891
  init_record_types();
109783
110892
  init_byte_writer();
109784
110893
  init_hyperlink_writer();
@@ -109787,7 +110896,7 @@ var init_ex_obj_list_writer = __esm({
109787
110896
  }
109788
110897
  });
109789
110898
 
109790
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/anchor-writer.js
110899
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/anchor-writer.js
109791
110900
  function emuToMaster2(emu2) {
109792
110901
  return Math.round(emu2 / EMU_PER_MASTER);
109793
110902
  }
@@ -109832,7 +110941,7 @@ function buildChildAnchor(rect2) {
109832
110941
  }
109833
110942
  var INT16_MIN, INT16_MAX;
109834
110943
  var init_anchor_writer = __esm({
109835
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/anchor-writer.js"() {
110944
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/anchor-writer.js"() {
109836
110945
  init_record_types();
109837
110946
  init_byte_writer();
109838
110947
  INT16_MIN = -32768;
@@ -109840,7 +110949,7 @@ var init_anchor_writer = __esm({
109840
110949
  }
109841
110950
  });
109842
110951
 
109843
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/colors.js
110952
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/colors.js
109844
110953
  function parseHex(rgb2) {
109845
110954
  const hex3 = (rgb2 ?? DEFAULT_RGB).replace(/^#/u, "");
109846
110955
  if (!/^[0-9a-fA-F]{6}$/u.test(hex3)) {
@@ -109862,12 +110971,12 @@ function encodeColorIndex(rgb2) {
109862
110971
  }
109863
110972
  var DEFAULT_RGB;
109864
110973
  var init_colors = __esm({
109865
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/colors.js"() {
110974
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/colors.js"() {
109866
110975
  DEFAULT_RGB = "000000";
109867
110976
  }
109868
110977
  });
109869
110978
 
109870
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-exception-writer.js
110979
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-exception-writer.js
109871
110980
  function writePfException(w, para) {
109872
110981
  let mask = 0;
109873
110982
  if (para.hasBullet !== void 0) {
@@ -109957,7 +111066,7 @@ function writeCfException(w, run, fontIndex) {
109957
111066
  }
109958
111067
  var ALIGN_CODE, EMU_PER_MASTER_UNIT;
109959
111068
  var init_text_exception_writer = __esm({
109960
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-exception-writer.js"() {
111069
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-exception-writer.js"() {
109961
111070
  init_colors();
109962
111071
  ALIGN_CODE = {
109963
111072
  l: 0,
@@ -109969,7 +111078,7 @@ var init_text_exception_writer = __esm({
109969
111078
  }
109970
111079
  });
109971
111080
 
109972
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-atom-writer.js
111081
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-atom-writer.js
109973
111082
  function joinParagraphText(body) {
109974
111083
  return body.paragraphs.map((p) => p.runs.map((r) => r.text).join("")).join("\r");
109975
111084
  }
@@ -110030,7 +111139,7 @@ function buildTextAtoms(body, fonts, hyperlinks) {
110030
111139
  return new ByteWriter().bytes(buildTextHeaderAtom(body.textType)).bytes(buildTextCharsAtom(text2)).bytes(buildStyleTextPropAtom(body, fontIndex)).bytes(buildRunHyperlinks(body, hyperlinks)).toBytes();
110031
111140
  }
110032
111141
  var init_text_atom_writer = __esm({
110033
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-atom-writer.js"() {
111142
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-atom-writer.js"() {
110034
111143
  init_record_types();
110035
111144
  init_byte_writer();
110036
111145
  init_hyperlink_writer();
@@ -110038,7 +111147,7 @@ var init_text_atom_writer = __esm({
110038
111147
  }
110039
111148
  });
110040
111149
 
110041
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-placeholders-writer.js
111150
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-placeholders-writer.js
110042
111151
  function utf16z(text2) {
110043
111152
  return new ByteWriter().utf16(text2).u16(0).toBytes();
110044
111153
  }
@@ -110135,7 +111244,7 @@ function buildMasterPlaceholders(placeholders, allocator, fieldFontIndex) {
110135
111244
  }
110136
111245
  var FSP_FLAGS, RECTANGLE_SPT, TEXT_TYPE_TITLE, TEXT_TYPE_BODY, TEXT_TYPE_OTHER, SPECS, MASTER_PLACEHOLDER_ORDER, TITLE_PROMPT, BODY_PROMPT, DEFAULT_FRAMES;
110137
111246
  var init_master_placeholders_writer = __esm({
110138
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-placeholders-writer.js"() {
111247
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-placeholders-writer.js"() {
110139
111248
  init_record_types();
110140
111249
  init_anchor_writer();
110141
111250
  init_byte_writer();
@@ -110202,18 +111311,18 @@ var init_master_placeholders_writer = __esm({
110202
111311
  }
110203
111312
  });
110204
111313
 
110205
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-style-fonts.js
111314
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-style-fonts.js
110206
111315
  function masterStyleFonts(styles) {
110207
111316
  if (!styles)
110208
111317
  return [];
110209
111318
  return [styles.title, styles.body, styles.other].flatMap((levels) => levels ?? []).map((level2) => level2.run.fontName).filter((name) => Boolean(name));
110210
111319
  }
110211
111320
  var init_master_style_fonts = __esm({
110212
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-style-fonts.js"() {
111321
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-style-fonts.js"() {
110213
111322
  }
110214
111323
  });
110215
111324
 
110216
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-text-styles-writer.js
111325
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-text-styles-writer.js
110217
111326
  function buildMasterStyleAtom(recInstance, levels, fontIndex) {
110218
111327
  const w = new ByteWriter().u16(levels.length);
110219
111328
  for (const level2 of levels) {
@@ -110244,7 +111353,7 @@ function buildMasterTextStyles(styles, fontIndex) {
110244
111353
  }
110245
111354
  var EMPTY_LEVELS, FIXED_INSTANCE_DATA;
110246
111355
  var init_master_text_styles_writer = __esm({
110247
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-text-styles-writer.js"() {
111356
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-text-styles-writer.js"() {
110248
111357
  init_record_types();
110249
111358
  init_byte_writer();
110250
111359
  init_text_exception_writer();
@@ -110260,7 +111369,7 @@ var init_master_text_styles_writer = __esm({
110260
111369
  }
110261
111370
  });
110262
111371
 
110263
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-props-writer.js
111372
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-props-writer.js
110264
111373
  function fillEntries(fill) {
110265
111374
  if (!fill || fill.kind === "none") {
110266
111375
  return [{ id: OPT.fNoFillHitTest, value: boolPropValue(false, 16, 1048576) }];
@@ -110315,7 +111424,7 @@ function buildShapeFoptProps(input) {
110315
111424
  }
110316
111425
  var DASH_CODE;
110317
111426
  var init_shape_props_writer = __esm({
110318
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-props-writer.js"() {
111427
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-props-writer.js"() {
110319
111428
  init_colors();
110320
111429
  init_fopt_writer();
110321
111430
  DASH_CODE = {
@@ -110330,7 +111439,7 @@ var init_shape_props_writer = __esm({
110330
111439
  }
110331
111440
  });
110332
111441
 
110333
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-writer.js
111442
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-writer.js
110334
111443
  function buildShapeAnchor(rect2, inGroup) {
110335
111444
  return inGroup ? buildChildAnchor(rect2) : buildClientAnchor(rect2);
110336
111445
  }
@@ -110432,7 +111541,7 @@ function buildMediaShapeContainer(media, allocator, hyperlinks, mediaEmbeds, inG
110432
111541
  }
110433
111542
  var FSP_FLAG_FLIPH, FSP_FLAG_FLIPV, FSP_FLAG_OLE_SHAPE, FSP_FLAG_CHILD, PLACEHOLDER_ID;
110434
111543
  var init_shape_writer = __esm({
110435
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-writer.js"() {
111544
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-writer.js"() {
110436
111545
  init_record_types();
110437
111546
  init_anchor_writer();
110438
111547
  init_byte_writer();
@@ -110454,7 +111563,7 @@ var init_shape_writer = __esm({
110454
111563
  }
110455
111564
  });
110456
111565
 
110457
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/group-writer.js
111566
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/group-writer.js
110458
111567
  function buildFspgr(childRect) {
110459
111568
  return record(OA.FSPGR, buildChildAnchorData(childRect), 0, false, 1);
110460
111569
  }
@@ -110495,7 +111604,7 @@ function buildGroupContainer(group, fonts, allocator, hyperlinks, oleEmbeds, med
110495
111604
  }
110496
111605
  var FSP_FLAG_GROUP, FSP_FLAG_PATRIARCH, FSP_FLAG_HAVE_ANCHOR, ZERO_RECT;
110497
111606
  var init_group_writer = __esm({
110498
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/group-writer.js"() {
111607
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/group-writer.js"() {
110499
111608
  init_record_types();
110500
111609
  init_anchor_writer();
110501
111610
  init_byte_writer();
@@ -110507,10 +111616,10 @@ var init_group_writer = __esm({
110507
111616
  }
110508
111617
  });
110509
111618
 
110510
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-id-allocator.js
111619
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-id-allocator.js
110511
111620
  var ShapeIdAllocator2;
110512
111621
  var init_shape_id_allocator = __esm({
110513
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-id-allocator.js"() {
111622
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-id-allocator.js"() {
110514
111623
  ShapeIdAllocator2 = class {
110515
111624
  current;
110516
111625
  constructor(drawingId, clusterSize) {
@@ -110536,7 +111645,7 @@ var init_shape_id_allocator = __esm({
110536
111645
  }
110537
111646
  });
110538
111647
 
110539
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/drawing-writer.js
111648
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/drawing-writer.js
110540
111649
  function buildDg(drawingId, shapeCount, lastShapeId) {
110541
111650
  const data = new ByteWriter().u32(shapeCount + 1).u32(lastShapeId).toBytes();
110542
111651
  return record(OA.Dg, data, drawingId, false, 0);
@@ -110567,7 +111676,7 @@ function buildDrawing(canvasRect, shapes, backgroundRgb, fonts, drawingId, hyper
110567
111676
  }
110568
111677
  var FSP_FLAG_BACKGROUND, BACKGROUND_RECT_SPT, SHAPE_ID_CLUSTER_SIZE2;
110569
111678
  var init_drawing_writer = __esm({
110570
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/drawing-writer.js"() {
111679
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/drawing-writer.js"() {
110571
111680
  init_record_types();
110572
111681
  init_byte_writer();
110573
111682
  init_colors();
@@ -110580,7 +111689,7 @@ var init_drawing_writer = __esm({
110580
111689
  }
110581
111690
  });
110582
111691
 
110583
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/notes-writer.js
111692
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/notes-writer.js
110584
111693
  function buildNotesAtom(slidePersistIdRef) {
110585
111694
  const data = new ByteWriter().i32(slidePersistIdRef).u16(0).u16(0).toBytes();
110586
111695
  return record(RT.NotesAtom, data, 0, false, 1);
@@ -110598,16 +111707,16 @@ function buildNotesContainer(paragraphs, notesRect, slidePersistIdRef, fonts, dr
110598
111707
  return record(RT.Notes, data, 0, true);
110599
111708
  }
110600
111709
  var init_notes_writer = __esm({
110601
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/notes-writer.js"() {
111710
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/notes-writer.js"() {
110602
111711
  init_record_types();
110603
111712
  init_byte_writer();
110604
111713
  init_drawing_writer();
110605
111714
  }
110606
111715
  });
110607
111716
 
110608
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-stream.js
111717
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-stream.js
110609
111718
  function readRecord(view, offset) {
110610
- if (offset < 0 || offset + RECORD_HEADER_SIZE > view.byteLength) {
111719
+ if (!Number.isSafeInteger(offset) || offset < 0 || offset + RECORD_HEADER_SIZE > view.byteLength) {
110611
111720
  return void 0;
110612
111721
  }
110613
111722
  const verAndInstance = view.getUint16(offset, true);
@@ -110635,6 +111744,9 @@ function isContainer(rec) {
110635
111744
  return rec.recVer === 15;
110636
111745
  }
110637
111746
  function* iterateRecords(view, start, end) {
111747
+ if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 0 || end < start) {
111748
+ return;
111749
+ }
110638
111750
  let offset = start;
110639
111751
  const limit = Math.min(end, view.byteLength);
110640
111752
  while (offset + RECORD_HEADER_SIZE <= limit) {
@@ -110661,16 +111773,19 @@ function findChild4(view, container2, recType, recInstance) {
110661
111773
  return void 0;
110662
111774
  }
110663
111775
  function findDescendant(view, container2, recType, recInstance) {
110664
- for (const child27 of iterateChildren(view, container2)) {
111776
+ const stack = [iterateChildren(view, container2)];
111777
+ while (stack.length > 0) {
111778
+ const next = stack[stack.length - 1].next();
111779
+ if (next.done) {
111780
+ stack.pop();
111781
+ continue;
111782
+ }
111783
+ const child27 = next.value;
110665
111784
  if (child27.recType === recType && (recInstance === void 0)) {
110666
111785
  return child27;
110667
111786
  }
110668
- if (isContainer(child27)) {
110669
- const found = findDescendant(view, child27, recType, recInstance);
110670
- if (found) {
110671
- return found;
110672
- }
110673
- }
111787
+ if (isContainer(child27))
111788
+ stack.push(iterateChildren(view, child27));
110674
111789
  }
110675
111790
  return void 0;
110676
111791
  }
@@ -110679,7 +111794,7 @@ function recordBytes(data, rec) {
110679
111794
  }
110680
111795
  var PptParseError, RECORD_HEADER_SIZE;
110681
111796
  var init_legacy_ppt_record_stream = __esm({
110682
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-stream.js"() {
111797
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-stream.js"() {
110683
111798
  PptParseError = class extends Error {
110684
111799
  constructor(message) {
110685
111800
  super(message);
@@ -110690,14 +111805,14 @@ var init_legacy_ppt_record_stream = __esm({
110690
111805
  }
110691
111806
  });
110692
111807
 
110693
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/record-stream.js
111808
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/record-stream.js
110694
111809
  var init_record_stream = __esm({
110695
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/record-stream.js"() {
111810
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/record-stream.js"() {
110696
111811
  init_legacy_ppt_record_stream();
110697
111812
  }
110698
111813
  });
110699
111814
 
110700
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/color-scheme.js
111815
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/color-scheme.js
110701
111816
  function toHex3(r, g2, b) {
110702
111817
  return [r, g2, b].map((v) => (v & 255).toString(16).padStart(2, "0").toUpperCase()).join("");
110703
111818
  }
@@ -110748,7 +111863,7 @@ function resolveEscherColor(colorRef, scheme) {
110748
111863
  }
110749
111864
  var SCHEME, DEFAULT_SCHEME;
110750
111865
  var init_color_scheme = __esm({
110751
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/color-scheme.js"() {
111866
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/color-scheme.js"() {
110752
111867
  init_record_stream();
110753
111868
  init_record_types();
110754
111869
  SCHEME = {
@@ -110774,7 +111889,7 @@ var init_color_scheme = __esm({
110774
111889
  }
110775
111890
  });
110776
111891
 
110777
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/color-scheme-writer.js
111892
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/color-scheme-writer.js
110778
111893
  function buildColorSchemeAtom(recInstance = 1, colors) {
110779
111894
  const w = new ByteWriter();
110780
111895
  for (const rgb2 of colors?.length === 8 ? colors : DEFAULT_SCHEME) {
@@ -110783,7 +111898,7 @@ function buildColorSchemeAtom(recInstance = 1, colors) {
110783
111898
  return record(RT.ColorSchemeAtom, w.toBytes(), recInstance, false, 0);
110784
111899
  }
110785
111900
  var init_color_scheme_writer = __esm({
110786
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/color-scheme-writer.js"() {
111901
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/color-scheme-writer.js"() {
110787
111902
  init_color_scheme();
110788
111903
  init_record_types();
110789
111904
  init_byte_writer();
@@ -110791,7 +111906,7 @@ var init_color_scheme_writer = __esm({
110791
111906
  }
110792
111907
  });
110793
111908
 
110794
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/slide-writer.js
111909
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/slide-writer.js
110795
111910
  function buildSlideAtomRaw(geom, masterIdRef, notesIdRef, flags) {
110796
111911
  const data = new ByteWriter().i32(geom).bytes(new Uint8Array(8)).u32(masterIdRef).i32(notesIdRef).u16(flags).u16(0).toBytes();
110797
111912
  return record(RT.SlideAtom, data, 0, false, 2);
@@ -110828,7 +111943,7 @@ function buildMainMasterContainer(slideRect, drawingId, hyperlinks, oleEmbeds, m
110828
111943
  }
110829
111944
  var SLIDE_FLAG_MASTER_OBJECTS, SLIDE_FLAG_MASTER_SCHEME, SLIDE_FLAG_MASTER_BACKGROUND, SLIDE_MASTER_ID_SENTINEL, MASTER_FIRST_COLOR_SCHEME_INSTANCE;
110830
111945
  var init_slide_writer = __esm({
110831
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/slide-writer.js"() {
111946
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/slide-writer.js"() {
110832
111947
  init_record_types();
110833
111948
  init_byte_writer();
110834
111949
  init_color_scheme_writer();
@@ -110843,7 +111958,7 @@ var init_slide_writer = __esm({
110843
111958
  }
110844
111959
  });
110845
111960
 
110846
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-stream-layout.js
111961
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-stream-layout.js
110847
111962
  function masterSlideId(index) {
110848
111963
  return MASTER_SLIDE_ID_SENTINEL + index;
110849
111964
  }
@@ -110967,7 +112082,7 @@ function ensureMinimumDocumentStreamSize(contentSizeWithoutPadding, maxPersistId
110967
112082
  }
110968
112083
  var DOC_ID, MASTER_ID;
110969
112084
  var init_document_stream_layout = __esm({
110970
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-stream-layout.js"() {
112085
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-stream-layout.js"() {
110971
112086
  init_bstore_writer();
110972
112087
  init_byte_writer();
110973
112088
  init_document_writer();
@@ -110985,15 +112100,15 @@ var init_document_stream_layout = __esm({
110985
112100
  }
110986
112101
  });
110987
112102
 
110988
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/crypto-constants.js
112103
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/crypto-constants.js
110989
112104
  var RC4_ALG_ID2;
110990
112105
  var init_crypto_constants = __esm({
110991
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/crypto-constants.js"() {
112106
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/crypto-constants.js"() {
110992
112107
  RC4_ALG_ID2 = 26625;
110993
112108
  }
110994
112109
  });
110995
112110
 
110996
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/rc4-cipher.js
112111
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/rc4-cipher.js
110997
112112
  function rc4Cipher(key2, data) {
110998
112113
  if (key2.length === 0) {
110999
112114
  throw new Error("RC4 key must not be empty.");
@@ -111024,11 +112139,11 @@ function rc4Cipher(key2, data) {
111024
112139
  return out;
111025
112140
  }
111026
112141
  var init_rc4_cipher = __esm({
111027
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/rc4-cipher.js"() {
112142
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/rc4-cipher.js"() {
111028
112143
  }
111029
112144
  });
111030
112145
 
111031
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-key.js
112146
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-key.js
111032
112147
  async function rc4CryptoApiKeyBase(password, salt) {
111033
112148
  return hash("SHA-1", concatArrays(salt, encodePasswordUtf16LE(password)));
111034
112149
  }
@@ -111069,14 +112184,14 @@ async function rc4CryptoApiEncryptVerifier(key0, verifier) {
111069
112184
  }
111070
112185
  var PADDED_40_BIT_KEY_BYTES;
111071
112186
  var init_rc4_cryptoapi_key = __esm({
111072
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-key.js"() {
112187
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-key.js"() {
111073
112188
  init_ooxml_crypto_primitives();
111074
112189
  init_rc4_cipher();
111075
112190
  PADDED_40_BIT_KEY_BYTES = 16;
111076
112191
  }
111077
112192
  });
111078
112193
 
111079
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-streams.js
112194
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-streams.js
111080
112195
  function readHeader(bytes) {
111081
112196
  const view = new DataView(bytes.buffer, bytes.byteOffset, RECORD_HEADER_SIZE);
111082
112197
  return {
@@ -111145,7 +112260,7 @@ async function cipherPicturesStream(stream, keyFor3, mode) {
111145
112260
  }
111146
112261
  var UID_SIZE, METAFILE_HEADER_SIZE, BITMAP_TAG_SIZE, METAFILE_BLIPS, BITMAP_BLIPS;
111147
112262
  var init_rc4_cryptoapi_streams = __esm({
111148
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-streams.js"() {
112263
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-streams.js"() {
111149
112264
  init_rc4_cipher();
111150
112265
  init_record_stream();
111151
112266
  UID_SIZE = 16;
@@ -111156,7 +112271,7 @@ var init_rc4_cryptoapi_streams = __esm({
111156
112271
  }
111157
112272
  });
111158
112273
 
111159
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/encrypt-writer.js
112274
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/encrypt-writer.js
111160
112275
  async function buildCryptSession(password) {
111161
112276
  const salt = new Uint8Array(SALT_SIZE);
111162
112277
  crypto.getRandomValues(salt);
@@ -111184,7 +112299,7 @@ async function encryptPicturesStream(stream, ctx) {
111184
112299
  }
111185
112300
  var CSP_NAME, KEY_SIZE_BITS, SALT_SIZE, VERIFIER_SIZE, VERIFIER_HASH_SIZE, ENCRYPTION_FLAGS;
111186
112301
  var init_encrypt_writer = __esm({
111187
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/encrypt-writer.js"() {
112302
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/encrypt-writer.js"() {
111188
112303
  init_crypto_constants();
111189
112304
  init_rc4_cryptoapi_key();
111190
112305
  init_rc4_cryptoapi_streams();
@@ -111199,7 +112314,7 @@ var init_encrypt_writer = __esm({
111199
112314
  }
111200
112315
  });
111201
112316
 
111202
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-relative-runs.js
112317
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-relative-runs.js
111203
112318
  function levelsFor(styles, textType) {
111204
112319
  switch (textType) {
111205
112320
  case 0:
@@ -111265,12 +112380,12 @@ function withMasterRelativeRunStyles(deck) {
111265
112380
  }
111266
112381
  var STYLE_KEYS;
111267
112382
  var init_master_relative_runs = __esm({
111268
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-relative-runs.js"() {
112383
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-relative-runs.js"() {
111269
112384
  STYLE_KEYS = ["bold", "italic", "underline"];
111270
112385
  }
111271
112386
  });
111272
112387
 
111273
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/persist-writer.js
112388
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/persist-writer.js
111274
112389
  function buildPersistDirectoryAtom(entries) {
111275
112390
  const sorted = [...entries].sort((a, b) => a[0] - b[0]);
111276
112391
  const w = new ByteWriter();
@@ -111300,17 +112415,17 @@ function buildEncryptedUserEditAtom(input) {
111300
112415
  }
111301
112416
  var MAX_RUN;
111302
112417
  var init_persist_writer = __esm({
111303
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/persist-writer.js"() {
112418
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/persist-writer.js"() {
111304
112419
  init_record_types();
111305
112420
  init_byte_writer();
111306
112421
  MAX_RUN = 4095;
111307
112422
  }
111308
112423
  });
111309
112424
 
111310
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/ppt-clsid.js
112425
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/ppt-clsid.js
111311
112426
  var PPT_STORAGE_CLSID;
111312
112427
  var init_ppt_clsid = __esm({
111313
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/ppt-clsid.js"() {
112428
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/ppt-clsid.js"() {
111314
112429
  PPT_STORAGE_CLSID = new Uint8Array([
111315
112430
  16,
111316
112431
  141,
@@ -111332,7 +112447,7 @@ var init_ppt_clsid = __esm({
111332
112447
  }
111333
112448
  });
111334
112449
 
111335
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/write-ppt.js
112450
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/write-ppt.js
111336
112451
  async function finishUnencrypted(layout, lastSlideId) {
111337
112452
  const w = new ByteWriter().append(layout.bytes);
111338
112453
  const dirAtom = buildPersistDirectoryAtom(layout.offsets);
@@ -111386,7 +112501,7 @@ async function buildPptFile(deck, options = {}) {
111386
112501
  return new Uint8Array(buildOle2(streams2, PPT_STORAGE_CLSID, 0));
111387
112502
  }
111388
112503
  var init_write_ppt = __esm({
111389
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/write-ppt.js"() {
112504
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/write-ppt.js"() {
111390
112505
  init_ole2_parser_write();
111391
112506
  init_byte_writer();
111392
112507
  init_current_user_writer();
@@ -111398,9 +112513,9 @@ var init_write_ppt = __esm({
111398
112513
  }
111399
112514
  });
111400
112515
 
111401
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-ppt-writer.js
112516
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-ppt-writer.js
111402
112517
  var init_legacy_ppt_writer = __esm({
111403
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-ppt-writer.js"() {
112518
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-ppt-writer.js"() {
111404
112519
  init_write_ppt();
111405
112520
  init_master_style_fonts();
111406
112521
  }
@@ -151283,61 +152398,115 @@ var init_deflate_utils = __esm({
151283
152398
  }
151284
152399
  });
151285
152400
 
151286
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/persist-directory.js
151287
- function parseUserEditAtom(view, offset) {
152401
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/persist-directory.js
152402
+ function checkedLimit(value) {
152403
+ if (!Number.isSafeInteger(value) || value < 1)
152404
+ throw new PptParseError("Invalid persist directory resource limit");
152405
+ return value;
152406
+ }
152407
+ function boundedAtom(view, offset, type) {
151288
152408
  const rec = readRecordOrThrow(view, offset);
151289
- if (rec.recType !== RT.UserEditAtom) {
151290
- throw new PptParseError(`Expected UserEditAtom at offset ${offset}, found recType 0x${rec.recType.toString(16)}`);
152409
+ if (rec.recType !== type || rec.recVer !== 0 || rec.recInstance !== 0) {
152410
+ throw new PptParseError(`Invalid persist atom header at offset ${offset}`);
152411
+ }
152412
+ if (rec.recLen > view.byteLength - rec.dataOffset) {
152413
+ throw new PptParseError(`Persist atom payload out of bounds at offset ${offset}`);
151291
152414
  }
152415
+ return rec;
152416
+ }
152417
+ function parseUserEditAtom(view, offset) {
152418
+ const rec = boundedAtom(view, offset, RT.UserEditAtom);
151292
152419
  if (rec.recLen !== 28 && rec.recLen !== 32) {
151293
152420
  throw new PptParseError(`UserEditAtom has invalid length ${rec.recLen}`);
151294
152421
  }
151295
152422
  const d = rec.dataOffset;
151296
- return {
152423
+ const edit = {
151297
152424
  offsetLastEdit: view.getUint32(d + 8, true),
151298
152425
  offsetPersistDirectory: view.getUint32(d + 12, true),
151299
152426
  docPersistIdRef: view.getUint32(d + 16, true),
151300
152427
  encryptSessionPersistIdRef: rec.recLen === 32 ? view.getUint32(d + 28, true) : void 0
151301
152428
  };
151302
- }
151303
- function parsePersistDirectoryAtom(view, offset) {
151304
- const rec = readRecordOrThrow(view, offset);
151305
- if (rec.recType !== RT.PersistDirectoryAtom) {
151306
- throw new PptParseError(`Expected PersistDirectoryAtom at offset ${offset}, found recType 0x${rec.recType.toString(16)}`);
152429
+ if (view.getUint8(d + 6) !== 0 || view.getUint8(d + 7) !== 3) {
152430
+ throw new PptParseError("Unsupported UserEditAtom storage version");
152431
+ }
152432
+ if (edit.offsetLastEdit >= offset || edit.offsetPersistDirectory <= edit.offsetLastEdit || edit.offsetPersistDirectory >= offset) {
152433
+ throw new PptParseError("Invalid UserEditAtom save history offsets");
151307
152434
  }
152435
+ if (edit.docPersistIdRef !== 1)
152436
+ throw new PptParseError("Invalid document persist identifier");
152437
+ return edit;
152438
+ }
152439
+ function parsePersistDirectoryAtom(view, offset, maxEntries = DEFAULT_MAX_ENTRIES) {
152440
+ checkedLimit(maxEntries);
152441
+ const rec = boundedAtom(view, offset, RT.PersistDirectoryAtom);
151308
152442
  const pairs = [];
151309
152443
  let pos2 = rec.dataOffset;
151310
152444
  const end = rec.dataOffset + rec.recLen;
151311
- while (pos2 + 4 <= end) {
152445
+ const seen = /* @__PURE__ */ new Set();
152446
+ while (pos2 < end) {
152447
+ if (end - pos2 < 4)
152448
+ throw new PptParseError("Truncated persist directory entry");
151312
152449
  const packed = view.getUint32(pos2, true);
151313
152450
  const persistId = packed & 1048575;
151314
152451
  const cPersist = packed >>> 20 & 4095;
151315
152452
  pos2 += 4;
151316
- for (let i2 = 0; i2 < cPersist && pos2 + 4 <= end; i2++, pos2 += 4) {
151317
- pairs.push([persistId + i2, view.getUint32(pos2, true)]);
152453
+ if (persistId > 1048574 || cPersist === 0 || persistId + cPersist - 1 > 1048575) {
152454
+ throw new PptParseError("Invalid persist identifier run");
152455
+ }
152456
+ if (cPersist * 4 > end - pos2)
152457
+ throw new PptParseError("Truncated persist offset run");
152458
+ if (pairs.length + cPersist > maxEntries)
152459
+ throw new PptParseError("Persist directory entry limit exceeded");
152460
+ for (let i2 = 0; i2 < cPersist; i2++, pos2 += 4) {
152461
+ const id = persistId + i2;
152462
+ if (seen.has(id))
152463
+ throw new PptParseError("Duplicate persist identifier");
152464
+ seen.add(id);
152465
+ const objectOffset = view.getUint32(pos2, true);
152466
+ if (objectOffset >= offset || objectOffset + 8 > view.byteLength)
152467
+ throw new PptParseError("Persist object offset out of bounds");
152468
+ pairs.push([id, objectOffset]);
151318
152469
  }
151319
152470
  }
151320
152471
  return pairs;
151321
152472
  }
151322
- function buildPersistDirectory(view, offsetToCurrentEdit) {
152473
+ function buildPersistDirectory(view, offsetToCurrentEdit, limits = {}) {
152474
+ const maxEdits = checkedLimit(limits.maxEdits ?? DEFAULT_MAX_EDITS);
152475
+ const maxEntries = checkedLimit(limits.maxEntries ?? DEFAULT_MAX_ENTRIES);
151323
152476
  const edits = [];
152477
+ const editOffsets = [];
151324
152478
  const seen = /* @__PURE__ */ new Set();
151325
152479
  let offset = offsetToCurrentEdit;
151326
152480
  while (offset !== 0) {
152481
+ if (edits.length >= maxEdits)
152482
+ throw new PptParseError("User edit chain limit exceeded");
151327
152483
  if (seen.has(offset)) {
151328
152484
  throw new PptParseError(`Circular UserEditAtom chain at offset ${offset}`);
151329
152485
  }
151330
152486
  seen.add(offset);
151331
152487
  const edit = parseUserEditAtom(view, offset);
151332
152488
  edits.push(edit);
152489
+ editOffsets.push(offset);
151333
152490
  offset = edit.offsetLastEdit;
151334
152491
  }
151335
152492
  if (edits.length === 0) {
151336
152493
  throw new PptParseError("No UserEditAtom found");
151337
152494
  }
151338
152495
  const directory = /* @__PURE__ */ new Map();
152496
+ let entryCount = 0;
151339
152497
  for (let i2 = edits.length - 1; i2 >= 0; i2--) {
151340
- for (const [id, off] of parsePersistDirectoryAtom(view, edits[i2].offsetPersistDirectory)) {
152498
+ const edit = edits[i2];
152499
+ const dirAtom = boundedAtom(view, edit.offsetPersistDirectory, RT.PersistDirectoryAtom);
152500
+ const editOffset = editOffsets[i2];
152501
+ if (dirAtom.dataOffset + dirAtom.recLen > editOffset)
152502
+ throw new PptParseError("Persist directory overlaps user edit");
152503
+ const entries = parsePersistDirectoryAtom(view, edit.offsetPersistDirectory, maxEntries);
152504
+ entryCount += entries.length;
152505
+ if (entryCount > maxEntries)
152506
+ throw new PptParseError("Save history persist entry limit exceeded");
152507
+ for (const [id, off] of entries) {
152508
+ if (off < edit.offsetLastEdit)
152509
+ throw new PptParseError("Persist object precedes corresponding user edit");
151341
152510
  directory.set(id, off);
151342
152511
  }
151343
152512
  }
@@ -151348,12 +152517,18 @@ function readPersistRecord(view, directory, persistId) {
151348
152517
  if (offset === void 0) {
151349
152518
  return void 0;
151350
152519
  }
151351
- return readRecordOrThrow(view, offset);
152520
+ const rec = readRecordOrThrow(view, offset);
152521
+ if (rec.recLen > view.byteLength - rec.dataOffset)
152522
+ throw new PptParseError("Persist object payload out of bounds");
152523
+ return rec;
151352
152524
  }
152525
+ var DEFAULT_MAX_EDITS, DEFAULT_MAX_ENTRIES;
151353
152526
  var init_persist_directory = __esm({
151354
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/persist-directory.js"() {
152527
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/persist-directory.js"() {
151355
152528
  init_record_stream();
151356
152529
  init_record_types();
152530
+ DEFAULT_MAX_EDITS = 1e4;
152531
+ DEFAULT_MAX_ENTRIES = 1e6;
151357
152532
  }
151358
152533
  });
151359
152534