reamkit 1.15.0 → 1.15.2

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 (316) hide show
  1. package/dist/esm/core/arc-to-bezier.d.ts +23 -0
  2. package/dist/esm/core/arc-to-bezier.js +23 -0
  3. package/dist/esm/core/bidi/algorithm.d.ts +26 -0
  4. package/dist/esm/core/bidi/algorithm.js +21 -0
  5. package/dist/esm/core/bidi/char-types.d.ts +17 -0
  6. package/dist/esm/core/bidi/char-types.js +10 -0
  7. package/dist/esm/core/bidi/index.d.ts +42 -0
  8. package/dist/esm/core/bidi/index.js +27 -0
  9. package/dist/esm/core/bidi/segments.d.ts +22 -0
  10. package/dist/esm/core/bidi/segments.js +14 -0
  11. package/dist/esm/core/bytes.d.ts +9 -0
  12. package/dist/esm/core/bytes.js +9 -0
  13. package/dist/esm/core/converter/facade.d.ts +38 -1
  14. package/dist/esm/core/converter/facade.js +25 -0
  15. package/dist/esm/core/converter/project.d.ts +12 -0
  16. package/dist/esm/core/converter/project.js +11 -0
  17. package/dist/esm/core/converter/ream.d.ts +107 -0
  18. package/dist/esm/core/converter/ream.js +76 -0
  19. package/dist/esm/core/crypto/asn1.d.ts +77 -0
  20. package/dist/esm/core/crypto/asn1.js +65 -0
  21. package/dist/esm/core/crypto/cms.d.ts +25 -0
  22. package/dist/esm/core/crypto/cms.js +8 -0
  23. package/dist/esm/core/document-model/index.d.ts +7 -0
  24. package/dist/esm/core/document-model/types.d.ts +328 -0
  25. package/dist/esm/core/drawingml/chart-geometry.d.ts +125 -0
  26. package/dist/esm/core/drawingml/chart-geometry.js +96 -0
  27. package/dist/esm/core/drawingml/chart-parser.d.ts +34 -0
  28. package/dist/esm/core/drawingml/chart-parser.js +34 -0
  29. package/dist/esm/core/drawingml/chart-serializer.d.ts +12 -0
  30. package/dist/esm/core/drawingml/chart-serializer.js +12 -0
  31. package/dist/esm/core/drawingml/colors.d.ts +53 -0
  32. package/dist/esm/core/drawingml/colors.js +41 -0
  33. package/dist/esm/core/drawingml/preset-geometry.d.ts +30 -0
  34. package/dist/esm/core/drawingml/preset-geometry.js +30 -0
  35. package/dist/esm/core/drawingml/shape-render.d.ts +54 -0
  36. package/dist/esm/core/drawingml/shape-render.js +54 -0
  37. package/dist/esm/core/drawingml/sparkline-geometry.d.ts +15 -0
  38. package/dist/esm/core/drawingml/sparkline-geometry.js +13 -0
  39. package/dist/esm/core/drawingml/theme-parser.d.ts +11 -0
  40. package/dist/esm/core/drawingml/theme-parser.js +11 -0
  41. package/dist/esm/core/font/arabic-joining.d.ts +21 -0
  42. package/dist/esm/core/font/arabic-joining.js +16 -0
  43. package/dist/esm/core/font/binary-reader.d.ts +17 -0
  44. package/dist/esm/core/font/binary-reader.js +17 -0
  45. package/dist/esm/core/font/font-registry.d.ts +37 -0
  46. package/dist/esm/core/font/font-registry.js +31 -0
  47. package/dist/esm/core/font/measure.d.ts +20 -0
  48. package/dist/esm/core/font/measure.js +11 -0
  49. package/dist/esm/core/font/opentype-layout.d.ts +49 -0
  50. package/dist/esm/core/font/opentype-layout.js +37 -0
  51. package/dist/esm/core/font/ttf-parser.d.ts +32 -0
  52. package/dist/esm/core/font/ttf-parser.js +7 -0
  53. package/dist/esm/core/font/ttf-subset.d.ts +21 -0
  54. package/dist/esm/core/font/ttf-subset.js +21 -0
  55. package/dist/esm/core/fonts/provider.d.ts +8 -1
  56. package/dist/esm/core/fonts/provider.js +1 -0
  57. package/dist/esm/core/fonts/remote-fonts.d.ts +22 -0
  58. package/dist/esm/core/fonts/remote-fonts.js +16 -0
  59. package/dist/esm/core/hyphenation/index.d.ts +25 -0
  60. package/dist/esm/core/hyphenation/index.js +17 -0
  61. package/dist/esm/core/hyphenation/liang.d.ts +27 -0
  62. package/dist/esm/core/hyphenation/liang.js +14 -0
  63. package/dist/esm/core/images.d.ts +32 -0
  64. package/dist/esm/core/images.js +12 -0
  65. package/dist/esm/core/ir/adapters.d.ts +23 -0
  66. package/dist/esm/core/ir/features.d.ts +8 -0
  67. package/dist/esm/core/ir/features.js +1 -0
  68. package/dist/esm/core/ir/flow.d.ts +20 -0
  69. package/dist/esm/core/ir/index.d.ts +7 -0
  70. package/dist/esm/core/ir/loss.d.ts +12 -0
  71. package/dist/esm/core/ir/loss.js +8 -0
  72. package/dist/esm/core/ir/resources.d.ts +12 -0
  73. package/dist/esm/core/ir/resources.js +11 -0
  74. package/dist/esm/core/ir/sheet.d.ts +81 -0
  75. package/dist/esm/core/ir/units.d.ts +9 -0
  76. package/dist/esm/core/ir/units.js +2 -0
  77. package/dist/esm/core/line-breaker/cjk.d.ts +26 -0
  78. package/dist/esm/core/line-breaker/cjk.js +60 -0
  79. package/dist/esm/core/line-breaker/greedy.d.ts +14 -0
  80. package/dist/esm/core/line-breaker/greedy.js +14 -0
  81. package/dist/esm/core/line-breaker/index.d.ts +1 -0
  82. package/dist/esm/core/line-breaker/index.js +3 -0
  83. package/dist/esm/core/line-breaker/knuth-plass.d.ts +29 -5
  84. package/dist/esm/core/line-breaker/knuth-plass.js +10 -5
  85. package/dist/esm/core/numbering/apply.d.ts +19 -0
  86. package/dist/esm/core/numbering/apply.js +19 -0
  87. package/dist/esm/core/numbering/state.d.ts +15 -0
  88. package/dist/esm/core/numbering/state.js +15 -0
  89. package/dist/esm/core/ole/cfb.d.ts +19 -0
  90. package/dist/esm/core/ole/cfb.js +50 -4
  91. package/dist/esm/core/opc/core-properties.d.ts +12 -0
  92. package/dist/esm/core/opc/core-properties.js +5 -0
  93. package/dist/esm/core/opc/opc-writer.d.ts +24 -4
  94. package/dist/esm/core/opc/opc-writer.js +12 -0
  95. package/dist/esm/core/opc/package.d.ts +55 -0
  96. package/dist/esm/core/opc/package.js +46 -0
  97. package/dist/esm/core/opc/relationship-types.d.ts +8 -0
  98. package/dist/esm/core/opc/relationship-types.js +5 -0
  99. package/dist/esm/core/opc/relationships.d.ts +12 -0
  100. package/dist/esm/core/opc/relationships.js +7 -0
  101. package/dist/esm/core/po-helpers.d.ts +38 -0
  102. package/dist/esm/core/po-helpers.js +33 -0
  103. package/dist/esm/core/spreadsheet-model/types.d.ts +281 -0
  104. package/dist/esm/core/style-cascade/resolver.d.ts +31 -0
  105. package/dist/esm/core/style-cascade/resolver.js +31 -0
  106. package/dist/esm/core/style-cascade/table.d.ts +7 -0
  107. package/dist/esm/core/style-cascade/table.js +7 -0
  108. package/dist/esm/core/style-cascade/types.d.ts +27 -0
  109. package/dist/esm/core/style-cascade/types.js +2 -0
  110. package/dist/esm/core/vector.d.ts +67 -0
  111. package/dist/esm/core/vector.js +23 -0
  112. package/dist/esm/excel/activex-parser.d.ts +31 -0
  113. package/dist/esm/excel/activex-parser.js +24 -0
  114. package/dist/esm/excel/cell-reference.d.ts +14 -0
  115. package/dist/esm/excel/cell-reference.js +9 -0
  116. package/dist/esm/excel/column-bands.d.ts +29 -0
  117. package/dist/esm/excel/column-bands.js +26 -0
  118. package/dist/esm/excel/comments-parser.d.ts +19 -0
  119. package/dist/esm/excel/comments-parser.js +19 -0
  120. package/dist/esm/excel/conditional-format.d.ts +38 -0
  121. package/dist/esm/excel/conditional-format.js +25 -0
  122. package/dist/esm/excel/defined-name-ref.d.ts +21 -0
  123. package/dist/esm/excel/defined-name-ref.js +20 -0
  124. package/dist/esm/excel/form-control-parser.d.ts +13 -0
  125. package/dist/esm/excel/form-control-parser.js +5 -0
  126. package/dist/esm/excel/formula/context.d.ts +37 -0
  127. package/dist/esm/excel/formula/dates.d.ts +23 -0
  128. package/dist/esm/excel/formula/dates.js +20 -0
  129. package/dist/esm/excel/formula/eval.d.ts +21 -0
  130. package/dist/esm/excel/formula/eval.js +11 -0
  131. package/dist/esm/excel/formula/functions.d.ts +12 -0
  132. package/dist/esm/excel/formula/functions.js +12 -0
  133. package/dist/esm/excel/formula/index.d.ts +21 -0
  134. package/dist/esm/excel/formula/index.js +16 -0
  135. package/dist/esm/excel/formula/lexer.d.ts +12 -0
  136. package/dist/esm/excel/formula/lexer.js +10 -0
  137. package/dist/esm/excel/formula/parser.d.ts +20 -0
  138. package/dist/esm/excel/formula/parser.js +53 -0
  139. package/dist/esm/excel/formula/value.d.ts +53 -0
  140. package/dist/esm/excel/formula/value.js +30 -0
  141. package/dist/esm/excel/header-footer.d.ts +9 -0
  142. package/dist/esm/excel/header-footer.js +9 -0
  143. package/dist/esm/excel/number-format.d.ts +34 -0
  144. package/dist/esm/excel/number-format.js +34 -0
  145. package/dist/esm/excel/pivot-table-parser.d.ts +8 -0
  146. package/dist/esm/excel/pivot-table-parser.js +8 -0
  147. package/dist/esm/excel/print-model.d.ts +56 -0
  148. package/dist/esm/excel/print-model.js +43 -0
  149. package/dist/esm/excel/shared-strings-parser.d.ts +13 -0
  150. package/dist/esm/excel/shared-strings-parser.js +5 -0
  151. package/dist/esm/excel/sheet-drawing.d.ts +34 -0
  152. package/dist/esm/excel/sheet-drawing.js +21 -0
  153. package/dist/esm/excel/sheet-shape-parser.d.ts +12 -0
  154. package/dist/esm/excel/sheet-shape-parser.js +12 -0
  155. package/dist/esm/excel/sheet-to-flow.d.ts +19 -0
  156. package/dist/esm/excel/sheet-to-flow.js +10 -0
  157. package/dist/esm/excel/slicer-parser.d.ts +23 -0
  158. package/dist/esm/excel/slicer-parser.js +10 -0
  159. package/dist/esm/excel/styles-parser.d.ts +8 -0
  160. package/dist/esm/excel/styles-parser.js +8 -0
  161. package/dist/esm/excel/table-parser.d.ts +24 -0
  162. package/dist/esm/excel/table-parser.js +5 -0
  163. package/dist/esm/excel/workbook-parser.d.ts +17 -0
  164. package/dist/esm/excel/workbook-parser.js +5 -0
  165. package/dist/esm/excel/worksheet-parser.d.ts +9 -0
  166. package/dist/esm/excel/worksheet-parser.js +9 -0
  167. package/dist/esm/excel/xls/biff-chart.d.ts +10 -0
  168. package/dist/esm/excel/xls/biff-chart.js +10 -0
  169. package/dist/esm/excel/xls/biff-reader.d.ts +27 -0
  170. package/dist/esm/excel/xls/biff-reader.js +44 -0
  171. package/dist/esm/excel/xls/biff-styles.d.ts +20 -0
  172. package/dist/esm/excel/xls/biff-styles.js +20 -0
  173. package/dist/esm/excel/xls/escher.d.ts +27 -0
  174. package/dist/esm/excel/xls/escher.js +18 -0
  175. package/dist/esm/excel/xls/xls-reader.d.ts +6 -0
  176. package/dist/esm/excel/xls/xls-reader.js +6 -0
  177. package/dist/esm/excel/xlsx-reader.d.ts +26 -0
  178. package/dist/esm/excel/xlsx-reader.js +26 -0
  179. package/dist/esm/excel/xlsx-to-pdf.d.ts +27 -0
  180. package/dist/esm/excel/xlsx-writer.d.ts +14 -0
  181. package/dist/esm/excel/xlsx-writer.js +13 -0
  182. package/dist/esm/html/html-writer.d.ts +18 -0
  183. package/dist/esm/html/html-writer.js +18 -0
  184. package/dist/esm/index.d.ts +23 -0
  185. package/dist/esm/layout/math-layout.d.ts +39 -0
  186. package/dist/esm/layout/math-layout.js +18 -0
  187. package/dist/esm/layout/page-doc.d.ts +91 -0
  188. package/dist/esm/layout/styled-layout.d.ts +175 -0
  189. package/dist/esm/layout/styled-layout.js +117 -2
  190. package/dist/esm/pdf/builtin-fonts.d.ts +5 -0
  191. package/dist/esm/pdf/cid-font.d.ts +22 -0
  192. package/dist/esm/pdf/cid-font.js +10 -0
  193. package/dist/esm/pdf/embedded-file.d.ts +16 -0
  194. package/dist/esm/pdf/embedded-file.js +9 -0
  195. package/dist/esm/pdf/encryption.d.ts +59 -0
  196. package/dist/esm/pdf/encryption.js +37 -0
  197. package/dist/esm/pdf/icc-profile.d.ts +8 -0
  198. package/dist/esm/pdf/icc-profile.js +8 -0
  199. package/dist/esm/pdf/image-xobject.d.ts +19 -0
  200. package/dist/esm/pdf/image-xobject.js +9 -0
  201. package/dist/esm/pdf/objects.d.ts +40 -0
  202. package/dist/esm/pdf/objects.js +36 -0
  203. package/dist/esm/pdf/serialize.d.ts +18 -0
  204. package/dist/esm/pdf/serialize.js +18 -0
  205. package/dist/esm/pdf/shading.d.ts +16 -0
  206. package/dist/esm/pdf/shading.js +16 -0
  207. package/dist/esm/pdf/signature.d.ts +36 -0
  208. package/dist/esm/pdf/signature.js +22 -0
  209. package/dist/esm/pdf/struct-tree.d.ts +64 -0
  210. package/dist/esm/pdf/struct-tree.js +60 -0
  211. package/dist/esm/pdf/styled-page-emitter.d.ts +33 -0
  212. package/dist/esm/pdf/styled-page-emitter.js +21 -0
  213. package/dist/esm/pdf/styled-page-renderer.d.ts +18 -0
  214. package/dist/esm/pdf/styled-page-renderer.js +18 -0
  215. package/dist/esm/pdf/text-encoding.d.ts +16 -0
  216. package/dist/esm/pdf/text-page-renderer.d.ts +11 -0
  217. package/dist/esm/pdf/vector-graphics.d.ts +12 -0
  218. package/dist/esm/pdf/vector-graphics.js +12 -0
  219. package/dist/esm/pdf/writer.d.ts +39 -0
  220. package/dist/esm/pdf/writer.js +27 -0
  221. package/dist/esm/pdf/xmp.d.ts +16 -0
  222. package/dist/esm/pdf/xmp.js +9 -0
  223. package/dist/esm/pdf-reader/ccitt.d.ts +25 -0
  224. package/dist/esm/pdf-reader/ccitt.js +15 -0
  225. package/dist/esm/pdf-reader/cmap.d.ts +12 -0
  226. package/dist/esm/pdf-reader/cmap.js +9 -0
  227. package/dist/esm/pdf-reader/content.d.ts +69 -0
  228. package/dist/esm/pdf-reader/content.js +16 -0
  229. package/dist/esm/pdf-reader/crypto.d.ts +5 -0
  230. package/dist/esm/pdf-reader/crypto.js +5 -0
  231. package/dist/esm/pdf-reader/decrypt.d.ts +17 -0
  232. package/dist/esm/pdf-reader/decrypt.js +12 -0
  233. package/dist/esm/pdf-reader/document.d.ts +53 -0
  234. package/dist/esm/pdf-reader/document.js +50 -0
  235. package/dist/esm/pdf-reader/flow-build.d.ts +51 -2
  236. package/dist/esm/pdf-reader/flow-build.js +67 -2
  237. package/dist/esm/pdf-reader/font.d.ts +12 -0
  238. package/dist/esm/pdf-reader/font.js +12 -0
  239. package/dist/esm/pdf-reader/image-decode.d.ts +21 -0
  240. package/dist/esm/pdf-reader/image-decode.js +14 -0
  241. package/dist/esm/pdf-reader/images.d.ts +19 -0
  242. package/dist/esm/pdf-reader/images.js +9 -0
  243. package/dist/esm/pdf-reader/layout.d.ts +15 -0
  244. package/dist/esm/pdf-reader/layout.js +17 -2
  245. package/dist/esm/pdf-reader/lexer.d.ts +43 -0
  246. package/dist/esm/pdf-reader/lexer.js +38 -0
  247. package/dist/esm/pdf-reader/parser.d.ts +15 -0
  248. package/dist/esm/pdf-reader/parser.js +8 -0
  249. package/dist/esm/pdf-reader/png-encode.d.ts +9 -0
  250. package/dist/esm/pdf-reader/png-encode.js +8 -0
  251. package/dist/esm/pdf-reader/predictor.d.ts +9 -0
  252. package/dist/esm/pdf-reader/predictor.js +8 -0
  253. package/dist/esm/pdf-reader/reader.d.ts +16 -0
  254. package/dist/esm/pdf-reader/reader.js +16 -0
  255. package/dist/esm/pdf-reader/shading.d.ts +10 -0
  256. package/dist/esm/pdf-reader/shading.js +10 -0
  257. package/dist/esm/pdf-reader/struct-tree.d.ts +24 -0
  258. package/dist/esm/pdf-reader/struct-tree.js +12 -0
  259. package/dist/esm/pdf-reader/tagged.d.ts +13 -0
  260. package/dist/esm/pdf-reader/tagged.js +15 -2
  261. package/dist/esm/pdf-reader/text.d.ts +11 -0
  262. package/dist/esm/pdf-reader/text.js +11 -0
  263. package/dist/esm/pdf-reader/vector.d.ts +19 -0
  264. package/dist/esm/pdf-reader/vector.js +9 -0
  265. package/dist/esm/pptx/placeholder-cascade.d.ts +21 -0
  266. package/dist/esm/pptx/placeholder-cascade.js +10 -0
  267. package/dist/esm/pptx/ppt/ppt-reader.d.ts +16 -0
  268. package/dist/esm/pptx/ppt/ppt-reader.js +16 -0
  269. package/dist/esm/pptx/ppt/ppt-text.d.ts +55 -0
  270. package/dist/esm/pptx/ppt/ppt-text.js +14 -0
  271. package/dist/esm/pptx/pptx-reader.d.ts +21 -0
  272. package/dist/esm/pptx/pptx-reader.js +37 -1
  273. package/dist/esm/pptx/slide-parser.d.ts +102 -0
  274. package/dist/esm/pptx/slide-parser.js +78 -0
  275. package/dist/esm/pptx/sp-helpers.d.ts +28 -0
  276. package/dist/esm/pptx/sp-helpers.js +22 -0
  277. package/dist/esm/svg/svg-writer.d.ts +17 -0
  278. package/dist/esm/svg/svg-writer.js +16 -0
  279. package/dist/esm/word/doc/doc-reader.d.ts +16 -0
  280. package/dist/esm/word/doc/doc-reader.js +26 -4
  281. package/dist/esm/word/doc/doc-text.d.ts +81 -0
  282. package/dist/esm/word/doc/doc-text.js +38 -0
  283. package/dist/esm/word/document-parser.d.ts +134 -0
  284. package/dist/esm/word/document-parser.js +86 -0
  285. package/dist/esm/word/docx-reader.d.ts +16 -0
  286. package/dist/esm/word/docx-reader.js +16 -0
  287. package/dist/esm/word/docx-to-pdf.d.ts +52 -0
  288. package/dist/esm/word/docx-to-pdf.js +21 -0
  289. package/dist/esm/word/docx-writer.d.ts +17 -0
  290. package/dist/esm/word/docx-writer.js +17 -0
  291. package/dist/esm/word/drawing-parser.d.ts +88 -0
  292. package/dist/esm/word/drawing-parser.js +68 -0
  293. package/dist/esm/word/font-table.d.ts +24 -0
  294. package/dist/esm/word/font-table.js +24 -0
  295. package/dist/esm/word/numbering-parser.d.ts +11 -0
  296. package/dist/esm/word/numbering-parser.js +11 -0
  297. package/dist/esm/word/omml-parser.d.ts +15 -0
  298. package/dist/esm/word/omml-parser.js +15 -0
  299. package/dist/esm/word/omml-serializer.d.ts +9 -0
  300. package/dist/esm/word/omml-serializer.js +9 -0
  301. package/dist/esm/word/paragraph-properties.d.ts +10 -0
  302. package/dist/esm/word/paragraph-properties.js +10 -0
  303. package/dist/esm/word/po-to-flat.d.ts +11 -0
  304. package/dist/esm/word/po-to-flat.js +11 -0
  305. package/dist/esm/word/run-properties.d.ts +10 -0
  306. package/dist/esm/word/run-properties.js +10 -0
  307. package/dist/esm/word/settings-parser.d.ts +13 -0
  308. package/dist/esm/word/settings-parser.js +8 -0
  309. package/dist/esm/word/styles-parser.d.ts +10 -0
  310. package/dist/esm/word/styles-parser.js +10 -0
  311. package/dist/esm/word/table-parser.d.ts +11 -0
  312. package/dist/esm/word/table-parser.js +11 -0
  313. package/dist/esm/word/text-extractor.d.ts +9 -0
  314. package/dist/esm/word/xml-helpers.d.ts +44 -0
  315. package/dist/esm/word/xml-helpers.js +38 -0
  316. package/package.json +1 -1
@@ -11,6 +11,16 @@ function pad2(n) {
11
11
  function pdfDate(d) {
12
12
  return `D:${d.getUTCFullYear()}${pad2(d.getUTCMonth() + 1)}${pad2(d.getUTCDate())}${pad2(d.getUTCHours())}${pad2(d.getUTCMinutes())}${pad2(d.getUTCSeconds())}+00'00'`;
13
13
  }
14
+ /**
15
+ * Add an (invisible) signature field plus its signature dictionary to a document
16
+ * being built (§12.8). The dictionary carries placeholder `/ByteRange` and
17
+ * `/Contents` that {@link signPdf} fills later.
18
+ *
19
+ * @param ph The signature metadata and reserved-bytes size.
20
+ * @param pageRef The page the (zero-size) widget annotation belongs to.
21
+ * @returns The field ref (attach to the page's `/Annots`) and the `/AcroForm`
22
+ * dictionary (attach to the catalog).
23
+ */
14
24
  function addSignaturePlaceholder(doc, ph, pageRef) {
15
25
  const reserve = ph.reserveBytes ?? DEFAULT_RESERVE_BYTES;
16
26
  const sigEntries = {
@@ -78,6 +88,18 @@ function toHex(bytes) {
78
88
  for (const b of bytes) s += HEX[b >> 4] + HEX[b & 15];
79
89
  return s;
80
90
  }
91
+ /**
92
+ * Sign a PDF that already carries a signature placeholder (from
93
+ * {@link addSignaturePlaceholder}). Computes the real `/ByteRange`, hashes the
94
+ * covered bytes (SHA-256), builds the detached PKCS#7/CMS, and writes it into
95
+ * the reserved `/Contents` hole — leaving every other byte untouched.
96
+ *
97
+ * @param pdf The placeholder-bearing PDF bytes.
98
+ * @param cred The signer's certificate, key and algorithm.
99
+ * @returns A new byte array with the real ByteRange and signature spliced in.
100
+ * @throws Error when no placeholder is found, it is malformed, WebCrypto is
101
+ * unavailable, or the signature exceeds the reserved `/Contents` size.
102
+ */
81
103
  async function signPdf(pdf, cred) {
82
104
  const out = pdf.slice();
83
105
  const brKey = indexOfAscii(out, `/ByteRange ${BYTE_RANGE_PLACEHOLDER}`);
@@ -1,37 +1,101 @@
1
1
  import { PdfRef } from './objects.js';
2
2
  import { PdfDocument } from './writer.js';
3
+ /**
4
+ * Standard structure types (ISO 32000-1 Table 333/337). Every type here is
5
+ * recognised without a `/RoleMap`, so the builder never emits one.
6
+ */
3
7
  export type StructType = 'Document' | 'Part' | 'Sect' | 'H1' | 'H2' | 'H3' | 'H4' | 'H5' | 'H6' | 'P' | 'L' | 'LI' | 'Lbl' | 'LBody' | 'Table' | 'TR' | 'TH' | 'TD' | 'Caption' | 'Figure' | 'Link' | 'Note' | 'Span';
4
8
  interface Mcref {
5
9
  readonly pageIndex: number;
6
10
  readonly mcid: number;
7
11
  }
12
+ /** One node in the logical structure tree: a {@link StructType} plus its children, marked-content and attributes. */
8
13
  export declare class StructNode {
9
14
  readonly id: number;
10
15
  type: StructType;
11
16
  readonly children: Array<StructNode>;
12
17
  readonly mcrefs: Array<Mcref>;
18
+ /**
19
+ * §14.7.4.3 object references (`/OBJR` kids) — e.g. a Link element pointing at
20
+ * its link annotation. The annotation's own `/StructParent` entry is recorded
21
+ * via {@link StructTreeBuilder.addAnnotParent}.
22
+ */
13
23
  readonly objrs: Array<{
14
24
  readonly annotRef: PdfRef;
15
25
  readonly pageIndex: number;
16
26
  }>;
17
27
  parent: StructNode | null;
18
28
  ref: PdfRef | null;
29
+ /** Alternate text (`/Alt`, §14.9.4) — required on Figure for PDF/A-1a. */
19
30
  alt: string | null;
31
+ /** Natural language (`/Lang`) when it differs from the document default. */
20
32
  lang: string | null;
33
+ /**
34
+ * §14.8.5.2 Table attribute (emitted via a `/A` attribute object on the cell):
35
+ * `/Scope` on a TH (Row/Column) so assistive tech binds headers to data cells.
36
+ */
21
37
  scope: 'Row' | 'Column' | null;
38
+ /** §14.8.5.2 — `/ColSpan` when the cell spans more than one column (gridSpan). */
22
39
  colSpan: number | null;
40
+ /** §14.8.5.2 — `/RowSpan` when the cell spans more than one row (vertical merge). */
23
41
  rowSpan: number | null;
42
+ /**
43
+ * @param id The node's index, used for deterministic id assignment and `/ID`.
44
+ * @param type The structure type (mutable, so the renderer can retag).
45
+ */
24
46
  constructor(id: number, type: StructType);
25
47
  }
48
+ /**
49
+ * Builds the tagged-PDF logical structure tree (ISO 32000-1 §14.7–14.8): a
50
+ * `/StructTreeRoot` over a tree of {@link StructNode}s, tied back to page
51
+ * marked-content via MCRs and the `/ParentTree`. A generic emitter — the
52
+ * structure-type mapping policy lives in the renderer. Object ids are assigned by
53
+ * a deterministic pre-order DFS so identical input yields byte-identical output.
54
+ */
26
55
  export declare class StructTreeBuilder {
27
56
  private readonly nodes;
57
+ /** The root logical element (the single `/Document` under `/StructTreeRoot`). */
28
58
  readonly root: StructNode;
29
59
  constructor();
60
+ /**
61
+ * Create a node of `type` as the last child of `parent`.
62
+ *
63
+ * @param parent The parent node, or `null` for a free node (only the root is
64
+ * created that way).
65
+ * @returns The new node.
66
+ */
30
67
  create(type: StructType, parent: StructNode | null): StructNode;
68
+ /**
69
+ * Look up a node by its id.
70
+ *
71
+ * @throws Error if no node has that id.
72
+ */
31
73
  node(id: number): StructNode;
74
+ /**
75
+ * Record that marked content `mcid` on page `pageIndex` is the content of node
76
+ * `nodeId`. Called from the emit phase as MCIDs are assigned.
77
+ */
32
78
  addMcref(nodeId: number, pageIndex: number, mcid: number): void;
79
+ /**
80
+ * §14.7.4.4: an annotation's `/StructParent` key maps DIRECTLY to its owning
81
+ * `/StructElem` in the parent tree (a scalar entry, unlike the per-page MCID
82
+ * arrays). The emit phase allocates keys above the page indices.
83
+ */
33
84
  private readonly annotParents;
85
+ /**
86
+ * Register that annotation parent-tree key `key` resolves to node `nodeId`.
87
+ *
88
+ * @see StructTreeBuilder.annotParents
89
+ */
34
90
  addAnnotParent(key: number, nodeId: number): void;
91
+ /**
92
+ * Emit the `/StructTreeRoot`, every `/StructElem`, and the `/ParentTree`. Must
93
+ * run after all pages are added (so `pageRefs` is complete) and after every
94
+ * {@link StructTreeBuilder.addMcref} call.
95
+ *
96
+ * @param pageRefs The page object references, indexed by page number.
97
+ * @returns A reference to the `/StructTreeRoot`, for the catalog.
98
+ */
35
99
  emit(doc: PdfDocument, pageRefs: ReadonlyArray<PdfRef>): PdfRef;
36
100
  }
37
101
  export {};
@@ -1,27 +1,60 @@
1
1
  import { PDF_NULL, dict, name, unicodeString } from "./objects.js";
2
2
  //#region src/pdf/struct-tree.ts
3
+ /** One node in the logical structure tree: a {@link StructType} plus its children, marked-content and attributes. */
3
4
  var StructNode = class {
4
5
  children = [];
5
6
  mcrefs = [];
7
+ /**
8
+ * §14.7.4.3 object references (`/OBJR` kids) — e.g. a Link element pointing at
9
+ * its link annotation. The annotation's own `/StructParent` entry is recorded
10
+ * via {@link StructTreeBuilder.addAnnotParent}.
11
+ */
6
12
  objrs = [];
7
13
  parent = null;
8
14
  ref = null;
15
+ /** Alternate text (`/Alt`, §14.9.4) — required on Figure for PDF/A-1a. */
9
16
  alt = null;
17
+ /** Natural language (`/Lang`) when it differs from the document default. */
10
18
  lang = null;
19
+ /**
20
+ * §14.8.5.2 Table attribute (emitted via a `/A` attribute object on the cell):
21
+ * `/Scope` on a TH (Row/Column) so assistive tech binds headers to data cells.
22
+ */
11
23
  scope = null;
24
+ /** §14.8.5.2 — `/ColSpan` when the cell spans more than one column (gridSpan). */
12
25
  colSpan = null;
26
+ /** §14.8.5.2 — `/RowSpan` when the cell spans more than one row (vertical merge). */
13
27
  rowSpan = null;
28
+ /**
29
+ * @param id The node's index, used for deterministic id assignment and `/ID`.
30
+ * @param type The structure type (mutable, so the renderer can retag).
31
+ */
14
32
  constructor(id, type) {
15
33
  this.id = id;
16
34
  this.type = type;
17
35
  }
18
36
  };
37
+ /**
38
+ * Builds the tagged-PDF logical structure tree (ISO 32000-1 §14.7–14.8): a
39
+ * `/StructTreeRoot` over a tree of {@link StructNode}s, tied back to page
40
+ * marked-content via MCRs and the `/ParentTree`. A generic emitter — the
41
+ * structure-type mapping policy lives in the renderer. Object ids are assigned by
42
+ * a deterministic pre-order DFS so identical input yields byte-identical output.
43
+ */
19
44
  var StructTreeBuilder = class {
20
45
  nodes = [];
46
+ /** The root logical element (the single `/Document` under `/StructTreeRoot`). */
21
47
  root;
22
48
  constructor() {
23
49
  this.root = this.create("Document", null);
24
50
  }
51
+ /**
52
+ * Create a node of `type` as the last child of `parent`.
53
+ *
54
+ * @param parent The parent node, or `null` for a free node (only the root is
55
+ * created that way).
56
+ * @returns The new node.
57
+ */
25
58
  create(type, parent) {
26
59
  const node = new StructNode(this.nodes.length, type);
27
60
  node.parent = parent;
@@ -29,24 +62,51 @@ var StructTreeBuilder = class {
29
62
  this.nodes.push(node);
30
63
  return node;
31
64
  }
65
+ /**
66
+ * Look up a node by its id.
67
+ *
68
+ * @throws Error if no node has that id.
69
+ */
32
70
  node(id) {
33
71
  const n = this.nodes[id];
34
72
  if (!n) throw new Error(`Unknown struct node id ${id}`);
35
73
  return n;
36
74
  }
75
+ /**
76
+ * Record that marked content `mcid` on page `pageIndex` is the content of node
77
+ * `nodeId`. Called from the emit phase as MCIDs are assigned.
78
+ */
37
79
  addMcref(nodeId, pageIndex, mcid) {
38
80
  this.node(nodeId).mcrefs.push({
39
81
  pageIndex,
40
82
  mcid
41
83
  });
42
84
  }
85
+ /**
86
+ * §14.7.4.4: an annotation's `/StructParent` key maps DIRECTLY to its owning
87
+ * `/StructElem` in the parent tree (a scalar entry, unlike the per-page MCID
88
+ * arrays). The emit phase allocates keys above the page indices.
89
+ */
43
90
  annotParents = [];
91
+ /**
92
+ * Register that annotation parent-tree key `key` resolves to node `nodeId`.
93
+ *
94
+ * @see StructTreeBuilder.annotParents
95
+ */
44
96
  addAnnotParent(key, nodeId) {
45
97
  this.annotParents.push({
46
98
  key,
47
99
  nodeId
48
100
  });
49
101
  }
102
+ /**
103
+ * Emit the `/StructTreeRoot`, every `/StructElem`, and the `/ParentTree`. Must
104
+ * run after all pages are added (so `pageRefs` is complete) and after every
105
+ * {@link StructTreeBuilder.addMcref} call.
106
+ *
107
+ * @param pageRefs The page object references, indexed by page number.
108
+ * @returns A reference to the `/StructTreeRoot`, for the catalog.
109
+ */
50
110
  emit(doc, pageRefs) {
51
111
  const order = [];
52
112
  const walk = (n) => {
@@ -2,12 +2,45 @@ import { LaidOutPdfDocument, StyledRenderOptions } from '../layout/styled-layout
2
2
  import { PdfDocument } from './writer.js';
3
3
  import { PdfEncryptOptions } from './encryption.js';
4
4
  type EmitOptions = Pick<StyledRenderOptions, 'attachments' | 'info' | 'language' | 'pdfUA' | 'signaturePlaceholder'>;
5
+ /**
6
+ * The emit phase: turn a laid-out document into PDF objects (ISO 32000) and
7
+ * serialize it. The counterpart of `layoutStyledDocument` (the seam of
8
+ * ir-design §7 / oop-design §4.1); it sees only the laid-out document plus the
9
+ * output-side options, never the layout options. Fonts and images embed first
10
+ * (the object order the pre-split renderer produced), pages replay their
11
+ * `PageItem`s, then the catalog assembles the OutputIntent / XMP / struct-tree /
12
+ * attachments as required.
13
+ *
14
+ * @returns The serialized PDF bytes.
15
+ */
5
16
  export declare function emitStyledPdf(laid: LaidOutPdfDocument, options: EmitOptions, doc: PdfDocument): Uint8Array;
17
+ /**
18
+ * The encrypted build (ISO 32000 §7.6): assemble as usual, encrypt every
19
+ * collected object with the derived file key, then add the (plaintext)
20
+ * `/Encrypt` dictionary and emit with a file `/ID`. Asynchronous because
21
+ * WebCrypto is.
22
+ *
23
+ * @param encrypt The encryption parameters (handler revision, permissions,
24
+ * passwords) used to prepare the file key and `/Encrypt` dict.
25
+ * @returns The serialized, encrypted PDF bytes.
26
+ */
6
27
  export declare function emitStyledPdfEncrypted(laid: LaidOutPdfDocument, options: EmitOptions, doc: PdfDocument, encrypt: PdfEncryptOptions): Promise<Uint8Array>;
28
+ /**
29
+ * Per-page tagging state threaded into `emitPageContent` when emitting a tagged
30
+ * PDF (ISO 32000-1 §14.7).
31
+ */
7
32
  export interface PageTagging {
33
+ /** The running MCID counter, reset per page. */
8
34
  next: number;
35
+ /** Whether any tagged marked content was emitted (so the page gets `/StructParents`). */
9
36
  assigned: boolean;
37
+ /** Tie an assigned MCID back to its structure node. */
10
38
  record: (structId: number, mcid: number) => void;
39
+ /**
40
+ * The marked-content tag for a structure node — its structure type, so the
41
+ * `BDC` tag matches the `StructElem` `/S` (§14.7.2: a heading is `/H1`, a
42
+ * cell's paragraph `/P`, …), not a hardcoded `/P`.
43
+ */
11
44
  tagFor: (structId: number) => string;
12
45
  }
13
46
  export {};
@@ -15,10 +15,31 @@ import { addSignaturePlaceholder } from "./signature.js";
15
15
  import { buildXmpPacket } from "./xmp.js";
16
16
  //#region src/pdf/styled-page-emitter.ts
17
17
  var encoder = new TextEncoder();
18
+ /**
19
+ * The emit phase: turn a laid-out document into PDF objects (ISO 32000) and
20
+ * serialize it. The counterpart of `layoutStyledDocument` (the seam of
21
+ * ir-design §7 / oop-design §4.1); it sees only the laid-out document plus the
22
+ * output-side options, never the layout options. Fonts and images embed first
23
+ * (the object order the pre-split renderer produced), pages replay their
24
+ * `PageItem`s, then the catalog assembles the OutputIntent / XMP / struct-tree /
25
+ * attachments as required.
26
+ *
27
+ * @returns The serialized PDF bytes.
28
+ */
18
29
  function emitStyledPdf(laid, options, doc) {
19
30
  const a = assembleStyledPdf(laid, options, doc);
20
31
  return doc.build(a.catalogRef, a.infoRef, a.buildOptions);
21
32
  }
33
+ /**
34
+ * The encrypted build (ISO 32000 §7.6): assemble as usual, encrypt every
35
+ * collected object with the derived file key, then add the (plaintext)
36
+ * `/Encrypt` dictionary and emit with a file `/ID`. Asynchronous because
37
+ * WebCrypto is.
38
+ *
39
+ * @param encrypt The encryption parameters (handler revision, permissions,
40
+ * passwords) used to prepare the file key and `/Encrypt` dict.
41
+ * @returns The serialized, encrypted PDF bytes.
42
+ */
22
43
  async function emitStyledPdfEncrypted(laid, options, doc, encrypt) {
23
44
  const a = assembleStyledPdf(laid, options, doc);
24
45
  const prepared = await preparePdfEncryption(encrypt);
@@ -1,6 +1,24 @@
1
1
  import { BodyElement } from '../core/document-model/index.js';
2
2
  import { StyledRenderOptions } from '../layout/styled-layout.js';
3
+ /**
4
+ * Render a body to a PDF: lay it out, then emit it over a fresh
5
+ * {@link PdfDocument}. The byte-stable synchronous path.
6
+ *
7
+ * @throws Error when `options.encrypt` is set — encryption requires the async
8
+ * {@link renderStyledPdfEncrypted} path (WebCrypto).
9
+ */
3
10
  export declare function renderStyledPdf(body: ReadonlyArray<BodyElement>, options: StyledRenderOptions): Uint8Array;
11
+ /**
12
+ * The encrypting variant of {@link renderStyledPdf} (ISO 32000 §7.6; async
13
+ * because WebCrypto is). Validates the standing conflicts here so every
14
+ * converter shares them: PDF/A forbids `/Encrypt` (ISO 19005), signatures +
15
+ * encryption is out of scope in v1, and PDF/UA requires assistive technology to
16
+ * keep extraction access (bit 10, forced on here). With no `options.encrypt` it
17
+ * falls through to the plain {@link renderStyledPdf}.
18
+ *
19
+ * @throws Error when `options.pdfA` is set (PDF/A forbids encryption) or when a
20
+ * signature placeholder is combined with encryption.
21
+ */
4
22
  export declare function renderStyledPdfEncrypted(body: ReadonlyArray<BodyElement>, options: StyledRenderOptions): Promise<Uint8Array>;
5
23
  export * from '../layout/page-doc.js';
6
24
  export * from '../layout/styled-layout.js';
@@ -3,10 +3,28 @@ import { layoutStyledDocument } from "../layout/styled-layout.js";
3
3
  import "../layout/page-doc.js";
4
4
  import { emitStyledPdf, emitStyledPdfEncrypted } from "./styled-page-emitter.js";
5
5
  //#region src/pdf/styled-page-renderer.ts
6
+ /**
7
+ * Render a body to a PDF: lay it out, then emit it over a fresh
8
+ * {@link PdfDocument}. The byte-stable synchronous path.
9
+ *
10
+ * @throws Error when `options.encrypt` is set — encryption requires the async
11
+ * {@link renderStyledPdfEncrypted} path (WebCrypto).
12
+ */
6
13
  function renderStyledPdf(body, options) {
7
14
  if (options.encrypt) throw new Error("PDF encryption requires the async conversion path (WebCrypto)");
8
15
  return emitStyledPdf(layoutStyledDocument(body, options), options, new PdfDocument());
9
16
  }
17
+ /**
18
+ * The encrypting variant of {@link renderStyledPdf} (ISO 32000 §7.6; async
19
+ * because WebCrypto is). Validates the standing conflicts here so every
20
+ * converter shares them: PDF/A forbids `/Encrypt` (ISO 19005), signatures +
21
+ * encryption is out of scope in v1, and PDF/UA requires assistive technology to
22
+ * keep extraction access (bit 10, forced on here). With no `options.encrypt` it
23
+ * falls through to the plain {@link renderStyledPdf}.
24
+ *
25
+ * @throws Error when `options.pdfA` is set (PDF/A forbids encryption) or when a
26
+ * signature placeholder is combined with encryption.
27
+ */
10
28
  async function renderStyledPdfEncrypted(body, options) {
11
29
  const encrypt = options.encrypt;
12
30
  if (!encrypt) return renderStyledPdf(body, options);
@@ -1,2 +1,18 @@
1
+ /**
2
+ * Encode text as WinAnsiEncoding (CP-1252) bytes (ISO 32000-1 §D.2). Latin-1 is
3
+ * passed through; the CP-1252 high range (smart quotes, dashes, €, …) is
4
+ * remapped; anything else becomes `?`.
5
+ *
6
+ * @param text The string to encode.
7
+ * @returns One byte per code point.
8
+ */
1
9
  export declare function encodeWinAnsi(text: string): Uint8Array;
10
+ /**
11
+ * Encode text as a PDF literal string body (ISO 32000-1 §7.3.4.2): WinAnsi
12
+ * bytes with `(`, `)` and `\` backslash-escaped. The result is ready to be
13
+ * wrapped in `(` … `)` within a content stream.
14
+ *
15
+ * @param text The string to encode.
16
+ * @returns The escaped bytes (without the surrounding parentheses).
17
+ */
2
18
  export declare function encodeLiteralBytes(text: string): Uint8Array;
@@ -1,7 +1,9 @@
1
1
  import { ParsedTtf } from '../core/font/index.js';
2
+ /** A font for {@link renderPlainTextPdf}: an already-parsed TTF or its raw bytes. */
2
3
  export type FontInput = ParsedTtf | {
3
4
  readonly bytes: Uint8Array;
4
5
  };
6
+ /** Options for {@link renderPlainTextPdf}; every layout dimension defaults (A4, 72pt margins, 12pt text). */
5
7
  export interface TextRenderOptions {
6
8
  readonly font: FontInput;
7
9
  readonly pageWidth?: number;
@@ -11,6 +13,15 @@ export interface TextRenderOptions {
11
13
  readonly marginTop?: number;
12
14
  readonly marginBottom?: number;
13
15
  readonly fontSize?: number;
16
+ /** Baseline-to-baseline distance in points; defaults to `1.2 × fontSize`. */
14
17
  readonly lineHeight?: number;
15
18
  }
19
+ /**
20
+ * Render plain-text paragraphs to a single-font PDF, paginating greedily with
21
+ * real TTF metrics and embedding the subset font.
22
+ *
23
+ * @param paragraphs One string per paragraph; empty strings become blank lines.
24
+ * @param options The font plus optional page geometry and type size.
25
+ * @returns The encoded PDF bytes.
26
+ */
16
27
  export declare function renderPlainTextPdf(paragraphs: ReadonlyArray<string>, options: TextRenderOptions): Uint8Array;
@@ -1,4 +1,16 @@
1
1
  import { VectorShape } from '../core/vector.js';
2
2
  export type { PathSegment, StrokeStyle, VectorPath, VectorShape } from '../core/vector.js';
3
3
  export { PathBuilder } from '../core/vector.js';
4
+ /**
5
+ * Emit a {@link VectorShape} as PDF content-stream operators (ISO 32000 §8.5),
6
+ * wrapped in a `q`/`Q` save-restore with the shape's transform as the CTM. The
7
+ * subpaths are painted with a single operator, so the winding rule is decided
8
+ * once (even-odd if any subpath asks).
9
+ *
10
+ * @param shape The shape to draw.
11
+ * @param patternName When set, the fill is this named shading pattern from the
12
+ * page's `/Pattern` resources (a gradient, EP16b) rather than a solid colour;
13
+ * only used if the shape actually carries a `fillGradient`.
14
+ * @returns The content-stream operator lines.
15
+ */
4
16
  export declare function emitVectorShape(shape: VectorShape, patternName?: string): Array<string>;
@@ -1,5 +1,17 @@
1
1
  import "../core/vector.js";
2
2
  //#region src/pdf/vector-graphics.ts
3
+ /**
4
+ * Emit a {@link VectorShape} as PDF content-stream operators (ISO 32000 §8.5),
5
+ * wrapped in a `q`/`Q` save-restore with the shape's transform as the CTM. The
6
+ * subpaths are painted with a single operator, so the winding rule is decided
7
+ * once (even-odd if any subpath asks).
8
+ *
9
+ * @param shape The shape to draw.
10
+ * @param patternName When set, the fill is this named shading pattern from the
11
+ * page's `/Pattern` resources (a gradient, EP16b) rather than a solid colour;
12
+ * only used if the shape actually carries a `fillGradient`.
13
+ * @returns The content-stream operator lines.
14
+ */
3
15
  function emitVectorShape(shape, patternName) {
4
16
  const out = [];
5
17
  out.push("q");
@@ -1,12 +1,51 @@
1
1
  import { PdfValue, PdfRef } from './objects.js';
2
+ /** Options for {@link PdfDocument.build}. */
2
3
  export interface BuildOptions {
4
+ /** PDF header version, e.g. `"1.7"` (default) or `"1.4"` (PDF/A-1). */
3
5
  readonly version?: string;
6
+ /**
7
+ * When true, emit a `/ID` array in the trailer (required by PDF/A). The two
8
+ * identifiers are a deterministic hash of the file body — no `Date`/random,
9
+ * so the same input always yields the same bytes.
10
+ */
4
11
  readonly id?: boolean;
12
+ /**
13
+ * The `/Encrypt` dictionary's ref (§7.6.2) — emitted in the trailer. The
14
+ * referenced object must be added AFTER {@link PdfDocument.encryptAll} so it
15
+ * stays plaintext.
16
+ */
5
17
  readonly encrypt?: PdfRef;
6
18
  }
19
+ /**
20
+ * Collects indirect objects and emits a complete PDF file (ISO 32000-1 §7.5):
21
+ * header (§7.5.2), body of indirect objects (§7.5.3), cross-reference table
22
+ * (§7.5.4) and trailer (§7.5.5).
23
+ */
7
24
  export declare class PdfDocument {
8
25
  private readonly objects;
26
+ /**
27
+ * Append `value` as a new indirect object.
28
+ *
29
+ * @param value The object to add.
30
+ * @returns An indirect reference to it (generation 0).
31
+ */
9
32
  add(value: PdfValue): PdfRef;
33
+ /**
34
+ * Encrypt every string and stream in every object added so far (§7.6). The
35
+ * `/Encrypt` dictionary itself must be added AFTER this pass so it stays
36
+ * plaintext.
37
+ *
38
+ * @param fileKey The document encryption key.
39
+ */
10
40
  encryptAll(fileKey: Uint8Array): Promise<void>;
41
+ /**
42
+ * Serialize the whole document to bytes: header, body, cross-reference table
43
+ * and trailer.
44
+ *
45
+ * @param root Reference to the document catalog (`/Root`).
46
+ * @param info Optional reference to the `/Info` dictionary.
47
+ * @param options Header version, `/ID` emission, and `/Encrypt` reference.
48
+ * @returns The complete PDF file bytes.
49
+ */
11
50
  build(root: PdfRef, info?: PdfRef, options?: BuildOptions): Uint8Array;
12
51
  }
@@ -11,8 +11,19 @@ var BINARY_MARKER = new Uint8Array([
11
11
  211,
12
12
  10
13
13
  ]);
14
+ /**
15
+ * Collects indirect objects and emits a complete PDF file (ISO 32000-1 §7.5):
16
+ * header (§7.5.2), body of indirect objects (§7.5.3), cross-reference table
17
+ * (§7.5.4) and trailer (§7.5.5).
18
+ */
14
19
  var PdfDocument = class {
15
20
  objects = [];
21
+ /**
22
+ * Append `value` as a new indirect object.
23
+ *
24
+ * @param value The object to add.
25
+ * @returns An indirect reference to it (generation 0).
26
+ */
16
27
  add(value) {
17
28
  const id = this.objects.length + 1;
18
29
  this.objects.push({
@@ -21,9 +32,25 @@ var PdfDocument = class {
21
32
  });
22
33
  return new PdfRef(id);
23
34
  }
35
+ /**
36
+ * Encrypt every string and stream in every object added so far (§7.6). The
37
+ * `/Encrypt` dictionary itself must be added AFTER this pass so it stays
38
+ * plaintext.
39
+ *
40
+ * @param fileKey The document encryption key.
41
+ */
24
42
  async encryptAll(fileKey) {
25
43
  for (const obj of this.objects) obj.value = await encryptObjectGraph(obj.value, fileKey);
26
44
  }
45
+ /**
46
+ * Serialize the whole document to bytes: header, body, cross-reference table
47
+ * and trailer.
48
+ *
49
+ * @param root Reference to the document catalog (`/Root`).
50
+ * @param info Optional reference to the `/Info` dictionary.
51
+ * @param options Header version, `/ID` emission, and `/Encrypt` reference.
52
+ * @returns The complete PDF file bytes.
53
+ */
27
54
  build(root, info, options = {}) {
28
55
  const parts = [];
29
56
  const offsets = new Array(this.objects.length + 1).fill(0);
@@ -1,14 +1,30 @@
1
+ /** The document metadata projected into an XMP packet by {@link buildXmpPacket}. */
1
2
  export interface XmpInput {
2
3
  readonly title?: string;
3
4
  readonly author?: string;
4
5
  readonly subject?: string;
5
6
  readonly keywords?: string;
7
+ /** Application that created the doc (`xmp:CreatorTool`). */
6
8
  readonly creator?: string;
7
9
  readonly producer?: string;
8
10
  readonly createDate?: Date;
9
11
  readonly modifyDate?: Date;
12
+ /**
13
+ * PDF/A identifier: part 1 (ISO 19005-1) / 2 / 3; conformance level
14
+ * `'A'` (tagged) / `'B'` (visual) / `'U'` (Unicode — parts 2/3 only).
15
+ */
10
16
  readonly pdfaPart?: '1' | '2' | '3';
17
+ /** PDF/UA identification (ISO 14289-1) — `pdfuaid:part`. */
11
18
  readonly pdfuaPart?: '1';
12
19
  readonly pdfaConformance?: 'A' | 'B' | 'U';
13
20
  }
21
+ /**
22
+ * Build an XMP metadata packet (ISO 16684-1) for the document `/Metadata`
23
+ * stream, emitting only the sections the supplied {@link XmpInput} populates
24
+ * (PDF/A and PDF/UA identifiers, Dublin Core, XMP basic, Adobe PDF). For PDF/A
25
+ * the standard properties must agree with the `/Info` dictionary.
26
+ *
27
+ * @param input The metadata to project.
28
+ * @returns The UTF-8 encoded XMP packet bytes.
29
+ */
14
30
  export declare function buildXmpPacket(input: XmpInput): Uint8Array;
@@ -6,6 +6,15 @@ function xmpDate(d) {
6
6
  const pad = (n, w = 2) => String(n).padStart(w, "0");
7
7
  return `${pad(d.getUTCFullYear(), 4)}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}T${pad(d.getUTCHours())}:${pad(d.getUTCMinutes())}:${pad(d.getUTCSeconds())}Z`;
8
8
  }
9
+ /**
10
+ * Build an XMP metadata packet (ISO 16684-1) for the document `/Metadata`
11
+ * stream, emitting only the sections the supplied {@link XmpInput} populates
12
+ * (PDF/A and PDF/UA identifiers, Dublin Core, XMP basic, Adobe PDF). For PDF/A
13
+ * the standard properties must agree with the `/Info` dictionary.
14
+ *
15
+ * @param input The metadata to project.
16
+ * @returns The UTF-8 encoded XMP packet bytes.
17
+ */
9
18
  function buildXmpPacket(input) {
10
19
  const props = [];
11
20
  if (input.pdfaPart) props.push(` <rdf:Description rdf:about="" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/">`, ` <pdfaid:part>${input.pdfaPart}</pdfaid:part>`, ` <pdfaid:conformance>${input.pdfaConformance ?? "B"}</pdfaid:conformance>`, ` </rdf:Description>`);
@@ -1,14 +1,39 @@
1
+ /**
2
+ * The `/CCITTFaxDecode` parameters that drive {@link decodeCcitt} (ISO 32000-1
3
+ * §7.4.6), pulled from the filter's `/DecodeParms`.
4
+ */
1
5
  export interface CcittParams {
6
+ /** `/K` — `<0` Group 4, `0` Group 3 1-D, `>0` Group 3 2-D (unsupported). */
2
7
  readonly k: number;
8
+ /** `/Columns` (pixels per row). */
3
9
  readonly columns: number;
10
+ /** `/Rows` (or the image `/Height`) — the row count to decode. */
4
11
  readonly rows: number;
12
+ /** `/EncodedByteAlign` — pad each row to a byte boundary. */
5
13
  readonly byteAlign: boolean;
6
14
  }
15
+ /**
16
+ * Decode a CCITT Group 3 / Group 4 fax stream into a packed 1-bit-per-pixel
17
+ * bitmap.
18
+ *
19
+ * @param data The raw fax codestream (any wrapping filters already stripped).
20
+ * @param params The `/CCITTFaxDecode` parameters.
21
+ * @returns The packed bitmap (`rowBytes × rows`, bit 1 = black, MSB first), or
22
+ * `undefined` when the stream cannot be decoded (e.g. Group 3 2-D, or nothing
23
+ * decoded at all).
24
+ */
7
25
  export declare function decodeCcitt(data: Uint8Array, params: CcittParams): Uint8Array | undefined;
26
+ /** A decoded T.6 two-dimensional mode code: pass, horizontal, or vertical V(d). */
8
27
  export interface Mode {
9
28
  readonly kind: 'pass' | 'horizontal' | 'vertical';
29
+ /** Vertical offset (−3..3); meaningful only when `kind` is `'vertical'`. */
10
30
  readonly d: number;
11
31
  }
32
+ /**
33
+ * T.4 white-run modified-Huffman codes as `[run, bit-string]` (terminating runs
34
+ * 0..63, make-up runs multiples of 64). Exported so the test can build an
35
+ * independent encoder and validate the codes form a valid prefix set.
36
+ */
12
37
  export declare const WHITE_CODES: ReadonlyArray<readonly [number, string]>;
13
38
  export declare const BLACK_CODES: ReadonlyArray<readonly [number, string]>;
14
39
  export declare const SHARED_MAKEUP: ReadonlyArray<readonly [number, string]>;