@adnsistemas/pdf-lib 2.9.0 → 2.9.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/dist/pdf-lib.js CHANGED
@@ -8680,34 +8680,39 @@
8680
8680
  constructor(map, context) {
8681
8681
  super();
8682
8682
  this.suppressEncryption = false;
8683
- this.dict = map;
8683
+ this.dict = new Map(Array.from(map.entries()).map((entry) => [entry[0].toString(), entry]));
8684
8684
  this.context = context;
8685
8685
  }
8686
8686
  keys() {
8687
- return Array.from(this.dict.keys());
8687
+ return Array.from(this.dict.values()).map((value) => value[0]);
8688
8688
  }
8689
8689
  values() {
8690
- return Array.from(this.dict.values());
8690
+ return Array.from(this.dict.values()).map((value) => value[1]);
8691
8691
  }
8692
8692
  entries() {
8693
- return Array.from(this.dict.entries());
8693
+ return Array.from(this.dict.values());
8694
8694
  }
8695
8695
  set(key, value) {
8696
8696
  this.registerChange();
8697
- this.dict.set(key, value);
8697
+ this.dict.set(key.asString(), [key, value]);
8698
8698
  }
8699
8699
  get(key,
8700
8700
  // TODO: `preservePDFNull` is for backwards compatibility. Should be
8701
8701
  // removed in next breaking API change.
8702
8702
  preservePDFNull = false) {
8703
- const value = this.dict.get(key);
8704
- if (value === PDFNull$1 && !preservePDFNull)
8703
+ if (!key.asString)
8705
8704
  return undefined;
8706
- return value;
8705
+ const value = this.dict.get(key.asString());
8706
+ if (!value ||
8707
+ (isPDFInstance(value[1], exports.PDFClasses.PDFNull) && !preservePDFNull))
8708
+ return undefined;
8709
+ return value[1];
8707
8710
  }
8708
8711
  has(key) {
8709
- const value = this.dict.get(key);
8710
- return value !== undefined && value !== PDFNull$1;
8712
+ if (!key.asString)
8713
+ return false;
8714
+ const value = this.dict.get(key.asString());
8715
+ return value !== undefined && !isPDFInstance(value[1], exports.PDFClasses.PDFNull);
8711
8716
  }
8712
8717
  lookupMaybe(key, ...types) {
8713
8718
  // TODO: `preservePDFNull` is for backwards compatibility. Should be
@@ -8716,7 +8721,7 @@
8716
8721
  const value = this.context.lookupMaybe(this.get(key, preservePDFNull),
8717
8722
  // @ts-ignore
8718
8723
  ...types);
8719
- if (value === PDFNull$1 && !preservePDFNull)
8724
+ if (isPDFInstance(value, exports.PDFClasses.PDFNull) && !preservePDFNull)
8720
8725
  return undefined;
8721
8726
  return value;
8722
8727
  }
@@ -8727,16 +8732,16 @@
8727
8732
  const value = this.context.lookup(this.get(key, preservePDFNull),
8728
8733
  // @ts-ignore
8729
8734
  ...types);
8730
- if (value === PDFNull$1 && !preservePDFNull)
8735
+ if (isPDFInstance(value, exports.PDFClasses.PDFNull) && !preservePDFNull)
8731
8736
  return undefined;
8732
8737
  return value;
8733
8738
  }
8734
8739
  delete(key) {
8735
8740
  this.registerChange();
8736
- return this.dict.delete(key);
8741
+ return this.dict.delete(key.asString());
8737
8742
  }
8738
8743
  asMap() {
8739
- return new Map(this.dict);
8744
+ return new Map(this.dict.values());
8740
8745
  }
8741
8746
  /** Generate a random key that doesn't exist in current key set */
8742
8747
  uniqueKey(tag = '') {
@@ -9263,18 +9268,18 @@
9263
9268
  }
9264
9269
  assign(ref, object) {
9265
9270
  if (this.preserveObjectsVersions) {
9266
- const prevOV = this.indirectObjects.get(ref);
9271
+ const prevOV = this.indirectObjects.get(ref.toString());
9267
9272
  if (prevOV) {
9268
- const prevList = this.objectsPreviousVersions.get(ref);
9273
+ const prevList = this.objectsPreviousVersions.get(ref.toString());
9269
9274
  if (!prevList) {
9270
- this.objectsPreviousVersions.set(ref, [prevOV]);
9275
+ this.objectsPreviousVersions.set(ref.toString(), [prevOV[1]]);
9271
9276
  }
9272
9277
  else {
9273
- prevList.unshift(prevOV);
9278
+ prevList.unshift(prevOV[1]);
9274
9279
  }
9275
9280
  }
9276
9281
  }
9277
- this.indirectObjects.set(ref, object);
9282
+ this.indirectObjects.set(ref.toString(), [ref, object]);
9278
9283
  if (ref.objectNumber > this.largestObjectNumber) {
9279
9284
  this.largestObjectNumber = ref.objectNumber;
9280
9285
  }
@@ -9295,27 +9300,32 @@
9295
9300
  if (this.snapshot)
9296
9301
  this.snapshot.markDeletedRef(ref);
9297
9302
  if (this.preserveObjectsVersions) {
9298
- const object = this.indirectObjects.get(ref);
9303
+ const object = this.indirectObjects.get(ref.toString());
9299
9304
  if (object) {
9300
9305
  // check is not already deleted
9301
- const verlist = this.objectsPreviousVersions.get(ref);
9306
+ const verlist = this.objectsPreviousVersions.get(ref.toString());
9302
9307
  if (verlist) {
9303
- verlist.unshift(object);
9308
+ verlist.unshift(object[1]);
9304
9309
  }
9305
9310
  else {
9306
- this.objectsPreviousVersions.set(ref, [object]);
9311
+ this.objectsPreviousVersions.set(ref.toString(), [object[1]]);
9307
9312
  }
9308
9313
  }
9309
9314
  }
9310
- return this.indirectObjects.delete(ref);
9315
+ return this.indirectObjects.delete(ref.toString());
9311
9316
  }
9312
9317
  lookupMaybe(ref, ...types) {
9313
9318
  // TODO: `preservePDFNull` is for backwards compatibility. Should be
9314
9319
  // removed in next breaking API change.
9315
9320
  const preservePDFNull = types.includes(PDFNull$1);
9316
- const result = isPDFInstance(ref, exports.PDFClasses.PDFRef)
9317
- ? this.indirectObjects.get(ref)
9318
- : ref;
9321
+ let result;
9322
+ if (isPDFInstance(ref, exports.PDFClasses.PDFRef)) {
9323
+ const iobj = this.indirectObjects.get(ref.toString());
9324
+ result = iobj ? iobj[1] : undefined;
9325
+ }
9326
+ else {
9327
+ result = ref;
9328
+ }
9319
9329
  if (!result ||
9320
9330
  (isPDFInstance(result, exports.PDFClasses.PDFNull) && !preservePDFNull))
9321
9331
  return undefined;
@@ -9330,9 +9340,14 @@
9330
9340
  throw new UnexpectedObjectTypeError(types, result);
9331
9341
  }
9332
9342
  lookup(ref, ...types) {
9333
- const result = isPDFInstance(ref, exports.PDFClasses.PDFRef)
9334
- ? this.indirectObjects.get(ref)
9335
- : ref;
9343
+ let result;
9344
+ if (isPDFInstance(ref, exports.PDFClasses.PDFRef)) {
9345
+ const iobj = this.indirectObjects.get(ref.toString());
9346
+ result = iobj ? iobj[1] : undefined;
9347
+ }
9348
+ else {
9349
+ result = ref;
9350
+ }
9336
9351
  if (types.length === 0)
9337
9352
  return result;
9338
9353
  for (let idx = 0, len = types.length; idx < len; idx++) {
@@ -9351,7 +9366,7 @@
9351
9366
  return this.getObjectRef(pdfObject);
9352
9367
  }
9353
9368
  getObjectRef(pdfObject) {
9354
- const entries = Array.from(this.indirectObjects.entries());
9369
+ const entries = Array.from(this.indirectObjects.values());
9355
9370
  for (let idx = 0, len = entries.length; idx < len; idx++) {
9356
9371
  const [ref, object] = entries[idx];
9357
9372
  if (object === pdfObject) {
@@ -9361,7 +9376,7 @@
9361
9376
  return undefined;
9362
9377
  }
9363
9378
  enumerateIndirectObjects() {
9364
- return Array.from(this.indirectObjects.entries()).sort(byAscendingObjectNumber);
9379
+ return Array.from(this.indirectObjects.values()).sort(byAscendingObjectNumber);
9365
9380
  }
9366
9381
  obj(literal) {
9367
9382
  if (isPDFInstance(literal, exports.PDFClasses.PDFObject)) {
@@ -9502,7 +9517,7 @@
9502
9517
  }
9503
9518
  }
9504
9519
  findContainingIndirectObject(target) {
9505
- const entries = Array.from(this.indirectObjects.entries());
9520
+ const entries = Array.from(this.indirectObjects.values());
9506
9521
  for (let idx = 0, len = entries.length; idx < len; idx++) {
9507
9522
  const [ref, object] = entries[idx];
9508
9523
  if (this.objectContains(object, target)) {
@@ -9536,7 +9551,7 @@
9536
9551
  getObjectVersions(ref) {
9537
9552
  if (!this.preserveObjectsVersions)
9538
9553
  return [];
9539
- const list = this.objectsPreviousVersions.get(ref);
9554
+ const list = this.objectsPreviousVersions.get(ref.toString());
9540
9555
  if (list)
9541
9556
  return list;
9542
9557
  return [];
@@ -37738,7 +37753,7 @@ end\
37738
37753
  const changed = new Map();
37739
37754
  for (const entry of entries) {
37740
37755
  const ref = entry.ref;
37741
- changed.set(ref, {
37756
+ changed.set(ref.toString(), {
37742
37757
  ref,
37743
37758
  actual: entry.deleted ? undefined : this.context.lookup(ref),
37744
37759
  previous: this.context.getObjectVersions(ref),
@@ -37746,13 +37761,13 @@ end\
37746
37761
  }
37747
37762
  // if not the las update, then check objects later modified and adjust PDFObjectVersions accordingly
37748
37763
  if (!lastUpdateMinusX)
37749
- return Array.from(changed.entries()).map((value) => value[1]);
37764
+ return Array.from(changed.values());
37750
37765
  while (lastUpdateMinusX) {
37751
37766
  lastUpdateMinusX -= 1;
37752
37767
  const upind = this.context.xrefs.length - lastUpdateMinusX - 1;
37753
37768
  const nentries = this.context.listXrefEntries(upind);
37754
37769
  for (const nentry of nentries) {
37755
- const oce = changed.get(nentry.ref);
37770
+ const oce = changed.get(nentry.ref.toString());
37756
37771
  if (oce && oce.actual) {
37757
37772
  oce.actual = oce.previous[0];
37758
37773
  oce.previous = oce.previous.slice(1);
@@ -37760,9 +37775,7 @@ end\
37760
37775
  }
37761
37776
  }
37762
37777
  // if PDF has errors, it may happen to end with objects that has no current, nor previous versions
37763
- return Array.from(changed.entries())
37764
- .map((value) => value[1])
37765
- .filter((ov) => ov.actual || ov.previous.length);
37778
+ return Array.from(changed.values()).filter((ov) => ov.actual || ov.previous.length);
37766
37779
  }
37767
37780
  /**
37768
37781
  * Saves the current changes to the document as an incremental update, returns the full document,