@pdfme/pdf-lib 6.0.3 → 6.0.4-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.
- package/{src/api/Embeddable.ts → dist/api/Embeddable.d.ts} +1 -1
- package/dist/api/PDFDocument.d.ts +778 -0
- package/dist/api/PDFDocumentOptions.d.ts +38 -0
- package/dist/api/PDFEmbeddedFile.d.ts +38 -0
- package/dist/api/PDFEmbeddedPage.d.ts +73 -0
- package/dist/api/PDFFont.d.ts +94 -0
- package/dist/api/PDFImage.d.ts +95 -0
- package/dist/api/PDFJavaScript.d.ts +38 -0
- package/dist/api/PDFPage.d.ts +910 -0
- package/dist/api/PDFPageOptions.d.ts +172 -0
- package/dist/api/StandardFonts.d.ts +16 -0
- package/dist/api/colors.d.ts +34 -0
- package/dist/api/errors.d.ts +42 -0
- package/dist/api/form/PDFButton.d.ts +137 -0
- package/dist/api/form/PDFCheckBox.d.ts +142 -0
- package/dist/api/form/PDFDropdown.d.ts +402 -0
- package/dist/api/form/PDFField.d.ts +203 -0
- package/dist/api/form/PDFForm.d.ts +411 -0
- package/dist/api/form/PDFOptionList.d.ts +335 -0
- package/dist/api/form/PDFRadioGroup.d.ts +252 -0
- package/dist/api/form/PDFSignature.d.ts +29 -0
- package/dist/api/form/PDFTextField.d.ts +537 -0
- package/dist/api/form/appearances.d.ts +41 -0
- package/dist/api/image/alignment.d.ts +5 -0
- package/dist/api/objects.d.ts +4 -0
- package/dist/api/operations.d.ts +226 -0
- package/dist/api/operators.d.ts +90 -0
- package/dist/api/rotations.d.ts +38 -0
- package/dist/api/sizes.d.ts +52 -0
- package/dist/api/svg.d.ts +70 -0
- package/dist/api/svgPath.d.ts +2 -0
- package/dist/api/text/alignment.d.ts +5 -0
- package/dist/api/text/layout.d.ts +54 -0
- package/dist/core/PDFContext.d.ts +84 -0
- package/dist/core/PDFObjectCopier.d.ts +37 -0
- package/dist/core/acroform/PDFAcroButton.d.ts +21 -0
- package/dist/core/acroform/PDFAcroCheckBox.d.ts +13 -0
- package/dist/core/acroform/PDFAcroChoice.d.ts +20 -0
- package/dist/core/acroform/PDFAcroComboBox.d.ts +9 -0
- package/dist/core/acroform/PDFAcroField.d.ts +36 -0
- package/dist/core/acroform/PDFAcroForm.d.ts +20 -0
- package/dist/core/acroform/PDFAcroListBox.d.ts +9 -0
- package/dist/core/acroform/PDFAcroNonTerminal.d.ts +13 -0
- package/dist/core/acroform/PDFAcroPushButton.d.ts +9 -0
- package/dist/core/acroform/PDFAcroRadioButton.d.ts +13 -0
- package/{src/core/acroform/PDFAcroSignature.ts → dist/core/acroform/PDFAcroSignature.d.ts} +2 -4
- package/dist/core/acroform/PDFAcroTerminal.d.ts +16 -0
- package/dist/core/acroform/PDFAcroText.d.ts +22 -0
- package/dist/core/acroform/flags.d.ts +141 -0
- package/dist/core/acroform/utils.d.ts +6 -0
- package/dist/core/annotation/AppearanceCharacteristics.d.ts +33 -0
- package/dist/core/annotation/BorderStyle.d.ts +11 -0
- package/dist/core/annotation/PDFAnnotation.d.ts +51 -0
- package/dist/core/annotation/PDFWidgetAnnotation.d.ts +26 -0
- package/dist/core/annotation/flags.d.ts +79 -0
- package/dist/core/crypto.d.ts +95 -0
- package/dist/core/document/PDFCrossRefSection.d.ts +27 -0
- package/dist/core/document/PDFHeader.d.ts +10 -0
- package/dist/core/document/PDFTrailer.d.ts +9 -0
- package/dist/core/document/PDFTrailerDict.d.ts +10 -0
- package/dist/core/embedders/CMap.d.ts +3 -0
- package/dist/core/embedders/CustomFontEmbedder.d.ts +44 -0
- package/dist/core/embedders/CustomFontSubsetEmbedder.d.ts +20 -0
- package/dist/core/embedders/FileEmbedder.d.ts +33 -0
- package/dist/core/embedders/FontFlags.d.ts +13 -0
- package/dist/core/embedders/JavaScriptEmbedder.d.ts +10 -0
- package/dist/core/embedders/JpegEmbedder.d.ts +23 -0
- package/dist/core/embedders/PDFPageEmbedder.d.ts +37 -0
- package/dist/core/embedders/PngEmbedder.d.ts +19 -0
- package/dist/core/embedders/StandardFontEmbedder.d.ts +36 -0
- package/dist/core/errors.d.ts +94 -0
- package/{src/core/index.ts → dist/core/index.d.ts} +1 -17
- package/dist/core/interactive/ViewerPreferences.d.ts +347 -0
- package/dist/core/objects/PDFArray.d.ts +63 -0
- package/dist/core/objects/PDFBool.d.ts +13 -0
- package/dist/core/objects/PDFDict.d.ts +62 -0
- package/dist/core/objects/PDFHexString.d.ts +16 -0
- package/dist/core/objects/PDFInvalidObject.d.ts +11 -0
- package/dist/core/objects/PDFName.d.ts +41 -0
- package/dist/core/objects/PDFNull.d.ts +10 -0
- package/dist/core/objects/PDFNumber.d.ts +15 -0
- package/dist/core/objects/PDFObject.d.ts +8 -0
- package/dist/core/objects/PDFRawStream.d.ts +16 -0
- package/dist/core/objects/PDFRef.d.ts +13 -0
- package/dist/core/objects/PDFStream.d.ts +16 -0
- package/dist/core/objects/PDFString.d.ts +16 -0
- package/dist/core/operators/PDFOperator.d.ts +19 -0
- package/dist/core/operators/PDFOperatorNames.d.ts +76 -0
- package/dist/core/parser/BaseParser.d.ts +14 -0
- package/dist/core/parser/ByteStream.d.ts +26 -0
- package/dist/core/parser/PDFObjectParser.d.ts +31 -0
- package/dist/core/parser/PDFObjectStreamParser.d.ts +13 -0
- package/dist/core/parser/PDFParser.d.ts +46 -0
- package/dist/core/parser/PDFXRefStreamParser.d.ts +21 -0
- package/dist/core/streams/Ascii85Stream.d.ts +9 -0
- package/dist/core/streams/AsciiHexStream.d.ts +9 -0
- package/dist/core/streams/DecodeStream.d.ts +26 -0
- package/dist/core/streams/DecryptStream.d.ts +12 -0
- package/dist/core/streams/FlateStream.d.ts +13 -0
- package/dist/core/streams/LZWStream.d.ts +12 -0
- package/dist/core/streams/RunLengthStream.d.ts +8 -0
- package/dist/core/streams/Stream.d.ts +34 -0
- package/dist/core/streams/decode.d.ts +3 -0
- package/dist/core/structures/PDFCatalog.d.ts +27 -0
- package/dist/core/structures/PDFContentStream.d.ts +15 -0
- package/dist/core/structures/PDFCrossRefStream.d.ts +53 -0
- package/dist/core/structures/PDFFlateStream.d.ts +13 -0
- package/dist/core/structures/PDFObjectStream.d.ts +20 -0
- package/dist/core/structures/PDFPageLeaf.d.ts +54 -0
- package/dist/core/structures/PDFPageTree.d.ts +41 -0
- package/dist/core/syntax/CharCodes.d.ts +61 -0
- package/dist/core/syntax/Delimiters.d.ts +1 -0
- package/dist/core/syntax/Irregular.d.ts +1 -0
- package/dist/core/syntax/Keywords.d.ts +22 -0
- package/dist/core/syntax/Numeric.d.ts +3 -0
- package/dist/core/syntax/Whitespace.d.ts +1 -0
- package/dist/core/writers/PDFStreamWriter.d.ts +19 -0
- package/dist/core/writers/PDFWriter.d.ts +29 -0
- package/dist/index.js +19124 -0
- package/dist/index.js.map +1 -0
- package/dist/types/fontkit.d.ts +597 -0
- package/{src/types/index.ts → dist/types/index.d.ts} +8 -13
- package/{src/types/matrix.ts → dist/types/matrix.d.ts} +1 -2
- package/dist/utils/Cache.d.ts +10 -0
- package/dist/utils/arrays.d.ts +16 -0
- package/dist/utils/async.d.ts +5 -0
- package/dist/utils/base64.d.ts +10 -0
- package/dist/utils/elements/Arc.d.ts +22 -0
- package/dist/utils/elements/Circle.d.ts +14 -0
- package/dist/utils/elements/Ellipse.d.ts +20 -0
- package/dist/utils/elements/GraphElement.d.ts +6 -0
- package/dist/utils/elements/Line.d.ts +23 -0
- package/dist/utils/elements/Plot.d.ts +11 -0
- package/dist/utils/elements/Point.d.ts +18 -0
- package/dist/utils/elements/Rectangle.d.ts +21 -0
- package/dist/utils/elements/Segment.d.ts +19 -0
- package/dist/utils/errors.d.ts +1 -0
- package/dist/utils/intersections.d.ts +9 -0
- package/dist/utils/maths.d.ts +45 -0
- package/dist/utils/numbers.d.ts +23 -0
- package/dist/utils/objects.d.ts +15 -0
- package/dist/utils/pdfDocEncoding.d.ts +7 -0
- package/dist/utils/png.d.ts +17 -0
- package/dist/utils/rng.d.ts +13 -0
- package/dist/utils/strings.d.ts +25 -0
- package/{src/utils/unicode.ts → dist/utils/unicode.d.ts} +8 -195
- package/dist/utils/validators.d.ts +26 -0
- package/package.json +6 -1
- package/__tests__/api/PDFDocument.spec.ts +0 -576
- package/__tests__/api/PDFImage.spec.ts +0 -60
- package/__tests__/api/PDFPage.spec.ts +0 -151
- package/__tests__/api/form/PDFCheckBox.spec.ts +0 -71
- package/__tests__/api/form/PDFDropdown.spec.ts +0 -118
- package/__tests__/api/form/PDFForm.spec.ts +0 -370
- package/__tests__/api/form/PDFOptionList.spec.ts +0 -104
- package/__tests__/api/form/PDFRadioGroup.spec.ts +0 -183
- package/__tests__/api/form/PDFTextField.spec.ts +0 -148
- package/__tests__/api/svgPath.spec.ts +0 -153
- package/__tests__/api/text/layout.spec.ts +0 -166
- package/__tests__/core/PDFContext.spec.ts +0 -194
- package/__tests__/core/PDFObjectCopier.spec.ts +0 -421
- package/__tests__/core/acroform/PDFAcroField.spec.ts +0 -98
- package/__tests__/core/acroform/PDFAcroTerminal.spec.ts +0 -39
- package/__tests__/core/annotation/PDFWidgetAnnotation.spec.ts +0 -40
- package/__tests__/core/document/PDFCrossRefSection.spec.ts +0 -88
- package/__tests__/core/document/PDFHeader.spec.ts +0 -22
- package/__tests__/core/document/PDFTrailer.spec.ts +0 -28
- package/__tests__/core/document/PDFTrailerDict.spec.ts +0 -24
- package/__tests__/core/embedders/CMap.spec.ts +0 -47
- package/__tests__/core/embedders/CustomFontEmbedder.spec.ts +0 -96
- package/__tests__/core/embedders/CustomFontSubsetEmbedder.spec.ts +0 -62
- package/__tests__/core/embedders/FileEmbedder.spec.ts +0 -54
- package/__tests__/core/embedders/JpegEmbedder.spec.ts +0 -67
- package/__tests__/core/embedders/PDFPageEmbedder.spec.ts +0 -65
- package/__tests__/core/embedders/PngEmbedder.spec.ts +0 -87
- package/__tests__/core/embedders/StandardFontEmbedder.spec.ts +0 -79
- package/__tests__/core/embedders/data/SourceHanSerifJP-Regular.otf.cmap +0 -16096
- package/__tests__/core/embedders/data/Ubuntu-R.ttf.cmap +0 -1211
- package/__tests__/core/objects/PDFArray.spec.ts +0 -134
- package/__tests__/core/objects/PDFBool.spec.ts +0 -42
- package/__tests__/core/objects/PDFDict.spec.ts +0 -195
- package/__tests__/core/objects/PDFHexString.spec.ts +0 -168
- package/__tests__/core/objects/PDFInvalidObject.spec.ts +0 -32
- package/__tests__/core/objects/PDFName.spec.ts +0 -122
- package/__tests__/core/objects/PDFNull.spec.ts +0 -30
- package/__tests__/core/objects/PDFNumber.spec.ts +0 -50
- package/__tests__/core/objects/PDFObject.spec.ts +0 -29
- package/__tests__/core/objects/PDFRawStream.spec.ts +0 -45
- package/__tests__/core/objects/PDFRef.spec.ts +0 -60
- package/__tests__/core/objects/PDFString.spec.ts +0 -237
- package/__tests__/core/operators/PDFOperator.spec.ts +0 -77
- package/__tests__/core/parser/PDFObjectParser.spec.ts +0 -730
- package/__tests__/core/parser/PDFObjectStreamParser.spec.ts +0 -158
- package/__tests__/core/parser/PDFParser.spec.ts +0 -398
- package/__tests__/core/parser/PDFXRefStreamParser.spec.ts +0 -187
- package/__tests__/core/parser/data/object-stream-invalid +0 -2
- package/__tests__/core/parser/data/object-stream1 +0 -16
- package/__tests__/core/parser/data/object-stream2 +0 -10
- package/__tests__/core/parser/data/object-stream3 +0 -0
- package/__tests__/core/parser/data/object-stream4 +0 -0
- package/__tests__/core/parser/data/xref-stream1 +0 -0
- package/__tests__/core/parser/data/xref-stream2 +0 -0
- package/__tests__/core/parser/data/xref-stream3 +0 -0
- package/__tests__/core/parser/data/xref-stream4 +0 -0
- package/__tests__/core/streams/Ascii85Stream.spec.ts +0 -20
- package/__tests__/core/streams/AsciiHexStream.spec.ts +0 -20
- package/__tests__/core/streams/FlateStream.spec.ts +0 -20
- package/__tests__/core/streams/LZWStream.spec.ts +0 -20
- package/__tests__/core/streams/RunLengthStream.spec.ts +0 -20
- package/__tests__/core/streams/Stream.spec.ts +0 -128
- package/__tests__/core/streams/data/ascii85/1.decoded +0 -0
- package/__tests__/core/streams/data/ascii85/1.encoded +0 -43
- package/__tests__/core/streams/data/asciihex/1.decoded +0 -1
- package/__tests__/core/streams/data/asciihex/1.encoded +0 -1
- package/__tests__/core/streams/data/asciihex/2.decoded +0 -7
- package/__tests__/core/streams/data/asciihex/2.encoded +0 -1
- package/__tests__/core/streams/data/flate/1.corrupt.encoded +0 -1
- package/__tests__/core/streams/data/flate/1.decoded +0 -0
- package/__tests__/core/streams/data/flate/1.encoded +0 -2
- package/__tests__/core/streams/data/flate/2.decoded +0 -33
- package/__tests__/core/streams/data/flate/2.encoded +0 -0
- package/__tests__/core/streams/data/flate/3.decoded +0 -15
- package/__tests__/core/streams/data/flate/3.encoded +0 -0
- package/__tests__/core/streams/data/flate/4.decoded +0 -16
- package/__tests__/core/streams/data/flate/4.encoded +0 -0
- package/__tests__/core/streams/data/flate/5.decoded +0 -0
- package/__tests__/core/streams/data/flate/5.encoded +0 -0
- package/__tests__/core/streams/data/flate/6.decoded +0 -17
- package/__tests__/core/streams/data/flate/6.encoded +0 -0
- package/__tests__/core/streams/data/flate/7.decoded +0 -20
- package/__tests__/core/streams/data/flate/7.encoded +0 -1
- package/__tests__/core/streams/data/lzw/1.decoded +0 -0
- package/__tests__/core/streams/data/lzw/1.encoded +0 -0
- package/__tests__/core/streams/data/lzw/2.decoded +0 -0
- package/__tests__/core/streams/data/lzw/2.encoded +0 -0
- package/__tests__/core/streams/data/lzw/3.decoded +0 -14
- package/__tests__/core/streams/data/lzw/3.encoded +0 -2
- package/__tests__/core/streams/data/lzw/4.decoded +0 -14
- package/__tests__/core/streams/data/lzw/4.encoded +0 -2
- package/__tests__/core/streams/data/runlength/1.decoded +0 -1
- package/__tests__/core/streams/data/runlength/1.encoded +0 -1
- package/__tests__/core/streams/data/runlength/2.decoded +0 -1
- package/__tests__/core/streams/data/runlength/2.encoded +0 -1
- package/__tests__/core/streams/data/runlength/3.decoded +0 -0
- package/__tests__/core/streams/data/runlength/3.encoded +0 -0
- package/__tests__/core/streams/data/runlength/4.decoded +0 -1
- package/__tests__/core/streams/data/runlength/4.encoded +0 -1
- package/__tests__/core/streams/data/runlength/5.decoded +0 -1
- package/__tests__/core/streams/data/runlength/5.encoded +0 -1
- package/__tests__/core/streams/data/runlength/empty.encoded +0 -1
- package/__tests__/core/structures/PDFCatalog.spec.ts +0 -108
- package/__tests__/core/structures/PDFContentStream.spec.ts +0 -117
- package/__tests__/core/structures/PDFCrossRefStream.spec.ts +0 -145
- package/__tests__/core/structures/PDFObjectStream.spec.ts +0 -138
- package/__tests__/core/structures/PDFPageLeaf.spec.ts +0 -355
- package/__tests__/core/structures/PDFPageTree.spec.ts +0 -592
- package/__tests__/core/writers/PDFStreamWriter.spec.ts +0 -71
- package/__tests__/core/writers/PDFWriter.spec.ts +0 -144
- package/__tests__/core/writers/data/stream-writer-1.pdf +0 -0
- package/__tests__/index.test.ts +0 -12
- package/__tests__/utils/base64.spec.ts +0 -61
- package/__tests__/utils/data/simple.pdf +0 -201
- package/__tests__/utils/data/simple.pdf.base64 +0 -1
- package/__tests__/utils/pdfDocEncoding.spec.ts +0 -82
- package/__tests__/utils/png.spec.ts +0 -53
- package/__tests__/utils/rng.spec.ts +0 -14
- package/__tests__/utils/strings.spec.ts +0 -98
- package/__tests__/utils/unicode.spec.ts +0 -337
- package/assets/fonts/source_hans_jp/SourceHanSerifJP-Regular.otf +0 -0
- package/assets/fonts/ubuntu/Ubuntu-B.ttf +0 -0
- package/assets/fonts/ubuntu/Ubuntu-R.ttf +0 -0
- package/assets/images/cat_riding_unicorn.jpg +0 -0
- package/assets/images/cmyk_colorspace.jpg +0 -0
- package/assets/images/greyscale_bird.png +0 -0
- package/assets/images/minions_banana_alpha.png +0 -0
- package/assets/images/minions_banana_no_alpha.png +0 -0
- package/assets/images/minions_laughing.jpg +0 -0
- package/assets/pdfs/bixby_guide.pdf +0 -0
- package/assets/pdfs/encrypted_new.pdf +0 -0
- package/assets/pdfs/encrypted_old.pdf +0 -0
- package/assets/pdfs/fancy_fields.pdf +0 -0
- package/assets/pdfs/giraffe.pdf +0 -0
- package/assets/pdfs/invalid_root_ref.pdf +0 -0
- package/assets/pdfs/just_metadata.pdf +0 -49
- package/assets/pdfs/missing_endobj_keyword.pdf +0 -70
- package/assets/pdfs/missing_xref_trailer_dict.pdf +0 -141
- package/assets/pdfs/normal.pdf +0 -0
- package/assets/pdfs/pdf20examples/PDF 2.0 with offset start.pdf +0 -179
- package/assets/pdfs/stuff_following_header.pdf +0 -0
- package/assets/pdfs/us_constitution.pdf +0 -0
- package/assets/pdfs/with_comments.pdf +0 -0
- package/assets/pdfs/with_invalid_objects.pdf +0 -53
- package/assets/pdfs/with_invalid_stream_EOL.pdf +0 -0
- package/assets/pdfs/with_null_parent_entry.pdf +0 -0
- package/assets/pdfs/with_signature.pdf +0 -0
- package/assets/pdfs/with_update_sections.pdf +0 -0
- package/assets/pdfs/with_viewer_prefs.pdf +0 -0
- package/assets/pdfs/with_xfa_fields.pdf +0 -0
- package/src/api/PDFDocument.ts +0 -1389
- package/src/api/PDFDocumentOptions.ts +0 -45
- package/src/api/PDFEmbeddedFile.ts +0 -87
- package/src/api/PDFEmbeddedPage.ts +0 -100
- package/src/api/PDFFont.ts +0 -149
- package/src/api/PDFImage.ts +0 -143
- package/src/api/PDFJavaScript.ts +0 -75
- package/src/api/PDFPage.ts +0 -1604
- package/src/api/PDFPageOptions.ts +0 -175
- package/src/api/StandardFonts.ts +0 -16
- package/src/api/colors.ts +0 -109
- package/src/api/errors.ts +0 -110
- package/src/api/form/PDFButton.ts +0 -242
- package/src/api/form/PDFCheckBox.ts +0 -247
- package/src/api/form/PDFDropdown.ts +0 -637
- package/src/api/form/PDFField.ts +0 -491
- package/src/api/form/PDFForm.ts +0 -842
- package/src/api/form/PDFOptionList.ts +0 -555
- package/src/api/form/PDFRadioGroup.ts +0 -455
- package/src/api/form/PDFSignature.ts +0 -44
- package/src/api/form/PDFTextField.ts +0 -811
- package/src/api/form/appearances.ts +0 -655
- package/src/api/image/alignment.ts +0 -5
- package/src/api/objects.ts +0 -10
- package/src/api/operations.ts +0 -873
- package/src/api/operators.ts +0 -335
- package/src/api/rotations.ts +0 -84
- package/src/api/sizes.ts +0 -52
- package/src/api/svg.ts +0 -888
- package/src/api/svgPath.ts +0 -460
- package/src/api/text/alignment.ts +0 -5
- package/src/api/text/layout.ts +0 -328
- package/src/core/PDFContext.ts +0 -274
- package/src/core/PDFObjectCopier.ts +0 -142
- package/src/core/acroform/PDFAcroButton.ts +0 -104
- package/src/core/acroform/PDFAcroCheckBox.ts +0 -48
- package/src/core/acroform/PDFAcroChoice.ts +0 -143
- package/src/core/acroform/PDFAcroComboBox.ts +0 -21
- package/src/core/acroform/PDFAcroField.ts +0 -168
- package/src/core/acroform/PDFAcroForm.ts +0 -96
- package/src/core/acroform/PDFAcroListBox.ts +0 -19
- package/src/core/acroform/PDFAcroNonTerminal.ts +0 -33
- package/src/core/acroform/PDFAcroPushButton.ts +0 -21
- package/src/core/acroform/PDFAcroRadioButton.ts +0 -57
- package/src/core/acroform/PDFAcroTerminal.ts +0 -70
- package/src/core/acroform/PDFAcroText.ts +0 -76
- package/src/core/acroform/flags.ts +0 -162
- package/src/core/acroform/utils.ts +0 -129
- package/src/core/annotation/AppearanceCharacteristics.ts +0 -133
- package/src/core/annotation/BorderStyle.ts +0 -31
- package/src/core/annotation/PDFAnnotation.ts +0 -148
- package/src/core/annotation/PDFWidgetAnnotation.ts +0 -111
- package/src/core/annotation/flags.ts +0 -90
- package/src/core/crypto.ts +0 -1844
- package/src/core/document/PDFCrossRefSection.ts +0 -161
- package/src/core/document/PDFHeader.ts +0 -48
- package/src/core/document/PDFTrailer.ts +0 -48
- package/src/core/document/PDFTrailerDict.ts +0 -39
- package/src/core/embedders/CMap.ts +0 -65
- package/src/core/embedders/CustomFontEmbedder.ts +0 -237
- package/src/core/embedders/CustomFontSubsetEmbedder.ts +0 -89
- package/src/core/embedders/FileEmbedder.ts +0 -77
- package/src/core/embedders/FontFlags.ts +0 -45
- package/src/core/embedders/JavaScriptEmbedder.ts +0 -34
- package/src/core/embedders/JpegEmbedder.ts +0 -118
- package/src/core/embedders/PDFPageEmbedder.ts +0 -139
- package/src/core/embedders/PngEmbedder.ts +0 -69
- package/src/core/embedders/StandardFontEmbedder.ts +0 -121
- package/src/core/errors.ts +0 -226
- package/src/core/interactive/ViewerPreferences.ts +0 -565
- package/src/core/objects/PDFArray.ts +0 -179
- package/src/core/objects/PDFBool.ts +0 -53
- package/src/core/objects/PDFDict.ts +0 -220
- package/src/core/objects/PDFHexString.ts +0 -94
- package/src/core/objects/PDFInvalidObject.ts +0 -34
- package/src/core/objects/PDFName.ts +0 -152
- package/src/core/objects/PDFNull.ts +0 -30
- package/src/core/objects/PDFNumber.ts +0 -44
- package/src/core/objects/PDFObject.ts +0 -22
- package/src/core/objects/PDFRawStream.ts +0 -41
- package/src/core/objects/PDFRef.ts +0 -51
- package/src/core/objects/PDFStream.ts +0 -87
- package/src/core/objects/PDFString.ts +0 -118
- package/src/core/operators/PDFOperator.ts +0 -72
- package/src/core/operators/PDFOperatorNames.ts +0 -92
- package/src/core/parser/BaseParser.ts +0 -119
- package/src/core/parser/ByteStream.ts +0 -76
- package/src/core/parser/PDFObjectParser.ts +0 -302
- package/src/core/parser/PDFObjectStreamParser.ts +0 -65
- package/src/core/parser/PDFParser.ts +0 -363
- package/src/core/parser/PDFXRefStreamParser.ts +0 -129
- package/src/core/streams/Ascii85Stream.ts +0 -97
- package/src/core/streams/AsciiHexStream.ts +0 -77
- package/src/core/streams/DecodeStream.ts +0 -188
- package/src/core/streams/DecryptStream.ts +0 -49
- package/src/core/streams/FlateStream.ts +0 -397
- package/src/core/streams/LZWStream.ts +0 -157
- package/src/core/streams/RunLengthStream.ts +0 -55
- package/src/core/streams/Stream.ts +0 -126
- package/src/core/streams/decode.ts +0 -70
- package/src/core/structures/PDFCatalog.ts +0 -81
- package/src/core/structures/PDFContentStream.ts +0 -58
- package/src/core/structures/PDFCrossRefStream.ts +0 -238
- package/src/core/structures/PDFFlateStream.ts +0 -40
- package/src/core/structures/PDFObjectStream.ts +0 -91
- package/src/core/structures/PDFPageLeaf.ts +0 -244
- package/src/core/structures/PDFPageTree.ts +0 -192
- package/src/core/syntax/CharCodes.ts +0 -62
- package/src/core/syntax/Delimiters.ts +0 -14
- package/src/core/syntax/Irregular.ts +0 -10
- package/src/core/syntax/Keywords.ts +0 -57
- package/src/core/syntax/Numeric.ts +0 -26
- package/src/core/syntax/Whitespace.ts +0 -10
- package/src/core/writers/PDFStreamWriter.ts +0 -114
- package/src/core/writers/PDFWriter.ts +0 -146
- package/src/types/fontkit.ts +0 -643
- package/src/utils/Cache.ts +0 -26
- package/src/utils/arrays.ts +0 -153
- package/src/utils/async.ts +0 -8
- package/src/utils/base64.ts +0 -98
- package/src/utils/elements/Arc.ts +0 -97
- package/src/utils/elements/Circle.ts +0 -47
- package/src/utils/elements/Ellipse.ts +0 -117
- package/src/utils/elements/GraphElement.ts +0 -14
- package/src/utils/elements/Line.ts +0 -83
- package/src/utils/elements/Plot.ts +0 -50
- package/src/utils/elements/Point.ts +0 -37
- package/src/utils/elements/Rectangle.ts +0 -65
- package/src/utils/elements/Segment.ts +0 -81
- package/src/utils/errors.ts +0 -3
- package/src/utils/intersections.ts +0 -237
- package/src/utils/maths.ts +0 -96
- package/src/utils/numbers.ts +0 -55
- package/src/utils/objects.ts +0 -13
- package/src/utils/pdfDocEncoding.ts +0 -69
- package/src/utils/png.ts +0 -100
- package/src/utils/rng.ts +0 -21
- package/src/utils/strings.ts +0 -191
- package/src/utils/validators.ts +0 -192
- package/tsconfig.build.json +0 -14
- package/tsconfig.json +0 -15
- package/vite.config.mts +0 -39
- /package/{src/api/form/index.ts → dist/api/form/index.d.ts} +0 -0
- /package/{src/api/image/index.ts → dist/api/image/index.d.ts} +0 -0
- /package/{src/api/index.ts → dist/api/index.d.ts} +0 -0
- /package/{src/api/text/index.ts → dist/api/text/index.d.ts} +0 -0
- /package/{src/core/acroform/index.ts → dist/core/acroform/index.d.ts} +0 -0
- /package/{src/core/annotation/index.ts → dist/core/annotation/index.d.ts} +0 -0
- /package/{src/index.ts → dist/index.d.ts} +0 -0
- /package/{src/utils/elements/index.ts → dist/utils/elements/index.d.ts} +0 -0
- /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
|
-
}
|
package/src/utils/errors.ts
DELETED
|
@@ -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
|
-
}
|
package/src/utils/maths.ts
DELETED
|
@@ -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
|
-
};
|
package/src/utils/numbers.ts
DELETED
|
@@ -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
|
-
};
|
package/src/utils/objects.ts
DELETED
|
@@ -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
|
-
};
|