@pdfme/pdf-lib 6.0.3 → 6.0.5-dev.1

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 (449) hide show
  1. package/{src/api/Embeddable.ts → dist/api/Embeddable.d.ts} +1 -1
  2. package/dist/api/PDFDocument.d.ts +778 -0
  3. package/dist/api/PDFDocumentOptions.d.ts +38 -0
  4. package/dist/api/PDFEmbeddedFile.d.ts +38 -0
  5. package/dist/api/PDFEmbeddedPage.d.ts +73 -0
  6. package/dist/api/PDFFont.d.ts +94 -0
  7. package/dist/api/PDFImage.d.ts +95 -0
  8. package/dist/api/PDFJavaScript.d.ts +38 -0
  9. package/dist/api/PDFPage.d.ts +910 -0
  10. package/dist/api/PDFPageOptions.d.ts +172 -0
  11. package/dist/api/StandardFonts.d.ts +16 -0
  12. package/dist/api/colors.d.ts +34 -0
  13. package/dist/api/errors.d.ts +42 -0
  14. package/dist/api/form/PDFButton.d.ts +137 -0
  15. package/dist/api/form/PDFCheckBox.d.ts +142 -0
  16. package/dist/api/form/PDFDropdown.d.ts +402 -0
  17. package/dist/api/form/PDFField.d.ts +203 -0
  18. package/dist/api/form/PDFForm.d.ts +411 -0
  19. package/dist/api/form/PDFOptionList.d.ts +335 -0
  20. package/dist/api/form/PDFRadioGroup.d.ts +252 -0
  21. package/dist/api/form/PDFSignature.d.ts +29 -0
  22. package/dist/api/form/PDFTextField.d.ts +537 -0
  23. package/dist/api/form/appearances.d.ts +41 -0
  24. package/dist/api/image/alignment.d.ts +5 -0
  25. package/dist/api/objects.d.ts +4 -0
  26. package/dist/api/operations.d.ts +226 -0
  27. package/dist/api/operators.d.ts +90 -0
  28. package/dist/api/rotations.d.ts +38 -0
  29. package/dist/api/sizes.d.ts +52 -0
  30. package/dist/api/svg.d.ts +70 -0
  31. package/dist/api/svgPath.d.ts +2 -0
  32. package/dist/api/text/alignment.d.ts +5 -0
  33. package/dist/api/text/layout.d.ts +54 -0
  34. package/dist/core/PDFContext.d.ts +84 -0
  35. package/dist/core/PDFObjectCopier.d.ts +37 -0
  36. package/dist/core/acroform/PDFAcroButton.d.ts +21 -0
  37. package/dist/core/acroform/PDFAcroCheckBox.d.ts +13 -0
  38. package/dist/core/acroform/PDFAcroChoice.d.ts +20 -0
  39. package/dist/core/acroform/PDFAcroComboBox.d.ts +9 -0
  40. package/dist/core/acroform/PDFAcroField.d.ts +36 -0
  41. package/dist/core/acroform/PDFAcroForm.d.ts +20 -0
  42. package/dist/core/acroform/PDFAcroListBox.d.ts +9 -0
  43. package/dist/core/acroform/PDFAcroNonTerminal.d.ts +13 -0
  44. package/dist/core/acroform/PDFAcroPushButton.d.ts +9 -0
  45. package/dist/core/acroform/PDFAcroRadioButton.d.ts +13 -0
  46. package/{src/core/acroform/PDFAcroSignature.ts → dist/core/acroform/PDFAcroSignature.d.ts} +2 -4
  47. package/dist/core/acroform/PDFAcroTerminal.d.ts +16 -0
  48. package/dist/core/acroform/PDFAcroText.d.ts +22 -0
  49. package/dist/core/acroform/flags.d.ts +141 -0
  50. package/dist/core/acroform/utils.d.ts +6 -0
  51. package/dist/core/annotation/AppearanceCharacteristics.d.ts +33 -0
  52. package/dist/core/annotation/BorderStyle.d.ts +11 -0
  53. package/dist/core/annotation/PDFAnnotation.d.ts +51 -0
  54. package/dist/core/annotation/PDFWidgetAnnotation.d.ts +26 -0
  55. package/dist/core/annotation/flags.d.ts +79 -0
  56. package/dist/core/crypto.d.ts +95 -0
  57. package/dist/core/document/PDFCrossRefSection.d.ts +27 -0
  58. package/dist/core/document/PDFHeader.d.ts +10 -0
  59. package/dist/core/document/PDFTrailer.d.ts +9 -0
  60. package/dist/core/document/PDFTrailerDict.d.ts +10 -0
  61. package/dist/core/embedders/CMap.d.ts +3 -0
  62. package/dist/core/embedders/CustomFontEmbedder.d.ts +44 -0
  63. package/dist/core/embedders/CustomFontSubsetEmbedder.d.ts +20 -0
  64. package/dist/core/embedders/FileEmbedder.d.ts +33 -0
  65. package/dist/core/embedders/FontFlags.d.ts +13 -0
  66. package/dist/core/embedders/JavaScriptEmbedder.d.ts +10 -0
  67. package/dist/core/embedders/JpegEmbedder.d.ts +23 -0
  68. package/dist/core/embedders/PDFPageEmbedder.d.ts +37 -0
  69. package/dist/core/embedders/PngEmbedder.d.ts +19 -0
  70. package/dist/core/embedders/StandardFontEmbedder.d.ts +36 -0
  71. package/dist/core/errors.d.ts +94 -0
  72. package/{src/core/index.ts → dist/core/index.d.ts} +1 -17
  73. package/dist/core/interactive/ViewerPreferences.d.ts +347 -0
  74. package/dist/core/objects/PDFArray.d.ts +63 -0
  75. package/dist/core/objects/PDFBool.d.ts +13 -0
  76. package/dist/core/objects/PDFDict.d.ts +62 -0
  77. package/dist/core/objects/PDFHexString.d.ts +16 -0
  78. package/dist/core/objects/PDFInvalidObject.d.ts +11 -0
  79. package/dist/core/objects/PDFName.d.ts +41 -0
  80. package/dist/core/objects/PDFNull.d.ts +10 -0
  81. package/dist/core/objects/PDFNumber.d.ts +15 -0
  82. package/dist/core/objects/PDFObject.d.ts +8 -0
  83. package/dist/core/objects/PDFRawStream.d.ts +16 -0
  84. package/dist/core/objects/PDFRef.d.ts +13 -0
  85. package/dist/core/objects/PDFStream.d.ts +16 -0
  86. package/dist/core/objects/PDFString.d.ts +16 -0
  87. package/dist/core/operators/PDFOperator.d.ts +19 -0
  88. package/dist/core/operators/PDFOperatorNames.d.ts +76 -0
  89. package/dist/core/parser/BaseParser.d.ts +14 -0
  90. package/dist/core/parser/ByteStream.d.ts +26 -0
  91. package/dist/core/parser/PDFObjectParser.d.ts +31 -0
  92. package/dist/core/parser/PDFObjectStreamParser.d.ts +13 -0
  93. package/dist/core/parser/PDFParser.d.ts +46 -0
  94. package/dist/core/parser/PDFXRefStreamParser.d.ts +21 -0
  95. package/dist/core/streams/Ascii85Stream.d.ts +9 -0
  96. package/dist/core/streams/AsciiHexStream.d.ts +9 -0
  97. package/dist/core/streams/DecodeStream.d.ts +26 -0
  98. package/dist/core/streams/DecryptStream.d.ts +12 -0
  99. package/dist/core/streams/FlateStream.d.ts +13 -0
  100. package/dist/core/streams/LZWStream.d.ts +12 -0
  101. package/dist/core/streams/RunLengthStream.d.ts +8 -0
  102. package/dist/core/streams/Stream.d.ts +34 -0
  103. package/dist/core/streams/decode.d.ts +3 -0
  104. package/dist/core/structures/PDFCatalog.d.ts +27 -0
  105. package/dist/core/structures/PDFContentStream.d.ts +15 -0
  106. package/dist/core/structures/PDFCrossRefStream.d.ts +53 -0
  107. package/dist/core/structures/PDFFlateStream.d.ts +13 -0
  108. package/dist/core/structures/PDFObjectStream.d.ts +20 -0
  109. package/dist/core/structures/PDFPageLeaf.d.ts +54 -0
  110. package/dist/core/structures/PDFPageTree.d.ts +41 -0
  111. package/dist/core/syntax/CharCodes.d.ts +61 -0
  112. package/dist/core/syntax/Delimiters.d.ts +1 -0
  113. package/dist/core/syntax/Irregular.d.ts +1 -0
  114. package/dist/core/syntax/Keywords.d.ts +22 -0
  115. package/dist/core/syntax/Numeric.d.ts +3 -0
  116. package/dist/core/syntax/Whitespace.d.ts +1 -0
  117. package/dist/core/writers/PDFStreamWriter.d.ts +19 -0
  118. package/dist/core/writers/PDFWriter.d.ts +29 -0
  119. package/dist/index.js +19124 -0
  120. package/dist/index.js.map +1 -0
  121. package/dist/types/fontkit.d.ts +597 -0
  122. package/{src/types/index.ts → dist/types/index.d.ts} +8 -13
  123. package/{src/types/matrix.ts → dist/types/matrix.d.ts} +1 -2
  124. package/dist/utils/Cache.d.ts +10 -0
  125. package/dist/utils/arrays.d.ts +16 -0
  126. package/dist/utils/async.d.ts +5 -0
  127. package/dist/utils/base64.d.ts +10 -0
  128. package/dist/utils/elements/Arc.d.ts +22 -0
  129. package/dist/utils/elements/Circle.d.ts +14 -0
  130. package/dist/utils/elements/Ellipse.d.ts +20 -0
  131. package/dist/utils/elements/GraphElement.d.ts +6 -0
  132. package/dist/utils/elements/Line.d.ts +23 -0
  133. package/dist/utils/elements/Plot.d.ts +11 -0
  134. package/dist/utils/elements/Point.d.ts +18 -0
  135. package/dist/utils/elements/Rectangle.d.ts +21 -0
  136. package/dist/utils/elements/Segment.d.ts +19 -0
  137. package/dist/utils/errors.d.ts +1 -0
  138. package/dist/utils/intersections.d.ts +9 -0
  139. package/dist/utils/maths.d.ts +45 -0
  140. package/dist/utils/numbers.d.ts +23 -0
  141. package/dist/utils/objects.d.ts +15 -0
  142. package/dist/utils/pdfDocEncoding.d.ts +7 -0
  143. package/dist/utils/png.d.ts +17 -0
  144. package/dist/utils/rng.d.ts +13 -0
  145. package/dist/utils/strings.d.ts +25 -0
  146. package/{src/utils/unicode.ts → dist/utils/unicode.d.ts} +8 -195
  147. package/dist/utils/validators.d.ts +26 -0
  148. package/package.json +6 -1
  149. package/__tests__/api/PDFDocument.spec.ts +0 -576
  150. package/__tests__/api/PDFImage.spec.ts +0 -60
  151. package/__tests__/api/PDFPage.spec.ts +0 -151
  152. package/__tests__/api/form/PDFCheckBox.spec.ts +0 -71
  153. package/__tests__/api/form/PDFDropdown.spec.ts +0 -118
  154. package/__tests__/api/form/PDFForm.spec.ts +0 -370
  155. package/__tests__/api/form/PDFOptionList.spec.ts +0 -104
  156. package/__tests__/api/form/PDFRadioGroup.spec.ts +0 -183
  157. package/__tests__/api/form/PDFTextField.spec.ts +0 -148
  158. package/__tests__/api/svgPath.spec.ts +0 -153
  159. package/__tests__/api/text/layout.spec.ts +0 -166
  160. package/__tests__/core/PDFContext.spec.ts +0 -194
  161. package/__tests__/core/PDFObjectCopier.spec.ts +0 -421
  162. package/__tests__/core/acroform/PDFAcroField.spec.ts +0 -98
  163. package/__tests__/core/acroform/PDFAcroTerminal.spec.ts +0 -39
  164. package/__tests__/core/annotation/PDFWidgetAnnotation.spec.ts +0 -40
  165. package/__tests__/core/document/PDFCrossRefSection.spec.ts +0 -88
  166. package/__tests__/core/document/PDFHeader.spec.ts +0 -22
  167. package/__tests__/core/document/PDFTrailer.spec.ts +0 -28
  168. package/__tests__/core/document/PDFTrailerDict.spec.ts +0 -24
  169. package/__tests__/core/embedders/CMap.spec.ts +0 -47
  170. package/__tests__/core/embedders/CustomFontEmbedder.spec.ts +0 -96
  171. package/__tests__/core/embedders/CustomFontSubsetEmbedder.spec.ts +0 -62
  172. package/__tests__/core/embedders/FileEmbedder.spec.ts +0 -54
  173. package/__tests__/core/embedders/JpegEmbedder.spec.ts +0 -67
  174. package/__tests__/core/embedders/PDFPageEmbedder.spec.ts +0 -65
  175. package/__tests__/core/embedders/PngEmbedder.spec.ts +0 -87
  176. package/__tests__/core/embedders/StandardFontEmbedder.spec.ts +0 -79
  177. package/__tests__/core/embedders/data/SourceHanSerifJP-Regular.otf.cmap +0 -16096
  178. package/__tests__/core/embedders/data/Ubuntu-R.ttf.cmap +0 -1211
  179. package/__tests__/core/objects/PDFArray.spec.ts +0 -134
  180. package/__tests__/core/objects/PDFBool.spec.ts +0 -42
  181. package/__tests__/core/objects/PDFDict.spec.ts +0 -195
  182. package/__tests__/core/objects/PDFHexString.spec.ts +0 -168
  183. package/__tests__/core/objects/PDFInvalidObject.spec.ts +0 -32
  184. package/__tests__/core/objects/PDFName.spec.ts +0 -122
  185. package/__tests__/core/objects/PDFNull.spec.ts +0 -30
  186. package/__tests__/core/objects/PDFNumber.spec.ts +0 -50
  187. package/__tests__/core/objects/PDFObject.spec.ts +0 -29
  188. package/__tests__/core/objects/PDFRawStream.spec.ts +0 -45
  189. package/__tests__/core/objects/PDFRef.spec.ts +0 -60
  190. package/__tests__/core/objects/PDFString.spec.ts +0 -237
  191. package/__tests__/core/operators/PDFOperator.spec.ts +0 -77
  192. package/__tests__/core/parser/PDFObjectParser.spec.ts +0 -730
  193. package/__tests__/core/parser/PDFObjectStreamParser.spec.ts +0 -158
  194. package/__tests__/core/parser/PDFParser.spec.ts +0 -398
  195. package/__tests__/core/parser/PDFXRefStreamParser.spec.ts +0 -187
  196. package/__tests__/core/parser/data/object-stream-invalid +0 -2
  197. package/__tests__/core/parser/data/object-stream1 +0 -16
  198. package/__tests__/core/parser/data/object-stream2 +0 -10
  199. package/__tests__/core/parser/data/object-stream3 +0 -0
  200. package/__tests__/core/parser/data/object-stream4 +0 -0
  201. package/__tests__/core/parser/data/xref-stream1 +0 -0
  202. package/__tests__/core/parser/data/xref-stream2 +0 -0
  203. package/__tests__/core/parser/data/xref-stream3 +0 -0
  204. package/__tests__/core/parser/data/xref-stream4 +0 -0
  205. package/__tests__/core/streams/Ascii85Stream.spec.ts +0 -20
  206. package/__tests__/core/streams/AsciiHexStream.spec.ts +0 -20
  207. package/__tests__/core/streams/FlateStream.spec.ts +0 -20
  208. package/__tests__/core/streams/LZWStream.spec.ts +0 -20
  209. package/__tests__/core/streams/RunLengthStream.spec.ts +0 -20
  210. package/__tests__/core/streams/Stream.spec.ts +0 -128
  211. package/__tests__/core/streams/data/ascii85/1.decoded +0 -0
  212. package/__tests__/core/streams/data/ascii85/1.encoded +0 -43
  213. package/__tests__/core/streams/data/asciihex/1.decoded +0 -1
  214. package/__tests__/core/streams/data/asciihex/1.encoded +0 -1
  215. package/__tests__/core/streams/data/asciihex/2.decoded +0 -7
  216. package/__tests__/core/streams/data/asciihex/2.encoded +0 -1
  217. package/__tests__/core/streams/data/flate/1.corrupt.encoded +0 -1
  218. package/__tests__/core/streams/data/flate/1.decoded +0 -0
  219. package/__tests__/core/streams/data/flate/1.encoded +0 -2
  220. package/__tests__/core/streams/data/flate/2.decoded +0 -33
  221. package/__tests__/core/streams/data/flate/2.encoded +0 -0
  222. package/__tests__/core/streams/data/flate/3.decoded +0 -15
  223. package/__tests__/core/streams/data/flate/3.encoded +0 -0
  224. package/__tests__/core/streams/data/flate/4.decoded +0 -16
  225. package/__tests__/core/streams/data/flate/4.encoded +0 -0
  226. package/__tests__/core/streams/data/flate/5.decoded +0 -0
  227. package/__tests__/core/streams/data/flate/5.encoded +0 -0
  228. package/__tests__/core/streams/data/flate/6.decoded +0 -17
  229. package/__tests__/core/streams/data/flate/6.encoded +0 -0
  230. package/__tests__/core/streams/data/flate/7.decoded +0 -20
  231. package/__tests__/core/streams/data/flate/7.encoded +0 -1
  232. package/__tests__/core/streams/data/lzw/1.decoded +0 -0
  233. package/__tests__/core/streams/data/lzw/1.encoded +0 -0
  234. package/__tests__/core/streams/data/lzw/2.decoded +0 -0
  235. package/__tests__/core/streams/data/lzw/2.encoded +0 -0
  236. package/__tests__/core/streams/data/lzw/3.decoded +0 -14
  237. package/__tests__/core/streams/data/lzw/3.encoded +0 -2
  238. package/__tests__/core/streams/data/lzw/4.decoded +0 -14
  239. package/__tests__/core/streams/data/lzw/4.encoded +0 -2
  240. package/__tests__/core/streams/data/runlength/1.decoded +0 -1
  241. package/__tests__/core/streams/data/runlength/1.encoded +0 -1
  242. package/__tests__/core/streams/data/runlength/2.decoded +0 -1
  243. package/__tests__/core/streams/data/runlength/2.encoded +0 -1
  244. package/__tests__/core/streams/data/runlength/3.decoded +0 -0
  245. package/__tests__/core/streams/data/runlength/3.encoded +0 -0
  246. package/__tests__/core/streams/data/runlength/4.decoded +0 -1
  247. package/__tests__/core/streams/data/runlength/4.encoded +0 -1
  248. package/__tests__/core/streams/data/runlength/5.decoded +0 -1
  249. package/__tests__/core/streams/data/runlength/5.encoded +0 -1
  250. package/__tests__/core/streams/data/runlength/empty.encoded +0 -1
  251. package/__tests__/core/structures/PDFCatalog.spec.ts +0 -108
  252. package/__tests__/core/structures/PDFContentStream.spec.ts +0 -117
  253. package/__tests__/core/structures/PDFCrossRefStream.spec.ts +0 -145
  254. package/__tests__/core/structures/PDFObjectStream.spec.ts +0 -138
  255. package/__tests__/core/structures/PDFPageLeaf.spec.ts +0 -355
  256. package/__tests__/core/structures/PDFPageTree.spec.ts +0 -592
  257. package/__tests__/core/writers/PDFStreamWriter.spec.ts +0 -71
  258. package/__tests__/core/writers/PDFWriter.spec.ts +0 -144
  259. package/__tests__/core/writers/data/stream-writer-1.pdf +0 -0
  260. package/__tests__/index.test.ts +0 -12
  261. package/__tests__/utils/base64.spec.ts +0 -61
  262. package/__tests__/utils/data/simple.pdf +0 -201
  263. package/__tests__/utils/data/simple.pdf.base64 +0 -1
  264. package/__tests__/utils/pdfDocEncoding.spec.ts +0 -82
  265. package/__tests__/utils/png.spec.ts +0 -53
  266. package/__tests__/utils/rng.spec.ts +0 -14
  267. package/__tests__/utils/strings.spec.ts +0 -98
  268. package/__tests__/utils/unicode.spec.ts +0 -337
  269. package/assets/fonts/source_hans_jp/SourceHanSerifJP-Regular.otf +0 -0
  270. package/assets/fonts/ubuntu/Ubuntu-B.ttf +0 -0
  271. package/assets/fonts/ubuntu/Ubuntu-R.ttf +0 -0
  272. package/assets/images/cat_riding_unicorn.jpg +0 -0
  273. package/assets/images/cmyk_colorspace.jpg +0 -0
  274. package/assets/images/greyscale_bird.png +0 -0
  275. package/assets/images/minions_banana_alpha.png +0 -0
  276. package/assets/images/minions_banana_no_alpha.png +0 -0
  277. package/assets/images/minions_laughing.jpg +0 -0
  278. package/assets/pdfs/bixby_guide.pdf +0 -0
  279. package/assets/pdfs/encrypted_new.pdf +0 -0
  280. package/assets/pdfs/encrypted_old.pdf +0 -0
  281. package/assets/pdfs/fancy_fields.pdf +0 -0
  282. package/assets/pdfs/giraffe.pdf +0 -0
  283. package/assets/pdfs/invalid_root_ref.pdf +0 -0
  284. package/assets/pdfs/just_metadata.pdf +0 -49
  285. package/assets/pdfs/missing_endobj_keyword.pdf +0 -70
  286. package/assets/pdfs/missing_xref_trailer_dict.pdf +0 -141
  287. package/assets/pdfs/normal.pdf +0 -0
  288. package/assets/pdfs/pdf20examples/PDF 2.0 with offset start.pdf +0 -179
  289. package/assets/pdfs/stuff_following_header.pdf +0 -0
  290. package/assets/pdfs/us_constitution.pdf +0 -0
  291. package/assets/pdfs/with_comments.pdf +0 -0
  292. package/assets/pdfs/with_invalid_objects.pdf +0 -53
  293. package/assets/pdfs/with_invalid_stream_EOL.pdf +0 -0
  294. package/assets/pdfs/with_null_parent_entry.pdf +0 -0
  295. package/assets/pdfs/with_signature.pdf +0 -0
  296. package/assets/pdfs/with_update_sections.pdf +0 -0
  297. package/assets/pdfs/with_viewer_prefs.pdf +0 -0
  298. package/assets/pdfs/with_xfa_fields.pdf +0 -0
  299. package/src/api/PDFDocument.ts +0 -1389
  300. package/src/api/PDFDocumentOptions.ts +0 -45
  301. package/src/api/PDFEmbeddedFile.ts +0 -87
  302. package/src/api/PDFEmbeddedPage.ts +0 -100
  303. package/src/api/PDFFont.ts +0 -149
  304. package/src/api/PDFImage.ts +0 -143
  305. package/src/api/PDFJavaScript.ts +0 -75
  306. package/src/api/PDFPage.ts +0 -1604
  307. package/src/api/PDFPageOptions.ts +0 -175
  308. package/src/api/StandardFonts.ts +0 -16
  309. package/src/api/colors.ts +0 -109
  310. package/src/api/errors.ts +0 -110
  311. package/src/api/form/PDFButton.ts +0 -242
  312. package/src/api/form/PDFCheckBox.ts +0 -247
  313. package/src/api/form/PDFDropdown.ts +0 -637
  314. package/src/api/form/PDFField.ts +0 -491
  315. package/src/api/form/PDFForm.ts +0 -842
  316. package/src/api/form/PDFOptionList.ts +0 -555
  317. package/src/api/form/PDFRadioGroup.ts +0 -455
  318. package/src/api/form/PDFSignature.ts +0 -44
  319. package/src/api/form/PDFTextField.ts +0 -811
  320. package/src/api/form/appearances.ts +0 -655
  321. package/src/api/image/alignment.ts +0 -5
  322. package/src/api/objects.ts +0 -10
  323. package/src/api/operations.ts +0 -873
  324. package/src/api/operators.ts +0 -335
  325. package/src/api/rotations.ts +0 -84
  326. package/src/api/sizes.ts +0 -52
  327. package/src/api/svg.ts +0 -888
  328. package/src/api/svgPath.ts +0 -460
  329. package/src/api/text/alignment.ts +0 -5
  330. package/src/api/text/layout.ts +0 -328
  331. package/src/core/PDFContext.ts +0 -274
  332. package/src/core/PDFObjectCopier.ts +0 -142
  333. package/src/core/acroform/PDFAcroButton.ts +0 -104
  334. package/src/core/acroform/PDFAcroCheckBox.ts +0 -48
  335. package/src/core/acroform/PDFAcroChoice.ts +0 -143
  336. package/src/core/acroform/PDFAcroComboBox.ts +0 -21
  337. package/src/core/acroform/PDFAcroField.ts +0 -168
  338. package/src/core/acroform/PDFAcroForm.ts +0 -96
  339. package/src/core/acroform/PDFAcroListBox.ts +0 -19
  340. package/src/core/acroform/PDFAcroNonTerminal.ts +0 -33
  341. package/src/core/acroform/PDFAcroPushButton.ts +0 -21
  342. package/src/core/acroform/PDFAcroRadioButton.ts +0 -57
  343. package/src/core/acroform/PDFAcroTerminal.ts +0 -70
  344. package/src/core/acroform/PDFAcroText.ts +0 -76
  345. package/src/core/acroform/flags.ts +0 -162
  346. package/src/core/acroform/utils.ts +0 -129
  347. package/src/core/annotation/AppearanceCharacteristics.ts +0 -133
  348. package/src/core/annotation/BorderStyle.ts +0 -31
  349. package/src/core/annotation/PDFAnnotation.ts +0 -148
  350. package/src/core/annotation/PDFWidgetAnnotation.ts +0 -111
  351. package/src/core/annotation/flags.ts +0 -90
  352. package/src/core/crypto.ts +0 -1844
  353. package/src/core/document/PDFCrossRefSection.ts +0 -161
  354. package/src/core/document/PDFHeader.ts +0 -48
  355. package/src/core/document/PDFTrailer.ts +0 -48
  356. package/src/core/document/PDFTrailerDict.ts +0 -39
  357. package/src/core/embedders/CMap.ts +0 -65
  358. package/src/core/embedders/CustomFontEmbedder.ts +0 -237
  359. package/src/core/embedders/CustomFontSubsetEmbedder.ts +0 -89
  360. package/src/core/embedders/FileEmbedder.ts +0 -77
  361. package/src/core/embedders/FontFlags.ts +0 -45
  362. package/src/core/embedders/JavaScriptEmbedder.ts +0 -34
  363. package/src/core/embedders/JpegEmbedder.ts +0 -118
  364. package/src/core/embedders/PDFPageEmbedder.ts +0 -139
  365. package/src/core/embedders/PngEmbedder.ts +0 -69
  366. package/src/core/embedders/StandardFontEmbedder.ts +0 -121
  367. package/src/core/errors.ts +0 -226
  368. package/src/core/interactive/ViewerPreferences.ts +0 -565
  369. package/src/core/objects/PDFArray.ts +0 -179
  370. package/src/core/objects/PDFBool.ts +0 -53
  371. package/src/core/objects/PDFDict.ts +0 -220
  372. package/src/core/objects/PDFHexString.ts +0 -94
  373. package/src/core/objects/PDFInvalidObject.ts +0 -34
  374. package/src/core/objects/PDFName.ts +0 -152
  375. package/src/core/objects/PDFNull.ts +0 -30
  376. package/src/core/objects/PDFNumber.ts +0 -44
  377. package/src/core/objects/PDFObject.ts +0 -22
  378. package/src/core/objects/PDFRawStream.ts +0 -41
  379. package/src/core/objects/PDFRef.ts +0 -51
  380. package/src/core/objects/PDFStream.ts +0 -87
  381. package/src/core/objects/PDFString.ts +0 -118
  382. package/src/core/operators/PDFOperator.ts +0 -72
  383. package/src/core/operators/PDFOperatorNames.ts +0 -92
  384. package/src/core/parser/BaseParser.ts +0 -119
  385. package/src/core/parser/ByteStream.ts +0 -76
  386. package/src/core/parser/PDFObjectParser.ts +0 -302
  387. package/src/core/parser/PDFObjectStreamParser.ts +0 -65
  388. package/src/core/parser/PDFParser.ts +0 -363
  389. package/src/core/parser/PDFXRefStreamParser.ts +0 -129
  390. package/src/core/streams/Ascii85Stream.ts +0 -97
  391. package/src/core/streams/AsciiHexStream.ts +0 -77
  392. package/src/core/streams/DecodeStream.ts +0 -188
  393. package/src/core/streams/DecryptStream.ts +0 -49
  394. package/src/core/streams/FlateStream.ts +0 -397
  395. package/src/core/streams/LZWStream.ts +0 -157
  396. package/src/core/streams/RunLengthStream.ts +0 -55
  397. package/src/core/streams/Stream.ts +0 -126
  398. package/src/core/streams/decode.ts +0 -70
  399. package/src/core/structures/PDFCatalog.ts +0 -81
  400. package/src/core/structures/PDFContentStream.ts +0 -58
  401. package/src/core/structures/PDFCrossRefStream.ts +0 -238
  402. package/src/core/structures/PDFFlateStream.ts +0 -40
  403. package/src/core/structures/PDFObjectStream.ts +0 -91
  404. package/src/core/structures/PDFPageLeaf.ts +0 -244
  405. package/src/core/structures/PDFPageTree.ts +0 -192
  406. package/src/core/syntax/CharCodes.ts +0 -62
  407. package/src/core/syntax/Delimiters.ts +0 -14
  408. package/src/core/syntax/Irregular.ts +0 -10
  409. package/src/core/syntax/Keywords.ts +0 -57
  410. package/src/core/syntax/Numeric.ts +0 -26
  411. package/src/core/syntax/Whitespace.ts +0 -10
  412. package/src/core/writers/PDFStreamWriter.ts +0 -114
  413. package/src/core/writers/PDFWriter.ts +0 -146
  414. package/src/types/fontkit.ts +0 -643
  415. package/src/utils/Cache.ts +0 -26
  416. package/src/utils/arrays.ts +0 -153
  417. package/src/utils/async.ts +0 -8
  418. package/src/utils/base64.ts +0 -98
  419. package/src/utils/elements/Arc.ts +0 -97
  420. package/src/utils/elements/Circle.ts +0 -47
  421. package/src/utils/elements/Ellipse.ts +0 -117
  422. package/src/utils/elements/GraphElement.ts +0 -14
  423. package/src/utils/elements/Line.ts +0 -83
  424. package/src/utils/elements/Plot.ts +0 -50
  425. package/src/utils/elements/Point.ts +0 -37
  426. package/src/utils/elements/Rectangle.ts +0 -65
  427. package/src/utils/elements/Segment.ts +0 -81
  428. package/src/utils/errors.ts +0 -3
  429. package/src/utils/intersections.ts +0 -237
  430. package/src/utils/maths.ts +0 -96
  431. package/src/utils/numbers.ts +0 -55
  432. package/src/utils/objects.ts +0 -13
  433. package/src/utils/pdfDocEncoding.ts +0 -69
  434. package/src/utils/png.ts +0 -100
  435. package/src/utils/rng.ts +0 -21
  436. package/src/utils/strings.ts +0 -191
  437. package/src/utils/validators.ts +0 -192
  438. package/tsconfig.build.json +0 -14
  439. package/tsconfig.json +0 -15
  440. package/vite.config.mts +0 -39
  441. /package/{src/api/form/index.ts → dist/api/form/index.d.ts} +0 -0
  442. /package/{src/api/image/index.ts → dist/api/image/index.d.ts} +0 -0
  443. /package/{src/api/index.ts → dist/api/index.d.ts} +0 -0
  444. /package/{src/api/text/index.ts → dist/api/text/index.d.ts} +0 -0
  445. /package/{src/core/acroform/index.ts → dist/core/acroform/index.d.ts} +0 -0
  446. /package/{src/core/annotation/index.ts → dist/core/annotation/index.d.ts} +0 -0
  447. /package/{src/index.ts → dist/index.d.ts} +0 -0
  448. /package/{src/utils/elements/index.ts → dist/utils/elements/index.d.ts} +0 -0
  449. /package/{src/utils/index.ts → dist/utils/index.d.ts} +0 -0
@@ -1,65 +0,0 @@
1
- import GraphElement from './GraphElement';
2
- import Point from './Point';
3
- import Segment from './Segment';
4
-
5
- export default class Rectangle extends GraphElement {
6
- static type = 'Rectangle';
7
- start: Point;
8
- end: Point;
9
- constructor(start: Point = new Point(), end: Point = new Point()) {
10
- super();
11
- this.start = start;
12
- this.end = end;
13
- }
14
-
15
- getSize() {
16
- const start = this.start.toCoords();
17
- const end = this.end.toCoords();
18
- return {
19
- width: Math.abs(start.x - end.x),
20
- height: Math.abs(start.y - end.y),
21
- };
22
- }
23
-
24
- getCoords() {
25
- const start = this.start.toCoords();
26
- const end = this.end.toCoords();
27
- return {
28
- x: Math.min(start.x, end.x),
29
- y: Math.max(start.y, end.y),
30
- };
31
- }
32
-
33
- getStart() {
34
- const start = new Point(this.getCoords());
35
- return start;
36
- }
37
-
38
- getEnd() {
39
- const { width, height } = this.getSize();
40
- const end = new Point(this.getStart()).plus({ x: width, y: -height });
41
- return end;
42
- }
43
-
44
- center() {
45
- const center = new Segment(this.getStart(), this.getEnd()).middle();
46
- return center;
47
- }
48
-
49
- isEqual(element: GraphElement): boolean {
50
- return (
51
- element instanceof Rectangle &&
52
- this.getStart().isEqual(element.getStart()) &&
53
- this.getEnd().isEqual(element.getEnd())
54
- );
55
- }
56
-
57
- orthoProjection(P: Point) {
58
- const { x, y } = this.getCoords();
59
- const end = this.getEnd().toCoords();
60
- const { x: Px, y: Py } = P.toCoords();
61
- const Hx = Px < x ? x : Px > end.x ? end.x : Px;
62
- const Hy = Py > y ? y : Py < end.y ? end.y : Py;
63
- return new Point({ x: Hx, y: Hy });
64
- }
65
- }
@@ -1,81 +0,0 @@
1
- import { distance, isColinear, norm, scalar, vector, plus, times } from '../maths';
2
-
3
- import GraphElement from './GraphElement';
4
- import Line from './Line';
5
- import Point from './Point';
6
-
7
- export default class Segment extends GraphElement {
8
- static type = 'Segment';
9
- A: Point;
10
- B: Point;
11
- constructor(A: Point = new Point(), B: Point = new Point()) {
12
- super();
13
- this.A = A;
14
- this.B = B;
15
- }
16
-
17
- origin(): Point {
18
- return this.A;
19
- }
20
-
21
- destination(): Point {
22
- return this.B;
23
- }
24
-
25
- dirVect() {
26
- return vector(this.origin(), this.destination());
27
- }
28
-
29
- length() {
30
- return distance(this.destination(), this.origin());
31
- }
32
-
33
- isEqual(element: GraphElement): boolean {
34
- if (!(element instanceof Segment)) return false;
35
- const o = this.origin();
36
- const dest = this.destination();
37
- const oE = element.origin();
38
- const destE = element.destination();
39
- return (
40
- element instanceof Segment &&
41
- ((o.isEqual(oE) && dest.isEqual(destE)) || (o.isEqual(destE) && dest.isEqual(oE)))
42
- );
43
- }
44
-
45
- /** Returns an equivalent line object */
46
- getLine() {
47
- const line = new Line(this.origin(), this.destination());
48
- return line;
49
- }
50
-
51
- includes(P: Point) {
52
- const vect = this.dirVect();
53
- const otherVect = vector(this.origin(), P);
54
- // The vectors are not even colinear
55
- if (!isColinear(vect, otherVect)) return false;
56
- // The point is behind the origin
57
- else if (scalar(vect, otherVect) < 0) return false;
58
- // The point is after the destination
59
- else if (norm(vect) < norm(otherVect)) return false;
60
- else return true;
61
- }
62
-
63
- middle() {
64
- const mid = new Point(plus(this.origin().toCoords(), times(this.dirVect(), 0.5)));
65
- return mid;
66
- }
67
-
68
- orthoProjection(P: Point) {
69
- const H = this.getLine().orthoProjection(P);
70
- const vect = this.dirVect();
71
- const origin = this.origin().toCoords();
72
- const destination = this.destination().toCoords();
73
- const otherVect = vector(this.origin(), H);
74
- // The point is before the origin
75
- if (scalar(vect, otherVect) < 0) return new Point(origin);
76
- // The point is after the destination
77
- else if (norm(vect) < norm(otherVect)) return new Point(destination);
78
- // The point is within the segment
79
- else return H;
80
- }
81
- }
@@ -1,3 +0,0 @@
1
- export const error = (msg: string) => {
2
- throw new Error(msg);
3
- };
@@ -1,237 +0,0 @@
1
- import Arc from './elements/Arc';
2
- import Circle from './elements/Circle';
3
- import Ellipse from './elements/Ellipse';
4
- import Line from './elements/Line';
5
- import Plot from './elements/Plot';
6
- import Point from './elements/Point';
7
- import Rectangle from './elements/Rectangle';
8
- import Segment from './elements/Segment';
9
- import { Coordinates, GraphicElement } from '../types';
10
- import {
11
- distance,
12
- isColinear,
13
- isEqual,
14
- norm,
15
- orthogonal,
16
- times,
17
- unitVector,
18
- vector,
19
- rotate,
20
- } from './maths';
21
-
22
- export function intersections(A: GraphicElement, B: GraphicElement): Coordinates[] {
23
- if (A instanceof Point || B instanceof Point) return [];
24
- else if (A instanceof Text || B instanceof Text) return [];
25
- else if (A instanceof Image || B instanceof Image) return [];
26
- // TODO: calculate the coords of the intersection: https://www.emathzone.com/tutorials/geometry/intersection-of-line-and-ellipse.html
27
- else if (A instanceof Line) return intersectionsLine(A, B);
28
- else if (A instanceof Segment) {
29
- return intersectionsLine(A.getLine(), B).filter((P) => A.includes(new Point(P)));
30
- } else if (A instanceof Circle) return intersectionsCircle(A, B);
31
- else if (A instanceof Arc) {
32
- return intersectionsCircle(A.getCircle(), B).filter((P) => A.includes(new Point(P)));
33
- } else if (A instanceof Plot) return intersectionsPlot(A, B);
34
- else if (A instanceof Rectangle) return intersectionsRectangle(A, B);
35
- else if (A instanceof Ellipse) return intersectionsEllipse(A, B);
36
- return A;
37
- }
38
-
39
- export function intersection(A: GraphicElement, B: GraphicElement): Coordinates | undefined {
40
- return intersections(A, B)[0];
41
- }
42
-
43
- function intersectionsLine(A: Line, B: Exclude<GraphicElement, Text | Point>): Coordinates[] {
44
- if (B instanceof Line) return intersectionLine(A, B);
45
- else if (B instanceof Segment) {
46
- return intersectionLine(A, B.getLine()).filter((P) => B.includes(new Point(P)));
47
- } else if (B instanceof Circle) return intersectionCircleLine(B, A);
48
- else if (B instanceof Arc) {
49
- return intersectionsCircle(B.getCircle(), A).filter((P) => B.includes(new Point(P)));
50
- } else if (B instanceof Plot) return intersectionsPlot(B, A);
51
- else if (B instanceof Rectangle) return intersectionsRectangle(B, A);
52
- else if (B instanceof Ellipse) return intersectionsEllipse(B, A);
53
- return B;
54
- }
55
-
56
- function intersectionsEllipse(A: Ellipse, B: Exclude<GraphicElement, Text | Point>): Coordinates[] {
57
- if (B instanceof Line) return intersectionsLineAndEllipse(A, B);
58
- else if (B instanceof Segment) {
59
- return intersectionsEllipse(A, B.getLine()).filter((P) => B.includes(new Point(P)));
60
- }
61
- // TODO:
62
- // else if (B instanceof Circle) return intersectionEllipseCircle(B, A)
63
- else if (B instanceof Circle) return [];
64
- // TODO:
65
- // else if (B instanceof Ellipse) return intersectionEllipseEllipse(B, A)
66
- else if (B instanceof Ellipse) return [];
67
- else if (B instanceof Arc) {
68
- return intersectionsEllipse(A, B.getCircle()).filter((P) => B.includes(new Point(P)));
69
- } else if (B instanceof Plot) return intersectionsPlot(B, A);
70
- else if (B instanceof Rectangle) return intersectionsRectangle(B, A);
71
- return B;
72
- }
73
-
74
- function intersectionsLineAndEllipse(A: Ellipse, B: Line): Coordinates[] {
75
- const center = A.center().toCoords();
76
- const a = A.a();
77
- const b = A.b();
78
- const rotation = A.rotation();
79
- const isLineParallel2YAxis = isEqual(B.dirVect().x, 0);
80
-
81
- // this is a dummy value to represent a point on the line
82
- const p1Y = isLineParallel2YAxis ? 1 : B.y(1);
83
- const p1X = isLineParallel2YAxis ? B.origin().toCoords().x : 1;
84
- const p1 = { x: p1X, y: p1Y };
85
-
86
- // this is a dummy value to represent a point on the line
87
- const p2Y = isLineParallel2YAxis ? 2 : B.y(2);
88
- const p2X = isLineParallel2YAxis ? B.origin().toCoords().x : 2;
89
- const p2 = { x: p2X, y: p2Y };
90
-
91
- const p1Normalized = rotate({ x: p1.x - center.x, y: p1.y - center.y }, -rotation);
92
- const p2Normalized = rotate({ x: p2.x - center.x, y: p2.y - center.y }, -rotation);
93
-
94
- const angular = (p1Normalized.y - p2Normalized.y) / (p1Normalized.x - p2Normalized.x);
95
- const linear = p1Normalized.y - angular * p1Normalized.x;
96
-
97
- const lineY = (x: number) => angular * x + linear;
98
- const denormalize = (coord: Coordinates) => {
99
- const rotated = rotate(coord, rotation);
100
- return {
101
- x: rotated.x + center.x,
102
- y: rotated.y + center.y,
103
- };
104
- };
105
-
106
- // Intersection with vertical line
107
- if (isEqual(p1Normalized.x - p2Normalized.x, 0)) {
108
- const x = p1Normalized.x;
109
- const delta = b ** 2 - (x ** 2 * b ** 2) / a ** 2;
110
- if (delta < 0) return [];
111
- else if (delta === 0) {
112
- return [{ x, y: 0 }].map(denormalize);
113
- } else {
114
- const y1 = Math.sqrt((b ** 2 * (a ** 2 - x ** 2)) / a ** 2);
115
- const y2 = -y1;
116
- return [
117
- { x, y: y1 },
118
- { x, y: y2 },
119
- ].map(denormalize);
120
- }
121
- }
122
-
123
- // Intersection with any line
124
-
125
- // the quadratic equation is:
126
- // alpha * x ** 2 + beta * x + gamma = 0
127
- const alpha = a ** 2 * angular ** 2 + b ** 2;
128
- const beta = 2 * a ** 2 * (angular * linear);
129
- const gamma = a ** 2 * (linear ** 2 - b ** 2);
130
-
131
- const delta = beta ** 2 - 4 * alpha * gamma;
132
- if (delta < 0) return [];
133
- else if (delta === 0) {
134
- const x = -(beta ** 2) / (2 * alpha);
135
- const y = lineY(x);
136
- return [{ x, y }].map(denormalize);
137
- } else {
138
- const x1 = (-beta + Math.sqrt(delta)) / (2 * alpha);
139
- const y1 = lineY(x1);
140
- const x2 = (-beta - Math.sqrt(delta)) / (2 * alpha);
141
- const y2 = lineY(x2);
142
- return [
143
- { x: x1, y: y1 },
144
- { x: x2, y: y2 },
145
- ].map(denormalize);
146
- }
147
- }
148
-
149
- export function intersectionLine(A: Line, B: Line): Coordinates[] {
150
- if (isColinear(A.dirVect(), B.dirVect())) return [];
151
- else {
152
- const { x: ux, y: uy } = A.dirVect();
153
- const { x: vx, y: vy } = B.dirVect();
154
- const { x: xA, y: yA } = A.origin().toCoords();
155
- const { x: xB, y: yB } = B.origin().toCoords();
156
- const x = (ux * (vx * (yA - yB) + vy * xB) - uy * vx * xA) / (ux * vy - uy * vx);
157
- const y = (uy * (vy * (xA - xB) + vx * yB) - ux * vy * yA) / (uy * vx - ux * vy);
158
- return [{ x, y }];
159
- }
160
- }
161
-
162
- function intersectionsPlot(A: Plot, B: GraphicElement): Coordinates[] {
163
- const points = A.getPoints().map((pt) => new Point(pt));
164
- const head = points.pop();
165
- const segments = points.map((pt, i) => new Segment(pt, points[i + 1] || head));
166
- // @ts-ignore
167
- const inters = segments.map((s) => intersections(s, B)).flat();
168
- return inters;
169
- }
170
-
171
- function intersectionsRectangle(A: Rectangle, B: GraphicElement): Coordinates[] {
172
- const P1 = A.getCoords();
173
- const P3 = A.getEnd();
174
- const P2 = { x: P1.x, y: P3.y };
175
- const P4 = { x: P3.x, y: P1.y };
176
- return intersections(new Plot([P1, P2, P3, P4, P1]), B);
177
- }
178
-
179
- export function intersectionCircleLine(A: Circle, B: Line): Coordinates[] {
180
- const rA = A.ray();
181
- const O = A.center();
182
- const H = B.orthoProjection(O);
183
- const OH = distance(O, H);
184
- // The line is tangeant
185
- if (isEqual(OH, rA)) return [H];
186
- // The line is too far from the circle
187
- else if (OH > A.ray()) return [];
188
- // The line cut the circle in 2 points
189
- else {
190
- // Pythagore
191
- const HP = Math.sqrt(rA * rA - OH * OH);
192
- const vect = unitVector(B.dirVect());
193
- return [H.plus(times(vect, HP)), H.plus(times(vect, -HP))];
194
- }
195
- }
196
-
197
- export function intersectionCircle(A: Circle, B: Circle): Coordinates[] {
198
- const oA = A.center();
199
- const oB = B.center();
200
- const rA = A.ray();
201
- const rB = B.ray();
202
- const axis = vector(oA, oB);
203
- const CC = norm(axis);
204
- // The circles are tangeant
205
- if (isEqual(CC, rA + rB)) return [A.orthoProjection(oB).toCoords()];
206
- // The circles are too far from eachother
207
- else if (CC > rA + rB) return [];
208
- // The intersections belong to an orthogonal axis
209
- else {
210
- const ratio = 1 / 2 + (rA * rA - rB * rB) / (CC * CC) / 2;
211
- const H = oA.plus(times(axis, ratio));
212
- return intersectionCircleLine(A, new Line(H, H.plus(orthogonal(axis))));
213
- }
214
- }
215
-
216
- function intersectionsCircle(A: Circle, B: Exclude<GraphicElement, Text | Point>): Coordinates[] {
217
- if (B instanceof Circle) return intersectionCircle(A, B);
218
- else if (B instanceof Line) return intersectionCircleLine(A, B);
219
- else if (B instanceof Segment) {
220
- return intersectionCircleLine(A, B.getLine()).filter((P) => B.includes(new Point(P)));
221
- } else if (B instanceof Arc) {
222
- return intersectionCircle(A, B.getCircle()).filter((P) => B.includes(new Point(P)));
223
- } else if (B instanceof Plot) return intersectionsPlot(B, A);
224
- else if (B instanceof Rectangle) return intersectionsRectangle(B, A);
225
- else if (B instanceof Ellipse) return intersectionsEllipse(B, A);
226
- return B;
227
- }
228
-
229
- export function getIntersections(elements: GraphicElement[]) {
230
- const checked: GraphicElement[] = [];
231
- const inters: Coordinates[] = [];
232
- elements.forEach((elt) => {
233
- checked.forEach((e) => inters.push(...intersections(e, elt)));
234
- checked.push(elt);
235
- });
236
- return inters;
237
- }
@@ -1,96 +0,0 @@
1
- import Point from './elements/Point';
2
- import { Coordinates } from '../types';
3
-
4
- /** This value represents the precision we accept for float values */
5
- export const FLOAT_APPROXIMATION = 0.000001;
6
-
7
- /** Calculates the distance between 2 points */
8
- export const distance = (A: Point, B: Point) => norm(vector(A, B));
9
-
10
- export const distanceCoords = (A: Coordinates, B: Coordinates) => norm(minus(B, A));
11
-
12
- /** Calculates the distance denoted by a vector */
13
- export const norm = (vect: Coordinates) => Math.sqrt(vect.x * vect.x + vect.y * vect.y);
14
-
15
- /** Calculates the orthogonal vector of provided vector */
16
- export const orthogonal = ({ x, y }: Coordinates): Coordinates => ({
17
- x: -y,
18
- y: x,
19
- });
20
-
21
- /** Check if 2 vectors are proportional */
22
- export const isColinear = ({ x: ux, y: uy }: Coordinates, { x: vx, y: vy }: Coordinates): boolean =>
23
- isEqual(ux * vy, uy * vx);
24
-
25
- /** Check if 2 floating values can be considered equals */
26
- export const isEqual = (a: number, b: number): boolean =>
27
- Math.round(Math.abs(a - b) / FLOAT_APPROXIMATION) === 0;
28
-
29
- /** Return true if a is proportional to b: (a = kb), considering float imprecision */
30
- export const isProportional = (a: number, b: number): boolean =>
31
- isEqual((Math.abs(a) + FLOAT_APPROXIMATION / 10) % b, 0);
32
-
33
- /** Calculate the scalar product between 2 vectors */
34
- export const scalar = ({ x: ux, y: uy }: Coordinates, { x: vx, y: vy }: Coordinates): number =>
35
- ux * vx + uy * vy;
36
-
37
- /** Calculate the sum of 2 vectors */
38
- export const plus = (
39
- { x: ux, y: uy }: Coordinates,
40
- { x: vx, y: vy }: Coordinates,
41
- ): Coordinates => ({ x: ux + vx, y: uy + vy });
42
-
43
- /** Calculate the vector multiplied by a scalar */
44
- export const times = ({ x, y }: Coordinates, k = 1): Coordinates => ({
45
- x: k * x,
46
- y: k * y,
47
- });
48
-
49
- /** Calculate the difference of 2 vectors */
50
- export const minus = (u: Coordinates, v: Coordinates): Coordinates => plus(u, times(v, -1));
51
-
52
- /** Returns the vector between 2 points. */
53
- export const vector = (A: Point, B: Point): Coordinates => minus(B.toCoords(), A.toCoords());
54
-
55
- /**
56
- * Returns the angle between the vector and the horizontal axis (Ox).
57
- * The return value is between -PI and PI.
58
- * @returns {number} angle in radian between -Pi and Pi
59
- */
60
- export const orientation = ({ x, y }: Coordinates): number => {
61
- const alpha = Math.acos(x / Math.sqrt(x * x + y * y));
62
- return y > 0 ? alpha : -alpha;
63
- };
64
-
65
- /** Returns the unit vector associated to the provided vector,
66
- * or the Null vector (0, 0) if the vector is null
67
- */
68
- export const unitVector = (u: Coordinates): Coordinates => {
69
- const l = norm(u);
70
- return l > 0 ? times(u, 1 / l) : u;
71
- };
72
-
73
- /** Returns the angle from u to v in radian */
74
- export const angle = (u: Coordinates, v: Coordinates, previousAngle = 0) => {
75
- let sweep = orientation(v) - orientation(u);
76
- // If the angle has the same sign as the arc orientation, we return the angle as is
77
- // Otherwise, we need to correct the value, adding or removing 2π
78
- while (Math.abs(previousAngle - sweep) > Math.PI) {
79
- sweep += Math.sign(previousAngle - sweep) * 2 * Math.PI;
80
- }
81
- return sweep;
82
- };
83
-
84
- /** Returns the angle between the lines (BA) and (BC) in radian
85
- * @returns {number} the angle in radian, between -Pi and Pi
86
- */
87
- export const angleABC = (A: Point, B: Point, C: Point, previousAngle = 0): number =>
88
- angle(vector(B, A), vector(B, C), previousAngle);
89
-
90
- /** Rotate the vector by an angle in radian */
91
- export const rotate = (vect: Coordinates, teta: number): Coordinates => {
92
- const { x, y } = vect;
93
- const nx = x * Math.cos(teta) - y * Math.sin(teta);
94
- const ny = y * Math.cos(teta) + x * Math.sin(teta);
95
- return { x: nx, y: ny };
96
- };
@@ -1,55 +0,0 @@
1
- // tslint:disable radix
2
-
3
- /**
4
- * Converts a number to its string representation in decimal. This function
5
- * differs from simply converting a number to a string with `.toString()`
6
- * because this function's output string will **not** contain exponential
7
- * notation.
8
- *
9
- * Credit: https://stackoverflow.com/a/46545519
10
- */
11
- export const numberToString = (num: number) => {
12
- let numStr = String(num);
13
-
14
- if (Math.abs(num) < 1.0) {
15
- const e = parseInt(num.toString().split('e-')[1]);
16
- if (e) {
17
- const negative = num < 0;
18
- if (negative) num *= -1;
19
- num *= Math.pow(10, e - 1);
20
- numStr = '0.' + Array(e).join('0') + num.toString().substring(2);
21
- if (negative) numStr = '-' + numStr;
22
- }
23
- } else {
24
- let e = parseInt(num.toString().split('+')[1]);
25
- if (e > 20) {
26
- e -= 20;
27
- num /= Math.pow(10, e);
28
- numStr = num.toString() + Array(e + 1).join('0');
29
- }
30
- }
31
-
32
- return numStr;
33
- };
34
-
35
- export const sizeInBytes = (n: number) => Math.ceil(n.toString(2).length / 8);
36
-
37
- /**
38
- * Converts a number into its constituent bytes and returns them as
39
- * a number[].
40
- *
41
- * Returns most significant byte as first element in array. It may be necessary
42
- * to call .reverse() to get the bits in the desired order.
43
- *
44
- * Example:
45
- * bytesFor(0x02A41E) => [ 0b10, 0b10100100, 0b11110 ]
46
- *
47
- * Credit for algorithm: https://stackoverflow.com/a/1936865
48
- */
49
- export const bytesFor = (n: number) => {
50
- const bytes = new Uint8Array(sizeInBytes(n));
51
- for (let i = 1; i <= bytes.length; i++) {
52
- bytes[i - 1] = n >> ((bytes.length - i) * 8);
53
- }
54
- return bytes;
55
- };
@@ -1,13 +0,0 @@
1
- import { FontNames } from '@pdf-lib/standard-fonts';
2
-
3
- export const values = (obj: any) => Object.keys(obj).map((k) => obj[k]);
4
-
5
- export const StandardFontValues = values(FontNames);
6
-
7
- export const isStandardFont = (input: any): input is FontNames =>
8
- StandardFontValues.includes(input);
9
-
10
- export const rectanglesAreEqual = (
11
- a: { x: number; y: number; width: number; height: number },
12
- b: { x: number; y: number; width: number; height: number },
13
- ) => a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
@@ -1,69 +0,0 @@
1
- import { toCharCode } from './strings';
2
-
3
- // Mapping from PDFDocEncoding to Unicode code point
4
- const pdfDocEncodingToUnicode = new Uint16Array(256);
5
-
6
- // Initialize the code points which are the same
7
- for (let idx = 0; idx < 256; idx++) {
8
- pdfDocEncodingToUnicode[idx] = idx;
9
- }
10
-
11
- // Set differences (see "Table D.2 – PDFDocEncoding Character Set" of the PDF spec)
12
- pdfDocEncodingToUnicode[0x16] = toCharCode('\u0017'); // SYNCRONOUS IDLE
13
- pdfDocEncodingToUnicode[0x18] = toCharCode('\u02D8'); // BREVE
14
- pdfDocEncodingToUnicode[0x19] = toCharCode('\u02C7'); // CARON
15
- pdfDocEncodingToUnicode[0x1a] = toCharCode('\u02C6'); // MODIFIER LETTER CIRCUMFLEX ACCENT
16
- pdfDocEncodingToUnicode[0x1b] = toCharCode('\u02D9'); // DOT ABOVE
17
- pdfDocEncodingToUnicode[0x1c] = toCharCode('\u02DD'); // DOUBLE ACUTE ACCENT
18
- pdfDocEncodingToUnicode[0x1d] = toCharCode('\u02DB'); // OGONEK
19
- pdfDocEncodingToUnicode[0x1e] = toCharCode('\u02DA'); // RING ABOVE
20
- pdfDocEncodingToUnicode[0x1f] = toCharCode('\u02DC'); // SMALL TILDE
21
- pdfDocEncodingToUnicode[0x7f] = toCharCode('\uFFFD'); // REPLACEMENT CHARACTER (box with questionmark)
22
- pdfDocEncodingToUnicode[0x80] = toCharCode('\u2022'); // BULLET
23
- pdfDocEncodingToUnicode[0x81] = toCharCode('\u2020'); // DAGGER
24
- pdfDocEncodingToUnicode[0x82] = toCharCode('\u2021'); // DOUBLE DAGGER
25
- pdfDocEncodingToUnicode[0x83] = toCharCode('\u2026'); // HORIZONTAL ELLIPSIS
26
- pdfDocEncodingToUnicode[0x84] = toCharCode('\u2014'); // EM DASH
27
- pdfDocEncodingToUnicode[0x85] = toCharCode('\u2013'); // EN DASH
28
- pdfDocEncodingToUnicode[0x86] = toCharCode('\u0192'); // LATIN SMALL LETTER SCRIPT F
29
- pdfDocEncodingToUnicode[0x87] = toCharCode('\u2044'); // FRACTION SLASH (solidus)
30
- pdfDocEncodingToUnicode[0x88] = toCharCode('\u2039'); // SINGLE LEFT-POINTING ANGLE QUOTATION MARK
31
- pdfDocEncodingToUnicode[0x89] = toCharCode('\u203A'); // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
32
- pdfDocEncodingToUnicode[0x8a] = toCharCode('\u2212'); // MINUS SIGN
33
- pdfDocEncodingToUnicode[0x8b] = toCharCode('\u2030'); // PER MILLE SIGN
34
- pdfDocEncodingToUnicode[0x8c] = toCharCode('\u201E'); // DOUBLE LOW-9 QUOTATION MARK (quotedblbase)
35
- pdfDocEncodingToUnicode[0x8d] = toCharCode('\u201C'); // LEFT DOUBLE QUOTATION MARK (quotedblleft)
36
- pdfDocEncodingToUnicode[0x8e] = toCharCode('\u201D'); // RIGHT DOUBLE QUOTATION MARK (quotedblright)
37
- pdfDocEncodingToUnicode[0x8f] = toCharCode('\u2018'); // LEFT SINGLE QUOTATION MARK (quoteleft)
38
- pdfDocEncodingToUnicode[0x90] = toCharCode('\u2019'); // RIGHT SINGLE QUOTATION MARK (quoteright)
39
- pdfDocEncodingToUnicode[0x91] = toCharCode('\u201A'); // SINGLE LOW-9 QUOTATION MARK (quotesinglbase)
40
- pdfDocEncodingToUnicode[0x92] = toCharCode('\u2122'); // TRADE MARK SIGN
41
- pdfDocEncodingToUnicode[0x93] = toCharCode('\uFB01'); // LATIN SMALL LIGATURE FI
42
- pdfDocEncodingToUnicode[0x94] = toCharCode('\uFB02'); // LATIN SMALL LIGATURE FL
43
- pdfDocEncodingToUnicode[0x95] = toCharCode('\u0141'); // LATIN CAPITAL LETTER L WITH STROKE
44
- pdfDocEncodingToUnicode[0x96] = toCharCode('\u0152'); // LATIN CAPITAL LIGATURE OE
45
- pdfDocEncodingToUnicode[0x97] = toCharCode('\u0160'); // LATIN CAPITAL LETTER S WITH CARON
46
- pdfDocEncodingToUnicode[0x98] = toCharCode('\u0178'); // LATIN CAPITAL LETTER Y WITH DIAERESIS
47
- pdfDocEncodingToUnicode[0x99] = toCharCode('\u017D'); // LATIN CAPITAL LETTER Z WITH CARON
48
- pdfDocEncodingToUnicode[0x9a] = toCharCode('\u0131'); // LATIN SMALL LETTER DOTLESS I
49
- pdfDocEncodingToUnicode[0x9b] = toCharCode('\u0142'); // LATIN SMALL LETTER L WITH STROKE
50
- pdfDocEncodingToUnicode[0x9c] = toCharCode('\u0153'); // LATIN SMALL LIGATURE OE
51
- pdfDocEncodingToUnicode[0x9d] = toCharCode('\u0161'); // LATIN SMALL LETTER S WITH CARON
52
- pdfDocEncodingToUnicode[0x9e] = toCharCode('\u017E'); // LATIN SMALL LETTER Z WITH CARON
53
- pdfDocEncodingToUnicode[0x9f] = toCharCode('\uFFFD'); // REPLACEMENT CHARACTER (box with questionmark)
54
- pdfDocEncodingToUnicode[0xa0] = toCharCode('\u20AC'); // EURO SIGN
55
- pdfDocEncodingToUnicode[0xad] = toCharCode('\uFFFD'); // REPLACEMENT CHARACTER (box with questionmark)
56
-
57
- /**
58
- * Decode a byte array into a string using PDFDocEncoding.
59
- *
60
- * @param bytes a byte array (decimal representation) containing a string
61
- * encoded with PDFDocEncoding.
62
- */
63
- export const pdfDocEncodingDecode = (bytes: Uint8Array): string => {
64
- const codePoints = Array<number>(bytes.length);
65
- for (let idx = 0, len = bytes.length; idx < len; idx++) {
66
- codePoints[idx] = pdfDocEncodingToUnicode[bytes[idx]];
67
- }
68
- return String.fromCodePoint(...codePoints);
69
- };