@pdfme/pdf-lib 6.1.12 → 6.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/dist/api/PDFDocument.d.ts +11 -11
  2. package/dist/api/PDFDocumentOptions.d.ts +2 -2
  3. package/dist/api/PDFEmbeddedFile.d.ts +4 -4
  4. package/dist/api/PDFEmbeddedPage.d.ts +3 -3
  5. package/dist/api/PDFFont.d.ts +3 -3
  6. package/dist/api/PDFImage.d.ts +3 -3
  7. package/dist/api/PDFJavaScript.d.ts +4 -4
  8. package/dist/api/PDFPage.d.ts +8 -8
  9. package/dist/api/PDFPageOptions.d.ts +5 -5
  10. package/dist/api/colors.d.ts +3 -3
  11. package/dist/api/form/PDFButton.d.ts +8 -8
  12. package/dist/api/form/PDFCheckBox.d.ts +5 -5
  13. package/dist/api/form/PDFDropdown.d.ts +6 -6
  14. package/dist/api/form/PDFField.d.ts +8 -8
  15. package/dist/api/form/PDFForm.d.ts +11 -11
  16. package/dist/api/form/PDFOptionList.d.ts +6 -6
  17. package/dist/api/form/PDFRadioGroup.d.ts +5 -5
  18. package/dist/api/form/PDFSignature.d.ts +3 -3
  19. package/dist/api/form/PDFTextField.d.ts +8 -8
  20. package/dist/api/form/appearances.d.ts +10 -10
  21. package/dist/api/form/index.d.ts +10 -10
  22. package/dist/api/image/index.d.ts +1 -1
  23. package/dist/api/index.d.ts +20 -20
  24. package/dist/api/objects.d.ts +1 -1
  25. package/dist/api/operations.d.ts +5 -5
  26. package/dist/api/operators.d.ts +1 -1
  27. package/dist/api/svg.d.ts +7 -7
  28. package/dist/api/svgPath.d.ts +1 -1
  29. package/dist/api/text/index.d.ts +2 -2
  30. package/dist/api/text/layout.d.ts +3 -3
  31. package/dist/core/PDFContext.d.ts +16 -16
  32. package/dist/core/PDFObjectCopier.d.ts +2 -2
  33. package/dist/core/acroform/PDFAcroButton.d.ts +7 -7
  34. package/dist/core/acroform/PDFAcroCheckBox.d.ts +5 -5
  35. package/dist/core/acroform/PDFAcroChoice.d.ts +4 -4
  36. package/dist/core/acroform/PDFAcroComboBox.d.ts +4 -4
  37. package/dist/core/acroform/PDFAcroField.d.ts +8 -8
  38. package/dist/core/acroform/PDFAcroForm.d.ts +5 -5
  39. package/dist/core/acroform/PDFAcroListBox.d.ts +4 -4
  40. package/dist/core/acroform/PDFAcroNonTerminal.d.ts +5 -5
  41. package/dist/core/acroform/PDFAcroPushButton.d.ts +4 -4
  42. package/dist/core/acroform/PDFAcroRadioButton.d.ts +5 -5
  43. package/dist/core/acroform/PDFAcroSignature.d.ts +3 -3
  44. package/dist/core/acroform/PDFAcroTerminal.d.ts +6 -6
  45. package/dist/core/acroform/PDFAcroText.d.ts +7 -7
  46. package/dist/core/acroform/index.d.ts +15 -15
  47. package/dist/core/acroform/utils.d.ts +4 -4
  48. package/dist/core/annotation/AppearanceCharacteristics.d.ts +5 -5
  49. package/dist/core/annotation/BorderStyle.d.ts +2 -2
  50. package/dist/core/annotation/PDFAnnotation.d.ts +6 -6
  51. package/dist/core/annotation/PDFWidgetAnnotation.d.ts +9 -9
  52. package/dist/core/annotation/index.d.ts +4 -4
  53. package/dist/core/document/PDFCrossRefSection.d.ts +1 -1
  54. package/dist/core/document/PDFTrailerDict.d.ts +1 -1
  55. package/dist/core/embedders/CMap.d.ts +1 -1
  56. package/dist/core/embedders/CustomFontEmbedder.d.ts +5 -5
  57. package/dist/core/embedders/CustomFontSubsetEmbedder.d.ts +3 -3
  58. package/dist/core/embedders/FileEmbedder.d.ts +2 -2
  59. package/dist/core/embedders/FontFlags.d.ts +1 -1
  60. package/dist/core/embedders/JavaScriptEmbedder.d.ts +2 -2
  61. package/dist/core/embedders/JpegEmbedder.d.ts +2 -2
  62. package/dist/core/embedders/PDFPageEmbedder.d.ts +4 -4
  63. package/dist/core/embedders/PngEmbedder.d.ts +2 -2
  64. package/dist/core/embedders/StandardFontEmbedder.d.ts +3 -3
  65. package/dist/core/errors.d.ts +1 -1
  66. package/dist/core/index.d.ts +47 -47
  67. package/dist/core/interactive/ViewerPreferences.d.ts +6 -6
  68. package/dist/core/objects/PDFArray.d.ts +12 -12
  69. package/dist/core/objects/PDFBool.d.ts +1 -1
  70. package/dist/core/objects/PDFDict.d.ts +11 -11
  71. package/dist/core/objects/PDFHexString.d.ts +1 -1
  72. package/dist/core/objects/PDFInvalidObject.d.ts +1 -1
  73. package/dist/core/objects/PDFName.d.ts +1 -1
  74. package/dist/core/objects/PDFNull.d.ts +1 -1
  75. package/dist/core/objects/PDFNumber.d.ts +1 -1
  76. package/dist/core/objects/PDFObject.d.ts +1 -1
  77. package/dist/core/objects/PDFRawStream.d.ts +4 -4
  78. package/dist/core/objects/PDFRef.d.ts +1 -1
  79. package/dist/core/objects/PDFStream.d.ts +3 -3
  80. package/dist/core/objects/PDFString.d.ts +1 -1
  81. package/dist/core/operators/PDFOperator.d.ts +7 -7
  82. package/dist/core/parser/BaseParser.d.ts +1 -1
  83. package/dist/core/parser/ByteStream.d.ts +1 -1
  84. package/dist/core/parser/PDFObjectParser.d.ts +14 -14
  85. package/dist/core/parser/PDFObjectStreamParser.d.ts +2 -2
  86. package/dist/core/parser/PDFParser.d.ts +3 -3
  87. package/dist/core/parser/PDFXRefStreamParser.d.ts +2 -2
  88. package/dist/core/streams/Ascii85Stream.d.ts +2 -2
  89. package/dist/core/streams/AsciiHexStream.d.ts +2 -2
  90. package/dist/core/streams/DecodeStream.d.ts +1 -1
  91. package/dist/core/streams/DecryptStream.d.ts +2 -2
  92. package/dist/core/streams/FlateStream.d.ts +2 -2
  93. package/dist/core/streams/LZWStream.d.ts +2 -2
  94. package/dist/core/streams/RunLengthStream.d.ts +2 -2
  95. package/dist/core/streams/decode.d.ts +2 -2
  96. package/dist/core/structures/PDFCatalog.d.ts +6 -6
  97. package/dist/core/structures/PDFContentStream.d.ts +4 -4
  98. package/dist/core/structures/PDFCrossRefStream.d.ts +4 -4
  99. package/dist/core/structures/PDFFlateStream.d.ts +3 -3
  100. package/dist/core/structures/PDFObjectStream.d.ts +4 -4
  101. package/dist/core/structures/PDFPageLeaf.d.ts +9 -9
  102. package/dist/core/structures/PDFPageTree.d.ts +6 -6
  103. package/dist/core/syntax/Keywords.d.ts +1 -1
  104. package/dist/core/writers/PDFStreamWriter.d.ts +6 -6
  105. package/dist/core/writers/PDFWriter.d.ts +8 -8
  106. package/dist/index.d.ts +4 -4
  107. package/dist/index.js +120 -87
  108. package/dist/index.js.map +1 -1
  109. package/dist/types/index.d.ts +9 -9
  110. package/dist/utils/elements/Arc.d.ts +4 -4
  111. package/dist/utils/elements/Circle.d.ts +2 -2
  112. package/dist/utils/elements/Ellipse.d.ts +4 -4
  113. package/dist/utils/elements/GraphElement.d.ts +1 -1
  114. package/dist/utils/elements/Line.d.ts +3 -3
  115. package/dist/utils/elements/Plot.d.ts +3 -3
  116. package/dist/utils/elements/Point.d.ts +2 -2
  117. package/dist/utils/elements/Rectangle.d.ts +2 -2
  118. package/dist/utils/elements/Segment.d.ts +4 -4
  119. package/dist/utils/elements/index.d.ts +9 -9
  120. package/dist/utils/index.d.ts +11 -11
  121. package/dist/utils/intersections.d.ts +3 -3
  122. package/dist/utils/maths.d.ts +2 -2
  123. package/package.json +10 -8
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Encodings, Font, FontNames } from "@pdf-lib/standard-fonts";
2
- import pako from "pako";
2
+ import { deflate } from "pako";
3
3
  import UPNGModule from "@pdf-lib/upng";
4
4
  import ColorParser from "color";
5
5
  import { NodeType, parse } from "node-html-better-parser";
@@ -530,13 +530,14 @@ var utf16Decode = (input, byteOrderMark = true) => {
530
530
  const codePoints = [];
531
531
  while (input.length - idx >= 2) {
532
532
  const first = decodeValues(input[idx++], input[idx++], byteOrder);
533
- if (isHighSurrogate(first)) if (input.length - idx < 2) codePoints.push(REPLACEMENT);
534
- else {
535
- const second = decodeValues(input[idx++], input[idx++], byteOrder);
536
- if (isLowSurrogate(second)) codePoints.push(first, second);
537
- else codePoints.push(REPLACEMENT);
538
- }
539
- else if (isLowSurrogate(first)) {
533
+ if (isHighSurrogate(first)) {
534
+ if (input.length - idx < 2) codePoints.push(REPLACEMENT);
535
+ else {
536
+ const second = decodeValues(input[idx++], input[idx++], byteOrder);
537
+ if (isLowSurrogate(second)) codePoints.push(first, second);
538
+ else codePoints.push(REPLACEMENT);
539
+ }
540
+ } else if (isLowSurrogate(first)) {
540
541
  idx += 2;
541
542
  codePoints.push(REPLACEMENT);
542
543
  } else codePoints.push(first);
@@ -814,7 +815,7 @@ var pdfDocEncodingDecode = (bytes) => {
814
815
  return String.fromCodePoint(...codePoints);
815
816
  };
816
817
  //#endregion
817
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
818
+ //#region \0@oxc-project+runtime@0.147.0/helpers/esm/typeof.js
818
819
  function _typeof(o) {
819
820
  "@babel/helpers - typeof";
820
821
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -824,7 +825,7 @@ function _typeof(o) {
824
825
  }, _typeof(o);
825
826
  }
826
827
  //#endregion
827
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
828
+ //#region \0@oxc-project+runtime@0.147.0/helpers/esm/toPrimitive.js
828
829
  function toPrimitive(t, r) {
829
830
  if ("object" != _typeof(t) || !t) return t;
830
831
  var e = t[Symbol.toPrimitive];
@@ -836,13 +837,13 @@ function toPrimitive(t, r) {
836
837
  return ("string" === r ? String : Number)(t);
837
838
  }
838
839
  //#endregion
839
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
840
+ //#region \0@oxc-project+runtime@0.147.0/helpers/esm/toPropertyKey.js
840
841
  function toPropertyKey(t) {
841
842
  var i = toPrimitive(t, "string");
842
843
  return "symbol" == _typeof(i) ? i : i + "";
843
844
  }
844
845
  //#endregion
845
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
846
+ //#region \0@oxc-project+runtime@0.147.0/helpers/esm/defineProperty.js
846
847
  function _defineProperty(e, r, t) {
847
848
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
848
849
  value: t,
@@ -1392,9 +1393,10 @@ var PDFName = class extends PDFObject {
1392
1393
  const char = this.encodedName[idx];
1393
1394
  const byte = toCharCode(char);
1394
1395
  const nextChar = this.encodedName[idx + 1];
1395
- if (!escaped) if (byte === CharCodes.Hash) escaped = true;
1396
- else pushByte(byte);
1397
- else if (byte >= CharCodes.Zero && byte <= CharCodes.Nine || byte >= CharCodes.a && byte <= CharCodes.f || byte >= CharCodes.A && byte <= CharCodes.F) {
1396
+ if (!escaped) {
1397
+ if (byte === CharCodes.Hash) escaped = true;
1398
+ else pushByte(byte);
1399
+ } else if (byte >= CharCodes.Zero && byte <= CharCodes.Nine || byte >= CharCodes.a && byte <= CharCodes.f || byte >= CharCodes.A && byte <= CharCodes.F) {
1398
1400
  hex += char;
1399
1401
  if (hex.length === 2 || !(nextChar >= "0" && nextChar <= "9" || nextChar >= "a" && nextChar <= "f" || nextChar >= "A" && nextChar <= "F")) {
1400
1402
  pushByte(parseInt(hex, 16));
@@ -1861,7 +1863,7 @@ var PDFFlateStream = class extends PDFStream {
1861
1863
  _defineProperty(this, "encode", void 0);
1862
1864
  _defineProperty(this, "computeContents", () => {
1863
1865
  const unencodedContents = this.getUnencodedContents();
1864
- return this.encode ? pako.deflate(unencodedContents) : unencodedContents;
1866
+ return this.encode ? deflate(unencodedContents) : unencodedContents;
1865
1867
  });
1866
1868
  this.encode = encode;
1867
1869
  if (encode) dict.set(PDFName.of("Filter"), PDFName.of("FlateDecode"));
@@ -2033,7 +2035,7 @@ var PDFContext = class {
2033
2035
  return PDFRawStream.of(this.obj(dict), typedArrayFor(contents));
2034
2036
  }
2035
2037
  flateStream(contents, dict = {}) {
2036
- return this.stream(pako.deflate(typedArrayFor(contents)), {
2038
+ return this.stream(deflate(typedArrayFor(contents)), {
2037
2039
  ...dict,
2038
2040
  Filter: "FlateDecode"
2039
2041
  });
@@ -3004,7 +3006,8 @@ var PDFHexString = class PDFHexString extends PDFObject {
3004
3006
  let hexOffset = 0;
3005
3007
  let bytesOffset = 0;
3006
3008
  while (hexOffset < hexLength) {
3007
- bytes[bytesOffset] = parseInt(hex.substring(hexOffset, hexOffset + 2), 16);
3009
+ const byte = parseInt(hex.substring(hexOffset, hexOffset + 2), 16);
3010
+ bytes[bytesOffset] = byte;
3008
3011
  hexOffset += 2;
3009
3012
  bytesOffset += 1;
3010
3013
  }
@@ -3137,7 +3140,9 @@ var createCmap = (glyphs, glyphId) => {
3137
3140
  const bfChars = Array(glyphs.length);
3138
3141
  for (let idx = 0, len = glyphs.length; idx < len; idx++) {
3139
3142
  const glyph = glyphs[idx];
3140
- bfChars[idx] = [cmapHexFormat(cmapHexString(glyphId(glyph))), cmapHexFormat(...glyph.codePoints.map(cmapCodePointFormat))];
3143
+ const id = cmapHexFormat(cmapHexString(glyphId(glyph)));
3144
+ const unicode = cmapHexFormat(...glyph.codePoints.map(cmapCodePointFormat));
3145
+ bfChars[idx] = [id, unicode];
3141
3146
  }
3142
3147
  return fillCmapTemplate(bfChars);
3143
3148
  };
@@ -3224,9 +3229,10 @@ var PDFString = class PDFString extends PDFObject {
3224
3229
  const char = this.value[idx];
3225
3230
  const byte = toCharCode(char);
3226
3231
  const nextChar = this.value[idx + 1];
3227
- if (!escaped) if (byte === CharCodes.BackSlash) escaped = true;
3228
- else pushByte(byte);
3229
- else if (byte === CharCodes.Newline) pushByte();
3232
+ if (!escaped) {
3233
+ if (byte === CharCodes.BackSlash) escaped = true;
3234
+ else pushByte(byte);
3235
+ } else if (byte === CharCodes.Newline) pushByte();
3230
3236
  else if (byte === CharCodes.CarriageReturn) pushByte();
3231
3237
  else if (byte === CharCodes.n) pushByte(CharCodes.Newline);
3232
3238
  else if (byte === CharCodes.r) pushByte(CharCodes.CarriageReturn);
@@ -3296,7 +3302,8 @@ _defineProperty(PDFString, "fromDate", (date) => {
3296
3302
  */
3297
3303
  var CustomFontEmbedder = class CustomFontEmbedder {
3298
3304
  static async for(fontkit, fontData, customName, fontFeatures) {
3299
- return new CustomFontEmbedder(fontkit.create(fontData), fontData, customName, fontFeatures);
3305
+ const font = fontkit.create(fontData);
3306
+ return new CustomFontEmbedder(font, fontData, customName, fontFeatures);
3300
3307
  }
3301
3308
  constructor(font, fontData, customName, fontFeatures) {
3302
3309
  _defineProperty(this, "font", void 0);
@@ -3464,7 +3471,8 @@ var CustomFontEmbedder = class CustomFontEmbedder {
3464
3471
  */
3465
3472
  var CustomFontSubsetEmbedder = class CustomFontSubsetEmbedder extends CustomFontEmbedder {
3466
3473
  static async for(fontkit, fontData, customFontName, fontFeatures) {
3467
- return new CustomFontSubsetEmbedder(fontkit.create(fontData), fontData, customFontName, fontFeatures);
3474
+ const font = fontkit.create(fontData);
3475
+ return new CustomFontSubsetEmbedder(font, fontData, customFontName, fontFeatures);
3468
3476
  }
3469
3477
  constructor(font, fontData, customFontName, fontFeatures) {
3470
3478
  super(font, fontData, customFontName, fontFeatures);
@@ -3725,7 +3733,8 @@ _defineProperty(PNG, "load", (pngData) => new _PNG(pngData));
3725
3733
  */
3726
3734
  var PngEmbedder = class PngEmbedder {
3727
3735
  static async for(imageData) {
3728
- return new PngEmbedder(PNG.load(imageData));
3736
+ const png = PNG.load(imageData);
3737
+ return new PngEmbedder(png);
3729
3738
  }
3730
3739
  constructor(png) {
3731
3740
  _defineProperty(this, "bitsPerComponent", void 0);
@@ -3854,7 +3863,7 @@ var emptyBuffer = /* @__PURE__ */ new Uint8Array(0);
3854
3863
  * Maximum allowed decoded buffer size (100 MB).
3855
3864
  * Prevents decompression bomb attacks from consuming unbounded memory.
3856
3865
  */
3857
- var MAX_DECODED_SIZE = 100 * 1024 * 1024;
3866
+ var MAX_DECODED_SIZE = 104857600;
3858
3867
  /**
3859
3868
  * Super class for the decoding streams
3860
3869
  */
@@ -4936,14 +4945,15 @@ var LZWStream = class extends DecodeStream {
4936
4945
  if (!code || code < 256) {
4937
4946
  currentSequence[0] = code;
4938
4947
  currentSequenceLength = 1;
4939
- } else if (code >= 258) if (code < nextCode) {
4940
- currentSequenceLength = dictionaryLengths[code];
4941
- for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
4942
- currentSequence[j] = dictionaryValues[q];
4943
- q = dictionaryPrevCodes[q];
4944
- }
4945
- } else currentSequence[currentSequenceLength++] = currentSequence[0];
4946
- else if (code === 256) {
4948
+ } else if (code >= 258) {
4949
+ if (code < nextCode) {
4950
+ currentSequenceLength = dictionaryLengths[code];
4951
+ for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
4952
+ currentSequence[j] = dictionaryValues[q];
4953
+ q = dictionaryPrevCodes[q];
4954
+ }
4955
+ } else currentSequence[currentSequenceLength++] = currentSequence[0];
4956
+ } else if (code === 256) {
4947
4957
  codeLength = 9;
4948
4958
  nextCode = 258;
4949
4959
  currentSequenceLength = 0;
@@ -5640,7 +5650,10 @@ var PDFAcroField = class PDFAcroField {
5640
5650
  }
5641
5651
  getParent() {
5642
5652
  const parentRef = this.dict.get(PDFName.of("Parent"));
5643
- if (parentRef instanceof PDFRef) return new PDFAcroField(this.dict.lookup(PDFName.of("Parent"), PDFDict), parentRef);
5653
+ if (parentRef instanceof PDFRef) {
5654
+ const parent = this.dict.lookup(PDFName.of("Parent"), PDFDict);
5655
+ return new PDFAcroField(parent, parentRef);
5656
+ }
5644
5657
  }
5645
5658
  setParent(parent) {
5646
5659
  if (!parent) this.dict.delete(PDFName.of("Parent"));
@@ -6628,7 +6641,8 @@ var PDFAcroForm = class {
6628
6641
  const fields = Array(Fields.size());
6629
6642
  for (let idx = 0, len = Fields.size(); idx < len; idx++) {
6630
6643
  const ref = Fields.get(idx);
6631
- fields[idx] = [createPDFAcroField(Fields.lookup(idx, PDFDict), ref), ref];
6644
+ const dict = Fields.lookup(idx, PDFDict);
6645
+ fields[idx] = [createPDFAcroField(dict, ref), ref];
6632
6646
  }
6633
6647
  return fields;
6634
6648
  }
@@ -6778,8 +6792,10 @@ var PDFPageTree = class PDFPageTree extends PDFDict {
6778
6792
  }
6779
6793
  const kidRef = Kids.get(idx);
6780
6794
  const kid = this.context.lookup(kidRef);
6781
- if (kid instanceof PDFPageTree) if (kid.Count().asNumber() > leafsRemainingUntilTarget) return kid.insertLeafNode(leafRef, leafsRemainingUntilTarget) || kidRef;
6782
- else leafsRemainingUntilTarget -= kid.Count().asNumber();
6795
+ if (kid instanceof PDFPageTree) {
6796
+ if (kid.Count().asNumber() > leafsRemainingUntilTarget) return kid.insertLeafNode(leafRef, leafsRemainingUntilTarget) || kidRef;
6797
+ else leafsRemainingUntilTarget -= kid.Count().asNumber();
6798
+ }
6783
6799
  if (kid instanceof PDFPageLeaf) leafsRemainingUntilTarget -= 1;
6784
6800
  }
6785
6801
  if (leafsRemainingUntilTarget === 0) {
@@ -6804,15 +6820,19 @@ var PDFPageTree = class PDFPageTree extends PDFDict {
6804
6820
  for (let idx = 0, len = Kids.size(); idx < len; idx++) {
6805
6821
  const kidRef = Kids.get(idx);
6806
6822
  const kid = this.context.lookup(kidRef);
6807
- if (kid instanceof PDFPageTree) if (kid.Count().asNumber() > leafsRemainingUntilTarget) {
6808
- kid.removeLeafNode(leafsRemainingUntilTarget, prune);
6809
- if (prune && kid.Kids().size() === 0) Kids.remove(idx);
6810
- return;
6811
- } else leafsRemainingUntilTarget -= kid.Count().asNumber();
6812
- if (kid instanceof PDFPageLeaf) if (leafsRemainingUntilTarget === 0) {
6813
- this.removeKid(idx);
6814
- return;
6815
- } else leafsRemainingUntilTarget -= 1;
6823
+ if (kid instanceof PDFPageTree) {
6824
+ if (kid.Count().asNumber() > leafsRemainingUntilTarget) {
6825
+ kid.removeLeafNode(leafsRemainingUntilTarget, prune);
6826
+ if (prune && kid.Kids().size() === 0) Kids.remove(idx);
6827
+ return;
6828
+ } else leafsRemainingUntilTarget -= kid.Count().asNumber();
6829
+ }
6830
+ if (kid instanceof PDFPageLeaf) {
6831
+ if (leafsRemainingUntilTarget === 0) {
6832
+ this.removeKid(idx);
6833
+ return;
6834
+ } else leafsRemainingUntilTarget -= 1;
6835
+ }
6816
6836
  }
6817
6837
  throw new CorruptPageTreeError(targetIndex, "removeLeafNode");
6818
6838
  }
@@ -6911,13 +6931,15 @@ var BaseParser = class {
6911
6931
  }
6912
6932
  const numberValue = Number(value);
6913
6933
  if (!value || !isFinite(numberValue)) throw new NumberParsingError(this.bytes.position(), value);
6914
- if (numberValue > Number.MAX_SAFE_INTEGER) if (this.capNumbers) {
6915
- const msg = `Parsed number that is too large for some PDF readers: ${value}, using Number.MAX_SAFE_INTEGER instead.`;
6916
- console.warn(msg);
6917
- return Number.MAX_SAFE_INTEGER;
6918
- } else {
6919
- const msg = `Parsed number that is too large for some PDF readers: ${value}, not capping.`;
6920
- console.warn(msg);
6934
+ if (numberValue > Number.MAX_SAFE_INTEGER) {
6935
+ if (this.capNumbers) {
6936
+ const msg = `Parsed number that is too large for some PDF readers: ${value}, using Number.MAX_SAFE_INTEGER instead.`;
6937
+ console.warn(msg);
6938
+ return Number.MAX_SAFE_INTEGER;
6939
+ } else {
6940
+ const msg = `Parsed number that is too large for some PDF readers: ${value}, not capping.`;
6941
+ console.warn(msg);
6942
+ }
6921
6943
  }
6922
6944
  return numberValue;
6923
6945
  }
@@ -8069,15 +8091,17 @@ var parse$2 = (path) => {
8069
8091
  curArg += c;
8070
8092
  if (c === ".") foundDecimal = true;
8071
8093
  }
8072
- if (curArg.length > 0) if (args.length === params) {
8073
- ret[ret.length] = {
8074
- cmd,
8075
- args
8076
- };
8077
- args = [+curArg];
8078
- if (cmd === "M") cmd = "L";
8079
- if (cmd === "m") cmd = "l";
8080
- } else args[args.length] = +curArg;
8094
+ if (curArg.length > 0) {
8095
+ if (args.length === params) {
8096
+ ret[ret.length] = {
8097
+ cmd,
8098
+ args
8099
+ };
8100
+ args = [+curArg];
8101
+ if (cmd === "M") cmd = "L";
8102
+ if (cmd === "m") cmd = "l";
8103
+ } else args[args.length] = +curArg;
8104
+ }
8081
8105
  ret[ret.length] = {
8082
8106
  cmd,
8083
8107
  args
@@ -8297,16 +8321,20 @@ var arcToSegments = (x, y, rx, ry, large, sweep, rotateX, ox, oy) => {
8297
8321
  else if (thArc > 0 && sweep === 0) thArc -= 2 * Math.PI;
8298
8322
  const segments = Math.ceil(Math.abs(thArc / (Math.PI * .5 + .001)));
8299
8323
  const result = [];
8300
- for (let i = 0; i < segments; i++) result[i] = [
8301
- xc,
8302
- yc,
8303
- th0 + i * thArc / segments,
8304
- th0 + (i + 1) * thArc / segments,
8305
- rx,
8306
- ry,
8307
- sinTh,
8308
- cosTh
8309
- ];
8324
+ for (let i = 0; i < segments; i++) {
8325
+ const th2 = th0 + i * thArc / segments;
8326
+ const th3 = th0 + (i + 1) * thArc / segments;
8327
+ result[i] = [
8328
+ xc,
8329
+ yc,
8330
+ th2,
8331
+ th3,
8332
+ rx,
8333
+ ry,
8334
+ sinTh,
8335
+ cosTh
8336
+ ];
8337
+ }
8310
8338
  return result;
8311
8339
  };
8312
8340
  var segmentToBezier = (cx1, cy1, th0, th1, rx, ry, sinTh, cosTh) => {
@@ -15575,17 +15603,19 @@ var CipherTransformFactory = class {
15575
15603
  if (!Number.isInteger(algorithm) || algorithm !== 1 && algorithm !== 2 && algorithm !== 4 && algorithm !== 5) throw new Error("unsupported encryption algorithm");
15576
15604
  this.algorithm = algorithm;
15577
15605
  let keyLength = dict.get(PDFName.of("Length")).asNumber();
15578
- if (!keyLength) if (algorithm <= 3) keyLength = 40;
15579
- else {
15580
- const cfDict = dict.get(PDFName.of("CF"));
15581
- const streamCryptoName = dict.get(PDFName.of("StmF"));
15582
- if (cfDict instanceof PDFDict && streamCryptoName instanceof PDFName) {
15583
- cfDict.suppressEncryption = true;
15584
- const handlerDict = cfDict.get(PDFName.of(streamCryptoName.asString()));
15585
- let keyLen = null;
15586
- if (handlerDict) keyLen = handlerDict.get(PDFName.of("Length"));
15587
- keyLength = keyLen && keyLen.asNumber() || 128;
15588
- if (keyLength < 40) keyLength <<= 3;
15606
+ if (!keyLength) {
15607
+ if (algorithm <= 3) keyLength = 40;
15608
+ else {
15609
+ const cfDict = dict.get(PDFName.of("CF"));
15610
+ const streamCryptoName = dict.get(PDFName.of("StmF"));
15611
+ if (cfDict instanceof PDFDict && streamCryptoName instanceof PDFName) {
15612
+ cfDict.suppressEncryption = true;
15613
+ const handlerDict = cfDict.get(PDFName.of(streamCryptoName.asString()));
15614
+ let keyLen = null;
15615
+ if (handlerDict) keyLen = handlerDict.get(PDFName.of("Length"));
15616
+ keyLength = keyLen && keyLen.asNumber() || 128;
15617
+ if (keyLength < 40) keyLength <<= 3;
15618
+ }
15589
15619
  }
15590
15620
  }
15591
15621
  if (!Number.isInteger(keyLength) || keyLength < 40 || keyLength % 8 !== 0) throw new Error("invalid key length");
@@ -15833,7 +15863,8 @@ var PDFDocument = class PDFDocument {
15833
15863
  if (!!context.lookup(context.trailerInfo.Encrypt) && password !== void 0) {
15834
15864
  const fileIds = context.lookup(context.trailerInfo.ID, PDFArray);
15835
15865
  const encryptDict = context.lookup(context.trailerInfo.Encrypt, PDFDict);
15836
- return new PDFDocument(await PDFParser.forBytesWithOptions(bytes, parseSpeed, throwOnInvalidObject, capNumbers, new CipherTransformFactory(encryptDict, fileIds.get(0).asBytes(), password)).parseDocument(), true, updateMetadata);
15866
+ const decryptedContext = await PDFParser.forBytesWithOptions(bytes, parseSpeed, throwOnInvalidObject, capNumbers, new CipherTransformFactory(encryptDict, fileIds.get(0).asBytes(), password)).parseDocument();
15867
+ return new PDFDocument(decryptedContext, true, updateMetadata);
15837
15868
  } else return new PDFDocument(context, ignoreEncryption, updateMetadata);
15838
15869
  }
15839
15870
  /**
@@ -18380,8 +18411,10 @@ var PDFPage = class {
18380
18411
  matrix: options.matrix,
18381
18412
  clipSpaces: options.clipSpaces
18382
18413
  }));
18383
- if (options.font) if (oldFont) this.setFont(oldFont);
18384
- else this.resetFont();
18414
+ if (options.font) {
18415
+ if (oldFont) this.setFont(oldFont);
18416
+ else this.resetFont();
18417
+ }
18385
18418
  }
18386
18419
  /**
18387
18420
  * Draw an image on this page. For example: