@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
@@ -7,7 +7,7 @@ import {
7
7
  convertToRGBA,
8
8
  grayToRGBA,
9
9
  wrapReason
10
- } from "./chunk-ZKUTXCS2.js";
10
+ } from "./chunk-AC5JE2E3.js";
11
11
  import {
12
12
  AbortException,
13
13
  AnnotationActionEventType,
@@ -63,12 +63,13 @@ import {
63
63
  unreachable,
64
64
  utf8StringToString,
65
65
  warn
66
- } from "./chunk-XMKSLA4K.js";
66
+ } from "./chunk-YDSKBMQ3.js";
67
67
  import {
68
68
  __privateAdd,
69
69
  __privateGet,
70
70
  __privateMethod,
71
71
  __privateSet,
72
+ __privateWrapper,
72
73
  __publicField
73
74
  } from "./chunk-7MW5RQZ5.js";
74
75
 
@@ -211,6 +212,33 @@ var Dict = class _Dict {
211
212
  }
212
213
  this._map.set(key, value);
213
214
  }
215
+ setIfNotExists(key, value) {
216
+ if (!this.has(key)) {
217
+ this.set(key, value);
218
+ }
219
+ }
220
+ setIfNumber(key, value) {
221
+ if (typeof value === "number") {
222
+ this.set(key, value);
223
+ }
224
+ }
225
+ setIfArray(key, value) {
226
+ if (Array.isArray(value) || ArrayBuffer.isView(value)) {
227
+ this.set(key, value);
228
+ }
229
+ }
230
+ setIfDefined(key, value) {
231
+ if (value !== void 0 && value !== null) {
232
+ this.set(key, value);
233
+ }
234
+ }
235
+ setIfName(key, value) {
236
+ if (typeof value === "string") {
237
+ this.set(key, Name.get(value));
238
+ } else if (value instanceof Name) {
239
+ this.set(key, value);
240
+ }
241
+ }
214
242
  has(key) {
215
243
  return this._map.has(key);
216
244
  }
@@ -767,7 +795,7 @@ function _collectJS(entry, xref, list, parents) {
767
795
  true
768
796
  ).replaceAll("\0", ""));
769
797
  if (code) {
770
- list.push(code);
798
+ list.push(code.trim());
771
799
  }
772
800
  }
773
801
  _collectJS(entry.getRaw("Next"), xref, list, parents);
@@ -973,6 +1001,9 @@ function getNewAnnotationsMap(annotationStorage) {
973
1001
  return newAnnotationsByPage.size > 0 ? newAnnotationsByPage : null;
974
1002
  }
975
1003
  function stringToAsciiOrUTF16BE(str) {
1004
+ if (str === null || str === void 0) {
1005
+ return str;
1006
+ }
976
1007
  return isAscii(str) ? str : stringToUTF16String(
977
1008
  str,
978
1009
  /* bigEndian = */
@@ -980,7 +1011,10 @@ function stringToAsciiOrUTF16BE(str) {
980
1011
  );
981
1012
  }
982
1013
  function isAscii(str) {
983
- return /^[\x00-\x7F]*$/.test(str);
1014
+ if (typeof str !== "string") {
1015
+ return false;
1016
+ }
1017
+ return !str || /^[\x00-\x7F]*$/.test(str);
984
1018
  }
985
1019
  function stringToUTF16HexString(str) {
986
1020
  const buf = [];
@@ -2270,6 +2304,9 @@ var _IccColorSpace = class _IccColorSpace extends ColorSpace {
2270
2304
  if (!__privateGet(this, _transformer)) {
2271
2305
  throw new Error("Failed to create ICC color space");
2272
2306
  }
2307
+ __privateGet(_IccColorSpace, _finalizer) || __privateSet(_IccColorSpace, _finalizer, new FinalizationRegistry((transformer) => {
2308
+ qcms_drop_transformer(transformer);
2309
+ }));
2273
2310
  __privateGet(_IccColorSpace, _finalizer).register(this, __privateGet(this, _transformer));
2274
2311
  }
2275
2312
  getRgbHex(src, srcOffset) {
@@ -2350,9 +2387,7 @@ _wasmUrl = new WeakMap();
2350
2387
  _finalizer = new WeakMap();
2351
2388
  __privateAdd(_IccColorSpace, _useWasm, true);
2352
2389
  __privateAdd(_IccColorSpace, _wasmUrl, null);
2353
- __privateAdd(_IccColorSpace, _finalizer, new FinalizationRegistry((transformer) => {
2354
- qcms_drop_transformer(transformer);
2355
- }));
2390
+ __privateAdd(_IccColorSpace, _finalizer, null);
2356
2391
  var IccColorSpace = _IccColorSpace;
2357
2392
  var _iccUrl;
2358
2393
  var _CmykICCBasedCS = class _CmykICCBasedCS extends IccColorSpace {
@@ -55855,6 +55890,22 @@ var PartialEvaluator = class _PartialEvaluator {
55855
55890
  args[0] = Math.abs(thickness);
55856
55891
  break;
55857
55892
  }
55893
+ case OPS.setDash: {
55894
+ const dashPhase = args[1];
55895
+ if (typeof dashPhase !== "number") {
55896
+ warn(`Invalid setDash: ${dashPhase}`);
55897
+ continue;
55898
+ }
55899
+ const dashArray = args[0];
55900
+ if (!Array.isArray(dashArray)) {
55901
+ warn(`Invalid setDash: ${dashArray}`);
55902
+ continue;
55903
+ }
55904
+ if (dashArray.some((x) => typeof x !== "number")) {
55905
+ args[0] = dashArray.filter((x) => typeof x === "number");
55906
+ }
55907
+ break;
55908
+ }
55858
55909
  case OPS.moveTo:
55859
55910
  case OPS.lineTo:
55860
55911
  case OPS.curveTo:
@@ -58503,11 +58554,11 @@ var FakeUnicodeFont = class _FakeUnicodeFont {
58503
58554
  get fontDescriptorRef() {
58504
58555
  if (!_FakeUnicodeFont._fontDescriptorRef) {
58505
58556
  const fontDescriptor = new Dict(this.xref);
58506
- fontDescriptor.set("Type", Name.get("FontDescriptor"));
58557
+ fontDescriptor.setIfName("Type", "FontDescriptor");
58507
58558
  fontDescriptor.set("FontName", this.fontName);
58508
58559
  fontDescriptor.set("FontFamily", "MyriadPro Regular");
58509
58560
  fontDescriptor.set("FontBBox", [0, 0, 0, 0]);
58510
- fontDescriptor.set("FontStretch", Name.get("Normal"));
58561
+ fontDescriptor.setIfName("FontStretch", "Normal");
58511
58562
  fontDescriptor.set("FontWeight", 400);
58512
58563
  fontDescriptor.set("ItalicAngle", 0);
58513
58564
  _FakeUnicodeFont._fontDescriptorRef = this.xref.getNewPersistentRef(fontDescriptor);
@@ -58517,9 +58568,9 @@ var FakeUnicodeFont = class _FakeUnicodeFont {
58517
58568
  get descendantFontRef() {
58518
58569
  const descendantFont = new Dict(this.xref);
58519
58570
  descendantFont.set("BaseFont", this.fontName);
58520
- descendantFont.set("Type", Name.get("Font"));
58521
- descendantFont.set("Subtype", Name.get("CIDFontType0"));
58522
- descendantFont.set("CIDToGIDMap", Name.get("Identity"));
58571
+ descendantFont.setIfName("Type", "Font");
58572
+ descendantFont.setIfName("Subtype", "CIDFontType0");
58573
+ descendantFont.setIfName("CIDToGIDMap", "Identity");
58523
58574
  descendantFont.set("FirstChar", this.firstChar);
58524
58575
  descendantFont.set("LastChar", this.lastChar);
58525
58576
  descendantFont.set("FontDescriptor", this.fontDescriptorRef);
@@ -58556,11 +58607,11 @@ var FakeUnicodeFont = class _FakeUnicodeFont {
58556
58607
  get baseFontRef() {
58557
58608
  const baseFont = new Dict(this.xref);
58558
58609
  baseFont.set("BaseFont", this.fontName);
58559
- baseFont.set("Type", Name.get("Font"));
58560
- baseFont.set("Subtype", Name.get("Type0"));
58561
- baseFont.set("Encoding", Name.get("Identity-H"));
58610
+ baseFont.setIfName("Type", "Font");
58611
+ baseFont.setIfName("Subtype", "Type0");
58612
+ baseFont.setIfName("Encoding", "Identity-H");
58562
58613
  baseFont.set("DescendantFonts", [this.descendantFontRef]);
58563
- baseFont.set("ToUnicode", Name.get("Identity-H"));
58614
+ baseFont.setIfName("ToUnicode", "Identity-H");
58564
58615
  return this.xref.getNewPersistentRef(baseFont);
58565
58616
  }
58566
58617
  get resources() {
@@ -58666,7 +58717,7 @@ var FakeUnicodeFont = class _FakeUnicodeFont {
58666
58717
  const r0 = new Dict(this.xref);
58667
58718
  r0.set("ca", strokeAlpha);
58668
58719
  r0.set("CA", strokeAlpha);
58669
- r0.set("Type", Name.get("ExtGState"));
58720
+ r0.setIfName("Type", "ExtGState");
58670
58721
  extGState.set("R0", r0);
58671
58722
  resources.set("ExtGState", extGState);
58672
58723
  }
@@ -58677,8 +58728,8 @@ var FakeUnicodeFont = class _FakeUnicodeFont {
58677
58728
  buffer.push("ET", "Q");
58678
58729
  const appearance = buffer.join("\n");
58679
58730
  const appearanceStreamDict = new Dict(this.xref);
58680
- appearanceStreamDict.set("Subtype", Name.get("Form"));
58681
- appearanceStreamDict.set("Type", Name.get("XObject"));
58731
+ appearanceStreamDict.setIfName("Subtype", "Form");
58732
+ appearanceStreamDict.setIfName("Type", "XObject");
58682
58733
  appearanceStreamDict.set("BBox", [0, 0, w, h]);
58683
58734
  appearanceStreamDict.set("Length", appearance.length);
58684
58735
  appearanceStreamDict.set("Resources", resources);
@@ -74066,11 +74117,12 @@ var AnnotationFactory = class {
74066
74117
  * @param {Object} idFactory
74067
74118
  * @param {boolean} [collectFields]
74068
74119
  * @param {Object} [orphanFields]
74120
+ * @param {Array<string>} [collectByType]
74069
74121
  * @param {Object} [pageRef]
74070
74122
  * @returns {Promise} A promise that is resolved with an {Annotation}
74071
74123
  * instance.
74072
74124
  */
74073
- static async create(xref, ref, annotationGlobals, idFactory, collectFields, orphanFields, pageRef) {
74125
+ static async create(xref, ref, annotationGlobals, idFactory, collectFields, orphanFields, collectByType, pageRef) {
74074
74126
  const pageIndex = collectFields ? await this._getPageIndex(xref, ref, annotationGlobals.pdfManager) : null;
74075
74127
  return annotationGlobals.pdfManager.ensure(this, "_create", [
74076
74128
  xref,
@@ -74079,6 +74131,7 @@ var AnnotationFactory = class {
74079
74131
  idFactory,
74080
74132
  collectFields,
74081
74133
  orphanFields,
74134
+ collectByType,
74082
74135
  pageIndex,
74083
74136
  pageRef
74084
74137
  ]);
@@ -74086,15 +74139,18 @@ var AnnotationFactory = class {
74086
74139
  /**
74087
74140
  * @private
74088
74141
  */
74089
- static _create(xref, ref, annotationGlobals, idFactory, collectFields = false, orphanFields = null, pageIndex = null, pageRef = null) {
74142
+ static _create(xref, ref, annotationGlobals, idFactory, collectFields = false, orphanFields = null, collectByType = null, pageIndex = null, pageRef = null) {
74090
74143
  const dict = xref.fetchIfRef(ref);
74091
74144
  if (!(dict instanceof Dict)) {
74092
74145
  return void 0;
74093
74146
  }
74094
- const { acroForm, pdfManager } = annotationGlobals;
74095
- const id = ref instanceof Ref ? ref.toString() : `annot_${idFactory.createObjId()}`;
74096
74147
  let subtype = dict.get("Subtype");
74097
74148
  subtype = subtype instanceof Name ? subtype.name : null;
74149
+ if (collectByType && !collectByType.has(AnnotationType[subtype.toUpperCase()])) {
74150
+ return null;
74151
+ }
74152
+ const { acroForm, pdfManager } = annotationGlobals;
74153
+ const id = ref instanceof Ref ? ref.toString() : `annot_${idFactory.createObjId()}`;
74098
74154
  const parameters = {
74099
74155
  xref,
74100
74156
  ref,
@@ -74239,10 +74295,10 @@ var AnnotationFactory = class {
74239
74295
  case AnnotationEditorType.FREETEXT:
74240
74296
  if (!baseFontRef) {
74241
74297
  const baseFont = new Dict(xref);
74242
- baseFont.set("BaseFont", Name.get("Helvetica"));
74243
- baseFont.set("Type", Name.get("Font"));
74244
- baseFont.set("Subtype", Name.get("Type1"));
74245
- baseFont.set("Encoding", Name.get("WinAnsiEncoding"));
74298
+ baseFont.setIfName("BaseFont", "Helvetica");
74299
+ baseFont.setIfName("Type", "Font");
74300
+ baseFont.setIfName("Subtype", "Type1");
74301
+ baseFont.setIfName("Encoding", "WinAnsiEncoding");
74246
74302
  baseFontRef = xref.getNewTemporaryRef();
74247
74303
  changes.put(baseFontRef, {
74248
74304
  data: baseFont
@@ -74303,7 +74359,7 @@ var AnnotationFactory = class {
74303
74359
  }
74304
74360
  }
74305
74361
  return {
74306
- annotations: await Promise.all(promises)
74362
+ annotations: (await Promise.all(promises)).flat()
74307
74363
  };
74308
74364
  }
74309
74365
  static async printNewAnnotations(annotationGlobals, evaluator, task, annotations, imagePromises) {
@@ -74428,8 +74484,8 @@ function getRgbColor(color, defaultColor = new Uint8ClampedArray(3)) {
74428
74484
  return defaultColor;
74429
74485
  }
74430
74486
  }
74431
- function getPdfColorArray(color) {
74432
- return Array.from(color, (c) => c / 255);
74487
+ function getPdfColorArray(color, defaultValue = null) {
74488
+ return color && Array.from(color, (c) => c / 255) || defaultValue;
74433
74489
  }
74434
74490
  function getQuadPoints(dict, rect) {
74435
74491
  const quadPoints = dict.getArray("QuadPoints");
@@ -75358,20 +75414,16 @@ var MarkupAnnotation = class extends Annotation {
75358
75414
  buffer.push("Q");
75359
75415
  const formDict = new Dict(xref);
75360
75416
  const appearanceStreamDict = new Dict(xref);
75361
- appearanceStreamDict.set("Subtype", Name.get("Form"));
75417
+ appearanceStreamDict.setIfName("Subtype", "Form");
75362
75418
  const appearanceStream = new StringStream(buffer.join(" "));
75363
75419
  appearanceStream.dict = appearanceStreamDict;
75364
75420
  formDict.set("Fm0", appearanceStream);
75365
75421
  const gsDict = new Dict(xref);
75366
75422
  if (blendMode) {
75367
- gsDict.set("BM", Name.get(blendMode));
75368
- }
75369
- if (typeof strokeAlpha === "number") {
75370
- gsDict.set("CA", strokeAlpha);
75371
- }
75372
- if (typeof fillAlpha === "number") {
75373
- gsDict.set("ca", fillAlpha);
75423
+ gsDict.setIfName("BM", blendMode);
75374
75424
  }
75425
+ gsDict.setIfNumber("CA", strokeAlpha);
75426
+ gsDict.setIfNumber("ca", fillAlpha);
75375
75427
  const stateDict = new Dict(xref);
75376
75428
  stateDict.set("GS0", gsDict);
75377
75429
  const resources = new Dict(xref);
@@ -75405,7 +75457,27 @@ var MarkupAnnotation = class extends Annotation {
75405
75457
  changes.put(annotationRef, {
75406
75458
  data: annotationDict
75407
75459
  });
75408
- return { ref: annotationRef };
75460
+ const retRef = { ref: annotationRef };
75461
+ if (annotation.popup) {
75462
+ const popup = annotation.popup;
75463
+ if (popup.deleted) {
75464
+ annotationDict.delete("Popup");
75465
+ annotationDict.delete("Contents");
75466
+ annotationDict.delete("RC");
75467
+ return retRef;
75468
+ }
75469
+ const popupRef = popup.ref || (popup.ref = xref.getNewTemporaryRef());
75470
+ popup.parent = annotationRef;
75471
+ const popupDict = PopupAnnotation.createNewDict(popup, xref);
75472
+ changes.put(popupRef, { data: popupDict });
75473
+ annotationDict.setIfDefined(
75474
+ "Contents",
75475
+ stringToAsciiOrUTF16BE(popup.contents)
75476
+ );
75477
+ annotationDict.set("Popup", popupRef);
75478
+ return [retRef, { ref: popupRef }];
75479
+ }
75480
+ return retRef;
75409
75481
  }
75410
75482
  static async createNewPrintAnnotation(annotationGlobals, xref, annotation, params) {
75411
75483
  const ap = await this.createNewAppearanceStream(annotation, xref, params);
@@ -75629,12 +75701,8 @@ var WidgetAnnotation = class _WidgetAnnotation extends Annotation {
75629
75701
  if (rotation) {
75630
75702
  mk.set("R", rotation);
75631
75703
  }
75632
- if (this.borderColor) {
75633
- mk.set("BC", getPdfColorArray(this.borderColor));
75634
- }
75635
- if (this.backgroundColor) {
75636
- mk.set("BG", getPdfColorArray(this.backgroundColor));
75637
- }
75704
+ mk.setIfArray("BC", getPdfColorArray(this.borderColor));
75705
+ mk.setIfArray("BG", getPdfColorArray(this.backgroundColor));
75638
75706
  return mk.size > 0 ? mk : null;
75639
75707
  }
75640
75708
  amendSavedDict(annotationStorage, dict) {
@@ -75737,7 +75805,7 @@ var WidgetAnnotation = class _WidgetAnnotation extends Annotation {
75737
75805
  const resources = this._getSaveFieldResources(xref);
75738
75806
  const appearanceStream = new StringStream(appearance);
75739
75807
  const appearanceDict = appearanceStream.dict = new Dict(xref);
75740
- appearanceDict.set("Subtype", Name.get("Form"));
75808
+ appearanceDict.setIfName("Subtype", "Form");
75741
75809
  appearanceDict.set("Resources", resources);
75742
75810
  const bbox = rotation % 180 === 0 ? [0, 0, this.width, this.height] : [0, 0, this.height, this.width];
75743
75811
  appearanceDict.set("BBox", bbox);
@@ -76114,17 +76182,52 @@ var TextWidgetAnnotation = class extends WidgetAnnotation {
76114
76182
  const {
76115
76183
  data: { actions }
76116
76184
  } = this;
76117
- for (const keystrokeAction of actions?.Keystroke || []) {
76118
- const m = keystrokeAction.trim().match(/^AF(Date|Time)_Keystroke(?:Ex)?\(['"]?([^'"]+)['"]?\);$/);
76119
- if (m) {
76120
- let format = m[2];
76121
- const num = parseInt(format, 10);
76122
- if (!isNaN(num) && Math.floor(Math.log10(num)) + 1 === m[2].length) {
76123
- format = (m[1] === "Date" ? DateFormats : TimeFormats)[num] ?? format;
76124
- }
76125
- this.data[m[1] === "Date" ? "dateFormat" : "timeFormat"] = format;
76185
+ if (!actions) {
76186
+ return;
76187
+ }
76188
+ const AFDateTime = /^AF(Date|Time)_(?:Keystroke|Format)(?:Ex)?\(['"]?([^'"]+)['"]?\);$/;
76189
+ let canUseHTMLDateTime = false;
76190
+ 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])) {
76191
+ canUseHTMLDateTime = true;
76192
+ }
76193
+ const actionsToVisit = [];
76194
+ if (actions.Format) {
76195
+ actionsToVisit.push(...actions.Format);
76196
+ }
76197
+ if (actions.Keystroke) {
76198
+ actionsToVisit.push(...actions.Keystroke);
76199
+ }
76200
+ if (canUseHTMLDateTime) {
76201
+ delete actions.Keystroke;
76202
+ actions.Format = actionsToVisit;
76203
+ }
76204
+ for (const formatAction of actionsToVisit) {
76205
+ const m = formatAction.match(AFDateTime);
76206
+ if (!m) {
76207
+ continue;
76208
+ }
76209
+ const isDate = m[1] === "Date";
76210
+ let format = m[2];
76211
+ const num = parseInt(format, 10);
76212
+ if (!isNaN(num) && Math.floor(Math.log10(num)) + 1 === m[2].length) {
76213
+ format = (isDate ? DateFormats : TimeFormats)[num] ?? format;
76214
+ }
76215
+ this.data.datetimeFormat = format;
76216
+ if (!canUseHTMLDateTime) {
76217
+ break;
76218
+ }
76219
+ if (isDate) {
76220
+ if (/HH|MM|ss|h/.test(format)) {
76221
+ this.data.datetimeType = "datetime-local";
76222
+ this.data.timeStep = /ss/.test(format) ? 1 : 60;
76223
+ } else {
76224
+ this.data.datetimeType = "date";
76225
+ }
76126
76226
  break;
76127
76227
  }
76228
+ this.data.datetimeType = "time";
76229
+ this.data.timeStep = /ss/.test(format) ? 1 : 60;
76230
+ break;
76128
76231
  }
76129
76232
  }
76130
76233
  get hasTextContent() {
@@ -76255,6 +76358,8 @@ var TextWidgetAnnotation = class extends WidgetAnnotation {
76255
76358
  strokeColor: this.data.borderColor,
76256
76359
  fillColor: this.data.backgroundColor,
76257
76360
  rotation: this.rotation,
76361
+ datetimeFormat: this.data.datetimeFormat,
76362
+ hasDatetimeHTML: !!this.data.datetimeType,
76258
76363
  type: "text"
76259
76364
  };
76260
76365
  }
@@ -76468,8 +76573,8 @@ var ButtonWidgetAnnotation = class extends WidgetAnnotation {
76468
76573
  const appearance = `q BT /PdfJsZaDb ${fontSize} Tf 0 g ${xShift} ${yShift} Td (${char}) Tj ET Q`;
76469
76574
  const appearanceStreamDict = new Dict(params.xref);
76470
76575
  appearanceStreamDict.set("FormType", 1);
76471
- appearanceStreamDict.set("Subtype", Name.get("Form"));
76472
- appearanceStreamDict.set("Type", Name.get("XObject"));
76576
+ appearanceStreamDict.setIfName("Subtype", "Form");
76577
+ appearanceStreamDict.setIfName("Type", "XObject");
76473
76578
  appearanceStreamDict.set("BBox", bbox);
76474
76579
  appearanceStreamDict.set("Matrix", [1, 0, 0, 1, 0, 0]);
76475
76580
  appearanceStreamDict.set("Length", appearance.length);
@@ -76618,10 +76723,10 @@ var ButtonWidgetAnnotation = class extends WidgetAnnotation {
76618
76723
  }
76619
76724
  get fallbackFontDict() {
76620
76725
  const dict = new Dict();
76621
- dict.set("BaseFont", Name.get("ZapfDingbats"));
76622
- dict.set("Type", Name.get("FallbackType"));
76623
- dict.set("Subtype", Name.get("FallbackType"));
76624
- dict.set("Encoding", Name.get("ZapfDingbatsEncoding"));
76726
+ dict.setIfName("BaseFont", "ZapfDingbats");
76727
+ dict.setIfName("Type", "FallbackType");
76728
+ dict.setIfName("Subtype", "FallbackType");
76729
+ dict.setIfName("Encoding", "ZapfDingbatsEncoding");
76625
76730
  return shadow(this, "fallbackFontDict", dict);
76626
76731
  }
76627
76732
  };
@@ -76885,6 +76990,9 @@ var LinkAnnotation = class extends Annotation {
76885
76990
  docAttachments: annotationGlobals.attachments
76886
76991
  });
76887
76992
  }
76993
+ get overlaysTextContent() {
76994
+ return true;
76995
+ }
76888
76996
  };
76889
76997
  var PopupAnnotation = class extends Annotation {
76890
76998
  constructor(params) {
@@ -76901,6 +77009,7 @@ var PopupAnnotation = class extends Annotation {
76901
77009
  return;
76902
77010
  }
76903
77011
  this.data.parentRect = lookupNormalRect(parentItem.getArray("Rect"), null);
77012
+ this.data.creationDate = parentItem.get("CreationDate") || "";
76904
77013
  const rt = parentItem.get("RT");
76905
77014
  if (isName(rt, AnnotationReplyType.GROUP)) {
76906
77015
  parentItem = parentItem.get("IRT");
@@ -76932,6 +77041,19 @@ var PopupAnnotation = class extends Annotation {
76932
77041
  }
76933
77042
  this.data.open = !!dict.get("Open");
76934
77043
  }
77044
+ static createNewDict(annotation, xref, _params) {
77045
+ const { oldAnnotation, rect, parent } = annotation;
77046
+ const popup = oldAnnotation || new Dict(xref);
77047
+ popup.setIfNotExists("Type", Name.get("Annot"));
77048
+ popup.setIfNotExists("Subtype", Name.get("Popup"));
77049
+ popup.setIfNotExists("Open", false);
77050
+ popup.setIfArray("Rect", rect);
77051
+ popup.set("Parent", parent);
77052
+ return popup;
77053
+ }
77054
+ static async createNewAppearanceStream(annotation, xref, params) {
77055
+ return null;
77056
+ }
76935
77057
  };
76936
77058
  var FreeTextAnnotation = class extends MarkupAnnotation {
76937
77059
  constructor(params) {
@@ -76988,54 +77110,61 @@ var FreeTextAnnotation = class extends MarkupAnnotation {
76988
77110
  return this._hasAppearance;
76989
77111
  }
76990
77112
  static createNewDict(annotation, xref, { apRef, ap }) {
76991
- const { color, fontSize, oldAnnotation, rect, rotation, user, value } = annotation;
77113
+ const {
77114
+ color,
77115
+ date,
77116
+ fontSize,
77117
+ oldAnnotation,
77118
+ rect,
77119
+ rotation,
77120
+ user,
77121
+ value
77122
+ } = annotation;
76992
77123
  const freetext = oldAnnotation || new Dict(xref);
76993
- freetext.set("Type", Name.get("Annot"));
76994
- freetext.set("Subtype", Name.get("FreeText"));
77124
+ freetext.setIfNotExists("Type", Name.get("Annot"));
77125
+ freetext.setIfNotExists("Subtype", Name.get("FreeText"));
77126
+ freetext.set(
77127
+ oldAnnotation ? "M" : "CreationDate",
77128
+ `D:${getModificationDate(date)}`
77129
+ );
76995
77130
  if (oldAnnotation) {
76996
- freetext.set("M", `D:${getModificationDate()}`);
76997
77131
  freetext.delete("RC");
76998
- } else {
76999
- freetext.set("CreationDate", `D:${getModificationDate()}`);
77000
77132
  }
77001
- freetext.set("Rect", rect);
77133
+ freetext.setIfArray("Rect", rect);
77002
77134
  const da = `/Helv ${fontSize} Tf ${getPdfColor(
77003
77135
  color,
77004
77136
  /* isFill */
77005
77137
  true
77006
77138
  )}`;
77007
77139
  freetext.set("DA", da);
77008
- freetext.set("Contents", stringToAsciiOrUTF16BE(value));
77009
- freetext.set("F", 4);
77010
- freetext.set("Border", [0, 0, 0]);
77011
- freetext.set("Rotate", rotation);
77012
- if (user) {
77013
- freetext.set("T", stringToAsciiOrUTF16BE(user));
77014
- }
77140
+ freetext.setIfDefined("Contents", stringToAsciiOrUTF16BE(value));
77141
+ freetext.setIfNotExists("F", 4);
77142
+ freetext.setIfNotExists("Border", [0, 0, 0]);
77143
+ freetext.setIfNumber("Rotate", rotation);
77144
+ freetext.setIfDefined("T", stringToAsciiOrUTF16BE(user));
77015
77145
  if (apRef || ap) {
77016
77146
  const n = new Dict(xref);
77017
77147
  freetext.set("AP", n);
77018
- if (apRef) {
77019
- n.set("N", apRef);
77020
- } else {
77021
- n.set("N", ap);
77022
- }
77148
+ n.set("N", apRef || ap);
77023
77149
  }
77024
77150
  return freetext;
77025
77151
  }
77026
77152
  static async createNewAppearanceStream(annotation, xref, params) {
77027
77153
  const { baseFontRef, evaluator, task } = params;
77028
77154
  const { color, fontSize, rect, rotation, value } = annotation;
77155
+ if (!color) {
77156
+ return null;
77157
+ }
77029
77158
  const resources = new Dict(xref);
77030
77159
  const font = new Dict(xref);
77031
77160
  if (baseFontRef) {
77032
77161
  font.set("Helv", baseFontRef);
77033
77162
  } else {
77034
77163
  const baseFont = new Dict(xref);
77035
- baseFont.set("BaseFont", Name.get("Helvetica"));
77036
- baseFont.set("Type", Name.get("Font"));
77037
- baseFont.set("Subtype", Name.get("Type1"));
77038
- baseFont.set("Encoding", Name.get("WinAnsiEncoding"));
77164
+ baseFont.setIfName("BaseFont", "Helvetica");
77165
+ baseFont.setIfName("Type", "Font");
77166
+ baseFont.setIfName("Subtype", "Type1");
77167
+ baseFont.setIfName("Encoding", "WinAnsiEncoding");
77039
77168
  font.set("Helv", baseFont);
77040
77169
  }
77041
77170
  resources.set("Font", font);
@@ -77132,8 +77261,8 @@ var FreeTextAnnotation = class extends MarkupAnnotation {
77132
77261
  const appearance = buffer.join("\n");
77133
77262
  const appearanceStreamDict = new Dict(xref);
77134
77263
  appearanceStreamDict.set("FormType", 1);
77135
- appearanceStreamDict.set("Subtype", Name.get("Form"));
77136
- appearanceStreamDict.set("Type", Name.get("XObject"));
77264
+ appearanceStreamDict.setIfName("Subtype", "Form");
77265
+ appearanceStreamDict.setIfName("Type", "XObject");
77137
77266
  appearanceStreamDict.set("BBox", rect);
77138
77267
  appearanceStreamDict.set("Resources", resources);
77139
77268
  appearanceStreamDict.set("Matrix", [1, 0, 0, 1, -rect[0], -rect[1]]);
@@ -77156,10 +77285,10 @@ var LineAnnotation = class extends MarkupAnnotation {
77156
77285
  this.data.lineEndings = this.lineEndings;
77157
77286
  }
77158
77287
  if (!this.appearance) {
77159
- const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
77288
+ const strokeColor = getPdfColorArray(this.color, [0, 0, 0]);
77160
77289
  const strokeAlpha = dict.get("CA");
77161
77290
  const interiorColor = getRgbColor(dict.getArray("IC"), null);
77162
- const fillColor = interiorColor ? getPdfColorArray(interiorColor) : null;
77291
+ const fillColor = getPdfColorArray(interiorColor);
77163
77292
  const fillAlpha = fillColor ? strokeAlpha : null;
77164
77293
  const borderWidth = this.borderStyle.width || 1, borderAdjust = 2 * borderWidth;
77165
77294
  const bbox = [
@@ -77203,10 +77332,10 @@ var SquareAnnotation = class extends MarkupAnnotation {
77203
77332
  this.data.hasOwnCanvas = this.data.noRotate;
77204
77333
  this.data.noHTML = false;
77205
77334
  if (!this.appearance) {
77206
- const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
77335
+ const strokeColor = getPdfColorArray(this.color, [0, 0, 0]);
77207
77336
  const strokeAlpha = dict.get("CA");
77208
77337
  const interiorColor = getRgbColor(dict.getArray("IC"), null);
77209
- const fillColor = interiorColor ? getPdfColorArray(interiorColor) : null;
77338
+ const fillColor = getPdfColorArray(interiorColor);
77210
77339
  const fillAlpha = fillColor ? strokeAlpha : null;
77211
77340
  if (this.borderStyle.width === 0 && !fillColor) {
77212
77341
  return;
@@ -77241,10 +77370,10 @@ var CircleAnnotation = class extends MarkupAnnotation {
77241
77370
  const { dict, xref } = params;
77242
77371
  this.data.annotationType = AnnotationType.CIRCLE;
77243
77372
  if (!this.appearance) {
77244
- const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
77373
+ const strokeColor = getPdfColorArray(this.color, [0, 0, 0]);
77245
77374
  const strokeAlpha = dict.get("CA");
77246
77375
  const interiorColor = getRgbColor(dict.getArray("IC"), null);
77247
- const fillColor = interiorColor ? getPdfColorArray(interiorColor) : null;
77376
+ const fillColor = getPdfColorArray(interiorColor);
77248
77377
  const fillAlpha = fillColor ? strokeAlpha : null;
77249
77378
  if (this.borderStyle.width === 0 && !fillColor) {
77250
77379
  return;
@@ -77303,8 +77432,22 @@ var PolylineAnnotation = class extends MarkupAnnotation {
77303
77432
  }
77304
77433
  const vertices = this.data.vertices = Float32Array.from(rawVertices);
77305
77434
  if (!this.appearance) {
77306
- const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
77435
+ const strokeColor = getPdfColorArray(this.color, [0, 0, 0]);
77307
77436
  const strokeAlpha = dict.get("CA");
77437
+ let fillColor = getRgbColor(dict.getArray("IC"), null);
77438
+ if (fillColor) {
77439
+ fillColor = getPdfColorArray(fillColor);
77440
+ }
77441
+ let operator;
77442
+ if (fillColor) {
77443
+ if (this.color) {
77444
+ operator = fillColor.every((c, i) => c === strokeColor[i]) ? "f" : "B";
77445
+ } else {
77446
+ operator = "f";
77447
+ }
77448
+ } else {
77449
+ operator = "S";
77450
+ }
77308
77451
  const borderWidth = this.borderStyle.width || 1, borderAdjust = 2 * borderWidth;
77309
77452
  const bbox = [Infinity, Infinity, -Infinity, -Infinity];
77310
77453
  for (let i = 0, ii = vertices.length; i < ii; i += 2) {
@@ -77324,13 +77467,15 @@ var PolylineAnnotation = class extends MarkupAnnotation {
77324
77467
  extra: `${borderWidth} w`,
77325
77468
  strokeColor,
77326
77469
  strokeAlpha,
77470
+ fillColor,
77471
+ fillAlpha: fillColor ? strokeAlpha : null,
77327
77472
  pointsCallback: (buffer, points) => {
77328
77473
  for (let i = 0, ii = vertices.length; i < ii; i += 2) {
77329
77474
  buffer.push(
77330
77475
  `${vertices[i]} ${vertices[i + 1]} ${i === 0 ? "m" : "l"}`
77331
77476
  );
77332
77477
  }
77333
- buffer.push("S");
77478
+ buffer.push(operator);
77334
77479
  return [points[0], points[7], points[2], points[3]];
77335
77480
  }
77336
77481
  });
@@ -77379,7 +77524,7 @@ var InkAnnotation = class extends MarkupAnnotation {
77379
77524
  }
77380
77525
  }
77381
77526
  if (!this.appearance) {
77382
- const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
77527
+ const strokeColor = getPdfColorArray(this.color, [0, 0, 0]);
77383
77528
  const strokeAlpha = dict.get("CA");
77384
77529
  const borderWidth = this.borderStyle.width || 1, borderAdjust = 2 * borderWidth;
77385
77530
  const bbox = [Infinity, Infinity, -Infinity, -Infinity];
@@ -77420,6 +77565,7 @@ var InkAnnotation = class extends MarkupAnnotation {
77420
77565
  const {
77421
77566
  oldAnnotation,
77422
77567
  color,
77568
+ date,
77423
77569
  opacity,
77424
77570
  paths,
77425
77571
  outlines,
@@ -77429,30 +77575,31 @@ var InkAnnotation = class extends MarkupAnnotation {
77429
77575
  user
77430
77576
  } = annotation;
77431
77577
  const ink = oldAnnotation || new Dict(xref);
77432
- ink.set("Type", Name.get("Annot"));
77433
- ink.set("Subtype", Name.get("Ink"));
77434
- ink.set(oldAnnotation ? "M" : "CreationDate", `D:${getModificationDate()}`);
77435
- ink.set("Rect", rect);
77436
- ink.set("InkList", outlines?.points || paths.points);
77437
- ink.set("F", 4);
77438
- ink.set("Rotate", rotation);
77439
- if (user) {
77440
- ink.set("T", stringToAsciiOrUTF16BE(user));
77441
- }
77578
+ ink.setIfNotExists("Type", Name.get("Annot"));
77579
+ ink.setIfNotExists("Subtype", Name.get("Ink"));
77580
+ ink.set(
77581
+ oldAnnotation ? "M" : "CreationDate",
77582
+ `D:${getModificationDate(date)}`
77583
+ );
77584
+ ink.setIfArray("Rect", rect);
77585
+ ink.setIfArray("InkList", outlines?.points || paths?.points);
77586
+ ink.setIfNotExists("F", 4);
77587
+ ink.setIfNumber("Rotate", rotation);
77588
+ ink.setIfDefined("T", stringToAsciiOrUTF16BE(user));
77442
77589
  if (outlines) {
77443
- ink.set("IT", Name.get("InkHighlight"));
77444
- }
77445
- const bs = new Dict(xref);
77446
- ink.set("BS", bs);
77447
- bs.set("W", thickness);
77448
- ink.set("C", getPdfColorArray(color));
77449
- ink.set("CA", opacity);
77450
- const n = new Dict(xref);
77451
- ink.set("AP", n);
77452
- if (apRef) {
77453
- n.set("N", apRef);
77454
- } else {
77455
- n.set("N", ap);
77590
+ ink.setIfName("IT", "InkHighlight");
77591
+ }
77592
+ if (thickness > 0) {
77593
+ const bs = new Dict(xref);
77594
+ ink.set("BS", bs);
77595
+ bs.set("W", thickness);
77596
+ }
77597
+ ink.setIfArray("C", getPdfColorArray(color));
77598
+ ink.setIfNumber("CA", opacity);
77599
+ if (ap || apRef) {
77600
+ const n = new Dict(xref);
77601
+ ink.set("AP", n);
77602
+ n.set("N", apRef || ap);
77456
77603
  }
77457
77604
  return ink;
77458
77605
  }
@@ -77465,6 +77612,9 @@ var InkAnnotation = class extends MarkupAnnotation {
77465
77612
  );
77466
77613
  }
77467
77614
  const { color, rect, paths, thickness, opacity } = annotation;
77615
+ if (!color) {
77616
+ return null;
77617
+ }
77468
77618
  const appearanceBuffer = [
77469
77619
  `${thickness} w 1 J 1 j`,
77470
77620
  `${getPdfColor(
@@ -77504,8 +77654,8 @@ var InkAnnotation = class extends MarkupAnnotation {
77504
77654
  const appearance = appearanceBuffer.join("\n");
77505
77655
  const appearanceStreamDict = new Dict(xref);
77506
77656
  appearanceStreamDict.set("FormType", 1);
77507
- appearanceStreamDict.set("Subtype", Name.get("Form"));
77508
- appearanceStreamDict.set("Type", Name.get("XObject"));
77657
+ appearanceStreamDict.setIfName("Subtype", "Form");
77658
+ appearanceStreamDict.setIfName("Type", "XObject");
77509
77659
  appearanceStreamDict.set("BBox", rect);
77510
77660
  appearanceStreamDict.set("Length", appearance.length);
77511
77661
  if (opacity !== 1) {
@@ -77513,7 +77663,7 @@ var InkAnnotation = class extends MarkupAnnotation {
77513
77663
  const extGState = new Dict(xref);
77514
77664
  const r0 = new Dict(xref);
77515
77665
  r0.set("CA", opacity);
77516
- r0.set("Type", Name.get("ExtGState"));
77666
+ r0.setIfName("Type", "ExtGState");
77517
77667
  extGState.set("R0", r0);
77518
77668
  resources.set("ExtGState", extGState);
77519
77669
  appearanceStreamDict.set("Resources", resources);
@@ -77529,6 +77679,9 @@ var InkAnnotation = class extends MarkupAnnotation {
77529
77679
  outlines: { outline },
77530
77680
  opacity
77531
77681
  } = annotation;
77682
+ if (!color) {
77683
+ return null;
77684
+ }
77532
77685
  const appearanceBuffer = [
77533
77686
  `${getPdfColor(
77534
77687
  color,
@@ -77558,8 +77711,8 @@ var InkAnnotation = class extends MarkupAnnotation {
77558
77711
  const appearance = appearanceBuffer.join("\n");
77559
77712
  const appearanceStreamDict = new Dict(xref);
77560
77713
  appearanceStreamDict.set("FormType", 1);
77561
- appearanceStreamDict.set("Subtype", Name.get("Form"));
77562
- appearanceStreamDict.set("Type", Name.get("XObject"));
77714
+ appearanceStreamDict.setIfName("Subtype", "Form");
77715
+ appearanceStreamDict.setIfName("Type", "XObject");
77563
77716
  appearanceStreamDict.set("BBox", rect);
77564
77717
  appearanceStreamDict.set("Length", appearance.length);
77565
77718
  const resources = new Dict(xref);
@@ -77568,10 +77721,10 @@ var InkAnnotation = class extends MarkupAnnotation {
77568
77721
  appearanceStreamDict.set("Resources", resources);
77569
77722
  const r0 = new Dict(xref);
77570
77723
  extGState.set("R0", r0);
77571
- r0.set("BM", Name.get("Multiply"));
77724
+ r0.setIfName("BM", "Multiply");
77572
77725
  if (opacity !== 1) {
77573
77726
  r0.set("ca", opacity);
77574
- r0.set("Type", Name.get("ExtGState"));
77727
+ r0.setIfName("Type", "ExtGState");
77575
77728
  }
77576
77729
  const ap = new StringStream(appearance);
77577
77730
  ap.dict = appearanceStreamDict;
@@ -77593,7 +77746,7 @@ var HighlightAnnotation = class extends MarkupAnnotation {
77593
77746
  if (this.appearance) {
77594
77747
  warn("HighlightAnnotation - ignoring built-in appearance stream.");
77595
77748
  }
77596
- const fillColor = this.color ? getPdfColorArray(this.color) : [1, 1, 0];
77749
+ const fillColor = getPdfColorArray(this.color, [1, 1, 0]);
77597
77750
  const fillAlpha = dict.get("CA");
77598
77751
  this._setDefaultAppearance({
77599
77752
  xref,
@@ -77620,25 +77773,31 @@ var HighlightAnnotation = class extends MarkupAnnotation {
77620
77773
  return true;
77621
77774
  }
77622
77775
  static createNewDict(annotation, xref, { apRef, ap }) {
77623
- const { color, oldAnnotation, opacity, rect, rotation, user, quadPoints } = annotation;
77776
+ const {
77777
+ color,
77778
+ date,
77779
+ oldAnnotation,
77780
+ opacity,
77781
+ rect,
77782
+ rotation,
77783
+ user,
77784
+ quadPoints
77785
+ } = annotation;
77624
77786
  const highlight = oldAnnotation || new Dict(xref);
77625
- highlight.set("Type", Name.get("Annot"));
77626
- highlight.set("Subtype", Name.get("Highlight"));
77787
+ highlight.setIfNotExists("Type", Name.get("Annot"));
77788
+ highlight.setIfNotExists("Subtype", Name.get("Highlight"));
77627
77789
  highlight.set(
77628
77790
  oldAnnotation ? "M" : "CreationDate",
77629
- `D:${getModificationDate()}`
77791
+ `D:${getModificationDate(date)}`
77630
77792
  );
77631
- highlight.set("CreationDate", `D:${getModificationDate()}`);
77632
- highlight.set("Rect", rect);
77633
- highlight.set("F", 4);
77634
- highlight.set("Border", [0, 0, 0]);
77635
- highlight.set("Rotate", rotation);
77636
- highlight.set("QuadPoints", quadPoints);
77637
- highlight.set("C", getPdfColorArray(color));
77638
- highlight.set("CA", opacity);
77639
- if (user) {
77640
- highlight.set("T", stringToAsciiOrUTF16BE(user));
77641
- }
77793
+ highlight.setIfArray("Rect", rect);
77794
+ highlight.setIfNotExists("F", 4);
77795
+ highlight.setIfNotExists("Border", [0, 0, 0]);
77796
+ highlight.setIfNumber("Rotate", rotation);
77797
+ highlight.setIfArray("QuadPoints", quadPoints);
77798
+ highlight.setIfArray("C", getPdfColorArray(color));
77799
+ highlight.setIfNumber("CA", opacity);
77800
+ highlight.setIfDefined("T", stringToAsciiOrUTF16BE(user));
77642
77801
  if (apRef || ap) {
77643
77802
  const n = new Dict(xref);
77644
77803
  highlight.set("AP", n);
@@ -77648,6 +77807,9 @@ var HighlightAnnotation = class extends MarkupAnnotation {
77648
77807
  }
77649
77808
  static async createNewAppearanceStream(annotation, xref, params) {
77650
77809
  const { color, rect, outlines, opacity } = annotation;
77810
+ if (!color) {
77811
+ return null;
77812
+ }
77651
77813
  const appearanceBuffer = [
77652
77814
  `${getPdfColor(
77653
77815
  color,
@@ -77674,8 +77836,8 @@ var HighlightAnnotation = class extends MarkupAnnotation {
77674
77836
  const appearance = appearanceBuffer.join("\n");
77675
77837
  const appearanceStreamDict = new Dict(xref);
77676
77838
  appearanceStreamDict.set("FormType", 1);
77677
- appearanceStreamDict.set("Subtype", Name.get("Form"));
77678
- appearanceStreamDict.set("Type", Name.get("XObject"));
77839
+ appearanceStreamDict.setIfName("Subtype", "Form");
77840
+ appearanceStreamDict.setIfName("Type", "XObject");
77679
77841
  appearanceStreamDict.set("BBox", rect);
77680
77842
  appearanceStreamDict.set("Length", appearance.length);
77681
77843
  const resources = new Dict(xref);
@@ -77684,10 +77846,10 @@ var HighlightAnnotation = class extends MarkupAnnotation {
77684
77846
  appearanceStreamDict.set("Resources", resources);
77685
77847
  const r0 = new Dict(xref);
77686
77848
  extGState.set("R0", r0);
77687
- r0.set("BM", Name.get("Multiply"));
77849
+ r0.setIfName("BM", "Multiply");
77688
77850
  if (opacity !== 1) {
77689
77851
  r0.set("ca", opacity);
77690
- r0.set("Type", Name.get("ExtGState"));
77852
+ r0.setIfName("Type", "ExtGState");
77691
77853
  }
77692
77854
  const ap = new StringStream(appearance);
77693
77855
  ap.dict = appearanceStreamDict;
@@ -77702,7 +77864,7 @@ var UnderlineAnnotation = class extends MarkupAnnotation {
77702
77864
  const quadPoints = this.data.quadPoints = getQuadPoints(dict, null);
77703
77865
  if (quadPoints) {
77704
77866
  if (!this.appearance) {
77705
- const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
77867
+ const strokeColor = getPdfColorArray(this.color, [0, 0, 0]);
77706
77868
  const strokeAlpha = dict.get("CA");
77707
77869
  this._setDefaultAppearance({
77708
77870
  xref,
@@ -77735,7 +77897,7 @@ var SquigglyAnnotation = class extends MarkupAnnotation {
77735
77897
  const quadPoints = this.data.quadPoints = getQuadPoints(dict, null);
77736
77898
  if (quadPoints) {
77737
77899
  if (!this.appearance) {
77738
- const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
77900
+ const strokeColor = getPdfColorArray(this.color, [0, 0, 0]);
77739
77901
  const strokeAlpha = dict.get("CA");
77740
77902
  this._setDefaultAppearance({
77741
77903
  xref,
@@ -77775,7 +77937,7 @@ var StrikeOutAnnotation = class extends MarkupAnnotation {
77775
77937
  const quadPoints = this.data.quadPoints = getQuadPoints(dict, null);
77776
77938
  if (quadPoints) {
77777
77939
  if (!this.appearance) {
77778
- const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
77940
+ const strokeColor = getPdfColorArray(this.color, [0, 0, 0]);
77779
77941
  const strokeAlpha = dict.get("CA");
77780
77942
  this._setDefaultAppearance({
77781
77943
  xref,
@@ -77847,8 +78009,8 @@ var StampAnnotation = class extends MarkupAnnotation {
77847
78009
  image.set("Type", xobjectName);
77848
78010
  image.set("Subtype", imageName);
77849
78011
  image.set("BitsPerComponent", 8);
77850
- image.set("ColorSpace", Name.get("DeviceRGB"));
77851
- image.set("Filter", Name.get("DCTDecode"));
78012
+ image.setIfName("ColorSpace", "DeviceRGB");
78013
+ image.setIfName("Filter", "DCTDecode");
77852
78014
  image.set("BBox", [0, 0, width, height]);
77853
78015
  image.set("Width", width);
77854
78016
  image.set("Height", height);
@@ -77868,7 +78030,7 @@ var StampAnnotation = class extends MarkupAnnotation {
77868
78030
  smask.set("Type", xobjectName);
77869
78031
  smask.set("Subtype", imageName);
77870
78032
  smask.set("BitsPerComponent", 8);
77871
- smask.set("ColorSpace", Name.get("DeviceGray"));
78033
+ smask.setIfName("ColorSpace", "DeviceGray");
77872
78034
  smask.set("Width", width);
77873
78035
  smask.set("Height", height);
77874
78036
  smaskStream = new Stream(alphaBuffer, 0, 0, smask);
@@ -77882,29 +78044,23 @@ var StampAnnotation = class extends MarkupAnnotation {
77882
78044
  };
77883
78045
  }
77884
78046
  static createNewDict(annotation, xref, { apRef, ap }) {
77885
- const { oldAnnotation, rect, rotation, user } = annotation;
78047
+ const { date, oldAnnotation, rect, rotation, user } = annotation;
77886
78048
  const stamp = oldAnnotation || new Dict(xref);
77887
- stamp.set("Type", Name.get("Annot"));
77888
- stamp.set("Subtype", Name.get("Stamp"));
78049
+ stamp.setIfNotExists("Type", Name.get("Annot"));
78050
+ stamp.setIfNotExists("Subtype", Name.get("Stamp"));
77889
78051
  stamp.set(
77890
78052
  oldAnnotation ? "M" : "CreationDate",
77891
- `D:${getModificationDate()}`
78053
+ `D:${getModificationDate(date)}`
77892
78054
  );
77893
- stamp.set("Rect", rect);
77894
- stamp.set("F", 4);
77895
- stamp.set("Border", [0, 0, 0]);
77896
- stamp.set("Rotate", rotation);
77897
- if (user) {
77898
- stamp.set("T", stringToAsciiOrUTF16BE(user));
77899
- }
78055
+ stamp.setIfArray("Rect", rect);
78056
+ stamp.setIfNotExists("F", 4);
78057
+ stamp.setIfNotExists("Border", [0, 0, 0]);
78058
+ stamp.setIfNumber("Rotate", rotation);
78059
+ stamp.setIfDefined("T", stringToAsciiOrUTF16BE(user));
77900
78060
  if (apRef || ap) {
77901
78061
  const n = new Dict(xref);
77902
78062
  stamp.set("AP", n);
77903
- if (apRef) {
77904
- n.set("N", apRef);
77905
- } else {
77906
- n.set("N", ap);
77907
- }
78063
+ n.set("N", apRef || ap);
77908
78064
  }
77909
78065
  return stamp;
77910
78066
  }
@@ -77924,8 +78080,8 @@ var StampAnnotation = class extends MarkupAnnotation {
77924
78080
  const appearance = `q ${width} 0 0 ${height} 0 0 cm /Im0 Do Q`;
77925
78081
  const appearanceStreamDict = new Dict(xref);
77926
78082
  appearanceStreamDict.set("FormType", 1);
77927
- appearanceStreamDict.set("Subtype", Name.get("Form"));
77928
- appearanceStreamDict.set("Type", Name.get("XObject"));
78083
+ appearanceStreamDict.setIfName("Subtype", "Form");
78084
+ appearanceStreamDict.setIfName("Type", "XObject");
77929
78085
  appearanceStreamDict.set("BBox", [0, 0, width, height]);
77930
78086
  appearanceStreamDict.set("Resources", resources);
77931
78087
  if (rotation) {
@@ -77941,6 +78097,9 @@ _savedHasOwnCanvas = new WeakMap();
77941
78097
  _StampAnnotation_static = new WeakSet();
77942
78098
  createNewAppearanceStreamForDrawing_fn = async function(annotation, xref) {
77943
78099
  const { areContours, color, rect, lines, thickness } = annotation;
78100
+ if (!color) {
78101
+ return null;
78102
+ }
77944
78103
  const appearanceBuffer = [
77945
78104
  `${thickness} w 1 J 1 j`,
77946
78105
  `${getPdfColor(
@@ -77975,8 +78134,8 @@ createNewAppearanceStreamForDrawing_fn = async function(annotation, xref) {
77975
78134
  const appearance = appearanceBuffer.join("\n");
77976
78135
  const appearanceStreamDict = new Dict(xref);
77977
78136
  appearanceStreamDict.set("FormType", 1);
77978
- appearanceStreamDict.set("Subtype", Name.get("Form"));
77979
- appearanceStreamDict.set("Type", Name.get("XObject"));
78137
+ appearanceStreamDict.setIfName("Subtype", "Form");
78138
+ appearanceStreamDict.setIfName("Type", "XObject");
77980
78139
  appearanceStreamDict.set("BBox", rect);
77981
78140
  appearanceStreamDict.set("Length", appearance.length);
77982
78141
  const ap = new StringStream(appearance);
@@ -78849,19 +79008,26 @@ var SingleIntersector = class {
78849
79008
  __privateAdd(this, _minY, Infinity);
78850
79009
  __privateAdd(this, _maxX, -Infinity);
78851
79010
  __privateAdd(this, _maxY, -Infinity);
78852
- __privateAdd(this, _quadPoints);
79011
+ __privateAdd(this, _quadPoints, null);
78853
79012
  __privateAdd(this, _text, []);
78854
79013
  __privateAdd(this, _extraChars, []);
78855
79014
  __privateAdd(this, _lastIntersectingQuadIndex, -1);
78856
79015
  __privateAdd(this, _canTakeExtraChars, false);
78857
79016
  __privateSet(this, _annotation, annotation);
78858
- const quadPoints = __privateSet(this, _quadPoints, annotation.data.quadPoints);
79017
+ const quadPoints = annotation.data.quadPoints;
79018
+ if (!quadPoints) {
79019
+ [__privateWrapper(this, _minX)._, __privateWrapper(this, _minY)._, __privateWrapper(this, _maxX)._, __privateWrapper(this, _maxY)._] = annotation.data.rect;
79020
+ return;
79021
+ }
78859
79022
  for (let i = 0, ii = quadPoints.length; i < ii; i += 8) {
78860
79023
  __privateSet(this, _minX, Math.min(__privateGet(this, _minX), quadPoints[i]));
78861
79024
  __privateSet(this, _maxX, Math.max(__privateGet(this, _maxX), quadPoints[i + 2]));
78862
79025
  __privateSet(this, _minY, Math.min(__privateGet(this, _minY), quadPoints[i + 5]));
78863
79026
  __privateSet(this, _maxY, Math.max(__privateGet(this, _maxY), quadPoints[i + 1]));
78864
79027
  }
79028
+ if (quadPoints.length > 8) {
79029
+ __privateSet(this, _quadPoints, quadPoints);
79030
+ }
78865
79031
  }
78866
79032
  overlaps(other) {
78867
79033
  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));
@@ -78918,7 +79084,7 @@ intersects_fn = function(x, y) {
78918
79084
  return false;
78919
79085
  }
78920
79086
  const quadPoints = __privateGet(this, _quadPoints);
78921
- if (quadPoints.length === 8) {
79087
+ if (!quadPoints) {
78922
79088
  return true;
78923
79089
  }
78924
79090
  if (__privateGet(this, _lastIntersectingQuadIndex) >= 0) {
@@ -78941,7 +79107,7 @@ var Intersector = class {
78941
79107
  constructor(annotations) {
78942
79108
  __privateAdd(this, _intersectors, /* @__PURE__ */ new Map());
78943
79109
  for (const annotation of annotations) {
78944
- if (!annotation.data.quadPoints) {
79110
+ if (!annotation.data.quadPoints && !annotation.data.rect) {
78945
79111
  continue;
78946
79112
  }
78947
79113
  const intersector = new SingleIntersector(annotation);
@@ -81944,11 +82110,12 @@ var XRef = class {
81944
82110
  return this.topDict;
81945
82111
  }
81946
82112
  if (!trailerDicts.length) {
81947
- for (const [num, entry] of this.entries.entries()) {
81948
- if (!entry) {
82113
+ for (const num in this.entries) {
82114
+ if (!Object.hasOwn(this.entries, num)) {
81949
82115
  continue;
81950
82116
  }
81951
- const ref = Ref.get(num, entry.gen);
82117
+ const entry = this.entries[num];
82118
+ const ref = Ref.get(parseInt(num), entry.gen);
81952
82119
  let obj;
81953
82120
  try {
81954
82121
  obj = this.fetch(ref);
@@ -82166,6 +82333,10 @@ var XRef = class {
82166
82333
  );
82167
82334
  }
82168
82335
  nums[i] = num;
82336
+ const entry = this.getEntry(num);
82337
+ if (entry?.offset === tableOffset && entry.gen !== i) {
82338
+ entry.gen = i;
82339
+ }
82169
82340
  offsets[i] = offset;
82170
82341
  }
82171
82342
  const start = (stream.start || 0) + first;
@@ -82229,7 +82400,7 @@ _firstXRefStmPos = new WeakMap();
82229
82400
 
82230
82401
  // src/pdf.js/src/core/document.js
82231
82402
  var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
82232
- var _resourcesPromise, _Page_instances, createPartialEvaluator_fn, getInheritableProperty_fn, getBoundingBox_fn, onSubStreamError_fn, replaceIdByRef_fn, getMergedResources_fn;
82403
+ var _areAnnotationsCached, _resourcesPromise, _Page_instances, createPartialEvaluator_fn, getInheritableProperty_fn, getBoundingBox_fn, onSubStreamError_fn, replaceIdByRef_fn, getMergedResources_fn;
82233
82404
  var Page = class {
82234
82405
  constructor({
82235
82406
  pdfManager,
@@ -82248,6 +82419,7 @@ var Page = class {
82248
82419
  xfaFactory
82249
82420
  }) {
82250
82421
  __privateAdd(this, _Page_instances);
82422
+ __privateAdd(this, _areAnnotationsCached, false);
82251
82423
  __privateAdd(this, _resourcesPromise, null);
82252
82424
  this.pdfManager = pdfManager;
82253
82425
  this.pageIndex = pageIndex;
@@ -82699,6 +82871,8 @@ var Page = class {
82699
82871
  /* collectFields */
82700
82872
  false,
82701
82873
  orphanFields,
82874
+ /* collectByType */
82875
+ null,
82702
82876
  this.ref
82703
82877
  ).catch(function(reason) {
82704
82878
  warn(`_parsedAnnotations: "${reason}".`);
@@ -82730,6 +82904,7 @@ var Page = class {
82730
82904
  }
82731
82905
  return sortedAnnotations;
82732
82906
  });
82907
+ __privateSet(this, _areAnnotationsCached, true);
82733
82908
  return shadow(this, "_parsedAnnotations", promise);
82734
82909
  }
82735
82910
  get jsActions() {
@@ -82740,7 +82915,57 @@ var Page = class {
82740
82915
  );
82741
82916
  return shadow(this, "jsActions", actions);
82742
82917
  }
82918
+ async collectAnnotationsByType(handler, task, types2, promises, annotationGlobals) {
82919
+ const { pageIndex } = this;
82920
+ if (__privateGet(this, _areAnnotationsCached)) {
82921
+ const cachedAnnotations = await this._parsedAnnotations;
82922
+ for (const { data } of cachedAnnotations) {
82923
+ if (!types2 || types2.has(data.annotationType)) {
82924
+ data.pageIndex = pageIndex;
82925
+ promises.push(Promise.resolve(data));
82926
+ }
82927
+ }
82928
+ return;
82929
+ }
82930
+ const annots = await this.pdfManager.ensure(this, "annotations");
82931
+ for (const annotationRef of annots) {
82932
+ promises.push(
82933
+ AnnotationFactory.create(
82934
+ this.xref,
82935
+ annotationRef,
82936
+ annotationGlobals,
82937
+ this._localIdFactory,
82938
+ /* collectFields */
82939
+ false,
82940
+ /* orphanFields */
82941
+ null,
82942
+ /* collectByType */
82943
+ types2,
82944
+ this.ref
82945
+ ).then(async (annotation) => {
82946
+ if (!annotation) {
82947
+ return null;
82948
+ }
82949
+ annotation.data.pageIndex = pageIndex;
82950
+ if (annotation.hasTextContent && annotation.viewable) {
82951
+ const partialEvaluator = __privateMethod(this, _Page_instances, createPartialEvaluator_fn).call(this, handler);
82952
+ await annotation.extractTextContent(partialEvaluator, task, [
82953
+ -Infinity,
82954
+ -Infinity,
82955
+ Infinity,
82956
+ Infinity
82957
+ ]);
82958
+ }
82959
+ return annotation.data;
82960
+ }).catch(function(reason) {
82961
+ warn(`collectAnnotationsByType: "${reason}".`);
82962
+ return null;
82963
+ })
82964
+ );
82965
+ }
82966
+ }
82743
82967
  };
82968
+ _areAnnotationsCached = new WeakMap();
82744
82969
  _resourcesPromise = new WeakMap();
82745
82970
  _Page_instances = new WeakSet();
82746
82971
  createPartialEvaluator_fn = function(handler) {
@@ -82820,6 +83045,12 @@ replaceIdByRef_fn = async function(annotations, deletedAnnotations, existingAnno
82820
83045
  }
82821
83046
  continue;
82822
83047
  }
83048
+ if (annotation.popup?.deleted) {
83049
+ const popupRef = Ref.fromString(annotation.popupRef);
83050
+ if (popupRef) {
83051
+ deletedAnnotations.put(popupRef, popupRef);
83052
+ }
83053
+ }
82823
83054
  existingAnnotations?.put(ref);
82824
83055
  annotation.ref = ref;
82825
83056
  promises.push(
@@ -83787,6 +84018,8 @@ collectFieldObjects_fn = async function(name, parentRef, fieldRef, promises, ann
83787
84018
  /* collectFields */
83788
84019
  true,
83789
84020
  orphanFields,
84021
+ /* collectByType */
84022
+ null,
83790
84023
  /* pageRef */
83791
84024
  null
83792
84025
  ).then((annotation) => annotation?.getFieldObject()).catch(function(reason) {
@@ -84159,7 +84392,7 @@ function updateXFA({ xfaData, xfaDatasetsRef, changes, xref }) {
84159
84392
  }
84160
84393
  const xfaDataStream = new StringStream(xfaData);
84161
84394
  xfaDataStream.dict = new Dict(xref);
84162
- xfaDataStream.dict.set("Type", Name.get("EmbeddedFile"));
84395
+ xfaDataStream.dict.setIfName("Type", "EmbeddedFile");
84163
84396
  changes.put(xfaDatasetsRef, {
84164
84397
  data: xfaDataStream
84165
84398
  });
@@ -84254,7 +84487,7 @@ function getTrailerDict(xrefInfo, changes, useXrefStream) {
84254
84487
  if (useXrefStream) {
84255
84488
  changes.put(refForXrefTable, { data: "" });
84256
84489
  newXref.set("Size", refForXrefTable.num + 1);
84257
- newXref.set("Type", Name.get("XRef"));
84490
+ newXref.setIfName("Type", "XRef");
84258
84491
  } else {
84259
84492
  newXref.set("Size", refForXrefTable.num);
84260
84493
  }
@@ -84731,6 +84964,53 @@ var _WorkerMessageHandler = class _WorkerMessageHandler {
84731
84964
  handler.on("GetPageJSActions", function({ pageIndex }) {
84732
84965
  return pdfManager.getPage(pageIndex).then((page) => pdfManager.ensure(page, "jsActions"));
84733
84966
  });
84967
+ handler.on(
84968
+ "GetAnnotationsByType",
84969
+ async function({ types: types2, pageIndexesToSkip }) {
84970
+ const [numPages, annotationGlobals] = await Promise.all([
84971
+ pdfManager.ensureDoc("numPages"),
84972
+ pdfManager.ensureDoc("annotationGlobals")
84973
+ ]);
84974
+ if (!annotationGlobals) {
84975
+ return null;
84976
+ }
84977
+ const pagePromises = [];
84978
+ const annotationPromises = [];
84979
+ let task = null;
84980
+ try {
84981
+ for (let i = 0, ii = numPages; i < ii; i++) {
84982
+ if (pageIndexesToSkip?.has(i)) {
84983
+ continue;
84984
+ }
84985
+ if (!task) {
84986
+ task = new WorkerTask("GetAnnotationsByType");
84987
+ startWorkerTask(task);
84988
+ }
84989
+ pagePromises.push(
84990
+ pdfManager.getPage(i).then(async (page) => {
84991
+ if (!page) {
84992
+ return [];
84993
+ }
84994
+ return page.collectAnnotationsByType(
84995
+ handler,
84996
+ task,
84997
+ types2,
84998
+ annotationPromises,
84999
+ annotationGlobals
85000
+ ) || [];
85001
+ })
85002
+ );
85003
+ }
85004
+ await Promise.all(pagePromises);
85005
+ const annotations = await Promise.all(annotationPromises);
85006
+ return annotations.filter((a) => !!a);
85007
+ } finally {
85008
+ if (task) {
85009
+ finishWorkerTask(task);
85010
+ }
85011
+ }
85012
+ }
85013
+ );
84734
85014
  handler.on("GetOutline", function(data) {
84735
85015
  return pdfManager.ensureCatalog("documentOutline");
84736
85016
  });