ooxml-core 0.12.0 → 0.14.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.
Files changed (37) hide show
  1. package/dist/collab/broadcast-transport.d.ts +21 -0
  2. package/dist/collab/broadcast-transport.d.ts.map +1 -0
  3. package/dist/collab/index.cjs +103 -0
  4. package/dist/collab/index.d.ts +2 -0
  5. package/dist/collab/index.d.ts.map +1 -1
  6. package/dist/collab/index.mjs +100 -1
  7. package/dist/collab/package-adapter.d.ts +15 -0
  8. package/dist/collab/package-adapter.d.ts.map +1 -0
  9. package/dist/crypto/index.cjs +118 -31
  10. package/dist/crypto/index.mjs +118 -31
  11. package/dist/docx/load/index.cjs +1273 -110
  12. package/dist/docx/load/index.mjs +1273 -110
  13. package/dist/docx/load/legacy-doc.d.ts.map +1 -1
  14. package/dist/pptx/automation/index.cjs +1479 -304
  15. package/dist/pptx/automation/index.d.ts +1 -1
  16. package/dist/pptx/automation/index.mjs +1479 -304
  17. package/dist/pptx/chunks/{index-LoCVDu8Z.d.ts → index-CT9y69AZ.d.ts} +22 -12
  18. package/dist/pptx/chunks/index-CT9y69AZ.d.ts.map +1 -0
  19. package/dist/pptx/cli/index.cjs +307 -152
  20. package/dist/pptx/cli/index.mjs +307 -152
  21. package/dist/pptx/index.cjs +1479 -304
  22. package/dist/pptx/index.d.ts +1 -1
  23. package/dist/pptx/index.mjs +1479 -304
  24. package/dist/visio/index.cjs +7498 -127
  25. package/dist/visio/index.d.ts +3 -1
  26. package/dist/visio/index.d.ts.map +1 -1
  27. package/dist/visio/index.mjs +7497 -128
  28. package/dist/visio/legacy.d.ts +10 -0
  29. package/dist/visio/legacy.d.ts.map +1 -0
  30. package/dist/visio/load.d.ts +5 -0
  31. package/dist/visio/load.d.ts.map +1 -0
  32. package/dist/visio/model.d.ts +1 -1
  33. package/dist/visio/model.d.ts.map +1 -1
  34. package/dist/xlsx/load/index.cjs +144 -52
  35. package/dist/xlsx/load/index.mjs +144 -52
  36. package/package.json +2 -2
  37. package/dist/pptx/chunks/index-LoCVDu8Z.d.ts.map +0 -1
@@ -15371,10 +15371,10 @@ var init_ole_utils = __esm({
15371
15371
  }
15372
15372
  });
15373
15373
 
15374
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-types.js
15374
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-types.js
15375
15375
  var OLE_MAGIC, ENDOFCHAIN, FREESECT, FATSECT, DIFSECT, MAXREGSECT, ENTRY_TYPE_EMPTY, ENTRY_TYPE_STREAM, ENTRY_TYPE_ROOT, DIR_ENTRY_SIZE, Ole2ParseError;
15376
15376
  var init_ole2_parser_types = __esm({
15377
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-types.js"() {
15377
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-types.js"() {
15378
15378
  OLE_MAGIC = new Uint8Array([208, 207, 17, 224, 161, 177, 26, 225]);
15379
15379
  ENDOFCHAIN = 4294967294;
15380
15380
  FREESECT = 4294967295;
@@ -15394,10 +15394,13 @@ var init_ole2_parser_types = __esm({
15394
15394
  }
15395
15395
  });
15396
15396
 
15397
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-read.js
15397
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-read.js
15398
15398
  function parseOle2(buffer) {
15399
15399
  const data = new Uint8Array(buffer);
15400
15400
  const view = new DataView(buffer);
15401
+ if (data.length < 512) {
15402
+ throw new Ole2ParseError("Truncated OLE2 compound file header");
15403
+ }
15401
15404
  for (let i = 0; i < OLE_MAGIC.length; i++) {
15402
15405
  if (data[i] !== OLE_MAGIC[i]) {
15403
15406
  throw new Ole2ParseError("Not a valid OLE2 compound file");
@@ -15411,8 +15414,15 @@ function parseOle2(buffer) {
15411
15414
  }
15412
15415
  const sectorSizePower = view.getUint16(30, true);
15413
15416
  const miniSectorSizePower = view.getUint16(32, true);
15417
+ if (majorVersion !== 3 && majorVersion !== 4 || sectorSizePower !== (majorVersion === 3 ? 9 : 12) || miniSectorSizePower !== 6) {
15418
+ throw new Ole2ParseError("Unsupported OLE2 version or sector size");
15419
+ }
15414
15420
  const sectorSize = 1 << sectorSizePower;
15415
15421
  const miniSectorSize = 1 << miniSectorSizePower;
15422
+ if (data.length < sectorSize || data.length % sectorSize !== 0) {
15423
+ throw new Ole2ParseError("Truncated OLE2 sector");
15424
+ }
15425
+ const sectorCount = data.length / sectorSize - 1;
15416
15426
  const totalFATSectors = view.getUint32(44, true);
15417
15427
  const firstDirectorySector = view.getUint32(48, true);
15418
15428
  const miniStreamCutoff = view.getUint32(56, true);
@@ -15420,6 +15430,9 @@ function parseOle2(buffer) {
15420
15430
  const totalMiniFATSectors = view.getUint32(64, true);
15421
15431
  const firstDIFATSector = view.getUint32(68, true);
15422
15432
  const totalDIFATSectors = view.getUint32(72, true);
15433
+ if (totalFATSectors > sectorCount || totalMiniFATSectors > sectorCount || totalDIFATSectors > sectorCount) {
15434
+ throw new Ole2ParseError("Allocation table count exceeds file size");
15435
+ }
15423
15436
  function sectorOffset(sector) {
15424
15437
  return (sector + 1) * sectorSize;
15425
15438
  }
@@ -15438,7 +15451,11 @@ function parseOle2(buffer) {
15438
15451
  }
15439
15452
  }
15440
15453
  let difatSector = firstDIFATSector;
15454
+ const difatSeen = /* @__PURE__ */ new Set();
15441
15455
  for (let d = 0; d < totalDIFATSectors && difatSector <= MAXREGSECT; d++) {
15456
+ if (difatSeen.has(difatSector))
15457
+ throw new Ole2ParseError("Circular DIFAT chain");
15458
+ difatSeen.add(difatSector);
15442
15459
  const difatData = readSector(difatSector);
15443
15460
  const difatView = new DataView(difatData.buffer, difatData.byteOffset, difatData.byteLength);
15444
15461
  const entriesPerSector = (sectorSize - 4) / 4;
@@ -15450,11 +15467,14 @@ function parseOle2(buffer) {
15450
15467
  }
15451
15468
  difatSector = difatView.getUint32(sectorSize - 4, true);
15452
15469
  }
15470
+ if (difatSeen.size !== totalDIFATSectors || fatSectors.length !== totalFATSectors || new Set(fatSectors).size !== fatSectors.length || fatSectors.some((id) => difatSeen.has(id))) {
15471
+ throw new Ole2ParseError("Invalid DIFAT allocation table");
15472
+ }
15453
15473
  const fatEntries = [];
15454
15474
  for (const fatSector of fatSectors) {
15455
15475
  const fatData = readSector(fatSector);
15456
15476
  const fatView = new DataView(fatData.buffer, fatData.byteOffset, fatData.byteLength);
15457
- for (let i = 0; i < sectorSize / 4; i++) {
15477
+ for (let i = 0; i < sectorSize / 4 && fatEntries.length < sectorCount; i++) {
15458
15478
  fatEntries.push(fatView.getUint32(i * 4, true));
15459
15479
  }
15460
15480
  }
@@ -15468,8 +15488,12 @@ function parseOle2(buffer) {
15468
15488
  }
15469
15489
  visited.add(current);
15470
15490
  sectors.push(readSector(current));
15471
- current = fatEntries[current] ?? ENDOFCHAIN;
15491
+ if (fatEntries[current] === void 0)
15492
+ throw new Ole2ParseError("Missing FAT chain entry");
15493
+ current = fatEntries[current];
15472
15494
  }
15495
+ if (current !== ENDOFCHAIN)
15496
+ throw new Ole2ParseError("Invalid FAT chain terminator");
15473
15497
  const totalLength = sectors.length * sectorSize;
15474
15498
  const result = new Uint8Array(totalLength);
15475
15499
  let offset = 0;
@@ -15480,16 +15504,14 @@ function parseOle2(buffer) {
15480
15504
  return result;
15481
15505
  }
15482
15506
  function readStream(startSector, size) {
15507
+ if (size === 0)
15508
+ return new Uint8Array(0);
15509
+ if (size > sectorCount * sectorSize)
15510
+ throw new Ole2ParseError("Stream size exceeds file size");
15483
15511
  const raw = readSectorChain(startSector);
15484
- return raw.subarray(0, Math.min(size, raw.length));
15485
- }
15486
- const miniFatEntries = [];
15487
- if (firstMiniFATSector <= MAXREGSECT && totalMiniFATSectors > 0) {
15488
- const miniFatRaw = readSectorChain(firstMiniFATSector);
15489
- const miniFatView = new DataView(miniFatRaw.buffer, miniFatRaw.byteOffset, miniFatRaw.byteLength);
15490
- for (let i = 0; i < miniFatRaw.length / 4; i++) {
15491
- miniFatEntries.push(miniFatView.getUint32(i * 4, true));
15492
- }
15512
+ if (raw.length < size)
15513
+ throw new Ole2ParseError("Truncated stream sector chain");
15514
+ return raw.subarray(0, size);
15493
15515
  }
15494
15516
  const dirRaw = readSectorChain(firstDirectorySector);
15495
15517
  const numEntries = Math.floor(dirRaw.length / DIR_ENTRY_SIZE);
@@ -15502,6 +15524,9 @@ function parseOle2(buffer) {
15502
15524
  if (objectType === ENTRY_TYPE_EMPTY) {
15503
15525
  continue;
15504
15526
  }
15527
+ if (nameLen < 2 || nameLen > 64 || nameLen % 2 !== 0 || entryView.getUint16(nameLen - 2, true) !== 0) {
15528
+ throw new Ole2ParseError("Invalid directory entry name");
15529
+ }
15505
15530
  const nameBytes = Math.max(0, nameLen - 2);
15506
15531
  let name = "";
15507
15532
  for (let j = 0; j < nameBytes; j += 2) {
@@ -15515,8 +15540,11 @@ function parseOle2(buffer) {
15515
15540
  const sizeLow = entryView.getUint32(120, true);
15516
15541
  let size = sizeLow;
15517
15542
  if (majorVersion === 4) {
15518
- entryView.getUint32(124, true);
15519
- size = sizeLow;
15543
+ const sizeHigh = entryView.getUint32(124, true);
15544
+ size = sizeLow + sizeHigh * 4294967296;
15545
+ if (!Number.isSafeInteger(size) || size > sectorCount * sectorSize) {
15546
+ throw new Ole2ParseError("Stream size exceeds supported file bounds");
15547
+ }
15520
15548
  }
15521
15549
  entries.push({
15522
15550
  name,
@@ -15530,11 +15558,28 @@ function parseOle2(buffer) {
15530
15558
  });
15531
15559
  }
15532
15560
  const rootEntry = entries.find((e) => e.type === ENTRY_TYPE_ROOT);
15561
+ if (!rootEntry || entries.filter((e) => e.type === ENTRY_TYPE_ROOT).length !== 1) {
15562
+ throw new Ole2ParseError("Invalid root directory entry");
15563
+ }
15533
15564
  let miniStreamData;
15534
15565
  if (rootEntry && rootEntry.startSector <= MAXREGSECT) {
15535
- miniStreamData = readSectorChain(rootEntry.startSector);
15566
+ miniStreamData = readStream(rootEntry.startSector, rootEntry.size);
15567
+ }
15568
+ const miniFatEntries = [];
15569
+ if (firstMiniFATSector <= MAXREGSECT && totalMiniFATSectors > 0) {
15570
+ const miniFatRaw = readSectorChain(firstMiniFATSector);
15571
+ if (miniFatRaw.length !== totalMiniFATSectors * sectorSize) {
15572
+ throw new Ole2ParseError("Unexpected mini FAT chain length");
15573
+ }
15574
+ const miniFatView = new DataView(miniFatRaw.buffer, miniFatRaw.byteOffset, miniFatRaw.byteLength);
15575
+ const miniCapacity = Math.floor((miniStreamData?.length ?? 0) / miniSectorSize);
15576
+ for (let i = 0; i < miniFatRaw.length / 4 && i < miniCapacity; i++) {
15577
+ miniFatEntries.push(miniFatView.getUint32(i * 4, true));
15578
+ }
15536
15579
  }
15537
15580
  function readMiniStream(startSector, size) {
15581
+ if (size === 0)
15582
+ return new Uint8Array(0);
15538
15583
  if (!miniStreamData) {
15539
15584
  throw new Ole2ParseError("Mini stream container not found");
15540
15585
  }
@@ -15547,17 +15592,24 @@ function parseOle2(buffer) {
15547
15592
  }
15548
15593
  visited.add(current);
15549
15594
  const offset2 = current * miniSectorSize;
15595
+ if (offset2 + miniSectorSize > miniStreamData.length || miniFatEntries[current] === void 0) {
15596
+ throw new Ole2ParseError("Mini stream sector exceeds allocation bounds");
15597
+ }
15550
15598
  sectors.push(miniStreamData.subarray(offset2, offset2 + miniSectorSize));
15551
- current = miniFatEntries[current] ?? ENDOFCHAIN;
15599
+ current = miniFatEntries[current];
15552
15600
  }
15601
+ if (current !== ENDOFCHAIN)
15602
+ throw new Ole2ParseError("Invalid mini FAT chain terminator");
15553
15603
  const totalLength = sectors.length * miniSectorSize;
15604
+ if (totalLength < size)
15605
+ throw new Ole2ParseError("Truncated mini stream sector chain");
15554
15606
  const result = new Uint8Array(totalLength);
15555
15607
  let offset = 0;
15556
15608
  for (const sector of sectors) {
15557
15609
  result.set(sector, offset);
15558
15610
  offset += miniSectorSize;
15559
15611
  }
15560
- return result.subarray(0, Math.min(size, result.length));
15612
+ return result.subarray(0, size);
15561
15613
  }
15562
15614
  function getStream(name) {
15563
15615
  const entry = entries.find((e) => (e.type === ENTRY_TYPE_STREAM || e.type === ENTRY_TYPE_ROOT) && e.name === name);
@@ -15572,7 +15624,7 @@ function parseOle2(buffer) {
15572
15624
  return { entries, getStream };
15573
15625
  }
15574
15626
  var init_ole2_parser_read = __esm({
15575
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-read.js"() {
15627
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-read.js"() {
15576
15628
  init_ole2_parser_types();
15577
15629
  }
15578
15630
  });
@@ -15712,13 +15764,16 @@ var init_ole_embedded_extract = __esm({
15712
15764
  }
15713
15765
  });
15714
15766
 
15715
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-helpers.js
15767
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-helpers.js
15716
15768
  function compareDirEntryNames(a, b) {
15769
+ const ua = a.toUpperCase();
15770
+ const ub = b.toUpperCase();
15771
+ if (ua.length !== a.length || ub.length !== b.length) {
15772
+ throw new Error("CFB stream names with expanding uppercase mappings are unsupported");
15773
+ }
15717
15774
  if (a.length !== b.length) {
15718
15775
  return a.length - b.length;
15719
15776
  }
15720
- const ua = a.toUpperCase();
15721
- const ub = b.toUpperCase();
15722
15777
  for (let i = 0; i < ua.length; i++) {
15723
15778
  const diff = ua.charCodeAt(i) - ub.charCodeAt(i);
15724
15779
  if (diff !== 0) {
@@ -15735,6 +15790,24 @@ function encodeName(name) {
15735
15790
  }
15736
15791
  return bytes;
15737
15792
  }
15793
+ function buildDirectoryTree(entryCount) {
15794
+ const links = /* @__PURE__ */ new Map();
15795
+ let redLevel = 0;
15796
+ for (let remaining = entryCount - 2; remaining >= 0; remaining = Math.floor(remaining / 2) - 1)
15797
+ redLevel++;
15798
+ const build = (low, high, level2) => {
15799
+ if (low > high)
15800
+ return 4294967295;
15801
+ const id = Math.floor((low + high) / 2);
15802
+ links.set(id, {
15803
+ left: build(low, id - 1, level2 + 1),
15804
+ right: build(id + 1, high, level2 + 1),
15805
+ color: level2 === redLevel ? 0 : 1
15806
+ });
15807
+ return id;
15808
+ };
15809
+ return { root: build(1, entryCount - 1, 0), links };
15810
+ }
15738
15811
  function writeFatChain(fat, chain2) {
15739
15812
  for (let i = 0; i < chain2.sectors.length; i++) {
15740
15813
  fat[chain2.sectors[i]] = i < chain2.sectors.length - 1 ? chain2.sectors[i + 1] : ENDOFCHAIN;
@@ -15758,12 +15831,12 @@ function writeInt32Sectors(outBytes, int32Data, firstSector, numSectors, sectorS
15758
15831
  }
15759
15832
  }
15760
15833
  var init_ole2_parser_write_helpers = __esm({
15761
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-helpers.js"() {
15834
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-helpers.js"() {
15762
15835
  init_ole2_parser_types();
15763
15836
  }
15764
15837
  });
15765
15838
 
15766
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-serialize.js
15839
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-serialize.js
15767
15840
  function writeHeader(outView, outBytes, params) {
15768
15841
  outBytes.set(OLE_MAGIC, 0);
15769
15842
  outView.setUint16(24, 62, true);
@@ -15820,6 +15893,7 @@ function writeDifatSectors(outView, params) {
15820
15893
  function serializeDirectoryEntries(dirEntries, numDirSectors, sectorSize) {
15821
15894
  const dirData = new Uint8Array(numDirSectors * sectorSize);
15822
15895
  const dirView = new DataView(dirData.buffer);
15896
+ const tree = buildDirectoryTree(dirEntries.length);
15823
15897
  for (let i = 0; i < dirEntries.length; i++) {
15824
15898
  const entry = dirEntries[i];
15825
15899
  const entryOffset = i * DIR_ENTRY_SIZE;
@@ -15827,17 +15901,17 @@ function serializeDirectoryEntries(dirEntries, numDirSectors, sectorSize) {
15827
15901
  dirData.set(nameBytes.subarray(0, Math.min(nameBytes.length, 64)), entryOffset);
15828
15902
  dirView.setUint16(entryOffset + 64, Math.min((entry.name.length + 1) * 2, 64), true);
15829
15903
  dirData[entryOffset + 66] = entry.type;
15830
- dirData[entryOffset + 67] = 1;
15904
+ dirData[entryOffset + 67] = i === 0 ? 1 : tree.links.get(i).color;
15831
15905
  if (entry.clsid) {
15832
15906
  dirData.set(entry.clsid.subarray(0, 16), entryOffset + 80);
15833
15907
  }
15834
15908
  if (i === 0) {
15835
15909
  dirView.setUint32(entryOffset + 68, 4294967295, true);
15836
15910
  dirView.setUint32(entryOffset + 72, 4294967295, true);
15837
- dirView.setUint32(entryOffset + 76, dirEntries.length > 1 ? 1 : 4294967295, true);
15911
+ dirView.setUint32(entryOffset + 76, tree.root, true);
15838
15912
  } else {
15839
- dirView.setUint32(entryOffset + 68, 4294967295, true);
15840
- dirView.setUint32(entryOffset + 72, i + 1 < dirEntries.length ? i + 1 : 4294967295, true);
15913
+ dirView.setUint32(entryOffset + 68, tree.links.get(i).left, true);
15914
+ dirView.setUint32(entryOffset + 72, tree.links.get(i).right, true);
15841
15915
  dirView.setUint32(entryOffset + 76, 4294967295, true);
15842
15916
  }
15843
15917
  dirView.setUint32(entryOffset + 116, entry.startSector, true);
@@ -15855,17 +15929,32 @@ function writeStreamSectors(outBytes, streamData, chain2, sectorSize) {
15855
15929
  }
15856
15930
  var HEADER_DIFAT_ENTRIES;
15857
15931
  var init_ole2_parser_write_serialize = __esm({
15858
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-serialize.js"() {
15932
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-write-serialize.js"() {
15859
15933
  init_ole2_parser_types();
15860
15934
  init_ole2_parser_write_helpers();
15861
15935
  HEADER_DIFAT_ENTRIES = 109;
15862
15936
  }
15863
15937
  });
15864
15938
 
15865
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-write.js
15939
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-write.js
15866
15940
  function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
15867
15941
  const sectorSize = 512;
15868
15942
  const miniSectorSize = 64;
15943
+ if (rootClsid && rootClsid.length !== 16)
15944
+ throw new Error("Root CLSID must contain 16 bytes");
15945
+ const names = [...streams2.keys()].sort(compareDirEntryNames);
15946
+ for (let i = 0; i < names.length; i++) {
15947
+ const name = names[i];
15948
+ if (name.toUpperCase().length !== name.length) {
15949
+ throw new Error("CFB stream names with expanding uppercase mappings are unsupported");
15950
+ }
15951
+ if (!name.length || name.length > 31 || /[\x00\\/:!]/.test(name)) {
15952
+ throw new Error("CFB stream names must be 1-31 UTF-16 code units without NUL, \\, /, :, or !");
15953
+ }
15954
+ if (i > 0 && compareDirEntryNames(names[i - 1], name) === 0) {
15955
+ throw new Error("Duplicate CFB stream names");
15956
+ }
15957
+ }
15869
15958
  const regularStreams = [];
15870
15959
  const miniStreams = [];
15871
15960
  for (const [name, data] of streams2) {
@@ -15883,7 +15972,7 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
15883
15972
  for (let i = 0; i < numSectors; i++) {
15884
15973
  sectors.push(nextSector++);
15885
15974
  }
15886
- fatChains.set(stream.name, { start: sectors[0] ?? 0, sectors });
15975
+ fatChains.set(stream.name, { start: sectors[0] ?? ENDOFCHAIN, sectors });
15887
15976
  }
15888
15977
  let miniStreamContainer = new Uint8Array(0);
15889
15978
  const miniFatChains = /* @__PURE__ */ new Map();
@@ -15906,7 +15995,7 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
15906
15995
  miniOffset += miniSectorSize;
15907
15996
  }
15908
15997
  miniFatChains.set(stream.name, {
15909
- start: miniSectors[0] ?? 0,
15998
+ start: miniSectors[0] ?? ENDOFCHAIN,
15910
15999
  sectors: miniSectors
15911
16000
  });
15912
16001
  }
@@ -15954,7 +16043,7 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
15954
16043
  nextSector += numDirSectors;
15955
16044
  let firstMiniFATSector = ENDOFCHAIN;
15956
16045
  let numMiniFATSectors = 0;
15957
- if (miniStreams.length > 0) {
16046
+ if (nextMiniSector > 0) {
15958
16047
  numMiniFATSectors = Math.ceil(nextMiniSector * 4 / sectorSize);
15959
16048
  firstMiniFATSector = nextSector;
15960
16049
  nextSector += numMiniFATSectors;
@@ -16028,7 +16117,7 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
16028
16117
  return output;
16029
16118
  }
16030
16119
  var init_ole2_parser_write = __esm({
16031
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-parser-write.js"() {
16120
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-parser-write.js"() {
16032
16121
  init_ole2_parser_types();
16033
16122
  init_ole2_parser_write_helpers();
16034
16123
  init_ole2_parser_write_serialize();
@@ -16730,7 +16819,7 @@ var init_ole_sheet_xlsx_editor = __esm({
16730
16819
  }
16731
16820
  });
16732
16821
 
16733
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-stream-edit.js
16822
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-edit.js
16734
16823
  function chain(table, start, limit) {
16735
16824
  if (start === END && limit === 0)
16736
16825
  return [];
@@ -16809,7 +16898,7 @@ function processCompoundFileStream(input, path, replacement) {
16809
16898
  const fat = [];
16810
16899
  for (const id of fatIds) {
16811
16900
  const bytes = sector(id), dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
16812
- for (let j = 0; j < sectorSize / 4; j++)
16901
+ for (let j = 0; j < sectorSize / 4 && fat.length < sectorCount; j++)
16813
16902
  fat.push(dv.getUint32(j * 4, true));
16814
16903
  }
16815
16904
  const exactChain = (table, start, bytes, unit) => chain(table, start, Math.ceil(bytes / unit));
@@ -16906,9 +16995,10 @@ function processCompoundFileStream(input, path, replacement) {
16906
16995
  if (new Set(metadataSectors).size !== metadataSectors.length)
16907
16996
  return reject();
16908
16997
  const miniFat = [];
16998
+ const miniCapacity = Math.floor(Math.min(root.size, sectorCount * sectorSize) / miniSize);
16909
16999
  for (const id of miniFatSectors) {
16910
17000
  const bytes = sector(id), dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
16911
- for (let j = 0; j < sectorSize / 4; j++)
17001
+ for (let j = 0; j < sectorSize / 4 && miniFat.length < miniCapacity; j++)
16912
17002
  miniFat.push(dv.getUint32(j * 4, true));
16913
17003
  }
16914
17004
  const reserved = /* @__PURE__ */ new Set([...fatIds, ...difatIds, ...dirSectors, ...miniFatSectors]);
@@ -16932,7 +17022,7 @@ function processCompoundFileStream(input, path, replacement) {
16932
17022
  continue;
16933
17023
  const ids = exactChain(miniFat, entry.start, entry.size, miniSize);
16934
17024
  for (const id of ids) {
16935
- if (id * miniSize >= rootMini.size || miniUsed.has(id))
17025
+ if ((id + 1) * miniSize > rootMini.size || miniUsed.has(id))
16936
17026
  return reject();
16937
17027
  miniUsed.add(id);
16938
17028
  }
@@ -16957,6 +17047,8 @@ function processCompoundFileStream(input, path, replacement) {
16957
17047
  });
16958
17048
  return result.slice(0, target.size);
16959
17049
  }
17050
+ if (replacement.length === 0)
17051
+ return input.slice();
16960
17052
  const output = input.slice();
16961
17053
  if (target.size >= miniCutoff) {
16962
17054
  const sectors = exactChain(fat, target.start, target.size, sectorSize);
@@ -16997,7 +17089,7 @@ function replaceCompoundFileStream(input, path, replacement) {
16997
17089
  }
16998
17090
  var END, MAX, NIL, SIZE;
16999
17091
  var init_ole2_stream_edit = __esm({
17000
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole2-stream-edit.js"() {
17092
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-edit.js"() {
17001
17093
  END = 4294967294;
17002
17094
  MAX = 4294967290;
17003
17095
  NIL = 4294967295;
@@ -17005,7 +17097,7 @@ var init_ole2_stream_edit = __esm({
17005
17097
  }
17006
17098
  });
17007
17099
 
17008
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-cfb.js
17100
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-cfb.js
17009
17101
  function unwrapXlsBytes(bytes) {
17010
17102
  if (!isCfb(bytes)) {
17011
17103
  return { workbookBytes: bytes };
@@ -17072,7 +17164,7 @@ function isCfb(bytes) {
17072
17164
  }
17073
17165
  var WORKBOOK_STREAM_NAMES;
17074
17166
  var init_legacy_excel_cfb = __esm({
17075
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-cfb.js"() {
17167
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-cfb.js"() {
17076
17168
  init_ole2_parser_read();
17077
17169
  init_ole2_parser_types();
17078
17170
  init_ole2_parser_write();
@@ -17081,7 +17173,178 @@ var init_legacy_excel_cfb = __esm({
17081
17173
  }
17082
17174
  });
17083
17175
 
17084
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8.js
17176
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-edit.js
17177
+ function encodeRkExact(value) {
17178
+ if (!Number.isFinite(value))
17179
+ return void 0;
17180
+ for (const scale of [1, 100]) {
17181
+ const scaled = value * scale;
17182
+ if (Number.isInteger(scaled) && scaled >= -536870912 && scaled < 536870912) {
17183
+ const rk2 = (scaled << 2 | 2 | (scale === 100 ? 1 : 0)) >>> 0;
17184
+ if (Object.is(decodeRk(rk2), value))
17185
+ return rk2;
17186
+ }
17187
+ const view = new DataView(new ArrayBuffer(8));
17188
+ view.setFloat64(0, scaled, true);
17189
+ const rk = (view.getUint32(4, true) & 4294967292 | (scale === 100 ? 1 : 0)) >>> 0;
17190
+ if (Object.is(decodeRk(rk), value))
17191
+ return rk;
17192
+ }
17193
+ return void 0;
17194
+ }
17195
+ function worksheetRanges(bytes) {
17196
+ const records = readRecords(bytes, 0, bytes.length);
17197
+ const last = records.at(-1);
17198
+ if (!last || bytes.subarray(last.dataOffset + last.length).some((b) => b !== 0))
17199
+ return void 0;
17200
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
17201
+ const ranges = [];
17202
+ let depth = 0;
17203
+ let start;
17204
+ for (const record2 of records) {
17205
+ if (record2.opcode === 2057) {
17206
+ if (record2.length < 4 || view.getUint16(record2.dataOffset, true) !== 1536 || depth >= 64)
17207
+ return void 0;
17208
+ if (depth === 0 && view.getUint16(record2.dataOffset + 2, true) === 16)
17209
+ start = record2.headerOffset;
17210
+ depth++;
17211
+ } else if (record2.opcode === 10) {
17212
+ if (depth === 0 || record2.length !== 0)
17213
+ return void 0;
17214
+ depth--;
17215
+ if (depth === 0 && start !== void 0) {
17216
+ ranges.push({ start, end: record2.dataOffset });
17217
+ start = void 0;
17218
+ }
17219
+ }
17220
+ }
17221
+ if (depth !== 0)
17222
+ return void 0;
17223
+ const globalsEnd = records.find((r) => r.opcode === 10)?.headerOffset ?? 0;
17224
+ const bounds = records.filter((r) => r.opcode === 133 && r.headerOffset < globalsEnd);
17225
+ if (bounds.length === 0)
17226
+ return ranges;
17227
+ const ordered4 = [];
17228
+ const used = /* @__PURE__ */ new Set();
17229
+ for (const bound of bounds) {
17230
+ if (bound.length < 8)
17231
+ return void 0;
17232
+ const p = bound.dataOffset;
17233
+ const nameLength = view.getUint8(p + 6);
17234
+ const width = view.getUint8(p + 7) & 1 ? 2 : 1;
17235
+ if (nameLength < 1 || nameLength > 31 || bound.length !== 8 + nameLength * width)
17236
+ return void 0;
17237
+ const kind = view.getUint8(p + 5);
17238
+ if (![0, 1, 2, 6].includes(kind))
17239
+ return void 0;
17240
+ if (kind !== 0)
17241
+ continue;
17242
+ const offset = view.getUint32(p, true);
17243
+ const range = ranges.find((r) => r.start === offset);
17244
+ if (!range || used.has(offset))
17245
+ return void 0;
17246
+ used.add(offset);
17247
+ ordered4.push(range);
17248
+ }
17249
+ return ordered4.length === ranges.length ? ordered4 : void 0;
17250
+ }
17251
+ function editXlsNumericCell(input, edit) {
17252
+ const unchanged2 = (reason) => ({ status: "unchanged", bytes: input, reason });
17253
+ const sheet = edit.worksheetIndex ?? 0;
17254
+ 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))
17255
+ return unchanged2("invalid-edit");
17256
+ try {
17257
+ const { workbookBytes: bytes, rewrap } = unwrapXlsBytes(input);
17258
+ if (!isSupportedBiff8Workbook(bytes))
17259
+ return unchanged2("unsupported-workbook");
17260
+ const ranges = worksheetRanges(bytes);
17261
+ if (!ranges)
17262
+ return unchanged2("malformed-records");
17263
+ const range = ranges[sheet];
17264
+ if (!range)
17265
+ return unchanged2("sheet-not-found");
17266
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
17267
+ let payload;
17268
+ let packed = false;
17269
+ let depth = 0;
17270
+ let matches = 0;
17271
+ for (const record2 of readRecords(bytes, range.start, range.end)) {
17272
+ if (record2.opcode === 2057) {
17273
+ depth++;
17274
+ continue;
17275
+ }
17276
+ if (record2.opcode === 10) {
17277
+ depth--;
17278
+ continue;
17279
+ }
17280
+ if (depth !== 1)
17281
+ continue;
17282
+ const p = record2.dataOffset;
17283
+ if (record2.opcode === 189) {
17284
+ if (record2.length < 12 || (record2.length - 6) % 6 !== 0)
17285
+ return unchanged2("malformed-records");
17286
+ const first = view.getUint16(p + 2, true);
17287
+ const lastCol = view.getUint16(p + record2.length - 2, true);
17288
+ if (lastCol > 255 || lastCol < first || lastCol - first + 1 !== (record2.length - 6) / 6)
17289
+ return unchanged2("malformed-records");
17290
+ if (view.getUint16(p, true) === edit.row && edit.col >= first && edit.col <= lastCol) {
17291
+ if (++matches > 1)
17292
+ return unchanged2("ambiguous-cell");
17293
+ payload = p + 6 + (edit.col - first) * 6;
17294
+ packed = true;
17295
+ }
17296
+ } else if (record2.opcode === 515 || record2.opcode === 638) {
17297
+ if (record2.length !== (record2.opcode === 515 ? 14 : 10))
17298
+ return unchanged2("malformed-records");
17299
+ if (view.getUint16(p, true) === edit.row && view.getUint16(p + 2, true) === edit.col) {
17300
+ if (++matches > 1)
17301
+ return unchanged2("ambiguous-cell");
17302
+ payload = p + 6;
17303
+ packed = record2.opcode === 638;
17304
+ }
17305
+ } else if ([6, 513, 516, 517, 253, 214].includes(record2.opcode)) {
17306
+ if (record2.length < 6)
17307
+ return unchanged2("malformed-records");
17308
+ if (view.getUint16(p, true) === edit.row && view.getUint16(p + 2, true) === edit.col && ++matches > 1)
17309
+ return unchanged2("ambiguous-cell");
17310
+ } else if (record2.opcode === 190) {
17311
+ if (record2.length < 8 || (record2.length - 6) % 2 !== 0)
17312
+ return unchanged2("malformed-records");
17313
+ const first = view.getUint16(p + 2, true);
17314
+ const lastCol = view.getUint16(p + record2.length - 2, true);
17315
+ if (lastCol > 255 || lastCol < first || lastCol - first + 1 !== (record2.length - 6) / 2)
17316
+ return unchanged2("malformed-records");
17317
+ if (view.getUint16(p, true) === edit.row && edit.col >= first && edit.col <= lastCol && ++matches > 1)
17318
+ return unchanged2("ambiguous-cell");
17319
+ }
17320
+ }
17321
+ if (payload === void 0)
17322
+ return unchanged2("cell-not-supported");
17323
+ const rk = packed ? encodeRkExact(edit.value) : void 0;
17324
+ if (packed && rk === void 0)
17325
+ return unchanged2("inexact-rk");
17326
+ const out = bytes.slice();
17327
+ const outView = new DataView(out.buffer, out.byteOffset, out.byteLength);
17328
+ if (packed)
17329
+ outView.setUint32(payload, rk, true);
17330
+ else
17331
+ outView.setFloat64(payload, edit.value, true);
17332
+ const result = rewrap ? rewrap(out) : out;
17333
+ if (result === input)
17334
+ return unchanged2("container-not-writable");
17335
+ return { status: "edited", bytes: result, recalculationRequired: true };
17336
+ } catch {
17337
+ return unchanged2("malformed-records");
17338
+ }
17339
+ }
17340
+ var init_legacy_excel_biff8_edit = __esm({
17341
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-edit.js"() {
17342
+ init_legacy_excel_biff8();
17343
+ init_legacy_excel_cfb();
17344
+ }
17345
+ });
17346
+
17347
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8.js
17085
17348
  function readRecords(bytes, start, end) {
17086
17349
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
17087
17350
  const records = [];
@@ -17135,7 +17398,7 @@ function findFirstWorksheetRange(bytes) {
17135
17398
  function parseSstSingleRecord(bytes) {
17136
17399
  const records = readRecords(bytes, 0, bytes.length);
17137
17400
  const sst = records.find((r) => r.opcode === OPCODE_SST);
17138
- if (!sst) {
17401
+ if (!sst || sst.length < 8) {
17139
17402
  return [];
17140
17403
  }
17141
17404
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
@@ -17143,7 +17406,8 @@ function parseSstSingleRecord(bytes) {
17143
17406
  let offset = sst.dataOffset + 8;
17144
17407
  const end = sst.dataOffset + sst.length;
17145
17408
  try {
17146
- while (offset + 3 <= end) {
17409
+ const unique = view.getUint32(sst.dataOffset + 4, true);
17410
+ while (strings2.length < unique && offset + 3 <= end) {
17147
17411
  const charCount = view.getUint16(offset, true);
17148
17412
  const flags = view.getUint8(offset + 2);
17149
17413
  offset += 3;
@@ -17153,13 +17417,19 @@ function parseSstSingleRecord(bytes) {
17153
17417
  let richRuns = 0;
17154
17418
  let extLen = 0;
17155
17419
  if (isRich) {
17420
+ if (offset + 2 > end)
17421
+ break;
17156
17422
  richRuns = view.getUint16(offset, true);
17157
17423
  offset += 2;
17158
17424
  }
17159
17425
  if (hasExt) {
17426
+ if (offset + 4 > end)
17427
+ break;
17160
17428
  extLen = view.getUint32(offset, true);
17161
17429
  offset += 4;
17162
17430
  }
17431
+ if (offset + charCount * (isWide ? 2 : 1) + richRuns * 4 + extLen > end)
17432
+ break;
17163
17433
  let text2 = "";
17164
17434
  for (let i = 0; i < charCount; i++) {
17165
17435
  if (isWide) {
@@ -17240,52 +17510,13 @@ function decodeRk(rk) {
17240
17510
  }
17241
17511
  return isDiv100 ? value / 100 : value;
17242
17512
  }
17243
- function encodeRk(value) {
17244
- if (Number.isInteger(value) && Math.abs(value) < 536870912) {
17245
- return (value << 2 | 2) >>> 0;
17246
- }
17247
- const buffer = new ArrayBuffer(8);
17248
- const view = new DataView(buffer);
17249
- view.setFloat64(0, value, false);
17250
- const high32 = view.getUint32(0, false);
17251
- return high32 & 4294967292;
17252
- }
17253
17513
  function writeOleXlsNumericCellEdit(inputBytes, edit) {
17254
- if (!Number.isFinite(edit.value)) {
17255
- return inputBytes;
17256
- }
17257
- const { workbookBytes: xlsBytes, rewrap } = unwrapXlsBytes(inputBytes);
17258
- if (!isSupportedBiff8Workbook(xlsBytes))
17259
- return inputBytes;
17260
- const range = findFirstWorksheetRange(xlsBytes);
17261
- if (!range) {
17262
- return inputBytes;
17263
- }
17264
- const out = new Uint8Array(xlsBytes);
17265
- const view = new DataView(out.buffer, out.byteOffset, out.byteLength);
17266
- for (const record2 of readRecords(out, range.start, range.end)) {
17267
- if (record2.length < 6) {
17268
- continue;
17269
- }
17270
- const row = view.getUint16(record2.dataOffset, true);
17271
- const col = view.getUint16(record2.dataOffset + 2, true);
17272
- if (row !== edit.row || col !== edit.col) {
17273
- continue;
17274
- }
17275
- if (record2.opcode === OPCODE_NUMBER && record2.length >= 14) {
17276
- view.setFloat64(record2.dataOffset + 6, edit.value, true);
17277
- return rewrap ? rewrap(out) : out;
17278
- }
17279
- if (record2.opcode === OPCODE_RK && record2.length >= 10) {
17280
- view.setInt32(record2.dataOffset + 6, encodeRk(edit.value), true);
17281
- return rewrap ? rewrap(out) : out;
17282
- }
17283
- }
17284
- return inputBytes;
17514
+ return editXlsNumericCell(inputBytes, edit).bytes;
17285
17515
  }
17286
17516
  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;
17287
17517
  var init_legacy_excel_biff8 = __esm({
17288
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8.js"() {
17518
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8.js"() {
17519
+ init_legacy_excel_biff8_edit();
17289
17520
  init_legacy_excel_cfb();
17290
17521
  OPCODE_BOF = 2057;
17291
17522
  OPCODE_EOF = 10;
@@ -17314,7 +17545,7 @@ var init_ole_sheet_xls_biff8 = __esm({
17314
17545
  }
17315
17546
  });
17316
17547
 
17317
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-grid.js
17548
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-grid.js
17318
17549
  function biffRecord(opcode, data) {
17319
17550
  return [
17320
17551
  opcode & 255,
@@ -17387,7 +17618,7 @@ function buildXlsRowCellRegion(grid) {
17387
17618
  const colFirst = cols[0] ?? 0;
17388
17619
  const colLast = cols.length > 0 ? cols[cols.length - 1] + 1 : 0;
17389
17620
  rowRecordOffsets.push(bytesOut.length);
17390
- const extra = row.extraRowBytes ?? [255, 0, 0, 0, 0, 1, 15, 0];
17621
+ const extra = row.extraRowBytes ?? [255, 0, 0, 0, 0, 1, 15, 0, 0, 0];
17391
17622
  bytesOut.push(...biffRecord(OPCODE_ROW, [...u16le(r), ...u16le(colFirst), ...u16le(colLast), ...extra]));
17392
17623
  }
17393
17624
  for (const r of rows) {
@@ -17422,8 +17653,12 @@ function buildXlsRowCellRegion(grid) {
17422
17653
  if (rows.length > 0) {
17423
17654
  const dbCellOffset = bytesOut.length;
17424
17655
  const dbData = [0, 0, 0, 0];
17425
- for (const off of firstCellOffsetPerRow) {
17426
- dbData.push(...u16le(dbCellOffset - off));
17656
+ for (let i = 0; i < firstCellOffsetPerRow.length; i++) {
17657
+ const base = i === 0 ? rowRecordOffsets[0] + 20 : firstCellOffsetPerRow[i - 1];
17658
+ const offset = firstCellOffsetPerRow[i] - base;
17659
+ if (offset < 0 || offset > 65535)
17660
+ throw new Error("DBCELL offset exceeds UInt16");
17661
+ dbData.push(...u16le(offset));
17427
17662
  }
17428
17663
  const backToFirstRow = dbCellOffset - rowRecordOffsets[0];
17429
17664
  dbData[0] = backToFirstRow & 255;
@@ -17435,28 +17670,39 @@ function buildXlsRowCellRegion(grid) {
17435
17670
  return Uint8Array.from(bytesOut);
17436
17671
  }
17437
17672
  var init_legacy_excel_biff8_grid = __esm({
17438
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-grid.js"() {
17673
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-grid.js"() {
17439
17674
  init_legacy_excel_biff8();
17440
17675
  }
17441
17676
  });
17442
17677
 
17443
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-writer.js
17444
- function resolveSstIndex(sharedStrings, value) {
17678
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-writer.js
17679
+ function resolveSstIndex(sharedStrings, value, bytes) {
17445
17680
  const existing = sharedStrings.indexOf(value);
17446
- if (existing !== -1) {
17681
+ if (existing !== -1)
17447
17682
  return { index: existing };
17448
- }
17449
- const next = [...sharedStrings, value];
17450
- const data = [];
17451
- data.push(...u16le(next.length & 65535), 0, 0);
17452
- data.push(...u16le(next.length & 65535), 0, 0);
17453
- for (const s of next) {
17454
- data.push(...u16le(s.length), 0);
17455
- for (const ch of s) {
17456
- data.push(ch.charCodeAt(0) & 255);
17457
- }
17458
- }
17459
- return { index: next.length - 1, rebuilt: biffRecord(OPCODE_SST, data) };
17683
+ const records = readRecords(bytes, 0, bytes.length);
17684
+ const sst = records.find((r) => r.opcode === OPCODE_SST);
17685
+ if (!sst || sst.length < 8 || value.length > 32767)
17686
+ throw new Error("Unsupported SST");
17687
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
17688
+ const unique = view.getUint32(sst.dataOffset + 4, true);
17689
+ if (unique !== sharedStrings.length || records[records.indexOf(sst) + 1]?.opcode === 60)
17690
+ throw new Error("Continued or incomplete SST");
17691
+ const data = Array.from(bytes.subarray(sst.dataOffset, sst.dataOffset + sst.length));
17692
+ const wide = Array.from({ length: value.length }, (_, i) => value.charCodeAt(i)).some((c) => c > 255);
17693
+ data.push(...u16le(value.length), wide ? 1 : 0);
17694
+ for (let i = 0; i < value.length; i++) {
17695
+ const c = value.charCodeAt(i);
17696
+ data.push(c & 255);
17697
+ if (wide)
17698
+ data.push(c >> 8);
17699
+ }
17700
+ if (data.length > 8224)
17701
+ throw new Error("SST continuation required");
17702
+ const counts = new DataView(new Uint8Array(data).buffer);
17703
+ counts.setUint32(0, view.getUint32(sst.dataOffset, true) + 1, true);
17704
+ counts.setUint32(4, unique + 1, true);
17705
+ return { index: unique, rebuilt: biffRecord(OPCODE_SST, Array.from(new Uint8Array(counts.buffer))) };
17460
17706
  }
17461
17707
  function tryInPlaceStringEdit(bytes, range, edit, sstIndex) {
17462
17708
  const out = new Uint8Array(bytes);
@@ -17503,18 +17749,27 @@ function patchBoundsheetOffsets(bytes, delta2) {
17503
17749
  return out;
17504
17750
  }
17505
17751
  function writeOleXlsStringCellEdit(inputBytes, edit) {
17752
+ 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)
17753
+ return inputBytes;
17506
17754
  try {
17507
17755
  const { workbookBytes: xlsBytes, rewrap } = unwrapXlsBytes(inputBytes);
17508
17756
  if (!isSupportedBiff8Workbook(xlsBytes))
17509
17757
  return inputBytes;
17510
- const finish2 = (result) => rewrap ? rewrap(result) : result;
17758
+ const finish2 = (result2) => {
17759
+ const records = readRecords(result2, 0, result2.length);
17760
+ const sst = records.find((r) => r.opcode === OPCODE_SST);
17761
+ if (sst && sst.length >= 8) {
17762
+ new DataView(result2.buffer, result2.byteOffset, result2.byteLength).setUint32(sst.dataOffset, records.filter((r) => r.opcode === OPCODE_LABELSST).length, true);
17763
+ }
17764
+ return rewrap ? rewrap(result2) : result2;
17765
+ };
17511
17766
  const ranges = findAllWorksheetRanges(xlsBytes);
17512
17767
  const target = ranges[0];
17513
17768
  if (!target) {
17514
17769
  return inputBytes;
17515
17770
  }
17516
17771
  const sharedStrings = parseSstSingleRecord(xlsBytes);
17517
- const { index: sstIndex, rebuilt: newSstRecord } = resolveSstIndex(sharedStrings, edit.value);
17772
+ const { index: sstIndex, rebuilt: newSstRecord } = resolveSstIndex(sharedStrings, edit.value, xlsBytes);
17518
17773
  if (!newSstRecord) {
17519
17774
  const inPlace = tryInPlaceStringEdit(xlsBytes, target, edit, sstIndex);
17520
17775
  if (inPlace) {
@@ -17527,10 +17782,22 @@ function writeOleXlsStringCellEdit(inputBytes, edit) {
17527
17782
  const allRecords = readRecords(xlsBytes, 0, xlsBytes.length);
17528
17783
  const sstRecord = allRecords.find((r) => r.opcode === OPCODE_SST);
17529
17784
  const extSstRecord = allRecords.find((r) => r.opcode === OPCODE_EXTSST);
17785
+ if (allRecords.filter((r) => r.opcode === OPCODE_BOUNDSHEET).length > 1)
17786
+ return inputBytes;
17787
+ if (sstRecord && extSstRecord && extSstRecord.headerOffset !== sstRecord.dataOffset + sstRecord.length)
17788
+ return inputBytes;
17530
17789
  if (!sstRecord) {
17531
17790
  return inputBytes;
17532
17791
  }
17792
+ const region = findRowCellRegion(xlsBytes, target);
17793
+ const sheetRecords = readRecords(xlsBytes, target.start, target.end);
17794
+ if (sheetRecords.some((r) => [523, 6, 517, 189, 190, OPCODE_LABEL, 214].includes(r.opcode)) || sheetRecords.filter((r) => r.opcode === 2057).length !== 1)
17795
+ return inputBytes;
17796
+ 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)))
17797
+ return inputBytes;
17533
17798
  const grid = parseXlsGrid(xlsBytes, target);
17799
+ if ((/* @__PURE__ */ new Set([...grid.keys(), edit.row])).size > 32)
17800
+ return inputBytes;
17534
17801
  const row = grid.get(edit.row) ?? { cells: /* @__PURE__ */ new Map() };
17535
17802
  row.cells.set(edit.col, {
17536
17803
  ixfe: row.cells.get(edit.col)?.ixfe ?? 15,
@@ -17539,8 +17806,7 @@ function writeOleXlsStringCellEdit(inputBytes, edit) {
17539
17806
  });
17540
17807
  grid.set(edit.row, row);
17541
17808
  const newRegion = buildXlsRowCellRegion(grid);
17542
- const region = findRowCellRegion(xlsBytes, target);
17543
- const sstEnd = extSstRecord ? extSstRecord.dataOffset + extSstRecord.length : sstRecord.dataOffset + sstRecord.length;
17809
+ const sstEnd = extSstRecord && extSstRecord.headerOffset === sstRecord.dataOffset + sstRecord.length ? extSstRecord.dataOffset + extSstRecord.length : sstRecord.dataOffset + sstRecord.length;
17544
17810
  const oldSstSpanLength = sstEnd - sstRecord.headerOffset;
17545
17811
  const newSstSpanLength = newSstRecord ? newSstRecord.length : oldSstSpanLength;
17546
17812
  const patchedXlsBytes = patchBoundsheetOffsets(xlsBytes, newSstSpanLength - oldSstSpanLength);
@@ -17552,13 +17818,26 @@ function writeOleXlsStringCellEdit(inputBytes, edit) {
17552
17818
  ...newRegion,
17553
17819
  ...patchedXlsBytes.subarray(region.end)
17554
17820
  ];
17555
- return finish2(Uint8Array.from(out));
17821
+ const result = Uint8Array.from(out);
17822
+ const dimensions = readRecords(result, 0, result.length).find((r) => r.opcode === OPCODE_DIMENSIONS);
17823
+ if (dimensions) {
17824
+ if (dimensions.length !== 14)
17825
+ return inputBytes;
17826
+ const view = new DataView(result.buffer);
17827
+ const rows = [...grid.keys()];
17828
+ const cols = [...grid.values()].flatMap((row2) => [...row2.cells.keys()]);
17829
+ view.setUint32(dimensions.dataOffset, Math.min(...rows), true);
17830
+ view.setUint32(dimensions.dataOffset + 4, Math.max(...rows) + 1, true);
17831
+ view.setUint16(dimensions.dataOffset + 8, Math.min(...cols), true);
17832
+ view.setUint16(dimensions.dataOffset + 10, Math.max(...cols) + 1, true);
17833
+ }
17834
+ return finish2(result);
17556
17835
  } catch {
17557
17836
  return inputBytes;
17558
17837
  }
17559
17838
  }
17560
17839
  var init_legacy_excel_biff8_writer = __esm({
17561
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-writer.js"() {
17840
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-excel-biff8-writer.js"() {
17562
17841
  init_legacy_excel_biff8();
17563
17842
  init_legacy_excel_biff8_grid();
17564
17843
  init_legacy_excel_cfb();
@@ -17664,15 +17943,20 @@ var init_ole_document_docx_editor = __esm({
17664
17943
  }
17665
17944
  });
17666
17945
 
17667
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fib.js
17946
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fib.js
17668
17947
  function readDocFib(wordDoc) {
17669
17948
  const view = new DataView(wordDoc.buffer, wordDoc.byteOffset, wordDoc.byteLength);
17670
17949
  const wIdent = view.getUint16(0, true);
17671
17950
  if (wIdent !== 42476) {
17672
17951
  throw new Error("Not a WordDocument FIB (bad wIdent)");
17673
17952
  }
17953
+ const nFibBase = view.getUint16(2, true);
17954
+ if (![193, 217, 257, 268, 274].includes(nFibBase))
17955
+ throw new Error("Unsupported Word FIB version");
17674
17956
  const flags1Offset = 10;
17675
17957
  const flags1 = view.getUint16(flags1Offset, true);
17958
+ if ((flags1 & 33024) !== 0)
17959
+ throw new Error("Encrypted or obfuscated Word document");
17676
17960
  const fWhichTblStm = flags1 >> 9 & 1;
17677
17961
  const csw = view.getUint16(32, true);
17678
17962
  const fibRgW97Offset = 34;
@@ -17681,6 +17965,21 @@ function readDocFib(wordDoc) {
17681
17965
  const fibRgLw97Offset = cslwOffset + 2;
17682
17966
  const cbRgFcLcbCountOffset = fibRgLw97Offset + cslw * 4;
17683
17967
  const fibRgFcLcbOffset = cbRgFcLcbCountOffset + 2;
17968
+ const fibRgFcLcbCount = view.getUint16(cbRgFcLcbCountOffset, true);
17969
+ if (csw !== 14 || cslw !== 22 || fibRgFcLcbOffset + fibRgFcLcbCount * 8 + 2 > wordDoc.length)
17970
+ throw new Error("Truncated Word FIB arrays");
17971
+ const cswNewOffset = fibRgFcLcbOffset + fibRgFcLcbCount * 8;
17972
+ const cswNew = view.getUint16(cswNewOffset, true);
17973
+ if (cswNewOffset + 2 + cswNew * 2 > wordDoc.length)
17974
+ throw new Error("Truncated Word FIB extension");
17975
+ const nFib = cswNew === 0 ? nFibBase : view.getUint16(cswNewOffset + 2, true);
17976
+ const expectedCounts = /* @__PURE__ */ new Map([[193, 93], [217, 108], [257, 136], [268, 164], [274, 183]]);
17977
+ if (expectedCounts.get(nFib) !== fibRgFcLcbCount || cswNew !== 0 && cswNew !== (nFib === 274 ? 5 : 2))
17978
+ throw new Error("Word FIB version and array counts disagree");
17979
+ const ccpText = view.getInt32(fibRgLw97Offset + 12, true);
17980
+ const otherStories = [4, 5, 7, 8, 9, 10].map((i) => view.getInt32(fibRgLw97Offset + i * 4, true));
17981
+ if (ccpText < 0 || otherStories.some((cp) => cp < 0))
17982
+ throw new Error("Negative Word story length");
17684
17983
  function fcLcbPair(index) {
17685
17984
  const off = fibRgFcLcbOffset + index * 8;
17686
17985
  return { fc: view.getUint32(off, true), lcb: view.getUint32(off + 4, true) };
@@ -17688,18 +17987,22 @@ function readDocFib(wordDoc) {
17688
17987
  const cbMacOffset = fibRgLw97Offset + 0;
17689
17988
  const ccpTextOffset = fibRgLw97Offset + 12;
17690
17989
  return {
17990
+ nFib,
17991
+ nFibBase,
17691
17992
  flags1Offset,
17692
17993
  flags1,
17693
17994
  tableStreamName: fWhichTblStm ? "1Table" : "0Table",
17694
17995
  cbMacOffset,
17695
17996
  cbMac: view.getUint32(cbMacOffset, true),
17696
17997
  ccpTextOffset,
17697
- ccpText: view.getInt32(ccpTextOffset, true),
17998
+ ccpText,
17999
+ ccpOtherStories: otherStories.reduce((sum, cp) => sum + cp, 0),
17698
18000
  plcfbteChpx: fcLcbPair(FC_LCB_INDEX.plcfbteChpx),
17699
18001
  plcfbtePapx: fcLcbPair(FC_LCB_INDEX.plcfbtePapx),
17700
18002
  sed: fcLcbPair(FC_LCB_INDEX.sed),
17701
18003
  clx: fcLcbPair(FC_LCB_INDEX.clx),
17702
- fibRgFcLcbOffset
18004
+ fibRgFcLcbOffset,
18005
+ fibRgFcLcbCount
17703
18006
  };
17704
18007
  }
17705
18008
  function fcLcbFieldOffset(fib, key2) {
@@ -17707,6 +18010,9 @@ function fcLcbFieldOffset(fib, key2) {
17707
18010
  }
17708
18011
  function readFcLcbAt(wordDoc, fib, index) {
17709
18012
  const view = new DataView(wordDoc.buffer, wordDoc.byteOffset, wordDoc.byteLength);
18013
+ const count = view.getUint16(fib.fibRgFcLcbOffset - 2, true);
18014
+ if (!Number.isInteger(index) || index < 0 || index >= count || fib.fibRgFcLcbCount !== void 0 && fib.fibRgFcLcbCount !== count)
18015
+ throw new Error("FIB fc/lcb index outside declared array");
17710
18016
  const off = fib.fibRgFcLcbOffset + index * 8;
17711
18017
  return { fc: view.getUint32(off, true), lcb: view.getUint32(off + 4, true) };
17712
18018
  }
@@ -17727,7 +18033,7 @@ function patchDocFib(wordDoc, fib, patch) {
17727
18033
  }
17728
18034
  var FC_LCB_INDEX, F_COMPLEX_BIT;
17729
18035
  var init_ole_document_doc_fib = __esm({
17730
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fib.js"() {
18036
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fib.js"() {
17731
18037
  FC_LCB_INDEX = {
17732
18038
  plcfbteChpx: 12,
17733
18039
  plcfbtePapx: 13,
@@ -17738,62 +18044,578 @@ var init_ole_document_doc_fib = __esm({
17738
18044
  }
17739
18045
  });
17740
18046
 
17741
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cfb.js
18047
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-v4.js
18048
+ function follow(table, start) {
18049
+ const ids = [], seen = /* @__PURE__ */ new Set();
18050
+ for (let id = start; id !== END2; id = table[id]) {
18051
+ if (id >= table.length || seen.has(id))
18052
+ throw new Error("Invalid allocation chain");
18053
+ seen.add(id);
18054
+ ids.push(id);
18055
+ }
18056
+ return ids;
18057
+ }
18058
+ function findSlot(slots, path) {
18059
+ let parent = slots.get(0);
18060
+ if (!parent || parent.type !== 5)
18061
+ throw new Error("Invalid root");
18062
+ const parents = /* @__PURE__ */ new Set();
18063
+ for (let part = 0; part < path.length; part++) {
18064
+ if (parents.has(parent.id))
18065
+ throw new Error("Cyclic storage hierarchy");
18066
+ parents.add(parent.id);
18067
+ const stack = [parent.child], seen = /* @__PURE__ */ new Set(), matches = [];
18068
+ while (stack.length) {
18069
+ const id = stack.pop();
18070
+ if (id === FREE)
18071
+ continue;
18072
+ if (seen.has(id))
18073
+ throw new Error("Invalid directory tree");
18074
+ seen.add(id);
18075
+ const slot = slots.get(id);
18076
+ if (!slot)
18077
+ throw new Error("Missing directory slot");
18078
+ if (slot.name.toLocaleLowerCase() === path[part].toLocaleLowerCase())
18079
+ matches.push(slot);
18080
+ stack.push(slot.left, slot.right);
18081
+ }
18082
+ if (matches.length !== 1)
18083
+ throw new Error("Missing or ambiguous stream");
18084
+ parent = matches[0];
18085
+ if (parent.type !== (part === path.length - 1 ? 2 : 1))
18086
+ throw new Error("Invalid storage path");
18087
+ }
18088
+ return parent;
18089
+ }
18090
+ function validateHierarchy(slots) {
18091
+ const owners = /* @__PURE__ */ new Set(), storages = [0];
18092
+ while (storages.length) {
18093
+ const storage = slots.get(storages.pop());
18094
+ const stack = [storage.child], names = /* @__PURE__ */ new Set();
18095
+ while (stack.length) {
18096
+ const id = stack.pop();
18097
+ if (id === FREE)
18098
+ continue;
18099
+ const slot = slots.get(id);
18100
+ if (!slot || slot.type !== 1 && slot.type !== 2 || owners.has(id))
18101
+ throw new Error("Ambiguous directory ownership");
18102
+ const name = slot.name.toLocaleLowerCase();
18103
+ if (names.has(name))
18104
+ throw new Error("Duplicate sibling name");
18105
+ names.add(name);
18106
+ owners.add(id);
18107
+ stack.push(slot.left, slot.right);
18108
+ if (slot.type === 1)
18109
+ storages.push(id);
18110
+ }
18111
+ }
18112
+ if (owners.size !== slots.size - 1)
18113
+ throw new Error("Unreachable directory entries");
18114
+ }
18115
+ function resizeCompoundFileStreamV4(input, path, replacement) {
18116
+ const fail2 = (reason) => ({ ok: false, bytes: input, reason });
18117
+ try {
18118
+ if (input.length < 512 || !path.length || path.some((part) => !part))
18119
+ return fail2("invalid-or-missing-stream");
18120
+ const view = new DataView(input.buffer, input.byteOffset, input.byteLength);
18121
+ const read = (offset) => view.getUint32(offset, true);
18122
+ const version = view.getUint16(26, true);
18123
+ if (version !== 4)
18124
+ return fail2("unsupported-version");
18125
+ const SECTOR3 = 4096, FAT_ENTRIES2 = SECTOR3 / 4, DIRECTORY_ENTRIES = SECTOR3 / 128;
18126
+ if (read(72) !== 0 || read(44) > 109)
18127
+ return fail2("unsupported-difat");
18128
+ const cutoff = read(56);
18129
+ if (cutoff !== 0 && cutoff !== 4096)
18130
+ return fail2("unsupported-layout");
18131
+ const original = readCompoundFileStream(input, path);
18132
+ if (!original)
18133
+ return fail2("invalid-or-missing-stream");
18134
+ const name = path[path.length - 1].toLocaleLowerCase();
18135
+ if (name === "worddocument" && original.length >= 12 && (original[10] | original[11] << 8) & 33024)
18136
+ return fail2("unsafe-edit");
18137
+ if (name === "book" || name === "workbook") {
18138
+ for (let offset = 0; offset + 4 <= original.length; ) {
18139
+ const record2 = original[offset] | original[offset + 1] << 8;
18140
+ const length = original[offset + 2] | original[offset + 3] << 8;
18141
+ if (record2 === 47)
18142
+ return fail2("unsafe-edit");
18143
+ if (record2 === 10 || offset + 4 + length > original.length)
18144
+ break;
18145
+ offset += 4 + length;
18146
+ }
18147
+ }
18148
+ const validated = replaceCompoundFileStream(input, path, original);
18149
+ if (validated === input)
18150
+ return fail2("unsafe-edit");
18151
+ const sameLength = replacement.length === original.length;
18152
+ if (!sameLength && original.length < cutoff)
18153
+ return fail2("unsupported-mini-stream");
18154
+ if (!sameLength && replacement.length < cutoff)
18155
+ return fail2("unsupported-mini-transition");
18156
+ const sectorCount = input.length / SECTOR3 - 1, fatCount = read(44);
18157
+ if (sectorCount > fatCount * FAT_ENTRIES2)
18158
+ return fail2("unsafe-edit");
18159
+ const fatIds = Array.from({ length: fatCount }, (_, i) => read(76 + 4 * i));
18160
+ const fat = [];
18161
+ for (const id of fatIds) {
18162
+ for (let i = 0; i < FAT_ENTRIES2 && fat.length < sectorCount; i++)
18163
+ fat.push(read((id + 1) * SECTOR3 + i * 4));
18164
+ }
18165
+ if (fatIds.some((id) => fat[id] !== FAT))
18166
+ return fail2("unsafe-edit");
18167
+ const slots = /* @__PURE__ */ new Map();
18168
+ const directoryChain = follow(fat, read(48));
18169
+ if (read(40) !== directoryChain.length)
18170
+ return fail2("unsafe-edit");
18171
+ for (const [block, sector] of directoryChain.entries()) {
18172
+ for (let entry = 0; entry < DIRECTORY_ENTRIES; entry++) {
18173
+ const offset = (sector + 1) * SECTOR3 + entry * 128, type = view.getUint8(offset + 66);
18174
+ if (!type)
18175
+ continue;
18176
+ const nameLength = view.getUint16(offset + 64, true);
18177
+ if (![1, 2, 5].includes(type) || nameLength < 2 || nameLength > 64 || nameLength % 2 || view.getUint16(offset + nameLength - 2, true))
18178
+ return fail2("unsafe-edit");
18179
+ let name2 = "";
18180
+ for (let i = 0; i < nameLength - 2; i += 2)
18181
+ name2 += String.fromCharCode(view.getUint16(offset + i, true));
18182
+ if (read(offset + 124) !== 0)
18183
+ return fail2("unsafe-edit");
18184
+ const id = block * DIRECTORY_ENTRIES + entry;
18185
+ 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 });
18186
+ }
18187
+ }
18188
+ if ([...slots.values()].filter((slot) => slot.type === 5).length !== 1)
18189
+ return fail2("unsafe-edit");
18190
+ const target = findSlot(slots, path);
18191
+ validateHierarchy(slots);
18192
+ if (sameLength) {
18193
+ const bytes = replaceCompoundFileStream(input, path, replacement);
18194
+ return bytes === input ? fail2("unsafe-edit") : { ok: true, bytes };
18195
+ }
18196
+ const oldChain = follow(fat, target.start);
18197
+ if (target.size !== original.length || oldChain.length !== Math.ceil(target.size / SECTOR3))
18198
+ return fail2("unsafe-edit");
18199
+ const payloadSectors = Math.ceil(replacement.length / SECTOR3);
18200
+ let newFatCount = fatCount;
18201
+ while (sectorCount + payloadSectors + newFatCount - fatCount > newFatCount * FAT_ENTRIES2)
18202
+ newFatCount++;
18203
+ if (newFatCount > 109)
18204
+ return fail2("allocation-limit");
18205
+ const totalSectors = sectorCount + payloadSectors + newFatCount - fatCount;
18206
+ const output = new Uint8Array((totalSectors + 1) * SECTOR3);
18207
+ output.set(input);
18208
+ output.set(replacement, (sectorCount + 1) * SECTOR3);
18209
+ const outView = new DataView(output.buffer);
18210
+ for (let i = fatCount; i < newFatCount; i++) {
18211
+ const id = sectorCount + payloadSectors + i - fatCount;
18212
+ fatIds.push(id);
18213
+ output.fill(255, (id + 1) * SECTOR3, (id + 2) * SECTOR3);
18214
+ outView.setUint32(76 + i * 4, id, true);
18215
+ }
18216
+ outView.setUint32(44, newFatCount, true);
18217
+ const writeFat = (id, value) => outView.setUint32((fatIds[Math.floor(id / FAT_ENTRIES2)] + 1) * SECTOR3 + id % FAT_ENTRIES2 * 4, value, true);
18218
+ for (const id of oldChain)
18219
+ writeFat(id, FREE);
18220
+ for (let i = 0; i < payloadSectors; i++)
18221
+ writeFat(sectorCount + i, i + 1 === payloadSectors ? END2 : sectorCount + i + 1);
18222
+ for (const id of fatIds)
18223
+ writeFat(id, FAT);
18224
+ outView.setUint32(target.offset + 116, payloadSectors ? sectorCount : END2, true);
18225
+ outView.setUint32(target.offset + 120, replacement.length, true);
18226
+ return { ok: true, bytes: output };
18227
+ } catch {
18228
+ return fail2("unsafe-edit");
18229
+ }
18230
+ }
18231
+ var END2, FREE, FAT;
18232
+ var init_ole2_stream_resize_v4 = __esm({
18233
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-v4.js"() {
18234
+ init_ole2_stream_edit();
18235
+ END2 = 4294967294;
18236
+ FREE = 4294967295;
18237
+ FAT = 4294967293;
18238
+ }
18239
+ });
18240
+
18241
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-allocation.js
18242
+ function appendCompoundAllocations(input, existingFatIds, payloads, sectorSize = 512) {
18243
+ const sectorCount = input.length / sectorSize - 1;
18244
+ const entriesPerFat = sectorSize / 4;
18245
+ const counts = payloads.map((payload) => Math.ceil(payload.length / sectorSize));
18246
+ const payloadSectors = counts.reduce((sum, count) => sum + count, 0);
18247
+ let fatCount = existingFatIds.length;
18248
+ while (sectorCount + payloadSectors + fatCount - existingFatIds.length > fatCount * entriesPerFat)
18249
+ fatCount++;
18250
+ if (fatCount > 109)
18251
+ return void 0;
18252
+ const totalSectors = sectorCount + payloadSectors + fatCount - existingFatIds.length;
18253
+ const bytes = new Uint8Array((totalSectors + 1) * sectorSize);
18254
+ bytes.set(input);
18255
+ const view = new DataView(bytes.buffer), fatIds = [...existingFatIds];
18256
+ for (let i = existingFatIds.length; i < fatCount; i++) {
18257
+ const id = sectorCount + payloadSectors + i - existingFatIds.length;
18258
+ fatIds.push(id);
18259
+ bytes.fill(255, (id + 1) * sectorSize, (id + 2) * sectorSize);
18260
+ view.setUint32(76 + i * 4, id, true);
18261
+ }
18262
+ view.setUint32(44, fatCount, true);
18263
+ const writeFat = (id, value) => view.setUint32((fatIds[Math.floor(id / entriesPerFat)] + 1) * sectorSize + id % entriesPerFat * 4, value, true);
18264
+ const chains = [];
18265
+ let next = sectorCount;
18266
+ for (let payload = 0; payload < payloads.length; payload++) {
18267
+ bytes.set(payloads[payload], (next + 1) * sectorSize);
18268
+ const chain2 = Array.from({ length: counts[payload] }, (_, i) => next + i);
18269
+ chain2.forEach((id, i) => writeFat(id, chain2[i + 1] ?? 4294967294));
18270
+ chains.push(chain2);
18271
+ next += counts[payload];
18272
+ }
18273
+ for (const id of fatIds)
18274
+ writeFat(id, 4294967293);
18275
+ return { bytes, view, chains, writeFat };
18276
+ }
18277
+ function followCompoundAllocation(table, start) {
18278
+ const ids = [], seen = /* @__PURE__ */ new Set();
18279
+ for (let id = start; id !== 4294967294; id = table[id]) {
18280
+ if (id >= table.length || seen.has(id))
18281
+ throw new Error("Invalid allocation chain");
18282
+ seen.add(id);
18283
+ ids.push(id);
18284
+ }
18285
+ return ids;
18286
+ }
18287
+ var init_ole2_stream_resize_allocation = __esm({
18288
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-allocation.js"() {
18289
+ }
18290
+ });
18291
+
18292
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-mini.js
18293
+ function resizeMiniCompoundStream(input, fat, fatIds, root, target, replacement, cutoff) {
18294
+ const inputView = new DataView(input.buffer, input.byteOffset, input.byteLength);
18295
+ const miniFatCount = inputView.getUint32(64, true);
18296
+ const miniFatSectors = miniFatCount ? followCompoundAllocation(fat, inputView.getUint32(60, true)) : [];
18297
+ if (miniFatSectors.length !== miniFatCount)
18298
+ throw new Error("Invalid mini FAT count");
18299
+ const rootSectors = root.size ? followCompoundAllocation(fat, root.start) : [];
18300
+ if (rootSectors.length !== Math.ceil(root.size / SECTOR))
18301
+ throw new Error("Invalid root mini stream");
18302
+ const miniCapacity = Math.floor(root.size / MINI), miniFat = [];
18303
+ for (const id of miniFatSectors) {
18304
+ for (let slot = 0; slot < SECTOR / 4 && miniFat.length < miniCapacity; slot++)
18305
+ miniFat.push(inputView.getUint32((id + 1) * SECTOR + slot * 4, true));
18306
+ }
18307
+ const wasMini = target.size < cutoff;
18308
+ const oldChain = followCompoundAllocation(wasMini ? miniFat : fat, target.start);
18309
+ if (oldChain.length !== Math.ceil(target.size / (wasMini ? MINI : SECTOR)))
18310
+ throw new Error("Invalid stream allocation");
18311
+ if (!replacement.length) {
18312
+ const bytes = input.slice(), view = new DataView(bytes.buffer);
18313
+ for (const id of oldChain) {
18314
+ const table = wasMini ? miniFatSectors : fatIds;
18315
+ view.setUint32((table[Math.floor(id / 128)] + 1) * SECTOR + id % 128 * 4, FREE2, true);
18316
+ }
18317
+ view.setUint32(target.offset + 116, END3, true);
18318
+ view.setUint32(target.offset + 120, 0, true);
18319
+ return bytes;
18320
+ }
18321
+ if (replacement.length >= cutoff) {
18322
+ const output2 = appendCompoundAllocations(input, fatIds, [replacement]);
18323
+ if (!output2)
18324
+ return void 0;
18325
+ for (const id of oldChain)
18326
+ output2.view.setUint32((miniFatSectors[Math.floor(id / 128)] + 1) * SECTOR + id % 128 * 4, FREE2, true);
18327
+ output2.view.setUint32(target.offset + 116, output2.chains[0][0] ?? END3, true);
18328
+ output2.view.setUint32(target.offset + 120, replacement.length, true);
18329
+ return output2.bytes;
18330
+ }
18331
+ const firstMini = Math.ceil(root.size / MINI), count = Math.ceil(replacement.length / MINI);
18332
+ const newRootSize = count ? (firstMini + count) * MINI : root.size;
18333
+ const newRoot = new Uint8Array(newRootSize);
18334
+ rootSectors.forEach((id, i) => newRoot.set(input.subarray((id + 1) * SECTOR, (id + 1) * SECTOR + Math.min(SECTOR, root.size - i * SECTOR)), i * SECTOR));
18335
+ if (count)
18336
+ newRoot.set(replacement, firstMini * MINI);
18337
+ const newMiniFatCount = Math.max(miniFatCount, Math.ceil((firstMini + count) / 128));
18338
+ const newMiniFat = new Uint8Array(newMiniFatCount * SECTOR).fill(255);
18339
+ miniFatSectors.forEach((id, i) => newMiniFat.set(input.subarray((id + 1) * SECTOR, (id + 2) * SECTOR), i * SECTOR));
18340
+ const miniView = new DataView(newMiniFat.buffer);
18341
+ if (wasMini)
18342
+ for (const id of oldChain)
18343
+ miniView.setUint32(id * 4, FREE2, true);
18344
+ for (let i = 0; i < count; i++)
18345
+ miniView.setUint32((firstMini + i) * 4, i + 1 === count ? END3 : firstMini + i + 1, true);
18346
+ const output = appendCompoundAllocations(input, fatIds, [newRoot, newMiniFat]);
18347
+ if (!output)
18348
+ return void 0;
18349
+ for (const id of [...rootSectors, ...miniFatSectors, ...wasMini ? [] : oldChain])
18350
+ output.writeFat(id, FREE2);
18351
+ output.view.setUint32(root.offset + 116, output.chains[0][0] ?? END3, true);
18352
+ output.view.setUint32(root.offset + 120, newRootSize, true);
18353
+ output.view.setUint32(60, output.chains[1][0] ?? END3, true);
18354
+ output.view.setUint32(64, newMiniFatCount, true);
18355
+ output.view.setUint32(target.offset + 116, count ? firstMini : END3, true);
18356
+ output.view.setUint32(target.offset + 120, replacement.length, true);
18357
+ return output.bytes;
18358
+ }
18359
+ var END3, FREE2, SECTOR, MINI;
18360
+ var init_ole2_stream_resize_mini = __esm({
18361
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize-mini.js"() {
18362
+ init_ole2_stream_resize_allocation();
18363
+ END3 = 4294967294;
18364
+ FREE2 = 4294967295;
18365
+ SECTOR = 512;
18366
+ MINI = 64;
18367
+ }
18368
+ });
18369
+
18370
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize.js
18371
+ function follow2(table, start) {
18372
+ const ids = [], seen = /* @__PURE__ */ new Set();
18373
+ for (let id = start; id !== END4; id = table[id]) {
18374
+ if (id >= table.length || seen.has(id))
18375
+ throw new Error("Invalid allocation chain");
18376
+ seen.add(id);
18377
+ ids.push(id);
18378
+ }
18379
+ return ids;
18380
+ }
18381
+ function findSlot2(slots, path) {
18382
+ let parent = slots.get(0);
18383
+ if (!parent || parent.type !== 5)
18384
+ throw new Error("Invalid root");
18385
+ const parents = /* @__PURE__ */ new Set();
18386
+ for (let part = 0; part < path.length; part++) {
18387
+ if (parents.has(parent.id))
18388
+ throw new Error("Cyclic storage hierarchy");
18389
+ parents.add(parent.id);
18390
+ const stack = [parent.child], seen = /* @__PURE__ */ new Set(), matches = [];
18391
+ while (stack.length) {
18392
+ const id = stack.pop();
18393
+ if (id === FREE3)
18394
+ continue;
18395
+ if (seen.has(id))
18396
+ throw new Error("Invalid directory tree");
18397
+ seen.add(id);
18398
+ const slot = slots.get(id);
18399
+ if (!slot)
18400
+ throw new Error("Missing directory slot");
18401
+ if (slot.name.toLocaleLowerCase() === path[part].toLocaleLowerCase())
18402
+ matches.push(slot);
18403
+ stack.push(slot.left, slot.right);
18404
+ }
18405
+ if (matches.length !== 1)
18406
+ throw new Error("Missing or ambiguous stream");
18407
+ parent = matches[0];
18408
+ if (parent.type !== (part === path.length - 1 ? 2 : 1))
18409
+ throw new Error("Invalid storage path");
18410
+ }
18411
+ return parent;
18412
+ }
18413
+ function validateHierarchy2(slots) {
18414
+ const owners = /* @__PURE__ */ new Set(), storages = [0];
18415
+ while (storages.length) {
18416
+ const storage = slots.get(storages.pop());
18417
+ const stack = [storage.child], names = /* @__PURE__ */ new Set();
18418
+ while (stack.length) {
18419
+ const id = stack.pop();
18420
+ if (id === FREE3)
18421
+ continue;
18422
+ const slot = slots.get(id);
18423
+ if (!slot || slot.type !== 1 && slot.type !== 2 || owners.has(id))
18424
+ throw new Error("Ambiguous directory ownership");
18425
+ const name = slot.name.toLocaleLowerCase();
18426
+ if (names.has(name))
18427
+ throw new Error("Duplicate sibling name");
18428
+ names.add(name);
18429
+ owners.add(id);
18430
+ stack.push(slot.left, slot.right);
18431
+ if (slot.type === 1)
18432
+ storages.push(id);
18433
+ }
18434
+ }
18435
+ if (owners.size !== slots.size - 1)
18436
+ throw new Error("Unreachable directory entries");
18437
+ }
18438
+ function resizeCompoundFileStream(input, path, replacement) {
18439
+ if (input.length >= 512 && new DataView(input.buffer, input.byteOffset, input.byteLength).getUint16(26, true) === 4)
18440
+ return resizeCompoundFileStreamV4(input, path, replacement);
18441
+ const fail2 = (reason) => ({ ok: false, bytes: input, reason });
18442
+ try {
18443
+ if (input.length < SECTOR2 || !path.length || path.some((part) => !part))
18444
+ return fail2("invalid-or-missing-stream");
18445
+ const view = new DataView(input.buffer, input.byteOffset, input.byteLength);
18446
+ const read = (offset) => view.getUint32(offset, true);
18447
+ if (view.getUint16(26, true) !== 3)
18448
+ return fail2("unsupported-version");
18449
+ if (read(72) !== 0 || read(44) > 109)
18450
+ return fail2("unsupported-difat");
18451
+ const cutoff = read(56);
18452
+ if (cutoff !== 0 && cutoff !== 4096)
18453
+ return fail2("unsupported-layout");
18454
+ const original = readCompoundFileStream(input, path);
18455
+ if (!original)
18456
+ return fail2("invalid-or-missing-stream");
18457
+ const name = path[path.length - 1].toLocaleLowerCase();
18458
+ if (name === "worddocument" && original.length >= 12 && (original[10] | original[11] << 8) & 33024)
18459
+ return fail2("unsafe-edit");
18460
+ if (name === "book" || name === "workbook") {
18461
+ for (let offset = 0; offset + 4 <= original.length; ) {
18462
+ const record2 = original[offset] | original[offset + 1] << 8;
18463
+ const length = original[offset + 2] | original[offset + 3] << 8;
18464
+ if (record2 === 47)
18465
+ return fail2("unsafe-edit");
18466
+ if (record2 === 10 || offset + 4 + length > original.length)
18467
+ break;
18468
+ offset += 4 + length;
18469
+ }
18470
+ }
18471
+ const validated = replaceCompoundFileStream(input, path, original);
18472
+ if (validated === input)
18473
+ return fail2("unsafe-edit");
18474
+ const sameLength = replacement.length === original.length;
18475
+ const sectorCount = input.length / SECTOR2 - 1, fatCount = read(44);
18476
+ if (sectorCount > fatCount * FAT_ENTRIES)
18477
+ return fail2("unsafe-edit");
18478
+ const fatIds = Array.from({ length: fatCount }, (_, i) => read(76 + 4 * i));
18479
+ const fat = [];
18480
+ for (const id of fatIds) {
18481
+ for (let i = 0; i < FAT_ENTRIES && fat.length < sectorCount; i++)
18482
+ fat.push(read((id + 1) * SECTOR2 + i * 4));
18483
+ }
18484
+ if (fatIds.some((id) => fat[id] !== FAT2))
18485
+ return fail2("unsafe-edit");
18486
+ const slots = /* @__PURE__ */ new Map();
18487
+ for (const [block, sector] of follow2(fat, read(48)).entries()) {
18488
+ for (let entry = 0; entry < 4; entry++) {
18489
+ const offset = (sector + 1) * SECTOR2 + entry * 128, type = view.getUint8(offset + 66);
18490
+ if (!type)
18491
+ continue;
18492
+ const nameLength = view.getUint16(offset + 64, true);
18493
+ if (![1, 2, 5].includes(type) || nameLength < 2 || nameLength > 64 || nameLength % 2 || view.getUint16(offset + nameLength - 2, true))
18494
+ return fail2("unsafe-edit");
18495
+ let name2 = "";
18496
+ for (let i = 0; i < nameLength - 2; i += 2)
18497
+ name2 += String.fromCharCode(view.getUint16(offset + i, true));
18498
+ const id = block * 4 + entry;
18499
+ 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 });
18500
+ }
18501
+ }
18502
+ if ([...slots.values()].filter((slot) => slot.type === 5).length !== 1)
18503
+ return fail2("unsafe-edit");
18504
+ const target = findSlot2(slots, path);
18505
+ validateHierarchy2(slots);
18506
+ if (sameLength) {
18507
+ const bytes = replaceCompoundFileStream(input, path, replacement);
18508
+ return bytes === input ? fail2("unsafe-edit") : { ok: true, bytes };
18509
+ }
18510
+ if (original.length < cutoff || replacement.length < cutoff) {
18511
+ const bytes = resizeMiniCompoundStream(input, fat, fatIds, slots.get(0), target, replacement, cutoff);
18512
+ return bytes ? { ok: true, bytes } : fail2("allocation-limit");
18513
+ }
18514
+ const oldChain = follow2(fat, target.start);
18515
+ if (target.size !== original.length || oldChain.length !== Math.ceil(target.size / SECTOR2))
18516
+ return fail2("unsafe-edit");
18517
+ const output = appendCompoundAllocations(input, fatIds, [replacement]);
18518
+ if (!output)
18519
+ return fail2("allocation-limit");
18520
+ for (const id of oldChain)
18521
+ output.writeFat(id, FREE3);
18522
+ output.view.setUint32(target.offset + 116, output.chains[0][0] ?? END4, true);
18523
+ output.view.setUint32(target.offset + 120, replacement.length, true);
18524
+ return { ok: true, bytes: output.bytes };
18525
+ } catch {
18526
+ return fail2("unsafe-edit");
18527
+ }
18528
+ }
18529
+ var END4, FREE3, FAT2, SECTOR2, FAT_ENTRIES;
18530
+ var init_ole2_stream_resize = __esm({
18531
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole2-stream-resize.js"() {
18532
+ init_ole2_stream_edit();
18533
+ init_ole2_stream_resize_v4();
18534
+ init_ole2_stream_resize_allocation();
18535
+ init_ole2_stream_resize_mini();
18536
+ END4 = 4294967294;
18537
+ FREE3 = 4294967295;
18538
+ FAT2 = 4294967293;
18539
+ SECTOR2 = 512;
18540
+ FAT_ENTRIES = SECTOR2 / 4;
18541
+ }
18542
+ });
18543
+
18544
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cfb.js
17742
18545
  function unwrapDocBytes(bytes) {
17743
18546
  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) {
17744
18547
  return void 0;
17745
18548
  }
17746
18549
  try {
17747
- const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
17748
- const ole = parseOle2(buffer);
17749
- const wordDocBytes = ole.getStream("WordDocument");
18550
+ const wordDocBytes = readCompoundFileStream(bytes, ["WordDocument"]);
17750
18551
  if (!wordDocBytes) {
17751
18552
  return void 0;
17752
18553
  }
17753
18554
  const fib = readDocFib(wordDocBytes);
17754
- const tableBytes = ole.getStream(fib.tableStreamName);
18555
+ const tableBytes = readCompoundFileStream(bytes, [fib.tableStreamName]);
17755
18556
  if (!tableBytes) {
17756
18557
  return void 0;
17757
18558
  }
17758
- const rootClsid = ole.entries.find((e) => e.type === ENTRY_TYPE_ROOT)?.clsid;
18559
+ const header = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
18560
+ const cutoff = header.getUint32(56, true);
18561
+ 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;
17759
18562
  return {
17760
18563
  wordDocBytes,
17761
18564
  tableStreamName: fib.tableStreamName,
17762
18565
  tableBytes,
18566
+ canRewrite,
17763
18567
  rewrap: (editedWordDocBytes, editedTableBytes) => {
17764
- const streams2 = /* @__PURE__ */ new Map();
17765
- for (const entry of ole.entries) {
17766
- if (entry.type !== ENTRY_TYPE_STREAM) {
17767
- continue;
17768
- }
17769
- const data = entry.name === "WordDocument" ? editedWordDocBytes : entry.name === fib.tableStreamName ? editedTableBytes : ole.getStream(entry.name);
17770
- if (data) {
17771
- streams2.set(entry.name, data);
17772
- }
17773
- }
17774
- return new Uint8Array(buildOle2(streams2, rootClsid));
18568
+ if (editedWordDocBytes.length === wordDocBytes.length && editedTableBytes.length === tableBytes.length) {
18569
+ const patchedWord = replaceCompoundFileStream(bytes, ["WordDocument"], editedWordDocBytes);
18570
+ if (patchedWord === bytes)
18571
+ throw new DocCfbRewriteError("Cannot safely patch WordDocument");
18572
+ if (editedTableBytes.every((value, i) => value === tableBytes[i]))
18573
+ return patchedWord;
18574
+ const patchedTable = replaceCompoundFileStream(patchedWord, [fib.tableStreamName], editedTableBytes);
18575
+ if (patchedTable === patchedWord)
18576
+ throw new DocCfbRewriteError("Cannot safely patch DOC table stream");
18577
+ return patchedTable;
18578
+ }
18579
+ const word = resizeCompoundFileStream(bytes, ["WordDocument"], editedWordDocBytes);
18580
+ if (!word.ok)
18581
+ throw new DocCfbRewriteError(`Cannot resize WordDocument: ${word.reason}`);
18582
+ const table = resizeCompoundFileStream(word.bytes, [fib.tableStreamName], editedTableBytes);
18583
+ if (!table.ok)
18584
+ throw new DocCfbRewriteError(`Cannot resize DOC table stream: ${table.reason}`);
18585
+ return table.bytes;
17775
18586
  }
17776
18587
  };
17777
18588
  } catch {
17778
18589
  return void 0;
17779
18590
  }
17780
18591
  }
18592
+ var DocCfbRewriteError;
17781
18593
  var init_ole_document_doc_cfb = __esm({
17782
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cfb.js"() {
18594
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cfb.js"() {
17783
18595
  init_ole_document_doc_fib();
17784
- init_ole2_parser_read();
17785
- init_ole2_parser_types();
17786
- init_ole2_parser_write();
18596
+ init_ole2_stream_edit();
18597
+ init_ole2_stream_resize();
18598
+ DocCfbRewriteError = class extends Error {
18599
+ constructor(message) {
18600
+ super(message);
18601
+ this.name = "DocCfbRewriteError";
18602
+ }
18603
+ };
17787
18604
  }
17788
18605
  });
17789
18606
 
17790
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fkp.js
18607
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fkp.js
17791
18608
  function parseBteTable(tableStream, at2) {
17792
18609
  const view = new DataView(tableStream.buffer, tableStream.byteOffset, tableStream.byteLength);
17793
- const n = Math.floor((at2.lcb - 4) / (4 + 4));
18610
+ 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)
18611
+ throw new Error("Invalid BTE table bounds");
18612
+ const n = (at2.lcb - 4) / 8;
17794
18613
  const fcs = [];
17795
18614
  for (let i = 0; i <= n; i++) {
17796
- fcs.push(view.getInt32(at2.fc + i * 4, true));
18615
+ const fc = view.getInt32(at2.fc + i * 4, true);
18616
+ if (fc < 0 || i > 0 && fc <= fcs[i - 1])
18617
+ throw new Error("Invalid BTE FC boundaries");
18618
+ fcs.push(fc);
17797
18619
  }
17798
18620
  const pns = [];
17799
18621
  for (let i = 0; i < n; i++) {
@@ -17814,10 +18636,17 @@ function buildBteTableBytes(table) {
17814
18636
  return bytes;
17815
18637
  }
17816
18638
  function findBteRangeIndex(table, fc) {
17817
- for (let i = 0; i < table.pns.length; i++) {
17818
- if (fc >= table.fcs[i] && fc < table.fcs[i + 1]) {
17819
- return i;
17820
- }
18639
+ let low = 0, high = table.pns.length;
18640
+ while (low < high) {
18641
+ const middle = low + Math.floor((high - low) / 2);
18642
+ if (fc < table.fcs[middle])
18643
+ high = middle;
18644
+ else if (fc >= table.fcs[middle + 1])
18645
+ low = middle + 1;
18646
+ else if (fc >= table.fcs[middle])
18647
+ return middle;
18648
+ else
18649
+ break;
17821
18650
  }
17822
18651
  throw new Error(`FC ${fc} is not covered by any BTE range`);
17823
18652
  }
@@ -17833,7 +18662,11 @@ function extractPapxBlob(wordDoc, papxBte, fc) {
17833
18662
  const rangeIndex = findBteRangeIndex(papxBte, fc);
17834
18663
  const pageOffset = papxBte.pns[rangeIndex] * PAGE_SIZE;
17835
18664
  const page = wordDoc.subarray(pageOffset, pageOffset + PAGE_SIZE);
18665
+ if (page.length !== PAGE_SIZE)
18666
+ throw new Error("Truncated PAPX page");
17836
18667
  const crun = page[PAGE_SIZE - 1];
18668
+ if (crun === 0 || (crun + 1) * 4 + crun * 13 > 511)
18669
+ throw new Error("Invalid PAPX run count");
17837
18670
  const pageView = new DataView(page.buffer, page.byteOffset, page.byteLength);
17838
18671
  const rgbxOffset = (crun + 1) * 4;
17839
18672
  for (let i = 0; i < crun; i++) {
@@ -17841,8 +18674,13 @@ function extractPapxBlob(wordDoc, papxBte, fc) {
17841
18674
  const runFcEnd = pageView.getInt32((i + 1) * 4, true);
17842
18675
  if (fc >= runFcStart && fc < runFcEnd) {
17843
18676
  const bOffsetWord = page[rgbxOffset + i * 13];
18677
+ if (bOffsetWord === 0)
18678
+ return new Uint8Array();
17844
18679
  const blobOffset = bOffsetWord * 2;
17845
- return page.slice(blobOffset, blobOffset + papxBlobLength(page, blobOffset));
18680
+ const blobLength = papxBlobLength(page, blobOffset);
18681
+ if (blobOffset < rgbxOffset + crun * 13 || !Number.isInteger(blobLength) || blobOffset + blobLength > 511)
18682
+ throw new Error("Invalid PAPX blob bounds");
18683
+ return page.slice(blobOffset, blobOffset + blobLength);
17846
18684
  }
17847
18685
  }
17848
18686
  throw new Error(`FC ${fc} is not covered by any run in PAPX page ${papxBte.pns[rangeIndex]}`);
@@ -17851,7 +18689,11 @@ function extractChpxBlob(wordDoc, chpxBte, fc) {
17851
18689
  const rangeIndex = findBteRangeIndex(chpxBte, fc);
17852
18690
  const pageOffset = chpxBte.pns[rangeIndex] * PAGE_SIZE;
17853
18691
  const page = wordDoc.subarray(pageOffset, pageOffset + PAGE_SIZE);
18692
+ if (page.length !== PAGE_SIZE)
18693
+ throw new Error("Truncated CHPX page");
17854
18694
  const crun = page[PAGE_SIZE - 1];
18695
+ if (crun === 0 || (crun + 1) * 4 + crun > 511)
18696
+ throw new Error("Invalid CHPX run count");
17855
18697
  const pageView = new DataView(page.buffer, page.byteOffset, page.byteLength);
17856
18698
  const rgbOffset = (crun + 1) * 4;
17857
18699
  for (let i = 0; i < crun; i++) {
@@ -17864,6 +18706,8 @@ function extractChpxBlob(wordDoc, chpxBte, fc) {
17864
18706
  }
17865
18707
  const blobOffset = bOffsetWord * 2;
17866
18708
  const cb = page[blobOffset];
18709
+ if (blobOffset < rgbOffset + crun || blobOffset + 1 + cb > 511)
18710
+ throw new Error("Invalid CHPX blob bounds");
17867
18711
  return page.slice(blobOffset, blobOffset + 1 + cb);
17868
18712
  }
17869
18713
  }
@@ -17875,8 +18719,12 @@ function buildSingleRunPapxPage(fcStart, fcEnd, blob) {
17875
18719
  view.setInt32(0, fcStart, true);
17876
18720
  view.setInt32(4, fcEnd, true);
17877
18721
  const blobByteOffset = 22;
17878
- page[8] = blobByteOffset / 2;
17879
- page.set(blob, blobByteOffset);
18722
+ if (blob.length > 511 - blobByteOffset)
18723
+ throw new Error("PAPX blob exceeds page capacity");
18724
+ if (blob.length > 0) {
18725
+ page[8] = blobByteOffset / 2;
18726
+ page.set(blob, blobByteOffset);
18727
+ }
17880
18728
  page[PAGE_SIZE - 1] = 1;
17881
18729
  return page;
17882
18730
  }
@@ -17887,6 +18735,8 @@ function buildSingleRunChpxPage(fcStart, fcEnd, blob) {
17887
18735
  view.setInt32(4, fcEnd, true);
17888
18736
  if (blob.length > 0) {
17889
18737
  const blobByteOffset = 10;
18738
+ if (blob.length > 511 - blobByteOffset)
18739
+ throw new Error("CHPX blob exceeds page capacity");
17890
18740
  page[8] = blobByteOffset / 2;
17891
18741
  page.set(blob, blobByteOffset);
17892
18742
  }
@@ -17895,12 +18745,12 @@ function buildSingleRunChpxPage(fcStart, fcEnd, blob) {
17895
18745
  }
17896
18746
  var PAGE_SIZE;
17897
18747
  var init_ole_document_doc_fkp = __esm({
17898
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fkp.js"() {
18748
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fkp.js"() {
17899
18749
  PAGE_SIZE = 512;
17900
18750
  }
17901
18751
  });
17902
18752
 
17903
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cp1252.js
18753
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cp1252.js
17904
18754
  function decodeCp1252Byte(byte) {
17905
18755
  if (byte >= 128 && byte <= 159) {
17906
18756
  return CP1252_HIGH_BLOCK[byte - 128];
@@ -17934,7 +18784,7 @@ function encodeCp1252(text2) {
17934
18784
  }
17935
18785
  var CP1252_HIGH_BLOCK, CP1252_HIGH_BLOCK_REVERSE;
17936
18786
  var init_ole_document_doc_cp1252 = __esm({
17937
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cp1252.js"() {
18787
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-cp1252.js"() {
17938
18788
  CP1252_HIGH_BLOCK = [
17939
18789
  8364,
17940
18790
  129,
@@ -17973,21 +18823,42 @@ var init_ole_document_doc_cp1252 = __esm({
17973
18823
  }
17974
18824
  });
17975
18825
 
17976
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-pieces.js
17977
- function parsePieceTable(tableStream, clx) {
18826
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-pieces.js
18827
+ function parseDocClx(tableStream, clx, maxPieces) {
18828
+ if (maxPieces !== void 0 && (!Number.isSafeInteger(maxPieces) || maxPieces < 0))
18829
+ throw new Error("Invalid DOC piece limit");
17978
18830
  const view = new DataView(tableStream.buffer, tableStream.byteOffset, tableStream.byteLength);
18831
+ if (!Number.isInteger(clx.fc) || !Number.isInteger(clx.lcb) || clx.fc < 0 || clx.lcb < 5 || clx.fc > tableStream.length - clx.lcb)
18832
+ throw new Error("Clx is outside the table stream");
17979
18833
  let off = clx.fc;
17980
18834
  const end = clx.fc + clx.lcb;
18835
+ let prcCount = 0;
17981
18836
  while (off < end) {
17982
18837
  const clxt = view.getUint8(off);
17983
18838
  if (clxt === CLXT_PRC) {
18839
+ if (off + 3 > end)
18840
+ throw new Error("Truncated Prc header");
17984
18841
  const cb = view.getUint16(off + 1, true);
18842
+ if (cb > end - off - 3)
18843
+ throw new Error("Prc extends beyond Clx");
17985
18844
  off += 1 + 2 + cb;
18845
+ prcCount++;
17986
18846
  continue;
17987
18847
  }
17988
18848
  if (clxt === CLXT_PCDT) {
18849
+ if (off + 5 > end)
18850
+ throw new Error("Truncated Pcdt header");
17989
18851
  const lcb = view.getInt32(off + 1, true);
17990
- return parsePlcPcd(view, off + 1 + 4, lcb);
18852
+ if (lcb < 4 || (lcb - 4) % 12 !== 0 || lcb !== end - off - 5)
18853
+ throw new Error("Invalid PlcPcd length");
18854
+ if (maxPieces !== void 0 && (lcb - 4) / 12 > maxPieces)
18855
+ throw new DocResourceLimitError("DOC piece count exceeds the processing limit");
18856
+ const pieces = parsePlcPcd(view, off + 5, lcb);
18857
+ for (const piece of pieces) {
18858
+ if ((piece.prm & 1) !== 0 && piece.prm >>> 1 >= prcCount)
18859
+ throw new Error("Prm1 references a missing Prc");
18860
+ }
18861
+ return { pieces, prcBytes: tableStream.slice(clx.fc, off) };
17991
18862
  }
17992
18863
  throw new Error(`Unrecognised Clx entry type ${clxt} at ${off}`);
17993
18864
  }
@@ -17997,7 +18868,10 @@ function parsePlcPcd(view, plcStart, lcb) {
17997
18868
  const n = Math.floor((lcb - 4) / (4 + 8));
17998
18869
  const cps = [];
17999
18870
  for (let i = 0; i <= n; i++) {
18000
- cps.push(view.getInt32(plcStart + i * 4, true));
18871
+ const cp = view.getInt32(plcStart + i * 4, true);
18872
+ if (i === 0 && cp !== 0 || i > 0 && cp <= cps[i - 1])
18873
+ throw new Error("Piece CPs must start at zero and increase");
18874
+ cps.push(cp);
18001
18875
  }
18002
18876
  const pcdStart = plcStart + (n + 1) * 4;
18003
18877
  const pieces = [];
@@ -18005,6 +18879,8 @@ function parsePlcPcd(view, plcStart, lcb) {
18005
18879
  const pOff = pcdStart + i * 8;
18006
18880
  const flagsWord = view.getUint16(pOff, true);
18007
18881
  const fcRaw = view.getUint32(pOff + 2, true);
18882
+ if ((fcRaw & 2147483648) !== 0)
18883
+ throw new Error("Reserved FcCompressed bit is set");
18008
18884
  const prm = view.getUint16(pOff + 6, true);
18009
18885
  const compressed = (fcRaw >>> 30 & 1) === 1;
18010
18886
  const fcField = fcRaw & 1073741823;
@@ -18021,6 +18897,9 @@ function parsePlcPcd(view, plcStart, lcb) {
18021
18897
  }
18022
18898
  function decodePieceText(wordDoc, piece) {
18023
18899
  const charLen = piece.cpEnd - piece.cpStart;
18900
+ const byteLen = charLen * (piece.compressed ? 1 : 2);
18901
+ if (!Number.isInteger(charLen) || charLen < 0 || !Number.isInteger(piece.fc) || piece.fc < 0 || piece.fc > wordDoc.length - byteLen)
18902
+ throw new Error("Piece text is outside WordDocument");
18024
18903
  if (piece.compressed) {
18025
18904
  return decodeCp1252(wordDoc.subarray(piece.fc, piece.fc + charLen));
18026
18905
  }
@@ -18031,8 +18910,19 @@ function decodePieceText(wordDoc, piece) {
18031
18910
  }
18032
18911
  return out;
18033
18912
  }
18034
- function decodePiecesText(wordDoc, pieces) {
18035
- return pieces.map((piece) => decodePieceText(wordDoc, piece)).join("");
18913
+ function decodePiecesText(wordDoc, pieces, maxChars) {
18914
+ if (maxChars !== void 0 && (!Number.isInteger(maxChars) || maxChars < 0))
18915
+ throw new Error("Invalid text character limit");
18916
+ const out = [];
18917
+ for (const piece of pieces) {
18918
+ const bytes = (piece.cpEnd - piece.cpStart) * (piece.compressed ? 1 : 2);
18919
+ if (piece.cpEnd < piece.cpStart || piece.fc < 0 || piece.fc > wordDoc.length - bytes)
18920
+ throw new Error("Piece text is outside WordDocument");
18921
+ const end = Math.min(piece.cpEnd, maxChars ?? piece.cpEnd);
18922
+ if (end > piece.cpStart)
18923
+ out.push(decodePieceText(wordDoc, { ...piece, cpEnd: end }));
18924
+ }
18925
+ return out.join("");
18036
18926
  }
18037
18927
  function encodePieceText(text2) {
18038
18928
  const compressedBytes = encodeCp1252(text2);
@@ -18070,7 +18960,7 @@ function replacePieceRange(pieces, cpStart, cpEnd, newPiece) {
18070
18960
  fc: newPiece.fc,
18071
18961
  compressed: newPiece.compressed,
18072
18962
  flagsWord: newPiece.flagsWord,
18073
- prm: 0,
18963
+ prm: newPiece.prm ?? 0,
18074
18964
  charLength: newPiece.charLength
18075
18965
  });
18076
18966
  inserted = true;
@@ -18091,7 +18981,7 @@ function replacePieceRange(pieces, cpStart, cpEnd, newPiece) {
18091
18981
  fc: newPiece.fc,
18092
18982
  compressed: newPiece.compressed,
18093
18983
  flagsWord: newPiece.flagsWord,
18094
- prm: 0,
18984
+ prm: newPiece.prm ?? 0,
18095
18985
  charLength: newPiece.charLength
18096
18986
  });
18097
18987
  }
@@ -18109,7 +18999,7 @@ function replacePieceRange(pieces, cpStart, cpEnd, newPiece) {
18109
18999
  };
18110
19000
  });
18111
19001
  }
18112
- function buildClxBytes(pieces) {
19002
+ function buildClxBytes(pieces, prcBytes = new Uint8Array()) {
18113
19003
  const n = pieces.length;
18114
19004
  const plcLcb = (n + 1) * 4 + n * 8;
18115
19005
  const bytes = new Uint8Array(1 + 4 + plcLcb);
@@ -18130,20 +19020,138 @@ function buildClxBytes(pieces) {
18130
19020
  view.setUint16(off + 6, piece.prm, true);
18131
19021
  off += 8;
18132
19022
  }
18133
- return bytes;
19023
+ const result = new Uint8Array(prcBytes.length + bytes.length);
19024
+ result.set(prcBytes);
19025
+ result.set(bytes, prcBytes.length);
19026
+ parseDocClx(result, { fc: 0, lcb: result.length });
19027
+ return result;
18134
19028
  }
18135
- var CLXT_PRC, CLXT_PCDT;
19029
+ var CLXT_PRC, CLXT_PCDT, DocResourceLimitError;
18136
19030
  var init_ole_document_doc_pieces = __esm({
18137
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-pieces.js"() {
19031
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-pieces.js"() {
18138
19032
  init_ole_document_doc_cp1252();
18139
19033
  CLXT_PRC = 1;
18140
19034
  CLXT_PCDT = 2;
19035
+ DocResourceLimitError = class extends Error {
19036
+ constructor(message) {
19037
+ super(message);
19038
+ this.name = "DocResourceLimitError";
19039
+ }
19040
+ };
19041
+ }
19042
+ });
19043
+
19044
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fields.js
19045
+ function checkFieldRanges(markers, editStart, editEnd, maxDepth2) {
19046
+ const stack = [];
19047
+ for (const { cp, ch } of markers) {
19048
+ if (ch === 19) {
19049
+ if (stack.length >= maxDepth2)
19050
+ throw new DocResourceLimitError("DOC field nesting exceeds the processing limit");
19051
+ stack.push({ start: cp, separated: false });
19052
+ } else if (ch === 20) {
19053
+ const field = stack.at(-1);
19054
+ if (!field || field.separated)
19055
+ throw new Error("Invalid DOC field separator nesting");
19056
+ field.separated = true;
19057
+ } else if (ch === 21) {
19058
+ const field = stack.pop();
19059
+ if (!field)
19060
+ throw new Error("Unmatched DOC field end");
19061
+ if (field.start < editEnd && cp + 1 > editStart)
19062
+ throw new UnsupportedDocFieldEditError("Paragraph overlaps a field code/result range");
19063
+ }
19064
+ }
19065
+ if (stack.length)
19066
+ throw new Error("Unterminated DOC field");
19067
+ }
19068
+ function* bodyMarkers(body) {
19069
+ for (let cp = 0; cp < body.length; cp++) {
19070
+ const ch = body.charCodeAt(cp);
19071
+ if (ch >= 19 && ch <= 21)
19072
+ yield { cp, ch };
19073
+ }
19074
+ }
19075
+ function shiftDocMainFieldCps(table, at2, body, editStart, editEnd, delta2, maxFields) {
19076
+ if (![editStart, editEnd, delta2, maxFields].every(Number.isSafeInteger) || editStart < 0 || editEnd <= editStart || editEnd > body.length || maxFields < 0 || body.length + delta2 < 0)
19077
+ throw new Error("Invalid field edit bounds or budget");
19078
+ checkFieldRanges(bodyMarkers(body), editStart, editEnd, maxFields);
19079
+ if (at2.lcb === 0)
19080
+ return void 0;
19081
+ if (!Number.isSafeInteger(at2.fc) || at2.fc < 0 || at2.lcb < 4 || (at2.lcb - 4) % 6 !== 0 || at2.fc > table.length - at2.lcb)
19082
+ throw new Error("Invalid main-story field PLC bounds");
19083
+ const n = (at2.lcb - 4) / 6;
19084
+ if (n > maxFields)
19085
+ throw new DocResourceLimitError("DOC field count exceeds the processing limit");
19086
+ const source = table.subarray(at2.fc, at2.fc + at2.lcb);
19087
+ const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
19088
+ const markers = [];
19089
+ let previous = -1;
19090
+ for (let i = 0; i < n; i++) {
19091
+ const cp = view.getInt32(i * 4, true);
19092
+ const ch = source[(n + 1) * 4 + i * 2] & 31;
19093
+ if (cp <= previous || cp >= body.length || ![19, 20, 21].includes(ch) || body.charCodeAt(cp) !== ch)
19094
+ throw new Error("Invalid main-story field marker");
19095
+ markers.push({ cp, ch });
19096
+ previous = cp;
19097
+ }
19098
+ checkFieldRanges(markers, editStart, editEnd, maxFields);
19099
+ const sentinel = view.getInt32(n * 4, true);
19100
+ if (sentinel < 0 || sentinel <= previous)
19101
+ throw new Error("Invalid field PLC sentinel");
19102
+ const result = source.slice();
19103
+ const out = new DataView(result.buffer);
19104
+ let shiftedLast = -1;
19105
+ for (let i = 0; i < n; i++) {
19106
+ const cp = markers[i].cp;
19107
+ const shifted = cp >= editEnd ? cp + delta2 : cp;
19108
+ if (shifted < 0 || shifted >= body.length + delta2 || shifted <= shiftedLast)
19109
+ throw new Error("Field position shifts outside the main story");
19110
+ out.setInt32(i * 4, shifted, true);
19111
+ shiftedLast = shifted;
19112
+ }
19113
+ let shiftedSentinel = sentinel >= editEnd ? sentinel + delta2 : sentinel;
19114
+ if (shiftedSentinel > 2147483647 || shiftedSentinel <= shiftedLast)
19115
+ shiftedSentinel = sentinel;
19116
+ if (shiftedSentinel <= shiftedLast)
19117
+ throw new Error("No representable field PLC sentinel");
19118
+ out.setInt32(n * 4, shiftedSentinel, true);
19119
+ return result;
19120
+ }
19121
+ var UnsupportedDocFieldEditError;
19122
+ var init_ole_document_doc_fields = __esm({
19123
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-fields.js"() {
19124
+ init_ole_document_doc_pieces();
19125
+ UnsupportedDocFieldEditError = class extends Error {
19126
+ constructor(message) {
19127
+ super(message);
19128
+ this.name = "UnsupportedDocFieldEditError";
19129
+ }
19130
+ };
18141
19131
  }
18142
19132
  });
18143
19133
 
18144
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-editor.js
19134
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-editor.js
19135
+ function processingLimits(limits) {
19136
+ const resolved = {
19137
+ maxCharacters: DEFAULT_OLE_DOC_PROCESSING_LIMITS.maxCharacters,
19138
+ maxPieces: DEFAULT_OLE_DOC_PROCESSING_LIMITS.maxPieces,
19139
+ maxFieldRecords: DEFAULT_OLE_DOC_PROCESSING_LIMITS.maxFieldRecords
19140
+ };
19141
+ if (!Number.isSafeInteger(resolved.maxCharacters) || resolved.maxCharacters < 0 || !Number.isSafeInteger(resolved.maxPieces) || resolved.maxPieces < 0 || !Number.isSafeInteger(resolved.maxFieldRecords) || resolved.maxFieldRecords < 0)
19142
+ throw new Error("DOC processing limits must be nonnegative safe integers");
19143
+ return resolved;
19144
+ }
18145
19145
  function hasUnsupportedFeatures(wordDoc, fib) {
19146
+ if (fib.ccpOtherStories > 0)
19147
+ return true;
19148
+ for (let index = 93; index < fib.fibRgFcLcbCount; index++) {
19149
+ if (!SAFE_EXTENDED_FC_LCB_INDICES.has(index) && readFcLcbAt(wordDoc, fib, index).lcb !== 0)
19150
+ return true;
19151
+ }
18146
19152
  for (const index of RISKY_PLCF_INDICES) {
19153
+ if (index >= fib.fibRgFcLcbCount)
19154
+ continue;
18147
19155
  if (readFcLcbAt(wordDoc, fib, index).lcb > 4) {
18148
19156
  return true;
18149
19157
  }
@@ -18176,15 +19184,30 @@ function paragraphBoundaries(bodyText) {
18176
19184
  }
18177
19185
  return boundaries;
18178
19186
  }
18179
- function readOleDocParagraphs(docBytes) {
19187
+ function encodePieceTextUtf16(text2) {
19188
+ const bytes = new Uint8Array(text2.length * 2);
19189
+ const view = new DataView(bytes.buffer);
19190
+ for (let i = 0; i < text2.length; i++)
19191
+ view.setUint16(i * 2, text2.charCodeAt(i), true);
19192
+ return bytes;
19193
+ }
19194
+ function readOleDocParagraphs(docBytes, limits) {
18180
19195
  try {
19196
+ const budget = processingLimits(limits);
18181
19197
  const cfb = unwrapDocBytes(docBytes);
18182
19198
  if (!cfb) {
18183
19199
  return void 0;
18184
19200
  }
18185
19201
  const fib = readDocFib(cfb.wordDocBytes);
18186
- const pieces = parsePieceTable(cfb.tableBytes, fib.clx);
18187
- const fullText = decodePiecesText(cfb.wordDocBytes, pieces);
19202
+ if (fib.ccpText > budget.maxCharacters)
19203
+ return void 0;
19204
+ const pieces = parseDocClx(cfb.tableBytes, fib.clx, budget.maxPieces).pieces;
19205
+ const totalCp = pieces.at(-1)?.cpEnd ?? 0;
19206
+ if (totalCp > fib.ccpText + fib.ccpOtherStories + 1)
19207
+ return void 0;
19208
+ const fullText = decodePiecesText(cfb.wordDocBytes, pieces, fib.ccpText);
19209
+ if (fullText.length < fib.ccpText)
19210
+ return void 0;
18188
19211
  const bodyText = fullText.slice(0, fib.ccpText);
18189
19212
  const boundaries = paragraphBoundaries(bodyText);
18190
19213
  let start = 0;
@@ -18201,7 +19224,9 @@ function readOleDocParagraphs(docBytes) {
18201
19224
  }
18202
19225
  function shiftSectionTableCps(tableBytes, sed, editEndCp, delta2) {
18203
19226
  const view = new DataView(tableBytes.buffer, tableBytes.byteOffset, tableBytes.byteLength);
18204
- const n = Math.floor((sed.lcb - 4) / (4 + 12));
19227
+ if (sed.lcb < 4 || (sed.lcb - 4) % 16 !== 0 || sed.fc > tableBytes.length - sed.lcb)
19228
+ throw new Error("Invalid section table");
19229
+ const n = (sed.lcb - 4) / 16;
18205
19230
  for (let i = 0; i <= n; i++) {
18206
19231
  const off = sed.fc + i * 4;
18207
19232
  const cp = view.getInt32(off, true);
@@ -18210,31 +19235,101 @@ function shiftSectionTableCps(tableBytes, sed, editEndCp, delta2) {
18210
19235
  }
18211
19236
  }
18212
19237
  }
18213
- function writeOleDocParagraphEdit(docBytes, paragraphIndex, text2) {
19238
+ function writeOleDocParagraphEdit(docBytes, paragraphIndex, text2, limits) {
19239
+ return tryWriteOleDocParagraphEdit(docBytes, paragraphIndex, text2, limits).bytes;
19240
+ }
19241
+ function tryWriteOleDocParagraphEdit(docBytes, paragraphIndex, text2, limits) {
19242
+ const rejected = (reason) => ({ status: "rejected", bytes: docBytes, reason });
19243
+ let budget;
19244
+ try {
19245
+ budget = processingLimits(limits);
19246
+ } catch {
19247
+ return rejected("invalid-limits");
19248
+ }
19249
+ if (text2.length > budget.maxCharacters)
19250
+ return rejected("resource-limit");
19251
+ if (!Number.isInteger(paragraphIndex) || paragraphIndex < 0)
19252
+ return rejected("invalid-paragraph-index");
19253
+ if (/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/u.test(text2))
19254
+ return rejected("invalid-text");
18214
19255
  try {
18215
19256
  const cfb = unwrapDocBytes(docBytes);
18216
19257
  if (!cfb) {
18217
- return docBytes;
19258
+ return rejected("invalid-payload");
18218
19259
  }
18219
19260
  const fib = readDocFib(cfb.wordDocBytes);
18220
- if (hasUnsupportedFeatures(cfb.wordDocBytes, fib)) {
18221
- return docBytes;
18222
- }
18223
- const pieces = parsePieceTable(cfb.tableBytes, fib.clx);
18224
- const fullText = decodePiecesText(cfb.wordDocBytes, pieces);
19261
+ if (fib.ccpText > budget.maxCharacters)
19262
+ return rejected("resource-limit");
19263
+ const { pieces, prcBytes } = parseDocClx(cfb.tableBytes, fib.clx, budget.maxPieces);
19264
+ const totalCp = pieces.at(-1)?.cpEnd ?? 0;
19265
+ if (totalCp > fib.ccpText + fib.ccpOtherStories + 1)
19266
+ return rejected("invalid-document");
19267
+ const fullText = decodePiecesText(cfb.wordDocBytes, pieces, fib.ccpText);
19268
+ if (fullText.length < fib.ccpText)
19269
+ return rejected("invalid-document");
18225
19270
  const bodyText = fullText.slice(0, fib.ccpText);
18226
19271
  const boundaries = paragraphBoundaries(bodyText);
18227
19272
  const paragraphEndCp = boundaries[paragraphIndex];
18228
19273
  if (paragraphEndCp === void 0) {
18229
- return docBytes;
19274
+ return rejected("invalid-paragraph-index");
18230
19275
  }
18231
19276
  const paragraphStartCp = paragraphIndex === 0 ? 0 : boundaries[paragraphIndex - 1];
19277
+ if (/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/u.test(bodyText.slice(paragraphStartCp, paragraphEndCp)))
19278
+ return rejected("unsupported-features");
19279
+ const sanitizedText = text2.replaceAll(/[\r\n]+/gu, " ");
19280
+ if (fib.ccpText - (paragraphEndCp - paragraphStartCp) + sanitizedText.length + 1 > budget.maxCharacters)
19281
+ return rejected("resource-limit");
19282
+ if (sanitizedText.length + 1 === paragraphEndCp - paragraphStartCp && bodyText[paragraphEndCp - 1] === "\r") {
19283
+ const replacement = `${sanitizedText}\r`;
19284
+ const patched = cfb.wordDocBytes.slice();
19285
+ let canPatch = true;
19286
+ for (const piece of pieces) {
19287
+ const start = Math.max(paragraphStartCp, piece.cpStart);
19288
+ const end = Math.min(paragraphEndCp, piece.cpEnd);
19289
+ if (start >= end)
19290
+ continue;
19291
+ const part = replacement.slice(start - paragraphStartCp, end - paragraphStartCp);
19292
+ const unit = piece.compressed ? 1 : 2;
19293
+ const fc = piece.fc + (start - piece.cpStart) * unit;
19294
+ const fcEnd = fc + part.length * unit;
19295
+ if (pieces.some((other) => other !== piece && other.fc < fcEnd && other.fc + (other.cpEnd - other.cpStart) * (other.compressed ? 1 : 2) > fc)) {
19296
+ canPatch = false;
19297
+ break;
19298
+ }
19299
+ const encoded = piece.compressed ? encodeCp1252(part) : encodePieceTextUtf16(part);
19300
+ if (!encoded) {
19301
+ canPatch = false;
19302
+ break;
19303
+ }
19304
+ patched.set(encoded, fc);
19305
+ }
19306
+ if (canPatch)
19307
+ return { status: "edited", strategy: "preserved-runs", bytes: cfb.rewrap(patched, cfb.tableBytes) };
19308
+ }
19309
+ if (!cfb.canRewrite)
19310
+ return rejected("unsupported-container");
19311
+ if (hasUnsupportedFeatures(cfb.wordDocBytes, fib))
19312
+ return rejected("unsupported-features");
19313
+ const delta2 = sanitizedText.length + 1 - (paragraphEndCp - paragraphStartCp);
19314
+ const mainFields = readFcLcbAt(cfb.wordDocBytes, fib, 16);
19315
+ if (mainFields.lcb > 0) {
19316
+ for (let index = 0; index < fib.fibRgFcLcbCount; index++) {
19317
+ if (index === 16 || index === 87)
19318
+ continue;
19319
+ const other = readFcLcbAt(cfb.wordDocBytes, fib, index);
19320
+ if (other.lcb > 0 && other.fc < mainFields.fc + mainFields.lcb && other.fc + other.lcb > mainFields.fc)
19321
+ return rejected("invalid-document");
19322
+ }
19323
+ }
19324
+ const shiftedFields = shiftDocMainFieldCps(cfb.tableBytes, mainFields, bodyText, paragraphStartCp, paragraphEndCp, delta2, budget.maxFieldRecords);
18232
19325
  const { piece: startPiece, fc: startFc } = pieceAndFcAtCp(pieces, paragraphStartCp);
19326
+ if (pieces.some((piece) => piece.cpStart < paragraphEndCp && piece.cpEnd > paragraphStartCp && piece.prm !== startPiece.prm))
19327
+ return rejected("unsupported-features");
19328
+ const { fc: paragraphMarkFc } = pieceAndFcAtCp(pieces, paragraphEndCp - 1);
18233
19329
  const papxBte = parseBteTable(cfb.tableBytes, fib.plcfbtePapx);
18234
19330
  const chpxBte = parseBteTable(cfb.tableBytes, fib.plcfbteChpx);
18235
- const papxBlob = extractPapxBlob(cfb.wordDocBytes, papxBte, startFc);
19331
+ const papxBlob = extractPapxBlob(cfb.wordDocBytes, papxBte, paragraphMarkFc);
18236
19332
  const chpxBlob = extractChpxBlob(cfb.wordDocBytes, chpxBte, startFc);
18237
- const sanitizedText = text2.replaceAll(/[\r\n]+/gu, " ");
18238
19333
  const { bytes: textBytes, compressed } = encodePieceText(`${sanitizedText}\r`);
18239
19334
  const originalLen = cfb.wordDocBytes.length;
18240
19335
  const newTextFc = originalLen;
@@ -18262,15 +19357,19 @@ function writeOleDocParagraphEdit(docBytes, paragraphIndex, text2) {
18262
19357
  fc: newTextFc,
18263
19358
  compressed,
18264
19359
  charLength: sanitizedText.length + 1,
18265
- flagsWord: startPiece.flagsWord
19360
+ flagsWord: startPiece.flagsWord,
19361
+ prm: startPiece.prm
18266
19362
  });
18267
- const delta2 = sanitizedText.length + 1 - (paragraphEndCp - paragraphStartCp);
19363
+ if (newPieces.length > budget.maxPieces)
19364
+ return rejected("resource-limit");
18268
19365
  const newCcpText = fib.ccpText + delta2;
18269
- const clxBytes = buildClxBytes(newPieces);
19366
+ const clxBytes = buildClxBytes(newPieces, prcBytes);
18270
19367
  const papxBteBytes = buildBteTableBytes(newPapxBte);
18271
19368
  const chpxBteBytes = buildBteTableBytes(newChpxBte);
18272
19369
  const newTableBytes = new Uint8Array(cfb.tableBytes.length + clxBytes.length + papxBteBytes.length + chpxBteBytes.length);
18273
19370
  newTableBytes.set(cfb.tableBytes, 0);
19371
+ if (shiftedFields)
19372
+ newTableBytes.set(shiftedFields, mainFields.fc);
18274
19373
  let tableOff = cfb.tableBytes.length;
18275
19374
  const newClx = { fc: tableOff, lcb: clxBytes.length };
18276
19375
  newTableBytes.set(clxBytes, tableOff);
@@ -18288,20 +19387,30 @@ function writeOleDocParagraphEdit(docBytes, paragraphIndex, text2) {
18288
19387
  plcfbteChpx: newChpxBteFcLcb,
18289
19388
  plcfbtePapx: newPapxBteFcLcb
18290
19389
  });
18291
- return cfb.rewrap(newWordDoc, newTableBytes);
18292
- } catch {
18293
- return docBytes;
19390
+ return { status: "edited", strategy: "piece-append", bytes: cfb.rewrap(newWordDoc, newTableBytes) };
19391
+ } catch (error) {
19392
+ if (error instanceof UnsupportedDocFieldEditError)
19393
+ return rejected("unsupported-features");
19394
+ if (error instanceof DocResourceLimitError)
19395
+ return rejected("resource-limit");
19396
+ if (error instanceof DocCfbRewriteError)
19397
+ return rejected("unsupported-container");
19398
+ return rejected("invalid-document");
18294
19399
  }
18295
19400
  }
18296
- var RISKY_PLCF_INDICES, RISKY_STTB_INDICES;
19401
+ var RISKY_PLCF_INDICES, RISKY_STTB_INDICES, SAFE_EXTENDED_FC_LCB_INDICES, DEFAULT_OLE_DOC_PROCESSING_LIMITS;
18297
19402
  var init_ole_document_doc_editor = __esm({
18298
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ole-document-doc-editor.js"() {
19403
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ole-document-doc-editor.js"() {
18299
19404
  init_ole_document_doc_cfb();
18300
19405
  init_ole_document_doc_fib();
18301
19406
  init_ole_document_doc_fkp();
18302
19407
  init_ole_document_doc_pieces();
18303
- RISKY_PLCF_INDICES = [3, 4, 5, 16, 17, 18, 19, 20];
19408
+ init_ole_document_doc_cp1252();
19409
+ init_ole_document_doc_fields();
19410
+ 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];
18304
19411
  RISKY_STTB_INDICES = [21, 22, 23];
19412
+ SAFE_EXTENDED_FC_LCB_INDICES = /* @__PURE__ */ new Set([93, 94, 113, 181, 182]);
19413
+ DEFAULT_OLE_DOC_PROCESSING_LIMITS = Object.freeze({ maxCharacters: 16777216, maxPieces: 65536, maxFieldRecords: 65536 });
18305
19414
  }
18306
19415
  });
18307
19416
 
@@ -18395,7 +19504,7 @@ var init_ole_nested_deck_editor = __esm({
18395
19504
  }
18396
19505
  });
18397
19506
 
18398
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/png-encoder.js
19507
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/png-encoder.js
18399
19508
  function crc32(bytes) {
18400
19509
  let crc = 4294967295;
18401
19510
  for (let i = 0; i < bytes.length; i++) {
@@ -18491,7 +19600,7 @@ function encodePng(width, height, rgba) {
18491
19600
  }
18492
19601
  var CRC_TABLE, PNG_SIGNATURE;
18493
19602
  var init_png_encoder = __esm({
18494
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/png-encoder.js"() {
19603
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/png-encoder.js"() {
18495
19604
  CRC_TABLE = (() => {
18496
19605
  const table = new Uint32Array(256);
18497
19606
  for (let n = 0; n < 256; n++) {
@@ -37793,7 +38902,7 @@ var init_encryption_detection = __esm({
37793
38902
  }
37794
38903
  });
37795
38904
 
37796
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/ooxml-crypto-primitives.js
38905
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/ooxml-crypto-primitives.js
37797
38906
  function getSubtle() {
37798
38907
  if (typeof globalThis.crypto !== "undefined" && globalThis.crypto.subtle) {
37799
38908
  return globalThis.crypto.subtle;
@@ -37911,7 +39020,7 @@ async function hmac(algorithm, key2, data) {
37911
39020
  return new Uint8Array(result);
37912
39021
  }
37913
39022
  var init_ooxml_crypto_primitives = __esm({
37914
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/ooxml-crypto-primitives.js"() {
39023
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/ooxml-crypto-primitives.js"() {
37915
39024
  }
37916
39025
  });
37917
39026
 
@@ -39109,7 +40218,7 @@ var init_ole2_parser = __esm({
39109
40218
  }
39110
40219
  });
39111
40220
 
39112
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/digests/bit-ops.js
40221
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/digests/bit-ops.js
39113
40222
  function rotl32(x, n) {
39114
40223
  return (x << n | x >>> 32 - n) >>> 0;
39115
40224
  }
@@ -39158,11 +40267,11 @@ function mdStyleDigest(message, initialState, transform2) {
39158
40267
  return out;
39159
40268
  }
39160
40269
  var init_bit_ops = __esm({
39161
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/digests/bit-ops.js"() {
40270
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/digests/bit-ops.js"() {
39162
40271
  }
39163
40272
  });
39164
40273
 
39165
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/digests/md4.js
40274
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/digests/md4.js
39166
40275
  function f1(x, y, z) {
39167
40276
  return x & y | ~x & z;
39168
40277
  }
@@ -39186,7 +40295,7 @@ function md4(message) {
39186
40295
  }
39187
40296
  var INITIAL_STATE, K22, K3, ROUND1, ROUND2, ROUND3;
39188
40297
  var init_md4 = __esm({
39189
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/digests/md4.js"() {
40298
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/digests/md4.js"() {
39190
40299
  init_bit_ops();
39191
40300
  INITIAL_STATE = [1732584193, 4023233417, 2562383102, 271733878];
39192
40301
  K22 = 1518500249;
@@ -94869,7 +95978,7 @@ var init_metro_blob_collect = __esm({
94869
95978
  }
94870
95979
  });
94871
95980
 
94872
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/byte-writer.js
95981
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/byte-writer.js
94873
95982
  function record(recType, data, recInstance = 0, isContainer2 = false, recVer = 0) {
94874
95983
  const header = new Uint8Array(8);
94875
95984
  const view = new DataView(header.buffer);
@@ -94884,7 +95993,7 @@ function record(recType, data, recInstance = 0, isContainer2 = false, recVer = 0
94884
95993
  }
94885
95994
  var ByteWriter;
94886
95995
  var init_byte_writer = __esm({
94887
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/byte-writer.js"() {
95996
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/byte-writer.js"() {
94888
95997
  ByteWriter = class {
94889
95998
  chunks = [];
94890
95999
  length = 0;
@@ -94967,13 +96076,13 @@ var init_byte_writer = __esm({
94967
96076
  }
94968
96077
  });
94969
96078
 
94970
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-types.js
96079
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-types.js
94971
96080
  function masterToEmu(mu) {
94972
96081
  return Math.round(mu * EMU_PER_MASTER);
94973
96082
  }
94974
96083
  var RT, OA, TEXT_TYPE, HEADER_TOKEN_PLAIN, HEADER_TOKEN_ENCRYPTED, EMU_PER_MASTER;
94975
96084
  var init_legacy_ppt_record_types = __esm({
94976
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-types.js"() {
96085
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-types.js"() {
94977
96086
  RT = {
94978
96087
  Document: 1e3,
94979
96088
  DocumentAtom: 1001,
@@ -95102,14 +96211,14 @@ var init_legacy_ppt_record_types = __esm({
95102
96211
  }
95103
96212
  });
95104
96213
 
95105
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/record-types.js
96214
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/record-types.js
95106
96215
  var init_record_types = __esm({
95107
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/record-types.js"() {
96216
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/record-types.js"() {
95108
96217
  init_legacy_ppt_record_types();
95109
96218
  }
95110
96219
  });
95111
96220
 
95112
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/current-user-writer.js
96221
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/current-user-writer.js
95113
96222
  function buildCurrentUserStream(offsetToCurrentEdit, encrypted) {
95114
96223
  const nameBytes = new ByteWriter().ansi(USER_NAME).toBytes();
95115
96224
  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();
@@ -95123,7 +96232,7 @@ function buildCurrentUserStream(offsetToCurrentEdit, encrypted) {
95123
96232
  }
95124
96233
  var USER_NAME, CURRENT_USER_STREAM_SIZE;
95125
96234
  var init_current_user_writer = __esm({
95126
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/current-user-writer.js"() {
96235
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/current-user-writer.js"() {
95127
96236
  init_record_types();
95128
96237
  init_byte_writer();
95129
96238
  USER_NAME = "pptx-viewer";
@@ -95131,7 +96240,7 @@ var init_current_user_writer = __esm({
95131
96240
  }
95132
96241
  });
95133
96242
 
95134
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/blip-writer.js
96243
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/blip-writer.js
95135
96244
  function pictureUid(picture) {
95136
96245
  return md4(picture.bytes);
95137
96246
  }
@@ -95154,7 +96263,7 @@ function buildFbse(picture, uid, foDelay, size) {
95154
96263
  }
95155
96264
  var MSOBLIP_PICT, BLIP_INFO;
95156
96265
  var init_blip_writer = __esm({
95157
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/blip-writer.js"() {
96266
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/blip-writer.js"() {
95158
96267
  init_md4();
95159
96268
  init_png_encoder();
95160
96269
  init_record_types();
@@ -95170,7 +96279,7 @@ var init_blip_writer = __esm({
95170
96279
  }
95171
96280
  });
95172
96281
 
95173
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/fopt-writer.js
96282
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/fopt-writer.js
95174
96283
  function boolPropValue(flag, bit, useBit) {
95175
96284
  return useBit | (flag ? bit : 0);
95176
96285
  }
@@ -95206,7 +96315,7 @@ function buildMetroBlobTertiaryFopt(metroBlob) {
95206
96315
  }
95207
96316
  var OPT, FBID_FLAG, METRO_BLOB_OPID;
95208
96317
  var init_fopt_writer = __esm({
95209
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/fopt-writer.js"() {
96318
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/fopt-writer.js"() {
95210
96319
  init_record_types();
95211
96320
  init_byte_writer();
95212
96321
  OPT = {
@@ -95234,7 +96343,7 @@ var init_fopt_writer = __esm({
95234
96343
  }
95235
96344
  });
95236
96345
 
95237
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/bstore-writer.js
96346
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/bstore-writer.js
95238
96347
  function buildDggDefaultProperties() {
95239
96348
  return buildFopt([
95240
96349
  { id: 385, value: 134217732 },
@@ -95292,7 +96401,7 @@ function buildPictureStore(pictures, shapesPerDrawing) {
95292
96401
  }
95293
96402
  var SHAPE_ID_CLUSTER_SIZE;
95294
96403
  var init_bstore_writer = __esm({
95295
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/bstore-writer.js"() {
96404
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/bstore-writer.js"() {
95296
96405
  init_record_types();
95297
96406
  init_blip_writer();
95298
96407
  init_byte_writer();
@@ -95301,7 +96410,7 @@ var init_bstore_writer = __esm({
95301
96410
  }
95302
96411
  });
95303
96412
 
95304
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/font-collection-writer.js
96413
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/font-collection-writer.js
95305
96414
  function buildFontEntityAtom(name, index) {
95306
96415
  const nameBytes = new ByteWriter().utf16(name.slice(0, 31)).u16(0).toBytes();
95307
96416
  const padded = new Uint8Array(LF_FACE_NAME_BYTES);
@@ -95329,14 +96438,14 @@ function buildEnvironment(fonts, otherTextStyle) {
95329
96438
  }
95330
96439
  var LF_FACE_NAME_BYTES;
95331
96440
  var init_font_collection_writer = __esm({
95332
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/font-collection-writer.js"() {
96441
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/font-collection-writer.js"() {
95333
96442
  init_record_types();
95334
96443
  init_byte_writer();
95335
96444
  LF_FACE_NAME_BYTES = 64;
95336
96445
  }
95337
96446
  });
95338
96447
 
95339
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-writer.js
96448
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-writer.js
95340
96449
  function emuToMaster(emu2) {
95341
96450
  return Math.round(emu2 / EMU_PER_MASTER);
95342
96451
  }
@@ -95392,7 +96501,7 @@ function buildDocumentContainer(input) {
95392
96501
  }
95393
96502
  var MASTER_SLIDE_ID_SENTINEL, RT_CSTRING, RT_BINARY_TAG_DATA_BLOB;
95394
96503
  var init_document_writer = __esm({
95395
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-writer.js"() {
96504
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-writer.js"() {
95396
96505
  init_record_types();
95397
96506
  init_byte_writer();
95398
96507
  init_font_collection_writer();
@@ -95402,7 +96511,7 @@ var init_document_writer = __esm({
95402
96511
  }
95403
96512
  });
95404
96513
 
95405
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/hyperlink-writer.js
96514
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/hyperlink-writer.js
95406
96515
  function buildCString(text2, recInstance) {
95407
96516
  return record(RT.CString, new ByteWriter().utf16(text2).toBytes(), recInstance, false, 0);
95408
96517
  }
@@ -95538,7 +96647,7 @@ function buildTextInteractiveInfoAtom(beginChar, endChar) {
95538
96647
  }
95539
96648
  var II_ACTION, II_JUMP, LT, FLAG_CUSTOM_SHOW_RETURN, HyperlinkCollector;
95540
96649
  var init_hyperlink_writer = __esm({
95541
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/hyperlink-writer.js"() {
96650
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/hyperlink-writer.js"() {
95542
96651
  init_record_types();
95543
96652
  init_byte_writer();
95544
96653
  II_ACTION = {
@@ -95601,7 +96710,7 @@ var init_hyperlink_writer = __esm({
95601
96710
  }
95602
96711
  });
95603
96712
 
95604
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/media-writer.js
96713
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/media-writer.js
95605
96714
  function buildCString2(text2, recInstance) {
95606
96715
  return record(RT.CString, new ByteWriter().utf16(text2).toBytes(), recInstance, false, 0);
95607
96716
  }
@@ -95637,7 +96746,7 @@ function buildMediaExObjEntries(media) {
95637
96746
  }
95638
96747
  var MediaCollector, SOUND_EXTENSION_WAV, SOUND_LENGTH_UNKNOWN;
95639
96748
  var init_media_writer = __esm({
95640
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/media-writer.js"() {
96749
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/media-writer.js"() {
95641
96750
  init_record_types();
95642
96751
  init_byte_writer();
95643
96752
  MediaCollector = class {
@@ -95673,7 +96782,7 @@ var init_media_writer = __esm({
95673
96782
  }
95674
96783
  });
95675
96784
 
95676
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/ole-writer.js
96785
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/ole-writer.js
95677
96786
  function hexToBytes(hex3) {
95678
96787
  const out = new Uint8Array(hex3.length / 2);
95679
96788
  for (let i = 0; i < out.length; i++) {
@@ -95735,7 +96844,7 @@ function buildExObjRefAtom(exObjId) {
95735
96844
  }
95736
96845
  var PACKAGE_ROOT_CLSID, COMP_OBJ_HEX, EX_OLE_EMBEDDED, DV_ASPECT_ICON, EX_OLE_SUB_DEFAULT, PACKAGER_MENU_NAME, OleCollector;
95737
96846
  var init_ole_writer = __esm({
95738
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/ole-writer.js"() {
96847
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/ole-writer.js"() {
95739
96848
  init_ole2_parser_write();
95740
96849
  init_record_types();
95741
96850
  init_byte_writer();
@@ -95795,7 +96904,7 @@ var init_ole_writer = __esm({
95795
96904
  }
95796
96905
  });
95797
96906
 
95798
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/ex-obj-list-writer.js
96907
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/ex-obj-list-writer.js
95799
96908
  function buildExObjList(hyperlinks, ole, media) {
95800
96909
  const oleEntries = ole?.all ?? [];
95801
96910
  const mediaEntries = media?.all ?? [];
@@ -95822,7 +96931,7 @@ function buildExObjList(hyperlinks, ole, media) {
95822
96931
  return record(RT.ExternalObjectList, w.toBytes(), 0, true);
95823
96932
  }
95824
96933
  var init_ex_obj_list_writer = __esm({
95825
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/ex-obj-list-writer.js"() {
96934
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/ex-obj-list-writer.js"() {
95826
96935
  init_record_types();
95827
96936
  init_byte_writer();
95828
96937
  init_hyperlink_writer();
@@ -95831,7 +96940,7 @@ var init_ex_obj_list_writer = __esm({
95831
96940
  }
95832
96941
  });
95833
96942
 
95834
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/anchor-writer.js
96943
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/anchor-writer.js
95835
96944
  function emuToMaster2(emu2) {
95836
96945
  return Math.round(emu2 / EMU_PER_MASTER);
95837
96946
  }
@@ -95876,7 +96985,7 @@ function buildChildAnchor(rect2) {
95876
96985
  }
95877
96986
  var INT16_MIN, INT16_MAX;
95878
96987
  var init_anchor_writer = __esm({
95879
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/anchor-writer.js"() {
96988
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/anchor-writer.js"() {
95880
96989
  init_record_types();
95881
96990
  init_byte_writer();
95882
96991
  INT16_MIN = -32768;
@@ -95884,7 +96993,7 @@ var init_anchor_writer = __esm({
95884
96993
  }
95885
96994
  });
95886
96995
 
95887
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/colors.js
96996
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/colors.js
95888
96997
  function parseHex(rgb2) {
95889
96998
  const hex3 = (rgb2 ?? DEFAULT_RGB).replace(/^#/u, "");
95890
96999
  if (!/^[0-9a-fA-F]{6}$/u.test(hex3)) {
@@ -95906,12 +97015,12 @@ function encodeColorIndex(rgb2) {
95906
97015
  }
95907
97016
  var DEFAULT_RGB;
95908
97017
  var init_colors = __esm({
95909
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/colors.js"() {
97018
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/colors.js"() {
95910
97019
  DEFAULT_RGB = "000000";
95911
97020
  }
95912
97021
  });
95913
97022
 
95914
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-exception-writer.js
97023
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-exception-writer.js
95915
97024
  function writePfException(w, para) {
95916
97025
  let mask = 0;
95917
97026
  if (para.hasBullet !== void 0) {
@@ -96001,7 +97110,7 @@ function writeCfException(w, run, fontIndex) {
96001
97110
  }
96002
97111
  var ALIGN_CODE, EMU_PER_MASTER_UNIT;
96003
97112
  var init_text_exception_writer = __esm({
96004
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-exception-writer.js"() {
97113
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-exception-writer.js"() {
96005
97114
  init_colors();
96006
97115
  ALIGN_CODE = {
96007
97116
  l: 0,
@@ -96013,7 +97122,7 @@ var init_text_exception_writer = __esm({
96013
97122
  }
96014
97123
  });
96015
97124
 
96016
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-atom-writer.js
97125
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-atom-writer.js
96017
97126
  function joinParagraphText(body) {
96018
97127
  return body.paragraphs.map((p) => p.runs.map((r) => r.text).join("")).join("\r");
96019
97128
  }
@@ -96074,7 +97183,7 @@ function buildTextAtoms(body, fonts, hyperlinks) {
96074
97183
  return new ByteWriter().bytes(buildTextHeaderAtom(body.textType)).bytes(buildTextCharsAtom(text2)).bytes(buildStyleTextPropAtom(body, fontIndex)).bytes(buildRunHyperlinks(body, hyperlinks)).toBytes();
96075
97184
  }
96076
97185
  var init_text_atom_writer = __esm({
96077
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-atom-writer.js"() {
97186
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/text-atom-writer.js"() {
96078
97187
  init_record_types();
96079
97188
  init_byte_writer();
96080
97189
  init_hyperlink_writer();
@@ -96082,7 +97191,7 @@ var init_text_atom_writer = __esm({
96082
97191
  }
96083
97192
  });
96084
97193
 
96085
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-placeholders-writer.js
97194
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-placeholders-writer.js
96086
97195
  function utf16z(text2) {
96087
97196
  return new ByteWriter().utf16(text2).u16(0).toBytes();
96088
97197
  }
@@ -96179,7 +97288,7 @@ function buildMasterPlaceholders(placeholders, allocator, fieldFontIndex) {
96179
97288
  }
96180
97289
  var FSP_FLAGS, RECTANGLE_SPT, TEXT_TYPE_TITLE, TEXT_TYPE_BODY, TEXT_TYPE_OTHER, SPECS, MASTER_PLACEHOLDER_ORDER, TITLE_PROMPT, BODY_PROMPT, DEFAULT_FRAMES;
96181
97290
  var init_master_placeholders_writer = __esm({
96182
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-placeholders-writer.js"() {
97291
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-placeholders-writer.js"() {
96183
97292
  init_record_types();
96184
97293
  init_anchor_writer();
96185
97294
  init_byte_writer();
@@ -96246,18 +97355,18 @@ var init_master_placeholders_writer = __esm({
96246
97355
  }
96247
97356
  });
96248
97357
 
96249
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-style-fonts.js
97358
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-style-fonts.js
96250
97359
  function masterStyleFonts(styles) {
96251
97360
  if (!styles)
96252
97361
  return [];
96253
97362
  return [styles.title, styles.body, styles.other].flatMap((levels) => levels ?? []).map((level2) => level2.run.fontName).filter((name) => Boolean(name));
96254
97363
  }
96255
97364
  var init_master_style_fonts = __esm({
96256
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-style-fonts.js"() {
97365
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-style-fonts.js"() {
96257
97366
  }
96258
97367
  });
96259
97368
 
96260
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-text-styles-writer.js
97369
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-text-styles-writer.js
96261
97370
  function buildMasterStyleAtom(recInstance, levels, fontIndex) {
96262
97371
  const w = new ByteWriter().u16(levels.length);
96263
97372
  for (const level2 of levels) {
@@ -96288,7 +97397,7 @@ function buildMasterTextStyles(styles, fontIndex) {
96288
97397
  }
96289
97398
  var EMPTY_LEVELS, FIXED_INSTANCE_DATA;
96290
97399
  var init_master_text_styles_writer = __esm({
96291
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-text-styles-writer.js"() {
97400
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-text-styles-writer.js"() {
96292
97401
  init_record_types();
96293
97402
  init_byte_writer();
96294
97403
  init_text_exception_writer();
@@ -96304,7 +97413,7 @@ var init_master_text_styles_writer = __esm({
96304
97413
  }
96305
97414
  });
96306
97415
 
96307
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-props-writer.js
97416
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-props-writer.js
96308
97417
  function fillEntries(fill) {
96309
97418
  if (!fill || fill.kind === "none") {
96310
97419
  return [{ id: OPT.fNoFillHitTest, value: boolPropValue(false, 16, 1048576) }];
@@ -96359,7 +97468,7 @@ function buildShapeFoptProps(input) {
96359
97468
  }
96360
97469
  var DASH_CODE;
96361
97470
  var init_shape_props_writer = __esm({
96362
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-props-writer.js"() {
97471
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-props-writer.js"() {
96363
97472
  init_colors();
96364
97473
  init_fopt_writer();
96365
97474
  DASH_CODE = {
@@ -96374,7 +97483,7 @@ var init_shape_props_writer = __esm({
96374
97483
  }
96375
97484
  });
96376
97485
 
96377
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-writer.js
97486
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-writer.js
96378
97487
  function buildShapeAnchor(rect2, inGroup) {
96379
97488
  return inGroup ? buildChildAnchor(rect2) : buildClientAnchor(rect2);
96380
97489
  }
@@ -96476,7 +97585,7 @@ function buildMediaShapeContainer(media, allocator, hyperlinks, mediaEmbeds, inG
96476
97585
  }
96477
97586
  var FSP_FLAG_FLIPH, FSP_FLAG_FLIPV, FSP_FLAG_OLE_SHAPE, FSP_FLAG_CHILD, PLACEHOLDER_ID;
96478
97587
  var init_shape_writer = __esm({
96479
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-writer.js"() {
97588
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-writer.js"() {
96480
97589
  init_record_types();
96481
97590
  init_anchor_writer();
96482
97591
  init_byte_writer();
@@ -96498,7 +97607,7 @@ var init_shape_writer = __esm({
96498
97607
  }
96499
97608
  });
96500
97609
 
96501
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/group-writer.js
97610
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/group-writer.js
96502
97611
  function buildFspgr(childRect) {
96503
97612
  return record(OA.FSPGR, buildChildAnchorData(childRect), 0, false, 1);
96504
97613
  }
@@ -96539,7 +97648,7 @@ function buildGroupContainer(group, fonts, allocator, hyperlinks, oleEmbeds, med
96539
97648
  }
96540
97649
  var FSP_FLAG_GROUP, FSP_FLAG_PATRIARCH, FSP_FLAG_HAVE_ANCHOR, ZERO_RECT;
96541
97650
  var init_group_writer = __esm({
96542
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/group-writer.js"() {
97651
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/group-writer.js"() {
96543
97652
  init_record_types();
96544
97653
  init_anchor_writer();
96545
97654
  init_byte_writer();
@@ -96551,10 +97660,10 @@ var init_group_writer = __esm({
96551
97660
  }
96552
97661
  });
96553
97662
 
96554
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-id-allocator.js
97663
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-id-allocator.js
96555
97664
  var ShapeIdAllocator2;
96556
97665
  var init_shape_id_allocator = __esm({
96557
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-id-allocator.js"() {
97666
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/shape-id-allocator.js"() {
96558
97667
  ShapeIdAllocator2 = class {
96559
97668
  current;
96560
97669
  constructor(drawingId, clusterSize) {
@@ -96580,7 +97689,7 @@ var init_shape_id_allocator = __esm({
96580
97689
  }
96581
97690
  });
96582
97691
 
96583
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/drawing-writer.js
97692
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/drawing-writer.js
96584
97693
  function buildDg(drawingId, shapeCount, lastShapeId) {
96585
97694
  const data = new ByteWriter().u32(shapeCount + 1).u32(lastShapeId).toBytes();
96586
97695
  return record(OA.Dg, data, drawingId, false, 0);
@@ -96611,7 +97720,7 @@ function buildDrawing(canvasRect, shapes, backgroundRgb, fonts, drawingId, hyper
96611
97720
  }
96612
97721
  var FSP_FLAG_BACKGROUND, BACKGROUND_RECT_SPT, SHAPE_ID_CLUSTER_SIZE2;
96613
97722
  var init_drawing_writer = __esm({
96614
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/drawing-writer.js"() {
97723
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/drawing-writer.js"() {
96615
97724
  init_record_types();
96616
97725
  init_byte_writer();
96617
97726
  init_colors();
@@ -96624,7 +97733,7 @@ var init_drawing_writer = __esm({
96624
97733
  }
96625
97734
  });
96626
97735
 
96627
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/notes-writer.js
97736
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/notes-writer.js
96628
97737
  function buildNotesAtom(slidePersistIdRef) {
96629
97738
  const data = new ByteWriter().i32(slidePersistIdRef).u16(0).u16(0).toBytes();
96630
97739
  return record(RT.NotesAtom, data, 0, false, 1);
@@ -96642,16 +97751,16 @@ function buildNotesContainer(paragraphs, notesRect, slidePersistIdRef, fonts, dr
96642
97751
  return record(RT.Notes, data, 0, true);
96643
97752
  }
96644
97753
  var init_notes_writer = __esm({
96645
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/notes-writer.js"() {
97754
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/notes-writer.js"() {
96646
97755
  init_record_types();
96647
97756
  init_byte_writer();
96648
97757
  init_drawing_writer();
96649
97758
  }
96650
97759
  });
96651
97760
 
96652
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-stream.js
97761
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-stream.js
96653
97762
  function readRecord(view, offset) {
96654
- if (offset < 0 || offset + RECORD_HEADER_SIZE > view.byteLength) {
97763
+ if (!Number.isSafeInteger(offset) || offset < 0 || offset + RECORD_HEADER_SIZE > view.byteLength) {
96655
97764
  return void 0;
96656
97765
  }
96657
97766
  const verAndInstance = view.getUint16(offset, true);
@@ -96679,6 +97788,9 @@ function isContainer(rec) {
96679
97788
  return rec.recVer === 15;
96680
97789
  }
96681
97790
  function* iterateRecords(view, start, end) {
97791
+ if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 0 || end < start) {
97792
+ return;
97793
+ }
96682
97794
  let offset = start;
96683
97795
  const limit = Math.min(end, view.byteLength);
96684
97796
  while (offset + RECORD_HEADER_SIZE <= limit) {
@@ -96705,16 +97817,19 @@ function findChild4(view, container2, recType, recInstance) {
96705
97817
  return void 0;
96706
97818
  }
96707
97819
  function findDescendant(view, container2, recType, recInstance) {
96708
- for (const child27 of iterateChildren(view, container2)) {
97820
+ const stack = [iterateChildren(view, container2)];
97821
+ while (stack.length > 0) {
97822
+ const next = stack[stack.length - 1].next();
97823
+ if (next.done) {
97824
+ stack.pop();
97825
+ continue;
97826
+ }
97827
+ const child27 = next.value;
96709
97828
  if (child27.recType === recType && (recInstance === void 0)) {
96710
97829
  return child27;
96711
97830
  }
96712
- if (isContainer(child27)) {
96713
- const found = findDescendant(view, child27, recType, recInstance);
96714
- if (found) {
96715
- return found;
96716
- }
96717
- }
97831
+ if (isContainer(child27))
97832
+ stack.push(iterateChildren(view, child27));
96718
97833
  }
96719
97834
  return void 0;
96720
97835
  }
@@ -96723,7 +97838,7 @@ function recordBytes(data, rec) {
96723
97838
  }
96724
97839
  var PptParseError, RECORD_HEADER_SIZE;
96725
97840
  var init_legacy_ppt_record_stream = __esm({
96726
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-stream.js"() {
97841
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-ppt-record-stream.js"() {
96727
97842
  PptParseError = class extends Error {
96728
97843
  constructor(message) {
96729
97844
  super(message);
@@ -96734,14 +97849,14 @@ var init_legacy_ppt_record_stream = __esm({
96734
97849
  }
96735
97850
  });
96736
97851
 
96737
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/record-stream.js
97852
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/record-stream.js
96738
97853
  var init_record_stream = __esm({
96739
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/record-stream.js"() {
97854
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/record-stream.js"() {
96740
97855
  init_legacy_ppt_record_stream();
96741
97856
  }
96742
97857
  });
96743
97858
 
96744
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/color-scheme.js
97859
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/color-scheme.js
96745
97860
  function toHex3(r, g, b) {
96746
97861
  return [r, g, b].map((v) => (v & 255).toString(16).padStart(2, "0").toUpperCase()).join("");
96747
97862
  }
@@ -96792,7 +97907,7 @@ function resolveEscherColor(colorRef, scheme) {
96792
97907
  }
96793
97908
  var SCHEME, DEFAULT_SCHEME;
96794
97909
  var init_color_scheme = __esm({
96795
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/color-scheme.js"() {
97910
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/color-scheme.js"() {
96796
97911
  init_record_stream();
96797
97912
  init_record_types();
96798
97913
  SCHEME = {
@@ -96818,7 +97933,7 @@ var init_color_scheme = __esm({
96818
97933
  }
96819
97934
  });
96820
97935
 
96821
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/color-scheme-writer.js
97936
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/color-scheme-writer.js
96822
97937
  function buildColorSchemeAtom(recInstance = 1, colors) {
96823
97938
  const w = new ByteWriter();
96824
97939
  for (const rgb2 of colors?.length === 8 ? colors : DEFAULT_SCHEME) {
@@ -96827,7 +97942,7 @@ function buildColorSchemeAtom(recInstance = 1, colors) {
96827
97942
  return record(RT.ColorSchemeAtom, w.toBytes(), recInstance, false, 0);
96828
97943
  }
96829
97944
  var init_color_scheme_writer = __esm({
96830
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/color-scheme-writer.js"() {
97945
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/color-scheme-writer.js"() {
96831
97946
  init_color_scheme();
96832
97947
  init_record_types();
96833
97948
  init_byte_writer();
@@ -96835,7 +97950,7 @@ var init_color_scheme_writer = __esm({
96835
97950
  }
96836
97951
  });
96837
97952
 
96838
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/slide-writer.js
97953
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/slide-writer.js
96839
97954
  function buildSlideAtomRaw(geom, masterIdRef, notesIdRef, flags) {
96840
97955
  const data = new ByteWriter().i32(geom).bytes(new Uint8Array(8)).u32(masterIdRef).i32(notesIdRef).u16(flags).u16(0).toBytes();
96841
97956
  return record(RT.SlideAtom, data, 0, false, 2);
@@ -96872,7 +97987,7 @@ function buildMainMasterContainer(slideRect, drawingId, hyperlinks, oleEmbeds, m
96872
97987
  }
96873
97988
  var SLIDE_FLAG_MASTER_OBJECTS, SLIDE_FLAG_MASTER_SCHEME, SLIDE_FLAG_MASTER_BACKGROUND, SLIDE_MASTER_ID_SENTINEL, MASTER_FIRST_COLOR_SCHEME_INSTANCE;
96874
97989
  var init_slide_writer = __esm({
96875
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/slide-writer.js"() {
97990
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/slide-writer.js"() {
96876
97991
  init_record_types();
96877
97992
  init_byte_writer();
96878
97993
  init_color_scheme_writer();
@@ -96887,7 +98002,7 @@ var init_slide_writer = __esm({
96887
98002
  }
96888
98003
  });
96889
98004
 
96890
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-stream-layout.js
98005
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-stream-layout.js
96891
98006
  function masterSlideId(index) {
96892
98007
  return MASTER_SLIDE_ID_SENTINEL + index;
96893
98008
  }
@@ -97011,7 +98126,7 @@ function ensureMinimumDocumentStreamSize(contentSizeWithoutPadding, maxPersistId
97011
98126
  }
97012
98127
  var DOC_ID, MASTER_ID;
97013
98128
  var init_document_stream_layout = __esm({
97014
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-stream-layout.js"() {
98129
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/document-stream-layout.js"() {
97015
98130
  init_bstore_writer();
97016
98131
  init_byte_writer();
97017
98132
  init_document_writer();
@@ -97029,15 +98144,15 @@ var init_document_stream_layout = __esm({
97029
98144
  }
97030
98145
  });
97031
98146
 
97032
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/crypto-constants.js
98147
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/crypto-constants.js
97033
98148
  var RC4_ALG_ID2;
97034
98149
  var init_crypto_constants = __esm({
97035
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/crypto-constants.js"() {
98150
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/crypto-constants.js"() {
97036
98151
  RC4_ALG_ID2 = 26625;
97037
98152
  }
97038
98153
  });
97039
98154
 
97040
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/rc4-cipher.js
98155
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/rc4-cipher.js
97041
98156
  function rc4Cipher(key2, data) {
97042
98157
  if (key2.length === 0) {
97043
98158
  throw new Error("RC4 key must not be empty.");
@@ -97068,11 +98183,11 @@ function rc4Cipher(key2, data) {
97068
98183
  return out;
97069
98184
  }
97070
98185
  var init_rc4_cipher = __esm({
97071
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/utils/rc4-cipher.js"() {
98186
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/utils/rc4-cipher.js"() {
97072
98187
  }
97073
98188
  });
97074
98189
 
97075
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-key.js
98190
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-key.js
97076
98191
  async function rc4CryptoApiKeyBase(password, salt) {
97077
98192
  return hash("SHA-1", concatArrays(salt, encodePasswordUtf16LE(password)));
97078
98193
  }
@@ -97113,14 +98228,14 @@ async function rc4CryptoApiEncryptVerifier(key0, verifier) {
97113
98228
  }
97114
98229
  var PADDED_40_BIT_KEY_BYTES;
97115
98230
  var init_rc4_cryptoapi_key = __esm({
97116
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-key.js"() {
98231
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-key.js"() {
97117
98232
  init_ooxml_crypto_primitives();
97118
98233
  init_rc4_cipher();
97119
98234
  PADDED_40_BIT_KEY_BYTES = 16;
97120
98235
  }
97121
98236
  });
97122
98237
 
97123
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-streams.js
98238
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-streams.js
97124
98239
  function readHeader(bytes) {
97125
98240
  const view = new DataView(bytes.buffer, bytes.byteOffset, RECORD_HEADER_SIZE);
97126
98241
  return {
@@ -97189,7 +98304,7 @@ async function cipherPicturesStream(stream, keyFor2, mode) {
97189
98304
  }
97190
98305
  var UID_SIZE, METAFILE_HEADER_SIZE, BITMAP_TAG_SIZE, METAFILE_BLIPS, BITMAP_BLIPS;
97191
98306
  var init_rc4_cryptoapi_streams = __esm({
97192
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-streams.js"() {
98307
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/rc4-cryptoapi-streams.js"() {
97193
98308
  init_rc4_cipher();
97194
98309
  init_record_stream();
97195
98310
  UID_SIZE = 16;
@@ -97200,7 +98315,7 @@ var init_rc4_cryptoapi_streams = __esm({
97200
98315
  }
97201
98316
  });
97202
98317
 
97203
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/encrypt-writer.js
98318
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/encrypt-writer.js
97204
98319
  async function buildCryptSession(password) {
97205
98320
  const salt = new Uint8Array(SALT_SIZE);
97206
98321
  crypto.getRandomValues(salt);
@@ -97228,7 +98343,7 @@ async function encryptPicturesStream(stream, ctx) {
97228
98343
  }
97229
98344
  var CSP_NAME, KEY_SIZE_BITS, SALT_SIZE, VERIFIER_SIZE, VERIFIER_HASH_SIZE, ENCRYPTION_FLAGS;
97230
98345
  var init_encrypt_writer = __esm({
97231
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/encrypt-writer.js"() {
98346
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/encrypt-writer.js"() {
97232
98347
  init_crypto_constants();
97233
98348
  init_rc4_cryptoapi_key();
97234
98349
  init_rc4_cryptoapi_streams();
@@ -97243,7 +98358,7 @@ var init_encrypt_writer = __esm({
97243
98358
  }
97244
98359
  });
97245
98360
 
97246
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-relative-runs.js
98361
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-relative-runs.js
97247
98362
  function levelsFor(styles, textType) {
97248
98363
  switch (textType) {
97249
98364
  case 0:
@@ -97309,12 +98424,12 @@ function withMasterRelativeRunStyles(deck) {
97309
98424
  }
97310
98425
  var STYLE_KEYS;
97311
98426
  var init_master_relative_runs = __esm({
97312
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-relative-runs.js"() {
98427
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/master-relative-runs.js"() {
97313
98428
  STYLE_KEYS = ["bold", "italic", "underline"];
97314
98429
  }
97315
98430
  });
97316
98431
 
97317
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/persist-writer.js
98432
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/persist-writer.js
97318
98433
  function buildPersistDirectoryAtom(entries) {
97319
98434
  const sorted = [...entries].sort((a, b) => a[0] - b[0]);
97320
98435
  const w = new ByteWriter();
@@ -97344,17 +98459,17 @@ function buildEncryptedUserEditAtom(input) {
97344
98459
  }
97345
98460
  var MAX_RUN;
97346
98461
  var init_persist_writer = __esm({
97347
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/persist-writer.js"() {
98462
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/persist-writer.js"() {
97348
98463
  init_record_types();
97349
98464
  init_byte_writer();
97350
98465
  MAX_RUN = 4095;
97351
98466
  }
97352
98467
  });
97353
98468
 
97354
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/ppt-clsid.js
98469
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/ppt-clsid.js
97355
98470
  var PPT_STORAGE_CLSID;
97356
98471
  var init_ppt_clsid = __esm({
97357
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/ppt-clsid.js"() {
98472
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/ppt-clsid.js"() {
97358
98473
  PPT_STORAGE_CLSID = new Uint8Array([
97359
98474
  16,
97360
98475
  141,
@@ -97376,7 +98491,7 @@ var init_ppt_clsid = __esm({
97376
98491
  }
97377
98492
  });
97378
98493
 
97379
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/write-ppt.js
98494
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/write-ppt.js
97380
98495
  async function finishUnencrypted(layout, lastSlideId) {
97381
98496
  const w = new ByteWriter().append(layout.bytes);
97382
98497
  const dirAtom = buildPersistDirectoryAtom(layout.offsets);
@@ -97430,7 +98545,7 @@ async function buildPptFile(deck, options = {}) {
97430
98545
  return new Uint8Array(buildOle2(streams2, PPT_STORAGE_CLSID, 0));
97431
98546
  }
97432
98547
  var init_write_ppt = __esm({
97433
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/writer/write-ppt.js"() {
98548
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/writer/write-ppt.js"() {
97434
98549
  init_ole2_parser_write();
97435
98550
  init_byte_writer();
97436
98551
  init_current_user_writer();
@@ -97442,9 +98557,9 @@ var init_write_ppt = __esm({
97442
98557
  }
97443
98558
  });
97444
98559
 
97445
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-ppt-writer.js
98560
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-ppt-writer.js
97446
98561
  var init_legacy_ppt_writer = __esm({
97447
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/legacy-ppt-writer.js"() {
98562
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/legacy-ppt-writer.js"() {
97448
98563
  init_write_ppt();
97449
98564
  init_master_style_fonts();
97450
98565
  }
@@ -136974,61 +138089,115 @@ var init_deflate_utils = __esm({
136974
138089
  }
136975
138090
  });
136976
138091
 
136977
- // node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/persist-directory.js
136978
- function parseUserEditAtom(view, offset) {
138092
+ // node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/persist-directory.js
138093
+ function checkedLimit(value) {
138094
+ if (!Number.isSafeInteger(value) || value < 1)
138095
+ throw new PptParseError("Invalid persist directory resource limit");
138096
+ return value;
138097
+ }
138098
+ function boundedAtom(view, offset, type) {
136979
138099
  const rec = readRecordOrThrow(view, offset);
136980
- if (rec.recType !== RT.UserEditAtom) {
136981
- throw new PptParseError(`Expected UserEditAtom at offset ${offset}, found recType 0x${rec.recType.toString(16)}`);
138100
+ if (rec.recType !== type || rec.recVer !== 0 || rec.recInstance !== 0) {
138101
+ throw new PptParseError(`Invalid persist atom header at offset ${offset}`);
138102
+ }
138103
+ if (rec.recLen > view.byteLength - rec.dataOffset) {
138104
+ throw new PptParseError(`Persist atom payload out of bounds at offset ${offset}`);
136982
138105
  }
138106
+ return rec;
138107
+ }
138108
+ function parseUserEditAtom(view, offset) {
138109
+ const rec = boundedAtom(view, offset, RT.UserEditAtom);
136983
138110
  if (rec.recLen !== 28 && rec.recLen !== 32) {
136984
138111
  throw new PptParseError(`UserEditAtom has invalid length ${rec.recLen}`);
136985
138112
  }
136986
138113
  const d = rec.dataOffset;
136987
- return {
138114
+ const edit = {
136988
138115
  offsetLastEdit: view.getUint32(d + 8, true),
136989
138116
  offsetPersistDirectory: view.getUint32(d + 12, true),
136990
138117
  docPersistIdRef: view.getUint32(d + 16, true),
136991
138118
  encryptSessionPersistIdRef: rec.recLen === 32 ? view.getUint32(d + 28, true) : void 0
136992
138119
  };
136993
- }
136994
- function parsePersistDirectoryAtom(view, offset) {
136995
- const rec = readRecordOrThrow(view, offset);
136996
- if (rec.recType !== RT.PersistDirectoryAtom) {
136997
- throw new PptParseError(`Expected PersistDirectoryAtom at offset ${offset}, found recType 0x${rec.recType.toString(16)}`);
138120
+ if (view.getUint8(d + 6) !== 0 || view.getUint8(d + 7) !== 3) {
138121
+ throw new PptParseError("Unsupported UserEditAtom storage version");
138122
+ }
138123
+ if (edit.offsetLastEdit >= offset || edit.offsetPersistDirectory <= edit.offsetLastEdit || edit.offsetPersistDirectory >= offset) {
138124
+ throw new PptParseError("Invalid UserEditAtom save history offsets");
136998
138125
  }
138126
+ if (edit.docPersistIdRef !== 1)
138127
+ throw new PptParseError("Invalid document persist identifier");
138128
+ return edit;
138129
+ }
138130
+ function parsePersistDirectoryAtom(view, offset, maxEntries = DEFAULT_MAX_ENTRIES) {
138131
+ checkedLimit(maxEntries);
138132
+ const rec = boundedAtom(view, offset, RT.PersistDirectoryAtom);
136999
138133
  const pairs = [];
137000
138134
  let pos2 = rec.dataOffset;
137001
138135
  const end = rec.dataOffset + rec.recLen;
137002
- while (pos2 + 4 <= end) {
138136
+ const seen = /* @__PURE__ */ new Set();
138137
+ while (pos2 < end) {
138138
+ if (end - pos2 < 4)
138139
+ throw new PptParseError("Truncated persist directory entry");
137003
138140
  const packed = view.getUint32(pos2, true);
137004
138141
  const persistId = packed & 1048575;
137005
138142
  const cPersist = packed >>> 20 & 4095;
137006
138143
  pos2 += 4;
137007
- for (let i = 0; i < cPersist && pos2 + 4 <= end; i++, pos2 += 4) {
137008
- pairs.push([persistId + i, view.getUint32(pos2, true)]);
138144
+ if (persistId > 1048574 || cPersist === 0 || persistId + cPersist - 1 > 1048575) {
138145
+ throw new PptParseError("Invalid persist identifier run");
138146
+ }
138147
+ if (cPersist * 4 > end - pos2)
138148
+ throw new PptParseError("Truncated persist offset run");
138149
+ if (pairs.length + cPersist > maxEntries)
138150
+ throw new PptParseError("Persist directory entry limit exceeded");
138151
+ for (let i = 0; i < cPersist; i++, pos2 += 4) {
138152
+ const id = persistId + i;
138153
+ if (seen.has(id))
138154
+ throw new PptParseError("Duplicate persist identifier");
138155
+ seen.add(id);
138156
+ const objectOffset = view.getUint32(pos2, true);
138157
+ if (objectOffset >= offset || objectOffset + 8 > view.byteLength)
138158
+ throw new PptParseError("Persist object offset out of bounds");
138159
+ pairs.push([id, objectOffset]);
137009
138160
  }
137010
138161
  }
137011
138162
  return pairs;
137012
138163
  }
137013
- function buildPersistDirectory(view, offsetToCurrentEdit) {
138164
+ function buildPersistDirectory(view, offsetToCurrentEdit, limits = {}) {
138165
+ const maxEdits = checkedLimit(limits.maxEdits ?? DEFAULT_MAX_EDITS);
138166
+ const maxEntries = checkedLimit(limits.maxEntries ?? DEFAULT_MAX_ENTRIES);
137014
138167
  const edits = [];
138168
+ const editOffsets = [];
137015
138169
  const seen = /* @__PURE__ */ new Set();
137016
138170
  let offset = offsetToCurrentEdit;
137017
138171
  while (offset !== 0) {
138172
+ if (edits.length >= maxEdits)
138173
+ throw new PptParseError("User edit chain limit exceeded");
137018
138174
  if (seen.has(offset)) {
137019
138175
  throw new PptParseError(`Circular UserEditAtom chain at offset ${offset}`);
137020
138176
  }
137021
138177
  seen.add(offset);
137022
138178
  const edit = parseUserEditAtom(view, offset);
137023
138179
  edits.push(edit);
138180
+ editOffsets.push(offset);
137024
138181
  offset = edit.offsetLastEdit;
137025
138182
  }
137026
138183
  if (edits.length === 0) {
137027
138184
  throw new PptParseError("No UserEditAtom found");
137028
138185
  }
137029
138186
  const directory = /* @__PURE__ */ new Map();
138187
+ let entryCount = 0;
137030
138188
  for (let i = edits.length - 1; i >= 0; i--) {
137031
- for (const [id, off] of parsePersistDirectoryAtom(view, edits[i].offsetPersistDirectory)) {
138189
+ const edit = edits[i];
138190
+ const dirAtom = boundedAtom(view, edit.offsetPersistDirectory, RT.PersistDirectoryAtom);
138191
+ const editOffset = editOffsets[i];
138192
+ if (dirAtom.dataOffset + dirAtom.recLen > editOffset)
138193
+ throw new PptParseError("Persist directory overlaps user edit");
138194
+ const entries = parsePersistDirectoryAtom(view, edit.offsetPersistDirectory, maxEntries);
138195
+ entryCount += entries.length;
138196
+ if (entryCount > maxEntries)
138197
+ throw new PptParseError("Save history persist entry limit exceeded");
138198
+ for (const [id, off] of entries) {
138199
+ if (off < edit.offsetLastEdit)
138200
+ throw new PptParseError("Persist object precedes corresponding user edit");
137032
138201
  directory.set(id, off);
137033
138202
  }
137034
138203
  }
@@ -137039,12 +138208,18 @@ function readPersistRecord(view, directory, persistId) {
137039
138208
  if (offset === void 0) {
137040
138209
  return void 0;
137041
138210
  }
137042
- return readRecordOrThrow(view, offset);
138211
+ const rec = readRecordOrThrow(view, offset);
138212
+ if (rec.recLen > view.byteLength - rec.dataOffset)
138213
+ throw new PptParseError("Persist object payload out of bounds");
138214
+ return rec;
137043
138215
  }
138216
+ var DEFAULT_MAX_EDITS, DEFAULT_MAX_ENTRIES;
137044
138217
  var init_persist_directory = __esm({
137045
- "node_modules/.bun/@christophervr+ole2@0.4.0/node_modules/@christophervr/ole2/dist/ppt/persist-directory.js"() {
138218
+ "node_modules/.bun/@christophervr+ole2@0.8.0/node_modules/@christophervr/ole2/dist/ppt/persist-directory.js"() {
137046
138219
  init_record_stream();
137047
138220
  init_record_types();
138221
+ DEFAULT_MAX_EDITS = 1e4;
138222
+ DEFAULT_MAX_ENTRIES = 1e6;
137048
138223
  }
137049
138224
  });
137050
138225