@pdfme/pdf-lib 1.17.3 → 1.18.3

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 (1475) hide show
  1. package/README.md +43 -23
  2. package/cjs/api/PDFDocument.d.ts +11 -11
  3. package/cjs/api/PDFDocument.d.ts.map +1 -1
  4. package/cjs/api/PDFDocument.js +368 -539
  5. package/cjs/api/PDFDocument.js.map +1 -1
  6. package/cjs/api/PDFDocumentOptions.d.ts +3 -2
  7. package/cjs/api/PDFDocumentOptions.d.ts.map +1 -1
  8. package/cjs/api/PDFEmbeddedFile.d.ts +4 -4
  9. package/cjs/api/PDFEmbeddedFile.d.ts.map +1 -1
  10. package/cjs/api/PDFEmbeddedFile.js +48 -63
  11. package/cjs/api/PDFEmbeddedFile.js.map +1 -1
  12. package/cjs/api/PDFEmbeddedPage.d.ts +3 -3
  13. package/cjs/api/PDFEmbeddedPage.d.ts.map +1 -1
  14. package/cjs/api/PDFEmbeddedPage.js +34 -47
  15. package/cjs/api/PDFEmbeddedPage.js.map +1 -1
  16. package/cjs/api/PDFFont.d.ts +3 -3
  17. package/cjs/api/PDFFont.d.ts.map +1 -1
  18. package/cjs/api/PDFFont.js +46 -58
  19. package/cjs/api/PDFFont.js.map +1 -1
  20. package/cjs/api/PDFImage.d.ts +3 -3
  21. package/cjs/api/PDFImage.d.ts.map +1 -1
  22. package/cjs/api/PDFImage.js +49 -63
  23. package/cjs/api/PDFImage.js.map +1 -1
  24. package/cjs/api/PDFJavaScript.d.ts +4 -4
  25. package/cjs/api/PDFJavaScript.d.ts.map +1 -1
  26. package/cjs/api/PDFJavaScript.js +37 -52
  27. package/cjs/api/PDFJavaScript.js.map +1 -1
  28. package/cjs/api/PDFPage.d.ts +21 -9
  29. package/cjs/api/PDFPage.d.ts.map +1 -1
  30. package/cjs/api/PDFPage.js +447 -426
  31. package/cjs/api/PDFPage.js.map +1 -1
  32. package/cjs/api/PDFPageOptions.d.ts +29 -12
  33. package/cjs/api/PDFPageOptions.d.ts.map +1 -1
  34. package/cjs/api/PDFPageOptions.js.map +1 -1
  35. package/cjs/api/colors.d.ts +4 -0
  36. package/cjs/api/colors.d.ts.map +1 -1
  37. package/cjs/api/colors.js +52 -43
  38. package/cjs/api/colors.js.map +1 -1
  39. package/cjs/api/errors.js +73 -130
  40. package/cjs/api/errors.js.map +1 -1
  41. package/cjs/api/form/PDFButton.d.ts +8 -8
  42. package/cjs/api/form/PDFButton.d.ts.map +1 -1
  43. package/cjs/api/form/PDFButton.js +68 -72
  44. package/cjs/api/form/PDFButton.js.map +1 -1
  45. package/cjs/api/form/PDFCheckBox.d.ts +5 -5
  46. package/cjs/api/form/PDFCheckBox.d.ts.map +1 -1
  47. package/cjs/api/form/PDFCheckBox.js +64 -69
  48. package/cjs/api/form/PDFCheckBox.js.map +1 -1
  49. package/cjs/api/form/PDFDropdown.d.ts +6 -6
  50. package/cjs/api/form/PDFDropdown.d.ts.map +1 -1
  51. package/cjs/api/form/PDFDropdown.js +126 -132
  52. package/cjs/api/form/PDFDropdown.js.map +1 -1
  53. package/cjs/api/form/PDFField.d.ts +6 -6
  54. package/cjs/api/form/PDFField.d.ts.map +1 -1
  55. package/cjs/api/form/PDFField.js +118 -123
  56. package/cjs/api/form/PDFField.js.map +1 -1
  57. package/cjs/api/form/PDFForm.d.ts +11 -11
  58. package/cjs/api/form/PDFForm.d.ts.map +1 -1
  59. package/cjs/api/form/PDFForm.js +218 -217
  60. package/cjs/api/form/PDFForm.js.map +1 -1
  61. package/cjs/api/form/PDFOptionList.d.ts +6 -6
  62. package/cjs/api/form/PDFOptionList.d.ts.map +1 -1
  63. package/cjs/api/form/PDFOptionList.js +115 -121
  64. package/cjs/api/form/PDFOptionList.js.map +1 -1
  65. package/cjs/api/form/PDFRadioGroup.d.ts +5 -5
  66. package/cjs/api/form/PDFRadioGroup.d.ts.map +1 -1
  67. package/cjs/api/form/PDFRadioGroup.js +98 -101
  68. package/cjs/api/form/PDFRadioGroup.js.map +1 -1
  69. package/cjs/api/form/PDFSignature.d.ts +3 -3
  70. package/cjs/api/form/PDFSignature.d.ts.map +1 -1
  71. package/cjs/api/form/PDFSignature.js +25 -28
  72. package/cjs/api/form/PDFSignature.js.map +1 -1
  73. package/cjs/api/form/PDFTextField.d.ts +8 -8
  74. package/cjs/api/form/PDFTextField.d.ts.map +1 -1
  75. package/cjs/api/form/PDFTextField.js +136 -141
  76. package/cjs/api/form/PDFTextField.js.map +1 -1
  77. package/cjs/api/form/appearances.d.ts +11 -11
  78. package/cjs/api/form/appearances.d.ts.map +1 -1
  79. package/cjs/api/form/appearances.js +297 -219
  80. package/cjs/api/form/appearances.js.map +1 -1
  81. package/cjs/api/form/index.d.ts +10 -10
  82. package/cjs/api/form/index.d.ts.map +1 -1
  83. package/cjs/api/form/index.js +12 -11
  84. package/cjs/api/form/index.js.map +1 -1
  85. package/cjs/api/image/index.d.ts +1 -1
  86. package/cjs/api/image/index.d.ts.map +1 -1
  87. package/cjs/api/image/index.js +2 -2
  88. package/cjs/api/image/index.js.map +1 -1
  89. package/cjs/api/index.d.ts +20 -20
  90. package/cjs/api/index.d.ts.map +1 -1
  91. package/cjs/api/index.js +21 -20
  92. package/cjs/api/index.js.map +1 -1
  93. package/cjs/api/objects.d.ts +1 -1
  94. package/cjs/api/objects.d.ts.map +1 -1
  95. package/cjs/api/objects.js +7 -10
  96. package/cjs/api/objects.js.map +1 -1
  97. package/cjs/api/operations.d.ts +20 -4
  98. package/cjs/api/operations.d.ts.map +1 -1
  99. package/cjs/api/operations.js +383 -347
  100. package/cjs/api/operations.js.map +1 -1
  101. package/cjs/api/operators.d.ts +6 -1
  102. package/cjs/api/operators.d.ts.map +1 -1
  103. package/cjs/api/operators.js +169 -183
  104. package/cjs/api/operators.js.map +1 -1
  105. package/cjs/api/rotations.d.ts +1 -1
  106. package/cjs/api/rotations.d.ts.map +1 -1
  107. package/cjs/api/rotations.js +31 -30
  108. package/cjs/api/rotations.js.map +1 -1
  109. package/cjs/api/svg.d.ts +71 -0
  110. package/cjs/api/svg.d.ts.map +1 -0
  111. package/cjs/api/svg.js +654 -0
  112. package/cjs/api/svg.js.map +1 -0
  113. package/cjs/api/svgPath.d.ts +1 -1
  114. package/cjs/api/svgPath.d.ts.map +1 -1
  115. package/cjs/api/svgPath.js +115 -118
  116. package/cjs/api/svgPath.js.map +1 -1
  117. package/cjs/api/text/index.d.ts +2 -2
  118. package/cjs/api/text/index.d.ts.map +1 -1
  119. package/cjs/api/text/index.js +3 -3
  120. package/cjs/api/text/index.js.map +1 -1
  121. package/cjs/api/text/layout.d.ts +3 -3
  122. package/cjs/api/text/layout.d.ts.map +1 -1
  123. package/cjs/api/text/layout.js +87 -88
  124. package/cjs/api/text/layout.js.map +1 -1
  125. package/cjs/core/PDFContext.d.ts +17 -16
  126. package/cjs/core/PDFContext.d.ts.map +1 -1
  127. package/cjs/core/PDFContext.js +93 -101
  128. package/cjs/core/PDFContext.js.map +1 -1
  129. package/cjs/core/PDFObjectCopier.d.ts +2 -2
  130. package/cjs/core/PDFObjectCopier.d.ts.map +1 -1
  131. package/cjs/core/PDFObjectCopier.js +58 -62
  132. package/cjs/core/PDFObjectCopier.js.map +1 -1
  133. package/cjs/core/acroform/PDFAcroButton.d.ts +7 -7
  134. package/cjs/core/acroform/PDFAcroButton.d.ts.map +1 -1
  135. package/cjs/core/acroform/PDFAcroButton.js +42 -47
  136. package/cjs/core/acroform/PDFAcroButton.js.map +1 -1
  137. package/cjs/core/acroform/PDFAcroCheckBox.d.ts +5 -5
  138. package/cjs/core/acroform/PDFAcroCheckBox.d.ts.map +1 -1
  139. package/cjs/core/acroform/PDFAcroCheckBox.js +28 -35
  140. package/cjs/core/acroform/PDFAcroCheckBox.js.map +1 -1
  141. package/cjs/core/acroform/PDFAcroChoice.d.ts +4 -4
  142. package/cjs/core/acroform/PDFAcroChoice.d.ts.map +1 -1
  143. package/cjs/core/acroform/PDFAcroChoice.js +47 -60
  144. package/cjs/core/acroform/PDFAcroChoice.js.map +1 -1
  145. package/cjs/core/acroform/PDFAcroComboBox.d.ts +4 -4
  146. package/cjs/core/acroform/PDFAcroComboBox.d.ts.map +1 -1
  147. package/cjs/core/acroform/PDFAcroComboBox.js +15 -22
  148. package/cjs/core/acroform/PDFAcroComboBox.js.map +1 -1
  149. package/cjs/core/acroform/PDFAcroField.d.ts +8 -8
  150. package/cjs/core/acroform/PDFAcroField.d.ts.map +1 -1
  151. package/cjs/core/acroform/PDFAcroField.js +80 -81
  152. package/cjs/core/acroform/PDFAcroField.js.map +1 -1
  153. package/cjs/core/acroform/PDFAcroForm.d.ts +5 -5
  154. package/cjs/core/acroform/PDFAcroForm.d.ts.map +1 -1
  155. package/cjs/core/acroform/PDFAcroForm.js +46 -47
  156. package/cjs/core/acroform/PDFAcroForm.js.map +1 -1
  157. package/cjs/core/acroform/PDFAcroListBox.d.ts +4 -4
  158. package/cjs/core/acroform/PDFAcroListBox.d.ts.map +1 -1
  159. package/cjs/core/acroform/PDFAcroListBox.js +13 -20
  160. package/cjs/core/acroform/PDFAcroListBox.js.map +1 -1
  161. package/cjs/core/acroform/PDFAcroNonTerminal.d.ts +4 -4
  162. package/cjs/core/acroform/PDFAcroNonTerminal.d.ts.map +1 -1
  163. package/cjs/core/acroform/PDFAcroNonTerminal.js +18 -25
  164. package/cjs/core/acroform/PDFAcroNonTerminal.js.map +1 -1
  165. package/cjs/core/acroform/PDFAcroPushButton.d.ts +4 -4
  166. package/cjs/core/acroform/PDFAcroPushButton.d.ts.map +1 -1
  167. package/cjs/core/acroform/PDFAcroPushButton.js +15 -22
  168. package/cjs/core/acroform/PDFAcroPushButton.js.map +1 -1
  169. package/cjs/core/acroform/PDFAcroRadioButton.d.ts +5 -5
  170. package/cjs/core/acroform/PDFAcroRadioButton.d.ts.map +1 -1
  171. package/cjs/core/acroform/PDFAcroRadioButton.js +33 -40
  172. package/cjs/core/acroform/PDFAcroRadioButton.js.map +1 -1
  173. package/cjs/core/acroform/PDFAcroSignature.d.ts +3 -3
  174. package/cjs/core/acroform/PDFAcroSignature.d.ts.map +1 -1
  175. package/cjs/core/acroform/PDFAcroSignature.js +5 -12
  176. package/cjs/core/acroform/PDFAcroSignature.js.map +1 -1
  177. package/cjs/core/acroform/PDFAcroTerminal.d.ts +5 -5
  178. package/cjs/core/acroform/PDFAcroTerminal.d.ts.map +1 -1
  179. package/cjs/core/acroform/PDFAcroTerminal.js +28 -35
  180. package/cjs/core/acroform/PDFAcroTerminal.js.map +1 -1
  181. package/cjs/core/acroform/PDFAcroText.d.ts +7 -7
  182. package/cjs/core/acroform/PDFAcroText.d.ts.map +1 -1
  183. package/cjs/core/acroform/PDFAcroText.js +40 -45
  184. package/cjs/core/acroform/PDFAcroText.js.map +1 -1
  185. package/cjs/core/acroform/flags.js +1 -1
  186. package/cjs/core/acroform/flags.js.map +1 -1
  187. package/cjs/core/acroform/index.d.ts +15 -15
  188. package/cjs/core/acroform/index.d.ts.map +1 -1
  189. package/cjs/core/acroform/index.js +17 -16
  190. package/cjs/core/acroform/index.js.map +1 -1
  191. package/cjs/core/acroform/utils.d.ts +4 -4
  192. package/cjs/core/acroform/utils.d.ts.map +1 -1
  193. package/cjs/core/acroform/utils.js +48 -48
  194. package/cjs/core/acroform/utils.js.map +1 -1
  195. package/cjs/core/annotation/AppearanceCharacteristics.d.ts +5 -5
  196. package/cjs/core/annotation/AppearanceCharacteristics.d.ts.map +1 -1
  197. package/cjs/core/annotation/AppearanceCharacteristics.js +61 -64
  198. package/cjs/core/annotation/AppearanceCharacteristics.js.map +1 -1
  199. package/cjs/core/annotation/BorderStyle.d.ts +2 -2
  200. package/cjs/core/annotation/BorderStyle.d.ts.map +1 -1
  201. package/cjs/core/annotation/BorderStyle.js +15 -16
  202. package/cjs/core/annotation/BorderStyle.js.map +1 -1
  203. package/cjs/core/annotation/PDFAnnotation.d.ts +6 -6
  204. package/cjs/core/annotation/PDFAnnotation.d.ts.map +1 -1
  205. package/cjs/core/annotation/PDFAnnotation.js +76 -77
  206. package/cjs/core/annotation/PDFAnnotation.js.map +1 -1
  207. package/cjs/core/annotation/PDFWidgetAnnotation.d.ts +9 -9
  208. package/cjs/core/annotation/PDFWidgetAnnotation.d.ts.map +1 -1
  209. package/cjs/core/annotation/PDFWidgetAnnotation.js +60 -67
  210. package/cjs/core/annotation/PDFWidgetAnnotation.js.map +1 -1
  211. package/cjs/core/annotation/flags.js +1 -1
  212. package/cjs/core/annotation/flags.js.map +1 -1
  213. package/cjs/core/annotation/index.d.ts +4 -4
  214. package/cjs/core/annotation/index.d.ts.map +1 -1
  215. package/cjs/core/annotation/index.js +6 -5
  216. package/cjs/core/annotation/index.js.map +1 -1
  217. package/cjs/core/crypto.d.ts +96 -0
  218. package/cjs/core/crypto.d.ts.map +1 -0
  219. package/cjs/core/crypto.js +1619 -0
  220. package/cjs/core/crypto.js.map +1 -0
  221. package/cjs/core/document/PDFCrossRefSection.d.ts +1 -1
  222. package/cjs/core/document/PDFCrossRefSection.d.ts.map +1 -1
  223. package/cjs/core/document/PDFCrossRefSection.js +62 -65
  224. package/cjs/core/document/PDFCrossRefSection.js.map +1 -1
  225. package/cjs/core/document/PDFHeader.js +18 -21
  226. package/cjs/core/document/PDFHeader.js.map +1 -1
  227. package/cjs/core/document/PDFTrailer.js +16 -19
  228. package/cjs/core/document/PDFTrailer.js.map +1 -1
  229. package/cjs/core/document/PDFTrailerDict.d.ts +1 -1
  230. package/cjs/core/document/PDFTrailerDict.d.ts.map +1 -1
  231. package/cjs/core/document/PDFTrailerDict.js +14 -15
  232. package/cjs/core/document/PDFTrailerDict.js.map +1 -1
  233. package/cjs/core/embedders/CMap.d.ts +1 -1
  234. package/cjs/core/embedders/CMap.d.ts.map +1 -1
  235. package/cjs/core/embedders/CMap.js +41 -28
  236. package/cjs/core/embedders/CMap.js.map +1 -1
  237. package/cjs/core/embedders/CustomFontEmbedder.d.ts +5 -5
  238. package/cjs/core/embedders/CustomFontEmbedder.d.ts.map +1 -1
  239. package/cjs/core/embedders/CustomFontEmbedder.js +126 -183
  240. package/cjs/core/embedders/CustomFontEmbedder.js.map +1 -1
  241. package/cjs/core/embedders/CustomFontSubsetEmbedder.d.ts +3 -3
  242. package/cjs/core/embedders/CustomFontSubsetEmbedder.d.ts.map +1 -1
  243. package/cjs/core/embedders/CustomFontSubsetEmbedder.js +39 -52
  244. package/cjs/core/embedders/CustomFontSubsetEmbedder.js.map +1 -1
  245. package/cjs/core/embedders/FileEmbedder.d.ts +2 -2
  246. package/cjs/core/embedders/FileEmbedder.d.ts.map +1 -1
  247. package/cjs/core/embedders/FileEmbedder.js +39 -48
  248. package/cjs/core/embedders/FileEmbedder.js.map +1 -1
  249. package/cjs/core/embedders/FontFlags.d.ts +1 -1
  250. package/cjs/core/embedders/FontFlags.d.ts.map +1 -1
  251. package/cjs/core/embedders/FontFlags.js +7 -6
  252. package/cjs/core/embedders/FontFlags.js.map +1 -1
  253. package/cjs/core/embedders/JavaScriptEmbedder.d.ts +2 -2
  254. package/cjs/core/embedders/JavaScriptEmbedder.d.ts.map +1 -1
  255. package/cjs/core/embedders/JavaScriptEmbedder.js +20 -27
  256. package/cjs/core/embedders/JavaScriptEmbedder.js.map +1 -1
  257. package/cjs/core/embedders/JpegEmbedder.d.ts +2 -2
  258. package/cjs/core/embedders/JpegEmbedder.d.ts.map +1 -1
  259. package/cjs/core/embedders/JpegEmbedder.js +62 -74
  260. package/cjs/core/embedders/JpegEmbedder.js.map +1 -1
  261. package/cjs/core/embedders/PDFPageEmbedder.d.ts +4 -4
  262. package/cjs/core/embedders/PDFPageEmbedder.d.ts.map +1 -1
  263. package/cjs/core/embedders/PDFPageEmbedder.js +53 -63
  264. package/cjs/core/embedders/PDFPageEmbedder.js.map +1 -1
  265. package/cjs/core/embedders/PngEmbedder.d.ts +2 -2
  266. package/cjs/core/embedders/PngEmbedder.d.ts.map +1 -1
  267. package/cjs/core/embedders/PngEmbedder.js +29 -42
  268. package/cjs/core/embedders/PngEmbedder.js.map +1 -1
  269. package/cjs/core/embedders/StandardFontEmbedder.d.ts +3 -3
  270. package/cjs/core/embedders/StandardFontEmbedder.d.ts.map +1 -1
  271. package/cjs/core/embedders/StandardFontEmbedder.js +46 -50
  272. package/cjs/core/embedders/StandardFontEmbedder.js.map +1 -1
  273. package/cjs/core/errors.d.ts +1 -1
  274. package/cjs/core/errors.d.ts.map +1 -1
  275. package/cjs/core/errors.js +147 -260
  276. package/cjs/core/errors.js.map +1 -1
  277. package/cjs/core/index.d.ts +47 -47
  278. package/cjs/core/index.d.ts.map +1 -1
  279. package/cjs/core/index.js +48 -47
  280. package/cjs/core/index.js.map +1 -1
  281. package/cjs/core/interactive/ViewerPreferences.d.ts +6 -6
  282. package/cjs/core/interactive/ViewerPreferences.d.ts.map +1 -1
  283. package/cjs/core/interactive/ViewerPreferences.js +135 -138
  284. package/cjs/core/interactive/ViewerPreferences.js.map +1 -1
  285. package/cjs/core/objects/PDFArray.d.ts +12 -12
  286. package/cjs/core/objects/PDFArray.d.ts.map +1 -1
  287. package/cjs/core/objects/PDFArray.js +72 -81
  288. package/cjs/core/objects/PDFArray.js.map +1 -1
  289. package/cjs/core/objects/PDFBool.d.ts +1 -1
  290. package/cjs/core/objects/PDFBool.d.ts.map +1 -1
  291. package/cjs/core/objects/PDFBool.js +22 -26
  292. package/cjs/core/objects/PDFBool.js.map +1 -1
  293. package/cjs/core/objects/PDFDict.d.ts +12 -11
  294. package/cjs/core/objects/PDFDict.d.ts.map +1 -1
  295. package/cjs/core/objects/PDFDict.js +74 -86
  296. package/cjs/core/objects/PDFDict.js.map +1 -1
  297. package/cjs/core/objects/PDFHexString.d.ts +1 -1
  298. package/cjs/core/objects/PDFHexString.d.ts.map +1 -1
  299. package/cjs/core/objects/PDFHexString.js +49 -52
  300. package/cjs/core/objects/PDFHexString.js.map +1 -1
  301. package/cjs/core/objects/PDFInvalidObject.d.ts +1 -1
  302. package/cjs/core/objects/PDFInvalidObject.d.ts.map +1 -1
  303. package/cjs/core/objects/PDFInvalidObject.js +19 -22
  304. package/cjs/core/objects/PDFInvalidObject.js.map +1 -1
  305. package/cjs/core/objects/PDFName.d.ts +1 -1
  306. package/cjs/core/objects/PDFName.d.ts.map +1 -1
  307. package/cjs/core/objects/PDFName.js +84 -92
  308. package/cjs/core/objects/PDFName.js.map +1 -1
  309. package/cjs/core/objects/PDFNull.d.ts +1 -1
  310. package/cjs/core/objects/PDFNull.d.ts.map +1 -1
  311. package/cjs/core/objects/PDFNull.js +15 -20
  312. package/cjs/core/objects/PDFNull.js.map +1 -1
  313. package/cjs/core/objects/PDFNumber.d.ts +1 -1
  314. package/cjs/core/objects/PDFNumber.d.ts.map +1 -1
  315. package/cjs/core/objects/PDFNumber.js +23 -26
  316. package/cjs/core/objects/PDFNumber.js.map +1 -1
  317. package/cjs/core/objects/PDFObject.d.ts +1 -1
  318. package/cjs/core/objects/PDFObject.d.ts.map +1 -1
  319. package/cjs/core/objects/PDFObject.js +11 -14
  320. package/cjs/core/objects/PDFObject.js.map +1 -1
  321. package/cjs/core/objects/PDFRawStream.d.ts +6 -4
  322. package/cjs/core/objects/PDFRawStream.d.ts.map +1 -1
  323. package/cjs/core/objects/PDFRawStream.js +21 -25
  324. package/cjs/core/objects/PDFRawStream.js.map +1 -1
  325. package/cjs/core/objects/PDFRef.d.ts +1 -1
  326. package/cjs/core/objects/PDFRef.d.ts.map +1 -1
  327. package/cjs/core/objects/PDFRef.js +31 -36
  328. package/cjs/core/objects/PDFRef.js.map +1 -1
  329. package/cjs/core/objects/PDFStream.d.ts +3 -3
  330. package/cjs/core/objects/PDFStream.d.ts.map +1 -1
  331. package/cjs/core/objects/PDFStream.js +32 -35
  332. package/cjs/core/objects/PDFStream.js.map +1 -1
  333. package/cjs/core/objects/PDFString.d.ts +1 -1
  334. package/cjs/core/objects/PDFString.d.ts.map +1 -1
  335. package/cjs/core/objects/PDFString.js +55 -58
  336. package/cjs/core/objects/PDFString.js.map +1 -1
  337. package/cjs/core/operators/PDFOperator.d.ts +7 -7
  338. package/cjs/core/operators/PDFOperator.d.ts.map +1 -1
  339. package/cjs/core/operators/PDFOperator.js +29 -32
  340. package/cjs/core/operators/PDFOperator.js.map +1 -1
  341. package/cjs/core/parser/BaseParser.d.ts +1 -1
  342. package/cjs/core/parser/BaseParser.d.ts.map +1 -1
  343. package/cjs/core/parser/BaseParser.js +40 -42
  344. package/cjs/core/parser/BaseParser.js.map +1 -1
  345. package/cjs/core/parser/ByteStream.d.ts +1 -1
  346. package/cjs/core/parser/ByteStream.d.ts.map +1 -1
  347. package/cjs/core/parser/ByteStream.js +30 -33
  348. package/cjs/core/parser/ByteStream.js.map +1 -1
  349. package/cjs/core/parser/PDFObjectParser.d.ts +22 -20
  350. package/cjs/core/parser/PDFObjectParser.d.ts.map +1 -1
  351. package/cjs/core/parser/PDFObjectParser.js +96 -88
  352. package/cjs/core/parser/PDFObjectParser.js.map +1 -1
  353. package/cjs/core/parser/PDFObjectStreamParser.d.ts +2 -2
  354. package/cjs/core/parser/PDFObjectStreamParser.d.ts.map +1 -1
  355. package/cjs/core/parser/PDFObjectStreamParser.js +41 -61
  356. package/cjs/core/parser/PDFObjectStreamParser.js.map +1 -1
  357. package/cjs/core/parser/PDFParser.d.ts +5 -4
  358. package/cjs/core/parser/PDFParser.d.ts.map +1 -1
  359. package/cjs/core/parser/PDFParser.js +157 -219
  360. package/cjs/core/parser/PDFParser.js.map +1 -1
  361. package/cjs/core/parser/PDFXRefStreamParser.d.ts +2 -2
  362. package/cjs/core/parser/PDFXRefStreamParser.d.ts.map +1 -1
  363. package/cjs/core/parser/PDFXRefStreamParser.js +38 -41
  364. package/cjs/core/parser/PDFXRefStreamParser.js.map +1 -1
  365. package/cjs/core/streams/Ascii85Stream.d.ts +2 -2
  366. package/cjs/core/streams/Ascii85Stream.d.ts.map +1 -1
  367. package/cjs/core/streams/Ascii85Stream.js +21 -26
  368. package/cjs/core/streams/Ascii85Stream.js.map +1 -1
  369. package/cjs/core/streams/AsciiHexStream.d.ts +2 -2
  370. package/cjs/core/streams/AsciiHexStream.d.ts.map +1 -1
  371. package/cjs/core/streams/AsciiHexStream.js +19 -22
  372. package/cjs/core/streams/AsciiHexStream.js.map +1 -1
  373. package/cjs/core/streams/DecodeStream.d.ts +1 -1
  374. package/cjs/core/streams/DecodeStream.d.ts.map +1 -1
  375. package/cjs/core/streams/DecodeStream.js +54 -61
  376. package/cjs/core/streams/DecodeStream.js.map +1 -1
  377. package/cjs/core/streams/DecryptStream.d.ts +13 -0
  378. package/cjs/core/streams/DecryptStream.d.ts.map +1 -0
  379. package/cjs/core/streams/DecryptStream.js +37 -0
  380. package/cjs/core/streams/DecryptStream.js.map +1 -0
  381. package/cjs/core/streams/FlateStream.d.ts +2 -2
  382. package/cjs/core/streams/FlateStream.d.ts.map +1 -1
  383. package/cjs/core/streams/FlateStream.js +81 -84
  384. package/cjs/core/streams/FlateStream.js.map +1 -1
  385. package/cjs/core/streams/LZWStream.d.ts +3 -3
  386. package/cjs/core/streams/LZWStream.d.ts.map +1 -1
  387. package/cjs/core/streams/LZWStream.js +42 -45
  388. package/cjs/core/streams/LZWStream.js.map +1 -1
  389. package/cjs/core/streams/RunLengthStream.d.ts +2 -2
  390. package/cjs/core/streams/RunLengthStream.d.ts.map +1 -1
  391. package/cjs/core/streams/RunLengthStream.js +16 -19
  392. package/cjs/core/streams/RunLengthStream.js.map +1 -1
  393. package/cjs/core/streams/Stream.js +45 -56
  394. package/cjs/core/streams/Stream.js.map +1 -1
  395. package/cjs/core/streams/decode.d.ts +3 -3
  396. package/cjs/core/streams/decode.d.ts.map +1 -1
  397. package/cjs/core/streams/decode.js +24 -21
  398. package/cjs/core/streams/decode.js.map +1 -1
  399. package/cjs/core/structures/PDFCatalog.d.ts +5 -5
  400. package/cjs/core/structures/PDFCatalog.d.ts.map +1 -1
  401. package/cjs/core/structures/PDFCatalog.js +40 -47
  402. package/cjs/core/structures/PDFCatalog.js.map +1 -1
  403. package/cjs/core/structures/PDFContentStream.d.ts +4 -4
  404. package/cjs/core/structures/PDFContentStream.d.ts.map +1 -1
  405. package/cjs/core/structures/PDFContentStream.js +31 -43
  406. package/cjs/core/structures/PDFContentStream.js.map +1 -1
  407. package/cjs/core/structures/PDFCrossRefStream.d.ts +4 -4
  408. package/cjs/core/structures/PDFCrossRefStream.d.ts.map +1 -1
  409. package/cjs/core/structures/PDFCrossRefStream.js +92 -100
  410. package/cjs/core/structures/PDFCrossRefStream.js.map +1 -1
  411. package/cjs/core/structures/PDFFlateStream.d.ts +3 -3
  412. package/cjs/core/structures/PDFFlateStream.d.ts.map +1 -1
  413. package/cjs/core/structures/PDFFlateStream.js +21 -24
  414. package/cjs/core/structures/PDFFlateStream.js.map +1 -1
  415. package/cjs/core/structures/PDFObjectStream.d.ts +4 -4
  416. package/cjs/core/structures/PDFObjectStream.d.ts.map +1 -1
  417. package/cjs/core/structures/PDFObjectStream.js +49 -56
  418. package/cjs/core/structures/PDFObjectStream.js.map +1 -1
  419. package/cjs/core/structures/PDFPageLeaf.d.ts +9 -9
  420. package/cjs/core/structures/PDFPageLeaf.d.ts.map +1 -1
  421. package/cjs/core/structures/PDFPageLeaf.js +126 -133
  422. package/cjs/core/structures/PDFPageLeaf.js.map +1 -1
  423. package/cjs/core/structures/PDFPageTree.d.ts +6 -6
  424. package/cjs/core/structures/PDFPageTree.d.ts.map +1 -1
  425. package/cjs/core/structures/PDFPageTree.js +67 -75
  426. package/cjs/core/structures/PDFPageTree.js.map +1 -1
  427. package/cjs/core/syntax/Delimiters.js +2 -2
  428. package/cjs/core/syntax/Delimiters.js.map +1 -1
  429. package/cjs/core/syntax/Irregular.js +5 -5
  430. package/cjs/core/syntax/Irregular.js.map +1 -1
  431. package/cjs/core/syntax/Keywords.d.ts +1 -1
  432. package/cjs/core/syntax/Keywords.d.ts.map +1 -1
  433. package/cjs/core/syntax/Keywords.js +14 -14
  434. package/cjs/core/syntax/Keywords.js.map +1 -1
  435. package/cjs/core/syntax/Numeric.js +3 -3
  436. package/cjs/core/syntax/Numeric.js.map +1 -1
  437. package/cjs/core/syntax/Whitespace.js +2 -2
  438. package/cjs/core/syntax/Whitespace.js.map +1 -1
  439. package/cjs/core/writers/PDFStreamWriter.d.ts +6 -6
  440. package/cjs/core/writers/PDFStreamWriter.d.ts.map +1 -1
  441. package/cjs/core/writers/PDFStreamWriter.js +74 -107
  442. package/cjs/core/writers/PDFStreamWriter.js.map +1 -1
  443. package/cjs/core/writers/PDFWriter.d.ts +12 -9
  444. package/cjs/core/writers/PDFWriter.d.ts.map +1 -1
  445. package/cjs/core/writers/PDFWriter.js +87 -127
  446. package/cjs/core/writers/PDFWriter.js.map +1 -1
  447. package/cjs/index.d.ts +4 -4
  448. package/cjs/index.d.ts.map +1 -1
  449. package/cjs/index.js +5 -5
  450. package/cjs/index.js.map +1 -1
  451. package/cjs/types/index.d.ts +25 -1
  452. package/cjs/types/index.d.ts.map +1 -1
  453. package/cjs/types/matrix.d.ts +8 -1
  454. package/cjs/types/matrix.d.ts.map +1 -1
  455. package/cjs/utils/Cache.js +10 -11
  456. package/cjs/utils/Cache.js.map +1 -1
  457. package/cjs/utils/arrays.d.ts +2 -1
  458. package/cjs/utils/arrays.d.ts.map +1 -1
  459. package/cjs/utils/arrays.js +83 -64
  460. package/cjs/utils/arrays.js.map +1 -1
  461. package/cjs/utils/async.d.ts.map +1 -1
  462. package/cjs/utils/async.js +4 -5
  463. package/cjs/utils/async.js.map +1 -1
  464. package/cjs/utils/base64.d.ts.map +1 -1
  465. package/cjs/utils/base64.js +29 -26
  466. package/cjs/utils/base64.js.map +1 -1
  467. package/cjs/utils/elements/Arc.d.ts +23 -0
  468. package/cjs/utils/elements/Arc.d.ts.map +1 -0
  469. package/cjs/utils/elements/Arc.js +78 -0
  470. package/cjs/utils/elements/Arc.js.map +1 -0
  471. package/cjs/utils/elements/Circle.d.ts +15 -0
  472. package/cjs/utils/elements/Circle.d.ts.map +1 -0
  473. package/cjs/utils/elements/Circle.js +41 -0
  474. package/cjs/utils/elements/Circle.js.map +1 -0
  475. package/cjs/utils/elements/Ellipse.d.ts +21 -0
  476. package/cjs/utils/elements/Ellipse.d.ts.map +1 -0
  477. package/cjs/utils/elements/Ellipse.js +91 -0
  478. package/cjs/utils/elements/Ellipse.js.map +1 -0
  479. package/cjs/utils/elements/GraphElement.d.ts +7 -0
  480. package/cjs/utils/elements/GraphElement.d.ts.map +1 -0
  481. package/cjs/utils/elements/GraphElement.js +11 -0
  482. package/cjs/utils/elements/GraphElement.js.map +1 -0
  483. package/cjs/utils/elements/Line.d.ts +24 -0
  484. package/cjs/utils/elements/Line.d.ts.map +1 -0
  485. package/cjs/utils/elements/Line.js +72 -0
  486. package/cjs/utils/elements/Line.js.map +1 -0
  487. package/cjs/utils/elements/Plot.d.ts +12 -0
  488. package/cjs/utils/elements/Plot.d.ts.map +1 -0
  489. package/cjs/utils/elements/Plot.js +46 -0
  490. package/cjs/utils/elements/Plot.js.map +1 -0
  491. package/cjs/utils/elements/Point.d.ts +19 -0
  492. package/cjs/utils/elements/Point.d.ts.map +1 -0
  493. package/cjs/utils/elements/Point.js +32 -0
  494. package/cjs/utils/elements/Point.js.map +1 -0
  495. package/cjs/utils/elements/Rectangle.d.ts +22 -0
  496. package/cjs/utils/elements/Rectangle.d.ts.map +1 -0
  497. package/cjs/utils/elements/Rectangle.js +58 -0
  498. package/cjs/utils/elements/Rectangle.js.map +1 -0
  499. package/cjs/utils/elements/Segment.d.ts +20 -0
  500. package/cjs/utils/elements/Segment.d.ts.map +1 -0
  501. package/cjs/utils/elements/Segment.js +80 -0
  502. package/cjs/utils/elements/Segment.js.map +1 -0
  503. package/cjs/utils/elements/index.d.ts +10 -0
  504. package/cjs/utils/elements/index.d.ts.map +1 -0
  505. package/cjs/utils/elements/index.js +25 -0
  506. package/cjs/utils/elements/index.js.map +1 -0
  507. package/cjs/utils/errors.js +2 -1
  508. package/cjs/utils/errors.js.map +1 -1
  509. package/cjs/utils/index.d.ts +11 -11
  510. package/cjs/utils/index.d.ts.map +1 -1
  511. package/cjs/utils/index.js +13 -12
  512. package/cjs/utils/index.js.map +1 -1
  513. package/cjs/utils/intersections.d.ts +10 -0
  514. package/cjs/utils/intersections.d.ts.map +1 -0
  515. package/cjs/utils/intersections.js +255 -0
  516. package/cjs/utils/intersections.js.map +1 -0
  517. package/cjs/utils/maths.d.ts +46 -0
  518. package/cjs/utils/maths.d.ts.map +1 -0
  519. package/cjs/utils/maths.js +89 -0
  520. package/cjs/utils/maths.js.map +1 -0
  521. package/cjs/utils/numbers.js +12 -9
  522. package/cjs/utils/numbers.js.map +1 -1
  523. package/cjs/utils/objects.js +8 -7
  524. package/cjs/utils/objects.js.map +1 -1
  525. package/cjs/utils/pdfDocEncoding.js +52 -51
  526. package/cjs/utils/pdfDocEncoding.js.map +1 -1
  527. package/cjs/utils/png.js +22 -23
  528. package/cjs/utils/png.js.map +1 -1
  529. package/cjs/utils/rng.js +7 -8
  530. package/cjs/utils/rng.js.map +1 -1
  531. package/cjs/utils/strings.d.ts +1 -0
  532. package/cjs/utils/strings.d.ts.map +1 -1
  533. package/cjs/utils/strings.js +84 -70
  534. package/cjs/utils/strings.js.map +1 -1
  535. package/cjs/utils/unicode.js +51 -64
  536. package/cjs/utils/unicode.js.map +1 -1
  537. package/cjs/utils/validators.js +84 -67
  538. package/cjs/utils/validators.js.map +1 -1
  539. package/dist/pdf-lib.esm.js +11480 -7021
  540. package/dist/pdf-lib.esm.js.map +1 -1
  541. package/dist/pdf-lib.esm.min.js +1 -15
  542. package/dist/pdf-lib.esm.min.js.map +1 -1
  543. package/dist/pdf-lib.js +11481 -7019
  544. package/dist/pdf-lib.js.map +1 -1
  545. package/dist/pdf-lib.min.js +1 -15
  546. package/dist/pdf-lib.min.js.map +1 -1
  547. package/es/api/Embeddable.js +1 -0
  548. package/es/api/PDFDocument.d.ts +11 -11
  549. package/es/api/PDFDocument.d.ts.map +1 -1
  550. package/es/api/PDFDocument.js +346 -519
  551. package/es/api/PDFDocument.js.map +1 -1
  552. package/es/api/PDFDocumentOptions.d.ts +3 -2
  553. package/es/api/PDFDocumentOptions.d.ts.map +1 -1
  554. package/es/api/PDFEmbeddedFile.d.ts +4 -4
  555. package/es/api/PDFEmbeddedFile.d.ts.map +1 -1
  556. package/es/api/PDFEmbeddedFile.js +48 -64
  557. package/es/api/PDFEmbeddedFile.js.map +1 -1
  558. package/es/api/PDFEmbeddedPage.d.ts +3 -3
  559. package/es/api/PDFEmbeddedPage.d.ts.map +1 -1
  560. package/es/api/PDFEmbeddedPage.js +29 -44
  561. package/es/api/PDFEmbeddedPage.js.map +1 -1
  562. package/es/api/PDFFont.d.ts +3 -3
  563. package/es/api/PDFFont.d.ts.map +1 -1
  564. package/es/api/PDFFont.js +36 -50
  565. package/es/api/PDFFont.js.map +1 -1
  566. package/es/api/PDFImage.d.ts +3 -3
  567. package/es/api/PDFImage.d.ts.map +1 -1
  568. package/es/api/PDFImage.js +42 -58
  569. package/es/api/PDFImage.js.map +1 -1
  570. package/es/api/PDFJavaScript.d.ts +4 -4
  571. package/es/api/PDFJavaScript.d.ts.map +1 -1
  572. package/es/api/PDFJavaScript.js +37 -53
  573. package/es/api/PDFJavaScript.js.map +1 -1
  574. package/es/api/PDFPage.d.ts +21 -9
  575. package/es/api/PDFPage.d.ts.map +1 -1
  576. package/es/api/PDFPage.js +279 -260
  577. package/es/api/PDFPage.js.map +1 -1
  578. package/es/api/PDFPageOptions.d.ts +29 -12
  579. package/es/api/PDFPageOptions.d.ts.map +1 -1
  580. package/es/api/PDFPageOptions.js.map +1 -1
  581. package/es/api/colors.d.ts +4 -0
  582. package/es/api/colors.d.ts.map +1 -1
  583. package/es/api/colors.js +34 -34
  584. package/es/api/colors.js.map +1 -1
  585. package/es/api/errors.js +73 -144
  586. package/es/api/errors.js.map +1 -1
  587. package/es/api/form/PDFButton.d.ts +8 -8
  588. package/es/api/form/PDFButton.d.ts.map +1 -1
  589. package/es/api/form/PDFButton.js +56 -62
  590. package/es/api/form/PDFButton.js.map +1 -1
  591. package/es/api/form/PDFCheckBox.d.ts +5 -5
  592. package/es/api/form/PDFCheckBox.d.ts.map +1 -1
  593. package/es/api/form/PDFCheckBox.js +55 -62
  594. package/es/api/form/PDFCheckBox.js.map +1 -1
  595. package/es/api/form/PDFDropdown.d.ts +6 -6
  596. package/es/api/form/PDFDropdown.d.ts.map +1 -1
  597. package/es/api/form/PDFDropdown.js +110 -118
  598. package/es/api/form/PDFDropdown.js.map +1 -1
  599. package/es/api/form/PDFField.d.ts +6 -6
  600. package/es/api/form/PDFField.d.ts.map +1 -1
  601. package/es/api/form/PDFField.js +98 -106
  602. package/es/api/form/PDFField.js.map +1 -1
  603. package/es/api/form/PDFForm.d.ts +11 -11
  604. package/es/api/form/PDFForm.d.ts.map +1 -1
  605. package/es/api/form/PDFForm.js +195 -196
  606. package/es/api/form/PDFForm.js.map +1 -1
  607. package/es/api/form/PDFOptionList.d.ts +6 -6
  608. package/es/api/form/PDFOptionList.d.ts.map +1 -1
  609. package/es/api/form/PDFOptionList.js +98 -106
  610. package/es/api/form/PDFOptionList.js.map +1 -1
  611. package/es/api/form/PDFRadioGroup.d.ts +5 -5
  612. package/es/api/form/PDFRadioGroup.d.ts.map +1 -1
  613. package/es/api/form/PDFRadioGroup.js +86 -91
  614. package/es/api/form/PDFRadioGroup.js.map +1 -1
  615. package/es/api/form/PDFSignature.d.ts +3 -3
  616. package/es/api/form/PDFSignature.d.ts.map +1 -1
  617. package/es/api/form/PDFSignature.js +23 -28
  618. package/es/api/form/PDFSignature.js.map +1 -1
  619. package/es/api/form/PDFTextField.d.ts +8 -8
  620. package/es/api/form/PDFTextField.d.ts.map +1 -1
  621. package/es/api/form/PDFTextField.js +121 -128
  622. package/es/api/form/PDFTextField.js.map +1 -1
  623. package/es/api/form/appearances.d.ts +11 -11
  624. package/es/api/form/appearances.d.ts.map +1 -1
  625. package/es/api/form/appearances.js +285 -214
  626. package/es/api/form/appearances.js.map +1 -1
  627. package/es/api/form/index.d.ts +10 -10
  628. package/es/api/form/index.d.ts.map +1 -1
  629. package/es/api/form/index.js +10 -10
  630. package/es/api/form/index.js.map +1 -1
  631. package/es/api/image/index.d.ts +1 -1
  632. package/es/api/image/index.d.ts.map +1 -1
  633. package/es/api/image/index.js +1 -1
  634. package/es/api/image/index.js.map +1 -1
  635. package/es/api/index.d.ts +20 -20
  636. package/es/api/index.d.ts.map +1 -1
  637. package/es/api/index.js +19 -19
  638. package/es/api/index.js.map +1 -1
  639. package/es/api/objects.d.ts +1 -1
  640. package/es/api/objects.d.ts.map +1 -1
  641. package/es/api/objects.js +4 -10
  642. package/es/api/objects.js.map +1 -1
  643. package/es/api/operations.d.ts +20 -4
  644. package/es/api/operations.d.ts.map +1 -1
  645. package/es/api/operations.js +229 -210
  646. package/es/api/operations.js.map +1 -1
  647. package/es/api/operators.d.ts +6 -1
  648. package/es/api/operators.d.ts.map +1 -1
  649. package/es/api/operators.js +114 -182
  650. package/es/api/operators.js.map +1 -1
  651. package/es/api/rotations.d.ts +1 -1
  652. package/es/api/rotations.d.ts.map +1 -1
  653. package/es/api/rotations.js +20 -28
  654. package/es/api/rotations.js.map +1 -1
  655. package/es/api/sizes.js +1 -1
  656. package/es/api/sizes.js.map +1 -1
  657. package/es/api/svg.d.ts +71 -0
  658. package/es/api/svg.d.ts.map +1 -0
  659. package/es/api/svg.js +650 -0
  660. package/es/api/svg.js.map +1 -0
  661. package/es/api/svgPath.d.ts +1 -1
  662. package/es/api/svgPath.d.ts.map +1 -1
  663. package/es/api/svgPath.js +104 -108
  664. package/es/api/svgPath.js.map +1 -1
  665. package/es/api/text/index.d.ts +2 -2
  666. package/es/api/text/index.d.ts.map +1 -1
  667. package/es/api/text/index.js +2 -2
  668. package/es/api/text/index.js.map +1 -1
  669. package/es/api/text/layout.d.ts +3 -3
  670. package/es/api/text/layout.d.ts.map +1 -1
  671. package/es/api/text/layout.js +84 -88
  672. package/es/api/text/layout.js.map +1 -1
  673. package/es/core/PDFContext.d.ts +17 -16
  674. package/es/core/PDFContext.d.ts.map +1 -1
  675. package/es/core/PDFContext.js +90 -99
  676. package/es/core/PDFContext.js.map +1 -1
  677. package/es/core/PDFObjectCopier.d.ts +2 -2
  678. package/es/core/PDFObjectCopier.d.ts.map +1 -1
  679. package/es/core/PDFObjectCopier.js +57 -61
  680. package/es/core/PDFObjectCopier.js.map +1 -1
  681. package/es/core/acroform/PDFAcroButton.d.ts +7 -7
  682. package/es/core/acroform/PDFAcroButton.d.ts.map +1 -1
  683. package/es/core/acroform/PDFAcroButton.js +41 -47
  684. package/es/core/acroform/PDFAcroButton.js.map +1 -1
  685. package/es/core/acroform/PDFAcroCheckBox.d.ts +5 -5
  686. package/es/core/acroform/PDFAcroCheckBox.d.ts.map +1 -1
  687. package/es/core/acroform/PDFAcroCheckBox.js +27 -35
  688. package/es/core/acroform/PDFAcroCheckBox.js.map +1 -1
  689. package/es/core/acroform/PDFAcroChoice.d.ts +4 -4
  690. package/es/core/acroform/PDFAcroChoice.d.ts.map +1 -1
  691. package/es/core/acroform/PDFAcroChoice.js +46 -60
  692. package/es/core/acroform/PDFAcroChoice.js.map +1 -1
  693. package/es/core/acroform/PDFAcroComboBox.d.ts +4 -4
  694. package/es/core/acroform/PDFAcroComboBox.d.ts.map +1 -1
  695. package/es/core/acroform/PDFAcroComboBox.js +14 -22
  696. package/es/core/acroform/PDFAcroComboBox.js.map +1 -1
  697. package/es/core/acroform/PDFAcroField.d.ts +8 -8
  698. package/es/core/acroform/PDFAcroField.d.ts.map +1 -1
  699. package/es/core/acroform/PDFAcroField.js +79 -80
  700. package/es/core/acroform/PDFAcroField.js.map +1 -1
  701. package/es/core/acroform/PDFAcroForm.d.ts +5 -5
  702. package/es/core/acroform/PDFAcroForm.d.ts.map +1 -1
  703. package/es/core/acroform/PDFAcroForm.js +43 -44
  704. package/es/core/acroform/PDFAcroForm.js.map +1 -1
  705. package/es/core/acroform/PDFAcroListBox.d.ts +4 -4
  706. package/es/core/acroform/PDFAcroListBox.d.ts.map +1 -1
  707. package/es/core/acroform/PDFAcroListBox.js +12 -20
  708. package/es/core/acroform/PDFAcroListBox.js.map +1 -1
  709. package/es/core/acroform/PDFAcroNonTerminal.d.ts +4 -4
  710. package/es/core/acroform/PDFAcroNonTerminal.d.ts.map +1 -1
  711. package/es/core/acroform/PDFAcroNonTerminal.js +17 -25
  712. package/es/core/acroform/PDFAcroNonTerminal.js.map +1 -1
  713. package/es/core/acroform/PDFAcroPushButton.d.ts +4 -4
  714. package/es/core/acroform/PDFAcroPushButton.d.ts.map +1 -1
  715. package/es/core/acroform/PDFAcroPushButton.js +14 -22
  716. package/es/core/acroform/PDFAcroPushButton.js.map +1 -1
  717. package/es/core/acroform/PDFAcroRadioButton.d.ts +5 -5
  718. package/es/core/acroform/PDFAcroRadioButton.d.ts.map +1 -1
  719. package/es/core/acroform/PDFAcroRadioButton.js +32 -40
  720. package/es/core/acroform/PDFAcroRadioButton.js.map +1 -1
  721. package/es/core/acroform/PDFAcroSignature.d.ts +3 -3
  722. package/es/core/acroform/PDFAcroSignature.d.ts.map +1 -1
  723. package/es/core/acroform/PDFAcroSignature.js +4 -12
  724. package/es/core/acroform/PDFAcroSignature.js.map +1 -1
  725. package/es/core/acroform/PDFAcroTerminal.d.ts +5 -5
  726. package/es/core/acroform/PDFAcroTerminal.d.ts.map +1 -1
  727. package/es/core/acroform/PDFAcroTerminal.js +27 -35
  728. package/es/core/acroform/PDFAcroTerminal.js.map +1 -1
  729. package/es/core/acroform/PDFAcroText.d.ts +7 -7
  730. package/es/core/acroform/PDFAcroText.d.ts.map +1 -1
  731. package/es/core/acroform/PDFAcroText.js +39 -45
  732. package/es/core/acroform/PDFAcroText.js.map +1 -1
  733. package/es/core/acroform/flags.js +1 -1
  734. package/es/core/acroform/flags.js.map +1 -1
  735. package/es/core/acroform/index.d.ts +15 -15
  736. package/es/core/acroform/index.d.ts.map +1 -1
  737. package/es/core/acroform/index.js +15 -15
  738. package/es/core/acroform/index.js.map +1 -1
  739. package/es/core/acroform/utils.d.ts +4 -4
  740. package/es/core/acroform/utils.d.ts.map +1 -1
  741. package/es/core/acroform/utils.js +44 -46
  742. package/es/core/acroform/utils.js.map +1 -1
  743. package/es/core/annotation/AppearanceCharacteristics.d.ts +5 -5
  744. package/es/core/annotation/AppearanceCharacteristics.d.ts.map +1 -1
  745. package/es/core/annotation/AppearanceCharacteristics.js +60 -63
  746. package/es/core/annotation/AppearanceCharacteristics.js.map +1 -1
  747. package/es/core/annotation/BorderStyle.d.ts +2 -2
  748. package/es/core/annotation/BorderStyle.d.ts.map +1 -1
  749. package/es/core/annotation/BorderStyle.js +14 -15
  750. package/es/core/annotation/BorderStyle.js.map +1 -1
  751. package/es/core/annotation/PDFAnnotation.d.ts +6 -6
  752. package/es/core/annotation/PDFAnnotation.d.ts.map +1 -1
  753. package/es/core/annotation/PDFAnnotation.js +75 -76
  754. package/es/core/annotation/PDFAnnotation.js.map +1 -1
  755. package/es/core/annotation/PDFWidgetAnnotation.d.ts +9 -9
  756. package/es/core/annotation/PDFWidgetAnnotation.d.ts.map +1 -1
  757. package/es/core/annotation/PDFWidgetAnnotation.js +59 -67
  758. package/es/core/annotation/PDFWidgetAnnotation.js.map +1 -1
  759. package/es/core/annotation/flags.js +1 -1
  760. package/es/core/annotation/flags.js.map +1 -1
  761. package/es/core/annotation/index.d.ts +4 -4
  762. package/es/core/annotation/index.d.ts.map +1 -1
  763. package/es/core/annotation/index.js +4 -4
  764. package/es/core/annotation/index.js.map +1 -1
  765. package/es/core/crypto.d.ts +96 -0
  766. package/es/core/crypto.d.ts.map +1 -0
  767. package/es/core/crypto.js +1605 -0
  768. package/es/core/crypto.js.map +1 -0
  769. package/es/core/document/PDFCrossRefSection.d.ts +1 -1
  770. package/es/core/document/PDFCrossRefSection.d.ts.map +1 -1
  771. package/es/core/document/PDFCrossRefSection.js +55 -58
  772. package/es/core/document/PDFCrossRefSection.js.map +1 -1
  773. package/es/core/document/PDFHeader.js +15 -18
  774. package/es/core/document/PDFHeader.js.map +1 -1
  775. package/es/core/document/PDFTrailer.js +14 -17
  776. package/es/core/document/PDFTrailer.js.map +1 -1
  777. package/es/core/document/PDFTrailerDict.d.ts +1 -1
  778. package/es/core/document/PDFTrailerDict.d.ts.map +1 -1
  779. package/es/core/document/PDFTrailerDict.js +13 -14
  780. package/es/core/document/PDFTrailerDict.js.map +1 -1
  781. package/es/core/embedders/CMap.d.ts +1 -1
  782. package/es/core/embedders/CMap.d.ts.map +1 -1
  783. package/es/core/embedders/CMap.js +38 -26
  784. package/es/core/embedders/CMap.js.map +1 -1
  785. package/es/core/embedders/CustomFontEmbedder.d.ts +5 -5
  786. package/es/core/embedders/CustomFontEmbedder.d.ts.map +1 -1
  787. package/es/core/embedders/CustomFontEmbedder.js +124 -182
  788. package/es/core/embedders/CustomFontEmbedder.js.map +1 -1
  789. package/es/core/embedders/CustomFontSubsetEmbedder.d.ts +3 -3
  790. package/es/core/embedders/CustomFontSubsetEmbedder.d.ts.map +1 -1
  791. package/es/core/embedders/CustomFontSubsetEmbedder.js +37 -51
  792. package/es/core/embedders/CustomFontSubsetEmbedder.js.map +1 -1
  793. package/es/core/embedders/FileEmbedder.d.ts +2 -2
  794. package/es/core/embedders/FileEmbedder.d.ts.map +1 -1
  795. package/es/core/embedders/FileEmbedder.js +38 -48
  796. package/es/core/embedders/FileEmbedder.js.map +1 -1
  797. package/es/core/embedders/FontFlags.d.ts +1 -1
  798. package/es/core/embedders/FontFlags.d.ts.map +1 -1
  799. package/es/core/embedders/FontFlags.js +6 -6
  800. package/es/core/embedders/FontFlags.js.map +1 -1
  801. package/es/core/embedders/JavaScriptEmbedder.d.ts +2 -2
  802. package/es/core/embedders/JavaScriptEmbedder.d.ts.map +1 -1
  803. package/es/core/embedders/JavaScriptEmbedder.js +19 -27
  804. package/es/core/embedders/JavaScriptEmbedder.js.map +1 -1
  805. package/es/core/embedders/JpegEmbedder.d.ts +2 -2
  806. package/es/core/embedders/JpegEmbedder.d.ts.map +1 -1
  807. package/es/core/embedders/JpegEmbedder.js +62 -74
  808. package/es/core/embedders/JpegEmbedder.js.map +1 -1
  809. package/es/core/embedders/PDFPageEmbedder.d.ts +4 -4
  810. package/es/core/embedders/PDFPageEmbedder.d.ts.map +1 -1
  811. package/es/core/embedders/PDFPageEmbedder.js +51 -62
  812. package/es/core/embedders/PDFPageEmbedder.js.map +1 -1
  813. package/es/core/embedders/PngEmbedder.d.ts +2 -2
  814. package/es/core/embedders/PngEmbedder.d.ts.map +1 -1
  815. package/es/core/embedders/PngEmbedder.js +29 -42
  816. package/es/core/embedders/PngEmbedder.js.map +1 -1
  817. package/es/core/embedders/StandardFontEmbedder.d.ts +3 -3
  818. package/es/core/embedders/StandardFontEmbedder.d.ts.map +1 -1
  819. package/es/core/embedders/StandardFontEmbedder.js +43 -47
  820. package/es/core/embedders/StandardFontEmbedder.js.map +1 -1
  821. package/es/core/errors.d.ts +1 -1
  822. package/es/core/errors.d.ts.map +1 -1
  823. package/es/core/errors.js +175 -316
  824. package/es/core/errors.js.map +1 -1
  825. package/es/core/index.d.ts +47 -47
  826. package/es/core/index.d.ts.map +1 -1
  827. package/es/core/index.js +47 -47
  828. package/es/core/index.js.map +1 -1
  829. package/es/core/interactive/ViewerPreferences.d.ts +6 -6
  830. package/es/core/interactive/ViewerPreferences.d.ts.map +1 -1
  831. package/es/core/interactive/ViewerPreferences.js +127 -130
  832. package/es/core/interactive/ViewerPreferences.js.map +1 -1
  833. package/es/core/objects/PDFArray.d.ts +12 -12
  834. package/es/core/objects/PDFArray.d.ts.map +1 -1
  835. package/es/core/objects/PDFArray.js +71 -81
  836. package/es/core/objects/PDFArray.js.map +1 -1
  837. package/es/core/objects/PDFBool.d.ts +1 -1
  838. package/es/core/objects/PDFBool.d.ts.map +1 -1
  839. package/es/core/objects/PDFBool.js +21 -26
  840. package/es/core/objects/PDFBool.js.map +1 -1
  841. package/es/core/objects/PDFDict.d.ts +12 -11
  842. package/es/core/objects/PDFDict.d.ts.map +1 -1
  843. package/es/core/objects/PDFDict.js +73 -86
  844. package/es/core/objects/PDFDict.js.map +1 -1
  845. package/es/core/objects/PDFHexString.d.ts +1 -1
  846. package/es/core/objects/PDFHexString.d.ts.map +1 -1
  847. package/es/core/objects/PDFHexString.js +44 -48
  848. package/es/core/objects/PDFHexString.js.map +1 -1
  849. package/es/core/objects/PDFInvalidObject.d.ts +1 -1
  850. package/es/core/objects/PDFInvalidObject.d.ts.map +1 -1
  851. package/es/core/objects/PDFInvalidObject.js +18 -22
  852. package/es/core/objects/PDFInvalidObject.js.map +1 -1
  853. package/es/core/objects/PDFName.d.ts +1 -1
  854. package/es/core/objects/PDFName.d.ts.map +1 -1
  855. package/es/core/objects/PDFName.js +82 -91
  856. package/es/core/objects/PDFName.js.map +1 -1
  857. package/es/core/objects/PDFNull.d.ts +1 -1
  858. package/es/core/objects/PDFNull.d.ts.map +1 -1
  859. package/es/core/objects/PDFNull.js +14 -20
  860. package/es/core/objects/PDFNull.js.map +1 -1
  861. package/es/core/objects/PDFNumber.d.ts +1 -1
  862. package/es/core/objects/PDFNumber.d.ts.map +1 -1
  863. package/es/core/objects/PDFNumber.js +21 -25
  864. package/es/core/objects/PDFNumber.js.map +1 -1
  865. package/es/core/objects/PDFObject.d.ts +1 -1
  866. package/es/core/objects/PDFObject.d.ts.map +1 -1
  867. package/es/core/objects/PDFObject.js +11 -14
  868. package/es/core/objects/PDFObject.js.map +1 -1
  869. package/es/core/objects/PDFRawStream.d.ts +6 -4
  870. package/es/core/objects/PDFRawStream.d.ts.map +1 -1
  871. package/es/core/objects/PDFRawStream.js +19 -24
  872. package/es/core/objects/PDFRawStream.js.map +1 -1
  873. package/es/core/objects/PDFRef.d.ts +1 -1
  874. package/es/core/objects/PDFRef.d.ts.map +1 -1
  875. package/es/core/objects/PDFRef.js +29 -35
  876. package/es/core/objects/PDFRef.js.map +1 -1
  877. package/es/core/objects/PDFStream.d.ts +3 -3
  878. package/es/core/objects/PDFStream.d.ts.map +1 -1
  879. package/es/core/objects/PDFStream.js +31 -35
  880. package/es/core/objects/PDFStream.js.map +1 -1
  881. package/es/core/objects/PDFString.d.ts +1 -1
  882. package/es/core/objects/PDFString.d.ts.map +1 -1
  883. package/es/core/objects/PDFString.js +50 -54
  884. package/es/core/objects/PDFString.js.map +1 -1
  885. package/es/core/operators/PDFOperator.d.ts +7 -7
  886. package/es/core/operators/PDFOperator.d.ts.map +1 -1
  887. package/es/core/operators/PDFOperator.js +26 -29
  888. package/es/core/operators/PDFOperator.js.map +1 -1
  889. package/es/core/parser/BaseParser.d.ts +1 -1
  890. package/es/core/parser/BaseParser.d.ts.map +1 -1
  891. package/es/core/parser/BaseParser.js +36 -38
  892. package/es/core/parser/BaseParser.js.map +1 -1
  893. package/es/core/parser/ByteStream.d.ts +1 -1
  894. package/es/core/parser/ByteStream.d.ts.map +1 -1
  895. package/es/core/parser/ByteStream.js +29 -32
  896. package/es/core/parser/ByteStream.js.map +1 -1
  897. package/es/core/parser/PDFObjectParser.d.ts +22 -20
  898. package/es/core/parser/PDFObjectParser.d.ts.map +1 -1
  899. package/es/core/parser/PDFObjectParser.js +92 -85
  900. package/es/core/parser/PDFObjectParser.js.map +1 -1
  901. package/es/core/parser/PDFObjectStreamParser.d.ts +2 -2
  902. package/es/core/parser/PDFObjectStreamParser.d.ts.map +1 -1
  903. package/es/core/parser/PDFObjectStreamParser.js +40 -61
  904. package/es/core/parser/PDFObjectStreamParser.js.map +1 -1
  905. package/es/core/parser/PDFParser.d.ts +5 -4
  906. package/es/core/parser/PDFParser.d.ts.map +1 -1
  907. package/es/core/parser/PDFParser.js +156 -219
  908. package/es/core/parser/PDFParser.js.map +1 -1
  909. package/es/core/parser/PDFXRefStreamParser.d.ts +2 -2
  910. package/es/core/parser/PDFXRefStreamParser.d.ts.map +1 -1
  911. package/es/core/parser/PDFXRefStreamParser.js +37 -40
  912. package/es/core/parser/PDFXRefStreamParser.js.map +1 -1
  913. package/es/core/streams/Ascii85Stream.d.ts +2 -2
  914. package/es/core/streams/Ascii85Stream.d.ts.map +1 -1
  915. package/es/core/streams/Ascii85Stream.js +20 -26
  916. package/es/core/streams/Ascii85Stream.js.map +1 -1
  917. package/es/core/streams/AsciiHexStream.d.ts +2 -2
  918. package/es/core/streams/AsciiHexStream.d.ts.map +1 -1
  919. package/es/core/streams/AsciiHexStream.js +18 -22
  920. package/es/core/streams/AsciiHexStream.js.map +1 -1
  921. package/es/core/streams/DecodeStream.d.ts +1 -1
  922. package/es/core/streams/DecodeStream.d.ts.map +1 -1
  923. package/es/core/streams/DecodeStream.js +53 -60
  924. package/es/core/streams/DecodeStream.js.map +1 -1
  925. package/es/core/streams/DecryptStream.d.ts +13 -0
  926. package/es/core/streams/DecryptStream.d.ts.map +1 -0
  927. package/es/core/streams/DecryptStream.js +34 -0
  928. package/es/core/streams/DecryptStream.js.map +1 -0
  929. package/es/core/streams/FlateStream.d.ts +2 -2
  930. package/es/core/streams/FlateStream.d.ts.map +1 -1
  931. package/es/core/streams/FlateStream.js +80 -84
  932. package/es/core/streams/FlateStream.js.map +1 -1
  933. package/es/core/streams/LZWStream.d.ts +3 -3
  934. package/es/core/streams/LZWStream.d.ts.map +1 -1
  935. package/es/core/streams/LZWStream.js +41 -45
  936. package/es/core/streams/LZWStream.js.map +1 -1
  937. package/es/core/streams/RunLengthStream.d.ts +2 -2
  938. package/es/core/streams/RunLengthStream.d.ts.map +1 -1
  939. package/es/core/streams/RunLengthStream.js +15 -19
  940. package/es/core/streams/RunLengthStream.js.map +1 -1
  941. package/es/core/streams/Stream.js +45 -56
  942. package/es/core/streams/Stream.js.map +1 -1
  943. package/es/core/streams/decode.d.ts +3 -3
  944. package/es/core/streams/decode.d.ts.map +1 -1
  945. package/es/core/streams/decode.js +22 -20
  946. package/es/core/streams/decode.js.map +1 -1
  947. package/es/core/structures/PDFCatalog.d.ts +5 -5
  948. package/es/core/structures/PDFCatalog.d.ts.map +1 -1
  949. package/es/core/structures/PDFCatalog.js +39 -47
  950. package/es/core/structures/PDFCatalog.js.map +1 -1
  951. package/es/core/structures/PDFContentStream.d.ts +4 -4
  952. package/es/core/structures/PDFContentStream.d.ts.map +1 -1
  953. package/es/core/structures/PDFContentStream.js +30 -43
  954. package/es/core/structures/PDFContentStream.js.map +1 -1
  955. package/es/core/structures/PDFCrossRefStream.d.ts +4 -4
  956. package/es/core/structures/PDFCrossRefStream.d.ts.map +1 -1
  957. package/es/core/structures/PDFCrossRefStream.js +91 -100
  958. package/es/core/structures/PDFCrossRefStream.js.map +1 -1
  959. package/es/core/structures/PDFFlateStream.d.ts +3 -3
  960. package/es/core/structures/PDFFlateStream.d.ts.map +1 -1
  961. package/es/core/structures/PDFFlateStream.js +19 -23
  962. package/es/core/structures/PDFFlateStream.js.map +1 -1
  963. package/es/core/structures/PDFObjectStream.d.ts +4 -4
  964. package/es/core/structures/PDFObjectStream.d.ts.map +1 -1
  965. package/es/core/structures/PDFObjectStream.js +46 -54
  966. package/es/core/structures/PDFObjectStream.js.map +1 -1
  967. package/es/core/structures/PDFPageLeaf.d.ts +9 -9
  968. package/es/core/structures/PDFPageLeaf.d.ts.map +1 -1
  969. package/es/core/structures/PDFPageLeaf.js +125 -133
  970. package/es/core/structures/PDFPageLeaf.js.map +1 -1
  971. package/es/core/structures/PDFPageTree.d.ts +6 -6
  972. package/es/core/structures/PDFPageTree.d.ts.map +1 -1
  973. package/es/core/structures/PDFPageTree.js +66 -75
  974. package/es/core/structures/PDFPageTree.js.map +1 -1
  975. package/es/core/syntax/Delimiters.js +2 -2
  976. package/es/core/syntax/Delimiters.js.map +1 -1
  977. package/es/core/syntax/Irregular.js +5 -5
  978. package/es/core/syntax/Irregular.js.map +1 -1
  979. package/es/core/syntax/Keywords.d.ts +1 -1
  980. package/es/core/syntax/Keywords.d.ts.map +1 -1
  981. package/es/core/syntax/Keywords.js +14 -15
  982. package/es/core/syntax/Keywords.js.map +1 -1
  983. package/es/core/syntax/Numeric.js +5 -5
  984. package/es/core/syntax/Numeric.js.map +1 -1
  985. package/es/core/syntax/Whitespace.js +2 -2
  986. package/es/core/syntax/Whitespace.js.map +1 -1
  987. package/es/core/writers/PDFStreamWriter.d.ts +6 -6
  988. package/es/core/writers/PDFStreamWriter.d.ts.map +1 -1
  989. package/es/core/writers/PDFStreamWriter.js +73 -107
  990. package/es/core/writers/PDFStreamWriter.js.map +1 -1
  991. package/es/core/writers/PDFWriter.d.ts +12 -9
  992. package/es/core/writers/PDFWriter.d.ts.map +1 -1
  993. package/es/core/writers/PDFWriter.js +86 -127
  994. package/es/core/writers/PDFWriter.js.map +1 -1
  995. package/es/index.d.ts +4 -4
  996. package/es/index.d.ts.map +1 -1
  997. package/es/index.js +4 -4
  998. package/es/index.js.map +1 -1
  999. package/es/package.json +3 -0
  1000. package/es/types/fontkit.js +1 -0
  1001. package/es/types/index.d.ts +25 -1
  1002. package/es/types/index.d.ts.map +1 -1
  1003. package/es/types/index.js +1 -0
  1004. package/es/types/matrix.d.ts +8 -1
  1005. package/es/types/matrix.d.ts.map +1 -1
  1006. package/es/types/matrix.js +1 -1
  1007. package/es/types/matrix.js.map +1 -1
  1008. package/es/utils/Cache.js +10 -11
  1009. package/es/utils/Cache.js.map +1 -1
  1010. package/es/utils/arrays.d.ts +2 -1
  1011. package/es/utils/arrays.d.ts.map +1 -1
  1012. package/es/utils/arrays.js +65 -60
  1013. package/es/utils/arrays.js.map +1 -1
  1014. package/es/utils/async.d.ts.map +1 -1
  1015. package/es/utils/async.js +3 -5
  1016. package/es/utils/async.js.map +1 -1
  1017. package/es/utils/base64.d.ts.map +1 -1
  1018. package/es/utils/base64.js +24 -24
  1019. package/es/utils/base64.js.map +1 -1
  1020. package/es/utils/elements/Arc.d.ts +23 -0
  1021. package/es/utils/elements/Arc.d.ts.map +1 -0
  1022. package/es/utils/elements/Arc.js +74 -0
  1023. package/es/utils/elements/Arc.js.map +1 -0
  1024. package/es/utils/elements/Circle.d.ts +15 -0
  1025. package/es/utils/elements/Circle.d.ts.map +1 -0
  1026. package/es/utils/elements/Circle.js +37 -0
  1027. package/es/utils/elements/Circle.js.map +1 -0
  1028. package/es/utils/elements/Ellipse.d.ts +21 -0
  1029. package/es/utils/elements/Ellipse.d.ts.map +1 -0
  1030. package/es/utils/elements/Ellipse.js +87 -0
  1031. package/es/utils/elements/Ellipse.js.map +1 -0
  1032. package/es/utils/elements/GraphElement.d.ts +7 -0
  1033. package/es/utils/elements/GraphElement.d.ts.map +1 -0
  1034. package/es/utils/elements/GraphElement.js +8 -0
  1035. package/es/utils/elements/GraphElement.js.map +1 -0
  1036. package/es/utils/elements/Line.d.ts +24 -0
  1037. package/es/utils/elements/Line.d.ts.map +1 -0
  1038. package/es/utils/elements/Line.js +68 -0
  1039. package/es/utils/elements/Line.js.map +1 -0
  1040. package/es/utils/elements/Plot.d.ts +12 -0
  1041. package/es/utils/elements/Plot.d.ts.map +1 -0
  1042. package/es/utils/elements/Plot.js +42 -0
  1043. package/es/utils/elements/Plot.js.map +1 -0
  1044. package/es/utils/elements/Point.d.ts +19 -0
  1045. package/es/utils/elements/Point.d.ts.map +1 -0
  1046. package/es/utils/elements/Point.js +28 -0
  1047. package/es/utils/elements/Point.js.map +1 -0
  1048. package/es/utils/elements/Rectangle.d.ts +22 -0
  1049. package/es/utils/elements/Rectangle.d.ts.map +1 -0
  1050. package/es/utils/elements/Rectangle.js +54 -0
  1051. package/es/utils/elements/Rectangle.js.map +1 -0
  1052. package/es/utils/elements/Segment.d.ts +20 -0
  1053. package/es/utils/elements/Segment.d.ts.map +1 -0
  1054. package/es/utils/elements/Segment.js +76 -0
  1055. package/es/utils/elements/Segment.js.map +1 -0
  1056. package/es/utils/elements/index.d.ts +10 -0
  1057. package/es/utils/elements/index.d.ts.map +1 -0
  1058. package/es/utils/elements/index.js +10 -0
  1059. package/es/utils/elements/index.js.map +1 -0
  1060. package/es/utils/errors.js +1 -1
  1061. package/es/utils/errors.js.map +1 -1
  1062. package/es/utils/index.d.ts +11 -11
  1063. package/es/utils/index.d.ts.map +1 -1
  1064. package/es/utils/index.js +11 -11
  1065. package/es/utils/index.js.map +1 -1
  1066. package/es/utils/intersections.d.ts +10 -0
  1067. package/es/utils/intersections.d.ts.map +1 -0
  1068. package/es/utils/intersections.js +245 -0
  1069. package/es/utils/intersections.js.map +1 -0
  1070. package/es/utils/maths.d.ts +46 -0
  1071. package/es/utils/maths.d.ts.map +1 -0
  1072. package/es/utils/maths.js +69 -0
  1073. package/es/utils/maths.js.map +1 -0
  1074. package/es/utils/numbers.js +9 -9
  1075. package/es/utils/numbers.js.map +1 -1
  1076. package/es/utils/objects.js +4 -6
  1077. package/es/utils/objects.js.map +1 -1
  1078. package/es/utils/pdfDocEncoding.js +7 -7
  1079. package/es/utils/pdfDocEncoding.js.map +1 -1
  1080. package/es/utils/png.js +20 -22
  1081. package/es/utils/png.js.map +1 -1
  1082. package/es/utils/rng.js +7 -9
  1083. package/es/utils/rng.js.map +1 -1
  1084. package/es/utils/strings.d.ts +1 -0
  1085. package/es/utils/strings.d.ts.map +1 -1
  1086. package/es/utils/strings.js +62 -68
  1087. package/es/utils/strings.js.map +1 -1
  1088. package/es/utils/unicode.js +42 -63
  1089. package/es/utils/unicode.js.map +1 -1
  1090. package/es/utils/validators.js +38 -38
  1091. package/es/utils/validators.js.map +1 -1
  1092. package/package.json +29 -20
  1093. package/src/api/PDFDocument.ts +48 -21
  1094. package/src/api/PDFDocumentOptions.ts +3 -2
  1095. package/src/api/PDFEmbeddedFile.ts +4 -4
  1096. package/src/api/PDFEmbeddedPage.ts +4 -4
  1097. package/src/api/PDFFont.ts +4 -4
  1098. package/src/api/PDFImage.ts +4 -4
  1099. package/src/api/PDFJavaScript.ts +4 -4
  1100. package/src/api/PDFPage.ts +66 -19
  1101. package/src/api/PDFPageOptions.ts +28 -12
  1102. package/src/api/colors.ts +12 -2
  1103. package/src/api/form/PDFButton.ts +11 -11
  1104. package/src/api/form/PDFCheckBox.ts +8 -8
  1105. package/src/api/form/PDFDropdown.ts +9 -9
  1106. package/src/api/form/PDFField.ts +7 -7
  1107. package/src/api/form/PDFForm.ts +46 -38
  1108. package/src/api/form/PDFOptionList.ts +9 -9
  1109. package/src/api/form/PDFRadioGroup.ts +8 -8
  1110. package/src/api/form/PDFSignature.ts +4 -4
  1111. package/src/api/form/PDFTextField.ts +13 -13
  1112. package/src/api/form/appearances.ts +40 -48
  1113. package/src/api/form/index.ts +10 -10
  1114. package/src/api/image/index.ts +1 -1
  1115. package/src/api/index.ts +20 -20
  1116. package/src/api/objects.ts +1 -1
  1117. package/src/api/operations.ts +55 -12
  1118. package/src/api/operators.ts +10 -3
  1119. package/src/api/rotations.ts +1 -1
  1120. package/src/api/svg.ts +937 -0
  1121. package/src/api/svgPath.ts +2 -4
  1122. package/src/api/text/index.ts +2 -2
  1123. package/src/api/text/layout.ts +5 -5
  1124. package/src/core/PDFContext.ts +20 -19
  1125. package/src/core/PDFObjectCopier.ts +8 -8
  1126. package/src/core/acroform/PDFAcroButton.ts +8 -8
  1127. package/src/core/acroform/PDFAcroCheckBox.ts +6 -6
  1128. package/src/core/acroform/PDFAcroChoice.ts +7 -10
  1129. package/src/core/acroform/PDFAcroComboBox.ts +5 -5
  1130. package/src/core/acroform/PDFAcroField.ts +12 -11
  1131. package/src/core/acroform/PDFAcroForm.ts +8 -11
  1132. package/src/core/acroform/PDFAcroListBox.ts +4 -4
  1133. package/src/core/acroform/PDFAcroNonTerminal.ts +5 -5
  1134. package/src/core/acroform/PDFAcroPushButton.ts +5 -5
  1135. package/src/core/acroform/PDFAcroRadioButton.ts +7 -7
  1136. package/src/core/acroform/PDFAcroSignature.ts +3 -3
  1137. package/src/core/acroform/PDFAcroTerminal.ts +6 -6
  1138. package/src/core/acroform/PDFAcroText.ts +8 -8
  1139. package/src/core/acroform/index.ts +15 -15
  1140. package/src/core/acroform/utils.ts +20 -20
  1141. package/src/core/annotation/AppearanceCharacteristics.ts +6 -6
  1142. package/src/core/annotation/BorderStyle.ts +3 -3
  1143. package/src/core/annotation/PDFAnnotation.ts +6 -6
  1144. package/src/core/annotation/PDFWidgetAnnotation.ts +9 -9
  1145. package/src/core/annotation/index.ts +4 -4
  1146. package/src/core/crypto.ts +1989 -0
  1147. package/src/core/document/PDFCrossRefSection.ts +3 -3
  1148. package/src/core/document/PDFHeader.ts +2 -2
  1149. package/src/core/document/PDFTrailer.ts +2 -2
  1150. package/src/core/document/PDFTrailerDict.ts +2 -2
  1151. package/src/core/embedders/CMap.ts +3 -3
  1152. package/src/core/embedders/CustomFontEmbedder.ts +9 -9
  1153. package/src/core/embedders/CustomFontSubsetEmbedder.ts +11 -4
  1154. package/src/core/embedders/FileEmbedder.ts +4 -4
  1155. package/src/core/embedders/FontFlags.ts +1 -1
  1156. package/src/core/embedders/JavaScriptEmbedder.ts +3 -3
  1157. package/src/core/embedders/JpegEmbedder.ts +2 -2
  1158. package/src/core/embedders/PDFPageEmbedder.ts +13 -13
  1159. package/src/core/embedders/PngEmbedder.ts +3 -3
  1160. package/src/core/embedders/StandardFontEmbedder.ts +4 -4
  1161. package/src/core/errors.ts +2 -2
  1162. package/src/core/index.ts +47 -47
  1163. package/src/core/interactive/ViewerPreferences.ts +7 -7
  1164. package/src/core/objects/PDFArray.ts +14 -14
  1165. package/src/core/objects/PDFBool.ts +3 -3
  1166. package/src/core/objects/PDFDict.ts +14 -12
  1167. package/src/core/objects/PDFHexString.ts +4 -4
  1168. package/src/core/objects/PDFInvalidObject.ts +1 -1
  1169. package/src/core/objects/PDFName.ts +5 -5
  1170. package/src/core/objects/PDFNull.ts +2 -2
  1171. package/src/core/objects/PDFNumber.ts +2 -2
  1172. package/src/core/objects/PDFObject.ts +2 -2
  1173. package/src/core/objects/PDFRawStream.ts +17 -7
  1174. package/src/core/objects/PDFRef.ts +3 -3
  1175. package/src/core/objects/PDFStream.ts +7 -7
  1176. package/src/core/objects/PDFString.ts +4 -4
  1177. package/src/core/operators/PDFOperator.ts +10 -10
  1178. package/src/core/parser/BaseParser.ts +6 -6
  1179. package/src/core/parser/ByteStream.ts +4 -4
  1180. package/src/core/parser/PDFObjectParser.ts +78 -41
  1181. package/src/core/parser/PDFObjectStreamParser.ts +9 -9
  1182. package/src/core/parser/PDFParser.ts +37 -22
  1183. package/src/core/parser/PDFXRefStreamParser.ts +9 -9
  1184. package/src/core/streams/Ascii85Stream.ts +2 -2
  1185. package/src/core/streams/AsciiHexStream.ts +2 -2
  1186. package/src/core/streams/DecodeStream.ts +2 -2
  1187. package/src/core/streams/DecryptStream.ts +56 -0
  1188. package/src/core/streams/FlateStream.ts +2 -2
  1189. package/src/core/streams/LZWStream.ts +3 -3
  1190. package/src/core/streams/RunLengthStream.ts +2 -2
  1191. package/src/core/streams/decode.ts +22 -17
  1192. package/src/core/structures/PDFCatalog.ts +6 -6
  1193. package/src/core/structures/PDFContentStream.ts +5 -5
  1194. package/src/core/structures/PDFCrossRefStream.ts +6 -6
  1195. package/src/core/structures/PDFFlateStream.ts +5 -5
  1196. package/src/core/structures/PDFObjectStream.ts +8 -8
  1197. package/src/core/structures/PDFPageLeaf.ts +9 -9
  1198. package/src/core/structures/PDFPageTree.ts +8 -8
  1199. package/src/core/syntax/Delimiters.ts +1 -1
  1200. package/src/core/syntax/Irregular.ts +3 -3
  1201. package/src/core/syntax/Keywords.ts +1 -1
  1202. package/src/core/syntax/Numeric.ts +1 -1
  1203. package/src/core/syntax/Whitespace.ts +1 -1
  1204. package/src/core/writers/PDFStreamWriter.ts +13 -13
  1205. package/src/core/writers/PDFWriter.ts +13 -19
  1206. package/src/index.ts +4 -4
  1207. package/src/types/index.ts +38 -1
  1208. package/src/utils/arrays.ts +14 -2
  1209. package/src/utils/base64.ts +2 -1
  1210. package/src/utils/elements/Arc.ts +107 -0
  1211. package/src/utils/elements/Circle.ts +55 -0
  1212. package/src/utils/elements/Ellipse.ts +135 -0
  1213. package/src/utils/elements/GraphElement.ts +14 -0
  1214. package/src/utils/elements/Line.ts +85 -0
  1215. package/src/utils/elements/Plot.ts +50 -0
  1216. package/src/utils/elements/Point.ts +37 -0
  1217. package/src/utils/elements/Rectangle.ts +65 -0
  1218. package/src/utils/elements/Segment.ts +92 -0
  1219. package/src/utils/elements/index.ts +9 -0
  1220. package/src/utils/index.ts +11 -11
  1221. package/src/utils/intersections.ts +282 -0
  1222. package/src/utils/maths.ts +108 -0
  1223. package/src/utils/pdfDocEncoding.ts +1 -1
  1224. package/src/utils/strings.ts +8 -1
  1225. package/src/utils/unicode.ts +1 -1
  1226. package/src/utils/validators.ts +1 -1
  1227. package/ts3.4/cjs/api/PDFDocument.d.ts +11 -11
  1228. package/ts3.4/cjs/api/PDFDocumentOptions.d.ts +3 -2
  1229. package/ts3.4/cjs/api/PDFEmbeddedFile.d.ts +4 -4
  1230. package/ts3.4/cjs/api/PDFEmbeddedPage.d.ts +3 -3
  1231. package/ts3.4/cjs/api/PDFFont.d.ts +3 -3
  1232. package/ts3.4/cjs/api/PDFImage.d.ts +3 -3
  1233. package/ts3.4/cjs/api/PDFJavaScript.d.ts +4 -4
  1234. package/ts3.4/cjs/api/PDFPage.d.ts +21 -9
  1235. package/ts3.4/cjs/api/PDFPageOptions.d.ts +29 -12
  1236. package/ts3.4/cjs/api/colors.d.ts +4 -0
  1237. package/ts3.4/cjs/api/form/PDFButton.d.ts +8 -8
  1238. package/ts3.4/cjs/api/form/PDFCheckBox.d.ts +5 -5
  1239. package/ts3.4/cjs/api/form/PDFDropdown.d.ts +6 -6
  1240. package/ts3.4/cjs/api/form/PDFField.d.ts +6 -6
  1241. package/ts3.4/cjs/api/form/PDFForm.d.ts +11 -11
  1242. package/ts3.4/cjs/api/form/PDFOptionList.d.ts +6 -6
  1243. package/ts3.4/cjs/api/form/PDFRadioGroup.d.ts +5 -5
  1244. package/ts3.4/cjs/api/form/PDFSignature.d.ts +3 -3
  1245. package/ts3.4/cjs/api/form/PDFTextField.d.ts +8 -8
  1246. package/ts3.4/cjs/api/form/appearances.d.ts +11 -11
  1247. package/ts3.4/cjs/api/form/index.d.ts +10 -10
  1248. package/ts3.4/cjs/api/image/index.d.ts +1 -1
  1249. package/ts3.4/cjs/api/index.d.ts +20 -20
  1250. package/ts3.4/cjs/api/objects.d.ts +1 -1
  1251. package/ts3.4/cjs/api/operations.d.ts +20 -4
  1252. package/ts3.4/cjs/api/operators.d.ts +6 -1
  1253. package/ts3.4/cjs/api/rotations.d.ts +1 -1
  1254. package/ts3.4/cjs/api/svg.d.ts +71 -0
  1255. package/ts3.4/cjs/api/svgPath.d.ts +1 -1
  1256. package/ts3.4/cjs/api/text/index.d.ts +2 -2
  1257. package/ts3.4/cjs/api/text/layout.d.ts +3 -3
  1258. package/ts3.4/cjs/core/PDFContext.d.ts +17 -16
  1259. package/ts3.4/cjs/core/PDFObjectCopier.d.ts +2 -2
  1260. package/ts3.4/cjs/core/acroform/PDFAcroButton.d.ts +7 -7
  1261. package/ts3.4/cjs/core/acroform/PDFAcroCheckBox.d.ts +5 -5
  1262. package/ts3.4/cjs/core/acroform/PDFAcroChoice.d.ts +4 -4
  1263. package/ts3.4/cjs/core/acroform/PDFAcroComboBox.d.ts +4 -4
  1264. package/ts3.4/cjs/core/acroform/PDFAcroField.d.ts +8 -8
  1265. package/ts3.4/cjs/core/acroform/PDFAcroForm.d.ts +5 -5
  1266. package/ts3.4/cjs/core/acroform/PDFAcroListBox.d.ts +4 -4
  1267. package/ts3.4/cjs/core/acroform/PDFAcroNonTerminal.d.ts +4 -4
  1268. package/ts3.4/cjs/core/acroform/PDFAcroPushButton.d.ts +4 -4
  1269. package/ts3.4/cjs/core/acroform/PDFAcroRadioButton.d.ts +5 -5
  1270. package/ts3.4/cjs/core/acroform/PDFAcroSignature.d.ts +3 -3
  1271. package/ts3.4/cjs/core/acroform/PDFAcroTerminal.d.ts +5 -5
  1272. package/ts3.4/cjs/core/acroform/PDFAcroText.d.ts +7 -7
  1273. package/ts3.4/cjs/core/acroform/index.d.ts +15 -15
  1274. package/ts3.4/cjs/core/acroform/utils.d.ts +4 -4
  1275. package/ts3.4/cjs/core/annotation/AppearanceCharacteristics.d.ts +5 -5
  1276. package/ts3.4/cjs/core/annotation/BorderStyle.d.ts +2 -2
  1277. package/ts3.4/cjs/core/annotation/PDFAnnotation.d.ts +6 -6
  1278. package/ts3.4/cjs/core/annotation/PDFWidgetAnnotation.d.ts +9 -9
  1279. package/ts3.4/cjs/core/annotation/index.d.ts +4 -4
  1280. package/ts3.4/cjs/core/crypto.d.ts +96 -0
  1281. package/ts3.4/cjs/core/document/PDFCrossRefSection.d.ts +1 -1
  1282. package/ts3.4/cjs/core/document/PDFTrailerDict.d.ts +1 -1
  1283. package/ts3.4/cjs/core/embedders/CMap.d.ts +1 -1
  1284. package/ts3.4/cjs/core/embedders/CustomFontEmbedder.d.ts +5 -5
  1285. package/ts3.4/cjs/core/embedders/CustomFontSubsetEmbedder.d.ts +3 -3
  1286. package/ts3.4/cjs/core/embedders/FileEmbedder.d.ts +2 -2
  1287. package/ts3.4/cjs/core/embedders/FontFlags.d.ts +1 -1
  1288. package/ts3.4/cjs/core/embedders/JavaScriptEmbedder.d.ts +2 -2
  1289. package/ts3.4/cjs/core/embedders/JpegEmbedder.d.ts +2 -2
  1290. package/ts3.4/cjs/core/embedders/PDFPageEmbedder.d.ts +4 -4
  1291. package/ts3.4/cjs/core/embedders/PngEmbedder.d.ts +2 -2
  1292. package/ts3.4/cjs/core/embedders/StandardFontEmbedder.d.ts +3 -3
  1293. package/ts3.4/cjs/core/errors.d.ts +1 -1
  1294. package/ts3.4/cjs/core/index.d.ts +47 -47
  1295. package/ts3.4/cjs/core/interactive/ViewerPreferences.d.ts +6 -6
  1296. package/ts3.4/cjs/core/objects/PDFArray.d.ts +12 -12
  1297. package/ts3.4/cjs/core/objects/PDFBool.d.ts +1 -1
  1298. package/ts3.4/cjs/core/objects/PDFDict.d.ts +12 -11
  1299. package/ts3.4/cjs/core/objects/PDFHexString.d.ts +1 -1
  1300. package/ts3.4/cjs/core/objects/PDFInvalidObject.d.ts +1 -1
  1301. package/ts3.4/cjs/core/objects/PDFName.d.ts +1 -1
  1302. package/ts3.4/cjs/core/objects/PDFNull.d.ts +1 -1
  1303. package/ts3.4/cjs/core/objects/PDFNumber.d.ts +1 -1
  1304. package/ts3.4/cjs/core/objects/PDFObject.d.ts +1 -1
  1305. package/ts3.4/cjs/core/objects/PDFRawStream.d.ts +6 -4
  1306. package/ts3.4/cjs/core/objects/PDFRef.d.ts +1 -1
  1307. package/ts3.4/cjs/core/objects/PDFStream.d.ts +3 -3
  1308. package/ts3.4/cjs/core/objects/PDFString.d.ts +1 -1
  1309. package/ts3.4/cjs/core/operators/PDFOperator.d.ts +7 -7
  1310. package/ts3.4/cjs/core/parser/BaseParser.d.ts +1 -1
  1311. package/ts3.4/cjs/core/parser/ByteStream.d.ts +1 -1
  1312. package/ts3.4/cjs/core/parser/PDFObjectParser.d.ts +22 -20
  1313. package/ts3.4/cjs/core/parser/PDFObjectStreamParser.d.ts +2 -2
  1314. package/ts3.4/cjs/core/parser/PDFParser.d.ts +5 -4
  1315. package/ts3.4/cjs/core/parser/PDFXRefStreamParser.d.ts +2 -2
  1316. package/ts3.4/cjs/core/streams/Ascii85Stream.d.ts +2 -2
  1317. package/ts3.4/cjs/core/streams/AsciiHexStream.d.ts +2 -2
  1318. package/ts3.4/cjs/core/streams/DecodeStream.d.ts +1 -1
  1319. package/ts3.4/cjs/core/streams/DecryptStream.d.ts +13 -0
  1320. package/ts3.4/cjs/core/streams/FlateStream.d.ts +2 -2
  1321. package/ts3.4/cjs/core/streams/LZWStream.d.ts +3 -3
  1322. package/ts3.4/cjs/core/streams/RunLengthStream.d.ts +2 -2
  1323. package/ts3.4/cjs/core/streams/decode.d.ts +3 -3
  1324. package/ts3.4/cjs/core/structures/PDFCatalog.d.ts +5 -5
  1325. package/ts3.4/cjs/core/structures/PDFContentStream.d.ts +4 -4
  1326. package/ts3.4/cjs/core/structures/PDFCrossRefStream.d.ts +4 -4
  1327. package/ts3.4/cjs/core/structures/PDFFlateStream.d.ts +3 -3
  1328. package/ts3.4/cjs/core/structures/PDFObjectStream.d.ts +4 -4
  1329. package/ts3.4/cjs/core/structures/PDFPageLeaf.d.ts +9 -9
  1330. package/ts3.4/cjs/core/structures/PDFPageTree.d.ts +6 -6
  1331. package/ts3.4/cjs/core/syntax/Keywords.d.ts +1 -1
  1332. package/ts3.4/cjs/core/writers/PDFStreamWriter.d.ts +6 -6
  1333. package/ts3.4/cjs/core/writers/PDFWriter.d.ts +8 -8
  1334. package/ts3.4/cjs/index.d.ts +4 -4
  1335. package/ts3.4/cjs/types/index.d.ts +25 -1
  1336. package/ts3.4/cjs/utils/arrays.d.ts +2 -1
  1337. package/ts3.4/cjs/utils/elements/Arc.d.ts +23 -0
  1338. package/ts3.4/cjs/utils/elements/Circle.d.ts +15 -0
  1339. package/ts3.4/cjs/utils/elements/Ellipse.d.ts +21 -0
  1340. package/ts3.4/cjs/utils/elements/GraphElement.d.ts +7 -0
  1341. package/ts3.4/cjs/utils/elements/Line.d.ts +24 -0
  1342. package/ts3.4/cjs/utils/elements/Plot.d.ts +12 -0
  1343. package/ts3.4/cjs/utils/elements/Point.d.ts +19 -0
  1344. package/ts3.4/cjs/utils/elements/Rectangle.d.ts +22 -0
  1345. package/ts3.4/cjs/utils/elements/Segment.d.ts +20 -0
  1346. package/ts3.4/cjs/utils/elements/index.d.ts +10 -0
  1347. package/ts3.4/cjs/utils/index.d.ts +11 -11
  1348. package/ts3.4/cjs/utils/intersections.d.ts +10 -0
  1349. package/ts3.4/cjs/utils/maths.d.ts +46 -0
  1350. package/ts3.4/cjs/utils/strings.d.ts +1 -0
  1351. package/ts3.4/es/api/PDFDocument.d.ts +11 -11
  1352. package/ts3.4/es/api/PDFDocumentOptions.d.ts +3 -2
  1353. package/ts3.4/es/api/PDFEmbeddedFile.d.ts +4 -4
  1354. package/ts3.4/es/api/PDFEmbeddedPage.d.ts +3 -3
  1355. package/ts3.4/es/api/PDFFont.d.ts +3 -3
  1356. package/ts3.4/es/api/PDFImage.d.ts +3 -3
  1357. package/ts3.4/es/api/PDFJavaScript.d.ts +4 -4
  1358. package/ts3.4/es/api/PDFPage.d.ts +21 -9
  1359. package/ts3.4/es/api/PDFPageOptions.d.ts +29 -12
  1360. package/ts3.4/es/api/colors.d.ts +4 -0
  1361. package/ts3.4/es/api/form/PDFButton.d.ts +8 -8
  1362. package/ts3.4/es/api/form/PDFCheckBox.d.ts +5 -5
  1363. package/ts3.4/es/api/form/PDFDropdown.d.ts +6 -6
  1364. package/ts3.4/es/api/form/PDFField.d.ts +6 -6
  1365. package/ts3.4/es/api/form/PDFForm.d.ts +11 -11
  1366. package/ts3.4/es/api/form/PDFOptionList.d.ts +6 -6
  1367. package/ts3.4/es/api/form/PDFRadioGroup.d.ts +5 -5
  1368. package/ts3.4/es/api/form/PDFSignature.d.ts +3 -3
  1369. package/ts3.4/es/api/form/PDFTextField.d.ts +8 -8
  1370. package/ts3.4/es/api/form/appearances.d.ts +11 -11
  1371. package/ts3.4/es/api/form/index.d.ts +10 -10
  1372. package/ts3.4/es/api/image/index.d.ts +1 -1
  1373. package/ts3.4/es/api/index.d.ts +20 -20
  1374. package/ts3.4/es/api/objects.d.ts +1 -1
  1375. package/ts3.4/es/api/operations.d.ts +20 -4
  1376. package/ts3.4/es/api/operators.d.ts +6 -1
  1377. package/ts3.4/es/api/rotations.d.ts +1 -1
  1378. package/ts3.4/es/api/svg.d.ts +71 -0
  1379. package/ts3.4/es/api/svgPath.d.ts +1 -1
  1380. package/ts3.4/es/api/text/index.d.ts +2 -2
  1381. package/ts3.4/es/api/text/layout.d.ts +3 -3
  1382. package/ts3.4/es/core/PDFContext.d.ts +17 -16
  1383. package/ts3.4/es/core/PDFObjectCopier.d.ts +2 -2
  1384. package/ts3.4/es/core/acroform/PDFAcroButton.d.ts +7 -7
  1385. package/ts3.4/es/core/acroform/PDFAcroCheckBox.d.ts +5 -5
  1386. package/ts3.4/es/core/acroform/PDFAcroChoice.d.ts +4 -4
  1387. package/ts3.4/es/core/acroform/PDFAcroComboBox.d.ts +4 -4
  1388. package/ts3.4/es/core/acroform/PDFAcroField.d.ts +8 -8
  1389. package/ts3.4/es/core/acroform/PDFAcroForm.d.ts +5 -5
  1390. package/ts3.4/es/core/acroform/PDFAcroListBox.d.ts +4 -4
  1391. package/ts3.4/es/core/acroform/PDFAcroNonTerminal.d.ts +4 -4
  1392. package/ts3.4/es/core/acroform/PDFAcroPushButton.d.ts +4 -4
  1393. package/ts3.4/es/core/acroform/PDFAcroRadioButton.d.ts +5 -5
  1394. package/ts3.4/es/core/acroform/PDFAcroSignature.d.ts +3 -3
  1395. package/ts3.4/es/core/acroform/PDFAcroTerminal.d.ts +5 -5
  1396. package/ts3.4/es/core/acroform/PDFAcroText.d.ts +7 -7
  1397. package/ts3.4/es/core/acroform/index.d.ts +15 -15
  1398. package/ts3.4/es/core/acroform/utils.d.ts +4 -4
  1399. package/ts3.4/es/core/annotation/AppearanceCharacteristics.d.ts +5 -5
  1400. package/ts3.4/es/core/annotation/BorderStyle.d.ts +2 -2
  1401. package/ts3.4/es/core/annotation/PDFAnnotation.d.ts +6 -6
  1402. package/ts3.4/es/core/annotation/PDFWidgetAnnotation.d.ts +9 -9
  1403. package/ts3.4/es/core/annotation/index.d.ts +4 -4
  1404. package/ts3.4/es/core/crypto.d.ts +96 -0
  1405. package/ts3.4/es/core/document/PDFCrossRefSection.d.ts +1 -1
  1406. package/ts3.4/es/core/document/PDFTrailerDict.d.ts +1 -1
  1407. package/ts3.4/es/core/embedders/CMap.d.ts +1 -1
  1408. package/ts3.4/es/core/embedders/CustomFontEmbedder.d.ts +5 -5
  1409. package/ts3.4/es/core/embedders/CustomFontSubsetEmbedder.d.ts +3 -3
  1410. package/ts3.4/es/core/embedders/FileEmbedder.d.ts +2 -2
  1411. package/ts3.4/es/core/embedders/FontFlags.d.ts +1 -1
  1412. package/ts3.4/es/core/embedders/JavaScriptEmbedder.d.ts +2 -2
  1413. package/ts3.4/es/core/embedders/JpegEmbedder.d.ts +2 -2
  1414. package/ts3.4/es/core/embedders/PDFPageEmbedder.d.ts +4 -4
  1415. package/ts3.4/es/core/embedders/PngEmbedder.d.ts +2 -2
  1416. package/ts3.4/es/core/embedders/StandardFontEmbedder.d.ts +3 -3
  1417. package/ts3.4/es/core/errors.d.ts +1 -1
  1418. package/ts3.4/es/core/index.d.ts +47 -47
  1419. package/ts3.4/es/core/interactive/ViewerPreferences.d.ts +6 -6
  1420. package/ts3.4/es/core/objects/PDFArray.d.ts +12 -12
  1421. package/ts3.4/es/core/objects/PDFBool.d.ts +1 -1
  1422. package/ts3.4/es/core/objects/PDFDict.d.ts +12 -11
  1423. package/ts3.4/es/core/objects/PDFHexString.d.ts +1 -1
  1424. package/ts3.4/es/core/objects/PDFInvalidObject.d.ts +1 -1
  1425. package/ts3.4/es/core/objects/PDFName.d.ts +1 -1
  1426. package/ts3.4/es/core/objects/PDFNull.d.ts +1 -1
  1427. package/ts3.4/es/core/objects/PDFNumber.d.ts +1 -1
  1428. package/ts3.4/es/core/objects/PDFObject.d.ts +1 -1
  1429. package/ts3.4/es/core/objects/PDFRawStream.d.ts +6 -4
  1430. package/ts3.4/es/core/objects/PDFRef.d.ts +1 -1
  1431. package/ts3.4/es/core/objects/PDFStream.d.ts +3 -3
  1432. package/ts3.4/es/core/objects/PDFString.d.ts +1 -1
  1433. package/ts3.4/es/core/operators/PDFOperator.d.ts +7 -7
  1434. package/ts3.4/es/core/parser/BaseParser.d.ts +1 -1
  1435. package/ts3.4/es/core/parser/ByteStream.d.ts +1 -1
  1436. package/ts3.4/es/core/parser/PDFObjectParser.d.ts +22 -20
  1437. package/ts3.4/es/core/parser/PDFObjectStreamParser.d.ts +2 -2
  1438. package/ts3.4/es/core/parser/PDFParser.d.ts +5 -4
  1439. package/ts3.4/es/core/parser/PDFXRefStreamParser.d.ts +2 -2
  1440. package/ts3.4/es/core/streams/Ascii85Stream.d.ts +2 -2
  1441. package/ts3.4/es/core/streams/AsciiHexStream.d.ts +2 -2
  1442. package/ts3.4/es/core/streams/DecodeStream.d.ts +1 -1
  1443. package/ts3.4/es/core/streams/DecryptStream.d.ts +13 -0
  1444. package/ts3.4/es/core/streams/FlateStream.d.ts +2 -2
  1445. package/ts3.4/es/core/streams/LZWStream.d.ts +3 -3
  1446. package/ts3.4/es/core/streams/RunLengthStream.d.ts +2 -2
  1447. package/ts3.4/es/core/streams/decode.d.ts +3 -3
  1448. package/ts3.4/es/core/structures/PDFCatalog.d.ts +5 -5
  1449. package/ts3.4/es/core/structures/PDFContentStream.d.ts +4 -4
  1450. package/ts3.4/es/core/structures/PDFCrossRefStream.d.ts +4 -4
  1451. package/ts3.4/es/core/structures/PDFFlateStream.d.ts +3 -3
  1452. package/ts3.4/es/core/structures/PDFObjectStream.d.ts +4 -4
  1453. package/ts3.4/es/core/structures/PDFPageLeaf.d.ts +9 -9
  1454. package/ts3.4/es/core/structures/PDFPageTree.d.ts +6 -6
  1455. package/ts3.4/es/core/syntax/Keywords.d.ts +1 -1
  1456. package/ts3.4/es/core/writers/PDFStreamWriter.d.ts +6 -6
  1457. package/ts3.4/es/core/writers/PDFWriter.d.ts +8 -8
  1458. package/ts3.4/es/index.d.ts +4 -4
  1459. package/ts3.4/es/types/index.d.ts +25 -1
  1460. package/ts3.4/es/utils/arrays.d.ts +2 -1
  1461. package/ts3.4/es/utils/elements/Arc.d.ts +23 -0
  1462. package/ts3.4/es/utils/elements/Circle.d.ts +15 -0
  1463. package/ts3.4/es/utils/elements/Ellipse.d.ts +21 -0
  1464. package/ts3.4/es/utils/elements/GraphElement.d.ts +7 -0
  1465. package/ts3.4/es/utils/elements/Line.d.ts +24 -0
  1466. package/ts3.4/es/utils/elements/Plot.d.ts +12 -0
  1467. package/ts3.4/es/utils/elements/Point.d.ts +19 -0
  1468. package/ts3.4/es/utils/elements/Rectangle.d.ts +22 -0
  1469. package/ts3.4/es/utils/elements/Segment.d.ts +20 -0
  1470. package/ts3.4/es/utils/elements/index.d.ts +10 -0
  1471. package/ts3.4/es/utils/index.d.ts +11 -11
  1472. package/ts3.4/es/utils/intersections.d.ts +10 -0
  1473. package/ts3.4/es/utils/maths.d.ts +46 -0
  1474. package/ts3.4/es/utils/strings.d.ts +1 -0
  1475. package/yarn.lock +0 -4408
@@ -0,0 +1,1989 @@
1
+ /* Copyright 2012 Mozilla Foundation
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ import { arrayAsString, isArrayEqual } from '../utils/arrays';
17
+ import { stringAsByteArray } from '../utils/strings';
18
+ import PDFBool from './objects/PDFBool.js';
19
+ import PDFDict from './objects/PDFDict.js';
20
+ import PDFName from './objects/PDFName.js';
21
+ import PDFNumber from './objects/PDFNumber.js';
22
+ import PDFString from './objects/PDFString.js';
23
+ import DecryptStream from './streams/DecryptStream.js';
24
+ import { StreamType } from './streams/Stream.js';
25
+
26
+ class ARCFourCipher {
27
+ private s: Uint8Array;
28
+ private a: number;
29
+ private b: number;
30
+
31
+ constructor(key: Uint8Array) {
32
+ this.a = 0;
33
+ this.b = 0;
34
+ const s = new Uint8Array(256);
35
+ const keyLength = key.length;
36
+
37
+ for (let i = 0; i < 256; ++i) {
38
+ s[i] = i;
39
+ }
40
+ for (let i = 0, j = 0; i < 256; ++i) {
41
+ const tmp = s[i];
42
+ j = (j + tmp + key[i % keyLength]) & 0xff;
43
+ s[i] = s[j];
44
+ s[j] = tmp;
45
+ }
46
+ this.s = s;
47
+ }
48
+
49
+ encryptBlock(data: Uint8Array) {
50
+ let a = this.a,
51
+ b = this.b;
52
+ const s = this.s;
53
+ const n = data.length;
54
+ const output = new Uint8Array(n);
55
+ for (let i = 0; i < n; ++i) {
56
+ a = (a + 1) & 0xff;
57
+ const tmp = s[a];
58
+ b = (b + tmp) & 0xff;
59
+ const tmp2 = s[b];
60
+ s[a] = tmp2;
61
+ s[b] = tmp;
62
+ output[i] = data[i] ^ s[(tmp + tmp2) & 0xff];
63
+ }
64
+ this.a = a;
65
+ this.b = b;
66
+ return output;
67
+ }
68
+
69
+ decryptBlock(data: Uint8Array) {
70
+ return this.encryptBlock(data);
71
+ }
72
+
73
+ encrypt(data: Uint8Array) {
74
+ return this.encryptBlock(data);
75
+ }
76
+ }
77
+
78
+ const calculateMD5 = (function calculateMD5Closure() {
79
+ const r = new Uint8Array([
80
+ 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5,
81
+ 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11,
82
+ 16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10,
83
+ 15, 21,
84
+ ]);
85
+
86
+ const k = new Int32Array([
87
+ -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
88
+ -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
89
+ 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
90
+ 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
91
+ 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
92
+ 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
93
+ -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
94
+ -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
95
+ -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
96
+ -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
97
+ -145523070, -1120210379, 718787259, -343485551,
98
+ ]);
99
+
100
+ function hash(data: Uint8Array, offset: number, length: number) {
101
+ let h0 = 1732584193,
102
+ h1 = -271733879,
103
+ h2 = -1732584194,
104
+ h3 = 271733878;
105
+ // pre-processing
106
+ const paddedLength = (length + 72) & ~63; // data + 9 extra bytes
107
+ const padded = new Uint8Array(paddedLength);
108
+ let i, j;
109
+ for (i = 0; i < length; ++i) {
110
+ padded[i] = data[offset++];
111
+ }
112
+ padded[i++] = 0x80;
113
+ const n = paddedLength - 8;
114
+ while (i < n) {
115
+ padded[i++] = 0;
116
+ }
117
+ padded[i++] = (length << 3) & 0xff;
118
+ padded[i++] = (length >> 5) & 0xff;
119
+ padded[i++] = (length >> 13) & 0xff;
120
+ padded[i++] = (length >> 21) & 0xff;
121
+ padded[i++] = (length >>> 29) & 0xff;
122
+ padded[i++] = 0;
123
+ padded[i++] = 0;
124
+ padded[i++] = 0;
125
+ const w = new Int32Array(16);
126
+ for (i = 0; i < paddedLength; ) {
127
+ for (j = 0; j < 16; ++j, i += 4) {
128
+ w[j] =
129
+ padded[i] |
130
+ (padded[i + 1] << 8) |
131
+ (padded[i + 2] << 16) |
132
+ (padded[i + 3] << 24);
133
+ }
134
+ let a = h0,
135
+ b = h1,
136
+ c = h2,
137
+ d = h3,
138
+ f,
139
+ g;
140
+ for (j = 0; j < 64; ++j) {
141
+ if (j < 16) {
142
+ f = (b & c) | (~b & d);
143
+ g = j;
144
+ } else if (j < 32) {
145
+ f = (d & b) | (~d & c);
146
+ g = (5 * j + 1) & 15;
147
+ } else if (j < 48) {
148
+ f = b ^ c ^ d;
149
+ g = (3 * j + 5) & 15;
150
+ } else {
151
+ f = c ^ (b | ~d);
152
+ g = (7 * j) & 15;
153
+ }
154
+ const tmp = d,
155
+ rotateArg = (a + f + k[j] + w[g]) | 0,
156
+ rotate = r[j];
157
+ d = c;
158
+ c = b;
159
+ b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
160
+ a = tmp;
161
+ }
162
+ h0 = (h0 + a) | 0;
163
+ h1 = (h1 + b) | 0;
164
+ h2 = (h2 + c) | 0;
165
+ h3 = (h3 + d) | 0;
166
+ }
167
+ // prettier-ignore
168
+ return new Uint8Array([
169
+ h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
170
+ h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
171
+ h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
172
+ h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
173
+ ]);
174
+ }
175
+
176
+ return hash;
177
+ })();
178
+
179
+ class Word64 {
180
+ private low: number;
181
+ private high: number;
182
+
183
+ constructor(highInteger: number, lowInteger: number) {
184
+ this.high = highInteger | 0;
185
+ this.low = lowInteger | 0;
186
+ }
187
+
188
+ and(word: Word64) {
189
+ this.high &= word.high;
190
+ this.low &= word.low;
191
+ }
192
+
193
+ xor(word: Word64) {
194
+ this.high ^= word.high;
195
+ this.low ^= word.low;
196
+ }
197
+
198
+ or(word: Word64) {
199
+ this.high |= word.high;
200
+ this.low |= word.low;
201
+ }
202
+
203
+ shiftRight(places: number) {
204
+ if (places >= 32) {
205
+ this.low = (this.high >>> (places - 32)) | 0;
206
+ this.high = 0;
207
+ } else {
208
+ this.low = (this.low >>> places) | (this.high << (32 - places));
209
+ this.high = (this.high >>> places) | 0;
210
+ }
211
+ }
212
+
213
+ shiftLeft(places: number) {
214
+ if (places >= 32) {
215
+ this.high = this.low << (places - 32);
216
+ this.low = 0;
217
+ } else {
218
+ this.high = (this.high << places) | (this.low >>> (32 - places));
219
+ this.low <<= places;
220
+ }
221
+ }
222
+
223
+ rotateRight(places: number) {
224
+ let low, high;
225
+ if (places & 32) {
226
+ high = this.low;
227
+ low = this.high;
228
+ } else {
229
+ low = this.low;
230
+ high = this.high;
231
+ }
232
+ places &= 31;
233
+ this.low = (low >>> places) | (high << (32 - places));
234
+ this.high = (high >>> places) | (low << (32 - places));
235
+ }
236
+
237
+ not() {
238
+ this.high = ~this.high;
239
+ this.low = ~this.low;
240
+ }
241
+
242
+ add(word: Word64) {
243
+ const lowAdd = (this.low >>> 0) + (word.low >>> 0);
244
+ let highAdd = (this.high >>> 0) + (word.high >>> 0);
245
+ if (lowAdd > 0xffffffff) {
246
+ highAdd += 1;
247
+ }
248
+ this.low = lowAdd | 0;
249
+ this.high = highAdd | 0;
250
+ }
251
+
252
+ copyTo(bytes: Uint8Array, offset: number) {
253
+ bytes[offset] = (this.high >>> 24) & 0xff;
254
+ bytes[offset + 1] = (this.high >> 16) & 0xff;
255
+ bytes[offset + 2] = (this.high >> 8) & 0xff;
256
+ bytes[offset + 3] = this.high & 0xff;
257
+ bytes[offset + 4] = (this.low >>> 24) & 0xff;
258
+ bytes[offset + 5] = (this.low >> 16) & 0xff;
259
+ bytes[offset + 6] = (this.low >> 8) & 0xff;
260
+ bytes[offset + 7] = this.low & 0xff;
261
+ }
262
+
263
+ assign(word: Word64) {
264
+ this.high = word.high;
265
+ this.low = word.low;
266
+ }
267
+ }
268
+
269
+ const calculateSHA256 = (function calculateSHA256Closure() {
270
+ function rotr(x: number, n: number) {
271
+ return (x >>> n) | (x << (32 - n));
272
+ }
273
+
274
+ function ch(x: number, y: number, z: number) {
275
+ return (x & y) ^ (~x & z);
276
+ }
277
+
278
+ function maj(x: number, y: number, z: number) {
279
+ return (x & y) ^ (x & z) ^ (y & z);
280
+ }
281
+
282
+ function sigma(x: number) {
283
+ return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
284
+ }
285
+
286
+ function sigmaPrime(x: number) {
287
+ return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
288
+ }
289
+
290
+ function littleSigma(x: number) {
291
+ return rotr(x, 7) ^ rotr(x, 18) ^ (x >>> 3);
292
+ }
293
+
294
+ function littleSigmaPrime(x: number) {
295
+ return rotr(x, 17) ^ rotr(x, 19) ^ (x >>> 10);
296
+ }
297
+
298
+ const k = [
299
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
300
+ 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
301
+ 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
302
+ 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
303
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
304
+ 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
305
+ 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
306
+ 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
307
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
308
+ 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
309
+ 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
310
+ ];
311
+
312
+ function hash(data: Uint8Array, offset: number, length: number) {
313
+ // initial hash values
314
+ let h0 = 0x6a09e667,
315
+ h1 = 0xbb67ae85,
316
+ h2 = 0x3c6ef372,
317
+ h3 = 0xa54ff53a,
318
+ h4 = 0x510e527f,
319
+ h5 = 0x9b05688c,
320
+ h6 = 0x1f83d9ab,
321
+ h7 = 0x5be0cd19;
322
+ // pre-processing
323
+ const paddedLength = Math.ceil((length + 9) / 64) * 64;
324
+ const padded = new Uint8Array(paddedLength);
325
+ let i, j;
326
+ for (i = 0; i < length; ++i) {
327
+ padded[i] = data[offset++];
328
+ }
329
+ padded[i++] = 0x80;
330
+ const n = paddedLength - 8;
331
+ while (i < n) {
332
+ padded[i++] = 0;
333
+ }
334
+ padded[i++] = 0;
335
+ padded[i++] = 0;
336
+ padded[i++] = 0;
337
+ padded[i++] = (length >>> 29) & 0xff;
338
+ padded[i++] = (length >> 21) & 0xff;
339
+ padded[i++] = (length >> 13) & 0xff;
340
+ padded[i++] = (length >> 5) & 0xff;
341
+ padded[i++] = (length << 3) & 0xff;
342
+ const w = new Uint32Array(64);
343
+ // for each 512 bit block
344
+ for (i = 0; i < paddedLength; ) {
345
+ for (j = 0; j < 16; ++j) {
346
+ w[j] =
347
+ (padded[i] << 24) |
348
+ (padded[i + 1] << 16) |
349
+ (padded[i + 2] << 8) |
350
+ padded[i + 3];
351
+ i += 4;
352
+ }
353
+
354
+ for (j = 16; j < 64; ++j) {
355
+ w[j] =
356
+ (littleSigmaPrime(w[j - 2]) +
357
+ w[j - 7] +
358
+ littleSigma(w[j - 15]) +
359
+ w[j - 16]) |
360
+ 0;
361
+ }
362
+ let a = h0,
363
+ b = h1,
364
+ c = h2,
365
+ d = h3,
366
+ e = h4,
367
+ f = h5,
368
+ g = h6,
369
+ h = h7,
370
+ t1,
371
+ t2;
372
+ for (j = 0; j < 64; ++j) {
373
+ t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
374
+ t2 = sigma(a) + maj(a, b, c);
375
+ h = g;
376
+ g = f;
377
+ f = e;
378
+ e = (d + t1) | 0;
379
+ d = c;
380
+ c = b;
381
+ b = a;
382
+ a = (t1 + t2) | 0;
383
+ }
384
+ h0 = (h0 + a) | 0;
385
+ h1 = (h1 + b) | 0;
386
+ h2 = (h2 + c) | 0;
387
+ h3 = (h3 + d) | 0;
388
+ h4 = (h4 + e) | 0;
389
+ h5 = (h5 + f) | 0;
390
+ h6 = (h6 + g) | 0;
391
+ h7 = (h7 + h) | 0;
392
+ }
393
+ // prettier-ignore
394
+ return new Uint8Array([
395
+ (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
396
+ (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
397
+ (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
398
+ (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
399
+ (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
400
+ (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
401
+ (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
402
+ (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
403
+ ]);
404
+ }
405
+
406
+ return hash;
407
+ })();
408
+
409
+ const calculateSHA512 = (function calculateSHA512Closure() {
410
+ function ch(result: Word64, x: Word64, y: Word64, z: Word64, tmp: Word64) {
411
+ result.assign(x);
412
+ result.and(y);
413
+ tmp.assign(x);
414
+ tmp.not();
415
+ tmp.and(z);
416
+ result.xor(tmp);
417
+ }
418
+
419
+ function maj(result: Word64, x: Word64, y: Word64, z: Word64, tmp: Word64) {
420
+ result.assign(x);
421
+ result.and(y);
422
+ tmp.assign(x);
423
+ tmp.and(z);
424
+ result.xor(tmp);
425
+ tmp.assign(y);
426
+ tmp.and(z);
427
+ result.xor(tmp);
428
+ }
429
+
430
+ function sigma(result: Word64, x: Word64, tmp: Word64) {
431
+ result.assign(x);
432
+ result.rotateRight(28);
433
+ tmp.assign(x);
434
+ tmp.rotateRight(34);
435
+ result.xor(tmp);
436
+ tmp.assign(x);
437
+ tmp.rotateRight(39);
438
+ result.xor(tmp);
439
+ }
440
+
441
+ function sigmaPrime(result: Word64, x: Word64, tmp: Word64) {
442
+ result.assign(x);
443
+ result.rotateRight(14);
444
+ tmp.assign(x);
445
+ tmp.rotateRight(18);
446
+ result.xor(tmp);
447
+ tmp.assign(x);
448
+ tmp.rotateRight(41);
449
+ result.xor(tmp);
450
+ }
451
+
452
+ function littleSigma(result: Word64, x: Word64, tmp: Word64) {
453
+ result.assign(x);
454
+ result.rotateRight(1);
455
+ tmp.assign(x);
456
+ tmp.rotateRight(8);
457
+ result.xor(tmp);
458
+ tmp.assign(x);
459
+ tmp.shiftRight(7);
460
+ result.xor(tmp);
461
+ }
462
+
463
+ function littleSigmaPrime(result: Word64, x: Word64, tmp: Word64) {
464
+ result.assign(x);
465
+ result.rotateRight(19);
466
+ tmp.assign(x);
467
+ tmp.rotateRight(61);
468
+ result.xor(tmp);
469
+ tmp.assign(x);
470
+ tmp.shiftRight(6);
471
+ result.xor(tmp);
472
+ }
473
+
474
+ // prettier-ignore
475
+ const k = [
476
+ new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
477
+ new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
478
+ new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
479
+ new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
480
+ new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
481
+ new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
482
+ new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
483
+ new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
484
+ new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
485
+ new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
486
+ new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
487
+ new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
488
+ new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
489
+ new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
490
+ new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
491
+ new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
492
+ new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
493
+ new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
494
+ new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
495
+ new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
496
+ new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
497
+ new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
498
+ new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
499
+ new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
500
+ new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
501
+ new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
502
+ new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
503
+ new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
504
+ new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
505
+ new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
506
+ new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
507
+ new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
508
+ new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
509
+ new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
510
+ new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
511
+ new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
512
+ new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
513
+ new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
514
+ new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
515
+ new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
516
+
517
+ function hash(
518
+ data: Uint8Array,
519
+ offset: number,
520
+ length: number,
521
+ mode384: boolean = false,
522
+ ) {
523
+ // initial hash values
524
+ let h0, h1, h2, h3, h4, h5, h6, h7;
525
+ if (!mode384) {
526
+ h0 = new Word64(0x6a09e667, 0xf3bcc908);
527
+ h1 = new Word64(0xbb67ae85, 0x84caa73b);
528
+ h2 = new Word64(0x3c6ef372, 0xfe94f82b);
529
+ h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
530
+ h4 = new Word64(0x510e527f, 0xade682d1);
531
+ h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
532
+ h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
533
+ h7 = new Word64(0x5be0cd19, 0x137e2179);
534
+ } else {
535
+ // SHA384 is exactly the same
536
+ // except with different starting values and a trimmed result
537
+ h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
538
+ h1 = new Word64(0x629a292a, 0x367cd507);
539
+ h2 = new Word64(0x9159015a, 0x3070dd17);
540
+ h3 = new Word64(0x152fecd8, 0xf70e5939);
541
+ h4 = new Word64(0x67332667, 0xffc00b31);
542
+ h5 = new Word64(0x8eb44a87, 0x68581511);
543
+ h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
544
+ h7 = new Word64(0x47b5481d, 0xbefa4fa4);
545
+ }
546
+
547
+ // pre-processing
548
+ const paddedLength = Math.ceil((length + 17) / 128) * 128;
549
+ const padded = new Uint8Array(paddedLength);
550
+ let i, j;
551
+ for (i = 0; i < length; ++i) {
552
+ padded[i] = data[offset++];
553
+ }
554
+ padded[i++] = 0x80;
555
+ const n = paddedLength - 16;
556
+ while (i < n) {
557
+ padded[i++] = 0;
558
+ }
559
+ padded[i++] = 0;
560
+ padded[i++] = 0;
561
+ padded[i++] = 0;
562
+ padded[i++] = 0;
563
+ padded[i++] = 0;
564
+ padded[i++] = 0;
565
+ padded[i++] = 0;
566
+ padded[i++] = 0;
567
+ padded[i++] = 0;
568
+ padded[i++] = 0;
569
+ padded[i++] = 0;
570
+ padded[i++] = (length >>> 29) & 0xff;
571
+ padded[i++] = (length >> 21) & 0xff;
572
+ padded[i++] = (length >> 13) & 0xff;
573
+ padded[i++] = (length >> 5) & 0xff;
574
+ padded[i++] = (length << 3) & 0xff;
575
+
576
+ const w = new Array(80);
577
+ for (i = 0; i < 80; i++) {
578
+ w[i] = new Word64(0, 0);
579
+ }
580
+ let a = new Word64(0, 0),
581
+ b = new Word64(0, 0),
582
+ c = new Word64(0, 0);
583
+ let d = new Word64(0, 0),
584
+ e = new Word64(0, 0),
585
+ f = new Word64(0, 0);
586
+ let g = new Word64(0, 0),
587
+ h = new Word64(0, 0);
588
+ const t1 = new Word64(0, 0),
589
+ t2 = new Word64(0, 0);
590
+ const tmp1 = new Word64(0, 0),
591
+ tmp2 = new Word64(0, 0);
592
+ let tmp3;
593
+
594
+ // for each 1024 bit block
595
+ for (i = 0; i < paddedLength; ) {
596
+ for (j = 0; j < 16; ++j) {
597
+ w[j].high =
598
+ (padded[i] << 24) |
599
+ (padded[i + 1] << 16) |
600
+ (padded[i + 2] << 8) |
601
+ padded[i + 3];
602
+ w[j].low =
603
+ (padded[i + 4] << 24) |
604
+ (padded[i + 5] << 16) |
605
+ (padded[i + 6] << 8) |
606
+ padded[i + 7];
607
+ i += 8;
608
+ }
609
+ for (j = 16; j < 80; ++j) {
610
+ tmp3 = w[j];
611
+ littleSigmaPrime(tmp3, w[j - 2], tmp2);
612
+ tmp3.add(w[j - 7]);
613
+ littleSigma(tmp1, w[j - 15], tmp2);
614
+ tmp3.add(tmp1);
615
+ tmp3.add(w[j - 16]);
616
+ }
617
+
618
+ a.assign(h0);
619
+ b.assign(h1);
620
+ c.assign(h2);
621
+ d.assign(h3);
622
+ e.assign(h4);
623
+ f.assign(h5);
624
+ g.assign(h6);
625
+ h.assign(h7);
626
+ for (j = 0; j < 80; ++j) {
627
+ t1.assign(h);
628
+ sigmaPrime(tmp1, e, tmp2);
629
+ t1.add(tmp1);
630
+ ch(tmp1, e, f, g, tmp2);
631
+ t1.add(tmp1);
632
+ t1.add(k[j]);
633
+ t1.add(w[j]);
634
+
635
+ sigma(t2, a, tmp2);
636
+ maj(tmp1, a, b, c, tmp2);
637
+ t2.add(tmp1);
638
+
639
+ tmp3 = h;
640
+ h = g;
641
+ g = f;
642
+ f = e;
643
+ d.add(t1);
644
+ e = d;
645
+ d = c;
646
+ c = b;
647
+ b = a;
648
+ tmp3.assign(t1);
649
+ tmp3.add(t2);
650
+ a = tmp3;
651
+ }
652
+ h0.add(a);
653
+ h1.add(b);
654
+ h2.add(c);
655
+ h3.add(d);
656
+ h4.add(e);
657
+ h5.add(f);
658
+ h6.add(g);
659
+ h7.add(h);
660
+ }
661
+
662
+ let result;
663
+ if (!mode384) {
664
+ result = new Uint8Array(64);
665
+ h0.copyTo(result, 0);
666
+ h1.copyTo(result, 8);
667
+ h2.copyTo(result, 16);
668
+ h3.copyTo(result, 24);
669
+ h4.copyTo(result, 32);
670
+ h5.copyTo(result, 40);
671
+ h6.copyTo(result, 48);
672
+ h7.copyTo(result, 56);
673
+ } else {
674
+ result = new Uint8Array(48);
675
+ h0.copyTo(result, 0);
676
+ h1.copyTo(result, 8);
677
+ h2.copyTo(result, 16);
678
+ h3.copyTo(result, 24);
679
+ h4.copyTo(result, 32);
680
+ h5.copyTo(result, 40);
681
+ }
682
+ return result;
683
+ }
684
+
685
+ return hash;
686
+ })();
687
+
688
+ function calculateSHA384(data: Uint8Array, offset: number, length: number) {
689
+ return calculateSHA512(data, offset, length, /* mode384 = */ true);
690
+ }
691
+
692
+ class NullCipher {
693
+ decryptBlock(data: Uint8Array) {
694
+ return data;
695
+ }
696
+
697
+ encrypt(data: Uint8Array) {
698
+ return data;
699
+ }
700
+ }
701
+
702
+ class AESBaseCipher {
703
+ protected _s: Uint8Array;
704
+ protected _keySize!: number;
705
+ protected _key!: Uint8Array;
706
+ protected _cyclesOfRepetition!: number;
707
+ private _inv_s: Uint8Array;
708
+ private _mix: Uint32Array;
709
+ private _mixCol: Uint8Array;
710
+ buffer: Uint8Array;
711
+ bufferPosition: number;
712
+ bufferLength!: number;
713
+ iv!: Uint8Array;
714
+
715
+ constructor() {
716
+ if (this.constructor === AESBaseCipher) {
717
+ throw new Error('Cannot initialize AESBaseCipher.');
718
+ }
719
+
720
+ this._s = new Uint8Array([
721
+ 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
722
+ 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
723
+ 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
724
+ 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
725
+ 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
726
+ 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
727
+ 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
728
+ 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
729
+ 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
730
+ 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
731
+ 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
732
+ 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
733
+ 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
734
+ 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
735
+ 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
736
+ 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
737
+ 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
738
+ 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
739
+ 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
740
+ 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
741
+ 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
742
+ 0xb0, 0x54, 0xbb, 0x16,
743
+ ]);
744
+
745
+ this._inv_s = new Uint8Array([
746
+ 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
747
+ 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
748
+ 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
749
+ 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
750
+ 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
751
+ 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
752
+ 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
753
+ 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
754
+ 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
755
+ 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
756
+ 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
757
+ 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
758
+ 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
759
+ 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
760
+ 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
761
+ 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
762
+ 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
763
+ 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
764
+ 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
765
+ 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
766
+ 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
767
+ 0x55, 0x21, 0x0c, 0x7d,
768
+ ]);
769
+
770
+ this._mix = new Uint32Array([
771
+ 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
772
+ 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
773
+ 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
774
+ 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
775
+ 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
776
+ 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
777
+ 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
778
+ 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
779
+ 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
780
+ 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
781
+ 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
782
+ 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
783
+ 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
784
+ 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
785
+ 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
786
+ 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
787
+ 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
788
+ 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
789
+ 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
790
+ 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
791
+ 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
792
+ 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
793
+ 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
794
+ 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
795
+ 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
796
+ 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
797
+ 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
798
+ 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
799
+ 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
800
+ 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
801
+ 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
802
+ 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
803
+ 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
804
+ 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
805
+ 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
806
+ 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
807
+ 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
808
+ 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
809
+ 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
810
+ 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
811
+ 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
812
+ 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
813
+ 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3,
814
+ ]);
815
+
816
+ this._mixCol = new Uint8Array(256);
817
+ for (let i = 0; i < 256; i++) {
818
+ if (i < 128) {
819
+ this._mixCol[i] = i << 1;
820
+ } else {
821
+ this._mixCol[i] = (i << 1) ^ 0x1b;
822
+ }
823
+ }
824
+
825
+ this.buffer = new Uint8Array(16);
826
+ this.bufferPosition = 0;
827
+ }
828
+
829
+ _expandKey(_cipherKey: Uint8Array) {
830
+ throw new Error('Cannot call `_expandKey` on the base class');
831
+ }
832
+
833
+ _decrypt(input: Uint8Array, key: Uint8Array) {
834
+ let t, u, v;
835
+ const state = new Uint8Array(16);
836
+ state.set(input);
837
+
838
+ // AddRoundKey
839
+ for (let j = 0, k = this._keySize; j < 16; ++j, ++k) {
840
+ state[j] ^= key[k];
841
+ }
842
+ for (let i = this._cyclesOfRepetition - 1; i >= 1; --i) {
843
+ // InvShiftRows
844
+ t = state[13];
845
+ state[13] = state[9];
846
+ state[9] = state[5];
847
+ state[5] = state[1];
848
+ state[1] = t;
849
+ t = state[14];
850
+ u = state[10];
851
+ state[14] = state[6];
852
+ state[10] = state[2];
853
+ state[6] = t;
854
+ state[2] = u;
855
+ t = state[15];
856
+ u = state[11];
857
+ v = state[7];
858
+ state[15] = state[3];
859
+ state[11] = t;
860
+ state[7] = u;
861
+ state[3] = v;
862
+ // InvSubBytes
863
+ for (let j = 0; j < 16; ++j) {
864
+ state[j] = this._inv_s[state[j]];
865
+ }
866
+ // AddRoundKey
867
+ for (let j = 0, k = i * 16; j < 16; ++j, ++k) {
868
+ state[j] ^= key[k];
869
+ }
870
+ // InvMixColumns
871
+ for (let j = 0; j < 16; j += 4) {
872
+ const s0 = this._mix[state[j]];
873
+ const s1 = this._mix[state[j + 1]];
874
+ const s2 = this._mix[state[j + 2]];
875
+ const s3 = this._mix[state[j + 3]];
876
+ t =
877
+ s0 ^
878
+ (s1 >>> 8) ^
879
+ (s1 << 24) ^
880
+ (s2 >>> 16) ^
881
+ (s2 << 16) ^
882
+ (s3 >>> 24) ^
883
+ (s3 << 8);
884
+ state[j] = (t >>> 24) & 0xff;
885
+ state[j + 1] = (t >> 16) & 0xff;
886
+ state[j + 2] = (t >> 8) & 0xff;
887
+ state[j + 3] = t & 0xff;
888
+ }
889
+ }
890
+ // InvShiftRows
891
+ t = state[13];
892
+ state[13] = state[9];
893
+ state[9] = state[5];
894
+ state[5] = state[1];
895
+ state[1] = t;
896
+ t = state[14];
897
+ u = state[10];
898
+ state[14] = state[6];
899
+ state[10] = state[2];
900
+ state[6] = t;
901
+ state[2] = u;
902
+ t = state[15];
903
+ u = state[11];
904
+ v = state[7];
905
+ state[15] = state[3];
906
+ state[11] = t;
907
+ state[7] = u;
908
+ state[3] = v;
909
+ for (let j = 0; j < 16; ++j) {
910
+ // InvSubBytes
911
+ state[j] = this._inv_s[state[j]];
912
+ // AddRoundKey
913
+ state[j] ^= key[j];
914
+ }
915
+ return state;
916
+ }
917
+
918
+ _encrypt(input: Uint8Array, key: Uint8Array) {
919
+ const s = this._s;
920
+
921
+ let t, u, v;
922
+ const state = new Uint8Array(16);
923
+ state.set(input);
924
+
925
+ for (let j = 0; j < 16; ++j) {
926
+ // AddRoundKey
927
+ state[j] ^= key[j];
928
+ }
929
+
930
+ for (let i = 1; i < this._cyclesOfRepetition; i++) {
931
+ // SubBytes
932
+ for (let j = 0; j < 16; ++j) {
933
+ state[j] = s[state[j]];
934
+ }
935
+ // ShiftRows
936
+ v = state[1];
937
+ state[1] = state[5];
938
+ state[5] = state[9];
939
+ state[9] = state[13];
940
+ state[13] = v;
941
+ v = state[2];
942
+ u = state[6];
943
+ state[2] = state[10];
944
+ state[6] = state[14];
945
+ state[10] = v;
946
+ state[14] = u;
947
+ v = state[3];
948
+ u = state[7];
949
+ t = state[11];
950
+ state[3] = state[15];
951
+ state[7] = v;
952
+ state[11] = u;
953
+ state[15] = t;
954
+ // MixColumns
955
+ for (let j = 0; j < 16; j += 4) {
956
+ const s0 = state[j + 0];
957
+ const s1 = state[j + 1];
958
+ const s2 = state[j + 2];
959
+ const s3 = state[j + 3];
960
+ t = s0 ^ s1 ^ s2 ^ s3;
961
+ state[j + 0] ^= t ^ this._mixCol[s0 ^ s1];
962
+ state[j + 1] ^= t ^ this._mixCol[s1 ^ s2];
963
+ state[j + 2] ^= t ^ this._mixCol[s2 ^ s3];
964
+ state[j + 3] ^= t ^ this._mixCol[s3 ^ s0];
965
+ }
966
+ // AddRoundKey
967
+ for (let j = 0, k = i * 16; j < 16; ++j, ++k) {
968
+ state[j] ^= key[k];
969
+ }
970
+ }
971
+
972
+ // SubBytes
973
+ for (let j = 0; j < 16; ++j) {
974
+ state[j] = s[state[j]];
975
+ }
976
+ // ShiftRows
977
+ v = state[1];
978
+ state[1] = state[5];
979
+ state[5] = state[9];
980
+ state[9] = state[13];
981
+ state[13] = v;
982
+ v = state[2];
983
+ u = state[6];
984
+ state[2] = state[10];
985
+ state[6] = state[14];
986
+ state[10] = v;
987
+ state[14] = u;
988
+ v = state[3];
989
+ u = state[7];
990
+ t = state[11];
991
+ state[3] = state[15];
992
+ state[7] = v;
993
+ state[11] = u;
994
+ state[15] = t;
995
+ // AddRoundKey
996
+ for (let j = 0, k = this._keySize; j < 16; ++j, ++k) {
997
+ state[j] ^= key[k];
998
+ }
999
+ return state;
1000
+ }
1001
+
1002
+ _decryptBlock2(data: Uint8Array, finalize: boolean) {
1003
+ const sourceLength = data.length;
1004
+ let buffer = this.buffer,
1005
+ bufferLength = this.bufferPosition;
1006
+ const result: Uint8Array[] = [];
1007
+ let iv = this.iv;
1008
+
1009
+ for (let i = 0; i < sourceLength; ++i) {
1010
+ buffer[bufferLength] = data[i];
1011
+ ++bufferLength;
1012
+ if (bufferLength < 16) {
1013
+ continue;
1014
+ }
1015
+ // buffer is full, decrypting
1016
+ const plain = this._decrypt(buffer, this._key);
1017
+ // xor-ing the IV vector to get plain text
1018
+ for (let j = 0; j < 16; ++j) {
1019
+ plain[j] ^= iv[j];
1020
+ }
1021
+ iv = buffer;
1022
+ result.push(plain);
1023
+ buffer = new Uint8Array(16);
1024
+ bufferLength = 0;
1025
+ }
1026
+ // saving incomplete buffer
1027
+ this.buffer = buffer;
1028
+ this.bufferLength = bufferLength;
1029
+ this.iv = iv;
1030
+ if (result.length === 0) {
1031
+ return new Uint8Array(0);
1032
+ }
1033
+ // combining plain text blocks into one
1034
+ let outputLength = 16 * result.length;
1035
+ if (finalize) {
1036
+ // undo a padding that is described in RFC 2898
1037
+ const lastBlock = result[result.length - 1];
1038
+ let psLen = lastBlock[15];
1039
+ if (psLen <= 16) {
1040
+ for (let i = 15, ii = 16 - psLen; i >= ii; --i) {
1041
+ if (lastBlock[i] !== psLen) {
1042
+ // Invalid padding, assume that the block has no padding.
1043
+ psLen = 0;
1044
+ break;
1045
+ }
1046
+ }
1047
+ outputLength -= psLen;
1048
+ result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
1049
+ }
1050
+ }
1051
+ const output = new Uint8Array(outputLength);
1052
+ for (let i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
1053
+ output.set(result[i], j);
1054
+ }
1055
+ return output;
1056
+ }
1057
+
1058
+ decryptBlock(
1059
+ data: Uint8Array,
1060
+ finalize: boolean,
1061
+ iv?: Uint8Array,
1062
+ ): Uint8Array {
1063
+ const sourceLength = data.length;
1064
+ const buffer = this.buffer;
1065
+ let bufferLength = this.bufferPosition;
1066
+ // If an IV is not supplied, wait for IV values. They are at the start
1067
+ // of the stream.
1068
+ if (iv) {
1069
+ this.iv = iv;
1070
+ } else {
1071
+ for (
1072
+ let i = 0;
1073
+ bufferLength < 16 && i < sourceLength;
1074
+ ++i, ++bufferLength
1075
+ ) {
1076
+ buffer[bufferLength] = data[i];
1077
+ }
1078
+ if (bufferLength < 16) {
1079
+ // Need more data.
1080
+ this.bufferLength = bufferLength;
1081
+ return new Uint8Array(0);
1082
+ }
1083
+ this.iv = buffer;
1084
+ data = data.subarray(16);
1085
+ }
1086
+ this.buffer = new Uint8Array(16);
1087
+ this.bufferLength = 0;
1088
+ // starting decryption
1089
+ this.decryptBlock = this._decryptBlock2;
1090
+ return this.decryptBlock(data, finalize);
1091
+ }
1092
+
1093
+ encrypt(data: Uint8Array, iv: Uint8Array) {
1094
+ const sourceLength = data.length;
1095
+ let buffer = this.buffer,
1096
+ bufferLength = this.bufferPosition;
1097
+ const result = [];
1098
+
1099
+ if (!iv) {
1100
+ iv = new Uint8Array(16);
1101
+ }
1102
+ for (let i = 0; i < sourceLength; ++i) {
1103
+ buffer[bufferLength] = data[i];
1104
+ ++bufferLength;
1105
+ if (bufferLength < 16) {
1106
+ continue;
1107
+ }
1108
+
1109
+ for (let j = 0; j < 16; ++j) {
1110
+ buffer[j] ^= iv[j];
1111
+ }
1112
+
1113
+ // buffer is full, encrypting
1114
+ const cipher = this._encrypt(buffer, this._key);
1115
+ iv = cipher;
1116
+ result.push(cipher);
1117
+ buffer = new Uint8Array(16);
1118
+ bufferLength = 0;
1119
+ }
1120
+ // saving incomplete buffer
1121
+ this.buffer = buffer;
1122
+ this.bufferLength = bufferLength;
1123
+ this.iv = iv;
1124
+ if (result.length === 0) {
1125
+ return new Uint8Array(0);
1126
+ }
1127
+ // combining plain text blocks into one
1128
+ const outputLength = 16 * result.length;
1129
+ const output = new Uint8Array(outputLength);
1130
+ for (let i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
1131
+ output.set(result[i], j);
1132
+ }
1133
+ return output;
1134
+ }
1135
+ }
1136
+
1137
+ class AES128Cipher extends AESBaseCipher {
1138
+ private _rcon: Uint8Array;
1139
+
1140
+ constructor(key: Uint8Array) {
1141
+ super();
1142
+
1143
+ this._cyclesOfRepetition = 10;
1144
+ this._keySize = 160; // bits
1145
+
1146
+ this._rcon = new Uint8Array([
1147
+ 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
1148
+ 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
1149
+ 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
1150
+ 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
1151
+ 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
1152
+ 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
1153
+ 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
1154
+ 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
1155
+ 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
1156
+ 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
1157
+ 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
1158
+ 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
1159
+ 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
1160
+ 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
1161
+ 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
1162
+ 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
1163
+ 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
1164
+ 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
1165
+ 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
1166
+ 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
1167
+ 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
1168
+ 0x74, 0xe8, 0xcb, 0x8d,
1169
+ ]);
1170
+
1171
+ this._key = this._expandKey(key);
1172
+ }
1173
+
1174
+ _expandKey(cipherKey: Uint8Array) {
1175
+ const b = 176;
1176
+ const s = this._s;
1177
+ const rcon = this._rcon;
1178
+
1179
+ const result = new Uint8Array(b);
1180
+ result.set(cipherKey);
1181
+
1182
+ for (let j = 16, i = 1; j < b; ++i) {
1183
+ // RotWord
1184
+ let t1 = result[j - 3];
1185
+ let t2 = result[j - 2];
1186
+ let t3 = result[j - 1];
1187
+ let t4 = result[j - 4];
1188
+ // SubWord
1189
+ t1 = s[t1];
1190
+ t2 = s[t2];
1191
+ t3 = s[t3];
1192
+ t4 = s[t4];
1193
+ // Rcon
1194
+ t1 ^= rcon[i];
1195
+ for (let n = 0; n < 4; ++n) {
1196
+ result[j] = t1 ^= result[j - 16];
1197
+ j++;
1198
+ result[j] = t2 ^= result[j - 16];
1199
+ j++;
1200
+ result[j] = t3 ^= result[j - 16];
1201
+ j++;
1202
+ result[j] = t4 ^= result[j - 16];
1203
+ j++;
1204
+ }
1205
+ }
1206
+ return result;
1207
+ }
1208
+ }
1209
+
1210
+ class AES256Cipher extends AESBaseCipher {
1211
+ constructor(key: Uint8Array) {
1212
+ super();
1213
+
1214
+ this._cyclesOfRepetition = 14;
1215
+ this._keySize = 224; // bits
1216
+
1217
+ this._key = this._expandKey(key);
1218
+ }
1219
+
1220
+ _expandKey(cipherKey: Uint8Array) {
1221
+ const b = 240;
1222
+ const s = this._s;
1223
+
1224
+ const result = new Uint8Array(b);
1225
+ result.set(cipherKey);
1226
+
1227
+ let r = 1;
1228
+ let t1 = 0,
1229
+ t2 = 0,
1230
+ t3 = 0,
1231
+ t4 = 0;
1232
+ for (let j = 32, i = 1; j < b; ++i) {
1233
+ if (j % 32 === 16) {
1234
+ t1 = s[t1];
1235
+ t2 = s[t2];
1236
+ t3 = s[t3];
1237
+ t4 = s[t4];
1238
+ } else if (j % 32 === 0) {
1239
+ // RotWord
1240
+ t1 = result[j - 3];
1241
+ t2 = result[j - 2];
1242
+ t3 = result[j - 1];
1243
+ t4 = result[j - 4];
1244
+ // SubWord
1245
+ t1 = s[t1];
1246
+ t2 = s[t2];
1247
+ t3 = s[t3];
1248
+ t4 = s[t4];
1249
+ // Rcon
1250
+ t1 ^= r;
1251
+ if ((r <<= 1) >= 256) {
1252
+ r = (r ^ 0x1b) & 0xff;
1253
+ }
1254
+ }
1255
+
1256
+ for (let n = 0; n < 4; ++n) {
1257
+ result[j] = t1 ^= result[j - 32];
1258
+ j++;
1259
+ result[j] = t2 ^= result[j - 32];
1260
+ j++;
1261
+ result[j] = t3 ^= result[j - 32];
1262
+ j++;
1263
+ result[j] = t4 ^= result[j - 32];
1264
+ j++;
1265
+ }
1266
+ }
1267
+ return result;
1268
+ }
1269
+ }
1270
+
1271
+ class PDF17 {
1272
+ checkOwnerPassword(
1273
+ password: Uint8Array,
1274
+ ownerValidationSalt: Uint8Array,
1275
+ userBytes: Uint8Array,
1276
+ ownerPassword: Uint8Array,
1277
+ ) {
1278
+ const hashData = new Uint8Array(password.length + 56);
1279
+ hashData.set(password, 0);
1280
+ hashData.set(ownerValidationSalt, password.length);
1281
+ hashData.set(userBytes, password.length + ownerValidationSalt.length);
1282
+ const result = calculateSHA256(hashData, 0, hashData.length);
1283
+ return isArrayEqual(result, ownerPassword);
1284
+ }
1285
+
1286
+ checkUserPassword(
1287
+ password: Uint8Array,
1288
+ userValidationSalt: Uint8Array,
1289
+ userPassword: Uint8Array,
1290
+ ) {
1291
+ const hashData = new Uint8Array(password.length + 8);
1292
+ hashData.set(password, 0);
1293
+ hashData.set(userValidationSalt, password.length);
1294
+ const result = calculateSHA256(hashData, 0, hashData.length);
1295
+ return isArrayEqual(result, userPassword);
1296
+ }
1297
+
1298
+ getOwnerKey(
1299
+ password: Uint8Array,
1300
+ ownerKeySalt: Uint8Array,
1301
+ userBytes: Uint8Array,
1302
+ ownerEncryption: Uint8Array,
1303
+ ) {
1304
+ const hashData = new Uint8Array(password.length + 56);
1305
+ hashData.set(password, 0);
1306
+ hashData.set(ownerKeySalt, password.length);
1307
+ hashData.set(userBytes, password.length + ownerKeySalt.length);
1308
+ const key = calculateSHA256(hashData, 0, hashData.length);
1309
+ const cipher = new AES256Cipher(key);
1310
+ return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
1311
+ }
1312
+
1313
+ getUserKey(
1314
+ password: Uint8Array,
1315
+ userKeySalt: Uint8Array,
1316
+ userEncryption: Uint8Array,
1317
+ ) {
1318
+ const hashData = new Uint8Array(password.length + 8);
1319
+ hashData.set(password, 0);
1320
+ hashData.set(userKeySalt, password.length);
1321
+ // `key` is the decryption key for the UE string.
1322
+ const key = calculateSHA256(hashData, 0, hashData.length);
1323
+ const cipher = new AES256Cipher(key);
1324
+ return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
1325
+ }
1326
+ }
1327
+
1328
+ class PDF20 {
1329
+ calculatePDF20Hash(
1330
+ password: Uint8Array,
1331
+ input: Uint8Array,
1332
+ userBytes: Uint8Array,
1333
+ ) {
1334
+ // This refers to Algorithm 2.B as defined in ISO 32000-2.
1335
+ let k = calculateSHA256(input, 0, input.length).subarray(0, 32);
1336
+ let e: Uint8Array = new Uint8Array([0]);
1337
+ let i = 0;
1338
+ while (i < 64 || e[e.length - 1] > i - 32) {
1339
+ const combinedLength = password.length + k.length + userBytes.length,
1340
+ combinedArray = new Uint8Array(combinedLength);
1341
+ let writeOffset = 0;
1342
+ combinedArray.set(password, writeOffset);
1343
+ writeOffset += password.length;
1344
+ combinedArray.set(k, writeOffset);
1345
+ writeOffset += k.length;
1346
+ combinedArray.set(userBytes, writeOffset);
1347
+
1348
+ const k1 = new Uint8Array(combinedLength * 64);
1349
+ for (let j = 0, pos = 0; j < 64; j++, pos += combinedLength) {
1350
+ k1.set(combinedArray, pos);
1351
+ }
1352
+ // AES128 CBC NO PADDING with first 16 bytes of k as the key
1353
+ // and the second 16 as the iv.
1354
+ const cipher = new AES128Cipher(k.subarray(0, 16));
1355
+ e = cipher.encrypt(k1, k.subarray(16, 32));
1356
+ // Now we have to take the first 16 bytes of an unsigned big endian
1357
+ // integer and compute the remainder modulo 3. That is a fairly large
1358
+ // number and JavaScript isn't going to handle that well.
1359
+ // The number is e0 + 256 * e1 + 256^2 * e2... and 256 % 3 === 1, hence
1360
+ // the powers of 256 are === 1 modulo 3 and finally the number modulo 3
1361
+ // is equal to the remainder modulo 3 of the sum of the e_n.
1362
+ const remainder = e.slice(0, 16).reduce((a, b) => a + b, 0) % 3;
1363
+ if (remainder === 0) {
1364
+ k = calculateSHA256(e, 0, e.length);
1365
+ } else if (remainder === 1) {
1366
+ k = calculateSHA384(e, 0, e.length);
1367
+ } else if (remainder === 2) {
1368
+ k = calculateSHA512(e, 0, e.length);
1369
+ }
1370
+ i++;
1371
+ }
1372
+ return k.subarray(0, 32);
1373
+ }
1374
+
1375
+ hash(password: Uint8Array, concatBytes: Uint8Array, userBytes: Uint8Array) {
1376
+ return this.calculatePDF20Hash(password, concatBytes, userBytes);
1377
+ }
1378
+
1379
+ checkOwnerPassword(
1380
+ password: Uint8Array,
1381
+ ownerValidationSalt: Uint8Array,
1382
+ userBytes: Uint8Array,
1383
+ ownerPassword: Uint8Array,
1384
+ ) {
1385
+ const hashData = new Uint8Array(password.length + 56);
1386
+ hashData.set(password, 0);
1387
+ hashData.set(ownerValidationSalt, password.length);
1388
+ hashData.set(userBytes, password.length + ownerValidationSalt.length);
1389
+ const result = this.calculatePDF20Hash(password, hashData, userBytes);
1390
+ return isArrayEqual(result, ownerPassword);
1391
+ }
1392
+
1393
+ checkUserPassword(
1394
+ password: Uint8Array,
1395
+ userValidationSalt: Uint8Array,
1396
+ userPassword: Uint8Array,
1397
+ ) {
1398
+ const hashData = new Uint8Array(password.length + 8);
1399
+ hashData.set(password, 0);
1400
+ hashData.set(userValidationSalt, password.length);
1401
+ const result = this.calculatePDF20Hash(
1402
+ password,
1403
+ hashData,
1404
+ new Uint8Array(),
1405
+ );
1406
+ return isArrayEqual(result, userPassword);
1407
+ }
1408
+
1409
+ getOwnerKey(
1410
+ password: Uint8Array,
1411
+ ownerKeySalt: Uint8Array,
1412
+ userBytes: Uint8Array,
1413
+ ownerEncryption: Uint8Array,
1414
+ ) {
1415
+ const hashData = new Uint8Array(password.length + 56);
1416
+ hashData.set(password, 0);
1417
+ hashData.set(ownerKeySalt, password.length);
1418
+ hashData.set(userBytes, password.length + ownerKeySalt.length);
1419
+ const key = this.calculatePDF20Hash(password, hashData, userBytes);
1420
+ const cipher = new AES256Cipher(key);
1421
+ return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
1422
+ }
1423
+
1424
+ getUserKey(
1425
+ password: Uint8Array,
1426
+ userKeySalt: Uint8Array,
1427
+ userEncryption: Uint8Array,
1428
+ ) {
1429
+ const hashData = new Uint8Array(password.length + 8);
1430
+ hashData.set(password, 0);
1431
+ hashData.set(userKeySalt, password.length);
1432
+ // `key` is the decryption key for the UE string.
1433
+ const key = this.calculatePDF20Hash(password, hashData, new Uint8Array());
1434
+ const cipher = new AES256Cipher(key);
1435
+ return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
1436
+ }
1437
+ }
1438
+
1439
+ type Cipher = ARCFourCipher | NullCipher | AES128Cipher | AES256Cipher;
1440
+ class CipherTransform {
1441
+ private StringCipherConstructor: () => Cipher;
1442
+ private StreamCipherConstructor: () => Cipher;
1443
+
1444
+ constructor(
1445
+ stringCipherConstructor: () => Cipher,
1446
+ streamCipherConstructor: () => Cipher,
1447
+ ) {
1448
+ this.StringCipherConstructor = stringCipherConstructor;
1449
+ this.StreamCipherConstructor = streamCipherConstructor;
1450
+ }
1451
+
1452
+ createStream(stream: StreamType, length: number) {
1453
+ const cipher = this.StreamCipherConstructor();
1454
+ return new DecryptStream(
1455
+ stream,
1456
+ function cipherTransformDecryptStream(data, finalize) {
1457
+ return cipher.decryptBlock(data as Uint8Array, finalize);
1458
+ },
1459
+ length,
1460
+ );
1461
+ }
1462
+
1463
+ decryptString(s: string) {
1464
+ const cipher = this.StringCipherConstructor();
1465
+ let data = stringAsByteArray(s);
1466
+ data = cipher.decryptBlock(data, true);
1467
+ return arrayAsString(data);
1468
+ }
1469
+
1470
+ decryptBytes(d: Uint8Array) {
1471
+ const cipher = this.StringCipherConstructor();
1472
+ return cipher.decryptBlock(d, true);
1473
+ }
1474
+
1475
+ encryptString(s: string) {
1476
+ const cipher = this.StringCipherConstructor();
1477
+ if (cipher instanceof AESBaseCipher) {
1478
+ // Append some chars equal to "16 - (M mod 16)"
1479
+ // where M is the string length (see section 7.6.2 in PDF specification)
1480
+ // to have a final string where the length is a multiple of 16.
1481
+ // Special note:
1482
+ // "Note that the pad is present when M is evenly divisible by 16;
1483
+ // it contains 16 bytes of 0x10."
1484
+ const strLen = s.length;
1485
+ const pad = 16 - (strLen % 16);
1486
+ s += String.fromCharCode(pad).repeat(pad);
1487
+
1488
+ // Generate an initialization vector
1489
+ const iv = new Uint8Array(16);
1490
+ if (typeof crypto !== 'undefined') {
1491
+ crypto.getRandomValues(iv);
1492
+ } else {
1493
+ for (let i = 0; i < 16; i++) {
1494
+ iv[i] = Math.floor(256 * Math.random());
1495
+ }
1496
+ }
1497
+
1498
+ let data = stringAsByteArray(s);
1499
+ data = cipher.encrypt(data, iv);
1500
+
1501
+ const buf = new Uint8Array(16 + data.length);
1502
+ buf.set(iv);
1503
+ buf.set(data, 16);
1504
+
1505
+ return arrayAsString(buf);
1506
+ }
1507
+
1508
+ let data = stringAsByteArray(s);
1509
+ data = cipher.encrypt(data);
1510
+ return arrayAsString(data);
1511
+ }
1512
+ }
1513
+
1514
+ // eslint-disable-next-line no-shadow
1515
+ class CipherTransformFactory {
1516
+ encryptMetadata: boolean;
1517
+ encryptionKey: Uint8Array;
1518
+ algorithm: number;
1519
+ filterName: string;
1520
+ dict: PDFDict;
1521
+ cf!: PDFDict;
1522
+ stmf!: PDFName;
1523
+ strf!: PDFName;
1524
+ eff!: PDFName;
1525
+
1526
+ private defaultPasswordBytes = new Uint8Array([
1527
+ 0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, 0x64, 0x00, 0x4e, 0x56,
1528
+ 0xff, 0xfa, 0x01, 0x08, 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80,
1529
+ 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a,
1530
+ ]);
1531
+ private identityName = PDFName.of('Identity');
1532
+
1533
+ constructor(dict: PDFDict, fileIdBytes: Uint8Array, password?: string) {
1534
+ const filter = dict.get(PDFName.of('Filter')) as PDFName;
1535
+ if (filter.asString() !== '/Standard') {
1536
+ throw new Error('unknown encryption method');
1537
+ }
1538
+ this.filterName = filter.asString();
1539
+ this.dict = dict;
1540
+ const algorithm = (dict.get(PDFName.of('V')) as PDFNumber).asNumber();
1541
+ if (
1542
+ !Number.isInteger(algorithm) ||
1543
+ (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 && algorithm !== 5)
1544
+ ) {
1545
+ throw new Error('unsupported encryption algorithm');
1546
+ }
1547
+ this.algorithm = algorithm;
1548
+ let keyLength = (dict.get(PDFName.of('Length')) as PDFNumber).asNumber();
1549
+ if (!keyLength) {
1550
+ // Spec asks to rely on encryption dictionary's Length entry, however
1551
+ // some PDFs don't have it. Trying to recover.
1552
+ if (algorithm <= 3) {
1553
+ // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
1554
+ keyLength = 40;
1555
+ } else {
1556
+ // Trying to find default handler -- it usually has Length.
1557
+ const cfDict = dict.get(PDFName.of('CF')) as PDFDict;
1558
+ const streamCryptoName = dict.get(PDFName.of('StmF')) as PDFName;
1559
+ if (cfDict instanceof PDFDict && streamCryptoName instanceof PDFName) {
1560
+ cfDict.suppressEncryption = true;
1561
+ const handlerDict = cfDict.get(
1562
+ PDFName.of(streamCryptoName.asString()),
1563
+ ) as PDFDict;
1564
+ let keyLen: PDFNumber | null = null;
1565
+ if (handlerDict) {
1566
+ keyLen = handlerDict.get(PDFName.of('Length')) as PDFNumber;
1567
+ }
1568
+ keyLength = (keyLen && keyLen.asNumber()) || 128;
1569
+ if (keyLength < 40) {
1570
+ // Sometimes it's incorrect value of bits, generators specify
1571
+ // bytes.
1572
+ keyLength <<= 3;
1573
+ }
1574
+ }
1575
+ }
1576
+ }
1577
+ if (!Number.isInteger(keyLength) || keyLength < 40 || keyLength % 8 !== 0) {
1578
+ throw new Error('invalid key length');
1579
+ }
1580
+
1581
+ const oPdfStr = (dict.get(PDFName.of('O')) as PDFString).asBytes();
1582
+ const uPdfStr = (dict.get(PDFName.of('U')) as PDFString).asBytes();
1583
+ // prepare keys
1584
+ const ownerPassword = oPdfStr.subarray(0, 32);
1585
+ const userPassword = uPdfStr.subarray(0, 32);
1586
+ const flags = (dict.get(PDFName.of('P')) as PDFNumber).asNumber();
1587
+ const revision = (dict.get(PDFName.of('R')) as PDFNumber).asNumber();
1588
+ // meaningful when V is 4 or 5
1589
+ const encryptMetadata =
1590
+ (algorithm === 4 || algorithm === 5) &&
1591
+ (dict.get(PDFName.of('EncryptMetadata')) as PDFBool)?.asBoolean() !==
1592
+ false;
1593
+ this.encryptMetadata = encryptMetadata;
1594
+
1595
+ let passwordBytes: Uint8Array | undefined;
1596
+ if (password) {
1597
+ if (revision === 6) {
1598
+ try {
1599
+ password = unescape(encodeURIComponent(password));
1600
+ } catch (ex) {
1601
+ console.warn(
1602
+ 'CipherTransformFactory: ' +
1603
+ 'Unable to convert UTF8 encoded password.',
1604
+ );
1605
+ }
1606
+ }
1607
+ passwordBytes = stringAsByteArray(password!);
1608
+ }
1609
+
1610
+ let encryptionKey;
1611
+ if (algorithm !== 5) {
1612
+ encryptionKey = this.prepareKeyData(
1613
+ fileIdBytes,
1614
+ passwordBytes,
1615
+ ownerPassword,
1616
+ userPassword,
1617
+ flags,
1618
+ revision,
1619
+ keyLength,
1620
+ encryptMetadata,
1621
+ );
1622
+ } else {
1623
+ const ownerValidationSalt = oPdfStr.subarray(32, 40);
1624
+ const ownerKeySalt = oPdfStr.subarray(40, 48);
1625
+ const uBytes = uPdfStr.subarray(0, 48);
1626
+ const userValidationSalt = uPdfStr.subarray(32, 40);
1627
+ const userKeySalt = uPdfStr.subarray(40, 48);
1628
+
1629
+ const ownerEncryption = (
1630
+ dict.get(PDFName.of('OE')) as PDFString
1631
+ ).asBytes();
1632
+ const userEncryption = (
1633
+ dict.get(PDFName.of('UE')) as PDFString
1634
+ ).asBytes();
1635
+ const perms = (dict.get(PDFName.of('Perms')) as PDFString).asBytes();
1636
+ encryptionKey = this.createEncryptionKey20(
1637
+ revision,
1638
+ passwordBytes,
1639
+ ownerPassword,
1640
+ ownerValidationSalt,
1641
+ ownerKeySalt,
1642
+ uBytes,
1643
+ userPassword,
1644
+ userValidationSalt,
1645
+ userKeySalt,
1646
+ ownerEncryption,
1647
+ userEncryption,
1648
+ perms,
1649
+ );
1650
+ }
1651
+ if (!encryptionKey && !password) {
1652
+ throw new Error('NEEDS PASSWORD');
1653
+ } else if (!encryptionKey && password) {
1654
+ // Attempting use the password as an owner password
1655
+ const decodedPassword = this.decodeUserPassword(
1656
+ passwordBytes!,
1657
+ ownerPassword,
1658
+ revision,
1659
+ keyLength,
1660
+ );
1661
+ encryptionKey = this.prepareKeyData(
1662
+ fileIdBytes,
1663
+ decodedPassword,
1664
+ ownerPassword,
1665
+ userPassword,
1666
+ flags,
1667
+ revision,
1668
+ keyLength,
1669
+ encryptMetadata,
1670
+ );
1671
+ }
1672
+
1673
+ if (!encryptionKey) {
1674
+ throw new Error('Password incorrect');
1675
+ }
1676
+
1677
+ this.encryptionKey = encryptionKey;
1678
+
1679
+ if (algorithm >= 4) {
1680
+ const cf = dict.get(PDFName.of('CF')) as PDFDict;
1681
+ if (cf instanceof PDFDict) {
1682
+ // The 'CF' dictionary itself should not be encrypted, and by setting
1683
+ // `suppressEncryption` we can prevent an infinite loop inside of
1684
+ // `XRef_fetchUncompressed` if the dictionary contains indirect
1685
+ // objects (fixes issue7665.pdf).
1686
+ cf.suppressEncryption = true;
1687
+ }
1688
+ this.cf = cf;
1689
+ this.stmf =
1690
+ (dict.get(PDFName.of('StmF')) as PDFName) || this.identityName;
1691
+ this.strf =
1692
+ (dict.get(PDFName.of('StrF')) as PDFName) || this.identityName;
1693
+ this.eff = (dict.get(PDFName.of('EFF')) as PDFName) || this.stmf;
1694
+ }
1695
+ }
1696
+
1697
+ createCipherTransform(num: number, gen: number) {
1698
+ if (this.algorithm === 4 || this.algorithm === 5) {
1699
+ return new CipherTransform(
1700
+ this.buildCipherConstructor(
1701
+ this.cf,
1702
+ this.strf,
1703
+ num,
1704
+ gen,
1705
+ this.encryptionKey,
1706
+ ),
1707
+ this.buildCipherConstructor(
1708
+ this.cf,
1709
+ this.stmf,
1710
+ num,
1711
+ gen,
1712
+ this.encryptionKey,
1713
+ ),
1714
+ );
1715
+ }
1716
+ // algorithms 1 and 2
1717
+ const key = this.buildObjectKey(
1718
+ num,
1719
+ gen,
1720
+ this.encryptionKey,
1721
+ /* isAes = */ false,
1722
+ );
1723
+ const cipherConstructor = function buildCipherCipherConstructor() {
1724
+ return new ARCFourCipher(key);
1725
+ };
1726
+ return new CipherTransform(cipherConstructor, cipherConstructor);
1727
+ }
1728
+
1729
+ createEncryptionKey20(
1730
+ revision: number,
1731
+ password: Uint8Array | undefined,
1732
+ ownerPassword: Uint8Array,
1733
+ ownerValidationSalt: Uint8Array,
1734
+ ownerKeySalt: Uint8Array,
1735
+ uBytes: Uint8Array,
1736
+ userPassword: Uint8Array,
1737
+ userValidationSalt: Uint8Array,
1738
+ userKeySalt: Uint8Array,
1739
+ ownerEncryption: Uint8Array,
1740
+ userEncryption: Uint8Array,
1741
+ _perms: Uint8Array,
1742
+ ) {
1743
+ if (password) {
1744
+ const passwordLength = Math.min(127, password.length);
1745
+ password = password.subarray(0, passwordLength);
1746
+ } else {
1747
+ password = new Uint8Array();
1748
+ }
1749
+ let pdfAlgorithm;
1750
+ if (revision === 6) {
1751
+ pdfAlgorithm = new PDF20();
1752
+ } else {
1753
+ pdfAlgorithm = new PDF17();
1754
+ }
1755
+
1756
+ if (
1757
+ pdfAlgorithm.checkUserPassword(password, userValidationSalt, userPassword)
1758
+ ) {
1759
+ return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
1760
+ } else if (
1761
+ password.length &&
1762
+ pdfAlgorithm.checkOwnerPassword(
1763
+ password,
1764
+ ownerValidationSalt,
1765
+ uBytes,
1766
+ ownerPassword,
1767
+ )
1768
+ ) {
1769
+ return pdfAlgorithm.getOwnerKey(
1770
+ password,
1771
+ ownerKeySalt,
1772
+ uBytes,
1773
+ ownerEncryption,
1774
+ );
1775
+ }
1776
+
1777
+ return null;
1778
+ }
1779
+
1780
+ prepareKeyData(
1781
+ fileId: Uint8Array,
1782
+ password: Uint8Array | undefined,
1783
+ ownerPassword: Uint8Array,
1784
+ userPassword: Uint8Array,
1785
+ flags: number,
1786
+ revision: number,
1787
+ keyLength: number,
1788
+ encryptMetadata: boolean,
1789
+ ) {
1790
+ const hashDataSize = 40 + ownerPassword.length + fileId.length;
1791
+ const hashData = new Uint8Array(hashDataSize);
1792
+ let i = 0,
1793
+ j,
1794
+ n;
1795
+ if (password) {
1796
+ n = Math.min(32, password.length);
1797
+ for (; i < n; ++i) {
1798
+ hashData[i] = password[i];
1799
+ }
1800
+ }
1801
+ j = 0;
1802
+ while (i < 32) {
1803
+ hashData[i++] = this.defaultPasswordBytes[j++];
1804
+ }
1805
+ // as now the padded password in the hashData[0..i]
1806
+ for (j = 0, n = ownerPassword.length; j < n; ++j) {
1807
+ hashData[i++] = ownerPassword[j];
1808
+ }
1809
+ hashData[i++] = flags & 0xff;
1810
+ hashData[i++] = (flags >> 8) & 0xff;
1811
+ hashData[i++] = (flags >> 16) & 0xff;
1812
+ hashData[i++] = (flags >>> 24) & 0xff;
1813
+ for (j = 0, n = fileId.length; j < n; ++j) {
1814
+ hashData[i++] = fileId[j];
1815
+ }
1816
+ if (revision >= 4 && !encryptMetadata) {
1817
+ hashData[i++] = 0xff;
1818
+ hashData[i++] = 0xff;
1819
+ hashData[i++] = 0xff;
1820
+ hashData[i++] = 0xff;
1821
+ }
1822
+ let hash = calculateMD5(hashData, 0, i);
1823
+ const keyLengthInBytes = keyLength >> 3;
1824
+ if (revision >= 3) {
1825
+ for (j = 0; j < 50; ++j) {
1826
+ hash = calculateMD5(hash, 0, keyLengthInBytes);
1827
+ }
1828
+ }
1829
+ const encryptionKey = hash.subarray(0, keyLengthInBytes);
1830
+ let cipher, checkData;
1831
+
1832
+ if (revision >= 3) {
1833
+ for (i = 0; i < 32; ++i) {
1834
+ hashData[i] = this.defaultPasswordBytes[i];
1835
+ }
1836
+ for (j = 0, n = fileId.length; j < n; ++j) {
1837
+ hashData[i++] = fileId[j];
1838
+ }
1839
+ cipher = new ARCFourCipher(encryptionKey);
1840
+ checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
1841
+ n = encryptionKey.length;
1842
+ const derivedKey = new Uint8Array(n);
1843
+ for (j = 1; j <= 19; ++j) {
1844
+ for (let k = 0; k < n; ++k) {
1845
+ derivedKey[k] = encryptionKey[k] ^ j;
1846
+ }
1847
+ cipher = new ARCFourCipher(derivedKey);
1848
+ checkData = cipher.encryptBlock(checkData);
1849
+ }
1850
+ for (j = 0, n = checkData.length; j < n; ++j) {
1851
+ if (userPassword[j] !== checkData[j]) {
1852
+ return null;
1853
+ }
1854
+ }
1855
+ } else {
1856
+ cipher = new ARCFourCipher(encryptionKey);
1857
+ checkData = cipher.encryptBlock(this.defaultPasswordBytes);
1858
+ for (j = 0, n = checkData.length; j < n; ++j) {
1859
+ if (userPassword[j] !== checkData[j]) {
1860
+ return null;
1861
+ }
1862
+ }
1863
+ }
1864
+ return encryptionKey;
1865
+ }
1866
+
1867
+ decodeUserPassword(
1868
+ password: Uint8Array,
1869
+ ownerPassword: Uint8Array,
1870
+ revision: number,
1871
+ keyLength: number,
1872
+ ) {
1873
+ const hashData = new Uint8Array(32);
1874
+ let i = 0;
1875
+ const n = Math.min(32, password.length);
1876
+ for (; i < n; ++i) {
1877
+ hashData[i] = password[i];
1878
+ }
1879
+ let j = 0;
1880
+ while (i < 32) {
1881
+ hashData[i++] = this.defaultPasswordBytes[j++];
1882
+ }
1883
+ let hash = calculateMD5(hashData, 0, i);
1884
+ const keyLengthInBytes = keyLength >> 3;
1885
+ if (revision >= 3) {
1886
+ for (j = 0; j < 50; ++j) {
1887
+ hash = calculateMD5(hash, 0, hash.length);
1888
+ }
1889
+ }
1890
+
1891
+ let cipher, userPassword;
1892
+ if (revision >= 3) {
1893
+ userPassword = ownerPassword;
1894
+ const derivedKey = new Uint8Array(keyLengthInBytes);
1895
+ for (j = 19; j >= 0; j--) {
1896
+ for (let k = 0; k < keyLengthInBytes; ++k) {
1897
+ derivedKey[k] = hash[k] ^ j;
1898
+ }
1899
+ cipher = new ARCFourCipher(derivedKey);
1900
+ userPassword = cipher.encryptBlock(userPassword);
1901
+ }
1902
+ } else {
1903
+ cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
1904
+ userPassword = cipher.encryptBlock(ownerPassword);
1905
+ }
1906
+ return userPassword;
1907
+ }
1908
+
1909
+ buildObjectKey(
1910
+ num: number,
1911
+ gen: number,
1912
+ encryptionKey: Uint8Array,
1913
+ isAes: boolean = false,
1914
+ ) {
1915
+ const key = new Uint8Array(encryptionKey.length + 9);
1916
+ const n = encryptionKey.length;
1917
+ let i;
1918
+ for (i = 0; i < n; ++i) {
1919
+ key[i] = encryptionKey[i];
1920
+ }
1921
+ key[i++] = num & 0xff;
1922
+ key[i++] = (num >> 8) & 0xff;
1923
+ key[i++] = (num >> 16) & 0xff;
1924
+ key[i++] = gen & 0xff;
1925
+ key[i++] = (gen >> 8) & 0xff;
1926
+ if (isAes) {
1927
+ key[i++] = 0x73;
1928
+ key[i++] = 0x41;
1929
+ key[i++] = 0x6c;
1930
+ key[i++] = 0x54;
1931
+ }
1932
+ const hash = calculateMD5(key, 0, i);
1933
+ return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
1934
+ }
1935
+
1936
+ buildCipherConstructor(
1937
+ cf: PDFDict,
1938
+ name: PDFName,
1939
+ num: number,
1940
+ gen: number,
1941
+ key: Uint8Array,
1942
+ ) {
1943
+ if (!(name instanceof PDFName)) {
1944
+ throw new Error('Invalid crypt filter name.');
1945
+ }
1946
+ const cryptFilter = cf.get(
1947
+ PDFName.of(name.asString().replace('/', '')),
1948
+ ) as PDFDict;
1949
+ let cfm;
1950
+ if (cryptFilter !== null && cryptFilter !== undefined) {
1951
+ cfm = cryptFilter.get(PDFName.of('CFM')) as PDFName;
1952
+ }
1953
+ if (!cfm || cfm.asString() === '/None') {
1954
+ return function cipherTransformFactoryBuildCipherConstructorNone() {
1955
+ return new NullCipher();
1956
+ };
1957
+ }
1958
+ if (cfm.asString() === '/V2') {
1959
+ return () =>
1960
+ new ARCFourCipher(
1961
+ this.buildObjectKey(num, gen, key, /* isAes = */ false),
1962
+ );
1963
+ }
1964
+ if (cfm.asString() === '/AESV2') {
1965
+ return () =>
1966
+ new AES128Cipher(
1967
+ this.buildObjectKey(num, gen, key, /* isAes = */ true),
1968
+ );
1969
+ }
1970
+ if (cfm.asString() === '/AESV3') {
1971
+ return () => new AES256Cipher(key);
1972
+ }
1973
+ throw new Error('Unknown crypto method');
1974
+ }
1975
+ }
1976
+
1977
+ export {
1978
+ AES128Cipher,
1979
+ AES256Cipher,
1980
+ ARCFourCipher,
1981
+ calculateMD5,
1982
+ calculateSHA256,
1983
+ calculateSHA384,
1984
+ calculateSHA512,
1985
+ CipherTransformFactory,
1986
+ CipherTransform,
1987
+ PDF17,
1988
+ PDF20,
1989
+ };