@poe-platform/safe-bash 0.1.815 → 0.1.817

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 (602) hide show
  1. package/dist/image-ast/index.js +1 -1
  2. package/dist/mp4-ast/codecs.d.ts +3 -0
  3. package/dist/mp4-ast/esds-source.d.ts +7 -0
  4. package/dist/mp4-ast/index.d.ts +5 -1
  5. package/dist/mp4-ast/mp4-codec-metadata.d.ts +48 -0
  6. package/dist/mp4-ast/mp4-codec-source.d.ts +8 -0
  7. package/dist/mp4-ast/mp4-packets-source.d.ts +11 -0
  8. package/dist/pdf-ast/ast.d.ts +6 -0
  9. package/dist/pdf-ast/content/evaluator.d.ts +8 -1
  10. package/dist/pdf-ast/content/stored-dictionary.d.ts +15 -1
  11. package/dist/pdf-ast/content/stored-record.d.ts +6 -0
  12. package/dist/pdf-ast/cos/retained-writer.d.ts +1 -0
  13. package/dist/pdf-ast/cos/value-parser.d.ts +7 -0
  14. package/dist/pdf-ast/edit/retained-graph.d.ts +1 -0
  15. package/dist/pdf-ast/edit/retained-page-copy.d.ts +10 -0
  16. package/dist/pdf-ast/extract/images.d.ts +2 -1
  17. package/dist/pdf-ast/fonts/resolve.d.ts +6 -1
  18. package/dist/pdf-ast/index.d.ts +2 -0
  19. package/dist/pdf-ast/index.js +1249 -473
  20. package/dist/pdf-ast/render/raster.d.ts +14 -0
  21. package/dist/pdf-ast/render/svg-image-stream.d.ts +6 -0
  22. package/dist/pdf-ast/render/svg-path-stream.d.ts +15 -0
  23. package/dist/pdf-ast/retained-document.d.ts +1 -1
  24. package/dist/safe-bash/chunks/{chunk-I6ECNJMR.js → chunk-AXGI5JVL.js} +1 -1
  25. package/dist/safe-bash/chunks/{chunk-TPG55BAQ.js → chunk-FQRI5AS5.js} +1 -1
  26. package/dist/safe-bash/chunks/{chunk-TWWGAW4M.js → chunk-HD6DWOAC.js} +1 -1
  27. package/dist/safe-bash/chunks/{chunk-5JCZEXEM.js → chunk-SXSEF5E2.js} +12 -7
  28. package/dist/safe-bash/command-chunks/biff-KLS4T7FP-UO3CXFFF.js +5581 -0
  29. package/dist/safe-bash/command-chunks/{chunk-S7HIOT7Z.js → chunk-26JE5JEB.js} +4 -4
  30. package/dist/safe-bash/command-chunks/{chunk-AG2SNMP5.js → chunk-2ALHVXEM.js} +2 -2
  31. package/dist/safe-bash/command-chunks/{chunk-4YLACJHE.js → chunk-2IMIKROX.js} +6 -6
  32. package/dist/safe-bash/command-chunks/chunk-2J4OQT3F.js +153 -0
  33. package/dist/safe-bash/command-chunks/{chunk-MYZ46FQL.js → chunk-2QZUAZTH.js} +1 -1
  34. package/dist/safe-bash/command-chunks/{chunk-YAD7EV4N.js → chunk-2TWXRJPB.js} +11 -11
  35. package/dist/safe-bash/command-chunks/{chunk-NYFYTL5G.js → chunk-345YBIHP.js} +27 -27
  36. package/dist/safe-bash/command-chunks/{chunk-3MG5EAMX.js → chunk-35DU6I2M.js} +5 -5
  37. package/dist/safe-bash/command-chunks/{chunk-FSVJ67G5.js → chunk-3DWFXESW.js} +2 -2
  38. package/dist/safe-bash/command-chunks/{chunk-TKCUGMRZ.js → chunk-3K5CVXUV.js} +18 -18
  39. package/dist/safe-bash/command-chunks/{chunk-6LPSKLLD.js → chunk-3MUFXGA2.js} +3 -3
  40. package/dist/safe-bash/command-chunks/{chunk-44F5TOHZ.js → chunk-3PM46VWH.js} +15 -15
  41. package/dist/safe-bash/command-chunks/{chunk-6QYSF7I2.js → chunk-3ZWFE4CK.js} +7 -7
  42. package/dist/safe-bash/command-chunks/{chunk-NEYITAAO.js → chunk-45DKGZYO.js} +744 -328
  43. package/dist/safe-bash/command-chunks/{chunk-U3C6IT2C.js → chunk-4772DJKS.js} +14 -10
  44. package/dist/safe-bash/command-chunks/{chunk-FOONI6BD.js → chunk-4ABR3KGK.js} +7 -7
  45. package/dist/safe-bash/command-chunks/{chunk-7KZ5LWV2.js → chunk-4IDV763L.js} +1 -1
  46. package/dist/safe-bash/command-chunks/{chunk-RV5AGXOV.js → chunk-4X2MPZXW.js} +2 -2
  47. package/dist/safe-bash/command-chunks/{chunk-LNTEV56A.js → chunk-4YFTJS5U.js} +2 -2
  48. package/dist/safe-bash/command-chunks/{chunk-6XES7Z4G.js → chunk-57PK2QFX.js} +12 -12
  49. package/dist/safe-bash/command-chunks/{chunk-42MEXZBJ.js → chunk-5GDF5FAS.js} +1 -1
  50. package/dist/safe-bash/command-chunks/{chunk-BS3ZEQGT.js → chunk-5KZMR6AJ.js} +18 -16
  51. package/dist/safe-bash/command-chunks/{chunk-ZU2KJMXO.js → chunk-5MNQTHED.js} +10 -10
  52. package/dist/safe-bash/command-chunks/{chunk-W25EIKDJ.js → chunk-5NC2IQMQ.js} +1 -1
  53. package/dist/safe-bash/command-chunks/{chunk-KY4LCHUF.js → chunk-5O45KGW5.js} +1 -1
  54. package/dist/safe-bash/command-chunks/{chunk-GYM5ICK4.js → chunk-5V7WIQ2D.js} +7 -7
  55. package/dist/safe-bash/command-chunks/{chunk-GPGLTWNR.js → chunk-5XUWGUGN.js} +16 -11
  56. package/dist/safe-bash/command-chunks/{chunk-SUTHGUD3.js → chunk-5YL453ZF.js} +34 -34
  57. package/dist/safe-bash/command-chunks/{chunk-IHXZMAMY.js → chunk-62RG3GHF.js} +6 -6
  58. package/dist/safe-bash/command-chunks/{chunk-P2LT6TGR.js → chunk-6EZWG56T.js} +9 -9
  59. package/dist/safe-bash/command-chunks/{chunk-CCMAHM3I.js → chunk-6JGICYHP.js} +2 -2
  60. package/dist/safe-bash/command-chunks/{chunk-AWPI4DZR.js → chunk-6KJDTKE4.js} +3 -3
  61. package/dist/safe-bash/command-chunks/{chunk-FUQMEUAT.js → chunk-6M3JTPKE.js} +8 -8
  62. package/dist/safe-bash/command-chunks/{chunk-H33D4R26.js → chunk-6RLWPB44.js} +4 -4
  63. package/dist/safe-bash/command-chunks/{chunk-3GRMU7TM.js → chunk-6W4RMBFH.js} +6 -6
  64. package/dist/safe-bash/command-chunks/{chunk-RIVKF77R.js → chunk-6YF2QADH.js} +6 -6
  65. package/dist/safe-bash/command-chunks/{chunk-LEO4VRIN.js → chunk-77ROD2TR.js} +5 -5
  66. package/dist/safe-bash/command-chunks/{chunk-XNGM3W5R.js → chunk-7B2MHKIW.js} +1 -1
  67. package/dist/safe-bash/command-chunks/{chunk-RFMHNTTF.js → chunk-7OCTMVYJ.js} +1 -1
  68. package/dist/safe-bash/command-chunks/{chunk-DBLQUZGN.js → chunk-7PYDVQPB.js} +2 -2
  69. package/dist/safe-bash/command-chunks/{chunk-AM5LANIE.js → chunk-A2L3U7DW.js} +7 -7
  70. package/dist/safe-bash/command-chunks/{chunk-UYGQEQIP.js → chunk-A4P37F3P.js} +5 -5
  71. package/dist/safe-bash/command-chunks/{chunk-ADHFF2IM.js → chunk-A5SPMSKD.js} +9 -9
  72. package/dist/safe-bash/command-chunks/{chunk-ENEIE44W.js → chunk-A6OTPNNI.js} +3 -3
  73. package/dist/safe-bash/command-chunks/{chunk-HQ2UN2L2.js → chunk-ABL2DPJI.js} +27 -27
  74. package/dist/safe-bash/command-chunks/chunk-AF2IO57Q.js +733 -0
  75. package/dist/safe-bash/command-chunks/{chunk-AFPXADZG.js → chunk-AHD3CGAY.js} +4 -4
  76. package/dist/safe-bash/command-chunks/{chunk-YW2VYN4V.js → chunk-ALD53QFL.js} +74 -27
  77. package/dist/safe-bash/command-chunks/{chunk-4B2ZUGLT.js → chunk-ARE267HR.js} +5 -5
  78. package/dist/safe-bash/command-chunks/{chunk-OTF2AJ5M.js → chunk-AYQPJQJR.js} +6 -6
  79. package/dist/safe-bash/command-chunks/{chunk-2VVJRVYM.js → chunk-B6XTAKKQ.js} +1 -1
  80. package/dist/safe-bash/command-chunks/{chunk-GCHB7VNX.js → chunk-BIJW6QWB.js} +17 -17
  81. package/dist/safe-bash/command-chunks/{chunk-OVEPYULA.js → chunk-BKK4MS3V.js} +1 -1
  82. package/dist/safe-bash/command-chunks/{chunk-3EB2FSAN.js → chunk-BOVDUJ3A.js} +7 -7
  83. package/dist/safe-bash/command-chunks/{chunk-SEPUP6TZ.js → chunk-BSTABZIK.js} +1 -1
  84. package/dist/safe-bash/command-chunks/{chunk-ATHHWPSE.js → chunk-BZRWZ6GO.js} +1 -1
  85. package/dist/safe-bash/command-chunks/{chunk-BZMNC7Q5.js → chunk-CGJ7GMHO.js} +7 -7
  86. package/dist/safe-bash/command-chunks/{chunk-RGDOYWOD.js → chunk-CHZE6FNT.js} +2 -2
  87. package/dist/safe-bash/command-chunks/{chunk-V7E3PZOK.js → chunk-CKA7ZROU.js} +7 -7
  88. package/dist/safe-bash/command-chunks/{chunk-MEM2ZPMI.js → chunk-CKIXC7AO.js} +3 -3
  89. package/dist/safe-bash/command-chunks/{chunk-Y54L4P4J.js → chunk-CORUUCS2.js} +5 -5
  90. package/dist/safe-bash/command-chunks/{chunk-6ZGCKUAM.js → chunk-DIRK47GT.js} +1 -1
  91. package/dist/safe-bash/command-chunks/{chunk-WYZG3DRR.js → chunk-DM5WURQL.js} +2 -2
  92. package/dist/safe-bash/command-chunks/{chunk-EBHOZIBS.js → chunk-DOVWHVHI.js} +6 -6
  93. package/dist/safe-bash/command-chunks/{chunk-ZIGENXGC.js → chunk-DXOXUKQB.js} +8 -8
  94. package/dist/safe-bash/command-chunks/{chunk-JR3Q6QNL.js → chunk-DZOKH5BL.js} +7 -7
  95. package/dist/safe-bash/command-chunks/{chunk-6EINUY5G.js → chunk-E22EAYJN.js} +54 -12
  96. package/dist/safe-bash/command-chunks/{chunk-3EASXF5D.js → chunk-E4TF5W6O.js} +2 -2
  97. package/dist/safe-bash/command-chunks/{chunk-6CDDKNNA.js → chunk-E64ZI2YB.js} +155 -12
  98. package/dist/safe-bash/command-chunks/{chunk-MLOYUXUV.js → chunk-EJ4UP7DA.js} +31 -9
  99. package/dist/safe-bash/command-chunks/{chunk-USGZN2KE.js → chunk-ENMJHB2C.js} +5 -5
  100. package/dist/safe-bash/command-chunks/{chunk-ZSQZHFWS.js → chunk-ERWIJYCS.js} +7 -7
  101. package/dist/safe-bash/command-chunks/{chunk-S2QNBAN6.js → chunk-ET6LMDEX.js} +12 -12
  102. package/dist/safe-bash/command-chunks/{chunk-6XGDWFNQ.js → chunk-EWC56JNI.js} +5 -5
  103. package/dist/safe-bash/command-chunks/{chunk-EQWFKNHJ.js → chunk-EZDWPTYB.js} +19 -19
  104. package/dist/safe-bash/command-chunks/{chunk-CQBACD2V.js → chunk-F2NF6FHV.js} +2 -2
  105. package/dist/safe-bash/command-chunks/{chunk-NFII726L.js → chunk-FAU2KL6I.js} +2 -2
  106. package/dist/safe-bash/command-chunks/{chunk-4EHY6J2Z.js → chunk-FB2WPI3M.js} +5 -5
  107. package/dist/safe-bash/command-chunks/{chunk-2PKBXGXD.js → chunk-FEBTT5NH.js} +5 -5
  108. package/dist/safe-bash/command-chunks/chunk-FGARVKAX.js +704 -0
  109. package/dist/safe-bash/command-chunks/{chunk-N4MUBJCT.js → chunk-FGHSE3RZ.js} +1 -1
  110. package/dist/safe-bash/command-chunks/{chunk-WBKB7HBZ.js → chunk-FHQOFEQK.js} +8 -8
  111. package/dist/safe-bash/command-chunks/{chunk-3ZRCL756.js → chunk-FJLSYX5P.js} +7 -7
  112. package/dist/safe-bash/command-chunks/{chunk-PMWW7KSB.js → chunk-FJSD43VF.js} +1 -1
  113. package/dist/safe-bash/command-chunks/{chunk-XKAUKLF7.js → chunk-FLSXHLJG.js} +9 -9
  114. package/dist/safe-bash/command-chunks/{chunk-3EW7GYHM.js → chunk-FR63MJSO.js} +7 -7
  115. package/dist/safe-bash/command-chunks/{chunk-KRRG4MGH.js → chunk-FSG6UC2N.js} +246 -108
  116. package/dist/safe-bash/command-chunks/{chunk-NRFTYZ2R.js → chunk-FUYZUETI.js} +6 -6
  117. package/dist/safe-bash/command-chunks/{chunk-JUHOL5KB.js → chunk-G3FK5VVG.js} +1 -1
  118. package/dist/safe-bash/command-chunks/{chunk-4UPKVQWH.js → chunk-G3LUT475.js} +6 -6
  119. package/dist/safe-bash/command-chunks/{chunk-Q7UZTMF4.js → chunk-GAROGIVU.js} +1 -1
  120. package/dist/safe-bash/command-chunks/{chunk-4RRYWHED.js → chunk-GMBUOYTN.js} +4 -4
  121. package/dist/safe-bash/command-chunks/{chunk-FYYFV6PW.js → chunk-GR4ONCQ5.js} +6 -6
  122. package/dist/safe-bash/command-chunks/{chunk-XTEIT5CI.js → chunk-GTOMW4VV.js} +1 -1
  123. package/dist/safe-bash/command-chunks/{chunk-OVQP6KH5.js → chunk-H56BSMFQ.js} +6 -6
  124. package/dist/safe-bash/command-chunks/{chunk-RQYPFLZJ.js → chunk-HOJ7WDTS.js} +6 -6
  125. package/dist/safe-bash/command-chunks/{chunk-BLIFGBIO.js → chunk-HOKPYTHQ.js} +2 -2
  126. package/dist/safe-bash/command-chunks/chunk-HQEYSSZV.js +152 -0
  127. package/dist/safe-bash/command-chunks/{chunk-NEMUPUUB.js → chunk-ICJH6A73.js} +7 -7
  128. package/dist/safe-bash/command-chunks/{chunk-CSE4VQKG.js → chunk-IJE65P52.js} +3 -3
  129. package/dist/safe-bash/command-chunks/{chunk-MKOIPOXX.js → chunk-IOXMGD2H.js} +3 -3
  130. package/dist/safe-bash/command-chunks/{chunk-LDW3RF7Y.js → chunk-ISFGPCED.js} +12 -12
  131. package/dist/safe-bash/command-chunks/{chunk-S43QRKDC.js → chunk-IVKAFEPO.js} +7 -7
  132. package/dist/safe-bash/command-chunks/{chunk-A347DLRB.js → chunk-IWVANZWH.js} +3 -3
  133. package/dist/safe-bash/command-chunks/{chunk-ZXELXF2H.js → chunk-IZ3SD5S2.js} +4 -4
  134. package/dist/safe-bash/command-chunks/{chunk-HGIMFVI2.js → chunk-J6FNSVHT.js} +5 -5
  135. package/dist/safe-bash/command-chunks/{chunk-GLAF45M7.js → chunk-JA36YOZI.js} +1 -1
  136. package/dist/safe-bash/command-chunks/{chunk-WHNYT34N.js → chunk-K2R7H3KO.js} +1 -1
  137. package/dist/safe-bash/command-chunks/{chunk-CKEMZUE3.js → chunk-KDBU5Q2N.js} +6 -6
  138. package/dist/safe-bash/command-chunks/{chunk-6VBDJC6V.js → chunk-KDDXLHN7.js} +6 -6
  139. package/dist/safe-bash/command-chunks/{chunk-NEVQWOU6.js → chunk-KLAC2MIZ.js} +10 -10
  140. package/dist/safe-bash/command-chunks/{chunk-QGD64UHJ.js → chunk-KLCHCSIV.js} +1 -1
  141. package/dist/safe-bash/command-chunks/{chunk-CXME4YHU.js → chunk-KM2SMMXZ.js} +59 -201
  142. package/dist/safe-bash/command-chunks/{chunk-RHU44OMN.js → chunk-KXM3HTAF.js} +1 -1
  143. package/dist/safe-bash/command-chunks/{chunk-AVOGFREX.js → chunk-KYIGYYEY.js} +3 -3
  144. package/dist/safe-bash/command-chunks/{chunk-5OM3UIK3.js → chunk-L2VLASZ4.js} +3 -3
  145. package/dist/safe-bash/command-chunks/{chunk-Z7QOSXQC.js → chunk-LECGQSQW.js} +7 -7
  146. package/dist/safe-bash/command-chunks/{chunk-RXQ2G2YK.js → chunk-LFSWLJPR.js} +9 -9
  147. package/dist/safe-bash/command-chunks/{chunk-OSYY6E23.js → chunk-LJ3UYESS.js} +1 -1
  148. package/dist/safe-bash/command-chunks/{chunk-MVLVIMJ6.js → chunk-LMLBQSAM.js} +6 -6
  149. package/dist/safe-bash/command-chunks/{chunk-MGMTRGKM.js → chunk-LNAZ3E4Q.js} +4 -4
  150. package/dist/safe-bash/command-chunks/{chunk-WJ2ERUCQ.js → chunk-LNKZVU5V.js} +1 -1
  151. package/dist/safe-bash/command-chunks/{chunk-WWHMI4S3.js → chunk-LQDANF2B.js} +8 -8
  152. package/dist/safe-bash/command-chunks/{chunk-CIRDVCAZ.js → chunk-LQX7RAF7.js} +7 -7
  153. package/dist/safe-bash/command-chunks/{chunk-SWAKALDJ.js → chunk-LT2YCGC5.js} +10 -10
  154. package/dist/safe-bash/command-chunks/{chunk-Y7AXMCFV.js → chunk-LZY46GYY.js} +8 -8
  155. package/dist/safe-bash/command-chunks/{chunk-VT2PHQ63.js → chunk-MDFNUNK5.js} +15 -15
  156. package/dist/safe-bash/command-chunks/{chunk-YP3WWV5N.js → chunk-MN3BB4WW.js} +4 -4
  157. package/dist/safe-bash/command-chunks/{chunk-WTVJLHMG.js → chunk-MOUCMZZP.js} +1 -1
  158. package/dist/safe-bash/command-chunks/{chunk-IB5QP4LF.js → chunk-MQE77MEQ.js} +3 -3
  159. package/dist/safe-bash/command-chunks/{chunk-FSYMSWJU.js → chunk-MUTARE5I.js} +6 -6
  160. package/dist/safe-bash/command-chunks/{chunk-F762XDNG.js → chunk-MZYQKH26.js} +3 -3
  161. package/dist/safe-bash/command-chunks/{chunk-N6G3345Q.js → chunk-N32AP43V.js} +7 -7
  162. package/dist/safe-bash/command-chunks/{chunk-XU6S3XUZ.js → chunk-N35IJXBK.js} +9 -9
  163. package/dist/safe-bash/command-chunks/{chunk-EVYKV3QI.js → chunk-N3ZH4YYH.js} +3 -3
  164. package/dist/safe-bash/command-chunks/{chunk-VUWXLH3E.js → chunk-N4HWOLGZ.js} +2 -2
  165. package/dist/safe-bash/command-chunks/{chunk-WAT2562G.js → chunk-N5J3IZZK.js} +8042 -7189
  166. package/dist/safe-bash/command-chunks/{chunk-W3ZSWK76.js → chunk-NCNHJRIY.js} +8 -8
  167. package/dist/safe-bash/command-chunks/{chunk-FXCSPPYE.js → chunk-NDALIHKK.js} +20 -20
  168. package/dist/safe-bash/command-chunks/{chunk-BS5JEUEW.js → chunk-NKK76B4V.js} +8 -8
  169. package/dist/safe-bash/command-chunks/{chunk-4EZJV4FZ.js → chunk-NLCUQD7Y.js} +1 -1
  170. package/dist/safe-bash/command-chunks/{chunk-G2COZLXX.js → chunk-OBIXFO25.js} +10 -10
  171. package/dist/safe-bash/command-chunks/{chunk-47IAU25U.js → chunk-OCV5ZU35.js} +3 -3
  172. package/dist/safe-bash/command-chunks/{chunk-3YEQI5B7.js → chunk-OFDJJRAD.js} +9 -9
  173. package/dist/safe-bash/command-chunks/{chunk-VDTFVRYX.js → chunk-OFONWWEZ.js} +2 -2
  174. package/dist/safe-bash/command-chunks/{chunk-F4YFTO2K.js → chunk-OHEZQ4QA.js} +9 -9
  175. package/dist/safe-bash/command-chunks/{chunk-JW6WVNTM.js → chunk-OIHQXURE.js} +1 -1
  176. package/dist/safe-bash/command-chunks/{chunk-ZTMZO4IT.js → chunk-ONQP4FNV.js} +1 -1
  177. package/dist/safe-bash/command-chunks/{chunk-K2WOMJOQ.js → chunk-OVUY46QF.js} +1 -1
  178. package/dist/safe-bash/command-chunks/{chunk-DGBQ7QDE.js → chunk-OWCBX5M2.js} +1 -1
  179. package/dist/safe-bash/command-chunks/{chunk-LKGTH2Q7.js → chunk-P462JTNT.js} +5 -5
  180. package/dist/safe-bash/command-chunks/{chunk-5LFGXN3D.js → chunk-P4OWVKMD.js} +6 -6
  181. package/dist/safe-bash/command-chunks/{chunk-46AMTJPE.js → chunk-POGVOCOB.js} +8 -8
  182. package/dist/safe-bash/command-chunks/{chunk-PLMF35XK.js → chunk-PPN53PX3.js} +4 -4
  183. package/dist/safe-bash/command-chunks/{chunk-V5XC43BX.js → chunk-PRO7JOIH.js} +8 -8
  184. package/dist/safe-bash/command-chunks/{chunk-UJERQEJB.js → chunk-PU5DMQGG.js} +1 -1
  185. package/dist/safe-bash/command-chunks/{chunk-IWHNRYER.js → chunk-Q65GWGQR.js} +3 -3
  186. package/dist/safe-bash/command-chunks/{chunk-BLGGAHQW.js → chunk-QCIAX6HZ.js} +1 -1
  187. package/dist/safe-bash/command-chunks/{chunk-ET5SFGRH.js → chunk-QDV2NIFR.js} +1 -1
  188. package/dist/safe-bash/command-chunks/{chunk-Y42KSX63.js → chunk-QMBMZSJF.js} +6 -6
  189. package/dist/safe-bash/command-chunks/{chunk-KUOCGGEU.js → chunk-QNETPOMH.js} +6 -5
  190. package/dist/safe-bash/command-chunks/{chunk-QB72X7FF.js → chunk-QNX5LZBK.js} +7 -7
  191. package/dist/safe-bash/command-chunks/{chunk-LZ2JFMKT.js → chunk-QOKFSYD5.js} +9 -9
  192. package/dist/safe-bash/command-chunks/{chunk-7DOLY7IV.js → chunk-R7LF4XQV.js} +2 -2
  193. package/dist/safe-bash/command-chunks/{chunk-MPXMRTMY.js → chunk-ROQ3VNVX.js} +8 -8
  194. package/dist/safe-bash/command-chunks/{chunk-6WNVGCXD.js → chunk-RRAQII52.js} +5 -5
  195. package/dist/safe-bash/command-chunks/{chunk-2BNGPR6Z.js → chunk-RTHYAGKI.js} +2 -2
  196. package/dist/safe-bash/command-chunks/chunk-RTKDZBJS.js +816 -0
  197. package/dist/safe-bash/command-chunks/{chunk-JVKE7YZN.js → chunk-RVWIEXR7.js} +4 -4
  198. package/dist/safe-bash/command-chunks/{chunk-XM5QJCPD.js → chunk-S5ER73EA.js} +8 -8
  199. package/dist/safe-bash/command-chunks/{chunk-FGGHYUWR.js → chunk-S5X7PBO4.js} +102 -7
  200. package/dist/safe-bash/command-chunks/{chunk-YRPXBGRX.js → chunk-SBXS4S6Y.js} +3 -3
  201. package/dist/safe-bash/command-chunks/{chunk-HI6ZYH3W.js → chunk-SHLT5R64.js} +9 -9
  202. package/dist/safe-bash/command-chunks/{chunk-Q5PWYPQV.js → chunk-SICTBSLW.js} +7 -7
  203. package/dist/safe-bash/command-chunks/{chunk-AXXZNB7U.js → chunk-SL4LD25A.js} +9 -9
  204. package/dist/safe-bash/command-chunks/{chunk-JGKSWDGP.js → chunk-SNA2LVBX.js} +1 -1
  205. package/dist/safe-bash/command-chunks/{chunk-TXPDKEGY.js → chunk-SWIF6BBY.js} +8 -8
  206. package/dist/safe-bash/command-chunks/{chunk-PS5GDFIP.js → chunk-T2FRXSQT.js} +2 -2
  207. package/dist/safe-bash/command-chunks/{chunk-HELAVGZH.js → chunk-T4SEQU66.js} +3 -3
  208. package/dist/safe-bash/command-chunks/{chunk-3SPLP2DB.js → chunk-T5OQ53XS.js} +1 -1
  209. package/dist/safe-bash/command-chunks/{chunk-KBAQHE5Y.js → chunk-TG2RVQLP.js} +2 -2
  210. package/dist/safe-bash/command-chunks/{chunk-IHLZ6HNQ.js → chunk-TSKJNCKD.js} +3 -2
  211. package/dist/safe-bash/command-chunks/{chunk-CZ5K2YPU.js → chunk-TXU7MMHN.js} +24 -24
  212. package/dist/safe-bash/command-chunks/{chunk-TYPS5MOU.js → chunk-TXWDR2P4.js} +1 -1
  213. package/dist/safe-bash/command-chunks/{chunk-ETXPMVR6.js → chunk-TY7JXEWI.js} +11 -11
  214. package/dist/safe-bash/command-chunks/{chunk-X6OHFKBL.js → chunk-U42WHQRH.js} +8 -8
  215. package/dist/safe-bash/command-chunks/{chunk-Z2WNYEPD.js → chunk-UFLMOU3B.js} +4 -4
  216. package/dist/safe-bash/command-chunks/{chunk-2BLTUQNK.js → chunk-UJYXSLM6.js} +2 -2
  217. package/dist/safe-bash/command-chunks/{chunk-Q7TVCBU2.js → chunk-UKAGRRLZ.js} +1 -1
  218. package/dist/safe-bash/command-chunks/{chunk-4GQKCUS5.js → chunk-UPWLHHZ2.js} +13 -13
  219. package/dist/safe-bash/command-chunks/{chunk-5L4YGRQU.js → chunk-URQSUMMJ.js} +4 -4
  220. package/dist/safe-bash/command-chunks/{chunk-KPHLESD4.js → chunk-UT5X6QRU.js} +5 -5
  221. package/dist/safe-bash/command-chunks/{chunk-QDVDBN2N.js → chunk-UYZ6EFZE.js} +164 -47
  222. package/dist/safe-bash/command-chunks/{chunk-T5S4SJGO.js → chunk-V6JPIZUW.js} +7 -7
  223. package/dist/safe-bash/command-chunks/{chunk-MKK6FM5H.js → chunk-VMZIAFVJ.js} +11 -11
  224. package/dist/safe-bash/command-chunks/{chunk-HK6MSB7Z.js → chunk-VNNNVT4C.js} +5 -5
  225. package/dist/safe-bash/command-chunks/{chunk-ROL5AEX6.js → chunk-VVV45NLY.js} +1 -1
  226. package/dist/safe-bash/command-chunks/chunk-VVWHFNHD.js +502 -0
  227. package/dist/safe-bash/command-chunks/{chunk-KCLJGRU7.js → chunk-VZTVR3JI.js} +12 -12
  228. package/dist/safe-bash/command-chunks/{chunk-B2C3UPJS.js → chunk-W42SUPD6.js} +13 -1
  229. package/dist/safe-bash/command-chunks/{chunk-PLR5IULU.js → chunk-WDVPHDBH.js} +5 -5
  230. package/dist/safe-bash/command-chunks/{chunk-MNK3DDH6.js → chunk-WH624PKJ.js} +2 -2
  231. package/dist/safe-bash/command-chunks/{chunk-TJLXSENN.js → chunk-WHZ6XK7Y.js} +1 -1
  232. package/dist/safe-bash/command-chunks/{chunk-DN6MSXY7.js → chunk-WIW3KDBS.js} +2 -2
  233. package/dist/safe-bash/command-chunks/{chunk-GXMPXMDP.js → chunk-WMBELKPP.js} +11 -11
  234. package/dist/safe-bash/command-chunks/{chunk-NHNZYWPW.js → chunk-WMV5224N.js} +3 -3
  235. package/dist/safe-bash/command-chunks/{chunk-RTNI47C5.js → chunk-WOL3LBXE.js} +4 -4
  236. package/dist/safe-bash/command-chunks/{chunk-7SOE7XIS.js → chunk-WVD5WZXD.js} +5 -5
  237. package/dist/safe-bash/command-chunks/{chunk-XMTR7QGL.js → chunk-X42MJT2J.js} +4 -4
  238. package/dist/safe-bash/command-chunks/{chunk-XUJAQA3S.js → chunk-XBWD6SI3.js} +33 -33
  239. package/dist/safe-bash/command-chunks/{chunk-ZQM37BGE.js → chunk-XFIDOCYH.js} +2 -2
  240. package/dist/safe-bash/command-chunks/{chunk-IBYMPAUW.js → chunk-XPQUUFQD.js} +2 -2
  241. package/dist/safe-bash/command-chunks/{chunk-NQINS4XY.js → chunk-XVEI4HZL.js} +1 -1
  242. package/dist/safe-bash/command-chunks/{chunk-KSBNZTAZ.js → chunk-YKODRSGT.js} +6 -6
  243. package/dist/safe-bash/command-chunks/{chunk-WZRFS5OY.js → chunk-YXR4JE4U.js} +4 -4
  244. package/dist/safe-bash/command-chunks/{chunk-DCMSPMMD.js → chunk-Z7UIOPHJ.js} +1 -1
  245. package/dist/safe-bash/command-chunks/{chunk-AY3KQ4EN.js → chunk-ZAYTFXUX.js} +7 -7
  246. package/dist/safe-bash/command-chunks/chunk-ZHHALBM7.js +398 -0
  247. package/dist/safe-bash/command-chunks/{chunk-DZH54L3F.js → chunk-ZM7HMBAJ.js} +10 -10
  248. package/dist/safe-bash/command-chunks/{chunk-NFGCBQN3.js → chunk-ZNCPIZCN.js} +2 -2
  249. package/dist/safe-bash/command-chunks/{chunk-HKGNBH7Z.js → chunk-ZRHKXN6W.js} +4 -4
  250. package/dist/safe-bash/command-chunks/{chunk-A45UG4KT.js → chunk-ZZERSKAR.js} +5 -5
  251. package/dist/safe-bash/command-chunks/{clipboard-BBDK33GP-QZ4ERNQX.js → clipboard-BBDK33GP-VB22F7GI.js} +2 -2
  252. package/dist/safe-bash/command-chunks/{command-engine-M7S4QIXV.js → command-engine-2QXVRRH3.js} +59 -23
  253. package/dist/safe-bash/command-chunks/{engine-YUYZJIB4-NZUDFEHL.js → engine-T4GP6QOK-ECFKMR5V.js} +1 -1
  254. package/dist/safe-bash/command-chunks/{gnumeric-UJPXWBVR-7VOHQAPM.js → gnumeric-UJPXWBVR-YPXTNEDZ.js} +2 -2
  255. package/dist/safe-bash/command-chunks/model-store-I7YAWL5V.js +54 -0
  256. package/dist/safe-bash/command-chunks/odf-SL5TG4B3-XI3FNOTN.js +3041 -0
  257. package/dist/safe-bash/command-chunks/{xlsx-RE54MFCS-DI3F765V.js → xlsx-RE54MFCS-4UZ5W3U7.js} +1 -1
  258. package/dist/safe-bash/commands/bc/index.browser.js +1 -1
  259. package/dist/safe-bash/full-core.browser.js +4 -4
  260. package/dist/safe-bash/plugins/index.browser.js +3 -3
  261. package/dist/safe-bash/registry-entry.browser.js +2 -2
  262. package/dist/safe-bash/search.browser.js +1 -1
  263. package/dist/safe-bash/shell/runtime.d.ts +1 -0
  264. package/dist/safe-bash/shell/runtime.js +12 -3
  265. package/dist/safe-bash/shell/sync-extra-evaluators.js +7 -4
  266. package/dist/safe-bash/shell-entry.browser.js +2 -2
  267. package/dist/safe-bash-command-apply-patch/apply.js +1 -1
  268. package/dist/safe-bash-command-apply-patch/index.js +1 -1
  269. package/dist/safe-bash-command-awk/awk-runtime.js +3 -3
  270. package/dist/safe-bash-command-awk/awk.js +4 -4
  271. package/dist/safe-bash-command-awk/index.js +4 -4
  272. package/dist/safe-bash-command-cp/index.js +3 -3
  273. package/dist/safe-bash-command-csvkit/index.js +1 -1
  274. package/dist/safe-bash-command-diff/diff.js +2 -2
  275. package/dist/safe-bash-command-diff/index.js +3 -3
  276. package/dist/safe-bash-command-diff/sync.js +2 -2
  277. package/dist/safe-bash-command-factor/command.js +2 -2
  278. package/dist/safe-bash-command-factor/index.js +2 -2
  279. package/dist/safe-bash-command-ffmpeg/index.js +1 -1
  280. package/dist/safe-bash-command-ffprobe/index.js +2 -2
  281. package/dist/safe-bash-command-ffprobe/media.d.ts +5 -1
  282. package/dist/safe-bash-command-ffprobe/media.js +2 -2
  283. package/dist/safe-bash-command-getopt/command.js +2 -2
  284. package/dist/safe-bash-command-getopt/index.js +2 -2
  285. package/dist/safe-bash-command-html-to-markdown/index.js +51 -813
  286. package/dist/safe-bash-command-html-to-markdown/stored-destination.d.ts +8 -0
  287. package/dist/safe-bash-command-html-to-markdown/stored-destination.js +10 -0
  288. package/dist/safe-bash-command-html-to-markdown/stored-text.d.ts +4 -1
  289. package/dist/safe-bash-command-html-to-markdown/stored-text.js +1 -1
  290. package/dist/safe-bash-command-htmlq/index.js +1280 -419
  291. package/dist/safe-bash-command-iconv/command.js +2 -2
  292. package/dist/safe-bash-command-iconv/index.js +2 -2
  293. package/dist/safe-bash-command-llm/index.js +2 -2
  294. package/dist/safe-bash-command-llm/openai.js +2 -2
  295. package/dist/safe-bash-command-llm/providers/index.js +2 -2
  296. package/dist/safe-bash-command-llm/providers/openai.js +2 -2
  297. package/dist/safe-bash-command-node/commands/node/browser.js +4 -4
  298. package/dist/safe-bash-command-node/commands/node/default-runtime.js +4 -4
  299. package/dist/safe-bash-command-node/commands/node/safejs.js +4 -4
  300. package/dist/safe-bash-command-pandoc/command.js +10 -9
  301. package/dist/safe-bash-command-pandoc/index.js +60 -59
  302. package/dist/safe-bash-command-patch/index.js +6 -6
  303. package/dist/safe-bash-command-patch/patch-formats.js +3 -3
  304. package/dist/safe-bash-command-patch/patch-gnu-reject.js +1 -1
  305. package/dist/safe-bash-command-patch/patch.js +6 -6
  306. package/dist/safe-bash-command-patch/stored-patch.d.ts +7 -6
  307. package/dist/safe-bash-command-patch/unified.d.ts +5 -5
  308. package/dist/safe-bash-command-patch/unified.js +2 -2
  309. package/dist/safe-bash-command-pdftk/index.js +21 -108
  310. package/dist/safe-bash-command-pdftoppm/index.js +131 -27
  311. package/dist/safe-bash-command-playwright-cli/index.js +12 -12
  312. package/dist/safe-bash-command-playwright-cli/playwright/abilities.js +1 -1
  313. package/dist/safe-bash-command-playwright-cli/playwright/capability-events.js +1 -1
  314. package/dist/safe-bash-command-playwright-cli/playwright/capability-result.js +1 -1
  315. package/dist/safe-bash-command-playwright-cli/playwright/controller.js +7 -7
  316. package/dist/safe-bash-command-playwright-cli/playwright/download-capabilities.js +1 -1
  317. package/dist/safe-bash-command-playwright-cli/playwright/drop-capability.js +1 -1
  318. package/dist/safe-bash-command-playwright-cli/playwright/index.js +12 -12
  319. package/dist/safe-bash-command-playwright-cli/playwright/modal-capabilities.js +1 -1
  320. package/dist/safe-bash-command-playwright-cli/playwright/native-evaluation.js +1 -1
  321. package/dist/safe-bash-command-playwright-cli/playwright/native-json-snapshot.js +1 -1
  322. package/dist/safe-bash-command-playwright-cli/playwright/native-snapshot.js +1 -1
  323. package/dist/safe-bash-command-playwright-cli/playwright/open-options.js +2 -2
  324. package/dist/safe-bash-command-playwright-cli/playwright/profile.js +3 -3
  325. package/dist/safe-bash-command-playwright-cli/playwright/recording-capabilities.js +1 -1
  326. package/dist/safe-bash-command-playwright-cli/playwright/route-capabilities.js +1 -1
  327. package/dist/safe-bash-command-playwright-cli/playwright/snapshot.js +3 -3
  328. package/dist/safe-bash-command-playwright-cli/playwright/standard-capabilities.js +1 -1
  329. package/dist/safe-bash-command-playwright-cli/playwright/storage-capabilities.js +1 -1
  330. package/dist/safe-bash-command-playwright-cli/playwright/tracing-capabilities.js +1 -1
  331. package/dist/safe-bash-command-playwright-cli/playwright/webmcp-capabilities.js +1 -1
  332. package/dist/safe-bash-command-pptx/engine.js +1 -1
  333. package/dist/safe-bash-command-python/executor.js +11 -11
  334. package/dist/safe-bash-command-python/index.js +11 -11
  335. package/dist/safe-bash-command-python/jspi.js +2 -2
  336. package/dist/safe-bash-command-rg/index.js +3 -3
  337. package/dist/safe-bash-command-rg/rg-command.js +3 -3
  338. package/dist/safe-bash-command-safejs/index.js +4 -4
  339. package/dist/safe-bash-command-safejs/io.js +3 -3
  340. package/dist/safe-bash-command-safejs/render.js +2 -2
  341. package/dist/safe-bash-command-safejs/runtime.js +4 -4
  342. package/dist/safe-bash-command-soffice/index.js +5 -4
  343. package/dist/safe-bash-command-sort/index.js +3 -3
  344. package/dist/safe-bash-command-ssconvert/index.js +13 -13
  345. package/dist/safe-bash-command-tar/create.js +3 -3
  346. package/dist/safe-bash-command-tar/extract.js +3 -3
  347. package/dist/safe-bash-command-tar/index.js +7 -7
  348. package/dist/safe-bash-command-tar/modes.js +5 -5
  349. package/dist/safe-bash-command-unzip/index.js +2 -2
  350. package/dist/safe-bash-command-unzip/unzip.js +2 -2
  351. package/dist/safe-bash-command-xmllint/index.js +1 -1
  352. package/dist/safe-bash-command-xz/index.js +5 -5
  353. package/dist/safe-bash-compression-engine/files.js +5 -5
  354. package/dist/safe-bash-compression-engine/index.js +3 -3
  355. package/dist/safe-bash-compression-engine/operand.js +6 -6
  356. package/dist/safe-bash-compression-engine/stream.js +3 -3
  357. package/dist/safe-bash-compression-engine/zstd-decode.js +2 -2
  358. package/dist/safe-bash-contracts/escaping.js +3 -3
  359. package/dist/safe-bash-contracts/filesystem-output.js +3 -3
  360. package/dist/safe-bash-contracts/index.js +10 -10
  361. package/dist/safe-bash-docx-engine/ancillary-resources.js +9 -9
  362. package/dist/safe-bash-docx-engine/batch-operations.js +66 -66
  363. package/dist/safe-bash-docx-engine/batch-result-schema.js +78 -78
  364. package/dist/safe-bash-docx-engine/batch.js +77 -77
  365. package/dist/safe-bash-docx-engine/bookmarks.js +17 -17
  366. package/dist/safe-bash-docx-engine/charts.js +10 -10
  367. package/dist/safe-bash-docx-engine/command-option-rules.js +5 -5
  368. package/dist/safe-bash-docx-engine/command-properties.js +3 -3
  369. package/dist/safe-bash-docx-engine/comments.js +25 -25
  370. package/dist/safe-bash-docx-engine/control-bindings.js +20 -20
  371. package/dist/safe-bash-docx-engine/control-repeat.js +20 -20
  372. package/dist/safe-bash-docx-engine/controls.js +18 -18
  373. package/dist/safe-bash-docx-engine/create.js +10 -10
  374. package/dist/safe-bash-docx-engine/diagrams.js +10 -10
  375. package/dist/safe-bash-docx-engine/diff.js +12 -12
  376. package/dist/safe-bash-docx-engine/document-properties.js +15 -15
  377. package/dist/safe-bash-docx-engine/equations.js +16 -16
  378. package/dist/safe-bash-docx-engine/extract.js +13 -13
  379. package/dist/safe-bash-docx-engine/fields.js +22 -22
  380. package/dist/safe-bash-docx-engine/font-inventory.js +17 -17
  381. package/dist/safe-bash-docx-engine/font-resources.js +5 -5
  382. package/dist/safe-bash-docx-engine/image-batch-operations.js +13 -13
  383. package/dist/safe-bash-docx-engine/image-insertion.js +20 -20
  384. package/dist/safe-bash-docx-engine/image-layout.js +18 -18
  385. package/dist/safe-bash-docx-engine/image-replacement.js +21 -21
  386. package/dist/safe-bash-docx-engine/images.js +18 -18
  387. package/dist/safe-bash-docx-engine/index.js +113 -113
  388. package/dist/safe-bash-docx-engine/inspection.js +19 -19
  389. package/dist/safe-bash-docx-engine/invocation.js +8 -8
  390. package/dist/safe-bash-docx-engine/io.js +8 -8
  391. package/dist/safe-bash-docx-engine/links.js +20 -20
  392. package/dist/safe-bash-docx-engine/lists.js +19 -19
  393. package/dist/safe-bash-docx-engine/locations.js +14 -14
  394. package/dist/safe-bash-docx-engine/notes.js +21 -21
  395. package/dist/safe-bash-docx-engine/objects.js +18 -18
  396. package/dist/safe-bash-docx-engine/operation-json-schema.js +3 -3
  397. package/dist/safe-bash-docx-engine/operation-schema.js +2 -2
  398. package/dist/safe-bash-docx-engine/pack.js +13 -13
  399. package/dist/safe-bash-docx-engine/package-view-batch-operations.js +21 -21
  400. package/dist/safe-bash-docx-engine/pandoc-adapter.js +28 -28
  401. package/dist/safe-bash-docx-engine/paragraph-edit.js +24 -24
  402. package/dist/safe-bash-docx-engine/part-provider.js +3 -3
  403. package/dist/safe-bash-docx-engine/property-values.js +3 -3
  404. package/dist/safe-bash-docx-engine/publication.js +8 -8
  405. package/dist/safe-bash-docx-engine/removal.js +20 -20
  406. package/dist/safe-bash-docx-engine/revision-decisions.js +21 -21
  407. package/dist/safe-bash-docx-engine/revision-edit.js +19 -19
  408. package/dist/safe-bash-docx-engine/revisions.js +17 -17
  409. package/dist/safe-bash-docx-engine/run-format.js +19 -19
  410. package/dist/safe-bash-docx-engine/sanitize.js +33 -33
  411. package/dist/safe-bash-docx-engine/sections.js +18 -18
  412. package/dist/safe-bash-docx-engine/settings.js +10 -10
  413. package/dist/safe-bash-docx-engine/shape-edit.js +20 -20
  414. package/dist/safe-bash-docx-engine/signatures.js +14 -14
  415. package/dist/safe-bash-docx-engine/stories.js +21 -21
  416. package/dist/safe-bash-docx-engine/structure-model-batch-operations.js +37 -37
  417. package/dist/safe-bash-docx-engine/style-model-batch-operations.js +26 -26
  418. package/dist/safe-bash-docx-engine/style-model-result-schema.js +43 -43
  419. package/dist/safe-bash-docx-engine/styles.js +17 -17
  420. package/dist/safe-bash-docx-engine/table-edit.js +26 -26
  421. package/dist/safe-bash-docx-engine/table-read.js +15 -15
  422. package/dist/safe-bash-docx-engine/template.js +21 -21
  423. package/dist/safe-bash-docx-engine/text-replace.js +19 -19
  424. package/dist/safe-bash-docx-engine/text-resource-read.js +15 -15
  425. package/dist/safe-bash-docx-engine/text.js +15 -15
  426. package/dist/safe-bash-docx-engine/validation.js +6 -6
  427. package/dist/safe-bash-docx-engine/xml-parts.js +21 -21
  428. package/dist/safe-bash-line-ending-engine/command.js +4 -4
  429. package/dist/safe-bash-line-ending-engine/index.js +7 -7
  430. package/dist/safe-bash-markdown-engine/commonmark-blocks.js +3 -3
  431. package/dist/safe-bash-markdown-engine/commonmark-inlines.js +3 -3
  432. package/dist/safe-bash-markdown-engine/gfm-syntax.js +2 -2
  433. package/dist/safe-bash-markdown-engine/index.js +4 -4
  434. package/dist/safe-bash-network-engine/aggregate.js +3 -3
  435. package/dist/safe-bash-network-engine/args.js +3 -3
  436. package/dist/safe-bash-network-engine/body.js +4 -4
  437. package/dist/safe-bash-network-engine/decode.js +3 -3
  438. package/dist/safe-bash-network-engine/fetch-transport.js +3 -3
  439. package/dist/safe-bash-network-engine/index.js +3 -3
  440. package/dist/safe-bash-network-engine/output.js +3 -3
  441. package/dist/safe-bash-network-engine/platform-portable.js +3 -3
  442. package/dist/safe-bash-network-engine/shared.js +2 -2
  443. package/dist/safe-bash-network-engine/transfer.js +9 -9
  444. package/dist/safe-bash-presentation-engine/accessibility.js +31 -30
  445. package/dist/safe-bash-presentation-engine/animation-editing.js +16 -15
  446. package/dist/safe-bash-presentation-engine/animations.js +16 -15
  447. package/dist/safe-bash-presentation-engine/backgrounds.js +17 -16
  448. package/dist/safe-bash-presentation-engine/bytes.js +4 -3
  449. package/dist/safe-bash-presentation-engine/chart-editing.js +34 -33
  450. package/dist/safe-bash-presentation-engine/chart-object-operations.js +25 -24
  451. package/dist/safe-bash-presentation-engine/charts.js +31 -30
  452. package/dist/safe-bash-presentation-engine/command-placeholder.js +60 -58
  453. package/dist/safe-bash-presentation-engine/comments.js +17 -16
  454. package/dist/safe-bash-presentation-engine/connector-operations.js +32 -31
  455. package/dist/safe-bash-presentation-engine/connectors.js +29 -28
  456. package/dist/safe-bash-presentation-engine/content-types.js +5 -4
  457. package/dist/safe-bash-presentation-engine/creation.js +7 -6
  458. package/dist/safe-bash-presentation-engine/diff.d.ts +1 -0
  459. package/dist/safe-bash-presentation-engine/diff.js +44 -33
  460. package/dist/safe-bash-presentation-engine/drawing-format.js +20 -19
  461. package/dist/safe-bash-presentation-engine/drawing-operations.js +31 -30
  462. package/dist/safe-bash-presentation-engine/drawing-schema.js +21 -20
  463. package/dist/safe-bash-presentation-engine/equations.js +17 -16
  464. package/dist/safe-bash-presentation-engine/errors.js +3 -2
  465. package/dist/safe-bash-presentation-engine/fields.js +17 -16
  466. package/dist/safe-bash-presentation-engine/font-metrics.js +4 -3
  467. package/dist/safe-bash-presentation-engine/image-extraction.js +20 -19
  468. package/dist/safe-bash-presentation-engine/image-formatting.js +32 -31
  469. package/dist/safe-bash-presentation-engine/image-insertion.js +18 -17
  470. package/dist/safe-bash-presentation-engine/image-replacement.js +21 -20
  471. package/dist/safe-bash-presentation-engine/image-value.js +5 -4
  472. package/dist/safe-bash-presentation-engine/images.js +19 -18
  473. package/dist/safe-bash-presentation-engine/index.js +135 -132
  474. package/dist/safe-bash-presentation-engine/layouts.js +16 -15
  475. package/dist/safe-bash-presentation-engine/length.js +4 -3
  476. package/dist/safe-bash-presentation-engine/links.js +16 -15
  477. package/dist/safe-bash-presentation-engine/masters.js +15 -14
  478. package/dist/safe-bash-presentation-engine/media-editing.js +24 -23
  479. package/dist/safe-bash-presentation-engine/media-extraction.js +17 -16
  480. package/dist/safe-bash-presentation-engine/media.js +16 -15
  481. package/dist/safe-bash-presentation-engine/memberships.js +15 -14
  482. package/dist/safe-bash-presentation-engine/notes.js +18 -17
  483. package/dist/safe-bash-presentation-engine/ole-enum.js +5 -4
  484. package/dist/safe-bash-presentation-engine/ole-insertion.js +20 -19
  485. package/dist/safe-bash-presentation-engine/opaque-objects.js +10 -9
  486. package/dist/safe-bash-presentation-engine/package-reader.js +6 -5
  487. package/dist/safe-bash-presentation-engine/package-tools.js +19 -18
  488. package/dist/safe-bash-presentation-engine/package-uri.js +4 -3
  489. package/dist/safe-bash-presentation-engine/package-writer.js +5 -4
  490. package/dist/safe-bash-presentation-engine/presentation-model.js +59 -57
  491. package/dist/safe-bash-presentation-engine/presentation-settings.js +14 -13
  492. package/dist/safe-bash-presentation-engine/properties.d.ts +2 -1
  493. package/dist/safe-bash-presentation-engine/properties.js +25 -15
  494. package/dist/safe-bash-presentation-engine/relationships.js +5 -4
  495. package/dist/safe-bash-presentation-engine/resource-limits.js +2 -1
  496. package/dist/safe-bash-presentation-engine/retained-diff.d.ts +56 -0
  497. package/dist/safe-bash-presentation-engine/retained-inspection.js +14 -13
  498. package/dist/safe-bash-presentation-engine/retained-package.js +6 -5
  499. package/dist/safe-bash-presentation-engine/retained-properties.d.ts +26 -0
  500. package/dist/safe-bash-presentation-engine/retained-tags.d.ts +20 -0
  501. package/dist/safe-bash-presentation-engine/retained-text.js +33 -517
  502. package/dist/safe-bash-presentation-engine/sanitize.js +20 -16
  503. package/dist/safe-bash-presentation-engine/selectors.js +11 -10
  504. package/dist/safe-bash-presentation-engine/shape-groups.js +31 -30
  505. package/dist/safe-bash-presentation-engine/shape-operations.js +30 -29
  506. package/dist/safe-bash-presentation-engine/shape-path-operations.js +32 -31
  507. package/dist/safe-bash-presentation-engine/shape-paths.js +16 -15
  508. package/dist/safe-bash-presentation-engine/shape-presets.js +4 -3
  509. package/dist/safe-bash-presentation-engine/shape-selection.js +31 -30
  510. package/dist/safe-bash-presentation-engine/shape-transforms.js +18 -17
  511. package/dist/safe-bash-presentation-engine/shapes.js +27 -26
  512. package/dist/safe-bash-presentation-engine/slide-copy.js +17 -16
  513. package/dist/safe-bash-presentation-engine/slide-import.js +18 -17
  514. package/dist/safe-bash-presentation-engine/slide-merge-split.js +20 -19
  515. package/dist/safe-bash-presentation-engine/slide-model.js +43 -42
  516. package/dist/safe-bash-presentation-engine/slide-removal.js +18 -17
  517. package/dist/safe-bash-presentation-engine/slide-transfer-budget.js +10 -9
  518. package/dist/safe-bash-presentation-engine/slides.js +19 -18
  519. package/dist/safe-bash-presentation-engine/table-operations.js +33 -32
  520. package/dist/safe-bash-presentation-engine/table-spans.js +32 -31
  521. package/dist/safe-bash-presentation-engine/tables.js +31 -30
  522. package/dist/safe-bash-presentation-engine/tags.d.ts +2 -0
  523. package/dist/safe-bash-presentation-engine/tags.js +26 -17
  524. package/dist/safe-bash-presentation-engine/template-bindings.js +33 -32
  525. package/dist/safe-bash-presentation-engine/template-repeat.js +40 -39
  526. package/dist/safe-bash-presentation-engine/text-fitting.js +27 -26
  527. package/dist/safe-bash-presentation-engine/text-frames.js +27 -26
  528. package/dist/safe-bash-presentation-engine/text-paragraphs.js +27 -26
  529. package/dist/safe-bash-presentation-engine/text-reading.js +12 -11
  530. package/dist/safe-bash-presentation-engine/text-replacement.js +17 -16
  531. package/dist/safe-bash-presentation-engine/text-runs.js +20 -19
  532. package/dist/safe-bash-presentation-engine/themes.js +16 -15
  533. package/dist/safe-bash-presentation-engine/transitions.js +16 -15
  534. package/dist/safe-bash-presentation-engine/validation.js +10 -9
  535. package/dist/safe-bash-presentation-engine/xml-parts.js +19 -18
  536. package/dist/safe-bash-presentation-engine/xml-view.js +4 -3
  537. package/dist/safe-bash-presentation-engine/xml.js +4 -3
  538. package/dist/safe-bash-query-engine/index.js +3 -3
  539. package/dist/safe-bash-query-engine/interpreter.js +2 -2
  540. package/dist/safe-bash-query-engine/query-core.js +3 -3
  541. package/dist/safe-bash-regex-engine/ere/matcher.js +3 -3
  542. package/dist/safe-bash-xml-engine/document.js +3 -3
  543. package/dist/safe-bash-xml-engine/evaluate.js +1 -1
  544. package/dist/safe-bash-xml-engine/index.js +4 -4
  545. package/dist/safe-bash-xml-engine/json.js +14 -10
  546. package/dist/safe-bash-xml-engine/query.js +2 -2
  547. package/dist/safe-bash-xml-engine/stored-document.d.ts +6 -0
  548. package/dist/safe-bash-xml-engine/stored-document.js +1 -1
  549. package/dist/safe-bash-xml-engine/stored-evaluate.js +4 -4
  550. package/dist/safe-bash-xml-engine/stored-namespaces.d.ts +21 -0
  551. package/dist/safe-bash-zip-engine/index.js +2 -2
  552. package/dist/safe-bash-zip-engine/zip/repair.js +2 -2
  553. package/dist/safe-bash-zip-engine/zip/safety.js +1 -1
  554. package/dist/safe-bash-zip-engine/zip/sfx.js +2 -2
  555. package/dist/safe-bash-zip-engine/zip/volumes.js +1 -1
  556. package/dist/safe-bash-zip-engine/zip-format.js +2 -2
  557. package/dist/spreadsheet-format-xls/biff-properties-merge.js +66 -70
  558. package/dist/spreadsheet-format-xls/biff-properties.d.ts +4 -2
  559. package/dist/spreadsheet-format-xls/biff-properties.js +141 -122
  560. package/dist/spreadsheet-format-xls/biff-property-names.d.ts +24 -0
  561. package/dist/spreadsheet-format-xls/biff-property-names.js +167 -0
  562. package/dist/spreadsheet-format-xls/biff-property-transcode.d.ts +6 -1
  563. package/dist/spreadsheet-format-xls/biff-property-transcode.js +15 -4
  564. package/dist/spreadsheet-format-xls/biff-property-values.d.ts +6 -1
  565. package/dist/spreadsheet-format-xls/biff-property-values.js +81 -12
  566. package/dist/xlsx-ast/comment-geometry.d.ts +12 -0
  567. package/dist/xlsx-ast/comment-geometry.js +71 -0
  568. package/dist/xlsx-ast/xlsx-metadata.d.ts +1 -1
  569. package/dist/xlsx-ast/xlsx-metadata.js +27 -2
  570. package/dist/xlsx-ast/xlsx-write-metadata.js +9 -1
  571. package/dist/xlsx-ast/xlsx.js +9 -4
  572. package/package.json +6 -3
  573. package/dist/safe-bash/command-chunks/biff-A7XPBWAK-DCLG5QKF.js +0 -5417
  574. package/dist/safe-bash/command-chunks/chunk-DBNJEXHK.js +0 -387
  575. package/dist/safe-bash/command-chunks/chunk-EV5G535P.js +0 -240
  576. package/dist/safe-bash/command-chunks/chunk-RHDERFMR.js +0 -161
  577. package/dist/safe-bash/command-chunks/chunk-ZUP5TBRG.js +0 -99
  578. package/dist/safe-bash/command-chunks/model-store-UB5DWMAP.js +0 -54
  579. package/dist/safe-bash/command-chunks/odf-3EA3EVSD-7B5GVNTC.js +0 -3097
  580. package/dist/safe-bash/command-chunks/{chunk-NGSO645G.js → chunk-3ZVK2OAY.js} +6 -6
  581. package/dist/safe-bash/command-chunks/{chunk-W2FKFEVY.js → chunk-4YSBUQPV.js} +3 -3
  582. package/dist/safe-bash/command-chunks/{chunk-UJSLBBQ7.js → chunk-5MFRN3CB.js} +4 -4
  583. package/dist/safe-bash/command-chunks/{chunk-AW4Q3GZW.js → chunk-5QXRIZSS.js} +3 -3
  584. package/dist/safe-bash/command-chunks/{chunk-KUGV3SSL.js → chunk-CZXYWGVO.js} +3 -3
  585. package/dist/safe-bash/command-chunks/{chunk-JWORWL72.js → chunk-DX7KU6YU.js} +3 -3
  586. package/dist/safe-bash/command-chunks/{chunk-Z37OM247.js → chunk-E3BL7W5C.js} +3 -3
  587. package/dist/safe-bash/command-chunks/{chunk-RIKNMBLZ.js → chunk-FEKECRJP.js} +3 -3
  588. package/dist/safe-bash/command-chunks/{chunk-D3HW7R2N.js → chunk-FTZFCMVI.js} +9 -9
  589. package/dist/safe-bash/command-chunks/{chunk-NBRXQUK7.js → chunk-M3OXQXCU.js} +3 -3
  590. package/dist/safe-bash/command-chunks/{chunk-JRSZ5IGD.js → chunk-OAM2SUUI.js} +6 -6
  591. package/dist/safe-bash/command-chunks/{chunk-HFKS6AET.js → chunk-OCOJMKDP.js} +4 -4
  592. package/dist/safe-bash/command-chunks/{chunk-FMJKCVSQ.js → chunk-OOB7YCFQ.js} +3 -3
  593. package/dist/safe-bash/command-chunks/{chunk-GGH376XQ.js → chunk-OU4VE5CR.js} +6 -6
  594. package/dist/safe-bash/command-chunks/{chunk-DYERIXPU.js → chunk-QGTQJCKW.js} +3 -3
  595. package/dist/safe-bash/command-chunks/{chunk-ZSQCROFE.js → chunk-RXXNLH7A.js} +3 -3
  596. package/dist/safe-bash/command-chunks/{chunk-TI52LKLL.js → chunk-UVM6QG2H.js} +3 -3
  597. package/dist/safe-bash/command-chunks/{chunk-BJXADHRT.js → chunk-WKU65Z3Q.js} +6 -6
  598. package/dist/safe-bash/command-chunks/{chunk-KGKF5NM2.js → chunk-WOXLPDO6.js} +3 -3
  599. package/dist/safe-bash/command-chunks/{chunk-Y5ADXWBQ.js → chunk-WXW665TV.js} +4 -4
  600. package/dist/safe-bash/command-chunks/{chunk-FWCUEZ3K.js → chunk-WYBCSJFG.js} +3 -3
  601. package/dist/safe-bash/command-chunks/{chunk-BXU5Y7I5.js → chunk-XI2LETBJ.js} +3 -3
  602. package/dist/safe-bash/command-chunks/{chunk-LNLACEAN.js → chunk-Y3ZRIZL7.js} +3 -3
@@ -336,6 +336,157 @@ var PdfStagingStorage = class {
336
336
  }
337
337
  };
338
338
 
339
+ // packages/pdf-ast/src/content/stored-path.ts
340
+ var BLOCK_BYTES = 4096;
341
+ var RECORD_BYTES = 56;
342
+ var RECORDS = Math.floor((BLOCK_BYTES - 8) / RECORD_BYTES);
343
+ var kinds = ["close", "move", "line", "cubic", "rect"];
344
+ var StoredPathWriter = class {
345
+ constructor(storage, signal) {
346
+ this.storage = storage;
347
+ this.signal = signal;
348
+ }
349
+ storage;
350
+ signal;
351
+ bytes = new Uint8Array(BLOCK_BYTES);
352
+ view = new DataView(this.bytes.buffer);
353
+ first = -1;
354
+ position = -1;
355
+ used = 0;
356
+ count = 0;
357
+ finished = false;
358
+ bounds = [Infinity, Infinity, -Infinity, -Infinity];
359
+ allocate() {
360
+ const at = this.storage.allocate(BLOCK_BYTES);
361
+ if (!Number.isSafeInteger(at) || at < 0 || !Number.isSafeInteger(at + BLOCK_BYTES)) throw new RangeError("Invalid PDF path allocation");
362
+ return at;
363
+ }
364
+ async append(segment) {
365
+ this.signal?.throwIfAborted();
366
+ if (this.finished) throw new Error("PDF path is already finished");
367
+ if (this.position === -1) this.first = this.position = this.allocate();
368
+ if (this.used === RECORDS) {
369
+ const next = this.allocate();
370
+ this.view.setFloat64(0, next, true);
371
+ await this.storage.write(this.position, this.bytes, this.signal ? { signal: this.signal } : void 0);
372
+ this.position = next;
373
+ this.used = 0;
374
+ }
375
+ const at = 8 + this.used++ * RECORD_BYTES;
376
+ this.view.setFloat64(at, kinds.indexOf(segment.kind), true);
377
+ const values = segment.kind === "close" ? [] : segment.kind === "cubic" ? [segment.x, segment.y, segment.x1, segment.y1, segment.x2, segment.y2] : segment.kind === "rect" ? [segment.x, segment.y, segment.width, segment.height] : [segment.x, segment.y];
378
+ for (let i = 0; i < values.length; i++) this.view.setFloat64(at + 8 + i * 8, values[i], true);
379
+ const include = (x, y) => {
380
+ this.bounds[0] = Math.min(this.bounds[0], x);
381
+ this.bounds[1] = Math.min(this.bounds[1], y);
382
+ this.bounds[2] = Math.max(this.bounds[2], x);
383
+ this.bounds[3] = Math.max(this.bounds[3], y);
384
+ };
385
+ if (segment.kind !== "close") include(segment.x, segment.y);
386
+ if (segment.kind === "cubic") {
387
+ include(segment.x1, segment.y1);
388
+ include(segment.x2, segment.y2);
389
+ }
390
+ if (segment.kind === "rect") include(segment.x + segment.width, segment.y + segment.height);
391
+ this.count++;
392
+ }
393
+ async finish() {
394
+ this.signal?.throwIfAborted();
395
+ if (this.finished) throw new Error("PDF path is already finished");
396
+ this.finished = true;
397
+ if (this.position !== -1) {
398
+ this.view.setFloat64(0, -1, true);
399
+ await this.storage.write(this.position, this.bytes.subarray(0, 8 + this.used * RECORD_BYTES), this.signal ? { signal: this.signal } : void 0);
400
+ }
401
+ return { kind: "stored-path", storage: this.storage, position: this.first, count: this.count, bounds: this.bounds };
402
+ }
403
+ };
404
+ async function* readStoredPath(path, signal) {
405
+ let position = path.position, remaining = path.count;
406
+ while (remaining > 0) {
407
+ signal?.throwIfAborted();
408
+ if (!Number.isSafeInteger(position) || position < 0) throw new Error("Invalid PDF path block");
409
+ const count = Math.min(RECORDS, remaining), length = 8 + count * RECORD_BYTES;
410
+ const bytes = (await path.storage.read(position, length, signal ? { signal } : void 0)).slice();
411
+ if (bytes.length !== length) throw new Error("Incomplete PDF path block");
412
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
413
+ position = view.getFloat64(0, true);
414
+ for (let i = 0; i < count; i++) {
415
+ signal?.throwIfAborted();
416
+ const at = 8 + i * RECORD_BYTES, kind = kinds[view.getFloat64(at, true)];
417
+ const value = (n) => view.getFloat64(at + 8 + n * 8, true);
418
+ if (kind === "close") yield { kind };
419
+ else if (kind === "move" || kind === "line") yield { kind, x: value(0), y: value(1) };
420
+ else if (kind === "rect") yield { kind, x: value(0), y: value(1), width: value(2), height: value(3) };
421
+ else if (kind === "cubic") yield { kind, x: value(0), y: value(1), x1: value(2), y1: value(3), x2: value(4), y2: value(5) };
422
+ else throw new Error("Invalid PDF path record");
423
+ }
424
+ remaining -= count;
425
+ }
426
+ }
427
+
428
+ // packages/pdf-ast/src/render/svg-path-stream.ts
429
+ function svgPathSegment(segment, height, matrix2) {
430
+ const point = (x, y) => matrix2 ? `${matrix2[0] * x + matrix2[2] * y + matrix2[4]} ${height - matrix2[1] * x - matrix2[3] * y - matrix2[5]}` : `${x} ${height - y}`;
431
+ switch (segment.kind) {
432
+ case "move":
433
+ return `M ${point(segment.x, segment.y)}`;
434
+ case "line":
435
+ return `L ${point(segment.x, segment.y)}`;
436
+ case "cubic":
437
+ return `C ${point(segment.x1, segment.y1)} ${point(segment.x2, segment.y2)} ${point(segment.x, segment.y)}`;
438
+ case "rect":
439
+ return matrix2 ? `M ${point(segment.x, segment.y)} L ${point(segment.x + segment.width, segment.y)} L ${point(segment.x + segment.width, segment.y + segment.height)} L ${point(segment.x, segment.y + segment.height)} Z` : `M ${segment.x} ${height - segment.y} h ${segment.width} v ${-segment.height} h ${-segment.width} Z`;
440
+ case "close":
441
+ return "Z";
442
+ }
443
+ }
444
+ function limit(value) {
445
+ if (value === void 0 || value === Infinity) return Infinity;
446
+ if (!Number.isSafeInteger(value) || value < 0) throw new RangeError("Invalid SVG path limit");
447
+ return value;
448
+ }
449
+ async function* encodeSvgPathDataChunks(input, height, options = {}) {
450
+ const { signal } = options;
451
+ signal?.throwIfAborted();
452
+ const chunkBytes = options.chunkBytes ?? 16384, maxSegments = limit(options.maxSegments), maximum10 = limit(options.maxOutputBytes);
453
+ if (!Number.isSafeInteger(chunkBytes) || chunkBytes < 1) throw new RangeError("Invalid SVG path chunk size");
454
+ const stored = "kind" in input && input.kind === "stored-path" ? input : void 0;
455
+ if (stored && (!Number.isSafeInteger(stored.count) || stored.count < 0)) throw new RangeError("Invalid stored SVG path count");
456
+ if (stored && stored.count > maxSegments) throw new PdfError("E_LIMIT", "SVG path segment limit exceeded");
457
+ const source = stored ? readStoredPath(stored, signal) : input;
458
+ const buffer = new Uint8Array(Math.min(16384, chunkBytes)), encoder = new TextEncoder();
459
+ let used = 0, count = 0, total = 0, first = true;
460
+ for await (const segment of source) {
461
+ signal?.throwIfAborted();
462
+ if (count >= maxSegments) throw new PdfError("E_LIMIT", "SVG path segment limit exceeded");
463
+ if (++count % 64 === 0) {
464
+ await new Promise((resolve2) => setTimeout(resolve2, 0));
465
+ signal?.throwIfAborted();
466
+ }
467
+ const part = svgPathSegment(segment, height, options.matrix);
468
+ if (part === void 0) continue;
469
+ const text = (first ? "" : " ") + part;
470
+ first = false;
471
+ if (text.length > maximum10 - total || !Number.isSafeInteger(total + text.length)) throw new PdfError("E_LIMIT", "SVG path output byte limit exceeded");
472
+ total += text.length;
473
+ const bytes = encoder.encode(text);
474
+ for (let at = 0; at < bytes.length; ) {
475
+ signal?.throwIfAborted();
476
+ const take = Math.min(buffer.length - used, bytes.length - at);
477
+ buffer.set(bytes.subarray(at, at + take), used);
478
+ used += take;
479
+ at += take;
480
+ if (used === buffer.length) {
481
+ yield buffer.slice();
482
+ used = 0;
483
+ }
484
+ }
485
+ }
486
+ signal?.throwIfAborted();
487
+ if (used) yield buffer.slice(0, used);
488
+ }
489
+
339
490
  // packages/pdf-ast/src/content/stored-record.ts
340
491
  function* encodeParts(value, storage, key, ancestors) {
341
492
  if (key === "storage") {
@@ -522,6 +673,87 @@ var RecordReader = class {
522
673
  }
523
674
  return result;
524
675
  }
676
+ async size(tag) {
677
+ const bytes = await this.take(8);
678
+ const size = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getFloat64(0, true);
679
+ if (!Number.isSafeInteger(size) || size < 0 || size > this.remaining || tag === 4 /* String */ && size * 2 > this.remaining) throw new Error("Invalid capture field length");
680
+ return size;
681
+ }
682
+ async discard(length) {
683
+ while (length) {
684
+ const count = Math.min(length, 4096);
685
+ await this.take(count);
686
+ length -= count;
687
+ }
688
+ }
689
+ async stringEquals(expected) {
690
+ const length = await this.size(4 /* String */);
691
+ let equal2 = length === expected.length;
692
+ for (let at = 0; at < length; at += 2048) {
693
+ const bytes = await this.take(Math.min(2048, length - at) * 2);
694
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
695
+ if (equal2) for (let i = 0; i < bytes.length / 2; i++) {
696
+ if (view.getUint16(i * 2, true) !== expected.charCodeAt(at + i)) {
697
+ equal2 = false;
698
+ break;
699
+ }
700
+ }
701
+ }
702
+ return equal2;
703
+ }
704
+ /** Skip without constructing arrays, strings or byte payloads. Only 32
705
+ * container counters stay resident; deeper counters use caller backing. */
706
+ async skip(tag) {
707
+ const frames = [];
708
+ const spilled = new StoredMetadataStack(this.storage, this.signal);
709
+ let remaining = 1;
710
+ for (; ; ) {
711
+ if (remaining === 0) {
712
+ const parent = frames.pop() ?? await spilled.pop();
713
+ if (parent === void 0) return;
714
+ remaining = parent;
715
+ continue;
716
+ }
717
+ if (remaining === -1) {
718
+ const field3 = (await this.take(1))[0];
719
+ if (field3 === 9 /* End */) {
720
+ remaining = 0;
721
+ continue;
722
+ }
723
+ if (field3 !== 4 /* String */) throw new Error("Invalid capture key");
724
+ await this.discard(await this.size(4 /* String */) * 2);
725
+ } else remaining--;
726
+ const current = tag ?? (await this.take(1))[0];
727
+ tag = void 0;
728
+ if (current === 8 /* Object */ || current === 7 /* Array */) {
729
+ const children = current === 8 /* Object */ ? -1 : await this.size(7 /* Array */);
730
+ if (frames.length === 32) await spilled.push(frames.shift());
731
+ frames.push(remaining);
732
+ remaining = children;
733
+ } else if (current === 4 /* String */ || current === 5 /* Bytes */) {
734
+ await this.discard(await this.size(current) * (current === 4 /* String */ ? 2 : 1));
735
+ } else if (current === 3 /* Number */) await this.take(8);
736
+ else if (current !== 0 /* Null */ && current !== 1 /* False */ && current !== 2 /* True */ && current !== 6 /* Storage */) {
737
+ throw new Error("Invalid capture tag");
738
+ }
739
+ }
740
+ }
741
+ async matches(path, expected, depth = 0) {
742
+ const tag = (await this.take(1))[0];
743
+ if (depth === path.length && tag === 4 /* String */) return this.stringEquals(expected);
744
+ if (depth === path.length || tag !== 8 /* Object */) {
745
+ await this.skip(tag);
746
+ return false;
747
+ }
748
+ let matched = false;
749
+ for (; ; ) {
750
+ const field3 = (await this.take(1))[0];
751
+ if (field3 === 9 /* End */) return matched;
752
+ if (field3 !== 4 /* String */) throw new Error("Invalid capture key");
753
+ if (await this.stringEquals(path[depth])) matched = await this.matches(path, expected, depth + 1);
754
+ else await this.skip();
755
+ }
756
+ }
525
757
  async value(tag) {
526
758
  tag ??= (await this.take(1))[0];
527
759
  if (tag === 0 /* Null */) return null;
@@ -531,10 +763,10 @@ var RecordReader = class {
531
763
  if (tag === 8 /* Object */) {
532
764
  const value2 = {};
533
765
  for (; ; ) {
534
- const field2 = (await this.take(1))[0];
535
- if (field2 === 9 /* End */) return value2;
536
- if (field2 !== 4 /* String */) throw new Error("Invalid capture key");
537
- const key = await this.value(field2);
766
+ const field3 = (await this.take(1))[0];
767
+ if (field3 === 9 /* End */) return value2;
768
+ if (field3 !== 4 /* String */) throw new Error("Invalid capture key");
769
+ const key = await this.value(field3);
538
770
  Object.defineProperty(value2, key, {
539
771
  value: await this.value(),
540
772
  enumerable: true,
@@ -571,7 +803,7 @@ var RecordReader = class {
571
803
  return value;
572
804
  }
573
805
  };
574
- async function readStoredRecord(storage, position, signal) {
806
+ async function openStoredRecord(storage, position, signal) {
575
807
  signal?.throwIfAborted();
576
808
  if (!Number.isSafeInteger(position) || position < 0)
577
809
  throw new RangeError("Invalid capture position");
@@ -581,11 +813,22 @@ async function readStoredRecord(storage, position, signal) {
581
813
  const view = new DataView(header2.buffer, header2.byteOffset, header2.byteLength), next = view.getFloat64(0, true), length = view.getFloat64(8, true);
582
814
  if (!Number.isSafeInteger(length) || length < 1 || !Number.isSafeInteger(position + 16 + length))
583
815
  throw new RangeError("Invalid capture length");
584
- const reader = new RecordReader(storage, position + 16, length, signal), value = await reader.value();
816
+ return { reader: new RecordReader(storage, position + 16, length, signal), next };
817
+ }
818
+ async function readStoredRecord(storage, position, signal) {
819
+ const { reader, next } = await openStoredRecord(storage, position, signal);
820
+ const value = await reader.value();
585
821
  if (reader.remaining) throw new Error("Trailing capture bytes");
586
822
  signal?.throwIfAborted();
587
823
  return { value, next };
588
824
  }
825
+ async function storedRecordMatches(storage, position, path, expected, signal) {
826
+ const { reader, next } = await openStoredRecord(storage, position, signal);
827
+ const matched = await reader.matches(path, expected);
828
+ if (reader.remaining) throw new Error("Trailing capture bytes");
829
+ signal?.throwIfAborted();
830
+ return { matched, next };
831
+ }
589
832
  var StoredMetadataStack = class {
590
833
  constructor(storage, signal) {
591
834
  this.storage = storage;
@@ -699,95 +942,6 @@ async function* readStoredOperations(source, signal) {
699
942
  }
700
943
  }
701
944
 
702
- // packages/pdf-ast/src/content/stored-path.ts
703
- var BLOCK_BYTES = 4096;
704
- var RECORD_BYTES = 56;
705
- var RECORDS = Math.floor((BLOCK_BYTES - 8) / RECORD_BYTES);
706
- var kinds = ["close", "move", "line", "cubic", "rect"];
707
- var StoredPathWriter = class {
708
- constructor(storage, signal) {
709
- this.storage = storage;
710
- this.signal = signal;
711
- }
712
- storage;
713
- signal;
714
- bytes = new Uint8Array(BLOCK_BYTES);
715
- view = new DataView(this.bytes.buffer);
716
- first = -1;
717
- position = -1;
718
- used = 0;
719
- count = 0;
720
- finished = false;
721
- bounds = [Infinity, Infinity, -Infinity, -Infinity];
722
- allocate() {
723
- const at = this.storage.allocate(BLOCK_BYTES);
724
- if (!Number.isSafeInteger(at) || at < 0 || !Number.isSafeInteger(at + BLOCK_BYTES)) throw new RangeError("Invalid PDF path allocation");
725
- return at;
726
- }
727
- async append(segment) {
728
- this.signal?.throwIfAborted();
729
- if (this.finished) throw new Error("PDF path is already finished");
730
- if (this.position === -1) this.first = this.position = this.allocate();
731
- if (this.used === RECORDS) {
732
- const next = this.allocate();
733
- this.view.setFloat64(0, next, true);
734
- await this.storage.write(this.position, this.bytes, this.signal ? { signal: this.signal } : void 0);
735
- this.position = next;
736
- this.used = 0;
737
- }
738
- const at = 8 + this.used++ * RECORD_BYTES;
739
- this.view.setFloat64(at, kinds.indexOf(segment.kind), true);
740
- const values = segment.kind === "close" ? [] : segment.kind === "cubic" ? [segment.x, segment.y, segment.x1, segment.y1, segment.x2, segment.y2] : segment.kind === "rect" ? [segment.x, segment.y, segment.width, segment.height] : [segment.x, segment.y];
741
- for (let i = 0; i < values.length; i++) this.view.setFloat64(at + 8 + i * 8, values[i], true);
742
- const include = (x, y) => {
743
- this.bounds[0] = Math.min(this.bounds[0], x);
744
- this.bounds[1] = Math.min(this.bounds[1], y);
745
- this.bounds[2] = Math.max(this.bounds[2], x);
746
- this.bounds[3] = Math.max(this.bounds[3], y);
747
- };
748
- if (segment.kind !== "close") include(segment.x, segment.y);
749
- if (segment.kind === "cubic") {
750
- include(segment.x1, segment.y1);
751
- include(segment.x2, segment.y2);
752
- }
753
- if (segment.kind === "rect") include(segment.x + segment.width, segment.y + segment.height);
754
- this.count++;
755
- }
756
- async finish() {
757
- this.signal?.throwIfAborted();
758
- if (this.finished) throw new Error("PDF path is already finished");
759
- this.finished = true;
760
- if (this.position !== -1) {
761
- this.view.setFloat64(0, -1, true);
762
- await this.storage.write(this.position, this.bytes.subarray(0, 8 + this.used * RECORD_BYTES), this.signal ? { signal: this.signal } : void 0);
763
- }
764
- return { kind: "stored-path", storage: this.storage, position: this.first, count: this.count, bounds: this.bounds };
765
- }
766
- };
767
- async function* readStoredPath(path, signal) {
768
- let position = path.position, remaining = path.count;
769
- while (remaining > 0) {
770
- signal?.throwIfAborted();
771
- if (!Number.isSafeInteger(position) || position < 0) throw new Error("Invalid PDF path block");
772
- const count = Math.min(RECORDS, remaining), length = 8 + count * RECORD_BYTES;
773
- const bytes = (await path.storage.read(position, length, signal ? { signal } : void 0)).slice();
774
- if (bytes.length !== length) throw new Error("Incomplete PDF path block");
775
- const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
776
- position = view.getFloat64(0, true);
777
- for (let i = 0; i < count; i++) {
778
- signal?.throwIfAborted();
779
- const at = 8 + i * RECORD_BYTES, kind = kinds[view.getFloat64(at, true)];
780
- const value = (n) => view.getFloat64(at + 8 + n * 8, true);
781
- if (kind === "close") yield { kind };
782
- else if (kind === "move" || kind === "line") yield { kind, x: value(0), y: value(1) };
783
- else if (kind === "rect") yield { kind, x: value(0), y: value(1), width: value(2), height: value(3) };
784
- else if (kind === "cubic") yield { kind, x: value(0), y: value(1), x1: value(2), y1: value(3), x2: value(4), y2: value(5) };
785
- else throw new Error("Invalid PDF path record");
786
- }
787
- remaining -= count;
788
- }
789
- }
790
-
791
945
  // packages/pdf-ast/src/content/stored-clips.ts
792
946
  var PAGE_BYTES = 4096;
793
947
  var RECORD_BYTES2 = 64;
@@ -14851,17 +15005,17 @@ var Type1Font = class {
14851
15005
  "StdHW",
14852
15006
  "StdVW"
14853
15007
  ];
14854
- for (const field2 of fields2) {
14855
- if (!properties.privateData.has(field2)) {
15008
+ for (const field3 of fields2) {
15009
+ if (!properties.privateData.has(field3)) {
14856
15010
  continue;
14857
15011
  }
14858
- const value = properties.privateData.get(field2);
15012
+ const value = properties.privateData.get(field3);
14859
15013
  if (Array.isArray(value)) {
14860
15014
  for (let j = value.length - 1; j > 0; j--) {
14861
15015
  value[j] -= value[j - 1];
14862
15016
  }
14863
15017
  }
14864
- privateDict.setByName(field2, value);
15018
+ privateDict.setByName(field3, value);
14865
15019
  }
14866
15020
  cff.topDict.privateDict = privateDict;
14867
15021
  const subrIndex = new CFFIndex();
@@ -18715,14 +18869,14 @@ var FlateStream = class extends DecodeStream {
18715
18869
  throw new FormatError("Unknown block type in flate stream");
18716
18870
  }
18717
18871
  buffer = this.buffer;
18718
- let limit10 = buffer ? buffer.length : 0;
18872
+ let limit11 = buffer ? buffer.length : 0;
18719
18873
  let pos = this.bufferLength;
18720
18874
  while (true) {
18721
18875
  let code1 = this.getCode(litCodeTable);
18722
18876
  if (code1 < 256) {
18723
- if (pos + 1 >= limit10) {
18877
+ if (pos + 1 >= limit11) {
18724
18878
  buffer = this.ensureBuffer(pos + 1);
18725
- limit10 = buffer.length;
18879
+ limit11 = buffer.length;
18726
18880
  }
18727
18881
  buffer[pos++] = code1;
18728
18882
  continue;
@@ -18745,9 +18899,9 @@ var FlateStream = class extends DecodeStream {
18745
18899
  code2 = this.getBits(code2);
18746
18900
  }
18747
18901
  const dist = (code1 & 65535) + code2;
18748
- if (pos + len >= limit10) {
18902
+ if (pos + len >= limit11) {
18749
18903
  buffer = this.ensureBuffer(pos + len);
18750
- limit10 = buffer.length;
18904
+ limit11 = buffer.length;
18751
18905
  }
18752
18906
  for (let k = 0; k < len; ++k, ++pos) {
18753
18907
  buffer[pos] = buffer[pos - dist];
@@ -28224,6 +28378,8 @@ function* repairCandidateSteps(size) {
28224
28378
  // packages/pdf-ast/src/cos/value-parser.ts
28225
28379
  function* parseValueSteps(lexer, maxDepth, repair = false, maxNodes = Infinity, options = {}) {
28226
28380
  yield;
28381
+ if (options.deferArrayValues && !options.deferDictionaryValues) throw new TypeError("Deferred array values require deferred dictionary values");
28382
+ if (options.deferDictionaryValues && (!options.dictionaryStorage || options.arrayStorage !== options.dictionaryStorage || options.stringStorage !== options.dictionaryStorage || options.containerStorage !== options.dictionaryStorage)) throw new TypeError("Deferred resource values require shared caller backing");
28227
28383
  let work = 0;
28228
28384
  let nodes = 0;
28229
28385
  const charge = () => {
@@ -28233,14 +28389,15 @@ function* parseValueSteps(lexer, maxDepth, repair = false, maxNodes = Infinity,
28233
28389
  const residentDepth = 32;
28234
28390
  const stack = [];
28235
28391
  let current, depth = 0;
28236
- const pathLength = (options.storedArrayPaths ?? []).reduce((length, path) => Math.max(length, path.length - 1), 0);
28237
- function matchesStoredPath(parent) {
28238
- return options.storedArrayPaths?.some((path) => {
28239
- const length = parent.path.length + 1;
28392
+ const pathLength = [...options.storedArrayPaths ?? [], ...options.storedDictionaryPaths ?? []].reduce((length, path) => Math.max(length, path.length - 1), 0);
28393
+ function matchesStoredPath(parent, paths) {
28394
+ const currentPath = parent ? [...parent.path, parent.kind === "dict" ? parent.key?.decoded : null] : options.arrayPathPrefix ?? [];
28395
+ return paths?.some((path) => {
28396
+ const length = currentPath.length;
28240
28397
  if (!path.length || path.length > length) return false;
28241
28398
  for (let i = 0; i < path.length; i++) {
28242
28399
  const at = length - path.length + i;
28243
- const key = at === parent.path.length ? parent.kind === "dict" ? parent.key?.decoded : void 0 : parent.path[at];
28400
+ const key = currentPath[at];
28244
28401
  if (key == null || path[i] !== "*" && path[i] !== key) return false;
28245
28402
  }
28246
28403
  return true;
@@ -28265,7 +28422,9 @@ function* parseValueSteps(lexer, maxDepth, repair = false, maxNodes = Infinity,
28265
28422
  while (true) {
28266
28423
  if (++work % 16 === 0) yield;
28267
28424
  const parent = current;
28268
- lexer.setStringStorage?.(options.stringStorage && (parent?.kind === "dict" && parent.key && options.storedStringKeys?.includes(parent.key.decoded) || !parent && options.storeRootString) ? options.stringStorage : void 0);
28425
+ const deferred = options.deferDictionaryValues && (parent?.deferred || parent?.kind === "dict" && parent.storedEntries || options.deferArrayValues && parent?.kind === "array" && parent.storedItems);
28426
+ const selectedString = parent?.kind === "dict" && parent.key && options.storedStringKeys?.includes(parent.key.decoded) || !parent && options.storeRootString;
28427
+ lexer.setStringStorage?.(options.stringStorage && (selectedString || deferred) ? options.stringStorage : void 0);
28269
28428
  const tok = yield "token";
28270
28429
  if (!tok) {
28271
28430
  if (!parent) return void 0;
@@ -28278,11 +28437,11 @@ function* parseValueSteps(lexer, maxDepth, repair = false, maxNodes = Infinity,
28278
28437
  let node;
28279
28438
  if (parent?.kind === "array" && tok.kind === "array-end") {
28280
28439
  yield* pop();
28281
- node = { kind: "array", items: parent.items, ...parent.storedItems ? { storedItems: parent.storedItems } : {}, span: { start: parent.start, end: tok.span.end } };
28440
+ node = { kind: "array", items: parent.items, ...parent.deferred ? { deferred: true } : {}, ...parent.storedItems ? { storedItems: parent.storedItems } : {}, span: { start: parent.start, end: tok.span.end } };
28282
28441
  } else if (parent?.kind === "dict" && !parent.key) {
28283
28442
  if (tok.kind === "dict-end") {
28284
28443
  yield* pop();
28285
- node = yield { kind: "dict", entries: parent.entries, ...parent.storedEntries ? { storedEntries: parent.storedEntries } : {}, span: { start: parent.start, end: tok.span.end } };
28444
+ node = yield { kind: "dict", entries: parent.entries, ...parent.deferred ? { deferred: true } : {}, ...parent.storedEntries ? { storedEntries: parent.storedEntries } : {}, span: { start: parent.start, end: tok.span.end } };
28286
28445
  } else if (tok.kind === "name") {
28287
28446
  charge();
28288
28447
  parent.key = { kind: "name", rawBytes: tok.rawBytes, decoded: tok.decoded, span: tok.span };
@@ -28298,30 +28457,33 @@ function* parseValueSteps(lexer, maxDepth, repair = false, maxNodes = Infinity,
28298
28457
  charge();
28299
28458
  if (depth > maxDepth) throw new PdfError("E_LIMIT", "PDF syntax nesting limit exceeded");
28300
28459
  if (tok.kind === "array-start") {
28301
- const backed = options.arrayStorage && (parent?.kind === "array" && parent.storedItems || parent?.kind === "dict" && (options.storedArrayKeys?.includes(parent.key.decoded) || matchesStoredPath(parent)) || !parent && options.storeRootArray);
28460
+ const backed = options.arrayStorage && (parent?.kind === "array" && parent.storedItems && !parent.deferred || parent?.kind === "dict" && (options.storedArrayKeys?.includes(parent.key.decoded) || matchesStoredPath(parent, options.storedArrayPaths)) || !parent && options.storeRootArray);
28302
28461
  yield* push({
28303
28462
  kind: "array",
28304
28463
  path: ancestorPath(parent),
28305
28464
  start: tok.span.start,
28306
28465
  items: [],
28307
28466
  tail: -1,
28308
- ...backed ? { storedItems: { storage: options.arrayStorage, position: -1, length: 0 } } : {}
28467
+ ...deferred && !backed ? { deferred: true } : {},
28468
+ ...backed || deferred ? { storedItems: { storage: options.arrayStorage, position: -1, length: 0 } } : {}
28309
28469
  });
28310
28470
  continue;
28311
28471
  }
28312
28472
  if (tok.kind === "dict-start") {
28313
- const backed = options.dictionaryStorage && (parent?.kind === "dict" && !parent.storedEntries && options.storedDictionaryKeys?.includes(parent.key.decoded) || !parent && options.storeRootDictionary);
28473
+ const backed = options.dictionaryStorage && (parent?.kind === "dict" && (!parent.storedEntries || parent.deferred) && (options.storedDictionaryKeys?.includes(parent.key.decoded) || matchesStoredPath(parent, options.storedDictionaryPaths)) || !parent && (options.storeRootDictionary || matchesStoredPath(void 0, options.storedDictionaryPaths)));
28314
28474
  yield* push({
28315
28475
  kind: "dict",
28316
28476
  path: ancestorPath(parent),
28317
28477
  start: tok.span.start,
28318
28478
  entries: [],
28319
28479
  tail: -1,
28320
- ...backed ? { storedEntries: { storage: options.dictionaryStorage, position: -1, length: 0 } } : {}
28480
+ ...deferred && !backed ? { deferred: true } : {},
28481
+ ...backed || deferred ? { storedEntries: { storage: options.dictionaryStorage, position: -1, length: 0 } } : {}
28321
28482
  });
28322
28483
  continue;
28323
28484
  }
28324
28485
  node = yield* parseLeafFromToken(tok, lexer);
28486
+ if (deferred && !selectedString && node.kind === "string") node = { ...node, deferred: true };
28325
28487
  }
28326
28488
  const container = current;
28327
28489
  if (!container) return node;
@@ -28680,8 +28842,8 @@ var PdfNameIndex = class {
28680
28842
  this.storage = storage;
28681
28843
  this.maximum = maximum10;
28682
28844
  this.signal = signal;
28683
- const limit10 = typeof maximum10 === "function" ? maximum10() : maximum10;
28684
- if (limit10 !== Infinity && (!Number.isSafeInteger(limit10) || limit10 < 0)) throw new RangeError("Invalid name staging limit");
28845
+ const limit11 = typeof maximum10 === "function" ? maximum10() : maximum10;
28846
+ if (limit11 !== Infinity && (!Number.isSafeInteger(limit11) || limit11 < 0)) throw new RangeError("Invalid name staging limit");
28685
28847
  }
28686
28848
  storage;
28687
28849
  maximum;
@@ -28720,8 +28882,8 @@ var PdfNameIndex = class {
28720
28882
  for (const [objectNumber, offset] of tail) yield { objectNumber, offset, type: "uncompressed" };
28721
28883
  for (const index2 of inputs) yield* index2.entries(signal);
28722
28884
  }
28723
- const limit10 = typeof this.maximum === "function" ? this.maximum() : this.maximum;
28724
- const remaining = Math.min(limit10, Number.MAX_SAFE_INTEGER) - this.stagedBytes;
28885
+ const limit11 = typeof this.maximum === "function" ? this.maximum() : this.maximum;
28886
+ const remaining = Math.min(limit11, Number.MAX_SAFE_INTEGER) - this.stagedBytes;
28725
28887
  if (remaining < 0) throw new PdfError("E_LIMIT", "PDF name staging byte limit exceeded");
28726
28888
  const combined = await PdfObjectIndex.build(rows(), this.storage, {
28727
28889
  runEntries: 64,
@@ -28791,7 +28953,7 @@ var PdfNameIndex = class {
28791
28953
  };
28792
28954
 
28793
28955
  // packages/pdf-ast/src/content/stored-dictionary.ts
28794
- async function* readPdfDictionaryEntries(dict, signal) {
28956
+ async function* readRawPdfDictionaryEntries(dict, signal) {
28795
28957
  signal?.throwIfAborted();
28796
28958
  if (dict.storedEntries) yield* readStoredItems(dict.storedEntries, signal);
28797
28959
  else for (const entry of dict.entries) {
@@ -28799,10 +28961,59 @@ async function* readPdfDictionaryEntries(dict, signal) {
28799
28961
  yield entry;
28800
28962
  }
28801
28963
  }
28802
- async function readPdfDictionaryValue(dict, key, signal) {
28964
+ async function materializeResourceValue(node, signal) {
28965
+ signal?.throwIfAborted();
28966
+ if (node.kind === "dict" && node.deferred && node.storedEntries) {
28967
+ const { deferred: ignoredDeferred, storedEntries: ignoredEntries, ...ordinary } = node;
28968
+ const entries = [];
28969
+ for await (const entry of readRawPdfDictionaryEntries(node, signal)) entries.push({ ...entry, value: await materializeResourceValue(entry.value, signal) });
28970
+ return { ...ordinary, entries };
28971
+ }
28972
+ if (node.kind === "array" && node.deferred && node.storedItems) {
28973
+ const { deferred: ignoredDeferred, storedItems: ignoredItems, ...ordinary } = node;
28974
+ const items = [];
28975
+ for await (const item of readStoredItems(node.storedItems, signal)) items.push(await materializeResourceValue(item, signal));
28976
+ return { ...ordinary, items };
28977
+ }
28978
+ if (node.kind === "string" && node.deferred && node.storedBytes) {
28979
+ const { deferred: ignoredDeferred, storedBytes, ...ordinary } = node;
28980
+ if (!Number.isSafeInteger(storedBytes.byteLength) || storedBytes.byteLength < 0) throw new RangeError("Invalid deferred resource string length");
28981
+ const bytes = new Uint8Array(storedBytes.byteLength);
28982
+ for (let at = 0; at < bytes.length; at += 4096) {
28983
+ if (at && at % 65536 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
28984
+ const length = Math.min(4096, bytes.length - at);
28985
+ const chunk = await storedBytes.storage.read(storedBytes.position + at, length, signal ? { signal } : void 0);
28986
+ signal?.throwIfAborted();
28987
+ if (chunk.length !== length) throw new Error("Incomplete deferred resource string");
28988
+ bytes.set(chunk, at);
28989
+ }
28990
+ return { ...ordinary, bytes };
28991
+ }
28992
+ return node;
28993
+ }
28994
+ async function* readPdfDictionaryEntries(dict, signal) {
28995
+ for await (const entry of readRawPdfDictionaryEntries(dict, signal)) yield { ...entry, value: await materializeResourceValue(entry.value, signal) };
28996
+ }
28997
+ async function readPdfDictionaryValue(dict, key, signal, options = {}) {
28998
+ if (dict.storedEntries) {
28999
+ const { storage, length } = dict.storedEntries;
29000
+ if (!Number.isSafeInteger(length) || length < 0) throw new RangeError("Invalid stored array length");
29001
+ let position = dict.storedEntries.position, selected = -1;
29002
+ for (let i = 0; i < length; i++) {
29003
+ if (i && i % 256 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
29004
+ const record = await storedRecordMatches(storage, position, ["key", "decoded"], key, signal);
29005
+ if (record.matched) selected = position;
29006
+ position = record.next;
29007
+ }
29008
+ if (position !== -1) throw new Error("Invalid stored array terminator");
29009
+ signal?.throwIfAborted();
29010
+ if (selected === -1) return void 0;
29011
+ const value2 = (await readStoredRecord(storage, selected, signal)).value.value;
29012
+ return options.preserveDeferred ? value2 : materializeResourceValue(value2, signal);
29013
+ }
28803
29014
  let value;
28804
- for await (const entry of readPdfDictionaryEntries(dict, signal)) if (entry.key.decoded === key) value = entry.value;
28805
- return value;
29015
+ for await (const entry of readRawPdfDictionaryEntries(dict, signal)) if (entry.key.decoded === key) value = entry.value;
29016
+ return value && !options.preserveDeferred ? materializeResourceValue(value, signal) : value;
28806
29017
  }
28807
29018
  async function mergePdfResourceDictionaries(destination, source, indexStorage, signal) {
28808
29019
  const storage = destination.storedEntries?.storage ?? source?.storedEntries?.storage;
@@ -28812,7 +29023,7 @@ async function mergePdfResourceDictionaries(destination, source, indexStorage, s
28812
29023
  async function* rows() {
28813
29024
  for (const [dict, replace] of [[destination, true], [source, false]]) {
28814
29025
  if (!dict) continue;
28815
- for await (const entry of readPdfDictionaryEntries(dict, signal)) {
29026
+ for await (const entry of readRawPdfDictionaryEntries(dict, signal)) {
28816
29027
  const name = await names.intern(entry.key.decoded);
28817
29028
  if (!replace && !name.added) continue;
28818
29029
  const position = await writeStoredRecord(storage, entry, -1, signal);
@@ -30901,13 +31112,13 @@ async function decryptPdfObjectStrings(state, objectNumber, generationNumber, va
30901
31112
  let signatureDict = node;
30902
31113
  if (node.storedEntries) {
30903
31114
  signatureDict = { kind: "dict", entries: [] };
30904
- for await (const entry of readPdfDictionaryEntries(node, options.signal)) {
31115
+ for await (const entry of readRawPdfDictionaryEntries(node, options.signal)) {
30905
31116
  if (["Type", "FT", "ByteRange", "Filter"].includes(entry.key.decoded)) dictSet(signatureDict, entry.key.decoded, entry.value);
30906
31117
  }
30907
31118
  }
30908
31119
  const signature = isSignatureDictionary(signatureDict);
30909
31120
  let position = -1, tail = -1;
30910
- for await (const entry of readPdfDictionaryEntries(node, options.signal)) {
31121
+ for await (const entry of readRawPdfDictionaryEntries(node, options.signal)) {
30911
31122
  const transformed = { key: entry.key, value: signature && entry.key.decoded === "Contents" ? entry.value : await transform(entry.value) };
30912
31123
  if (node.storedEntries) {
30913
31124
  tail = await appendStoredRecord(node.storedEntries.storage, transformed, tail, options.signal);
@@ -31635,27 +31846,27 @@ function* parseXrefRevisionAtSteps(bytes, xrefOffset, maxDecompressedBytes, maxR
31635
31846
  const objNum = startObj + i;
31636
31847
  const field0 = w0 > 0 ? readInt(w0) : 1;
31637
31848
  const field1 = readInt(w1);
31638
- const field2 = w2 > 0 ? readInt(w2) : 0;
31849
+ const field22 = w2 > 0 ? readInt(w2) : 0;
31639
31850
  if (field0 === 0) {
31640
31851
  entries.set(objNum, {
31641
31852
  type: "free",
31642
31853
  objectNumber: objNum,
31643
31854
  nextFreeObjectNumber: field1,
31644
- generationNumber: field2
31855
+ generationNumber: field22
31645
31856
  });
31646
31857
  } else if (field0 === 1) {
31647
31858
  entries.set(objNum, {
31648
31859
  type: "uncompressed",
31649
31860
  objectNumber: objNum,
31650
31861
  offset: field1,
31651
- generationNumber: field2
31862
+ generationNumber: field22
31652
31863
  });
31653
31864
  } else if (field0 === 2) {
31654
31865
  entries.set(objNum, {
31655
31866
  type: "compressed",
31656
31867
  objectNumber: objNum,
31657
31868
  objectStreamNumber: field1,
31658
- indexInStream: field2
31869
+ indexInStream: field22
31659
31870
  });
31660
31871
  } else {
31661
31872
  throw new PdfError("E_PARSE", `Invalid XRef entry type: ${field0}`);
@@ -33259,13 +33470,19 @@ function embedTrueTypeFontInCos(doc, font, usedGlyphs) {
33259
33470
  }
33260
33471
 
33261
33472
  // packages/pdf-ast/src/fonts/resolve.ts
33262
- function* resolve(node, storeRootArray = false, storeRootDictionary = false) {
33263
- const value = yield { kind: "resolve", node, storeRootArray, storeRootDictionary };
33473
+ function* field(dict, key) {
33474
+ if (!dict.storedEntries) return dictGet(dict, key);
33475
+ const value = yield { kind: "dictionary-value", dict, key };
33476
+ if (value && !("kind" in value)) throw new TypeError("Expected a font dictionary value");
33477
+ return value;
33478
+ }
33479
+ function* resolve(node, storeRootArray = false, storeRootDictionary = false, arrayPathPrefix) {
33480
+ const value = yield { kind: "resolve", node, storeRootArray, storeRootDictionary, ...arrayPathPrefix ? { arrayPathPrefix } : {} };
33264
33481
  if (value && !("kind" in value)) throw new TypeError("Font lookup returned stream bytes instead of a COS value");
33265
33482
  return value;
33266
33483
  }
33267
- function* resolveDict2(node, backed = false) {
33268
- const value = yield* resolve(node, false, backed);
33484
+ function* resolveDict2(node, backed = false, path) {
33485
+ const value = yield* resolve(node, false, backed, path);
33269
33486
  return value?.kind === "dict" ? value : value?.kind === "stream" ? value.dict : void 0;
33270
33487
  }
33271
33488
  function* resolveArray2(node, backed = false) {
@@ -33296,10 +33513,10 @@ function* resolvePageFontsSteps(rootRef, resourcesDict, selectedName, options =
33296
33513
  const allocationOptions = { onAllocation: (bytes) => allocation.admit(bytes) };
33297
33514
  const fonts = /* @__PURE__ */ new Map();
33298
33515
  const catalog = yield* resolveDict2(rootRef);
33299
- const acroForm = catalog ? yield* resolveDict2(dictGet(catalog, "AcroForm")) : void 0;
33300
- const drDict = acroForm ? yield* resolveDict2(dictGet(acroForm, "DR")) : void 0;
33301
- const drFontDict = drDict ? yield* resolveDict2(dictGet(drDict, "Font"), true) : void 0;
33302
- const pageFontDict = resourcesDict ? yield* resolveDict2(dictGet(resourcesDict, "Font"), true) : void 0;
33516
+ const acroForm = catalog ? yield* resolveDict2(yield* field(catalog, "AcroForm")) : void 0;
33517
+ const drDict = acroForm ? yield* resolveDict2(yield* field(acroForm, "DR")) : void 0;
33518
+ const drFontDict = drDict ? yield* resolveDict2(yield* field(drDict, "Font"), true) : void 0;
33519
+ const pageFontDict = resourcesDict ? yield* resolveDict2(yield* field(resourcesDict, "Font"), true) : void 0;
33303
33520
  for (const dictionary of [drFontDict, pageFontDict]) {
33304
33521
  if (!dictionary) continue;
33305
33522
  const cursor = new PdfDictionaryCursor(dictionary);
@@ -33310,17 +33527,17 @@ function* resolvePageFontsSteps(rootRef, resourcesDict, selectedName, options =
33310
33527
  const fName = entry.key.decoded;
33311
33528
  if (selectedName !== void 0 && fName !== selectedName)
33312
33529
  continue;
33313
- const fObj = yield* resolveDict2(entry.value);
33530
+ const fObj = yield* resolveDict2(entry.value, true);
33314
33531
  if (!fObj)
33315
33532
  continue;
33316
33533
  allocation.admit(1024);
33317
- const subtypeNode = yield* resolve(dictGet(fObj, "Subtype"));
33534
+ const subtypeNode = yield* resolve(yield* field(fObj, "Subtype"));
33318
33535
  const subtype = subtypeNode?.kind === "name" ? subtypeNode.decoded : "Type1";
33319
- const baseFontNode = yield* resolve(dictGet(fObj, "BaseFont"));
33536
+ const baseFontNode = yield* resolve(yield* field(fObj, "BaseFont"));
33320
33537
  const baseFont = baseFontNode?.kind === "name" ? baseFontNode.decoded : "Helvetica";
33321
33538
  let cmap;
33322
33539
  let storedCMap;
33323
- const toUniNode = yield* resolve(dictGet(fObj, "ToUnicode"));
33540
+ const toUniNode = yield* resolve(yield* field(fObj, "ToUnicode"));
33324
33541
  if (toUniNode?.kind === "stream") {
33325
33542
  try {
33326
33543
  const value = yield { kind: "decode", stream: toUniNode, purpose: "unicode-cmap" };
@@ -33334,17 +33551,14 @@ function* resolvePageFontsSteps(rootRef, resourcesDict, selectedName, options =
33334
33551
  throw error;
33335
33552
  }
33336
33553
  }
33337
- const encNode = yield* resolve(dictGet(fObj, "Encoding"));
33554
+ let encNode = yield* resolve(yield* field(fObj, "Encoding"), false, true);
33555
+ let differenceArray;
33338
33556
  if (encNode?.kind === "dict") {
33339
- const diffRef = dictGet(encNode, "Differences");
33340
- if (diffRef?.kind === "ref") {
33341
- const resolvedDiff = yield* resolve(diffRef, true);
33342
- if (resolvedDiff?.kind === "array") {
33343
- dictSet(encNode, "Differences", resolvedDiff);
33344
- }
33345
- }
33557
+ differenceArray = yield* field(encNode, "Differences");
33558
+ if (differenceArray?.kind === "ref") differenceArray = yield* resolve(differenceArray, true);
33559
+ const baseEncoding = yield* field(encNode, "BaseEncoding");
33560
+ encNode = cosDict({ ...baseEncoding ? { BaseEncoding: baseEncoding } : {}, ...differenceArray ? { Differences: differenceArray } : {} });
33346
33561
  }
33347
- const differenceArray = encNode?.kind === "dict" ? dictGet(encNode, "Differences") : void 0;
33348
33562
  let storedEncoding;
33349
33563
  if (options.resourceStorage && differenceArray?.kind === "array") {
33350
33564
  const value = yield { kind: "font-encoding", array: differenceArray };
@@ -33370,28 +33584,29 @@ function* resolvePageFontsSteps(rootRef, resourcesDict, selectedName, options =
33370
33584
  let charProcs;
33371
33585
  let fontResources;
33372
33586
  if (subtype === "Type3") {
33373
- const fmArr = yield* resolveArray2(dictGet(fObj, "FontMatrix"));
33374
- if (fmArr && fmArr.items.length >= 6) {
33375
- const mn = function* (idx, fb = 0) {
33376
- const r = yield* resolve(fmArr.items[idx]);
33377
- return r?.kind === "number" ? r.value : fb;
33378
- };
33379
- fontMatrix = [yield* mn(0, 1e-3), yield* mn(1, 0), yield* mn(2, 0), yield* mn(3, 1e-3), yield* mn(4, 0), yield* mn(5, 0)];
33587
+ const fmArr = yield* resolveArray2(yield* field(fObj, "FontMatrix"), true);
33588
+ if (fmArr && (fmArr.storedItems?.length ?? fmArr.items.length) >= 6) {
33589
+ const cursor2 = arrayCursor(fmArr);
33590
+ fontMatrix = [1e-3, 0, 0, 1e-3, 0, 0];
33591
+ for (let i = 0; i < 6; i++) {
33592
+ const value = yield* resolve(yield* cursor2.next());
33593
+ if (value?.kind === "number") fontMatrix[i] = value.value;
33594
+ }
33380
33595
  } else {
33381
33596
  fontMatrix = [1e-3, 0, 0, 1e-3, 0, 0];
33382
33597
  }
33383
- charProcs = yield* resolveDict2(dictGet(fObj, "CharProcs"));
33384
- fontResources = yield* resolveDict2(dictGet(fObj, "Resources"));
33598
+ charProcs = yield* resolveDict2(yield* field(fObj, "CharProcs"), true);
33599
+ fontResources = yield* resolveDict2(yield* field(fObj, "Resources"), false, ["Resources"]);
33385
33600
  }
33386
33601
  const type3Scale1000 = subtype === "Type3" && fontMatrix ? Math.hypot(fontMatrix[0], fontMatrix[1]) * 1e3 : 1;
33602
+ const descendants = subtype === "Type0" ? yield* resolveArray2(yield* field(fObj, "DescendantFonts"), true) : void 0;
33603
+ const cidDict = descendants ? yield* resolveDict2(yield* arrayCursor(descendants).next(), true) : void 0;
33387
33604
  if (subtype === "Type0") {
33388
- const descArr = yield* resolveArray2(dictGet(fObj, "DescendantFonts"));
33389
- const cidDict = descArr && descArr.items[0] ? yield* resolveDict2(descArr.items[0]) : void 0;
33390
33605
  if (cidDict) {
33391
- const dwNode = yield* resolve(dictGet(cidDict, "DW"));
33606
+ const dwNode = yield* resolve(yield* field(cidDict, "DW"));
33392
33607
  if (dwNode?.kind === "number")
33393
33608
  defaultWidth = dwNode.value;
33394
- const wArr = yield* resolveArray2(dictGet(cidDict, "W"), true);
33609
+ const wArr = yield* resolveArray2(yield* field(cidDict, "W"), true);
33395
33610
  if (wArr) {
33396
33611
  const cursor2 = arrayCursor(wArr);
33397
33612
  while (cursor2.remaining) {
@@ -33417,11 +33632,11 @@ function* resolvePageFontsSteps(rootRef, resourcesDict, selectedName, options =
33417
33632
  }
33418
33633
  }
33419
33634
  } else {
33420
- const firstCharNode = yield* resolve(dictGet(fObj, "FirstChar"));
33421
- const widthsArr = yield* resolveArray2(dictGet(fObj, "Widths"), true);
33635
+ const firstCharNode = yield* resolve(yield* field(fObj, "FirstChar"));
33636
+ const widthsArr = yield* resolveArray2(yield* field(fObj, "Widths"), true);
33422
33637
  if (widthsArr) {
33423
- const descriptor = yield* resolveDict2(dictGet(fObj, "FontDescriptor"));
33424
- const missingWidth = descriptor ? yield* resolve(dictGet(descriptor, "MissingWidth")) : void 0;
33638
+ const descriptor = yield* resolveDict2(yield* field(fObj, "FontDescriptor"), true);
33639
+ const missingWidth = descriptor ? yield* resolve(yield* field(descriptor, "MissingWidth")) : void 0;
33425
33640
  defaultWidth = (missingWidth?.kind === "number" ? missingWidth.value : 0) * type3Scale1000;
33426
33641
  const firstChar = firstCharNode?.kind === "number" ? firstCharNode.value : 0;
33427
33642
  const cursor2 = arrayCursor(widthsArr);
@@ -33444,13 +33659,11 @@ function* resolvePageFontsSteps(rootRef, resourcesDict, selectedName, options =
33444
33659
  let storedTrueType;
33445
33660
  let embeddedTrueType;
33446
33661
  let simpleToGid;
33447
- const fDescDirect = yield* resolveDict2(dictGet(fObj, "FontDescriptor"));
33448
- const descArrForTt = subtype === "Type0" ? yield* resolveArray2(dictGet(fObj, "DescendantFonts")) : void 0;
33449
- const cidDictForTt = descArrForTt && descArrForTt.items[0] ? yield* resolveDict2(descArrForTt.items[0]) : void 0;
33450
- const fDesc = fDescDirect ?? (cidDictForTt ? yield* resolveDict2(dictGet(cidDictForTt, "FontDescriptor")) : void 0);
33662
+ const fDescDirect = yield* resolveDict2(yield* field(fObj, "FontDescriptor"), true);
33663
+ const fDesc = fDescDirect ?? (cidDict ? yield* resolveDict2(yield* field(cidDict, "FontDescriptor"), true) : void 0);
33451
33664
  let cidToGid;
33452
33665
  let storedCidToGid;
33453
- const cidMap = cidDictForTt ? yield* resolve(dictGet(cidDictForTt, "CIDToGIDMap")) : void 0;
33666
+ const cidMap = cidDict ? yield* resolve(yield* field(cidDict, "CIDToGIDMap")) : void 0;
33454
33667
  if (cidMap?.kind === "stream") {
33455
33668
  const bytes = yield { kind: "decode", stream: cidMap, purpose: "cid-map" };
33456
33669
  if (bytes && "byteLength" in bytes && "storage" in bytes) storedCidToGid = bytes;
@@ -33462,15 +33675,15 @@ function* resolvePageFontsSteps(rootRef, resourcesDict, selectedName, options =
33462
33675
  } else throw new TypeError("Font decoder did not return CID map bytes");
33463
33676
  }
33464
33677
  if (fDesc) {
33465
- const type1Program = yield* resolve(dictGet(fDesc, "FontFile"));
33466
- const program = (yield* resolve(dictGet(fDesc, "FontFile2"))) ?? (yield* resolve(dictGet(fDesc, "FontFile3"))) ?? type1Program;
33678
+ const type1Program = yield* resolve(yield* field(fDesc, "FontFile"));
33679
+ const program = (yield* resolve(yield* field(fDesc, "FontFile2"))) ?? (yield* resolve(yield* field(fDesc, "FontFile3"))) ?? type1Program;
33467
33680
  if (program?.kind === "stream") {
33468
- const programType = yield* resolve(dictGet(program.dict, "Subtype"));
33469
- const baseEncoding = encNode?.kind === "dict" ? yield* resolve(dictGet(encNode, "BaseEncoding")) : encNode;
33681
+ const programType = yield* resolve(yield* field(program.dict, "Subtype"));
33682
+ const baseEncoding = encNode?.kind === "dict" ? yield* resolve(yield* field(encNode, "BaseEncoding")) : encNode;
33470
33683
  if (program === type1Program) {
33471
- const length1 = yield* resolve(dictGet(program.dict, "Length1"));
33472
- const length2 = yield* resolve(dictGet(program.dict, "Length2"));
33473
- const flags = yield* resolve(dictGet(fDesc, "Flags"));
33684
+ const length1 = yield* resolve(yield* field(program.dict, "Length1"));
33685
+ const length2 = yield* resolve(yield* field(program.dict, "Length2"));
33686
+ const flags = yield* resolve(yield* field(fDesc, "Flags"));
33474
33687
  const type1Properties = {
33475
33688
  length1: length1?.kind === "number" ? length1.value : 0,
33476
33689
  length2: length2?.kind === "number" ? length2.value : 0,
@@ -33590,7 +33803,7 @@ function resolvePageFonts(doc, resourcesDict, selectedName) {
33590
33803
  while (!step.done) {
33591
33804
  let value;
33592
33805
  try {
33593
- if (step.value.kind === "dictionary-entry" || step.value.kind === "font-encoding" || step.value.kind === "font-label" || step.value.kind === "array-item" || step.value.kind === "truetype-map" || step.value.kind === "font-width-set") throw new TypeError("Stored font requires asynchronous evaluation");
33806
+ if (step.value.kind === "dictionary-value" || step.value.kind === "dictionary-entry" || step.value.kind === "font-encoding" || step.value.kind === "font-label" || step.value.kind === "array-item" || step.value.kind === "truetype-map" || step.value.kind === "font-width-set") throw new TypeError("Stored font requires asynchronous evaluation");
33594
33807
  value = step.value.kind === "resolve" ? doc.resolve(step.value.node) : doc.decodeStream(step.value.stream);
33595
33808
  } catch (error) {
33596
33809
  step = steps.throw(error);
@@ -34479,8 +34692,8 @@ var CCITTFaxDecoder = class {
34479
34692
  }
34480
34693
  this.codingPos = codingPos;
34481
34694
  }
34482
- *_findTableCode(start, end, table, limit10) {
34483
- const limitValue = limit10 || 0;
34695
+ *_findTableCode(start, end, table, limit11) {
34696
+ const limitValue = limit11 || 0;
34484
34697
  for (let i = start; i <= end; ++i) {
34485
34698
  let code = yield* this._lookBits(i);
34486
34699
  if (code === ccittEOF) {
@@ -35204,7 +35417,7 @@ var StoredJbigIndex = class {
35204
35417
  *set(key, value) {
35205
35418
  const record = yield* StoredJbigList.create(9);
35206
35419
  const fields2 = value instanceof StoredJbigHuffman ? [2, value.nodes.length, value.nodes.capacity, value.nodes.buffer.position, value.nodes.buffer.length] : value instanceof StoredJbigList ? [0, value.length, value.capacity, value.buffer.position, value.buffer.length] : [1, value.width, value.height, value.length, value.bitmap.position, value.bitmap.length, value.bitmap.rowSize, value.bitmap.width, value.bitmap.height];
35207
- for (const field2 of fields2) yield* record.push(field2);
35420
+ for (const field3 of fields2) yield* record.push(field3);
35208
35421
  const slot = yield* this.find(key, true);
35209
35422
  yield { kind: "number-write", ...slot, value: record.buffer.position + 1 };
35210
35423
  }
@@ -38151,7 +38364,7 @@ var JpxImage = class {
38151
38364
  } };
38152
38365
  const tile = yield* this.parseCodestreamTileSteps(data, start, end, selected);
38153
38366
  const values = [tile.left, tile.top, tile.width, tile.height, tile.items.position, tile.items.length];
38154
- for (let field2 = 0; field2 < 6; field2++) yield* jpxVectorWrite(records2, number * 6 + field2, values[field2]);
38367
+ for (let field3 = 0; field3 < 6; field3++) yield* jpxVectorWrite(records2, number * 6 + field3, values[field3]);
38155
38368
  }
38156
38369
  this.storedTiles = { length: count, records: records2 };
38157
38370
  }
@@ -38633,8 +38846,8 @@ function* buildCodeblocks(context, subband, dimensions) {
38633
38846
  if (context.storedPlanes) {
38634
38847
  codeblock.record = codeblocks.records;
38635
38848
  codeblock.recordIndex = codeblocks.length++;
38636
- for (let field2 = 0; field2 < jpxCodeblockGeometry.length; field2++) {
38637
- yield* jpxVectorWrite(codeblock.record, codeblock.recordIndex * 18 + field2, codeblock[jpxCodeblockGeometry[field2]]);
38849
+ for (let field3 = 0; field3 < jpxCodeblockGeometry.length; field3++) {
38850
+ yield* jpxVectorWrite(codeblock.record, codeblock.recordIndex * 18 + field3, codeblock[jpxCodeblockGeometry[field3]]);
38638
38851
  }
38639
38852
  yield* writeJpxCodeblock(codeblock);
38640
38853
  } else codeblocks.push(codeblock);
@@ -38688,8 +38901,8 @@ function* writeJpxPrecinct(precinct) {
38688
38901
  precinct.zeroBitPlanesTree ? precinct.zeroBitPlanesTree.root.position + 1 : 0,
38689
38902
  precinct.zeroBitPlanesTree ? precinct.zeroBitPlanesTree.presence.position + 1 : 0
38690
38903
  ];
38691
- for (let field2 = 0; field2 < values.length; field2++) {
38692
- yield* jpxVectorWrite(collection.records, precinct.number * 8 + field2, values[field2]);
38904
+ for (let field3 = 0; field3 < values.length; field3++) {
38905
+ yield* jpxVectorWrite(collection.records, precinct.number * 8 + field3, values[field3]);
38693
38906
  }
38694
38907
  collection.cached = precinct;
38695
38908
  }
@@ -38698,7 +38911,7 @@ function* readJpxPrecinct(collection, number) {
38698
38911
  if (collection.cached?.number === number) return collection.cached;
38699
38912
  if (!(yield* jpxVectorRead(collection.records, number * 8))) return void 0;
38700
38913
  const values = [];
38701
- for (let field2 = 1; field2 < 8; field2++) values.push(yield* jpxVectorRead(collection.records, number * 8 + field2));
38914
+ for (let field3 = 1; field3 < 8; field3++) values.push(yield* jpxVectorRead(collection.records, number * 8 + field3));
38702
38915
  const precinct = { collection, number, cbxMin: values[0], cbyMin: values[1], cbxMax: values[2], cbyMax: values[3] };
38703
38916
  if (values[4]) {
38704
38917
  const width = precinct.cbxMax - precinct.cbxMin + 1, height = precinct.cbyMax - precinct.cbyMin + 1;
@@ -38727,8 +38940,8 @@ function* writeJpxCodeblock(block) {
38727
38940
  data?.totalLength ?? 0,
38728
38941
  data?.codingpasses ?? 0
38729
38942
  ];
38730
- for (let field2 = 0; field2 < values.length; field2++) {
38731
- yield* jpxVectorWrite(block.record, block.recordIndex * 18 + 7 + field2, values[field2]);
38943
+ for (let field3 = 0; field3 < values.length; field3++) {
38944
+ yield* jpxVectorWrite(block.record, block.recordIndex * 18 + 7 + field3, values[field3]);
38732
38945
  }
38733
38946
  }
38734
38947
  function* readJpxCodeblock(subband, index2, withPrecinct = true) {
@@ -38736,8 +38949,8 @@ function* readJpxCodeblock(subband, index2, withPrecinct = true) {
38736
38949
  if (!blocks.records) return blocks[index2];
38737
38950
  const block = { record: blocks.records, recordIndex: index2, subbandType: subband.type };
38738
38951
  const values = [];
38739
- for (let field2 = 0; field2 < 18; field2++) values.push(yield* jpxVectorRead(blocks.records, index2 * 18 + field2));
38740
- for (let field2 = 0; field2 < jpxCodeblockGeometry.length; field2++) block[jpxCodeblockGeometry[field2]] = values[field2];
38952
+ for (let field3 = 0; field3 < 18; field3++) values.push(yield* jpxVectorRead(blocks.records, index2 * 18 + field3));
38953
+ for (let field3 = 0; field3 < jpxCodeblockGeometry.length; field3++) block[jpxCodeblockGeometry[field3]] = values[field3];
38741
38954
  if (withPrecinct) block.precinct = yield* readJpxPrecinct(subband.precincts, block.precinctNumber);
38742
38955
  block.Lblock = values[7];
38743
38956
  if (values[8]) block.included = true;
@@ -39051,12 +39264,12 @@ var jpxSubbandFields = ["tbx0", "tby0", "tbx1", "tby1"];
39051
39264
  var jpxBlockFields = ["codeblockWidth", "codeblockHeight", "numcodeblockwide", "numcodeblockhigh"];
39052
39265
  var jpxSubbandTypes = ["LL", "HL", "LH", "HH"];
39053
39266
  function* writeJpxResolution(collection, resolution) {
39054
- const values = jpxResolutionFields.map((field2) => resolution[field2]);
39055
- values.push(...jpxPrecinctFields.map((field2) => resolution.precinctParameters[field2]), resolution.subbands.length);
39267
+ const values = jpxResolutionFields.map((field3) => resolution[field3]);
39268
+ values.push(...jpxPrecinctFields.map((field3) => resolution.precinctParameters[field3]), resolution.subbands.length);
39056
39269
  for (const band of resolution.subbands) values.push(
39057
39270
  jpxSubbandTypes.indexOf(band.type),
39058
- ...jpxSubbandFields.map((field2) => band[field2]),
39059
- ...jpxBlockFields.map((field2) => band.codeblockParameters[field2]),
39271
+ ...jpxSubbandFields.map((field3) => band[field3]),
39272
+ ...jpxBlockFields.map((field3) => band.codeblockParameters[field3]),
39060
39273
  band.codeblocks.length,
39061
39274
  band.codeblocks.records.position,
39062
39275
  band.codeblocks.records.length,
@@ -39081,13 +39294,13 @@ function* readJpxResolution(collection, index2) {
39081
39294
  return yield* jpxVectorRead(collection.records, offset++);
39082
39295
  };
39083
39296
  const resolution = { onAllocation: context.onAllocation, packetAdmission: 128, precinctParameters: {}, subbands: [] };
39084
- for (const field2 of jpxResolutionFields) resolution[field2] = yield* read();
39085
- for (const field2 of jpxPrecinctFields) resolution.precinctParameters[field2] = yield* read();
39297
+ for (const field3 of jpxResolutionFields) resolution[field3] = yield* read();
39298
+ for (const field3 of jpxPrecinctFields) resolution.precinctParameters[field3] = yield* read();
39086
39299
  const count = yield* read();
39087
39300
  for (let i = 0; i < count; i++) {
39088
39301
  const band = { type: jpxSubbandTypes[yield* read()], resolution, codeblockParameters: {} };
39089
- for (const field2 of jpxSubbandFields) band[field2] = yield* read();
39090
- for (const field2 of jpxBlockFields) band.codeblockParameters[field2] = yield* read();
39302
+ for (const field3 of jpxSubbandFields) band[field3] = yield* read();
39303
+ for (const field3 of jpxBlockFields) band.codeblockParameters[field3] = yield* read();
39091
39304
  band.codeblocks = { length: yield* read(), records: { position: yield* read(), length: yield* read(), bytesPerElement: 8, integer: false } };
39092
39305
  band.precincts = { records: { position: yield* read(), length: yield* read(), bytesPerElement: 8, integer: false }, admission: entry.trees[i] };
39093
39306
  resolution.subbands.push(band);
@@ -40622,8 +40835,8 @@ function* looksLikePostEiContentStream(size, posAfterEi) {
40622
40835
  let p = posAfterEi;
40623
40836
  while (p < size && isPdfWhitespace(yield* byte2(p))) p++;
40624
40837
  if (p >= size) return true;
40625
- const limit10 = Math.min(size, p + 16);
40626
- for (let i = p; i < limit10; i++) {
40838
+ const limit11 = Math.min(size, p + 16);
40839
+ for (let i = p; i < limit11; i++) {
40627
40840
  const b = yield* byte2(i);
40628
40841
  if (b === 40 || b === 60 || b === 37) break;
40629
40842
  if (!isPdfWhitespace(b) && (b < 32 || b > 126)) {
@@ -41188,6 +41401,11 @@ function* resolveColorSpaceInfoSteps(doc, node, resources) {
41188
41401
  case "resolve":
41189
41402
  result = doc.resolve(request.node);
41190
41403
  break;
41404
+ case "resource": {
41405
+ const map = doc.resolveDict(dictGet(request.resources, request.category));
41406
+ result = map ? dictGet(map, request.name) : void 0;
41407
+ break;
41408
+ }
41191
41409
  case "palette":
41192
41410
  result = request.node.kind === "stream" ? doc.decodeStream(request.node) : request.node.bytes;
41193
41411
  break;
@@ -41228,9 +41446,7 @@ function* imageColorSpaceProgram(csNode, resourcesDict, maxDepth = Infinity, dep
41228
41446
  if (name === "DeviceRGB" || name === "RGB" || name === "CalRGB") {
41229
41447
  return { colorSpace: "rgb", colorSpaceLabel: name === "CalRGB" ? "cal-rgb" : "rgb", components: 3 };
41230
41448
  }
41231
- const csResources = resourcesDict ? yield { kind: "resolve", node: dictGet(resourcesDict, "ColorSpace") } : void 0;
41232
- const csResDict = csResources?.kind === "dict" ? csResources : void 0;
41233
- const mapped = csResDict ? dictGet(csResDict, name) : void 0;
41449
+ const mapped = resourcesDict ? yield { kind: "resource", resources: resourcesDict, category: "ColorSpace", name } : void 0;
41234
41450
  if (mapped) {
41235
41451
  return yield* imageColorSpaceProgram(mapped, resourcesDict, maxDepth, depth + 1);
41236
41452
  }
@@ -42555,8 +42771,12 @@ function* runColorProgramSteps(doc, work, sources) {
42555
42771
  let step = work.next();
42556
42772
  while (!step.done) {
42557
42773
  const request = step.value;
42558
- if (request.kind === "resolve") step = work.next(doc?.resolve(request.node));
42559
- else {
42774
+ if (request.kind === "dictionary-value") step = work.next(dictGet(request.dict, request.key));
42775
+ else if (request.kind === "resolve") step = work.next(doc?.resolve(request.node));
42776
+ else if (request.kind === "resource") {
42777
+ const map = doc?.resolveDict(dictGet(request.resources, request.category));
42778
+ step = work.next(map ? dictGet(map, request.name) : void 0);
42779
+ } else {
42560
42780
  if (!doc) throw new PdfError("E_CAPABILITY", "PDF resource color requires a source driver");
42561
42781
  if (request.kind === "decode") {
42562
42782
  const bytes = doc.decodeStream(request.stream);
@@ -42581,8 +42801,7 @@ function* colorComponentCountSteps(hasDocument, csNode, activeResources, depth =
42581
42801
  if (name === "DeviceCMYK" || name === "CMYK") return 4;
42582
42802
  if (name === "DeviceRGB" || name === "RGB" || name === "CalRGB" || name === "Lab") return 3;
42583
42803
  if (hasDocument && activeResources) {
42584
- const csDict = yield* resolveColorNode(dictGet(activeResources, "ColorSpace"), "dict");
42585
- const mapped = csDict ? dictGet(csDict, name) : void 0;
42804
+ const mapped = yield { kind: "resource", resources: activeResources, category: "ColorSpace", name };
42586
42805
  if (mapped) return yield* colorComponentCountSteps(hasDocument, mapped, activeResources, depth + 1);
42587
42806
  }
42588
42807
  return 3;
@@ -42613,8 +42832,7 @@ function* convertContentColorSteps(hasDocument, csNode, csNameFallback, comps, a
42613
42832
  if ((!resolved || resolved.kind === "name") && hasDocument && activeResources) {
42614
42833
  const lookupName = resolved?.kind === "name" ? resolved.decoded : csNameFallback;
42615
42834
  if (lookupName && lookupName !== "DeviceRGB" && lookupName !== "RGB" && lookupName !== "DeviceGray" && lookupName !== "G" && lookupName !== "DeviceCMYK" && lookupName !== "CMYK") {
42616
- const csDict = yield* resolveColorNode(dictGet(activeResources, "ColorSpace"), "dict");
42617
- const mapped = csDict ? dictGet(csDict, lookupName) : void 0;
42835
+ const mapped = yield { kind: "resource", resources: activeResources, category: "ColorSpace", name: lookupName };
42618
42836
  if (mapped) {
42619
42837
  resolved = yield* resolveColorNode(mapped);
42620
42838
  }
@@ -42996,20 +43214,20 @@ function isOptionalContentVisible(doc, ocNode) {
42996
43214
  }
42997
43215
  return step.value;
42998
43216
  }
42999
- function* resolveEvaluationNode(node, storeRootArray = false, arrayPathPrefix) {
43217
+ function* resolveEvaluationNode(node, storeRootArray = false, arrayPathPrefix, storeRootDictionary = false) {
43000
43218
  if (!node) return void 0;
43001
- const result = yield { kind: "resolve", node, ...storeRootArray ? { storeRootArray } : {}, ...arrayPathPrefix ? { arrayPathPrefix } : {} };
43219
+ const result = yield { kind: "resolve", node, ...storeRootDictionary ? { storeRootDictionary } : {}, ...storeRootArray ? { storeRootArray } : {}, ...arrayPathPrefix ? { arrayPathPrefix } : {} };
43002
43220
  if (!result || !("kind" in result) || result.kind !== "resolved") throw new TypeError("Expected a resolved PDF object");
43003
43221
  return result.node;
43004
43222
  }
43005
- function* resolveEvaluationDict(node, arrayPathPrefix) {
43006
- const resolved = yield* resolveEvaluationNode(node, false, arrayPathPrefix);
43223
+ function* resolveEvaluationDict(node, arrayPathPrefix, storeRootDictionary = false) {
43224
+ const resolved = yield* resolveEvaluationNode(node, false, arrayPathPrefix, storeRootDictionary);
43007
43225
  return resolved?.kind === "dict" ? resolved : resolved?.kind === "stream" ? resolved.dict : void 0;
43008
43226
  }
43009
- function* lookupEvaluationDictionary(dict, key) {
43227
+ function* lookupEvaluationDictionary(dict, key, preserveDeferred = false) {
43010
43228
  if (!dict) return void 0;
43011
43229
  if (!dict.storedEntries) return dictGet(dict, key);
43012
- const result = yield { kind: "dictionary-value", dict, key };
43230
+ const result = yield { kind: "dictionary-value", dict, key, ...preserveDeferred ? { preserveDeferred } : {} };
43013
43231
  if (!result || !("kind" in result) || result.kind !== "resolved") throw new TypeError("Expected a PDF dictionary value");
43014
43232
  return result.node;
43015
43233
  }
@@ -43017,6 +43235,23 @@ function* resolveEvaluationArray(node, storeRootArray = false, arrayPathPrefix)
43017
43235
  const resolved = yield* resolveEvaluationNode(node, storeRootArray, arrayPathPrefix);
43018
43236
  return resolved?.kind === "array" ? resolved : void 0;
43019
43237
  }
43238
+ function* evaluationArrayPrefix(array, count) {
43239
+ if (!array.storedItems) return array.items.slice(0, count);
43240
+ const items = array.storedItems;
43241
+ if (!Number.isSafeInteger(items.length) || items.length < 0) throw new RangeError("Invalid stored array length");
43242
+ const prefix = [];
43243
+ let position = items.position;
43244
+ for (let i = 0; i < Math.min(count, items.length); i++) {
43245
+ const reply = yield { kind: "array-item", items, position };
43246
+ if (!reply || !("kind" in reply) || reply.kind !== "resolved" || reply.node?.kind !== "array") throw new TypeError("Expected stored array item");
43247
+ const [next, value] = reply.node.items;
43248
+ if (next?.kind !== "number" || !value) throw new TypeError("Expected stored array record");
43249
+ position = next.value;
43250
+ prefix.push(value);
43251
+ }
43252
+ if (items.length <= count && position !== -1) throw new PdfError("E_PARSE", "Invalid stored array terminator");
43253
+ return prefix;
43254
+ }
43020
43255
  function* visitEvaluationArray(array, visit) {
43021
43256
  if (!array.storedItems) {
43022
43257
  for (const item of array.items) yield* visit(item);
@@ -43115,7 +43350,7 @@ function* evaluateMaskTransferSteps(doc, transfer, sources) {
43115
43350
  function* resolveMaskParameterSteps(mask, form, activeResources) {
43116
43351
  const group = yield* resolveColorNode(dictGet(form.dict, "Group"), "dict");
43117
43352
  const colorSpace = group ? dictGet(group, "CS") : void 0;
43118
- const bc = yield* resolveColorNode(dictGet(mask, "BC"), "array");
43353
+ const bc = yield* resolveColorNode(yield { kind: "dictionary-value", dict: mask, key: "BC" }, "array");
43119
43354
  let components;
43120
43355
  if (bc) {
43121
43356
  components = [];
@@ -43125,7 +43360,7 @@ function* resolveMaskParameterSteps(mask, form, activeResources) {
43125
43360
  }
43126
43361
  }
43127
43362
  const [r, g, b] = components ? yield* convertContentColorSteps(true, colorSpace, "DeviceRGB", components, activeResources) : [0, 0, 0];
43128
- const transfer = yield* resolveColorNode(dictGet(mask, "TR"));
43363
+ const transfer = yield* resolveColorNode(yield { kind: "dictionary-value", dict: mask, key: "TR" });
43129
43364
  const transferMap = transfer?.kind === "dict" || transfer?.kind === "stream" ? yield { kind: "transfer", node: transfer } : void 0;
43130
43365
  return { backdrop: { r, g, b }, transferMap };
43131
43366
  }
@@ -43461,8 +43696,8 @@ function* evaluateContentSteps(params) {
43461
43696
  st.dashPhase = void 0;
43462
43697
  }
43463
43698
  } else if (operator === "sh" && activeResources && ops[0]?.kind === "name") {
43464
- const shMap = yield* resolveEvaluationDict(dictGet(activeResources, "Shading"));
43465
- const shNode = shMap ? yield* resolveEvaluationNode(dictGet(shMap, ops[0].decoded)) : void 0;
43699
+ const shMap = yield* resolveEvaluationDict(dictGet(activeResources, "Shading"), ["Resources", "Shading"]);
43700
+ const shNode = shMap ? yield* resolveEvaluationNode(yield* lookupEvaluationDictionary(shMap, ops[0].decoded)) : void 0;
43466
43701
  const shDict = shNode?.kind === "dict" ? shNode : shNode?.kind === "stream" ? shNode.dict : void 0;
43467
43702
  const shStream = shNode?.kind === "stream" ? shNode : void 0;
43468
43703
  if (shDict) {
@@ -43513,15 +43748,15 @@ function* evaluateContentSteps(params) {
43513
43748
  } else if (operator === "K") {
43514
43749
  st.strokeColor = yield* resolveScColorOperands("DeviceCMYK", ops, activeResources);
43515
43750
  } else if (operator === "gs" && activeResources && ops[0]?.kind === "name") {
43516
- const extDict = yield* resolveEvaluationDict(dictGet(activeResources, "ExtGState"), ["ExtGState"]);
43517
- const gsDict = extDict ? yield* resolveEvaluationDict(dictGet(extDict, ops[0].decoded), ["ExtGState", ops[0].decoded]) : void 0;
43751
+ const extDict = yield* resolveEvaluationDict(dictGet(activeResources, "ExtGState"), ["Resources", "ExtGState"]);
43752
+ const gsDict = extDict ? yield* resolveEvaluationDict(yield* lookupEvaluationDictionary(extDict, ops[0].decoded, true), ["Resources", "ExtGState", ops[0].decoded], true) : void 0;
43518
43753
  if (gsDict) {
43519
- const mask = yield* resolveEvaluationNode(dictGet(gsDict, "SMask"));
43754
+ const mask = yield* resolveEvaluationNode(yield* lookupEvaluationDictionary(gsDict, "SMask", true), false, void 0, true);
43520
43755
  if (mask?.kind === "name" && mask.decoded === "None") {
43521
43756
  st.softMask = void 0;
43522
43757
  } else if (mask?.kind === "dict") {
43523
- const subtype = yield* resolveEvaluationNode(dictGet(mask, "S"));
43524
- const form = yield* resolveEvaluationNode(dictGet(mask, "G"));
43758
+ const subtype = yield* resolveEvaluationNode(yield* lookupEvaluationDictionary(mask, "S"));
43759
+ const form = yield* resolveEvaluationNode(yield* lookupEvaluationDictionary(mask, "G"));
43525
43760
  if (form?.kind === "stream" && subtype?.kind === "name" && (subtype.decoded === "Alpha" || subtype.decoded === "Luminosity")) {
43526
43761
  if (depth >= 8) throw new PdfError("E_LIMIT", "Soft-mask nesting exceeds the form depth limit");
43527
43762
  const parentOperations = capturedOperations;
@@ -43549,48 +43784,36 @@ function* evaluateContentSteps(params) {
43549
43784
  st.softMask = { subtype: subtype.decoded, operations: captured instanceof StoredOperationsWriter ? [] : captured, ...captured instanceof StoredOperationsWriter ? { storedOperations: captured.snapshot() } : {}, ...parameters.value };
43550
43785
  }
43551
43786
  }
43552
- const bmNode = yield* resolveEvaluationNode(dictGet(gsDict, "BM"));
43787
+ const bmNode = yield* resolveEvaluationNode(yield* lookupEvaluationDictionary(gsDict, "BM", true), true);
43553
43788
  if (bmNode?.kind === "name") {
43554
43789
  st.blendMode = bmNode.decoded === "Compatible" ? "Normal" : bmNode.decoded;
43555
- } else if (bmNode?.kind === "array" && bmNode.items.length > 0) {
43556
- const firstBm = yield* resolveEvaluationNode(bmNode.items[0]);
43790
+ } else if (bmNode?.kind === "array" && (bmNode.storedItems?.length ?? bmNode.items.length) > 0) {
43791
+ const firstBm = yield* resolveEvaluationNode((yield* evaluationArrayPrefix(bmNode, 1))[0]);
43557
43792
  if (firstBm?.kind === "name") {
43558
43793
  st.blendMode = firstBm.decoded === "Compatible" ? "Normal" : firstBm.decoded;
43559
43794
  }
43560
43795
  }
43561
- const caNode = yield* resolveEvaluationNode(dictGet(gsDict, "ca"));
43796
+ const caNode = yield* resolveEvaluationNode(yield* lookupEvaluationDictionary(gsDict, "ca", true), true);
43562
43797
  if (caNode?.kind === "number") st.fillAlpha = Math.max(0, Math.min(1, caNode.value));
43563
- const CANode = yield* resolveEvaluationNode(dictGet(gsDict, "CA"));
43798
+ const CANode = yield* resolveEvaluationNode(yield* lookupEvaluationDictionary(gsDict, "CA", true), true);
43564
43799
  if (CANode?.kind === "number") st.strokeAlpha = Math.max(0, Math.min(1, CANode.value));
43565
- const lwNode = yield* resolveEvaluationNode(dictGet(gsDict, "LW"));
43800
+ const lwNode = yield* resolveEvaluationNode(yield* lookupEvaluationDictionary(gsDict, "LW", true), true);
43566
43801
  if (lwNode?.kind === "number") st.strokeWidth = Math.max(0, lwNode.value);
43567
- const lcNode = yield* resolveEvaluationNode(dictGet(gsDict, "LC"));
43802
+ const lcNode = yield* resolveEvaluationNode(yield* lookupEvaluationDictionary(gsDict, "LC", true), true);
43568
43803
  if (lcNode?.kind === "number" && (lcNode.value === 0 || lcNode.value === 1 || lcNode.value === 2)) {
43569
43804
  st.lineCap = lcNode.value;
43570
43805
  }
43571
- const ljNode = yield* resolveEvaluationNode(dictGet(gsDict, "LJ"));
43806
+ const ljNode = yield* resolveEvaluationNode(yield* lookupEvaluationDictionary(gsDict, "LJ", true), true);
43572
43807
  if (ljNode?.kind === "number" && (ljNode.value === 0 || ljNode.value === 1 || ljNode.value === 2)) {
43573
43808
  st.lineJoin = ljNode.value;
43574
43809
  }
43575
- const mlNode = yield* resolveEvaluationNode(dictGet(gsDict, "ML"));
43810
+ const mlNode = yield* resolveEvaluationNode(yield* lookupEvaluationDictionary(gsDict, "ML", true), true);
43576
43811
  if (mlNode?.kind === "number" && mlNode.value > 0) {
43577
43812
  st.miterLimit = mlNode.value;
43578
43813
  }
43579
- const dArr = yield* resolveEvaluationArray(dictGet(gsDict, "D"), true);
43814
+ const dArr = yield* resolveEvaluationArray(yield* lookupEvaluationDictionary(gsDict, "D", true), true);
43580
43815
  if (dArr && (dArr.storedItems?.length ?? dArr.items.length) >= 2) {
43581
- let pair = dArr.items;
43582
- if (dArr.storedItems) {
43583
- pair = [];
43584
- let position = dArr.storedItems.position;
43585
- for (let i = 0; i < 2; i++) {
43586
- const reply = yield { kind: "array-item", items: dArr.storedItems, position };
43587
- if (!reply || !("kind" in reply) || reply.kind !== "resolved" || reply.node?.kind !== "array") throw new TypeError("Expected dash state record");
43588
- const [next, value] = reply.node.items;
43589
- if (next?.kind !== "number" || !value) throw new TypeError("Expected dash state value");
43590
- position = next.value;
43591
- pair.push(value);
43592
- }
43593
- }
43816
+ const pair = yield* evaluationArrayPrefix(dArr, 2);
43594
43817
  const patArr = yield* resolveEvaluationArray(pair[0], true);
43595
43818
  const phaseNode = yield* resolveEvaluationNode(pair[1]);
43596
43819
  if (patArr && params.geometryStorage) {
@@ -43611,9 +43834,10 @@ function* evaluateContentSteps(params) {
43611
43834
  st.dashPhase = phaseNode?.kind === "number" ? phaseNode.value : 0;
43612
43835
  }
43613
43836
  }
43614
- const fontArr = yield* resolveEvaluationArray(dictGet(gsDict, "Font"));
43615
- if (fontArr && fontArr.items.length >= 2) {
43616
- const fSizeNode = yield* resolveEvaluationNode(fontArr.items[1]);
43837
+ const fontArr = yield* resolveEvaluationArray(yield* lookupEvaluationDictionary(gsDict, "Font", true), true);
43838
+ if (fontArr && (fontArr.storedItems?.length ?? fontArr.items.length) >= 2) {
43839
+ const pair = yield* evaluationArrayPrefix(fontArr, 2);
43840
+ const fSizeNode = yield* resolveEvaluationNode(pair[1]);
43617
43841
  if (fSizeNode?.kind === "number") st.fontSize = fSizeNode.value;
43618
43842
  const gsFontKey = `__ExtGS_Font_${ops[0].decoded}`;
43619
43843
  const gsFontResources = {
@@ -43626,7 +43850,7 @@ function* evaluateContentSteps(params) {
43626
43850
  entries: [
43627
43851
  {
43628
43852
  key: { kind: "name", decoded: gsFontKey, rawBytes: new Uint8Array(0) },
43629
- value: fontArr.items[0]
43853
+ value: pair[0]
43630
43854
  }
43631
43855
  ]
43632
43856
  }
@@ -43665,8 +43889,8 @@ function* evaluateContentSteps(params) {
43665
43889
  const st = curState();
43666
43890
  if (!st.fillPatternName || !resources) return false;
43667
43891
  if (depth >= 8) throw new PdfError("E_LIMIT", "Pattern nesting exceeds the form depth limit");
43668
- const patterns = yield* resolveEvaluationDict(dictGet(resources, "Pattern"));
43669
- const pattern = patterns && (yield* resolveEvaluationNode(dictGet(patterns, st.fillPatternName)));
43892
+ const patterns = yield* resolveEvaluationDict(dictGet(resources, "Pattern"), ["Resources", "Pattern"]);
43893
+ const pattern = patterns && (yield* resolveEvaluationNode(yield* lookupEvaluationDictionary(patterns, st.fillPatternName)));
43670
43894
  const dict = pattern?.kind === "stream" ? pattern.dict : pattern?.kind === "dict" ? pattern : void 0;
43671
43895
  if (!dict) return false;
43672
43896
  const nums = function* (key, fallback) {
@@ -43749,7 +43973,7 @@ function* evaluateContentSteps(params) {
43749
43973
  const iy1 = Math.ceil((Math.max(...corners.map((p) => p[1])) - box[1]) / yStep) - 1;
43750
43974
  if ((ix1 - ix0 + 1) * (iy1 - iy0 + 1) > 2e4) throw new PdfError("E_LIMIT", "Pattern tile count exceeds 20000");
43751
43975
  const nodes = { stream: pattern };
43752
- const patternResources = (yield* resolveEvaluationDict(dictGet(dict, "Resources"))) ?? resources;
43976
+ const patternResources = (yield* resolveEvaluationDict(dictGet(dict, "Resources"), ["Resources"])) ?? resources;
43753
43977
  const patternFonts = [patternResources, ...activeFonts];
43754
43978
  for (let iy = iy0; iy <= iy1; iy++) {
43755
43979
  for (let ix = ix0; ix <= ix1; ix++) {
@@ -43783,7 +44007,7 @@ function* evaluateContentSteps(params) {
43783
44007
  const isolated = isolation?.kind === "boolean" && isolation.value;
43784
44008
  const compositeGroup = !maskGroup && groupType?.kind === "name" && groupType.decoded === "Transparency" && (isolated || st.fillAlpha !== 1 || !!st.softMask || !!st.blendMode && st.blendMode !== "Normal" && st.blendMode !== "Compatible");
43785
44009
  const formNodes = { stream: form };
43786
- const formResDict = (yield* resolveEvaluationDict(dictGet(form.dict, "Resources"))) ?? activeResources;
44010
+ const formResDict = (yield* resolveEvaluationDict(dictGet(form.dict, "Resources"), ["Resources"])) ?? activeResources;
43787
44011
  const formFonts = [formResDict, ...activeFonts];
43788
44012
  let nextCtm = [...st.ctm];
43789
44013
  const matArr = yield* resolveEvaluationArray(dictGet(form.dict, "Matrix"));
@@ -43860,7 +44084,7 @@ function* evaluateContentSteps(params) {
43860
44084
  let resolvedMcid = node.mcid;
43861
44085
  let resolvedActualText = node.actualText ?? node.storedActualText;
43862
44086
  if (typeof node.properties === "string" && activeResources) {
43863
- const propsMap = yield* resolveEvaluationDict(dictGet(activeResources, "Properties"), ["Properties"]);
44087
+ const propsMap = yield* resolveEvaluationDict(dictGet(activeResources, "Properties"), ["Resources", "Properties"]);
43864
44088
  const propRefOrNode = yield* lookupEvaluationDictionary(propsMap, node.properties);
43865
44089
  if (propRefOrNode) {
43866
44090
  const propDict = yield* resolveEvaluationDict(propRefOrNode);
@@ -44044,7 +44268,7 @@ function* evaluateContentSteps(params) {
44044
44268
  case "xobject": {
44045
44269
  const st = curState();
44046
44270
  if (activeResources) {
44047
- const xobjDict = yield* resolveEvaluationDict(dictGet(activeResources, "XObject"), ["XObject"]);
44271
+ const xobjDict = yield* resolveEvaluationDict(dictGet(activeResources, "XObject"), ["Resources", "XObject"]);
44048
44272
  const xobjNode = xobjDict ? yield* resolveEvaluationNode(yield* lookupEvaluationDictionary(xobjDict, node.name)) : void 0;
44049
44273
  if (xobjNode?.kind === "stream") {
44050
44274
  if (!(yield* optionalContentVisibilitySteps(dictGet(xobjNode.dict, "OC")))) {
@@ -44146,7 +44370,7 @@ function* evaluateContentSteps(params) {
44146
44370
  explicitName = reply.node?.kind === "name" ? reply.node.decoded : void 0;
44147
44371
  }
44148
44372
  const gName = explicitName ?? item.unicode;
44149
- const procNode = gName ? yield* resolveEvaluationNode(dictGet(font.charProcs, gName)) : void 0;
44373
+ const procNode = gName ? yield* resolveEvaluationNode(yield* lookupEvaluationDictionary(font.charProcs, gName)) : void 0;
44150
44374
  if (procNode?.kind === "stream") {
44151
44375
  const fm = font.fontMatrix ?? [1e-3, 0, 0, 1e-3, 0, 0];
44152
44376
  const source2 = { stream: procNode };
@@ -44635,10 +44859,10 @@ function* visible(node) {
44635
44859
  function* preparePageAppearanceSteps(pageDict, pageRes, evalResourcesDict, hideAnnotations = false, onAllocation) {
44636
44860
  onAllocation?.(64 * pageRes.entries.length);
44637
44861
  for (const entry of pageRes.entries) {
44638
- const sub = yield* resolveDict3(entry.value, [entry.key.decoded]);
44862
+ const sub = yield* resolveDict3(entry.value, ["Resources", entry.key.decoded]);
44639
44863
  if (sub) {
44640
44864
  onAllocation?.(64 + sub.entries.length * 64);
44641
- const shareBacking = entry.key.decoded === "XObject" || entry.key.decoded === "Properties";
44865
+ const shareBacking = entry.key.decoded !== "Font";
44642
44866
  const clonedSub = sub.storedEntries ? shareBacking ? { ...sub, entries: [] } : yield { kind: "dictionary-merge", destination: sub } : cosDict({});
44643
44867
  if (!sub.storedEntries) for (const se of sub.entries) dictSet(clonedSub, se.key.decoded, se.value);
44644
44868
  dictSet(evalResourcesDict, entry.key.decoded, clonedSub);
@@ -44682,12 +44906,12 @@ function* preparePageAppearanceSteps(pageDict, pageRes, evalResourcesDict, hideA
44682
44906
  if (hasContent === true) {
44683
44907
  onAllocation?.(2048);
44684
44908
  renderedApStream = true;
44685
- const apRes = yield* resolveDict3(dictGet(apN.dict, "Resources"));
44909
+ const apRes = yield* resolveDict3(dictGet(apN.dict, "Resources"), ["Resources"]);
44686
44910
  if (apRes) {
44687
44911
  for (const subKey of ["Font", "XObject", "ExtGState", "ColorSpace", "Pattern", "Shading"]) {
44688
- const srcSub = yield* resolveDict3(dictGet(apRes, subKey), [subKey]);
44912
+ const srcSub = yield* resolveDict3(dictGet(apRes, subKey), ["Resources", subKey]);
44689
44913
  if (!srcSub) continue;
44690
- let dstSub = yield* resolveDict3(dictGet(evalResourcesDict, subKey), [subKey]);
44914
+ let dstSub = yield* resolveDict3(dictGet(evalResourcesDict, subKey), ["Resources", subKey]);
44691
44915
  if (!dstSub) {
44692
44916
  onAllocation?.(64);
44693
44917
  dstSub = cosDict({});
@@ -48314,24 +48538,13 @@ function* svgImageSteps(image, pageHeight) {
48314
48538
  }
48315
48539
  function* svgPathDataSteps(segments, height, matrix2) {
48316
48540
  let work = 0;
48317
- const dParts = [];
48318
- const point = (x, y) => matrix2 ? `${matrix2[0] * x + matrix2[2] * y + matrix2[4]} ${height - matrix2[1] * x - matrix2[3] * y - matrix2[5]}` : `${x} ${height - y}`;
48319
- for (const seg of segments) {
48541
+ const parts = [];
48542
+ for (const segment of segments) {
48320
48543
  if (++work % 16384 === 0) yield;
48321
- if (seg.kind === "move") {
48322
- dParts.push(`M ${point(seg.x, seg.y)}`);
48323
- } else if (seg.kind === "line") {
48324
- dParts.push(`L ${point(seg.x, seg.y)}`);
48325
- } else if (seg.kind === "cubic") {
48326
- dParts.push(`C ${point(seg.x1, seg.y1)} ${point(seg.x2, seg.y2)} ${point(seg.x, seg.y)}`);
48327
- } else if (seg.kind === "rect") {
48328
- if (matrix2) dParts.push(`M ${point(seg.x, seg.y)} L ${point(seg.x + seg.width, seg.y)} L ${point(seg.x + seg.width, seg.y + seg.height)} L ${point(seg.x, seg.y + seg.height)} Z`);
48329
- else dParts.push(`M ${seg.x} ${height - seg.y} h ${seg.width} v ${-seg.height} h ${-seg.width} Z`);
48330
- } else if (seg.kind === "close") {
48331
- dParts.push("Z");
48332
- }
48544
+ const part = svgPathSegment(segment, height, matrix2);
48545
+ if (part !== void 0) parts.push(part);
48333
48546
  }
48334
- return dParts.join(" ");
48547
+ return parts.join(" ");
48335
48548
  }
48336
48549
  function* renderDisplayListToSvgSteps(displayList, options = {}) {
48337
48550
  const baseScale = options.scale ?? (options.dpi ? options.dpi / 72 : 1);
@@ -48641,6 +48854,139 @@ function renderPdfPageToPng(pdfBytes, pageIndex = 0, options) {
48641
48854
  while (!next.done) next = steps.next();
48642
48855
  return next.value;
48643
48856
  }
48857
+ async function* encodeSvgPathPaintChunks(original, pageHeight, options = {}) {
48858
+ const { signal } = options;
48859
+ signal?.throwIfAborted();
48860
+ const chunkBytes = options.chunkBytes ?? 16384, maximum10 = options.maxOutputBytes ?? Infinity, scale = options.scale ?? 1;
48861
+ if (!Number.isSafeInteger(chunkBytes) || chunkBytes < 1) throw new RangeError("Invalid SVG paint chunk size");
48862
+ for (const value of [maximum10, options.maxSegments ?? Infinity, options.maxDashEntries ?? Infinity]) if (value !== Infinity && (!Number.isSafeInteger(value) || value < 0)) throw new RangeError("Invalid SVG paint limit");
48863
+ if (!Number.isFinite(scale) || scale <= 0) throw new RangeError("Invalid SVG paint scale");
48864
+ if (original.kind === "glyph" && (original.value.renderMode === 3 || !original.value.outline && !original.value.unicode.trim())) return;
48865
+ const p = original.kind === "glyph" ? glyphPaint(original.value) : original.value;
48866
+ const segmentCount = p.storedSegments?.count ?? p.segments.length, dashCount = p.storedDash?.length ?? p.dashArray?.length ?? 0;
48867
+ if (!Number.isSafeInteger(segmentCount) || segmentCount < 0 || !Number.isSafeInteger(dashCount) || dashCount < 0) throw new RangeError("Invalid SVG paint record count");
48868
+ if (segmentCount > (options.maxSegments ?? Infinity) || dashCount > (options.maxDashEntries ?? Infinity)) throw new PdfError("E_LIMIT", "SVG paint record limit exceeded");
48869
+ if (!segmentCount) return;
48870
+ let emitted = 0, work = 0;
48871
+ const encoder = new TextEncoder();
48872
+ function* bytes(bytes2) {
48873
+ if (bytes2.length > maximum10 - emitted || !Number.isSafeInteger(emitted + bytes2.length)) throw new PdfError("E_LIMIT", "SVG paint output byte limit exceeded");
48874
+ emitted += bytes2.length;
48875
+ for (let at = 0; at < bytes2.length; at += chunkBytes) {
48876
+ signal?.throwIfAborted();
48877
+ yield bytes2.slice(at, at + chunkBytes);
48878
+ }
48879
+ }
48880
+ function* text(value) {
48881
+ for (let at = 0; at < value.length; ) {
48882
+ let end = Math.min(at + 2048, value.length);
48883
+ if (end < value.length && value.charCodeAt(end - 1) >= 55296 && value.charCodeAt(end - 1) <= 56319) end--;
48884
+ yield* bytes(encoder.encode(value.slice(at, end)));
48885
+ at = end;
48886
+ }
48887
+ }
48888
+ async function checkpoint() {
48889
+ signal?.throwIfAborted();
48890
+ if (++work % 64 === 0) {
48891
+ await new Promise((resolve2) => setTimeout(resolve2, 0));
48892
+ signal?.throwIfAborted();
48893
+ }
48894
+ }
48895
+ async function* dashes(factor) {
48896
+ if (!p.storedDash) {
48897
+ for (const value of p.dashArray ?? []) {
48898
+ await checkpoint();
48899
+ yield value * factor;
48900
+ }
48901
+ return;
48902
+ }
48903
+ const source = p.storedDash;
48904
+ if (!Number.isSafeInteger(source.position) || source.position < 0 || !Number.isSafeInteger(source.position + dashCount * 8)) throw new RangeError("Invalid SVG dash position");
48905
+ for (let at = 0; at < dashCount; at += 512) {
48906
+ await checkpoint();
48907
+ const length = Math.min(512, dashCount - at) * 8, data = (await source.storage.read(source.position + at * 8, length, signal ? { signal } : void 0)).slice();
48908
+ if (data.length !== length) throw new Error("Incomplete SVG dash pattern");
48909
+ const view = new DataView(data.buffer, data.byteOffset, data.length);
48910
+ for (let i = 0; i < length; i += 8) {
48911
+ await checkpoint();
48912
+ yield view.getFloat64(i, true) * factor;
48913
+ }
48914
+ }
48915
+ }
48916
+ const prepared = p.strokeColor ? prepareStroke(p, scale) : void 0;
48917
+ let outlineStroke = false;
48918
+ if (prepared) for await (const value of dashes(1)) {
48919
+ if (value === 0) {
48920
+ outlineStroke = true;
48921
+ break;
48922
+ }
48923
+ }
48924
+ const matrix2 = prepared && (prepared.matrix[0] !== 1 || prepared.matrix[1] !== 0 || prepared.matrix[2] !== 0 || prepared.matrix[3] !== 1) ? prepared.matrix : void 0, inverse = matrix2 ? inverseStrokeMatrix(matrix2) : void 0;
48925
+ const transform = inverse && matrix2 ? ` transform="matrix(${matrix2[0]} ${-matrix2[1]} ${-matrix2[2]} ${matrix2[3]} ${matrix2[4]} ${pageHeight - matrix2[5]})"` : "";
48926
+ const fill = p.fillColor ? `rgb(${Math.round(p.fillColor.r * 255)},${Math.round(p.fillColor.g * 255)},${Math.round(p.fillColor.b * 255)})` : "none", stroke = p.strokeColor && prepared ? `rgb(${Math.round(p.strokeColor.r * 255)},${Math.round(p.strokeColor.g * 255)},${Math.round(p.strokeColor.b * 255)})` : "none";
48927
+ const label = original.kind === "glyph" ? ` aria-label="${escapeXmlText(original.value.unicode)}"` : "";
48928
+ let painted = false;
48929
+ if (!outlineStroke || p.fillColor) {
48930
+ painted = true;
48931
+ yield* text(` <path${label}${transform} d="`);
48932
+ for await (const chunk of encodeSvgPathDataChunks(p.storedSegments ?? p.segments, inverse ? 0 : pageHeight, { ...options, ...inverse ? { matrix: inverse } : {} })) yield* bytes(chunk);
48933
+ yield* text(`" fill="${fill}"${p.fillRule === "evenodd" ? ' fill-rule="evenodd"' : ""}${p.fillAlpha !== void 0 && p.fillAlpha < 1 ? ` fill-opacity="${p.fillAlpha}"` : ""} stroke="${outlineStroke ? "none" : stroke}"${p.strokeAlpha !== void 0 && p.strokeAlpha < 1 ? ` stroke-opacity="${p.strokeAlpha}"` : ""}`);
48934
+ yield* text(p.strokeWidth <= 0 && !matrix2 && !dashCount ? ' stroke-width="1" vector-effect="non-scaling-stroke"' : ` stroke-width="${prepared?.width ?? p.strokeWidth}"`);
48935
+ yield* text(`${p.lineCap === 1 ? ' stroke-linecap="round"' : p.lineCap === 2 ? ' stroke-linecap="square"' : ""}${p.lineJoin === 1 ? ' stroke-linejoin="round"' : p.lineJoin === 2 ? ' stroke-linejoin="bevel"' : ""}${p.miterLimit !== void 0 && p.miterLimit !== 10 ? ` stroke-miterlimit="${p.miterLimit}"` : ""}`);
48936
+ if (!outlineStroke && prepared && dashCount) {
48937
+ yield* text(' stroke-dasharray="');
48938
+ let first = true;
48939
+ const factor = p.storedDash ? prepared.storedDashScale : 1;
48940
+ if (p.storedDash) {
48941
+ for await (const value of dashes(factor)) {
48942
+ yield* text(`${first ? "" : " "}${value}`);
48943
+ first = false;
48944
+ }
48945
+ } else for (const value of prepared.dashArray ?? []) {
48946
+ await checkpoint();
48947
+ yield* text(`${first ? "" : " "}${value}`);
48948
+ first = false;
48949
+ }
48950
+ yield* text('"');
48951
+ }
48952
+ if (!outlineStroke && prepared?.dashPhase) yield* text(` stroke-dashoffset="${prepared.dashPhase}"`);
48953
+ yield* text("/>");
48954
+ }
48955
+ if (outlineStroke) {
48956
+ const io = { signal }, iterator = strokeContourPoints(p, pageHeight, scale, 0, 0, 0, 0, io)[Symbol.iterator]();
48957
+ let firstPoint = true, started = false, contours = 0;
48958
+ try {
48959
+ for (; ; ) {
48960
+ await checkpoint();
48961
+ const next = iterator.next();
48962
+ if (next.done) break;
48963
+ if (io.pathRequest) {
48964
+ const request = io.pathRequest;
48965
+ io.pathRequest = void 0;
48966
+ await request();
48967
+ }
48968
+ const point = next.value;
48969
+ if (point === null) continue;
48970
+ if (!started) {
48971
+ yield* text(`${painted ? "\n" : ""} <path${label} d="`);
48972
+ started = true;
48973
+ }
48974
+ if (firstPoint && contours) yield* text(" ");
48975
+ if (point) {
48976
+ yield* text(`${firstPoint ? "M" : " L"} ${point[0] / scale} ${point[1] / scale}`);
48977
+ firstPoint = false;
48978
+ } else {
48979
+ yield* text(" Z");
48980
+ firstPoint = true;
48981
+ contours++;
48982
+ }
48983
+ }
48984
+ } finally {
48985
+ iterator.return?.();
48986
+ }
48987
+ if (started) yield* text(`" fill="${stroke}" fill-opacity="${p.strokeAlpha ?? 1}"/>`);
48988
+ }
48989
+ }
48644
48990
 
48645
48991
  // packages/pdf-ast/src/render/retained-page-pixels.ts
48646
48992
  async function renderRetainedPagePixels(page2, storage, options = {}) {
@@ -48728,7 +49074,7 @@ async function renderRetainedPagePixels(page2, storage, options = {}) {
48728
49074
 
48729
49075
  // packages/pdf-ast/src/cos/range-parser.ts
48730
49076
  import { listenForAbort as listenForAbort2 } from "@poe-platform/safe-fs/contracts";
48731
- function limit(value, name) {
49077
+ function limit2(value, name) {
48732
49078
  const result = value ?? Infinity;
48733
49079
  if (result !== Infinity && (!Number.isSafeInteger(result) || result < 0)) throw new RangeError(`Invalid ${name}`);
48734
49080
  return result;
@@ -48832,16 +49178,16 @@ async function readValue(lexer, depth, nodes, options) {
48832
49178
  return value;
48833
49179
  }
48834
49180
  async function parseCosRangeValue(source, offset, options = {}) {
48835
- const depth = limit(options.maxRecursionDepth, "maxRecursionDepth");
48836
- const nodes = limit(options.maxNodes, "maxNodes");
48837
- const maxTokenBytes = limit(options.maxTokenBytes, "maxTokenBytes");
49181
+ const depth = limit2(options.maxRecursionDepth, "maxRecursionDepth");
49182
+ const nodes = limit2(options.maxNodes, "maxNodes");
49183
+ const maxTokenBytes = limit2(options.maxTokenBytes, "maxTokenBytes");
48838
49184
  const lexer = new CosRangeLexer(source, { compactNumbers: options.compactNumbers ?? false, compactKeywords: options.compactKeywords ?? false, ...options.onBackingError ? { onBackingError: options.onBackingError } : {}, start: offset, ...options.end === void 0 ? {} : { end: options.end }, maxTokenBytes, ...options.signal ? { signal: options.signal } : {} });
48839
49185
  return { value: await readValue(lexer, depth, nodes, options), offset: lexer.offset };
48840
49186
  }
48841
49187
  async function parseCosRangeObject(source, offset, options = {}) {
48842
- const depth = limit(options.maxRecursionDepth, "maxRecursionDepth");
48843
- const nodes = limit(options.maxNodes, "maxNodes");
48844
- const tokenBytes = limit(options.maxTokenBytes, "maxTokenBytes");
49188
+ const depth = limit2(options.maxRecursionDepth, "maxRecursionDepth");
49189
+ const nodes = limit2(options.maxNodes, "maxNodes");
49190
+ const tokenBytes = limit2(options.maxTokenBytes, "maxTokenBytes");
48845
49191
  const { signal } = options;
48846
49192
  signal?.throwIfAborted();
48847
49193
  const lexer = new CosRangeLexer(source, { compactNumbers: options.compactNumbers ?? false, compactKeywords: options.compactKeywords ?? false, ...options.onBackingError ? { onBackingError: options.onBackingError } : {}, start: offset, maxTokenBytes: tokenBytes, ...signal ? { signal } : {} });
@@ -48863,7 +49209,13 @@ async function parseCosRangeObject(source, offset, options = {}) {
48863
49209
  const first = await byteAt(source, start, signal);
48864
49210
  if (first === 13) start += await byteAt(source, start + 1, signal) === 10 ? 2 : 1;
48865
49211
  else if (first === 10) start++;
48866
- const entry = dictGet(value, "Length");
49212
+ let entry;
49213
+ try {
49214
+ entry = value.storedEntries ? await readPdfDictionaryValue(value, "Length", signal, { preserveDeferred: true }) : dictGet(value, "Length");
49215
+ } catch (error) {
49216
+ options.onBackingError?.(error);
49217
+ throw error;
49218
+ }
48867
49219
  const length = await resolveStreamLength(entry, options);
48868
49220
  signal?.throwIfAborted();
48869
49221
  if (length !== void 0 && Number.isSafeInteger(length) && length >= 0 && length <= source.size - start) {
@@ -49110,11 +49462,11 @@ async function* readCosXrefRevision(source, offset, options = {}) {
49110
49462
  for (let i = 0; i < count; i++) {
49111
49463
  const type = w0 ? await reader.integer(w0) : 1;
49112
49464
  const field1 = await reader.integer(w1);
49113
- const field2 = w2 ? await reader.integer(w2) : 0;
49465
+ const field22 = w2 ? await reader.integer(w2) : 0;
49114
49466
  signal?.throwIfAborted();
49115
- if (type === 0) yield { type: "free", objectNumber: start + i, nextFreeObjectNumber: field1, generationNumber: field2 };
49116
- else if (type === 1) yield { type: "uncompressed", objectNumber: start + i, offset: field1, generationNumber: field2 };
49117
- else if (type === 2) yield { type: "compressed", objectNumber: start + i, objectStreamNumber: field1, indexInStream: field2 };
49467
+ if (type === 0) yield { type: "free", objectNumber: start + i, nextFreeObjectNumber: field1, generationNumber: field22 };
49468
+ else if (type === 1) yield { type: "uncompressed", objectNumber: start + i, offset: field1, generationNumber: field22 };
49469
+ else if (type === 2) yield { type: "compressed", objectNumber: start + i, objectStreamNumber: field1, indexInStream: field22 };
49118
49470
  else throw new PdfError("E_PARSE", `Invalid XRef entry type: ${type}`);
49119
49471
  if (++turns % 64 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
49120
49472
  }
@@ -49552,7 +49904,7 @@ function integer2(value, name, minimum = 0) {
49552
49904
  function maximum2(value, name) {
49553
49905
  return value === void 0 || value === Infinity ? Number.MAX_SAFE_INTEGER : integer2(value, name);
49554
49906
  }
49555
- function field(dict, key) {
49907
+ function field2(dict, key) {
49556
49908
  const value = dictGet(dict, key);
49557
49909
  if (value?.kind !== "number" || !Number.isSafeInteger(value.value) || value.value < 0) throw new PdfError("E_PARSE", `Invalid object stream /${key}`);
49558
49910
  return value.value;
@@ -49762,7 +50114,15 @@ var PdfObjectReader = class {
49762
50114
  this.repairedOffsets.set(objectNumber, object.span.start);
49763
50115
  }
49764
50116
  if (this.options.encryption && objectNumber !== this.options.encryptionObjectNumber) {
49765
- let type = object.stream && object.value.kind === "dict" ? dictGet(object.value, "Type") : void 0;
50117
+ let type;
50118
+ if (object.stream && object.value.kind === "dict") {
50119
+ try {
50120
+ type = object.value.storedEntries ? await readPdfDictionaryValue(object.value, "Type", this.options.signal, { preserveDeferred: true }) : dictGet(object.value, "Type");
50121
+ } catch (error) {
50122
+ onBackingError(error);
50123
+ throw error;
50124
+ }
50125
+ }
49766
50126
  if (type?.kind === "ref") type = (await this.load(type.objectNumber, type.generationNumber, active))?.value;
49767
50127
  const value = await decryptPdfObjectStrings(
49768
50128
  this.options.encryption,
@@ -49813,8 +50173,8 @@ var PdfObjectReader = class {
49813
50173
  }
49814
50174
  const object = await this.load(number, generation, active);
49815
50175
  if (object?.value.kind !== "dict" || !object.stream || dictGet(object.value, "Type")?.kind !== "name" || dictGet(object.value, "Type").decoded !== "ObjStm") throw new PdfError("E_PARSE", "Invalid object stream dictionary");
49816
- const count = field(object.value, "N");
49817
- const first = field(object.value, "First");
50176
+ const count = field2(object.value, "N");
50177
+ const first = field2(object.value, "First");
49818
50178
  if (count > maximum2(this.options.maxObjectStreamMembers, "maxObjectStreamMembers") || count > Math.floor(Number.MAX_SAFE_INTEGER / 16)) throw new PdfError("E_LIMIT", "PDF object stream member limit exceeded");
49819
50179
  active.add(number);
49820
50180
  let dict;
@@ -50816,16 +51176,16 @@ async function renderRetainedMesh(context, dict, type, input, settings, storage,
50816
51176
 
50817
51177
  // packages/pdf-ast/src/extract/retained-color.ts
50818
51178
  import { readBytes as readBytes14 } from "@poe-platform/safe-fs/contracts";
50819
- function limit2(value, fallback, name) {
51179
+ function limit3(value, fallback, name) {
50820
51180
  const result = value ?? fallback;
50821
51181
  if (result !== Infinity && (!Number.isSafeInteger(result) || result < 0)) throw new RangeError(`Invalid ${name}`);
50822
51182
  return Math.min(result, Number.MAX_SAFE_INTEGER);
50823
51183
  }
50824
51184
  function createRetainedColorAccess(document2, storage, options, storedFunctions = false) {
50825
- const maximum10 = limit2(options.maxWorkingBytes, Infinity, "maxWorkingBytes");
50826
- const maxStaging = limit2(options.maxStagingBytes, Infinity, "maxStagingBytes");
50827
- const maxNodes = limit2(options.maxNodes, 65536, "maxNodes");
50828
- const maxDepth = limit2(options.maxDepth, document2.depthLimit, "maxDepth");
51185
+ const maximum10 = limit3(options.maxWorkingBytes, Infinity, "maxWorkingBytes");
51186
+ const maxStaging = limit3(options.maxStagingBytes, Infinity, "maxStagingBytes");
51187
+ const maxNodes = limit3(options.maxNodes, 65536, "maxNodes");
51188
+ const maxDepth = limit3(options.maxDepth, document2.depthLimit, "maxDepth");
50829
51189
  const chunkBytes = options.chunkBytes ?? 4096;
50830
51190
  if (!Number.isSafeInteger(chunkBytes) || chunkBytes <= 0) throw new RangeError("Invalid chunkBytes");
50831
51191
  let used = 0;
@@ -50875,11 +51235,11 @@ function createRetainedColorAccess(document2, storage, options, storedFunctions
50875
51235
  options.onAllocation?.(bytes);
50876
51236
  used += bytes;
50877
51237
  }
50878
- async function resolve2(value) {
51238
+ async function resolve2(value, path) {
50879
51239
  options.signal?.throwIfAborted();
50880
51240
  if (++nodes > maxNodes) throw new PdfError("E_LIMIT", "PDF color node limit exceeded");
50881
51241
  charge(64);
50882
- const resolved = await document2.lookup(value);
51242
+ const resolved = await document2.lookup(value, void 0, path);
50883
51243
  options.signal?.throwIfAborted();
50884
51244
  if (!resolved) return void 0;
50885
51245
  if (resolved.stream && resolved.reference && resolved.value.kind === "dict") {
@@ -50890,6 +51250,11 @@ function createRetainedColorAccess(document2, storage, options, storedFunctions
50890
51250
  if (resolved.value.kind === "name") charge(resolved.value.decoded.length * 2);
50891
51251
  return resolved.value;
50892
51252
  }
51253
+ async function resource(request) {
51254
+ const map = await resolve2(dictGet(request.resources, request.category), ["Resources", request.category]);
51255
+ const dictionary = map?.kind === "stream" ? map.dict : map;
51256
+ return dictionary?.kind === "dict" ? readPdfDictionaryValue(dictionary, request.name, options.signal) : void 0;
51257
+ }
50893
51258
  function contents(stream) {
50894
51259
  const reference = streams.get(stream);
50895
51260
  return reference ? document2.objects.decodeStream(reference.objectNumber, reference.generationNumber) : decodePdfStreamChunks(stream.dict, async function* () {
@@ -50993,8 +51358,8 @@ function createRetainedColorAccess(document2, storage, options, storedFunctions
50993
51358
  const item = dictGet(dict, key);
50994
51359
  if (!item) continue;
50995
51360
  charge(64);
50996
- const field2 = key === "Functions" ? await snapshotFunction(item, depth + 1) : await snapshotNumbers(item);
50997
- selected.entries.push({ key: cosName(key), value: field2 ?? { kind: "null" } });
51361
+ const field3 = key === "Functions" ? await snapshotFunction(item, depth + 1) : await snapshotNumbers(item);
51362
+ selected.entries.push({ key: cosName(key), value: field3 ?? { kind: "null" } });
50998
51363
  }
50999
51364
  if (value?.kind === "stream" && (kind === 0 || kind === 4) && storedFunctions) return storeFunction(value, selected);
51000
51365
  return value?.kind === "stream" && (kind === 0 || kind === 4) ? cosStream(selected, await decode2(value)) : selected;
@@ -51075,7 +51440,7 @@ function createRetainedColorAccess(document2, storage, options, storedFunctions
51075
51440
  maxRecursionDepth: maxDepth
51076
51441
  });
51077
51442
  options.signal?.throwIfAborted();
51078
- return { resolve: resolve2, decode: decode2, contents, snapshot, snapshotColor, snapshotFunction, charge, context, maxDepth, functionSources, storedFunctions, async close() {
51443
+ return { resolve: resolve2, resource, decode: decode2, contents, snapshot, snapshotColor, snapshotFunction, charge, context, maxDepth, functionSources, storedFunctions, async close() {
51079
51444
  await functionBacking?.close();
51080
51445
  } };
51081
51446
  }
@@ -51094,7 +51459,7 @@ async function openRetainedImageColor(document2, node, resources, storage, optio
51094
51459
  }
51095
51460
  }
51096
51461
  async function resolveImageColor(access, node, resources, options) {
51097
- const { resolve: resolve2, decode: decode2, snapshot, snapshotFunction, charge, context, maxDepth, functionSources } = access;
51462
+ const { resolve: resolve2, resource, decode: decode2, snapshot, snapshotFunction, charge, context, maxDepth, functionSources } = access;
51098
51463
  const work = imageColorSpaceProgram(node, resources, maxDepth);
51099
51464
  try {
51100
51465
  let step = work.next();
@@ -51106,6 +51471,9 @@ async function resolveImageColor(access, node, resources, options) {
51106
51471
  case "resolve":
51107
51472
  result = await resolve2(request.node);
51108
51473
  break;
51474
+ case "resource":
51475
+ result = await resource(request);
51476
+ break;
51109
51477
  case "palette": {
51110
51478
  if (!Number.isSafeInteger(request.maxBytes) || request.maxBytes < 0) throw new PdfError("E_LIMIT", "PDF palette size limit exceeded");
51111
51479
  if (request.node.kind === "stream") result = await decode2(request.node, request.maxBytes);
@@ -51164,7 +51532,7 @@ async function runFunctionSteps(work, signal) {
51164
51532
  }
51165
51533
  }
51166
51534
  async function runRetainedColorProgram(document2, storage, options, work) {
51167
- const { resolve: resolve2, decode: decode2, snapshot, snapshotFunction, context, charge, functionSources, close } = createRetainedColorAccess(document2, storage, options, true);
51535
+ const { resolve: resolve2, resource, decode: decode2, snapshot, snapshotFunction, context, charge, functionSources, close } = createRetainedColorAccess(document2, storage, options, true);
51168
51536
  let failed = false;
51169
51537
  try {
51170
51538
  let step = work.next();
@@ -51172,7 +51540,9 @@ async function runRetainedColorProgram(document2, storage, options, work) {
51172
51540
  options.signal?.throwIfAborted();
51173
51541
  const request = step.value;
51174
51542
  let result;
51175
- if (request.kind === "resolve") result = await resolve2(request.node);
51543
+ if (request.kind === "dictionary-value") result = await readPdfDictionaryValue(request.dict, request.key, options.signal);
51544
+ else if (request.kind === "resolve") result = await resolve2(request.node);
51545
+ else if (request.kind === "resource") result = await resource(request);
51176
51546
  else if (request.kind === "decode") result = await decode2(request.stream, request.length, request.start);
51177
51547
  else if (request.kind === "calibrated") result = createCalibratedColorSpace(context, request.family, await snapshot(request.parameters));
51178
51548
  else if (request.kind === "transfer") {
@@ -51247,7 +51617,7 @@ async function renderRetainedShading(document2, node, settings, storage, options
51247
51617
  import { PagedStorage as PagedStorage3 } from "@poe-platform/safe-fs/storage";
51248
51618
 
51249
51619
  // packages/pdf-ast/src/extract/retained-jpeg.ts
51250
- function limit3(value, name) {
51620
+ function limit4(value, name) {
51251
51621
  if (value === void 0 || value === Infinity) return Number.MAX_SAFE_INTEGER;
51252
51622
  if (!Number.isSafeInteger(value) || value < 0) throw new RangeError(`Invalid ${name}`);
51253
51623
  return value;
@@ -51272,8 +51642,8 @@ var PdfRetainedJpeg = class _PdfRetainedJpeg {
51272
51642
  static async open(source, options = {}) {
51273
51643
  const controller = new AbortController();
51274
51644
  options = { ...options, signal: options.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal };
51275
- const maximum10 = limit3(options.maxWorkingBytes, "maxWorkingBytes");
51276
- const outputMaximum = limit3(options.maxOutputBytes, "maxOutputBytes");
51645
+ const maximum10 = limit4(options.maxWorkingBytes, "maxWorkingBytes");
51646
+ const outputMaximum = limit4(options.maxOutputBytes, "maxOutputBytes");
51277
51647
  let allocated = 0;
51278
51648
  let parsing = true;
51279
51649
  function charge(bytes) {
@@ -51463,7 +51833,7 @@ async function* tileDescriptors(tiles, storage, signal) {
51463
51833
  }
51464
51834
  }
51465
51835
  }
51466
- function limit4(value, name) {
51836
+ function limit5(value, name) {
51467
51837
  if (value === void 0 || value === Infinity) return Number.MAX_SAFE_INTEGER;
51468
51838
  if (!Number.isSafeInteger(value) || value < 0) throw new RangeError(`Invalid ${name}`);
51469
51839
  return value;
@@ -51497,8 +51867,8 @@ var PdfRetainedJpx = class _PdfRetainedJpx {
51497
51867
  ...options,
51498
51868
  signal: options.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal
51499
51869
  };
51500
- const maximum10 = limit4(options.maxWorkingBytes, "maxWorkingBytes");
51501
- const outputMaximum = limit4(options.maxOutputBytes, "maxOutputBytes");
51870
+ const maximum10 = limit5(options.maxWorkingBytes, "maxWorkingBytes");
51871
+ const outputMaximum = limit5(options.maxOutputBytes, "maxOutputBytes");
51502
51872
  let allocated = 0;
51503
51873
  let allocationFailure;
51504
51874
  function charge(bytes) {
@@ -51725,7 +52095,7 @@ var PdfRetainedJpx = class _PdfRetainedJpx {
51725
52095
  };
51726
52096
 
51727
52097
  // packages/pdf-ast/src/extract/retained-jbig2.ts
51728
- function limit5(value, name) {
52098
+ function limit6(value, name) {
51729
52099
  if (value === void 0 || value === Infinity) return Number.MAX_SAFE_INTEGER;
51730
52100
  if (!Number.isSafeInteger(value) || value < 0) throw new RangeError(`Invalid ${name}`);
51731
52101
  return value;
@@ -51752,8 +52122,8 @@ var PdfRetainedJbig2 = class _PdfRetainedJbig2 {
51752
52122
  static async open(source, fallbackWidth, fallbackHeight, options = {}) {
51753
52123
  const controller = new AbortController();
51754
52124
  options = { ...options, signal: options.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal };
51755
- const maximum10 = limit5(options.maxWorkingBytes, "maxWorkingBytes");
51756
- const outputMaximum = limit5(options.maxOutputBytes, "maxOutputBytes");
52125
+ const maximum10 = limit6(options.maxWorkingBytes, "maxWorkingBytes");
52126
+ const outputMaximum = limit6(options.maxOutputBytes, "maxOutputBytes");
51757
52127
  let allocated = 0;
51758
52128
  function charge(bytes) {
51759
52129
  if (!Number.isSafeInteger(bytes) || bytes < 0 || bytes > maximum10 - allocated) throw new PdfError("E_LIMIT", "JBIG2 working byte limit exceeded");
@@ -51922,7 +52292,7 @@ var PdfRetainedJbig2 = class _PdfRetainedJbig2 {
51922
52292
 
51923
52293
  // packages/pdf-ast/src/extract/retained-mask.ts
51924
52294
  import { readBytes as readBytes15 } from "@poe-platform/safe-fs/contracts";
51925
- function limit6(value, name) {
52295
+ function limit7(value, name) {
51926
52296
  if (value === void 0 || value === Infinity) return Number.MAX_SAFE_INTEGER;
51927
52297
  if (!Number.isSafeInteger(value) || value < 0) throw new RangeError(`Invalid ${name}`);
51928
52298
  return value;
@@ -51932,8 +52302,8 @@ async function* applyRetainedImageMask(rows, width, height, mask, options) {
51932
52302
  if (!Number.isSafeInteger(value) || value <= 0) throw new RangeError(`Invalid ${name}`);
51933
52303
  }
51934
52304
  if (options.mode !== "soft" && options.mode !== "explicit") throw new RangeError("Invalid mask mode");
51935
- const workingLimit = limit6(options.maxWorkingBytes, "maxWorkingBytes");
51936
- const outputLimit = limit6(options.maxOutputBytes, "maxOutputBytes");
52305
+ const workingLimit = limit7(options.maxWorkingBytes, "maxWorkingBytes");
52306
+ const outputLimit = limit7(options.maxOutputBytes, "maxOutputBytes");
51937
52307
  const pixels = width * height;
51938
52308
  const maskPixels = mask.width * mask.height;
51939
52309
  if (!Number.isSafeInteger(pixels) || pixels > Math.floor(outputLimit / 4)) throw new PdfError("E_LIMIT", "PDF masked output byte limit exceeded");
@@ -51975,7 +52345,7 @@ async function* applyRetainedImageMask(rows, width, height, mask, options) {
51975
52345
  }
51976
52346
 
51977
52347
  // packages/pdf-ast/src/extract/retained-samples.ts
51978
- function limit7(value, name) {
52348
+ function limit8(value, name) {
51979
52349
  if (value === void 0 || value === Infinity) return Number.MAX_SAFE_INTEGER;
51980
52350
  if (!Number.isSafeInteger(value) || value < 0) throw new RangeError(`Invalid ${name}`);
51981
52351
  return value;
@@ -51984,8 +52354,8 @@ async function* decodeRetainedSampleRows(source, width, height, bitsPerComponent
51984
52354
  for (const [name, value] of [["width", width], ["height", height], ["bitsPerComponent", bitsPerComponent], ["components", color.components]]) {
51985
52355
  if (!Number.isSafeInteger(value) || value <= 0) throw new RangeError(`Invalid ${name}`);
51986
52356
  }
51987
- const workingLimit = limit7(options.maxWorkingBytes, "maxWorkingBytes");
51988
- const outputLimit = limit7(options.maxOutputBytes, "maxOutputBytes");
52357
+ const workingLimit = limit8(options.maxWorkingBytes, "maxWorkingBytes");
52358
+ const outputLimit = limit8(options.maxOutputBytes, "maxOutputBytes");
51989
52359
  const pixels = width * height;
51990
52360
  if (!Number.isSafeInteger(pixels) || pixels > Math.floor(outputLimit / 4)) throw new PdfError("E_LIMIT", "PDF sample output byte limit exceeded");
51991
52361
  options.signal?.throwIfAborted();
@@ -53095,8 +53465,8 @@ async function readType1Header(lexer, initialMatrix, storage, signal) {
53095
53465
  if (!await token2.equals("/")) continue;
53096
53466
  switch (await (await lexer.next())?.keyword()) {
53097
53467
  case "FontMatrix": {
53098
- const field2 = await readType1NumberArray(lexer);
53099
- matrix2 = field2.count > 6 ? [...field2.values, 0] : field2.values;
53468
+ const field3 = await readType1NumberArray(lexer);
53469
+ matrix2 = field3.count > 6 ? [...field3.values, 0] : field3.values;
53100
53470
  break;
53101
53471
  }
53102
53472
  case "FontBBox":
@@ -53371,8 +53741,8 @@ async function parseStoredType1Cid(source, properties, storage, signal) {
53371
53741
  const key = await keyToken?.keyword();
53372
53742
  switch (key) {
53373
53743
  case "FontMatrix": {
53374
- const field2 = await readType1NumberArray(lexer);
53375
- properties.fontMatrix = field2.count > 6 ? [...field2.values, 0] : field2.values;
53744
+ const field3 = await readType1NumberArray(lexer);
53745
+ properties.fontMatrix = field3.count > 6 ? [...field3.values, 0] : field3.values;
53376
53746
  break;
53377
53747
  }
53378
53748
  case "FontBBox":
@@ -54129,8 +54499,8 @@ async function readCffDictionary(source, selected) {
54129
54499
  var TOP_FIELDS = /* @__PURE__ */ new Set([15, 16, 17, 18, 3079, 3102, 3108, 3109]);
54130
54500
  var PRIVATE_FIELDS = /* @__PURE__ */ new Set([19]);
54131
54501
  var DEFAULT_MATRIX = [1e-3, 0, 0, 1e-3, 0, 0];
54132
- function scalar(dict, field2, fallback = 0) {
54133
- return dict.get(field2)?.values[0] ?? fallback;
54502
+ function scalar(dict, field3, fallback = 0) {
54503
+ return dict.get(field3)?.values[0] ?? fallback;
54134
54504
  }
54135
54505
  function matrix(dict) {
54136
54506
  const entry = dict.get(3079);
@@ -55072,8 +55442,8 @@ async function resolveRetainedFont(document2, storage, resources, name, options
55072
55442
  }
55073
55443
  let value;
55074
55444
  if (step.value.kind === "resolve") {
55075
- const retained = await document2.lookup(step.value.node, options.resourceStorage ? { dictionaryStorage: options.resourceStorage, storedDictionaryKeys: ["Font", "XObject", "Properties"], storeRootDictionary: step.value.storeRootDictionary ?? false, arrayStorage: options.resourceStorage, storedArrayKeys: ["Widths", "W", "Differences"], storeRootArray: step.value.storeRootArray ?? false } : {});
55076
- value = retained?.value;
55445
+ const retained = await document2.lookup(step.value.node, options.resourceStorage ? { dictionaryStorage: options.resourceStorage, deferDictionaryValues: true, deferArrayValues: true, containerStorage: options.resourceStorage, stringStorage: options.resourceStorage, storedDictionaryKeys: ["Font", "XObject", "Properties"], storedDictionaryPaths: [["Resources", "*"]], storeRootDictionary: step.value.storeRootDictionary ?? false, arrayStorage: options.resourceStorage, storedArrayKeys: ["Widths", "W", "Differences"], storeRootArray: step.value.storeRootArray ?? false } : {}, step.value.arrayPathPrefix);
55446
+ value = retained ? options.resourceStorage && (step.value.storeRootDictionary || step.value.storeRootArray) ? retained.value : await materializeResourceValue(retained.value, signal) : void 0;
55077
55447
  if (retained?.stream) {
55078
55448
  if (retained.value.kind !== "dict" || !retained.reference) throw new PdfError("E_PARSE", "Font stream has no retained identity");
55079
55449
  allocation.admit(256);
@@ -55081,6 +55451,8 @@ async function resolveRetainedFont(document2, storage, resources, name, options
55081
55451
  identities.set(stream, retained.reference);
55082
55452
  value = stream;
55083
55453
  }
55454
+ } else if (step.value.kind === "dictionary-value") {
55455
+ value = await readPdfDictionaryValue(step.value.dict, step.value.key, signal, { preserveDeferred: true });
55084
55456
  } else if (step.value.kind === "dictionary-entry") {
55085
55457
  const record = await readStoredRecord(step.value.entries.storage, step.value.position, signal);
55086
55458
  value = cosArray([record.value.key, record.value.value, cosNumber(record.next)]);
@@ -55265,9 +55637,9 @@ async function* evaluateRetainedContentSteps(document2, content, params, storage
55265
55637
  admitted += bytes;
55266
55638
  }
55267
55639
  const identities = /* @__PURE__ */ new WeakMap();
55268
- async function resolve2(node, storeRootArray = false, arrayPathPrefix) {
55640
+ async function resolve2(node, storeRootArray = false, arrayPathPrefix, storeRootDictionary = false) {
55269
55641
  charge(64);
55270
- const value = await document2.lookup(node, storeRootArray && options.imageStorage ? { arrayStorage: options.imageStorage, storeRootArray: true } : void 0, arrayPathPrefix);
55642
+ const value = await document2.lookup(node, void 0, arrayPathPrefix, storeRootDictionary, storeRootArray ? options.imageStorage : void 0);
55271
55643
  signal?.throwIfAborted();
55272
55644
  if (value?.stream && value.reference && value.value.kind === "dict") {
55273
55645
  charge(128);
@@ -55406,14 +55778,14 @@ async function* evaluateRetainedContentSteps(document2, content, params, storage
55406
55778
  }
55407
55779
  case "resolve":
55408
55780
  case "catalog":
55409
- reply = { kind: "resolved", node: await resolve2(request.kind === "catalog" ? document2.crossReference.rootRef : request.node, request.kind === "resolve" && request.storeRootArray, request.kind === "resolve" ? request.arrayPathPrefix : void 0) };
55781
+ reply = { kind: "resolved", node: await resolve2(request.kind === "catalog" ? document2.crossReference.rootRef : request.node, request.kind === "resolve" && request.storeRootArray, request.kind === "resolve" ? request.arrayPathPrefix : void 0, request.kind === "resolve" && request.storeRootDictionary) };
55410
55782
  break;
55411
55783
  case "dash-array": {
55412
55784
  reply = { kind: "dash-array", value: await storeDashArray(request.array, request.storage, request.resolveReferences ? resolve2 : async (node) => node, signal) };
55413
55785
  break;
55414
55786
  }
55415
55787
  case "dictionary-value":
55416
- reply = { kind: "resolved", node: await readPdfDictionaryValue(request.dict, request.key, signal) };
55788
+ reply = { kind: "resolved", node: await readPdfDictionaryValue(request.dict, request.key, signal, request.preserveDeferred ? { preserveDeferred: true } : {}) };
55417
55789
  break;
55418
55790
  case "array-reference":
55419
55791
  reply = { kind: "resolved", node: cosBool(await memberships.has(request.items, request.objectNumber)) };
@@ -58349,8 +58721,8 @@ async function* walkRetainedFormFieldDetails(document2, storage, options = {}) {
58349
58721
  yield value2;
58350
58722
  }
58351
58723
  }
58352
- async function* appearances(field2) {
58353
- const appearance = await resolve2(dictGet(field2, "AP"));
58724
+ async function* appearances(field3) {
58725
+ const appearance = await resolve2(dictGet(field3, "AP"));
58354
58726
  const normal = appearance?.kind === "dict" ? await resolve2(dictGet(appearance, "N")) : void 0;
58355
58727
  if (normal?.kind === "dict") for (const pair of normal.entries) {
58356
58728
  await checkpoint();
@@ -58363,8 +58735,8 @@ async function* walkRetainedFormFieldDetails(document2, storage, options = {}) {
58363
58735
  yield* appearances(dict);
58364
58736
  const kids = await resolve2(dictGet(dict, "Kids"));
58365
58737
  if (kids?.kind === "array") for (const kid of kids.items) {
58366
- const field2 = await resolve2(kid);
58367
- if (field2?.kind === "dict") yield* appearances(field2);
58738
+ const field3 = await resolve2(kid);
58739
+ if (field3?.kind === "dict") yield* appearances(field3);
58368
58740
  }
58369
58741
  if (count === 1) yield* unique("Yes");
58370
58742
  }
@@ -59121,10 +59493,10 @@ async function* streamRawTextChunks(glyphs, storage, options = {}) {
59121
59493
  }
59122
59494
  })();
59123
59495
  const encoder = new TextEncoder(), buffer = new Uint8Array(chunkBytes);
59124
- function* encode3(text, offset = 0, limit10 = text.length) {
59125
- while (offset < limit10) {
59126
- let end = Math.min(limit10, offset + Math.floor(chunkBytes / 3));
59127
- if (end < limit10 && text.charCodeAt(end - 1) >= 55296 && text.charCodeAt(end - 1) <= 56319 && text.charCodeAt(end) >= 56320 && text.charCodeAt(end) <= 57343) end--;
59496
+ function* encode3(text, offset = 0, limit11 = text.length) {
59497
+ while (offset < limit11) {
59498
+ let end = Math.min(limit11, offset + Math.floor(chunkBytes / 3));
59499
+ if (end < limit11 && text.charCodeAt(end - 1) >= 55296 && text.charCodeAt(end - 1) <= 56319 && text.charCodeAt(end) >= 56320 && text.charCodeAt(end) <= 57343) end--;
59128
59500
  const { read, written } = encoder.encodeInto(text.slice(offset, end), buffer);
59129
59501
  offset += read;
59130
59502
  yield buffer.subarray(0, written);
@@ -59513,15 +59885,15 @@ var PdfStagedOutputs = class _PdfStagedOutputs {
59513
59885
  static async create(storage, input, options = {}) {
59514
59886
  const chunkBytes = maximum7(options.chunkBytes, 65536);
59515
59887
  if (chunkBytes < 32 || chunkBytes === Number.MAX_SAFE_INTEGER) throw new RangeError("PDF output chunkBytes must be finite and at least 32");
59516
- const limit10 = maximum7(options.maxStagingBytes, Infinity);
59888
+ const limit11 = maximum7(options.maxStagingBytes, Infinity);
59517
59889
  const nameLimit = maximum7(options.maxNameChars, 1048576);
59518
59890
  const { signal } = options;
59519
59891
  let written = 0;
59520
- const names = new PdfNameIndex(storage, () => limit10 - written, signal);
59892
+ const names = new PdfNameIndex(storage, () => limit11 - written, signal);
59521
59893
  let data;
59522
59894
  let index2;
59523
59895
  const charge = (size) => {
59524
- if (size > limit10 - written - names.stagedBytes) throw new PdfError("E_LIMIT", "PDF output staging byte limit exceeded");
59896
+ if (size > limit11 - written - names.stagedBytes) throw new PdfError("E_LIMIT", "PDF output staging byte limit exceeded");
59525
59897
  written += size;
59526
59898
  };
59527
59899
  async function* records2() {
@@ -59555,7 +59927,7 @@ var PdfStagedOutputs = class _PdfStagedOutputs {
59555
59927
  }
59556
59928
  }
59557
59929
  try {
59558
- data = await PdfFileSource.fromStream(storage.fs, storage.directory, records2(), { chunkBytes, cacheBytes: chunkBytes, maxInputBytes: limit10, ...signal ? { signal } : {} });
59930
+ data = await PdfFileSource.fromStream(storage.fs, storage.directory, records2(), { chunkBytes, cacheBytes: chunkBytes, maxInputBytes: limit11, ...signal ? { signal } : {} });
59559
59931
  await names.close();
59560
59932
  const source = data;
59561
59933
  async function* rows() {
@@ -59572,7 +59944,7 @@ var PdfStagedOutputs = class _PdfStagedOutputs {
59572
59944
  runEntries: 64,
59573
59945
  chunkBytes: indexChunk,
59574
59946
  cacheBytes: indexChunk,
59575
- maxStagingBytes: limit10 - data.size,
59947
+ maxStagingBytes: limit11 - data.size,
59576
59948
  ...signal ? { signal } : {}
59577
59949
  });
59578
59950
  return new _PdfStagedOutputs(data, index2, signal, nameLimit);
@@ -59666,7 +60038,7 @@ async function markedText(document2, page2, mcid, storage, options) {
59666
60038
  };
59667
60039
  var boundary = boundary2, scan = scan2;
59668
60040
  source = await PdfFileSource.fromStream(storage.fs, storage.directory, input(), { chunkBytes, cacheBytes: chunkBytes, maxInputBytes: maximum10, ...signal ? { signal } : {} });
59669
- const resources = (await document2.lookup(dictGet(page2, "Resources")))?.value;
60041
+ const resources = (await document2.lookup(dictGet(page2, "Resources"), void 0, ["Resources"]))?.value;
59670
60042
  const properties = resources?.kind === "dict" ? (await document2.lookup(dictGet(resources, "Properties"), void 0, ["Properties"]))?.value : void 0;
59671
60043
  const operators2 = parseContentRangeOperators(source, storage, { chunkBytes, maxStagingBytes: maximum10 - source.size, ...signal ? { signal } : {} });
59672
60044
  let pending, matching = false, inText = false, part = 0, recorded = false;
@@ -60048,7 +60420,7 @@ async function* walkRetainedJavaScripts(document2, storage, options) {
60048
60420
  const kids = await resolve2(dictGet(dict, "Kids"));
60049
60421
  if (kids?.kind === "array") for (const kid of kids.items) yield* tree(kid, depth + 1);
60050
60422
  }
60051
- async function* field2(node, fallback, depth = 0) {
60423
+ async function* field3(node, fallback, depth = 0) {
60052
60424
  if (depth > options.maxDepth) throw new PdfError("E_LIMIT", "PDF JavaScript field depth limit exceeded");
60053
60425
  const dict = await dictionary(node, "field");
60054
60426
  if (!dict) return;
@@ -60057,7 +60429,7 @@ async function* walkRetainedJavaScripts(document2, storage, options) {
60057
60429
  yield* action(dictGet(dict, "A"), `${label} Action`);
60058
60430
  yield* additional(dictGet(dict, "AA"), label);
60059
60431
  const kids = await resolve2(dictGet(dict, "Kids"));
60060
- if (kids?.kind === "array") for (const kid of kids.items) yield* field2(kid, label, depth + 1);
60432
+ if (kids?.kind === "array") for (const kid of kids.items) yield* field3(kid, label, depth + 1);
60061
60433
  }
60062
60434
  try {
60063
60435
  const root = await dictionary(document2.crossReference.rootRef);
@@ -60070,11 +60442,11 @@ async function* walkRetainedJavaScripts(document2, storage, options) {
60070
60442
  const label = `Page ${page2.index + 1}`;
60071
60443
  yield* additional(dictGet(page2.dict, "AA"), label);
60072
60444
  const annots = await resolve2(dictGet(page2.dict, "Annots"));
60073
- if (annots?.kind === "array") for (let i = 0; i < annots.items.length; i++) yield* field2(annots.items[i], `${label} Annot ${i + 1}`);
60445
+ if (annots?.kind === "array") for (let i = 0; i < annots.items.length; i++) yield* field3(annots.items[i], `${label} Annot ${i + 1}`);
60074
60446
  }
60075
60447
  const form = await dictionary(dictGet(root, "AcroForm"));
60076
60448
  const fields2 = form ? await resolve2(dictGet(form, "Fields")) : void 0;
60077
- if (fields2?.kind === "array") for (let i = 0; i < fields2.items.length; i++) yield* field2(fields2.items[i], `Field ${i + 1}`);
60449
+ if (fields2?.kind === "array") for (let i = 0; i < fields2.items.length; i++) yield* field3(fields2.items[i], `Field ${i + 1}`);
60078
60450
  } catch (error) {
60079
60451
  failed = true;
60080
60452
  throw error;
@@ -60096,7 +60468,7 @@ async function* walkRetainedImages(document2, storage, options) {
60096
60468
  let imageIndex = 0;
60097
60469
  let stagedBytes = 0;
60098
60470
  async function dictionary(node, resourceKey) {
60099
- const value = await document2.lookup(node, void 0, resourceKey ? [resourceKey] : void 0);
60471
+ const value = await document2.lookup(node, void 0, resourceKey ? resourceKey === "Resources" ? [resourceKey] : ["Resources", resourceKey] : void 0);
60100
60472
  return value?.value.kind === "dict" && !value.stream ? value.value : void 0;
60101
60473
  }
60102
60474
  async function number(node, fallback) {
@@ -60216,7 +60588,7 @@ async function* walkRetainedImages(document2, storage, options) {
60216
60588
  try {
60217
60589
  yield* content(
60218
60590
  document2.objects.decodeStream(ref.objectNumber, ref.generationNumber),
60219
- await dictionary(dictGet(target.value, "Resources")) ?? activeResources,
60591
+ await dictionary(dictGet(target.value, "Resources"), "Resources") ?? activeResources,
60220
60592
  transform,
60221
60593
  active,
60222
60594
  depth + 1
@@ -60246,7 +60618,7 @@ async function* walkRetainedImages(document2, storage, options) {
60246
60618
  if (value.stream && value.reference) {
60247
60619
  yield* content(
60248
60620
  document2.objects.decodeStream(value.reference.objectNumber, value.reference.generationNumber),
60249
- await dictionary(dictGet(value.value, "Resources")) ?? inherited,
60621
+ await dictionary(dictGet(value.value, "Resources"), "Resources") ?? inherited,
60250
60622
  identity,
60251
60623
  /* @__PURE__ */ new Set([value.reference.objectNumber]),
60252
60624
  0
@@ -60255,8 +60627,8 @@ async function* walkRetainedImages(document2, storage, options) {
60255
60627
  }
60256
60628
  try {
60257
60629
  yield* content(page2.streamContents(), resources, identity, /* @__PURE__ */ new Set(), 0);
60258
- const patterns = await dictionary(dictGet(resources, "Pattern"));
60259
- if (patterns) for (const entry of patterns.entries) yield* auxiliary(entry.value, resources);
60630
+ const patterns = await dictionary(dictGet(resources, "Pattern"), "Pattern");
60631
+ if (patterns) for await (const entry of readPdfDictionaryEntries(patterns, options.signal)) yield* auxiliary(entry.value, resources);
60260
60632
  const fonts = await dictionary(dictGet(resources, "Font"), "Font");
60261
60633
  if (fonts) for await (const entry of readPdfDictionaryEntries(fonts, options.signal)) {
60262
60634
  const font = await dictionary(entry.value);
@@ -60264,7 +60636,7 @@ async function* walkRetainedImages(document2, storage, options) {
60264
60636
  const subtype = (await document2.lookup(dictGet(font, "Subtype")))?.value;
60265
60637
  if (subtype?.kind !== "name" || subtype.decoded !== "Type3") continue;
60266
60638
  const procedures = await dictionary(dictGet(font, "CharProcs"));
60267
- const inherited = await dictionary(dictGet(font, "Resources")) ?? resources;
60639
+ const inherited = await dictionary(dictGet(font, "Resources"), "Resources") ?? resources;
60268
60640
  if (procedures) for (const entry2 of procedures.entries) yield* auxiliary(entry2.value, inherited);
60269
60641
  }
60270
60642
  const annotations = (await document2.lookup(dictGet(page2.dict, "Annots")))?.value;
@@ -60312,7 +60684,7 @@ async function* walkRetainedFonts(document2, storage, options) {
60312
60684
  if (!Number.isSafeInteger(first) || first < 1 || last !== Infinity && (!Number.isSafeInteger(last) || last < first)) throw new RangeError("Invalid PDF font page range");
60313
60685
  let failed = false;
60314
60686
  async function dictionary(node, resourceKey) {
60315
- const resolved = await document2.lookup(node, void 0, resourceKey ? [resourceKey] : void 0);
60687
+ const resolved = await document2.lookup(node, void 0, resourceKey ? resourceKey === "Resources" ? [resourceKey] : ["Resources", resourceKey] : void 0);
60316
60688
  return resolved?.value.kind === "dict" && !resolved.stream ? resolved.value : void 0;
60317
60689
  }
60318
60690
  async function* font(node, key, depth) {
@@ -60342,7 +60714,7 @@ async function* walkRetainedFonts(document2, storage, options) {
60342
60714
  const enc = (await document2.lookup(dictGet(value, "Encoding")))?.value;
60343
60715
  const encoding = enc?.kind === "name" ? enc.decoded === "WinAnsiEncoding" ? "WinAnsi" : enc.decoded === "MacRomanEncoding" ? "MacRoman" : enc.decoded === "StandardEncoding" ? "Standard" : enc.decoded : enc?.kind === "dict" ? "Custom" : "Builtin";
60344
60716
  yield { name, type, encoding, embedded, unicode: Boolean(dictGet(value, "ToUnicode")), ...node.kind === "ref" ? { reference: node } : {} };
60345
- if (raw === "Type3") yield* resources(await dictionary(dictGet(value, "Resources")), depth + 1);
60717
+ if (raw === "Type3") yield* resources(await dictionary(dictGet(value, "Resources"), "Resources"), depth + 1);
60346
60718
  }
60347
60719
  async function* resources(value, depth) {
60348
60720
  options.signal?.throwIfAborted();
@@ -60350,8 +60722,8 @@ async function* walkRetainedFonts(document2, storage, options) {
60350
60722
  if (depth > options.maxDepth) throw new PdfError("E_LIMIT", "PDF font resource depth limit exceeded");
60351
60723
  const fonts = await dictionary(dictGet(value, "Font"), "Font");
60352
60724
  if (fonts) for await (const entry of readPdfDictionaryEntries(fonts, options.signal)) yield* font(entry.value, entry.key.decoded, depth);
60353
- const states = await dictionary(dictGet(value, "ExtGState"));
60354
- if (states) for (const entry of states.entries) {
60725
+ const states = await dictionary(dictGet(value, "ExtGState"), "ExtGState");
60726
+ if (states) for await (const entry of readPdfDictionaryEntries(states, options.signal)) {
60355
60727
  const state = await dictionary(entry.value);
60356
60728
  const gsFont = state ? (await document2.lookup(dictGet(state, "Font")))?.value : void 0;
60357
60729
  if (gsFont?.kind === "array" && gsFont.items[0]) yield* font(gsFont.items[0], `ExtGS_${entry.key.decoded}`, depth);
@@ -60365,7 +60737,7 @@ async function* walkRetainedFonts(document2, storage, options) {
60365
60737
  if (!resolved?.stream || resolved.value.kind !== "dict") continue;
60366
60738
  const subtype = (await document2.lookup(dictGet(resolved.value, "Subtype")))?.value;
60367
60739
  if (key === "XObject" && !(subtype?.kind === "name" && subtype.decoded === "Form")) continue;
60368
- yield* resources(await dictionary(dictGet(resolved.value, "Resources")), depth + 1);
60740
+ yield* resources(await dictionary(dictGet(resolved.value, "Resources"), "Resources"), depth + 1);
60369
60741
  }
60370
60742
  }
60371
60743
  }
@@ -60383,10 +60755,10 @@ async function* walkRetainedFonts(document2, storage, options) {
60383
60755
  for (const key of ["N", "R", "D"]) {
60384
60756
  const ap = await document2.lookup(dictGet(appearance, key));
60385
60757
  if (ap?.value.kind !== "dict") continue;
60386
- if (ap.stream) yield* resources(await dictionary(dictGet(ap.value, "Resources")), 0);
60758
+ if (ap.stream) yield* resources(await dictionary(dictGet(ap.value, "Resources"), "Resources"), 0);
60387
60759
  else for (const entry of ap.value.entries) {
60388
60760
  const stream = await document2.lookup(entry.value);
60389
- if (stream?.stream && stream.value.kind === "dict") yield* resources(await dictionary(dictGet(stream.value, "Resources")), 0);
60761
+ if (stream?.stream && stream.value.kind === "dict") yield* resources(await dictionary(dictGet(stream.value, "Resources"), "Resources"), 0);
60390
60762
  }
60391
60763
  }
60392
60764
  }
@@ -60474,7 +60846,7 @@ async function* walkRetainedAttachments(document2, storage, options) {
60474
60846
  }
60475
60847
 
60476
60848
  // packages/pdf-ast/src/retained-document.ts
60477
- function limit8(value, name, fallback) {
60849
+ function limit9(value, name, fallback) {
60478
60850
  const result = value ?? fallback;
60479
60851
  if (result !== Infinity && (!Number.isSafeInteger(result) || result < 0)) throw new RangeError(`Invalid ${name}`);
60480
60852
  return result;
@@ -60503,9 +60875,9 @@ var PdfRetainedDocument = class _PdfRetainedDocument {
60503
60875
  walks = /* @__PURE__ */ new Set();
60504
60876
  closing;
60505
60877
  static async open(source, storage, options = {}) {
60506
- const maxPages = limit8(options.maxPages, "maxPages", Infinity);
60507
- const maxPageTreeDepth = limit8(options.maxPageTreeDepth, "maxPageTreeDepth", 100);
60508
- const maxTraversalStagingBytes = limit8(options.maxTraversalStagingBytes, "maxTraversalStagingBytes", Infinity);
60878
+ const maxPages = limit9(options.maxPages, "maxPages", Infinity);
60879
+ const maxPageTreeDepth = limit9(options.maxPageTreeDepth, "maxPageTreeDepth", 100);
60880
+ const maxTraversalStagingBytes = limit9(options.maxTraversalStagingBytes, "maxTraversalStagingBytes", Infinity);
60509
60881
  const controller = new AbortController();
60510
60882
  const signal = options.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal;
60511
60883
  const configured = { ...options, signal, maxPages, maxPageTreeDepth, maxTraversalStagingBytes };
@@ -60515,9 +60887,9 @@ var PdfRetainedDocument = class _PdfRetainedDocument {
60515
60887
  /** Read an editable caller-backed graph without normalizing it through a PDF
60516
60888
  * save. The caller retains ownership of the store and its object identities. */
60517
60889
  static async openStore(store, storage, options) {
60518
- const maxPages = limit8(options.maxPages, "maxPages", Infinity);
60519
- const maxPageTreeDepth = limit8(options.maxPageTreeDepth, "maxPageTreeDepth", 100);
60520
- const maxTraversalStagingBytes = limit8(options.maxTraversalStagingBytes, "maxTraversalStagingBytes", Infinity);
60890
+ const maxPages = limit9(options.maxPages, "maxPages", Infinity);
60891
+ const maxPageTreeDepth = limit9(options.maxPageTreeDepth, "maxPageTreeDepth", 100);
60892
+ const maxTraversalStagingBytes = limit9(options.maxTraversalStagingBytes, "maxTraversalStagingBytes", Infinity);
60521
60893
  const controller = new AbortController();
60522
60894
  const signal = options.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal;
60523
60895
  const configured = { ...options, signal, maxPages, maxPageTreeDepth, maxTraversalStagingBytes };
@@ -60529,8 +60901,10 @@ var PdfRetainedDocument = class _PdfRetainedDocument {
60529
60901
  this.options.signal?.throwIfAborted();
60530
60902
  }
60531
60903
  /** Resolve a bounded reference chain, retaining the final stream's identity. */
60532
- async lookup(node, arrays = this.options.valueArrays ?? {}, arrayPathPrefix) {
60904
+ async lookup(node, arrays = this.options.valueArrays ?? {}, arrayPathPrefix, storeRootDictionary = false, rootArrayStorage) {
60533
60905
  this.assertOpen();
60906
+ if (rootArrayStorage) arrays = { ...arrays, arrayStorage: arrays.arrayStorage ?? rootArrayStorage, storeRootArray: true };
60907
+ if (storeRootDictionary && arrays.dictionaryStorage) arrays = { ...arrays, storeRootDictionary: true };
60534
60908
  if (arrayPathPrefix) arrays = {
60535
60909
  ...arrays,
60536
60910
  arrayPathPrefix,
@@ -61106,7 +61480,7 @@ var PdfRetainedPage = class {
61106
61480
  for (const key of keys) {
61107
61481
  const entry = dictGet(current, key);
61108
61482
  if (values.has(key) || !entry) continue;
61109
- const value = (await this.document.lookup(entry))?.value;
61483
+ const value = (await this.document.lookup(entry, void 0, key === "Resources" ? ["Resources"] : void 0))?.value;
61110
61484
  if (key.endsWith("Box")) {
61111
61485
  const rectangle = await box(value, this.document);
61112
61486
  if (!rectangle) continue;
@@ -61323,6 +61697,82 @@ async function* encodeRetainedPng(width, height, input, storage, options = {}) {
61323
61697
  }
61324
61698
  }
61325
61699
 
61700
+ // packages/pdf-ast/src/render/svg-image-stream.ts
61701
+ async function* encodeSvgImageChunks(image, pageHeight, storage, options = {}) {
61702
+ const { signal } = options;
61703
+ signal?.throwIfAborted();
61704
+ if (!image.decodedRgba && !image.storedRgba) return;
61705
+ const { width, height } = image, chunkBytes = options.chunkBytes ?? 65536, maximum10 = options.maxOutputBytes ?? Infinity;
61706
+ if (![width, height].every((value) => Number.isSafeInteger(value) && value > 0 && value <= 4294967295) || !Number.isSafeInteger(width * height * 4)) throw new PdfError("E_LIMIT", "SVG image dimension limit exceeded");
61707
+ if (!Number.isSafeInteger(chunkBytes) || chunkBytes < 1) throw new RangeError("Invalid SVG image chunk size");
61708
+ if (maximum10 !== Infinity && (!Number.isSafeInteger(maximum10) || maximum10 < 0)) throw new RangeError("Invalid SVG output byte limit");
61709
+ const [a, b, c, d, e, f] = image.matrix;
61710
+ const prefix = `<image width="1" height="1" preserveAspectRatio="none" transform="matrix(${a} ${-b} ${-c} ${d} ${e + c} ${pageHeight - f - d})" href="data:image/png;base64,`, suffix = '"/>';
61711
+ const encoder = new TextEncoder(), header2 = encoder.encode(prefix), tail = encoder.encode(suffix), available = maximum10 - header2.length - tail.length;
61712
+ const pngMaximum = maximum10 === Infinity ? Infinity : Math.floor(available / 4) * 3;
61713
+ if (pngMaximum < 57) throw new PdfError("E_LIMIT", "SVG image output byte limit exceeded");
61714
+ let outputBytes = 0;
61715
+ function* emit(bytes) {
61716
+ if (bytes.length > maximum10 - outputBytes) throw new PdfError("E_LIMIT", "SVG image output byte limit exceeded");
61717
+ outputBytes += bytes.length;
61718
+ for (let at = 0; at < bytes.length; at += chunkBytes) {
61719
+ signal?.throwIfAborted();
61720
+ yield bytes.slice(at, at + chunkBytes);
61721
+ }
61722
+ }
61723
+ async function* pixels() {
61724
+ if (image.decodedRgba) {
61725
+ for (let at = 0; at < image.decodedRgba.length; at += chunkBytes) {
61726
+ signal?.throwIfAborted();
61727
+ yield image.decodedRgba.subarray(at, at + chunkBytes);
61728
+ }
61729
+ return;
61730
+ }
61731
+ const source = image.storedRgba;
61732
+ for (let at = 0; at < width * height * 4; ) {
61733
+ signal?.throwIfAborted();
61734
+ const count = Math.min(chunkBytes, width * height * 4 - at), bytes = await source.storage.read(source.position + at, count, signal ? { signal } : void 0);
61735
+ if (bytes.length > count) throw new Error("Oversized SVG pixel read");
61736
+ if (!bytes.length) return;
61737
+ yield bytes;
61738
+ at += bytes.length;
61739
+ }
61740
+ }
61741
+ yield* emit(header2);
61742
+ const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
61743
+ const buffer = new Uint8Array(Math.min(8192, Math.max(4, chunkBytes))), triple = new Uint8Array(3);
61744
+ let used = 0, pending = 0, work = 0;
61745
+ function group(count) {
61746
+ const n = triple[0] << 16 | triple[1] << 8 | triple[2];
61747
+ buffer[used++] = alphabet.charCodeAt(n >>> 18);
61748
+ buffer[used++] = alphabet.charCodeAt(n >>> 12 & 63);
61749
+ buffer[used++] = count > 1 ? alphabet.charCodeAt(n >>> 6 & 63) : 61;
61750
+ buffer[used++] = count > 2 ? alphabet.charCodeAt(n & 63) : 61;
61751
+ triple.fill(0);
61752
+ pending = 0;
61753
+ }
61754
+ const capacity = buffer.length - buffer.length % 4;
61755
+ for await (const bytes of encodeRetainedPng(width, height, pixels(), storage, { ...options, alpha: "rgba", maxOutputBytes: pngMaximum })) {
61756
+ for (const byte3 of bytes) {
61757
+ triple[pending++] = byte3;
61758
+ if (pending === 3) {
61759
+ group(3);
61760
+ if (used === capacity) {
61761
+ yield* emit(buffer.subarray(0, used));
61762
+ used = 0;
61763
+ }
61764
+ if (++work % 4096 === 0) {
61765
+ await new Promise((resolve2) => setTimeout(resolve2, 0));
61766
+ signal?.throwIfAborted();
61767
+ }
61768
+ }
61769
+ }
61770
+ }
61771
+ if (pending) group(pending);
61772
+ if (used) yield* emit(buffer.subarray(0, used));
61773
+ yield* emit(tail);
61774
+ }
61775
+
61326
61776
  // packages/pdf-ast/src/render/retained-tiff.ts
61327
61777
  function maximum9(value) {
61328
61778
  if (value === void 0 || value === Infinity) return Number.MAX_SAFE_INTEGER;
@@ -61897,6 +62347,12 @@ async function createRetainedPageCopy(input, indicesOrStorage, storageOrOptions,
61897
62347
  const value = await box(key);
61898
62348
  if (value[0] !== 0 || value[1] !== 0 || value[2] !== width || value[3] !== height) dictSet(page2, key, cosArray(value.map((value2) => cosNumber(value2))));
61899
62349
  }
62350
+ dictSet(page2, "Parent", cosRef(2));
62351
+ const boxes = options.pageBoxes?.({ width, height }, selection.index);
62352
+ for (const [key, value] of [["MediaBox", boxes?.mediaBox], ["CropBox", boxes?.cropBox]]) if (value) {
62353
+ if (value.length !== 4 || !value.every(Number.isFinite)) throw new RangeError("Invalid copied page box");
62354
+ dictSet(page2, key, cosArray(value.map((coordinate) => cosNumber(coordinate))));
62355
+ }
61900
62356
  await store.set({ objectNumber: pageRef.objectNumber, generationNumber: 0, value: page2 });
61901
62357
  }
61902
62358
  const sourceCatalog = await sourceValue(document2.crossReference.rootRef), acro = sourceCatalog?.kind === "dict" ? await sourceValue(dictGet(sourceCatalog, "AcroForm")) : void 0;
@@ -61932,14 +62388,14 @@ async function createRetainedPageCopy(input, indicesOrStorage, storageOrOptions,
61932
62388
  if (fields2?.kind === "array" && acro?.kind === "dict") {
61933
62389
  let addedFields = false;
61934
62390
  const rootNumbers = new IntegerTable6(backing, 64);
61935
- for (const field2 of fields2.items) {
61936
- if (!await hasCloned(field2)) continue;
61937
- const cloned = await clone(field2);
62391
+ for (const field3 of fields2.items) {
62392
+ if (!await hasCloned(field3)) continue;
62393
+ const cloned = await clone(field3);
61938
62394
  if (cloned.kind !== "ref") continue;
61939
- const dict = await targetDict(cloned), source = await sourceValue(field2), sourceKids = source?.kind === "dict" ? await sourceValue(dictGet(source, "Kids")) : void 0;
62395
+ const dict = await targetDict(cloned), source = await sourceValue(field3), sourceKids = source?.kind === "dict" ? await sourceValue(dictGet(source, "Kids")) : void 0;
61940
62396
  let kids = dict && dictGet(dict, "Kids");
61941
62397
  if (kids?.kind === "ref") kids = (await store.get(kids.objectNumber))?.value;
61942
- if (dict && kids?.kind === "array" && field2.kind === "ref" && sourceKids?.kind === "array" && sourceKids.items.length === kids.items.length) {
62398
+ if (dict && kids?.kind === "array" && field3.kind === "ref" && sourceKids?.kind === "array" && sourceKids.items.length === kids.items.length) {
61943
62399
  const filtered = [];
61944
62400
  for (let i = 0; i < kids.items.length; i++) if (await hasCloned(sourceKids.items[i])) filtered.push(kids.items[i]);
61945
62401
  if (filtered.length) {
@@ -61986,12 +62442,12 @@ async function createRetainedPageCopy(input, indicesOrStorage, storageOrOptions,
61986
62442
  }
61987
62443
  }
61988
62444
  const encoder = new TextEncoder();
61989
- async function* dictionary(dict, field2, values) {
62445
+ async function* dictionary(dict, field3, values) {
61990
62446
  yield encoder.encode("<<\n");
61991
62447
  for (const entry of dict.entries) {
61992
62448
  yield* serializeCosNodeChunks(entry.key, { chunkBytes: options.chunkBytes ?? 16384, maxRecursionDepth: maximumDepth, signal }, 1);
61993
62449
  yield encoder.encode(" ");
61994
- if (entry.key.decoded === field2) {
62450
+ if (entry.key.decoded === field3) {
61995
62451
  if (values.count && maximumDepth < 2) throw new PdfError("E_LIMIT", "PDF page copy depth limit exceeded");
61996
62452
  yield encoder.encode("[ ");
61997
62453
  for await (const reference of references(values)) yield encoder.encode(`${reference.objectNumber} 0 R `);
@@ -62019,10 +62475,10 @@ async function createRetainedPageCopy(input, indicesOrStorage, storageOrOptions,
62019
62475
  const pageTree = cosDict({ Type: cosName("Pages"), Count: cosNumber(pageCount), Kids: cosArray([]) });
62020
62476
  if (pageLabels) await store.setSerializedValue(pageLabels);
62021
62477
  if (attachmentNames) await store.setSerializedValue(attachmentNames);
62022
- async function saveList(number, dict, field2, values) {
62478
+ async function saveList(number, dict, field3, values) {
62023
62479
  let length = 0;
62024
- for await (const bytes of dictionary(dict, field2, values)) length += bytes.length;
62025
- await store.setSerializedValue({ objectNumber: number, generationNumber: 0, body: { length, chunks: dictionary(dict, field2, values) } });
62480
+ for await (const bytes of dictionary(dict, field3, values)) length += bytes.length;
62481
+ await store.setSerializedValue({ objectNumber: number, generationNumber: 0, body: { length, chunks: dictionary(dict, field3, values) } });
62026
62482
  }
62027
62483
  await saveList(2, pageTree, "Kids", pages);
62028
62484
  if (formRef) await saveList(formRef.objectNumber, (await store.get(formRef.objectNumber)).value, "Fields", formFields);
@@ -62059,13 +62515,13 @@ async function* copyRetainedPagesChunks(input, indicesOrStorage, storageOrOption
62059
62515
  }
62060
62516
 
62061
62517
  // packages/pdf-ast/src/cos/retained-objects.ts
62062
- function limit9(value) {
62518
+ function limit10(value) {
62063
62519
  if (value === void 0 || value === Infinity) return Number.MAX_SAFE_INTEGER;
62064
62520
  if (!Number.isSafeInteger(value) || value < 0) throw new RangeError("Invalid retained object limit");
62065
62521
  return value;
62066
62522
  }
62067
62523
  async function* retainedCosObjects(document2, storage, options = {}) {
62068
- const maxObjects = limit9(options.maxObjects), maxStreamBytes = limit9(options.maxStreamBytes), signal = options.signal;
62524
+ const maxObjects = limit10(options.maxObjects), maxStreamBytes = limit10(options.maxStreamBytes), signal = options.signal;
62069
62525
  let count = 0;
62070
62526
  for await (const entry of document2.crossReference.index.entries(signal)) {
62071
62527
  signal?.throwIfAborted();
@@ -62431,16 +62887,329 @@ async function* saveRetainedDocumentChunks(document2, storage, options = {}) {
62431
62887
  }
62432
62888
  }
62433
62889
 
62890
+ // packages/pdf-ast/src/edit/retained-flatten-forms.ts
62891
+ import { IntegerTable as IntegerTable8, PagedStorage as PagedStorage13 } from "@poe-platform/safe-fs/storage";
62892
+ async function flattenRetainedForms(document2, store, storage, signal) {
62893
+ if (!document2.crossReference.rootRef) return;
62894
+ const backing = new PagedStorage13({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), names = new PdfNameIndex(storage, Infinity, signal), baked = new IntegerTable8(backing), active = new IntegerTable8(backing), fields2 = new IntegerTable8(backing), pagesSeen = new IntegerTable8(backing), walkMarks = new IntegerTable8(backing);
62895
+ let head = -1, fieldCount = 0, work = 0, walk = 0, failed = false;
62896
+ async function checkpoint(depth = 0) {
62897
+ signal.throwIfAborted();
62898
+ if (depth > document2.depthLimit) throw new PdfError("E_LIMIT", "PDF form field depth limit exceeded");
62899
+ if (++work % 64 === 0) {
62900
+ await new Promise((resolve3) => setTimeout(resolve3, 0));
62901
+ signal.throwIfAborted();
62902
+ }
62903
+ }
62904
+ const child = (location, key) => ({ reference: location.reference, path: [...location.path, key] });
62905
+ async function locate(location) {
62906
+ let owner = await store.get(location.reference.objectNumber);
62907
+ if (!owner || owner.generationNumber !== location.reference.generationNumber || owner.stream) return;
62908
+ let value = owner.value, path = [], reference = location.reference, refs = 0;
62909
+ for (let i = 0; i <= location.path.length; i++) {
62910
+ while (value?.kind === "ref") {
62911
+ await checkpoint(++refs);
62912
+ reference = value;
62913
+ owner = await store.get(value.objectNumber);
62914
+ if (!owner || owner.generationNumber !== reference.generationNumber || owner.stream) return;
62915
+ value = owner.value;
62916
+ path = [];
62917
+ }
62918
+ if (!value) return;
62919
+ if (i === location.path.length) return { value, owner, location: { reference, path } };
62920
+ const key = location.path[i];
62921
+ path.push(key);
62922
+ value = typeof key === "number" ? value.kind === "array" ? value.items[key] : void 0 : value.kind === "dict" ? dictGet(value, key) : void 0;
62923
+ }
62924
+ }
62925
+ async function identity(location) {
62926
+ return (await names.intern(`${location.reference.objectNumber}:${location.reference.generationNumber}:${JSON.stringify(location.path)}`)).index;
62927
+ }
62928
+ async function resolve2(node) {
62929
+ const found = await document2.lookup(node);
62930
+ return found?.stream ? void 0 : found?.value;
62931
+ }
62932
+ async function number(node, fallback) {
62933
+ const value = await resolve2(node);
62934
+ return value?.kind === "number" ? value.value : fallback;
62935
+ }
62936
+ async function push(frame) {
62937
+ head = await appendStoredRecord(backing, { frame, previous: head }, -1, signal);
62938
+ }
62939
+ async function set(location, key, value) {
62940
+ const found = await locate(location);
62941
+ if (found?.value.kind === "dict") {
62942
+ dictSet(found.value, key, value);
62943
+ await store.set(found.owner);
62944
+ }
62945
+ }
62946
+ async function stream(dict, chunks) {
62947
+ const source = await PdfFileSource.fromStream(storage.fs, storage.directory, chunks, { signal });
62948
+ let failed2 = false;
62949
+ try {
62950
+ dictSet(dict, "Length", cosNumber(source.size));
62951
+ const ref = await store.allocate();
62952
+ await store.set({ objectNumber: ref.objectNumber, generationNumber: 0, value: dict, stream: { length: source.size, chunks: source.stream(0, source.size, signal), decoded: true } });
62953
+ return ref;
62954
+ } catch (error) {
62955
+ failed2 = true;
62956
+ throw error;
62957
+ } finally {
62958
+ await source.close().catch((error) => {
62959
+ if (!failed2) throw error;
62960
+ });
62961
+ }
62962
+ }
62963
+ async function append(page2, ref) {
62964
+ const found = await locate(page2);
62965
+ if (found?.value.kind !== "dict") return;
62966
+ const existing = dictGet(found.value, "Contents");
62967
+ if (!existing) {
62968
+ dictSet(found.value, "Contents", ref);
62969
+ await store.set(found.owner);
62970
+ return;
62971
+ }
62972
+ const contents = await locate(child(page2, "Contents"));
62973
+ if (contents?.value.kind === "array") {
62974
+ contents.value.items.push(ref);
62975
+ await store.set(contents.owner);
62976
+ } else {
62977
+ dictSet(found.value, "Contents", cosArray([existing, ref]));
62978
+ await store.set(found.owner);
62979
+ }
62980
+ }
62981
+ async function inheritedResources(page2) {
62982
+ const mark = BigInt(++walk);
62983
+ let location = page2;
62984
+ while (location) {
62985
+ await checkpoint();
62986
+ const found = await locate(location);
62987
+ if (found?.value.kind !== "dict") return;
62988
+ const key = BigInt(await identity(found.location));
62989
+ if (await walkMarks.get(key) === mark) return;
62990
+ await walkMarks.set(key, mark);
62991
+ const node = dictGet(found.value, "Resources");
62992
+ if (node !== void 0) {
62993
+ const value = await resolve2(node);
62994
+ return value?.kind === "dict" ? value : void 0;
62995
+ }
62996
+ location = child(found.location, "Parent");
62997
+ }
62998
+ }
62999
+ const encoder = new TextEncoder();
63000
+ function* textChunks(text, x, y, font) {
63001
+ yield encoder.encode(`
63002
+ q BT /${font} 11 Tf `);
63003
+ const normalized = text.replaceAll("\r\n", "\n");
63004
+ let offset = 0, line = 0;
63005
+ while (offset <= normalized.length) {
63006
+ signal.throwIfAborted();
63007
+ const end = normalized.indexOf("\n", offset), part = normalized.slice(offset, end < 0 ? normalized.length : end);
63008
+ yield encoder.encode(line++ ? " 0 -13 Td (" : `${Math.round(x)} ${Math.round(y)} Td (`);
63009
+ let escaped = "";
63010
+ for (const char of part) {
63011
+ escaped += (char === "(" || char === ")" || char === "\\" ? "\\" : "") + char;
63012
+ if (escaped.length >= 2048) {
63013
+ yield encoder.encode(escaped);
63014
+ escaped = "";
63015
+ }
63016
+ }
63017
+ if (escaped) yield encoder.encode(escaped);
63018
+ yield encoder.encode(") Tj");
63019
+ if (end < 0) break;
63020
+ offset = end + 1;
63021
+ }
63022
+ yield encoder.encode(" ET Q\n");
63023
+ }
63024
+ async function draw(page2, text, x, y) {
63025
+ if (!text) return;
63026
+ let resources = await locate(child(page2, "Resources"));
63027
+ if (resources?.value.kind !== "dict") {
63028
+ await set(page2, "Resources", cosDict({}));
63029
+ resources = await locate(child(page2, "Resources"));
63030
+ }
63031
+ const resourceLocation = resources.location;
63032
+ let fonts = await locate(child(resourceLocation, "Font"));
63033
+ if (fonts?.value.kind !== "dict") {
63034
+ await set(resourceLocation, "Font", cosDict({}));
63035
+ fonts = await locate(child(resourceLocation, "Font"));
63036
+ }
63037
+ const font = fonts.value, key = dictGet(font, "F1") ? "F_AcroFlat" : "F1";
63038
+ if (!dictGet(font, key)) {
63039
+ dictSet(font, key, await store.allocate(cosDict({ Type: cosName("Font"), Subtype: cosName("Type1"), BaseFont: cosName("Helvetica") })));
63040
+ await store.set(fonts.owner);
63041
+ }
63042
+ await append(page2, await stream(cosDict({}), textChunks(text, x, y, key)));
63043
+ }
63044
+ async function textValue(node, arrays) {
63045
+ if (node?.kind === "string") return decodePdfString(node);
63046
+ if (node?.kind === "name" && node.decoded !== "Off") return node.decoded;
63047
+ if (node?.kind === "boolean" && node.value) return "Yes";
63048
+ if (arrays && node?.kind === "array") {
63049
+ let text = "", count = 0;
63050
+ for (const item of node.items) {
63051
+ await checkpoint();
63052
+ const value = await resolve2(item);
63053
+ if (value?.kind === "string" || value?.kind === "name") text += (count++ ? ", " : "") + (value.kind === "string" ? decodePdfString(value) : value.decoded);
63054
+ }
63055
+ return text;
63056
+ }
63057
+ return "";
63058
+ }
63059
+ const root = { reference: document2.crossReference.rootRef, path: [] }, form = child(root, "AcroForm");
63060
+ try {
63061
+ const fieldArray = await locate(child(form, "Fields"));
63062
+ if (fieldArray?.value.kind === "array") for (let i = fieldArray.value.items.length - 1; i >= 0; i--) {
63063
+ await checkpoint();
63064
+ await push({ location: child(fieldArray.location, i), named: false, ft: "", depth: 0 });
63065
+ }
63066
+ while (head !== -1) {
63067
+ const record = (await readStoredRecord(backing, head, signal)).value;
63068
+ head = record.previous;
63069
+ const frame = record.frame;
63070
+ if ("exit" in frame) {
63071
+ await active.set(BigInt(frame.exit), 0n);
63072
+ continue;
63073
+ }
63074
+ await checkpoint(frame.depth);
63075
+ const found = await locate(frame.location);
63076
+ if (found?.value.kind !== "dict") continue;
63077
+ const id = await identity(found.location);
63078
+ if (await active.get(BigInt(id))) continue;
63079
+ await active.set(BigInt(id), 1n);
63080
+ await push({ exit: id });
63081
+ const name = await resolve2(dictGet(found.value, "T")), type = await resolve2(dictGet(found.value, "FT")), named = frame.named || (name?.kind === "string" ? !!decodePdfString(name) : name?.kind === "name" ? !!name.decoded : false), ft = type?.kind === "name" ? type.decoded : frame.ft;
63082
+ const kids = await locate(child(found.location, "Kids"));
63083
+ let descend = false;
63084
+ if (kids?.value.kind === "array" && kids.value.items.length) {
63085
+ let namedKids = false;
63086
+ for (let i = 0; i < kids.value.items.length; i++) {
63087
+ await checkpoint();
63088
+ const kid = await locate(child(kids.location, i));
63089
+ if (kid?.value.kind === "dict" && dictGet(kid.value, "T")) {
63090
+ namedKids = true;
63091
+ break;
63092
+ }
63093
+ }
63094
+ descend = namedKids || !ft || !named;
63095
+ if (descend) for (let i = kids.value.items.length - 1; i >= 0; i--) {
63096
+ await checkpoint();
63097
+ await push({ location: child(kids.location, i), named, ft, depth: frame.depth + 1 });
63098
+ }
63099
+ }
63100
+ if (!descend && named) {
63101
+ const at = await appendStoredRecord(backing, found.location, -1, signal);
63102
+ await fields2.set(BigInt(fieldCount++), BigInt(at));
63103
+ }
63104
+ }
63105
+ let firstPage;
63106
+ for await (const page2 of document2.pages()) {
63107
+ await checkpoint();
63108
+ if (!page2.reference) throw new PdfError("E_PARSE", "Expected retained form page reference");
63109
+ const pageLocation = { reference: page2.reference, path: [] };
63110
+ if (!firstPage) firstPage = pageLocation;
63111
+ if (await pagesSeen.get(BigInt(page2.reference.objectNumber))) continue;
63112
+ await pagesSeen.set(BigInt(page2.reference.objectNumber), 1n);
63113
+ const annotations = await locate(child(pageLocation, "Annots"));
63114
+ if (annotations?.value.kind !== "array") continue;
63115
+ const survivors = [];
63116
+ for (let i = 0; i < annotations.value.items.length; i++) {
63117
+ await checkpoint();
63118
+ const annotation = await locate(child(annotations.location, i));
63119
+ if (annotation?.value.kind !== "dict") {
63120
+ survivors.push(annotations.value.items[i]);
63121
+ continue;
63122
+ }
63123
+ const subtype = await resolve2(dictGet(annotation.value, "Subtype"));
63124
+ if (!(subtype?.kind === "name" && subtype.decoded === "Widget") && !dictGet(annotation.value, "FT") && !dictGet(annotation.value, "T")) {
63125
+ survivors.push(annotations.value.items[i]);
63126
+ continue;
63127
+ }
63128
+ await baked.set(BigInt(await identity(annotation.location)), 1n);
63129
+ const parent = await locate(child(annotation.location, "Parent"));
63130
+ if (parent?.value.kind === "dict") await baked.set(BigInt(await identity(parent.location)), 1n);
63131
+ const rect = await resolve2(dictGet(annotation.value, "Rect")), items = rect?.kind === "array" ? rect.items : [];
63132
+ const x = await number(items[0], 50), y = await number(items[1], 700), ownState = await resolve2(dictGet(annotation.value, "AS"));
63133
+ const value = ownState ?? await resolve2(dictGet(annotation.value, "V") ?? (parent?.value.kind === "dict" ? dictGet(parent.value, "V") ?? dictGet(parent.value, "AS") : void 0));
63134
+ const appearance = await locate(child(annotation.location, "AP"));
63135
+ let normal = appearance?.value.kind === "dict" ? await document2.lookup(dictGet(appearance.value, "N")) : void 0;
63136
+ if (normal?.value.kind === "dict" && !normal.stream && value?.kind === "name" && value.decoded !== "Off") normal = await document2.lookup(dictGet(normal.value, value.decoded));
63137
+ if (normal?.stream && normal.reference && normal.value.kind === "dict") {
63138
+ const inherited = await inheritedResources(pageLocation), resources = { kind: "dict", entries: [...inherited?.entries ?? []] };
63139
+ const old = await resolve2(dictGet(resources, "XObject")), objects = { kind: "dict", entries: [...old?.kind === "dict" ? old.entries : []] };
63140
+ let suffix = 1;
63141
+ while (dictGet(objects, `AcroAppearance${suffix}`)) {
63142
+ await checkpoint();
63143
+ suffix++;
63144
+ }
63145
+ const name = `AcroAppearance${suffix}`, dict = { kind: "dict", entries: [...normal.value.entries] };
63146
+ dictSet(dict, "Type", cosName("XObject"));
63147
+ dictSet(dict, "Subtype", cosName("Form"));
63148
+ const original = await store.get(normal.reference.objectNumber), ref = await store.allocate();
63149
+ if (!original?.stream) throw new PdfError("E_PARSE", "Missing retained appearance stream");
63150
+ await store.set({ ...original, objectNumber: ref.objectNumber, generationNumber: 0, value: dict });
63151
+ dictSet(objects, name, ref);
63152
+ dictSet(resources, "XObject", objects);
63153
+ await set(pageLocation, "Resources", resources);
63154
+ const r2 = await resolve2(items[2]), r3 = await resolve2(items[3]), width = r2?.kind === "number" ? Math.max(1, Math.abs(r2.value - x)) : 20, height = r3?.kind === "number" ? Math.max(1, Math.abs(r3.value - y)) : 20;
63155
+ const bbox = await resolve2(dictGet(dict, "BBox"));
63156
+ let bx0 = 0, by0 = 0, bx1 = width, by1 = height;
63157
+ if (bbox?.kind === "array" && bbox.items.length >= 4) {
63158
+ const b = await Promise.all(bbox.items.slice(0, 4).map(resolve2));
63159
+ if (b.every((v) => v?.kind === "number")) {
63160
+ const n = b;
63161
+ bx0 = Math.min(n[0].value, n[2].value);
63162
+ by0 = Math.min(n[1].value, n[3].value);
63163
+ bx1 = Math.max(n[0].value, n[2].value);
63164
+ by1 = Math.max(n[1].value, n[3].value);
63165
+ }
63166
+ }
63167
+ const matrix2 = await resolve2(dictGet(dict, "Matrix")), values = matrix2?.kind === "array" && matrix2.items.length >= 6 ? await Promise.all(matrix2.items.slice(0, 6).map((v) => number(v, 0))) : [1, 0, 0, 1, 0, 0];
63168
+ const [ma, mb, mc, md, me, mf] = values, corners = [[bx0 * ma + by0 * mc + me, bx0 * mb + by0 * md + mf], [bx1 * ma + by0 * mc + me, bx1 * mb + by0 * md + mf], [bx0 * ma + by1 * mc + me, bx0 * mb + by1 * md + mf], [bx1 * ma + by1 * mc + me, bx1 * mb + by1 * md + mf]];
63169
+ const minX = Math.min(...corners.map((c) => c[0])), minY = Math.min(...corners.map((c) => c[1])), bw = Math.max(1, Math.max(...corners.map((c) => c[0])) - minX), bh = Math.max(1, Math.max(...corners.map((c) => c[1])) - minY);
63170
+ const sx = Number((width / bw).toFixed(6)), sy = Number((height / bh).toFixed(6)), tx = Number((x - minX * sx).toFixed(6)), ty = Number((y - minY * sy).toFixed(6));
63171
+ await append(pageLocation, await stream(cosDict({}), [encoder.encode(`
63172
+ q ${sx} 0 0 ${sy} ${tx} ${ty} cm /${name} Do Q
63173
+ `)]));
63174
+ } else await draw(pageLocation, await textValue(value, true), x + 2, y + 4);
63175
+ }
63176
+ await set(pageLocation, "Annots", cosArray(survivors));
63177
+ }
63178
+ if (!firstPage) return;
63179
+ for (let i = 0; i < fieldCount; i++) {
63180
+ await checkpoint();
63181
+ const location = (await readStoredRecord(backing, Number(await fields2.get(BigInt(i))), signal)).value, field3 = await locate(location);
63182
+ if (field3?.value.kind !== "dict" || await baked.get(BigInt(await identity(field3.location)))) continue;
63183
+ const rect = await resolve2(dictGet(field3.value, "Rect")), items = rect?.kind === "array" ? rect.items : [], x = await number(items[0], 50), y = await number(items[1], 700), value = await resolve2(dictGet(field3.value, "V") ?? dictGet(field3.value, "AS"));
63184
+ await draw(firstPage, await textValue(value, false), x + 2, y + 4);
63185
+ }
63186
+ const latest = await locate(form);
63187
+ if (latest?.value.kind === "dict") {
63188
+ dictSet(latest.value, "Fields", cosArray([]));
63189
+ dictSet(latest.value, "NeedAppearances", cosBool(false));
63190
+ await store.set(latest.owner);
63191
+ }
63192
+ } catch (error) {
63193
+ failed = true;
63194
+ throw error;
63195
+ } finally {
63196
+ const results = await Promise.allSettled([backing.close(), names.close()]);
63197
+ if (!failed) {
63198
+ for (const result of results) if (result.status === "rejected") await Promise.reject(result.reason);
63199
+ }
63200
+ }
63201
+ }
63202
+
62434
63203
  // packages/pdf-ast/src/edit/retained-info-updates.ts
62435
- import { PagedStorage as PagedStorage14 } from "@poe-platform/safe-fs/storage";
63204
+ import { PagedStorage as PagedStorage15 } from "@poe-platform/safe-fs/storage";
62436
63205
 
62437
63206
  // packages/pdf-ast/src/edit/retained-bookmarks.ts
62438
- import { PagedStorage as PagedStorage13 } from "@poe-platform/safe-fs/storage";
63207
+ import { PagedStorage as PagedStorage14 } from "@poe-platform/safe-fs/storage";
62439
63208
  async function setRetainedBookmarks(store, storage, root, pageCount, pageReference, bookmarks, signal, maxDepth = Infinity) {
62440
63209
  if (!pageCount) return;
62441
63210
  const catalog = await store.get(root.objectNumber);
62442
63211
  if (catalog?.value.kind !== "dict") return;
62443
- const frames = new PagedStorage13({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
63212
+ const frames = new PagedStorage14({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
62444
63213
  const base = frames.allocate(0);
62445
63214
  let depth = 0, capacity = 0, failed = false, work = 0;
62446
63215
  async function write(index2, frame) {
@@ -62513,7 +63282,7 @@ async function setRetainedBookmarks(store, storage, root, pageCount, pageReferen
62513
63282
 
62514
63283
  // packages/pdf-ast/src/edit/retained-info-updates.ts
62515
63284
  async function applyRetainedInfoUpdates(document2, store, storage, count, getPage, updates, signal, maxDepth) {
62516
- const pages = new PagedStorage14({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
63285
+ const pages = new PagedStorage15({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
62517
63286
  const base = pages.allocate(count * 4 * 48), heads = [-1, -1, -1, -1], tails = [-1, -1, -1, -1];
62518
63287
  const labels = new PdfMutableObjectStore(storage, { signal }), bookmarks = new PdfMutableObjectStore(storage, { signal });
62519
63288
  let infoRef = document2.crossReference.infoRef, idArray = document2.crossReference.idArray, labelCount = 0, work = 0, failed = false;
@@ -62755,7 +63524,7 @@ async function appendRetainedAttachments(document2, target, storage, attachments
62755
63524
  }
62756
63525
 
62757
63526
  // packages/pdf-ast/src/edit/retained-form-appearances.ts
62758
- import { IntegerTable as IntegerTable8, PagedStorage as PagedStorage15 } from "@poe-platform/safe-fs/storage";
63527
+ import { IntegerTable as IntegerTable9, PagedStorage as PagedStorage16 } from "@poe-platform/safe-fs/storage";
62759
63528
 
62760
63529
  // packages/pdf-ast/src/edit/form-appearance-chunks.ts
62761
63530
  function* serializeFormAppearanceChunks(text, options) {
@@ -62843,7 +63612,7 @@ function* operators(text, options) {
62843
63612
  // packages/pdf-ast/src/edit/retained-form-appearances.ts
62844
63613
  async function generateRetainedFormAppearances(document2, store, storage, signal, update) {
62845
63614
  if (!document2.crossReference.rootRef) return;
62846
- const backing = new PagedStorage15({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), active = new IntegerTable8(backing);
63615
+ const backing = new PagedStorage16({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), active = new IntegerTable9(backing);
62847
63616
  let head = -1, failed = false, work = 0;
62848
63617
  let matched = false;
62849
63618
  let defaultAppearance;
@@ -62982,21 +63751,21 @@ async function generateRetainedFormAppearances(document2, store, storage, signal
62982
63751
  continue;
62983
63752
  }
62984
63753
  await checkpoint(frame.depth);
62985
- const field2 = await locate(frame.location);
62986
- if (field2?.value.kind !== "dict") continue;
62987
- if (!field2.location.path.length) {
62988
- const id = field2.location.reference.objectNumber;
63754
+ const field3 = await locate(frame.location);
63755
+ if (field3?.value.kind !== "dict") continue;
63756
+ if (!field3.location.path.length) {
63757
+ const id = field3.location.reference.objectNumber;
62989
63758
  if (await active.get(BigInt(id)) === 1n) continue;
62990
63759
  await active.set(BigInt(id), 1n);
62991
63760
  await push({ exit: id });
62992
63761
  }
62993
- const name = await resolve2(dictGet(field2.value, "T")), ft = await resolve2(dictGet(field2.value, "FT"));
63762
+ const name = await resolve2(dictGet(field3.value, "T")), ft = await resolve2(dictGet(field3.value, "FT"));
62994
63763
  const partial = name?.kind === "name" ? name.decoded : name?.kind === "string" ? decodePdfString(name) : "";
62995
63764
  const named = update ? frame.named && partial ? `${frame.named}.${partial}` : partial || frame.named : frame.named || partial ? "1" : "";
62996
- const inherited = { ...frame, named, ft: ft?.kind === "name" ? ft.decoded : frame.ft, ff: await number(dictGet(field2.value, "Ff"), frame.ff), q: await number(dictGet(field2.value, "Q"), frame.q) };
62997
- const maxLen = await resolve2(dictGet(field2.value, "MaxLen"));
63765
+ const inherited = { ...frame, named, ft: ft?.kind === "name" ? ft.decoded : frame.ft, ff: await number(dictGet(field3.value, "Ff"), frame.ff), q: await number(dictGet(field3.value, "Q"), frame.q) };
63766
+ const maxLen = await resolve2(dictGet(field3.value, "MaxLen"));
62998
63767
  if (maxLen?.kind === "number") inherited.maxLen = maxLen.value;
62999
- const kids = await locate(child(field2.location, "Kids"));
63768
+ const kids = await locate(child(field3.location, "Kids"));
63000
63769
  if (kids?.value.kind === "array" && kids.value.items.length) {
63001
63770
  let namedKids = false;
63002
63771
  for (let i = 0; i < kids.value.items.length; i++) {
@@ -63021,14 +63790,14 @@ async function generateRetainedFormAppearances(document2, store, storage, signal
63021
63790
  matched = true;
63022
63791
  const value2 = update.value;
63023
63792
  if (typeof value2 === "boolean" || inherited.ft === "Btn") {
63024
- const on = await onValue(field2.location);
63793
+ const on = await onValue(field3.location);
63025
63794
  const checked = typeof value2 === "boolean" ? value2 : value2 !== "Off" && value2 !== "false" && value2 !== "0" && value2 !== "";
63026
63795
  const chosen = typeof value2 === "string" && value2 !== "true" && value2 !== "false" && value2 !== "Off" ? value2 : on;
63027
63796
  const state = cosName(checked ? chosen : "Off");
63028
- dictSet(field2.value, "FT", cosName("Btn"));
63029
- dictSet(field2.value, "V", state);
63030
- dictSet(field2.value, "AS", state);
63031
- await store.set(field2.owner);
63797
+ dictSet(field3.value, "FT", cosName("Btn"));
63798
+ dictSet(field3.value, "V", state);
63799
+ dictSet(field3.value, "AS", state);
63800
+ await store.set(field3.owner);
63032
63801
  if (kids?.value.kind === "array") for (let i = 0; i < kids.value.items.length; i++) {
63033
63802
  await checkpoint();
63034
63803
  const kid = await locate(itemLocation(kids.location, i, kids.value.items[i]));
@@ -63040,13 +63809,13 @@ async function generateRetainedFormAppearances(document2, store, storage, signal
63040
63809
  }
63041
63810
  continue;
63042
63811
  }
63043
- if (!inherited.ft) dictSet(field2.value, "FT", cosName("Tx"));
63812
+ if (!inherited.ft) dictSet(field3.value, "FT", cosName("Tx"));
63044
63813
  let text2 = String(value2);
63045
63814
  const multi = inherited.ft === "Ch" && !!(inherited.ff & 1 << 21) && text2.includes(",");
63046
63815
  const selected = multi ? text2.split(",").map((value3) => value3.trim()).filter(Boolean) : [text2];
63047
- dictSet(field2.value, "V", multi ? cosArray(selected.map((value3) => cosString(value3))) : cosString(text2));
63816
+ dictSet(field3.value, "V", multi ? cosArray(selected.map((value3) => cosString(value3))) : cosString(text2));
63048
63817
  if (inherited.ft === "Ch") {
63049
- const choices = await resolve2(dictGet(field2.value, "Opt")), indices = [];
63818
+ const choices = await resolve2(dictGet(field3.value, "Opt")), indices = [];
63050
63819
  if (choices?.kind === "array") for (let i = 0; i < choices.items.length; i++) {
63051
63820
  await checkpoint();
63052
63821
  const option = await resolve2(choices.items[i]);
@@ -63069,10 +63838,10 @@ async function generateRetainedFormAppearances(document2, store, storage, signal
63069
63838
  }
63070
63839
  }
63071
63840
  }
63072
- if (indices.length) dictSet(field2.value, "I", cosArray(indices.map((value3) => cosNumber(value3))));
63841
+ if (indices.length) dictSet(field3.value, "I", cosArray(indices.map((value3) => cosNumber(value3))));
63073
63842
  }
63074
- await store.set(field2.owner);
63075
- await synthesize(field2.location, text2, inherited);
63843
+ await store.set(field3.owner);
63844
+ await synthesize(field3.location, text2, inherited);
63076
63845
  if (kids?.value.kind === "array") for (let i = 0; i < kids.value.items.length; i++) {
63077
63846
  await checkpoint();
63078
63847
  const kid = await locate(itemLocation(kids.location, i, kids.value.items[i]));
@@ -63080,24 +63849,24 @@ async function generateRetainedFormAppearances(document2, store, storage, signal
63080
63849
  }
63081
63850
  continue;
63082
63851
  }
63083
- const value = await resolve2(dictGet(field2.value, "V"));
63852
+ const value = await resolve2(dictGet(field3.value, "V"));
63084
63853
  if (!value) continue;
63085
- const appearance = await resolve2(dictGet(field2.value, "AP")), hasNormal = appearance?.kind === "dict" && dictGet(appearance, "N") !== void 0;
63854
+ const appearance = await resolve2(dictGet(field3.value, "AP")), hasNormal = appearance?.kind === "dict" && dictGet(appearance, "N") !== void 0;
63086
63855
  if (!force && hasNormal) continue;
63087
63856
  if (inherited.ft === "Btn") {
63088
- dictSet(field2.value, "AS", cosName(value.kind === "name" ? value.decoded : value.kind === "string" ? decodePdfString(value) : "Off"));
63857
+ dictSet(field3.value, "AS", cosName(value.kind === "name" ? value.decoded : value.kind === "string" ? decodePdfString(value) : "Off"));
63089
63858
  if (!hasNormal) {
63090
- const name2 = await onValue(field2.location), dict = cosDict({ Type: cosName("XObject"), Subtype: cosName("Form"), BBox: cosArray([0, 0, 12, 12].map((v) => cosNumber(v))) });
63859
+ const name2 = await onValue(field3.location), dict = cosDict({ Type: cosName("XObject"), Subtype: cosName("Form"), BBox: cosArray([0, 0, 12, 12].map((v) => cosNumber(v))) });
63091
63860
  const on = await stream(dict, [new TextEncoder().encode("q 0 0 0 rg 2 2 8 8 re f Q\n")]);
63092
63861
  const off = await stream(dict, [new TextEncoder().encode("q Q\n")]);
63093
- dictSet(field2.value, "AP", cosDict({ N: cosDict({ [name2]: on, Off: off }) }));
63862
+ dictSet(field3.value, "AP", cosDict({ N: cosDict({ [name2]: on, Off: off }) }));
63094
63863
  }
63095
- await store.set(field2.owner);
63864
+ await store.set(field3.owner);
63096
63865
  continue;
63097
63866
  }
63098
63867
  let text = value.kind === "string" ? decodePdfString(value) : value.kind === "name" ? value.decoded : "";
63099
63868
  if (inherited.ft === "Ch") {
63100
- const choices = await resolve2(dictGet(field2.value, "Opt"));
63869
+ const choices = await resolve2(dictGet(field3.value, "Opt"));
63101
63870
  if (choices?.kind === "array") for (const choice of choices.items) {
63102
63871
  await checkpoint();
63103
63872
  const pair = await resolve2(choice);
@@ -63110,7 +63879,7 @@ async function generateRetainedFormAppearances(document2, store, storage, signal
63110
63879
  }
63111
63880
  }
63112
63881
  }
63113
- await synthesize(field2.location, text, inherited);
63882
+ await synthesize(field3.location, text, inherited);
63114
63883
  if (kids?.value.kind === "array") for (let i = 0; i < kids.value.items.length; i++) {
63115
63884
  await checkpoint();
63116
63885
  const kid = await locate(itemLocation(kids.location, i, kids.value.items[i]));
@@ -63121,8 +63890,8 @@ async function generateRetainedFormAppearances(document2, store, storage, signal
63121
63890
  const fields3 = await locate(child(formLocation, "Fields"));
63122
63891
  if (fields3?.value.kind === "array") {
63123
63892
  const value = update.value;
63124
- const field2 = typeof value === "boolean" ? cosDict({ FT: cosName("Btn"), T: cosString(update.name), V: cosName(value ? "Yes" : "Off"), AS: cosName(value ? "Yes" : "Off") }) : cosDict({ FT: cosName("Tx"), T: cosString(update.name), V: cosString(value) });
63125
- fields3.value.items.push(await store.allocate(field2));
63893
+ const field3 = typeof value === "boolean" ? cosDict({ FT: cosName("Btn"), T: cosString(update.name), V: cosName(value ? "Yes" : "Off"), AS: cosName(value ? "Yes" : "Off") }) : cosDict({ FT: cosName("Tx"), T: cosString(update.name), V: cosString(value) });
63894
+ fields3.value.items.push(await store.allocate(field3));
63126
63895
  await store.set(fields3.owner);
63127
63896
  }
63128
63897
  }
@@ -63142,17 +63911,17 @@ async function generateRetainedFormAppearances(document2, store, storage, signal
63142
63911
  }
63143
63912
 
63144
63913
  // packages/pdf-ast/src/edit/retained-flatten-annotations.ts
63145
- import { IntegerTable as IntegerTable10, PagedStorage as PagedStorage19 } from "@poe-platform/safe-fs/storage";
63914
+ import { IntegerTable as IntegerTable11, PagedStorage as PagedStorage20 } from "@poe-platform/safe-fs/storage";
63146
63915
 
63147
63916
  // packages/pdf-ast/src/edit/retained-content-edit.ts
63148
- import { IntegerTable as IntegerTable9, PagedStorage as PagedStorage16 } from "@poe-platform/safe-fs/storage";
63917
+ import { IntegerTable as IntegerTable10, PagedStorage as PagedStorage17 } from "@poe-platform/safe-fs/storage";
63149
63918
  var RetainedContentEditor = class _RetainedContentEditor {
63150
63919
  constructor(store, storage, signal) {
63151
63920
  this.store = store;
63152
63921
  this.storage = storage;
63153
63922
  this.signal = signal;
63154
- this.backing = new PagedStorage16({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
63155
- this.counts = new IntegerTable9(this.backing);
63923
+ this.backing = new PagedStorage17({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
63924
+ this.counts = new IntegerTable10(this.backing);
63156
63925
  this.identities = new PdfNameIndex(storage, Infinity, signal);
63157
63926
  }
63158
63927
  store;
@@ -63223,14 +63992,14 @@ var RetainedContentEditor = class _RetainedContentEditor {
63223
63992
  };
63224
63993
 
63225
63994
  // packages/pdf-ast/src/edit/retained-name-replacement.ts
63226
- import { PagedStorage as PagedStorage17 } from "@poe-platform/safe-fs/storage";
63995
+ import { PagedStorage as PagedStorage18 } from "@poe-platform/safe-fs/storage";
63227
63996
  async function* replaceRetainedPdfName(input, oldName, newName, storage, options = {}) {
63228
63997
  const chunkBytes = options.chunkBytes ?? 16384, maximum10 = options.maxOutputBytes ?? Infinity;
63229
63998
  if (!Number.isSafeInteger(chunkBytes) || chunkBytes < 1) throw new RangeError("Invalid name replacement chunk size");
63230
63999
  if (maximum10 !== Infinity && (!Number.isSafeInteger(maximum10) || maximum10 < 0)) throw new RangeError("Invalid name replacement output limit");
63231
64000
  const signal = options.signal ?? new AbortController().signal;
63232
64001
  signal.throwIfAborted();
63233
- const table = new PagedStorage17({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), length = oldName.length + 1;
64002
+ const table = new PagedStorage18({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), length = oldName.length + 1;
63234
64003
  const base = table.allocate(length * 8), record = new Uint8Array(8), view = new DataView(record.buffer);
63235
64004
  const pattern = (at) => at ? oldName.charCodeAt(at - 1) : 47;
63236
64005
  let buffer = new Uint8Array(chunkBytes), used = 0, total = 0, work = 0, failed = false;
@@ -63308,10 +64077,10 @@ async function* replaceRetainedPdfName(input, oldName, newName, storage, options
63308
64077
  }
63309
64078
 
63310
64079
  // packages/pdf-ast/src/edit/retained-draw-text.ts
63311
- import { PagedStorage as PagedStorage18 } from "@poe-platform/safe-fs/storage";
64080
+ import { PagedStorage as PagedStorage19 } from "@poe-platform/safe-fs/storage";
63312
64081
  async function drawRetainedAnnotationText(page2, editor, storage, text, x, y, isolated, font, signal) {
63313
64082
  const source = await PdfFileSource.fromStream(storage.fs, storage.directory, page2.streamContents(), { signal });
63314
- const backing = new PagedStorage18({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
64083
+ const backing = new PagedStorage19({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
63315
64084
  let failed = false;
63316
64085
  try {
63317
64086
  const name = await font(), position = backing.allocate(text.length);
@@ -63387,7 +64156,7 @@ async function flattenRetainedAnnotations(document2, store, storage, mode, signa
63387
64156
  for await (const page2 of document2.pages()) {
63388
64157
  const annotations = await array(dictGet(page2.dict, "Annots"));
63389
64158
  if (!annotations) continue;
63390
- const survivorStorage = new PagedStorage19({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
64159
+ const survivorStorage = new PagedStorage20({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
63391
64160
  const survivorBase = survivorStorage.allocate(0);
63392
64161
  let pageFailed = false;
63393
64162
  try {
@@ -63473,7 +64242,7 @@ async function flattenRetainedAnnotations(document2, store, storage, mode, signa
63473
64242
  }
63474
64243
  if (normal?.stream && normal.reference && normal.value.kind === "dict") {
63475
64244
  let content = await PdfFileSource.fromStream(storage.fs, storage.directory, document2.objects.decodeStream(normal.reference.objectNumber, normal.reference.generationNumber), { signal });
63476
- const backing = new PagedStorage19({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), renames = new IntegerTable10(backing), names = new PdfNameIndex(storage, Infinity, signal);
64245
+ const backing = new PagedStorage20({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), renames = new IntegerTable11(backing), names = new PdfNameIndex(storage, Infinity, signal);
63477
64246
  let appearanceFailed = false, count = 0;
63478
64247
  try {
63479
64248
  if (content.size) {
@@ -63592,11 +64361,11 @@ q ${scaleX} 0 0 ${scaleY} ${tx} ${ty} cm${matSuffix}
63592
64361
  }
63593
64362
 
63594
64363
  // packages/pdf-ast/src/edit/retained-name-map.ts
63595
- import { PagedStorage as PagedStorage20 } from "@poe-platform/safe-fs/storage";
64364
+ import { PagedStorage as PagedStorage21 } from "@poe-platform/safe-fs/storage";
63596
64365
  async function* replaceRetainedPdfNames(input, names, storage, options = {}) {
63597
64366
  const signal = options.signal ?? new AbortController().signal, size = options.chunkBytes ?? 16384;
63598
64367
  if (!Number.isSafeInteger(size) || size < 1) throw new RangeError("Invalid name replacement chunk size");
63599
- const trie = new PagedStorage20({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), pending = new PagedStorage20({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
64368
+ const trie = new PagedStorage21({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), pending = new PagedStorage21({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
63600
64369
  const root = trie.allocate(40), prefixBase = pending.allocate(0);
63601
64370
  let output = new Uint8Array(size), used = 0, failed = false, work = 0;
63602
64371
  const body = (byte3) => byte3 >= 48 && byte3 <= 57 || byte3 >= 65 && byte3 <= 90 || byte3 >= 97 && byte3 <= 122 || [95, 46, 43, 45].includes(byte3);
@@ -63878,7 +64647,7 @@ async function preserveRetainedStamp(document2, source, page2, other, store, edi
63878
64647
  }
63879
64648
 
63880
64649
  // packages/pdf-ast/src/edit/retained-stamps.ts
63881
- import { IntegerTable as IntegerTable11, PagedStorage as PagedStorage21 } from "@poe-platform/safe-fs/storage";
64650
+ import { IntegerTable as IntegerTable12, PagedStorage as PagedStorage22 } from "@poe-platform/safe-fs/storage";
63882
64651
  async function stampRetainedPages(document2, store, storage, getPage, stamps, signal) {
63883
64652
  const editor = await RetainedContentEditor.open(store, storage, signal);
63884
64653
  let counter = 1, failed = false, work = 0;
@@ -63889,7 +64658,7 @@ async function stampRetainedPages(document2, store, storage, getPage, stamps, si
63889
64658
  try {
63890
64659
  for await (const stamp of stamps) {
63891
64660
  const source = await editRetainedDocument(stamp.source, storage, { signal });
63892
- const backing = new PagedStorage21({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), memo = new IntegerTable11(backing);
64661
+ const backing = new PagedStorage22({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), memo = new IntegerTable12(backing);
63893
64662
  let stampFailed = false;
63894
64663
  async function clone(node, depth = 0) {
63895
64664
  await checkpoint();
@@ -64075,12 +64844,12 @@ ${fmt6(s)} 0 0 ${fmt6(s)} ${fmt4(tx)} ${fmt4(ty)} cm
64075
64844
  }
64076
64845
 
64077
64846
  // packages/pdf-ast/src/edit/retained-inline-images.ts
64078
- import { PagedStorage as PagedStorage22 } from "@poe-platform/safe-fs/storage";
64847
+ import { PagedStorage as PagedStorage23 } from "@poe-platform/safe-fs/storage";
64079
64848
  async function externalizeRetainedInlineImages(document2, store, storage, options, signal) {
64080
64849
  const minimum = options.minBytes ?? 1024;
64081
64850
  if (!Number.isSafeInteger(minimum) || minimum < 0) throw new RangeError("Invalid inline-image minimum size");
64082
64851
  const editor = await RetainedContentEditor.open(store, storage, signal);
64083
- const paths = new PagedStorage22({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
64852
+ const paths = new PagedStorage23({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
64084
64853
  const keys = { BPC: "BitsPerComponent", CS: "ColorSpace", D: "Decode", DP: "DecodeParms", F: "Filter", H: "Height", IM: "ImageMask", I: "Interpolate", W: "Width" };
64085
64854
  const colors = { G: "DeviceGray", RGB: "DeviceRGB", CMYK: "DeviceCMYK", I: "Indexed" };
64086
64855
  const filters = { AHx: "ASCIIHexDecode", A85: "ASCII85Decode", LZW: "LZWDecode", Fl: "FlateDecode", RL: "RunLengthDecode", CCF: "CCITTFaxDecode", DCT: "DCTDecode" };
@@ -64172,7 +64941,7 @@ async function externalizeRetainedInlineImages(document2, store, storage, option
64172
64941
  }
64173
64942
 
64174
64943
  // packages/pdf-ast/src/edit/retained-resource-pruning.ts
64175
- import { IntegerTable as IntegerTable12, PagedStorage as PagedStorage23 } from "@poe-platform/safe-fs/storage";
64944
+ import { IntegerTable as IntegerTable13, PagedStorage as PagedStorage24 } from "@poe-platform/safe-fs/storage";
64176
64945
  async function collectNames(input, names, found, signal) {
64177
64946
  const iterator = input[Symbol.asyncIterator](), pending = [];
64178
64947
  let chunk = new Uint8Array(), at = 0, ended = false, changed = false, work = 0, failed = false;
@@ -64254,7 +65023,7 @@ async function pruneRetainedResources(document2, store, storage, signal) {
64254
65023
  return { ...found2, value: same(page2.reference) ? page2.dict : same(resources?.reference) ? resources.value : found2.value };
64255
65024
  }
64256
65025
  const names = new PdfNameIndex(storage, Infinity, signal), visitedNames = new PdfNameIndex(storage, Infinity, signal);
64257
- const backing = new PagedStorage23({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), found = new IntegerTable12(backing);
65026
+ const backing = new PagedStorage24({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), found = new IntegerTable13(backing);
64258
65027
  let failed = false;
64259
65028
  try {
64260
65029
  const referenced = async (name) => await found.get(BigInt((await names.intern(name)).index)) !== void 0;
@@ -64384,7 +65153,7 @@ async function flattenRetainedRotations(document2, store, storage, signal) {
64384
65153
  }
64385
65154
 
64386
65155
  // packages/pdf-ast/src/edit/retained-attachment-edits.ts
64387
- import { IntegerTable as IntegerTable13, PagedStorage as PagedStorage24 } from "@poe-platform/safe-fs/storage";
65156
+ import { IntegerTable as IntegerTable14, PagedStorage as PagedStorage25 } from "@poe-platform/safe-fs/storage";
64388
65157
  var PdfDuplicateAttachment = class extends PdfError {
64389
65158
  constructor(key) {
64390
65159
  super("E_CAPABILITY", `Duplicate attachment key: ${key}`);
@@ -64395,7 +65164,7 @@ var PdfDuplicateAttachment = class extends PdfError {
64395
65164
  async function editRetainedAttachments(document2, target, storage, remove, additions, signal, preserveTree = false) {
64396
65165
  const pairs = new PdfMutableObjectStore(storage, { signal });
64397
65166
  const names = new PdfNameIndex(storage, Infinity, signal), removed = new PdfNameIndex(storage, Infinity, signal);
64398
- const backing = new PagedStorage24({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), first = new IntegerTable13(backing), removals = new IntegerTable13(backing);
65167
+ const backing = new PagedStorage25({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), first = new IntegerTable14(backing), removals = new IntegerTable14(backing);
64399
65168
  let failed = false, count = 0, work = 0;
64400
65169
  async function checkpoint() {
64401
65170
  signal.throwIfAborted();
@@ -64597,13 +65366,13 @@ async function* retainedAttachmentNameTokens(document2, storage, root, signal, r
64597
65366
  }
64598
65367
 
64599
65368
  // packages/pdf-ast/src/edit/retained-graph.ts
64600
- import { PagedStorage as PagedStorage25 } from "@poe-platform/safe-fs/storage";
65369
+ import { PagedStorage as PagedStorage26 } from "@poe-platform/safe-fs/storage";
64601
65370
  async function editRetainedDocument(source, storage, options = {}) {
64602
65371
  if (options.maxPages !== void 0 && options.maxPages !== Infinity && (!Number.isSafeInteger(options.maxPages) || options.maxPages < 0)) throw new RangeError("Invalid page limit");
64603
65372
  if (options.maxRecursionDepth !== void 0 && options.maxRecursionDepth !== Infinity && (!Number.isSafeInteger(options.maxRecursionDepth) || options.maxRecursionDepth < 1)) throw new RangeError("Invalid edit depth");
64604
65373
  const signal = options.signal ?? new AbortController().signal;
64605
65374
  const store = new PdfMutableObjectStore(storage, { ...options, signal });
64606
- const pages = new PagedStorage25({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
65375
+ const pages = new PagedStorage26({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
64607
65376
  const base = pages.allocate(0);
64608
65377
  let count = 0, document2;
64609
65378
  let closing;
@@ -64730,6 +65499,10 @@ async function editRetainedDocument(source, storage, options = {}) {
64730
65499
  await generateRetainedFormAppearances(document2, store, storage, signal);
64731
65500
  addedObjects = true;
64732
65501
  }
65502
+ if (options.flattenForms) {
65503
+ await flattenRetainedForms(document2, store, storage, signal);
65504
+ addedObjects = true;
65505
+ }
64733
65506
  if (options.removeInfo) {
64734
65507
  await removeRoot(["Metadata"]);
64735
65508
  const found = await document2.lookup(infoRef);
@@ -64837,10 +65610,10 @@ async function* copyRetainedAttachments(document2, storage, options = {}) {
64837
65610
  }
64838
65611
 
64839
65612
  // packages/pdf-ast/src/cos/retained-object-order.ts
64840
- import { IntegerTable as IntegerTable14, PagedStorage as PagedStorage26 } from "@poe-platform/safe-fs/storage";
65613
+ import { IntegerTable as IntegerTable15, PagedStorage as PagedStorage27 } from "@poe-platform/safe-fs/storage";
64841
65614
  async function* retainedObjectOrder(document2, source, storage, signal) {
64842
- const backing = new PagedStorage26({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
64843
- const seen = new IntegerTable14(backing), streams = new IntegerTable14(backing);
65615
+ const backing = new PagedStorage27({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
65616
+ const seen = new IntegerTable15(backing), streams = new IntegerTable15(backing);
64844
65617
  let failed = false, work = 0;
64845
65618
  async function candidate(number) {
64846
65619
  signal.throwIfAborted();
@@ -64854,7 +65627,7 @@ async function* retainedObjectOrder(document2, source, storage, signal) {
64854
65627
  try {
64855
65628
  if (document2.crossReference.revisionCount) {
64856
65629
  for (const kind of ["uncompressed", "compressed"]) {
64857
- const revisions = new IntegerTable14(backing);
65630
+ const revisions = new IntegerTable15(backing);
64858
65631
  let offset = document2.crossReference.xrefOffset;
64859
65632
  while (offset !== void 0 && await revisions.get(BigInt(offset)) === void 0) {
64860
65633
  await revisions.set(BigInt(offset), 1n);
@@ -64976,14 +65749,14 @@ async function* encryptRetainedPdfChunks(source, storage, options = {}) {
64976
65749
  }
64977
65750
 
64978
65751
  // packages/pdf-ast/src/cos/qpdf-json-values.ts
64979
- import { IntegerTable as IntegerTable15, PagedStorage as PagedStorage27 } from "@poe-platform/safe-fs/storage";
65752
+ import { IntegerTable as IntegerTable16, PagedStorage as PagedStorage28 } from "@poe-platform/safe-fs/storage";
64980
65753
  var QpdfJsonValues = class _QpdfJsonValues {
64981
65754
  constructor(tree, storage, signal) {
64982
65755
  this.tree = tree;
64983
65756
  this.signal = signal;
64984
- this.scratch = new PagedStorage27({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
64985
- this.first = new IntegerTable15(this.scratch, 64);
64986
- this.next = new IntegerTable15(this.scratch, 64);
65757
+ this.scratch = new PagedStorage28({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
65758
+ this.first = new IntegerTable16(this.scratch, 64);
65759
+ this.next = new IntegerTable16(this.scratch, 64);
64987
65760
  }
64988
65761
  tree;
64989
65762
  signal;
@@ -65081,7 +65854,7 @@ var QpdfJsonValues = class _QpdfJsonValues {
65081
65854
  await this.cooperate();
65082
65855
  const header2 = await this.tree.describe(position);
65083
65856
  if (header2.kind === "object") {
65084
- const hashes = new IntegerTable15(this.scratch, 64);
65857
+ const hashes = new IntegerTable16(this.scratch, 64);
65085
65858
  let head = 0, tail = 0;
65086
65859
  for await (const { key } of order.entries(position)) {
65087
65860
  let hash2 = 0;
@@ -65374,19 +66147,19 @@ var QpdfJsonValues = class _QpdfJsonValues {
65374
66147
  };
65375
66148
 
65376
66149
  // packages/pdf-ast/src/cos/qpdf-json-document.ts
65377
- import { IntegerTable as IntegerTable16, PagedStorage as PagedStorage28 } from "@poe-platform/safe-fs/storage";
66150
+ import { IntegerTable as IntegerTable17, PagedStorage as PagedStorage29 } from "@poe-platform/safe-fs/storage";
65378
66151
  var QpdfJsonDocument = class _QpdfJsonDocument {
65379
66152
  constructor(storage, options = {}) {
65380
66153
  this.storage = storage;
65381
66154
  this.signal = options.signal ? AbortSignal.any([options.signal, this.controller.signal]) : this.controller.signal;
65382
66155
  this.store = new PdfMutableObjectStore(storage, { signal: this.signal });
65383
- this.backing = new PagedStorage28(
66156
+ this.backing = new PagedStorage29(
65384
66157
  { fs: storage.fs, cwd: storage.directory, env: {}, signal: this.signal },
65385
66158
  4
65386
66159
  );
65387
- this.positions = new IntegerTable16(this.backing, 64);
65388
- this.order = new IntegerTable16(this.backing, 64);
65389
- this.catalogs = new IntegerTable16(this.backing, 64);
66160
+ this.positions = new IntegerTable17(this.backing, 64);
66161
+ this.order = new IntegerTable17(this.backing, 64);
66162
+ this.catalogs = new IntegerTable17(this.backing, 64);
65390
66163
  }
65391
66164
  storage;
65392
66165
  rootRef;
@@ -65449,7 +66222,7 @@ var QpdfJsonDocument = class _QpdfJsonDocument {
65449
66222
  env: {},
65450
66223
  signal: this.signal
65451
66224
  };
65452
- const tape = new PagedStorage28(context, 4), scratch = new PagedStorage28(context, 4);
66225
+ const tape = new PagedStorage29(context, 4), scratch = new PagedStorage29(context, 4);
65453
66226
  let values, failed = false, work = 0;
65454
66227
  const cooperate = async (units = 1) => {
65455
66228
  this.signal.throwIfAborted();
@@ -65672,12 +66445,12 @@ var QpdfJsonDocument = class _QpdfJsonDocument {
65672
66445
  };
65673
66446
 
65674
66447
  // packages/pdf-ast/src/edit/retained-form-data.ts
65675
- import { IntegerTable as IntegerTable18, PagedStorage as PagedStorage30 } from "@poe-platform/safe-fs/storage";
66448
+ import { IntegerTable as IntegerTable19, PagedStorage as PagedStorage31 } from "@poe-platform/safe-fs/storage";
65676
66449
 
65677
66450
  // packages/pdf-ast/src/edit/retained-form-data-fdf.ts
65678
- import { IntegerTable as IntegerTable17, PagedStorage as PagedStorage29 } from "@poe-platform/safe-fs/storage";
66451
+ import { IntegerTable as IntegerTable18, PagedStorage as PagedStorage30 } from "@poe-platform/safe-fs/storage";
65679
66452
  async function parseRetainedFdf(source, storage, set, signal) {
65680
- const backing = new PagedStorage29({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), tokens = new IntegerTable17(backing), starts = new IntegerTable17(backing), children = new IntegerTable17(backing), visited = new IntegerTable17(backing), names = new PdfNameIndex(storage, Infinity, signal);
66453
+ const backing = new PagedStorage30({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), tokens = new IntegerTable18(backing), starts = new IntegerTable18(backing), children = new IntegerTable18(backing), visited = new IntegerTable18(backing), names = new PdfNameIndex(storage, Infinity, signal);
65681
66454
  let count = 0, cursor = 0, head = -1, work = 0, failed = false;
65682
66455
  const cache = /* @__PURE__ */ new Map();
65683
66456
  async function checkpoint() {
@@ -65937,7 +66710,7 @@ var FormText = class {
65937
66710
  };
65938
66711
  async function* parseRetainedFormData(source, storage, options = {}) {
65939
66712
  const signal = options.signal ?? new AbortController().signal, context = { fs: storage.fs, cwd: storage.directory, env: {}, signal };
65940
- const textBacking = new PagedStorage30(context, 2), state = new PagedStorage30(context, 4), names = new PdfNameIndex(storage, Infinity, signal), values = new IntegerTable18(state);
66713
+ const textBacking = new PagedStorage31(context, 2), state = new PagedStorage31(context, 4), names = new PdfNameIndex(storage, Infinity, signal), values = new IntegerTable19(state);
65941
66714
  const text = new FormText(textBacking, signal);
65942
66715
  let count = 0, failed = false, work = 0;
65943
66716
  async function checkpoint() {
@@ -65963,7 +66736,7 @@ async function* parseRetainedFormData(source, storage, options = {}) {
65963
66736
  const prefix = await text.prefix();
65964
66737
  if (prefix === "%FDF-" || await text.indexOf("/FDF") >= 0 && await text.indexOf("/Fields") >= 0) await parseRetainedFdf(source, storage, set, signal);
65965
66738
  else if (prefix === "<?xml" || prefix === "<xfdf" || await text.indexOf("<fields") >= 0) {
65966
- let position = 0, head = -1, field2 = "";
66739
+ let position = 0, head = -1, field3 = "";
65967
66740
  while (position < text.length) {
65968
66741
  await checkpoint();
65969
66742
  const lt = await text.indexOf("<", position);
@@ -65976,7 +66749,7 @@ async function* parseRetainedFormData(source, storage, options = {}) {
65976
66749
  if (raw.startsWith("/")) {
65977
66750
  if (raw.slice(1).trim().toLowerCase() === "field" && head !== -1) {
65978
66751
  const row = (await readStoredRecord(state, head, signal)).value;
65979
- field2 = row.field;
66752
+ field3 = row.field;
65980
66753
  head = row.previous;
65981
66754
  }
65982
66755
  continue;
@@ -65993,14 +66766,14 @@ async function* parseRetainedFormData(source, storage, options = {}) {
65993
66766
  }
65994
66767
  }
65995
66768
  if (!selfClosing) {
65996
- head = await appendStoredRecord(state, { field: field2, previous: head }, -1, signal);
65997
- field2 = field2 && part ? `${field2}.${part}` : field2 || part;
66769
+ head = await appendStoredRecord(state, { field: field3, previous: head }, -1, signal);
66770
+ field3 = field3 && part ? `${field3}.${part}` : field3 || part;
65998
66771
  }
65999
66772
  } else if (name === "value" && !selfClosing && head !== -1) {
66000
66773
  const close = await text.indexOf("</value>", position);
66001
66774
  if (close >= 0) {
66002
66775
  const value = decodeFormDataEntities(await text.read(position, close));
66003
- if (field2) await set(field2, value === "Off" ? false : value === "Yes" || value === "On" ? true : value, true);
66776
+ if (field3) await set(field3, value === "Off" ? false : value === "Yes" || value === "On" ? true : value, true);
66004
66777
  position = close + 8;
66005
66778
  }
66006
66779
  }
@@ -66173,6 +66946,9 @@ export {
66173
66946
  encodeRgbaToPng,
66174
66947
  encodeRgbaToPngSteps,
66175
66948
  encodeRunLength,
66949
+ encodeSvgImageChunks,
66950
+ encodeSvgPathDataChunks,
66951
+ encodeSvgPathPaintChunks,
66176
66952
  encodeTiff,
66177
66953
  encodeTiffSteps,
66178
66954
  encodeWinAnsiBytes,