@chialab/pdfjs-lib 1.0.0-alpha.24 → 1.0.0-alpha.26

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 (28) hide show
  1. package/dist/browser/{chunk-W3YEFTNG.js → chunk-YWSFNHP3.js} +23 -5
  2. package/dist/browser/index.js +6775 -5170
  3. package/dist/browser/worker.js +460 -180
  4. package/dist/lib/Path2D.d.ts +8 -48
  5. package/dist/node/{NodeUtils-EDBNTTIR.js → NodeUtils-ZGLDDB6J.js} +2 -2
  6. package/dist/node/{chunk-ZKUTXCS2.js → chunk-AC5JE2E3.js} +1 -1
  7. package/dist/node/{chunk-K6VD27AD.js → chunk-GVC6TP3T.js} +4 -1
  8. package/dist/node/{chunk-XMKSLA4K.js → chunk-YDSKBMQ3.js} +23 -5
  9. package/dist/node/index.js +6776 -5174
  10. package/dist/node/worker.js +461 -181
  11. package/dist/pdf.js/src/display/annotation_layer.d.ts +9 -0
  12. package/dist/pdf.js/src/display/api.d.ts +43 -6
  13. package/dist/pdf.js/src/display/canvas.d.ts +82 -80
  14. package/dist/pdf.js/src/display/canvas_dependency_tracker.d.ts +144 -0
  15. package/dist/pdf.js/src/display/editor/annotation_editor_layer.d.ts +1 -1
  16. package/dist/pdf.js/src/display/editor/color_picker.d.ts +19 -0
  17. package/dist/pdf.js/src/display/editor/comment.d.ts +32 -0
  18. package/dist/pdf.js/src/display/editor/draw.d.ts +1 -1
  19. package/dist/pdf.js/src/display/editor/editor.d.ts +27 -2
  20. package/dist/pdf.js/src/display/editor/freetext.d.ts +7 -0
  21. package/dist/pdf.js/src/display/editor/highlight.d.ts +1 -0
  22. package/dist/pdf.js/src/display/editor/ink.d.ts +4 -0
  23. package/dist/pdf.js/src/display/editor/toolbar.d.ts +2 -1
  24. package/dist/pdf.js/src/display/editor/tools.d.ts +11 -3
  25. package/dist/pdf.js/src/pdf.d.ts +2 -1
  26. package/dist/pdf.js/src/shared/util.d.ts +6 -2
  27. package/dist/pdf.js/web/interfaces.d.ts +7 -0
  28. package/package.json +1 -1
@@ -61,12 +61,13 @@ import {
61
61
  utf8StringToString,
62
62
  warn,
63
63
  wrapReason
64
- } from "./chunk-W3YEFTNG.js";
64
+ } from "./chunk-YWSFNHP3.js";
65
65
  import {
66
66
  __privateAdd,
67
67
  __privateGet,
68
68
  __privateMethod,
69
69
  __privateSet,
70
+ __privateWrapper,
70
71
  __publicField
71
72
  } from "./chunk-O4UKW7AD.js";
72
73
 
@@ -209,6 +210,33 @@ var Dict = class _Dict {
209
210
  }
210
211
  this._map.set(key, value);
211
212
  }
213
+ setIfNotExists(key, value) {
214
+ if (!this.has(key)) {
215
+ this.set(key, value);
216
+ }
217
+ }
218
+ setIfNumber(key, value) {
219
+ if (typeof value === "number") {
220
+ this.set(key, value);
221
+ }
222
+ }
223
+ setIfArray(key, value) {
224
+ if (Array.isArray(value) || ArrayBuffer.isView(value)) {
225
+ this.set(key, value);
226
+ }
227
+ }
228
+ setIfDefined(key, value) {
229
+ if (value !== void 0 && value !== null) {
230
+ this.set(key, value);
231
+ }
232
+ }
233
+ setIfName(key, value) {
234
+ if (typeof value === "string") {
235
+ this.set(key, Name.get(value));
236
+ } else if (value instanceof Name) {
237
+ this.set(key, value);
238
+ }
239
+ }
212
240
  has(key) {
213
241
  return this._map.has(key);
214
242
  }
@@ -765,7 +793,7 @@ function _collectJS(entry, xref, list, parents) {
765
793
  true
766
794
  ).replaceAll("\0", ""));
767
795
  if (code) {
768
- list.push(code);
796
+ list.push(code.trim());
769
797
  }
770
798
  }
771
799
  _collectJS(entry.getRaw("Next"), xref, list, parents);
@@ -971,6 +999,9 @@ function getNewAnnotationsMap(annotationStorage) {
971
999
  return newAnnotationsByPage.size > 0 ? newAnnotationsByPage : null;
972
1000
  }
973
1001
  function stringToAsciiOrUTF16BE(str) {
1002
+ if (str === null || str === void 0) {
1003
+ return str;
1004
+ }
974
1005
  return isAscii(str) ? str : stringToUTF16String(
975
1006
  str,
976
1007
  /* bigEndian = */
@@ -978,7 +1009,10 @@ function stringToAsciiOrUTF16BE(str) {
978
1009
  );
979
1010
  }
980
1011
  function isAscii(str) {
981
- return /^[\x00-\x7F]*$/.test(str);
1012
+ if (typeof str !== "string") {
1013
+ return false;
1014
+ }
1015
+ return !str || /^[\x00-\x7F]*$/.test(str);
982
1016
  }
983
1017
  function stringToUTF16HexString(str) {
984
1018
  const buf = [];
@@ -2268,6 +2302,9 @@ var _IccColorSpace = class _IccColorSpace extends ColorSpace {
2268
2302
  if (!__privateGet(this, _transformer)) {
2269
2303
  throw new Error("Failed to create ICC color space");
2270
2304
  }
2305
+ __privateGet(_IccColorSpace, _finalizer) || __privateSet(_IccColorSpace, _finalizer, new FinalizationRegistry((transformer) => {
2306
+ qcms_drop_transformer(transformer);
2307
+ }));
2271
2308
  __privateGet(_IccColorSpace, _finalizer).register(this, __privateGet(this, _transformer));
2272
2309
  }
2273
2310
  getRgbHex(src, srcOffset) {
@@ -2348,9 +2385,7 @@ _wasmUrl = new WeakMap();
2348
2385
  _finalizer = new WeakMap();
2349
2386
  __privateAdd(_IccColorSpace, _useWasm, true);
2350
2387
  __privateAdd(_IccColorSpace, _wasmUrl, null);
2351
- __privateAdd(_IccColorSpace, _finalizer, new FinalizationRegistry((transformer) => {
2352
- qcms_drop_transformer(transformer);
2353
- }));
2388
+ __privateAdd(_IccColorSpace, _finalizer, null);
2354
2389
  var IccColorSpace = _IccColorSpace;
2355
2390
  var _iccUrl;
2356
2391
  var _CmykICCBasedCS = class _CmykICCBasedCS extends IccColorSpace {
@@ -55853,6 +55888,22 @@ var PartialEvaluator = class _PartialEvaluator {
55853
55888
  args[0] = Math.abs(thickness);
55854
55889
  break;
55855
55890
  }
55891
+ case OPS.setDash: {
55892
+ const dashPhase = args[1];
55893
+ if (typeof dashPhase !== "number") {
55894
+ warn(`Invalid setDash: ${dashPhase}`);
55895
+ continue;
55896
+ }
55897
+ const dashArray = args[0];
55898
+ if (!Array.isArray(dashArray)) {
55899
+ warn(`Invalid setDash: ${dashArray}`);
55900
+ continue;
55901
+ }
55902
+ if (dashArray.some((x) => typeof x !== "number")) {
55903
+ args[0] = dashArray.filter((x) => typeof x === "number");
55904
+ }
55905
+ break;
55906
+ }
55856
55907
  case OPS.moveTo:
55857
55908
  case OPS.lineTo:
55858
55909
  case OPS.curveTo:
@@ -58501,11 +58552,11 @@ var FakeUnicodeFont = class _FakeUnicodeFont {
58501
58552
  get fontDescriptorRef() {
58502
58553
  if (!_FakeUnicodeFont._fontDescriptorRef) {
58503
58554
  const fontDescriptor = new Dict(this.xref);
58504
- fontDescriptor.set("Type", Name.get("FontDescriptor"));
58555
+ fontDescriptor.setIfName("Type", "FontDescriptor");
58505
58556
  fontDescriptor.set("FontName", this.fontName);
58506
58557
  fontDescriptor.set("FontFamily", "MyriadPro Regular");
58507
58558
  fontDescriptor.set("FontBBox", [0, 0, 0, 0]);
58508
- fontDescriptor.set("FontStretch", Name.get("Normal"));
58559
+ fontDescriptor.setIfName("FontStretch", "Normal");
58509
58560
  fontDescriptor.set("FontWeight", 400);
58510
58561
  fontDescriptor.set("ItalicAngle", 0);
58511
58562
  _FakeUnicodeFont._fontDescriptorRef = this.xref.getNewPersistentRef(fontDescriptor);
@@ -58515,9 +58566,9 @@ var FakeUnicodeFont = class _FakeUnicodeFont {
58515
58566
  get descendantFontRef() {
58516
58567
  const descendantFont = new Dict(this.xref);
58517
58568
  descendantFont.set("BaseFont", this.fontName);
58518
- descendantFont.set("Type", Name.get("Font"));
58519
- descendantFont.set("Subtype", Name.get("CIDFontType0"));
58520
- descendantFont.set("CIDToGIDMap", Name.get("Identity"));
58569
+ descendantFont.setIfName("Type", "Font");
58570
+ descendantFont.setIfName("Subtype", "CIDFontType0");
58571
+ descendantFont.setIfName("CIDToGIDMap", "Identity");
58521
58572
  descendantFont.set("FirstChar", this.firstChar);
58522
58573
  descendantFont.set("LastChar", this.lastChar);
58523
58574
  descendantFont.set("FontDescriptor", this.fontDescriptorRef);
@@ -58554,11 +58605,11 @@ var FakeUnicodeFont = class _FakeUnicodeFont {
58554
58605
  get baseFontRef() {
58555
58606
  const baseFont = new Dict(this.xref);
58556
58607
  baseFont.set("BaseFont", this.fontName);
58557
- baseFont.set("Type", Name.get("Font"));
58558
- baseFont.set("Subtype", Name.get("Type0"));
58559
- baseFont.set("Encoding", Name.get("Identity-H"));
58608
+ baseFont.setIfName("Type", "Font");
58609
+ baseFont.setIfName("Subtype", "Type0");
58610
+ baseFont.setIfName("Encoding", "Identity-H");
58560
58611
  baseFont.set("DescendantFonts", [this.descendantFontRef]);
58561
- baseFont.set("ToUnicode", Name.get("Identity-H"));
58612
+ baseFont.setIfName("ToUnicode", "Identity-H");
58562
58613
  return this.xref.getNewPersistentRef(baseFont);
58563
58614
  }
58564
58615
  get resources() {
@@ -58664,7 +58715,7 @@ var FakeUnicodeFont = class _FakeUnicodeFont {
58664
58715
  const r0 = new Dict(this.xref);
58665
58716
  r0.set("ca", strokeAlpha);
58666
58717
  r0.set("CA", strokeAlpha);
58667
- r0.set("Type", Name.get("ExtGState"));
58718
+ r0.setIfName("Type", "ExtGState");
58668
58719
  extGState.set("R0", r0);
58669
58720
  resources.set("ExtGState", extGState);
58670
58721
  }
@@ -58675,8 +58726,8 @@ var FakeUnicodeFont = class _FakeUnicodeFont {
58675
58726
  buffer.push("ET", "Q");
58676
58727
  const appearance = buffer.join("\n");
58677
58728
  const appearanceStreamDict = new Dict(this.xref);
58678
- appearanceStreamDict.set("Subtype", Name.get("Form"));
58679
- appearanceStreamDict.set("Type", Name.get("XObject"));
58729
+ appearanceStreamDict.setIfName("Subtype", "Form");
58730
+ appearanceStreamDict.setIfName("Type", "XObject");
58680
58731
  appearanceStreamDict.set("BBox", [0, 0, w, h]);
58681
58732
  appearanceStreamDict.set("Length", appearance.length);
58682
58733
  appearanceStreamDict.set("Resources", resources);
@@ -74064,11 +74115,12 @@ var AnnotationFactory = class {
74064
74115
  * @param {Object} idFactory
74065
74116
  * @param {boolean} [collectFields]
74066
74117
  * @param {Object} [orphanFields]
74118
+ * @param {Array<string>} [collectByType]
74067
74119
  * @param {Object} [pageRef]
74068
74120
  * @returns {Promise} A promise that is resolved with an {Annotation}
74069
74121
  * instance.
74070
74122
  */
74071
- static async create(xref, ref, annotationGlobals, idFactory, collectFields, orphanFields, pageRef) {
74123
+ static async create(xref, ref, annotationGlobals, idFactory, collectFields, orphanFields, collectByType, pageRef) {
74072
74124
  const pageIndex = collectFields ? await this._getPageIndex(xref, ref, annotationGlobals.pdfManager) : null;
74073
74125
  return annotationGlobals.pdfManager.ensure(this, "_create", [
74074
74126
  xref,
@@ -74077,6 +74129,7 @@ var AnnotationFactory = class {
74077
74129
  idFactory,
74078
74130
  collectFields,
74079
74131
  orphanFields,
74132
+ collectByType,
74080
74133
  pageIndex,
74081
74134
  pageRef
74082
74135
  ]);
@@ -74084,15 +74137,18 @@ var AnnotationFactory = class {
74084
74137
  /**
74085
74138
  * @private
74086
74139
  */
74087
- static _create(xref, ref, annotationGlobals, idFactory, collectFields = false, orphanFields = null, pageIndex = null, pageRef = null) {
74140
+ static _create(xref, ref, annotationGlobals, idFactory, collectFields = false, orphanFields = null, collectByType = null, pageIndex = null, pageRef = null) {
74088
74141
  const dict = xref.fetchIfRef(ref);
74089
74142
  if (!(dict instanceof Dict)) {
74090
74143
  return void 0;
74091
74144
  }
74092
- const { acroForm, pdfManager } = annotationGlobals;
74093
- const id = ref instanceof Ref ? ref.toString() : `annot_${idFactory.createObjId()}`;
74094
74145
  let subtype = dict.get("Subtype");
74095
74146
  subtype = subtype instanceof Name ? subtype.name : null;
74147
+ if (collectByType && !collectByType.has(AnnotationType[subtype.toUpperCase()])) {
74148
+ return null;
74149
+ }
74150
+ const { acroForm, pdfManager } = annotationGlobals;
74151
+ const id = ref instanceof Ref ? ref.toString() : `annot_${idFactory.createObjId()}`;
74096
74152
  const parameters = {
74097
74153
  xref,
74098
74154
  ref,
@@ -74237,10 +74293,10 @@ var AnnotationFactory = class {
74237
74293
  case AnnotationEditorType.FREETEXT:
74238
74294
  if (!baseFontRef) {
74239
74295
  const baseFont = new Dict(xref);
74240
- baseFont.set("BaseFont", Name.get("Helvetica"));
74241
- baseFont.set("Type", Name.get("Font"));
74242
- baseFont.set("Subtype", Name.get("Type1"));
74243
- baseFont.set("Encoding", Name.get("WinAnsiEncoding"));
74296
+ baseFont.setIfName("BaseFont", "Helvetica");
74297
+ baseFont.setIfName("Type", "Font");
74298
+ baseFont.setIfName("Subtype", "Type1");
74299
+ baseFont.setIfName("Encoding", "WinAnsiEncoding");
74244
74300
  baseFontRef = xref.getNewTemporaryRef();
74245
74301
  changes.put(baseFontRef, {
74246
74302
  data: baseFont
@@ -74301,7 +74357,7 @@ var AnnotationFactory = class {
74301
74357
  }
74302
74358
  }
74303
74359
  return {
74304
- annotations: await Promise.all(promises)
74360
+ annotations: (await Promise.all(promises)).flat()
74305
74361
  };
74306
74362
  }
74307
74363
  static async printNewAnnotations(annotationGlobals, evaluator, task, annotations, imagePromises) {
@@ -74426,8 +74482,8 @@ function getRgbColor(color, defaultColor = new Uint8ClampedArray(3)) {
74426
74482
  return defaultColor;
74427
74483
  }
74428
74484
  }
74429
- function getPdfColorArray(color) {
74430
- return Array.from(color, (c) => c / 255);
74485
+ function getPdfColorArray(color, defaultValue = null) {
74486
+ return color && Array.from(color, (c) => c / 255) || defaultValue;
74431
74487
  }
74432
74488
  function getQuadPoints(dict, rect) {
74433
74489
  const quadPoints = dict.getArray("QuadPoints");
@@ -75356,20 +75412,16 @@ var MarkupAnnotation = class extends Annotation {
75356
75412
  buffer.push("Q");
75357
75413
  const formDict = new Dict(xref);
75358
75414
  const appearanceStreamDict = new Dict(xref);
75359
- appearanceStreamDict.set("Subtype", Name.get("Form"));
75415
+ appearanceStreamDict.setIfName("Subtype", "Form");
75360
75416
  const appearanceStream = new StringStream(buffer.join(" "));
75361
75417
  appearanceStream.dict = appearanceStreamDict;
75362
75418
  formDict.set("Fm0", appearanceStream);
75363
75419
  const gsDict = new Dict(xref);
75364
75420
  if (blendMode) {
75365
- gsDict.set("BM", Name.get(blendMode));
75366
- }
75367
- if (typeof strokeAlpha === "number") {
75368
- gsDict.set("CA", strokeAlpha);
75369
- }
75370
- if (typeof fillAlpha === "number") {
75371
- gsDict.set("ca", fillAlpha);
75421
+ gsDict.setIfName("BM", blendMode);
75372
75422
  }
75423
+ gsDict.setIfNumber("CA", strokeAlpha);
75424
+ gsDict.setIfNumber("ca", fillAlpha);
75373
75425
  const stateDict = new Dict(xref);
75374
75426
  stateDict.set("GS0", gsDict);
75375
75427
  const resources = new Dict(xref);
@@ -75403,7 +75455,27 @@ var MarkupAnnotation = class extends Annotation {
75403
75455
  changes.put(annotationRef, {
75404
75456
  data: annotationDict
75405
75457
  });
75406
- return { ref: annotationRef };
75458
+ const retRef = { ref: annotationRef };
75459
+ if (annotation.popup) {
75460
+ const popup = annotation.popup;
75461
+ if (popup.deleted) {
75462
+ annotationDict.delete("Popup");
75463
+ annotationDict.delete("Contents");
75464
+ annotationDict.delete("RC");
75465
+ return retRef;
75466
+ }
75467
+ const popupRef = popup.ref || (popup.ref = xref.getNewTemporaryRef());
75468
+ popup.parent = annotationRef;
75469
+ const popupDict = PopupAnnotation.createNewDict(popup, xref);
75470
+ changes.put(popupRef, { data: popupDict });
75471
+ annotationDict.setIfDefined(
75472
+ "Contents",
75473
+ stringToAsciiOrUTF16BE(popup.contents)
75474
+ );
75475
+ annotationDict.set("Popup", popupRef);
75476
+ return [retRef, { ref: popupRef }];
75477
+ }
75478
+ return retRef;
75407
75479
  }
75408
75480
  static async createNewPrintAnnotation(annotationGlobals, xref, annotation, params) {
75409
75481
  const ap = await this.createNewAppearanceStream(annotation, xref, params);
@@ -75627,12 +75699,8 @@ var WidgetAnnotation = class _WidgetAnnotation extends Annotation {
75627
75699
  if (rotation) {
75628
75700
  mk.set("R", rotation);
75629
75701
  }
75630
- if (this.borderColor) {
75631
- mk.set("BC", getPdfColorArray(this.borderColor));
75632
- }
75633
- if (this.backgroundColor) {
75634
- mk.set("BG", getPdfColorArray(this.backgroundColor));
75635
- }
75702
+ mk.setIfArray("BC", getPdfColorArray(this.borderColor));
75703
+ mk.setIfArray("BG", getPdfColorArray(this.backgroundColor));
75636
75704
  return mk.size > 0 ? mk : null;
75637
75705
  }
75638
75706
  amendSavedDict(annotationStorage, dict) {
@@ -75735,7 +75803,7 @@ var WidgetAnnotation = class _WidgetAnnotation extends Annotation {
75735
75803
  const resources = this._getSaveFieldResources(xref);
75736
75804
  const appearanceStream = new StringStream(appearance);
75737
75805
  const appearanceDict = appearanceStream.dict = new Dict(xref);
75738
- appearanceDict.set("Subtype", Name.get("Form"));
75806
+ appearanceDict.setIfName("Subtype", "Form");
75739
75807
  appearanceDict.set("Resources", resources);
75740
75808
  const bbox = rotation % 180 === 0 ? [0, 0, this.width, this.height] : [0, 0, this.height, this.width];
75741
75809
  appearanceDict.set("BBox", bbox);
@@ -76112,17 +76180,52 @@ var TextWidgetAnnotation = class extends WidgetAnnotation {
76112
76180
  const {
76113
76181
  data: { actions }
76114
76182
  } = this;
76115
- for (const keystrokeAction of actions?.Keystroke || []) {
76116
- const m = keystrokeAction.trim().match(/^AF(Date|Time)_Keystroke(?:Ex)?\(['"]?([^'"]+)['"]?\);$/);
76117
- if (m) {
76118
- let format = m[2];
76119
- const num = parseInt(format, 10);
76120
- if (!isNaN(num) && Math.floor(Math.log10(num)) + 1 === m[2].length) {
76121
- format = (m[1] === "Date" ? DateFormats : TimeFormats)[num] ?? format;
76122
- }
76123
- this.data[m[1] === "Date" ? "dateFormat" : "timeFormat"] = format;
76183
+ if (!actions) {
76184
+ return;
76185
+ }
76186
+ const AFDateTime = /^AF(Date|Time)_(?:Keystroke|Format)(?:Ex)?\(['"]?([^'"]+)['"]?\);$/;
76187
+ let canUseHTMLDateTime = false;
76188
+ if (actions.Format?.length === 1 && actions.Keystroke?.length === 1 && AFDateTime.test(actions.Format[0]) && AFDateTime.test(actions.Keystroke[0]) || actions.Format?.length === 0 && actions.Keystroke?.length === 1 && AFDateTime.test(actions.Keystroke[0]) || actions.Keystroke?.length === 0 && actions.Format?.length === 1 && AFDateTime.test(actions.Format[0])) {
76189
+ canUseHTMLDateTime = true;
76190
+ }
76191
+ const actionsToVisit = [];
76192
+ if (actions.Format) {
76193
+ actionsToVisit.push(...actions.Format);
76194
+ }
76195
+ if (actions.Keystroke) {
76196
+ actionsToVisit.push(...actions.Keystroke);
76197
+ }
76198
+ if (canUseHTMLDateTime) {
76199
+ delete actions.Keystroke;
76200
+ actions.Format = actionsToVisit;
76201
+ }
76202
+ for (const formatAction of actionsToVisit) {
76203
+ const m = formatAction.match(AFDateTime);
76204
+ if (!m) {
76205
+ continue;
76206
+ }
76207
+ const isDate = m[1] === "Date";
76208
+ let format = m[2];
76209
+ const num = parseInt(format, 10);
76210
+ if (!isNaN(num) && Math.floor(Math.log10(num)) + 1 === m[2].length) {
76211
+ format = (isDate ? DateFormats : TimeFormats)[num] ?? format;
76212
+ }
76213
+ this.data.datetimeFormat = format;
76214
+ if (!canUseHTMLDateTime) {
76215
+ break;
76216
+ }
76217
+ if (isDate) {
76218
+ if (/HH|MM|ss|h/.test(format)) {
76219
+ this.data.datetimeType = "datetime-local";
76220
+ this.data.timeStep = /ss/.test(format) ? 1 : 60;
76221
+ } else {
76222
+ this.data.datetimeType = "date";
76223
+ }
76124
76224
  break;
76125
76225
  }
76226
+ this.data.datetimeType = "time";
76227
+ this.data.timeStep = /ss/.test(format) ? 1 : 60;
76228
+ break;
76126
76229
  }
76127
76230
  }
76128
76231
  get hasTextContent() {
@@ -76253,6 +76356,8 @@ var TextWidgetAnnotation = class extends WidgetAnnotation {
76253
76356
  strokeColor: this.data.borderColor,
76254
76357
  fillColor: this.data.backgroundColor,
76255
76358
  rotation: this.rotation,
76359
+ datetimeFormat: this.data.datetimeFormat,
76360
+ hasDatetimeHTML: !!this.data.datetimeType,
76256
76361
  type: "text"
76257
76362
  };
76258
76363
  }
@@ -76466,8 +76571,8 @@ var ButtonWidgetAnnotation = class extends WidgetAnnotation {
76466
76571
  const appearance = `q BT /PdfJsZaDb ${fontSize} Tf 0 g ${xShift} ${yShift} Td (${char}) Tj ET Q`;
76467
76572
  const appearanceStreamDict = new Dict(params.xref);
76468
76573
  appearanceStreamDict.set("FormType", 1);
76469
- appearanceStreamDict.set("Subtype", Name.get("Form"));
76470
- appearanceStreamDict.set("Type", Name.get("XObject"));
76574
+ appearanceStreamDict.setIfName("Subtype", "Form");
76575
+ appearanceStreamDict.setIfName("Type", "XObject");
76471
76576
  appearanceStreamDict.set("BBox", bbox);
76472
76577
  appearanceStreamDict.set("Matrix", [1, 0, 0, 1, 0, 0]);
76473
76578
  appearanceStreamDict.set("Length", appearance.length);
@@ -76616,10 +76721,10 @@ var ButtonWidgetAnnotation = class extends WidgetAnnotation {
76616
76721
  }
76617
76722
  get fallbackFontDict() {
76618
76723
  const dict = new Dict();
76619
- dict.set("BaseFont", Name.get("ZapfDingbats"));
76620
- dict.set("Type", Name.get("FallbackType"));
76621
- dict.set("Subtype", Name.get("FallbackType"));
76622
- dict.set("Encoding", Name.get("ZapfDingbatsEncoding"));
76724
+ dict.setIfName("BaseFont", "ZapfDingbats");
76725
+ dict.setIfName("Type", "FallbackType");
76726
+ dict.setIfName("Subtype", "FallbackType");
76727
+ dict.setIfName("Encoding", "ZapfDingbatsEncoding");
76623
76728
  return shadow(this, "fallbackFontDict", dict);
76624
76729
  }
76625
76730
  };
@@ -76883,6 +76988,9 @@ var LinkAnnotation = class extends Annotation {
76883
76988
  docAttachments: annotationGlobals.attachments
76884
76989
  });
76885
76990
  }
76991
+ get overlaysTextContent() {
76992
+ return true;
76993
+ }
76886
76994
  };
76887
76995
  var PopupAnnotation = class extends Annotation {
76888
76996
  constructor(params) {
@@ -76899,6 +77007,7 @@ var PopupAnnotation = class extends Annotation {
76899
77007
  return;
76900
77008
  }
76901
77009
  this.data.parentRect = lookupNormalRect(parentItem.getArray("Rect"), null);
77010
+ this.data.creationDate = parentItem.get("CreationDate") || "";
76902
77011
  const rt = parentItem.get("RT");
76903
77012
  if (isName(rt, AnnotationReplyType.GROUP)) {
76904
77013
  parentItem = parentItem.get("IRT");
@@ -76930,6 +77039,19 @@ var PopupAnnotation = class extends Annotation {
76930
77039
  }
76931
77040
  this.data.open = !!dict.get("Open");
76932
77041
  }
77042
+ static createNewDict(annotation, xref, _params) {
77043
+ const { oldAnnotation, rect, parent } = annotation;
77044
+ const popup = oldAnnotation || new Dict(xref);
77045
+ popup.setIfNotExists("Type", Name.get("Annot"));
77046
+ popup.setIfNotExists("Subtype", Name.get("Popup"));
77047
+ popup.setIfNotExists("Open", false);
77048
+ popup.setIfArray("Rect", rect);
77049
+ popup.set("Parent", parent);
77050
+ return popup;
77051
+ }
77052
+ static async createNewAppearanceStream(annotation, xref, params) {
77053
+ return null;
77054
+ }
76933
77055
  };
76934
77056
  var FreeTextAnnotation = class extends MarkupAnnotation {
76935
77057
  constructor(params) {
@@ -76986,54 +77108,61 @@ var FreeTextAnnotation = class extends MarkupAnnotation {
76986
77108
  return this._hasAppearance;
76987
77109
  }
76988
77110
  static createNewDict(annotation, xref, { apRef, ap }) {
76989
- const { color, fontSize, oldAnnotation, rect, rotation, user, value } = annotation;
77111
+ const {
77112
+ color,
77113
+ date,
77114
+ fontSize,
77115
+ oldAnnotation,
77116
+ rect,
77117
+ rotation,
77118
+ user,
77119
+ value
77120
+ } = annotation;
76990
77121
  const freetext = oldAnnotation || new Dict(xref);
76991
- freetext.set("Type", Name.get("Annot"));
76992
- freetext.set("Subtype", Name.get("FreeText"));
77122
+ freetext.setIfNotExists("Type", Name.get("Annot"));
77123
+ freetext.setIfNotExists("Subtype", Name.get("FreeText"));
77124
+ freetext.set(
77125
+ oldAnnotation ? "M" : "CreationDate",
77126
+ `D:${getModificationDate(date)}`
77127
+ );
76993
77128
  if (oldAnnotation) {
76994
- freetext.set("M", `D:${getModificationDate()}`);
76995
77129
  freetext.delete("RC");
76996
- } else {
76997
- freetext.set("CreationDate", `D:${getModificationDate()}`);
76998
77130
  }
76999
- freetext.set("Rect", rect);
77131
+ freetext.setIfArray("Rect", rect);
77000
77132
  const da = `/Helv ${fontSize} Tf ${getPdfColor(
77001
77133
  color,
77002
77134
  /* isFill */
77003
77135
  true
77004
77136
  )}`;
77005
77137
  freetext.set("DA", da);
77006
- freetext.set("Contents", stringToAsciiOrUTF16BE(value));
77007
- freetext.set("F", 4);
77008
- freetext.set("Border", [0, 0, 0]);
77009
- freetext.set("Rotate", rotation);
77010
- if (user) {
77011
- freetext.set("T", stringToAsciiOrUTF16BE(user));
77012
- }
77138
+ freetext.setIfDefined("Contents", stringToAsciiOrUTF16BE(value));
77139
+ freetext.setIfNotExists("F", 4);
77140
+ freetext.setIfNotExists("Border", [0, 0, 0]);
77141
+ freetext.setIfNumber("Rotate", rotation);
77142
+ freetext.setIfDefined("T", stringToAsciiOrUTF16BE(user));
77013
77143
  if (apRef || ap) {
77014
77144
  const n = new Dict(xref);
77015
77145
  freetext.set("AP", n);
77016
- if (apRef) {
77017
- n.set("N", apRef);
77018
- } else {
77019
- n.set("N", ap);
77020
- }
77146
+ n.set("N", apRef || ap);
77021
77147
  }
77022
77148
  return freetext;
77023
77149
  }
77024
77150
  static async createNewAppearanceStream(annotation, xref, params) {
77025
77151
  const { baseFontRef, evaluator, task } = params;
77026
77152
  const { color, fontSize, rect, rotation, value } = annotation;
77153
+ if (!color) {
77154
+ return null;
77155
+ }
77027
77156
  const resources = new Dict(xref);
77028
77157
  const font = new Dict(xref);
77029
77158
  if (baseFontRef) {
77030
77159
  font.set("Helv", baseFontRef);
77031
77160
  } else {
77032
77161
  const baseFont = new Dict(xref);
77033
- baseFont.set("BaseFont", Name.get("Helvetica"));
77034
- baseFont.set("Type", Name.get("Font"));
77035
- baseFont.set("Subtype", Name.get("Type1"));
77036
- baseFont.set("Encoding", Name.get("WinAnsiEncoding"));
77162
+ baseFont.setIfName("BaseFont", "Helvetica");
77163
+ baseFont.setIfName("Type", "Font");
77164
+ baseFont.setIfName("Subtype", "Type1");
77165
+ baseFont.setIfName("Encoding", "WinAnsiEncoding");
77037
77166
  font.set("Helv", baseFont);
77038
77167
  }
77039
77168
  resources.set("Font", font);
@@ -77130,8 +77259,8 @@ var FreeTextAnnotation = class extends MarkupAnnotation {
77130
77259
  const appearance = buffer.join("\n");
77131
77260
  const appearanceStreamDict = new Dict(xref);
77132
77261
  appearanceStreamDict.set("FormType", 1);
77133
- appearanceStreamDict.set("Subtype", Name.get("Form"));
77134
- appearanceStreamDict.set("Type", Name.get("XObject"));
77262
+ appearanceStreamDict.setIfName("Subtype", "Form");
77263
+ appearanceStreamDict.setIfName("Type", "XObject");
77135
77264
  appearanceStreamDict.set("BBox", rect);
77136
77265
  appearanceStreamDict.set("Resources", resources);
77137
77266
  appearanceStreamDict.set("Matrix", [1, 0, 0, 1, -rect[0], -rect[1]]);
@@ -77154,10 +77283,10 @@ var LineAnnotation = class extends MarkupAnnotation {
77154
77283
  this.data.lineEndings = this.lineEndings;
77155
77284
  }
77156
77285
  if (!this.appearance) {
77157
- const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
77286
+ const strokeColor = getPdfColorArray(this.color, [0, 0, 0]);
77158
77287
  const strokeAlpha = dict.get("CA");
77159
77288
  const interiorColor = getRgbColor(dict.getArray("IC"), null);
77160
- const fillColor = interiorColor ? getPdfColorArray(interiorColor) : null;
77289
+ const fillColor = getPdfColorArray(interiorColor);
77161
77290
  const fillAlpha = fillColor ? strokeAlpha : null;
77162
77291
  const borderWidth = this.borderStyle.width || 1, borderAdjust = 2 * borderWidth;
77163
77292
  const bbox = [
@@ -77201,10 +77330,10 @@ var SquareAnnotation = class extends MarkupAnnotation {
77201
77330
  this.data.hasOwnCanvas = this.data.noRotate;
77202
77331
  this.data.noHTML = false;
77203
77332
  if (!this.appearance) {
77204
- const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
77333
+ const strokeColor = getPdfColorArray(this.color, [0, 0, 0]);
77205
77334
  const strokeAlpha = dict.get("CA");
77206
77335
  const interiorColor = getRgbColor(dict.getArray("IC"), null);
77207
- const fillColor = interiorColor ? getPdfColorArray(interiorColor) : null;
77336
+ const fillColor = getPdfColorArray(interiorColor);
77208
77337
  const fillAlpha = fillColor ? strokeAlpha : null;
77209
77338
  if (this.borderStyle.width === 0 && !fillColor) {
77210
77339
  return;
@@ -77239,10 +77368,10 @@ var CircleAnnotation = class extends MarkupAnnotation {
77239
77368
  const { dict, xref } = params;
77240
77369
  this.data.annotationType = AnnotationType.CIRCLE;
77241
77370
  if (!this.appearance) {
77242
- const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
77371
+ const strokeColor = getPdfColorArray(this.color, [0, 0, 0]);
77243
77372
  const strokeAlpha = dict.get("CA");
77244
77373
  const interiorColor = getRgbColor(dict.getArray("IC"), null);
77245
- const fillColor = interiorColor ? getPdfColorArray(interiorColor) : null;
77374
+ const fillColor = getPdfColorArray(interiorColor);
77246
77375
  const fillAlpha = fillColor ? strokeAlpha : null;
77247
77376
  if (this.borderStyle.width === 0 && !fillColor) {
77248
77377
  return;
@@ -77301,8 +77430,22 @@ var PolylineAnnotation = class extends MarkupAnnotation {
77301
77430
  }
77302
77431
  const vertices = this.data.vertices = Float32Array.from(rawVertices);
77303
77432
  if (!this.appearance) {
77304
- const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
77433
+ const strokeColor = getPdfColorArray(this.color, [0, 0, 0]);
77305
77434
  const strokeAlpha = dict.get("CA");
77435
+ let fillColor = getRgbColor(dict.getArray("IC"), null);
77436
+ if (fillColor) {
77437
+ fillColor = getPdfColorArray(fillColor);
77438
+ }
77439
+ let operator;
77440
+ if (fillColor) {
77441
+ if (this.color) {
77442
+ operator = fillColor.every((c, i) => c === strokeColor[i]) ? "f" : "B";
77443
+ } else {
77444
+ operator = "f";
77445
+ }
77446
+ } else {
77447
+ operator = "S";
77448
+ }
77306
77449
  const borderWidth = this.borderStyle.width || 1, borderAdjust = 2 * borderWidth;
77307
77450
  const bbox = [Infinity, Infinity, -Infinity, -Infinity];
77308
77451
  for (let i = 0, ii = vertices.length; i < ii; i += 2) {
@@ -77322,13 +77465,15 @@ var PolylineAnnotation = class extends MarkupAnnotation {
77322
77465
  extra: `${borderWidth} w`,
77323
77466
  strokeColor,
77324
77467
  strokeAlpha,
77468
+ fillColor,
77469
+ fillAlpha: fillColor ? strokeAlpha : null,
77325
77470
  pointsCallback: (buffer, points) => {
77326
77471
  for (let i = 0, ii = vertices.length; i < ii; i += 2) {
77327
77472
  buffer.push(
77328
77473
  `${vertices[i]} ${vertices[i + 1]} ${i === 0 ? "m" : "l"}`
77329
77474
  );
77330
77475
  }
77331
- buffer.push("S");
77476
+ buffer.push(operator);
77332
77477
  return [points[0], points[7], points[2], points[3]];
77333
77478
  }
77334
77479
  });
@@ -77377,7 +77522,7 @@ var InkAnnotation = class extends MarkupAnnotation {
77377
77522
  }
77378
77523
  }
77379
77524
  if (!this.appearance) {
77380
- const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
77525
+ const strokeColor = getPdfColorArray(this.color, [0, 0, 0]);
77381
77526
  const strokeAlpha = dict.get("CA");
77382
77527
  const borderWidth = this.borderStyle.width || 1, borderAdjust = 2 * borderWidth;
77383
77528
  const bbox = [Infinity, Infinity, -Infinity, -Infinity];
@@ -77418,6 +77563,7 @@ var InkAnnotation = class extends MarkupAnnotation {
77418
77563
  const {
77419
77564
  oldAnnotation,
77420
77565
  color,
77566
+ date,
77421
77567
  opacity,
77422
77568
  paths,
77423
77569
  outlines,
@@ -77427,30 +77573,31 @@ var InkAnnotation = class extends MarkupAnnotation {
77427
77573
  user
77428
77574
  } = annotation;
77429
77575
  const ink = oldAnnotation || new Dict(xref);
77430
- ink.set("Type", Name.get("Annot"));
77431
- ink.set("Subtype", Name.get("Ink"));
77432
- ink.set(oldAnnotation ? "M" : "CreationDate", `D:${getModificationDate()}`);
77433
- ink.set("Rect", rect);
77434
- ink.set("InkList", outlines?.points || paths.points);
77435
- ink.set("F", 4);
77436
- ink.set("Rotate", rotation);
77437
- if (user) {
77438
- ink.set("T", stringToAsciiOrUTF16BE(user));
77439
- }
77576
+ ink.setIfNotExists("Type", Name.get("Annot"));
77577
+ ink.setIfNotExists("Subtype", Name.get("Ink"));
77578
+ ink.set(
77579
+ oldAnnotation ? "M" : "CreationDate",
77580
+ `D:${getModificationDate(date)}`
77581
+ );
77582
+ ink.setIfArray("Rect", rect);
77583
+ ink.setIfArray("InkList", outlines?.points || paths?.points);
77584
+ ink.setIfNotExists("F", 4);
77585
+ ink.setIfNumber("Rotate", rotation);
77586
+ ink.setIfDefined("T", stringToAsciiOrUTF16BE(user));
77440
77587
  if (outlines) {
77441
- ink.set("IT", Name.get("InkHighlight"));
77442
- }
77443
- const bs = new Dict(xref);
77444
- ink.set("BS", bs);
77445
- bs.set("W", thickness);
77446
- ink.set("C", getPdfColorArray(color));
77447
- ink.set("CA", opacity);
77448
- const n = new Dict(xref);
77449
- ink.set("AP", n);
77450
- if (apRef) {
77451
- n.set("N", apRef);
77452
- } else {
77453
- n.set("N", ap);
77588
+ ink.setIfName("IT", "InkHighlight");
77589
+ }
77590
+ if (thickness > 0) {
77591
+ const bs = new Dict(xref);
77592
+ ink.set("BS", bs);
77593
+ bs.set("W", thickness);
77594
+ }
77595
+ ink.setIfArray("C", getPdfColorArray(color));
77596
+ ink.setIfNumber("CA", opacity);
77597
+ if (ap || apRef) {
77598
+ const n = new Dict(xref);
77599
+ ink.set("AP", n);
77600
+ n.set("N", apRef || ap);
77454
77601
  }
77455
77602
  return ink;
77456
77603
  }
@@ -77463,6 +77610,9 @@ var InkAnnotation = class extends MarkupAnnotation {
77463
77610
  );
77464
77611
  }
77465
77612
  const { color, rect, paths, thickness, opacity } = annotation;
77613
+ if (!color) {
77614
+ return null;
77615
+ }
77466
77616
  const appearanceBuffer = [
77467
77617
  `${thickness} w 1 J 1 j`,
77468
77618
  `${getPdfColor(
@@ -77502,8 +77652,8 @@ var InkAnnotation = class extends MarkupAnnotation {
77502
77652
  const appearance = appearanceBuffer.join("\n");
77503
77653
  const appearanceStreamDict = new Dict(xref);
77504
77654
  appearanceStreamDict.set("FormType", 1);
77505
- appearanceStreamDict.set("Subtype", Name.get("Form"));
77506
- appearanceStreamDict.set("Type", Name.get("XObject"));
77655
+ appearanceStreamDict.setIfName("Subtype", "Form");
77656
+ appearanceStreamDict.setIfName("Type", "XObject");
77507
77657
  appearanceStreamDict.set("BBox", rect);
77508
77658
  appearanceStreamDict.set("Length", appearance.length);
77509
77659
  if (opacity !== 1) {
@@ -77511,7 +77661,7 @@ var InkAnnotation = class extends MarkupAnnotation {
77511
77661
  const extGState = new Dict(xref);
77512
77662
  const r0 = new Dict(xref);
77513
77663
  r0.set("CA", opacity);
77514
- r0.set("Type", Name.get("ExtGState"));
77664
+ r0.setIfName("Type", "ExtGState");
77515
77665
  extGState.set("R0", r0);
77516
77666
  resources.set("ExtGState", extGState);
77517
77667
  appearanceStreamDict.set("Resources", resources);
@@ -77527,6 +77677,9 @@ var InkAnnotation = class extends MarkupAnnotation {
77527
77677
  outlines: { outline },
77528
77678
  opacity
77529
77679
  } = annotation;
77680
+ if (!color) {
77681
+ return null;
77682
+ }
77530
77683
  const appearanceBuffer = [
77531
77684
  `${getPdfColor(
77532
77685
  color,
@@ -77556,8 +77709,8 @@ var InkAnnotation = class extends MarkupAnnotation {
77556
77709
  const appearance = appearanceBuffer.join("\n");
77557
77710
  const appearanceStreamDict = new Dict(xref);
77558
77711
  appearanceStreamDict.set("FormType", 1);
77559
- appearanceStreamDict.set("Subtype", Name.get("Form"));
77560
- appearanceStreamDict.set("Type", Name.get("XObject"));
77712
+ appearanceStreamDict.setIfName("Subtype", "Form");
77713
+ appearanceStreamDict.setIfName("Type", "XObject");
77561
77714
  appearanceStreamDict.set("BBox", rect);
77562
77715
  appearanceStreamDict.set("Length", appearance.length);
77563
77716
  const resources = new Dict(xref);
@@ -77566,10 +77719,10 @@ var InkAnnotation = class extends MarkupAnnotation {
77566
77719
  appearanceStreamDict.set("Resources", resources);
77567
77720
  const r0 = new Dict(xref);
77568
77721
  extGState.set("R0", r0);
77569
- r0.set("BM", Name.get("Multiply"));
77722
+ r0.setIfName("BM", "Multiply");
77570
77723
  if (opacity !== 1) {
77571
77724
  r0.set("ca", opacity);
77572
- r0.set("Type", Name.get("ExtGState"));
77725
+ r0.setIfName("Type", "ExtGState");
77573
77726
  }
77574
77727
  const ap = new StringStream(appearance);
77575
77728
  ap.dict = appearanceStreamDict;
@@ -77591,7 +77744,7 @@ var HighlightAnnotation = class extends MarkupAnnotation {
77591
77744
  if (this.appearance) {
77592
77745
  warn("HighlightAnnotation - ignoring built-in appearance stream.");
77593
77746
  }
77594
- const fillColor = this.color ? getPdfColorArray(this.color) : [1, 1, 0];
77747
+ const fillColor = getPdfColorArray(this.color, [1, 1, 0]);
77595
77748
  const fillAlpha = dict.get("CA");
77596
77749
  this._setDefaultAppearance({
77597
77750
  xref,
@@ -77618,25 +77771,31 @@ var HighlightAnnotation = class extends MarkupAnnotation {
77618
77771
  return true;
77619
77772
  }
77620
77773
  static createNewDict(annotation, xref, { apRef, ap }) {
77621
- const { color, oldAnnotation, opacity, rect, rotation, user, quadPoints } = annotation;
77774
+ const {
77775
+ color,
77776
+ date,
77777
+ oldAnnotation,
77778
+ opacity,
77779
+ rect,
77780
+ rotation,
77781
+ user,
77782
+ quadPoints
77783
+ } = annotation;
77622
77784
  const highlight = oldAnnotation || new Dict(xref);
77623
- highlight.set("Type", Name.get("Annot"));
77624
- highlight.set("Subtype", Name.get("Highlight"));
77785
+ highlight.setIfNotExists("Type", Name.get("Annot"));
77786
+ highlight.setIfNotExists("Subtype", Name.get("Highlight"));
77625
77787
  highlight.set(
77626
77788
  oldAnnotation ? "M" : "CreationDate",
77627
- `D:${getModificationDate()}`
77789
+ `D:${getModificationDate(date)}`
77628
77790
  );
77629
- highlight.set("CreationDate", `D:${getModificationDate()}`);
77630
- highlight.set("Rect", rect);
77631
- highlight.set("F", 4);
77632
- highlight.set("Border", [0, 0, 0]);
77633
- highlight.set("Rotate", rotation);
77634
- highlight.set("QuadPoints", quadPoints);
77635
- highlight.set("C", getPdfColorArray(color));
77636
- highlight.set("CA", opacity);
77637
- if (user) {
77638
- highlight.set("T", stringToAsciiOrUTF16BE(user));
77639
- }
77791
+ highlight.setIfArray("Rect", rect);
77792
+ highlight.setIfNotExists("F", 4);
77793
+ highlight.setIfNotExists("Border", [0, 0, 0]);
77794
+ highlight.setIfNumber("Rotate", rotation);
77795
+ highlight.setIfArray("QuadPoints", quadPoints);
77796
+ highlight.setIfArray("C", getPdfColorArray(color));
77797
+ highlight.setIfNumber("CA", opacity);
77798
+ highlight.setIfDefined("T", stringToAsciiOrUTF16BE(user));
77640
77799
  if (apRef || ap) {
77641
77800
  const n = new Dict(xref);
77642
77801
  highlight.set("AP", n);
@@ -77646,6 +77805,9 @@ var HighlightAnnotation = class extends MarkupAnnotation {
77646
77805
  }
77647
77806
  static async createNewAppearanceStream(annotation, xref, params) {
77648
77807
  const { color, rect, outlines, opacity } = annotation;
77808
+ if (!color) {
77809
+ return null;
77810
+ }
77649
77811
  const appearanceBuffer = [
77650
77812
  `${getPdfColor(
77651
77813
  color,
@@ -77672,8 +77834,8 @@ var HighlightAnnotation = class extends MarkupAnnotation {
77672
77834
  const appearance = appearanceBuffer.join("\n");
77673
77835
  const appearanceStreamDict = new Dict(xref);
77674
77836
  appearanceStreamDict.set("FormType", 1);
77675
- appearanceStreamDict.set("Subtype", Name.get("Form"));
77676
- appearanceStreamDict.set("Type", Name.get("XObject"));
77837
+ appearanceStreamDict.setIfName("Subtype", "Form");
77838
+ appearanceStreamDict.setIfName("Type", "XObject");
77677
77839
  appearanceStreamDict.set("BBox", rect);
77678
77840
  appearanceStreamDict.set("Length", appearance.length);
77679
77841
  const resources = new Dict(xref);
@@ -77682,10 +77844,10 @@ var HighlightAnnotation = class extends MarkupAnnotation {
77682
77844
  appearanceStreamDict.set("Resources", resources);
77683
77845
  const r0 = new Dict(xref);
77684
77846
  extGState.set("R0", r0);
77685
- r0.set("BM", Name.get("Multiply"));
77847
+ r0.setIfName("BM", "Multiply");
77686
77848
  if (opacity !== 1) {
77687
77849
  r0.set("ca", opacity);
77688
- r0.set("Type", Name.get("ExtGState"));
77850
+ r0.setIfName("Type", "ExtGState");
77689
77851
  }
77690
77852
  const ap = new StringStream(appearance);
77691
77853
  ap.dict = appearanceStreamDict;
@@ -77700,7 +77862,7 @@ var UnderlineAnnotation = class extends MarkupAnnotation {
77700
77862
  const quadPoints = this.data.quadPoints = getQuadPoints(dict, null);
77701
77863
  if (quadPoints) {
77702
77864
  if (!this.appearance) {
77703
- const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
77865
+ const strokeColor = getPdfColorArray(this.color, [0, 0, 0]);
77704
77866
  const strokeAlpha = dict.get("CA");
77705
77867
  this._setDefaultAppearance({
77706
77868
  xref,
@@ -77733,7 +77895,7 @@ var SquigglyAnnotation = class extends MarkupAnnotation {
77733
77895
  const quadPoints = this.data.quadPoints = getQuadPoints(dict, null);
77734
77896
  if (quadPoints) {
77735
77897
  if (!this.appearance) {
77736
- const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
77898
+ const strokeColor = getPdfColorArray(this.color, [0, 0, 0]);
77737
77899
  const strokeAlpha = dict.get("CA");
77738
77900
  this._setDefaultAppearance({
77739
77901
  xref,
@@ -77773,7 +77935,7 @@ var StrikeOutAnnotation = class extends MarkupAnnotation {
77773
77935
  const quadPoints = this.data.quadPoints = getQuadPoints(dict, null);
77774
77936
  if (quadPoints) {
77775
77937
  if (!this.appearance) {
77776
- const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
77938
+ const strokeColor = getPdfColorArray(this.color, [0, 0, 0]);
77777
77939
  const strokeAlpha = dict.get("CA");
77778
77940
  this._setDefaultAppearance({
77779
77941
  xref,
@@ -77845,8 +78007,8 @@ var StampAnnotation = class extends MarkupAnnotation {
77845
78007
  image.set("Type", xobjectName);
77846
78008
  image.set("Subtype", imageName);
77847
78009
  image.set("BitsPerComponent", 8);
77848
- image.set("ColorSpace", Name.get("DeviceRGB"));
77849
- image.set("Filter", Name.get("DCTDecode"));
78010
+ image.setIfName("ColorSpace", "DeviceRGB");
78011
+ image.setIfName("Filter", "DCTDecode");
77850
78012
  image.set("BBox", [0, 0, width, height]);
77851
78013
  image.set("Width", width);
77852
78014
  image.set("Height", height);
@@ -77866,7 +78028,7 @@ var StampAnnotation = class extends MarkupAnnotation {
77866
78028
  smask.set("Type", xobjectName);
77867
78029
  smask.set("Subtype", imageName);
77868
78030
  smask.set("BitsPerComponent", 8);
77869
- smask.set("ColorSpace", Name.get("DeviceGray"));
78031
+ smask.setIfName("ColorSpace", "DeviceGray");
77870
78032
  smask.set("Width", width);
77871
78033
  smask.set("Height", height);
77872
78034
  smaskStream = new Stream(alphaBuffer, 0, 0, smask);
@@ -77880,29 +78042,23 @@ var StampAnnotation = class extends MarkupAnnotation {
77880
78042
  };
77881
78043
  }
77882
78044
  static createNewDict(annotation, xref, { apRef, ap }) {
77883
- const { oldAnnotation, rect, rotation, user } = annotation;
78045
+ const { date, oldAnnotation, rect, rotation, user } = annotation;
77884
78046
  const stamp = oldAnnotation || new Dict(xref);
77885
- stamp.set("Type", Name.get("Annot"));
77886
- stamp.set("Subtype", Name.get("Stamp"));
78047
+ stamp.setIfNotExists("Type", Name.get("Annot"));
78048
+ stamp.setIfNotExists("Subtype", Name.get("Stamp"));
77887
78049
  stamp.set(
77888
78050
  oldAnnotation ? "M" : "CreationDate",
77889
- `D:${getModificationDate()}`
78051
+ `D:${getModificationDate(date)}`
77890
78052
  );
77891
- stamp.set("Rect", rect);
77892
- stamp.set("F", 4);
77893
- stamp.set("Border", [0, 0, 0]);
77894
- stamp.set("Rotate", rotation);
77895
- if (user) {
77896
- stamp.set("T", stringToAsciiOrUTF16BE(user));
77897
- }
78053
+ stamp.setIfArray("Rect", rect);
78054
+ stamp.setIfNotExists("F", 4);
78055
+ stamp.setIfNotExists("Border", [0, 0, 0]);
78056
+ stamp.setIfNumber("Rotate", rotation);
78057
+ stamp.setIfDefined("T", stringToAsciiOrUTF16BE(user));
77898
78058
  if (apRef || ap) {
77899
78059
  const n = new Dict(xref);
77900
78060
  stamp.set("AP", n);
77901
- if (apRef) {
77902
- n.set("N", apRef);
77903
- } else {
77904
- n.set("N", ap);
77905
- }
78061
+ n.set("N", apRef || ap);
77906
78062
  }
77907
78063
  return stamp;
77908
78064
  }
@@ -77922,8 +78078,8 @@ var StampAnnotation = class extends MarkupAnnotation {
77922
78078
  const appearance = `q ${width} 0 0 ${height} 0 0 cm /Im0 Do Q`;
77923
78079
  const appearanceStreamDict = new Dict(xref);
77924
78080
  appearanceStreamDict.set("FormType", 1);
77925
- appearanceStreamDict.set("Subtype", Name.get("Form"));
77926
- appearanceStreamDict.set("Type", Name.get("XObject"));
78081
+ appearanceStreamDict.setIfName("Subtype", "Form");
78082
+ appearanceStreamDict.setIfName("Type", "XObject");
77927
78083
  appearanceStreamDict.set("BBox", [0, 0, width, height]);
77928
78084
  appearanceStreamDict.set("Resources", resources);
77929
78085
  if (rotation) {
@@ -77939,6 +78095,9 @@ _savedHasOwnCanvas = new WeakMap();
77939
78095
  _StampAnnotation_static = new WeakSet();
77940
78096
  createNewAppearanceStreamForDrawing_fn = async function(annotation, xref) {
77941
78097
  const { areContours, color, rect, lines, thickness } = annotation;
78098
+ if (!color) {
78099
+ return null;
78100
+ }
77942
78101
  const appearanceBuffer = [
77943
78102
  `${thickness} w 1 J 1 j`,
77944
78103
  `${getPdfColor(
@@ -77973,8 +78132,8 @@ createNewAppearanceStreamForDrawing_fn = async function(annotation, xref) {
77973
78132
  const appearance = appearanceBuffer.join("\n");
77974
78133
  const appearanceStreamDict = new Dict(xref);
77975
78134
  appearanceStreamDict.set("FormType", 1);
77976
- appearanceStreamDict.set("Subtype", Name.get("Form"));
77977
- appearanceStreamDict.set("Type", Name.get("XObject"));
78135
+ appearanceStreamDict.setIfName("Subtype", "Form");
78136
+ appearanceStreamDict.setIfName("Type", "XObject");
77978
78137
  appearanceStreamDict.set("BBox", rect);
77979
78138
  appearanceStreamDict.set("Length", appearance.length);
77980
78139
  const ap = new StringStream(appearance);
@@ -78847,19 +79006,26 @@ var SingleIntersector = class {
78847
79006
  __privateAdd(this, _minY, Infinity);
78848
79007
  __privateAdd(this, _maxX, -Infinity);
78849
79008
  __privateAdd(this, _maxY, -Infinity);
78850
- __privateAdd(this, _quadPoints);
79009
+ __privateAdd(this, _quadPoints, null);
78851
79010
  __privateAdd(this, _text, []);
78852
79011
  __privateAdd(this, _extraChars, []);
78853
79012
  __privateAdd(this, _lastIntersectingQuadIndex, -1);
78854
79013
  __privateAdd(this, _canTakeExtraChars, false);
78855
79014
  __privateSet(this, _annotation, annotation);
78856
- const quadPoints = __privateSet(this, _quadPoints, annotation.data.quadPoints);
79015
+ const quadPoints = annotation.data.quadPoints;
79016
+ if (!quadPoints) {
79017
+ [__privateWrapper(this, _minX)._, __privateWrapper(this, _minY)._, __privateWrapper(this, _maxX)._, __privateWrapper(this, _maxY)._] = annotation.data.rect;
79018
+ return;
79019
+ }
78857
79020
  for (let i = 0, ii = quadPoints.length; i < ii; i += 8) {
78858
79021
  __privateSet(this, _minX, Math.min(__privateGet(this, _minX), quadPoints[i]));
78859
79022
  __privateSet(this, _maxX, Math.max(__privateGet(this, _maxX), quadPoints[i + 2]));
78860
79023
  __privateSet(this, _minY, Math.min(__privateGet(this, _minY), quadPoints[i + 5]));
78861
79024
  __privateSet(this, _maxY, Math.max(__privateGet(this, _maxY), quadPoints[i + 1]));
78862
79025
  }
79026
+ if (quadPoints.length > 8) {
79027
+ __privateSet(this, _quadPoints, quadPoints);
79028
+ }
78863
79029
  }
78864
79030
  overlaps(other) {
78865
79031
  return !(__privateGet(this, _minX) >= __privateGet(other, _maxX) || __privateGet(this, _maxX) <= __privateGet(other, _minX) || __privateGet(this, _minY) >= __privateGet(other, _maxY) || __privateGet(this, _maxY) <= __privateGet(other, _minY));
@@ -78916,7 +79082,7 @@ intersects_fn = function(x, y) {
78916
79082
  return false;
78917
79083
  }
78918
79084
  const quadPoints = __privateGet(this, _quadPoints);
78919
- if (quadPoints.length === 8) {
79085
+ if (!quadPoints) {
78920
79086
  return true;
78921
79087
  }
78922
79088
  if (__privateGet(this, _lastIntersectingQuadIndex) >= 0) {
@@ -78939,7 +79105,7 @@ var Intersector = class {
78939
79105
  constructor(annotations) {
78940
79106
  __privateAdd(this, _intersectors, /* @__PURE__ */ new Map());
78941
79107
  for (const annotation of annotations) {
78942
- if (!annotation.data.quadPoints) {
79108
+ if (!annotation.data.quadPoints && !annotation.data.rect) {
78943
79109
  continue;
78944
79110
  }
78945
79111
  const intersector = new SingleIntersector(annotation);
@@ -81942,11 +82108,12 @@ var XRef = class {
81942
82108
  return this.topDict;
81943
82109
  }
81944
82110
  if (!trailerDicts.length) {
81945
- for (const [num, entry] of this.entries.entries()) {
81946
- if (!entry) {
82111
+ for (const num in this.entries) {
82112
+ if (!Object.hasOwn(this.entries, num)) {
81947
82113
  continue;
81948
82114
  }
81949
- const ref = Ref.get(num, entry.gen);
82115
+ const entry = this.entries[num];
82116
+ const ref = Ref.get(parseInt(num), entry.gen);
81950
82117
  let obj;
81951
82118
  try {
81952
82119
  obj = this.fetch(ref);
@@ -82164,6 +82331,10 @@ var XRef = class {
82164
82331
  );
82165
82332
  }
82166
82333
  nums[i] = num;
82334
+ const entry = this.getEntry(num);
82335
+ if (entry?.offset === tableOffset && entry.gen !== i) {
82336
+ entry.gen = i;
82337
+ }
82167
82338
  offsets[i] = offset;
82168
82339
  }
82169
82340
  const start = (stream.start || 0) + first;
@@ -82227,7 +82398,7 @@ _firstXRefStmPos = new WeakMap();
82227
82398
 
82228
82399
  // src/pdf.js/src/core/document.js
82229
82400
  var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
82230
- var _resourcesPromise, _Page_instances, createPartialEvaluator_fn, getInheritableProperty_fn, getBoundingBox_fn, onSubStreamError_fn, replaceIdByRef_fn, getMergedResources_fn;
82401
+ var _areAnnotationsCached, _resourcesPromise, _Page_instances, createPartialEvaluator_fn, getInheritableProperty_fn, getBoundingBox_fn, onSubStreamError_fn, replaceIdByRef_fn, getMergedResources_fn;
82231
82402
  var Page = class {
82232
82403
  constructor({
82233
82404
  pdfManager,
@@ -82246,6 +82417,7 @@ var Page = class {
82246
82417
  xfaFactory
82247
82418
  }) {
82248
82419
  __privateAdd(this, _Page_instances);
82420
+ __privateAdd(this, _areAnnotationsCached, false);
82249
82421
  __privateAdd(this, _resourcesPromise, null);
82250
82422
  this.pdfManager = pdfManager;
82251
82423
  this.pageIndex = pageIndex;
@@ -82697,6 +82869,8 @@ var Page = class {
82697
82869
  /* collectFields */
82698
82870
  false,
82699
82871
  orphanFields,
82872
+ /* collectByType */
82873
+ null,
82700
82874
  this.ref
82701
82875
  ).catch(function(reason) {
82702
82876
  warn(`_parsedAnnotations: "${reason}".`);
@@ -82728,6 +82902,7 @@ var Page = class {
82728
82902
  }
82729
82903
  return sortedAnnotations;
82730
82904
  });
82905
+ __privateSet(this, _areAnnotationsCached, true);
82731
82906
  return shadow(this, "_parsedAnnotations", promise);
82732
82907
  }
82733
82908
  get jsActions() {
@@ -82738,7 +82913,57 @@ var Page = class {
82738
82913
  );
82739
82914
  return shadow(this, "jsActions", actions);
82740
82915
  }
82916
+ async collectAnnotationsByType(handler, task, types2, promises, annotationGlobals) {
82917
+ const { pageIndex } = this;
82918
+ if (__privateGet(this, _areAnnotationsCached)) {
82919
+ const cachedAnnotations = await this._parsedAnnotations;
82920
+ for (const { data } of cachedAnnotations) {
82921
+ if (!types2 || types2.has(data.annotationType)) {
82922
+ data.pageIndex = pageIndex;
82923
+ promises.push(Promise.resolve(data));
82924
+ }
82925
+ }
82926
+ return;
82927
+ }
82928
+ const annots = await this.pdfManager.ensure(this, "annotations");
82929
+ for (const annotationRef of annots) {
82930
+ promises.push(
82931
+ AnnotationFactory.create(
82932
+ this.xref,
82933
+ annotationRef,
82934
+ annotationGlobals,
82935
+ this._localIdFactory,
82936
+ /* collectFields */
82937
+ false,
82938
+ /* orphanFields */
82939
+ null,
82940
+ /* collectByType */
82941
+ types2,
82942
+ this.ref
82943
+ ).then(async (annotation) => {
82944
+ if (!annotation) {
82945
+ return null;
82946
+ }
82947
+ annotation.data.pageIndex = pageIndex;
82948
+ if (annotation.hasTextContent && annotation.viewable) {
82949
+ const partialEvaluator = __privateMethod(this, _Page_instances, createPartialEvaluator_fn).call(this, handler);
82950
+ await annotation.extractTextContent(partialEvaluator, task, [
82951
+ -Infinity,
82952
+ -Infinity,
82953
+ Infinity,
82954
+ Infinity
82955
+ ]);
82956
+ }
82957
+ return annotation.data;
82958
+ }).catch(function(reason) {
82959
+ warn(`collectAnnotationsByType: "${reason}".`);
82960
+ return null;
82961
+ })
82962
+ );
82963
+ }
82964
+ }
82741
82965
  };
82966
+ _areAnnotationsCached = new WeakMap();
82742
82967
  _resourcesPromise = new WeakMap();
82743
82968
  _Page_instances = new WeakSet();
82744
82969
  createPartialEvaluator_fn = function(handler) {
@@ -82818,6 +83043,12 @@ replaceIdByRef_fn = async function(annotations, deletedAnnotations, existingAnno
82818
83043
  }
82819
83044
  continue;
82820
83045
  }
83046
+ if (annotation.popup?.deleted) {
83047
+ const popupRef = Ref.fromString(annotation.popupRef);
83048
+ if (popupRef) {
83049
+ deletedAnnotations.put(popupRef, popupRef);
83050
+ }
83051
+ }
82821
83052
  existingAnnotations?.put(ref);
82822
83053
  annotation.ref = ref;
82823
83054
  promises.push(
@@ -83785,6 +84016,8 @@ collectFieldObjects_fn = async function(name, parentRef, fieldRef, promises, ann
83785
84016
  /* collectFields */
83786
84017
  true,
83787
84018
  orphanFields,
84019
+ /* collectByType */
84020
+ null,
83788
84021
  /* pageRef */
83789
84022
  null
83790
84023
  ).then((annotation) => annotation?.getFieldObject()).catch(function(reason) {
@@ -84157,7 +84390,7 @@ function updateXFA({ xfaData, xfaDatasetsRef, changes, xref }) {
84157
84390
  }
84158
84391
  const xfaDataStream = new StringStream(xfaData);
84159
84392
  xfaDataStream.dict = new Dict(xref);
84160
- xfaDataStream.dict.set("Type", Name.get("EmbeddedFile"));
84393
+ xfaDataStream.dict.setIfName("Type", "EmbeddedFile");
84161
84394
  changes.put(xfaDatasetsRef, {
84162
84395
  data: xfaDataStream
84163
84396
  });
@@ -84252,7 +84485,7 @@ function getTrailerDict(xrefInfo, changes, useXrefStream) {
84252
84485
  if (useXrefStream) {
84253
84486
  changes.put(refForXrefTable, { data: "" });
84254
84487
  newXref.set("Size", refForXrefTable.num + 1);
84255
- newXref.set("Type", Name.get("XRef"));
84488
+ newXref.setIfName("Type", "XRef");
84256
84489
  } else {
84257
84490
  newXref.set("Size", refForXrefTable.num);
84258
84491
  }
@@ -84729,6 +84962,53 @@ var _WorkerMessageHandler = class _WorkerMessageHandler {
84729
84962
  handler.on("GetPageJSActions", function({ pageIndex }) {
84730
84963
  return pdfManager.getPage(pageIndex).then((page) => pdfManager.ensure(page, "jsActions"));
84731
84964
  });
84965
+ handler.on(
84966
+ "GetAnnotationsByType",
84967
+ async function({ types: types2, pageIndexesToSkip }) {
84968
+ const [numPages, annotationGlobals] = await Promise.all([
84969
+ pdfManager.ensureDoc("numPages"),
84970
+ pdfManager.ensureDoc("annotationGlobals")
84971
+ ]);
84972
+ if (!annotationGlobals) {
84973
+ return null;
84974
+ }
84975
+ const pagePromises = [];
84976
+ const annotationPromises = [];
84977
+ let task = null;
84978
+ try {
84979
+ for (let i = 0, ii = numPages; i < ii; i++) {
84980
+ if (pageIndexesToSkip?.has(i)) {
84981
+ continue;
84982
+ }
84983
+ if (!task) {
84984
+ task = new WorkerTask("GetAnnotationsByType");
84985
+ startWorkerTask(task);
84986
+ }
84987
+ pagePromises.push(
84988
+ pdfManager.getPage(i).then(async (page) => {
84989
+ if (!page) {
84990
+ return [];
84991
+ }
84992
+ return page.collectAnnotationsByType(
84993
+ handler,
84994
+ task,
84995
+ types2,
84996
+ annotationPromises,
84997
+ annotationGlobals
84998
+ ) || [];
84999
+ })
85000
+ );
85001
+ }
85002
+ await Promise.all(pagePromises);
85003
+ const annotations = await Promise.all(annotationPromises);
85004
+ return annotations.filter((a) => !!a);
85005
+ } finally {
85006
+ if (task) {
85007
+ finishWorkerTask(task);
85008
+ }
85009
+ }
85010
+ }
85011
+ );
84732
85012
  handler.on("GetOutline", function(data) {
84733
85013
  return pdfManager.ensureCatalog("documentOutline");
84734
85014
  });