@pdfme/pdf-lib 6.1.11 → 6.1.12-dev.3

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/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import ColorParser from "color";
5
5
  import { NodeType, parse } from "node-html-better-parser";
6
6
  //#region src/utils/base64.ts
7
7
  var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
8
- var lookup = new Uint8Array(256);
8
+ var lookup = /* @__PURE__ */ new Uint8Array(256);
9
9
  for (let i = 0; i < 64; i++) lookup[chars.charCodeAt(i)] = i;
10
10
  var encodeToBase64 = (bytes) => {
11
11
  let base64 = "";
@@ -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);
@@ -756,7 +757,7 @@ var assertPositive = (value, valueName) => {
756
757
  };
757
758
  //#endregion
758
759
  //#region src/utils/pdfDocEncoding.ts
759
- var pdfDocEncodingToUnicode = new Uint16Array(256);
760
+ var pdfDocEncodingToUnicode = /* @__PURE__ */ new Uint16Array(256);
760
761
  for (let idx = 0; idx < 256; idx++) pdfDocEncodingToUnicode[idx] = idx;
761
762
  pdfDocEncodingToUnicode[22] = toCharCode("");
762
763
  pdfDocEncodingToUnicode[24] = toCharCode("˘");
@@ -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.132.0/helpers/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.132.0/helpers/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.132.0/helpers/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.132.0/helpers/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,
@@ -1335,7 +1336,7 @@ _defineProperty(PDFBool, "True", new _PDFBool(ENFORCER$2, true));
1335
1336
  _defineProperty(PDFBool, "False", new _PDFBool(ENFORCER$2, false));
1336
1337
  //#endregion
1337
1338
  //#region src/core/syntax/Delimiters.ts
1338
- var IsDelimiter = new Uint8Array(256);
1339
+ var IsDelimiter = /* @__PURE__ */ new Uint8Array(256);
1339
1340
  IsDelimiter[CharCodes.LeftParen] = 1;
1340
1341
  IsDelimiter[CharCodes.RightParen] = 1;
1341
1342
  IsDelimiter[CharCodes.LessThan] = 1;
@@ -1348,7 +1349,7 @@ IsDelimiter[CharCodes.ForwardSlash] = 1;
1348
1349
  IsDelimiter[CharCodes.Percent] = 1;
1349
1350
  //#endregion
1350
1351
  //#region src/core/syntax/Whitespace.ts
1351
- var IsWhitespace = new Uint8Array(256);
1352
+ var IsWhitespace = /* @__PURE__ */ new Uint8Array(256);
1352
1353
  IsWhitespace[CharCodes.Null] = 1;
1353
1354
  IsWhitespace[CharCodes.Tab] = 1;
1354
1355
  IsWhitespace[CharCodes.Newline] = 1;
@@ -1357,7 +1358,7 @@ IsWhitespace[CharCodes.CarriageReturn] = 1;
1357
1358
  IsWhitespace[CharCodes.Space] = 1;
1358
1359
  //#endregion
1359
1360
  //#region src/core/syntax/Irregular.ts
1360
- var IsIrregular = new Uint8Array(256);
1361
+ var IsIrregular = /* @__PURE__ */ new Uint8Array(256);
1361
1362
  for (let idx = 0, len = 256; idx < len; idx++) IsIrregular[idx] = IsWhitespace[idx] || IsDelimiter[idx] ? 1 : 0;
1362
1363
  IsIrregular[CharCodes.Hash] = 1;
1363
1364
  //#endregion
@@ -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));
@@ -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);
@@ -3849,12 +3858,12 @@ var Stream = class Stream {
3849
3858
  };
3850
3859
  //#endregion
3851
3860
  //#region src/core/streams/DecodeStream.ts
3852
- var emptyBuffer = new Uint8Array(0);
3861
+ var emptyBuffer = /* @__PURE__ */ new Uint8Array(0);
3853
3862
  /**
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
  */
@@ -3970,7 +3979,7 @@ var Ascii85Stream = class extends DecodeStream {
3970
3979
  _defineProperty(this, "stream", void 0);
3971
3980
  _defineProperty(this, "input", void 0);
3972
3981
  this.stream = stream;
3973
- this.input = new Uint8Array(5);
3982
+ this.input = /* @__PURE__ */ new Uint8Array(5);
3974
3983
  if (maybeLength) maybeLength = .8 * maybeLength;
3975
3984
  }
3976
3985
  readBlock() {
@@ -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
  }
@@ -6860,7 +6880,7 @@ _defineProperty(PDFPageTree, "withContext", (context, parent) => {
6860
6880
  _defineProperty(PDFPageTree, "fromMapWithContext", (map, context) => new _PDFPageTree(map, context));
6861
6881
  //#endregion
6862
6882
  //#region src/core/syntax/Numeric.ts
6863
- var IsDigit = new Uint8Array(256);
6883
+ var IsDigit = /* @__PURE__ */ new Uint8Array(256);
6864
6884
  IsDigit[CharCodes.Zero] = 1;
6865
6885
  IsDigit[CharCodes.One] = 1;
6866
6886
  IsDigit[CharCodes.Two] = 1;
@@ -6871,11 +6891,11 @@ IsDigit[CharCodes.Six] = 1;
6871
6891
  IsDigit[CharCodes.Seven] = 1;
6872
6892
  IsDigit[CharCodes.Eight] = 1;
6873
6893
  IsDigit[CharCodes.Nine] = 1;
6874
- var IsNumericPrefix = new Uint8Array(256);
6894
+ var IsNumericPrefix = /* @__PURE__ */ new Uint8Array(256);
6875
6895
  IsNumericPrefix[CharCodes.Period] = 1;
6876
6896
  IsNumericPrefix[CharCodes.Plus] = 1;
6877
6897
  IsNumericPrefix[CharCodes.Minus] = 1;
6878
- var IsNumeric = new Uint8Array(256);
6898
+ var IsNumeric = /* @__PURE__ */ new Uint8Array(256);
6879
6899
  for (let idx = 0, len = 256; idx < len; idx++) IsNumeric[idx] = IsDigit[idx] || IsNumericPrefix[idx] ? 1 : 0;
6880
6900
  //#endregion
6881
6901
  //#region src/core/parser/BaseParser.ts
@@ -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
  }
@@ -8010,7 +8032,7 @@ var px = 0;
8010
8032
  var py = 0;
8011
8033
  var sx = 0;
8012
8034
  var sy = 0;
8013
- var parameters = new Map([
8035
+ var parameters = /* @__PURE__ */ new Map([
8014
8036
  ["A", 7],
8015
8037
  ["a", 7],
8016
8038
  ["C", 6],
@@ -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) => {
@@ -13287,7 +13315,7 @@ var ARCFourCipher = class {
13287
13315
  _defineProperty(this, "b", void 0);
13288
13316
  this.a = 0;
13289
13317
  this.b = 0;
13290
- const s = new Uint8Array(256);
13318
+ const s = /* @__PURE__ */ new Uint8Array(256);
13291
13319
  const keyLength = key.length;
13292
13320
  for (let i = 0; i < 256; ++i) s[i] = i;
13293
13321
  for (let i = 0, j = 0; i < 256; ++i) {
@@ -13473,7 +13501,7 @@ var calculateMD5 = (function calculateMD5Closure() {
13473
13501
  padded[i++] = 0;
13474
13502
  padded[i++] = 0;
13475
13503
  padded[i++] = 0;
13476
- const w = new Int32Array(16);
13504
+ const w = /* @__PURE__ */ new Int32Array(16);
13477
13505
  for (i = 0; i < paddedLength;) {
13478
13506
  for (j = 0; j < 16; ++j, i += 4) w[j] = padded[i] | padded[i + 1] << 8 | padded[i + 2] << 16 | padded[i + 3] << 24;
13479
13507
  let a = h0, b = h1, c = h2, d = h3, f, g;
@@ -13704,7 +13732,7 @@ var calculateSHA256 = (function calculateSHA256Closure() {
13704
13732
  padded[i++] = length >> 13 & 255;
13705
13733
  padded[i++] = length >> 5 & 255;
13706
13734
  padded[i++] = length << 3 & 255;
13707
- const w = new Uint32Array(64);
13735
+ const w = /* @__PURE__ */ new Uint32Array(64);
13708
13736
  for (i = 0; i < paddedLength;) {
13709
13737
  for (j = 0; j < 16; ++j) {
13710
13738
  w[j] = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
@@ -14020,7 +14048,7 @@ var calculateSHA512 = (function calculateSHA512Closure() {
14020
14048
  }
14021
14049
  let result;
14022
14050
  if (!mode384) {
14023
- result = new Uint8Array(64);
14051
+ result = /* @__PURE__ */ new Uint8Array(64);
14024
14052
  h0.copyTo(result, 0);
14025
14053
  h1.copyTo(result, 8);
14026
14054
  h2.copyTo(result, 16);
@@ -14030,7 +14058,7 @@ var calculateSHA512 = (function calculateSHA512Closure() {
14030
14058
  h6.copyTo(result, 48);
14031
14059
  h7.copyTo(result, 56);
14032
14060
  } else {
14033
- result = new Uint8Array(48);
14061
+ result = /* @__PURE__ */ new Uint8Array(48);
14034
14062
  h0.copyTo(result, 0);
14035
14063
  h1.copyTo(result, 8);
14036
14064
  h2.copyTo(result, 16);
@@ -14841,10 +14869,10 @@ var AESBaseCipher = class AESBaseCipher {
14841
14869
  2203032232,
14842
14870
  2370213795
14843
14871
  ]);
14844
- this._mixCol = new Uint8Array(256);
14872
+ this._mixCol = /* @__PURE__ */ new Uint8Array(256);
14845
14873
  for (let i = 0; i < 256; i++) if (i < 128) this._mixCol[i] = i << 1;
14846
14874
  else this._mixCol[i] = i << 1 ^ 27;
14847
- this.buffer = new Uint8Array(16);
14875
+ this.buffer = /* @__PURE__ */ new Uint8Array(16);
14848
14876
  this.bufferPosition = 0;
14849
14877
  }
14850
14878
  _expandKey(_cipherKey) {
@@ -14852,7 +14880,7 @@ var AESBaseCipher = class AESBaseCipher {
14852
14880
  }
14853
14881
  _decrypt(input, key) {
14854
14882
  let t, u, v;
14855
- const state = new Uint8Array(16);
14883
+ const state = /* @__PURE__ */ new Uint8Array(16);
14856
14884
  state.set(input);
14857
14885
  for (let j = 0, k = this._keySize; j < 16; ++j, ++k) state[j] ^= key[k];
14858
14886
  for (let i = this._cyclesOfRepetition - 1; i >= 1; --i) {
@@ -14915,7 +14943,7 @@ var AESBaseCipher = class AESBaseCipher {
14915
14943
  _encrypt(input, key) {
14916
14944
  const s = this._s;
14917
14945
  let t, u, v;
14918
- const state = new Uint8Array(16);
14946
+ const state = /* @__PURE__ */ new Uint8Array(16);
14919
14947
  state.set(input);
14920
14948
  for (let j = 0; j < 16; ++j) state[j] ^= key[j];
14921
14949
  for (let i = 1; i < this._cyclesOfRepetition; i++) {
@@ -14986,13 +15014,13 @@ var AESBaseCipher = class AESBaseCipher {
14986
15014
  for (let j = 0; j < 16; ++j) plain[j] ^= iv[j];
14987
15015
  iv = buffer;
14988
15016
  result.push(plain);
14989
- buffer = new Uint8Array(16);
15017
+ buffer = /* @__PURE__ */ new Uint8Array(16);
14990
15018
  bufferLength = 0;
14991
15019
  }
14992
15020
  this.buffer = buffer;
14993
15021
  this.bufferLength = bufferLength;
14994
15022
  this.iv = iv;
14995
- if (result.length === 0) return new Uint8Array(0);
15023
+ if (result.length === 0) return /* @__PURE__ */ new Uint8Array(0);
14996
15024
  let outputLength = 16 * result.length;
14997
15025
  if (finalize) {
14998
15026
  const lastBlock = result[result.length - 1];
@@ -15019,12 +15047,12 @@ var AESBaseCipher = class AESBaseCipher {
15019
15047
  for (let i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) buffer[bufferLength] = data[i];
15020
15048
  if (bufferLength < 16) {
15021
15049
  this.bufferLength = bufferLength;
15022
- return new Uint8Array(0);
15050
+ return /* @__PURE__ */ new Uint8Array(0);
15023
15051
  }
15024
15052
  this.iv = buffer;
15025
15053
  data = data.subarray(16);
15026
15054
  }
15027
- this.buffer = new Uint8Array(16);
15055
+ this.buffer = /* @__PURE__ */ new Uint8Array(16);
15028
15056
  this.bufferLength = 0;
15029
15057
  this.decryptBlock = this._decryptBlock2;
15030
15058
  return this.decryptBlock(data, finalize);
@@ -15033,7 +15061,7 @@ var AESBaseCipher = class AESBaseCipher {
15033
15061
  const sourceLength = data.length;
15034
15062
  let buffer = this.buffer, bufferLength = this.bufferPosition;
15035
15063
  const result = [];
15036
- if (!iv) iv = new Uint8Array(16);
15064
+ if (!iv) iv = /* @__PURE__ */ new Uint8Array(16);
15037
15065
  for (let i = 0; i < sourceLength; ++i) {
15038
15066
  buffer[bufferLength] = data[i];
15039
15067
  ++bufferLength;
@@ -15042,13 +15070,13 @@ var AESBaseCipher = class AESBaseCipher {
15042
15070
  const cipher = this._encrypt(buffer, this._key);
15043
15071
  iv = cipher;
15044
15072
  result.push(cipher);
15045
- buffer = new Uint8Array(16);
15073
+ buffer = /* @__PURE__ */ new Uint8Array(16);
15046
15074
  bufferLength = 0;
15047
15075
  }
15048
15076
  this.buffer = buffer;
15049
15077
  this.bufferLength = bufferLength;
15050
15078
  this.iv = iv;
15051
- if (result.length === 0) return new Uint8Array(0);
15079
+ if (result.length === 0) return /* @__PURE__ */ new Uint8Array(0);
15052
15080
  const outputLength = 16 * result.length;
15053
15081
  const output = new Uint8Array(outputLength);
15054
15082
  for (let i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) output.set(result[i], j);
@@ -15416,13 +15444,13 @@ var PDF17 = class {
15416
15444
  hashData.set(password, 0);
15417
15445
  hashData.set(ownerKeySalt, password.length);
15418
15446
  hashData.set(userBytes, password.length + ownerKeySalt.length);
15419
- return new AES256Cipher(calculateSHA256(hashData, 0, hashData.length)).decryptBlock(ownerEncryption, false, new Uint8Array(16));
15447
+ return new AES256Cipher(calculateSHA256(hashData, 0, hashData.length)).decryptBlock(ownerEncryption, false, /* @__PURE__ */ new Uint8Array(16));
15420
15448
  }
15421
15449
  getUserKey(password, userKeySalt, userEncryption) {
15422
15450
  const hashData = new Uint8Array(password.length + 8);
15423
15451
  hashData.set(password, 0);
15424
15452
  hashData.set(userKeySalt, password.length);
15425
- return new AES256Cipher(calculateSHA256(hashData, 0, hashData.length)).decryptBlock(userEncryption, false, new Uint8Array(16));
15453
+ return new AES256Cipher(calculateSHA256(hashData, 0, hashData.length)).decryptBlock(userEncryption, false, /* @__PURE__ */ new Uint8Array(16));
15426
15454
  }
15427
15455
  };
15428
15456
  var PDF20 = class {
@@ -15463,20 +15491,20 @@ var PDF20 = class {
15463
15491
  const hashData = new Uint8Array(password.length + 8);
15464
15492
  hashData.set(password, 0);
15465
15493
  hashData.set(userValidationSalt, password.length);
15466
- return isArrayEqual(this.calculatePDF20Hash(password, hashData, new Uint8Array()), userPassword);
15494
+ return isArrayEqual(this.calculatePDF20Hash(password, hashData, /* @__PURE__ */ new Uint8Array()), userPassword);
15467
15495
  }
15468
15496
  getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
15469
15497
  const hashData = new Uint8Array(password.length + 56);
15470
15498
  hashData.set(password, 0);
15471
15499
  hashData.set(ownerKeySalt, password.length);
15472
15500
  hashData.set(userBytes, password.length + ownerKeySalt.length);
15473
- return new AES256Cipher(this.calculatePDF20Hash(password, hashData, userBytes)).decryptBlock(ownerEncryption, false, new Uint8Array(16));
15501
+ return new AES256Cipher(this.calculatePDF20Hash(password, hashData, userBytes)).decryptBlock(ownerEncryption, false, /* @__PURE__ */ new Uint8Array(16));
15474
15502
  }
15475
15503
  getUserKey(password, userKeySalt, userEncryption) {
15476
15504
  const hashData = new Uint8Array(password.length + 8);
15477
15505
  hashData.set(password, 0);
15478
15506
  hashData.set(userKeySalt, password.length);
15479
- return new AES256Cipher(this.calculatePDF20Hash(password, hashData, new Uint8Array())).decryptBlock(userEncryption, false, new Uint8Array(16));
15507
+ return new AES256Cipher(this.calculatePDF20Hash(password, hashData, /* @__PURE__ */ new Uint8Array())).decryptBlock(userEncryption, false, /* @__PURE__ */ new Uint8Array(16));
15480
15508
  }
15481
15509
  };
15482
15510
  var CipherTransform = class {
@@ -15506,7 +15534,7 @@ var CipherTransform = class {
15506
15534
  if (cipher instanceof AESBaseCipher) {
15507
15535
  const pad = 16 - s.length % 16;
15508
15536
  s += String.fromCharCode(pad).repeat(pad);
15509
- const iv = new Uint8Array(16);
15537
+ const iv = /* @__PURE__ */ new Uint8Array(16);
15510
15538
  if (typeof crypto !== "undefined") crypto.getRandomValues(iv);
15511
15539
  else for (let i = 0; i < 16; i++) iv[i] = Math.floor(256 * Math.random());
15512
15540
  let data = stringAsByteArray(s);
@@ -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");
@@ -15647,7 +15677,7 @@ var CipherTransformFactory = class {
15647
15677
  if (password) {
15648
15678
  const passwordLength = Math.min(127, password.length);
15649
15679
  password = password.subarray(0, passwordLength);
15650
- } else password = new Uint8Array();
15680
+ } else password = /* @__PURE__ */ new Uint8Array();
15651
15681
  let pdfAlgorithm;
15652
15682
  if (revision === 6) pdfAlgorithm = new PDF20();
15653
15683
  else pdfAlgorithm = new PDF17();
@@ -15703,7 +15733,7 @@ var CipherTransformFactory = class {
15703
15733
  return encryptionKey;
15704
15734
  }
15705
15735
  decodeUserPassword(password, ownerPassword, revision, keyLength) {
15706
- const hashData = new Uint8Array(32);
15736
+ const hashData = /* @__PURE__ */ new Uint8Array(32);
15707
15737
  let i = 0;
15708
15738
  const n = Math.min(32, password.length);
15709
15739
  for (; i < n; ++i) hashData[i] = password[i];
@@ -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: