@poe-platform/safe-bash 0.1.789 → 0.1.790

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 (207) hide show
  1. package/dist/image-ast/index.browser.js +147 -80
  2. package/dist/image-ast/index.js +147 -80
  3. package/dist/mp4-ast/mp4.d.ts +2 -0
  4. package/dist/pdf-ast/cos/parser.d.ts +1 -0
  5. package/dist/pdf-ast/cos/security.d.ts +2 -0
  6. package/dist/pdf-ast/cos/writer.d.ts +1 -0
  7. package/dist/pdf-ast/document.d.ts +3 -0
  8. package/dist/pdf-ast/edit/forms.d.ts +1 -0
  9. package/dist/pdf-ast/index.js +171 -82
  10. package/dist/safe-bash/chunks/{chunk-L5QQLNTO.js → chunk-22PI65AH.js} +2 -2
  11. package/dist/safe-bash/chunks/{chunk-KHJGUF2W.js → chunk-2TAGYMPK.js} +43 -42
  12. package/dist/safe-bash/chunks/{chunk-D4PHJK4T.js → chunk-2W4HTMEK.js} +52 -48
  13. package/dist/safe-bash/chunks/{chunk-FFZXP6ZC.js → chunk-3M7L7XU2.js} +2 -2
  14. package/dist/safe-bash/chunks/{chunk-XNODZRVD.js → chunk-3QAO6UYS.js} +2 -2
  15. package/dist/safe-bash/chunks/{chunk-YPETOVQU.js → chunk-3VKFK3NF.js} +2 -2
  16. package/dist/safe-bash/chunks/chunk-5OST7NOX.js +42 -0
  17. package/dist/safe-bash/chunks/{chunk-KEBSX2AX.js → chunk-6HLURHVU.js} +2 -2
  18. package/dist/safe-bash/chunks/chunk-DYEUZE6Z.js +19 -0
  19. package/dist/safe-bash/chunks/{chunk-T2TGCHKE.js → chunk-FM3WBSZT.js} +2 -2
  20. package/dist/safe-bash/chunks/chunk-GAYRKQM6.js +22 -0
  21. package/dist/safe-bash/chunks/{chunk-Q45QCA4J.js → chunk-I3KSESCR.js} +0 -7
  22. package/dist/safe-bash/chunks/{chunk-OSKDIBQS.js → chunk-JLIMK5TD.js} +1 -1
  23. package/dist/safe-bash/chunks/{chunk-2AYZCT5X.js → chunk-JQ2FAJJT.js} +27 -23
  24. package/dist/safe-bash/chunks/{chunk-QA3NVP43.js → chunk-JRE6Z3T7.js} +2 -2
  25. package/dist/safe-bash/chunks/{chunk-DC5EHLKS.js → chunk-NDIL6T7Y.js} +5 -5
  26. package/dist/safe-bash/chunks/{chunk-747G42FY.js → chunk-OPR4UAIT.js} +2 -2
  27. package/dist/safe-bash/chunks/chunk-OSMQCYSP.js +19 -0
  28. package/dist/safe-bash/chunks/chunk-OYB332PQ.js +17 -0
  29. package/dist/safe-bash/chunks/{chunk-X5ZCECM6.js → chunk-QTIH2AFE.js} +77 -69
  30. package/dist/safe-bash/chunks/{chunk-CTUHLNJM.js → chunk-SBESXWT2.js} +43 -44
  31. package/dist/safe-bash/chunks/{chunk-4FDQJUFW.js → chunk-SDEPGTOF.js} +1 -1
  32. package/dist/safe-bash/chunks/chunk-UZU5BIJI.js +32 -0
  33. package/dist/safe-bash/chunks/{chunk-BI6JV62X.js → chunk-VCCMROTL.js} +7 -10
  34. package/dist/safe-bash/chunks/chunk-W47GHRRF.js +13 -0
  35. package/dist/safe-bash/chunks/{chunk-NPMQWZUZ.js → chunk-WS7KZIUM.js} +2 -2
  36. package/dist/safe-bash/chunks/{chunk-3PZYHMGM.js → chunk-YYAERCWS.js} +7 -7
  37. package/dist/safe-bash/chunks/{chunk-5U7JECDB.js → chunk-ZPGVEUKF.js} +8 -7
  38. package/dist/safe-bash/chunks/{csvkit-K55OYAQC.js → csvkit-USUJG62I.js} +65 -11
  39. package/dist/safe-bash/chunks/{ffmpeg-BEFTQ6DZ.js → ffmpeg-KRGG5DLH.js} +21 -10
  40. package/dist/safe-bash/chunks/{gh-HQWOWLWE.js → gh-UCFDUZCX.js} +16 -8
  41. package/dist/safe-bash/chunks/{git-HO7WDPHZ.js → git-LPAF6KDG.js} +7 -9
  42. package/dist/safe-bash/chunks/{imagemagick-53BMHH6D.js → imagemagick-KGREKK4G.js} +38 -7
  43. package/dist/safe-bash/chunks/{implementation-QUTAAYMT.js → implementation-FXDRYS5A.js} +34 -8
  44. package/dist/safe-bash/chunks/{pdfimages-4OYI6FLG.js → pdfimages-UADCF4G4.js} +12 -8
  45. package/dist/safe-bash/chunks/{pdfinfo-I7U6TQPP.js → pdfinfo-O7UWPF4W.js} +38 -13
  46. package/dist/safe-bash/chunks/{pdftk-SUA6FMHI.js → pdftk-AERXIJTN.js} +13 -8
  47. package/dist/safe-bash/chunks/{pdftoppm-4C5DGEWX.js → pdftoppm-L466JQKI.js} +17 -10
  48. package/dist/safe-bash/chunks/{pdftotext-Y4WI225Y.js → pdftotext-SUSI4WXS.js} +19 -9
  49. package/dist/safe-bash/chunks/{qpdf-IORB4RV5.js → qpdf-YL24KVRH.js} +14 -8
  50. package/dist/safe-bash/chunks/{sips-WHAMJFEU.js → sips-QXEQZERX.js} +14 -7
  51. package/dist/safe-bash/chunks/{soffice-SYEK6WJS.js → soffice-TBITRML3.js} +16 -8
  52. package/dist/safe-bash/chunks/{wkhtmltopdf-ZIICWJLF.js → wkhtmltopdf-NJA2THRC.js} +27 -7
  53. package/dist/safe-bash/command-chunks/chunk-2C5BEBPY.js +1388 -0
  54. package/dist/safe-bash/command-chunks/{chunk-2VTMZTV3.js → chunk-2EXV2ZLV.js} +2 -2
  55. package/dist/safe-bash/command-chunks/{chunk-UJOO6DKY.js → chunk-6EASC5EC.js} +1 -1
  56. package/dist/safe-bash/command-chunks/{chunk-ZF3ZVGQC.js → chunk-7JRITHKW.js} +150 -80
  57. package/dist/safe-bash/{chunks/chunk-LD76P7AG.js → command-chunks/chunk-AKDMCNX4.js} +74 -39
  58. package/dist/safe-bash/command-chunks/{chunk-6F7QJMJ3.js → chunk-CBDVLMJB.js} +1 -1
  59. package/dist/safe-bash/command-chunks/chunk-H4LWTITX.js +169 -0
  60. package/dist/safe-bash/command-chunks/chunk-I2MQNBGR.js +145 -0
  61. package/dist/safe-bash/command-chunks/{chunk-5GRLAARV.js → chunk-IOXI5ZAJ.js} +1 -1
  62. package/dist/safe-bash/command-chunks/{chunk-XNHSCU6I.js → chunk-MDPIOQUD.js} +6 -6
  63. package/dist/safe-bash/command-chunks/chunk-QI4MGIN6.js +6 -0
  64. package/dist/safe-bash/command-chunks/chunk-QTYZAWSB.js +91 -0
  65. package/dist/safe-bash/command-chunks/chunk-SNK7K3XW.js +90 -0
  66. package/dist/safe-bash/command-chunks/chunk-T5OLGM43.js +314 -0
  67. package/dist/safe-bash/command-chunks/chunk-TB7IFMUZ.js +802 -0
  68. package/dist/safe-bash/command-chunks/{chunk-AT6ZSOE6.js → chunk-TPPBPIWL.js} +1 -1
  69. package/dist/safe-bash/command-chunks/chunk-VMK4XVKO.js +82 -0
  70. package/dist/safe-bash/command-chunks/chunk-VNSJKXDU.js +130 -0
  71. package/dist/safe-bash/command-chunks/chunk-YFNTMH6Z.js +6 -0
  72. package/dist/safe-bash/commands/csplit/index.browser.js +2 -2
  73. package/dist/safe-bash/commands/docx/index.browser.js +2 -2
  74. package/dist/safe-bash/commands/factor/index.browser.js +2 -2
  75. package/dist/safe-bash/commands/getopt/index.browser.js +2 -2
  76. package/dist/safe-bash/commands/hexdump/index.browser.js +2 -2
  77. package/dist/safe-bash/commands/iconv/index.browser.js +2 -2
  78. package/dist/safe-bash/commands/line-endings/index.browser.js +2 -2
  79. package/dist/safe-bash/commands/llm/command.d.ts +1 -4
  80. package/dist/safe-bash/commands/llm/command.js +1 -248
  81. package/dist/safe-bash/commands/llm/elevenlabs-stream.d.ts +1 -2
  82. package/dist/safe-bash/commands/llm/elevenlabs-stream.js +1 -117
  83. package/dist/safe-bash/commands/llm/elevenlabs.d.ts +1 -15
  84. package/dist/safe-bash/commands/llm/elevenlabs.js +1 -123
  85. package/dist/safe-bash/commands/llm/index.browser.js +20 -15
  86. package/dist/safe-bash/commands/llm/index.d.ts +1 -6
  87. package/dist/safe-bash/commands/llm/index.js +1 -4
  88. package/dist/safe-bash/commands/llm/mime.d.ts +1 -2
  89. package/dist/safe-bash/commands/llm/mime.js +1 -136
  90. package/dist/safe-bash/commands/llm/openai-http.d.ts +1 -8
  91. package/dist/safe-bash/commands/llm/openai-http.js +1 -143
  92. package/dist/safe-bash/commands/llm/openai-sse.d.ts +1 -3
  93. package/dist/safe-bash/commands/llm/openai-sse.js +1 -78
  94. package/dist/safe-bash/commands/llm/openai.d.ts +1 -14
  95. package/dist/safe-bash/commands/llm/openai.js +1 -288
  96. package/dist/safe-bash/commands/llm/providers/elevenlabs.d.ts +1 -1
  97. package/dist/safe-bash/commands/llm/providers/elevenlabs.js +1 -1
  98. package/dist/safe-bash/commands/llm/providers/index.browser.js +6 -6
  99. package/dist/safe-bash/commands/llm/providers/index.d.ts +1 -3
  100. package/dist/safe-bash/commands/llm/providers/index.js +1 -2
  101. package/dist/safe-bash/commands/llm/providers/openai.d.ts +1 -1
  102. package/dist/safe-bash/commands/llm/providers/openai.js +1 -1
  103. package/dist/safe-bash/commands/llm/providers/shared.d.ts +1 -23
  104. package/dist/safe-bash/commands/llm/providers/shared.js +1 -65
  105. package/dist/safe-bash/commands/llm/service.d.ts +1 -37
  106. package/dist/safe-bash/commands/llm/service.js +1 -151
  107. package/dist/safe-bash/commands/llm/types.d.ts +1 -52
  108. package/dist/safe-bash/commands/llm/types.js +1 -1
  109. package/dist/safe-bash/commands/mdq/index.browser.js +3 -3
  110. package/dist/safe-bash/commands/media/index.browser.js +1 -1
  111. package/dist/safe-bash/commands/network/index.browser.js +9 -9
  112. package/dist/safe-bash/commands/network/types.d.ts +2 -40
  113. package/dist/safe-bash/commands/node/index.browser.js +6 -8
  114. package/dist/safe-bash/commands/op/index.browser.js +3 -3
  115. package/dist/safe-bash/commands/op/index.js +12 -28
  116. package/dist/safe-bash/commands/pr/index.browser.js +2 -2
  117. package/dist/safe-bash/commands/python/index.browser.js +8 -8
  118. package/dist/safe-bash/commands/python/worker.browser.js +2 -2
  119. package/dist/safe-bash/commands/tsort/index.browser.js +2 -2
  120. package/dist/safe-bash/commands/xml/index.browser.js +2 -2
  121. package/dist/safe-bash/commands/yq/index.browser.js +3 -3
  122. package/dist/safe-bash/core.browser.js +9775 -10975
  123. package/dist/safe-bash/core.d.ts +0 -1
  124. package/dist/safe-bash/core.js +0 -1
  125. package/dist/safe-bash/jobs.browser.js +5 -4
  126. package/dist/safe-bash/optional-host.browser.js +61 -88
  127. package/dist/safe-bash/shell/runtime.js +34 -12
  128. package/dist/safe-bash/yq-browser/index.js +1 -1
  129. package/dist/safe-bash-command-ffmpeg/index.js +8130 -8011
  130. package/dist/safe-bash-command-git/git_rust.wasm +0 -0
  131. package/dist/safe-bash-command-git/wasm.generated.js +1 -1
  132. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  133. package/dist/safe-bash-command-llm/LICENSE +21 -0
  134. package/dist/safe-bash-command-llm/command.d.ts +5 -0
  135. package/dist/safe-bash-command-llm/command.js +14 -0
  136. package/dist/safe-bash-command-llm/configuration.d.ts +18 -0
  137. package/dist/safe-bash-command-llm/elevenlabs-stream.d.ts +2 -0
  138. package/dist/safe-bash-command-llm/elevenlabs-stream.js +7 -0
  139. package/dist/safe-bash-command-llm/elevenlabs.d.ts +15 -0
  140. package/dist/safe-bash-command-llm/elevenlabs.js +10 -0
  141. package/dist/safe-bash-command-llm/index.d.ts +10 -0
  142. package/dist/safe-bash-command-llm/index.js +46 -0
  143. package/dist/safe-bash-command-llm/mime.d.ts +2 -0
  144. package/dist/safe-bash-command-llm/mime.js +9 -0
  145. package/dist/safe-bash-command-llm/model-options.d.ts +3 -0
  146. package/dist/safe-bash-command-llm/openai-http.d.ts +8 -0
  147. package/dist/safe-bash-command-llm/openai-http.js +17 -0
  148. package/dist/safe-bash-command-llm/openai-sse.d.ts +3 -0
  149. package/dist/safe-bash-command-llm/openai-sse.js +8 -0
  150. package/dist/safe-bash-command-llm/openai.d.ts +14 -0
  151. package/dist/safe-bash-command-llm/openai.js +12 -0
  152. package/dist/safe-bash-command-llm/providers/elevenlabs.d.ts +1 -0
  153. package/dist/safe-bash-command-llm/providers/elevenlabs.js +11 -0
  154. package/dist/safe-bash-command-llm/providers/index.d.ts +3 -0
  155. package/dist/safe-bash-command-llm/providers/index.js +24 -0
  156. package/dist/safe-bash-command-llm/providers/openai.d.ts +1 -0
  157. package/dist/safe-bash-command-llm/providers/openai.js +13 -0
  158. package/dist/safe-bash-command-llm/providers/shared.d.ts +23 -0
  159. package/dist/safe-bash-command-llm/providers/shared.js +13 -0
  160. package/dist/safe-bash-command-llm/schemas.d.ts +2 -0
  161. package/dist/safe-bash-command-llm/service.d.ts +42 -0
  162. package/dist/safe-bash-command-llm/service.js +9 -0
  163. package/dist/safe-bash-command-llm/templates.d.ts +27 -0
  164. package/dist/safe-bash-command-llm/types.d.ts +87 -0
  165. package/dist/safe-bash-command-llm/types.js +6 -0
  166. package/dist/safe-bash-command-mmdc/command.d.ts +4 -0
  167. package/dist/safe-bash-command-mmdc/index.d.ts +1 -1
  168. package/dist/safe-bash-command-mmdc/index.js +7084 -6687
  169. package/dist/safe-bash-command-mmdc/layout.d.ts +1 -0
  170. package/dist/safe-bash-command-mmdc/parser.d.ts +1 -0
  171. package/dist/safe-bash-command-mmdc/png.d.ts +3 -0
  172. package/dist/safe-bash-command-mmdc/raster.d.ts +1 -0
  173. package/dist/safe-bash-command-pandoc/command.js +3 -3
  174. package/dist/safe-bash-command-pandoc/index.js +3 -3
  175. package/dist/safe-bash-command-pdfimages/index.js +147 -80
  176. package/dist/safe-bash-command-pdfinfo/index.js +147 -80
  177. package/dist/safe-bash-command-pdftk/index.js +147 -80
  178. package/dist/safe-bash-command-pdftoppm/index.js +147 -80
  179. package/dist/safe-bash-command-pdftotext/index.js +147 -80
  180. package/dist/safe-bash-command-qpdf/index.js +174 -101
  181. package/dist/safe-bash-command-sips/index.js +2 -2
  182. package/dist/safe-bash-command-soffice/index.js +1 -1
  183. package/dist/safe-bash-command-ssconvert/index.js +147 -80
  184. package/dist/safe-bash-command-wkhtmltopdf/index.js +147 -80
  185. package/dist/safe-bash-contracts/default-executor.d.ts +5 -0
  186. package/dist/safe-bash-contracts/default-executor.js +37 -0
  187. package/dist/safe-bash-contracts/http.d.ts +41 -0
  188. package/dist/safe-bash-contracts/http.js +6 -0
  189. package/dist/safe-bash-io-engine/commands/search/requirements.js +3 -3
  190. package/dist/safe-bash-io-engine/commands/text-programs/shared.js +3 -3
  191. package/dist/safe-bash-io-engine/gnu-information.d.ts +1 -1
  192. package/dist/safe-bash-io-engine/gnu-information.js +1 -1
  193. package/dist/safe-bash-io-engine/internal.js +2 -2
  194. package/dist/safe-bash-query-engine/index.js +3 -3
  195. package/dist/safe-bash-query-engine/interpreter.js +2 -2
  196. package/dist/safe-bash-query-engine/query-core.js +3 -3
  197. package/package.json +2 -2
  198. package/dist/safe-bash/chunks/chunk-2G2T5MEM.js +0 -14
  199. package/dist/safe-bash/chunks/chunk-2MUJ7RLZ.js +0 -409
  200. package/dist/safe-bash/chunks/chunk-GJWUEOT6.js +0 -14
  201. package/dist/safe-bash/chunks/chunk-H7MMJS26.js +0 -37
  202. package/dist/safe-bash/chunks/chunk-LAPF2XE6.js +0 -14
  203. package/dist/safe-bash/chunks/chunk-S2LSZFZ6.js +0 -758
  204. package/dist/safe-bash/chunks/chunk-T3VDYWKZ.js +0 -21
  205. package/dist/safe-bash/chunks/chunk-VUVKC6HV.js +0 -81
  206. package/dist/safe-bash/chunks/chunk-VYW4Q6KF.js +0 -12
  207. package/dist/safe-bash/command-chunks/{chunk-BJ6DGYJA.js → chunk-KNI4GRXF.js} +3 -3
@@ -27101,6 +27101,11 @@ function tokenizeCos(bytes, start = 0, end = bytes.length) {
27101
27101
  }
27102
27102
  return tokens;
27103
27103
  }
27104
+ function drainWork(work) {
27105
+ let step = work.next();
27106
+ while (!step.done) step = work.next();
27107
+ return step.value;
27108
+ }
27104
27109
  function bytesToString3(bytes) {
27105
27110
  if (typeof bytes !== "object" || bytes?.length === void 0) {
27106
27111
  throw new Error("Invalid argument for bytesToString");
@@ -27696,7 +27701,9 @@ function concatByteArrays(chunks) {
27696
27701
  }
27697
27702
  return out;
27698
27703
  }
27699
- function serializeCosDocument(options) {
27704
+ function* serializeCosDocumentSteps(options) {
27705
+ yield;
27706
+ let work = 0;
27700
27707
  const maxOutputBytes = options.maxOutputBytes ?? Infinity;
27701
27708
  const maxObjects = options.maxObjects ?? Infinity;
27702
27709
  const sorted = [...options.objects].sort((a, b) => a.objectNumber - b.objectNumber);
@@ -27719,6 +27726,7 @@ function serializeCosDocument(options) {
27719
27726
  const packable = [];
27720
27727
  const direct = [];
27721
27728
  for (const obj of sorted) {
27729
+ if (++work % 16 === 0) yield;
27722
27730
  const isLinearized = obj.value.kind === "dict" && dictGet(obj.value, "Linearized") !== void 0;
27723
27731
  if (obj.value.kind !== "stream" && obj.generationNumber === 0 && !isLinearized) {
27724
27732
  packable.push(obj);
@@ -27733,6 +27741,7 @@ function serializeCosDocument(options) {
27733
27741
  const headerPairs = [];
27734
27742
  let relOffset = 0;
27735
27743
  for (const pObj of packable) {
27744
+ if (++work % 16 === 0) yield;
27736
27745
  headerPairs.push(`${pObj.objectNumber} ${relOffset}`);
27737
27746
  const bBytes = serializeCosNodeBytes(pObj.value);
27738
27747
  const nl = textEncoder2.encode("\n");
@@ -27758,6 +27767,7 @@ function serializeCosDocument(options) {
27758
27767
  ];
27759
27768
  const directOffsets = /* @__PURE__ */ new Map();
27760
27769
  for (const dObj of allDirect) {
27770
+ if (++work % 16 === 0) yield;
27761
27771
  directOffsets.set(dObj.objectNumber, { offset, generation: dObj.generationNumber });
27762
27772
  const prefix = textEncoder2.encode(`${dObj.objectNumber} ${dObj.generationNumber} obj
27763
27773
  `);
@@ -27768,6 +27778,7 @@ function serializeCosDocument(options) {
27768
27778
  }
27769
27779
  const compressedMap = /* @__PURE__ */ new Map();
27770
27780
  for (let idx = 0; idx < packable.length; idx++) {
27781
+ if (++work % 16 === 0) yield;
27771
27782
  compressedMap.set(packable[idx].objectNumber, idx);
27772
27783
  }
27773
27784
  const xrefOffset2 = offset;
@@ -27785,6 +27796,7 @@ function serializeCosDocument(options) {
27785
27796
  };
27786
27797
  writeEntry7(0, 0, 0, 65535);
27787
27798
  for (let i = 1; i < size2; i++) {
27799
+ if (++work % 16 === 0) yield;
27788
27800
  if (i === xrefStmNum) {
27789
27801
  writeEntry7(i, 1, xrefOffset2, 0);
27790
27802
  } else if (compressedMap.has(i)) {
@@ -27865,6 +27877,7 @@ ${xrefOffset2}
27865
27877
  let pageCount = 0;
27866
27878
  let firstPageObjNum = options.rootRef.objectNumber;
27867
27879
  for (const o of sorted) {
27880
+ if (++work % 16 === 0) yield;
27868
27881
  if (o.value.kind === "dict") {
27869
27882
  const t = dictGet(o.value, "Type");
27870
27883
  if (t?.kind === "name" && t.decoded === "Page") {
@@ -27912,6 +27925,7 @@ ${xrefOffset2}
27912
27925
  }
27913
27926
  const objectOffsets = /* @__PURE__ */ new Map();
27914
27927
  for (const obj of sorted) {
27928
+ if (++work % 16 === 0) yield;
27915
27929
  objectOffsets.set(obj.objectNumber, { offset, generation: obj.generationNumber });
27916
27930
  let value = obj.value;
27917
27931
  if (options.normalizeContent && value.kind === "stream" && value.decodedBytes) {
@@ -27943,6 +27957,7 @@ ${xrefOffset2}
27943
27957
  0000000000 65535 f
27944
27958
  `;
27945
27959
  for (let i = 1; i < size; i++) {
27960
+ if (++work % 16 === 0) yield;
27946
27961
  const entry = objectOffsets.get(i);
27947
27962
  if (entry) {
27948
27963
  xrefText += `${String(entry.offset).padStart(10, "0")} ${String(entry.generation).padStart(5, "0")} n
@@ -27989,6 +28004,7 @@ ${xrefOffset}
27989
28004
  let endFirstPage = xrefOffset;
27990
28005
  const sortedOffsets = [...objectOffsets.entries()].sort((a, b) => a[1].offset - b[1].offset);
27991
28006
  for (let i = 0; i < sortedOffsets.length; i++) {
28007
+ if (++work % 16 === 0) yield;
27992
28008
  const [objNum, info3] = sortedOffsets[i];
27993
28009
  const nextOff = sortedOffsets[i + 1]?.[1].offset ?? xrefOffset;
27994
28010
  if (objNum === hintObjAfter.objectNumber) {
@@ -28022,6 +28038,9 @@ ${xrefOffset}
28022
28038
  }
28023
28039
  return fullBytes;
28024
28040
  }
28041
+ function serializeCosDocument(options) {
28042
+ return drainWork(serializeCosDocumentSteps(options));
28043
+ }
28025
28044
  function appendIncrementalRevision(originalBytes, doc, updatedObjects) {
28026
28045
  const chunks = [originalBytes, textEncoder2.encode("\n")];
28027
28046
  let offset = originalBytes.length + 1;
@@ -28295,48 +28314,30 @@ function encryptPdfBuffer(state, objectNumber, generationNumber, plaintext) {
28295
28314
  const objKey = md5Bytes([state.fileKey, suffix]).subarray(0, Math.min(16, state.fileKey.length + 5));
28296
28315
  return rc4Transform(objKey, plaintext);
28297
28316
  }
28298
- function transformNodeStringsAndStreams(node, transform, transformStream) {
28317
+ function* transformNodeStringsAndStreamsSteps(node, transform, transformStream) {
28318
+ yield;
28299
28319
  switch (node.kind) {
28300
28320
  case "string":
28301
- return {
28302
- kind: "string",
28303
- format: "hex",
28304
- bytes: transform(node.bytes)
28305
- };
28306
- case "array":
28307
- return {
28308
- kind: "array",
28309
- items: node.items.map((item) => transformNodeStringsAndStreams(item, transform, transformStream))
28310
- };
28321
+ return { kind: "string", format: "hex", bytes: transform(node.bytes) };
28322
+ case "array": {
28323
+ const items = [];
28324
+ for (const item of node.items) items.push(yield* transformNodeStringsAndStreamsSteps(item, transform, transformStream));
28325
+ return { kind: "array", items };
28326
+ }
28311
28327
  case "dict": {
28312
- const type = dictGet(node, "Type");
28313
- const fieldType = dictGet(node, "FT");
28314
- const byteRange = dictGet(node, "ByteRange");
28328
+ const type = dictGet(node, "Type"), fieldType = dictGet(node, "FT"), byteRange = dictGet(node, "ByteRange");
28315
28329
  const signature = type?.kind === "name" && type.decoded === "Sig" || fieldType?.kind === "name" && fieldType.decoded === "Sig" || byteRange?.kind === "array" && dictGet(node, "Filter")?.kind === "name";
28316
- return {
28317
- kind: "dict",
28318
- entries: node.entries.map((e) => ({
28319
- key: e.key,
28320
- value: signature && e.key.decoded === "Contents" ? e.value : transformNodeStringsAndStreams(e.value, transform, transformStream)
28321
- }))
28322
- };
28330
+ const entries = [];
28331
+ for (const e of node.entries) entries.push({ key: e.key, value: signature && e.key.decoded === "Contents" ? e.value : yield* transformNodeStringsAndStreamsSteps(e.value, transform, transformStream) });
28332
+ return { kind: "dict", entries };
28323
28333
  }
28324
28334
  case "stream": {
28325
28335
  const type = dictGet(node.dict, "Type");
28326
28336
  if (type?.kind === "name" && type.decoded === "XRef") return node;
28327
28337
  const stream = transformStream ? transformStream(node) : { ...node, rawBytes: transform(node.rawBytes) };
28328
- const updatedDict = {
28329
- kind: "dict",
28330
- entries: stream.dict.entries.map((e) => ({
28331
- key: e.key,
28332
- value: e.key.decoded === "Length" ? cosNumber(stream.rawBytes.length) : transformNodeStringsAndStreams(e.value, transform, transformStream)
28333
- }))
28334
- };
28335
- return {
28336
- kind: "stream",
28337
- dict: updatedDict,
28338
- rawBytes: stream.rawBytes
28339
- };
28338
+ const entries = [];
28339
+ for (const e of stream.dict.entries) entries.push({ key: e.key, value: e.key.decoded === "Length" ? cosNumber(stream.rawBytes.length) : yield* transformNodeStringsAndStreamsSteps(e.value, transform, transformStream) });
28340
+ return { kind: "stream", dict: { kind: "dict", entries }, rawBytes: stream.rawBytes };
28340
28341
  }
28341
28342
  default:
28342
28343
  return node;
@@ -28405,7 +28406,8 @@ function createR6Encryption(userPassword, ownerPassword, pMask) {
28405
28406
  StrF: cosName("StdCF")
28406
28407
  }) };
28407
28408
  }
28408
- function encryptCosDocument(doc, options = {}) {
28409
+ function* encryptCosDocumentSteps(doc, options = {}) {
28410
+ yield;
28409
28411
  const userPassword = options.userPassword ?? "";
28410
28412
  const ownerPassword = options.ownerPassword ?? userPassword;
28411
28413
  const revision = options.revision ?? 6;
@@ -28427,14 +28429,15 @@ function encryptCosDocument(doc, options = {}) {
28427
28429
  const encryptObjNum = maxObjNum + 1;
28428
28430
  const encryptedObjects = [];
28429
28431
  for (const obj of doc.objects.values()) {
28430
- const transformed = transformNodeStringsAndStreams(
28432
+ yield;
28433
+ const transformed = yield* transformNodeStringsAndStreamsSteps(
28431
28434
  obj.value,
28432
28435
  (plain) => encryptPdfBuffer(state, obj.objectNumber, obj.generationNumber, plain)
28433
28436
  );
28434
28437
  encryptedObjects.push({ objectNumber: obj.objectNumber, generationNumber: obj.generationNumber, value: transformed });
28435
28438
  }
28436
28439
  encryptedObjects.push({ objectNumber: encryptObjNum, generationNumber: 0, value: encryptDict });
28437
- return serializeCosDocument({
28440
+ return yield* serializeCosDocumentSteps({
28438
28441
  objects: encryptedObjects,
28439
28442
  rootRef: doc.rootRef,
28440
28443
  infoRef: doc.infoRef,
@@ -28484,17 +28487,19 @@ function decryptStream(doc, stream, transform) {
28484
28487
  }
28485
28488
  return { kind: "stream", dict, rawBytes: bytes };
28486
28489
  }
28487
- function decryptCosDocument(doc, state) {
28490
+ function* decryptCosDocumentSteps(doc, state) {
28491
+ yield;
28488
28492
  const encryptObjNum = doc.encryptRef?.objectNumber;
28489
28493
  const handler = securityHandlers.get(state);
28490
28494
  for (const [num, obj] of doc.objects.entries()) {
28495
+ yield;
28491
28496
  if (num === encryptObjNum || handler?.plaintextObjects.has(num)) continue;
28492
28497
  if (obj.value.kind === "stream") {
28493
28498
  const type = doc.resolve(dictGet(obj.value.dict, "Type"));
28494
28499
  if (type?.kind === "name" && (type.decoded === "XRef" || type.decoded === "Metadata" && !state.encryptMetadata)) continue;
28495
28500
  }
28496
28501
  const transform = handler?.factory.createCipherTransform(obj.objectNumber, obj.generationNumber);
28497
- const decrypted = transformNodeStringsAndStreams(
28502
+ const decrypted = yield* transformNodeStringsAndStreamsSteps(
28498
28503
  obj.value,
28499
28504
  (cipher) => decryptPdfBuffer(state, obj.objectNumber, obj.generationNumber, cipher),
28500
28505
  transform ? (stream) => decryptStream(doc, stream, transform) : void 0
@@ -28608,9 +28613,12 @@ var ParsedCosDocument = class {
28608
28613
  return void 0;
28609
28614
  }
28610
28615
  };
28611
- function parseNodeFromLexer(lexer, bytes, maxDepth, repair = false) {
28616
+ function* parseNodeFromLexerSteps(lexer, bytes, maxDepth, repair = false) {
28617
+ yield;
28618
+ let work = 0;
28612
28619
  const stack = [];
28613
28620
  while (true) {
28621
+ if (++work % 16 === 0) yield;
28614
28622
  const tok = lexer.nextToken();
28615
28623
  const parent = stack.at(-1);
28616
28624
  if (!tok) {
@@ -28806,7 +28814,8 @@ function parseHeaderVersion(bytes) {
28806
28814
  }
28807
28815
  return head.slice(idx + 5, idx + 8);
28808
28816
  }
28809
- function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
28817
+ function* parseObjectAtOffsetSteps(bytes, offset, maxRecursionDepth, repair = false) {
28818
+ yield;
28810
28819
  const lexer = new CosByteLexer(bytes, offset);
28811
28820
  const objNumTok = lexer.nextToken();
28812
28821
  const genNumTok = lexer.nextToken();
@@ -28814,7 +28823,7 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
28814
28823
  if (objNumTok?.kind !== "number" || genNumTok?.kind !== "number" || objKwTok?.kind !== "keyword" || objKwTok.value !== "obj") {
28815
28824
  throw new PdfError("E_PARSE", `Malformed indirect object header at byte offset ${offset}`);
28816
28825
  }
28817
- const value = parseNodeFromLexer(lexer, bytes, maxRecursionDepth, repair);
28826
+ const value = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth, repair);
28818
28827
  if (!value) {
28819
28828
  throw new PdfError("E_PARSE", `Empty indirect object ${objNumTok.value} at offset ${offset}`);
28820
28829
  }
@@ -28825,7 +28834,9 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
28825
28834
  span: { start: objNumTok.span.start, end: lexer.offset }
28826
28835
  };
28827
28836
  }
28828
- function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects) {
28837
+ function* parseXrefRevisionAtSteps(bytes, xrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects) {
28838
+ yield;
28839
+ let work = 0;
28829
28840
  if (xrefOffset < 0 || xrefOffset >= bytes.length) {
28830
28841
  throw new PdfError("E_PARSE", `Invalid xref offset: ${xrefOffset}`);
28831
28842
  }
@@ -28837,6 +28848,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
28837
28848
  if (firstTok.kind === "keyword" && firstTok.value === "xref") {
28838
28849
  const entries2 = /* @__PURE__ */ new Map();
28839
28850
  while (true) {
28851
+ if (++work % 16 === 0) yield;
28840
28852
  const saved = lexer.offset;
28841
28853
  const tok = lexer.nextToken();
28842
28854
  if (!tok) {
@@ -28860,6 +28872,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
28860
28872
  }
28861
28873
  if (count > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
28862
28874
  for (let i = 0; i < count; i++) {
28875
+ if (++work % 16 === 0) yield;
28863
28876
  const offTok = lexer.nextToken();
28864
28877
  const genTok = lexer.nextToken();
28865
28878
  const flagTok = lexer.nextToken();
@@ -28885,7 +28898,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
28885
28898
  if (entries2.size > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
28886
28899
  }
28887
28900
  }
28888
- const trailerNode = parseNodeFromLexer(lexer, bytes, maxRecursionDepth);
28901
+ const trailerNode = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth);
28889
28902
  if (!trailerNode || trailerNode.kind !== "dict") {
28890
28903
  throw new PdfError("E_PARSE", "Missing trailer dictionary after xref table");
28891
28904
  }
@@ -28897,7 +28910,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
28897
28910
  previousXrefOffset: prevNode2?.kind === "number" ? prevNode2.value : void 0
28898
28911
  };
28899
28912
  }
28900
- const xrefObj = parseObjectAtOffset(bytes, xrefOffset, maxRecursionDepth);
28913
+ const xrefObj = yield* parseObjectAtOffsetSteps(bytes, xrefOffset, maxRecursionDepth);
28901
28914
  if (xrefObj.value.kind !== "stream") {
28902
28915
  throw new PdfError("E_PARSE", `Expected xref table or XRef stream at offset ${xrefOffset}`);
28903
28916
  }
@@ -28918,6 +28931,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
28918
28931
  if (indexArray) {
28919
28932
  if (indexArray.kind !== "array" || indexArray.items.length % 2 !== 0) throw new PdfError("E_PARSE", "Invalid XRef range fields");
28920
28933
  for (let i = 0; i < indexArray.items.length; i += 2) {
28934
+ if (++work % 16 === 0) yield;
28921
28935
  const first = indexArray.items[i];
28922
28936
  const count = indexArray.items[i + 1];
28923
28937
  if (first?.kind !== "number" || count?.kind !== "number" || !Number.isSafeInteger(first.value) || first.value < 0 || !Number.isSafeInteger(count.value) || count.value < 0 || !Number.isSafeInteger(first.value + count.value)) {
@@ -28940,9 +28954,11 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
28940
28954
  return v;
28941
28955
  };
28942
28956
  for (const [startObj, count] of subsections) {
28957
+ if (++work % 16 === 0) yield;
28943
28958
  if (count > (decoded.length - pos) / stride) throw new PdfError("E_PARSE", "Truncated XRef stream");
28944
28959
  if (count > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
28945
28960
  for (let i = 0; i < count; i++) {
28961
+ if (++work % 16 === 0) yield;
28946
28962
  const objNum = startObj + i;
28947
28963
  const field0 = w0 > 0 ? readInt(w0) : 1;
28948
28964
  const field1 = readInt(w1);
@@ -28988,12 +29004,16 @@ function isAsciiWhitespace(ch3) {
28988
29004
  function isAsciiDigit(ch3) {
28989
29005
  return ch3 >= 48 && ch3 <= 57;
28990
29006
  }
28991
- function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
29007
+ function* repairScanCosDocumentSteps(bytes, maxObjects, maxRecursionDepth) {
29008
+ yield;
29009
+ let work = 0;
28992
29010
  const objects = /* @__PURE__ */ new Map();
28993
29011
  const trailers = [];
28994
29012
  let pos = 0;
28995
29013
  while (pos < bytes.length) {
29014
+ if (++work % 16 === 0) yield;
28996
29015
  while (pos < bytes.length && !isAsciiDigit(bytes[pos])) {
29016
+ if (++work % 16 === 0) yield;
28997
29017
  if (bytes[pos] === 37) {
28998
29018
  while (pos < bytes.length && bytes[pos] !== 10 && bytes[pos] !== 13) pos++;
28999
29019
  continue;
@@ -29003,7 +29023,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
29003
29023
  try {
29004
29024
  const token = lexer.nextToken();
29005
29025
  if (token?.kind === "keyword" && token.value === "trailer") {
29006
- const trailer = parseNodeFromLexer(lexer, bytes, maxRecursionDepth, true);
29026
+ const trailer = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth, true);
29007
29027
  if (trailer?.kind === "dict") trailers.push(trailer);
29008
29028
  pos = lexer.offset;
29009
29029
  continue;
@@ -29036,7 +29056,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
29036
29056
  bytes[pos + 3] === 40)) {
29037
29057
  pos += 3;
29038
29058
  try {
29039
- const parsed = parseObjectAtOffset(bytes, headerStart, maxRecursionDepth, true);
29059
+ const parsed = yield* parseObjectAtOffsetSteps(bytes, headerStart, maxRecursionDepth, true);
29040
29060
  objects.set(parsed.objectNumber, parsed);
29041
29061
  if (parsed.value.kind === "stream") {
29042
29062
  const type = dictGet(parsed.value.dict, "Type");
@@ -29053,13 +29073,17 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
29053
29073
  }
29054
29074
  return { objects, trailers };
29055
29075
  }
29056
- function unpackRecoveredObjects(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth) {
29076
+ function* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth) {
29077
+ yield;
29078
+ let work = 0;
29057
29079
  for (const obj of [...objects.values()]) {
29080
+ if (++work % 16 === 0) yield;
29058
29081
  if (obj.value.kind === "stream") {
29059
29082
  const t = dictGet(obj.value.dict, "Type");
29060
29083
  if (t?.kind === "name" && t.decoded === "ObjStm") {
29061
29084
  try {
29062
- for (const [unpackedNum, unpackedVal] of unpackObjectStream(obj.value, maxDecompressedBytes, maxRecursionDepth, true).entries()) {
29085
+ for (const [unpackedNum, unpackedVal] of (yield* unpackObjectStreamSteps(obj.value, maxDecompressedBytes, maxRecursionDepth, true)).entries()) {
29086
+ if (++work % 16 === 0) yield;
29063
29087
  if (!objects.has(unpackedNum)) {
29064
29088
  objects.set(unpackedNum, {
29065
29089
  objectNumber: unpackedNum,
@@ -29095,7 +29119,9 @@ function recoveredReferences(objects) {
29095
29119
  }
29096
29120
  return { ...rootRef ? { rootRef } : {}, ...infoRef ? { infoRef } : {} };
29097
29121
  }
29098
- function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth, repair = false) {
29122
+ function* unpackObjectStreamSteps(streamObj, maxDecompressedBytes, maxRecursionDepth, repair = false) {
29123
+ yield;
29124
+ let work = 0;
29099
29125
  const nNode = dictGet(streamObj.dict, "N");
29100
29126
  const firstNode = dictGet(streamObj.dict, "First");
29101
29127
  if (nNode?.kind !== "number" || firstNode?.kind !== "number") {
@@ -29105,6 +29131,7 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
29105
29131
  const headerLexer = new CosByteLexer(decoded, 0);
29106
29132
  const pairs = [];
29107
29133
  for (let i = 0; i < nNode.value; i++) {
29134
+ if (++work % 16 === 0) yield;
29108
29135
  const numTok = headerLexer.nextToken();
29109
29136
  const offTok = headerLexer.nextToken();
29110
29137
  if (numTok?.kind === "number" && offTok?.kind === "number") {
@@ -29113,9 +29140,10 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
29113
29140
  }
29114
29141
  const result = /* @__PURE__ */ new Map();
29115
29142
  for (const pair of pairs) {
29143
+ if (++work % 16 === 0) yield;
29116
29144
  try {
29117
29145
  const valLexer = new CosByteLexer(decoded, firstNode.value + pair.relativeOffset);
29118
- const node = parseNodeFromLexer(valLexer, decoded, maxRecursionDepth, repair);
29146
+ const node = yield* parseNodeFromLexerSteps(valLexer, decoded, maxRecursionDepth, repair);
29119
29147
  if (node) {
29120
29148
  result.set(pair.objectNumber, node);
29121
29149
  }
@@ -29125,7 +29153,9 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
29125
29153
  }
29126
29154
  return result;
29127
29155
  }
29128
- function parseCosDocument(bytes, options = {}) {
29156
+ function* parseCosDocumentSteps(bytes, options = {}) {
29157
+ yield;
29158
+ let work = 0;
29129
29159
  const version = parseHeaderVersion(bytes);
29130
29160
  const recovery = options.recovery ?? "strict";
29131
29161
  const maxObjects = options.maxObjects ?? Infinity;
@@ -29160,10 +29190,12 @@ function parseCosDocument(bytes, options = {}) {
29160
29190
  let currentXrefOffset = offsetTok.value;
29161
29191
  const visitedOffsets = /* @__PURE__ */ new Set();
29162
29192
  while (currentXrefOffset !== void 0 && !visitedOffsets.has(currentXrefOffset)) {
29193
+ if (++work % 16 === 0) yield;
29163
29194
  visitedOffsets.add(currentXrefOffset);
29164
- const rev = parseXrefRevisionAt(bytes, currentXrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects);
29195
+ const rev = yield* parseXrefRevisionAtSteps(bytes, currentXrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects);
29165
29196
  revisions.push(rev);
29166
29197
  for (const [num, entry] of rev.entries.entries()) {
29198
+ if (++work % 16 === 0) yield;
29167
29199
  if (!mergedXref.has(num)) {
29168
29200
  mergedXref.set(num, entry);
29169
29201
  if (mergedXref.size > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
@@ -29196,8 +29228,9 @@ function parseCosDocument(bytes, options = {}) {
29196
29228
  if (!useRepair && rootRef) {
29197
29229
  try {
29198
29230
  for (const [objNum, entry] of mergedXref.entries()) {
29231
+ if (++work % 16 === 0) yield;
29199
29232
  if (entry.type !== "uncompressed") continue;
29200
- const parsed = parseObjectAtOffset(bytes, entry.offset ?? 0, maxRecursionDepth, recovery === "repair");
29233
+ const parsed = yield* parseObjectAtOffsetSteps(bytes, entry.offset ?? 0, maxRecursionDepth, recovery === "repair");
29201
29234
  if (parsed.objectNumber !== objNum || parsed.generationNumber !== (entry.generationNumber ?? 0)) {
29202
29235
  throw new PdfError("E_PARSE", `Bad uncompressed XRef entry for object ${objNum}`);
29203
29236
  }
@@ -29215,7 +29248,7 @@ function parseCosDocument(bytes, options = {}) {
29215
29248
  throw new PdfError("E_PARSE", "PDF trailer missing /Root reference");
29216
29249
  }
29217
29250
  useRepair = true;
29218
- const scanned = repairScanCosDocument(bytes, maxObjects, maxRecursionDepth);
29251
+ const scanned = yield* repairScanCosDocumentSteps(bytes, maxObjects, maxRecursionDepth);
29219
29252
  objects = scanned.objects;
29220
29253
  revisions.length = 0;
29221
29254
  mergedXref.clear();
@@ -29250,7 +29283,7 @@ function parseCosDocument(bytes, options = {}) {
29250
29283
  encryptNode = encrypt?.kind === "ref" || encrypt?.kind === "dict" ? encrypt : void 0;
29251
29284
  encryptRef = encrypt?.kind === "ref" ? encrypt : void 0;
29252
29285
  idArray = id?.kind === "array" ? id : void 0;
29253
- if (!rootRef && !encryptNode) unpackRecoveredObjects(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
29286
+ if (!rootRef && !encryptNode) yield* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
29254
29287
  const fallback = recoveredReferences(objects);
29255
29288
  rootRef ??= fallback.rootRef;
29256
29289
  infoRef ??= fallback.infoRef;
@@ -29285,20 +29318,21 @@ function parseCosDocument(bytes, options = {}) {
29285
29318
  maxRecursionDepth
29286
29319
  });
29287
29320
  doc.encryption = encState;
29288
- decryptCosDocument(doc, encState);
29321
+ yield* decryptCosDocumentSteps(doc, encState);
29289
29322
  }
29290
29323
  if (useRepair) {
29291
- unpackRecoveredObjects(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
29324
+ yield* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
29292
29325
  doc.infoRef ??= recoveredReferences(objects).infoRef;
29293
29326
  }
29294
29327
  const objStmCache = /* @__PURE__ */ new Map();
29295
29328
  for (const [objNum, entry] of mergedXref.entries()) {
29329
+ if (++work % 16 === 0) yield;
29296
29330
  if (entry.type === "compressed" && entry.objectStreamNumber !== void 0) {
29297
29331
  let unpacked = objStmCache.get(entry.objectStreamNumber);
29298
29332
  if (!unpacked) {
29299
29333
  const stmObj = objects.get(entry.objectStreamNumber)?.value;
29300
29334
  if (stmObj?.kind === "stream") {
29301
- unpacked = unpackObjectStream(stmObj, maxDecompressedBytes, maxRecursionDepth, recovery === "repair");
29335
+ unpacked = yield* unpackObjectStreamSteps(stmObj, maxDecompressedBytes, maxRecursionDepth, recovery === "repair");
29302
29336
  objStmCache.set(entry.objectStreamNumber, unpacked);
29303
29337
  }
29304
29338
  }
@@ -29315,6 +29349,9 @@ function parseCosDocument(bytes, options = {}) {
29315
29349
  }
29316
29350
  return doc;
29317
29351
  }
29352
+ function parseCosDocument(bytes, options = {}) {
29353
+ return drainWork(parseCosDocumentSteps(bytes, options));
29354
+ }
29318
29355
  var WIN_ANSI_HIGH_BYTES = {
29319
29356
  128: 8364,
29320
29357
  130: 8218,
@@ -40345,7 +40382,8 @@ function resolveInheritedFieldEntry(doc, dict, key) {
40345
40382
  }
40346
40383
  return void 0;
40347
40384
  }
40348
- function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen) {
40385
+ function* collectFieldDictsSteps(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen, yieldState = { work: 0 }) {
40386
+ if (++yieldState.work % 256 === 0) yield;
40349
40387
  const dict = doc.resolveDict(node);
40350
40388
  if (!dict) return out;
40351
40389
  const tNode = doc.resolve(dictGet(dict, "T"));
@@ -40378,7 +40416,8 @@ function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", pare
40378
40416
  return out;
40379
40417
  }
40380
40418
  for (const kid of kidsArr.items) {
40381
- collectFieldDicts(doc, kid, fullName, out, currentFt, currentFf, currentQ, currentMaxLen);
40419
+ if (++yieldState.work % 16 === 0) yield;
40420
+ yield* collectFieldDictsSteps(doc, kid, fullName, out, currentFt, currentFf, currentQ, currentMaxLen, yieldState);
40382
40421
  }
40383
40422
  } else if (fullName) {
40384
40423
  out.push({
@@ -40807,7 +40846,9 @@ function setDocumentFormField(doc, fieldName, value) {
40807
40846
  const fieldRef = doc.allocateObject(newFieldDict);
40808
40847
  fieldsArr.items.push(fieldRef);
40809
40848
  }
40810
- function generateDocumentFormAppearances(doc) {
40849
+ function* generateDocumentFormAppearancesSteps(doc) {
40850
+ yield;
40851
+ let work = 0;
40811
40852
  const catalog = doc.resolveDict(doc.rootRef);
40812
40853
  if (!catalog) return;
40813
40854
  const acroForm = doc.resolveDict(dictGet(catalog, "AcroForm"));
@@ -40818,9 +40859,11 @@ function generateDocumentFormAppearances(doc) {
40818
40859
  if (fieldsArr) {
40819
40860
  const all = [];
40820
40861
  for (const item of fieldsArr.items) {
40821
- collectFieldDicts(doc, item, "", all);
40862
+ if (++work % 16 === 0) yield;
40863
+ yield* collectFieldDictsSteps(doc, item, "", all);
40822
40864
  }
40823
40865
  for (const entry of all) {
40866
+ if (++work % 16 === 0) yield;
40824
40867
  const ftNode = doc.resolve(dictGet(entry.dict, "FT"));
40825
40868
  const ft = entry.inheritedFt || (ftNode?.kind === "name" ? ftNode.decoded : "");
40826
40869
  const vNode = doc.resolve(dictGet(entry.dict, "V"));
@@ -40870,6 +40913,7 @@ function generateDocumentFormAppearances(doc) {
40870
40913
  const optArr = doc.resolveArray(dictGet(entry.dict, "Opt"));
40871
40914
  if (optArr) {
40872
40915
  for (const optItem of optArr.items) {
40916
+ if (++work % 16 === 0) yield;
40873
40917
  const resolvedOpt = doc.resolve(optItem);
40874
40918
  if (resolvedOpt?.kind === "array" && resolvedOpt.items.length >= 2) {
40875
40919
  const expNode = doc.resolve(resolvedOpt.items[0]);
@@ -40898,6 +40942,7 @@ function generateDocumentFormAppearances(doc) {
40898
40942
  const kidsArr = doc.resolveArray(dictGet(entry.dict, "Kids"));
40899
40943
  if (kidsArr) {
40900
40944
  for (const kid of kidsArr.items) {
40945
+ if (++work % 16 === 0) yield;
40901
40946
  const kidDict = doc.resolveDict(kid);
40902
40947
  if (kidDict && !dictGet(kidDict, "T")) {
40903
40948
  synthesizeTextAppearanceStream(
@@ -40929,6 +40974,9 @@ function escapePdfLiteralString(str) {
40929
40974
  }
40930
40975
  return out;
40931
40976
  }
40977
+ function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen) {
40978
+ drainWork(collectFieldDictsSteps(doc, node, prefix, out, parentFt, parentFf, parentQ, parentMaxLen));
40979
+ }
40932
40980
  var PdfPage = class {
40933
40981
  cosDoc;
40934
40982
  pageRef;
@@ -43382,14 +43430,18 @@ var PdfDocument = class _PdfDocument {
43382
43430
  });
43383
43431
  return new _PdfDocument(parseCosDocument(rawBytes));
43384
43432
  }
43385
- static load(bytes, options) {
43433
+ static *loadSteps(bytes, options) {
43434
+ yield;
43386
43435
  return new _PdfDocument(
43387
- parseCosDocument(bytes, {
43436
+ yield* parseCosDocumentSteps(bytes, {
43388
43437
  ...options,
43389
43438
  recovery: options?.recovery ?? "repair"
43390
43439
  })
43391
43440
  );
43392
43441
  }
43442
+ static load(bytes, options) {
43443
+ return drainWork(_PdfDocument.loadSteps(bytes, options));
43444
+ }
43393
43445
  rebuildPagesList() {
43394
43446
  const catalog = this.cos.resolveDict(this.cos.rootRef);
43395
43447
  const pagesNode = catalog ? dictGet(catalog, "Pages") : void 0;
@@ -43471,20 +43523,30 @@ var PdfDocument = class _PdfDocument {
43471
43523
  this.pages.splice(index, 1);
43472
43524
  this.syncPageTree();
43473
43525
  }
43474
- copyPagesFrom(sourceDoc, indices) {
43526
+ *copyPagesFromSteps(sourceDoc, indices) {
43527
+ function* cloneItems(items) {
43528
+ const result = [];
43529
+ for (const item of items) result.push(yield* cloneNode(item));
43530
+ return result;
43531
+ }
43532
+ yield;
43533
+ let work = 0;
43475
43534
  const memo = /* @__PURE__ */ new Map();
43476
43535
  const sourcePageObjNums = /* @__PURE__ */ new Set();
43477
43536
  for (let i = 0; i < sourceDoc.getPageCount(); i++) {
43537
+ if (++work % 16 === 0) yield;
43478
43538
  sourcePageObjNums.add(sourceDoc.getPage(i).ref.objectNumber);
43479
43539
  }
43480
43540
  const targetPageRefs = [];
43481
43541
  for (const idx of indices) {
43542
+ if (++work % 16 === 0) yield;
43482
43543
  const srcPage = sourceDoc.getPage(idx);
43483
43544
  const pageRef = this.cos.allocateObject({ kind: "null" });
43484
43545
  targetPageRefs.push(pageRef);
43485
43546
  memo.set(srcPage.ref.objectNumber, pageRef);
43486
43547
  }
43487
- const cloneNode = (node) => {
43548
+ const cloneNode = function* (node) {
43549
+ if (++work % 16 === 0) yield;
43488
43550
  if (node.kind === "ref") {
43489
43551
  const existing = memo.get(node.objectNumber);
43490
43552
  if (existing) return existing;
@@ -43495,12 +43557,12 @@ var PdfDocument = class _PdfDocument {
43495
43557
  if (!target) return cosRef(0);
43496
43558
  const placeholderRef = this.cos.allocateObject({ kind: "null" });
43497
43559
  memo.set(node.objectNumber, placeholderRef);
43498
- const clonedTarget = cloneNode(target);
43560
+ const clonedTarget = yield* cloneNode(target);
43499
43561
  this.cos.setObject(placeholderRef.objectNumber, clonedTarget, 0);
43500
43562
  return placeholderRef;
43501
43563
  }
43502
43564
  if (node.kind === "array") {
43503
- return cosArray(node.items.map(cloneNode));
43565
+ return cosArray(yield* cloneItems(node.items));
43504
43566
  }
43505
43567
  if (node.kind === "dict") {
43506
43568
  const typeEntry = dictGet(node, "Type");
@@ -43510,13 +43572,13 @@ var PdfDocument = class _PdfDocument {
43510
43572
  if (isPageTreeNode && entry.key.decoded === "Parent") continue;
43511
43573
  newEntries.push({
43512
43574
  key: { ...entry.key },
43513
- value: cloneNode(entry.value)
43575
+ value: yield* cloneNode(entry.value)
43514
43576
  });
43515
43577
  }
43516
43578
  return { kind: "dict", entries: newEntries };
43517
43579
  }
43518
43580
  if (node.kind === "stream") {
43519
- const clonedDict = cloneNode(node.dict);
43581
+ const clonedDict = yield* cloneNode(node.dict);
43520
43582
  return {
43521
43583
  kind: "stream",
43522
43584
  dict: clonedDict,
@@ -43525,11 +43587,12 @@ var PdfDocument = class _PdfDocument {
43525
43587
  };
43526
43588
  }
43527
43589
  return node;
43528
- };
43590
+ }.bind(this);
43529
43591
  const copiedPages = [];
43530
43592
  for (const [position, idx] of indices.entries()) {
43593
+ if (++work % 16 === 0) yield;
43531
43594
  const srcPage = sourceDoc.getPage(idx);
43532
- const clonedPageDict = cloneNode(srcPage.pageDict);
43595
+ const clonedPageDict = yield* cloneNode(srcPage.pageDict);
43533
43596
  const size = srcPage.getSize();
43534
43597
  if (!dictGet(clonedPageDict, "MediaBox")) {
43535
43598
  dictSet(
@@ -43539,13 +43602,14 @@ var PdfDocument = class _PdfDocument {
43539
43602
  );
43540
43603
  }
43541
43604
  if (!dictGet(clonedPageDict, "Resources")) {
43542
- dictSet(clonedPageDict, "Resources", cloneNode(srcPage.getResourcesDict()));
43605
+ dictSet(clonedPageDict, "Resources", yield* cloneNode(srcPage.getResourcesDict()));
43543
43606
  }
43544
43607
  if (!dictGet(clonedPageDict, "Rotate") && srcPage.getRotation() !== 0) {
43545
43608
  dictSet(clonedPageDict, "Rotate", cosNumber(srcPage.getRotation()));
43546
43609
  }
43547
43610
  const inheritedBoxKeys = ["CropBox", "BleedBox", "TrimBox", "ArtBox"];
43548
43611
  for (const boxKey of inheritedBoxKeys) {
43612
+ if (++work % 16 === 0) yield;
43549
43613
  if (!dictGet(clonedPageDict, boxKey)) {
43550
43614
  const boxVal = boxKey === "CropBox" ? srcPage.getCropBox() : boxKey === "BleedBox" ? srcPage.getBleedBox() : boxKey === "TrimBox" ? srcPage.getTrimBox() : srcPage.getArtBox();
43551
43615
  if (boxVal[0] !== 0 || boxVal[1] !== 0 || boxVal[2] !== size.width || boxVal[3] !== size.height) {
@@ -43587,8 +43651,9 @@ var PdfDocument = class _PdfDocument {
43587
43651
  };
43588
43652
  const clonedRootFieldRefs = [];
43589
43653
  for (const item of srcFieldsArr.items) {
43654
+ if (++work % 16 === 0) yield;
43590
43655
  if (!hasClonedDescendant(item)) continue;
43591
- const cloned = cloneNode(item);
43656
+ const cloned = yield* cloneNode(item);
43592
43657
  if (cloned.kind === "ref") {
43593
43658
  const clonedDict = this.cos.resolveDict(cloned);
43594
43659
  const kidsArr = clonedDict ? this.cos.resolveArray(dictGet(clonedDict, "Kids")) : void 0;
@@ -43622,6 +43687,7 @@ var PdfDocument = class _PdfDocument {
43622
43687
  dstFields.items.filter((x) => x.kind === "ref").map((x) => x.objectNumber)
43623
43688
  );
43624
43689
  for (const fRef of clonedRootFieldRefs) {
43690
+ if (++work % 16 === 0) yield;
43625
43691
  if (!existingNums.has(fRef.objectNumber)) {
43626
43692
  dstFields.items.push(fRef);
43627
43693
  existingNums.add(fRef.objectNumber);
@@ -43629,11 +43695,11 @@ var PdfDocument = class _PdfDocument {
43629
43695
  }
43630
43696
  const srcDr = dictGet(srcAcroForm, "DR");
43631
43697
  if (srcDr && !dictGet(dstAcroForm, "DR")) {
43632
- dictSet(dstAcroForm, "DR", cloneNode(srcDr));
43698
+ dictSet(dstAcroForm, "DR", yield* cloneNode(srcDr));
43633
43699
  }
43634
43700
  const srcDa = dictGet(srcAcroForm, "DA");
43635
43701
  if (srcDa && !dictGet(dstAcroForm, "DA")) {
43636
- dictSet(dstAcroForm, "DA", cloneNode(srcDa));
43702
+ dictSet(dstAcroForm, "DA", yield* cloneNode(srcDa));
43637
43703
  }
43638
43704
  }
43639
43705
  }
@@ -43642,12 +43708,15 @@ var PdfDocument = class _PdfDocument {
43642
43708
  if (srcOcProps) {
43643
43709
  const dstCatalog = this.cos.resolveDict(this.cos.rootRef);
43644
43710
  if (dstCatalog && !dictGet(dstCatalog, "OCProperties")) {
43645
- dictSet(dstCatalog, "OCProperties", cloneNode(srcOcProps));
43711
+ dictSet(dstCatalog, "OCProperties", yield* cloneNode(srcOcProps));
43646
43712
  }
43647
43713
  }
43648
43714
  this.syncPageTree();
43649
43715
  return copiedPages;
43650
43716
  }
43717
+ copyPagesFrom(sourceDoc, indices) {
43718
+ return drainWork(this.copyPagesFromSteps(sourceDoc, indices));
43719
+ }
43651
43720
  embedStandardFont(fontName) {
43652
43721
  return createStandardFontHandle(fontName);
43653
43722
  }
@@ -43847,14 +43916,15 @@ var PdfDocument = class _PdfDocument {
43847
43916
  });
43848
43917
  return buildSemanticAstFromPages(extractedPages, tablesByPage, displayLists);
43849
43918
  }
43850
- save(options = {}) {
43919
+ *saveSteps(options = {}) {
43920
+ yield;
43851
43921
  this.syncPageTree();
43852
43922
  if (this.cos.requiresFullRewrite) {
43853
43923
  pruneUnusedXObjects(this.cos, this.pages);
43854
43924
  discardUnreachableObjects(this.cos);
43855
43925
  }
43856
43926
  if (options.encrypt) {
43857
- return encryptCosDocument(this.cos, options.encrypt);
43927
+ return yield* encryptCosDocumentSteps(this.cos, options.encrypt);
43858
43928
  }
43859
43929
  const allObjects = [...this.cos.objects.values()].sort(
43860
43930
  (a, b) => a.objectNumber - b.objectNumber
@@ -43862,7 +43932,7 @@ var PdfDocument = class _PdfDocument {
43862
43932
  if (options.incremental && !this.cos.requiresFullRewrite && this.cos.bytes.length > 0) {
43863
43933
  return appendIncrementalRevision(this.cos.bytes, this.cos, allObjects);
43864
43934
  }
43865
- return serializeCosDocument({
43935
+ return yield* serializeCosDocumentSteps({
43866
43936
  objects: allObjects,
43867
43937
  rootRef: this.cos.rootRef,
43868
43938
  infoRef: this.cos.infoRef,
@@ -43873,6 +43943,9 @@ var PdfDocument = class _PdfDocument {
43873
43943
  linearize: options.linearize
43874
43944
  });
43875
43945
  }
43946
+ save(options = {}) {
43947
+ return drainWork(this.saveSteps(options));
43948
+ }
43876
43949
  };
43877
43950
  function resolveDestinationPageIndex(doc, destOrActionNode) {
43878
43951
  const cos = doc.cos;
@@ -44951,7 +45024,7 @@ function* executeQpdfCli(options, files) {
44951
45024
  return { exitCode: 0, stdout: "", stderr: "" };
44952
45025
  }
44953
45026
  try {
44954
- parseCosDocument(raw, { password });
45027
+ yield* parseCosDocumentSteps(raw, { password });
44955
45028
  return { exitCode: 3, stdout: "", stderr: "" };
44956
45029
  } catch {
44957
45030
  return { exitCode: 0, stdout: "", stderr: "" };
@@ -44979,12 +45052,12 @@ function* executeQpdfCli(options, files) {
44979
45052
  return { exitCode: 2, stdout: "", stderr: `qpdf: ${inputFile}: missing trailer /Root
44980
45053
  ` };
44981
45054
  }
44982
- const rebuiltBytes = serializeCosDocument({
45055
+ const rebuiltBytes = yield* serializeCosDocumentSteps({
44983
45056
  objects: [...objectsMap.values()],
44984
45057
  rootRef,
44985
45058
  infoRef
44986
45059
  });
44987
- baseDoc = PdfDocument.load(rebuiltBytes);
45060
+ baseDoc = yield* PdfDocument.loadSteps(rebuiltBytes);
44988
45061
  } catch (err2) {
44989
45062
  const msg = err2 instanceof Error ? err2.message : String(err2);
44990
45063
  return { exitCode: 2, stdout: "", stderr: `qpdf: ${inputFile}: ${msg}
@@ -44992,10 +45065,10 @@ function* executeQpdfCli(options, files) {
44992
45065
  }
44993
45066
  } else {
44994
45067
  try {
44995
- baseDoc = PdfDocument.load(raw, password !== void 0 ? { password } : {});
45068
+ baseDoc = yield* PdfDocument.loadSteps(raw, password !== void 0 ? { password } : {});
44996
45069
  } catch {
44997
45070
  try {
44998
- baseDoc = PdfDocument.load(raw, {
45071
+ baseDoc = yield* PdfDocument.loadSteps(raw, {
44999
45072
  ...password !== void 0 ? { password } : {},
45000
45073
  recovery: "repair"
45001
45074
  });
@@ -45026,12 +45099,12 @@ function* executeQpdfCli(options, files) {
45026
45099
  ` };
45027
45100
  }
45028
45101
  }
45029
- const updatedBytes = serializeCosDocument({
45102
+ const updatedBytes = yield* serializeCosDocumentSteps({
45030
45103
  objects: [...baseDoc.cos.objects.values()],
45031
45104
  rootRef: baseDoc.cos.rootRef,
45032
45105
  infoRef: baseDoc.cos.infoRef
45033
45106
  });
45034
- baseDoc = PdfDocument.load(updatedBytes);
45107
+ baseDoc = yield* PdfDocument.loadSteps(updatedBytes);
45035
45108
  }
45036
45109
  if (showLinearization) {
45037
45110
  const cos = baseDoc.cos;
@@ -45346,7 +45419,7 @@ extract for accessibility: ${enc.permissions.copy ? "allowed" : "not allowed"}
45346
45419
  ` };
45347
45420
  }
45348
45421
  const srcPw = spec.password ?? password;
45349
- const srcDoc = PdfDocument.load(srcBytes, srcPw !== void 0 ? { password: srcPw } : {});
45422
+ const srcDoc = yield* PdfDocument.loadSteps(srcBytes, srcPw !== void 0 ? { password: srcPw } : {});
45350
45423
  const pageNumbers = parseQpdfPageRange(spec.range, srcDoc.getPageCount());
45351
45424
  loadedSpecs.push({ doc: srcDoc, indices: pageNumbers.map((p) => p - 1) });
45352
45425
  }
@@ -45360,7 +45433,7 @@ extract for accessibility: ${enc.permissions.copy ? "allowed" : "not allowed"}
45360
45433
  const cur = cursors[s];
45361
45434
  if (cur < item.indices.length) {
45362
45435
  const slice = item.indices.slice(cur, cur + collateCount);
45363
- mergedDoc.copyPagesFrom(item.doc, slice);
45436
+ yield* mergedDoc.copyPagesFromSteps(item.doc, slice);
45364
45437
  cursors[s] = cur + slice.length;
45365
45438
  if (cursors[s] < item.indices.length) remaining = true;
45366
45439
  }
@@ -45368,7 +45441,7 @@ extract for accessibility: ${enc.permissions.copy ? "allowed" : "not allowed"}
45368
45441
  }
45369
45442
  } else {
45370
45443
  for (const item of loadedSpecs) {
45371
- mergedDoc.copyPagesFrom(item.doc, item.indices);
45444
+ yield* mergedDoc.copyPagesFromSteps(item.doc, item.indices);
45372
45445
  }
45373
45446
  }
45374
45447
  workingDoc = mergedDoc;
@@ -45397,7 +45470,7 @@ extract for accessibility: ${enc.permissions.copy ? "allowed" : "not allowed"}
45397
45470
  ` };
45398
45471
  }
45399
45472
  const stampPw = stamp.password ?? password;
45400
- const stampDoc = PdfDocument.load(stampBytes, stampPw !== void 0 ? { password: stampPw } : {});
45473
+ const stampDoc = yield* PdfDocument.loadSteps(stampBytes, stampPw !== void 0 ? { password: stampPw } : {});
45401
45474
  const fromPages = parseQpdfPageRange(stamp.fromRange, stampDoc.getPageCount());
45402
45475
  const toPages = parseQpdfPageRange(stamp.toRange, workingDoc.getPageCount());
45403
45476
  const repeatPages = stamp.repeatRange ? parseQpdfPageRange(stamp.repeatRange, stampDoc.getPageCount()) : fromPages;
@@ -45957,7 +46030,7 @@ Q
45957
46030
  }
45958
46031
  }
45959
46032
  if (generateAppearances && !removeAcroform) {
45960
- generateDocumentFormAppearances(workingDoc.cos);
46033
+ yield* generateDocumentFormAppearancesSteps(workingDoc.cos);
45961
46034
  }
45962
46035
  if (removeInfo || removeMetadata || removeStructure || removeAcroform) {
45963
46036
  const rootDict = asDict(workingDoc.cos.resolve(workingDoc.cos.rootRef));
@@ -45992,7 +46065,7 @@ Q
45992
46065
  return { exitCode: 2, stdout: "", stderr: `qpdf: cannot open ${copySpec.file}
45993
46066
  ` };
45994
46067
  }
45995
- const srcDoc = PdfDocument.load(srcBytes, copySpec.password ? { password: copySpec.password } : {});
46068
+ const srcDoc = yield* PdfDocument.loadSteps(srcBytes, copySpec.password ? { password: copySpec.password } : {});
45996
46069
  const srcRoot = asDict(srcDoc.cos.resolve(srcDoc.cos.rootRef));
45997
46070
  const srcNames = srcRoot ? asDict(srcDoc.cos.resolve(dictGet(srcRoot, "Names"))) : void 0;
45998
46071
  const srcEf = srcNames ? asDict(srcDoc.cos.resolve(dictGet(srcNames, "EmbeddedFiles"))) : void 0;
@@ -46230,24 +46303,24 @@ Q
46230
46303
  if (wMeta.keywords) subDoc.setKeywords(wMeta.keywords);
46231
46304
  const indices = [];
46232
46305
  for (let k = startIdx; k <= endIdx; k++) indices.push(k);
46233
- subDoc.copyPagesFrom(workingDoc, indices);
46306
+ yield* subDoc.copyPagesFromSteps(workingDoc, indices);
46234
46307
  const sPad = String(startIdx + 1).padStart(padLen, "0");
46235
46308
  const ePad = String(endIdx + 1).padStart(padLen, "0");
46236
46309
  const suffix = splitPagesGroup === 1 ? sPad : `${sPad}-${ePad}`;
46237
46310
  const formattedSpec = formatSplitSpec(finalTarget, startIdx + 1, endIdx + 1);
46238
46311
  const splitName = formattedSpec ?? `${baseStem}-${suffix}.pdf`;
46239
- files.set(splitName, subDoc.save({ normalizeContent: qdf }));
46312
+ files.set(splitName, yield* subDoc.saveSteps({ normalizeContent: qdf }));
46240
46313
  }
46241
46314
  return { exitCode: 0, stdout: "", stderr: "" };
46242
46315
  }
46243
46316
  const shouldNormalizeContent = normalizeContentFlag !== void 0 ? normalizeContentFlag : qdf || streamDataMode === "uncompress";
46244
- let outBytes = workingDoc.save({
46317
+ let outBytes = yield* workingDoc.saveSteps({
46245
46318
  normalizeContent: shouldNormalizeContent,
46246
46319
  objectStreams: objectStreamsMode
46247
46320
  });
46248
46321
  if (encryptConfig && !decrypt2) {
46249
- const parsedOut = parseCosDocument(outBytes);
46250
- outBytes = encryptCosDocument(parsedOut, {
46322
+ const parsedOut = yield* parseCosDocumentSteps(outBytes);
46323
+ outBytes = yield* encryptCosDocumentSteps(parsedOut, {
46251
46324
  userPassword: encryptConfig.userPassword,
46252
46325
  ownerPassword: encryptConfig.ownerPassword,
46253
46326
  permissions: {
@@ -46260,7 +46333,7 @@ Q
46260
46333
  } else if (decrypt2 && workingDoc.cos.encryption) {
46261
46334
  workingDoc.cos.encryptRef = void 0;
46262
46335
  workingDoc.cos.encryption = void 0;
46263
- outBytes = serializeCosDocument({
46336
+ outBytes = yield* serializeCosDocumentSteps({
46264
46337
  objects: [...workingDoc.cos.objects.values()],
46265
46338
  rootRef: workingDoc.cos.rootRef,
46266
46339
  infoRef: workingDoc.cos.infoRef