@chialab/pdfjs-lib 1.0.0-alpha.29 → 1.0.0-alpha.30

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 (40) hide show
  1. package/dist/browser/{chunk-W35PJZ6L.js → chunk-R7G44NYV.js} +521 -3
  2. package/dist/browser/index.js +2329 -969
  3. package/dist/browser/openjpeg-Q27OVS4T.js +9 -0
  4. package/dist/browser/worker.js +594 -609
  5. package/dist/index.d.ts +1 -1
  6. package/dist/lib/TextLayer.d.ts +4 -0
  7. package/dist/node/{NodeUtils-ZPPZPJWD.js → NodeUtils-PVXQMWFJ.js} +2 -2
  8. package/dist/node/{chunk-GWGW2EKY.js → chunk-4Y7OZIIX.js} +520 -2
  9. package/dist/node/{chunk-D4U3W2CD.js → chunk-O74KGUUC.js} +451 -1
  10. package/dist/node/{chunk-FHASHZBJ.js → chunk-T2JWSGAF.js} +2 -2
  11. package/dist/node/index.js +1896 -972
  12. package/dist/node/openjpeg-QFJSFVSJ.js +9 -0
  13. package/dist/node/worker.js +595 -610
  14. package/dist/pdf.js/external/openjpeg/openjpeg.d.ts +1 -1
  15. package/dist/pdf.js/src/core/fonts.d.ts +7 -1
  16. package/dist/pdf.js/src/display/annotation_layer.d.ts +28 -6
  17. package/dist/pdf.js/src/display/annotation_storage.d.ts +2 -0
  18. package/dist/pdf.js/src/display/api.d.ts +13 -7
  19. package/dist/pdf.js/src/display/canvas.d.ts +1 -1
  20. package/dist/pdf.js/src/display/canvas_dependency_tracker.d.ts +36 -20
  21. package/dist/pdf.js/src/display/display_utils.d.ts +22 -0
  22. package/dist/pdf.js/src/display/editor/annotation_editor_layer.d.ts +4 -2
  23. package/dist/pdf.js/src/display/editor/comment.d.ts +20 -5
  24. package/dist/pdf.js/src/display/editor/drawers/freedraw.d.ts +1 -0
  25. package/dist/pdf.js/src/display/editor/drawers/highlight.d.ts +2 -1
  26. package/dist/pdf.js/src/display/editor/editor.d.ts +67 -15
  27. package/dist/pdf.js/src/display/editor/freetext.d.ts +1 -1
  28. package/dist/pdf.js/src/display/editor/highlight.d.ts +3 -1
  29. package/dist/pdf.js/src/display/editor/ink.d.ts +2 -1
  30. package/dist/pdf.js/src/display/editor/signature.d.ts +0 -5
  31. package/dist/pdf.js/src/display/editor/toolbar.d.ts +3 -1
  32. package/dist/pdf.js/src/display/editor/tools.d.ts +21 -3
  33. package/dist/pdf.js/src/display/font_loader.d.ts +27 -1
  34. package/dist/pdf.js/src/display/pattern_helper.d.ts +2 -2
  35. package/dist/pdf.js/src/pdf.d.ts +5 -1
  36. package/dist/pdf.js/src/shared/obj-bin-transform.d.ts +64 -0
  37. package/dist/pdf.js/web/comment_manager.d.ts +20 -0
  38. package/package.json +1 -1
  39. package/dist/browser/openjpeg-QLA762TL.js +0 -9
  40. package/dist/node/openjpeg-TRZ4ANDN.js +0 -9
@@ -1,12 +1,15 @@
1
1
  import {
2
2
  ColorConverters,
3
+ FontInfo,
3
4
  MessageHandler,
4
5
  MurmurHash3_64,
5
6
  convertBlackAndWhiteToRGBA,
6
7
  wrapReason
7
- } from "./chunk-GWGW2EKY.js";
8
+ } from "./chunk-4Y7OZIIX.js";
8
9
  import {
9
10
  BaseStandardFontDataFactory,
11
+ CSSConstants,
12
+ ColorScheme,
10
13
  DOMCMapReaderFactory,
11
14
  DOMCanvasFactory,
12
15
  DOMFilterFactory,
@@ -25,10 +28,14 @@ import {
25
28
  SVG_NS,
26
29
  StatTimer,
27
30
  SupportedImageMimeTypes,
31
+ XfaLayer,
32
+ XfaText,
33
+ applyOpacity,
28
34
  canvasToData,
29
35
  colorToRgb,
30
36
  deprecated,
31
37
  fetchData,
38
+ findContrastColor,
32
39
  getColorValues,
33
40
  getCurrentTransform,
34
41
  getCurrentTransformInverse,
@@ -42,11 +49,12 @@ import {
42
49
  makeSerializable,
43
50
  noContextMenu,
44
51
  parseRgbaColor,
52
+ renderRichText,
45
53
  rgbToHex,
46
54
  setLayerDimensions,
47
55
  stopEvent,
48
56
  toDataUrl
49
- } from "./chunk-D4U3W2CD.js";
57
+ } from "./chunk-O74KGUUC.js";
50
58
  import {
51
59
  AbortException,
52
60
  AnnotationBorderStyleType,
@@ -89,7 +97,7 @@ import {
89
97
  unreachable,
90
98
  updateUrlHash,
91
99
  warn
92
- } from "./chunk-FHASHZBJ.js";
100
+ } from "./chunk-T2JWSGAF.js";
93
101
  import {
94
102
  __commonJS,
95
103
  __privateAdd,
@@ -12368,7 +12376,7 @@ var require_opentype = __commonJS({
12368
12376
  });
12369
12377
 
12370
12378
  // src/pdf.js/src/display/editor/toolbar.js
12371
- var _toolbar, _colorPicker, _editor, _buttons, _altText, _comment, _signatureDescriptionButton, _l10nRemove, _EditorToolbar_static, pointerDown_fn, _EditorToolbar_instances, focusIn_fn, focusOut_fn, addListenersToElement_fn, divider_get;
12379
+ var _toolbar, _colorPicker, _editor, _buttons, _altText, _comment, _commentButtonDivider, _signatureDescriptionButton, _l10nRemove, _EditorToolbar_static, pointerDown_fn, _EditorToolbar_instances, focusIn_fn, focusOut_fn, addListenersToElement_fn, divider_get;
12372
12380
  var _EditorToolbar = class _EditorToolbar {
12373
12381
  constructor(editor) {
12374
12382
  __privateAdd(this, _EditorToolbar_instances);
@@ -12378,6 +12386,7 @@ var _EditorToolbar = class _EditorToolbar {
12378
12386
  __privateAdd(this, _buttons, null);
12379
12387
  __privateAdd(this, _altText, null);
12380
12388
  __privateAdd(this, _comment, null);
12389
+ __privateAdd(this, _commentButtonDivider, null);
12381
12390
  __privateAdd(this, _signatureDescriptionButton, null);
12382
12391
  __privateSet(this, _editor, editor);
12383
12392
  __privateGet(_EditorToolbar, _l10nRemove) || __privateSet(_EditorToolbar, _l10nRemove, Object.freeze({
@@ -12446,16 +12455,22 @@ var _EditorToolbar = class _EditorToolbar {
12446
12455
  __privateGet(this, _buttons).append(button, __privateGet(this, _EditorToolbar_instances, divider_get));
12447
12456
  __privateSet(this, _altText, altText);
12448
12457
  }
12449
- addComment(comment) {
12458
+ addComment(comment, beforeElement = null) {
12450
12459
  if (__privateGet(this, _comment)) {
12451
12460
  return;
12452
12461
  }
12453
- const button = comment.render();
12462
+ const button = comment.renderForToolbar();
12454
12463
  if (!button) {
12455
12464
  return;
12456
12465
  }
12457
12466
  __privateMethod(this, _EditorToolbar_instances, addListenersToElement_fn).call(this, button);
12458
- __privateGet(this, _buttons).append(button, __privateGet(this, _EditorToolbar_instances, divider_get));
12467
+ const divider = __privateSet(this, _commentButtonDivider, __privateGet(this, _EditorToolbar_instances, divider_get));
12468
+ if (!beforeElement) {
12469
+ __privateGet(this, _buttons).append(button, divider);
12470
+ } else {
12471
+ __privateGet(this, _buttons).insertBefore(button, beforeElement);
12472
+ __privateGet(this, _buttons).insertBefore(divider, beforeElement);
12473
+ }
12459
12474
  __privateSet(this, _comment, comment);
12460
12475
  comment.toolbar = this;
12461
12476
  }
@@ -12473,6 +12488,16 @@ var _EditorToolbar = class _EditorToolbar {
12473
12488
  __privateMethod(this, _EditorToolbar_instances, addListenersToElement_fn).call(this, button);
12474
12489
  __privateGet(this, _buttons).append(button, __privateGet(this, _EditorToolbar_instances, divider_get));
12475
12490
  }
12491
+ removeButton(name) {
12492
+ switch (name) {
12493
+ case "comment":
12494
+ __privateGet(this, _comment)?.removeToolbarCommentButton();
12495
+ __privateSet(this, _comment, null);
12496
+ __privateGet(this, _commentButtonDivider)?.remove();
12497
+ __privateSet(this, _commentButtonDivider, null);
12498
+ break;
12499
+ }
12500
+ }
12476
12501
  async addButton(name, tool) {
12477
12502
  switch (name) {
12478
12503
  case "colorPicker":
@@ -12492,6 +12517,15 @@ var _EditorToolbar = class _EditorToolbar {
12492
12517
  break;
12493
12518
  }
12494
12519
  }
12520
+ async addButtonBefore(name, tool, beforeSelector) {
12521
+ const beforeElement = __privateGet(this, _buttons).querySelector(beforeSelector);
12522
+ if (!beforeElement) {
12523
+ return;
12524
+ }
12525
+ if (name === "comment") {
12526
+ this.addComment(tool, beforeElement);
12527
+ }
12528
+ }
12495
12529
  updateEditSignatureButton(description) {
12496
12530
  if (__privateGet(this, _signatureDescriptionButton)) {
12497
12531
  __privateGet(this, _signatureDescriptionButton).title = description;
@@ -12509,6 +12543,7 @@ _editor = new WeakMap();
12509
12543
  _buttons = new WeakMap();
12510
12544
  _altText = new WeakMap();
12511
12545
  _comment = new WeakMap();
12546
+ _commentButtonDivider = new WeakMap();
12512
12547
  _signatureDescriptionButton = new WeakMap();
12513
12548
  _l10nRemove = new WeakMap();
12514
12549
  _EditorToolbar_static = new WeakSet();
@@ -13204,6 +13239,7 @@ var _AnnotationEditorUIManager = class _AnnotationEditorUIManager {
13204
13239
  this.isShiftKeyDown = false;
13205
13240
  this._editorUndoBar = editorUndoBar || null;
13206
13241
  this._supportsPinchToZoom = supportsPinchToZoom !== false;
13242
+ commentManager?.setSidebarUiManager(this);
13207
13243
  if (false) {
13208
13244
  Object.defineProperty(this, "reset", {
13209
13245
  value: () => {
@@ -13466,8 +13502,50 @@ var _AnnotationEditorUIManager = class _AnnotationEditorUIManager {
13466
13502
  hasCommentManager() {
13467
13503
  return !!__privateGet(this, _commentManager);
13468
13504
  }
13469
- editComment(editor, position) {
13470
- __privateGet(this, _commentManager)?.open(this, editor, position);
13505
+ editComment(editor, posX, posY, options) {
13506
+ __privateGet(this, _commentManager)?.showDialog(this, editor, posX, posY, options);
13507
+ }
13508
+ selectComment(pageIndex, uid) {
13509
+ const layer = __privateGet(this, _allLayers).get(pageIndex);
13510
+ const editor = layer?.getEditorByUID(uid);
13511
+ editor?.toggleComment(
13512
+ /* isSelected */
13513
+ true,
13514
+ /* visibility */
13515
+ true
13516
+ );
13517
+ }
13518
+ updateComment(editor) {
13519
+ __privateGet(this, _commentManager)?.updateComment(editor.getData());
13520
+ }
13521
+ updatePopupColor(editor) {
13522
+ __privateGet(this, _commentManager)?.updatePopupColor(editor);
13523
+ }
13524
+ removeComment(editor) {
13525
+ __privateGet(this, _commentManager)?.removeComments([editor.uid]);
13526
+ }
13527
+ toggleComment(editor, isSelected, visibility = void 0) {
13528
+ __privateGet(this, _commentManager)?.toggleCommentPopup(editor, isSelected, visibility);
13529
+ }
13530
+ makeCommentColor(color, opacity) {
13531
+ return color && __privateGet(this, _commentManager)?.makeCommentColor(color, opacity) || null;
13532
+ }
13533
+ getCommentDialogElement() {
13534
+ return __privateGet(this, _commentManager)?.dialogElement || null;
13535
+ }
13536
+ async waitForEditorsRendered(pageNumber) {
13537
+ if (__privateGet(this, _allLayers).has(pageNumber - 1)) {
13538
+ return;
13539
+ }
13540
+ const { resolve, promise } = Promise.withResolvers();
13541
+ const onEditorsRendered = (evt) => {
13542
+ if (evt.pageNumber === pageNumber) {
13543
+ this._eventBus._off("editorsrendered", onEditorsRendered);
13544
+ resolve();
13545
+ }
13546
+ };
13547
+ this._eventBus.on("editorsrendered", onEditorsRendered);
13548
+ await promise;
13471
13549
  }
13472
13550
  getSignature(editor) {
13473
13551
  __privateGet(this, _signatureManager)?.getSignature({ uiManager: this, editor });
@@ -13591,6 +13669,25 @@ var _AnnotationEditorUIManager = class _AnnotationEditorUIManager {
13591
13669
  true
13592
13670
  );
13593
13671
  }
13672
+ /**
13673
+ * Some annotations may have been modified in the annotation layer
13674
+ * (e.g. comments added or modified).
13675
+ * So this function retrieves the data from the storage and removes
13676
+ * them from the storage in order to be able to save them later.
13677
+ * @param {string} annotationId
13678
+ * @returns {Object|null} The data associated to the annotation or null.
13679
+ */
13680
+ getAndRemoveDataFromAnnotationStorage(annotationId) {
13681
+ if (!__privateGet(this, _annotationStorage)) {
13682
+ return null;
13683
+ }
13684
+ const key = `${AnnotationEditorPrefix}${annotationId}`;
13685
+ const storedValue = __privateGet(this, _annotationStorage).getRawValue(key);
13686
+ if (storedValue) {
13687
+ __privateGet(this, _annotationStorage).remove(key);
13688
+ }
13689
+ return storedValue;
13690
+ }
13594
13691
  /**
13595
13692
  * Add an editor in the annotation storage.
13596
13693
  * @param {AnnotationEditor} editor
@@ -13909,29 +14006,57 @@ var _AnnotationEditorUIManager = class _AnnotationEditorUIManager {
13909
14006
  if (__privateGet(this, _mode) === AnnotationEditorType.POPUP) {
13910
14007
  __privateGet(this, _commentManager)?.hideSidebar();
13911
14008
  }
14009
+ __privateGet(this, _commentManager)?.destroyPopup();
13912
14010
  __privateSet(this, _mode, mode);
13913
14011
  if (mode === AnnotationEditorType.NONE) {
13914
14012
  this.setEditingState(false);
13915
14013
  __privateMethod(this, _AnnotationEditorUIManager_instances, disableAll_fn).call(this);
14014
+ for (const editor of __privateGet(this, _allEditors).values()) {
14015
+ editor.hideStandaloneCommentButton();
14016
+ }
13916
14017
  this._editorUndoBar?.hide();
14018
+ this.toggleComment(
14019
+ /* editor = */
14020
+ null
14021
+ );
13917
14022
  __privateGet(this, _updateModeCapability).resolve();
13918
14023
  return;
13919
14024
  }
14025
+ for (const editor of __privateGet(this, _allEditors).values()) {
14026
+ editor.addStandaloneCommentButton();
14027
+ }
13920
14028
  if (mode === AnnotationEditorType.SIGNATURE) {
13921
14029
  await __privateGet(this, _signatureManager)?.loadSignatures();
13922
14030
  }
13923
- if (mode === AnnotationEditorType.POPUP) {
13924
- __privateGet(this, _allEditableAnnotations) || __privateSet(this, _allEditableAnnotations, await __privateGet(this, _pdfDocument).getAnnotationsByType(
13925
- new Set(__privateGet(this, _editorTypes).map((editorClass) => editorClass._editorType))
13926
- ));
13927
- __privateGet(this, _commentManager)?.showSidebar(__privateGet(this, _allEditableAnnotations));
13928
- }
13929
14031
  this.setEditingState(true);
13930
14032
  await __privateMethod(this, _AnnotationEditorUIManager_instances, enableAll_fn).call(this);
13931
14033
  this.unselectAll();
13932
14034
  for (const layer of __privateGet(this, _allLayers).values()) {
13933
14035
  layer.updateMode(mode);
13934
14036
  }
14037
+ if (mode === AnnotationEditorType.POPUP) {
14038
+ __privateGet(this, _allEditableAnnotations) || __privateSet(this, _allEditableAnnotations, await __privateGet(this, _pdfDocument).getAnnotationsByType(
14039
+ new Set(__privateGet(this, _editorTypes).map((editorClass) => editorClass._editorType))
14040
+ ));
14041
+ const elementIds = /* @__PURE__ */ new Set();
14042
+ const allComments = [];
14043
+ for (const editor of __privateGet(this, _allEditors).values()) {
14044
+ const { annotationElementId, hasComment, deleted } = editor;
14045
+ if (annotationElementId) {
14046
+ elementIds.add(annotationElementId);
14047
+ }
14048
+ if (hasComment && !deleted) {
14049
+ allComments.push(editor.getData());
14050
+ }
14051
+ }
14052
+ for (const annotation of __privateGet(this, _allEditableAnnotations)) {
14053
+ const { id: id2, popupRef, contentsObj } = annotation;
14054
+ if (popupRef && contentsObj?.str && !elementIds.has(id2) && !__privateGet(this, _deletedAnnotationsElementIds).has(id2)) {
14055
+ allComments.push(annotation);
14056
+ }
14057
+ }
14058
+ __privateGet(this, _commentManager)?.showSidebar(allComments);
14059
+ }
13935
14060
  if (!editId) {
13936
14061
  if (isFromKeyboard) {
13937
14062
  this.addNewEditorFromKeyboard();
@@ -13940,12 +14065,14 @@ var _AnnotationEditorUIManager = class _AnnotationEditorUIManager {
13940
14065
  return;
13941
14066
  }
13942
14067
  for (const editor of __privateGet(this, _allEditors).values()) {
13943
- if (editor.annotationElementId === editId || editor.id === editId) {
14068
+ if (editor.uid === editId) {
13944
14069
  this.setSelected(editor);
13945
14070
  if (editComment) {
13946
14071
  editor.editComment();
13947
14072
  } else if (mustEnterInEditMode) {
13948
14073
  editor.enterInEditMode();
14074
+ } else {
14075
+ editor.focus();
13949
14076
  }
13950
14077
  } else {
13951
14078
  editor.unselect();
@@ -14041,16 +14168,14 @@ var _AnnotationEditorUIManager = class _AnnotationEditorUIManager {
14041
14168
  /**
14042
14169
  * Get all the editors belonging to a given page.
14043
14170
  * @param {number} pageIndex
14044
- * @returns {Array<AnnotationEditor>}
14171
+ * @yields {AnnotationEditor}
14045
14172
  */
14046
- getEditors(pageIndex) {
14047
- const editors = [];
14173
+ *getEditors(pageIndex) {
14048
14174
  for (const editor of __privateGet(this, _allEditors).values()) {
14049
14175
  if (editor.pageIndex === pageIndex) {
14050
- editors.push(editor);
14176
+ yield editor;
14051
14177
  }
14052
14178
  }
14053
- return editors;
14054
14179
  }
14055
14180
  /**
14056
14181
  * Get an editor with the given id.
@@ -14486,6 +14611,9 @@ var _AnnotationEditorUIManager = class _AnnotationEditorUIManager {
14486
14611
  getMode() {
14487
14612
  return __privateGet(this, _mode);
14488
14613
  }
14614
+ isEditingMode() {
14615
+ return __privateGet(this, _mode) !== AnnotationEditorType.NONE;
14616
+ }
14489
14617
  get imageManager() {
14490
14618
  return shadow(this, "imageManager", new ImageManager());
14491
14619
  }
@@ -15197,72 +15325,137 @@ __publicField(_AltText, "_l10n", null);
15197
15325
  var AltText = _AltText;
15198
15326
 
15199
15327
  // src/pdf.js/src/display/editor/comment.js
15200
- var _commentButton, _commentWasFromKeyBoard, _editor3, _initialText, _text, _date, _deleted;
15328
+ var _commentStandaloneButton, _commentToolbarButton, _commentWasFromKeyBoard, _editor3, _initialText, _richText, _text, _date, _deleted, _popupPosition, _Comment_instances, render_fn2;
15201
15329
  var Comment = class {
15202
15330
  constructor(editor) {
15203
- __privateAdd(this, _commentButton, null);
15331
+ __privateAdd(this, _Comment_instances);
15332
+ __privateAdd(this, _commentStandaloneButton, null);
15333
+ __privateAdd(this, _commentToolbarButton, null);
15204
15334
  __privateAdd(this, _commentWasFromKeyBoard, false);
15205
15335
  __privateAdd(this, _editor3, null);
15206
15336
  __privateAdd(this, _initialText, null);
15337
+ __privateAdd(this, _richText, null);
15207
15338
  __privateAdd(this, _text, null);
15208
15339
  __privateAdd(this, _date, null);
15209
15340
  __privateAdd(this, _deleted, false);
15341
+ __privateAdd(this, _popupPosition, null);
15210
15342
  __privateSet(this, _editor3, editor);
15211
- this.toolbar = null;
15212
15343
  }
15213
- render() {
15214
- if (!__privateGet(this, _editor3)._uiManager.hasCommentManager()) {
15344
+ renderForToolbar() {
15345
+ const button = __privateSet(this, _commentToolbarButton, document.createElement("button"));
15346
+ button.className = "comment";
15347
+ return __privateMethod(this, _Comment_instances, render_fn2).call(this, button, false);
15348
+ }
15349
+ renderForStandalone() {
15350
+ const button = __privateSet(this, _commentStandaloneButton, document.createElement("button"));
15351
+ button.className = "annotationCommentButton";
15352
+ const position = __privateGet(this, _editor3).commentButtonPosition;
15353
+ if (position) {
15354
+ const { style } = button;
15355
+ style.insetInlineEnd = `calc(${100 * (__privateGet(this, _editor3)._uiManager.direction === "ltr" ? 1 - position[0] : position[0])}% - var(--comment-button-dim))`;
15356
+ style.top = `calc(${100 * position[1]}% - var(--comment-button-dim))`;
15357
+ const color = __privateGet(this, _editor3).commentButtonColor;
15358
+ if (color) {
15359
+ style.backgroundColor = color;
15360
+ }
15361
+ }
15362
+ return __privateMethod(this, _Comment_instances, render_fn2).call(this, button, true);
15363
+ }
15364
+ focusButton() {
15365
+ setTimeout(() => {
15366
+ (__privateGet(this, _commentStandaloneButton) ?? __privateGet(this, _commentToolbarButton))?.focus();
15367
+ }, 0);
15368
+ }
15369
+ onUpdatedColor() {
15370
+ if (!__privateGet(this, _commentStandaloneButton)) {
15371
+ return;
15372
+ }
15373
+ const color = __privateGet(this, _editor3).commentButtonColor;
15374
+ if (color) {
15375
+ __privateGet(this, _commentStandaloneButton).style.backgroundColor = color;
15376
+ }
15377
+ __privateGet(this, _editor3)._uiManager.updatePopupColor(__privateGet(this, _editor3));
15378
+ }
15379
+ get commentButtonWidth() {
15380
+ return (__privateGet(this, _commentStandaloneButton)?.getBoundingClientRect().width ?? 0) / __privateGet(this, _editor3).parent.boundingClientRect.width;
15381
+ }
15382
+ get commentPopupPositionInLayer() {
15383
+ if (__privateGet(this, _popupPosition)) {
15384
+ return __privateGet(this, _popupPosition);
15385
+ }
15386
+ if (!__privateGet(this, _commentStandaloneButton)) {
15215
15387
  return null;
15216
15388
  }
15217
- const comment = __privateSet(this, _commentButton, document.createElement("button"));
15218
- comment.className = "comment";
15219
- comment.tabIndex = "0";
15220
- comment.setAttribute("data-l10n-id", "pdfjs-editor-edit-comment-button");
15221
- const signal = __privateGet(this, _editor3)._uiManager._signal;
15222
- if (!(signal instanceof AbortSignal) || signal.aborted) {
15223
- return comment;
15389
+ const { x, y, height } = __privateGet(this, _commentStandaloneButton).getBoundingClientRect();
15390
+ const {
15391
+ x: parentX,
15392
+ y: parentY,
15393
+ width: parentWidth,
15394
+ height: parentHeight
15395
+ } = __privateGet(this, _editor3).parent.boundingClientRect;
15396
+ return [(x - parentX) / parentWidth, (y + height - parentY) / parentHeight];
15397
+ }
15398
+ set commentPopupPositionInLayer(pos) {
15399
+ __privateSet(this, _popupPosition, pos);
15400
+ }
15401
+ hasDefaultPopupPosition() {
15402
+ return __privateGet(this, _popupPosition) === null;
15403
+ }
15404
+ removeStandaloneCommentButton() {
15405
+ __privateGet(this, _commentStandaloneButton)?.remove();
15406
+ __privateSet(this, _commentStandaloneButton, null);
15407
+ }
15408
+ removeToolbarCommentButton() {
15409
+ __privateGet(this, _commentToolbarButton)?.remove();
15410
+ __privateSet(this, _commentToolbarButton, null);
15411
+ }
15412
+ setCommentButtonStates({ selected, hasPopup }) {
15413
+ if (!__privateGet(this, _commentStandaloneButton)) {
15414
+ return;
15224
15415
  }
15225
- comment.addEventListener("contextmenu", noContextMenu, { signal });
15226
- comment.addEventListener("pointerdown", (event) => event.stopPropagation(), {
15227
- signal
15228
- });
15229
- const onClick = (event) => {
15230
- event.preventDefault();
15231
- this.edit();
15232
- };
15233
- comment.addEventListener("click", onClick, { capture: true, signal });
15234
- comment.addEventListener(
15235
- "keydown",
15236
- (event) => {
15237
- if (event.target === comment && event.key === "Enter") {
15238
- __privateSet(this, _commentWasFromKeyBoard, true);
15239
- onClick(event);
15240
- }
15241
- },
15242
- { signal }
15243
- );
15244
- return comment;
15416
+ __privateGet(this, _commentStandaloneButton).classList.toggle("selected", selected);
15417
+ __privateGet(this, _commentStandaloneButton).ariaExpanded = hasPopup;
15245
15418
  }
15246
- edit() {
15247
- const { bottom, left, right } = __privateGet(this, _editor3).getClientDimensions();
15248
- const position = { top: bottom };
15249
- if (__privateGet(this, _editor3)._uiManager.direction === "ltr") {
15250
- position.right = right;
15419
+ edit(options) {
15420
+ const position = this.commentPopupPositionInLayer;
15421
+ let posX, posY;
15422
+ if (position) {
15423
+ [posX, posY] = position;
15251
15424
  } else {
15252
- position.left = left;
15425
+ [posX, posY] = __privateGet(this, _editor3).commentButtonPosition;
15426
+ const { width, height, x, y } = __privateGet(this, _editor3);
15427
+ posX = x + posX * width;
15428
+ posY = y + posY * height;
15253
15429
  }
15254
- __privateGet(this, _editor3)._uiManager.editComment(__privateGet(this, _editor3), position);
15430
+ const parentDimensions = __privateGet(this, _editor3).parent.boundingClientRect;
15431
+ const {
15432
+ x: parentX,
15433
+ y: parentY,
15434
+ width: parentWidth,
15435
+ height: parentHeight
15436
+ } = parentDimensions;
15437
+ __privateGet(this, _editor3)._uiManager.editComment(
15438
+ __privateGet(this, _editor3),
15439
+ parentX + posX * parentWidth,
15440
+ parentY + posY * parentHeight,
15441
+ { ...options, parentDimensions }
15442
+ );
15255
15443
  }
15256
15444
  finish() {
15257
- if (!__privateGet(this, _commentButton)) {
15445
+ if (!__privateGet(this, _commentToolbarButton)) {
15258
15446
  return;
15259
15447
  }
15260
- __privateGet(this, _commentButton).focus({ focusVisible: __privateGet(this, _commentWasFromKeyBoard) });
15448
+ __privateGet(this, _commentToolbarButton).focus({
15449
+ focusVisible: __privateGet(this, _commentWasFromKeyBoard)
15450
+ });
15261
15451
  __privateSet(this, _commentWasFromKeyBoard, false);
15262
15452
  }
15263
15453
  isDeleted() {
15264
15454
  return __privateGet(this, _deleted) || __privateGet(this, _text) === "";
15265
15455
  }
15456
+ isEmpty() {
15457
+ return __privateGet(this, _text) === null;
15458
+ }
15266
15459
  hasBeenEdited() {
15267
15460
  return this.isDeleted() || __privateGet(this, _text) !== __privateGet(this, _initialText);
15268
15461
  }
@@ -15272,14 +15465,18 @@ var Comment = class {
15272
15465
  get data() {
15273
15466
  return {
15274
15467
  text: __privateGet(this, _text),
15468
+ richText: __privateGet(this, _richText),
15275
15469
  date: __privateGet(this, _date),
15276
- deleted: __privateGet(this, _deleted)
15470
+ deleted: this.isDeleted()
15277
15471
  };
15278
15472
  }
15279
15473
  /**
15280
15474
  * Set the comment data.
15281
15475
  */
15282
15476
  set data(text) {
15477
+ if (text !== __privateGet(this, _text)) {
15478
+ __privateSet(this, _richText, null);
15479
+ }
15283
15480
  if (text === null) {
15284
15481
  __privateSet(this, _text, "");
15285
15482
  __privateSet(this, _deleted, true);
@@ -15289,35 +15486,133 @@ var Comment = class {
15289
15486
  __privateSet(this, _date, /* @__PURE__ */ new Date());
15290
15487
  __privateSet(this, _deleted, false);
15291
15488
  }
15292
- setInitialText(text) {
15489
+ setInitialText(text, richText = null) {
15293
15490
  __privateSet(this, _initialText, text);
15294
15491
  this.data = text;
15295
- }
15296
- toggle(enabled = false) {
15297
- if (!__privateGet(this, _commentButton)) {
15298
- return;
15299
- }
15300
- __privateGet(this, _commentButton).disabled = !enabled;
15492
+ __privateSet(this, _date, null);
15493
+ __privateSet(this, _richText, richText);
15301
15494
  }
15302
15495
  shown() {
15303
15496
  }
15304
15497
  destroy() {
15305
- __privateGet(this, _commentButton)?.remove();
15306
- __privateSet(this, _commentButton, null);
15498
+ __privateGet(this, _commentToolbarButton)?.remove();
15499
+ __privateSet(this, _commentToolbarButton, null);
15500
+ __privateGet(this, _commentStandaloneButton)?.remove();
15501
+ __privateSet(this, _commentStandaloneButton, null);
15307
15502
  __privateSet(this, _text, "");
15503
+ __privateSet(this, _richText, null);
15308
15504
  __privateSet(this, _date, null);
15309
15505
  __privateSet(this, _editor3, null);
15310
15506
  __privateSet(this, _commentWasFromKeyBoard, false);
15311
15507
  __privateSet(this, _deleted, false);
15312
15508
  }
15313
15509
  };
15314
- _commentButton = new WeakMap();
15510
+ _commentStandaloneButton = new WeakMap();
15511
+ _commentToolbarButton = new WeakMap();
15315
15512
  _commentWasFromKeyBoard = new WeakMap();
15316
15513
  _editor3 = new WeakMap();
15317
15514
  _initialText = new WeakMap();
15515
+ _richText = new WeakMap();
15318
15516
  _text = new WeakMap();
15319
15517
  _date = new WeakMap();
15320
15518
  _deleted = new WeakMap();
15519
+ _popupPosition = new WeakMap();
15520
+ _Comment_instances = new WeakSet();
15521
+ render_fn2 = function(comment, isStandalone) {
15522
+ if (!__privateGet(this, _editor3)._uiManager.hasCommentManager()) {
15523
+ return null;
15524
+ }
15525
+ comment.tabIndex = "0";
15526
+ comment.ariaHasPopup = "dialog";
15527
+ if (isStandalone) {
15528
+ comment.ariaControls = "commentPopup";
15529
+ comment.setAttribute("data-l10n-id", "pdfjs-show-comment-button");
15530
+ } else {
15531
+ comment.ariaControlsElements = [
15532
+ __privateGet(this, _editor3)._uiManager.getCommentDialogElement()
15533
+ ];
15534
+ comment.setAttribute("data-l10n-id", "pdfjs-editor-edit-comment-button");
15535
+ }
15536
+ const signal = __privateGet(this, _editor3)._uiManager._signal;
15537
+ if (!(signal instanceof AbortSignal) || signal.aborted) {
15538
+ return comment;
15539
+ }
15540
+ comment.addEventListener("contextmenu", noContextMenu, { signal });
15541
+ if (isStandalone) {
15542
+ comment.addEventListener(
15543
+ "focusin",
15544
+ (e) => {
15545
+ __privateGet(this, _editor3)._focusEventsAllowed = false;
15546
+ stopEvent(e);
15547
+ },
15548
+ {
15549
+ capture: true,
15550
+ signal
15551
+ }
15552
+ );
15553
+ comment.addEventListener(
15554
+ "focusout",
15555
+ (e) => {
15556
+ __privateGet(this, _editor3)._focusEventsAllowed = true;
15557
+ stopEvent(e);
15558
+ },
15559
+ {
15560
+ capture: true,
15561
+ signal
15562
+ }
15563
+ );
15564
+ }
15565
+ comment.addEventListener("pointerdown", (event) => event.stopPropagation(), {
15566
+ signal
15567
+ });
15568
+ const onClick = (event) => {
15569
+ event.preventDefault();
15570
+ if (comment === __privateGet(this, _commentToolbarButton)) {
15571
+ this.edit();
15572
+ } else {
15573
+ __privateGet(this, _editor3).toggleComment(
15574
+ /* isSelected = */
15575
+ true
15576
+ );
15577
+ }
15578
+ };
15579
+ comment.addEventListener("click", onClick, { capture: true, signal });
15580
+ comment.addEventListener(
15581
+ "keydown",
15582
+ (event) => {
15583
+ if (event.target === comment && event.key === "Enter") {
15584
+ __privateSet(this, _commentWasFromKeyBoard, true);
15585
+ onClick(event);
15586
+ }
15587
+ },
15588
+ { signal }
15589
+ );
15590
+ comment.addEventListener(
15591
+ "pointerenter",
15592
+ () => {
15593
+ __privateGet(this, _editor3).toggleComment(
15594
+ /* isSelected = */
15595
+ false,
15596
+ /* visibility = */
15597
+ true
15598
+ );
15599
+ },
15600
+ { signal }
15601
+ );
15602
+ comment.addEventListener(
15603
+ "pointerleave",
15604
+ () => {
15605
+ __privateGet(this, _editor3).toggleComment(
15606
+ /* isSelected = */
15607
+ false,
15608
+ /* visibility = */
15609
+ false
15610
+ );
15611
+ },
15612
+ { signal }
15613
+ );
15614
+ return comment;
15615
+ };
15321
15616
 
15322
15617
  // src/pdf.js/src/display/touch_manager.js
15323
15618
  var _container2, _isPinching, _isPinchingStopped, _isPinchingDisabled, _onPinchStart, _onPinching, _onPinchEnd, _pointerDownAC, _signal, _touchInfo, _touchManagerAC, _touchMoveAC, _TouchManager_instances, onTouchStart_fn, onTouchMove_fn, onTouchEnd_fn;
@@ -15512,7 +15807,7 @@ onTouchEnd_fn = function(evt) {
15512
15807
  var TouchManager = _TouchManager;
15513
15808
 
15514
15809
  // src/pdf.js/src/display/editor/editor.js
15515
- var _accessibilityData, _allResizerDivs, _altText3, _comment2, _disabled, _dragPointerId, _dragPointerType, _keepAspectRatio, _resizersDiv, _lastPointerCoords, _savedDimensions, _focusAC, _focusedResizerName, _hasBeenClicked, _initialRect, _isEditing, _isInEditMode, _isResizerEnabledForKeyboard, _moveInDOMTimeout, _prevDragX, _prevDragY, _telemetryTimeouts, _touchManager, _isDraggable, _zIndex, _AnnotationEditor_instances, translate_fn, _AnnotationEditor_static, rotatePoint_fn, getRotationMatrix_fn, createResizers_fn, resizerPointerdown_fn, resize_fn, addResizeToUndoStack_fn, resizerPointermove_fn, touchPinchStartCallback_fn, touchPinchCallback_fn, touchPinchEndCallback_fn, selectOnPointerEvent_fn, setUpDragSession_fn, addFocusListeners_fn, resizerKeydown_fn, resizerBlur_fn, resizerFocus_fn, setResizerTabIndex_fn, stopResizing_fn;
15810
+ var _accessibilityData, _allResizerDivs, _altText3, _comment2, _commentStandaloneButton2, _disabled, _dragPointerId, _dragPointerType, _resizersDiv, _lastPointerCoords, _savedDimensions, _fakeAnnotation, _focusAC, _focusedResizerName, _hasBeenClicked, _initialRect, _isEditing, _isInEditMode, _isResizerEnabledForKeyboard, _moveInDOMTimeout, _prevDragX, _prevDragY, _telemetryTimeouts, _touchManager, _isDraggable, _zIndex, _AnnotationEditor_instances, translate_fn, _AnnotationEditor_static, rotatePoint_fn, getRotationMatrix_fn, createResizers_fn, resizerPointerdown_fn, resize_fn, addResizeToUndoStack_fn, resizerPointermove_fn, touchPinchStartCallback_fn, touchPinchCallback_fn, touchPinchEndCallback_fn, selectOnPointerEvent_fn, setUpDragSession_fn, addFocusListeners_fn, resizerKeydown_fn, resizerBlur_fn, resizerFocus_fn, setResizerTabIndex_fn, stopResizing_fn;
15516
15811
  var _AnnotationEditor = class _AnnotationEditor {
15517
15812
  /**
15518
15813
  * @param {AnnotationEditorParameters} parameters
@@ -15523,13 +15818,14 @@ var _AnnotationEditor = class _AnnotationEditor {
15523
15818
  __privateAdd(this, _allResizerDivs, null);
15524
15819
  __privateAdd(this, _altText3, null);
15525
15820
  __privateAdd(this, _comment2, null);
15821
+ __privateAdd(this, _commentStandaloneButton2, null);
15526
15822
  __privateAdd(this, _disabled, false);
15527
15823
  __privateAdd(this, _dragPointerId, null);
15528
15824
  __privateAdd(this, _dragPointerType, "");
15529
- __privateAdd(this, _keepAspectRatio, false);
15530
15825
  __privateAdd(this, _resizersDiv, null);
15531
15826
  __privateAdd(this, _lastPointerCoords, null);
15532
15827
  __privateAdd(this, _savedDimensions, null);
15828
+ __privateAdd(this, _fakeAnnotation, null);
15533
15829
  __privateAdd(this, _focusAC, null);
15534
15830
  __privateAdd(this, _focusedResizerName, "");
15535
15831
  __privateAdd(this, _hasBeenClicked, false);
@@ -15567,6 +15863,8 @@ var _AnnotationEditor = class _AnnotationEditor {
15567
15863
  this._initialOptions.isCentered = parameters.isCentered;
15568
15864
  this._structTreeParentId = null;
15569
15865
  this.annotationElementId = parameters.annotationElementId || null;
15866
+ this.creationDate = parameters.creationDate || /* @__PURE__ */ new Date();
15867
+ this.modificationDate = parameters.modificationDate || null;
15570
15868
  const {
15571
15869
  rotation,
15572
15870
  rawDims: { pageWidth, pageHeight, pageX, pageY }
@@ -15706,6 +16004,9 @@ var _AnnotationEditor = class _AnnotationEditor {
15706
16004
  __privateSet(this, _isDraggable, value);
15707
16005
  this.div?.classList.toggle("draggable", value);
15708
16006
  }
16007
+ get uid() {
16008
+ return this.annotationElementId || this.id;
16009
+ }
15709
16010
  /**
15710
16011
  * @returns {boolean} true if the editor handles the Enter key itself.
15711
16012
  */
@@ -15762,6 +16063,8 @@ var _AnnotationEditor = class _AnnotationEditor {
15762
16063
  this.pageDimensions = parent.pageDimensions;
15763
16064
  } else {
15764
16065
  __privateMethod(this, _AnnotationEditor_instances, stopResizing_fn).call(this);
16066
+ __privateGet(this, _fakeAnnotation)?.remove();
16067
+ __privateSet(this, _fakeAnnotation, null);
15765
16068
  }
15766
16069
  this.parent = parent;
15767
16070
  }
@@ -16014,32 +16317,15 @@ var _AnnotationEditor = class _AnnotationEditor {
16014
16317
  }
16015
16318
  /**
16016
16319
  * Set the dimensions of this editor.
16017
- * @param {number} width
16018
- * @param {number} height
16019
16320
  */
16020
- setDims(width, height) {
16021
- const [parentWidth, parentHeight] = this.parentDimensions;
16022
- const { style } = this.div;
16023
- style.width = `${(100 * width / parentWidth).toFixed(2)}%`;
16024
- if (!__privateGet(this, _keepAspectRatio)) {
16025
- style.height = `${(100 * height / parentHeight).toFixed(2)}%`;
16026
- }
16027
- }
16028
- fixDims() {
16029
- const { style } = this.div;
16030
- const { height, width } = style;
16031
- const widthPercent = width.endsWith("%");
16032
- const heightPercent = !__privateGet(this, _keepAspectRatio) && height.endsWith("%");
16033
- if (widthPercent && heightPercent) {
16034
- return;
16035
- }
16036
- const [parentWidth, parentHeight] = this.parentDimensions;
16037
- if (!widthPercent) {
16038
- style.width = `${(100 * parseFloat(width) / parentWidth).toFixed(2)}%`;
16039
- }
16040
- if (!__privateGet(this, _keepAspectRatio) && !heightPercent) {
16041
- style.height = `${(100 * parseFloat(height) / parentHeight).toFixed(2)}%`;
16042
- }
16321
+ setDims() {
16322
+ const {
16323
+ div: { style },
16324
+ width,
16325
+ height
16326
+ } = this;
16327
+ style.width = `${(100 * width).toFixed(2)}%`;
16328
+ style.height = `${(100 * height).toFixed(2)}%`;
16043
16329
  }
16044
16330
  /**
16045
16331
  * Get the translation used to position this editor when it's created.
@@ -16090,15 +16376,24 @@ var _AnnotationEditor = class _AnnotationEditor {
16090
16376
  await this._editToolbar.addButton(name, tool);
16091
16377
  }
16092
16378
  }
16093
- this._editToolbar.addButton("comment", this.addCommentButton());
16379
+ if (!this.hasComment) {
16380
+ this._editToolbar.addButton("comment", this.addCommentButton());
16381
+ }
16094
16382
  this._editToolbar.addButton("delete");
16095
16383
  return this._editToolbar;
16096
16384
  }
16385
+ addCommentButtonInToolbar() {
16386
+ this._editToolbar?.addButtonBefore(
16387
+ "comment",
16388
+ this.addCommentButton(),
16389
+ ".deleteButton"
16390
+ );
16391
+ }
16392
+ removeCommentButtonFromToolbar() {
16393
+ this._editToolbar?.removeButton("comment");
16394
+ }
16097
16395
  removeEditToolbar() {
16098
- if (!this._editToolbar) {
16099
- return;
16100
- }
16101
- this._editToolbar.remove();
16396
+ this._editToolbar?.remove();
16102
16397
  this._editToolbar = null;
16103
16398
  __privateGet(this, _altText3)?.destroy();
16104
16399
  }
@@ -16155,44 +16450,94 @@ var _AnnotationEditor = class _AnnotationEditor {
16155
16450
  hasAltTextData() {
16156
16451
  return __privateGet(this, _altText3)?.hasData() ?? false;
16157
16452
  }
16453
+ focusCommentButton() {
16454
+ __privateGet(this, _comment2)?.focusButton();
16455
+ }
16158
16456
  addCommentButton() {
16159
- if (__privateGet(this, _comment2)) {
16160
- return __privateGet(this, _comment2);
16457
+ return __privateGet(this, _comment2) || __privateSet(this, _comment2, new Comment(this));
16458
+ }
16459
+ addStandaloneCommentButton() {
16460
+ if (__privateGet(this, _commentStandaloneButton2)) {
16461
+ if (this._uiManager.isEditingMode()) {
16462
+ __privateGet(this, _commentStandaloneButton2).classList.remove("hidden");
16463
+ }
16464
+ return;
16161
16465
  }
16162
- return __privateSet(this, _comment2, new Comment(this));
16466
+ if (!this.hasComment) {
16467
+ return;
16468
+ }
16469
+ __privateSet(this, _commentStandaloneButton2, __privateGet(this, _comment2).renderForStandalone());
16470
+ this.div.append(__privateGet(this, _commentStandaloneButton2));
16163
16471
  }
16164
- get commentColor() {
16165
- return null;
16472
+ removeStandaloneCommentButton() {
16473
+ __privateGet(this, _comment2).removeStandaloneCommentButton();
16474
+ __privateSet(this, _commentStandaloneButton2, null);
16475
+ }
16476
+ hideStandaloneCommentButton() {
16477
+ __privateGet(this, _commentStandaloneButton2)?.classList.add("hidden");
16166
16478
  }
16167
16479
  get comment() {
16168
- const comment = __privateGet(this, _comment2);
16480
+ const {
16481
+ data: { richText, text, date, deleted }
16482
+ } = __privateGet(this, _comment2);
16169
16483
  return {
16170
- text: comment.data.text,
16171
- date: comment.data.date,
16172
- deleted: comment.isDeleted(),
16173
- color: this.commentColor
16484
+ text,
16485
+ richText,
16486
+ date,
16487
+ deleted,
16488
+ color: this.getNonHCMColor(),
16489
+ opacity: this.opacity ?? 1
16174
16490
  };
16175
16491
  }
16176
16492
  set comment(text) {
16177
- if (!__privateGet(this, _comment2)) {
16178
- __privateSet(this, _comment2, new Comment(this));
16179
- }
16493
+ __privateGet(this, _comment2) || __privateSet(this, _comment2, new Comment(this));
16180
16494
  __privateGet(this, _comment2).data = text;
16495
+ if (this.hasComment) {
16496
+ this.removeCommentButtonFromToolbar();
16497
+ this.addStandaloneCommentButton();
16498
+ this._uiManager.updateComment(this);
16499
+ } else {
16500
+ this.addCommentButtonInToolbar();
16501
+ this.removeStandaloneCommentButton();
16502
+ this._uiManager.removeComment(this);
16503
+ }
16181
16504
  }
16182
- setCommentData(text) {
16183
- if (!__privateGet(this, _comment2)) {
16184
- __privateSet(this, _comment2, new Comment(this));
16505
+ setCommentData({ comment, popupRef, richText }) {
16506
+ if (!popupRef) {
16507
+ return;
16508
+ }
16509
+ __privateGet(this, _comment2) || __privateSet(this, _comment2, new Comment(this));
16510
+ __privateGet(this, _comment2).setInitialText(comment, richText);
16511
+ if (!this.annotationElementId) {
16512
+ return;
16513
+ }
16514
+ const storedData = this._uiManager.getAndRemoveDataFromAnnotationStorage(
16515
+ this.annotationElementId
16516
+ );
16517
+ if (storedData) {
16518
+ this.updateFromAnnotationLayer(storedData);
16185
16519
  }
16186
- __privateGet(this, _comment2).setInitialText(text);
16187
16520
  }
16188
16521
  get hasEditedComment() {
16189
16522
  return __privateGet(this, _comment2)?.hasBeenEdited();
16190
16523
  }
16191
- async editComment() {
16192
- if (!__privateGet(this, _comment2)) {
16193
- __privateSet(this, _comment2, new Comment(this));
16524
+ get hasDeletedComment() {
16525
+ return __privateGet(this, _comment2)?.isDeleted();
16526
+ }
16527
+ get hasComment() {
16528
+ return !!__privateGet(this, _comment2) && !__privateGet(this, _comment2).isEmpty() && !__privateGet(this, _comment2).isDeleted();
16529
+ }
16530
+ async editComment(options) {
16531
+ __privateGet(this, _comment2) || __privateSet(this, _comment2, new Comment(this));
16532
+ __privateGet(this, _comment2).edit(options);
16533
+ }
16534
+ toggleComment(isSelected, visibility = void 0) {
16535
+ if (this.hasComment) {
16536
+ this._uiManager.toggleComment(this, isSelected, visibility);
16194
16537
  }
16195
- __privateGet(this, _comment2).edit();
16538
+ }
16539
+ setSelectedCommentButton(selected) {
16540
+ __privateGet(this, _comment2).setSelectedButton(selected);
16196
16541
  }
16197
16542
  addComment(serialized) {
16198
16543
  if (this.hasEditedComment) {
@@ -16211,6 +16556,12 @@ var _AnnotationEditor = class _AnnotationEditor {
16211
16556
  };
16212
16557
  }
16213
16558
  }
16559
+ updateFromAnnotationLayer({ popup: { contents, deleted } }) {
16560
+ __privateGet(this, _comment2).data = deleted ? null : contents;
16561
+ }
16562
+ get parentBoundingClientRect() {
16563
+ return this.parent.boundingClientRect;
16564
+ }
16214
16565
  /**
16215
16566
  * Render this editor in a div.
16216
16567
  * @returns {HTMLDivElement | null}
@@ -16252,6 +16603,7 @@ var _AnnotationEditor = class _AnnotationEditor {
16252
16603
  signal: this._uiManager._signal
16253
16604
  }));
16254
16605
  }
16606
+ this.addStandaloneCommentButton();
16255
16607
  this._uiManager._editorUndoBar?.hide();
16256
16608
  return div;
16257
16609
  }
@@ -16371,6 +16723,38 @@ var _AnnotationEditor = class _AnnotationEditor {
16371
16723
  getPDFRect() {
16372
16724
  return this.getRect(0, 0);
16373
16725
  }
16726
+ getNonHCMColor() {
16727
+ return this.color && _AnnotationEditor._colorManager.convert(
16728
+ this._uiManager.getNonHCMColor(this.color)
16729
+ );
16730
+ }
16731
+ /**
16732
+ * The color has been changed.
16733
+ */
16734
+ onUpdatedColor() {
16735
+ __privateGet(this, _comment2)?.onUpdatedColor();
16736
+ }
16737
+ getData() {
16738
+ const {
16739
+ comment: { text: str, color, date, opacity, deleted, richText },
16740
+ uid: id2,
16741
+ pageIndex,
16742
+ creationDate,
16743
+ modificationDate
16744
+ } = this;
16745
+ return {
16746
+ id: id2,
16747
+ pageIndex,
16748
+ rect: this.getPDFRect(),
16749
+ richText,
16750
+ contentsObj: { str },
16751
+ creationDate,
16752
+ modificationDate: date || modificationDate,
16753
+ popupRef: !deleted,
16754
+ color,
16755
+ opacity
16756
+ };
16757
+ }
16374
16758
  /**
16375
16759
  * Executed once this editor has been rendered.
16376
16760
  * @param {boolean} focus - true if the editor should be focused.
@@ -16477,7 +16861,14 @@ var _AnnotationEditor = class _AnnotationEditor {
16477
16861
  * @returns {Object | null}
16478
16862
  */
16479
16863
  serialize(isForCopying = false, context = null) {
16480
- unreachable("An editor must be serializable");
16864
+ return {
16865
+ annotationType: this.mode,
16866
+ pageIndex: this.pageIndex,
16867
+ rect: this.getPDFRect(),
16868
+ rotation: this.rotation,
16869
+ structTreeParentId: this._structTreeParentId,
16870
+ popupRef: this._initialData?.popupRef || ""
16871
+ };
16481
16872
  }
16482
16873
  /**
16483
16874
  * Deserialize the editor.
@@ -16493,7 +16884,9 @@ var _AnnotationEditor = class _AnnotationEditor {
16493
16884
  parent,
16494
16885
  id: parent.getNextId(),
16495
16886
  uiManager,
16496
- annotationElementId: data.annotationElementId
16887
+ annotationElementId: data.annotationElementId,
16888
+ creationDate: data.creationDate,
16889
+ modificationDate: data.modificationDate
16497
16890
  });
16498
16891
  editor.rotation = data.rotation;
16499
16892
  __privateSet(editor, _accessibilityData, data.accessibilityData);
@@ -16566,6 +16959,47 @@ var _AnnotationEditor = class _AnnotationEditor {
16566
16959
  get toolbarPosition() {
16567
16960
  return null;
16568
16961
  }
16962
+ /**
16963
+ * Get the position of the comment button.
16964
+ * @returns {Array<number>|null}
16965
+ */
16966
+ get commentButtonPosition() {
16967
+ return this._uiManager.direction === "ltr" ? [1, 0] : [0, 0];
16968
+ }
16969
+ get commentButtonPositionInPage() {
16970
+ const {
16971
+ commentButtonPosition: [posX, posY]
16972
+ } = this;
16973
+ const [blX, blY, trX, trY] = this.getPDFRect();
16974
+ return [
16975
+ _AnnotationEditor._round(blX + (trX - blX) * posX),
16976
+ _AnnotationEditor._round(blY + (trY - blY) * (1 - posY))
16977
+ ];
16978
+ }
16979
+ get commentButtonColor() {
16980
+ return this._uiManager.makeCommentColor(
16981
+ this.getNonHCMColor(),
16982
+ this.opacity
16983
+ );
16984
+ }
16985
+ get commentPopupPosition() {
16986
+ return __privateGet(this, _comment2).commentPopupPositionInLayer;
16987
+ }
16988
+ set commentPopupPosition(pos) {
16989
+ __privateGet(this, _comment2).commentPopupPositionInLayer = pos;
16990
+ }
16991
+ hasDefaultPopupPosition() {
16992
+ return __privateGet(this, _comment2).hasDefaultPopupPosition();
16993
+ }
16994
+ get commentButtonWidth() {
16995
+ return __privateGet(this, _comment2).commentButtonWidth;
16996
+ }
16997
+ get elementBeforePopup() {
16998
+ return this.div;
16999
+ }
17000
+ setCommentButtonStates(options) {
17001
+ __privateGet(this, _comment2).setCommentButtonStates(options);
17002
+ }
16569
17003
  /**
16570
17004
  * onkeydown callback.
16571
17005
  * @param {KeyboardEvent} event
@@ -16649,6 +17083,7 @@ var _AnnotationEditor = class _AnnotationEditor {
16649
17083
  */
16650
17084
  select() {
16651
17085
  if (this.isSelected && this._editToolbar) {
17086
+ this._editToolbar.show();
16652
17087
  return;
16653
17088
  }
16654
17089
  this.isSelected = true;
@@ -16665,6 +17100,11 @@ var _AnnotationEditor = class _AnnotationEditor {
16665
17100
  this._editToolbar?.show();
16666
17101
  __privateGet(this, _altText3)?.toggleAltTextBadge(false);
16667
17102
  }
17103
+ focus() {
17104
+ if (this.div && !this.div.contains(document.activeElement)) {
17105
+ setTimeout(() => this.div?.focus({ preventScroll: true }), 0);
17106
+ }
17107
+ }
16668
17108
  /**
16669
17109
  * Unselect this editor.
16670
17110
  */
@@ -16682,6 +17122,15 @@ var _AnnotationEditor = class _AnnotationEditor {
16682
17122
  }
16683
17123
  this._editToolbar?.hide();
16684
17124
  __privateGet(this, _altText3)?.toggleAltTextBadge(true);
17125
+ if (this.hasComment) {
17126
+ this._uiManager.toggleComment(
17127
+ this,
17128
+ /* isSelected = */
17129
+ false,
17130
+ /* visibility = */
17131
+ false
17132
+ );
17133
+ }
16685
17134
  }
16686
17135
  /**
16687
17136
  * Update some parameters which have been changed through the UI.
@@ -16726,6 +17175,9 @@ var _AnnotationEditor = class _AnnotationEditor {
16726
17175
  * @param {MouseEvent} event
16727
17176
  */
16728
17177
  dblclick(event) {
17178
+ if (event.target.nodeName === "BUTTON") {
17179
+ return;
17180
+ }
16729
17181
  this.enterInEditMode();
16730
17182
  this.parent.updateToolbar({
16731
17183
  mode: this.constructor._editorType,
@@ -16768,18 +17220,6 @@ var _AnnotationEditor = class _AnnotationEditor {
16768
17220
  this.parent.setActiveEditor(null);
16769
17221
  }
16770
17222
  }
16771
- /**
16772
- * Set the aspect ratio to use when resizing.
16773
- * @param {number} width
16774
- * @param {number} height
16775
- */
16776
- setAspectRatio(width, height) {
16777
- __privateSet(this, _keepAspectRatio, true);
16778
- const aspectRatio = width / height;
16779
- const { style } = this.div;
16780
- style.aspectRatio = aspectRatio;
16781
- style.height = "auto";
16782
- }
16783
17223
  static get MIN_SIZE() {
16784
17224
  return 16;
16785
17225
  }
@@ -16847,6 +17287,23 @@ var _AnnotationEditor = class _AnnotationEditor {
16847
17287
  }
16848
17288
  __privateSet(this, _disabled, true);
16849
17289
  }
17290
+ updateFakeAnnotationElement(annotationLayer) {
17291
+ if (!__privateGet(this, _fakeAnnotation) && !this.deleted) {
17292
+ __privateSet(this, _fakeAnnotation, annotationLayer.addFakeAnnotation(this));
17293
+ return;
17294
+ }
17295
+ if (this.deleted) {
17296
+ __privateGet(this, _fakeAnnotation).remove();
17297
+ __privateSet(this, _fakeAnnotation, null);
17298
+ return;
17299
+ }
17300
+ if (this.hasEditedComment || this._hasBeenMoved || this._hasBeenResized) {
17301
+ __privateGet(this, _fakeAnnotation).updateEdited({
17302
+ rect: this.getPDFRect(),
17303
+ popup: this.comment
17304
+ });
17305
+ }
17306
+ }
16850
17307
  /**
16851
17308
  * Render an annotation in the annotation layer.
16852
17309
  * @param {Object} annotation
@@ -16881,13 +17338,14 @@ _accessibilityData = new WeakMap();
16881
17338
  _allResizerDivs = new WeakMap();
16882
17339
  _altText3 = new WeakMap();
16883
17340
  _comment2 = new WeakMap();
17341
+ _commentStandaloneButton2 = new WeakMap();
16884
17342
  _disabled = new WeakMap();
16885
17343
  _dragPointerId = new WeakMap();
16886
17344
  _dragPointerType = new WeakMap();
16887
- _keepAspectRatio = new WeakMap();
16888
17345
  _resizersDiv = new WeakMap();
16889
17346
  _lastPointerCoords = new WeakMap();
16890
17347
  _savedDimensions = new WeakMap();
17348
+ _fakeAnnotation = new WeakMap();
16891
17349
  _focusAC = new WeakMap();
16892
17350
  _focusedResizerName = new WeakMap();
16893
17351
  _hasBeenClicked = new WeakMap();
@@ -17021,8 +17479,7 @@ resize_fn = function(x, y, width, height) {
17021
17479
  this.height = height;
17022
17480
  this.x = x;
17023
17481
  this.y = y;
17024
- const [parentWidth, parentHeight] = this.parentDimensions;
17025
- this.setDims(parentWidth * width, parentHeight * height);
17482
+ this.setDims();
17026
17483
  this.fixAndSetPosition();
17027
17484
  this._onResized();
17028
17485
  };
@@ -17163,7 +17620,7 @@ resizerPointermove_fn = function(name, event) {
17163
17620
  this.height = newHeight;
17164
17621
  this.x = newX;
17165
17622
  this.y = newY;
17166
- this.setDims(parentWidth * newWidth, parentHeight * newHeight);
17623
+ this.setDims();
17167
17624
  this.fixAndSetPosition();
17168
17625
  this._onResizing();
17169
17626
  };
@@ -17214,7 +17671,7 @@ touchPinchCallback_fn = function(_origin, prevDistance, distance) {
17214
17671
  this.y = centerY - newTransfCenterPoint[1];
17215
17672
  this.width = newWidth;
17216
17673
  this.height = newHeight;
17217
- this.setDims(parentWidth * newWidth, parentHeight * newHeight);
17674
+ this.setDims();
17218
17675
  this.fixAndSetPosition();
17219
17676
  this._onResizing();
17220
17677
  };
@@ -17259,6 +17716,13 @@ setUpDragSession_fn = function(event) {
17259
17716
  (e) => {
17260
17717
  if (!hasDraggingStarted) {
17261
17718
  hasDraggingStarted = true;
17719
+ this._uiManager.toggleComment(
17720
+ this,
17721
+ /* isSelected = */
17722
+ true,
17723
+ /* visibility = */
17724
+ false
17725
+ );
17262
17726
  this._onStartDragging();
17263
17727
  }
17264
17728
  const { clientX: x, clientY: y, pointerId } = e;
@@ -17366,12 +17830,13 @@ var SerializableEmpty = Object.freeze({
17366
17830
  hash: "",
17367
17831
  transfer: void 0
17368
17832
  });
17369
- var _modified, _modifiedIds, _storage, _AnnotationStorage_instances, setModified_fn;
17833
+ var _modified, _modifiedIds, _editorsMap, _storage, _AnnotationStorage_instances, setModified_fn;
17370
17834
  var AnnotationStorage = class {
17371
17835
  constructor() {
17372
17836
  __privateAdd(this, _AnnotationStorage_instances);
17373
17837
  __privateAdd(this, _modified, false);
17374
17838
  __privateAdd(this, _modifiedIds, null);
17839
+ __privateAdd(this, _editorsMap, null);
17375
17840
  __privateAdd(this, _storage, /* @__PURE__ */ new Map());
17376
17841
  this.onSetModified = null;
17377
17842
  this.onResetModified = null;
@@ -17412,6 +17877,13 @@ var AnnotationStorage = class {
17412
17877
  * @param {string} key
17413
17878
  */
17414
17879
  remove(key) {
17880
+ const storedValue = __privateGet(this, _storage).get(key);
17881
+ if (storedValue === void 0) {
17882
+ return;
17883
+ }
17884
+ if (storedValue instanceof AnnotationEditor) {
17885
+ __privateGet(this, _editorsMap).delete(storedValue.annotationElementId);
17886
+ }
17415
17887
  __privateGet(this, _storage).delete(key);
17416
17888
  if (__privateGet(this, _storage).size === 0) {
17417
17889
  this.resetModified();
@@ -17447,8 +17919,11 @@ var AnnotationStorage = class {
17447
17919
  if (modified) {
17448
17920
  __privateMethod(this, _AnnotationStorage_instances, setModified_fn).call(this);
17449
17921
  }
17450
- if (value instanceof AnnotationEditor && typeof this.onAnnotationEditor === "function") {
17451
- this.onAnnotationEditor(value.constructor._type);
17922
+ if (value instanceof AnnotationEditor) {
17923
+ (__privateGet(this, _editorsMap) || __privateSet(this, _editorsMap, /* @__PURE__ */ new Map())).set(value.annotationElementId, value);
17924
+ if (typeof this.onAnnotationEditor === "function") {
17925
+ this.onAnnotationEditor(value.constructor._type);
17926
+ }
17452
17927
  }
17453
17928
  }
17454
17929
  /**
@@ -17511,10 +17986,24 @@ var AnnotationStorage = class {
17511
17986
  get editorStats() {
17512
17987
  let stats = null;
17513
17988
  const typeToEditor = /* @__PURE__ */ new Map();
17989
+ let numberOfEditedComments = 0;
17990
+ let numberOfDeletedComments = 0;
17514
17991
  for (const value of __privateGet(this, _storage).values()) {
17515
17992
  if (!(value instanceof AnnotationEditor)) {
17993
+ if (value.popup) {
17994
+ if (value.popup.deleted) {
17995
+ numberOfDeletedComments += 1;
17996
+ } else {
17997
+ numberOfEditedComments += 1;
17998
+ }
17999
+ }
17516
18000
  continue;
17517
18001
  }
18002
+ if (value.isCommentDeleted) {
18003
+ numberOfDeletedComments += 1;
18004
+ } else if (value.hasEditedComment) {
18005
+ numberOfEditedComments += 1;
18006
+ }
17518
18007
  const editorStats = value.telemetryFinalData;
17519
18008
  if (!editorStats) {
17520
18009
  continue;
@@ -17538,6 +18027,16 @@ var AnnotationStorage = class {
17538
18027
  counters.set(val, count + 1);
17539
18028
  }
17540
18029
  }
18030
+ if (numberOfDeletedComments > 0 || numberOfEditedComments > 0) {
18031
+ stats || (stats = /* @__PURE__ */ Object.create(null));
18032
+ stats.comments = {
18033
+ deleted: numberOfDeletedComments,
18034
+ edited: numberOfEditedComments
18035
+ };
18036
+ }
18037
+ if (!stats) {
18038
+ return null;
18039
+ }
17541
18040
  for (const [type, editor] of typeToEditor) {
17542
18041
  stats[type] = editor.computeTelemetryFinalData(stats[type]);
17543
18042
  }
@@ -17546,6 +18045,17 @@ var AnnotationStorage = class {
17546
18045
  resetModifiedIds() {
17547
18046
  __privateSet(this, _modifiedIds, null);
17548
18047
  }
18048
+ updateEditor(annotationId, data) {
18049
+ const value = __privateGet(this, _editorsMap)?.get(annotationId);
18050
+ if (value) {
18051
+ value.updateFromAnnotationLayer(data);
18052
+ return true;
18053
+ }
18054
+ return false;
18055
+ }
18056
+ getEditor(annotationId) {
18057
+ return __privateGet(this, _editorsMap)?.get(annotationId) || null;
18058
+ }
17549
18059
  /**
17550
18060
  * @returns {{ids: Set<string>, hash: string}}
17551
18061
  */
@@ -17554,11 +18064,13 @@ var AnnotationStorage = class {
17554
18064
  return __privateGet(this, _modifiedIds);
17555
18065
  }
17556
18066
  const ids = [];
17557
- for (const value of __privateGet(this, _storage).values()) {
17558
- if (!(value instanceof AnnotationEditor) || !value.annotationElementId || !value.serialize()) {
17559
- continue;
18067
+ if (__privateGet(this, _editorsMap)) {
18068
+ for (const value of __privateGet(this, _editorsMap).values()) {
18069
+ if (!value.serialize()) {
18070
+ continue;
18071
+ }
18072
+ ids.push(value.annotationElementId);
17560
18073
  }
17561
- ids.push(value.annotationElementId);
17562
18074
  }
17563
18075
  return __privateSet(this, _modifiedIds, {
17564
18076
  ids: new Set(ids),
@@ -17571,6 +18083,7 @@ var AnnotationStorage = class {
17571
18083
  };
17572
18084
  _modified = new WeakMap();
17573
18085
  _modifiedIds = new WeakMap();
18086
+ _editorsMap = new WeakMap();
17574
18087
  _storage = new WeakMap();
17575
18088
  _AnnotationStorage_instances = new WeakSet();
17576
18089
  setModified_fn = function() {
@@ -18139,12 +18652,12 @@ var FontLoader = class {
18139
18652
  }
18140
18653
  };
18141
18654
  _systemFonts = new WeakMap();
18655
+ var _fontData;
18142
18656
  var FontFaceObject = class {
18143
- constructor(translatedData, inspectFont = null) {
18657
+ constructor(translatedData, inspectFont = null, extra, charProcOperatorList) {
18658
+ __privateAdd(this, _fontData);
18144
18659
  this.compiledGlyphs = /* @__PURE__ */ Object.create(null);
18145
- for (const i in translatedData) {
18146
- this[i] = translatedData[i];
18147
- }
18660
+ __privateSet(this, _fontData, translatedData);
18148
18661
  if (false) {
18149
18662
  if (typeof this.disableFontFace !== "boolean") {
18150
18663
  unreachable("disableFontFace must be available.");
@@ -18154,6 +18667,12 @@ var FontFaceObject = class {
18154
18667
  }
18155
18668
  }
18156
18669
  this._inspectFont = inspectFont;
18670
+ if (extra) {
18671
+ Object.assign(this, extra);
18672
+ }
18673
+ if (charProcOperatorList) {
18674
+ this.charProcOperatorList = charProcOperatorList;
18675
+ }
18157
18676
  }
18158
18677
  createNativeFontFace() {
18159
18678
  if (!this.data || this.disableFontFace) {
@@ -18213,7 +18732,80 @@ var FontFaceObject = class {
18213
18732
  }
18214
18733
  return this.compiledGlyphs[character] = path;
18215
18734
  }
18735
+ get black() {
18736
+ return __privateGet(this, _fontData).black;
18737
+ }
18738
+ get bold() {
18739
+ return __privateGet(this, _fontData).bold;
18740
+ }
18741
+ get disableFontFace() {
18742
+ return __privateGet(this, _fontData).disableFontFace ?? false;
18743
+ }
18744
+ get fontExtraProperties() {
18745
+ return __privateGet(this, _fontData).fontExtraProperties ?? false;
18746
+ }
18747
+ get isInvalidPDFjsFont() {
18748
+ return __privateGet(this, _fontData).isInvalidPDFjsFont;
18749
+ }
18750
+ get isType3Font() {
18751
+ return __privateGet(this, _fontData).isType3Font;
18752
+ }
18753
+ get italic() {
18754
+ return __privateGet(this, _fontData).italic;
18755
+ }
18756
+ get missingFile() {
18757
+ return __privateGet(this, _fontData).missingFile;
18758
+ }
18759
+ get remeasure() {
18760
+ return __privateGet(this, _fontData).remeasure;
18761
+ }
18762
+ get vertical() {
18763
+ return __privateGet(this, _fontData).vertical;
18764
+ }
18765
+ get ascent() {
18766
+ return __privateGet(this, _fontData).ascent;
18767
+ }
18768
+ get defaultWidth() {
18769
+ return __privateGet(this, _fontData).defaultWidth;
18770
+ }
18771
+ get descent() {
18772
+ return __privateGet(this, _fontData).descent;
18773
+ }
18774
+ get bbox() {
18775
+ return __privateGet(this, _fontData).bbox;
18776
+ }
18777
+ get fontMatrix() {
18778
+ return __privateGet(this, _fontData).fontMatrix;
18779
+ }
18780
+ get fallbackName() {
18781
+ return __privateGet(this, _fontData).fallbackName;
18782
+ }
18783
+ get loadedName() {
18784
+ return __privateGet(this, _fontData).loadedName;
18785
+ }
18786
+ get mimetype() {
18787
+ return __privateGet(this, _fontData).mimetype;
18788
+ }
18789
+ get name() {
18790
+ return __privateGet(this, _fontData).name;
18791
+ }
18792
+ get data() {
18793
+ return __privateGet(this, _fontData).data;
18794
+ }
18795
+ clearData() {
18796
+ __privateGet(this, _fontData).clearData();
18797
+ }
18798
+ get cssFontInfo() {
18799
+ return __privateGet(this, _fontData).cssFontInfo;
18800
+ }
18801
+ get systemFontInfo() {
18802
+ return __privateGet(this, _fontData).systemFontInfo;
18803
+ }
18804
+ get defaultVMetrics() {
18805
+ return __privateGet(this, _fontData).defaultVMetrics;
18806
+ }
18216
18807
  };
18808
+ _fontData = new WeakMap();
18217
18809
 
18218
18810
  // src/pdf.js/src/display/api_utils.js
18219
18811
  function getUrlProp(val) {
@@ -18321,9 +18913,58 @@ _deferred = new WeakMap();
18321
18913
 
18322
18914
  // src/pdf.js/src/display/canvas_dependency_tracker.js
18323
18915
  var FORCED_DEPENDENCY_LABEL = "__forcedDependency";
18324
- var _simple, _incremental, _namedDependencies, _savesStack, _markedContentStack, _baseTransformStack, _clipBox, _pendingBBox, _pendingBBoxIdx, _pendingDependencies, _operations, _fontBBoxTrustworthy, _canvasWidth, _canvasHeight;
18916
+ var { floor, ceil } = Math;
18917
+ function expandBBox(array, index, minX, minY, maxX, maxY) {
18918
+ array[index * 4 + 0] = Math.min(array[index * 4 + 0], minX);
18919
+ array[index * 4 + 1] = Math.min(array[index * 4 + 1], minY);
18920
+ array[index * 4 + 2] = Math.max(array[index * 4 + 2], maxX);
18921
+ array[index * 4 + 3] = Math.max(array[index * 4 + 3], maxY);
18922
+ }
18923
+ var EMPTY_BBOX = new Uint32Array(new Uint8Array([255, 255, 0, 0]).buffer)[0];
18924
+ var _bboxes, _coords;
18925
+ var BBoxReader = class {
18926
+ constructor(bboxes, coords) {
18927
+ __privateAdd(this, _bboxes);
18928
+ __privateAdd(this, _coords);
18929
+ __privateSet(this, _bboxes, bboxes);
18930
+ __privateSet(this, _coords, coords);
18931
+ }
18932
+ get length() {
18933
+ return __privateGet(this, _bboxes).length;
18934
+ }
18935
+ isEmpty(i) {
18936
+ return __privateGet(this, _bboxes)[i] === EMPTY_BBOX;
18937
+ }
18938
+ minX(i) {
18939
+ return __privateGet(this, _coords)[i * 4 + 0] / 256;
18940
+ }
18941
+ minY(i) {
18942
+ return __privateGet(this, _coords)[i * 4 + 1] / 256;
18943
+ }
18944
+ maxX(i) {
18945
+ return (__privateGet(this, _coords)[i * 4 + 2] + 1) / 256;
18946
+ }
18947
+ maxY(i) {
18948
+ return (__privateGet(this, _coords)[i * 4 + 3] + 1) / 256;
18949
+ }
18950
+ };
18951
+ _bboxes = new WeakMap();
18952
+ _coords = new WeakMap();
18953
+ var ensureDebugMetadata = (map, key) => {
18954
+ if (!map) {
18955
+ return void 0;
18956
+ }
18957
+ let value = map.get(key);
18958
+ if (!value) {
18959
+ value = { dependencies: /* @__PURE__ */ new Set(), isRenderingOperation: false };
18960
+ map.set(key, value);
18961
+ }
18962
+ return value;
18963
+ };
18964
+ var _simple, _incremental, _namedDependencies, _savesStack, _markedContentStack, _baseTransformStack, _clipBox, _pendingBBox, _pendingBBoxIdx, _pendingDependencies, _operations, _fontBBoxTrustworthy, _canvasWidth, _canvasHeight, _bboxesCoords, _bboxes2, _debugMetadata, _CanvasDependencyTracker_instances, initializeBBoxes_fn;
18325
18965
  var CanvasDependencyTracker = class {
18326
- constructor(canvas) {
18966
+ constructor(canvas, operationsCount, recordDebugMetadata = false) {
18967
+ __privateAdd(this, _CanvasDependencyTracker_instances);
18327
18968
  /** @type {Record<SimpleDependency, number>} */
18328
18969
  __privateAdd(this, _simple, { __proto__: null });
18329
18970
  /** @type {Record<InternalIncrementalDependency , number[]>} */
@@ -18347,8 +18988,21 @@ var CanvasDependencyTracker = class {
18347
18988
  __privateAdd(this, _fontBBoxTrustworthy, /* @__PURE__ */ new Map());
18348
18989
  __privateAdd(this, _canvasWidth);
18349
18990
  __privateAdd(this, _canvasHeight);
18991
+ // Uint8ClampedArray<minX, minY, maxX, maxY>
18992
+ __privateAdd(this, _bboxesCoords);
18993
+ __privateAdd(this, _bboxes2);
18994
+ __privateAdd(this, _debugMetadata);
18350
18995
  __privateSet(this, _canvasWidth, canvas.width);
18351
18996
  __privateSet(this, _canvasHeight, canvas.height);
18997
+ __privateMethod(this, _CanvasDependencyTracker_instances, initializeBBoxes_fn).call(this, operationsCount);
18998
+ if (recordDebugMetadata) {
18999
+ __privateSet(this, _debugMetadata, /* @__PURE__ */ new Map());
19000
+ }
19001
+ }
19002
+ growOperationsCount(operationsCount) {
19003
+ if (operationsCount >= __privateGet(this, _bboxes2).length) {
19004
+ __privateMethod(this, _CanvasDependencyTracker_instances, initializeBBoxes_fn).call(this, operationsCount, __privateGet(this, _bboxes2));
19005
+ }
18352
19006
  }
18353
19007
  save(opIdx) {
18354
19008
  __privateSet(this, _simple, { __proto__: __privateGet(this, _simple) });
@@ -18362,7 +19016,7 @@ var CanvasDependencyTracker = class {
18362
19016
  }
18363
19017
  });
18364
19018
  __privateSet(this, _clipBox, { __proto__: __privateGet(this, _clipBox) });
18365
- __privateGet(this, _savesStack).push([opIdx, null]);
19019
+ __privateGet(this, _savesStack).push(opIdx);
18366
19020
  return this;
18367
19021
  }
18368
19022
  restore(opIdx) {
@@ -18373,9 +19027,12 @@ var CanvasDependencyTracker = class {
18373
19027
  __privateSet(this, _simple, previous);
18374
19028
  __privateSet(this, _incremental, Object.getPrototypeOf(__privateGet(this, _incremental)));
18375
19029
  __privateSet(this, _clipBox, Object.getPrototypeOf(__privateGet(this, _clipBox)));
18376
- const lastPair = __privateGet(this, _savesStack).pop();
18377
- if (lastPair !== void 0) {
18378
- lastPair[1] = opIdx;
19030
+ const lastSave = __privateGet(this, _savesStack).pop();
19031
+ if (lastSave !== void 0) {
19032
+ ensureDebugMetadata(__privateGet(this, _debugMetadata), opIdx)?.dependencies.add(
19033
+ lastSave
19034
+ );
19035
+ __privateGet(this, _bboxes2)[opIdx] = __privateGet(this, _bboxes2)[lastSave];
18379
19036
  }
18380
19037
  return this;
18381
19038
  }
@@ -18383,32 +19040,38 @@ var CanvasDependencyTracker = class {
18383
19040
  * @param {number} idx
18384
19041
  */
18385
19042
  recordOpenMarker(idx) {
18386
- __privateGet(this, _savesStack).push([idx, null]);
19043
+ __privateGet(this, _savesStack).push(idx);
18387
19044
  return this;
18388
19045
  }
18389
19046
  getOpenMarker() {
18390
19047
  if (__privateGet(this, _savesStack).length === 0) {
18391
19048
  return null;
18392
19049
  }
18393
- return __privateGet(this, _savesStack).at(-1)[0];
19050
+ return __privateGet(this, _savesStack).at(-1);
18394
19051
  }
18395
- recordCloseMarker(idx) {
18396
- const lastPair = __privateGet(this, _savesStack).pop();
18397
- if (lastPair !== void 0) {
18398
- lastPair[1] = idx;
19052
+ recordCloseMarker(opIdx) {
19053
+ const lastSave = __privateGet(this, _savesStack).pop();
19054
+ if (lastSave !== void 0) {
19055
+ ensureDebugMetadata(__privateGet(this, _debugMetadata), opIdx)?.dependencies.add(
19056
+ lastSave
19057
+ );
19058
+ __privateGet(this, _bboxes2)[opIdx] = __privateGet(this, _bboxes2)[lastSave];
18399
19059
  }
18400
19060
  return this;
18401
19061
  }
18402
19062
  // Marked content needs a separate stack from save/restore, because they
18403
19063
  // form two independent trees.
18404
19064
  beginMarkedContent(opIdx) {
18405
- __privateGet(this, _markedContentStack).push([opIdx, null]);
19065
+ __privateGet(this, _markedContentStack).push(opIdx);
18406
19066
  return this;
18407
19067
  }
18408
19068
  endMarkedContent(opIdx) {
18409
- const lastPair = __privateGet(this, _markedContentStack).pop();
18410
- if (lastPair !== void 0) {
18411
- lastPair[1] = opIdx;
19069
+ const lastSave = __privateGet(this, _markedContentStack).pop();
19070
+ if (lastSave !== void 0) {
19071
+ ensureDebugMetadata(__privateGet(this, _debugMetadata), opIdx)?.dependencies.add(
19072
+ lastSave
19073
+ );
19074
+ __privateGet(this, _bboxes2)[opIdx] = __privateGet(this, _bboxes2)[lastSave];
18412
19075
  }
18413
19076
  return this;
18414
19077
  }
@@ -18455,6 +19118,14 @@ var CanvasDependencyTracker = class {
18455
19118
  __privateGet(this, _namedDependencies).set(name, idx);
18456
19119
  return this;
18457
19120
  }
19121
+ /**
19122
+ * @param {SimpleDependency} name
19123
+ * @param {string} depName
19124
+ * @param {number} fallbackIdx
19125
+ */
19126
+ recordSimpleDataFromNamed(name, depName, fallbackIdx) {
19127
+ __privateGet(this, _simple)[name] = __privateGet(this, _namedDependencies).get(depName) ?? fallbackIdx;
19128
+ }
18458
19129
  // All next operations, until the next .restore(), will depend on this
18459
19130
  recordFutureForcedDependency(name, idx) {
18460
19131
  this.recordIncrementalData(FORCED_DEPENDENCY_LABEL, idx);
@@ -18477,16 +19148,15 @@ var CanvasDependencyTracker = class {
18477
19148
  return this;
18478
19149
  }
18479
19150
  resetBBox(idx) {
18480
- __privateSet(this, _pendingBBoxIdx, idx);
18481
- __privateGet(this, _pendingBBox)[0] = Infinity;
18482
- __privateGet(this, _pendingBBox)[1] = Infinity;
18483
- __privateGet(this, _pendingBBox)[2] = -Infinity;
18484
- __privateGet(this, _pendingBBox)[3] = -Infinity;
19151
+ if (__privateGet(this, _pendingBBoxIdx) !== idx) {
19152
+ __privateSet(this, _pendingBBoxIdx, idx);
19153
+ __privateGet(this, _pendingBBox)[0] = Infinity;
19154
+ __privateGet(this, _pendingBBox)[1] = Infinity;
19155
+ __privateGet(this, _pendingBBox)[2] = -Infinity;
19156
+ __privateGet(this, _pendingBBox)[3] = -Infinity;
19157
+ }
18485
19158
  return this;
18486
19159
  }
18487
- get hasPendingBBox() {
18488
- return __privateGet(this, _pendingBBoxIdx) !== -1;
18489
- }
18490
19160
  recordClipBox(idx, ctx, minX, maxX, minY, maxY) {
18491
19161
  const transform = Util.multiplyByDOMMatrix(
18492
19162
  __privateGet(this, _baseTransformStack).at(-1),
@@ -18619,17 +19289,6 @@ var CanvasDependencyTracker = class {
18619
19289
  }
18620
19290
  return this;
18621
19291
  }
18622
- copyDependenciesFromIncrementalOperation(idx, name) {
18623
- const operations = __privateGet(this, _operations);
18624
- const pendingDependencies = __privateGet(this, _pendingDependencies);
18625
- for (const depIdx of __privateGet(this, _incremental)[name]) {
18626
- operations.get(depIdx).dependencies.forEach(
18627
- pendingDependencies.add,
18628
- pendingDependencies.add(depIdx)
18629
- );
18630
- }
18631
- return this;
18632
- }
18633
19292
  recordNamedDependency(idx, name) {
18634
19293
  if (__privateGet(this, _namedDependencies).has(name)) {
18635
19294
  __privateGet(this, _pendingDependencies).add(__privateGet(this, _namedDependencies).get(name));
@@ -18639,32 +19298,65 @@ var CanvasDependencyTracker = class {
18639
19298
  /**
18640
19299
  * @param {number} idx
18641
19300
  */
18642
- recordOperation(idx, preserveBbox = false) {
19301
+ recordOperation(idx, preserve = false) {
18643
19302
  this.recordDependencies(idx, [FORCED_DEPENDENCY_LABEL]);
18644
- const dependencies = new Set(__privateGet(this, _pendingDependencies));
18645
- const pairs = __privateGet(this, _savesStack).concat(__privateGet(this, _markedContentStack));
18646
- const bbox = __privateGet(this, _pendingBBoxIdx) === idx ? {
18647
- minX: __privateGet(this, _pendingBBox)[0],
18648
- minY: __privateGet(this, _pendingBBox)[1],
18649
- maxX: __privateGet(this, _pendingBBox)[2],
18650
- maxY: __privateGet(this, _pendingBBox)[3]
18651
- } : null;
18652
- __privateGet(this, _operations).set(idx, { bbox, pairs, dependencies });
18653
- if (!preserveBbox) {
18654
- __privateSet(this, _pendingBBoxIdx, -1);
19303
+ if (__privateGet(this, _debugMetadata)) {
19304
+ const metadata = ensureDebugMetadata(__privateGet(this, _debugMetadata), idx);
19305
+ const { dependencies } = metadata;
19306
+ __privateGet(this, _pendingDependencies).forEach(dependencies.add, dependencies);
19307
+ __privateGet(this, _savesStack).forEach(dependencies.add, dependencies);
19308
+ __privateGet(this, _markedContentStack).forEach(dependencies.add, dependencies);
19309
+ dependencies.delete(idx);
19310
+ metadata.isRenderingOperation = true;
19311
+ }
19312
+ if (__privateGet(this, _pendingBBoxIdx) === idx) {
19313
+ const minX = floor(__privateGet(this, _pendingBBox)[0] * 256 / __privateGet(this, _canvasWidth));
19314
+ const minY = floor(__privateGet(this, _pendingBBox)[1] * 256 / __privateGet(this, _canvasHeight));
19315
+ const maxX = ceil(__privateGet(this, _pendingBBox)[2] * 256 / __privateGet(this, _canvasWidth));
19316
+ const maxY = ceil(__privateGet(this, _pendingBBox)[3] * 256 / __privateGet(this, _canvasHeight));
19317
+ expandBBox(__privateGet(this, _bboxesCoords), idx, minX, minY, maxX, maxY);
19318
+ for (const depIdx of __privateGet(this, _pendingDependencies)) {
19319
+ if (depIdx !== idx) {
19320
+ expandBBox(__privateGet(this, _bboxesCoords), depIdx, minX, minY, maxX, maxY);
19321
+ }
19322
+ }
19323
+ for (const saveIdx of __privateGet(this, _savesStack)) {
19324
+ if (saveIdx !== idx) {
19325
+ expandBBox(__privateGet(this, _bboxesCoords), saveIdx, minX, minY, maxX, maxY);
19326
+ }
19327
+ }
19328
+ for (const saveIdx of __privateGet(this, _markedContentStack)) {
19329
+ if (saveIdx !== idx) {
19330
+ expandBBox(__privateGet(this, _bboxesCoords), saveIdx, minX, minY, maxX, maxY);
19331
+ }
19332
+ }
19333
+ if (!preserve) {
19334
+ __privateGet(this, _pendingDependencies).clear();
19335
+ __privateSet(this, _pendingBBoxIdx, -1);
19336
+ }
18655
19337
  }
18656
- __privateGet(this, _pendingDependencies).clear();
18657
19338
  return this;
18658
19339
  }
18659
- bboxToClipBoxDropOperation(idx) {
18660
- if (__privateGet(this, _pendingBBoxIdx) !== -1) {
19340
+ recordShowTextOperation(idx, preserve = false) {
19341
+ const deps = Array.from(__privateGet(this, _pendingDependencies));
19342
+ this.recordOperation(idx, preserve);
19343
+ this.recordIncrementalData("sameLineText", idx);
19344
+ for (const dep of deps) {
19345
+ this.recordIncrementalData("sameLineText", dep);
19346
+ }
19347
+ return this;
19348
+ }
19349
+ bboxToClipBoxDropOperation(idx, preserve = false) {
19350
+ if (__privateGet(this, _pendingBBoxIdx) === idx) {
18661
19351
  __privateSet(this, _pendingBBoxIdx, -1);
18662
19352
  __privateGet(this, _clipBox)[0] = Math.max(__privateGet(this, _clipBox)[0], __privateGet(this, _pendingBBox)[0]);
18663
19353
  __privateGet(this, _clipBox)[1] = Math.max(__privateGet(this, _clipBox)[1], __privateGet(this, _pendingBBox)[1]);
18664
19354
  __privateGet(this, _clipBox)[2] = Math.min(__privateGet(this, _clipBox)[2], __privateGet(this, _pendingBBox)[2]);
18665
19355
  __privateGet(this, _clipBox)[3] = Math.min(__privateGet(this, _clipBox)[3], __privateGet(this, _pendingBBox)[3]);
19356
+ if (!preserve) {
19357
+ __privateGet(this, _pendingDependencies).clear();
19358
+ }
18666
19359
  }
18667
- __privateGet(this, _pendingDependencies).clear();
18668
19360
  return this;
18669
19361
  }
18670
19362
  _takePendingDependencies() {
@@ -18684,21 +19376,10 @@ var CanvasDependencyTracker = class {
18684
19376
  }
18685
19377
  take() {
18686
19378
  __privateGet(this, _fontBBoxTrustworthy).clear();
18687
- return Array.from(
18688
- __privateGet(this, _operations),
18689
- ([idx, { bbox, pairs, dependencies }]) => {
18690
- pairs.forEach((pair) => pair.forEach(dependencies.add, dependencies));
18691
- dependencies.delete(idx);
18692
- return {
18693
- minX: (bbox?.minX ?? 0) / __privateGet(this, _canvasWidth),
18694
- maxX: (bbox?.maxX ?? __privateGet(this, _canvasWidth)) / __privateGet(this, _canvasWidth),
18695
- minY: (bbox?.minY ?? 0) / __privateGet(this, _canvasHeight),
18696
- maxY: (bbox?.maxY ?? __privateGet(this, _canvasHeight)) / __privateGet(this, _canvasHeight),
18697
- dependencies: Array.from(dependencies).sort((a, b) => a - b),
18698
- idx
18699
- };
18700
- }
18701
- );
19379
+ return new BBoxReader(__privateGet(this, _bboxes2), __privateGet(this, _bboxesCoords));
19380
+ }
19381
+ takeDebugMetadata() {
19382
+ return __privateGet(this, _debugMetadata);
18702
19383
  }
18703
19384
  };
18704
19385
  _simple = new WeakMap();
@@ -18715,22 +19396,40 @@ _operations = new WeakMap();
18715
19396
  _fontBBoxTrustworthy = new WeakMap();
18716
19397
  _canvasWidth = new WeakMap();
18717
19398
  _canvasHeight = new WeakMap();
18718
- var _dependencyTracker, _opIdx, _nestingLevel, _outerDependencies, _savesLevel;
19399
+ _bboxesCoords = new WeakMap();
19400
+ _bboxes2 = new WeakMap();
19401
+ _debugMetadata = new WeakMap();
19402
+ _CanvasDependencyTracker_instances = new WeakSet();
19403
+ initializeBBoxes_fn = function(operationsCount, oldBBoxes) {
19404
+ const buffer = new ArrayBuffer(operationsCount * 4);
19405
+ __privateSet(this, _bboxesCoords, new Uint8ClampedArray(buffer));
19406
+ __privateSet(this, _bboxes2, new Uint32Array(buffer));
19407
+ if (oldBBoxes && oldBBoxes.length > 0) {
19408
+ __privateGet(this, _bboxes2).set(oldBBoxes);
19409
+ __privateGet(this, _bboxes2).fill(EMPTY_BBOX, oldBBoxes.length);
19410
+ } else {
19411
+ __privateGet(this, _bboxes2).fill(EMPTY_BBOX);
19412
+ }
19413
+ };
19414
+ var _dependencyTracker, _opIdx, _ignoreBBoxes, _nestingLevel, _savesLevel;
18719
19415
  var _CanvasNestedDependencyTracker = class _CanvasNestedDependencyTracker {
18720
- constructor(dependencyTracker, opIdx) {
19416
+ constructor(dependencyTracker, opIdx, ignoreBBoxes) {
18721
19417
  /** @type {CanvasDependencyTracker} */
18722
19418
  __privateAdd(this, _dependencyTracker);
18723
19419
  /** @type {number} */
18724
19420
  __privateAdd(this, _opIdx);
19421
+ __privateAdd(this, _ignoreBBoxes);
18725
19422
  __privateAdd(this, _nestingLevel, 0);
18726
- __privateAdd(this, _outerDependencies);
18727
19423
  __privateAdd(this, _savesLevel, 0);
18728
- if (dependencyTracker instanceof _CanvasNestedDependencyTracker) {
19424
+ if (dependencyTracker instanceof _CanvasNestedDependencyTracker && __privateGet(dependencyTracker, _ignoreBBoxes) === !!ignoreBBoxes) {
18729
19425
  return dependencyTracker;
18730
19426
  }
18731
19427
  __privateSet(this, _dependencyTracker, dependencyTracker);
18732
- __privateSet(this, _outerDependencies, dependencyTracker._takePendingDependencies());
18733
19428
  __privateSet(this, _opIdx, opIdx);
19429
+ __privateSet(this, _ignoreBBoxes, !!ignoreBBoxes);
19430
+ }
19431
+ growOperationsCount() {
19432
+ throw new Error("Unreachable");
18734
19433
  }
18735
19434
  save(opIdx) {
18736
19435
  __privateWrapper(this, _savesLevel)._++;
@@ -18796,6 +19495,19 @@ var _CanvasNestedDependencyTracker = class _CanvasNestedDependencyTracker {
18796
19495
  recordNamedData(name, idx) {
18797
19496
  return this;
18798
19497
  }
19498
+ /**
19499
+ * @param {SimpleDependency} name
19500
+ * @param {string} depName
19501
+ * @param {number} fallbackIdx
19502
+ */
19503
+ recordSimpleDataFromNamed(name, depName, fallbackIdx) {
19504
+ __privateGet(this, _dependencyTracker).recordSimpleDataFromNamed(
19505
+ name,
19506
+ depName,
19507
+ __privateGet(this, _opIdx)
19508
+ );
19509
+ return this;
19510
+ }
18799
19511
  // All next operations, until the next .restore(), will depend on this
18800
19512
  recordFutureForcedDependency(name, idx) {
18801
19513
  __privateGet(this, _dependencyTracker).recordFutureForcedDependency(name, __privateGet(this, _opIdx));
@@ -18812,50 +19524,55 @@ var _CanvasNestedDependencyTracker = class _CanvasNestedDependencyTracker {
18812
19524
  return this;
18813
19525
  }
18814
19526
  resetBBox(idx) {
18815
- if (!__privateGet(this, _dependencyTracker).hasPendingBBox) {
19527
+ if (!__privateGet(this, _ignoreBBoxes)) {
18816
19528
  __privateGet(this, _dependencyTracker).resetBBox(__privateGet(this, _opIdx));
18817
19529
  }
18818
19530
  return this;
18819
19531
  }
18820
- get hasPendingBBox() {
18821
- return __privateGet(this, _dependencyTracker).hasPendingBBox;
18822
- }
18823
19532
  recordClipBox(idx, ctx, minX, maxX, minY, maxY) {
18824
- __privateGet(this, _dependencyTracker).recordClipBox(
18825
- __privateGet(this, _opIdx),
18826
- ctx,
18827
- minX,
18828
- maxX,
18829
- minY,
18830
- maxY
18831
- );
19533
+ if (!__privateGet(this, _ignoreBBoxes)) {
19534
+ __privateGet(this, _dependencyTracker).recordClipBox(
19535
+ __privateGet(this, _opIdx),
19536
+ ctx,
19537
+ minX,
19538
+ maxX,
19539
+ minY,
19540
+ maxY
19541
+ );
19542
+ }
18832
19543
  return this;
18833
19544
  }
18834
19545
  recordBBox(idx, ctx, minX, maxX, minY, maxY) {
18835
- __privateGet(this, _dependencyTracker).recordBBox(
18836
- __privateGet(this, _opIdx),
18837
- ctx,
18838
- minX,
18839
- maxX,
18840
- minY,
18841
- maxY
18842
- );
19546
+ if (!__privateGet(this, _ignoreBBoxes)) {
19547
+ __privateGet(this, _dependencyTracker).recordBBox(
19548
+ __privateGet(this, _opIdx),
19549
+ ctx,
19550
+ minX,
19551
+ maxX,
19552
+ minY,
19553
+ maxY
19554
+ );
19555
+ }
18843
19556
  return this;
18844
19557
  }
18845
19558
  recordCharacterBBox(idx, ctx, font, scale, x, y, getMeasure) {
18846
- __privateGet(this, _dependencyTracker).recordCharacterBBox(
18847
- __privateGet(this, _opIdx),
18848
- ctx,
18849
- font,
18850
- scale,
18851
- x,
18852
- y,
18853
- getMeasure
18854
- );
19559
+ if (!__privateGet(this, _ignoreBBoxes)) {
19560
+ __privateGet(this, _dependencyTracker).recordCharacterBBox(
19561
+ __privateGet(this, _opIdx),
19562
+ ctx,
19563
+ font,
19564
+ scale,
19565
+ x,
19566
+ y,
19567
+ getMeasure
19568
+ );
19569
+ }
18855
19570
  return this;
18856
19571
  }
18857
19572
  recordFullPageBBox(idx) {
18858
- __privateGet(this, _dependencyTracker).recordFullPageBBox(__privateGet(this, _opIdx));
19573
+ if (!__privateGet(this, _ignoreBBoxes)) {
19574
+ __privateGet(this, _dependencyTracker).recordFullPageBBox(__privateGet(this, _opIdx));
19575
+ }
18859
19576
  return this;
18860
19577
  }
18861
19578
  getSimpleIndex(dependencyName) {
@@ -18865,13 +19582,6 @@ var _CanvasNestedDependencyTracker = class _CanvasNestedDependencyTracker {
18865
19582
  __privateGet(this, _dependencyTracker).recordDependencies(__privateGet(this, _opIdx), dependencyNames);
18866
19583
  return this;
18867
19584
  }
18868
- copyDependenciesFromIncrementalOperation(idx, name) {
18869
- __privateGet(this, _dependencyTracker).copyDependenciesFromIncrementalOperation(
18870
- __privateGet(this, _opIdx),
18871
- name
18872
- );
18873
- return this;
18874
- }
18875
19585
  recordNamedDependency(idx, name) {
18876
19586
  __privateGet(this, _dependencyTracker).recordNamedDependency(__privateGet(this, _opIdx), name);
18877
19587
  return this;
@@ -18882,29 +19592,29 @@ var _CanvasNestedDependencyTracker = class _CanvasNestedDependencyTracker {
18882
19592
  */
18883
19593
  recordOperation(idx) {
18884
19594
  __privateGet(this, _dependencyTracker).recordOperation(__privateGet(this, _opIdx), true);
18885
- const operation = __privateGet(this, _dependencyTracker)._extractOperation(__privateGet(this, _opIdx));
18886
- for (const depIdx of operation.dependencies) {
18887
- __privateGet(this, _outerDependencies).add(depIdx);
18888
- }
18889
- __privateGet(this, _outerDependencies).delete(__privateGet(this, _opIdx));
18890
- __privateGet(this, _outerDependencies).delete(null);
18891
19595
  return this;
18892
19596
  }
18893
- bboxToClipBoxDropOperation(idx) {
18894
- __privateGet(this, _dependencyTracker).bboxToClipBoxDropOperation(__privateGet(this, _opIdx));
19597
+ recordShowTextOperation(idx) {
19598
+ __privateGet(this, _dependencyTracker).recordShowTextOperation(__privateGet(this, _opIdx), true);
18895
19599
  return this;
18896
19600
  }
18897
- recordNestedDependencies() {
18898
- __privateGet(this, _dependencyTracker)._pushPendingDependencies(__privateGet(this, _outerDependencies));
19601
+ bboxToClipBoxDropOperation(idx) {
19602
+ if (!__privateGet(this, _ignoreBBoxes)) {
19603
+ __privateGet(this, _dependencyTracker).bboxToClipBoxDropOperation(__privateGet(this, _opIdx), true);
19604
+ }
19605
+ return this;
18899
19606
  }
18900
19607
  take() {
18901
19608
  throw new Error("Unreachable");
18902
19609
  }
19610
+ takeDebugMetadata() {
19611
+ throw new Error("Unreachable");
19612
+ }
18903
19613
  };
18904
19614
  _dependencyTracker = new WeakMap();
18905
19615
  _opIdx = new WeakMap();
19616
+ _ignoreBBoxes = new WeakMap();
18906
19617
  _nestingLevel = new WeakMap();
18907
- _outerDependencies = new WeakMap();
18908
19618
  _savesLevel = new WeakMap();
18909
19619
  var CanvasNestedDependencyTracker = _CanvasNestedDependencyTracker;
18910
19620
  var Dependencies = {
@@ -18948,14 +19658,15 @@ var Dependencies = {
18948
19658
  "moveText",
18949
19659
  "textMatrix",
18950
19660
  "font",
19661
+ "fontObj",
18951
19662
  "filter",
18952
19663
  "fillColor",
18953
19664
  "textRenderingMode",
18954
19665
  "SMask",
18955
19666
  "fillAlpha",
18956
19667
  "strokeAlpha",
18957
- "globalCompositeOperation"
18958
- // TODO: More
19668
+ "globalCompositeOperation",
19669
+ "sameLineText"
18959
19670
  ],
18960
19671
  transform: ["transform"],
18961
19672
  transformAndFill: ["transform", "fillColor"]
@@ -19354,7 +20065,7 @@ var _TilingPattern = class _TilingPattern {
19354
20065
  this.canvasGraphicsFactory = canvasGraphicsFactory;
19355
20066
  this.baseTransform = baseTransform;
19356
20067
  }
19357
- createPatternCanvas(owner) {
20068
+ createPatternCanvas(owner, opIdx) {
19358
20069
  const {
19359
20070
  bbox,
19360
20071
  operatorList,
@@ -19407,7 +20118,7 @@ var _TilingPattern = class _TilingPattern {
19407
20118
  dimy.size
19408
20119
  );
19409
20120
  const tmpCtx = tmpCanvas.context;
19410
- const graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
20121
+ const graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx, opIdx);
19411
20122
  graphics.groupLevel = owner.groupLevel;
19412
20123
  this.setFillAndStrokeStyleToContext(graphics, paintType, color);
19413
20124
  tmpCtx.translate(-dimx.scale * x0, -dimy.scale * y0);
@@ -19430,7 +20141,7 @@ var _TilingPattern = class _TilingPattern {
19430
20141
  graphics.baseTransform = getCurrentTransform(graphics.ctx);
19431
20142
  graphics.executeOperatorList(operatorList);
19432
20143
  graphics.endDrawing();
19433
- graphics.dependencyTracker?.restore().recordNestedDependencies?.();
20144
+ graphics.dependencyTracker?.restore();
19434
20145
  tmpCtx.restore();
19435
20146
  if (redrawHorizontally || redrawVertically) {
19436
20147
  const image = tmpCanvas.canvas;
@@ -19532,7 +20243,7 @@ var _TilingPattern = class _TilingPattern {
19532
20243
  isModifyingCurrentTransform() {
19533
20244
  return false;
19534
20245
  }
19535
- getPattern(ctx, owner, inverse, pathType) {
20246
+ getPattern(ctx, owner, inverse, pathType, opIdx) {
19536
20247
  let matrix = inverse;
19537
20248
  if (pathType !== PathType.SHADING) {
19538
20249
  matrix = Util.transform(matrix, owner.baseTransform);
@@ -19540,7 +20251,7 @@ var _TilingPattern = class _TilingPattern {
19540
20251
  matrix = Util.transform(matrix, this.matrix);
19541
20252
  }
19542
20253
  }
19543
- const temporaryPatternCanvas = this.createPatternCanvas(owner);
20254
+ const temporaryPatternCanvas = this.createPatternCanvas(owner, opIdx);
19544
20255
  let domMatrix = new DOMMatrix(matrix);
19545
20256
  domMatrix = domMatrix.translate(
19546
20257
  temporaryPatternCanvas.offsetX,
@@ -20067,7 +20778,7 @@ var _CanvasGraphics = class _CanvasGraphics {
20067
20778
  this.viewportScale = viewport.scale;
20068
20779
  this.baseTransform = getCurrentTransform(this.ctx);
20069
20780
  }
20070
- executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper, filteredOperationIndexes) {
20781
+ executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper, operationsFilter) {
20071
20782
  const argsArray = operatorList.argsArray;
20072
20783
  const fnArray = operatorList.fnArray;
20073
20784
  let i = executionStartIdx || 0;
@@ -20086,7 +20797,7 @@ var _CanvasGraphics = class _CanvasGraphics {
20086
20797
  stepper.breakIt(i, continueCallback);
20087
20798
  return i;
20088
20799
  }
20089
- if (!filteredOperationIndexes || filteredOperationIndexes.has(i)) {
20800
+ if (!operationsFilter || operationsFilter(i)) {
20090
20801
  fnId = fnArray[i];
20091
20802
  fnArgs = argsArray[i] ?? null;
20092
20803
  if (fnId !== OPS.dependency) {
@@ -20287,7 +20998,7 @@ var _CanvasGraphics = class _CanvasGraphics {
20287
20998
  -offsetX,
20288
20999
  -offsetY
20289
21000
  ]);
20290
- fillCtx.fillStyle = isPatternFill ? fillColor.getPattern(ctx, this, inverse, PathType.FILL) : fillColor;
21001
+ fillCtx.fillStyle = isPatternFill ? fillColor.getPattern(ctx, this, inverse, PathType.FILL, opIdx) : fillColor;
20291
21002
  fillCtx.fillRect(0, 0, width, height);
20292
21003
  if (cache && !isPatternFill) {
20293
21004
  this.cachedCanvases.delete("fillCanvas");
@@ -20650,7 +21361,8 @@ var _CanvasGraphics = class _CanvasGraphics {
20650
21361
  ctx,
20651
21362
  this,
20652
21363
  getCurrentTransformInverse(ctx),
20653
- PathType.STROKE
21364
+ PathType.STROKE,
21365
+ opIdx
20654
21366
  );
20655
21367
  if (baseTransform) {
20656
21368
  const newPath = new SvgPath2D();
@@ -20703,7 +21415,8 @@ var _CanvasGraphics = class _CanvasGraphics {
20703
21415
  ctx,
20704
21416
  this,
20705
21417
  getCurrentTransformInverse(ctx),
20706
- PathType.FILL
21418
+ PathType.FILL,
21419
+ opIdx
20707
21420
  );
20708
21421
  if (baseTransform) {
20709
21422
  const newPath = new SvgPath2D();
@@ -20823,7 +21536,7 @@ var _CanvasGraphics = class _CanvasGraphics {
20823
21536
  this.current.leading = -leading;
20824
21537
  }
20825
21538
  setFont(opIdx, fontRefName, size) {
20826
- this.dependencyTracker?.recordSimpleData("font", opIdx).recordNamedDependency(opIdx, fontRefName);
21539
+ this.dependencyTracker?.recordSimpleData("font", opIdx).recordSimpleDataFromNamed("fontObj", fontRefName, opIdx);
20827
21540
  const fontObj = this.commonObjs.get(fontRefName);
20828
21541
  const current = this.current;
20829
21542
  if (!fontObj) {
@@ -21017,7 +21730,7 @@ var _CanvasGraphics = class _CanvasGraphics {
21017
21730
  }
21018
21731
  showText(opIdx, glyphs) {
21019
21732
  if (this.dependencyTracker) {
21020
- this.dependencyTracker.recordDependencies(opIdx, Dependencies.showText).copyDependenciesFromIncrementalOperation(opIdx, "sameLineText").resetBBox(opIdx);
21733
+ this.dependencyTracker.recordDependencies(opIdx, Dependencies.showText).resetBBox(opIdx);
21021
21734
  if (this.current.textRenderingMode & TextRenderingMode.ADD_TO_PATH_FLAG) {
21022
21735
  this.dependencyTracker.recordFutureForcedDependency("textClip", opIdx).inheritPendingDependenciesAsFutureForcedDependencies();
21023
21736
  }
@@ -21026,7 +21739,7 @@ var _CanvasGraphics = class _CanvasGraphics {
21026
21739
  const font = current.font;
21027
21740
  if (font.isType3Font) {
21028
21741
  this.showType3Text(opIdx, glyphs);
21029
- this.dependencyTracker?.recordOperation(opIdx).recordIncrementalData("sameLineText", opIdx);
21742
+ this.dependencyTracker?.recordShowTextOperation(opIdx);
21030
21743
  return void 0;
21031
21744
  }
21032
21745
  const fontSize = current.fontSize;
@@ -21063,7 +21776,8 @@ var _CanvasGraphics = class _CanvasGraphics {
21063
21776
  ctx,
21064
21777
  this,
21065
21778
  getCurrentTransformInverse(ctx),
21066
- PathType.FILL
21779
+ PathType.FILL,
21780
+ opIdx
21067
21781
  );
21068
21782
  patternFillTransform = getCurrentTransform(ctx);
21069
21783
  ctx.restore();
@@ -21075,7 +21789,8 @@ var _CanvasGraphics = class _CanvasGraphics {
21075
21789
  ctx,
21076
21790
  this,
21077
21791
  getCurrentTransformInverse(ctx),
21078
- PathType.STROKE
21792
+ PathType.STROKE,
21793
+ opIdx
21079
21794
  );
21080
21795
  patternStrokeTransform = getCurrentTransform(ctx);
21081
21796
  ctx.restore();
@@ -21114,7 +21829,7 @@ var _CanvasGraphics = class _CanvasGraphics {
21114
21829
  measure.actualBoundingBoxRight,
21115
21830
  -measure.actualBoundingBoxAscent,
21116
21831
  measure.actualBoundingBoxDescent
21117
- ).recordOperation(opIdx).recordIncrementalData("sameLineText", opIdx);
21832
+ ).recordShowTextOperation(opIdx);
21118
21833
  }
21119
21834
  current.x += width * widthAdvanceScale * textHScale;
21120
21835
  ctx.restore();
@@ -21208,7 +21923,7 @@ var _CanvasGraphics = class _CanvasGraphics {
21208
21923
  }
21209
21924
  ctx.restore();
21210
21925
  this.compose();
21211
- this.dependencyTracker?.recordOperation(opIdx).recordIncrementalData("sameLineText", opIdx);
21926
+ this.dependencyTracker?.recordShowTextOperation(opIdx);
21212
21927
  return void 0;
21213
21928
  }
21214
21929
  showType3Text(opIdx, glyphs) {
@@ -21265,7 +21980,6 @@ var _CanvasGraphics = class _CanvasGraphics {
21265
21980
  }
21266
21981
  ctx.restore();
21267
21982
  if (dependencyTracker) {
21268
- this.dependencyTracker.recordNestedDependencies();
21269
21983
  this.dependencyTracker = dependencyTracker;
21270
21984
  }
21271
21985
  }
@@ -21285,7 +21999,7 @@ var _CanvasGraphics = class _CanvasGraphics {
21285
21999
  if (IR[0] === "TilingPattern") {
21286
22000
  const baseTransform = this.baseTransform || getCurrentTransform(this.ctx);
21287
22001
  const canvasGraphicsFactory = {
21288
- createCanvasGraphics: (ctx) => new _CanvasGraphics(
22002
+ createCanvasGraphics: (ctx, renderingOpIdx) => new _CanvasGraphics(
21289
22003
  ctx,
21290
22004
  this.commonObjs,
21291
22005
  this.objs,
@@ -21297,7 +22011,12 @@ var _CanvasGraphics = class _CanvasGraphics {
21297
22011
  },
21298
22012
  void 0,
21299
22013
  void 0,
21300
- this.dependencyTracker ? new CanvasNestedDependencyTracker(this.dependencyTracker, opIdx) : null
22014
+ this.dependencyTracker ? new CanvasNestedDependencyTracker(
22015
+ this.dependencyTracker,
22016
+ renderingOpIdx,
22017
+ /* ignoreBBoxes */
22018
+ true
22019
+ ) : null
21301
22020
  )
21302
22021
  };
21303
22022
  pattern = new TilingPattern(
@@ -21365,7 +22084,8 @@ var _CanvasGraphics = class _CanvasGraphics {
21365
22084
  ctx,
21366
22085
  this,
21367
22086
  getCurrentTransformInverse(ctx),
21368
- PathType.SHADING
22087
+ PathType.SHADING,
22088
+ opIdx
21369
22089
  );
21370
22090
  const inv = getCurrentTransformInverse(ctx);
21371
22091
  if (inv) {
@@ -21702,7 +22422,8 @@ var _CanvasGraphics = class _CanvasGraphics {
21702
22422
  maskCtx,
21703
22423
  this,
21704
22424
  getCurrentTransformInverse(ctx),
21705
- PathType.FILL
22425
+ PathType.FILL,
22426
+ opIdx
21706
22427
  ) : fillColor;
21707
22428
  maskCtx.fillRect(0, 0, width, height);
21708
22429
  maskCtx.restore();
@@ -24197,64 +24918,6 @@ __privateAdd(_TextLayer, _minFontSize, null);
24197
24918
  __privateAdd(_TextLayer, _pendingTextLayers, /* @__PURE__ */ new Set());
24198
24919
  var TextLayer = _TextLayer;
24199
24920
 
24200
- // src/pdf.js/src/display/xfa_text.js
24201
- var XfaText = class _XfaText {
24202
- /**
24203
- * Walk an XFA tree and create an array of text nodes that is compatible
24204
- * with a regular PDFs TextContent. Currently, only TextItem.str is supported,
24205
- * all other fields and styles haven't been implemented.
24206
- *
24207
- * @param {Object} xfa - An XFA fake DOM object.
24208
- *
24209
- * @returns {TextContent}
24210
- */
24211
- static textContent(xfa) {
24212
- const items = [];
24213
- const output = {
24214
- items,
24215
- styles: /* @__PURE__ */ Object.create(null)
24216
- };
24217
- function walk(node) {
24218
- if (!node) {
24219
- return;
24220
- }
24221
- let str = null;
24222
- const name = node.name;
24223
- if (name === "#text") {
24224
- str = node.value;
24225
- } else if (!_XfaText.shouldBuildText(name)) {
24226
- return;
24227
- } else if (node?.attributes?.textContent) {
24228
- str = node.attributes.textContent;
24229
- } else if (node.value) {
24230
- str = node.value;
24231
- }
24232
- if (str !== null) {
24233
- items.push({
24234
- str
24235
- });
24236
- }
24237
- if (!node.children) {
24238
- return;
24239
- }
24240
- for (const child of node.children) {
24241
- walk(child);
24242
- }
24243
- }
24244
- walk(xfa);
24245
- return output;
24246
- }
24247
- /**
24248
- * @param {string} name - DOM node name. (lower case)
24249
- *
24250
- * @returns {boolean} true if the DOM node should have a corresponding text
24251
- * node.
24252
- */
24253
- static shouldBuildText(name) {
24254
- return !(name === "textarea" || name === "input" || name === "option" || name === "select");
24255
- }
24256
- };
24257
-
24258
24921
  // src/pdf.js/src/display/api.js
24259
24922
  var RENDERING_CANCELLED_TIMEOUT = 100;
24260
24923
  function getDocument(src = {}) {
@@ -24614,9 +25277,6 @@ var PDFDocumentProxy = class {
24614
25277
  Object.defineProperty(this, "getXFADatasets", {
24615
25278
  value: () => this._transport.getXFADatasets()
24616
25279
  });
24617
- Object.defineProperty(this, "getXRefPrevValue", {
24618
- value: () => this._transport.getXRefPrevValue()
24619
- });
24620
25280
  Object.defineProperty(this, "getStartXRefPos", {
24621
25281
  value: () => this._transport.getStartXRefPos()
24622
25282
  });
@@ -24946,7 +25606,7 @@ var PDFPageProxy = class {
24946
25606
  this.objs = new PDFObjects();
24947
25607
  this._intentStates = /* @__PURE__ */ new Map();
24948
25608
  this.destroyed = false;
24949
- this.recordedGroups = null;
25609
+ this.recordedBBoxes = null;
24950
25610
  }
24951
25611
  /**
24952
25612
  * @type {number} Page number of the page. First page is 1.
@@ -25059,7 +25719,7 @@ var PDFPageProxy = class {
25059
25719
  printAnnotationStorage = null,
25060
25720
  isEditing = false,
25061
25721
  recordOperations = false,
25062
- filteredOperationIndexes = null
25722
+ operationsFilter = null
25063
25723
  }) {
25064
25724
  this._stats?.time("Overall");
25065
25725
  const intentArgs = this._transport.getRenderingIntent(
@@ -25092,18 +25752,24 @@ var PDFPageProxy = class {
25092
25752
  this._stats?.time("Page Request");
25093
25753
  this._pumpOperatorList(intentArgs);
25094
25754
  }
25095
- const shouldRecordOperations = !this.recordedGroups && (recordOperations || this._pdfBug && globalThis.StepperManager?.enabled);
25755
+ const recordForDebugger = Boolean(
25756
+ this._pdfBug && globalThis.StepperManager?.enabled
25757
+ );
25758
+ const shouldRecordOperations = !this.recordedBBoxes && (recordOperations || recordForDebugger);
25096
25759
  const complete = (error) => {
25097
25760
  intentState.renderTasks.delete(internalRenderTask);
25098
25761
  if (shouldRecordOperations) {
25099
- const recordedGroups = internalRenderTask.gfx?.dependencyTracker.take();
25100
- if (recordedGroups) {
25101
- internalRenderTask.stepper?.setOperatorGroups(recordedGroups);
25762
+ const recordedBBoxes = internalRenderTask.gfx?.dependencyTracker.take();
25763
+ if (recordedBBoxes) {
25764
+ if (internalRenderTask.stepper) {
25765
+ internalRenderTask.stepper.setOperatorBBoxes(
25766
+ recordedBBoxes,
25767
+ internalRenderTask.gfx.dependencyTracker.takeDebugMetadata()
25768
+ );
25769
+ }
25102
25770
  if (recordOperations) {
25103
- this.recordedGroups = recordedGroups;
25771
+ this.recordedBBoxes = recordedBBoxes;
25104
25772
  }
25105
- } else if (recordOperations) {
25106
- this.recordedGroups = [];
25107
25773
  }
25108
25774
  }
25109
25775
  if (intentPrint) {
@@ -25133,7 +25799,11 @@ var PDFPageProxy = class {
25133
25799
  params: {
25134
25800
  canvas,
25135
25801
  canvasContext,
25136
- dependencyTracker: shouldRecordOperations ? new CanvasDependencyTracker(canvas) : null,
25802
+ dependencyTracker: shouldRecordOperations ? new CanvasDependencyTracker(
25803
+ canvas,
25804
+ intentState.operatorList.length,
25805
+ recordForDebugger
25806
+ ) : null,
25137
25807
  viewport,
25138
25808
  transform,
25139
25809
  background
@@ -25149,7 +25819,7 @@ var PDFPageProxy = class {
25149
25819
  pdfBug: this._pdfBug,
25150
25820
  pageColors,
25151
25821
  enableHWA: this._transport.enableHWA,
25152
- filteredOperationIndexes
25822
+ operationsFilter
25153
25823
  });
25154
25824
  (intentState.renderTasks || (intentState.renderTasks = /* @__PURE__ */ new Set())).add(internalRenderTask);
25155
25825
  const renderTask = internalRenderTask.task;
@@ -26061,11 +26731,17 @@ var WorkerTransport = class {
26061
26731
  this.commonObjs.resolve(id2, exportedError);
26062
26732
  break;
26063
26733
  }
26734
+ const fontData = new FontInfo(exportedData);
26064
26735
  const inspectFont = this._params.pdfBug && globalThis.FontInspector?.enabled ? (font2, url) => globalThis.FontInspector.fontAdded(font2, url) : null;
26065
- const font = new FontFaceObject(exportedData, inspectFont);
26736
+ const font = new FontFaceObject(
26737
+ fontData,
26738
+ inspectFont,
26739
+ exportedData.extra,
26740
+ exportedData.charProcOperatorList
26741
+ );
26066
26742
  this.fontLoader.bind(font).catch(() => messageHandler.sendWithPromise("FontFallback", { id: id2 })).finally(() => {
26067
26743
  if (!font.fontExtraProperties && font.data) {
26068
- font.data = null;
26744
+ font.clearData();
26069
26745
  }
26070
26746
  this.commonObjs.resolve(id2, font);
26071
26747
  });
@@ -26419,7 +27095,7 @@ var _InternalRenderTask = class _InternalRenderTask {
26419
27095
  pdfBug = false,
26420
27096
  pageColors = null,
26421
27097
  enableHWA = false,
26422
- filteredOperationIndexes = null
27098
+ operationsFilter = null
26423
27099
  }) {
26424
27100
  __privateAdd(this, _rAF, null);
26425
27101
  this.callback = callback;
@@ -26449,7 +27125,7 @@ var _InternalRenderTask = class _InternalRenderTask {
26449
27125
  this._canvasContext = params.canvas ? null : params.canvasContext;
26450
27126
  this._enableHWA = enableHWA;
26451
27127
  this._dependencyTracker = params.dependencyTracker;
26452
- this._filteredOperationIndexes = filteredOperationIndexes;
27128
+ this._operationsFilter = operationsFilter;
26453
27129
  }
26454
27130
  get completed() {
26455
27131
  return this.capability.promise.catch(function() {
@@ -26519,6 +27195,9 @@ var _InternalRenderTask = class _InternalRenderTask {
26519
27195
  this.graphicsReadyCallback || (this.graphicsReadyCallback = this._continueBound);
26520
27196
  return;
26521
27197
  }
27198
+ this.gfx.dependencyTracker?.growOperationsCount(
27199
+ this.operatorList.fnArray.length
27200
+ );
26522
27201
  this.stepper?.updateOperatorList(this.operatorList);
26523
27202
  if (this.running) {
26524
27203
  return;
@@ -26555,7 +27234,7 @@ var _InternalRenderTask = class _InternalRenderTask {
26555
27234
  this.operatorListIdx,
26556
27235
  this._continueBound,
26557
27236
  this.stepper,
26558
- this._filteredOperationIndexes
27237
+ this._operationsFilter
26559
27238
  );
26560
27239
  if (this.operatorListIdx === this.operatorList.argsArray.length) {
26561
27240
  this.running = false;
@@ -26925,212 +27604,6 @@ var DOMSVGFactory = class extends BaseSVGFactory {
26925
27604
  }
26926
27605
  };
26927
27606
 
26928
- // src/pdf.js/src/display/xfa_layer.js
26929
- var XfaLayer = class {
26930
- static setupStorage(html, id2, element, storage, intent) {
26931
- const storedData = storage.getValue(id2, { value: null });
26932
- switch (element.name) {
26933
- case "textarea":
26934
- if (storedData.value !== null) {
26935
- html.textContent = storedData.value;
26936
- }
26937
- if (intent === "print") {
26938
- break;
26939
- }
26940
- html.addEventListener("input", (event) => {
26941
- storage.setValue(id2, { value: event.target.value });
26942
- });
26943
- break;
26944
- case "input":
26945
- if (element.attributes.type === "radio" || element.attributes.type === "checkbox") {
26946
- if (storedData.value === element.attributes.xfaOn) {
26947
- html.setAttribute("checked", true);
26948
- } else if (storedData.value === element.attributes.xfaOff) {
26949
- html.removeAttribute("checked");
26950
- }
26951
- if (intent === "print") {
26952
- break;
26953
- }
26954
- html.addEventListener("change", (event) => {
26955
- storage.setValue(id2, {
26956
- value: event.target.checked ? event.target.getAttribute("xfaOn") : event.target.getAttribute("xfaOff")
26957
- });
26958
- });
26959
- } else {
26960
- if (storedData.value !== null) {
26961
- html.setAttribute("value", storedData.value);
26962
- }
26963
- if (intent === "print") {
26964
- break;
26965
- }
26966
- html.addEventListener("input", (event) => {
26967
- storage.setValue(id2, { value: event.target.value });
26968
- });
26969
- }
26970
- break;
26971
- case "select":
26972
- if (storedData.value !== null) {
26973
- html.setAttribute("value", storedData.value);
26974
- for (const option of element.children) {
26975
- if (option.attributes.value === storedData.value) {
26976
- option.attributes.selected = true;
26977
- } else if (option.attributes.hasOwnProperty("selected")) {
26978
- delete option.attributes.selected;
26979
- }
26980
- }
26981
- }
26982
- html.addEventListener("input", (event) => {
26983
- const options = event.target.options;
26984
- const value = options.selectedIndex === -1 ? "" : options[options.selectedIndex].value;
26985
- storage.setValue(id2, { value });
26986
- });
26987
- break;
26988
- }
26989
- }
26990
- static setAttributes({ html, element, storage = null, intent, linkService }) {
26991
- const { attributes } = element;
26992
- const isHTMLAnchorElement = html instanceof HTMLAnchorElement;
26993
- if (attributes.type === "radio") {
26994
- attributes.name = `${attributes.name}-${intent}`;
26995
- }
26996
- for (const [key, value] of Object.entries(attributes)) {
26997
- if (value === null || value === void 0) {
26998
- continue;
26999
- }
27000
- switch (key) {
27001
- case "class":
27002
- if (value.length) {
27003
- html.setAttribute(key, value.join(" "));
27004
- }
27005
- break;
27006
- case "dataId":
27007
- break;
27008
- case "id":
27009
- html.setAttribute("data-element-id", value);
27010
- break;
27011
- case "style":
27012
- Object.assign(html.style, value);
27013
- break;
27014
- case "textContent":
27015
- html.textContent = value;
27016
- break;
27017
- default:
27018
- if (!isHTMLAnchorElement || key !== "href" && key !== "newWindow") {
27019
- html.setAttribute(key, value);
27020
- }
27021
- }
27022
- }
27023
- if (isHTMLAnchorElement) {
27024
- linkService.addLinkAttributes(
27025
- html,
27026
- attributes.href,
27027
- attributes.newWindow
27028
- );
27029
- }
27030
- if (storage && attributes.dataId) {
27031
- this.setupStorage(html, attributes.dataId, element, storage);
27032
- }
27033
- }
27034
- /**
27035
- * Render the XFA layer.
27036
- *
27037
- * @param {XfaLayerParameters} parameters
27038
- */
27039
- static render(parameters) {
27040
- const storage = parameters.annotationStorage;
27041
- const linkService = parameters.linkService;
27042
- const root = parameters.xfaHtml;
27043
- const intent = parameters.intent || "display";
27044
- const rootHtml = document.createElement(root.name);
27045
- if (root.attributes) {
27046
- this.setAttributes({
27047
- html: rootHtml,
27048
- element: root,
27049
- intent,
27050
- linkService
27051
- });
27052
- }
27053
- const isNotForRichText = intent !== "richText";
27054
- const rootDiv = parameters.div;
27055
- rootDiv.append(rootHtml);
27056
- if (parameters.viewport) {
27057
- const transform = `matrix(${parameters.viewport.transform.join(",")})`;
27058
- rootDiv.style.transform = transform;
27059
- }
27060
- if (isNotForRichText) {
27061
- rootDiv.setAttribute("class", "xfaLayer xfaFont");
27062
- }
27063
- const textDivs = [];
27064
- if (root.children.length === 0) {
27065
- if (root.value) {
27066
- const node = document.createTextNode(root.value);
27067
- rootHtml.append(node);
27068
- if (isNotForRichText && XfaText.shouldBuildText(root.name)) {
27069
- textDivs.push(node);
27070
- }
27071
- }
27072
- return { textDivs };
27073
- }
27074
- const stack = [[root, -1, rootHtml]];
27075
- while (stack.length > 0) {
27076
- const [parent, i, html] = stack.at(-1);
27077
- if (i + 1 === parent.children.length) {
27078
- stack.pop();
27079
- continue;
27080
- }
27081
- const child = parent.children[++stack.at(-1)[1]];
27082
- if (child === null) {
27083
- continue;
27084
- }
27085
- const { name } = child;
27086
- if (name === "#text") {
27087
- const node = document.createTextNode(child.value);
27088
- textDivs.push(node);
27089
- html.append(node);
27090
- continue;
27091
- }
27092
- const childHtml = child?.attributes?.xmlns ? document.createElementNS(child.attributes.xmlns, name) : document.createElement(name);
27093
- html.append(childHtml);
27094
- if (child.attributes) {
27095
- this.setAttributes({
27096
- html: childHtml,
27097
- element: child,
27098
- storage,
27099
- intent,
27100
- linkService
27101
- });
27102
- }
27103
- if (child.children?.length > 0) {
27104
- stack.push([child, -1, childHtml]);
27105
- } else if (child.value) {
27106
- const node = document.createTextNode(child.value);
27107
- if (isNotForRichText && XfaText.shouldBuildText(name)) {
27108
- textDivs.push(node);
27109
- }
27110
- childHtml.append(node);
27111
- }
27112
- }
27113
- for (const el of rootDiv.querySelectorAll(
27114
- ".xfaNonInteractive input, .xfaNonInteractive textarea"
27115
- )) {
27116
- el.setAttribute("readOnly", true);
27117
- }
27118
- return {
27119
- textDivs
27120
- };
27121
- }
27122
- /**
27123
- * Update the XFA layer.
27124
- *
27125
- * @param {XfaLayerParameters} parameters
27126
- */
27127
- static update(parameters) {
27128
- const transform = `matrix(${parameters.viewport.transform.join(",")})`;
27129
- parameters.div.style.transform = transform;
27130
- parameters.div.hidden = false;
27131
- }
27132
- };
27133
-
27134
27607
  // src/pdf.js/src/display/annotation_layer.js
27135
27608
  var DEFAULT_FONT_SIZE2 = 9;
27136
27609
  var GetElementsByNameSet = /* @__PURE__ */ new WeakSet();
@@ -27200,7 +27673,7 @@ var AnnotationElementFactory = class {
27200
27673
  }
27201
27674
  }
27202
27675
  };
27203
- var _updates, _hasBorder, _popupElement, _AnnotationElement_instances, changeLightness_fn, setRectEdited_fn;
27676
+ var _updates, _hasBorder, _popupElement, _AnnotationElement_instances, setRectEdited_fn;
27204
27677
  var _AnnotationElement = class _AnnotationElement {
27205
27678
  constructor(parameters, {
27206
27679
  isRenderable = false,
@@ -27239,13 +27712,25 @@ var _AnnotationElement = class _AnnotationElement {
27239
27712
  return this.data.isEditable;
27240
27713
  }
27241
27714
  get hasPopupData() {
27242
- return _AnnotationElement._hasPopupData(this.data);
27715
+ return _AnnotationElement._hasPopupData(this.data) || this.enableComment && !!this.commentText;
27716
+ }
27717
+ get commentData() {
27718
+ const { data } = this;
27719
+ const editor = this.annotationStorage?.getEditor(data.id);
27720
+ if (editor) {
27721
+ return editor.getData();
27722
+ }
27723
+ return data;
27243
27724
  }
27244
27725
  get hasCommentButton() {
27245
- return this.enableComment && this._isEditable && this.hasPopupElement;
27726
+ return this.enableComment && this.hasPopupElement;
27246
27727
  }
27247
27728
  get commentButtonPosition() {
27248
- const { quadPoints, rect } = this.data;
27729
+ const editor = this.annotationStorage?.getEditor(this.data.id);
27730
+ if (editor) {
27731
+ return editor.commentButtonPositionInPage;
27732
+ }
27733
+ const { quadPoints, inkLists, rect } = this.data;
27249
27734
  let maxX = -Infinity;
27250
27735
  let maxY = -Infinity;
27251
27736
  if (quadPoints?.length >= 8) {
@@ -27259,20 +27744,26 @@ var _AnnotationElement = class _AnnotationElement {
27259
27744
  }
27260
27745
  return [maxX, maxY];
27261
27746
  }
27747
+ if (inkLists?.length >= 1) {
27748
+ for (const inkList of inkLists) {
27749
+ for (let i = 0, ii = inkList.length; i < ii; i += 2) {
27750
+ if (inkList[i + 1] > maxY) {
27751
+ maxY = inkList[i + 1];
27752
+ maxX = inkList[i];
27753
+ } else if (inkList[i + 1] === maxY) {
27754
+ maxX = Math.max(maxX, inkList[i]);
27755
+ }
27756
+ }
27757
+ }
27758
+ if (maxX !== Infinity) {
27759
+ return [maxX, maxY];
27760
+ }
27761
+ }
27262
27762
  if (rect) {
27263
27763
  return [rect[2], rect[3]];
27264
27764
  }
27265
27765
  return null;
27266
27766
  }
27267
- get commentButtonColor() {
27268
- if (!this.data.color) {
27269
- return null;
27270
- }
27271
- const [r, g, b] = this.data.color;
27272
- const opacity = this.data.opacity ?? 1;
27273
- const oppositeOpacity = 255 * (1 - opacity);
27274
- return __privateMethod(this, _AnnotationElement_instances, changeLightness_fn).call(this, Math.min(r + oppositeOpacity, 255), Math.min(g + oppositeOpacity, 255), Math.min(b + oppositeOpacity, 255));
27275
- }
27276
27767
  _normalizePoint(point) {
27277
27768
  const {
27278
27769
  page: { view },
@@ -27285,6 +27776,31 @@ var _AnnotationElement = class _AnnotationElement {
27285
27776
  point[1] = 100 * (point[1] - pageY) / pageHeight;
27286
27777
  return point;
27287
27778
  }
27779
+ get commentText() {
27780
+ const { data } = this;
27781
+ return this.annotationStorage.getRawValue(`${AnnotationEditorPrefix}${data.id}`)?.popup?.contents || data.contentsObj?.str || "";
27782
+ }
27783
+ set commentText(text) {
27784
+ const { data } = this;
27785
+ const popup = { deleted: !text, contents: text || "" };
27786
+ if (!this.annotationStorage.updateEditor(data.id, { popup })) {
27787
+ this.annotationStorage.setValue(`${AnnotationEditorPrefix}${data.id}`, {
27788
+ id: data.id,
27789
+ annotationType: data.annotationType,
27790
+ pageIndex: this.parent.page._pageIndex,
27791
+ popup,
27792
+ popupRef: data.popupRef,
27793
+ modificationDate: /* @__PURE__ */ new Date()
27794
+ });
27795
+ }
27796
+ if (!text) {
27797
+ this.removePopup();
27798
+ }
27799
+ }
27800
+ removePopup() {
27801
+ (__privateGet(this, _popupElement)?.popup || this.popup)?.remove();
27802
+ __privateSet(this, _popupElement, this.popup = null);
27803
+ }
27288
27804
  updateEdited(params) {
27289
27805
  if (!this.container) {
27290
27806
  return;
@@ -27650,11 +28166,16 @@ var _AnnotationElement = class _AnnotationElement {
27650
28166
  parent: this.parent,
27651
28167
  elements: [this]
27652
28168
  }));
27653
- this.parent.div.append(popup.render());
28169
+ if (!this.parent._commentManager) {
28170
+ this.parent.div.append(popup.render());
28171
+ }
27654
28172
  }
27655
28173
  get hasPopupElement() {
27656
28174
  return !!(__privateGet(this, _popupElement) || this.popup || this.data.popupRef);
27657
28175
  }
28176
+ get extraPopupElement() {
28177
+ return __privateGet(this, _popupElement);
28178
+ }
27658
28179
  /**
27659
28180
  * Render the annotation's HTML element(s).
27660
28181
  *
@@ -27767,30 +28288,6 @@ _updates = new WeakMap();
27767
28288
  _hasBorder = new WeakMap();
27768
28289
  _popupElement = new WeakMap();
27769
28290
  _AnnotationElement_instances = new WeakSet();
27770
- changeLightness_fn = function(r, g, b) {
27771
- r /= 255;
27772
- g /= 255;
27773
- b /= 255;
27774
- const max = Math.max(r, g, b);
27775
- const min = Math.min(r, g, b);
27776
- const l = (max + min) / 2;
27777
- const newL = ((1 + Math.sqrt(l)) / 2 * 100).toFixed(2);
27778
- if (max === min) {
27779
- return `hsl(0, 0%, ${newL}%)`;
27780
- }
27781
- const d = max - min;
27782
- let h;
27783
- if (max === r) {
27784
- h = (g - b) / d + (g < b ? 6 : 0);
27785
- } else if (max === g) {
27786
- h = (b - r) / d + 2;
27787
- } else {
27788
- h = (r - g) / d + 4;
27789
- }
27790
- h = (h * 60).toFixed(2);
27791
- const s = (d / (1 - Math.abs(2 * l - 1)) * 100).toFixed(2);
27792
- return `hsl(${h}, ${s}%, ${newL}%)`;
27793
- };
27794
28291
  setRectEdited_fn = function(rect) {
27795
28292
  const {
27796
28293
  container: { style },
@@ -27814,6 +28311,47 @@ setRectEdited_fn = function(rect) {
27814
28311
  }
27815
28312
  };
27816
28313
  var AnnotationElement = _AnnotationElement;
28314
+ var EditorAnnotationElement = class extends AnnotationElement {
28315
+ constructor(parameters) {
28316
+ super(parameters, { isRenderable: true, ignoreBorder: true });
28317
+ this.editor = parameters.editor;
28318
+ }
28319
+ render() {
28320
+ this.container.className = "editorAnnotation";
28321
+ return this.container;
28322
+ }
28323
+ createOrUpdatePopup() {
28324
+ const { editor } = this;
28325
+ if (!editor.hasComment) {
28326
+ return;
28327
+ }
28328
+ this._createPopup(editor.comment);
28329
+ this.extraPopupElement.popup.renderCommentButton();
28330
+ }
28331
+ get hasCommentButton() {
28332
+ return this.enableComment && this.editor.hasComment;
28333
+ }
28334
+ get commentButtonPosition() {
28335
+ return this.editor.commentButtonPositionInPage;
28336
+ }
28337
+ get commentText() {
28338
+ return this.editor.comment.text;
28339
+ }
28340
+ set commentText(text) {
28341
+ this.editor.comment = text;
28342
+ if (!text) {
28343
+ this.removePopup();
28344
+ }
28345
+ }
28346
+ get commentData() {
28347
+ return this.editor.getData();
28348
+ }
28349
+ remove() {
28350
+ this.container.remove();
28351
+ this.container = null;
28352
+ this.removePopup();
28353
+ }
28354
+ };
27817
28355
  var _LinkAnnotationElement_instances, setInternalLink_fn, bindAttachment_fn, bindSetOCGState_fn;
27818
28356
  var LinkAnnotationElement = class extends AnnotationElement {
27819
28357
  constructor(parameters, options = null) {
@@ -28485,6 +29023,9 @@ var TextWidgetAnnotationElement = class extends WidgetAnnotationElement {
28485
29023
  ).valueOf();
28486
29024
  target.step = "";
28487
29025
  } else {
29026
+ if (!value.includes("T")) {
29027
+ value = `${value}T00:00`;
29028
+ }
28488
29029
  value = new Date(value).valueOf();
28489
29030
  }
28490
29031
  target.type = "text";
@@ -29048,31 +29589,30 @@ var ChoiceWidgetAnnotationElement = class extends WidgetAnnotationElement {
29048
29589
  return this.container;
29049
29590
  }
29050
29591
  };
29592
+ var _PopupAnnotationElement_instances, createPopup_fn;
29051
29593
  var PopupAnnotationElement = class extends AnnotationElement {
29052
29594
  constructor(parameters) {
29053
- const { data, elements } = parameters;
29054
- super(parameters, { isRenderable: AnnotationElement._hasPopupData(data) });
29595
+ const { data, elements, parent } = parameters;
29596
+ const hasCommentManager = !!parent._commentManager;
29597
+ super(parameters, {
29598
+ isRenderable: !hasCommentManager && AnnotationElement._hasPopupData(data)
29599
+ });
29600
+ __privateAdd(this, _PopupAnnotationElement_instances);
29055
29601
  this.elements = elements;
29056
- this.popup = null;
29602
+ if (hasCommentManager && AnnotationElement._hasPopupData(data)) {
29603
+ const popup = this.popup = __privateMethod(this, _PopupAnnotationElement_instances, createPopup_fn).call(this);
29604
+ for (const element of elements) {
29605
+ element.popup = popup;
29606
+ }
29607
+ } else {
29608
+ this.popup = null;
29609
+ }
29057
29610
  }
29058
29611
  render() {
29059
29612
  const { container } = this;
29060
29613
  container.classList.add("popupAnnotation");
29061
29614
  container.role = "comment";
29062
- const popup = this.popup = new PopupElement({
29063
- container: this.container,
29064
- color: this.data.color,
29065
- titleObj: this.data.titleObj,
29066
- modificationDate: this.data.modificationDate || this.data.creationDate,
29067
- contentsObj: this.data.contentsObj,
29068
- richText: this.data.richText,
29069
- rect: this.data.rect,
29070
- parentRect: this.data.parentRect || null,
29071
- parent: this.parent,
29072
- elements: this.elements,
29073
- open: this.data.open,
29074
- eventBus: this.linkService.eventBus
29075
- });
29615
+ const popup = this.popup = __privateMethod(this, _PopupAnnotationElement_instances, createPopup_fn).call(this);
29076
29616
  const elementIds = [];
29077
29617
  for (const element of this.elements) {
29078
29618
  element.popup = popup;
@@ -29087,7 +29627,24 @@ var PopupAnnotationElement = class extends AnnotationElement {
29087
29627
  return this.container;
29088
29628
  }
29089
29629
  };
29090
- var _boundKeyDown, _boundHide, _boundShow, _boundToggle, _color, _container4, _contentsObj, _dateObj, _elements, _eventBus2, _parent, _parentRect, _pinned, _popup, _popupAbortController, _position2, _commentButton2, _commentButtonPosition, _commentButtonColor, _rect, _richText, _titleObj, _updates2, _wasVisible, _PopupElement_instances, addEventListeners_fn, setCommentButtonPosition_fn, renderCommentButton_fn, html_get, fontSize_get, fontColor_get, makePopupContent_fn, keyDown_fn2, setPosition_fn, toggle_fn, show_fn, hide_fn;
29630
+ _PopupAnnotationElement_instances = new WeakSet();
29631
+ createPopup_fn = function() {
29632
+ return new PopupElement({
29633
+ container: this.container,
29634
+ color: this.data.color,
29635
+ titleObj: this.data.titleObj,
29636
+ modificationDate: this.data.modificationDate || this.data.creationDate,
29637
+ contentsObj: this.data.contentsObj,
29638
+ richText: this.data.richText,
29639
+ rect: this.data.rect,
29640
+ parentRect: this.data.parentRect || null,
29641
+ parent: this.parent,
29642
+ elements: this.elements,
29643
+ open: this.data.open,
29644
+ commentManager: this.parent._commentManager
29645
+ });
29646
+ };
29647
+ var _commentManager2, _boundKeyDown, _boundHide, _boundShow, _boundToggle, _color, _container4, _contentsObj, _dateObj, _elements, _parent, _parentRect, _pinned, _popup, _popupAbortController, _position2, _commentButton, _commentButtonPosition, _popupPosition2, _rect, _richText2, _titleObj, _updates2, _wasVisible, _firstElement, _commentText, _PopupElement_instances, addEventListeners_fn, setCommentButtonPosition_fn, updateCommentButtonPosition_fn, updateColor_fn, html_get, fontSize_get, fontColor_get, makePopupContent_fn, keyDown_fn2, setPosition_fn, toggle_fn, show_fn, hide_fn;
29091
29648
  var PopupElement = class {
29092
29649
  constructor({
29093
29650
  container,
@@ -29101,9 +29658,10 @@ var PopupElement = class {
29101
29658
  rect,
29102
29659
  parentRect,
29103
29660
  open,
29104
- eventBus = null
29661
+ commentManager = null
29105
29662
  }) {
29106
29663
  __privateAdd(this, _PopupElement_instances);
29664
+ __privateAdd(this, _commentManager2, null);
29107
29665
  __privateAdd(this, _boundKeyDown, __privateMethod(this, _PopupElement_instances, keyDown_fn2).bind(this));
29108
29666
  __privateAdd(this, _boundHide, __privateMethod(this, _PopupElement_instances, hide_fn).bind(this));
29109
29667
  __privateAdd(this, _boundShow, __privateMethod(this, _PopupElement_instances, show_fn).bind(this));
@@ -29113,45 +29671,214 @@ var PopupElement = class {
29113
29671
  __privateAdd(this, _contentsObj, null);
29114
29672
  __privateAdd(this, _dateObj, null);
29115
29673
  __privateAdd(this, _elements, null);
29116
- __privateAdd(this, _eventBus2, null);
29117
29674
  __privateAdd(this, _parent, null);
29118
29675
  __privateAdd(this, _parentRect, null);
29119
29676
  __privateAdd(this, _pinned, false);
29120
29677
  __privateAdd(this, _popup, null);
29121
29678
  __privateAdd(this, _popupAbortController, null);
29122
29679
  __privateAdd(this, _position2, null);
29123
- __privateAdd(this, _commentButton2, null);
29680
+ __privateAdd(this, _commentButton, null);
29124
29681
  __privateAdd(this, _commentButtonPosition, null);
29125
- __privateAdd(this, _commentButtonColor, null);
29682
+ __privateAdd(this, _popupPosition2, null);
29126
29683
  __privateAdd(this, _rect, null);
29127
- __privateAdd(this, _richText, null);
29684
+ __privateAdd(this, _richText2, null);
29128
29685
  __privateAdd(this, _titleObj, null);
29129
29686
  __privateAdd(this, _updates2, null);
29130
29687
  __privateAdd(this, _wasVisible, false);
29688
+ __privateAdd(this, _firstElement, null);
29689
+ __privateAdd(this, _commentText, null);
29131
29690
  __privateSet(this, _container4, container);
29132
29691
  __privateSet(this, _titleObj, titleObj);
29133
29692
  __privateSet(this, _contentsObj, contentsObj);
29134
- __privateSet(this, _richText, richText);
29693
+ __privateSet(this, _richText2, richText);
29135
29694
  __privateSet(this, _parent, parent);
29136
29695
  __privateSet(this, _color, color);
29137
29696
  __privateSet(this, _rect, rect);
29138
29697
  __privateSet(this, _parentRect, parentRect);
29139
29698
  __privateSet(this, _elements, elements);
29140
- __privateSet(this, _eventBus2, eventBus);
29699
+ __privateSet(this, _commentManager2, commentManager);
29700
+ __privateSet(this, _firstElement, elements[0]);
29141
29701
  __privateSet(this, _dateObj, PDFDateString.toDateObject(modificationDate));
29142
29702
  this.trigger = elements.flatMap((e) => e.getElementsToTriggerPopup());
29143
- __privateMethod(this, _PopupElement_instances, addEventListeners_fn).call(this);
29144
- __privateGet(this, _container4).hidden = true;
29145
- if (open) {
29146
- __privateMethod(this, _PopupElement_instances, toggle_fn).call(this);
29703
+ if (commentManager) {
29704
+ this.renderCommentButton();
29705
+ } else {
29706
+ __privateMethod(this, _PopupElement_instances, addEventListeners_fn).call(this);
29707
+ __privateGet(this, _container4).hidden = true;
29708
+ if (open) {
29709
+ __privateMethod(this, _PopupElement_instances, toggle_fn).call(this);
29710
+ }
29711
+ if (false) {
29712
+ __privateGet(this, _parent).popupShow.push(async () => {
29713
+ if (__privateGet(this, _container4).hidden) {
29714
+ __privateMethod(this, _PopupElement_instances, show_fn).call(this);
29715
+ }
29716
+ });
29717
+ }
29147
29718
  }
29148
- if (false) {
29149
- __privateGet(this, _parent).popupShow.push(async () => {
29150
- if (__privateGet(this, _container4).hidden) {
29151
- __privateMethod(this, _PopupElement_instances, show_fn).call(this);
29152
- }
29153
- });
29719
+ }
29720
+ renderCommentButton() {
29721
+ if (__privateGet(this, _commentButton)) {
29722
+ return;
29723
+ }
29724
+ if (!__privateGet(this, _commentButtonPosition)) {
29725
+ __privateMethod(this, _PopupElement_instances, setCommentButtonPosition_fn).call(this);
29154
29726
  }
29727
+ if (!__privateGet(this, _commentButtonPosition)) {
29728
+ return;
29729
+ }
29730
+ const { signal } = __privateSet(this, _popupAbortController, new AbortController());
29731
+ const hasOwnButton = !!__privateGet(this, _firstElement).extraPopupElement;
29732
+ const togglePopup = () => {
29733
+ __privateGet(this, _commentManager2).toggleCommentPopup(
29734
+ this,
29735
+ /* isSelected = */
29736
+ true,
29737
+ /* visibility = */
29738
+ void 0,
29739
+ /* isEditable = */
29740
+ !hasOwnButton
29741
+ );
29742
+ };
29743
+ const showPopup = () => {
29744
+ __privateGet(this, _commentManager2).toggleCommentPopup(
29745
+ this,
29746
+ /* isSelected = */
29747
+ false,
29748
+ /* visibility = */
29749
+ true,
29750
+ /* isEditable = */
29751
+ !hasOwnButton
29752
+ );
29753
+ };
29754
+ const hidePopup = () => {
29755
+ __privateGet(this, _commentManager2).toggleCommentPopup(
29756
+ this,
29757
+ /* isSelected = */
29758
+ false,
29759
+ /* visibility = */
29760
+ false
29761
+ );
29762
+ };
29763
+ if (!hasOwnButton) {
29764
+ const button = __privateSet(this, _commentButton, document.createElement("button"));
29765
+ button.className = "annotationCommentButton";
29766
+ const parentContainer = __privateGet(this, _firstElement).container;
29767
+ button.style.zIndex = parentContainer.style.zIndex + 1;
29768
+ button.tabIndex = 0;
29769
+ button.ariaHasPopup = "dialog";
29770
+ button.ariaControls = "commentPopup";
29771
+ button.setAttribute("data-l10n-id", "pdfjs-show-comment-button");
29772
+ __privateMethod(this, _PopupElement_instances, updateColor_fn).call(this);
29773
+ __privateMethod(this, _PopupElement_instances, updateCommentButtonPosition_fn).call(this);
29774
+ button.addEventListener("keydown", __privateGet(this, _boundKeyDown), { signal });
29775
+ button.addEventListener("click", togglePopup, { signal });
29776
+ button.addEventListener("pointerenter", showPopup, { signal });
29777
+ button.addEventListener("pointerleave", hidePopup, { signal });
29778
+ parentContainer.after(button);
29779
+ } else {
29780
+ __privateSet(this, _commentButton, __privateGet(this, _firstElement).container);
29781
+ for (const element of this.trigger) {
29782
+ element.ariaHasPopup = "dialog";
29783
+ element.ariaControls = "commentPopup";
29784
+ element.addEventListener("keydown", __privateGet(this, _boundKeyDown), { signal });
29785
+ element.addEventListener("click", togglePopup, { signal });
29786
+ element.addEventListener("pointerenter", showPopup, { signal });
29787
+ element.addEventListener("pointerleave", hidePopup, { signal });
29788
+ element.classList.add("popupTriggerArea");
29789
+ }
29790
+ }
29791
+ }
29792
+ get commentButtonColor() {
29793
+ const { color, opacity } = __privateGet(this, _firstElement).commentData;
29794
+ if (!color) {
29795
+ return null;
29796
+ }
29797
+ return __privateGet(this, _parent)._commentManager.makeCommentColor(color, opacity);
29798
+ }
29799
+ focusCommentButton() {
29800
+ setTimeout(() => {
29801
+ __privateGet(this, _commentButton)?.focus();
29802
+ }, 0);
29803
+ }
29804
+ getData() {
29805
+ const { richText, color, opacity, creationDate, modificationDate } = __privateGet(this, _firstElement).commentData;
29806
+ return {
29807
+ contentsObj: { str: this.comment },
29808
+ richText,
29809
+ color,
29810
+ opacity,
29811
+ creationDate,
29812
+ modificationDate
29813
+ };
29814
+ }
29815
+ get elementBeforePopup() {
29816
+ return __privateGet(this, _commentButton);
29817
+ }
29818
+ get comment() {
29819
+ __privateGet(this, _commentText) || __privateSet(this, _commentText, __privateGet(this, _firstElement).commentText);
29820
+ return __privateGet(this, _commentText);
29821
+ }
29822
+ set comment(text) {
29823
+ if (text === this.comment) {
29824
+ return;
29825
+ }
29826
+ __privateGet(this, _firstElement).commentText = __privateSet(this, _commentText, text);
29827
+ }
29828
+ get parentBoundingClientRect() {
29829
+ return __privateGet(this, _firstElement).layer.getBoundingClientRect();
29830
+ }
29831
+ setCommentButtonStates({ selected, hasPopup }) {
29832
+ if (!__privateGet(this, _commentButton)) {
29833
+ return;
29834
+ }
29835
+ __privateGet(this, _commentButton).classList.toggle("selected", selected);
29836
+ __privateGet(this, _commentButton).ariaExpanded = hasPopup;
29837
+ }
29838
+ setSelectedCommentButton(selected) {
29839
+ __privateGet(this, _commentButton).classList.toggle("selected", selected);
29840
+ }
29841
+ get commentPopupPosition() {
29842
+ if (__privateGet(this, _popupPosition2)) {
29843
+ return __privateGet(this, _popupPosition2);
29844
+ }
29845
+ const { x, y, height } = __privateGet(this, _commentButton).getBoundingClientRect();
29846
+ const {
29847
+ x: parentX,
29848
+ y: parentY,
29849
+ width: parentWidth,
29850
+ height: parentHeight
29851
+ } = __privateGet(this, _firstElement).layer.getBoundingClientRect();
29852
+ return [(x - parentX) / parentWidth, (y + height - parentY) / parentHeight];
29853
+ }
29854
+ set commentPopupPosition(pos) {
29855
+ __privateSet(this, _popupPosition2, pos);
29856
+ }
29857
+ hasDefaultPopupPosition() {
29858
+ return __privateGet(this, _popupPosition2) === null;
29859
+ }
29860
+ get commentButtonPosition() {
29861
+ return __privateGet(this, _commentButtonPosition);
29862
+ }
29863
+ get commentButtonWidth() {
29864
+ return __privateGet(this, _commentButton).getBoundingClientRect().width / this.parentBoundingClientRect.width;
29865
+ }
29866
+ editComment(options) {
29867
+ const [posX, posY] = __privateGet(this, _popupPosition2) || this.commentButtonPosition.map((x) => x / 100);
29868
+ const parentDimensions = this.parentBoundingClientRect;
29869
+ const {
29870
+ x: parentX,
29871
+ y: parentY,
29872
+ width: parentWidth,
29873
+ height: parentHeight
29874
+ } = parentDimensions;
29875
+ __privateGet(this, _commentManager2).showDialog(
29876
+ null,
29877
+ this,
29878
+ parentX + posX * parentWidth,
29879
+ parentY + posY * parentHeight,
29880
+ { ...options, parentDimensions }
29881
+ );
29155
29882
  }
29156
29883
  render() {
29157
29884
  if (__privateGet(this, _popup)) {
@@ -29188,43 +29915,36 @@ var PopupElement = class {
29188
29915
  modificationDate.dateTime = __privateGet(this, _dateObj).toISOString();
29189
29916
  header.append(modificationDate);
29190
29917
  }
29191
- const html = __privateGet(this, _PopupElement_instances, html_get);
29192
- if (html) {
29193
- XfaLayer.render({
29194
- xfaHtml: html,
29195
- intent: "richText",
29196
- div: popup
29197
- });
29198
- popup.lastChild.classList.add("richText", "popupContent");
29199
- } else {
29200
- const contents = this._formatContents(__privateGet(this, _contentsObj));
29201
- popup.append(contents);
29202
- }
29918
+ renderRichText(
29919
+ {
29920
+ html: __privateGet(this, _PopupElement_instances, html_get) || __privateGet(this, _contentsObj).str,
29921
+ dir: __privateGet(this, _contentsObj)?.dir,
29922
+ className: "popupContent"
29923
+ },
29924
+ popup
29925
+ );
29203
29926
  __privateGet(this, _container4).append(popup);
29204
29927
  }
29205
- /**
29206
- * Format the contents of the popup by adding newlines where necessary.
29207
- *
29208
- * @private
29209
- * @param {Object<string, string>} contentsObj
29210
- * @memberof PopupElement
29211
- * @returns {HTMLParagraphElement}
29212
- */
29213
- _formatContents({ str, dir }) {
29214
- const p = document.createElement("p");
29215
- p.classList.add("popupContent");
29216
- p.dir = dir;
29217
- const lines = str.split(/(?:\r\n?|\n)/);
29218
- for (let i = 0, ii = lines.length; i < ii; ++i) {
29219
- const line = lines[i];
29220
- p.append(document.createTextNode(line));
29221
- if (i < ii - 1) {
29222
- p.append(document.createElement("br"));
29928
+ updateEdited({ rect, popup, deleted }) {
29929
+ if (__privateGet(this, _commentManager2)) {
29930
+ if (deleted) {
29931
+ this.remove();
29932
+ __privateSet(this, _commentText, null);
29933
+ } else if (popup) {
29934
+ if (popup.deleted) {
29935
+ this.remove();
29936
+ } else {
29937
+ __privateMethod(this, _PopupElement_instances, updateColor_fn).call(this);
29938
+ __privateSet(this, _commentText, popup.text);
29939
+ }
29223
29940
  }
29941
+ if (rect) {
29942
+ __privateSet(this, _commentButtonPosition, null);
29943
+ __privateMethod(this, _PopupElement_instances, setCommentButtonPosition_fn).call(this);
29944
+ __privateMethod(this, _PopupElement_instances, updateCommentButtonPosition_fn).call(this);
29945
+ }
29946
+ return;
29224
29947
  }
29225
- return p;
29226
- }
29227
- updateEdited({ rect, popup, deleted }) {
29228
29948
  if (deleted || popup?.deleted) {
29229
29949
  this.remove();
29230
29950
  return;
@@ -29232,13 +29952,13 @@ var PopupElement = class {
29232
29952
  __privateMethod(this, _PopupElement_instances, addEventListeners_fn).call(this);
29233
29953
  __privateGet(this, _updates2) || __privateSet(this, _updates2, {
29234
29954
  contentsObj: __privateGet(this, _contentsObj),
29235
- richText: __privateGet(this, _richText)
29955
+ richText: __privateGet(this, _richText2)
29236
29956
  });
29237
29957
  if (rect) {
29238
29958
  __privateSet(this, _position2, null);
29239
29959
  }
29240
- if (popup) {
29241
- __privateSet(this, _richText, __privateMethod(this, _PopupElement_instances, makePopupContent_fn).call(this, popup.text));
29960
+ if (popup && popup.text) {
29961
+ __privateSet(this, _richText2, __privateMethod(this, _PopupElement_instances, makePopupContent_fn).call(this, popup.text));
29242
29962
  __privateSet(this, _dateObj, PDFDateString.toDateObject(popup.date));
29243
29963
  __privateSet(this, _contentsObj, null);
29244
29964
  }
@@ -29249,7 +29969,7 @@ var PopupElement = class {
29249
29969
  if (!__privateGet(this, _updates2)) {
29250
29970
  return;
29251
29971
  }
29252
- ({ contentsObj: __privateWrapper(this, _contentsObj)._, richText: __privateWrapper(this, _richText)._ } = __privateGet(this, _updates2));
29972
+ ({ contentsObj: __privateWrapper(this, _contentsObj)._, richText: __privateWrapper(this, _richText2)._ } = __privateGet(this, _updates2));
29253
29973
  __privateSet(this, _updates2, null);
29254
29974
  __privateGet(this, _popup)?.remove();
29255
29975
  __privateSet(this, _popup, null);
@@ -29262,8 +29982,12 @@ var PopupElement = class {
29262
29982
  __privateSet(this, _popup, null);
29263
29983
  __privateSet(this, _wasVisible, false);
29264
29984
  __privateSet(this, _pinned, false);
29265
- for (const element of this.trigger) {
29266
- element.classList.remove("popupTriggerArea");
29985
+ __privateGet(this, _commentButton)?.remove();
29986
+ __privateSet(this, _commentButton, null);
29987
+ if (this.trigger) {
29988
+ for (const element of this.trigger) {
29989
+ element.classList.remove("popupTriggerArea");
29990
+ }
29267
29991
  }
29268
29992
  }
29269
29993
  forceHide() {
@@ -29274,6 +29998,9 @@ var PopupElement = class {
29274
29998
  __privateGet(this, _container4).hidden = true;
29275
29999
  }
29276
30000
  maybeShow() {
30001
+ if (__privateGet(this, _commentManager2)) {
30002
+ return;
30003
+ }
29277
30004
  __privateMethod(this, _PopupElement_instances, addEventListeners_fn).call(this);
29278
30005
  if (!__privateGet(this, _wasVisible)) {
29279
30006
  return;
@@ -29285,9 +30012,13 @@ var PopupElement = class {
29285
30012
  __privateGet(this, _container4).hidden = false;
29286
30013
  }
29287
30014
  get isVisible() {
30015
+ if (__privateGet(this, _commentManager2)) {
30016
+ return false;
30017
+ }
29288
30018
  return __privateGet(this, _container4).hidden === false;
29289
30019
  }
29290
30020
  };
30021
+ _commentManager2 = new WeakMap();
29291
30022
  _boundKeyDown = new WeakMap();
29292
30023
  _boundHide = new WeakMap();
29293
30024
  _boundShow = new WeakMap();
@@ -29297,21 +30028,22 @@ _container4 = new WeakMap();
29297
30028
  _contentsObj = new WeakMap();
29298
30029
  _dateObj = new WeakMap();
29299
30030
  _elements = new WeakMap();
29300
- _eventBus2 = new WeakMap();
29301
30031
  _parent = new WeakMap();
29302
30032
  _parentRect = new WeakMap();
29303
30033
  _pinned = new WeakMap();
29304
30034
  _popup = new WeakMap();
29305
30035
  _popupAbortController = new WeakMap();
29306
30036
  _position2 = new WeakMap();
29307
- _commentButton2 = new WeakMap();
30037
+ _commentButton = new WeakMap();
29308
30038
  _commentButtonPosition = new WeakMap();
29309
- _commentButtonColor = new WeakMap();
30039
+ _popupPosition2 = new WeakMap();
29310
30040
  _rect = new WeakMap();
29311
- _richText = new WeakMap();
30041
+ _richText2 = new WeakMap();
29312
30042
  _titleObj = new WeakMap();
29313
30043
  _updates2 = new WeakMap();
29314
30044
  _wasVisible = new WeakMap();
30045
+ _firstElement = new WeakMap();
30046
+ _commentText = new WeakMap();
29315
30047
  _PopupElement_instances = new WeakSet();
29316
30048
  addEventListeners_fn = function() {
29317
30049
  if (__privateGet(this, _popupAbortController)) {
@@ -29321,8 +30053,8 @@ addEventListeners_fn = function() {
29321
30053
  const { signal } = __privateGet(this, _popupAbortController);
29322
30054
  for (const element of this.trigger) {
29323
30055
  element.addEventListener("click", __privateGet(this, _boundToggle), { signal });
29324
- element.addEventListener("mouseenter", __privateGet(this, _boundShow), { signal });
29325
- element.addEventListener("mouseleave", __privateGet(this, _boundHide), { signal });
30056
+ element.addEventListener("pointerenter", __privateGet(this, _boundShow), { signal });
30057
+ element.addEventListener("pointerleave", __privateGet(this, _boundHide), { signal });
29326
30058
  element.classList.add("popupTriggerArea");
29327
30059
  }
29328
30060
  for (const element of __privateGet(this, _elements)) {
@@ -29330,7 +30062,6 @@ addEventListeners_fn = function() {
29330
30062
  signal
29331
30063
  });
29332
30064
  }
29333
- __privateMethod(this, _PopupElement_instances, renderCommentButton_fn).call(this);
29334
30065
  };
29335
30066
  setCommentButtonPosition_fn = function() {
29336
30067
  const element = __privateGet(this, _elements).find((e) => e.hasCommentButton);
@@ -29340,57 +30071,29 @@ setCommentButtonPosition_fn = function() {
29340
30071
  __privateSet(this, _commentButtonPosition, element._normalizePoint(
29341
30072
  element.commentButtonPosition
29342
30073
  ));
29343
- __privateSet(this, _commentButtonColor, element.commentButtonColor);
29344
30074
  };
29345
- renderCommentButton_fn = function() {
29346
- if (__privateGet(this, _commentButton2)) {
30075
+ updateCommentButtonPosition_fn = function() {
30076
+ if (__privateGet(this, _firstElement).extraPopupElement && !__privateGet(this, _firstElement).editor) {
29347
30077
  return;
29348
30078
  }
29349
- if (!__privateGet(this, _commentButtonPosition)) {
29350
- __privateMethod(this, _PopupElement_instances, setCommentButtonPosition_fn).call(this);
29351
- }
29352
- if (!__privateGet(this, _commentButtonPosition)) {
30079
+ this.renderCommentButton();
30080
+ const [x, y] = __privateGet(this, _commentButtonPosition);
30081
+ const { style } = __privateGet(this, _commentButton);
30082
+ style.left = `calc(${x}%)`;
30083
+ style.top = `calc(${y}% - var(--comment-button-dim))`;
30084
+ };
30085
+ updateColor_fn = function() {
30086
+ if (__privateGet(this, _firstElement).extraPopupElement) {
29353
30087
  return;
29354
30088
  }
29355
- const button = __privateSet(this, _commentButton2, document.createElement("button"));
29356
- button.className = "annotationCommentButton";
29357
- const parentContainer = __privateGet(this, _elements)[0].container;
29358
- button.style.zIndex = parentContainer.style.zIndex + 1;
29359
- button.tabIndex = 0;
29360
- const { signal } = __privateGet(this, _popupAbortController);
29361
- button.addEventListener("hover", __privateGet(this, _boundToggle), { signal });
29362
- button.addEventListener("keydown", __privateGet(this, _boundKeyDown), { signal });
29363
- button.addEventListener(
29364
- "click",
29365
- () => {
29366
- const [
29367
- {
29368
- data: { id: editId },
29369
- annotationEditorType: mode
29370
- }
29371
- ] = __privateGet(this, _elements);
29372
- __privateGet(this, _eventBus2)?.dispatch("switchannotationeditormode", {
29373
- source: this,
29374
- editId,
29375
- mode,
29376
- editComment: true
29377
- });
29378
- },
29379
- { signal }
29380
- );
29381
- const { style } = button;
29382
- style.left = `calc(${__privateGet(this, _commentButtonPosition)[0]}%)`;
29383
- style.top = `calc(${__privateGet(this, _commentButtonPosition)[1]}% - var(--comment-button-dim))`;
29384
- if (__privateGet(this, _commentButtonColor)) {
29385
- style.backgroundColor = __privateGet(this, _commentButtonColor);
29386
- }
29387
- parentContainer.after(button);
30089
+ this.renderCommentButton();
30090
+ __privateGet(this, _commentButton).style.backgroundColor = this.commentButtonColor || "";
29388
30091
  };
29389
30092
  html_get = function() {
29390
- const richText = __privateGet(this, _richText);
30093
+ const richText = __privateGet(this, _richText2);
29391
30094
  const contentsObj = __privateGet(this, _contentsObj);
29392
30095
  if (richText?.str && (!contentsObj?.str || contentsObj.str === richText.str)) {
29393
- return __privateGet(this, _richText).html || null;
30096
+ return __privateGet(this, _richText2).html || null;
29394
30097
  }
29395
30098
  return null;
29396
30099
  };
@@ -29481,6 +30184,14 @@ setPosition_fn = function() {
29481
30184
  * Toggle the visibility of the popup.
29482
30185
  */
29483
30186
  toggle_fn = function() {
30187
+ if (__privateGet(this, _commentManager2)) {
30188
+ __privateGet(this, _commentManager2).toggleCommentPopup(
30189
+ this,
30190
+ /* isSelected = */
30191
+ false
30192
+ );
30193
+ return;
30194
+ }
29484
30195
  __privateSet(this, _pinned, !__privateGet(this, _pinned));
29485
30196
  if (__privateGet(this, _pinned)) {
29486
30197
  __privateMethod(this, _PopupElement_instances, show_fn).call(this);
@@ -29803,30 +30514,6 @@ var InkAnnotationElement = class extends AnnotationElement {
29803
30514
  addHighlightArea() {
29804
30515
  this.container.classList.add("highlightArea");
29805
30516
  }
29806
- get commentButtonPosition() {
29807
- const { inkLists, rect } = this.data;
29808
- if (inkLists?.length >= 1) {
29809
- let maxX = -Infinity;
29810
- let maxY = -Infinity;
29811
- for (const inkList of inkLists) {
29812
- for (let i = 0, ii = inkList.length; i < ii; i += 2) {
29813
- if (inkList[i + 1] > maxY) {
29814
- maxY = inkList[i + 1];
29815
- maxX = inkList[i];
29816
- } else if (inkList[i + 1] === maxY) {
29817
- maxX = Math.max(maxX, inkList[i]);
29818
- }
29819
- }
29820
- }
29821
- if (maxX !== Infinity) {
29822
- return [maxX, maxY];
29823
- }
29824
- }
29825
- if (rect) {
29826
- return [rect[2], rect[3]];
29827
- }
29828
- return null;
29829
- }
29830
30517
  };
29831
30518
  _polylinesGroupElement = new WeakMap();
29832
30519
  _polylines = new WeakMap();
@@ -30039,7 +30726,7 @@ _FileAttachmentAnnotationElement_instances = new WeakSet();
30039
30726
  download_fn = function() {
30040
30727
  this.downloadManager?.openOrDownloadData(this.content, this.filename);
30041
30728
  };
30042
- var _accessibilityManager, _annotationCanvasMap, _editableAnnotations, _structTreeLayer, _AnnotationLayer_instances, appendElement_fn, setAnnotationCanvasMap_fn;
30729
+ var _accessibilityManager, _annotationCanvasMap, _annotationStorage2, _editableAnnotations, _structTreeLayer, _linkService, _AnnotationLayer_instances, appendElement_fn, setAnnotationCanvasMap_fn;
30043
30730
  var _AnnotationLayer = class _AnnotationLayer {
30044
30731
  constructor({
30045
30732
  div,
@@ -30048,21 +30735,29 @@ var _AnnotationLayer = class _AnnotationLayer {
30048
30735
  annotationEditorUIManager,
30049
30736
  page,
30050
30737
  viewport,
30051
- structTreeLayer
30738
+ structTreeLayer,
30739
+ commentManager,
30740
+ linkService,
30741
+ annotationStorage
30052
30742
  }) {
30053
30743
  __privateAdd(this, _AnnotationLayer_instances);
30054
30744
  __privateAdd(this, _accessibilityManager, null);
30055
30745
  __privateAdd(this, _annotationCanvasMap, null);
30746
+ __privateAdd(this, _annotationStorage2, null);
30056
30747
  __privateAdd(this, _editableAnnotations, /* @__PURE__ */ new Map());
30057
30748
  __privateAdd(this, _structTreeLayer, null);
30749
+ __privateAdd(this, _linkService, null);
30058
30750
  this.div = div;
30059
30751
  __privateSet(this, _accessibilityManager, accessibilityManager);
30060
30752
  __privateSet(this, _annotationCanvasMap, annotationCanvasMap);
30061
30753
  __privateSet(this, _structTreeLayer, structTreeLayer || null);
30754
+ __privateSet(this, _linkService, linkService || null);
30755
+ __privateSet(this, _annotationStorage2, annotationStorage || new AnnotationStorage());
30062
30756
  this.page = page;
30063
30757
  this.viewport = viewport;
30064
30758
  this.zIndex = 0;
30065
30759
  this._annotationEditorUIManager = annotationEditorUIManager;
30760
+ this._commentManager = commentManager || null;
30066
30761
  if (false) {
30067
30762
  Object.defineProperty(this, "showPopups", {
30068
30763
  value: async () => {
@@ -30091,12 +30786,12 @@ var _AnnotationLayer = class _AnnotationLayer {
30091
30786
  const elementParams = {
30092
30787
  data: null,
30093
30788
  layer,
30094
- linkService: params.linkService,
30789
+ linkService: __privateGet(this, _linkService),
30095
30790
  downloadManager: params.downloadManager,
30096
30791
  imageResourcesPath: params.imageResourcesPath || "",
30097
30792
  renderForms: params.renderForms !== false,
30098
30793
  svgFactory: new DOMSVGFactory(),
30099
- annotationStorage: params.annotationStorage || new AnnotationStorage(),
30794
+ annotationStorage: __privateGet(this, _annotationStorage2),
30100
30795
  enableComment: params.enableComment === true,
30101
30796
  enableScripting: params.enableScripting === true,
30102
30797
  hasJSActions: params.hasJSActions,
@@ -30138,6 +30833,7 @@ var _AnnotationLayer = class _AnnotationLayer {
30138
30833
  rendered.style.visibility = "hidden";
30139
30834
  }
30140
30835
  await __privateMethod(this, _AnnotationLayer_instances, appendElement_fn).call(this, rendered, data.id, elementParams.elements);
30836
+ element.extraPopupElement?.popup?.renderCommentButton();
30141
30837
  if (element._isEditable) {
30142
30838
  __privateGet(this, _editableAnnotations).set(element.data.id, element);
30143
30839
  this._annotationEditorUIManager?.renderAnnotationElement(element);
@@ -30152,11 +30848,11 @@ var _AnnotationLayer = class _AnnotationLayer {
30152
30848
  * @param {IPDFLinkService} linkService
30153
30849
  * @memberof AnnotationLayer
30154
30850
  */
30155
- async addLinkAnnotations(annotations, linkService) {
30851
+ async addLinkAnnotations(annotations) {
30156
30852
  const elementParams = {
30157
30853
  data: null,
30158
30854
  layer: this.div,
30159
- linkService,
30855
+ linkService: __privateGet(this, _linkService),
30160
30856
  svgFactory: new DOMSVGFactory(),
30161
30857
  parent: this
30162
30858
  };
@@ -30190,6 +30886,34 @@ var _AnnotationLayer = class _AnnotationLayer {
30190
30886
  getEditableAnnotation(id2) {
30191
30887
  return __privateGet(this, _editableAnnotations).get(id2);
30192
30888
  }
30889
+ addFakeAnnotation(editor) {
30890
+ const { div } = this;
30891
+ const { id: id2, rotation } = editor;
30892
+ const element = new EditorAnnotationElement({
30893
+ data: {
30894
+ id: id2,
30895
+ rect: editor.getPDFRect(),
30896
+ rotation
30897
+ },
30898
+ editor,
30899
+ layer: div,
30900
+ parent: this,
30901
+ enableComment: !!this._commentManager,
30902
+ linkService: __privateGet(this, _linkService),
30903
+ annotationStorage: __privateGet(this, _annotationStorage2)
30904
+ });
30905
+ const htmlElement = element.render();
30906
+ div.append(htmlElement);
30907
+ __privateGet(this, _accessibilityManager)?.moveElementInDOM(
30908
+ div,
30909
+ htmlElement,
30910
+ htmlElement,
30911
+ /* isRemovable = */
30912
+ false
30913
+ );
30914
+ element.createOrUpdatePopup();
30915
+ return element;
30916
+ }
30193
30917
  /**
30194
30918
  * @private
30195
30919
  */
@@ -30210,8 +30934,10 @@ var _AnnotationLayer = class _AnnotationLayer {
30210
30934
  };
30211
30935
  _accessibilityManager = new WeakMap();
30212
30936
  _annotationCanvasMap = new WeakMap();
30937
+ _annotationStorage2 = new WeakMap();
30213
30938
  _editableAnnotations = new WeakMap();
30214
30939
  _structTreeLayer = new WeakMap();
30940
+ _linkService = new WeakMap();
30215
30941
  _AnnotationLayer_instances = new WeakSet();
30216
30942
  appendElement_fn = async function(element, id2, popupElements) {
30217
30943
  const contentElement = element.firstChild || element;
@@ -30277,18 +31003,17 @@ var AnnotationLayer = _AnnotationLayer;
30277
31003
 
30278
31004
  // src/pdf.js/src/display/editor/freetext.js
30279
31005
  var EOL_PATTERN = /\r\n?|\n/g;
30280
- var _color2, _content, _editorDivId, _editModeAC, _fontSize, _FreeTextEditor_instances, updateFontSize_fn, updateColor_fn, extractText_fn, setEditorDimensions_fn, _FreeTextEditor_static, getNodeContent_fn, setContent_fn, serializeContent_fn, deserializeContent_fn, hasElementChanged_fn;
31006
+ var _content, _editorDivId, _editModeAC, _fontSize, _FreeTextEditor_instances, updateFontSize_fn, updateColor_fn2, extractText_fn, setEditorDimensions_fn, _FreeTextEditor_static, getNodeContent_fn, setContent_fn, serializeContent_fn, deserializeContent_fn, hasElementChanged_fn;
30281
31007
  var _FreeTextEditor = class _FreeTextEditor extends AnnotationEditor {
30282
31008
  constructor(params) {
30283
31009
  super({ ...params, name: "freeTextEditor" });
30284
31010
  __privateAdd(this, _FreeTextEditor_instances);
30285
- __privateAdd(this, _color2);
30286
31011
  __privateAdd(this, _content, "");
30287
31012
  __privateAdd(this, _editorDivId, `${this.id}-editor`);
30288
31013
  __privateAdd(this, _editModeAC, null);
30289
31014
  __privateAdd(this, _fontSize);
30290
31015
  __publicField(this, "_colorPicker", null);
30291
- __privateSet(this, _color2, params.color || _FreeTextEditor._defaultColor || AnnotationEditor._defaultLineColor);
31016
+ this.color = params.color || _FreeTextEditor._defaultColor || AnnotationEditor._defaultLineColor;
30292
31017
  __privateSet(this, _fontSize, params.fontSize || _FreeTextEditor._defaultFontSize);
30293
31018
  if (!this.annotationElementId) {
30294
31019
  this._uiManager.a11yAlert("pdfjs-editor-freetext-added-alert");
@@ -30393,7 +31118,7 @@ var _FreeTextEditor = class _FreeTextEditor extends AnnotationEditor {
30393
31118
  __privateMethod(this, _FreeTextEditor_instances, updateFontSize_fn).call(this, value);
30394
31119
  break;
30395
31120
  case AnnotationEditorParamsType.FREETEXT_COLOR:
30396
- __privateMethod(this, _FreeTextEditor_instances, updateColor_fn).call(this, value);
31121
+ __privateMethod(this, _FreeTextEditor_instances, updateColor_fn2).call(this, value);
30397
31122
  break;
30398
31123
  }
30399
31124
  }
@@ -30414,7 +31139,7 @@ var _FreeTextEditor = class _FreeTextEditor extends AnnotationEditor {
30414
31139
  get propertiesToUpdate() {
30415
31140
  return [
30416
31141
  [AnnotationEditorParamsType.FREETEXT_SIZE, __privateGet(this, _fontSize)],
30417
- [AnnotationEditorParamsType.FREETEXT_COLOR, __privateGet(this, _color2)]
31142
+ [AnnotationEditorParamsType.FREETEXT_COLOR, this.color]
30418
31143
  ];
30419
31144
  }
30420
31145
  /** @inheritdoc */
@@ -30425,8 +31150,11 @@ var _FreeTextEditor = class _FreeTextEditor extends AnnotationEditor {
30425
31150
  get colorType() {
30426
31151
  return AnnotationEditorParamsType.FREETEXT_COLOR;
30427
31152
  }
30428
- get colorValue() {
30429
- return __privateGet(this, _color2);
31153
+ /** @inheritdoc */
31154
+ onUpdatedColor() {
31155
+ this.editorDiv.style.color = this.color;
31156
+ this._colorPicker?.update(this.color);
31157
+ super.onUpdatedColor();
30430
31158
  }
30431
31159
  /**
30432
31160
  * Helper to translate the editor with the keyboard when it's empty.
@@ -30651,7 +31379,7 @@ var _FreeTextEditor = class _FreeTextEditor extends AnnotationEditor {
30651
31379
  this.editorDiv.contentEditable = true;
30652
31380
  const { style } = this.editorDiv;
30653
31381
  style.fontSize = `calc(${__privateGet(this, _fontSize)}px * var(--total-scale-factor))`;
30654
- style.color = __privateGet(this, _color2);
31382
+ style.color = this.color;
30655
31383
  this.div.append(this.editorDiv);
30656
31384
  this.overlayDiv = document.createElement("div");
30657
31385
  this.overlayDiv.classList.add("overlay", "enabled");
@@ -30797,7 +31525,10 @@ var _FreeTextEditor = class _FreeTextEditor extends AnnotationEditor {
30797
31525
  rotation,
30798
31526
  id: id2,
30799
31527
  popupRef,
30800
- contentsObj
31528
+ richText,
31529
+ contentsObj,
31530
+ creationDate,
31531
+ modificationDate
30801
31532
  },
30802
31533
  textContent,
30803
31534
  textPosition,
@@ -30821,16 +31552,19 @@ var _FreeTextEditor = class _FreeTextEditor extends AnnotationEditor {
30821
31552
  id: id2,
30822
31553
  deleted: false,
30823
31554
  popupRef,
30824
- comment: contentsObj?.str || null
31555
+ comment: contentsObj?.str || null,
31556
+ richText,
31557
+ creationDate,
31558
+ modificationDate
30825
31559
  };
30826
31560
  }
30827
31561
  const editor = await super.deserialize(data, parent, uiManager);
30828
31562
  __privateSet(editor, _fontSize, data.fontSize);
30829
- __privateSet(editor, _color2, Util.makeHexColor(...data.color));
31563
+ editor.color = Util.makeHexColor(...data.color);
30830
31564
  __privateSet(editor, _content, __privateMethod(_a2 = _FreeTextEditor, _FreeTextEditor_static, deserializeContent_fn).call(_a2, data.value));
30831
31565
  editor._initialData = initialData;
30832
31566
  if (data.comment) {
30833
- editor.setCommentData(data.comment);
31567
+ editor.setCommentData(data);
30834
31568
  }
30835
31569
  return editor;
30836
31570
  }
@@ -30842,20 +31576,14 @@ var _FreeTextEditor = class _FreeTextEditor extends AnnotationEditor {
30842
31576
  if (this.deleted) {
30843
31577
  return this.serializeDeleted();
30844
31578
  }
30845
- const rect = this.getPDFRect();
30846
31579
  const color = AnnotationEditor._colorManager.convert(
30847
- this.isAttachedToDOM ? getComputedStyle(this.editorDiv).color : __privateGet(this, _color2)
31580
+ this.isAttachedToDOM ? getComputedStyle(this.editorDiv).color : this.color
30848
31581
  );
30849
- const serialized = {
30850
- annotationType: AnnotationEditorType.FREETEXT,
31582
+ const serialized = Object.assign(super.serialize(isForCopying), {
30851
31583
  color,
30852
31584
  fontSize: __privateGet(this, _fontSize),
30853
- value: __privateMethod(this, _FreeTextEditor_instances, serializeContent_fn).call(this),
30854
- pageIndex: this.pageIndex,
30855
- rect,
30856
- rotation: this.rotation,
30857
- structTreeParentId: this._structTreeParentId
30858
- };
31585
+ value: __privateMethod(this, _FreeTextEditor_instances, serializeContent_fn).call(this)
31586
+ });
30859
31587
  this.addComment(serialized);
30860
31588
  if (isForCopying) {
30861
31589
  serialized.isCopy = true;
@@ -30875,7 +31603,7 @@ var _FreeTextEditor = class _FreeTextEditor extends AnnotationEditor {
30875
31603
  }
30876
31604
  const { style } = content;
30877
31605
  style.fontSize = `calc(${__privateGet(this, _fontSize)}px * var(--total-scale-factor))`;
30878
- style.color = __privateGet(this, _color2);
31606
+ style.color = this.color;
30879
31607
  content.replaceChildren();
30880
31608
  for (const line of __privateGet(this, _content).split("\n")) {
30881
31609
  const div = document.createElement("div");
@@ -30884,11 +31612,10 @@ var _FreeTextEditor = class _FreeTextEditor extends AnnotationEditor {
30884
31612
  );
30885
31613
  content.append(div);
30886
31614
  }
30887
- const params = {
30888
- rect: this.getPDFRect()
30889
- };
30890
- params.popup = this.hasEditedComment ? this.comment : { text: __privateGet(this, _content) };
30891
- annotation.updateEdited(params);
31615
+ annotation.updateEdited({
31616
+ rect: this.getPDFRect(),
31617
+ popup: this._uiManager.hasCommentManager() || this.hasEditedComment ? this.comment : { text: __privateGet(this, _content) }
31618
+ });
30892
31619
  return content;
30893
31620
  }
30894
31621
  resetAnnotationElement(annotation) {
@@ -30896,7 +31623,6 @@ var _FreeTextEditor = class _FreeTextEditor extends AnnotationEditor {
30896
31623
  annotation.resetEdited();
30897
31624
  }
30898
31625
  };
30899
- _color2 = new WeakMap();
30900
31626
  _content = new WeakMap();
30901
31627
  _editorDivId = new WeakMap();
30902
31628
  _editModeAC = new WeakMap();
@@ -30928,12 +31654,12 @@ updateFontSize_fn = function(fontSize) {
30928
31654
  * Update the color and make this action undoable.
30929
31655
  * @param {string} color
30930
31656
  */
30931
- updateColor_fn = function(color) {
31657
+ updateColor_fn2 = function(color) {
30932
31658
  const setColor = (col) => {
30933
- __privateSet(this, _color2, this.editorDiv.style.color = col);
30934
- this._colorPicker?.update(col);
31659
+ this.color = col;
31660
+ this.onUpdatedColor();
30935
31661
  };
30936
- const savedColor = __privateGet(this, _color2);
31662
+ const savedColor = this.color;
30937
31663
  this.addCommands({
30938
31664
  cmd: setColor.bind(this, color),
30939
31665
  undo: setColor.bind(this, savedColor),
@@ -31501,6 +32227,7 @@ var FreeDrawOutline = class extends Outline {
31501
32227
  __privateSet(this, _scaleFactor2, scaleFactor);
31502
32228
  __privateSet(this, _innerMargin2, innerMargin);
31503
32229
  __privateSet(this, _isLTR2, isLTR);
32230
+ this.firstPoint = [NaN, NaN];
31504
32231
  this.lastPoint = [NaN, NaN];
31505
32232
  __privateMethod(this, _FreeDrawOutline_instances, computeMinMax_fn).call(this, isLTR);
31506
32233
  const [x, y, width, height] = __privateGet(this, _bbox);
@@ -31623,13 +32350,22 @@ computeMinMax_fn = function(isLTR) {
31623
32350
  let lastX = outline[4];
31624
32351
  let lastY = outline[5];
31625
32352
  const minMax = [lastX, lastY, lastX, lastY];
32353
+ let firstPointX = lastX;
32354
+ let firstPointY = lastY;
31626
32355
  let lastPointX = lastX;
31627
32356
  let lastPointY = lastY;
31628
32357
  const ltrCallback = isLTR ? Math.max : Math.min;
32358
+ const bezierBbox = new Float32Array(4);
31629
32359
  for (let i = 6, ii = outline.length; i < ii; i += 6) {
31630
32360
  const x = outline[i + 4], y = outline[i + 5];
31631
32361
  if (isNaN(outline[i])) {
31632
32362
  Util.pointBoundingBox(x, y, minMax);
32363
+ if (firstPointY > y) {
32364
+ firstPointX = x;
32365
+ firstPointY = y;
32366
+ } else if (firstPointY === y) {
32367
+ firstPointX = ltrCallback(firstPointX, x);
32368
+ }
31633
32369
  if (lastPointY < y) {
31634
32370
  lastPointX = x;
31635
32371
  lastPointY = y;
@@ -31637,14 +32373,32 @@ computeMinMax_fn = function(isLTR) {
31637
32373
  lastPointX = ltrCallback(lastPointX, x);
31638
32374
  }
31639
32375
  } else {
31640
- const bbox2 = [Infinity, Infinity, -Infinity, -Infinity];
31641
- Util.bezierBoundingBox(lastX, lastY, ...outline.slice(i, i + 6), bbox2);
31642
- Util.rectBoundingBox(...bbox2, minMax);
31643
- if (lastPointY < bbox2[3]) {
31644
- lastPointX = bbox2[2];
31645
- lastPointY = bbox2[3];
31646
- } else if (lastPointY === bbox2[3]) {
31647
- lastPointX = ltrCallback(lastPointX, bbox2[2]);
32376
+ bezierBbox[0] = bezierBbox[1] = Infinity;
32377
+ bezierBbox[2] = bezierBbox[3] = -Infinity;
32378
+ Util.bezierBoundingBox(
32379
+ lastX,
32380
+ lastY,
32381
+ ...outline.slice(i, i + 6),
32382
+ bezierBbox
32383
+ );
32384
+ Util.rectBoundingBox(
32385
+ bezierBbox[0],
32386
+ bezierBbox[1],
32387
+ bezierBbox[2],
32388
+ bezierBbox[3],
32389
+ minMax
32390
+ );
32391
+ if (firstPointY > bezierBbox[1]) {
32392
+ firstPointX = bezierBbox[0];
32393
+ firstPointY = bezierBbox[1];
32394
+ } else if (firstPointY === bezierBbox[1]) {
32395
+ firstPointX = ltrCallback(firstPointX, bezierBbox[0]);
32396
+ }
32397
+ if (lastPointY < bezierBbox[3]) {
32398
+ lastPointX = bezierBbox[2];
32399
+ lastPointY = bezierBbox[3];
32400
+ } else if (lastPointY === bezierBbox[3]) {
32401
+ lastPointX = ltrCallback(lastPointX, bezierBbox[2]);
31648
32402
  }
31649
32403
  }
31650
32404
  lastX = x;
@@ -31655,11 +32409,12 @@ computeMinMax_fn = function(isLTR) {
31655
32409
  bbox[1] = minMax[1] - __privateGet(this, _innerMargin2);
31656
32410
  bbox[2] = minMax[2] - minMax[0] + 2 * __privateGet(this, _innerMargin2);
31657
32411
  bbox[3] = minMax[3] - minMax[1] + 2 * __privateGet(this, _innerMargin2);
32412
+ this.firstPoint = [firstPointX, firstPointY];
31658
32413
  this.lastPoint = [lastPointX, lastPointY];
31659
32414
  };
31660
32415
 
31661
32416
  // src/pdf.js/src/display/editor/drawers/highlight.js
31662
- var _box3, _lastPoint, _verticalEdges, _intervals, _HighlightOutliner_instances, getOutlines_fn, binarySearch_fn, insert_fn, remove_fn, breakEdge_fn;
32417
+ var _box3, _firstPoint, _lastPoint, _verticalEdges, _intervals, _HighlightOutliner_instances, getOutlines_fn, binarySearch_fn, insert_fn, remove_fn, breakEdge_fn;
31663
32418
  var HighlightOutliner = class {
31664
32419
  /**
31665
32420
  * Construct an outliner.
@@ -31676,6 +32431,7 @@ var HighlightOutliner = class {
31676
32431
  constructor(boxes, borderWidth = 0, innerMargin = 0, isLTR = true) {
31677
32432
  __privateAdd(this, _HighlightOutliner_instances);
31678
32433
  __privateAdd(this, _box3);
32434
+ __privateAdd(this, _firstPoint);
31679
32435
  __privateAdd(this, _lastPoint);
31680
32436
  __privateAdd(this, _verticalEdges, []);
31681
32437
  __privateAdd(this, _intervals, []);
@@ -31696,10 +32452,27 @@ var HighlightOutliner = class {
31696
32452
  const bboxHeight = minMax[3] - minMax[1] + 2 * innerMargin;
31697
32453
  const shiftedMinX = minMax[0] - innerMargin;
31698
32454
  const shiftedMinY = minMax[1] - innerMargin;
32455
+ let firstPointX = isLTR ? -Infinity : Infinity;
32456
+ let firstPointY = Infinity;
31699
32457
  const lastEdge = __privateGet(this, _verticalEdges).at(isLTR ? -1 : -2);
31700
32458
  const lastPoint = [lastEdge[0], lastEdge[2]];
31701
32459
  for (const edge of __privateGet(this, _verticalEdges)) {
31702
- const [x, y1, y2] = edge;
32460
+ const [x, y1, y2, left] = edge;
32461
+ if (!left && isLTR) {
32462
+ if (y1 < firstPointY) {
32463
+ firstPointY = y1;
32464
+ firstPointX = x;
32465
+ } else if (y1 === firstPointY) {
32466
+ firstPointX = Math.max(firstPointX, x);
32467
+ }
32468
+ } else if (left && !isLTR) {
32469
+ if (y1 < firstPointY) {
32470
+ firstPointY = y1;
32471
+ firstPointX = x;
32472
+ } else if (y1 === firstPointY) {
32473
+ firstPointX = Math.min(firstPointX, x);
32474
+ }
32475
+ }
31703
32476
  edge[0] = (x - shiftedMinX) / bboxWidth;
31704
32477
  edge[1] = (y1 - shiftedMinY) / bboxHeight;
31705
32478
  edge[2] = (y2 - shiftedMinY) / bboxHeight;
@@ -31710,6 +32483,7 @@ var HighlightOutliner = class {
31710
32483
  bboxWidth,
31711
32484
  bboxHeight
31712
32485
  ]));
32486
+ __privateSet(this, _firstPoint, [firstPointX, firstPointY]);
31713
32487
  __privateSet(this, _lastPoint, lastPoint);
31714
32488
  }
31715
32489
  getOutlines() {
@@ -31730,6 +32504,7 @@ var HighlightOutliner = class {
31730
32504
  }
31731
32505
  };
31732
32506
  _box3 = new WeakMap();
32507
+ _firstPoint = new WeakMap();
31733
32508
  _lastPoint = new WeakMap();
31734
32509
  _verticalEdges = new WeakMap();
31735
32510
  _intervals = new WeakMap();
@@ -31779,7 +32554,12 @@ getOutlines_fn = function(outlineVerticalEdges) {
31779
32554
  }
31780
32555
  outline.push(lastPointX, lastPointY);
31781
32556
  }
31782
- return new HighlightOutline(outlines, __privateGet(this, _box3), __privateGet(this, _lastPoint));
32557
+ return new HighlightOutline(
32558
+ outlines,
32559
+ __privateGet(this, _box3),
32560
+ __privateGet(this, _firstPoint),
32561
+ __privateGet(this, _lastPoint)
32562
+ );
31783
32563
  };
31784
32564
  binarySearch_fn = function(y) {
31785
32565
  const array = __privateGet(this, _intervals);
@@ -31860,12 +32640,13 @@ breakEdge_fn = function(edge) {
31860
32640
  };
31861
32641
  var _box4, _outlines;
31862
32642
  var HighlightOutline = class extends Outline {
31863
- constructor(outlines, box, lastPoint) {
32643
+ constructor(outlines, box, firstPoint, lastPoint) {
31864
32644
  super();
31865
32645
  __privateAdd(this, _box4);
31866
32646
  __privateAdd(this, _outlines);
31867
32647
  __privateSet(this, _outlines, outlines);
31868
32648
  __privateSet(this, _box4, box);
32649
+ this.firstPoint = firstPoint;
31869
32650
  this.lastPoint = lastPoint;
31870
32651
  }
31871
32652
  toSVGPath() {
@@ -31943,7 +32724,7 @@ var FreeHighlightOutline = class extends FreeDrawOutline {
31943
32724
  };
31944
32725
 
31945
32726
  // src/pdf.js/src/display/editor/highlight.js
31946
- var _anchorNode, _anchorOffset, _boxes, _clipPathId, _colorPicker2, _focusOutlines, _focusNode, _focusOffset, _highlightDiv, _highlightOutlines, _id3, _isFreeHighlight, _lastPoint2, _opacity, _outlineId, _text2, _thickness2, _methodOfCreation, _HighlightEditor_instances, createOutlines_fn, createFreeOutlines_fn, updateColor_fn2, updateThickness_fn, changeThickness_fn, cleanDrawLayer_fn, addToDrawLayer_fn, _HighlightEditor_static, rotateBbox_fn, keydown_fn, setCaret_fn, getRotation_fn, serializeBoxes_fn, serializeOutlines_fn, highlightMove_fn, endHighlight_fn, hasElementChanged_fn2;
32727
+ var _anchorNode, _anchorOffset, _boxes, _clipPathId, _colorPicker2, _focusOutlines, _focusNode, _focusOffset, _highlightDiv, _highlightOutlines, _id3, _isFreeHighlight, _firstPoint2, _lastPoint2, _outlineId, _text2, _thickness2, _methodOfCreation, _HighlightEditor_instances, createOutlines_fn, createFreeOutlines_fn, updateColor_fn3, updateThickness_fn, changeThickness_fn, cleanDrawLayer_fn, addToDrawLayer_fn, _HighlightEditor_static, rotateBbox_fn, keydown_fn, setCaret_fn, getRotation_fn, serializeBoxes_fn, serializeOutlines_fn, highlightMove_fn, endHighlight_fn, hasElementChanged_fn2;
31947
32728
  var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
31948
32729
  constructor(params) {
31949
32730
  super({ ...params, name: "highlightEditor" });
@@ -31960,15 +32741,15 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
31960
32741
  __privateAdd(this, _highlightOutlines, null);
31961
32742
  __privateAdd(this, _id3, null);
31962
32743
  __privateAdd(this, _isFreeHighlight, false);
32744
+ __privateAdd(this, _firstPoint2, null);
31963
32745
  __privateAdd(this, _lastPoint2, null);
31964
- __privateAdd(this, _opacity);
31965
32746
  __privateAdd(this, _outlineId, null);
31966
32747
  __privateAdd(this, _text2, "");
31967
32748
  __privateAdd(this, _thickness2);
31968
32749
  __privateAdd(this, _methodOfCreation, "");
31969
32750
  this.color = params.color || _HighlightEditor._defaultColor;
31970
32751
  __privateSet(this, _thickness2, params.thickness || _HighlightEditor._defaultThickness);
31971
- __privateSet(this, _opacity, params.opacity || _HighlightEditor._defaultOpacity);
32752
+ this.opacity = params.opacity || _HighlightEditor._defaultOpacity;
31972
32753
  __privateSet(this, _boxes, params.boxes || null);
31973
32754
  __privateSet(this, _methodOfCreation, params.methodOfCreation || "");
31974
32755
  __privateSet(this, _text2, params.text || "");
@@ -32021,9 +32802,6 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
32021
32802
  color: this._uiManager.getNonHCMColorName(this.color)
32022
32803
  };
32023
32804
  }
32024
- get commentColor() {
32025
- return this.color;
32026
- }
32027
32805
  static computeTelemetryFinalData(data) {
32028
32806
  return { numberOfColors: data.get("color").size };
32029
32807
  }
@@ -32051,10 +32829,14 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
32051
32829
  return __privateGet(this, _lastPoint2);
32052
32830
  }
32053
32831
  /** @inheritdoc */
32832
+ get commentButtonPosition() {
32833
+ return __privateGet(this, _firstPoint2);
32834
+ }
32835
+ /** @inheritdoc */
32054
32836
  updateParams(type, value) {
32055
32837
  switch (type) {
32056
32838
  case AnnotationEditorParamsType.HIGHLIGHT_COLOR:
32057
- __privateMethod(this, _HighlightEditor_instances, updateColor_fn2).call(this, value);
32839
+ __privateMethod(this, _HighlightEditor_instances, updateColor_fn3).call(this, value);
32058
32840
  break;
32059
32841
  case AnnotationEditorParamsType.HIGHLIGHT_THICKNESS:
32060
32842
  __privateMethod(this, _HighlightEditor_instances, updateThickness_fn).call(this, value);
@@ -32088,6 +32870,17 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
32088
32870
  ];
32089
32871
  }
32090
32872
  /** @inheritdoc */
32873
+ onUpdatedColor() {
32874
+ this.parent?.drawLayer.updateProperties(__privateGet(this, _id3), {
32875
+ root: {
32876
+ fill: this.color,
32877
+ "fill-opacity": this.opacity
32878
+ }
32879
+ });
32880
+ __privateGet(this, _colorPicker2)?.updateColor(this.color);
32881
+ super.onUpdatedColor();
32882
+ }
32883
+ /** @inheritdoc */
32091
32884
  get toolbarButtons() {
32092
32885
  if (this._uiManager.highlightColors) {
32093
32886
  const colorPicker = __privateSet(this, _colorPicker2, new ColorPicker({
@@ -32210,8 +33003,7 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
32210
33003
  highlightDiv.setAttribute("aria-hidden", "true");
32211
33004
  highlightDiv.className = "internal";
32212
33005
  highlightDiv.style.clipPath = __privateGet(this, _clipPathId);
32213
- const [parentWidth, parentHeight] = this.parentDimensions;
32214
- this.setDims(this.width * parentWidth, this.height * parentHeight);
33006
+ this.setDims(this.width, this.height);
32215
33007
  bindEvents(this, __privateGet(this, _highlightDiv), ["pointerover", "pointerleave"]);
32216
33008
  this.enableEditing();
32217
33009
  return div;
@@ -32382,7 +33174,10 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
32382
33174
  color: color2,
32383
33175
  opacity: opacity2,
32384
33176
  popupRef,
32385
- contentsObj
33177
+ richText,
33178
+ contentsObj,
33179
+ creationDate,
33180
+ modificationDate
32386
33181
  },
32387
33182
  parent: {
32388
33183
  page: { pageNumber }
@@ -32401,7 +33196,10 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
32401
33196
  id: id2,
32402
33197
  deleted: false,
32403
33198
  popupRef,
32404
- comment: contentsObj?.str || null
33199
+ richText,
33200
+ comment: contentsObj?.str || null,
33201
+ creationDate,
33202
+ modificationDate
32405
33203
  };
32406
33204
  } else if (data instanceof InkAnnotationElement) {
32407
33205
  const {
@@ -32413,7 +33211,10 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
32413
33211
  color: color2,
32414
33212
  borderStyle: { rawWidth: thickness },
32415
33213
  popupRef,
32416
- contentsObj
33214
+ richText,
33215
+ contentsObj,
33216
+ creationDate,
33217
+ modificationDate
32417
33218
  },
32418
33219
  parent: {
32419
33220
  page: { pageNumber }
@@ -32432,19 +33233,22 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
32432
33233
  id: id2,
32433
33234
  deleted: false,
32434
33235
  popupRef,
32435
- comment: contentsObj?.str || null
33236
+ richText,
33237
+ comment: contentsObj?.str || null,
33238
+ creationDate,
33239
+ modificationDate
32436
33240
  };
32437
33241
  }
32438
33242
  const { color, quadPoints, inkLists, opacity } = data;
32439
33243
  const editor = await super.deserialize(data, parent, uiManager);
32440
33244
  editor.color = Util.makeHexColor(...color);
32441
- __privateSet(editor, _opacity, opacity || 1);
33245
+ editor.opacity = opacity || 1;
32442
33246
  if (inkLists) {
32443
33247
  __privateSet(editor, _thickness2, data.thickness);
32444
33248
  }
32445
33249
  editor._initialData = initialData;
32446
33250
  if (data.comment) {
32447
- editor.setCommentData(data.comment);
33251
+ editor.setCommentData(data);
32448
33252
  }
32449
33253
  const [pageWidth, pageHeight] = editor.pageDimensions;
32450
33254
  const [pageX, pageY] = editor.pageTranslation;
@@ -32520,22 +33324,17 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
32520
33324
  if (this.deleted) {
32521
33325
  return this.serializeDeleted();
32522
33326
  }
32523
- const rect = this.getPDFRect();
32524
33327
  const color = AnnotationEditor._colorManager.convert(
32525
33328
  this._uiManager.getNonHCMColor(this.color)
32526
33329
  );
32527
- const serialized = {
32528
- annotationType: AnnotationEditorType.HIGHLIGHT,
33330
+ const serialized = super.serialize(isForCopying);
33331
+ Object.assign(serialized, {
32529
33332
  color,
32530
- opacity: __privateGet(this, _opacity),
33333
+ opacity: this.opacity,
32531
33334
  thickness: __privateGet(this, _thickness2),
32532
33335
  quadPoints: __privateMethod(this, _HighlightEditor_instances, serializeBoxes_fn).call(this),
32533
- outlines: __privateMethod(this, _HighlightEditor_instances, serializeOutlines_fn).call(this, rect),
32534
- pageIndex: this.pageIndex,
32535
- rect,
32536
- rotation: __privateMethod(this, _HighlightEditor_instances, getRotation_fn).call(this),
32537
- structTreeParentId: this._structTreeParentId
32538
- };
33336
+ outlines: __privateMethod(this, _HighlightEditor_instances, serializeOutlines_fn).call(this, serialized.rect)
33337
+ });
32539
33338
  this.addComment(serialized);
32540
33339
  if (this.annotationElementId && !__privateMethod(this, _HighlightEditor_instances, hasElementChanged_fn2).call(this, serialized)) {
32541
33340
  return null;
@@ -32549,13 +33348,10 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
32549
33348
  annotation.hide();
32550
33349
  return null;
32551
33350
  }
32552
- const params = {
32553
- rect: this.getPDFRect()
32554
- };
32555
- if (this.hasEditedComment) {
32556
- params.popup = this.comment;
32557
- }
32558
- annotation.updateEdited(params);
33351
+ annotation.updateEdited({
33352
+ rect: this.getPDFRect(),
33353
+ popup: this.comment
33354
+ });
32559
33355
  return null;
32560
33356
  }
32561
33357
  static canCreateNewEmptyEditor() {
@@ -32574,8 +33370,8 @@ _highlightDiv = new WeakMap();
32574
33370
  _highlightOutlines = new WeakMap();
32575
33371
  _id3 = new WeakMap();
32576
33372
  _isFreeHighlight = new WeakMap();
33373
+ _firstPoint2 = new WeakMap();
32577
33374
  _lastPoint2 = new WeakMap();
32578
- _opacity = new WeakMap();
32579
33375
  _outlineId = new WeakMap();
32580
33376
  _text2 = new WeakMap();
32581
33377
  _thickness2 = new WeakMap();
@@ -32598,6 +33394,11 @@ createOutlines_fn = function() {
32598
33394
  this._uiManager.direction === "ltr"
32599
33395
  );
32600
33396
  __privateSet(this, _focusOutlines, outlinerForOutline.getOutlines());
33397
+ const { firstPoint } = __privateGet(this, _highlightOutlines);
33398
+ __privateSet(this, _firstPoint2, [
33399
+ (firstPoint[0] - this.x) / this.width,
33400
+ (firstPoint[1] - this.y) / this.height
33401
+ ]);
32601
33402
  const { lastPoint } = __privateGet(this, _focusOutlines);
32602
33403
  __privateSet(this, _lastPoint2, [
32603
33404
  (lastPoint[0] - this.x) / this.width,
@@ -32684,6 +33485,11 @@ createFreeOutlines_fn = function({ highlightOutlines, highlightId, clipPathId })
32684
33485
  break;
32685
33486
  }
32686
33487
  }
33488
+ const { firstPoint } = highlightOutlines;
33489
+ __privateSet(this, _firstPoint2, [
33490
+ (firstPoint[0] - x) / width,
33491
+ (firstPoint[1] - y) / height
33492
+ ]);
32687
33493
  const { lastPoint } = __privateGet(this, _focusOutlines);
32688
33494
  __privateSet(this, _lastPoint2, [(lastPoint[0] - x) / width, (lastPoint[1] - y) / height]);
32689
33495
  };
@@ -32691,20 +33497,14 @@ createFreeOutlines_fn = function({ highlightOutlines, highlightId, clipPathId })
32691
33497
  * Update the color and make this action undoable.
32692
33498
  * @param {string} color
32693
33499
  */
32694
- updateColor_fn2 = function(color) {
33500
+ updateColor_fn3 = function(color) {
32695
33501
  const setColorAndOpacity = (col, opa) => {
32696
33502
  this.color = col;
32697
- __privateSet(this, _opacity, opa);
32698
- this.parent?.drawLayer.updateProperties(__privateGet(this, _id3), {
32699
- root: {
32700
- fill: col,
32701
- "fill-opacity": opa
32702
- }
32703
- });
32704
- __privateGet(this, _colorPicker2)?.updateColor(col);
33503
+ this.opacity = opa;
33504
+ this.onUpdatedColor();
32705
33505
  };
32706
33506
  const savedColor = this.color;
32707
- const savedOpacity = __privateGet(this, _opacity);
33507
+ const savedOpacity = this.opacity;
32708
33508
  this.addCommands({
32709
33509
  cmd: setColorAndOpacity.bind(
32710
33510
  this,
@@ -32760,8 +33560,7 @@ changeThickness_fn = function(thickness) {
32760
33560
  highlightOutlines: __privateGet(this, _highlightOutlines).getNewOutline(thickness / 2)
32761
33561
  });
32762
33562
  this.fixAndSetPosition();
32763
- const [parentWidth, parentHeight] = this.parentDimensions;
32764
- this.setDims(this.width * parentWidth, this.height * parentHeight);
33563
+ this.setDims(this.width, this.height);
32765
33564
  };
32766
33565
  cleanDrawLayer_fn = function() {
32767
33566
  if (__privateGet(this, _id3) === null || !this.parent) {
@@ -32782,7 +33581,7 @@ addToDrawLayer_fn = function(parent = this.parent) {
32782
33581
  root: {
32783
33582
  viewBox: "0 0 1 1",
32784
33583
  fill: this.color,
32785
- "fill-opacity": __privateGet(this, _opacity)
33584
+ "fill-opacity": this.opacity
32786
33585
  },
32787
33586
  rootClass: {
32788
33587
  highlight: true,
@@ -32957,6 +33756,11 @@ var _DrawingEditor = class _DrawingEditor extends AnnotationEditor {
32957
33756
  __privateSet(this, _mustBeCommitted, params.mustBeCommitted || false);
32958
33757
  this._addOutlines(params);
32959
33758
  }
33759
+ /** @inheritdoc */
33760
+ onUpdatedColor() {
33761
+ this._colorPicker?.update(this.color);
33762
+ super.onUpdatedColor();
33763
+ }
32960
33764
  _addOutlines(params) {
32961
33765
  if (params.drawOutlines) {
32962
33766
  __privateMethod(this, _DrawingEditor_instances, createDrawOutlines_fn).call(this, params);
@@ -33056,7 +33860,7 @@ var _DrawingEditor = class _DrawingEditor extends AnnotationEditor {
33056
33860
  options.toSVGProperties()
33057
33861
  );
33058
33862
  if (type === this.colorType) {
33059
- this._colorPicker?.update(val);
33863
+ this.onUpdatedColor();
33060
33864
  }
33061
33865
  };
33062
33866
  this.addCommands({
@@ -33250,8 +34054,7 @@ var _DrawingEditor = class _DrawingEditor extends AnnotationEditor {
33250
34054
  div.append(drawDiv);
33251
34055
  drawDiv.setAttribute("aria-hidden", "true");
33252
34056
  drawDiv.className = "internal";
33253
- const [parentWidth, parentHeight] = this.parentDimensions;
33254
- this.setDims(this.width * parentWidth, this.height * parentHeight);
34057
+ this.setDims();
33255
34058
  this._uiManager.addShouldRescale(this);
33256
34059
  this.disableEditing();
33257
34060
  if (this._isCopy) {
@@ -33645,8 +34448,7 @@ updateBbox_fn = function(bbox) {
33645
34448
  [this.x, this.y, this.width, this.height] = __privateMethod(this, _DrawingEditor_instances, convertToParentSpace_fn).call(this, bbox);
33646
34449
  if (this.div) {
33647
34450
  this.fixAndSetPosition();
33648
- const [parentWidth, parentHeight] = this.parentDimensions;
33649
- this.setDims(this.width * parentWidth, this.height * parentHeight);
34451
+ this.setDims();
33650
34452
  }
33651
34453
  this._onResized();
33652
34454
  };
@@ -34573,7 +35375,10 @@ var _InkEditor = class _InkEditor extends DrawingEditor {
34573
35375
  opacity,
34574
35376
  borderStyle: { rawWidth: thickness },
34575
35377
  popupRef,
34576
- contentsObj
35378
+ richText,
35379
+ contentsObj,
35380
+ creationDate,
35381
+ modificationDate
34577
35382
  },
34578
35383
  parent: {
34579
35384
  page: { pageNumber }
@@ -34593,13 +35398,16 @@ var _InkEditor = class _InkEditor extends DrawingEditor {
34593
35398
  id: id2,
34594
35399
  deleted: false,
34595
35400
  popupRef,
34596
- comment: contentsObj?.str || null
35401
+ richText,
35402
+ comment: contentsObj?.str || null,
35403
+ creationDate,
35404
+ modificationDate
34597
35405
  };
34598
35406
  }
34599
35407
  const editor = await super.deserialize(data, parent, uiManager);
34600
35408
  editor._initialData = initialData;
34601
35409
  if (data.comment) {
34602
- editor.setCommentData(data.comment);
35410
+ editor.setCommentData(data);
34603
35411
  }
34604
35412
  return editor;
34605
35413
  }
@@ -34611,9 +35419,12 @@ var _InkEditor = class _InkEditor extends DrawingEditor {
34611
35419
  get colorType() {
34612
35420
  return AnnotationEditorParamsType.INK_COLOR;
34613
35421
  }
34614
- get colorValue() {
35422
+ get color() {
34615
35423
  return this._drawingOptions.stroke;
34616
35424
  }
35425
+ get opacity() {
35426
+ return this._drawingOptions["stroke-opacity"];
35427
+ }
34617
35428
  /** @inheritdoc */
34618
35429
  onScaleChanging() {
34619
35430
  if (!this.parent) {
@@ -34655,7 +35466,7 @@ var _InkEditor = class _InkEditor extends DrawingEditor {
34655
35466
  if (this.deleted) {
34656
35467
  return this.serializeDeleted();
34657
35468
  }
34658
- const { lines, points, rect } = this.serializeDraw(isForCopying);
35469
+ const { lines, points } = this.serializeDraw(isForCopying);
34659
35470
  const {
34660
35471
  _drawingOptions: {
34661
35472
  stroke,
@@ -34663,20 +35474,15 @@ var _InkEditor = class _InkEditor extends DrawingEditor {
34663
35474
  "stroke-width": thickness
34664
35475
  }
34665
35476
  } = this;
34666
- const serialized = {
34667
- annotationType: AnnotationEditorType.INK,
35477
+ const serialized = Object.assign(super.serialize(isForCopying), {
34668
35478
  color: AnnotationEditor._colorManager.convert(stroke),
34669
35479
  opacity,
34670
35480
  thickness,
34671
35481
  paths: {
34672
35482
  lines,
34673
35483
  points
34674
- },
34675
- pageIndex: this.pageIndex,
34676
- rect,
34677
- rotation: this.rotation,
34678
- structTreeParentId: this._structTreeParentId
34679
- };
35484
+ }
35485
+ });
34680
35486
  this.addComment(serialized);
34681
35487
  if (isForCopying) {
34682
35488
  serialized.isCopy = true;
@@ -34698,15 +35504,12 @@ var _InkEditor = class _InkEditor extends DrawingEditor {
34698
35504
  /* isForCopying = */
34699
35505
  false
34700
35506
  );
34701
- const params = {
35507
+ annotation.updateEdited({
34702
35508
  rect,
34703
35509
  thickness: this._drawingOptions["stroke-width"],
34704
- points
34705
- };
34706
- if (this.hasEditedComment) {
34707
- params.popup = this.comment;
34708
- }
34709
- annotation.updateEdited(params);
35510
+ points,
35511
+ popup: this.comment
35512
+ });
34710
35513
  return null;
34711
35514
  }
34712
35515
  };
@@ -35582,7 +36385,6 @@ var _SignatureEditor = class _SignatureEditor extends DrawingEditor {
35582
36385
  drawOutlines: outline,
35583
36386
  drawingOptions
35584
36387
  });
35585
- const [parentWidth, parentHeight] = this.parentDimensions;
35586
36388
  const [, pageHeight] = this.pageDimensions;
35587
36389
  let newHeight = heightInPage / pageHeight;
35588
36390
  newHeight = newHeight >= 1 ? 0.5 : newHeight;
@@ -35592,7 +36394,7 @@ var _SignatureEditor = class _SignatureEditor extends DrawingEditor {
35592
36394
  this.width = 0.9;
35593
36395
  }
35594
36396
  this.height = newHeight;
35595
- this.setDims(parentWidth * this.width, parentHeight * this.height);
36397
+ this.setDims();
35596
36398
  this.x = savedX;
35597
36399
  this.y = savedY;
35598
36400
  this.center();
@@ -35666,21 +36468,16 @@ var _SignatureEditor = class _SignatureEditor extends DrawingEditor {
35666
36468
  if (this.isEmpty()) {
35667
36469
  return null;
35668
36470
  }
35669
- const { lines, points, rect } = this.serializeDraw(isForCopying);
36471
+ const { lines, points } = this.serializeDraw(isForCopying);
35670
36472
  const {
35671
36473
  _drawingOptions: { "stroke-width": thickness }
35672
36474
  } = this;
35673
- const serialized = {
35674
- annotationType: AnnotationEditorType.SIGNATURE,
36475
+ const serialized = Object.assign(super.serialize(isForCopying), {
35675
36476
  isSignature: true,
35676
36477
  areContours: __privateGet(this, _isExtracted),
35677
36478
  color: [0, 0, 0],
35678
- thickness: __privateGet(this, _isExtracted) ? 0 : thickness,
35679
- pageIndex: this.pageIndex,
35680
- rect,
35681
- rotation: this.rotation,
35682
- structTreeParentId: this._structTreeParentId
35683
- };
36479
+ thickness: __privateGet(this, _isExtracted) ? 0 : thickness
36480
+ });
35684
36481
  this.addComment(serialized);
35685
36482
  if (isForCopying) {
35686
36483
  serialized.paths = { lines, points };
@@ -35974,7 +36771,7 @@ var StampEditor = class extends AnnotationEditor {
35974
36771
  let white = "white", black = "#cfcfd8";
35975
36772
  if (this._uiManager.hcmFilter !== "none") {
35976
36773
  black = "black";
35977
- } else if (window.matchMedia?.("(prefers-color-scheme: dark)").matches) {
36774
+ } else if (ColorScheme.isDarkMode) {
35978
36775
  white = "#8f8f9d";
35979
36776
  black = "#42414d";
35980
36777
  }
@@ -36051,7 +36848,17 @@ var StampEditor = class extends AnnotationEditor {
36051
36848
  let missingCanvas = false;
36052
36849
  if (data instanceof StampAnnotationElement) {
36053
36850
  const {
36054
- data: { rect: rect2, rotation, id: id2, structParent, popupRef, contentsObj },
36851
+ data: {
36852
+ rect: rect2,
36853
+ rotation,
36854
+ id: id2,
36855
+ structParent,
36856
+ popupRef,
36857
+ richText,
36858
+ contentsObj,
36859
+ creationDate,
36860
+ modificationDate
36861
+ },
36055
36862
  container,
36056
36863
  parent: {
36057
36864
  page: { pageNumber }
@@ -36088,7 +36895,10 @@ var StampEditor = class extends AnnotationEditor {
36088
36895
  isSvg: false,
36089
36896
  structParent,
36090
36897
  popupRef,
36091
- comment: contentsObj?.str || null
36898
+ richText,
36899
+ comment: contentsObj?.str || null,
36900
+ creationDate,
36901
+ modificationDate
36092
36902
  };
36093
36903
  }
36094
36904
  const editor = await super.deserialize(data, parent, uiManager);
@@ -36113,7 +36923,7 @@ var StampEditor = class extends AnnotationEditor {
36113
36923
  }
36114
36924
  editor._initialData = initialData;
36115
36925
  if (data.comment) {
36116
- editor.setCommentData(data.comment);
36926
+ editor.setCommentData(data);
36117
36927
  }
36118
36928
  __privateSet(editor, _hasBeenAddedInUndoStack, !!initialData);
36119
36929
  return editor;
@@ -36126,15 +36936,10 @@ var StampEditor = class extends AnnotationEditor {
36126
36936
  if (this.deleted) {
36127
36937
  return this.serializeDeleted();
36128
36938
  }
36129
- const serialized = {
36130
- annotationType: AnnotationEditorType.STAMP,
36939
+ const serialized = Object.assign(super.serialize(isForCopying), {
36131
36940
  bitmapId: __privateGet(this, _bitmapId),
36132
- pageIndex: this.pageIndex,
36133
- rect: this.getPDFRect(),
36134
- rotation: this.rotation,
36135
- isSvg: __privateGet(this, _isSvg),
36136
- structTreeParentId: this._structTreeParentId
36137
- };
36941
+ isSvg: __privateGet(this, _isSvg)
36942
+ });
36138
36943
  this.addComment(serialized);
36139
36944
  if (isForCopying) {
36140
36945
  serialized.bitmapUrl = __privateMethod(this, _StampEditor_instances, serializeBitmap_fn).call(
@@ -36160,8 +36965,10 @@ var StampEditor = class extends AnnotationEditor {
36160
36965
  } else {
36161
36966
  serialized.accessibilityData.structParent = this._initialData.structParent ?? -1;
36162
36967
  }
36968
+ serialized.id = this.annotationElementId;
36969
+ delete serialized.bitmapId;
36970
+ return serialized;
36163
36971
  }
36164
- serialized.id = this.annotationElementId;
36165
36972
  if (context === null) {
36166
36973
  return serialized;
36167
36974
  }
@@ -36194,13 +37001,10 @@ var StampEditor = class extends AnnotationEditor {
36194
37001
  annotation.hide();
36195
37002
  return null;
36196
37003
  }
36197
- const params = {
36198
- rect: this.getPDFRect()
36199
- };
36200
- if (this.hasEditedComment) {
36201
- params.popup = this.comment;
36202
- }
36203
- annotation.updateEdited(params);
37004
+ annotation.updateEdited({
37005
+ rect: this.getPDFRect(),
37006
+ popup: this.comment
37007
+ });
36204
37008
  return null;
36205
37009
  }
36206
37010
  };
@@ -36347,17 +37151,13 @@ createCanvas_fn = function() {
36347
37151
  width *= factor;
36348
37152
  height *= factor;
36349
37153
  }
36350
- const [parentWidth, parentHeight] = this.parentDimensions;
36351
- this.setDims(
36352
- width * parentWidth / pageWidth,
36353
- height * parentHeight / pageHeight
36354
- );
36355
37154
  this._uiManager.enableWaiting(false);
36356
37155
  const canvas = __privateSet(this, _canvas, document.createElement("canvas"));
36357
37156
  canvas.setAttribute("role", "img");
36358
37157
  this.addContainer(canvas);
36359
37158
  this.width = width / pageWidth;
36360
37159
  this.height = height / pageHeight;
37160
+ this.setDims();
36361
37161
  if (this._initialOptions?.isCentered) {
36362
37162
  this.center();
36363
37163
  } else {
@@ -36495,7 +37295,7 @@ __publicField(StampEditor, "_type", "stamp");
36495
37295
  __publicField(StampEditor, "_editorType", AnnotationEditorType.STAMP);
36496
37296
 
36497
37297
  // src/pdf.js/src/display/editor/annotation_editor_layer.js
36498
- var _accessibilityManager2, _allowClick, _annotationLayer, _clickAC, _editorFocusTimeoutId, _editors, _hadPointerDown, _isDisabling, _isEnabling, _drawingAC, _focusedElement, _textLayer, _textSelectionAC, _textLayerDblClickAC, _lastPointerDownTimestamp, _uiManager4, _editorTypes2, _AnnotationEditorLayer_instances, textLayerPointerDown_fn, currentEditorType_get, createNewEditor_fn, getCenterPoint_fn, cleanup_fn;
37298
+ var _accessibilityManager2, _allowClick, _annotationLayer, _clickAC, _editorFocusTimeoutId, _editors, _hadPointerDown, _isDisabling, _isEnabling, _drawingAC, _focusedElement, _textLayer, _textSelectionAC, _textLayerDblClickAC, _lastPointerDownTimestamp, _uiManager4, _editorTypes2, _AnnotationEditorLayer_instances, allEditorsIterator_get, textLayerPointerDown_fn, currentEditorType_get, createNewEditor_fn, getCenterPoint_fn, cleanup_fn;
36499
37299
  var _AnnotationEditorLayer = class _AnnotationEditorLayer {
36500
37300
  /**
36501
37301
  * @param {AnnotationEditorLayerOptions} options
@@ -36569,6 +37369,7 @@ var _AnnotationEditorLayer = class _AnnotationEditorLayer {
36569
37369
  __privateMethod(this, _AnnotationEditorLayer_instances, cleanup_fn).call(this);
36570
37370
  switch (mode) {
36571
37371
  case AnnotationEditorType.NONE:
37372
+ this.div.classList.toggle("nonEditing", true);
36572
37373
  this.disableTextSelection();
36573
37374
  this.togglePointerEvents(false);
36574
37375
  this.toggleAnnotationLayerPointerEvents(true);
@@ -36591,11 +37392,17 @@ var _AnnotationEditorLayer = class _AnnotationEditorLayer {
36591
37392
  }
36592
37393
  this.toggleAnnotationLayerPointerEvents(false);
36593
37394
  const { classList } = this.div;
36594
- for (const editorType of __privateGet(_AnnotationEditorLayer, _editorTypes2).values()) {
36595
- classList.toggle(
36596
- `${editorType._type}Editing`,
36597
- mode === editorType._editorType
36598
- );
37395
+ classList.toggle("nonEditing", false);
37396
+ if (mode === AnnotationEditorType.POPUP) {
37397
+ classList.toggle("commentEditing", true);
37398
+ } else {
37399
+ classList.toggle("commentEditing", false);
37400
+ for (const editorType of __privateGet(_AnnotationEditorLayer, _editorTypes2).values()) {
37401
+ classList.toggle(
37402
+ `${editorType._type}Editing`,
37403
+ mode === editorType._editorType
37404
+ );
37405
+ }
36599
37406
  }
36600
37407
  this.div.hidden = false;
36601
37408
  }
@@ -36636,10 +37443,11 @@ var _AnnotationEditorLayer = class _AnnotationEditorLayer {
36636
37443
  __privateSet(this, _isEnabling, true);
36637
37444
  this.div.tabIndex = 0;
36638
37445
  this.togglePointerEvents(true);
37446
+ this.div.classList.toggle("nonEditing", false);
36639
37447
  __privateGet(this, _textLayerDblClickAC)?.abort();
36640
37448
  __privateSet(this, _textLayerDblClickAC, null);
36641
37449
  const annotationElementIds = /* @__PURE__ */ new Set();
36642
- for (const editor of __privateGet(this, _editors).values()) {
37450
+ for (const editor of __privateGet(this, _AnnotationEditorLayer_instances, allEditorsIterator_get)) {
36643
37451
  editor.enableEditing();
36644
37452
  editor.show(true);
36645
37453
  if (editor.annotationElementId) {
@@ -36647,27 +37455,29 @@ var _AnnotationEditorLayer = class _AnnotationEditorLayer {
36647
37455
  annotationElementIds.add(editor.annotationElementId);
36648
37456
  }
36649
37457
  }
36650
- if (!__privateGet(this, _annotationLayer)) {
36651
- __privateSet(this, _isEnabling, false);
36652
- return;
36653
- }
36654
- const editables = __privateGet(this, _annotationLayer).getEditableAnnotations();
36655
- for (const editable of editables) {
36656
- editable.hide();
36657
- if (__privateGet(this, _uiManager4).isDeletedAnnotationElement(editable.data.id)) {
36658
- continue;
36659
- }
36660
- if (annotationElementIds.has(editable.data.id)) {
36661
- continue;
36662
- }
36663
- const editor = await this.deserialize(editable);
36664
- if (!editor) {
36665
- continue;
37458
+ const annotationLayer = __privateGet(this, _annotationLayer);
37459
+ if (annotationLayer) {
37460
+ for (const editable of annotationLayer.getEditableAnnotations()) {
37461
+ editable.hide();
37462
+ if (__privateGet(this, _uiManager4).isDeletedAnnotationElement(editable.data.id)) {
37463
+ continue;
37464
+ }
37465
+ if (annotationElementIds.has(editable.data.id)) {
37466
+ continue;
37467
+ }
37468
+ const editor = await this.deserialize(editable);
37469
+ if (!editor) {
37470
+ continue;
37471
+ }
37472
+ this.addOrRebuild(editor);
37473
+ editor.enableEditing();
36666
37474
  }
36667
- this.addOrRebuild(editor);
36668
- editor.enableEditing();
36669
37475
  }
36670
37476
  __privateSet(this, _isEnabling, false);
37477
+ __privateGet(this, _uiManager4)._eventBus.dispatch("editorsrendered", {
37478
+ source: this,
37479
+ pageNumber: this.pageIndex + 1
37480
+ });
36671
37481
  }
36672
37482
  /**
36673
37483
  * Disable editor creation.
@@ -36676,6 +37486,7 @@ var _AnnotationEditorLayer = class _AnnotationEditorLayer {
36676
37486
  __privateSet(this, _isDisabling, true);
36677
37487
  this.div.tabIndex = -1;
36678
37488
  this.togglePointerEvents(false);
37489
+ this.div.classList.toggle("nonEditing", true);
36679
37490
  if (__privateGet(this, _textLayer) && !__privateGet(this, _textLayerDblClickAC)) {
36680
37491
  __privateSet(this, _textLayerDblClickAC, new AbortController());
36681
37492
  const signal = __privateGet(this, _uiManager4).combinedSignal(__privateGet(this, _textLayerDblClickAC));
@@ -36712,30 +37523,32 @@ var _AnnotationEditorLayer = class _AnnotationEditorLayer {
36712
37523
  if (editor?.annotationElementId === null) {
36713
37524
  e.stopPropagation();
36714
37525
  e.preventDefault();
36715
- editor.dblclick();
37526
+ editor.dblclick(e);
36716
37527
  }
36717
37528
  },
36718
37529
  { signal, capture: true }
36719
37530
  );
36720
37531
  }
36721
- const changedAnnotations = /* @__PURE__ */ new Map();
36722
- const resetAnnotations = /* @__PURE__ */ new Map();
36723
- for (const editor of __privateGet(this, _editors).values()) {
36724
- editor.disableEditing();
36725
- if (!editor.annotationElementId) {
36726
- continue;
36727
- }
36728
- if (editor.serialize() !== null) {
36729
- changedAnnotations.set(editor.annotationElementId, editor);
36730
- continue;
36731
- } else {
36732
- resetAnnotations.set(editor.annotationElementId, editor);
37532
+ const annotationLayer = __privateGet(this, _annotationLayer);
37533
+ if (annotationLayer) {
37534
+ const changedAnnotations = /* @__PURE__ */ new Map();
37535
+ const resetAnnotations = /* @__PURE__ */ new Map();
37536
+ for (const editor of __privateGet(this, _AnnotationEditorLayer_instances, allEditorsIterator_get)) {
37537
+ editor.disableEditing();
37538
+ if (!editor.annotationElementId) {
37539
+ editor.updateFakeAnnotationElement(annotationLayer);
37540
+ continue;
37541
+ }
37542
+ if (editor.serialize() !== null) {
37543
+ changedAnnotations.set(editor.annotationElementId, editor);
37544
+ continue;
37545
+ } else {
37546
+ resetAnnotations.set(editor.annotationElementId, editor);
37547
+ }
37548
+ this.getEditableAnnotation(editor.annotationElementId)?.show();
37549
+ editor.remove();
36733
37550
  }
36734
- this.getEditableAnnotation(editor.annotationElementId)?.show();
36735
- editor.remove();
36736
- }
36737
- if (__privateGet(this, _annotationLayer)) {
36738
- const editables = __privateGet(this, _annotationLayer).getEditableAnnotations();
37551
+ const editables = annotationLayer.getEditableAnnotations();
36739
37552
  for (const editable of editables) {
36740
37553
  const { id: id2 } = editable.data;
36741
37554
  if (__privateGet(this, _uiManager4).isDeletedAnnotationElement(id2)) {
@@ -36948,6 +37761,14 @@ var _AnnotationEditorLayer = class _AnnotationEditorLayer {
36948
37761
  };
36949
37762
  this.addCommands({ cmd, undo, mustExec: false });
36950
37763
  }
37764
+ getEditorByUID(uid) {
37765
+ for (const editor of __privateGet(this, _editors).values()) {
37766
+ if (editor.uid === uid) {
37767
+ return editor;
37768
+ }
37769
+ }
37770
+ return null;
37771
+ }
36951
37772
  /**
36952
37773
  * Get an id for an editor.
36953
37774
  * @returns {string}
@@ -36987,7 +37808,7 @@ var _AnnotationEditorLayer = class _AnnotationEditorLayer {
36987
37808
  /**
36988
37809
  * Create a new editor
36989
37810
  * @param {Object} data
36990
- * @returns {AnnotationEditor | null}
37811
+ * @returns {Promise<AnnotationEditor | null>}
36991
37812
  */
36992
37813
  async deserialize(data) {
36993
37814
  return await __privateGet(_AnnotationEditorLayer, _editorTypes2).get(data.annotationType ?? data.annotationEditorType)?.deserialize(data, this, __privateGet(this, _uiManager4)) || null;
@@ -37015,6 +37836,9 @@ var _AnnotationEditorLayer = class _AnnotationEditorLayer {
37015
37836
  }
37016
37837
  return editor;
37017
37838
  }
37839
+ get boundingClientRect() {
37840
+ return this.div.getBoundingClientRect();
37841
+ }
37018
37842
  /**
37019
37843
  * Create and add a new editor.
37020
37844
  */
@@ -37267,6 +38091,9 @@ _lastPointerDownTimestamp = new WeakMap();
37267
38091
  _uiManager4 = new WeakMap();
37268
38092
  _editorTypes2 = new WeakMap();
37269
38093
  _AnnotationEditorLayer_instances = new WeakSet();
38094
+ allEditorsIterator_get = function() {
38095
+ return __privateGet(this, _editors).size !== 0 ? __privateGet(this, _editors).values() : __privateGet(this, _uiManager4).getEditors(this.pageIndex);
38096
+ };
37270
38097
  textLayerPointerDown_fn = function(event) {
37271
38098
  __privateGet(this, _uiManager4).unselectAll();
37272
38099
  const { target } = event;
@@ -37312,7 +38139,7 @@ createNewEditor_fn = function(params) {
37312
38139
  return editorType ? new editorType.prototype.constructor(params) : null;
37313
38140
  };
37314
38141
  getCenterPoint_fn = function() {
37315
- const { x, y, width, height } = this.div.getBoundingClientRect();
38142
+ const { x, y, width, height } = this.boundingClientRect;
37316
38143
  const tlX = Math.max(0, x);
37317
38144
  const tlY = Math.max(0, y);
37318
38145
  const brX = Math.min(window.innerWidth, x + width);
@@ -37559,13 +38386,16 @@ globalThis.pdfjsLib = {
37559
38386
  AnnotationLayer,
37560
38387
  AnnotationMode,
37561
38388
  AnnotationType,
38389
+ applyOpacity,
37562
38390
  build,
37563
38391
  ColorPicker,
37564
38392
  createValidAbsoluteUrl,
38393
+ CSSConstants,
37565
38394
  DOMSVGFactory,
37566
38395
  DrawLayer,
37567
38396
  FeatureTest,
37568
38397
  fetchData,
38398
+ findContrastColor,
37569
38399
  getDocument,
37570
38400
  getFilenameFromUrl,
37571
38401
  getPdfFilenameFromUrl,
@@ -37590,6 +38420,7 @@ globalThis.pdfjsLib = {
37590
38420
  PermissionFlag,
37591
38421
  PixelsPerInch,
37592
38422
  RenderingCancelledException,
38423
+ renderRichText,
37593
38424
  ResponseException,
37594
38425
  setLayerDimensions,
37595
38426
  shadow,
@@ -39003,7 +39834,7 @@ function destroySvgContext(ctx) {
39003
39834
 
39004
39835
  // src/lib/PDFPageProxy.ts
39005
39836
  async function loadNodeCanvasFactory() {
39006
- const { NodeCanvasFactory: NodeCanvasFactory2 } = await import("./NodeUtils-ZPPZPJWD.js");
39837
+ const { NodeCanvasFactory: NodeCanvasFactory2 } = await import("./NodeUtils-PVXQMWFJ.js");
39007
39838
  return new NodeCanvasFactory2({});
39008
39839
  }
39009
39840
  var getAnnotations = PDFPageProxy.prototype.getAnnotations;
@@ -39392,6 +40223,94 @@ var MAX_TEXT_DIVS_TO_RENDER2 = 1e5;
39392
40223
  var DEFAULT_FONT_SIZE3 = 30;
39393
40224
  var DEFAULT_FONT_ASCENT = 0.8;
39394
40225
  var HYPHEN_REGEX = /-\n+$/;
40226
+ var renderTextLayer = (root, options = {}) => {
40227
+ const { classes = false, styles = false } = options;
40228
+ const serializeAttributes = (attrs) => {
40229
+ return Object.entries(attrs).filter(([_, value]) => value != null).map(([key, value]) => `${key}="${value}"`).join(" ");
40230
+ };
40231
+ const serializeStyles = (styles2) => {
40232
+ return Object.entries(styles2).filter(([_, value]) => value != null).map(([key, value]) => `${key}: ${value};`).join(" ");
40233
+ };
40234
+ const internalRenderNode = (node, parents = []) => {
40235
+ if (typeof node === "string") {
40236
+ return node;
40237
+ }
40238
+ if (isTextNode(node)) {
40239
+ const isHeading = parents.find((p) => p.role.match(/^h[1-6]$/));
40240
+ const tag2 = isHeading ? "span" : node.fontWeight >= 700 ? "strong" : node.fontStyle === "italic" ? "em" : "span";
40241
+ const serializedAttrs2 = serializeAttributes(
40242
+ classes ? {
40243
+ class: "tl-text"
40244
+ } : {}
40245
+ );
40246
+ const serializedStyle = styles ? serializeStyles({
40247
+ "--tl-left": `${node.left}px`,
40248
+ "--tl-top": `${node.top}px`,
40249
+ "--tl-font-size": `${node.fontSize}px`,
40250
+ "--tl-font-style": node.fontStyle,
40251
+ "--tl-font-weight": node.fontWeight,
40252
+ "--tl-transform": [
40253
+ typeof node.scale === "number" && node.scale !== 1 ? `scaleX(${node.scale})` : null,
40254
+ typeof node.angle === "number" && node.angle !== 0 ? `rotate(${node.angle}deg)` : null
40255
+ ].filter((v) => v !== null).join(" ")
40256
+ }) : "";
40257
+ let contents;
40258
+ if (typeof node.text === "string") {
40259
+ contents = node.text;
40260
+ } else {
40261
+ contents = node.text.map((chunk) => {
40262
+ const tag3 = !isHeading && node.fontWeight >= 700 && node.fontStyle === "italic";
40263
+ const serializedAttrs3 = serializeAttributes(
40264
+ classes ? {
40265
+ class: "tl-span"
40266
+ } : {}
40267
+ );
40268
+ const serializedStyle2 = styles ? serializeStyles({
40269
+ "--tl-left": `${chunk.left}px`,
40270
+ "--tl-top": `${chunk.top}px`,
40271
+ "--tl-transform": typeof chunk.scale === "number" && chunk.scale !== 1 ? `scaleX(${chunk.scale ?? 1})` : null
40272
+ }) : "";
40273
+ return `<${tag3}${serializedAttrs3 ? ` ${serializedAttrs3}` : ""}${serializedStyle2 ? ` style="${serializedStyle2}` : ""}">${chunk.text}</${tag3}>`;
40274
+ }).join("");
40275
+ }
40276
+ return `<${tag2}${serializedAttrs2 ? ` ${serializedAttrs2}` : ""}${serializedStyle ? ` style="${serializedStyle}"` : ""}>${contents}</${tag2}>`;
40277
+ }
40278
+ if (isAnchorNode(node)) {
40279
+ return `<a href="${node.href}" target="_blank" rel="noopener noreferrer nofollow">
40280
+ ${node.children.map((child) => internalRenderNode(child, [...parents, node])).join("")}
40281
+ </a>`;
40282
+ }
40283
+ const attrs = {};
40284
+ if (classes) {
40285
+ if (isElementNode(node)) {
40286
+ attrs.class = "tl-element";
40287
+ } else {
40288
+ attrs.class = "tl-node";
40289
+ }
40290
+ }
40291
+ switch (node.role) {
40292
+ case "th":
40293
+ case "td": {
40294
+ if (node.attrs?.ColSpan) {
40295
+ attrs.colspan = node.attrs.ColSpan;
40296
+ }
40297
+ if (node.attrs?.RowSpan) {
40298
+ attrs.rowspan = node.attrs.RowSpan;
40299
+ }
40300
+ break;
40301
+ }
40302
+ }
40303
+ const tag = node.role === "root" ? "article" : node.role;
40304
+ const serializedAttrs = serializeAttributes(attrs);
40305
+ if (!isElementNode(node)) {
40306
+ return `<${tag}${serializedAttrs ? ` ${serializedAttrs}` : ""}></${tag}>`;
40307
+ }
40308
+ return `<${tag}${serializedAttrs ? ` ${serializedAttrs}` : ""}>
40309
+ ${node.children.map((child) => internalRenderNode(child, [...parents, node])).join("")}
40310
+ </${tag}>`;
40311
+ };
40312
+ return internalRenderNode(root);
40313
+ };
39395
40314
  var decorateStructTree = (node, rootContainer, graphics, annotations, parents = []) => {
39396
40315
  let parent = parents.at(-1) || rootContainer;
39397
40316
  if ("role" in node) {
@@ -39896,7 +40815,7 @@ var WasmFactory = class {
39896
40815
  }) {
39897
40816
  switch (filename) {
39898
40817
  case "openjpeg.wasm":
39899
- return import("./openjpeg-TRZ4ANDN.js").then(
40818
+ return import("./openjpeg-QFJSFVSJ.js").then(
39900
40819
  (module) => module.default
39901
40820
  );
39902
40821
  case "qcms_bg":
@@ -40359,6 +41278,7 @@ export {
40359
41278
  AnnotationLayer,
40360
41279
  AnnotationMode,
40361
41280
  AnnotationType,
41281
+ CSSConstants,
40362
41282
  ColorPicker,
40363
41283
  DOMSVGFactory,
40364
41284
  DrawLayer,
@@ -40389,6 +41309,7 @@ export {
40389
41309
  VerbosityLevel,
40390
41310
  WasmFactory,
40391
41311
  XfaLayer,
41312
+ applyOpacity,
40392
41313
  build,
40393
41314
  canvasToData,
40394
41315
  colorToRgb,
@@ -40399,6 +41320,7 @@ export {
40399
41320
  createValidAbsoluteUrl,
40400
41321
  destroySvgContext,
40401
41322
  fetchData,
41323
+ findContrastColor,
40402
41324
  getDocument,
40403
41325
  getFilenameFromUrl,
40404
41326
  getPdfFilenameFromUrl,
@@ -40452,7 +41374,9 @@ export {
40452
41374
  noContextMenu,
40453
41375
  normalizeUnicode,
40454
41376
  parseRgbaColor,
41377
+ renderRichText,
40455
41378
  renderSvgNode,
41379
+ renderTextLayer,
40456
41380
  rgbToHex,
40457
41381
  setLayerDimensions,
40458
41382
  shadow,