ooxml-core 1.25.1 → 1.26.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 (109) hide show
  1. package/README.md +16 -0
  2. package/dist/{PptxHandler-AUK27AQD.mjs → PptxHandler-5QBRBXRX.mjs} +3 -3
  3. package/dist/{PptxHandler-QBGEZDCO.cjs → PptxHandler-CVYP5PAN.cjs} +3 -3
  4. package/dist/PptxHandler-TOAD6P7N.mjs +4 -0
  5. package/dist/{PresentationBuilder-RX7D75GZ.mjs → PresentationBuilder-EBVNYMLE.mjs} +2 -2
  6. package/dist/{PresentationBuilder-MEETJGEA.mjs → PresentationBuilder-M5UXW4AF.mjs} +3 -3
  7. package/dist/{PresentationBuilder-CI45KEHL.cjs → PresentationBuilder-RVQZCTIO.cjs} +5 -5
  8. package/dist/automation/index.cjs +273 -156
  9. package/dist/automation/index.mjs +273 -156
  10. package/dist/automation/xlsx-read.d.ts +2 -8
  11. package/dist/automation/xlsx-read.d.ts.map +1 -1
  12. package/dist/automation/xlsx.d.ts +2 -2
  13. package/dist/chart/index.cjs +89 -47
  14. package/dist/chart/index.mjs +89 -47
  15. package/dist/{chunk-6DHZZD5R.mjs → chunk-2XMK5SXU.mjs} +106 -48
  16. package/dist/{chunk-TX2QFS3J.mjs → chunk-4IIR2QEH.mjs} +608 -371
  17. package/dist/{chunk-635WPRNJ.mjs → chunk-DNYZX6YG.mjs} +19 -3
  18. package/dist/{chunk-VGDHSED6.mjs → chunk-EBJ724RB.mjs} +1 -1
  19. package/dist/{chunk-GMETZZ3V.cjs → chunk-EEHK52XB.cjs} +1677 -1440
  20. package/dist/{chunk-E2PYQQQV.mjs → chunk-JJ37PCNR.mjs} +89 -47
  21. package/dist/{chunk-5F7OB7PA.mjs → chunk-K6OFJ5GJ.mjs} +605 -368
  22. package/dist/{chunk-HVRFRYYS.mjs → chunk-KONCS53X.mjs} +5 -5
  23. package/dist/{chunk-S5TGOEQX.cjs → chunk-MU3XSASV.cjs} +106 -47
  24. package/dist/{chunk-E3PRAHL6.mjs → chunk-ZXPPM63Y.mjs} +1 -1
  25. package/dist/docx/embedded.cjs +89 -47
  26. package/dist/docx/embedded.mjs +89 -47
  27. package/dist/docx/index.cjs +89 -47
  28. package/dist/docx/index.mjs +89 -47
  29. package/dist/docx/layout/index.cjs +2 -2
  30. package/dist/docx/layout/index.mjs +2 -2
  31. package/dist/docx/layout/input.d.ts +6 -1
  32. package/dist/docx/layout/input.d.ts.map +1 -1
  33. package/dist/docx/layout/result.d.ts +1 -0
  34. package/dist/docx/layout/result.d.ts.map +1 -1
  35. package/dist/docx/load/index.cjs +89 -47
  36. package/dist/docx/load/index.mjs +89 -47
  37. package/dist/index.cjs +128 -53
  38. package/dist/index.mjs +128 -53
  39. package/dist/opc/index.cjs +90 -47
  40. package/dist/opc/index.mjs +90 -48
  41. package/dist/opc/zip-limits.d.ts +6 -0
  42. package/dist/opc/zip-limits.d.ts.map +1 -1
  43. package/dist/pptx/automation/index.cjs +766 -444
  44. package/dist/pptx/automation/index.d.ts +4 -4
  45. package/dist/pptx/automation/index.mjs +6 -6
  46. package/dist/pptx/chunks/{index-CgjEEpfK.d.ts → index-B94RKk84.d.ts} +276 -115
  47. package/dist/pptx/chunks/index-B94RKk84.d.ts.map +1 -0
  48. package/dist/pptx/chunks/{index-CX0RM1fF.d.ts → index-BOpULlxB.d.ts} +3 -3
  49. package/dist/pptx/chunks/{index-CX0RM1fF.d.ts.map → index-BOpULlxB.d.ts.map} +1 -1
  50. package/dist/pptx/chunks/{index-DCbp5fOs.d.ts → index-D3gKRIAi.d.ts} +12 -5
  51. package/dist/pptx/chunks/{index-DCbp5fOs.d.ts.map → index-D3gKRIAi.d.ts.map} +1 -1
  52. package/dist/pptx/chunks/{text-operations-CjalmJIi.d.ts → text-operations-CNfUj45U.d.ts} +16 -2
  53. package/dist/pptx/chunks/{text-operations-CjalmJIi.d.ts.map → text-operations-CNfUj45U.d.ts.map} +1 -1
  54. package/dist/pptx/cli/index.cjs +766 -444
  55. package/dist/pptx/cli/index.d.ts +1 -1
  56. package/dist/pptx/cli/index.mjs +5 -5
  57. package/dist/pptx/converter/index.d.ts +1 -1
  58. package/dist/pptx/converter/index.mjs +3 -3
  59. package/dist/pptx/editor/render/editor-history.cjs +21 -0
  60. package/dist/pptx/editor/render/editor-history.d.ts +9 -0
  61. package/dist/pptx/editor/render/editor-history.d.ts.map +1 -1
  62. package/dist/pptx/editor/render/editor-history.mjs +21 -0
  63. package/dist/pptx/editor/render/find-replace.cjs +14 -14
  64. package/dist/pptx/editor/render/find-replace.d.ts +2 -2
  65. package/dist/pptx/editor/render/find-replace.mjs +1 -1
  66. package/dist/pptx/editor/render/slide-operations.cjs +8 -8
  67. package/dist/pptx/editor/render/slide-operations.mjs +2 -2
  68. package/dist/pptx/index.cjs +765 -442
  69. package/dist/pptx/index.d.ts +5 -5
  70. package/dist/pptx/index.mjs +6 -6
  71. package/dist/pptx/node/index.d.ts +1 -1
  72. package/dist/pptx/signature-node/index.cjs +89 -47
  73. package/dist/pptx/signature-node/index.mjs +2 -2
  74. package/dist/visio/index.cjs +266 -150
  75. package/dist/visio/index.mjs +266 -150
  76. package/dist/visio/ui/index.cjs +266 -150
  77. package/dist/visio/ui/index.mjs +266 -150
  78. package/dist/xlsx/index.cjs +518 -153
  79. package/dist/xlsx/index.mjs +518 -154
  80. package/dist/xlsx/load/index.cjs +266 -150
  81. package/dist/xlsx/load/index.mjs +266 -150
  82. package/dist/xlsx/numfmt/view.d.ts +13 -0
  83. package/dist/xlsx/numfmt/view.d.ts.map +1 -0
  84. package/dist/xlsx/read/index.d.ts +1 -0
  85. package/dist/xlsx/read/index.d.ts.map +1 -1
  86. package/dist/xlsx/read/limits.d.ts +5 -0
  87. package/dist/xlsx/read/limits.d.ts.map +1 -1
  88. package/dist/xlsx/read/package.d.ts +6 -0
  89. package/dist/xlsx/read/package.d.ts.map +1 -1
  90. package/dist/xlsx/read/rows-stream.d.ts +12 -0
  91. package/dist/xlsx/read/rows-stream.d.ts.map +1 -0
  92. package/dist/xlsx/read/rows.d.ts +37 -0
  93. package/dist/xlsx/read/rows.d.ts.map +1 -0
  94. package/dist/xlsx/read/shared-strings.d.ts +6 -1
  95. package/dist/xlsx/read/shared-strings.d.ts.map +1 -1
  96. package/dist/xlsx/read/sheet-data-source.d.ts +30 -3
  97. package/dist/xlsx/read/sheet-data-source.d.ts.map +1 -1
  98. package/dist/xlsx/read/sheet-data.d.ts +13 -2
  99. package/dist/xlsx/read/sheet-data.d.ts.map +1 -1
  100. package/dist/xlsx/read/worksheet.d.ts.map +1 -1
  101. package/dist/xlsx/ui/index.cjs +266 -150
  102. package/dist/xlsx/ui/index.mjs +266 -150
  103. package/dist/xml/index.cjs +38 -6
  104. package/dist/xml/index.mjs +37 -7
  105. package/dist/xml/lite.d.ts +15 -0
  106. package/dist/xml/lite.d.ts.map +1 -1
  107. package/package.json +1 -1
  108. package/dist/PptxHandler-5UO5DD5K.mjs +0 -4
  109. package/dist/pptx/chunks/index-CgjEEpfK.d.ts.map +0 -1
package/dist/index.cjs CHANGED
@@ -2452,6 +2452,7 @@ function nudgeOutsideLabels(boxes, disc, minY, maxY) {
2452
2452
  var xml_exports = {};
2453
2453
  __export(xml_exports, {
2454
2454
  DEFAULT_XML_LIMITS: () => DEFAULT_XML_LIMITS,
2455
+ LiteDeclinedError: () => LiteDeclinedError,
2455
2456
  LiteElement: () => LiteElement,
2456
2457
  NS: () => NS,
2457
2458
  XmlLimitError: () => XmlLimitError,
@@ -2462,6 +2463,7 @@ __export(xml_exports, {
2462
2463
  elements: () => elements,
2463
2464
  first: () => first,
2464
2465
  isElement: () => isElement,
2466
+ liteChildElements: () => liteChildElements,
2465
2467
  makeNS: () => makeNS,
2466
2468
  named: () => named,
2467
2469
  parseLiteFragment: () => parseLiteFragment,
@@ -2716,40 +2718,68 @@ function decode(text3) {
2716
2718
  }
2717
2719
  var isSpace = (code) => code === 32 || code === 9 || code === 10 || code === 13;
2718
2720
  var hasLineEnds = (xml) => xml.includes("\r") || xml.includes("\x85") || xml.includes("\u2028") || xml.includes("\u2029");
2721
+ var LiteDeclinedError = class extends Error {
2722
+ constructor() {
2723
+ super("The XML fragment needs the full parser");
2724
+ this.name = "LiteDeclinedError";
2725
+ }
2726
+ };
2719
2727
  function parseLiteFragment(xml, container, namespaces) {
2728
+ const nodes = topLevelNodes(xml, namespaces);
2729
+ for (let next = nodes.next(); ; next = nodes.next()) {
2730
+ if (next.done) return next.value ? container : void 0;
2731
+ container.childNodes.push(next.value);
2732
+ }
2733
+ }
2734
+ function* liteChildElements(xml, namespaces) {
2735
+ const nodes = topLevelNodes(xml, namespaces);
2736
+ for (let next = nodes.next(); ; next = nodes.next()) {
2737
+ if (next.done) {
2738
+ if (next.value) return;
2739
+ throw new LiteDeclinedError();
2740
+ }
2741
+ if (typeof next.value !== "string") yield next.value.asElement();
2742
+ }
2743
+ }
2744
+ function* topLevelNodes(xml, namespaces) {
2720
2745
  const source = hasLineEnds(xml) ? xml.replace(/\r[\n\u0085]/g, "\n").replace(/[\r\u0085\u2028\u2029]/g, "\n") : xml;
2721
- const root = container;
2746
+ const root = new LiteElement("", "", null);
2747
+ const level3 = root.childNodes;
2722
2748
  const stack = [root];
2723
2749
  let top = root;
2724
2750
  const n2 = source.length;
2725
2751
  let pos = 0;
2726
2752
  while (pos < n2) {
2753
+ if (level3.length && stack.length === 1) {
2754
+ yield* level3;
2755
+ level3.length = 0;
2756
+ }
2727
2757
  const lt = source.indexOf("<", pos);
2728
2758
  const end = lt < 0 ? n2 : lt;
2729
2759
  if (end > pos) {
2730
2760
  const text3 = decode(source.slice(pos, end));
2731
- if (text3 === void 0) return void 0;
2761
+ if (text3 === void 0) return false;
2732
2762
  top.childNodes.push(text3);
2733
2763
  }
2734
2764
  if (lt < 0) break;
2735
2765
  const next = source.charCodeAt(lt + 1);
2736
2766
  if (next === 33) {
2737
2767
  const after = skipCommentOrCdata(source, lt, top);
2738
- if (after < 0) return void 0;
2768
+ if (after < 0) return false;
2739
2769
  pos = after;
2740
2770
  continue;
2741
2771
  }
2742
2772
  if (next === 47) {
2743
2773
  const gt = source.indexOf(">", lt);
2744
2774
  if (gt < 0 || stack.length < 2 || source.slice(lt + 2, gt).trimEnd() !== top.tagName)
2745
- return void 0;
2775
+ return false;
2746
2776
  stack.pop();
2747
2777
  top = stack[stack.length - 1];
2748
2778
  pos = gt + 1;
2749
2779
  continue;
2750
2780
  }
2751
2781
  const parsed = startTag(source, lt + 1, namespaces);
2752
- if (!parsed) return void 0;
2782
+ if (!parsed) return false;
2753
2783
  top.childNodes.push(parsed.element);
2754
2784
  if (!parsed.selfClosing) {
2755
2785
  stack.push(parsed.element);
@@ -2757,7 +2787,9 @@ function parseLiteFragment(xml, container, namespaces) {
2757
2787
  }
2758
2788
  pos = parsed.end;
2759
2789
  }
2760
- return stack.length === 1 ? root : void 0;
2790
+ if (stack.length !== 1) return false;
2791
+ yield* level3;
2792
+ return true;
2761
2793
  }
2762
2794
  var DECLARATIONS = /<!DOCTYPE|<!ENTITY/i;
2763
2795
  function skipCommentOrCdata(source, lt, parent) {
@@ -12393,57 +12425,99 @@ function resolveLimits(limits) {
12393
12425
  fail: (message, limit, kind) => create2 ? create2(message, { limit, kind }) : new ZipLimitError(message, { limit, kind })
12394
12426
  };
12395
12427
  }
12396
- function inflateEntryGuarded(entry3, alreadyRead, limits) {
12428
+ async function inflateEntryGuarded(entry3, alreadyRead, limits) {
12429
+ const chunks = [];
12430
+ let size = 0;
12431
+ for await (const chunk of streamEntryGuarded(entry3, alreadyRead, limits)) {
12432
+ chunks.push(chunk);
12433
+ size += chunk.byteLength;
12434
+ }
12435
+ if (chunks.length === 1 && chunks[0]) return chunks[0];
12436
+ const out = new Uint8Array(size);
12437
+ let offset = 0;
12438
+ for (const chunk of chunks) {
12439
+ out.set(chunk, offset);
12440
+ offset += chunk.byteLength;
12441
+ }
12442
+ return out;
12443
+ }
12444
+ var AHEAD = 8;
12445
+ async function* streamEntryGuarded(entry3, alreadyRead, limits) {
12397
12446
  const r = resolveLimits(limits);
12398
12447
  const declared = declaredEntrySize(entry3);
12399
- return new Promise((resolvePromise, reject2) => {
12400
- const chunks = [];
12401
- let size = 0;
12402
- let done = false;
12403
- const stream = entry3.internalStream("uint8array");
12404
- const abort = (error) => {
12405
- if (done) return;
12406
- done = true;
12407
- stream.pause();
12408
- chunks.length = 0;
12409
- reject2(error);
12410
- };
12411
- stream.on("data", (chunk) => {
12412
- if (done) return;
12413
- size += chunk.byteLength;
12414
- if (size > declared || size > r.maxEntryBytes)
12415
- return abort(
12416
- r.fail(
12417
- `${r.label} part ${entry3.name} inflates past its declared size`,
12418
- r.maxEntryBytes,
12419
- size > declared ? "declaredSize" : "maxEntryBytes"
12420
- )
12421
- );
12422
- if (alreadyRead + size > r.maxTotalBytes)
12423
- return abort(
12424
- r.fail(
12425
- `${r.label} package exceeds the ${mib(r.maxTotalBytes)} MiB uncompressed content limit`,
12426
- r.maxTotalBytes,
12427
- "maxTotalBytes"
12428
- )
12429
- );
12430
- chunks.push(chunk);
12431
- });
12432
- stream.on("error", (error) => abort(error));
12433
- stream.on("end", () => {
12434
- if (done) return;
12435
- done = true;
12436
- if (chunks.length === 1 && chunks[0]) return resolvePromise(chunks[0]);
12437
- const out = new Uint8Array(size);
12438
- let offset = 0;
12439
- for (const chunk of chunks) {
12440
- out.set(chunk, offset);
12441
- offset += chunk.byteLength;
12442
- }
12443
- resolvePromise(out);
12444
- });
12448
+ const stream = entry3.internalStream("uint8array");
12449
+ const queue = [];
12450
+ let size = 0;
12451
+ let ended = false;
12452
+ let stopped = false;
12453
+ let failure;
12454
+ let paused = false;
12455
+ let wake;
12456
+ const pause = () => {
12457
+ paused = true;
12458
+ stream.pause();
12459
+ };
12460
+ const resume = () => {
12461
+ if (!paused || stopped) return;
12462
+ paused = false;
12445
12463
  stream.resume();
12464
+ };
12465
+ const fail = (error) => {
12466
+ failure ??= error;
12467
+ stopped = true;
12468
+ queue.length = 0;
12469
+ pause();
12470
+ wake?.();
12471
+ };
12472
+ stream.on("data", (chunk) => {
12473
+ if (stopped) return pause();
12474
+ size += chunk.byteLength;
12475
+ if (size > declared || size > r.maxEntryBytes)
12476
+ return fail(
12477
+ r.fail(
12478
+ `${r.label} part ${entry3.name} inflates past its declared size`,
12479
+ r.maxEntryBytes,
12480
+ size > declared ? "declaredSize" : "maxEntryBytes"
12481
+ )
12482
+ );
12483
+ if (alreadyRead + size > r.maxTotalBytes)
12484
+ return fail(
12485
+ r.fail(
12486
+ `${r.label} package exceeds the ${mib(r.maxTotalBytes)} MiB uncompressed content limit`,
12487
+ r.maxTotalBytes,
12488
+ "maxTotalBytes"
12489
+ )
12490
+ );
12491
+ queue.push(chunk);
12492
+ if (queue.length >= AHEAD) pause();
12493
+ wake?.();
12494
+ });
12495
+ stream.on("error", (error) => fail(error));
12496
+ stream.on("end", () => {
12497
+ ended = true;
12498
+ wake?.();
12446
12499
  });
12500
+ stream.resume();
12501
+ try {
12502
+ for (; ; ) {
12503
+ if (failure) throw failure;
12504
+ const chunk = queue.shift();
12505
+ if (chunk) {
12506
+ if (queue.length < AHEAD / 2) resume();
12507
+ yield chunk;
12508
+ continue;
12509
+ }
12510
+ if (ended) return;
12511
+ await new Promise((resolve) => {
12512
+ wake = resolve;
12513
+ resume();
12514
+ });
12515
+ wake = void 0;
12516
+ }
12517
+ } finally {
12518
+ stopped = true;
12519
+ if (!ended) pause();
12520
+ }
12447
12521
  }
12448
12522
  function toBase64(bytes) {
12449
12523
  let binary = "";
@@ -40323,6 +40397,7 @@ __export(opc_exports, {
40323
40397
  replaceTitleGroup: () => replaceTitleGroup,
40324
40398
  resolvePartPath: () => resolvePartPath,
40325
40399
  signature: () => signature_exports,
40400
+ streamEntryGuarded: () => streamEntryGuarded,
40326
40401
  titleGroups: () => titleGroups,
40327
40402
  writeAppProperties: () => writeAppProperties,
40328
40403
  writeCoreProperties: () => writeCoreProperties,
package/dist/index.mjs CHANGED
@@ -2446,6 +2446,7 @@ function nudgeOutsideLabels(boxes, disc, minY, maxY) {
2446
2446
  var xml_exports = {};
2447
2447
  __export(xml_exports, {
2448
2448
  DEFAULT_XML_LIMITS: () => DEFAULT_XML_LIMITS,
2449
+ LiteDeclinedError: () => LiteDeclinedError,
2449
2450
  LiteElement: () => LiteElement,
2450
2451
  NS: () => NS,
2451
2452
  XmlLimitError: () => XmlLimitError,
@@ -2456,6 +2457,7 @@ __export(xml_exports, {
2456
2457
  elements: () => elements,
2457
2458
  first: () => first,
2458
2459
  isElement: () => isElement,
2460
+ liteChildElements: () => liteChildElements,
2459
2461
  makeNS: () => makeNS,
2460
2462
  named: () => named,
2461
2463
  parseLiteFragment: () => parseLiteFragment,
@@ -2710,40 +2712,68 @@ function decode(text3) {
2710
2712
  }
2711
2713
  var isSpace = (code) => code === 32 || code === 9 || code === 10 || code === 13;
2712
2714
  var hasLineEnds = (xml) => xml.includes("\r") || xml.includes("\x85") || xml.includes("\u2028") || xml.includes("\u2029");
2715
+ var LiteDeclinedError = class extends Error {
2716
+ constructor() {
2717
+ super("The XML fragment needs the full parser");
2718
+ this.name = "LiteDeclinedError";
2719
+ }
2720
+ };
2713
2721
  function parseLiteFragment(xml, container, namespaces) {
2722
+ const nodes = topLevelNodes(xml, namespaces);
2723
+ for (let next = nodes.next(); ; next = nodes.next()) {
2724
+ if (next.done) return next.value ? container : void 0;
2725
+ container.childNodes.push(next.value);
2726
+ }
2727
+ }
2728
+ function* liteChildElements(xml, namespaces) {
2729
+ const nodes = topLevelNodes(xml, namespaces);
2730
+ for (let next = nodes.next(); ; next = nodes.next()) {
2731
+ if (next.done) {
2732
+ if (next.value) return;
2733
+ throw new LiteDeclinedError();
2734
+ }
2735
+ if (typeof next.value !== "string") yield next.value.asElement();
2736
+ }
2737
+ }
2738
+ function* topLevelNodes(xml, namespaces) {
2714
2739
  const source = hasLineEnds(xml) ? xml.replace(/\r[\n\u0085]/g, "\n").replace(/[\r\u0085\u2028\u2029]/g, "\n") : xml;
2715
- const root = container;
2740
+ const root = new LiteElement("", "", null);
2741
+ const level3 = root.childNodes;
2716
2742
  const stack = [root];
2717
2743
  let top = root;
2718
2744
  const n2 = source.length;
2719
2745
  let pos = 0;
2720
2746
  while (pos < n2) {
2747
+ if (level3.length && stack.length === 1) {
2748
+ yield* level3;
2749
+ level3.length = 0;
2750
+ }
2721
2751
  const lt = source.indexOf("<", pos);
2722
2752
  const end = lt < 0 ? n2 : lt;
2723
2753
  if (end > pos) {
2724
2754
  const text3 = decode(source.slice(pos, end));
2725
- if (text3 === void 0) return void 0;
2755
+ if (text3 === void 0) return false;
2726
2756
  top.childNodes.push(text3);
2727
2757
  }
2728
2758
  if (lt < 0) break;
2729
2759
  const next = source.charCodeAt(lt + 1);
2730
2760
  if (next === 33) {
2731
2761
  const after = skipCommentOrCdata(source, lt, top);
2732
- if (after < 0) return void 0;
2762
+ if (after < 0) return false;
2733
2763
  pos = after;
2734
2764
  continue;
2735
2765
  }
2736
2766
  if (next === 47) {
2737
2767
  const gt = source.indexOf(">", lt);
2738
2768
  if (gt < 0 || stack.length < 2 || source.slice(lt + 2, gt).trimEnd() !== top.tagName)
2739
- return void 0;
2769
+ return false;
2740
2770
  stack.pop();
2741
2771
  top = stack[stack.length - 1];
2742
2772
  pos = gt + 1;
2743
2773
  continue;
2744
2774
  }
2745
2775
  const parsed = startTag(source, lt + 1, namespaces);
2746
- if (!parsed) return void 0;
2776
+ if (!parsed) return false;
2747
2777
  top.childNodes.push(parsed.element);
2748
2778
  if (!parsed.selfClosing) {
2749
2779
  stack.push(parsed.element);
@@ -2751,7 +2781,9 @@ function parseLiteFragment(xml, container, namespaces) {
2751
2781
  }
2752
2782
  pos = parsed.end;
2753
2783
  }
2754
- return stack.length === 1 ? root : void 0;
2784
+ if (stack.length !== 1) return false;
2785
+ yield* level3;
2786
+ return true;
2755
2787
  }
2756
2788
  var DECLARATIONS = /<!DOCTYPE|<!ENTITY/i;
2757
2789
  function skipCommentOrCdata(source, lt, parent) {
@@ -12387,57 +12419,99 @@ function resolveLimits(limits) {
12387
12419
  fail: (message, limit, kind) => create2 ? create2(message, { limit, kind }) : new ZipLimitError(message, { limit, kind })
12388
12420
  };
12389
12421
  }
12390
- function inflateEntryGuarded(entry3, alreadyRead, limits) {
12422
+ async function inflateEntryGuarded(entry3, alreadyRead, limits) {
12423
+ const chunks = [];
12424
+ let size = 0;
12425
+ for await (const chunk of streamEntryGuarded(entry3, alreadyRead, limits)) {
12426
+ chunks.push(chunk);
12427
+ size += chunk.byteLength;
12428
+ }
12429
+ if (chunks.length === 1 && chunks[0]) return chunks[0];
12430
+ const out = new Uint8Array(size);
12431
+ let offset = 0;
12432
+ for (const chunk of chunks) {
12433
+ out.set(chunk, offset);
12434
+ offset += chunk.byteLength;
12435
+ }
12436
+ return out;
12437
+ }
12438
+ var AHEAD = 8;
12439
+ async function* streamEntryGuarded(entry3, alreadyRead, limits) {
12391
12440
  const r = resolveLimits(limits);
12392
12441
  const declared = declaredEntrySize(entry3);
12393
- return new Promise((resolvePromise, reject2) => {
12394
- const chunks = [];
12395
- let size = 0;
12396
- let done = false;
12397
- const stream = entry3.internalStream("uint8array");
12398
- const abort = (error) => {
12399
- if (done) return;
12400
- done = true;
12401
- stream.pause();
12402
- chunks.length = 0;
12403
- reject2(error);
12404
- };
12405
- stream.on("data", (chunk) => {
12406
- if (done) return;
12407
- size += chunk.byteLength;
12408
- if (size > declared || size > r.maxEntryBytes)
12409
- return abort(
12410
- r.fail(
12411
- `${r.label} part ${entry3.name} inflates past its declared size`,
12412
- r.maxEntryBytes,
12413
- size > declared ? "declaredSize" : "maxEntryBytes"
12414
- )
12415
- );
12416
- if (alreadyRead + size > r.maxTotalBytes)
12417
- return abort(
12418
- r.fail(
12419
- `${r.label} package exceeds the ${mib(r.maxTotalBytes)} MiB uncompressed content limit`,
12420
- r.maxTotalBytes,
12421
- "maxTotalBytes"
12422
- )
12423
- );
12424
- chunks.push(chunk);
12425
- });
12426
- stream.on("error", (error) => abort(error));
12427
- stream.on("end", () => {
12428
- if (done) return;
12429
- done = true;
12430
- if (chunks.length === 1 && chunks[0]) return resolvePromise(chunks[0]);
12431
- const out = new Uint8Array(size);
12432
- let offset = 0;
12433
- for (const chunk of chunks) {
12434
- out.set(chunk, offset);
12435
- offset += chunk.byteLength;
12436
- }
12437
- resolvePromise(out);
12438
- });
12442
+ const stream = entry3.internalStream("uint8array");
12443
+ const queue = [];
12444
+ let size = 0;
12445
+ let ended = false;
12446
+ let stopped = false;
12447
+ let failure;
12448
+ let paused = false;
12449
+ let wake;
12450
+ const pause = () => {
12451
+ paused = true;
12452
+ stream.pause();
12453
+ };
12454
+ const resume = () => {
12455
+ if (!paused || stopped) return;
12456
+ paused = false;
12439
12457
  stream.resume();
12458
+ };
12459
+ const fail = (error) => {
12460
+ failure ??= error;
12461
+ stopped = true;
12462
+ queue.length = 0;
12463
+ pause();
12464
+ wake?.();
12465
+ };
12466
+ stream.on("data", (chunk) => {
12467
+ if (stopped) return pause();
12468
+ size += chunk.byteLength;
12469
+ if (size > declared || size > r.maxEntryBytes)
12470
+ return fail(
12471
+ r.fail(
12472
+ `${r.label} part ${entry3.name} inflates past its declared size`,
12473
+ r.maxEntryBytes,
12474
+ size > declared ? "declaredSize" : "maxEntryBytes"
12475
+ )
12476
+ );
12477
+ if (alreadyRead + size > r.maxTotalBytes)
12478
+ return fail(
12479
+ r.fail(
12480
+ `${r.label} package exceeds the ${mib(r.maxTotalBytes)} MiB uncompressed content limit`,
12481
+ r.maxTotalBytes,
12482
+ "maxTotalBytes"
12483
+ )
12484
+ );
12485
+ queue.push(chunk);
12486
+ if (queue.length >= AHEAD) pause();
12487
+ wake?.();
12488
+ });
12489
+ stream.on("error", (error) => fail(error));
12490
+ stream.on("end", () => {
12491
+ ended = true;
12492
+ wake?.();
12440
12493
  });
12494
+ stream.resume();
12495
+ try {
12496
+ for (; ; ) {
12497
+ if (failure) throw failure;
12498
+ const chunk = queue.shift();
12499
+ if (chunk) {
12500
+ if (queue.length < AHEAD / 2) resume();
12501
+ yield chunk;
12502
+ continue;
12503
+ }
12504
+ if (ended) return;
12505
+ await new Promise((resolve) => {
12506
+ wake = resolve;
12507
+ resume();
12508
+ });
12509
+ wake = void 0;
12510
+ }
12511
+ } finally {
12512
+ stopped = true;
12513
+ if (!ended) pause();
12514
+ }
12441
12515
  }
12442
12516
  function toBase64(bytes) {
12443
12517
  let binary = "";
@@ -40317,6 +40391,7 @@ __export(opc_exports, {
40317
40391
  replaceTitleGroup: () => replaceTitleGroup,
40318
40392
  resolvePartPath: () => resolvePartPath,
40319
40393
  signature: () => signature_exports,
40394
+ streamEntryGuarded: () => streamEntryGuarded,
40320
40395
  titleGroups: () => titleGroups,
40321
40396
  writeAppProperties: () => writeAppProperties,
40322
40397
  writeCoreProperties: () => writeCoreProperties,
@@ -534,57 +534,99 @@ function resolveLimits(limits) {
534
534
  fail: (message, limit, kind) => create ? create(message, { limit, kind }) : new ZipLimitError(message, { limit, kind })
535
535
  };
536
536
  }
537
- function inflateEntryGuarded(entry, alreadyRead, limits) {
537
+ async function inflateEntryGuarded(entry, alreadyRead, limits) {
538
+ const chunks = [];
539
+ let size = 0;
540
+ for await (const chunk of streamEntryGuarded(entry, alreadyRead, limits)) {
541
+ chunks.push(chunk);
542
+ size += chunk.byteLength;
543
+ }
544
+ if (chunks.length === 1 && chunks[0]) return chunks[0];
545
+ const out = new Uint8Array(size);
546
+ let offset = 0;
547
+ for (const chunk of chunks) {
548
+ out.set(chunk, offset);
549
+ offset += chunk.byteLength;
550
+ }
551
+ return out;
552
+ }
553
+ var AHEAD = 8;
554
+ async function* streamEntryGuarded(entry, alreadyRead, limits) {
538
555
  const r = resolveLimits(limits);
539
556
  const declared = declaredEntrySize(entry);
540
- return new Promise((resolvePromise, reject2) => {
541
- const chunks = [];
542
- let size = 0;
543
- let done = false;
544
- const stream = entry.internalStream("uint8array");
545
- const abort = (error) => {
546
- if (done) return;
547
- done = true;
548
- stream.pause();
549
- chunks.length = 0;
550
- reject2(error);
551
- };
552
- stream.on("data", (chunk) => {
553
- if (done) return;
554
- size += chunk.byteLength;
555
- if (size > declared || size > r.maxEntryBytes)
556
- return abort(
557
- r.fail(
558
- `${r.label} part ${entry.name} inflates past its declared size`,
559
- r.maxEntryBytes,
560
- size > declared ? "declaredSize" : "maxEntryBytes"
561
- )
562
- );
563
- if (alreadyRead + size > r.maxTotalBytes)
564
- return abort(
565
- r.fail(
566
- `${r.label} package exceeds the ${mib(r.maxTotalBytes)} MiB uncompressed content limit`,
567
- r.maxTotalBytes,
568
- "maxTotalBytes"
569
- )
570
- );
571
- chunks.push(chunk);
572
- });
573
- stream.on("error", (error) => abort(error));
574
- stream.on("end", () => {
575
- if (done) return;
576
- done = true;
577
- if (chunks.length === 1 && chunks[0]) return resolvePromise(chunks[0]);
578
- const out = new Uint8Array(size);
579
- let offset = 0;
580
- for (const chunk of chunks) {
581
- out.set(chunk, offset);
582
- offset += chunk.byteLength;
583
- }
584
- resolvePromise(out);
585
- });
557
+ const stream = entry.internalStream("uint8array");
558
+ const queue = [];
559
+ let size = 0;
560
+ let ended = false;
561
+ let stopped = false;
562
+ let failure;
563
+ let paused = false;
564
+ let wake;
565
+ const pause = () => {
566
+ paused = true;
567
+ stream.pause();
568
+ };
569
+ const resume = () => {
570
+ if (!paused || stopped) return;
571
+ paused = false;
586
572
  stream.resume();
573
+ };
574
+ const fail = (error) => {
575
+ failure ??= error;
576
+ stopped = true;
577
+ queue.length = 0;
578
+ pause();
579
+ wake?.();
580
+ };
581
+ stream.on("data", (chunk) => {
582
+ if (stopped) return pause();
583
+ size += chunk.byteLength;
584
+ if (size > declared || size > r.maxEntryBytes)
585
+ return fail(
586
+ r.fail(
587
+ `${r.label} part ${entry.name} inflates past its declared size`,
588
+ r.maxEntryBytes,
589
+ size > declared ? "declaredSize" : "maxEntryBytes"
590
+ )
591
+ );
592
+ if (alreadyRead + size > r.maxTotalBytes)
593
+ return fail(
594
+ r.fail(
595
+ `${r.label} package exceeds the ${mib(r.maxTotalBytes)} MiB uncompressed content limit`,
596
+ r.maxTotalBytes,
597
+ "maxTotalBytes"
598
+ )
599
+ );
600
+ queue.push(chunk);
601
+ if (queue.length >= AHEAD) pause();
602
+ wake?.();
603
+ });
604
+ stream.on("error", (error) => fail(error));
605
+ stream.on("end", () => {
606
+ ended = true;
607
+ wake?.();
587
608
  });
609
+ stream.resume();
610
+ try {
611
+ for (; ; ) {
612
+ if (failure) throw failure;
613
+ const chunk = queue.shift();
614
+ if (chunk) {
615
+ if (queue.length < AHEAD / 2) resume();
616
+ yield chunk;
617
+ continue;
618
+ }
619
+ if (ended) return;
620
+ await new Promise((resolve) => {
621
+ wake = resolve;
622
+ resume();
623
+ });
624
+ wake = void 0;
625
+ }
626
+ } finally {
627
+ stopped = true;
628
+ if (!ended) pause();
629
+ }
588
630
  }
589
631
  function toBase64(bytes) {
590
632
  let binary = "";
@@ -1694,6 +1736,7 @@ exports.replaceEmbeddedPackage = replaceEmbeddedPackage;
1694
1736
  exports.replaceTitleGroup = replaceTitleGroup;
1695
1737
  exports.resolvePartPath = resolvePartPath;
1696
1738
  exports.signature = signature_exports;
1739
+ exports.streamEntryGuarded = streamEntryGuarded;
1697
1740
  exports.titleGroups = titleGroups;
1698
1741
  exports.writeAppProperties = writeAppProperties;
1699
1742
  exports.writeCoreProperties = writeCoreProperties;