@pdfme/pdf-lib 6.0.3-dev.0 → 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
package/src/utils/png.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import UPNGModule from '@pdf-lib/upng';
|
|
2
|
-
|
|
3
|
-
type DecodedPng = {
|
|
4
|
-
ctype: number;
|
|
5
|
-
width: number;
|
|
6
|
-
height: number;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
type UPNGApi = {
|
|
10
|
-
decode: (input: ArrayBuffer) => DecodedPng;
|
|
11
|
-
toRGBA8: (decoded: DecodedPng) => ArrayBuffer[];
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const isUPNGApi = (value: unknown): value is UPNGApi =>
|
|
15
|
-
!!value &&
|
|
16
|
-
typeof value === 'object' &&
|
|
17
|
-
typeof (value as UPNGApi).decode === 'function' &&
|
|
18
|
-
typeof (value as UPNGApi).toRGBA8 === 'function';
|
|
19
|
-
|
|
20
|
-
const resolveUPNG = (value: unknown): UPNGApi => {
|
|
21
|
-
let current: unknown = value;
|
|
22
|
-
|
|
23
|
-
while (current && typeof current === 'object') {
|
|
24
|
-
if (isUPNGApi(current)) return current;
|
|
25
|
-
current = (current as { default?: unknown }).default;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
throw new TypeError('Failed to resolve @pdf-lib/upng exports');
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const UPNG = resolveUPNG(UPNGModule);
|
|
32
|
-
|
|
33
|
-
const getImageType = (ctype: number) => {
|
|
34
|
-
if (ctype === 0) return PngType.Greyscale;
|
|
35
|
-
if (ctype === 2) return PngType.Truecolour;
|
|
36
|
-
if (ctype === 3) return PngType.IndexedColour;
|
|
37
|
-
if (ctype === 4) return PngType.GreyscaleWithAlpha;
|
|
38
|
-
if (ctype === 6) return PngType.TruecolourWithAlpha;
|
|
39
|
-
throw new Error(`Unknown color type: ${ctype}`);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const splitAlphaChannel = (rgbaChannel: Uint8Array) => {
|
|
43
|
-
const pixelCount = Math.floor(rgbaChannel.length / 4);
|
|
44
|
-
|
|
45
|
-
const rgbChannel = new Uint8Array(pixelCount * 3);
|
|
46
|
-
const alphaChannel = new Uint8Array(pixelCount * 1);
|
|
47
|
-
|
|
48
|
-
let rgbaOffset = 0;
|
|
49
|
-
let rgbOffset = 0;
|
|
50
|
-
let alphaOffset = 0;
|
|
51
|
-
|
|
52
|
-
while (rgbaOffset < rgbaChannel.length) {
|
|
53
|
-
rgbChannel[rgbOffset++] = rgbaChannel[rgbaOffset++];
|
|
54
|
-
rgbChannel[rgbOffset++] = rgbaChannel[rgbaOffset++];
|
|
55
|
-
rgbChannel[rgbOffset++] = rgbaChannel[rgbaOffset++];
|
|
56
|
-
alphaChannel[alphaOffset++] = rgbaChannel[rgbaOffset++];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return { rgbChannel, alphaChannel };
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export enum PngType {
|
|
63
|
-
Greyscale = 'Greyscale',
|
|
64
|
-
Truecolour = 'Truecolour',
|
|
65
|
-
IndexedColour = 'IndexedColour',
|
|
66
|
-
GreyscaleWithAlpha = 'GreyscaleWithAlpha',
|
|
67
|
-
TruecolourWithAlpha = 'TruecolourWithAlpha',
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export class PNG {
|
|
71
|
-
static load = (pngData: Uint8Array) => new PNG(pngData);
|
|
72
|
-
|
|
73
|
-
readonly rgbChannel: Uint8Array;
|
|
74
|
-
readonly alphaChannel?: Uint8Array;
|
|
75
|
-
readonly type: PngType;
|
|
76
|
-
readonly width: number;
|
|
77
|
-
readonly height: number;
|
|
78
|
-
readonly bitsPerComponent: number;
|
|
79
|
-
|
|
80
|
-
private constructor(pngData: Uint8Array) {
|
|
81
|
-
const upng = UPNG.decode(pngData.buffer as ArrayBuffer);
|
|
82
|
-
const frames = UPNG.toRGBA8(upng);
|
|
83
|
-
|
|
84
|
-
if (frames.length > 1) throw new Error(`Animated PNGs are not supported`);
|
|
85
|
-
|
|
86
|
-
const frame = new Uint8Array(frames[0]);
|
|
87
|
-
const { rgbChannel, alphaChannel } = splitAlphaChannel(frame);
|
|
88
|
-
|
|
89
|
-
this.rgbChannel = rgbChannel;
|
|
90
|
-
|
|
91
|
-
const hasAlphaValues = alphaChannel.some((a) => a < 255);
|
|
92
|
-
if (hasAlphaValues) this.alphaChannel = alphaChannel;
|
|
93
|
-
|
|
94
|
-
this.type = getImageType(upng.ctype);
|
|
95
|
-
|
|
96
|
-
this.width = upng.width;
|
|
97
|
-
this.height = upng.height;
|
|
98
|
-
this.bitsPerComponent = 8;
|
|
99
|
-
}
|
|
100
|
-
}
|
package/src/utils/rng.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates a pseudo random number. Although it is not cryptographically secure
|
|
3
|
-
* and uniformly distributed, it is not a concern for the intended use-case,
|
|
4
|
-
* which is to generate distinct numbers.
|
|
5
|
-
*
|
|
6
|
-
* Credit: https://stackoverflow.com/a/19303725/10254049
|
|
7
|
-
*/
|
|
8
|
-
export class SimpleRNG {
|
|
9
|
-
static withSeed = (seed: number) => new SimpleRNG(seed);
|
|
10
|
-
|
|
11
|
-
private seed: number;
|
|
12
|
-
|
|
13
|
-
private constructor(seed: number) {
|
|
14
|
-
this.seed = seed;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
nextInt(): number {
|
|
18
|
-
const x = Math.sin(this.seed++) * 10000;
|
|
19
|
-
return x - Math.floor(x);
|
|
20
|
-
}
|
|
21
|
-
}
|
package/src/utils/strings.ts
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
export const toCharCode = (character: string) => character.charCodeAt(0);
|
|
2
|
-
|
|
3
|
-
export const toCodePoint = (character: string) => character.codePointAt(0);
|
|
4
|
-
|
|
5
|
-
export const toHexStringOfMinLength = (num: number, minLength: number) =>
|
|
6
|
-
padStart(num.toString(16), minLength, '0').toUpperCase();
|
|
7
|
-
|
|
8
|
-
export const toHexString = (num: number) => toHexStringOfMinLength(num, 2);
|
|
9
|
-
|
|
10
|
-
export const charFromCode = (code: number) => String.fromCharCode(code);
|
|
11
|
-
|
|
12
|
-
export const charFromHexCode = (hex: string) => charFromCode(parseInt(hex, 16));
|
|
13
|
-
|
|
14
|
-
export const padStart = (value: string, length: number, padChar: string) => {
|
|
15
|
-
let padding = '';
|
|
16
|
-
for (let idx = 0, len = length - value.length; idx < len; idx++) {
|
|
17
|
-
padding += padChar;
|
|
18
|
-
}
|
|
19
|
-
return padding + value;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const stringAsByteArray = (str: string): Uint8Array => {
|
|
23
|
-
const buffer = new Uint8Array(str.length);
|
|
24
|
-
copyStringIntoBuffer(str, buffer, 0);
|
|
25
|
-
return buffer;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const copyStringIntoBuffer = (str: string, buffer: Uint8Array, offset: number): number => {
|
|
29
|
-
const length = str.length;
|
|
30
|
-
for (let idx = 0; idx < length; idx++) {
|
|
31
|
-
buffer[offset++] = str.charCodeAt(idx);
|
|
32
|
-
}
|
|
33
|
-
return length;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export const addRandomSuffix = (prefix: string, suffixLength = 4) =>
|
|
37
|
-
`${prefix}-${Math.floor(Math.random() * 10 ** suffixLength)}`;
|
|
38
|
-
|
|
39
|
-
export const escapeRegExp = (str: string) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
40
|
-
|
|
41
|
-
export const cleanText = (text: string) =>
|
|
42
|
-
text.replace(/\t|\u0085|\u2028|\u2029/g, ' ').replace(/[\b\v]/g, '');
|
|
43
|
-
|
|
44
|
-
export const escapedNewlineChars = ['\\n', '\\f', '\\r', '\\v'];
|
|
45
|
-
|
|
46
|
-
export const newlineChars = ['\n', '\f', '\r', '\v'];
|
|
47
|
-
|
|
48
|
-
export const isNewlineChar = (text: string) => /^[\n\f\r\v]$/.test(text);
|
|
49
|
-
|
|
50
|
-
export const lineSplit = (text: string) => text.split(/[\n\f\r\v]/);
|
|
51
|
-
|
|
52
|
-
export const mergeLines = (text: string) => text.replace(/[\n\f\r\v]/g, ' ');
|
|
53
|
-
|
|
54
|
-
// JavaScript's String.charAt() method doesn work on strings containing UTF-16
|
|
55
|
-
// characters (with high and low surrogate pairs), such as 💩 (poo emoji). This
|
|
56
|
-
// `charAtIndex()` function does.
|
|
57
|
-
//
|
|
58
|
-
// Credit: https://github.com/mathiasbynens/String.prototype.at/blob/master/at.js#L14-L48
|
|
59
|
-
export const charAtIndex = (text: string, index: number): [string, number] => {
|
|
60
|
-
// Get the first code unit and code unit value
|
|
61
|
-
const cuFirst = text.charCodeAt(index);
|
|
62
|
-
let cuSecond: number;
|
|
63
|
-
const nextIndex = index + 1;
|
|
64
|
-
let length = 1;
|
|
65
|
-
if (
|
|
66
|
-
// Check if it's the start of a surrogate pair.
|
|
67
|
-
cuFirst >= 0xd800 &&
|
|
68
|
-
cuFirst <= 0xdbff && // high surrogate
|
|
69
|
-
text.length > nextIndex // there is a next code unit
|
|
70
|
-
) {
|
|
71
|
-
cuSecond = text.charCodeAt(nextIndex);
|
|
72
|
-
if (cuSecond >= 0xdc00 && cuSecond <= 0xdfff) length = 2; // low surrogate
|
|
73
|
-
}
|
|
74
|
-
return [text.slice(index, index + length), length];
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export const charSplit = (text: string) => {
|
|
78
|
-
const chars: string[] = [];
|
|
79
|
-
|
|
80
|
-
for (let idx = 0, len = text.length; idx < len; ) {
|
|
81
|
-
const [c, cLen] = charAtIndex(text, idx);
|
|
82
|
-
chars.push(c);
|
|
83
|
-
idx += cLen;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return chars;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const buildWordBreakRegex = (wordBreaks: string[]) => {
|
|
90
|
-
const newlineCharUnion = escapedNewlineChars.join('|');
|
|
91
|
-
|
|
92
|
-
const escapedRules: string[] = ['$'];
|
|
93
|
-
for (let idx = 0, len = wordBreaks.length; idx < len; idx++) {
|
|
94
|
-
const wordBreak = wordBreaks[idx];
|
|
95
|
-
if (isNewlineChar(wordBreak)) {
|
|
96
|
-
throw new TypeError(`\`wordBreak\` must not include ${newlineCharUnion}`);
|
|
97
|
-
}
|
|
98
|
-
escapedRules.push(wordBreak === '' ? '.' : escapeRegExp(wordBreak));
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const breakRules = escapedRules.join('|');
|
|
102
|
-
return new RegExp(`(${newlineCharUnion})|((.*?)(${breakRules}))`, 'gm');
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export const breakTextIntoLines = (
|
|
106
|
-
text: string,
|
|
107
|
-
wordBreaks: string[],
|
|
108
|
-
maxWidth: number,
|
|
109
|
-
computeWidthOfText: (t: string) => number,
|
|
110
|
-
): string[] => {
|
|
111
|
-
const regex = buildWordBreakRegex(wordBreaks);
|
|
112
|
-
|
|
113
|
-
const words = cleanText(text).match(regex)!;
|
|
114
|
-
|
|
115
|
-
let currLine = '';
|
|
116
|
-
let currWidth = 0;
|
|
117
|
-
const lines: string[] = [];
|
|
118
|
-
|
|
119
|
-
const pushCurrLine = () => {
|
|
120
|
-
if (currLine !== '') lines.push(currLine);
|
|
121
|
-
currLine = '';
|
|
122
|
-
currWidth = 0;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
for (let idx = 0, len = words.length; idx < len; idx++) {
|
|
126
|
-
const word = words[idx];
|
|
127
|
-
if (isNewlineChar(word)) {
|
|
128
|
-
pushCurrLine();
|
|
129
|
-
} else {
|
|
130
|
-
const width = computeWidthOfText(word);
|
|
131
|
-
if (currWidth + width > maxWidth) pushCurrLine();
|
|
132
|
-
currLine += word;
|
|
133
|
-
currWidth += width;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
pushCurrLine();
|
|
137
|
-
|
|
138
|
-
return lines;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
// See section "7.9.4 Dates" of the PDF specification
|
|
142
|
-
const dateRegex = /^D:(\d\d\d\d)(\d\d)?(\d\d)?(\d\d)?(\d\d)?(\d\d)?([+\-Z])?(\d\d)?'?(\d\d)?'?$/;
|
|
143
|
-
|
|
144
|
-
export const parseDate = (dateStr: string): Date | undefined => {
|
|
145
|
-
const match = dateStr.match(dateRegex);
|
|
146
|
-
|
|
147
|
-
if (!match) return undefined;
|
|
148
|
-
|
|
149
|
-
const [
|
|
150
|
-
,
|
|
151
|
-
year,
|
|
152
|
-
month = '01',
|
|
153
|
-
day = '01',
|
|
154
|
-
hours = '00',
|
|
155
|
-
mins = '00',
|
|
156
|
-
secs = '00',
|
|
157
|
-
offsetSign = 'Z',
|
|
158
|
-
offsetHours = '00',
|
|
159
|
-
offsetMins = '00',
|
|
160
|
-
] = match;
|
|
161
|
-
|
|
162
|
-
// http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15
|
|
163
|
-
const tzOffset = offsetSign === 'Z' ? 'Z' : `${offsetSign}${offsetHours}:${offsetMins}`;
|
|
164
|
-
const date = new Date(`${year}-${month}-${day}T${hours}:${mins}:${secs}${tzOffset}`);
|
|
165
|
-
|
|
166
|
-
return date;
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
export const findLastMatch = (value: string, regex: RegExp) => {
|
|
170
|
-
const MAX_STRING_LENGTH = 10000;
|
|
171
|
-
if (value.length > MAX_STRING_LENGTH) {
|
|
172
|
-
return { match: undefined, pos: 0 };
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
let position = 0;
|
|
176
|
-
let lastMatch: RegExpMatchArray | undefined;
|
|
177
|
-
let iterations = 0;
|
|
178
|
-
const MAX_ITERATIONS = 1000;
|
|
179
|
-
|
|
180
|
-
while (position < value.length) {
|
|
181
|
-
if (++iterations > MAX_ITERATIONS) {
|
|
182
|
-
return { match: lastMatch, pos: position };
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const match = value.substring(position).match(regex);
|
|
186
|
-
if (!match) return { match: lastMatch, pos: position };
|
|
187
|
-
lastMatch = match;
|
|
188
|
-
position += (match.index ?? 0) + match[0].length;
|
|
189
|
-
}
|
|
190
|
-
return { match: lastMatch, pos: position };
|
|
191
|
-
};
|
package/src/utils/validators.ts
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
/* tslint:disable:ban-types */
|
|
2
|
-
|
|
3
|
-
import { values as objectValues } from './objects';
|
|
4
|
-
|
|
5
|
-
export const backtick = (val: any) => `\`${val}\``;
|
|
6
|
-
export const singleQuote = (val: any) => `'${val}'`;
|
|
7
|
-
|
|
8
|
-
type Primitive = string | number | boolean | undefined | null;
|
|
9
|
-
|
|
10
|
-
// prettier-ignore
|
|
11
|
-
const formatValue = (value: any) => {
|
|
12
|
-
const type = typeof value;
|
|
13
|
-
if (type ==='string') return singleQuote(value);
|
|
14
|
-
else if (type ==='undefined') return backtick(value);
|
|
15
|
-
else return value;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const createValueErrorMsg = (value: any, valueName: string, values: Primitive[]) => {
|
|
19
|
-
const allowedValues = Array(values.length);
|
|
20
|
-
|
|
21
|
-
for (let idx = 0, len = values.length; idx < len; idx++) {
|
|
22
|
-
const v = values[idx];
|
|
23
|
-
allowedValues[idx] = formatValue(v);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const joinedValues = allowedValues.join(' or ');
|
|
27
|
-
|
|
28
|
-
// prettier-ignore
|
|
29
|
-
return `${backtick(valueName)} must be one of ${joinedValues}, but was actually ${formatValue(value)}`;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const assertIsOneOf = (
|
|
33
|
-
value: any,
|
|
34
|
-
valueName: string,
|
|
35
|
-
allowedValues: Primitive[] | { [key: string]: Primitive },
|
|
36
|
-
) => {
|
|
37
|
-
if (!Array.isArray(allowedValues)) {
|
|
38
|
-
allowedValues = objectValues(allowedValues);
|
|
39
|
-
}
|
|
40
|
-
for (let idx = 0, len = allowedValues.length; idx < len; idx++) {
|
|
41
|
-
if (value === allowedValues[idx]) return;
|
|
42
|
-
}
|
|
43
|
-
throw new TypeError(createValueErrorMsg(value, valueName, allowedValues));
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export const assertIsOneOfOrUndefined = (
|
|
47
|
-
value: any,
|
|
48
|
-
valueName: string,
|
|
49
|
-
allowedValues: Primitive[] | { [key: string]: Primitive },
|
|
50
|
-
) => {
|
|
51
|
-
if (!Array.isArray(allowedValues)) {
|
|
52
|
-
allowedValues = objectValues(allowedValues);
|
|
53
|
-
}
|
|
54
|
-
assertIsOneOf(value, valueName, allowedValues.concat(undefined));
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export const assertIsSubset = (
|
|
58
|
-
values: any[],
|
|
59
|
-
valueName: string,
|
|
60
|
-
allowedValues: Primitive[] | { [key: string]: Primitive },
|
|
61
|
-
) => {
|
|
62
|
-
if (!Array.isArray(allowedValues)) {
|
|
63
|
-
allowedValues = objectValues(allowedValues);
|
|
64
|
-
}
|
|
65
|
-
for (let idx = 0, len = values.length; idx < len; idx++) {
|
|
66
|
-
assertIsOneOf(values[idx], valueName, allowedValues);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export const getType = (val: any) => {
|
|
71
|
-
if (val === null) return 'null';
|
|
72
|
-
if (val === undefined) return 'undefined';
|
|
73
|
-
if (typeof val === 'string') return 'string';
|
|
74
|
-
if (isNaN(val)) return 'NaN';
|
|
75
|
-
if (typeof val === 'number') return 'number';
|
|
76
|
-
if (typeof val === 'boolean') return 'boolean';
|
|
77
|
-
if (typeof val === 'symbol') return 'symbol';
|
|
78
|
-
if (typeof val === 'bigint') return 'bigint';
|
|
79
|
-
if (val.constructor && val.constructor.name) return val.constructor.name;
|
|
80
|
-
if (val.name) return val.name;
|
|
81
|
-
if (val.constructor) return String(val.constructor);
|
|
82
|
-
return String(val);
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
export type TypeDescriptor =
|
|
86
|
-
| 'null'
|
|
87
|
-
| 'undefined'
|
|
88
|
-
| 'string'
|
|
89
|
-
| 'number'
|
|
90
|
-
| 'boolean'
|
|
91
|
-
| 'symbol'
|
|
92
|
-
| 'bigint'
|
|
93
|
-
| DateConstructor
|
|
94
|
-
| ArrayConstructor
|
|
95
|
-
| Uint8ArrayConstructor
|
|
96
|
-
| ArrayBufferConstructor
|
|
97
|
-
| FunctionConstructor
|
|
98
|
-
| [Function, string];
|
|
99
|
-
|
|
100
|
-
export const isType = (value: any, type: TypeDescriptor) => {
|
|
101
|
-
if (type === 'null') return value === null;
|
|
102
|
-
if (type === 'undefined') return value === undefined;
|
|
103
|
-
if (type === 'string') return typeof value === 'string';
|
|
104
|
-
if (type === 'number') return typeof value === 'number' && !isNaN(value);
|
|
105
|
-
if (type === 'boolean') return typeof value === 'boolean';
|
|
106
|
-
if (type === 'symbol') return typeof value === 'symbol';
|
|
107
|
-
if (type === 'bigint') return typeof value === 'bigint';
|
|
108
|
-
if (type === Date) return value instanceof Date;
|
|
109
|
-
if (type === Array) return value instanceof Array;
|
|
110
|
-
if (type === Uint8Array) return value instanceof Uint8Array;
|
|
111
|
-
if (type === ArrayBuffer) return value instanceof ArrayBuffer;
|
|
112
|
-
if (type === Function) return value instanceof Function;
|
|
113
|
-
return value instanceof (type as [Function, string])[0];
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
export const createTypeErrorMsg = (value: any, valueName: string, types: TypeDescriptor[]) => {
|
|
117
|
-
const allowedTypes = Array(types.length);
|
|
118
|
-
|
|
119
|
-
for (let idx = 0, len = types.length; idx < len; idx++) {
|
|
120
|
-
const type = types[idx];
|
|
121
|
-
if (type === 'null') allowedTypes[idx] = backtick('null');
|
|
122
|
-
if (type === 'undefined') allowedTypes[idx] = backtick('undefined');
|
|
123
|
-
if (type === 'string') allowedTypes[idx] = backtick('string');
|
|
124
|
-
else if (type === 'number') allowedTypes[idx] = backtick('number');
|
|
125
|
-
else if (type === 'boolean') allowedTypes[idx] = backtick('boolean');
|
|
126
|
-
else if (type === 'symbol') allowedTypes[idx] = backtick('symbol');
|
|
127
|
-
else if (type === 'bigint') allowedTypes[idx] = backtick('bigint');
|
|
128
|
-
else if (type === Array) allowedTypes[idx] = backtick('Array');
|
|
129
|
-
else if (type === Uint8Array) allowedTypes[idx] = backtick('Uint8Array');
|
|
130
|
-
else if (type === ArrayBuffer) allowedTypes[idx] = backtick('ArrayBuffer');
|
|
131
|
-
else allowedTypes[idx] = backtick((type as [Function, string])[1]);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const joinedTypes = allowedTypes.join(' or ');
|
|
135
|
-
|
|
136
|
-
// prettier-ignore
|
|
137
|
-
return `${backtick(valueName)} must be of type ${joinedTypes}, but was actually of type ${backtick(getType(value))}`;
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
export const assertIs = (value: any, valueName: string, types: TypeDescriptor[]) => {
|
|
141
|
-
for (let idx = 0, len = types.length; idx < len; idx++) {
|
|
142
|
-
if (isType(value, types[idx])) return;
|
|
143
|
-
}
|
|
144
|
-
throw new TypeError(createTypeErrorMsg(value, valueName, types));
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
export const assertOrUndefined = (value: any, valueName: string, types: TypeDescriptor[]) => {
|
|
148
|
-
assertIs(value, valueName, types.concat('undefined'));
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
export const assertEachIs = (values: any[], valueName: string, types: TypeDescriptor[]) => {
|
|
152
|
-
for (let idx = 0, len = values.length; idx < len; idx++) {
|
|
153
|
-
assertIs(values[idx], valueName, types);
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
export const assertRange = (value: any, valueName: string, min: number, max: number) => {
|
|
158
|
-
assertIs(value, valueName, ['number']);
|
|
159
|
-
assertIs(min, 'min', ['number']);
|
|
160
|
-
assertIs(max, 'max', ['number']);
|
|
161
|
-
max = Math.max(min, max);
|
|
162
|
-
if (value < min || value > max) {
|
|
163
|
-
// prettier-ignore
|
|
164
|
-
throw new Error(`${backtick(valueName)} must be at least ${min} and at most ${max}, but was actually ${value}`);
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
export const assertRangeOrUndefined = (value: any, valueName: string, min: number, max: number) => {
|
|
169
|
-
assertIs(value, valueName, ['number', 'undefined']);
|
|
170
|
-
if (typeof value === 'number') assertRange(value, valueName, min, max);
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
export const assertMultiple = (value: any, valueName: string, multiplier: number) => {
|
|
174
|
-
assertIs(value, valueName, ['number']);
|
|
175
|
-
if (value % multiplier !== 0) {
|
|
176
|
-
// prettier-ignore
|
|
177
|
-
throw new Error(`${backtick(valueName)} must be a multiple of ${multiplier}, but was actually ${value}`);
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
export const assertInteger = (value: any, valueName: string) => {
|
|
182
|
-
if (!Number.isInteger(value)) {
|
|
183
|
-
throw new Error(`${backtick(valueName)} must be an integer, but was actually ${value}`);
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
export const assertPositive = (value: number, valueName: string) => {
|
|
188
|
-
if (![1, 0].includes(Math.sign(value))) {
|
|
189
|
-
// prettier-ignore
|
|
190
|
-
throw new Error(`${backtick(valueName)} must be a positive number or 0, but was actually ${value}`);
|
|
191
|
-
}
|
|
192
|
-
};
|
package/tsconfig.build.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.build.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"declaration": true,
|
|
5
|
-
"declarationDir": "./dist",
|
|
6
|
-
"emitDeclarationOnly": true,
|
|
7
|
-
"module": "ESNext",
|
|
8
|
-
"moduleResolution": "bundler",
|
|
9
|
-
"outDir": "./dist",
|
|
10
|
-
"rootDir": "./src",
|
|
11
|
-
"skipLibCheck": true
|
|
12
|
-
},
|
|
13
|
-
"include": ["src/**/*.ts"]
|
|
14
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"composite": true,
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"declarationDir": "./dist/typecheck",
|
|
7
|
-
"emitDeclarationOnly": true,
|
|
8
|
-
"module": "ESNext",
|
|
9
|
-
"moduleResolution": "bundler",
|
|
10
|
-
"outDir": "./dist/typecheck",
|
|
11
|
-
"tsBuildInfoFile": "./dist/typecheck/tsconfig.tsbuildinfo",
|
|
12
|
-
"skipLibCheck": true
|
|
13
|
-
},
|
|
14
|
-
"include": ["src/**/*.ts"]
|
|
15
|
-
}
|
package/vite.config.mts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { builtinModules } from 'node:module';
|
|
3
|
-
import { dirname, resolve } from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { defineConfig } from 'vite';
|
|
6
|
-
|
|
7
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
const packageJson = JSON.parse(readFileSync(resolve(__dirname, 'package.json'), 'utf8')) as {
|
|
9
|
-
dependencies?: Record<string, string>;
|
|
10
|
-
peerDependencies?: Record<string, string>;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const builtinModuleSet = new Set([
|
|
14
|
-
...builtinModules,
|
|
15
|
-
...builtinModules.map((moduleName) => `node:${moduleName}`),
|
|
16
|
-
]);
|
|
17
|
-
const packageDependencies = [
|
|
18
|
-
...Object.keys(packageJson.dependencies ?? {}),
|
|
19
|
-
...Object.keys(packageJson.peerDependencies ?? {}),
|
|
20
|
-
];
|
|
21
|
-
|
|
22
|
-
const isExternal = (id: string) =>
|
|
23
|
-
builtinModuleSet.has(id) ||
|
|
24
|
-
packageDependencies.some((dependency) => id === dependency || id.startsWith(`${dependency}/`));
|
|
25
|
-
|
|
26
|
-
export default defineConfig({
|
|
27
|
-
build: {
|
|
28
|
-
lib: {
|
|
29
|
-
entry: resolve(__dirname, 'src/index.ts'),
|
|
30
|
-
fileName: 'index',
|
|
31
|
-
formats: ['es'],
|
|
32
|
-
},
|
|
33
|
-
minify: false,
|
|
34
|
-
outDir: 'dist',
|
|
35
|
-
rollupOptions: { external: isExternal },
|
|
36
|
-
sourcemap: true,
|
|
37
|
-
target: 'es2020',
|
|
38
|
-
},
|
|
39
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|