@poe-platform/safe-bash 0.1.810 → 0.1.812

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 (276) hide show
  1. package/dist/audio-ast/flac-source.d.ts +13 -0
  2. package/dist/audio-ast/index.d.ts +2 -0
  3. package/dist/audio-ast/index.js +253 -179
  4. package/dist/audio-ast/vorbis.d.ts +14 -0
  5. package/dist/image-ast/index.js +1 -1
  6. package/dist/json-ast/backed-json-parser.d.ts +12 -1
  7. package/dist/json-ast/index.d.ts +1 -1
  8. package/dist/office-xml/index.d.ts +1 -0
  9. package/dist/office-xml/retained-xml-edits.d.ts +22 -0
  10. package/dist/pdf-ast/cos/qpdf-json-document.d.ts +2 -1
  11. package/dist/pdf-ast/cos/value-parser.d.ts +23 -2
  12. package/dist/pdf-ast/extract/retained-form-field-details.d.ts +20 -0
  13. package/dist/pdf-ast/extract/retained-form-fields.d.ts +17 -4
  14. package/dist/pdf-ast/index.d.ts +1 -0
  15. package/dist/pdf-ast/index.js +844 -384
  16. package/dist/pdf-ast/retained-document.d.ts +6 -0
  17. package/dist/safe-bash/audio-ast.browser.js +3 -1
  18. package/dist/safe-bash/chunks/{chunk-65TFMAZU.js → chunk-BUYRKFW2.js} +8 -35
  19. package/dist/safe-bash/chunks/{chunk-ZA5FQ34E.js → chunk-TPG55BAQ.js} +0 -2
  20. package/dist/safe-bash/command-chunks/{biff-ORSHM4YX-QYPGRDAZ.js → biff-YKPDH35C-MVQIWNKV.js} +2192 -2155
  21. package/dist/safe-bash/command-chunks/{chunk-HEHGHIE2.js → chunk-22MOB45U.js} +6 -6
  22. package/dist/safe-bash/command-chunks/{chunk-6DEWZMOL.js → chunk-2CORNDGF.js} +2 -2
  23. package/dist/safe-bash/command-chunks/{chunk-DCD32BEY.js → chunk-2JSDKQ4J.js} +201 -84
  24. package/dist/safe-bash/command-chunks/{chunk-6UHGIWFX.js → chunk-2ZFLMWOX.js} +1 -1
  25. package/dist/safe-bash/command-chunks/{chunk-HONWGFDA.js → chunk-33YCKZZX.js} +6 -6
  26. package/dist/safe-bash/command-chunks/{chunk-AXWPJRY6.js → chunk-36XGIPOG.js} +1 -1
  27. package/dist/safe-bash/command-chunks/{chunk-D5AYP2UM.js → chunk-3Q247UDJ.js} +26 -16
  28. package/dist/safe-bash/command-chunks/{chunk-32ADKP5E.js → chunk-456PHA3L.js} +1 -1
  29. package/dist/safe-bash/command-chunks/{chunk-UJXP3T6R.js → chunk-4CKFNXRN.js} +1 -1
  30. package/dist/safe-bash/command-chunks/{chunk-5L6GHFRW.js → chunk-554Z6IKP.js} +2 -2
  31. package/dist/safe-bash/command-chunks/{chunk-ORZRWT62.js → chunk-56NYSX65.js} +9 -9
  32. package/dist/safe-bash/command-chunks/{chunk-53JP3S6H.js → chunk-5HPU7D36.js} +4 -4
  33. package/dist/safe-bash/command-chunks/{chunk-HARUYHH7.js → chunk-5HUICAWD.js} +1 -1
  34. package/dist/safe-bash/command-chunks/{chunk-IC5GJI7E.js → chunk-5Q22ZLNC.js} +6 -6
  35. package/dist/safe-bash/command-chunks/{chunk-YO3V5RLY.js → chunk-6CCQI6XZ.js} +12 -12
  36. package/dist/safe-bash/command-chunks/{chunk-EO2IVGV7.js → chunk-6M6TM5Z5.js} +3 -3
  37. package/dist/safe-bash/command-chunks/{chunk-Z54Z3KRN.js → chunk-6QBMND4A.js} +1 -1
  38. package/dist/safe-bash/command-chunks/{chunk-INX4JMQ6.js → chunk-6VPQ3CDZ.js} +5 -5
  39. package/dist/safe-bash/command-chunks/{chunk-VGXVN3BX.js → chunk-7GKKMNL6.js} +8 -8
  40. package/dist/safe-bash/command-chunks/{chunk-TZJC67W3.js → chunk-7PVHO47B.js} +6 -6
  41. package/dist/safe-bash/command-chunks/{chunk-CM3C7AXJ.js → chunk-A2CLZMQZ.js} +1 -1
  42. package/dist/safe-bash/command-chunks/{chunk-ASR27KHW.js → chunk-A5FZBR7X.js} +4 -4
  43. package/dist/safe-bash/command-chunks/{chunk-DMDHE5KC.js → chunk-AHA6IWAJ.js} +6 -6
  44. package/dist/safe-bash/command-chunks/{chunk-PTZ55XXN.js → chunk-APEWTWCC.js} +6 -6
  45. package/dist/safe-bash/command-chunks/{chunk-YUVH6CE4.js → chunk-ATTWQVR2.js} +17 -17
  46. package/dist/safe-bash/command-chunks/{chunk-2VCKUNDZ.js → chunk-B2C3UPJS.js} +27 -17
  47. package/dist/safe-bash/command-chunks/{chunk-JON5DB3Z.js → chunk-B5LDP7AA.js} +2 -2
  48. package/dist/safe-bash/command-chunks/{chunk-YTFWPJ3F.js → chunk-CJQSAATC.js} +26 -26
  49. package/dist/safe-bash/command-chunks/{chunk-CHJL6JMU.js → chunk-COKYZUBW.js} +1 -1
  50. package/dist/safe-bash/command-chunks/{chunk-KCTV4NVX.js → chunk-CRV2Q3PB.js} +1 -1
  51. package/dist/safe-bash/command-chunks/{chunk-V3WXPCKN.js → chunk-CV7M2QJU.js} +7 -7
  52. package/dist/safe-bash/command-chunks/{chunk-VPDSQPSN.js → chunk-DM2CPMB4.js} +2 -2
  53. package/dist/safe-bash/command-chunks/{chunk-3DTDMEOP.js → chunk-EAGIJ4VW.js} +1 -1
  54. package/dist/safe-bash/command-chunks/{chunk-JW6CMBF2.js → chunk-EHSM5ZQS.js} +8 -8
  55. package/dist/safe-bash/command-chunks/{chunk-WIOH7ZQN.js → chunk-ENT3IV2G.js} +12 -12
  56. package/dist/safe-bash/command-chunks/{chunk-5IE4LJGB.js → chunk-EUT24Y5Z.js} +8 -8
  57. package/dist/safe-bash/command-chunks/{chunk-WC2OCF4H.js → chunk-FDCIPJBQ.js} +7 -7
  58. package/dist/safe-bash/command-chunks/{chunk-COKZFXHG.js → chunk-FIIAYCWS.js} +2 -2
  59. package/dist/safe-bash/command-chunks/{chunk-MWVFP2HY.js → chunk-GEM47B2P.js} +7 -7
  60. package/dist/safe-bash/command-chunks/{chunk-EHL6B34L.js → chunk-HDJVJTCK.js} +9 -9
  61. package/dist/safe-bash/command-chunks/{chunk-JMM3MNAY.js → chunk-HKATEVAP.js} +6 -6
  62. package/dist/safe-bash/command-chunks/{chunk-VWY3EAVQ.js → chunk-HTVIYLVB.js} +4 -4
  63. package/dist/safe-bash/command-chunks/{chunk-CHR2OD2U.js → chunk-HWQ2UHMT.js} +9 -9
  64. package/dist/safe-bash/command-chunks/{chunk-Z4QJMDK3.js → chunk-IT7TAC3F.js} +16 -16
  65. package/dist/safe-bash/command-chunks/{chunk-EWS4KYJE.js → chunk-JFYWVQ4V.js} +8 -8
  66. package/dist/safe-bash/command-chunks/{chunk-ZCX63QWA.js → chunk-JOCFI7TG.js} +1 -1
  67. package/dist/safe-bash/command-chunks/{chunk-F5WTH4O4.js → chunk-JQVHUSDD.js} +5 -5
  68. package/dist/safe-bash/command-chunks/{chunk-O4VJEGL6.js → chunk-K5GB2YMN.js} +10 -10
  69. package/dist/safe-bash/command-chunks/{chunk-27C3NT5V.js → chunk-KB7DUBVL.js} +5 -5
  70. package/dist/safe-bash/command-chunks/{chunk-4DZ32PI7.js → chunk-KCOJA7EM.js} +7 -7
  71. package/dist/safe-bash/command-chunks/{chunk-CAXJ4RLF.js → chunk-KJ4XXZIL.js} +12 -12
  72. package/dist/safe-bash/command-chunks/{chunk-U6QHTC5J.js → chunk-L5MCW6CM.js} +4 -4
  73. package/dist/safe-bash/command-chunks/{chunk-LVL3A7YE.js → chunk-LCZDBW55.js} +5 -5
  74. package/dist/safe-bash/command-chunks/{chunk-DJVRDUCA.js → chunk-LXLLA4PM.js} +17 -17
  75. package/dist/safe-bash/command-chunks/{chunk-K7AGAS3K.js → chunk-M7QE2MN7.js} +6 -6
  76. package/dist/safe-bash/command-chunks/{chunk-SWT6ILF2.js → chunk-MPUHH2KR.js} +3 -3
  77. package/dist/safe-bash/command-chunks/{chunk-3ZWBBS6U.js → chunk-NARD63DY.js} +437 -34
  78. package/dist/safe-bash/command-chunks/{chunk-DC3OJLRB.js → chunk-NQDIT667.js} +5 -5
  79. package/dist/safe-bash/command-chunks/{chunk-LWZVDDJA.js → chunk-NUGQQDGE.js} +5 -1
  80. package/dist/safe-bash/command-chunks/{chunk-MFLQZLFR.js → chunk-OA75SGN2.js} +7 -7
  81. package/dist/safe-bash/command-chunks/{chunk-5LATYOF7.js → chunk-OEJM666F.js} +5 -5
  82. package/dist/safe-bash/command-chunks/{chunk-AF25YYIO.js → chunk-PMAM4N33.js} +9 -9
  83. package/dist/safe-bash/command-chunks/{chunk-KMMAJ6H6.js → chunk-PNGDJA6M.js} +2 -2
  84. package/dist/safe-bash/command-chunks/{chunk-62BHPSKJ.js → chunk-Q6S57NOQ.js} +7 -7
  85. package/dist/safe-bash/command-chunks/{chunk-KJ3PEDI2.js → chunk-Q73EMLLZ.js} +146 -4
  86. package/dist/safe-bash/command-chunks/{chunk-FXKBM5KJ.js → chunk-QC5RMGSA.js} +3 -3
  87. package/dist/safe-bash/command-chunks/{chunk-UQ6UIZMM.js → chunk-QD7ZRDUN.js} +1 -1
  88. package/dist/safe-bash/command-chunks/{chunk-JHUYZZGV.js → chunk-QYMEASQ6.js} +4 -4
  89. package/dist/safe-bash/command-chunks/{chunk-3GY5VDIX.js → chunk-QZZ73J2O.js} +6 -6
  90. package/dist/safe-bash/command-chunks/{chunk-S2CYIGWH.js → chunk-R6EGGK5M.js} +7 -7
  91. package/dist/safe-bash/command-chunks/{chunk-7AVN3OBH.js → chunk-RHYJVTJO.js} +2 -2
  92. package/dist/safe-bash/command-chunks/{chunk-EWGDSO6U.js → chunk-RID6VYS3.js} +8 -8
  93. package/dist/safe-bash/command-chunks/{chunk-MMBRBANA.js → chunk-RNSKXOG3.js} +6 -6
  94. package/dist/safe-bash/command-chunks/{chunk-D3ZRZTY5.js → chunk-RQIQ75W5.js} +5 -5
  95. package/dist/safe-bash/command-chunks/{chunk-DWKQPLRT.js → chunk-RRL3Y562.js} +11 -11
  96. package/dist/safe-bash/command-chunks/{chunk-NXCMXD74.js → chunk-S6R3IB36.js} +1 -1
  97. package/dist/safe-bash/command-chunks/{chunk-XUPKFHAQ.js → chunk-SDTPO2VV.js} +7 -7
  98. package/dist/safe-bash/command-chunks/{chunk-PIAGKRFW.js → chunk-SPLOIABU.js} +3 -3
  99. package/dist/safe-bash/command-chunks/{chunk-Z5QOVRVH.js → chunk-SU26FZLJ.js} +1 -1
  100. package/dist/safe-bash/command-chunks/{chunk-WLTJDNSQ.js → chunk-TVH4JORU.js} +3 -3
  101. package/dist/safe-bash/command-chunks/{chunk-6XVMWFHD.js → chunk-TW73OXPR.js} +6 -6
  102. package/dist/safe-bash/command-chunks/{chunk-SFO43CID.js → chunk-UAXSE3XE.js} +5 -5
  103. package/dist/safe-bash/command-chunks/{chunk-K35BSUHO.js → chunk-UYWSIIUX.js} +7 -7
  104. package/dist/safe-bash/command-chunks/{chunk-2E2YEDVB.js → chunk-W5YSINXC.js} +6 -6
  105. package/dist/safe-bash/command-chunks/{chunk-EYNT4OEJ.js → chunk-WGG6G2KG.js} +7 -7
  106. package/dist/safe-bash/command-chunks/{chunk-DVQBZXMQ.js → chunk-WJCN2IXI.js} +2 -2
  107. package/dist/safe-bash/command-chunks/{chunk-XBZ4ZWGL.js → chunk-WVMHRNXZ.js} +3 -3
  108. package/dist/safe-bash/command-chunks/{chunk-7GXUCQI4.js → chunk-WXRYDALR.js} +4 -4
  109. package/dist/safe-bash/command-chunks/{chunk-S4IIOSRA.js → chunk-X7FA7ZD5.js} +8 -8
  110. package/dist/safe-bash/command-chunks/{chunk-DPR5CYQV.js → chunk-XITDDJFT.js} +2 -0
  111. package/dist/safe-bash/command-chunks/{chunk-SFCERNHU.js → chunk-XPD636C4.js} +3 -3
  112. package/dist/safe-bash/command-chunks/{chunk-HYDWQLJ3.js → chunk-XRVKWGVQ.js} +6 -6
  113. package/dist/safe-bash/command-chunks/{chunk-ZEPDT6I5.js → chunk-XVLWZTPY.js} +249 -51
  114. package/dist/safe-bash/command-chunks/{chunk-3UJWHRK4.js → chunk-XVP6V5K3.js} +6 -6
  115. package/dist/safe-bash/command-chunks/{chunk-KTI3BULE.js → chunk-XZ2FWFNV.js} +6 -6
  116. package/dist/safe-bash/command-chunks/{chunk-QK3CHRGL.js → chunk-Y4EYCZFT.js} +10 -10
  117. package/dist/safe-bash/command-chunks/{chunk-GTWVMFBK.js → chunk-YORJDX4V.js} +4 -4
  118. package/dist/safe-bash/command-chunks/{chunk-H6F5SN2N.js → chunk-YSMNXMAO.js} +4 -4
  119. package/dist/safe-bash/command-chunks/{chunk-SE5SJ4JT.js → chunk-Z2JW6M2D.js} +3 -3
  120. package/dist/safe-bash/command-chunks/{chunk-WH3TIOTS.js → chunk-ZEGNRZV2.js} +9 -2
  121. package/dist/safe-bash/command-chunks/{chunk-BYZUOF6X.js → chunk-ZEX53S5I.js} +4010 -3980
  122. package/dist/safe-bash/command-chunks/{chunk-HQYFRQ5W.js → chunk-ZIIO6GRY.js} +7 -7
  123. package/dist/safe-bash/command-chunks/{chunk-NTRZMQZP.js → chunk-ZMHEGDU2.js} +2 -2
  124. package/dist/safe-bash/command-chunks/{chunk-EYBXHGA6.js → chunk-ZXR6LXV5.js} +2 -2
  125. package/dist/safe-bash/command-chunks/{command-engine-BEWABZ75.js → command-engine-BCUQGJJ4.js} +58 -21
  126. package/dist/safe-bash/command-chunks/{engine-MEPOXIXT-WZMRHACG.js → engine-LAUEWYSQ-DQCEI5HE.js} +1 -1
  127. package/dist/safe-bash/command-chunks/pdf-XHHFTOT4-UJJYOYJ2.js +573 -0
  128. package/dist/safe-bash/commands/diff-patch/index.js +0 -3
  129. package/dist/safe-bash/commands/diff3/index.js +0 -2
  130. package/dist/safe-bash/full-core.browser.js +2 -2
  131. package/dist/safe-bash/plugins/index.browser.js +2 -2
  132. package/dist/safe-bash/plugins/index.js +3 -1
  133. package/dist/safe-bash/plugins/portable-commands.d.ts +1 -1
  134. package/dist/safe-bash/plugins/portable-commands.js +5 -3
  135. package/dist/safe-bash/registry-entry.browser.js +1 -1
  136. package/dist/safe-bash-command-apply-patch/apply.js +4 -4
  137. package/dist/safe-bash-command-apply-patch/index.js +4 -4
  138. package/dist/safe-bash-command-apply-patch/matcher.js +2 -2
  139. package/dist/safe-bash-command-apply-patch/parser.js +2 -2
  140. package/dist/safe-bash-command-apply-patch/shared.d.ts +2 -0
  141. package/dist/safe-bash-command-apply-patch/shared.js +1 -1
  142. package/dist/safe-bash-command-diff/index.js +0 -2
  143. package/dist/safe-bash-command-diff3/index.js +830 -56
  144. package/dist/safe-bash-command-ffmpeg/index.js +1 -1
  145. package/dist/safe-bash-command-ffprobe/index.js +2 -2
  146. package/dist/safe-bash-command-ffprobe/media.js +2 -2
  147. package/dist/safe-bash-command-html-to-markdown/index.js +75 -21
  148. package/dist/safe-bash-command-pandoc/command.js +3 -3
  149. package/dist/safe-bash-command-pandoc/execution.d.ts +2 -2
  150. package/dist/safe-bash-command-pandoc/index.d.ts +1 -1
  151. package/dist/safe-bash-command-pandoc/index.js +14 -14
  152. package/dist/safe-bash-command-pandoc/lua-filters.js +2 -2
  153. package/dist/safe-bash-command-pandoc/types.d.ts +17 -2
  154. package/dist/safe-bash-command-patch/index.js +2 -2
  155. package/dist/safe-bash-command-patch/patch-publication.js +1 -1
  156. package/dist/safe-bash-command-patch/patch.js +2 -2
  157. package/dist/safe-bash-command-pdftk/index.js +649 -265
  158. package/dist/safe-bash-command-pptx/command-engine.d.ts +12 -3
  159. package/dist/safe-bash-command-pptx/engine.d.ts +2 -2
  160. package/dist/safe-bash-command-pptx/engine.js +1 -1
  161. package/dist/safe-bash-command-qpdf/index.js +115 -9
  162. package/dist/safe-bash-command-soffice/index.js +1 -1
  163. package/dist/safe-bash-command-ssconvert/index.js +2 -2
  164. package/dist/safe-bash-command-xq/index.js +45 -29
  165. package/dist/safe-bash-diff-engine/document.d.ts +2 -1
  166. package/dist/safe-bash-diff-engine/document.js +7 -4
  167. package/dist/safe-bash-presentation-engine/accessibility.js +30 -30
  168. package/dist/safe-bash-presentation-engine/animation-editing.js +15 -15
  169. package/dist/safe-bash-presentation-engine/animations.js +15 -15
  170. package/dist/safe-bash-presentation-engine/backgrounds.js +16 -16
  171. package/dist/safe-bash-presentation-engine/bytes.js +3 -3
  172. package/dist/safe-bash-presentation-engine/chart-editing.js +33 -33
  173. package/dist/safe-bash-presentation-engine/chart-object-operations.js +24 -24
  174. package/dist/safe-bash-presentation-engine/charts.js +30 -30
  175. package/dist/safe-bash-presentation-engine/command-placeholder.js +56 -55
  176. package/dist/safe-bash-presentation-engine/comments.js +16 -16
  177. package/dist/safe-bash-presentation-engine/connector-operations.js +31 -31
  178. package/dist/safe-bash-presentation-engine/connectors.js +28 -28
  179. package/dist/safe-bash-presentation-engine/content-types.js +4 -4
  180. package/dist/safe-bash-presentation-engine/creation.js +6 -6
  181. package/dist/safe-bash-presentation-engine/diff.js +31 -31
  182. package/dist/safe-bash-presentation-engine/drawing-format.js +19 -19
  183. package/dist/safe-bash-presentation-engine/drawing-operations.js +30 -30
  184. package/dist/safe-bash-presentation-engine/drawing-schema.js +20 -20
  185. package/dist/safe-bash-presentation-engine/equations.js +16 -16
  186. package/dist/safe-bash-presentation-engine/errors.js +2 -2
  187. package/dist/safe-bash-presentation-engine/fields.js +16 -16
  188. package/dist/safe-bash-presentation-engine/font-metrics.js +3 -3
  189. package/dist/safe-bash-presentation-engine/image-extraction.js +19 -19
  190. package/dist/safe-bash-presentation-engine/image-formatting.js +31 -31
  191. package/dist/safe-bash-presentation-engine/image-insertion.js +17 -17
  192. package/dist/safe-bash-presentation-engine/image-replacement.js +20 -20
  193. package/dist/safe-bash-presentation-engine/image-value.js +4 -4
  194. package/dist/safe-bash-presentation-engine/images.js +18 -18
  195. package/dist/safe-bash-presentation-engine/index.d.ts +1 -1
  196. package/dist/safe-bash-presentation-engine/index.js +99 -95
  197. package/dist/safe-bash-presentation-engine/layouts.js +15 -15
  198. package/dist/safe-bash-presentation-engine/length.js +3 -3
  199. package/dist/safe-bash-presentation-engine/links.js +15 -15
  200. package/dist/safe-bash-presentation-engine/masters.js +14 -14
  201. package/dist/safe-bash-presentation-engine/media-editing.js +23 -23
  202. package/dist/safe-bash-presentation-engine/media-extraction.js +16 -16
  203. package/dist/safe-bash-presentation-engine/media.js +15 -15
  204. package/dist/safe-bash-presentation-engine/memberships.js +14 -14
  205. package/dist/safe-bash-presentation-engine/notes.js +15 -15
  206. package/dist/safe-bash-presentation-engine/ole-enum.js +4 -4
  207. package/dist/safe-bash-presentation-engine/ole-insertion.js +19 -19
  208. package/dist/safe-bash-presentation-engine/opaque-objects.js +9 -9
  209. package/dist/safe-bash-presentation-engine/package-reader.js +5 -5
  210. package/dist/safe-bash-presentation-engine/package-tools.js +15 -15
  211. package/dist/safe-bash-presentation-engine/package-uri.js +3 -3
  212. package/dist/safe-bash-presentation-engine/package-writer.js +4 -4
  213. package/dist/safe-bash-presentation-engine/presentation-model.js +55 -54
  214. package/dist/safe-bash-presentation-engine/presentation-settings.js +13 -13
  215. package/dist/safe-bash-presentation-engine/properties.js +15 -15
  216. package/dist/safe-bash-presentation-engine/relationships.js +4 -4
  217. package/dist/safe-bash-presentation-engine/resource-limits.js +1 -1
  218. package/dist/safe-bash-presentation-engine/retained-inspection.js +12 -12
  219. package/dist/safe-bash-presentation-engine/retained-package.js +4 -4
  220. package/dist/safe-bash-presentation-engine/retained-slide-publication.d.ts +24 -0
  221. package/dist/safe-bash-presentation-engine/retained-slide-settings.d.ts +15 -0
  222. package/dist/safe-bash-presentation-engine/retained-text.js +17 -17
  223. package/dist/safe-bash-presentation-engine/sanitize.js +16 -16
  224. package/dist/safe-bash-presentation-engine/selectors.js +10 -10
  225. package/dist/safe-bash-presentation-engine/shape-groups.js +30 -30
  226. package/dist/safe-bash-presentation-engine/shape-operations.js +29 -29
  227. package/dist/safe-bash-presentation-engine/shape-path-operations.js +31 -31
  228. package/dist/safe-bash-presentation-engine/shape-paths.js +15 -15
  229. package/dist/safe-bash-presentation-engine/shape-presets.js +3 -3
  230. package/dist/safe-bash-presentation-engine/shape-selection.js +30 -30
  231. package/dist/safe-bash-presentation-engine/shape-transforms.js +17 -17
  232. package/dist/safe-bash-presentation-engine/shapes.js +26 -26
  233. package/dist/safe-bash-presentation-engine/slide-copy.js +16 -16
  234. package/dist/safe-bash-presentation-engine/slide-import.js +17 -17
  235. package/dist/safe-bash-presentation-engine/slide-merge-split.js +19 -19
  236. package/dist/safe-bash-presentation-engine/slide-model.js +42 -42
  237. package/dist/safe-bash-presentation-engine/slide-removal.js +17 -17
  238. package/dist/safe-bash-presentation-engine/slide-transfer-budget.js +9 -9
  239. package/dist/safe-bash-presentation-engine/slides.d.ts +3 -0
  240. package/dist/safe-bash-presentation-engine/slides.js +24 -16
  241. package/dist/safe-bash-presentation-engine/table-operations.js +32 -32
  242. package/dist/safe-bash-presentation-engine/table-spans.js +31 -31
  243. package/dist/safe-bash-presentation-engine/tables.js +30 -30
  244. package/dist/safe-bash-presentation-engine/tags.js +15 -15
  245. package/dist/safe-bash-presentation-engine/template-bindings.js +32 -32
  246. package/dist/safe-bash-presentation-engine/template-repeat.js +39 -39
  247. package/dist/safe-bash-presentation-engine/text-fitting.js +26 -26
  248. package/dist/safe-bash-presentation-engine/text-frames.js +26 -26
  249. package/dist/safe-bash-presentation-engine/text-paragraphs.js +26 -26
  250. package/dist/safe-bash-presentation-engine/text-reading.js +11 -11
  251. package/dist/safe-bash-presentation-engine/text-replacement.js +16 -16
  252. package/dist/safe-bash-presentation-engine/text-runs.js +19 -19
  253. package/dist/safe-bash-presentation-engine/themes.js +15 -15
  254. package/dist/safe-bash-presentation-engine/transitions.js +15 -15
  255. package/dist/safe-bash-presentation-engine/validation.js +9 -9
  256. package/dist/safe-bash-presentation-engine/xml-parts.js +15 -15
  257. package/dist/safe-bash-presentation-engine/xml-view.js +3 -3
  258. package/dist/safe-bash-presentation-engine/xml.js +3 -3
  259. package/dist/safe-bash-xml-engine/json.d.ts +1 -0
  260. package/dist/safe-bash-xml-engine/json.js +203 -0
  261. package/dist/safe-bash-xml-engine/stored-json.d.ts +5 -0
  262. package/dist/spreadsheet-engine/rendering/print/bidi-runs.d.ts +5 -0
  263. package/dist/spreadsheet-engine/rendering/print/bidi-runs.js +35 -0
  264. package/dist/spreadsheet-engine/rendering/print/control-bidi.d.ts +8 -0
  265. package/dist/spreadsheet-engine/rendering/print/control-bidi.js +80 -0
  266. package/dist/spreadsheet-format-xls/biff-encrypted-properties.d.ts +4 -4
  267. package/dist/spreadsheet-format-xls/biff-encrypted-properties.js +76 -30
  268. package/dist/spreadsheet-format-xls/biff-encryption.js +1 -1
  269. package/dist/spreadsheet-format-xls/biff-metadata.d.ts +1 -0
  270. package/dist/spreadsheet-format-xls/biff-metadata.js +2 -2
  271. package/dist/spreadsheet-format-xls/biff-property-bytes.d.ts +4 -1
  272. package/dist/spreadsheet-format-xls/biff-property-bytes.js +1 -1
  273. package/dist/spreadsheet-format-xls/biff-range.js +1 -1
  274. package/dist/spreadsheet-format-xls/biff-write-metadata.js +10 -1
  275. package/package.json +5 -2
  276. package/dist/safe-bash/command-chunks/pdf-LOZAXXS6-ERI57IAV.js +0 -557
@@ -9,7 +9,7 @@ import {
9
9
  indexJsonObjects,
10
10
  parseBackedJson,
11
11
  readJsonNumber
12
- } from "../safe-bash/command-chunks/chunk-LWZVDDJA.js";
12
+ } from "../safe-bash/command-chunks/chunk-NUGQQDGE.js";
13
13
  import "../safe-bash/command-chunks/chunk-65DS4IOB.js";
14
14
 
15
15
  // packages/pdf-ast/src/source.ts
@@ -28156,28 +28156,41 @@ function* parseValueSteps(lexer, maxDepth, repair = false, maxNodes = Infinity,
28156
28156
  if (nodes >= maxNodes) throw new PdfError("E_LIMIT", "PDF value node limit exceeded");
28157
28157
  nodes++;
28158
28158
  };
28159
+ const residentDepth = 32;
28159
28160
  const stack = [];
28160
- function matchesStoredPath() {
28161
+ let current, depth = 0;
28162
+ const pathLength = (options.storedArrayPaths ?? []).reduce((length, path) => Math.max(length, path.length - 1), 0);
28163
+ function matchesStoredPath(parent) {
28161
28164
  return options.storedArrayPaths?.some((path) => {
28162
- const prefix = options.arrayPathPrefix ?? [], length = prefix.length + stack.length;
28165
+ const length = parent.path.length + 1;
28163
28166
  if (!path.length || path.length > length) return false;
28164
28167
  for (let i = 0; i < path.length; i++) {
28165
28168
  const at = length - path.length + i;
28166
- let key;
28167
- if (at < prefix.length) key = prefix[at];
28168
- else {
28169
- const parent = stack[at - prefix.length];
28170
- if (parent.kind !== "dict") return false;
28171
- key = parent.key?.decoded;
28172
- }
28173
- if (key === void 0 || path[i] !== "*" && path[i] !== key) return false;
28169
+ const key = at === parent.path.length ? parent.kind === "dict" ? parent.key?.decoded : void 0 : parent.path[at];
28170
+ if (key == null || path[i] !== "*" && path[i] !== key) return false;
28174
28171
  }
28175
28172
  return true;
28176
28173
  }) ?? false;
28177
28174
  }
28175
+ function ancestorPath(parent) {
28176
+ if (!pathLength) return [];
28177
+ return parent ? [...parent.path, parent.kind === "dict" ? parent.key?.decoded ?? null : null].slice(-pathLength) : options.arrayPathPrefix?.slice(-pathLength) ?? [];
28178
+ }
28179
+ function* push(container) {
28180
+ if (current) {
28181
+ if (options.containerStorage && depth > residentDepth) yield { kind: "container-push", container: current };
28182
+ else stack.push(current);
28183
+ }
28184
+ current = container;
28185
+ depth++;
28186
+ }
28187
+ function* pop() {
28188
+ depth--;
28189
+ current = options.containerStorage && depth > residentDepth ? yield { kind: "container-pop" } : stack.pop();
28190
+ }
28178
28191
  while (true) {
28179
28192
  if (++work % 16 === 0) yield;
28180
- const parent = stack.at(-1);
28193
+ const parent = current;
28181
28194
  lexer.setStringStorage?.(options.stringStorage && (parent?.kind === "dict" && parent.key && options.storedStringKeys?.includes(parent.key.decoded) || !parent && options.storeRootString) ? options.stringStorage : void 0);
28182
28195
  const tok = yield "token";
28183
28196
  if (!tok) {
@@ -28190,11 +28203,11 @@ function* parseValueSteps(lexer, maxDepth, repair = false, maxNodes = Infinity,
28190
28203
  }
28191
28204
  let node;
28192
28205
  if (parent?.kind === "array" && tok.kind === "array-end") {
28193
- stack.pop();
28206
+ yield* pop();
28194
28207
  node = { kind: "array", items: parent.items, ...parent.storedItems ? { storedItems: parent.storedItems } : {}, span: { start: parent.start, end: tok.span.end } };
28195
28208
  } else if (parent?.kind === "dict" && !parent.key) {
28196
28209
  if (tok.kind === "dict-end") {
28197
- stack.pop();
28210
+ yield* pop();
28198
28211
  node = yield { kind: "dict", entries: parent.entries, span: { start: parent.start, end: tok.span.end } };
28199
28212
  } else if (tok.kind === "name") {
28200
28213
  charge();
@@ -28209,11 +28222,12 @@ function* parseValueSteps(lexer, maxDepth, repair = false, maxNodes = Infinity,
28209
28222
  throw new PdfError("E_PARSE", `Missing value for dictionary key /${parent.key.decoded}`);
28210
28223
  }
28211
28224
  charge();
28212
- if (stack.length > maxDepth) throw new PdfError("E_LIMIT", "PDF syntax nesting limit exceeded");
28225
+ if (depth > maxDepth) throw new PdfError("E_LIMIT", "PDF syntax nesting limit exceeded");
28213
28226
  if (tok.kind === "array-start") {
28214
- const backed = options.arrayStorage && (parent?.kind === "array" && parent.storedItems || parent?.kind === "dict" && (options.storedArrayKeys?.includes(parent.key.decoded) || matchesStoredPath()) || !parent && options.storeRootArray);
28215
- stack.push({
28227
+ const backed = options.arrayStorage && (parent?.kind === "array" && parent.storedItems || parent?.kind === "dict" && (options.storedArrayKeys?.includes(parent.key.decoded) || matchesStoredPath(parent)) || !parent && options.storeRootArray);
28228
+ yield* push({
28216
28229
  kind: "array",
28230
+ path: ancestorPath(parent),
28217
28231
  start: tok.span.start,
28218
28232
  items: [],
28219
28233
  tail: -1,
@@ -28222,12 +28236,12 @@ function* parseValueSteps(lexer, maxDepth, repair = false, maxNodes = Infinity,
28222
28236
  continue;
28223
28237
  }
28224
28238
  if (tok.kind === "dict-start") {
28225
- stack.push({ kind: "dict", start: tok.span.start, entries: [] });
28239
+ yield* push({ kind: "dict", path: ancestorPath(parent), start: tok.span.start, entries: [] });
28226
28240
  continue;
28227
28241
  }
28228
28242
  node = yield* parseLeafFromToken(tok, lexer);
28229
28243
  }
28230
- const container = stack.at(-1);
28244
+ const container = current;
28231
28245
  if (!container) return node;
28232
28246
  if (container.kind === "array") {
28233
28247
  if (container.storedItems) {
@@ -30819,7 +30833,7 @@ function* parseNodeFromLexerSteps(lexer, bytes, maxDepth, repair = false) {
30819
30833
  yield;
30820
30834
  step = work.next();
30821
30835
  } else {
30822
- if (step.value !== "token" && step.value.kind === "array-append") throw new TypeError("Stored arrays require asynchronous parsing");
30836
+ if (step.value !== "token" && step.value.kind !== "dict") throw new TypeError("Stored values require asynchronous parsing");
30823
30837
  step = work.next(step.value === "token" ? lexer.nextToken() : parseDictionaryStream(step.value, lexer, bytes));
30824
30838
  }
30825
30839
  }
@@ -31443,16 +31457,20 @@ function parseCosDocument(bytes, options = {}) {
31443
31457
 
31444
31458
  // packages/pdf-ast/src/content/array-cursor.ts
31445
31459
  var PdfArrayCursor = class {
31446
- constructor(array) {
31460
+ constructor(array, state) {
31447
31461
  this.array = array;
31448
31462
  this.length = array.storedItems?.length ?? array.items.length;
31449
31463
  if (!Number.isSafeInteger(this.length) || this.length < 0) throw new RangeError("Invalid stored array length");
31450
- this.position = array.storedItems?.position ?? -1;
31464
+ this.position = state?.position ?? array.storedItems?.position ?? -1;
31465
+ this.index = state?.index ?? 0;
31451
31466
  }
31452
31467
  array;
31453
31468
  index = 0;
31454
31469
  position;
31455
31470
  length;
31471
+ snapshot() {
31472
+ return { array: this.array, index: this.index, position: this.position };
31473
+ }
31456
31474
  *next() {
31457
31475
  if (this.index === this.length) {
31458
31476
  if (this.array.storedItems && this.position !== -1) throw new Error("Invalid stored array terminator");
@@ -31510,7 +31528,7 @@ function* sampledVertices(size, domain, encode3, inputs, sampleCount) {
31510
31528
  function* resolveNode(node, arrayKey) {
31511
31529
  if (!node) return void 0;
31512
31530
  const result = yield { kind: "resolve", node, ...arrayKey ? { arrayKey } : {} };
31513
- if (typeof result === "number" || typeof result === "boolean") throw new TypeError("Expected a PDF annotation object");
31531
+ if (typeof result === "number" || typeof result === "boolean" || result?.kind === "annotation-frame") throw new TypeError("Expected a PDF annotation object");
31514
31532
  return result;
31515
31533
  }
31516
31534
  function* resolveDict(node) {
@@ -31521,15 +31539,7 @@ function* resolveArray(node, arrayKey) {
31521
31539
  const result = yield* resolveNode(node, arrayKey);
31522
31540
  return result?.kind === "array" ? result : void 0;
31523
31541
  }
31524
- function* visitChildren(array, visit) {
31525
- const cursor = new PdfArrayCursor(array);
31526
- for (let step = yield* cursor.next(); !step.done; step = yield* cursor.next()) {
31527
- const found = yield* visit(step.value);
31528
- if (found !== void 0) return found;
31529
- }
31530
- return void 0;
31531
- }
31532
- function* extractPageAnnotationSteps(pageDict, root, maxDepth = Infinity) {
31542
+ function* extractPageAnnotationSteps(pageDict, root) {
31533
31543
  const annotsArr = yield* resolveArray(dictGet(pageDict, "Annots"), "Annots");
31534
31544
  if (!annotsArr) return;
31535
31545
  function* resolveDestToPageNum(destNode, depth = 0) {
@@ -31561,35 +31571,8 @@ function* extractPageAnnotationSteps(pageDict, root, maxDepth = Infinity) {
31561
31571
  }
31562
31572
  const namesDict = yield* resolveDict(dictGet(catalog, "Names"));
31563
31573
  const destsTree = namesDict ? dictGet(namesDict, "Dests") : void 0;
31564
- const active = /* @__PURE__ */ new Set();
31565
- function* searchNameTree(node, depth2 = 0) {
31566
- if (!node) return void 0;
31567
- if (depth2 > maxDepth) throw new PdfError("E_LIMIT", "PDF annotation name-tree depth limit exceeded");
31568
- const identity = node.kind === "ref" ? `${node.objectNumber}:${node.generationNumber}` : node;
31569
- if (active.has(identity)) return void 0;
31570
- active.add(identity);
31571
- try {
31572
- const treeDict = yield* resolveDict(node);
31573
- if (!treeDict) return void 0;
31574
- const namesArr = yield* resolveArray(dictGet(treeDict, "Names"));
31575
- if (namesArr) {
31576
- for (let i = 0; i + 1 < namesArr.items.length; i += 2) {
31577
- const kNode = yield* resolveNode(namesArr.items[i]);
31578
- const kStr = kNode?.kind === "string" ? decodePdfString(kNode) : kNode?.kind === "name" ? kNode.decoded : "";
31579
- if (kStr === destName) return namesArr.items[i + 1];
31580
- }
31581
- }
31582
- const kidsArr = yield* resolveArray(dictGet(treeDict, "Kids"), "Kids");
31583
- if (kidsArr) {
31584
- const found = yield* visitChildren(kidsArr, (kid) => searchNameTree(kid, depth2 + 1));
31585
- if (found) return found;
31586
- }
31587
- return void 0;
31588
- } finally {
31589
- active.delete(identity);
31590
- }
31591
- }
31592
- const treeFound = yield* searchNameTree(destsTree);
31574
+ const treeFound = yield { kind: "named-destination", node: destsTree, name: destName };
31575
+ if (typeof treeFound === "number" || typeof treeFound === "boolean" || treeFound?.kind === "annotation-frame") throw new TypeError("Expected a named destination object");
31593
31576
  if (treeFound) return yield* resolveDestToPageNum(treeFound, depth + 1);
31594
31577
  }
31595
31578
  }
@@ -31635,26 +31618,93 @@ function* extractPageAnnotationSteps(pageDict, root, maxDepth = Infinity) {
31635
31618
  }
31636
31619
  }
31637
31620
  function* annotationPageNumberSteps(root, reference, maxDepth = Infinity) {
31638
- let index2 = 0;
31639
- function* walk(node, depth = 0) {
31640
- if (!node) return void 0;
31621
+ let index2 = 0, depth = 0;
31622
+ const catalog = yield* resolveDict(root);
31623
+ let node = catalog ? dictGet(catalog, "Pages") : void 0;
31624
+ let cursor, cursorDepth = 0;
31625
+ while (true) {
31626
+ if (!node) {
31627
+ if (!cursor) {
31628
+ const frame = yield { kind: "pop-traversal-frame" };
31629
+ if (frame === void 0) return void 0;
31630
+ if (typeof frame !== "object" || frame.kind !== "annotation-frame") throw new TypeError("Expected an annotation page frame");
31631
+ cursor = new PdfArrayCursor(frame.cursor.array, frame.cursor);
31632
+ cursorDepth = frame.depth;
31633
+ }
31634
+ const step = yield* cursor.next();
31635
+ if (step.done) {
31636
+ cursor = void 0;
31637
+ continue;
31638
+ }
31639
+ node = step.value;
31640
+ depth = cursorDepth;
31641
+ if (!node) continue;
31642
+ }
31643
+ const current = node;
31644
+ node = void 0;
31641
31645
  if (depth > maxDepth) throw new PdfError("E_LIMIT", "PDF annotation page-tree depth limit exceeded");
31642
- if (node.kind === "ref" && !(yield { kind: "visit-page", reference: node })) return void 0;
31643
- const dict = yield* resolveDict(node);
31644
- if (!dict) return void 0;
31646
+ if (current.kind === "ref" && !(yield { kind: "visit-page", reference: current })) continue;
31647
+ const dict = yield* resolveDict(current);
31648
+ if (!dict) continue;
31645
31649
  const type = yield* resolveNode(dictGet(dict, "Type"));
31646
31650
  const kids = yield* resolveArray(dictGet(dict, "Kids"), "Kids");
31647
31651
  if (kids && (type?.kind !== "name" || type.decoded !== "Page")) {
31648
- const found = yield* visitChildren(kids, (child) => walk(child, depth + 1));
31649
- if (found !== void 0) return found;
31652
+ if (cursor) yield { kind: "push-traversal-frame", frame: { kind: "annotation-frame", cursor: cursor.snapshot(), depth: cursorDepth } };
31653
+ cursor = new PdfArrayCursor(kids);
31654
+ cursorDepth = depth + 1;
31650
31655
  } else {
31651
31656
  index2++;
31652
- if (node.kind === "ref" && node.objectNumber === reference.objectNumber) return index2;
31657
+ if (current.kind === "ref" && current.objectNumber === reference.objectNumber) return index2;
31653
31658
  }
31654
- return void 0;
31655
31659
  }
31656
- const catalog = yield* resolveDict(root);
31657
- return yield* walk(catalog ? dictGet(catalog, "Pages") : void 0);
31660
+ }
31661
+ function* annotationNameDestinationSteps(first, name, maxDepth = Infinity) {
31662
+ let node = first, depth = 0, cursor, cursorDepth = 0, identity;
31663
+ while (true) {
31664
+ if (!node) {
31665
+ if (!cursor) {
31666
+ const frame = yield { kind: "pop-traversal-frame" };
31667
+ if (frame === void 0) return void 0;
31668
+ if (typeof frame !== "object" || frame.kind !== "annotation-frame" || frame.identity === void 0) throw new TypeError("Expected an annotation name frame");
31669
+ cursor = new PdfArrayCursor(frame.cursor.array, frame.cursor);
31670
+ cursorDepth = frame.depth;
31671
+ identity = frame.identity;
31672
+ }
31673
+ const step = yield* cursor.next();
31674
+ if (step.done) {
31675
+ yield { kind: "leave-name-node", identity };
31676
+ cursor = void 0;
31677
+ continue;
31678
+ }
31679
+ node = step.value;
31680
+ depth = cursorDepth;
31681
+ if (!node) continue;
31682
+ }
31683
+ const current = node;
31684
+ node = void 0;
31685
+ if (depth > maxDepth) throw new PdfError("E_LIMIT", "PDF annotation name-tree depth limit exceeded");
31686
+ const entered = yield { kind: "enter-name-node", node: current };
31687
+ if (entered === void 0) continue;
31688
+ if (typeof entered !== "number") throw new TypeError("Expected an annotation node identity");
31689
+ const dict = yield* resolveDict(current);
31690
+ if (dict) {
31691
+ const names = yield* resolveArray(dictGet(dict, "Names"));
31692
+ if (names) for (let i = 0; i + 1 < names.items.length; i += 2) {
31693
+ const key = yield* resolveNode(names.items[i]);
31694
+ const decoded = key?.kind === "string" ? decodePdfString(key) : key?.kind === "name" ? key.decoded : "";
31695
+ if (decoded === name) return names.items[i + 1];
31696
+ }
31697
+ const kids = yield* resolveArray(dictGet(dict, "Kids"), "Kids");
31698
+ if (kids) {
31699
+ if (cursor) yield { kind: "push-traversal-frame", frame: { kind: "annotation-frame", cursor: cursor.snapshot(), depth: cursorDepth, identity } };
31700
+ cursor = new PdfArrayCursor(kids);
31701
+ cursorDepth = depth + 1;
31702
+ identity = entered;
31703
+ continue;
31704
+ }
31705
+ }
31706
+ yield { kind: "leave-name-node", identity: entered };
31707
+ }
31658
31708
  }
31659
31709
 
31660
31710
  // packages/pdf-ast/src/fonts/stored-widths.ts
@@ -43914,11 +43964,16 @@ function evaluateContentStreamToDisplayList(params) {
43914
43964
  function extractPageAnnotations(cosDoc, pageDict) {
43915
43965
  function pageNumber(reference) {
43916
43966
  const visited = /* @__PURE__ */ new Set();
43967
+ const frames = [];
43917
43968
  const work2 = annotationPageNumberSteps(cosDoc.rootRef, reference);
43918
43969
  let step2 = work2.next();
43919
43970
  while (!step2.done) {
43920
43971
  const request = step2.value;
43921
43972
  if (request.kind === "resolve") step2 = work2.next(cosDoc.resolve(request.node));
43973
+ else if (request.kind === "push-traversal-frame") {
43974
+ frames.push(request.frame);
43975
+ step2 = work2.next();
43976
+ } else if (request.kind === "pop-traversal-frame") step2 = work2.next(frames.pop());
43922
43977
  else if (request.kind === "visit-page") {
43923
43978
  const number = request.reference.objectNumber, added = !visited.has(number);
43924
43979
  visited.add(number);
@@ -43927,6 +43982,36 @@ function extractPageAnnotations(cosDoc, pageDict) {
43927
43982
  }
43928
43983
  return step2.value;
43929
43984
  }
43985
+ function namedDestination(node, name) {
43986
+ const identities = /* @__PURE__ */ new Map(), active = /* @__PURE__ */ new Set(), frames = [];
43987
+ const work2 = annotationNameDestinationSteps(node, name);
43988
+ let step2 = work2.next();
43989
+ while (!step2.done) {
43990
+ const request = step2.value;
43991
+ if (request.kind === "resolve") step2 = work2.next(cosDoc.resolve(request.node));
43992
+ else if (request.kind === "push-traversal-frame") {
43993
+ frames.push(request.frame);
43994
+ step2 = work2.next();
43995
+ } else if (request.kind === "pop-traversal-frame") step2 = work2.next(frames.pop());
43996
+ else if (request.kind === "enter-name-node") {
43997
+ const node2 = request.node, key = node2.kind === "ref" ? `${node2.objectNumber}:${node2.generationNumber}` : node2;
43998
+ let id = identities.get(key);
43999
+ if (id === void 0) {
44000
+ id = identities.size;
44001
+ identities.set(key, id);
44002
+ }
44003
+ if (active.has(id)) step2 = work2.next();
44004
+ else {
44005
+ active.add(id);
44006
+ step2 = work2.next(id);
44007
+ }
44008
+ } else if (request.kind === "leave-name-node") {
44009
+ active.delete(request.identity);
44010
+ step2 = work2.next();
44011
+ } else throw new TypeError("Unexpected annotation name lookup request");
44012
+ }
44013
+ return step2.value;
44014
+ }
43930
44015
  const output = [];
43931
44016
  const work = extractPageAnnotationSteps(pageDict, cosDoc.rootRef);
43932
44017
  let step = work.next();
@@ -43937,6 +44022,7 @@ function extractPageAnnotations(cosDoc, pageDict) {
43937
44022
  step = work.next();
43938
44023
  } else if (request.kind === "resolve") step = work.next(cosDoc.resolve(request.node));
43939
44024
  else if (request.kind === "page-number") step = work.next(pageNumber(request.reference));
44025
+ else if (request.kind === "named-destination") step = work.next(namedDestination(request.node, request.name));
43940
44026
  else throw new TypeError("Unexpected annotation request");
43941
44027
  }
43942
44028
  return output;
@@ -48128,6 +48214,7 @@ async function resolveStreamLength(entry, options) {
48128
48214
  async function readValue(lexer, depth, nodes, options) {
48129
48215
  const { signal } = options;
48130
48216
  const work = parseValueSteps(lexer, depth, options.recovery === "repair", nodes, options);
48217
+ const containers = options.containerStorage ? new StoredMetadataStack(options.containerStorage, signal) : void 0;
48131
48218
  let value;
48132
48219
  let turns = 0;
48133
48220
  try {
@@ -48144,6 +48231,16 @@ async function readValue(lexer, depth, nodes, options) {
48144
48231
  throw error;
48145
48232
  }
48146
48233
  step = work.next(position);
48234
+ } else if (request && request !== "token" && (request.kind === "container-push" || request.kind === "container-pop")) {
48235
+ let container;
48236
+ try {
48237
+ if (request.kind === "container-push") await containers.push(request.container);
48238
+ else container = await containers.pop();
48239
+ } catch (error) {
48240
+ options.onBackingError?.(error);
48241
+ throw error;
48242
+ }
48243
+ step = work.next(container);
48147
48244
  } else step = request === void 0 ? work.next() : work.next(request === "token" ? await lexer.nextToken() : request);
48148
48245
  if (++turns % 64 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
48149
48246
  }
@@ -57054,8 +57151,124 @@ function resolveDestinationPageIndex(doc, destOrActionNode) {
57054
57151
  return void 0;
57055
57152
  }
57056
57153
 
57057
- // packages/pdf-ast/src/retained-document.ts
57058
- import { PagedStorage as PagedStorage8 } from "@poe-platform/safe-fs/storage";
57154
+ // packages/pdf-ast/src/cos/name-index.ts
57155
+ var PdfNameIndex = class {
57156
+ constructor(storage, maximum10 = Infinity, signal) {
57157
+ this.storage = storage;
57158
+ this.maximum = maximum10;
57159
+ this.signal = signal;
57160
+ const limit10 = typeof maximum10 === "function" ? maximum10() : maximum10;
57161
+ if (limit10 !== Infinity && (!Number.isSafeInteger(limit10) || limit10 < 0)) throw new RangeError("Invalid name staging limit");
57162
+ }
57163
+ storage;
57164
+ maximum;
57165
+ signal;
57166
+ tail = /* @__PURE__ */ new Map();
57167
+ hot = /* @__PURE__ */ new Map();
57168
+ levels = [];
57169
+ nextNode = 2;
57170
+ nextName = 0;
57171
+ closed = false;
57172
+ get stagedBytes() {
57173
+ return this.levels.reduce((sum, index2) => sum + (index2?.size ?? 0) * 32, 0);
57174
+ }
57175
+ async get(edge) {
57176
+ if (this.tail.has(edge)) return this.tail.get(edge);
57177
+ if (this.hot.has(edge)) return this.hot.get(edge);
57178
+ for (const level of this.levels) {
57179
+ const entry = await level?.get(edge, this.signal);
57180
+ if (entry) {
57181
+ if (this.hot.size < 256) this.hot.set(edge, entry.offset);
57182
+ return entry.offset;
57183
+ }
57184
+ }
57185
+ return void 0;
57186
+ }
57187
+ async insert(edge, node) {
57188
+ this.tail.set(edge, node);
57189
+ if (this.hot.size < 256) this.hot.set(edge, node);
57190
+ if (this.tail.size < 64) return;
57191
+ let level = 0;
57192
+ while (this.levels[level]) level++;
57193
+ const inputs = this.levels.slice(0, level);
57194
+ const tail = this.tail;
57195
+ const signal = this.signal;
57196
+ async function* rows() {
57197
+ for (const [objectNumber, offset] of tail) yield { objectNumber, offset, type: "uncompressed" };
57198
+ for (const index2 of inputs) yield* index2.entries(signal);
57199
+ }
57200
+ const limit10 = typeof this.maximum === "function" ? this.maximum() : this.maximum;
57201
+ const remaining = Math.min(limit10, Number.MAX_SAFE_INTEGER) - this.stagedBytes;
57202
+ if (remaining < 0) throw new PdfError("E_LIMIT", "PDF name staging byte limit exceeded");
57203
+ const combined = await PdfObjectIndex.build(rows(), this.storage, {
57204
+ runEntries: 64,
57205
+ chunkBytes: 2048,
57206
+ cacheBytes: 2048,
57207
+ maxStagingBytes: remaining,
57208
+ ...signal ? { signal } : {}
57209
+ });
57210
+ try {
57211
+ for (let i = 0; i < level; i++) {
57212
+ await this.levels[i].close();
57213
+ this.levels[i] = void 0;
57214
+ }
57215
+ this.levels[level] = combined;
57216
+ this.tail.clear();
57217
+ } catch (error) {
57218
+ try {
57219
+ await combined.close();
57220
+ } catch {
57221
+ }
57222
+ throw error;
57223
+ }
57224
+ }
57225
+ async intern(value) {
57226
+ if (this.closed) throw new PdfError("E_CAPABILITY", "PDF name index is closed");
57227
+ this.signal?.throwIfAborted();
57228
+ let node = 1, newPath = false;
57229
+ const units = typeof value === "string" ? (function* () {
57230
+ for (let i = 0; i < value.length; i++) yield value.charCodeAt(i);
57231
+ })() : value;
57232
+ let work = 0;
57233
+ for await (const code of units) {
57234
+ this.signal?.throwIfAborted();
57235
+ if (!Number.isInteger(code) || code < 0 || code > 65535) throw new RangeError("Invalid PDF name code unit");
57236
+ if (++work % 512 === 0) {
57237
+ await new Promise((resolve2) => setTimeout(resolve2, 0));
57238
+ this.signal?.throwIfAborted();
57239
+ }
57240
+ for (const unit of [code & 255, code >>> 8]) {
57241
+ const edge = node * 257 + unit + 1;
57242
+ let child = newPath ? void 0 : await this.get(edge);
57243
+ if (child === void 0) {
57244
+ if (this.nextNode > Math.floor(Number.MAX_SAFE_INTEGER / 257) - 1) throw new PdfError("E_LIMIT", "PDF name index address limit exceeded");
57245
+ child = this.nextNode++;
57246
+ await this.insert(edge, child);
57247
+ newPath = true;
57248
+ }
57249
+ node = child;
57250
+ }
57251
+ }
57252
+ const terminal = node * 257;
57253
+ const existing = newPath ? void 0 : await this.get(terminal);
57254
+ if (existing !== void 0) return { index: existing, added: false };
57255
+ const index2 = this.nextName++;
57256
+ await this.insert(terminal, index2);
57257
+ return { index: index2, added: true };
57258
+ }
57259
+ async close() {
57260
+ if (this.closed) return;
57261
+ this.closed = true;
57262
+ const results = await Promise.allSettled(this.levels.map((index2) => index2?.close()));
57263
+ this.tail.clear();
57264
+ this.hot.clear();
57265
+ this.levels.length = 0;
57266
+ for (const result of results) if (result.status === "rejected") throw result.reason;
57267
+ }
57268
+ };
57269
+
57270
+ // packages/pdf-ast/src/extract/retained-form-fields.ts
57271
+ import { IntegerTable as IntegerTable4, PagedStorage as PagedStorage6 } from "@poe-platform/safe-fs/storage";
57059
57272
 
57060
57273
  // packages/pdf-ast/src/cos/mutable-object-store.ts
57061
57274
  import { IntegerTable as IntegerTable3, PagedStorage as PagedStorage5 } from "@poe-platform/safe-fs/storage";
@@ -57585,6 +57798,290 @@ var PdfMutableObjectStore = class {
57585
57798
  }
57586
57799
  };
57587
57800
 
57801
+ // packages/pdf-ast/src/extract/retained-form-fields.ts
57802
+ async function inheritedRetainedFieldEntry(document2, storage, dict, key, options) {
57803
+ const seen = new PdfReferenceSet(storage, options.maxStagingBytes, options.signal);
57804
+ let current = dict, depth = 0, failed = false;
57805
+ try {
57806
+ while (current) {
57807
+ options.signal?.throwIfAborted();
57808
+ if (++depth > (options.maxDepth ?? document2.depthLimit)) throw new PdfError("E_LIMIT", "PDF form field depth limit exceeded");
57809
+ if (depth % 64 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
57810
+ const value = dictGet(current, key);
57811
+ if (value !== void 0) return (await document2.lookup(value))?.value;
57812
+ const parent = dictGet(current, "Parent");
57813
+ if (parent?.kind === "ref" && !await seen.add(parent.objectNumber)) return;
57814
+ const found = await document2.lookup(parent);
57815
+ current = !found?.stream && found?.value.kind === "dict" ? found.value : void 0;
57816
+ }
57817
+ } catch (error) {
57818
+ failed = true;
57819
+ throw error;
57820
+ } finally {
57821
+ await seen.close().catch((error) => {
57822
+ if (!failed) throw error;
57823
+ });
57824
+ }
57825
+ }
57826
+ async function* walkRetainedFieldEntries(document2, storage, options = {}) {
57827
+ const signal = options.signal ?? new AbortController().signal, maxDepth = options.maxDepth ?? document2.depthLimit;
57828
+ signal.throwIfAborted();
57829
+ const frames = new PdfMutableObjectStore(storage, { signal, ...options.maxStagingBytes === void 0 ? {} : { maxStagingBytes: options.maxStagingBytes } });
57830
+ const backing = new PagedStorage6({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), active = new IntegerTable4(backing, 64);
57831
+ let pending = 0, work = 0, failed = false;
57832
+ async function checkpoint(depth = 0) {
57833
+ signal.throwIfAborted();
57834
+ if (depth > maxDepth) throw new PdfError("E_LIMIT", "PDF form field depth limit exceeded");
57835
+ if (++work % 64 === 0) await new Promise((resolve3) => setTimeout(resolve3, 0));
57836
+ signal.throwIfAborted();
57837
+ }
57838
+ async function resolve2(node) {
57839
+ const found = await document2.lookup(node);
57840
+ return found?.stream ? void 0 : found?.value;
57841
+ }
57842
+ async function push(node, prefix, ft, depth, flags = 0, justification = 0, maxLength) {
57843
+ await frames.set({ objectNumber: ++pending, generationNumber: 0, value: cosArray([node, cosString(prefix), cosString(ft), cosNumber(depth), cosNumber(flags), cosNumber(justification), maxLength === void 0 ? cosNull() : cosNumber(maxLength)]) });
57844
+ }
57845
+ try {
57846
+ const root = await resolve2(document2.crossReference.rootRef), form = root?.kind === "dict" ? await resolve2(dictGet(root, "AcroForm")) : void 0;
57847
+ const fields2 = form?.kind === "dict" ? await resolve2(dictGet(form, "Fields")) : void 0;
57848
+ if (fields2?.kind !== "array") return;
57849
+ for (let i = fields2.items.length - 1; i >= 0; i--) {
57850
+ await checkpoint();
57851
+ await push(fields2.items[i], "", "", 0);
57852
+ }
57853
+ while (pending) {
57854
+ const frame = (await frames.get(pending--)).value;
57855
+ if (frame.kind !== "array") throw new PdfError("E_PARSE", "Invalid form traversal frame");
57856
+ const [node, prefixNode, ftNode, depthNode, flagsNode, qNode, maxNode] = frame.items;
57857
+ if (frame.items.length === 1 && node?.kind === "number") {
57858
+ await active.set(BigInt(node.value), 0n);
57859
+ continue;
57860
+ }
57861
+ if (!node || prefixNode?.kind !== "string" || ftNode?.kind !== "string" || depthNode?.kind !== "number") throw new PdfError("E_PARSE", "Invalid form traversal frame");
57862
+ await checkpoint(depthNode.value);
57863
+ if (node.kind === "ref") {
57864
+ if (await active.get(BigInt(node.objectNumber)) === 1n) continue;
57865
+ await active.set(BigInt(node.objectNumber), 1n);
57866
+ await frames.set({ objectNumber: ++pending, generationNumber: 0, value: cosArray([cosNumber(node.objectNumber)]) });
57867
+ }
57868
+ const dict = await resolve2(node);
57869
+ if (dict?.kind !== "dict") continue;
57870
+ const named = await resolve2(dictGet(dict, "T")), ownFt = await resolve2(dictGet(dict, "FT"));
57871
+ const partial = named?.kind === "string" ? decodePdfString(named) : named?.kind === "name" ? named.decoded : "", prefix = decodePdfString(prefixNode);
57872
+ const name = prefix && partial ? `${prefix}.${partial}` : partial || prefix, ft = ownFt?.kind === "name" ? ownFt.decoded : decodePdfString(ftNode);
57873
+ const ownFlags = await resolve2(dictGet(dict, "Ff")), ownQ = await resolve2(dictGet(dict, "Q")), ownMax = await resolve2(dictGet(dict, "MaxLen"));
57874
+ const flags = ownFlags?.kind === "number" ? ownFlags.value : flagsNode?.kind === "number" ? flagsNode.value : 0;
57875
+ const justification = ownQ?.kind === "number" ? ownQ.value : qNode?.kind === "number" ? qNode.value : 0;
57876
+ const maxLength = ownMax?.kind === "number" ? ownMax.value : maxNode?.kind === "number" ? maxNode.value : void 0;
57877
+ const kids = await resolve2(dictGet(dict, "Kids"));
57878
+ if (kids?.kind === "array" && kids.items.length) {
57879
+ let namedKids = false;
57880
+ for (const kid of kids.items) {
57881
+ await checkpoint();
57882
+ const value = await resolve2(kid);
57883
+ if (value?.kind === "dict" && dictGet(value, "T")) {
57884
+ namedKids = true;
57885
+ break;
57886
+ }
57887
+ }
57888
+ if (namedKids || !ft || !name) {
57889
+ for (let i = kids.items.length - 1; i >= 0; i--) {
57890
+ await checkpoint();
57891
+ await push(kids.items[i], name, ft, depthNode.value + 1, flags, justification, maxLength);
57892
+ }
57893
+ continue;
57894
+ }
57895
+ }
57896
+ if (!name) continue;
57897
+ yield { name, dict, ft, flags, justification, maxLength };
57898
+ }
57899
+ } catch (error) {
57900
+ failed = true;
57901
+ throw error;
57902
+ } finally {
57903
+ const results = await Promise.allSettled([frames.close(), backing.close()]);
57904
+ if (!failed) {
57905
+ for (const result of results) if (result.status === "rejected") await Promise.reject(result.reason);
57906
+ }
57907
+ }
57908
+ }
57909
+ async function* walkRetainedFormFields(document2, storage, options = {}) {
57910
+ let work = 0;
57911
+ async function resolve2(node) {
57912
+ if (++work % 64 === 0) await new Promise((resolve3) => setTimeout(resolve3, 0));
57913
+ const found = await document2.lookup(node);
57914
+ return found?.stream ? void 0 : found?.value;
57915
+ }
57916
+ for await (const { name, dict, ft } of walkRetainedFieldEntries(document2, storage, options)) {
57917
+ const value = await inheritedRetainedFieldEntry(document2, storage, dict, "V", options);
57918
+ if (ft === "Btn") {
57919
+ yield { name, type: "checkbox", value: value?.kind === "name" ? value.decoded !== "Off" : value?.kind === "boolean" ? value.value : false };
57920
+ continue;
57921
+ }
57922
+ let text = value?.kind === "string" ? decodePdfString(value) : value?.kind === "name" ? value.decoded : "";
57923
+ if (value?.kind === "array") {
57924
+ let first = true;
57925
+ for (const item of value.items) {
57926
+ options.signal?.throwIfAborted();
57927
+ const found = await resolve2(item);
57928
+ if (found?.kind === "string" || found?.kind === "name") {
57929
+ text += `${first ? "" : ", "}${found.kind === "string" ? decodePdfString(found) : found.decoded}`;
57930
+ first = false;
57931
+ }
57932
+ }
57933
+ }
57934
+ yield { name, type: ft === "Tx" ? "text" : ft === "Ch" ? "choice" : "unknown", value: text };
57935
+ }
57936
+ }
57937
+
57938
+ // packages/pdf-ast/src/extract/retained-form-field-details.ts
57939
+ async function* walkRetainedFormFieldDetails(document2, storage, options = {}) {
57940
+ let work = 0;
57941
+ async function checkpoint() {
57942
+ options.signal?.throwIfAborted();
57943
+ if (++work % 64 === 0) await new Promise((resolve3) => setTimeout(resolve3, 0));
57944
+ options.signal?.throwIfAborted();
57945
+ }
57946
+ async function resolve2(node) {
57947
+ await checkpoint();
57948
+ const found = await document2.lookup(node);
57949
+ return found?.stream ? void 0 : found?.value;
57950
+ }
57951
+ const text = (node) => node?.kind === "string" ? decodePdfString(node) : node?.kind === "name" ? node.decoded : void 0;
57952
+ for await (const entry of walkRetainedFieldEntries(document2, storage, options)) {
57953
+ let owned2 = function(producer) {
57954
+ async function* visit() {
57955
+ assertActive();
57956
+ readers.add(reader);
57957
+ try {
57958
+ for await (const value2 of producer()) {
57959
+ assertActive();
57960
+ yield value2;
57961
+ }
57962
+ } finally {
57963
+ readers.delete(reader);
57964
+ }
57965
+ }
57966
+ const reader = visit();
57967
+ return reader;
57968
+ };
57969
+ var owned = owned2;
57970
+ const { dict, ft } = entry;
57971
+ let active = true;
57972
+ const readers = /* @__PURE__ */ new Set();
57973
+ const assertActive = () => {
57974
+ options.signal?.throwIfAborted();
57975
+ if (!active) throw new PdfError("E_CAPABILITY", "Retained form field is no longer active");
57976
+ };
57977
+ async function* stateOptions() {
57978
+ const seen = new PdfNameIndex(storage, options.maxStagingBytes, options.signal);
57979
+ let count = 0, failed2 = false;
57980
+ async function* unique(value2) {
57981
+ assertActive();
57982
+ if (value2 && (await seen.intern(value2)).added) {
57983
+ count++;
57984
+ yield value2;
57985
+ }
57986
+ }
57987
+ async function* appearances(field2) {
57988
+ const appearance = await resolve2(dictGet(field2, "AP"));
57989
+ const normal = appearance?.kind === "dict" ? await resolve2(dictGet(appearance, "N")) : void 0;
57990
+ if (normal?.kind === "dict") for (const pair of normal.entries) {
57991
+ await checkpoint();
57992
+ yield* unique(pair.key.decoded);
57993
+ }
57994
+ }
57995
+ try {
57996
+ if (ft === "Btn") {
57997
+ yield* unique("Off");
57998
+ yield* appearances(dict);
57999
+ const kids = await resolve2(dictGet(dict, "Kids"));
58000
+ if (kids?.kind === "array") for (const kid of kids.items) {
58001
+ const field2 = await resolve2(kid);
58002
+ if (field2?.kind === "dict") yield* appearances(field2);
58003
+ }
58004
+ if (count === 1) yield* unique("Yes");
58005
+ }
58006
+ const choices = await inheritedRetainedFieldEntry(document2, storage, dict, "Opt", options);
58007
+ if (choices?.kind === "array") for (const item of choices.items) {
58008
+ let value2 = await resolve2(item);
58009
+ if (value2?.kind === "array" && value2.items.length) value2 = await resolve2(value2.items[value2.items.length - 1]);
58010
+ yield* unique(text(value2));
58011
+ }
58012
+ } catch (error) {
58013
+ failed2 = true;
58014
+ throw error;
58015
+ } finally {
58016
+ await seen.close().catch((error) => {
58017
+ if (!failed2) throw error;
58018
+ });
58019
+ }
58020
+ }
58021
+ const value = await inheritedRetainedFieldEntry(document2, storage, dict, "V", options);
58022
+ const defaultValue = text(await inheritedRetainedFieldEntry(document2, storage, dict, "DV", options));
58023
+ const altName = text(await inheritedRetainedFieldEntry(document2, storage, dict, "TU", options));
58024
+ const checked = ft === "Btn" ? value?.kind === "name" ? value.decoded !== "Off" : value?.kind === "boolean" ? value.value : false : void 0;
58025
+ let stateValue;
58026
+ if (ft === "Btn") {
58027
+ stateValue = value?.kind === "name" ? value.decoded : checked ? "Yes" : "Off";
58028
+ if (checked && value?.kind !== "name") {
58029
+ for await (const option of stateOptions()) if (option !== "Off") {
58030
+ stateValue = option;
58031
+ break;
58032
+ }
58033
+ }
58034
+ }
58035
+ async function* values() {
58036
+ if (stateValue !== void 0) {
58037
+ yield stateValue;
58038
+ return;
58039
+ }
58040
+ if (value?.kind !== "array") {
58041
+ yield text(value) ?? "";
58042
+ return;
58043
+ }
58044
+ let any = false;
58045
+ for (const item of value.items) {
58046
+ const selected = text(await resolve2(item));
58047
+ if (selected !== void 0) {
58048
+ any = true;
58049
+ yield selected;
58050
+ }
58051
+ }
58052
+ if (!any) yield "";
58053
+ }
58054
+ let failed = false;
58055
+ try {
58056
+ yield {
58057
+ name: entry.name,
58058
+ type: ft === "Btn" ? "checkbox" : ft === "Ch" ? "choice" : ft === "Tx" ? "text" : "unknown",
58059
+ flags: entry.flags,
58060
+ justification: entry.justification === 1 ? "Centered" : entry.justification === 2 ? "Right" : "Left",
58061
+ maxLength: entry.maxLength,
58062
+ altName,
58063
+ defaultValue,
58064
+ checked,
58065
+ stateValue,
58066
+ values: () => owned2(values),
58067
+ options: () => owned2(stateOptions)
58068
+ };
58069
+ } catch (error) {
58070
+ failed = true;
58071
+ throw error;
58072
+ } finally {
58073
+ active = false;
58074
+ const results = await Promise.allSettled([...readers].map((reader) => reader.return()));
58075
+ if (!failed) {
58076
+ for (const result of results) if (result.status === "rejected") await Promise.reject(result.reason);
58077
+ }
58078
+ }
58079
+ }
58080
+ }
58081
+
58082
+ // packages/pdf-ast/src/retained-document.ts
58083
+ import { IntegerTable as IntegerTable5, PagedStorage as PagedStorage8 } from "@poe-platform/safe-fs/storage";
58084
+
57588
58085
  // packages/pdf-ast/src/edit/retained-merge-outlines.ts
57589
58086
  var PdfMergeOutlines = class {
57590
58087
  constructor(storage, signal, maxDepth = Infinity) {
@@ -57792,127 +58289,6 @@ async function* walkRetainedPageLabels(document2, storage, options = {}) {
57792
58289
  }
57793
58290
  }
57794
58291
 
57795
- // packages/pdf-ast/src/extract/retained-form-fields.ts
57796
- import { IntegerTable as IntegerTable4, PagedStorage as PagedStorage6 } from "@poe-platform/safe-fs/storage";
57797
- async function* walkRetainedFormFields(document2, storage, options = {}) {
57798
- const signal = options.signal ?? new AbortController().signal, maxDepth = options.maxDepth ?? document2.depthLimit;
57799
- signal.throwIfAborted();
57800
- const frames = new PdfMutableObjectStore(storage, { signal, ...options.maxStagingBytes === void 0 ? {} : { maxStagingBytes: options.maxStagingBytes } });
57801
- const backing = new PagedStorage6({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), active = new IntegerTable4(backing, 64);
57802
- let pending = 0, work = 0, failed = false;
57803
- async function checkpoint(depth = 0) {
57804
- signal.throwIfAborted();
57805
- if (depth > maxDepth) throw new PdfError("E_LIMIT", "PDF form field depth limit exceeded");
57806
- if (++work % 64 === 0) await new Promise((resolve3) => setTimeout(resolve3, 0));
57807
- signal.throwIfAborted();
57808
- }
57809
- async function resolve2(node) {
57810
- const found = await document2.lookup(node);
57811
- return found?.stream ? void 0 : found?.value;
57812
- }
57813
- async function push(node, prefix, ft, depth) {
57814
- await frames.set({ objectNumber: ++pending, generationNumber: 0, value: cosArray([node, cosString(prefix), cosString(ft), cosNumber(depth)]) });
57815
- }
57816
- async function inheritedValue(dict) {
57817
- const seen = new PdfReferenceSet(storage, options.maxStagingBytes, signal);
57818
- let current = dict, depth = 0, failed2 = false;
57819
- try {
57820
- while (current) {
57821
- await checkpoint(++depth);
57822
- const value = dictGet(current, "V");
57823
- if (value !== void 0) return await resolve2(value);
57824
- const parent = dictGet(current, "Parent");
57825
- if (parent?.kind === "ref" && !await seen.add(parent.objectNumber)) return;
57826
- const found = await resolve2(parent);
57827
- current = found?.kind === "dict" ? found : void 0;
57828
- }
57829
- } catch (error) {
57830
- failed2 = true;
57831
- throw error;
57832
- } finally {
57833
- await seen.close().catch((error) => {
57834
- if (!failed2) throw error;
57835
- });
57836
- }
57837
- }
57838
- try {
57839
- const root = await resolve2(document2.crossReference.rootRef), form = root?.kind === "dict" ? await resolve2(dictGet(root, "AcroForm")) : void 0;
57840
- const fields2 = form?.kind === "dict" ? await resolve2(dictGet(form, "Fields")) : void 0;
57841
- if (fields2?.kind !== "array") return;
57842
- for (let i = fields2.items.length - 1; i >= 0; i--) {
57843
- await checkpoint();
57844
- await push(fields2.items[i], "", "", 0);
57845
- }
57846
- while (pending) {
57847
- const frame = (await frames.get(pending--)).value;
57848
- if (frame.kind !== "array") throw new PdfError("E_PARSE", "Invalid form traversal frame");
57849
- const [node, prefixNode, ftNode, depthNode] = frame.items;
57850
- if (frame.items.length === 1 && node?.kind === "number") {
57851
- await active.set(BigInt(node.value), 0n);
57852
- continue;
57853
- }
57854
- if (!node || prefixNode?.kind !== "string" || ftNode?.kind !== "string" || depthNode?.kind !== "number") throw new PdfError("E_PARSE", "Invalid form traversal frame");
57855
- await checkpoint(depthNode.value);
57856
- if (node.kind === "ref") {
57857
- if (await active.get(BigInt(node.objectNumber)) === 1n) continue;
57858
- await active.set(BigInt(node.objectNumber), 1n);
57859
- await frames.set({ objectNumber: ++pending, generationNumber: 0, value: cosArray([cosNumber(node.objectNumber)]) });
57860
- }
57861
- const dict = await resolve2(node);
57862
- if (dict?.kind !== "dict") continue;
57863
- const named = await resolve2(dictGet(dict, "T")), ownFt = await resolve2(dictGet(dict, "FT"));
57864
- const partial = named?.kind === "string" ? decodePdfString(named) : named?.kind === "name" ? named.decoded : "", prefix = decodePdfString(prefixNode);
57865
- const name = prefix && partial ? `${prefix}.${partial}` : partial || prefix, ft = ownFt?.kind === "name" ? ownFt.decoded : decodePdfString(ftNode);
57866
- const kids = await resolve2(dictGet(dict, "Kids"));
57867
- if (kids?.kind === "array" && kids.items.length) {
57868
- let namedKids = false;
57869
- for (const kid of kids.items) {
57870
- await checkpoint();
57871
- const value2 = await resolve2(kid);
57872
- if (value2?.kind === "dict" && dictGet(value2, "T")) {
57873
- namedKids = true;
57874
- break;
57875
- }
57876
- }
57877
- if (namedKids || !ft || !name) {
57878
- for (let i = kids.items.length - 1; i >= 0; i--) {
57879
- await checkpoint();
57880
- await push(kids.items[i], name, ft, depthNode.value + 1);
57881
- }
57882
- continue;
57883
- }
57884
- }
57885
- if (!name) continue;
57886
- const value = await inheritedValue(dict);
57887
- if (ft === "Btn") {
57888
- yield { name, type: "checkbox", value: value?.kind === "name" ? value.decoded !== "Off" : value?.kind === "boolean" ? value.value : false };
57889
- continue;
57890
- }
57891
- let text = value?.kind === "string" ? decodePdfString(value) : value?.kind === "name" ? value.decoded : "";
57892
- if (value?.kind === "array") {
57893
- let first = true;
57894
- for (const item of value.items) {
57895
- await checkpoint();
57896
- const found = await resolve2(item);
57897
- if (found?.kind === "string" || found?.kind === "name") {
57898
- text += `${first ? "" : ", "}${found.kind === "string" ? decodePdfString(found) : found.decoded}`;
57899
- first = false;
57900
- }
57901
- }
57902
- }
57903
- yield { name, type: ft === "Tx" ? "text" : ft === "Ch" ? "choice" : "unknown", value: text };
57904
- }
57905
- } catch (error) {
57906
- failed = true;
57907
- throw error;
57908
- } finally {
57909
- const results = await Promise.allSettled([frames.close(), backing.close()]);
57910
- if (!failed) {
57911
- for (const result of results) if (result.status === "rejected") await Promise.reject(result.reason);
57912
- }
57913
- }
57914
- }
57915
-
57916
58292
  // packages/pdf-ast/src/cos/stored-object-reader.ts
57917
58293
  async function openStoredPdfObjectReader(store, storage, options) {
57918
58294
  let maximum10 = 0, closed = false;
@@ -58684,124 +59060,6 @@ async function prepareRetainedPageContent(document2, page2, pageResources, stora
58684
59060
 
58685
59061
  // packages/pdf-ast/src/staged-outputs.ts
58686
59062
  import { listenForAbort as listenForAbort3 } from "@poe-platform/safe-fs/contracts";
58687
-
58688
- // packages/pdf-ast/src/cos/name-index.ts
58689
- var PdfNameIndex = class {
58690
- constructor(storage, maximum10 = Infinity, signal) {
58691
- this.storage = storage;
58692
- this.maximum = maximum10;
58693
- this.signal = signal;
58694
- const limit10 = typeof maximum10 === "function" ? maximum10() : maximum10;
58695
- if (limit10 !== Infinity && (!Number.isSafeInteger(limit10) || limit10 < 0)) throw new RangeError("Invalid name staging limit");
58696
- }
58697
- storage;
58698
- maximum;
58699
- signal;
58700
- tail = /* @__PURE__ */ new Map();
58701
- hot = /* @__PURE__ */ new Map();
58702
- levels = [];
58703
- nextNode = 2;
58704
- nextName = 0;
58705
- closed = false;
58706
- get stagedBytes() {
58707
- return this.levels.reduce((sum, index2) => sum + (index2?.size ?? 0) * 32, 0);
58708
- }
58709
- async get(edge) {
58710
- if (this.tail.has(edge)) return this.tail.get(edge);
58711
- if (this.hot.has(edge)) return this.hot.get(edge);
58712
- for (const level of this.levels) {
58713
- const entry = await level?.get(edge, this.signal);
58714
- if (entry) {
58715
- if (this.hot.size < 256) this.hot.set(edge, entry.offset);
58716
- return entry.offset;
58717
- }
58718
- }
58719
- return void 0;
58720
- }
58721
- async insert(edge, node) {
58722
- this.tail.set(edge, node);
58723
- if (this.hot.size < 256) this.hot.set(edge, node);
58724
- if (this.tail.size < 64) return;
58725
- let level = 0;
58726
- while (this.levels[level]) level++;
58727
- const inputs = this.levels.slice(0, level);
58728
- const tail = this.tail;
58729
- const signal = this.signal;
58730
- async function* rows() {
58731
- for (const [objectNumber, offset] of tail) yield { objectNumber, offset, type: "uncompressed" };
58732
- for (const index2 of inputs) yield* index2.entries(signal);
58733
- }
58734
- const limit10 = typeof this.maximum === "function" ? this.maximum() : this.maximum;
58735
- const remaining = Math.min(limit10, Number.MAX_SAFE_INTEGER) - this.stagedBytes;
58736
- if (remaining < 0) throw new PdfError("E_LIMIT", "PDF name staging byte limit exceeded");
58737
- const combined = await PdfObjectIndex.build(rows(), this.storage, {
58738
- runEntries: 64,
58739
- chunkBytes: 2048,
58740
- cacheBytes: 2048,
58741
- maxStagingBytes: remaining,
58742
- ...signal ? { signal } : {}
58743
- });
58744
- try {
58745
- for (let i = 0; i < level; i++) {
58746
- await this.levels[i].close();
58747
- this.levels[i] = void 0;
58748
- }
58749
- this.levels[level] = combined;
58750
- this.tail.clear();
58751
- } catch (error) {
58752
- try {
58753
- await combined.close();
58754
- } catch {
58755
- }
58756
- throw error;
58757
- }
58758
- }
58759
- async intern(value) {
58760
- if (this.closed) throw new PdfError("E_CAPABILITY", "PDF name index is closed");
58761
- this.signal?.throwIfAborted();
58762
- let node = 1, newPath = false;
58763
- const units = typeof value === "string" ? (function* () {
58764
- for (let i = 0; i < value.length; i++) yield value.charCodeAt(i);
58765
- })() : value;
58766
- let work = 0;
58767
- for await (const code of units) {
58768
- this.signal?.throwIfAborted();
58769
- if (!Number.isInteger(code) || code < 0 || code > 65535) throw new RangeError("Invalid PDF name code unit");
58770
- if (++work % 512 === 0) {
58771
- await new Promise((resolve2) => setTimeout(resolve2, 0));
58772
- this.signal?.throwIfAborted();
58773
- }
58774
- for (const unit of [code & 255, code >>> 8]) {
58775
- const edge = node * 257 + unit + 1;
58776
- let child = newPath ? void 0 : await this.get(edge);
58777
- if (child === void 0) {
58778
- if (this.nextNode > Math.floor(Number.MAX_SAFE_INTEGER / 257) - 1) throw new PdfError("E_LIMIT", "PDF name index address limit exceeded");
58779
- child = this.nextNode++;
58780
- await this.insert(edge, child);
58781
- newPath = true;
58782
- }
58783
- node = child;
58784
- }
58785
- }
58786
- const terminal = node * 257;
58787
- const existing = newPath ? void 0 : await this.get(terminal);
58788
- if (existing !== void 0) return { index: existing, added: false };
58789
- const index2 = this.nextName++;
58790
- await this.insert(terminal, index2);
58791
- return { index: index2, added: true };
58792
- }
58793
- async close() {
58794
- if (this.closed) return;
58795
- this.closed = true;
58796
- const results = await Promise.allSettled(this.levels.map((index2) => index2?.close()));
58797
- this.tail.clear();
58798
- this.hot.clear();
58799
- this.levels.length = 0;
58800
- for (const result of results) if (result.status === "rejected") throw result.reason;
58801
- }
58802
- };
58803
-
58804
- // packages/pdf-ast/src/staged-outputs.ts
58805
59063
  function maximum7(value, fallback) {
58806
59064
  const result = value ?? fallback;
58807
59065
  if (result !== Infinity && (!Number.isSafeInteger(result) || result < 0)) throw new RangeError("Invalid PDF output limit");
@@ -59911,19 +60169,62 @@ var PdfRetainedDocument = class _PdfRetainedDocument {
59911
60169
  ...arrayPathPrefix.length && arrays.storedStringKeys?.includes(arrayPathPrefix[arrayPathPrefix.length - 1]) ? { storeRootString: true } : {}
59912
60170
  };
59913
60171
  let reference;
59914
- const visited = /* @__PURE__ */ new Set();
60172
+ const visited = new PdfReferenceSet(this.storage, this.options.maxTraversalStagingBytes, this.options.signal);
59915
60173
  const maximum10 = this.options.maxRecursionDepth ?? 100;
59916
- while (node?.kind === "ref") {
59917
- if (visited.size >= maximum10) throw new PdfError("E_LIMIT", "PDF reference depth limit exceeded");
59918
- if (visited.has(node.objectNumber)) throw new PdfError("E_PARSE", "Circular PDF indirect reference");
59919
- visited.add(node.objectNumber);
59920
- reference = node;
59921
- const object = await this.objects.get(node.objectNumber, node.generationNumber, arrays);
59922
- this.assertOpen();
59923
- if (object?.stream) return { value: object.value, reference, stream: object.stream };
59924
- node = object?.value;
60174
+ let depth = 0, failed = false;
60175
+ try {
60176
+ while (node?.kind === "ref") {
60177
+ if (depth >= maximum10) throw new PdfError("E_LIMIT", "PDF reference depth limit exceeded");
60178
+ if (!await visited.add(node.objectNumber)) throw new PdfError("E_PARSE", "Circular PDF indirect reference");
60179
+ if (++depth % 64 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
60180
+ this.assertOpen();
60181
+ reference = node;
60182
+ const object = await this.objects.get(node.objectNumber, node.generationNumber, arrays);
60183
+ this.assertOpen();
60184
+ if (object?.stream) return { value: object.value, reference, stream: object.stream };
60185
+ node = object?.value;
60186
+ }
60187
+ return node ? { value: node, ...reference ? { reference } : {} } : void 0;
60188
+ } catch (error) {
60189
+ failed = true;
60190
+ throw error;
60191
+ } finally {
60192
+ await visited.close().catch((error) => {
60193
+ if (!failed) throw error;
60194
+ });
60195
+ }
60196
+ }
60197
+ /** Visit page dictionaries in inheritance order using caller-backed cycle state. */
60198
+ pageAncestors(first) {
60199
+ async function* visit(doc) {
60200
+ doc.assertOpen();
60201
+ doc.walks.add(work);
60202
+ const visited = new PdfReferenceSet(doc.storage, doc.options.maxTraversalStagingBytes, doc.options.signal);
60203
+ let current = first, depth = 0, failed = false;
60204
+ try {
60205
+ while (current) {
60206
+ if (depth++ > doc.depthLimit) throw new PdfError("E_LIMIT", "PDF inherited page depth limit exceeded");
60207
+ if (depth % 64 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
60208
+ doc.assertOpen();
60209
+ yield current;
60210
+ doc.assertOpen();
60211
+ const parent = dictGet(current, "Parent");
60212
+ if (parent?.kind === "ref" && !await visited.add(parent.objectNumber)) break;
60213
+ const resolved = (await doc.lookup(parent))?.value;
60214
+ current = resolved?.kind === "dict" ? resolved : void 0;
60215
+ }
60216
+ } catch (error) {
60217
+ failed = true;
60218
+ throw error;
60219
+ } finally {
60220
+ doc.walks.delete(work);
60221
+ await visited.close().catch((error) => {
60222
+ if (!failed) throw error;
60223
+ });
60224
+ }
59925
60225
  }
59926
- return node ? { value: node, ...reference ? { reference } : {} } : void 0;
60226
+ const work = visit(this);
60227
+ return work;
59927
60228
  }
59928
60229
  /** Read one caller-backed array record with document cancellation and ownership. */
59929
60230
  async readArrayItem(items, position) {
@@ -59946,6 +60247,8 @@ var PdfRetainedDocument = class _PdfRetainedDocument {
59946
60247
  async annotationPageNumber(reference) {
59947
60248
  this.assertOpen();
59948
60249
  const visited = new PdfReferenceSet(this.storage, this.options.maxTraversalStagingBytes, this.options.signal);
60250
+ const backing = this.options.valueArrays?.storedArrayKeys?.includes("Kids") ? this.options.valueArrays.arrayStorage : void 0;
60251
+ const frames = backing ? new StoredMetadataStack(backing, this.options.signal) : [];
59949
60252
  const work = annotationPageNumberSteps(this.crossReference.rootRef, reference, this.depthLimit);
59950
60253
  let failed = false;
59951
60254
  try {
@@ -59959,7 +60262,11 @@ var PdfRetainedDocument = class _PdfRetainedDocument {
59959
60262
  step = work.next(resolved?.stream && resolved.value.kind === "dict" ? { kind: "stream", dict: resolved.value, rawBytes: new Uint8Array() } : resolved?.value);
59960
60263
  } else if (request.kind === "array-item") {
59961
60264
  step = work.next(await this.readArrayItem(request.items, request.position));
59962
- } else if (request.kind === "visit-page") step = work.next(await visited.add(request.reference.objectNumber));
60265
+ } else if (request.kind === "push-traversal-frame") {
60266
+ await frames.push(request.frame);
60267
+ step = work.next();
60268
+ } else if (request.kind === "pop-traversal-frame") step = work.next(await frames.pop());
60269
+ else if (request.kind === "visit-page") step = work.next(await visited.add(request.reference.objectNumber));
59963
60270
  else throw new TypeError("Unexpected annotation page lookup request");
59964
60271
  }
59965
60272
  return step.value;
@@ -59973,6 +60280,123 @@ var PdfRetainedDocument = class _PdfRetainedDocument {
59973
60280
  });
59974
60281
  }
59975
60282
  }
60283
+ /** Resolve a named annotation destination with caller-backed path state. */
60284
+ async annotationNamedDestination(node, name) {
60285
+ this.assertOpen();
60286
+ const storage = new PdfStagingStorage(this.storage, this.options.maxTraversalStagingBytes);
60287
+ let names;
60288
+ const flags = this.options.valueArrays?.arrayStorage;
60289
+ const pending = [];
60290
+ const signal = this.options.signal;
60291
+ async function initialize() {
60292
+ while (pending.length) {
60293
+ const { at, length } = pending.shift();
60294
+ signal?.throwIfAborted();
60295
+ await flags.write(at, new Uint8Array(length), signal ? { signal } : void 0);
60296
+ signal?.throwIfAborted();
60297
+ }
60298
+ }
60299
+ const indexStorage = flags ? {
60300
+ allocate(length) {
60301
+ const at = flags.allocate(length);
60302
+ pending.push({ at, length });
60303
+ return at;
60304
+ },
60305
+ async read(at, length) {
60306
+ await initialize();
60307
+ signal?.throwIfAborted();
60308
+ const bytes = await flags.read(at, length, signal ? { signal } : void 0);
60309
+ signal?.throwIfAborted();
60310
+ return bytes.slice();
60311
+ },
60312
+ async write(at, bytes) {
60313
+ await initialize();
60314
+ signal?.throwIfAborted();
60315
+ await flags.write(at, bytes, signal ? { signal } : void 0);
60316
+ signal?.throwIfAborted();
60317
+ }
60318
+ } : void 0;
60319
+ const references = indexStorage ? new IntegerTable5(indexStorage, 64) : void 0;
60320
+ const unusualReferences = indexStorage ? new IntegerTable5(indexStorage, 64) : void 0;
60321
+ const backing = this.options.valueArrays?.storedArrayKeys?.includes("Kids") ? flags : void 0;
60322
+ const frames = backing ? new StoredMetadataStack(backing, this.options.signal) : [];
60323
+ const buffered = /* @__PURE__ */ new Map(), active = /* @__PURE__ */ new Set();
60324
+ const direct = /* @__PURE__ */ new WeakMap();
60325
+ let failed = false;
60326
+ const work = annotationNameDestinationSteps(node, name, this.depthLimit);
60327
+ try {
60328
+ let step = work.next(), turns = 0;
60329
+ while (!step.done) {
60330
+ if (++turns % 256 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
60331
+ this.assertOpen();
60332
+ const request = step.value;
60333
+ let result;
60334
+ if (request.kind === "resolve") {
60335
+ const resolved = await this.lookup(request.node, void 0, request.arrayKey ? [request.arrayKey] : void 0);
60336
+ result = resolved?.stream && resolved.value.kind === "dict" ? { kind: "stream", dict: resolved.value, rawBytes: new Uint8Array() } : resolved?.value;
60337
+ } else if (request.kind === "array-item") result = await this.readArrayItem(request.items, request.position);
60338
+ else if (request.kind === "push-traversal-frame") await frames.push(request.frame);
60339
+ else if (request.kind === "pop-traversal-frame") result = await frames.pop();
60340
+ else if (request.kind === "enter-name-node") {
60341
+ const node2 = request.node;
60342
+ if (!flags) {
60343
+ const key = node2.kind === "ref" ? `${node2.objectNumber}:${node2.generationNumber}` : node2;
60344
+ let id2 = buffered.get(key);
60345
+ if (id2 === void 0) {
60346
+ id2 = buffered.size;
60347
+ buffered.set(key, id2);
60348
+ }
60349
+ if (!active.has(id2)) {
60350
+ active.add(id2);
60351
+ result = id2;
60352
+ }
60353
+ step = work.next(result);
60354
+ continue;
60355
+ }
60356
+ let id = node2.kind === "ref" ? void 0 : direct.get(node2);
60357
+ if (node2.kind === "ref") {
60358
+ const packed = Number.isSafeInteger(node2.objectNumber) && node2.objectNumber >= 0 && node2.objectNumber <= 281474976710655 && Number.isInteger(node2.generationNumber) && node2.generationNumber >= 0 && node2.generationNumber <= 65535;
60359
+ let key;
60360
+ const table = packed ? references : unusualReferences;
60361
+ if (packed) key = BigInt(node2.objectNumber) << 16n | BigInt(node2.generationNumber);
60362
+ else {
60363
+ names ??= new PdfNameIndex(storage, Infinity, this.options.signal);
60364
+ key = BigInt((await names.intern(`${node2.objectNumber}:${node2.generationNumber}`)).index);
60365
+ }
60366
+ const found = await table.get(key);
60367
+ if (found !== void 0) id = Number(found);
60368
+ else {
60369
+ id = flags.allocate(1);
60370
+ await flags.write(id, Uint8Array.of(0), signal ? { signal } : void 0);
60371
+ await table.set(key, BigInt(id));
60372
+ }
60373
+ } else if (id === void 0) {
60374
+ id = flags.allocate(1);
60375
+ await flags.write(id, Uint8Array.of(0), signal ? { signal } : void 0);
60376
+ direct.set(node2, id);
60377
+ }
60378
+ if ((await flags.read(id, 1, signal ? { signal } : void 0))[0] === 0) {
60379
+ await flags.write(id, Uint8Array.of(1), signal ? { signal } : void 0);
60380
+ result = id;
60381
+ }
60382
+ } else if (request.kind === "leave-name-node") {
60383
+ if (flags) await flags.write(request.identity, Uint8Array.of(0), signal ? { signal } : void 0);
60384
+ else active.delete(request.identity);
60385
+ } else throw new TypeError("Unexpected annotation name lookup request");
60386
+ step = work.next(result);
60387
+ }
60388
+ return step.value;
60389
+ } catch (error) {
60390
+ failed = true;
60391
+ throw error;
60392
+ } finally {
60393
+ work.return(void 0);
60394
+ const results = await Promise.allSettled([names?.close()]);
60395
+ if (!failed) {
60396
+ for (const result of results) if (result.status === "rejected") await Promise.reject(result.reason);
60397
+ }
60398
+ }
60399
+ }
59976
60400
  pages() {
59977
60401
  async function* visit(doc) {
59978
60402
  doc.assertOpen();
@@ -59980,21 +60404,50 @@ var PdfRetainedDocument = class _PdfRetainedDocument {
59980
60404
  const visited = new PdfReferenceSet(doc.storage, doc.options.maxTraversalStagingBytes, doc.options.signal);
59981
60405
  let count = 0;
59982
60406
  let failed = false;
59983
- async function* walk(node, depth) {
59984
- doc.assertOpen();
59985
- if (!node) return;
59986
- if (depth > doc.depthLimit) throw new PdfError("E_LIMIT", "PDF page tree depth limit exceeded");
59987
- if (node.kind === "ref" && !await visited.add(node.objectNumber)) return;
59988
- const resolved = await doc.lookup(node);
59989
- if (resolved?.value.kind !== "dict") return;
59990
- const dict = resolved.value;
59991
- const type = (await doc.lookup(dictGet(dict, "Type")))?.value;
59992
- const kids = (await doc.lookup(dictGet(dict, "Kids"), void 0, ["Kids"]))?.value;
59993
- if (type?.kind === "name" && type.decoded === "Pages" || kids?.kind === "array") {
59994
- if (kids?.kind === "array") for await (const kid of kids.storedItems ? readStoredItems(kids.storedItems, doc.options.signal) : kids.items) yield* walk(kid, depth + 1);
59995
- } else if (type?.kind === "name" && type.decoded === "Page" || dictGet(dict, "MediaBox") || dictGet(dict, "Contents")) {
59996
- if (count >= Math.min(doc.options.maxPages, Number.MAX_SAFE_INTEGER)) throw new PdfError("E_LIMIT", "PDF page count limit exceeded");
59997
- yield new PdfRetainedPage(doc, count++, dict, node.kind === "ref" ? node : void 0);
60407
+ async function* walk(first) {
60408
+ const backing = doc.options.valueArrays?.storedArrayKeys?.includes("Kids") ? doc.options.valueArrays.arrayStorage : void 0;
60409
+ const frames = backing ? new StoredMetadataStack(backing, doc.options.signal) : [];
60410
+ let frame, node = first, depth = 0, turns = 0;
60411
+ while (true) {
60412
+ if (++turns % 64 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
60413
+ doc.assertOpen();
60414
+ if (!node) {
60415
+ frame ??= await frames.pop();
60416
+ if (!frame) return;
60417
+ const stored = frame.kids.storedItems, length = stored?.length ?? frame.kids.items.length;
60418
+ if (!Number.isSafeInteger(length) || length < 0) throw new RangeError("Invalid stored array length");
60419
+ if (frame.index === length) {
60420
+ if (stored && frame.position !== -1) throw new Error("Invalid stored array terminator");
60421
+ frame = void 0;
60422
+ continue;
60423
+ }
60424
+ if (stored) {
60425
+ const record = await readStoredRecord(stored.storage, frame.position, doc.options.signal);
60426
+ frame.position = record.next;
60427
+ node = record.value;
60428
+ } else node = frame.kids.items[frame.index];
60429
+ frame.index++;
60430
+ depth = frame.depth;
60431
+ if (!node) continue;
60432
+ }
60433
+ const current = node;
60434
+ node = void 0;
60435
+ if (depth > doc.depthLimit) throw new PdfError("E_LIMIT", "PDF page tree depth limit exceeded");
60436
+ if (current.kind === "ref" && !await visited.add(current.objectNumber)) continue;
60437
+ const resolved = await doc.lookup(current);
60438
+ if (resolved?.value.kind !== "dict") continue;
60439
+ const dict = resolved.value;
60440
+ const type = (await doc.lookup(dictGet(dict, "Type")))?.value;
60441
+ const kids = (await doc.lookup(dictGet(dict, "Kids"), void 0, ["Kids"]))?.value;
60442
+ if (type?.kind === "name" && type.decoded === "Pages" || kids?.kind === "array") {
60443
+ if (kids?.kind === "array") {
60444
+ if (frame) await frames.push(frame);
60445
+ frame = { kids, index: 0, position: kids.storedItems?.position ?? -1, depth: depth + 1 };
60446
+ }
60447
+ } else if (type?.kind === "name" && type.decoded === "Page" || dictGet(dict, "MediaBox") || dictGet(dict, "Contents")) {
60448
+ if (count >= Math.min(doc.options.maxPages, Number.MAX_SAFE_INTEGER)) throw new PdfError("E_LIMIT", "PDF page count limit exceeded");
60449
+ yield new PdfRetainedPage(doc, count++, dict, current.kind === "ref" ? current : void 0);
60450
+ }
59998
60451
  }
59999
60452
  }
60000
60453
  try {
@@ -60008,7 +60461,7 @@ var PdfRetainedDocument = class _PdfRetainedDocument {
60008
60461
  }
60009
60462
  } else {
60010
60463
  const root = (await doc.lookup(doc.crossReference.rootRef))?.value;
60011
- if (root?.kind === "dict") yield* walk(dictGet(root, "Pages"), 0);
60464
+ if (root?.kind === "dict") yield* walk(dictGet(root, "Pages"));
60012
60465
  }
60013
60466
  } catch (error) {
60014
60467
  failed = true;
@@ -60153,6 +60606,23 @@ var PdfRetainedDocument = class _PdfRetainedDocument {
60153
60606
  const work = visit(this);
60154
60607
  return work;
60155
60608
  }
60609
+ formFieldDetails() {
60610
+ async function* visit(doc) {
60611
+ doc.assertOpen();
60612
+ doc.walks.add(work);
60613
+ try {
60614
+ yield* walkRetainedFormFieldDetails(doc, doc.storage, {
60615
+ maxDepth: doc.depthLimit,
60616
+ ...doc.options.maxTraversalStagingBytes === void 0 ? {} : { maxStagingBytes: doc.options.maxTraversalStagingBytes },
60617
+ ...doc.options.signal ? { signal: doc.options.signal } : {}
60618
+ });
60619
+ } finally {
60620
+ doc.walks.delete(work);
60621
+ }
60622
+ }
60623
+ const work = visit(this);
60624
+ return work;
60625
+ }
60156
60626
  attachments() {
60157
60627
  async function* visit(doc) {
60158
60628
  doc.assertOpen();
@@ -60239,11 +60709,7 @@ var PdfRetainedPage = class {
60239
60709
  const values = /* @__PURE__ */ new Map();
60240
60710
  const boxes = /* @__PURE__ */ new Map();
60241
60711
  const keys = ["MediaBox", "CropBox", "BleedBox", "TrimBox", "ArtBox", "Rotate", "Resources"];
60242
- let current = this.dict;
60243
- const visited = /* @__PURE__ */ new Set();
60244
- let depth = 0;
60245
- while (current) {
60246
- if (depth++ > this.document.depthLimit) throw new PdfError("E_LIMIT", "PDF inherited page depth limit exceeded");
60712
+ for await (const current of this.document.pageAncestors(this.dict)) {
60247
60713
  for (const key of keys) {
60248
60714
  const entry = dictGet(current, key);
60249
60715
  if (values.has(key) || !entry) continue;
@@ -60256,13 +60722,6 @@ var PdfRetainedPage = class {
60256
60722
  values.set(key, value);
60257
60723
  }
60258
60724
  if (values.size === keys.length) break;
60259
- const parent = dictGet(current, "Parent");
60260
- if (parent?.kind === "ref") {
60261
- if (visited.has(parent.objectNumber)) break;
60262
- visited.add(parent.objectNumber);
60263
- }
60264
- const resolved = (await this.document.lookup(parent))?.value;
60265
- current = resolved?.kind === "dict" ? resolved : void 0;
60266
60725
  }
60267
60726
  async function box(node, document2) {
60268
60727
  if (node?.kind !== "array" || node.items.length < 4) return void 0;
@@ -60363,7 +60822,7 @@ var PdfRetainedPage = class {
60363
60822
  /** Pull one annotation at a time. Destination page lookup uses the document's
60364
60823
  * caller-backed traversal index, without retaining a document-wide page map. */
60365
60824
  async *annotations() {
60366
- const work = extractPageAnnotationSteps(this.dict, this.document.crossReference.rootRef, this.document.depthLimit);
60825
+ const work = extractPageAnnotationSteps(this.dict, this.document.crossReference.rootRef);
60367
60826
  try {
60368
60827
  let step = work.next(), turns = 0;
60369
60828
  while (!step.done) {
@@ -60377,6 +60836,7 @@ var PdfRetainedPage = class {
60377
60836
  } else if (request.kind === "array-item") {
60378
60837
  result = await this.document.readArrayItem(request.items, request.position);
60379
60838
  } else if (request.kind === "page-number") result = await this.document.annotationPageNumber(request.reference);
60839
+ else if (request.kind === "named-destination") result = await this.document.annotationNamedDestination(request.node, request.name);
60380
60840
  else throw new TypeError("Unexpected annotation request");
60381
60841
  step = work.next(result);
60382
60842
  }
@@ -60806,7 +61266,7 @@ var PdfMergeAttachments = class {
60806
61266
  };
60807
61267
 
60808
61268
  // packages/pdf-ast/src/edit/retained-page-copy.ts
60809
- import { IntegerTable as IntegerTable5, PagedStorage as PagedStorage10 } from "@poe-platform/safe-fs/storage";
61269
+ import { IntegerTable as IntegerTable6, PagedStorage as PagedStorage10 } from "@poe-platform/safe-fs/storage";
60810
61270
  async function createRetainedPageCopy(input, indicesOrStorage, storageOrOptions, singleOptions = {}) {
60811
61271
  const single = "pages" in input;
60812
61272
  const storage = single ? storageOrOptions : indicesOrStorage;
@@ -60820,7 +61280,7 @@ async function createRetainedPageCopy(input, indicesOrStorage, storageOrOptions,
60820
61280
  const attachments = options.includeAttachments ? new PdfMergeAttachments(storage, signal) : void 0;
60821
61281
  const labels = options.includePageLabels ? new PdfMergeLabels(storage, signal, maximumDepth) : void 0;
60822
61282
  const outlines = options.includeOutlines ? new PdfMergeOutlines(storage, signal, maximumDepth) : void 0;
60823
- const pageReferences = outlines ? new IntegerTable5(lists, 64) : void 0;
61283
+ const pageReferences = outlines ? new IntegerTable6(lists, 64) : void 0;
60824
61284
  const catalog = cosDict({ Type: cosName("Catalog"), Pages: cosRef(2) });
60825
61285
  const pages = { first: 0, last: 0, count: 0 }, formFields = { first: 0, last: 0, count: 0 };
60826
61286
  let mayLinearize = false;
@@ -60870,7 +61330,7 @@ async function createRetainedPageCopy(input, indicesOrStorage, storageOrOptions,
60870
61330
  async function append(document2, pageIndices, resourceState) {
60871
61331
  const backing = new PagedStorage10({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
60872
61332
  const sourcePages = new PdfMutableObjectStore(storage, { maxRecursionDepth: maximumDepth, signal });
60873
- const memo = new IntegerTable5(backing, 64), wanted = new IntegerTable5(backing, 64), sourceReferences = new IntegerTable5(backing, 64);
61333
+ const memo = new IntegerTable6(backing, 64), wanted = new IntegerTable6(backing, 64), sourceReferences = new IntegerTable6(backing, 64);
60874
61334
  let firstSelection = 0, lastSelection = 0, sourceFailed = false;
60875
61335
  async function* selections() {
60876
61336
  let position = firstSelection;
@@ -61078,7 +61538,7 @@ async function createRetainedPageCopy(input, indicesOrStorage, storageOrOptions,
61078
61538
  }
61079
61539
  if (fields2?.kind === "array" && acro?.kind === "dict") {
61080
61540
  let addedFields = false;
61081
- const rootNumbers = new IntegerTable5(backing, 64);
61541
+ const rootNumbers = new IntegerTable6(backing, 64);
61082
61542
  for (const field2 of fields2.items) {
61083
61543
  if (!await hasCloned(field2)) continue;
61084
61544
  const cloned = await clone(field2);
@@ -61285,10 +61745,10 @@ async function* retainedCosObjects(document2, storage, options = {}) {
61285
61745
  }
61286
61746
 
61287
61747
  // packages/pdf-ast/src/cos/retained-object-streams.ts
61288
- import { IntegerTable as IntegerTable6, PagedStorage as PagedStorage11 } from "@poe-platform/safe-fs/storage";
61748
+ import { IntegerTable as IntegerTable7, PagedStorage as PagedStorage11 } from "@poe-platform/safe-fs/storage";
61289
61749
  async function* serializeRetainedObjectStreams(store, storage, options, objects, fallback) {
61290
61750
  const signal = options.signal ?? new AbortController().signal;
61291
- const backing = new PagedStorage11({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), packed = new IntegerTable6(backing);
61751
+ const backing = new PagedStorage11({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), packed = new IntegerTable7(backing);
61292
61752
  let count = 0, highest = 0, failed = false, compressed;
61293
61753
  try {
61294
61754
  for await (const identity of store.identities()) {
@@ -61559,7 +62019,7 @@ async function* saveRetainedDocumentChunks(document2, storage, options = {}) {
61559
62019
  }
61560
62020
 
61561
62021
  // packages/pdf-ast/src/edit/retained-form-appearances.ts
61562
- import { IntegerTable as IntegerTable7, PagedStorage as PagedStorage13 } from "@poe-platform/safe-fs/storage";
62022
+ import { IntegerTable as IntegerTable8, PagedStorage as PagedStorage13 } from "@poe-platform/safe-fs/storage";
61563
62023
 
61564
62024
  // packages/pdf-ast/src/edit/form-appearance-chunks.ts
61565
62025
  function* serializeFormAppearanceChunks(text, options) {
@@ -61647,7 +62107,7 @@ function* operators(text, options) {
61647
62107
  // packages/pdf-ast/src/edit/retained-form-appearances.ts
61648
62108
  async function generateRetainedFormAppearances(document2, store, storage, signal) {
61649
62109
  if (!document2.crossReference.rootRef) return;
61650
- const backing = new PagedStorage13({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), active = new IntegerTable7(backing);
62110
+ const backing = new PagedStorage13({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), active = new IntegerTable8(backing);
61651
62111
  let head = -1, failed = false, work = 0;
61652
62112
  let defaultAppearance;
61653
62113
  async function checkpoint(depth = 0) {
@@ -61854,17 +62314,17 @@ async function generateRetainedFormAppearances(document2, store, storage, signal
61854
62314
  }
61855
62315
 
61856
62316
  // packages/pdf-ast/src/edit/retained-flatten-annotations.ts
61857
- import { IntegerTable as IntegerTable9, PagedStorage as PagedStorage17 } from "@poe-platform/safe-fs/storage";
62317
+ import { IntegerTable as IntegerTable10, PagedStorage as PagedStorage17 } from "@poe-platform/safe-fs/storage";
61858
62318
 
61859
62319
  // packages/pdf-ast/src/edit/retained-content-edit.ts
61860
- import { IntegerTable as IntegerTable8, PagedStorage as PagedStorage14 } from "@poe-platform/safe-fs/storage";
62320
+ import { IntegerTable as IntegerTable9, PagedStorage as PagedStorage14 } from "@poe-platform/safe-fs/storage";
61861
62321
  var RetainedContentEditor = class _RetainedContentEditor {
61862
62322
  constructor(store, storage, signal) {
61863
62323
  this.store = store;
61864
62324
  this.storage = storage;
61865
62325
  this.signal = signal;
61866
62326
  this.backing = new PagedStorage14({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
61867
- this.counts = new IntegerTable8(this.backing);
62327
+ this.counts = new IntegerTable9(this.backing);
61868
62328
  this.identities = new PdfNameIndex(storage, Infinity, signal);
61869
62329
  }
61870
62330
  store;
@@ -62179,7 +62639,7 @@ async function flattenRetainedAnnotations(document2, store, storage, mode, signa
62179
62639
  }
62180
62640
  if (normal?.stream && normal.reference && normal.value.kind === "dict") {
62181
62641
  let content = await PdfFileSource.fromStream(storage.fs, storage.directory, document2.objects.decodeStream(normal.reference.objectNumber, normal.reference.generationNumber), { signal });
62182
- const backing = new PagedStorage17({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), renames = new IntegerTable9(backing), names = new PdfNameIndex(storage, Infinity, signal);
62642
+ const backing = new PagedStorage17({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), renames = new IntegerTable10(backing), names = new PdfNameIndex(storage, Infinity, signal);
62183
62643
  let appearanceFailed = false, count = 0;
62184
62644
  try {
62185
62645
  if (content.size) {
@@ -62298,7 +62758,7 @@ q ${scaleX} 0 0 ${scaleY} ${tx} ${ty} cm${matSuffix}
62298
62758
  }
62299
62759
 
62300
62760
  // packages/pdf-ast/src/edit/retained-stamps.ts
62301
- import { IntegerTable as IntegerTable10, PagedStorage as PagedStorage18 } from "@poe-platform/safe-fs/storage";
62761
+ import { IntegerTable as IntegerTable11, PagedStorage as PagedStorage18 } from "@poe-platform/safe-fs/storage";
62302
62762
  async function stampRetainedPages(document2, store, storage, getPage, stamps, signal) {
62303
62763
  const editor = await RetainedContentEditor.open(store, storage, signal);
62304
62764
  let counter = 1, failed = false, work = 0;
@@ -62309,7 +62769,7 @@ async function stampRetainedPages(document2, store, storage, getPage, stamps, si
62309
62769
  try {
62310
62770
  for await (const stamp of stamps) {
62311
62771
  const source = await editRetainedDocument(stamp.source, storage, { signal });
62312
- const backing = new PagedStorage18({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), memo = new IntegerTable10(backing);
62772
+ const backing = new PagedStorage18({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), memo = new IntegerTable11(backing);
62313
62773
  let stampFailed = false;
62314
62774
  async function clone(node, depth = 0) {
62315
62775
  await checkpoint();
@@ -62574,7 +63034,7 @@ async function externalizeRetainedInlineImages(document2, store, storage, option
62574
63034
  }
62575
63035
 
62576
63036
  // packages/pdf-ast/src/edit/retained-resource-pruning.ts
62577
- import { IntegerTable as IntegerTable11, PagedStorage as PagedStorage20 } from "@poe-platform/safe-fs/storage";
63037
+ import { IntegerTable as IntegerTable12, PagedStorage as PagedStorage20 } from "@poe-platform/safe-fs/storage";
62578
63038
  async function collectNames(input, names, found, signal) {
62579
63039
  const iterator = input[Symbol.asyncIterator](), pending = [];
62580
63040
  let chunk = new Uint8Array(), at = 0, ended = false, changed = false, work = 0, failed = false;
@@ -62656,7 +63116,7 @@ async function pruneRetainedResources(document2, store, storage, signal) {
62656
63116
  return { ...found2, value: same(page2.reference) ? page2.dict : same(resources?.reference) ? resources.value : found2.value };
62657
63117
  }
62658
63118
  const names = new PdfNameIndex(storage, Infinity, signal), visitedNames = new PdfNameIndex(storage, Infinity, signal);
62659
- const backing = new PagedStorage20({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), found = new IntegerTable11(backing);
63119
+ const backing = new PagedStorage20({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), found = new IntegerTable12(backing);
62660
63120
  let failed = false;
62661
63121
  try {
62662
63122
  const referenced = async (name) => await found.get(BigInt((await names.intern(name)).index)) !== void 0;
@@ -62786,7 +63246,7 @@ async function flattenRetainedRotations(document2, store, storage, signal) {
62786
63246
  }
62787
63247
 
62788
63248
  // packages/pdf-ast/src/edit/retained-attachment-edits.ts
62789
- import { IntegerTable as IntegerTable12, PagedStorage as PagedStorage21 } from "@poe-platform/safe-fs/storage";
63249
+ import { IntegerTable as IntegerTable13, PagedStorage as PagedStorage21 } from "@poe-platform/safe-fs/storage";
62790
63250
  var PdfDuplicateAttachment = class extends PdfError {
62791
63251
  constructor(key) {
62792
63252
  super("E_CAPABILITY", `Duplicate attachment key: ${key}`);
@@ -62797,7 +63257,7 @@ var PdfDuplicateAttachment = class extends PdfError {
62797
63257
  async function editRetainedAttachments(document2, target, storage, remove, additions, signal, preserveTree = false) {
62798
63258
  const pairs = new PdfMutableObjectStore(storage, { signal });
62799
63259
  const names = new PdfNameIndex(storage, Infinity, signal), removed = new PdfNameIndex(storage, Infinity, signal);
62800
- const backing = new PagedStorage21({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), first = new IntegerTable12(backing), removals = new IntegerTable12(backing);
63260
+ const backing = new PagedStorage21({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), first = new IntegerTable13(backing), removals = new IntegerTable13(backing);
62801
63261
  let failed = false, count = 0, work = 0;
62802
63262
  async function checkpoint() {
62803
63263
  signal.throwIfAborted();
@@ -63214,10 +63674,10 @@ async function* copyRetainedAttachments(document2, storage, options = {}) {
63214
63674
  }
63215
63675
 
63216
63676
  // packages/pdf-ast/src/cos/retained-object-order.ts
63217
- import { IntegerTable as IntegerTable13, PagedStorage as PagedStorage23 } from "@poe-platform/safe-fs/storage";
63677
+ import { IntegerTable as IntegerTable14, PagedStorage as PagedStorage23 } from "@poe-platform/safe-fs/storage";
63218
63678
  async function* retainedObjectOrder(document2, source, storage, signal) {
63219
63679
  const backing = new PagedStorage23({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
63220
- const seen = new IntegerTable13(backing), streams = new IntegerTable13(backing);
63680
+ const seen = new IntegerTable14(backing), streams = new IntegerTable14(backing);
63221
63681
  let failed = false, work = 0;
63222
63682
  async function candidate(number) {
63223
63683
  signal.throwIfAborted();
@@ -63231,7 +63691,7 @@ async function* retainedObjectOrder(document2, source, storage, signal) {
63231
63691
  try {
63232
63692
  if (document2.crossReference.revisionCount) {
63233
63693
  for (const kind of ["uncompressed", "compressed"]) {
63234
- const revisions = new IntegerTable13(backing);
63694
+ const revisions = new IntegerTable14(backing);
63235
63695
  let offset = document2.crossReference.xrefOffset;
63236
63696
  while (offset !== void 0 && await revisions.get(BigInt(offset)) === void 0) {
63237
63697
  await revisions.set(BigInt(offset), 1n);
@@ -63353,14 +63813,14 @@ async function* encryptRetainedPdfChunks(source, storage, options = {}) {
63353
63813
  }
63354
63814
 
63355
63815
  // packages/pdf-ast/src/cos/qpdf-json-values.ts
63356
- import { IntegerTable as IntegerTable14, PagedStorage as PagedStorage24 } from "@poe-platform/safe-fs/storage";
63816
+ import { IntegerTable as IntegerTable15, PagedStorage as PagedStorage24 } from "@poe-platform/safe-fs/storage";
63357
63817
  var QpdfJsonValues = class _QpdfJsonValues {
63358
63818
  constructor(tree, storage, signal) {
63359
63819
  this.tree = tree;
63360
63820
  this.signal = signal;
63361
63821
  this.scratch = new PagedStorage24({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
63362
- this.first = new IntegerTable14(this.scratch, 64);
63363
- this.next = new IntegerTable14(this.scratch, 64);
63822
+ this.first = new IntegerTable15(this.scratch, 64);
63823
+ this.next = new IntegerTable15(this.scratch, 64);
63364
63824
  }
63365
63825
  tree;
63366
63826
  signal;
@@ -63458,7 +63918,7 @@ var QpdfJsonValues = class _QpdfJsonValues {
63458
63918
  await this.cooperate();
63459
63919
  const header2 = await this.tree.describe(position);
63460
63920
  if (header2.kind === "object") {
63461
- const hashes = new IntegerTable14(this.scratch, 64);
63921
+ const hashes = new IntegerTable15(this.scratch, 64);
63462
63922
  let head = 0, tail = 0;
63463
63923
  for await (const { key } of order.entries(position)) {
63464
63924
  let hash2 = 0;
@@ -63751,7 +64211,7 @@ var QpdfJsonValues = class _QpdfJsonValues {
63751
64211
  };
63752
64212
 
63753
64213
  // packages/pdf-ast/src/cos/qpdf-json-document.ts
63754
- import { IntegerTable as IntegerTable15, PagedStorage as PagedStorage25 } from "@poe-platform/safe-fs/storage";
64214
+ import { IntegerTable as IntegerTable16, PagedStorage as PagedStorage25 } from "@poe-platform/safe-fs/storage";
63755
64215
  var QpdfJsonDocument = class _QpdfJsonDocument {
63756
64216
  constructor(storage, options = {}) {
63757
64217
  this.storage = storage;
@@ -63761,9 +64221,9 @@ var QpdfJsonDocument = class _QpdfJsonDocument {
63761
64221
  { fs: storage.fs, cwd: storage.directory, env: {}, signal: this.signal },
63762
64222
  4
63763
64223
  );
63764
- this.positions = new IntegerTable15(this.backing, 64);
63765
- this.order = new IntegerTable15(this.backing, 64);
63766
- this.catalogs = new IntegerTable15(this.backing, 64);
64224
+ this.positions = new IntegerTable16(this.backing, 64);
64225
+ this.order = new IntegerTable16(this.backing, 64);
64226
+ this.catalogs = new IntegerTable16(this.backing, 64);
63767
64227
  }
63768
64228
  storage;
63769
64229
  rootRef;