@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,188 +0,0 @@
|
|
|
1
|
-
import { MethodNotImplementedError, DecompressionBombError } from '../errors';
|
|
2
|
-
import Stream, { StreamType } from './Stream';
|
|
3
|
-
|
|
4
|
-
/*
|
|
5
|
-
* Copyright 2012 Mozilla Foundation
|
|
6
|
-
*
|
|
7
|
-
* The DecodeStream class contained in this file is a TypeScript port of the
|
|
8
|
-
* JavaScript DecodeStream class in Mozilla's pdf.js project, made available
|
|
9
|
-
* under the Apache 2.0 open source license.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
// Lots of DecodeStreams are created whose buffers are never used. For these
|
|
13
|
-
// we share a single empty buffer. This is (a) space-efficient and (b) avoids
|
|
14
|
-
// having special cases that would be required if we used |null| for an empty
|
|
15
|
-
// buffer.
|
|
16
|
-
const emptyBuffer = new Uint8Array(0);
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Maximum allowed decoded buffer size (100 MB).
|
|
20
|
-
* Prevents decompression bomb attacks from consuming unbounded memory.
|
|
21
|
-
*/
|
|
22
|
-
const MAX_DECODED_SIZE = 100 * 1024 * 1024;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Super class for the decoding streams
|
|
26
|
-
*/
|
|
27
|
-
class DecodeStream implements StreamType {
|
|
28
|
-
protected bufferLength: number;
|
|
29
|
-
protected buffer: Uint8Array;
|
|
30
|
-
protected eof: boolean;
|
|
31
|
-
|
|
32
|
-
private pos: number;
|
|
33
|
-
private minBufferLength: number;
|
|
34
|
-
|
|
35
|
-
constructor(maybeMinBufferLength?: number) {
|
|
36
|
-
this.pos = 0;
|
|
37
|
-
this.bufferLength = 0;
|
|
38
|
-
this.eof = false;
|
|
39
|
-
this.buffer = emptyBuffer;
|
|
40
|
-
this.minBufferLength = 512;
|
|
41
|
-
if (maybeMinBufferLength) {
|
|
42
|
-
// Compute the first power of two that is as big as maybeMinBufferLength.
|
|
43
|
-
while (this.minBufferLength < maybeMinBufferLength) {
|
|
44
|
-
this.minBufferLength *= 2;
|
|
45
|
-
}
|
|
46
|
-
if (this.minBufferLength > MAX_DECODED_SIZE) {
|
|
47
|
-
this.minBufferLength = MAX_DECODED_SIZE;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
get isEmpty() {
|
|
53
|
-
while (!this.eof && this.bufferLength === 0) {
|
|
54
|
-
this.readBlock();
|
|
55
|
-
}
|
|
56
|
-
return this.bufferLength === 0;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
getByte() {
|
|
60
|
-
const pos = this.pos;
|
|
61
|
-
while (this.bufferLength <= pos) {
|
|
62
|
-
if (this.eof) {
|
|
63
|
-
return -1;
|
|
64
|
-
}
|
|
65
|
-
this.readBlock();
|
|
66
|
-
}
|
|
67
|
-
return this.buffer[this.pos++];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
getUint16() {
|
|
71
|
-
const b0 = this.getByte();
|
|
72
|
-
const b1 = this.getByte();
|
|
73
|
-
if (b0 === -1 || b1 === -1) {
|
|
74
|
-
return -1;
|
|
75
|
-
}
|
|
76
|
-
return (b0 << 8) + b1;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
getInt32() {
|
|
80
|
-
const b0 = this.getByte();
|
|
81
|
-
const b1 = this.getByte();
|
|
82
|
-
const b2 = this.getByte();
|
|
83
|
-
const b3 = this.getByte();
|
|
84
|
-
return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
getBytes(length: number, forceClamped = false) {
|
|
88
|
-
let end;
|
|
89
|
-
const pos = this.pos;
|
|
90
|
-
|
|
91
|
-
if (length) {
|
|
92
|
-
this.ensureBuffer(pos + length);
|
|
93
|
-
end = pos + length;
|
|
94
|
-
|
|
95
|
-
while (!this.eof && this.bufferLength < end) {
|
|
96
|
-
this.readBlock();
|
|
97
|
-
}
|
|
98
|
-
const bufEnd = this.bufferLength;
|
|
99
|
-
if (end > bufEnd) {
|
|
100
|
-
end = bufEnd;
|
|
101
|
-
}
|
|
102
|
-
} else {
|
|
103
|
-
while (!this.eof) {
|
|
104
|
-
this.readBlock();
|
|
105
|
-
}
|
|
106
|
-
end = this.bufferLength;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
this.pos = end;
|
|
110
|
-
const subarray = this.buffer.subarray(pos, end);
|
|
111
|
-
// `this.buffer` is either a `Uint8Array` or `Uint8ClampedArray` here.
|
|
112
|
-
return forceClamped && !(subarray instanceof Uint8ClampedArray)
|
|
113
|
-
? new Uint8ClampedArray(subarray)
|
|
114
|
-
: subarray;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
peekByte() {
|
|
118
|
-
const peekedByte = this.getByte();
|
|
119
|
-
this.pos--;
|
|
120
|
-
return peekedByte;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
peekBytes(length: number, forceClamped = false) {
|
|
124
|
-
const bytes = this.getBytes(length, forceClamped);
|
|
125
|
-
this.pos -= bytes.length;
|
|
126
|
-
return bytes;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
skip(n: number) {
|
|
130
|
-
if (!n) {
|
|
131
|
-
n = 1;
|
|
132
|
-
}
|
|
133
|
-
this.pos += n;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
reset() {
|
|
137
|
-
this.pos = 0;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
makeSubStream(start: number, length: number /* dict */) {
|
|
141
|
-
const end = start + length;
|
|
142
|
-
while (this.bufferLength <= end && !this.eof) {
|
|
143
|
-
this.readBlock();
|
|
144
|
-
}
|
|
145
|
-
return new Stream(this.buffer, start, length /* dict */);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
decode(): Uint8Array {
|
|
149
|
-
while (!this.eof) this.readBlock();
|
|
150
|
-
return this.buffer.subarray(0, this.bufferLength);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
protected readBlock(): void {
|
|
154
|
-
throw new MethodNotImplementedError(this.constructor.name, 'readBlock');
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
protected ensureBuffer(requested: number) {
|
|
158
|
-
const buffer = this.buffer;
|
|
159
|
-
if (requested <= buffer.byteLength) {
|
|
160
|
-
return buffer;
|
|
161
|
-
}
|
|
162
|
-
if (requested > MAX_DECODED_SIZE) {
|
|
163
|
-
throw new DecompressionBombError(requested, MAX_DECODED_SIZE);
|
|
164
|
-
}
|
|
165
|
-
let size = this.minBufferLength;
|
|
166
|
-
while (size < requested) {
|
|
167
|
-
size *= 2;
|
|
168
|
-
}
|
|
169
|
-
if (size > MAX_DECODED_SIZE) {
|
|
170
|
-
size = MAX_DECODED_SIZE;
|
|
171
|
-
if (size < requested) {
|
|
172
|
-
throw new DecompressionBombError(requested, MAX_DECODED_SIZE);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
const buffer2 = new Uint8Array(size);
|
|
176
|
-
buffer2.set(buffer);
|
|
177
|
-
return (this.buffer = buffer2);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// getBaseStreams() {
|
|
181
|
-
// if (this.str && this.str.getBaseStreams) {
|
|
182
|
-
// return this.str.getBaseStreams();
|
|
183
|
-
// }
|
|
184
|
-
// return [];
|
|
185
|
-
// }
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export default DecodeStream;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import DecodeStream from './DecodeStream';
|
|
2
|
-
import { StreamType } from './Stream';
|
|
3
|
-
|
|
4
|
-
const chunkSize = 512;
|
|
5
|
-
|
|
6
|
-
type DecryptFnType = (arg1: Uint8Array | Uint8ClampedArray, arg2: boolean) => Uint8Array;
|
|
7
|
-
|
|
8
|
-
class DecryptStream extends DecodeStream {
|
|
9
|
-
private stream: StreamType;
|
|
10
|
-
private initialized: boolean;
|
|
11
|
-
private nextChunk: Uint8Array | Uint8ClampedArray | null;
|
|
12
|
-
private decrypt: DecryptFnType;
|
|
13
|
-
|
|
14
|
-
constructor(stream: StreamType, decrypt: DecryptFnType, maybeLength?: number) {
|
|
15
|
-
super(maybeLength);
|
|
16
|
-
|
|
17
|
-
this.stream = stream;
|
|
18
|
-
this.decrypt = decrypt;
|
|
19
|
-
this.nextChunk = null;
|
|
20
|
-
this.initialized = false;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
readBlock() {
|
|
24
|
-
let chunk;
|
|
25
|
-
if (this.initialized) {
|
|
26
|
-
chunk = this.nextChunk;
|
|
27
|
-
} else {
|
|
28
|
-
chunk = this.stream.getBytes(chunkSize);
|
|
29
|
-
this.initialized = true;
|
|
30
|
-
}
|
|
31
|
-
if (!chunk || chunk.length === 0) {
|
|
32
|
-
this.eof = true;
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
this.nextChunk = this.stream.getBytes(chunkSize);
|
|
36
|
-
const hasMoreData = this.nextChunk && this.nextChunk.length > 0;
|
|
37
|
-
|
|
38
|
-
const decrypt = this.decrypt;
|
|
39
|
-
chunk = decrypt(chunk, !hasMoreData);
|
|
40
|
-
|
|
41
|
-
const bufferLength = this.bufferLength,
|
|
42
|
-
newLength = bufferLength + chunk.length,
|
|
43
|
-
buffer = this.ensureBuffer(newLength);
|
|
44
|
-
buffer.set(chunk, bufferLength);
|
|
45
|
-
this.bufferLength = newLength;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export default DecryptStream;
|
|
@@ -1,397 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 1996-2003 Glyph & Cog, LLC
|
|
3
|
-
*
|
|
4
|
-
* The flate stream implementation contained in this file is a JavaScript port
|
|
5
|
-
* of XPDF's implementation, made available under the Apache 2.0 open source
|
|
6
|
-
* license.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/*
|
|
10
|
-
* Copyright 2012 Mozilla Foundation
|
|
11
|
-
*
|
|
12
|
-
* The FlateStream class contained in this file is a TypeScript port of the
|
|
13
|
-
* JavaScript FlateStream class in Mozilla's pdf.js project, made available
|
|
14
|
-
* under the Apache 2.0 open source license.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/* tslint:disable no-conditional-assignment */
|
|
18
|
-
import DecodeStream from '../../core/streams/DecodeStream';
|
|
19
|
-
import { StreamType } from '../../core/streams/Stream';
|
|
20
|
-
|
|
21
|
-
// prettier-ignore
|
|
22
|
-
const codeLenCodeMap = new Int32Array([
|
|
23
|
-
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
|
|
24
|
-
]);
|
|
25
|
-
|
|
26
|
-
// prettier-ignore
|
|
27
|
-
const lengthDecode = new Int32Array([
|
|
28
|
-
0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
|
|
29
|
-
0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
|
|
30
|
-
0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
|
|
31
|
-
0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
|
|
32
|
-
]);
|
|
33
|
-
|
|
34
|
-
// prettier-ignore
|
|
35
|
-
const distDecode = new Int32Array([
|
|
36
|
-
0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
|
|
37
|
-
0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
|
|
38
|
-
0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
|
|
39
|
-
0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
|
|
40
|
-
]);
|
|
41
|
-
|
|
42
|
-
// prettier-ignore
|
|
43
|
-
const fixedLitCodeTab = [new Int32Array([
|
|
44
|
-
0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
|
|
45
|
-
0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
|
|
46
|
-
0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
|
|
47
|
-
0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
|
|
48
|
-
0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
|
|
49
|
-
0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
|
|
50
|
-
0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
|
|
51
|
-
0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
|
|
52
|
-
0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
|
|
53
|
-
0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
|
|
54
|
-
0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
|
|
55
|
-
0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
|
|
56
|
-
0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
|
|
57
|
-
0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
|
|
58
|
-
0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
|
|
59
|
-
0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
|
|
60
|
-
0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
|
|
61
|
-
0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
|
|
62
|
-
0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
|
|
63
|
-
0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
|
|
64
|
-
0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
|
|
65
|
-
0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
|
|
66
|
-
0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
|
|
67
|
-
0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
|
|
68
|
-
0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
|
|
69
|
-
0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
|
|
70
|
-
0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
|
|
71
|
-
0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
|
|
72
|
-
0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
|
|
73
|
-
0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
|
|
74
|
-
0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
|
|
75
|
-
0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
|
|
76
|
-
0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
|
|
77
|
-
0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
|
|
78
|
-
0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
|
|
79
|
-
0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
|
|
80
|
-
0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
|
|
81
|
-
0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
|
|
82
|
-
0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
|
|
83
|
-
0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
|
|
84
|
-
0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
|
|
85
|
-
0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
|
|
86
|
-
0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
|
|
87
|
-
0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
|
|
88
|
-
0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
|
|
89
|
-
0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
|
|
90
|
-
0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
|
|
91
|
-
0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
|
|
92
|
-
0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
|
|
93
|
-
0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
|
|
94
|
-
0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
|
|
95
|
-
0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
|
|
96
|
-
0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
|
|
97
|
-
0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
|
|
98
|
-
0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
|
|
99
|
-
0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
|
|
100
|
-
0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
|
|
101
|
-
0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
|
|
102
|
-
0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
|
|
103
|
-
0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
|
|
104
|
-
0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
|
|
105
|
-
0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
|
|
106
|
-
0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
|
|
107
|
-
0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
|
|
108
|
-
]), 9] as [Int32Array, number];
|
|
109
|
-
|
|
110
|
-
// prettier-ignore
|
|
111
|
-
const fixedDistCodeTab = [new Int32Array([
|
|
112
|
-
0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
|
|
113
|
-
0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
|
|
114
|
-
0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
|
|
115
|
-
0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
|
|
116
|
-
]), 5] as [Int32Array, number];
|
|
117
|
-
|
|
118
|
-
class FlateStream extends DecodeStream {
|
|
119
|
-
private stream: StreamType;
|
|
120
|
-
private codeSize: number;
|
|
121
|
-
private codeBuf: number;
|
|
122
|
-
|
|
123
|
-
constructor(stream: StreamType, maybeLength?: number) {
|
|
124
|
-
super(maybeLength);
|
|
125
|
-
|
|
126
|
-
this.stream = stream;
|
|
127
|
-
|
|
128
|
-
const cmf = stream.getByte();
|
|
129
|
-
const flg = stream.getByte();
|
|
130
|
-
if (cmf === -1 || flg === -1) {
|
|
131
|
-
throw new Error(`Invalid header in flate stream: ${cmf}, ${flg}`);
|
|
132
|
-
}
|
|
133
|
-
if ((cmf & 0x0f) !== 0x08) {
|
|
134
|
-
throw new Error(`Unknown compression method in flate stream: ${cmf}, ${flg}`);
|
|
135
|
-
}
|
|
136
|
-
if (((cmf << 8) + flg) % 31 !== 0) {
|
|
137
|
-
throw new Error(`Bad FCHECK in flate stream: ${cmf}, ${flg}`);
|
|
138
|
-
}
|
|
139
|
-
if (flg & 0x20) {
|
|
140
|
-
throw new Error(`FDICT bit set in flate stream: ${cmf}, ${flg}`);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
this.codeSize = 0;
|
|
144
|
-
this.codeBuf = 0;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
protected readBlock() {
|
|
148
|
-
let buffer;
|
|
149
|
-
let len;
|
|
150
|
-
const str = this.stream;
|
|
151
|
-
// read block header
|
|
152
|
-
let hdr = this.getBits(3);
|
|
153
|
-
if (hdr & 1) {
|
|
154
|
-
this.eof = true;
|
|
155
|
-
}
|
|
156
|
-
hdr >>= 1;
|
|
157
|
-
|
|
158
|
-
if (hdr === 0) {
|
|
159
|
-
// uncompressed block
|
|
160
|
-
let b;
|
|
161
|
-
|
|
162
|
-
if ((b = str.getByte()) === -1) {
|
|
163
|
-
throw new Error('Bad block header in flate stream');
|
|
164
|
-
}
|
|
165
|
-
let blockLen = b;
|
|
166
|
-
if ((b = str.getByte()) === -1) {
|
|
167
|
-
throw new Error('Bad block header in flate stream');
|
|
168
|
-
}
|
|
169
|
-
blockLen |= b << 8;
|
|
170
|
-
if ((b = str.getByte()) === -1) {
|
|
171
|
-
throw new Error('Bad block header in flate stream');
|
|
172
|
-
}
|
|
173
|
-
let check = b;
|
|
174
|
-
if ((b = str.getByte()) === -1) {
|
|
175
|
-
throw new Error('Bad block header in flate stream');
|
|
176
|
-
}
|
|
177
|
-
check |= b << 8;
|
|
178
|
-
if (check !== (~blockLen & 0xffff) && (blockLen !== 0 || check !== 0)) {
|
|
179
|
-
// Ignoring error for bad "empty" block (see issue 1277)
|
|
180
|
-
throw new Error('Bad uncompressed block length in flate stream');
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
this.codeBuf = 0;
|
|
184
|
-
this.codeSize = 0;
|
|
185
|
-
|
|
186
|
-
const bufferLength = this.bufferLength;
|
|
187
|
-
buffer = this.ensureBuffer(bufferLength + blockLen);
|
|
188
|
-
const end = bufferLength + blockLen;
|
|
189
|
-
this.bufferLength = end;
|
|
190
|
-
if (blockLen === 0) {
|
|
191
|
-
if (str.peekByte() === -1) {
|
|
192
|
-
this.eof = true;
|
|
193
|
-
}
|
|
194
|
-
} else {
|
|
195
|
-
for (let n = bufferLength; n < end; ++n) {
|
|
196
|
-
if ((b = str.getByte()) === -1) {
|
|
197
|
-
this.eof = true;
|
|
198
|
-
break;
|
|
199
|
-
}
|
|
200
|
-
buffer[n] = b;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
let litCodeTable;
|
|
207
|
-
let distCodeTable;
|
|
208
|
-
if (hdr === 1) {
|
|
209
|
-
// compressed block, fixed codes
|
|
210
|
-
litCodeTable = fixedLitCodeTab;
|
|
211
|
-
distCodeTable = fixedDistCodeTab;
|
|
212
|
-
} else if (hdr === 2) {
|
|
213
|
-
// compressed block, dynamic codes
|
|
214
|
-
const numLitCodes = this.getBits(5) + 257;
|
|
215
|
-
const numDistCodes = this.getBits(5) + 1;
|
|
216
|
-
const numCodeLenCodes = this.getBits(4) + 4;
|
|
217
|
-
|
|
218
|
-
// build the code lengths code table
|
|
219
|
-
const codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
|
|
220
|
-
|
|
221
|
-
let i;
|
|
222
|
-
for (i = 0; i < numCodeLenCodes; ++i) {
|
|
223
|
-
codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
|
|
224
|
-
}
|
|
225
|
-
const codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
|
|
226
|
-
|
|
227
|
-
// build the literal and distance code tables
|
|
228
|
-
len = 0;
|
|
229
|
-
i = 0;
|
|
230
|
-
const codes = numLitCodes + numDistCodes;
|
|
231
|
-
const codeLengths = new Uint8Array(codes);
|
|
232
|
-
let bitsLength;
|
|
233
|
-
let bitsOffset;
|
|
234
|
-
let what;
|
|
235
|
-
while (i < codes) {
|
|
236
|
-
const code = this.getCode(codeLenCodeTab);
|
|
237
|
-
if (code === 16) {
|
|
238
|
-
bitsLength = 2;
|
|
239
|
-
bitsOffset = 3;
|
|
240
|
-
what = len;
|
|
241
|
-
} else if (code === 17) {
|
|
242
|
-
bitsLength = 3;
|
|
243
|
-
bitsOffset = 3;
|
|
244
|
-
what = len = 0;
|
|
245
|
-
} else if (code === 18) {
|
|
246
|
-
bitsLength = 7;
|
|
247
|
-
bitsOffset = 11;
|
|
248
|
-
what = len = 0;
|
|
249
|
-
} else {
|
|
250
|
-
codeLengths[i++] = len = code;
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
let repeatLength = this.getBits(bitsLength) + bitsOffset;
|
|
255
|
-
while (repeatLength-- > 0) {
|
|
256
|
-
codeLengths[i++] = what;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
litCodeTable = this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
|
|
261
|
-
distCodeTable = this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
|
|
262
|
-
} else {
|
|
263
|
-
throw new Error('Unknown block type in flate stream');
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
buffer = this.buffer;
|
|
267
|
-
let limit = buffer ? buffer.length : 0;
|
|
268
|
-
let pos = this.bufferLength;
|
|
269
|
-
while (true) {
|
|
270
|
-
let code1 = this.getCode(litCodeTable);
|
|
271
|
-
if (code1 < 256) {
|
|
272
|
-
if (pos + 1 >= limit) {
|
|
273
|
-
buffer = this.ensureBuffer(pos + 1);
|
|
274
|
-
limit = buffer.length;
|
|
275
|
-
}
|
|
276
|
-
buffer[pos++] = code1;
|
|
277
|
-
continue;
|
|
278
|
-
}
|
|
279
|
-
if (code1 === 256) {
|
|
280
|
-
this.bufferLength = pos;
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
code1 -= 257;
|
|
284
|
-
code1 = lengthDecode[code1];
|
|
285
|
-
let code2 = code1 >> 16;
|
|
286
|
-
if (code2 > 0) {
|
|
287
|
-
code2 = this.getBits(code2);
|
|
288
|
-
}
|
|
289
|
-
len = (code1 & 0xffff) + code2;
|
|
290
|
-
code1 = this.getCode(distCodeTable);
|
|
291
|
-
code1 = distDecode[code1];
|
|
292
|
-
code2 = code1 >> 16;
|
|
293
|
-
if (code2 > 0) {
|
|
294
|
-
code2 = this.getBits(code2);
|
|
295
|
-
}
|
|
296
|
-
const dist = (code1 & 0xffff) + code2;
|
|
297
|
-
if (pos + len >= limit) {
|
|
298
|
-
buffer = this.ensureBuffer(pos + len);
|
|
299
|
-
limit = buffer.length;
|
|
300
|
-
}
|
|
301
|
-
for (let k = 0; k < len; ++k, ++pos) {
|
|
302
|
-
buffer[pos] = buffer[pos - dist];
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
private getBits(bits: number) {
|
|
308
|
-
const str = this.stream;
|
|
309
|
-
let codeSize = this.codeSize;
|
|
310
|
-
let codeBuf = this.codeBuf;
|
|
311
|
-
|
|
312
|
-
let b;
|
|
313
|
-
while (codeSize < bits) {
|
|
314
|
-
if ((b = str.getByte()) === -1) {
|
|
315
|
-
throw new Error('Bad encoding in flate stream');
|
|
316
|
-
}
|
|
317
|
-
codeBuf |= b << codeSize;
|
|
318
|
-
codeSize += 8;
|
|
319
|
-
}
|
|
320
|
-
b = codeBuf & ((1 << bits) - 1);
|
|
321
|
-
this.codeBuf = codeBuf >> bits;
|
|
322
|
-
this.codeSize = codeSize -= bits;
|
|
323
|
-
|
|
324
|
-
return b;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
private getCode(table: [Int32Array, number]) {
|
|
328
|
-
const str = this.stream;
|
|
329
|
-
const codes = table[0];
|
|
330
|
-
const maxLen = table[1];
|
|
331
|
-
let codeSize = this.codeSize;
|
|
332
|
-
let codeBuf = this.codeBuf;
|
|
333
|
-
|
|
334
|
-
let b;
|
|
335
|
-
while (codeSize < maxLen) {
|
|
336
|
-
if ((b = str.getByte()) === -1) {
|
|
337
|
-
// premature end of stream. code might however still be valid.
|
|
338
|
-
// codeSize < codeLen check below guards against incomplete codeVal.
|
|
339
|
-
break;
|
|
340
|
-
}
|
|
341
|
-
codeBuf |= b << codeSize;
|
|
342
|
-
codeSize += 8;
|
|
343
|
-
}
|
|
344
|
-
const code = codes[codeBuf & ((1 << maxLen) - 1)];
|
|
345
|
-
if (typeof codes === 'number') {
|
|
346
|
-
console.log('FLATE:', code);
|
|
347
|
-
}
|
|
348
|
-
const codeLen = code >> 16;
|
|
349
|
-
const codeVal = code & 0xffff;
|
|
350
|
-
if (codeLen < 1 || codeSize < codeLen) {
|
|
351
|
-
throw new Error('Bad encoding in flate stream');
|
|
352
|
-
}
|
|
353
|
-
this.codeBuf = codeBuf >> codeLen;
|
|
354
|
-
this.codeSize = codeSize - codeLen;
|
|
355
|
-
return codeVal;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
private generateHuffmanTable(lengths: Uint8Array): [Int32Array, number] {
|
|
359
|
-
const n = lengths.length;
|
|
360
|
-
|
|
361
|
-
// find max code length
|
|
362
|
-
let maxLen = 0;
|
|
363
|
-
let i;
|
|
364
|
-
for (i = 0; i < n; ++i) {
|
|
365
|
-
if (lengths[i] > maxLen) {
|
|
366
|
-
maxLen = lengths[i];
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// build the table
|
|
371
|
-
const size = 1 << maxLen;
|
|
372
|
-
const codes = new Int32Array(size);
|
|
373
|
-
for (let len = 1, code = 0, skip = 2; len <= maxLen; ++len, code <<= 1, skip <<= 1) {
|
|
374
|
-
for (let val = 0; val < n; ++val) {
|
|
375
|
-
if (lengths[val] === len) {
|
|
376
|
-
// bit-reverse the code
|
|
377
|
-
let code2 = 0;
|
|
378
|
-
let t = code;
|
|
379
|
-
for (i = 0; i < len; ++i) {
|
|
380
|
-
code2 = (code2 << 1) | (t & 1);
|
|
381
|
-
t >>= 1;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
// fill the table entries
|
|
385
|
-
for (i = code2; i < size; i += skip) {
|
|
386
|
-
codes[i] = (len << 16) | val;
|
|
387
|
-
}
|
|
388
|
-
++code;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
return [codes, maxLen];
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
export default FlateStream;
|