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
@@ -1,7 +1,7 @@
1
- import { findText, replaceText, replaceTextInSlide, mergePresentation } from './chunk-E3PRAHL6.mjs';
2
- import { PresentationBuilder, PptxHandler, SlideBuilder, validateSeriesIndex, removeEmptyDataPoint, ensureDataPoint, ensureChartData, assertChartGradientSupported, toChartGradientFill, isLineDrawnChartType, chartFormatTargetKey, applyChartGroupOptionsInput, countExistingLayouts, addLayoutToSlideMaster, addLayoutContentType, createLayout, STANDARD_LAYOUTS, generateLayoutXml, layoutRelsXml, createTextElement, createShapeElement, createImageElement, createTableElement, createChartElement, createConnectorElement, createMediaElement, createGroupElement, relationshipsPartFor, parseRelationships, resolvePartPath, clonePartGraph, buildRelationshipsXml, buildBlankPresentationArchive, nextRelationshipId, relativePartTarget, PptxXmlBuilder } from './chunk-TX2QFS3J.mjs';
3
- import { EMU_PER_PIXEL, EMU_PER_INCH, parseXml, first, elements, buildXml, bytesToBase64, base64ToBytes, hasTextProperties, escAttr } from './chunk-635WPRNJ.mjs';
4
- import { openPptxZip } from './chunk-E2PYQQQV.mjs';
1
+ import { findText, replaceText, replaceTextInSlide, mergePresentation } from './chunk-ZXPPM63Y.mjs';
2
+ import { PresentationBuilder, PptxHandler, SlideBuilder, validateSeriesIndex, removeEmptyDataPoint, ensureDataPoint, ensureChartData, assertChartGradientSupported, toChartGradientFill, isLineDrawnChartType, chartFormatTargetKey, applyChartGroupOptionsInput, countExistingLayouts, addLayoutToSlideMaster, addLayoutContentType, createLayout, STANDARD_LAYOUTS, generateLayoutXml, layoutRelsXml, createTextElement, createShapeElement, createImageElement, createTableElement, createChartElement, createConnectorElement, createMediaElement, createGroupElement, relationshipsPartFor, parseRelationships, resolvePartPath, clonePartGraph, buildRelationshipsXml, buildBlankPresentationArchive, nextRelationshipId, relativePartTarget, PptxXmlBuilder } from './chunk-4IIR2QEH.mjs';
3
+ import { EMU_PER_PIXEL, EMU_PER_INCH, parseXml, first, elements, buildXml, bytesToBase64, base64ToBytes, hasTextProperties, escAttr } from './chunk-DNYZX6YG.mjs';
4
+ import { openPptxZip } from './chunk-JJ37PCNR.mjs';
5
5
  import { cloneSlide, cloneElement } from './chunk-54S5A5PZ.mjs';
6
6
 
7
7
  // pptx/core/types/transition.ts
@@ -14771,7 +14771,7 @@ async function setPresentationRunText(bytes, slideIndex, elementId, runIndex, te
14771
14771
  async function createPresentationFromOutline(slides, options = {}) {
14772
14772
  if (!(slides instanceof Array) || !slides.length || slides.length > 200)
14773
14773
  throw new Error("A presentation outline has 1 to 200 slides");
14774
- const { PresentationBuilder: PresentationBuilder2 } = await import('./PresentationBuilder-MEETJGEA.mjs');
14774
+ const { PresentationBuilder: PresentationBuilder2 } = await import('./PresentationBuilder-M5UXW4AF.mjs');
14775
14775
  const { handler, data, createSlide } = await PresentationBuilder2.create({
14776
14776
  ...options.title ? { title: options.title } : {}
14777
14777
  });
@@ -2880,57 +2880,99 @@ function resolveLimits(limits) {
2880
2880
  fail: (message, limit, kind) => create ? create(message, { limit, kind }) : new ZipLimitError(message, { limit, kind })
2881
2881
  };
2882
2882
  }
2883
- function inflateEntryGuarded(entry, alreadyRead, limits) {
2883
+ async function inflateEntryGuarded(entry, alreadyRead, limits) {
2884
+ const chunks = [];
2885
+ let size = 0;
2886
+ for await (const chunk2 of streamEntryGuarded(entry, alreadyRead, limits)) {
2887
+ chunks.push(chunk2);
2888
+ size += chunk2.byteLength;
2889
+ }
2890
+ if (chunks.length === 1 && chunks[0]) return chunks[0];
2891
+ const out = new Uint8Array(size);
2892
+ let offset = 0;
2893
+ for (const chunk2 of chunks) {
2894
+ out.set(chunk2, offset);
2895
+ offset += chunk2.byteLength;
2896
+ }
2897
+ return out;
2898
+ }
2899
+ var AHEAD = 8;
2900
+ async function* streamEntryGuarded(entry, alreadyRead, limits) {
2884
2901
  const r = resolveLimits(limits);
2885
2902
  const declared = declaredEntrySize(entry);
2886
- return new Promise((resolvePromise, reject) => {
2887
- const chunks = [];
2888
- let size = 0;
2889
- let done = false;
2890
- const stream = entry.internalStream("uint8array");
2891
- const abort = (error) => {
2892
- if (done) return;
2893
- done = true;
2894
- stream.pause();
2895
- chunks.length = 0;
2896
- reject(error);
2897
- };
2898
- stream.on("data", (chunk2) => {
2899
- if (done) return;
2900
- size += chunk2.byteLength;
2901
- if (size > declared || size > r.maxEntryBytes)
2902
- return abort(
2903
- r.fail(
2904
- `${r.label} part ${entry.name} inflates past its declared size`,
2905
- r.maxEntryBytes,
2906
- size > declared ? "declaredSize" : "maxEntryBytes"
2907
- )
2908
- );
2909
- if (alreadyRead + size > r.maxTotalBytes)
2910
- return abort(
2911
- r.fail(
2912
- `${r.label} package exceeds the ${mib(r.maxTotalBytes)} MiB uncompressed content limit`,
2913
- r.maxTotalBytes,
2914
- "maxTotalBytes"
2915
- )
2916
- );
2917
- chunks.push(chunk2);
2918
- });
2919
- stream.on("error", (error) => abort(error));
2920
- stream.on("end", () => {
2921
- if (done) return;
2922
- done = true;
2923
- if (chunks.length === 1 && chunks[0]) return resolvePromise(chunks[0]);
2924
- const out = new Uint8Array(size);
2925
- let offset = 0;
2926
- for (const chunk2 of chunks) {
2927
- out.set(chunk2, offset);
2928
- offset += chunk2.byteLength;
2929
- }
2930
- resolvePromise(out);
2931
- });
2903
+ const stream = entry.internalStream("uint8array");
2904
+ const queue = [];
2905
+ let size = 0;
2906
+ let ended = false;
2907
+ let stopped = false;
2908
+ let failure;
2909
+ let paused = false;
2910
+ let wake;
2911
+ const pause = () => {
2912
+ paused = true;
2913
+ stream.pause();
2914
+ };
2915
+ const resume = () => {
2916
+ if (!paused || stopped) return;
2917
+ paused = false;
2932
2918
  stream.resume();
2919
+ };
2920
+ const fail = (error) => {
2921
+ failure ??= error;
2922
+ stopped = true;
2923
+ queue.length = 0;
2924
+ pause();
2925
+ wake?.();
2926
+ };
2927
+ stream.on("data", (chunk2) => {
2928
+ if (stopped) return pause();
2929
+ size += chunk2.byteLength;
2930
+ if (size > declared || size > r.maxEntryBytes)
2931
+ return fail(
2932
+ r.fail(
2933
+ `${r.label} part ${entry.name} inflates past its declared size`,
2934
+ r.maxEntryBytes,
2935
+ size > declared ? "declaredSize" : "maxEntryBytes"
2936
+ )
2937
+ );
2938
+ if (alreadyRead + size > r.maxTotalBytes)
2939
+ return fail(
2940
+ r.fail(
2941
+ `${r.label} package exceeds the ${mib(r.maxTotalBytes)} MiB uncompressed content limit`,
2942
+ r.maxTotalBytes,
2943
+ "maxTotalBytes"
2944
+ )
2945
+ );
2946
+ queue.push(chunk2);
2947
+ if (queue.length >= AHEAD) pause();
2948
+ wake?.();
2949
+ });
2950
+ stream.on("error", (error) => fail(error));
2951
+ stream.on("end", () => {
2952
+ ended = true;
2953
+ wake?.();
2933
2954
  });
2955
+ stream.resume();
2956
+ try {
2957
+ for (; ; ) {
2958
+ if (failure) throw failure;
2959
+ const chunk2 = queue.shift();
2960
+ if (chunk2) {
2961
+ if (queue.length < AHEAD / 2) resume();
2962
+ yield chunk2;
2963
+ continue;
2964
+ }
2965
+ if (ended) return;
2966
+ await new Promise((resolve) => {
2967
+ wake = resolve;
2968
+ resume();
2969
+ });
2970
+ wake = void 0;
2971
+ }
2972
+ } finally {
2973
+ stopped = true;
2974
+ if (!ended) pause();
2975
+ }
2934
2976
  }
2935
2977
  function toBase64(bytes) {
2936
2978
  let binary = "";
@@ -39134,6 +39176,22 @@ var THEME_EFFECT_SCHEMES = THEME_EFFECT_SCHEME_SOURCES.map(([id, name, fmtScheme
39134
39176
  function findThemeEffectScheme(id) {
39135
39177
  return THEME_EFFECT_SCHEMES.find((scheme) => scheme.id === id);
39136
39178
  }
39179
+ function formatSchemeKey(scheme) {
39180
+ const raw = (styles) => (styles ?? []).map((style) => style.rawNode ?? null);
39181
+ const lists = [scheme.fillStyles, scheme.lineStyles, scheme.effectStyles];
39182
+ return JSON.stringify(
39183
+ [scheme.name ?? null, ...lists.map(raw), raw(scheme.backgroundFillStyles)],
39184
+ (_key, value) => {
39185
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
39186
+ return value;
39187
+ }
39188
+ const entries = Object.entries(value);
39189
+ const isAttribute = ([key]) => key.startsWith("@_");
39190
+ const attributes2 = entries.filter(isAttribute).sort(([x], [y]) => x < y ? -1 : 1);
39191
+ return Object.fromEntries([...attributes2, ...entries.filter((entry) => !isAttribute(entry))]);
39192
+ }
39193
+ );
39194
+ }
39137
39195
  function wrapFormatSchemeXml(fmtSchemeXml) {
39138
39196
  return fmtSchemeXml.replace(
39139
39197
  /^<a:fmtScheme/u,
@@ -44863,6 +44921,7 @@ exports.first = first;
44863
44921
  exports.firstParagraphRuns = firstParagraphRuns;
44864
44922
  exports.flattenCellTxBodyText = flattenCellTxBodyText;
44865
44923
  exports.formatAutoNumberMarker = formatAutoNumberMarker;
44924
+ exports.formatSchemeKey = formatSchemeKey;
44866
44925
  exports.generateFontGuid = generateFontGuid;
44867
44926
  exports.getSignaturePathsToStrip = getSignaturePathsToStrip;
44868
44927
  exports.getTblFromRawXml = getTblFromRawXml;
@@ -1,4 +1,4 @@
1
- import { hasTextProperties } from './chunk-635WPRNJ.mjs';
1
+ import { hasTextProperties } from './chunk-DNYZX6YG.mjs';
2
2
  import { cloneSlide } from './chunk-54S5A5PZ.mjs';
3
3
 
4
4
  // pptx/core/builders/sdk/merge-operations.ts
@@ -1555,57 +1555,99 @@ function resolveLimits(limits) {
1555
1555
  fail: (message, limit, kind) => create2 ? create2(message, { limit, kind }) : new ZipLimitError(message, { limit, kind })
1556
1556
  };
1557
1557
  }
1558
- function inflateEntryGuarded(entry2, alreadyRead, limits) {
1558
+ async function inflateEntryGuarded(entry2, alreadyRead, limits) {
1559
+ const chunks = [];
1560
+ let size = 0;
1561
+ for await (const chunk of streamEntryGuarded(entry2, alreadyRead, limits)) {
1562
+ chunks.push(chunk);
1563
+ size += chunk.byteLength;
1564
+ }
1565
+ if (chunks.length === 1 && chunks[0]) return chunks[0];
1566
+ const out = new Uint8Array(size);
1567
+ let offset = 0;
1568
+ for (const chunk of chunks) {
1569
+ out.set(chunk, offset);
1570
+ offset += chunk.byteLength;
1571
+ }
1572
+ return out;
1573
+ }
1574
+ var AHEAD = 8;
1575
+ async function* streamEntryGuarded(entry2, alreadyRead, limits) {
1559
1576
  const r = resolveLimits(limits);
1560
1577
  const declared = declaredEntrySize(entry2);
1561
- return new Promise((resolvePromise, reject) => {
1562
- const chunks = [];
1563
- let size = 0;
1564
- let done = false;
1565
- const stream = entry2.internalStream("uint8array");
1566
- const abort = (error) => {
1567
- if (done) return;
1568
- done = true;
1569
- stream.pause();
1570
- chunks.length = 0;
1571
- reject(error);
1572
- };
1573
- stream.on("data", (chunk) => {
1574
- if (done) return;
1575
- size += chunk.byteLength;
1576
- if (size > declared || size > r.maxEntryBytes)
1577
- return abort(
1578
- r.fail(
1579
- `${r.label} part ${entry2.name} inflates past its declared size`,
1580
- r.maxEntryBytes,
1581
- size > declared ? "declaredSize" : "maxEntryBytes"
1582
- )
1583
- );
1584
- if (alreadyRead + size > r.maxTotalBytes)
1585
- return abort(
1586
- r.fail(
1587
- `${r.label} package exceeds the ${mib(r.maxTotalBytes)} MiB uncompressed content limit`,
1588
- r.maxTotalBytes,
1589
- "maxTotalBytes"
1590
- )
1591
- );
1592
- chunks.push(chunk);
1593
- });
1594
- stream.on("error", (error) => abort(error));
1595
- stream.on("end", () => {
1596
- if (done) return;
1597
- done = true;
1598
- if (chunks.length === 1 && chunks[0]) return resolvePromise(chunks[0]);
1599
- const out = new Uint8Array(size);
1600
- let offset = 0;
1601
- for (const chunk of chunks) {
1602
- out.set(chunk, offset);
1603
- offset += chunk.byteLength;
1604
- }
1605
- resolvePromise(out);
1606
- });
1578
+ const stream = entry2.internalStream("uint8array");
1579
+ const queue = [];
1580
+ let size = 0;
1581
+ let ended = false;
1582
+ let stopped = false;
1583
+ let failure;
1584
+ let paused = false;
1585
+ let wake;
1586
+ const pause = () => {
1587
+ paused = true;
1588
+ stream.pause();
1589
+ };
1590
+ const resume = () => {
1591
+ if (!paused || stopped) return;
1592
+ paused = false;
1607
1593
  stream.resume();
1594
+ };
1595
+ const fail = (error) => {
1596
+ failure ??= error;
1597
+ stopped = true;
1598
+ queue.length = 0;
1599
+ pause();
1600
+ wake?.();
1601
+ };
1602
+ stream.on("data", (chunk) => {
1603
+ if (stopped) return pause();
1604
+ size += chunk.byteLength;
1605
+ if (size > declared || size > r.maxEntryBytes)
1606
+ return fail(
1607
+ r.fail(
1608
+ `${r.label} part ${entry2.name} inflates past its declared size`,
1609
+ r.maxEntryBytes,
1610
+ size > declared ? "declaredSize" : "maxEntryBytes"
1611
+ )
1612
+ );
1613
+ if (alreadyRead + size > r.maxTotalBytes)
1614
+ return fail(
1615
+ r.fail(
1616
+ `${r.label} package exceeds the ${mib(r.maxTotalBytes)} MiB uncompressed content limit`,
1617
+ r.maxTotalBytes,
1618
+ "maxTotalBytes"
1619
+ )
1620
+ );
1621
+ queue.push(chunk);
1622
+ if (queue.length >= AHEAD) pause();
1623
+ wake?.();
1624
+ });
1625
+ stream.on("error", (error) => fail(error));
1626
+ stream.on("end", () => {
1627
+ ended = true;
1628
+ wake?.();
1608
1629
  });
1630
+ stream.resume();
1631
+ try {
1632
+ for (; ; ) {
1633
+ if (failure) throw failure;
1634
+ const chunk = queue.shift();
1635
+ if (chunk) {
1636
+ if (queue.length < AHEAD / 2) resume();
1637
+ yield chunk;
1638
+ continue;
1639
+ }
1640
+ if (ended) return;
1641
+ await new Promise((resolve) => {
1642
+ wake = resolve;
1643
+ resume();
1644
+ });
1645
+ wake = void 0;
1646
+ }
1647
+ } finally {
1648
+ stopped = true;
1649
+ if (!ended) pause();
1650
+ }
1609
1651
  }
1610
1652
  function toBase64(bytes) {
1611
1653
  let binary = "";
@@ -1549,57 +1549,99 @@ function resolveLimits(limits) {
1549
1549
  fail: (message, limit, kind) => create2 ? create2(message, { limit, kind }) : new ZipLimitError(message, { limit, kind })
1550
1550
  };
1551
1551
  }
1552
- function inflateEntryGuarded(entry2, alreadyRead, limits) {
1552
+ async function inflateEntryGuarded(entry2, alreadyRead, limits) {
1553
+ const chunks = [];
1554
+ let size = 0;
1555
+ for await (const chunk of streamEntryGuarded(entry2, alreadyRead, limits)) {
1556
+ chunks.push(chunk);
1557
+ size += chunk.byteLength;
1558
+ }
1559
+ if (chunks.length === 1 && chunks[0]) return chunks[0];
1560
+ const out = new Uint8Array(size);
1561
+ let offset = 0;
1562
+ for (const chunk of chunks) {
1563
+ out.set(chunk, offset);
1564
+ offset += chunk.byteLength;
1565
+ }
1566
+ return out;
1567
+ }
1568
+ var AHEAD = 8;
1569
+ async function* streamEntryGuarded(entry2, alreadyRead, limits) {
1553
1570
  const r = resolveLimits(limits);
1554
1571
  const declared = declaredEntrySize(entry2);
1555
- return new Promise((resolvePromise, reject) => {
1556
- const chunks = [];
1557
- let size = 0;
1558
- let done = false;
1559
- const stream = entry2.internalStream("uint8array");
1560
- const abort = (error) => {
1561
- if (done) return;
1562
- done = true;
1563
- stream.pause();
1564
- chunks.length = 0;
1565
- reject(error);
1566
- };
1567
- stream.on("data", (chunk) => {
1568
- if (done) return;
1569
- size += chunk.byteLength;
1570
- if (size > declared || size > r.maxEntryBytes)
1571
- return abort(
1572
- r.fail(
1573
- `${r.label} part ${entry2.name} inflates past its declared size`,
1574
- r.maxEntryBytes,
1575
- size > declared ? "declaredSize" : "maxEntryBytes"
1576
- )
1577
- );
1578
- if (alreadyRead + size > r.maxTotalBytes)
1579
- return abort(
1580
- r.fail(
1581
- `${r.label} package exceeds the ${mib(r.maxTotalBytes)} MiB uncompressed content limit`,
1582
- r.maxTotalBytes,
1583
- "maxTotalBytes"
1584
- )
1585
- );
1586
- chunks.push(chunk);
1587
- });
1588
- stream.on("error", (error) => abort(error));
1589
- stream.on("end", () => {
1590
- if (done) return;
1591
- done = true;
1592
- if (chunks.length === 1 && chunks[0]) return resolvePromise(chunks[0]);
1593
- const out = new Uint8Array(size);
1594
- let offset = 0;
1595
- for (const chunk of chunks) {
1596
- out.set(chunk, offset);
1597
- offset += chunk.byteLength;
1598
- }
1599
- resolvePromise(out);
1600
- });
1572
+ const stream = entry2.internalStream("uint8array");
1573
+ const queue = [];
1574
+ let size = 0;
1575
+ let ended = false;
1576
+ let stopped = false;
1577
+ let failure;
1578
+ let paused = false;
1579
+ let wake;
1580
+ const pause = () => {
1581
+ paused = true;
1582
+ stream.pause();
1583
+ };
1584
+ const resume = () => {
1585
+ if (!paused || stopped) return;
1586
+ paused = false;
1601
1587
  stream.resume();
1588
+ };
1589
+ const fail = (error) => {
1590
+ failure ??= error;
1591
+ stopped = true;
1592
+ queue.length = 0;
1593
+ pause();
1594
+ wake?.();
1595
+ };
1596
+ stream.on("data", (chunk) => {
1597
+ if (stopped) return pause();
1598
+ size += chunk.byteLength;
1599
+ if (size > declared || size > r.maxEntryBytes)
1600
+ return fail(
1601
+ r.fail(
1602
+ `${r.label} part ${entry2.name} inflates past its declared size`,
1603
+ r.maxEntryBytes,
1604
+ size > declared ? "declaredSize" : "maxEntryBytes"
1605
+ )
1606
+ );
1607
+ if (alreadyRead + size > r.maxTotalBytes)
1608
+ return fail(
1609
+ r.fail(
1610
+ `${r.label} package exceeds the ${mib(r.maxTotalBytes)} MiB uncompressed content limit`,
1611
+ r.maxTotalBytes,
1612
+ "maxTotalBytes"
1613
+ )
1614
+ );
1615
+ queue.push(chunk);
1616
+ if (queue.length >= AHEAD) pause();
1617
+ wake?.();
1618
+ });
1619
+ stream.on("error", (error) => fail(error));
1620
+ stream.on("end", () => {
1621
+ ended = true;
1622
+ wake?.();
1602
1623
  });
1624
+ stream.resume();
1625
+ try {
1626
+ for (; ; ) {
1627
+ if (failure) throw failure;
1628
+ const chunk = queue.shift();
1629
+ if (chunk) {
1630
+ if (queue.length < AHEAD / 2) resume();
1631
+ yield chunk;
1632
+ continue;
1633
+ }
1634
+ if (ended) return;
1635
+ await new Promise((resolve) => {
1636
+ wake = resolve;
1637
+ resume();
1638
+ });
1639
+ wake = void 0;
1640
+ }
1641
+ } finally {
1642
+ stopped = true;
1643
+ if (!ended) pause();
1644
+ }
1603
1645
  }
1604
1646
  function toBase64(bytes) {
1605
1647
  let binary = "";
@@ -2640,57 +2640,99 @@ function resolveLimits(limits) {
2640
2640
  fail: (message, limit, kind) => create2 ? create2(message, { limit, kind }) : new ZipLimitError(message, { limit, kind })
2641
2641
  };
2642
2642
  }
2643
- function inflateEntryGuarded(entry2, alreadyRead, limits) {
2643
+ async function inflateEntryGuarded(entry2, alreadyRead, limits) {
2644
+ const chunks = [];
2645
+ let size = 0;
2646
+ for await (const chunk of streamEntryGuarded(entry2, alreadyRead, limits)) {
2647
+ chunks.push(chunk);
2648
+ size += chunk.byteLength;
2649
+ }
2650
+ if (chunks.length === 1 && chunks[0]) return chunks[0];
2651
+ const out = new Uint8Array(size);
2652
+ let offset = 0;
2653
+ for (const chunk of chunks) {
2654
+ out.set(chunk, offset);
2655
+ offset += chunk.byteLength;
2656
+ }
2657
+ return out;
2658
+ }
2659
+ var AHEAD = 8;
2660
+ async function* streamEntryGuarded(entry2, alreadyRead, limits) {
2644
2661
  const r = resolveLimits(limits);
2645
2662
  const declared = declaredEntrySize(entry2);
2646
- return new Promise((resolvePromise, reject) => {
2647
- const chunks = [];
2648
- let size = 0;
2649
- let done = false;
2650
- const stream = entry2.internalStream("uint8array");
2651
- const abort = (error) => {
2652
- if (done) return;
2653
- done = true;
2654
- stream.pause();
2655
- chunks.length = 0;
2656
- reject(error);
2657
- };
2658
- stream.on("data", (chunk) => {
2659
- if (done) return;
2660
- size += chunk.byteLength;
2661
- if (size > declared || size > r.maxEntryBytes)
2662
- return abort(
2663
- r.fail(
2664
- `${r.label} part ${entry2.name} inflates past its declared size`,
2665
- r.maxEntryBytes,
2666
- size > declared ? "declaredSize" : "maxEntryBytes"
2667
- )
2668
- );
2669
- if (alreadyRead + size > r.maxTotalBytes)
2670
- return abort(
2671
- r.fail(
2672
- `${r.label} package exceeds the ${mib(r.maxTotalBytes)} MiB uncompressed content limit`,
2673
- r.maxTotalBytes,
2674
- "maxTotalBytes"
2675
- )
2676
- );
2677
- chunks.push(chunk);
2678
- });
2679
- stream.on("error", (error) => abort(error));
2680
- stream.on("end", () => {
2681
- if (done) return;
2682
- done = true;
2683
- if (chunks.length === 1 && chunks[0]) return resolvePromise(chunks[0]);
2684
- const out = new Uint8Array(size);
2685
- let offset = 0;
2686
- for (const chunk of chunks) {
2687
- out.set(chunk, offset);
2688
- offset += chunk.byteLength;
2689
- }
2690
- resolvePromise(out);
2691
- });
2663
+ const stream = entry2.internalStream("uint8array");
2664
+ const queue = [];
2665
+ let size = 0;
2666
+ let ended = false;
2667
+ let stopped = false;
2668
+ let failure;
2669
+ let paused = false;
2670
+ let wake;
2671
+ const pause = () => {
2672
+ paused = true;
2673
+ stream.pause();
2674
+ };
2675
+ const resume = () => {
2676
+ if (!paused || stopped) return;
2677
+ paused = false;
2692
2678
  stream.resume();
2679
+ };
2680
+ const fail = (error) => {
2681
+ failure ??= error;
2682
+ stopped = true;
2683
+ queue.length = 0;
2684
+ pause();
2685
+ wake?.();
2686
+ };
2687
+ stream.on("data", (chunk) => {
2688
+ if (stopped) return pause();
2689
+ size += chunk.byteLength;
2690
+ if (size > declared || size > r.maxEntryBytes)
2691
+ return fail(
2692
+ r.fail(
2693
+ `${r.label} part ${entry2.name} inflates past its declared size`,
2694
+ r.maxEntryBytes,
2695
+ size > declared ? "declaredSize" : "maxEntryBytes"
2696
+ )
2697
+ );
2698
+ if (alreadyRead + size > r.maxTotalBytes)
2699
+ return fail(
2700
+ r.fail(
2701
+ `${r.label} package exceeds the ${mib(r.maxTotalBytes)} MiB uncompressed content limit`,
2702
+ r.maxTotalBytes,
2703
+ "maxTotalBytes"
2704
+ )
2705
+ );
2706
+ queue.push(chunk);
2707
+ if (queue.length >= AHEAD) pause();
2708
+ wake?.();
2709
+ });
2710
+ stream.on("error", (error) => fail(error));
2711
+ stream.on("end", () => {
2712
+ ended = true;
2713
+ wake?.();
2693
2714
  });
2715
+ stream.resume();
2716
+ try {
2717
+ for (; ; ) {
2718
+ if (failure) throw failure;
2719
+ const chunk = queue.shift();
2720
+ if (chunk) {
2721
+ if (queue.length < AHEAD / 2) resume();
2722
+ yield chunk;
2723
+ continue;
2724
+ }
2725
+ if (ended) return;
2726
+ await new Promise((resolve) => {
2727
+ wake = resolve;
2728
+ resume();
2729
+ });
2730
+ wake = void 0;
2731
+ }
2732
+ } finally {
2733
+ stopped = true;
2734
+ if (!ended) pause();
2735
+ }
2694
2736
  }
2695
2737
  function toBase64(bytes) {
2696
2738
  let binary = "";