@chialab/pdfjs-lib 1.0.0-alpha.15 → 1.0.0-alpha.17

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.
@@ -8,6 +8,7 @@ import {
8
8
  AnnotationPrefix,
9
9
  AnnotationType,
10
10
  BaseException,
11
+ ColorConverters,
11
12
  DrawOPS,
12
13
  FONT_IDENTITY_MATRIX,
13
14
  FeatureTest,
@@ -45,7 +46,7 @@ import {
45
46
  updateUrlHash,
46
47
  warn,
47
48
  wrapReason
48
- } from "./chunk-MAMMG4XK.js";
49
+ } from "./chunk-4FQTXXTH.js";
49
50
  import {
50
51
  __privateAdd,
51
52
  __privateGet,
@@ -301,22 +302,71 @@ function getPdfFilenameFromUrl(url, defaultFilename = "document.pdf") {
301
302
  warn('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.');
302
303
  return defaultFilename;
303
304
  }
304
- const reURI = /^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
305
- const reFilename = /[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
306
- const splitURI = reURI.exec(url);
307
- let suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
308
- if (suggestedFilename) {
309
- suggestedFilename = suggestedFilename[0];
310
- if (suggestedFilename.includes("%")) {
305
+ const getURL = (urlString) => {
306
+ try {
307
+ return new URL(urlString);
308
+ } catch {
311
309
  try {
312
- suggestedFilename = reFilename.exec(
313
- decodeURIComponent(suggestedFilename)
314
- )[0];
310
+ return new URL(decodeURIComponent(urlString));
315
311
  } catch {
312
+ try {
313
+ return new URL(urlString, "https://foo.bar");
314
+ } catch {
315
+ try {
316
+ return new URL(decodeURIComponent(urlString), "https://foo.bar");
317
+ } catch {
318
+ return null;
319
+ }
320
+ }
321
+ }
322
+ }
323
+ };
324
+ const newURL = getURL(url);
325
+ if (!newURL) {
326
+ return defaultFilename;
327
+ }
328
+ const decode = (name) => {
329
+ try {
330
+ let decoded = decodeURIComponent(name);
331
+ if (decoded.includes("/")) {
332
+ decoded = decoded.split("/").at(-1);
333
+ if (decoded.test(/^\.pdf$/i)) {
334
+ return decoded;
335
+ }
336
+ return name;
337
+ }
338
+ return decoded;
339
+ } catch {
340
+ return name;
341
+ }
342
+ };
343
+ const pdfRegex = /\.pdf$/i;
344
+ const filename = newURL.pathname.split("/").at(-1);
345
+ if (pdfRegex.test(filename)) {
346
+ return decode(filename);
347
+ }
348
+ if (newURL.searchParams.size > 0) {
349
+ const values = Array.from(newURL.searchParams.values()).reverse();
350
+ for (const value of values) {
351
+ if (pdfRegex.test(value)) {
352
+ return decode(value);
353
+ }
354
+ }
355
+ const keys = Array.from(newURL.searchParams.keys()).reverse();
356
+ for (const key of keys) {
357
+ if (pdfRegex.test(key)) {
358
+ return decode(key);
316
359
  }
317
360
  }
318
361
  }
319
- return suggestedFilename || defaultFilename;
362
+ if (newURL.hash) {
363
+ const reFilename = /[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
364
+ const hashFilename = reFilename.exec(newURL.hash);
365
+ if (hashFilename) {
366
+ return decode(hashFilename[0]);
367
+ }
368
+ }
369
+ return defaultFilename;
320
370
  }
321
371
  var StatTimer = class {
322
372
  constructor() {
@@ -570,7 +620,7 @@ var SupportedImageMimeTypes = [
570
620
  ];
571
621
 
572
622
  // src/pdf.js/src/display/editor/toolbar.js
573
- var _toolbar, _colorPicker, _editor, _buttons, _altText, _signatureDescriptionButton, _l10nRemove, _EditorToolbar_static, pointerDown_fn, _EditorToolbar_instances, focusIn_fn, focusOut_fn, addListenersToElement_fn, addDeleteButton_fn, divider_get;
623
+ var _toolbar, _colorPicker, _editor, _buttons, _altText, _signatureDescriptionButton, _l10nRemove, _EditorToolbar_static, pointerDown_fn, _EditorToolbar_instances, focusIn_fn, focusOut_fn, addListenersToElement_fn, divider_get;
574
624
  var _EditorToolbar = class _EditorToolbar {
575
625
  constructor(editor) {
576
626
  __privateAdd(this, _EditorToolbar_instances);
@@ -608,7 +658,6 @@ var _EditorToolbar = class _EditorToolbar {
608
658
  style.insetInlineEnd = `${100 * x}%`;
609
659
  style.top = `calc(${100 * position[1]}% + var(--editor-toolbar-vert-offset))`;
610
660
  }
611
- __privateMethod(this, _EditorToolbar_instances, addDeleteButton_fn).call(this);
612
661
  return editToolbar;
613
662
  }
614
663
  get div() {
@@ -622,22 +671,54 @@ var _EditorToolbar = class _EditorToolbar {
622
671
  __privateGet(this, _toolbar).classList.remove("hidden");
623
672
  __privateGet(this, _altText)?.shown();
624
673
  }
674
+ addDeleteButton() {
675
+ const { editorType, _uiManager: _uiManager4 } = __privateGet(this, _editor);
676
+ const button = document.createElement("button");
677
+ button.className = "delete";
678
+ button.tabIndex = 0;
679
+ button.setAttribute("data-l10n-id", __privateGet(_EditorToolbar, _l10nRemove)[editorType]);
680
+ __privateMethod(this, _EditorToolbar_instances, addListenersToElement_fn).call(this, button);
681
+ button.addEventListener(
682
+ "click",
683
+ (e) => {
684
+ _uiManager4.delete();
685
+ },
686
+ { signal: _uiManager4._signal }
687
+ );
688
+ __privateGet(this, _buttons).append(button);
689
+ }
625
690
  async addAltText(altText) {
626
691
  const button = await altText.render();
627
692
  __privateMethod(this, _EditorToolbar_instances, addListenersToElement_fn).call(this, button);
628
- __privateGet(this, _buttons).prepend(button, __privateGet(this, _EditorToolbar_instances, divider_get));
693
+ __privateGet(this, _buttons).append(button, __privateGet(this, _EditorToolbar_instances, divider_get));
629
694
  __privateSet(this, _altText, altText);
630
695
  }
631
696
  addColorPicker(colorPicker) {
632
697
  __privateSet(this, _colorPicker, colorPicker);
633
698
  const button = colorPicker.renderButton();
634
699
  __privateMethod(this, _EditorToolbar_instances, addListenersToElement_fn).call(this, button);
635
- __privateGet(this, _buttons).prepend(button, __privateGet(this, _EditorToolbar_instances, divider_get));
700
+ __privateGet(this, _buttons).append(button, __privateGet(this, _EditorToolbar_instances, divider_get));
636
701
  }
637
702
  async addEditSignatureButton(signatureManager) {
638
703
  const button = __privateSet(this, _signatureDescriptionButton, await signatureManager.renderEditButton(__privateGet(this, _editor)));
639
704
  __privateMethod(this, _EditorToolbar_instances, addListenersToElement_fn).call(this, button);
640
- __privateGet(this, _buttons).prepend(button, __privateGet(this, _EditorToolbar_instances, divider_get));
705
+ __privateGet(this, _buttons).append(button, __privateGet(this, _EditorToolbar_instances, divider_get));
706
+ }
707
+ async addButton(name, tool) {
708
+ switch (name) {
709
+ case "colorPicker":
710
+ this.addColorPicker(tool);
711
+ break;
712
+ case "altText":
713
+ await this.addAltText(tool);
714
+ break;
715
+ case "editSignature":
716
+ await this.addEditSignatureButton(tool);
717
+ break;
718
+ case "delete":
719
+ this.addDeleteButton();
720
+ break;
721
+ }
641
722
  }
642
723
  updateEditSignatureButton(description) {
643
724
  if (__privateGet(this, _signatureDescriptionButton)) {
@@ -682,22 +763,6 @@ addListenersToElement_fn = function(element) {
682
763
  });
683
764
  element.addEventListener("contextmenu", noContextMenu, { signal });
684
765
  };
685
- addDeleteButton_fn = function() {
686
- const { editorType, _uiManager: _uiManager4 } = __privateGet(this, _editor);
687
- const button = document.createElement("button");
688
- button.className = "delete";
689
- button.tabIndex = 0;
690
- button.setAttribute("data-l10n-id", __privateGet(_EditorToolbar, _l10nRemove)[editorType]);
691
- __privateMethod(this, _EditorToolbar_instances, addListenersToElement_fn).call(this, button);
692
- button.addEventListener(
693
- "click",
694
- (e) => {
695
- _uiManager4.delete();
696
- },
697
- { signal: _uiManager4._signal }
698
- );
699
- __privateGet(this, _buttons).append(button);
700
- };
701
766
  divider_get = function() {
702
767
  const divider = document.createElement("div");
703
768
  divider.className = "divider";
@@ -1242,9 +1307,9 @@ __publicField(_ColorManager, "_colorsMapping", /* @__PURE__ */ new Map([
1242
1307
  ["Canvas", [255, 255, 255]]
1243
1308
  ]));
1244
1309
  var ColorManager = _ColorManager;
1245
- var _abortController, _activeEditor, _allEditors, _allLayers, _altTextManager, _annotationStorage, _changedExistingAnnotations, _commandManager, _copyPasteAC, _currentDrawingSession, _currentPageIndex, _deletedAnnotationsElementIds, _draggingEditors, _editorTypes, _editorsToRescale, _enableHighlightFloatingButton, _enableUpdatedAddImage, _enableNewAltTextWhenAddingImage, _filterFactory, _focusMainContainerTimeoutId, _focusManagerAC, _highlightColors, _highlightWhenShiftUp, _highlightToolbar, _idManager, _isEnabled, _isWaiting, _keyboardManagerAC, _lastActiveElement, _mainHighlightColorPicker, _missingCanvases, _mlManager, _mode, _selectedEditors, _selectedTextNode, _signatureManager, _pageColors, _showAllStates, _previousStates, _translation, _translationTimeoutId, _container, _viewer, _updateModeCapability, _AnnotationEditorUIManager_instances, getAnchorElementForSelection_fn, getLayerForTextLayer_fn, displayHighlightToolbar_fn, selectionChange_fn, onSelectEnd_fn, addSelectionListener_fn, addFocusManager_fn, removeFocusManager_fn, addKeyboardManager_fn, removeKeyboardManager_fn, addCopyPasteListeners_fn, removeCopyPasteListeners_fn, addDragAndDropListeners_fn, dispatchUpdateStates_fn, dispatchUpdateUI_fn, enableAll_fn, disableAll_fn, addEditorToLayer_fn, lastSelectedEditor_get, isEmpty_fn, selectEditors_fn;
1310
+ var _abortController, _activeEditor, _allEditors, _allLayers, _altTextManager, _annotationStorage, _changedExistingAnnotations, _commandManager, _copyPasteAC, _currentDrawingSession, _currentPageIndex, _deletedAnnotationsElementIds, _draggingEditors, _editorTypes, _editorsToRescale, _enableHighlightFloatingButton, _enableUpdatedAddImage, _enableNewAltTextWhenAddingImage, _filterFactory, _focusMainContainerTimeoutId, _focusManagerAC, _highlightColors, _highlightWhenShiftUp, _highlightToolbar, _idManager, _isEnabled, _isWaiting, _keyboardManagerAC, _lastActiveElement, _mainHighlightColorPicker, _missingCanvases, _mlManager, _mode, _selectedEditors, _selectedTextNode, _signatureManager, _pageColors, _showAllStates, _previousStates, _translation, _translationTimeoutId, _container, _viewer, _viewerAlert, _updateModeCapability, _AnnotationEditorUIManager_instances, getAnchorElementForSelection_fn, getLayerForTextLayer_fn, displayHighlightToolbar_fn, selectionChange_fn, onSelectEnd_fn, addSelectionListener_fn, addFocusManager_fn, removeFocusManager_fn, addKeyboardManager_fn, removeKeyboardManager_fn, addCopyPasteListeners_fn, removeCopyPasteListeners_fn, addDragAndDropListeners_fn, dispatchUpdateStates_fn, dispatchUpdateUI_fn, enableAll_fn, disableAll_fn, addEditorToLayer_fn, lastSelectedEditor_get, isEmpty_fn, selectEditors_fn;
1246
1311
  var _AnnotationEditorUIManager = class _AnnotationEditorUIManager {
1247
- constructor(container, viewer, altTextManager, signatureManager, eventBus, pdfDocument, pageColors, highlightColors, enableHighlightFloatingButton, enableUpdatedAddImage, enableNewAltTextWhenAddingImage, mlManager, editorUndoBar, supportsPinchToZoom) {
1312
+ constructor(container, viewer, viewerAlert, altTextManager, signatureManager, eventBus, pdfDocument, pageColors, highlightColors, enableHighlightFloatingButton, enableUpdatedAddImage, enableNewAltTextWhenAddingImage, mlManager, editorUndoBar, supportsPinchToZoom) {
1248
1313
  __privateAdd(this, _AnnotationEditorUIManager_instances);
1249
1314
  __privateAdd(this, _abortController, new AbortController());
1250
1315
  __privateAdd(this, _activeEditor, null);
@@ -1297,10 +1362,12 @@ var _AnnotationEditorUIManager = class _AnnotationEditorUIManager {
1297
1362
  __privateAdd(this, _translationTimeoutId, null);
1298
1363
  __privateAdd(this, _container, null);
1299
1364
  __privateAdd(this, _viewer, null);
1365
+ __privateAdd(this, _viewerAlert, null);
1300
1366
  __privateAdd(this, _updateModeCapability, null);
1301
1367
  const signal = this._signal = __privateGet(this, _abortController).signal;
1302
1368
  __privateSet(this, _container, container);
1303
1369
  __privateSet(this, _viewer, viewer);
1370
+ __privateSet(this, _viewerAlert, viewerAlert);
1304
1371
  __privateSet(this, _altTextManager, altTextManager);
1305
1372
  __privateSet(this, _signatureManager, signatureManager);
1306
1373
  this._eventBus = eventBus;
@@ -1527,7 +1594,11 @@ var _AnnotationEditorUIManager = class _AnnotationEditorUIManager {
1527
1594
  this,
1528
1595
  "highlightColors",
1529
1596
  __privateGet(this, _highlightColors) ? new Map(
1530
- __privateGet(this, _highlightColors).split(",").map((pair) => pair.split("=").map((x) => x.trim()))
1597
+ __privateGet(this, _highlightColors).split(",").map((pair) => {
1598
+ pair = pair.split("=").map((x) => x.trim());
1599
+ pair[1] = pair[1].toUpperCase();
1600
+ return pair;
1601
+ })
1531
1602
  ) : null
1532
1603
  );
1533
1604
  }
@@ -1678,6 +1749,18 @@ var _AnnotationEditorUIManager = class _AnnotationEditorUIManager {
1678
1749
  __privateGet(this, _annotationStorage).setValue(editor.id, editor);
1679
1750
  }
1680
1751
  }
1752
+ a11yAlert(messageId, args = null) {
1753
+ const viewerAlert = __privateGet(this, _viewerAlert);
1754
+ if (!viewerAlert) {
1755
+ return;
1756
+ }
1757
+ viewerAlert.setAttribute("data-l10n-id", messageId);
1758
+ if (args) {
1759
+ viewerAlert.setAttribute("data-l10n-args", JSON.stringify(args));
1760
+ } else {
1761
+ viewerAlert.removeAttribute("data-l10n-args");
1762
+ }
1763
+ }
1681
1764
  blur() {
1682
1765
  this.isShiftKeyDown = false;
1683
1766
  if (__privateGet(this, _highlightWhenShiftUp)) {
@@ -1952,8 +2035,10 @@ var _AnnotationEditorUIManager = class _AnnotationEditorUIManager {
1952
2035
  * @param {string|null} editId
1953
2036
  * @param {boolean} [isFromKeyboard] - true if the mode change is due to a
1954
2037
  * keyboard action.
2038
+ * @param {boolean} [mustEnterInEditMode] - true if the editor must enter in
2039
+ * edit mode.
1955
2040
  */
1956
- async updateMode(mode, editId = null, isFromKeyboard = false) {
2041
+ async updateMode(mode, editId = null, isFromKeyboard = false, mustEnterInEditMode = false) {
1957
2042
  if (__privateGet(this, _mode) === mode) {
1958
2043
  return;
1959
2044
  }
@@ -1992,7 +2077,9 @@ var _AnnotationEditorUIManager = class _AnnotationEditorUIManager {
1992
2077
  for (const editor of __privateGet(this, _allEditors).values()) {
1993
2078
  if (editor.annotationElementId === editId || editor.id === editId) {
1994
2079
  this.setSelected(editor);
1995
- editor.enterInEditMode();
2080
+ if (mustEnterInEditMode) {
2081
+ editor.enterInEditMode();
2082
+ }
1996
2083
  } else {
1997
2084
  editor.unselect();
1998
2085
  }
@@ -2212,6 +2299,10 @@ var _AnnotationEditorUIManager = class _AnnotationEditorUIManager {
2212
2299
  * @param {AnnotationEditor} editor
2213
2300
  */
2214
2301
  setSelected(editor) {
2302
+ this.updateToolbar({
2303
+ mode: editor.mode,
2304
+ editId: editor.id
2305
+ });
2215
2306
  __privateGet(this, _currentDrawingSession)?.commitOrRemove();
2216
2307
  for (const ed of __privateGet(this, _selectedEditors)) {
2217
2308
  if (ed !== editor) {
@@ -2675,6 +2766,7 @@ _translation = new WeakMap();
2675
2766
  _translationTimeoutId = new WeakMap();
2676
2767
  _container = new WeakMap();
2677
2768
  _viewer = new WeakMap();
2769
+ _viewerAlert = new WeakMap();
2678
2770
  _updateModeCapability = new WeakMap();
2679
2771
  _AnnotationEditorUIManager_instances = new WeakSet();
2680
2772
  getAnchorElementForSelection_fn = function({ anchorNode }) {
@@ -3474,6 +3566,7 @@ var _AnnotationEditor = class _AnnotationEditor {
3474
3566
  this._willKeepAspectRatio = false;
3475
3567
  this._initialOptions.isCentered = parameters.isCentered;
3476
3568
  this._structTreeParentId = null;
3569
+ this.annotationElementId = parameters.annotationElementId || null;
3477
3570
  const {
3478
3571
  rotation,
3479
3572
  rawDims: { pageWidth, pageHeight, pageX, pageY }
@@ -3522,6 +3615,9 @@ var _AnnotationEditor = class _AnnotationEditor {
3522
3615
  get editorType() {
3523
3616
  return Object.getPrototypeOf(this).constructor._type;
3524
3617
  }
3618
+ get mode() {
3619
+ return Object.getPrototypeOf(this).constructor._editorType;
3620
+ }
3525
3621
  static get isDrawer() {
3526
3622
  return false;
3527
3623
  }
@@ -3713,6 +3809,9 @@ var _AnnotationEditor = class _AnnotationEditor {
3713
3809
  * Commit the data contained in this editor.
3714
3810
  */
3715
3811
  commit() {
3812
+ if (!this.isInEditMode()) {
3813
+ return;
3814
+ }
3716
3815
  this.addToAnnotationStorage();
3717
3816
  }
3718
3817
  addToAnnotationStorage() {
@@ -3968,6 +4067,13 @@ var _AnnotationEditor = class _AnnotationEditor {
3968
4067
  altTextFinish() {
3969
4068
  __privateGet(this, _altText3)?.finish();
3970
4069
  }
4070
+ /**
4071
+ * Get the toolbar buttons for this editor.
4072
+ * @returns {Array<Array<string|object>>|null}
4073
+ */
4074
+ get toolbarButtons() {
4075
+ return null;
4076
+ }
3971
4077
  /**
3972
4078
  * Add a toolbar for this editor.
3973
4079
  * @returns {Promise<EditorToolbar|null>}
@@ -3978,9 +4084,13 @@ var _AnnotationEditor = class _AnnotationEditor {
3978
4084
  }
3979
4085
  this._editToolbar = new EditorToolbar(this);
3980
4086
  this.div.append(this._editToolbar.render());
3981
- if (__privateGet(this, _altText3)) {
3982
- await this._editToolbar.addAltText(__privateGet(this, _altText3));
4087
+ const { toolbarButtons } = this;
4088
+ if (toolbarButtons) {
4089
+ for (const [name, tool] of toolbarButtons) {
4090
+ await this._editToolbar.addButton(name, tool);
4091
+ }
3983
4092
  }
4093
+ this._editToolbar.addButton("delete");
3984
4094
  return this._editToolbar;
3985
4095
  }
3986
4096
  removeEditToolbar() {
@@ -4002,17 +4112,20 @@ var _AnnotationEditor = class _AnnotationEditor {
4002
4112
  getClientDimensions() {
4003
4113
  return this.div.getBoundingClientRect();
4004
4114
  }
4005
- async addAltTextButton() {
4006
- if (__privateGet(this, _altText3)) {
4007
- return;
4008
- }
4009
- AltText.initialize(_AnnotationEditor._l10n);
4010
- __privateSet(this, _altText3, new AltText(this));
4011
- if (__privateGet(this, _accessibilityData)) {
4012
- __privateGet(this, _altText3).data = __privateGet(this, _accessibilityData);
4013
- __privateSet(this, _accessibilityData, null);
4115
+ /**
4116
+ * Create the alt text for this editor.
4117
+ * @returns {object}
4118
+ */
4119
+ createAltText() {
4120
+ if (!__privateGet(this, _altText3)) {
4121
+ AltText.initialize(_AnnotationEditor._l10n);
4122
+ __privateSet(this, _altText3, new AltText(this));
4123
+ if (__privateGet(this, _accessibilityData)) {
4124
+ __privateGet(this, _altText3).data = __privateGet(this, _accessibilityData);
4125
+ __privateSet(this, _accessibilityData, null);
4126
+ }
4014
4127
  }
4015
- await this.addEditToolbar();
4128
+ return __privateGet(this, _altText3);
4016
4129
  }
4017
4130
  get altTextData() {
4018
4131
  return __privateGet(this, _altText3)?.data;
@@ -4314,7 +4427,8 @@ var _AnnotationEditor = class _AnnotationEditor {
4314
4427
  const editor = new this.prototype.constructor({
4315
4428
  parent,
4316
4429
  id: parent.getNextId(),
4317
- uiManager
4430
+ uiManager,
4431
+ annotationElementId: data.annotationElementId
4318
4432
  });
4319
4433
  editor.rotation = data.rotation;
4320
4434
  __privateSet(editor, _accessibilityData, data.accessibilityData);
@@ -14585,74 +14699,6 @@ var InternalRenderTask = _InternalRenderTask;
14585
14699
  var version = false ? null : null;
14586
14700
  var build = false ? null : null;
14587
14701
 
14588
- // src/pdf.js/src/shared/scripting_utils.js
14589
- function makeColorComp(n) {
14590
- return Math.floor(Math.max(0, Math.min(1, n)) * 255).toString(16).padStart(2, "0");
14591
- }
14592
- function scaleAndClamp(x) {
14593
- return Math.max(0, Math.min(255, 255 * x));
14594
- }
14595
- var ColorConverters = class {
14596
- static CMYK_G([c, y, m, k]) {
14597
- return ["G", 1 - Math.min(1, 0.3 * c + 0.59 * m + 0.11 * y + k)];
14598
- }
14599
- static G_CMYK([g]) {
14600
- return ["CMYK", 0, 0, 0, 1 - g];
14601
- }
14602
- static G_RGB([g]) {
14603
- return ["RGB", g, g, g];
14604
- }
14605
- static G_rgb([g]) {
14606
- g = scaleAndClamp(g);
14607
- return [g, g, g];
14608
- }
14609
- static G_HTML([g]) {
14610
- const G = makeColorComp(g);
14611
- return `#${G}${G}${G}`;
14612
- }
14613
- static RGB_G([r, g, b]) {
14614
- return ["G", 0.3 * r + 0.59 * g + 0.11 * b];
14615
- }
14616
- static RGB_rgb(color) {
14617
- return color.map(scaleAndClamp);
14618
- }
14619
- static RGB_HTML(color) {
14620
- return `#${color.map(makeColorComp).join("")}`;
14621
- }
14622
- static T_HTML() {
14623
- return "#00000000";
14624
- }
14625
- static T_rgb() {
14626
- return [null];
14627
- }
14628
- static CMYK_RGB([c, y, m, k]) {
14629
- return [
14630
- "RGB",
14631
- 1 - Math.min(1, c + k),
14632
- 1 - Math.min(1, m + k),
14633
- 1 - Math.min(1, y + k)
14634
- ];
14635
- }
14636
- static CMYK_rgb([c, y, m, k]) {
14637
- return [
14638
- scaleAndClamp(1 - Math.min(1, c + k)),
14639
- scaleAndClamp(1 - Math.min(1, m + k)),
14640
- scaleAndClamp(1 - Math.min(1, y + k))
14641
- ];
14642
- }
14643
- static CMYK_HTML(components) {
14644
- const rgb = this.CMYK_RGB(components).slice(1);
14645
- return this.RGB_HTML(rgb);
14646
- }
14647
- static RGB_CMYK([r, g, b]) {
14648
- const c = 1 - r;
14649
- const m = 1 - g;
14650
- const y = 1 - b;
14651
- const k = Math.min(c, m, y);
14652
- return ["CMYK", c, m, y, k];
14653
- }
14654
- };
14655
-
14656
14702
  // src/pdf.js/src/display/svg_factory.js
14657
14703
  var BaseSVGFactory = class {
14658
14704
  constructor() {
@@ -14903,7 +14949,6 @@ var XfaLayer = class {
14903
14949
  };
14904
14950
 
14905
14951
  // src/pdf.js/src/display/annotation_layer.js
14906
- var DEFAULT_TAB_INDEX = 1e3;
14907
14952
  var DEFAULT_FONT_SIZE2 = 9;
14908
14953
  var GetElementsByNameSet = /* @__PURE__ */ new WeakSet();
14909
14954
  var AnnotationElementFactory = class {
@@ -15002,8 +15047,8 @@ var _AnnotationElement = class _AnnotationElement {
15002
15047
  this._createQuadrilaterals();
15003
15048
  }
15004
15049
  }
15005
- static _hasPopupData({ titleObj, contentsObj, richText }) {
15006
- return !!(titleObj?.str || contentsObj?.str || richText?.str);
15050
+ static _hasPopupData({ contentsObj, richText }) {
15051
+ return !!(contentsObj?.str || richText?.str);
15007
15052
  }
15008
15053
  get _isEditable() {
15009
15054
  return this.data.isEditable;
@@ -15048,7 +15093,7 @@ var _AnnotationElement = class _AnnotationElement {
15048
15093
  const container = document.createElement("section");
15049
15094
  container.setAttribute("data-annotation-id", data.id);
15050
15095
  if (!(this instanceof WidgetAnnotationElement)) {
15051
- container.tabIndex = DEFAULT_TAB_INDEX;
15096
+ container.tabIndex = 0;
15052
15097
  }
15053
15098
  const { style } = container;
15054
15099
  style.zIndex = this.parent.zIndex++;
@@ -15287,6 +15332,7 @@ var _AnnotationElement = class _AnnotationElement {
15287
15332
  svg.classList.add("quadrilateralsContainer");
15288
15333
  svg.setAttribute("width", 0);
15289
15334
  svg.setAttribute("height", 0);
15335
+ svg.role = "none";
15290
15336
  const defs = svgFactory.createElement("defs");
15291
15337
  svg.append(defs);
15292
15338
  const clipPath = svgFactory.createElement("clipPath");
@@ -15340,7 +15386,8 @@ var _AnnotationElement = class _AnnotationElement {
15340
15386
  parentRect: data.rect,
15341
15387
  borderStyle: 0,
15342
15388
  id: `popup_${data.id}`,
15343
- rotation: data.rotation
15389
+ rotation: data.rotation,
15390
+ noRotate: true
15344
15391
  },
15345
15392
  parent: this.parent,
15346
15393
  elements: [this]
@@ -15443,7 +15490,8 @@ var _AnnotationElement = class _AnnotationElement {
15443
15490
  this.linkService.eventBus?.dispatch("switchannotationeditormode", {
15444
15491
  source: this,
15445
15492
  mode,
15446
- editId
15493
+ editId,
15494
+ mustEnterInEditMode: true
15447
15495
  });
15448
15496
  });
15449
15497
  }
@@ -15950,7 +15998,11 @@ var TextWidgetAnnotationElement = class extends WidgetAnnotationElement {
15950
15998
  element.setAttribute("data-element-id", id);
15951
15999
  element.disabled = this.data.readOnly;
15952
16000
  element.name = this.data.fieldName;
15953
- element.tabIndex = DEFAULT_TAB_INDEX;
16001
+ element.tabIndex = 0;
16002
+ const format = this.data.dateFormat || this.data.timeFormat;
16003
+ if (format) {
16004
+ element.title = format;
16005
+ }
15954
16006
  this._setRequired(element, this.data.required);
15955
16007
  if (maxLen) {
15956
16008
  element.maxLength = maxLen;
@@ -16222,7 +16274,7 @@ var CheckboxWidgetAnnotationElement = class extends WidgetAnnotationElement {
16222
16274
  element.setAttribute("checked", true);
16223
16275
  }
16224
16276
  element.setAttribute("exportValue", data.exportValue);
16225
- element.tabIndex = DEFAULT_TAB_INDEX;
16277
+ element.tabIndex = 0;
16226
16278
  element.addEventListener("change", (event) => {
16227
16279
  const { name, checked } = event.target;
16228
16280
  for (const checkbox of this._getElementsByName(
@@ -16309,7 +16361,7 @@ var RadioButtonWidgetAnnotationElement = class extends WidgetAnnotationElement {
16309
16361
  if (value) {
16310
16362
  element.setAttribute("checked", true);
16311
16363
  }
16312
- element.tabIndex = DEFAULT_TAB_INDEX;
16364
+ element.tabIndex = 0;
16313
16365
  element.addEventListener("change", (event) => {
16314
16366
  const { name, checked } = event.target;
16315
16367
  for (const radio of this._getElementsByName(
@@ -16398,7 +16450,7 @@ var ChoiceWidgetAnnotationElement = class extends WidgetAnnotationElement {
16398
16450
  selectElement.disabled = this.data.readOnly;
16399
16451
  this._setRequired(selectElement, this.data.required);
16400
16452
  selectElement.name = this.data.fieldName;
16401
- selectElement.tabIndex = DEFAULT_TAB_INDEX;
16453
+ selectElement.tabIndex = 0;
16402
16454
  let addAnEmptyEntry = this.data.combo && this.data.options.length > 0;
16403
16455
  if (!this.data.combo) {
16404
16456
  selectElement.size = this.data.options.length;
@@ -16653,7 +16705,9 @@ var PopupAnnotationElement = class extends AnnotationElement {
16653
16705
  this.popup = null;
16654
16706
  }
16655
16707
  render() {
16656
- this.container.classList.add("popupAnnotation");
16708
+ const { container } = this;
16709
+ container.classList.add("popupAnnotation");
16710
+ container.role = "comment";
16657
16711
  const popup = this.popup = new PopupElement({
16658
16712
  container: this.container,
16659
16713
  color: this.data.color,
@@ -16767,7 +16821,7 @@ var PopupElement = class {
16767
16821
  ({ dir: title.dir, str: title.textContent } = __privateGet(this, _titleObj));
16768
16822
  popup.append(header);
16769
16823
  if (__privateGet(this, _dateObj)) {
16770
- const modificationDate = document.createElement("span");
16824
+ const modificationDate = document.createElement("time");
16771
16825
  modificationDate.classList.add("popupDate");
16772
16826
  modificationDate.setAttribute(
16773
16827
  "data-l10n-id",
@@ -16777,6 +16831,7 @@ var PopupElement = class {
16777
16831
  "data-l10n-args",
16778
16832
  JSON.stringify({ dateObj: __privateGet(this, _dateObj).valueOf() })
16779
16833
  );
16834
+ modificationDate.dateTime = __privateGet(this, _dateObj).toISOString();
16780
16835
  header.append(modificationDate);
16781
16836
  }
16782
16837
  const html = __privateGet(this, _PopupElement_instances, html_get);
@@ -17340,11 +17395,20 @@ var HighlightAnnotationElement = class extends AnnotationElement {
17340
17395
  this.annotationEditorType = AnnotationEditorType.HIGHLIGHT;
17341
17396
  }
17342
17397
  render() {
17343
- if (!this.data.popupRef && this.hasPopupData) {
17398
+ const {
17399
+ data: { overlaidText, popupRef }
17400
+ } = this;
17401
+ if (!popupRef && this.hasPopupData) {
17344
17402
  this._createPopup();
17345
17403
  }
17346
17404
  this.container.classList.add("highlightAnnotation");
17347
17405
  this._editOnDoubleClick();
17406
+ if (overlaidText) {
17407
+ const mark = document.createElement("mark");
17408
+ mark.classList.add("overlaidText");
17409
+ mark.textContent = overlaidText;
17410
+ this.container.append(mark);
17411
+ }
17348
17412
  return this.container;
17349
17413
  }
17350
17414
  };
@@ -17357,10 +17421,19 @@ var UnderlineAnnotationElement = class extends AnnotationElement {
17357
17421
  });
17358
17422
  }
17359
17423
  render() {
17360
- if (!this.data.popupRef && this.hasPopupData) {
17424
+ const {
17425
+ data: { overlaidText, popupRef }
17426
+ } = this;
17427
+ if (!popupRef && this.hasPopupData) {
17361
17428
  this._createPopup();
17362
17429
  }
17363
17430
  this.container.classList.add("underlineAnnotation");
17431
+ if (overlaidText) {
17432
+ const underline = document.createElement("u");
17433
+ underline.classList.add("overlaidText");
17434
+ underline.textContent = overlaidText;
17435
+ this.container.append(underline);
17436
+ }
17364
17437
  return this.container;
17365
17438
  }
17366
17439
  };
@@ -17373,10 +17446,19 @@ var SquigglyAnnotationElement = class extends AnnotationElement {
17373
17446
  });
17374
17447
  }
17375
17448
  render() {
17376
- if (!this.data.popupRef && this.hasPopupData) {
17449
+ const {
17450
+ data: { overlaidText, popupRef }
17451
+ } = this;
17452
+ if (!popupRef && this.hasPopupData) {
17377
17453
  this._createPopup();
17378
17454
  }
17379
17455
  this.container.classList.add("squigglyAnnotation");
17456
+ if (overlaidText) {
17457
+ const underline = document.createElement("u");
17458
+ underline.classList.add("overlaidText");
17459
+ underline.textContent = overlaidText;
17460
+ this.container.append(underline);
17461
+ }
17380
17462
  return this.container;
17381
17463
  }
17382
17464
  };
@@ -17389,10 +17471,19 @@ var StrikeOutAnnotationElement = class extends AnnotationElement {
17389
17471
  });
17390
17472
  }
17391
17473
  render() {
17392
- if (!this.data.popupRef && this.hasPopupData) {
17474
+ const {
17475
+ data: { overlaidText, popupRef }
17476
+ } = this;
17477
+ if (!popupRef && this.hasPopupData) {
17393
17478
  this._createPopup();
17394
17479
  }
17395
17480
  this.container.classList.add("strikeoutAnnotation");
17481
+ if (overlaidText) {
17482
+ const strikeout = document.createElement("s");
17483
+ strikeout.classList.add("overlaidText");
17484
+ strikeout.textContent = overlaidText;
17485
+ this.container.append(strikeout);
17486
+ }
17396
17487
  return this.container;
17397
17488
  }
17398
17489
  };
@@ -17571,7 +17662,7 @@ var _AnnotationLayer = class _AnnotationLayer {
17571
17662
  if (data.hidden) {
17572
17663
  rendered.style.visibility = "hidden";
17573
17664
  }
17574
- await __privateMethod(this, _AnnotationLayer_instances, appendElement_fn).call(this, rendered, data.id);
17665
+ await __privateMethod(this, _AnnotationLayer_instances, appendElement_fn).call(this, rendered, data.id, elementParams.elements);
17575
17666
  if (element._isEditable) {
17576
17667
  __privateGet(this, _editableAnnotations).set(element.data.id, element);
17577
17668
  this._annotationEditorUIManager?.renderAnnotationElement(element);
@@ -17602,7 +17693,7 @@ var _AnnotationLayer = class _AnnotationLayer {
17602
17693
  continue;
17603
17694
  }
17604
17695
  const rendered = element.render();
17605
- await __privateMethod(this, _AnnotationLayer_instances, appendElement_fn).call(this, rendered, data.id);
17696
+ await __privateMethod(this, _AnnotationLayer_instances, appendElement_fn).call(this, rendered, data.id, null);
17606
17697
  }
17607
17698
  }
17608
17699
  /**
@@ -17647,7 +17738,7 @@ _annotationCanvasMap = new WeakMap();
17647
17738
  _editableAnnotations = new WeakMap();
17648
17739
  _structTreeLayer = new WeakMap();
17649
17740
  _AnnotationLayer_instances = new WeakSet();
17650
- appendElement_fn = async function(element, id) {
17741
+ appendElement_fn = async function(element, id, popupElements) {
17651
17742
  const contentElement = element.firstChild || element;
17652
17743
  const annotationId = contentElement.id = `${AnnotationPrefix}${id}`;
17653
17744
  const ariaAttributes = await __privateGet(this, _structTreeLayer)?.getAriaAttributes(annotationId);
@@ -17656,14 +17747,18 @@ appendElement_fn = async function(element, id) {
17656
17747
  contentElement.setAttribute(key, value);
17657
17748
  }
17658
17749
  }
17659
- this.div.append(element);
17660
- __privateGet(this, _accessibilityManager)?.moveElementInDOM(
17661
- this.div,
17662
- element,
17663
- contentElement,
17664
- /* isRemovable = */
17665
- false
17666
- );
17750
+ if (popupElements) {
17751
+ popupElements.at(-1).container.after(element);
17752
+ } else {
17753
+ this.div.append(element);
17754
+ __privateGet(this, _accessibilityManager)?.moveElementInDOM(
17755
+ this.div,
17756
+ element,
17757
+ contentElement,
17758
+ /* isRemovable = */
17759
+ false
17760
+ );
17761
+ }
17667
17762
  };
17668
17763
  setAnnotationCanvasMap_fn = function() {
17669
17764
  if (!__privateGet(this, _annotationCanvasMap)) {
@@ -17719,6 +17814,9 @@ var _FreeTextEditor = class _FreeTextEditor extends AnnotationEditor {
17719
17814
  __privateAdd(this, _fontSize);
17720
17815
  __privateSet(this, _color2, params.color || _FreeTextEditor._defaultColor || AnnotationEditor._defaultLineColor);
17721
17816
  __privateSet(this, _fontSize, params.fontSize || _FreeTextEditor._defaultFontSize);
17817
+ if (!this.annotationElementId) {
17818
+ this._uiManager.a11yAlert("pdfjs-editor-freetext-added-alert");
17819
+ }
17722
17820
  }
17723
17821
  static get _keyboardManager() {
17724
17822
  const proto = _FreeTextEditor.prototype;
@@ -18226,6 +18324,7 @@ var _FreeTextEditor = class _FreeTextEditor extends AnnotationEditor {
18226
18324
  pageIndex: pageNumber - 1,
18227
18325
  rect: rect.slice(0),
18228
18326
  rotation,
18327
+ annotationElementId: id,
18229
18328
  id,
18230
18329
  deleted: false,
18231
18330
  popupRef
@@ -18235,7 +18334,6 @@ var _FreeTextEditor = class _FreeTextEditor extends AnnotationEditor {
18235
18334
  __privateSet(editor, _fontSize, data.fontSize);
18236
18335
  __privateSet(editor, _color2, Util.makeHexColor(...data.color));
18237
18336
  __privateSet(editor, _content, __privateMethod(_a2 = _FreeTextEditor, _FreeTextEditor_static, deserializeContent_fn).call(_a2, data.value));
18238
- editor.annotationElementId = data.id || null;
18239
18337
  editor._initialData = initialData;
18240
18338
  return editor;
18241
18339
  }
@@ -19372,7 +19470,7 @@ var _ColorPicker = class _ColorPicker {
19372
19470
  }
19373
19471
  __privateSet(this, _uiManager2, editor?._uiManager || uiManager);
19374
19472
  __privateSet(this, _eventBus, __privateGet(this, _uiManager2)._eventBus);
19375
- __privateSet(this, _defaultColor, editor?.color || __privateGet(this, _uiManager2)?.highlightColors.values().next().value || "#FFFF98");
19473
+ __privateSet(this, _defaultColor, editor?.color?.toUpperCase() || __privateGet(this, _uiManager2)?.highlightColors.values().next().value || "#FFFF98");
19376
19474
  __privateGet(_ColorPicker, _l10nColor) || __privateSet(_ColorPicker, _l10nColor, Object.freeze({
19377
19475
  blue: "pdfjs-editor-colorpicker-blue",
19378
19476
  green: "pdfjs-editor-colorpicker-green",
@@ -19409,21 +19507,24 @@ var _ColorPicker = class _ColorPicker {
19409
19507
  button.className = "colorPicker";
19410
19508
  button.tabIndex = "0";
19411
19509
  button.setAttribute("data-l10n-id", "pdfjs-editor-colorpicker-button");
19412
- button.setAttribute("aria-haspopup", true);
19510
+ button.ariaHasPopup = "true";
19511
+ if (__privateGet(this, _editor3)) {
19512
+ button.ariaControls = `${__privateGet(this, _editor3).id}_colorpicker_dropdown`;
19513
+ }
19413
19514
  const signal = __privateGet(this, _uiManager2)._signal;
19414
19515
  button.addEventListener("click", __privateMethod(this, _ColorPicker_instances, openDropdown_fn).bind(this), { signal });
19415
19516
  button.addEventListener("keydown", __privateMethod(this, _ColorPicker_instances, keyDown_fn2).bind(this), { signal });
19416
19517
  const swatch = __privateSet(this, _buttonSwatch, document.createElement("span"));
19417
19518
  swatch.className = "swatch";
19418
- swatch.setAttribute("aria-hidden", true);
19519
+ swatch.ariaHidden = "true";
19419
19520
  swatch.style.backgroundColor = __privateGet(this, _defaultColor);
19420
19521
  button.append(swatch);
19421
19522
  return button;
19422
19523
  }
19423
19524
  renderMainDropdown() {
19424
19525
  const dropdown = __privateSet(this, _dropdown, __privateMethod(this, _ColorPicker_instances, getDropdownRoot_fn).call(this));
19425
- dropdown.setAttribute("aria-orientation", "horizontal");
19426
- dropdown.setAttribute("aria-labelledby", "highlightColorPickerLabel");
19526
+ dropdown.ariaOrientation = "horizontal";
19527
+ dropdown.ariaLabelledBy = "highlightColorPickerLabel";
19427
19528
  return dropdown;
19428
19529
  }
19429
19530
  _colorSelectFromKeyboard(event) {
@@ -19476,6 +19577,7 @@ var _ColorPicker = class _ColorPicker {
19476
19577
  }
19477
19578
  hideDropdown() {
19478
19579
  __privateGet(this, _dropdown)?.classList.add("hidden");
19580
+ __privateGet(this, _button).ariaExpanded = "false";
19479
19581
  __privateGet(this, _openDropdownAC)?.abort();
19480
19582
  __privateSet(this, _openDropdownAC, null);
19481
19583
  }
@@ -19502,7 +19604,7 @@ var _ColorPicker = class _ColorPicker {
19502
19604
  }
19503
19605
  const i = __privateGet(this, _uiManager2).highlightColors.values();
19504
19606
  for (const child of __privateGet(this, _dropdown).children) {
19505
- child.setAttribute("aria-selected", i.next().value === color);
19607
+ child.ariaSelected = i.next().value === color.toUpperCase();
19506
19608
  }
19507
19609
  }
19508
19610
  destroy() {
@@ -19532,9 +19634,12 @@ getDropdownRoot_fn = function() {
19532
19634
  div.addEventListener("contextmenu", noContextMenu, { signal });
19533
19635
  div.className = "dropdown";
19534
19636
  div.role = "listbox";
19535
- div.setAttribute("aria-multiselectable", false);
19536
- div.setAttribute("aria-orientation", "vertical");
19637
+ div.ariaMultiSelectable = "false";
19638
+ div.ariaOrientation = "vertical";
19537
19639
  div.setAttribute("data-l10n-id", "pdfjs-editor-colorpicker-dropdown");
19640
+ if (__privateGet(this, _editor3)) {
19641
+ div.id = `${__privateGet(this, _editor3).id}_colorpicker_dropdown`;
19642
+ }
19538
19643
  for (const [name, color] of __privateGet(this, _uiManager2).highlightColors) {
19539
19644
  const button = document.createElement("button");
19540
19645
  button.tabIndex = "0";
@@ -19546,7 +19651,7 @@ getDropdownRoot_fn = function() {
19546
19651
  button.append(swatch);
19547
19652
  swatch.className = "swatch";
19548
19653
  swatch.style.backgroundColor = color;
19549
- button.setAttribute("aria-selected", color === __privateGet(this, _defaultColor));
19654
+ button.ariaSelected = color === __privateGet(this, _defaultColor);
19550
19655
  button.addEventListener("click", __privateMethod(this, _ColorPicker_instances, colorSelect_fn).bind(this, color), {
19551
19656
  signal
19552
19657
  });
@@ -19578,6 +19683,7 @@ openDropdown_fn = function(event) {
19578
19683
  signal: __privateGet(this, _uiManager2).combinedSignal(__privateGet(this, _openDropdownAC))
19579
19684
  });
19580
19685
  }
19686
+ __privateGet(this, _button).ariaExpanded = "true";
19581
19687
  if (__privateGet(this, _dropdown)) {
19582
19688
  __privateGet(this, _dropdown).classList.remove("hidden");
19583
19689
  return;
@@ -19642,6 +19748,9 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
19642
19748
  __privateMethod(this, _HighlightEditor_instances, addToDrawLayer_fn).call(this);
19643
19749
  this.rotate(this.rotation);
19644
19750
  }
19751
+ if (!this.annotationElementId) {
19752
+ this._uiManager.a11yAlert("pdfjs-editor-highlight-added-alert");
19753
+ }
19645
19754
  }
19646
19755
  static get _keyboardManager() {
19647
19756
  const proto = _HighlightEditor.prototype;
@@ -19737,16 +19846,14 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
19737
19846
  ];
19738
19847
  }
19739
19848
  /** @inheritdoc */
19740
- async addEditToolbar() {
19741
- const toolbar = await super.addEditToolbar();
19742
- if (!toolbar) {
19743
- return null;
19744
- }
19849
+ get toolbarButtons() {
19745
19850
  if (this._uiManager.highlightColors) {
19746
- __privateSet(this, _colorPicker2, new ColorPicker({ editor: this }));
19747
- toolbar.addColorPicker(__privateGet(this, _colorPicker2));
19851
+ const colorPicker = __privateSet(this, _colorPicker2, new ColorPicker({
19852
+ editor: this
19853
+ }));
19854
+ return [["colorPicker", colorPicker]];
19748
19855
  }
19749
- return toolbar;
19856
+ return super.toolbarButtons;
19750
19857
  }
19751
19858
  /** @inheritdoc */
19752
19859
  disableEditing() {
@@ -20039,6 +20146,7 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
20039
20146
  pageIndex: pageNumber - 1,
20040
20147
  rect: rect.slice(0),
20041
20148
  rotation,
20149
+ annotationElementId: id,
20042
20150
  id,
20043
20151
  deleted: false,
20044
20152
  popupRef
@@ -20067,6 +20175,7 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
20067
20175
  pageIndex: pageNumber - 1,
20068
20176
  rect: rect.slice(0),
20069
20177
  rotation,
20178
+ annotationElementId: id,
20070
20179
  id,
20071
20180
  deleted: false,
20072
20181
  popupRef
@@ -20079,7 +20188,6 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
20079
20188
  if (inkLists) {
20080
20189
  __privateSet(editor, _thickness2, data.thickness);
20081
20190
  }
20082
- editor.annotationElementId = data.id || null;
20083
20191
  editor._initialData = initialData;
20084
20192
  const [pageWidth, pageHeight] = editor.pageDimensions;
20085
20193
  const [pageX, pageY] = editor.pageTranslation;
@@ -21179,6 +21287,9 @@ _DrawingEditor_instances = new WeakSet();
21179
21287
  createDrawOutlines_fn = function({ drawOutlines, drawId, drawingOptions }) {
21180
21288
  __privateSet(this, _drawOutlines, drawOutlines);
21181
21289
  this._drawingOptions || (this._drawingOptions = drawingOptions);
21290
+ if (!this.annotationElementId) {
21291
+ this._uiManager.a11yAlert(`pdfjs-editor-${this.editorType}-added-alert`);
21292
+ }
21182
21293
  if (drawId >= 0) {
21183
21294
  this._drawId = drawId;
21184
21295
  this.parent.drawLayer.finalizeDraw(
@@ -22205,13 +22316,13 @@ var _InkEditor = class _InkEditor extends DrawingEditor {
22205
22316
  pageIndex: pageNumber - 1,
22206
22317
  rect: rect.slice(0),
22207
22318
  rotation,
22319
+ annotationElementId: id,
22208
22320
  id,
22209
22321
  deleted: false,
22210
22322
  popupRef
22211
22323
  };
22212
22324
  }
22213
22325
  const editor = await super.deserialize(data, parent, uiManager);
22214
- editor.annotationElementId = data.id || null;
22215
22326
  editor._initialData = initialData;
22216
22327
  return editor;
22217
22328
  }
@@ -23150,26 +23261,17 @@ var _SignatureEditor = class _SignatureEditor extends DrawingEditor {
23150
23261
  return { areContours, outline: outlineData.outline };
23151
23262
  }
23152
23263
  /** @inheritdoc */
23153
- async addEditToolbar() {
23154
- const toolbar = await super.addEditToolbar();
23155
- if (!toolbar) {
23156
- return null;
23157
- }
23158
- if (this._uiManager.signatureManager && __privateGet(this, _description) !== null) {
23159
- await toolbar.addEditSignatureButton(
23160
- this._uiManager.signatureManager,
23161
- __privateGet(this, _signatureUUID),
23162
- __privateGet(this, _description)
23163
- );
23164
- toolbar.show();
23264
+ get toolbarButtons() {
23265
+ if (this._uiManager.signatureManager) {
23266
+ return [["editSignature", this._uiManager.signatureManager]];
23165
23267
  }
23166
- return toolbar;
23268
+ return super.toolbarButtons;
23167
23269
  }
23168
23270
  addSignature(data, heightInPage, description, uuid) {
23169
23271
  const { x: savedX, y: savedY } = this;
23170
23272
  const { outline } = __privateSet(this, _signatureData, data);
23171
23273
  __privateSet(this, _isExtracted, outline instanceof ContourDrawOutline);
23172
- __privateSet(this, _description, description);
23274
+ this.description = description;
23173
23275
  this.div.setAttribute("data-l10n-args", JSON.stringify({ description }));
23174
23276
  let drawingOptions;
23175
23277
  if (__privateGet(this, _isExtracted)) {
@@ -23479,6 +23581,10 @@ var StampEditor = class extends AnnotationEditor {
23479
23581
  return !(__privateGet(this, _bitmapPromise) || __privateGet(this, _bitmap) || __privateGet(this, _bitmapUrl) || __privateGet(this, _bitmapFile) || __privateGet(this, _bitmapId) || __privateGet(this, _missingCanvas));
23480
23582
  }
23481
23583
  /** @inheritdoc */
23584
+ get toolbarButtons() {
23585
+ return [["altText", this.createAltText()]];
23586
+ }
23587
+ /** @inheritdoc */
23482
23588
  get isResizable() {
23483
23589
  return true;
23484
23590
  }
@@ -23494,7 +23600,7 @@ var StampEditor = class extends AnnotationEditor {
23494
23600
  }
23495
23601
  super.render();
23496
23602
  this.div.hidden = true;
23497
- this.addAltTextButton();
23603
+ this.createAltText();
23498
23604
  if (!__privateGet(this, _missingCanvas)) {
23499
23605
  if (__privateGet(this, _bitmap)) {
23500
23606
  __privateMethod(this, _StampEditor_instances, createCanvas_fn).call(this);
@@ -23673,6 +23779,7 @@ var StampEditor = class extends AnnotationEditor {
23673
23779
  pageIndex: pageNumber - 1,
23674
23780
  rect: rect2.slice(0),
23675
23781
  rotation,
23782
+ annotationElementId: id,
23676
23783
  id,
23677
23784
  deleted: false,
23678
23785
  accessibilityData: {
@@ -23701,7 +23808,6 @@ var StampEditor = class extends AnnotationEditor {
23701
23808
  const [parentWidth, parentHeight] = editor.pageDimensions;
23702
23809
  editor.width = (rect[2] - rect[0]) / parentWidth;
23703
23810
  editor.height = (rect[3] - rect[1]) / parentHeight;
23704
- editor.annotationElementId = data.id || null;
23705
23811
  if (accessibilityData) {
23706
23812
  editor.altTextData = accessibilityData;
23707
23813
  }
@@ -23820,12 +23926,14 @@ getBitmapDone_fn = function() {
23820
23926
  return;
23821
23927
  }
23822
23928
  if (this._uiManager.useNewAltTextWhenAddingImage && this._uiManager.useNewAltTextFlow && __privateGet(this, _bitmap)) {
23823
- this._editToolbar.hide();
23824
- this._uiManager.editAltText(
23825
- this,
23826
- /* firstTime = */
23827
- true
23828
- );
23929
+ this.addEditToolbar().then(() => {
23930
+ this._editToolbar.hide();
23931
+ this._uiManager.editAltText(
23932
+ this,
23933
+ /* firstTime = */
23934
+ true
23935
+ );
23936
+ });
23829
23937
  return;
23830
23938
  }
23831
23939
  if (!this._uiManager.useNewAltTextWhenAddingImage && this._uiManager.useNewAltTextFlow && __privateGet(this, _bitmap)) {
@@ -23958,6 +24066,9 @@ createCanvas_fn = function() {
23958
24066
  if (__privateGet(this, _bitmapFileName)) {
23959
24067
  this.div.setAttribute("aria-description", __privateGet(this, _bitmapFileName));
23960
24068
  }
24069
+ if (!this.annotationElementId) {
24070
+ this._uiManager.a11yAlert("pdfjs-editor-stamp-added-alert");
24071
+ }
23961
24072
  };
23962
24073
  scaleBitmap_fn = function(width, height) {
23963
24074
  const { width: bitmapWidth, height: bitmapHeight } = __privateGet(this, _bitmap);
@@ -24072,7 +24183,7 @@ __publicField(StampEditor, "_type", "stamp");
24072
24183
  __publicField(StampEditor, "_editorType", AnnotationEditorType.STAMP);
24073
24184
 
24074
24185
  // src/pdf.js/src/display/editor/annotation_editor_layer.js
24075
- var _accessibilityManager2, _allowClick, _annotationLayer, _clickAC, _editorFocusTimeoutId, _editors, _hadPointerDown, _isDisabling, _isEnabling, _drawingAC, _focusedElement, _textLayer, _textSelectionAC, _uiManager3, _editorTypes2, _AnnotationEditorLayer_instances, textLayerPointerDown_fn, currentEditorType_get, createNewEditor_fn, getCenterPoint_fn, cleanup_fn;
24186
+ var _accessibilityManager2, _allowClick, _annotationLayer, _clickAC, _editorFocusTimeoutId, _editors, _hadPointerDown, _isDisabling, _isEnabling, _drawingAC, _focusedElement, _textLayer, _textSelectionAC, _textLayerDblClickAC, _lastPointerDownTimestamp, _uiManager3, _editorTypes2, _AnnotationEditorLayer_instances, textLayerPointerDown_fn, currentEditorType_get, createNewEditor_fn, getCenterPoint_fn, cleanup_fn;
24076
24187
  var _AnnotationEditorLayer = class _AnnotationEditorLayer {
24077
24188
  /**
24078
24189
  * @param {AnnotationEditorLayerOptions} options
@@ -24103,6 +24214,8 @@ var _AnnotationEditorLayer = class _AnnotationEditorLayer {
24103
24214
  __privateAdd(this, _focusedElement, null);
24104
24215
  __privateAdd(this, _textLayer, null);
24105
24216
  __privateAdd(this, _textSelectionAC, null);
24217
+ __privateAdd(this, _textLayerDblClickAC, null);
24218
+ __privateAdd(this, _lastPointerDownTimestamp, -1);
24106
24219
  __privateAdd(this, _uiManager3);
24107
24220
  const editorTypes = [...__privateGet(_AnnotationEditorLayer, _editorTypes2).values()];
24108
24221
  if (!_AnnotationEditorLayer._initialized) {
@@ -24211,6 +24324,8 @@ var _AnnotationEditorLayer = class _AnnotationEditorLayer {
24211
24324
  __privateSet(this, _isEnabling, true);
24212
24325
  this.div.tabIndex = 0;
24213
24326
  this.togglePointerEvents(true);
24327
+ __privateGet(this, _textLayerDblClickAC)?.abort();
24328
+ __privateSet(this, _textLayerDblClickAC, null);
24214
24329
  const annotationElementIds = /* @__PURE__ */ new Set();
24215
24330
  for (const editor of __privateGet(this, _editors).values()) {
24216
24331
  editor.enableEditing();
@@ -24249,6 +24364,48 @@ var _AnnotationEditorLayer = class _AnnotationEditorLayer {
24249
24364
  __privateSet(this, _isDisabling, true);
24250
24365
  this.div.tabIndex = -1;
24251
24366
  this.togglePointerEvents(false);
24367
+ if (__privateGet(this, _textLayer) && !__privateGet(this, _textLayerDblClickAC)) {
24368
+ __privateSet(this, _textLayerDblClickAC, new AbortController());
24369
+ const signal = __privateGet(this, _uiManager3).combinedSignal(__privateGet(this, _textLayerDblClickAC));
24370
+ __privateGet(this, _textLayer).div.addEventListener(
24371
+ "pointerdown",
24372
+ (e) => {
24373
+ const DBL_CLICK_THRESHOLD = 500;
24374
+ const { clientX, clientY, timeStamp } = e;
24375
+ const lastPointerDownTimestamp = __privateGet(this, _lastPointerDownTimestamp);
24376
+ if (timeStamp - lastPointerDownTimestamp > DBL_CLICK_THRESHOLD) {
24377
+ __privateSet(this, _lastPointerDownTimestamp, timeStamp);
24378
+ return;
24379
+ }
24380
+ __privateSet(this, _lastPointerDownTimestamp, -1);
24381
+ const { classList: classList2 } = this.div;
24382
+ classList2.toggle("getElements", true);
24383
+ const elements = document.elementsFromPoint(clientX, clientY);
24384
+ classList2.toggle("getElements", false);
24385
+ if (!this.div.contains(elements[0])) {
24386
+ return;
24387
+ }
24388
+ let id;
24389
+ const regex = new RegExp(`^${AnnotationEditorPrefix}[0-9]+$`);
24390
+ for (const element of elements) {
24391
+ if (regex.test(element.id)) {
24392
+ id = element.id;
24393
+ break;
24394
+ }
24395
+ }
24396
+ if (!id) {
24397
+ return;
24398
+ }
24399
+ const editor = __privateGet(this, _editors).get(id);
24400
+ if (editor?.annotationElementId === null) {
24401
+ e.stopPropagation();
24402
+ e.preventDefault();
24403
+ editor.dblclick();
24404
+ }
24405
+ },
24406
+ { signal, capture: true }
24407
+ );
24408
+ }
24252
24409
  const changedAnnotations = /* @__PURE__ */ new Map();
24253
24410
  const resetAnnotations = /* @__PURE__ */ new Map();
24254
24411
  for (const editor of __privateGet(this, _editors).values()) {
@@ -24792,6 +24949,8 @@ _drawingAC = new WeakMap();
24792
24949
  _focusedElement = new WeakMap();
24793
24950
  _textLayer = new WeakMap();
24794
24951
  _textSelectionAC = new WeakMap();
24952
+ _textLayerDblClickAC = new WeakMap();
24953
+ _lastPointerDownTimestamp = new WeakMap();
24795
24954
  _uiManager3 = new WeakMap();
24796
24955
  _editorTypes2 = new WeakMap();
24797
24956
  _AnnotationEditorLayer_instances = new WeakSet();
@@ -25264,7 +25423,7 @@ var SvgPattern = class {
25264
25423
  this.transform = matrix;
25265
25424
  }
25266
25425
  };
25267
- var SvgGradient = class {
25426
+ var SvgLinearGradient = class {
25268
25427
  constructor(x1, y1, x2, y2) {
25269
25428
  __publicField(this, "x1");
25270
25429
  __publicField(this, "y1");
@@ -25280,6 +25439,26 @@ var SvgGradient = class {
25280
25439
  this.stops.push({ offset, color });
25281
25440
  }
25282
25441
  };
25442
+ var SvgRadialGradient = class {
25443
+ constructor(x0, y0, r0, x1, y1, r1) {
25444
+ __publicField(this, "x0");
25445
+ __publicField(this, "y0");
25446
+ __publicField(this, "r0");
25447
+ __publicField(this, "x1");
25448
+ __publicField(this, "y1");
25449
+ __publicField(this, "r1");
25450
+ __publicField(this, "stops", []);
25451
+ this.x0 = x0;
25452
+ this.y0 = y0;
25453
+ this.r0 = r0;
25454
+ this.x1 = x1;
25455
+ this.y1 = y1;
25456
+ this.r1 = r1;
25457
+ }
25458
+ addColorStop(offset, color) {
25459
+ this.stops.push({ offset, color });
25460
+ }
25461
+ };
25283
25462
  function isSvgElement(node) {
25284
25463
  return "children" in node;
25285
25464
  }
@@ -25816,7 +25995,10 @@ var SvgCanvasContext = class {
25816
25995
  return new SvgPattern(src, width, height);
25817
25996
  }
25818
25997
  createLinearGradient(x1, x2, y1, y2) {
25819
- return new SvgGradient(x1, y1, x2, y2);
25998
+ return new SvgLinearGradient(x1, y1, x2, y2);
25999
+ }
26000
+ createRadialGradient(x0, y0, r0, x1, y1, r1) {
26001
+ return new SvgRadialGradient(x0, y0, r0, x1, y1, r1);
25820
26002
  }
25821
26003
  clip(path, fillRule) {
25822
26004
  if (typeof path === "string" || fillRule) {
@@ -25932,6 +26114,37 @@ var SvgCanvasContext = class {
25932
26114
  }
25933
26115
  _createGradientNode(gradient) {
25934
26116
  const id = `pattern_${crypto.randomUUID()}`;
26117
+ if (gradient instanceof SvgRadialGradient) {
26118
+ return {
26119
+ tag: "radialGradient",
26120
+ attrs: {
26121
+ id,
26122
+ cx: `${gradient.x1}`,
26123
+ cy: `${gradient.y1}`,
26124
+ r: `${gradient.r1}`,
26125
+ fx: `${gradient.x0}`,
26126
+ fy: `${gradient.y0}`,
26127
+ gradientUnits: "userSpaceOnUse"
26128
+ },
26129
+ children: gradient.stops.map(({ offset, color }) => {
26130
+ const stopElement = {
26131
+ tag: "stop",
26132
+ attrs: {
26133
+ offset: `${offset}`,
26134
+ "stop-color": color
26135
+ }
26136
+ };
26137
+ if (color.startsWith("rgba(")) {
26138
+ const parsed = parseRGBAColor(color);
26139
+ stopElement.attrs["stop-color"] = `rgb(${parsed.r}, ${parsed.g}, ${parsed.b})`;
26140
+ stopElement.attrs["stop-opacity"] = `${parsed.a ?? 1}`;
26141
+ } else {
26142
+ stopElement.attrs["stop-color"] = color;
26143
+ }
26144
+ return stopElement;
26145
+ })
26146
+ };
26147
+ }
25935
26148
  return {
25936
26149
  tag: "linearGradient",
25937
26150
  attrs: {
@@ -25975,7 +26188,11 @@ var SvgCanvasContext = class {
25975
26188
  const pattern = this._createPatternNode(fillStyle, fillStyle.transform);
25976
26189
  this._defs.children.push(pattern);
25977
26190
  currentElement.attrs.fill = `url(#${pattern.attrs.id})`;
25978
- } else if (fillStyle instanceof SvgGradient) {
26191
+ } else if (fillStyle instanceof SvgLinearGradient) {
26192
+ const gradient = this._createGradientNode(fillStyle);
26193
+ this._defs.children.push(gradient);
26194
+ currentElement.attrs.fill = `url(#${gradient.attrs.id})`;
26195
+ } else if (fillStyle instanceof SvgRadialGradient) {
25979
26196
  const gradient = this._createGradientNode(fillStyle);
25980
26197
  this._defs.children.push(gradient);
25981
26198
  currentElement.attrs.fill = `url(#${gradient.attrs.id})`;
@@ -25997,7 +26214,7 @@ var SvgCanvasContext = class {
25997
26214
  );
25998
26215
  this._defs.children.push(pattern);
25999
26216
  currentElement.attrs.stroke = `url(#${pattern.attrs.id})`;
26000
- } else if (strokeStyle instanceof SvgGradient) {
26217
+ } else if (strokeStyle instanceof SvgLinearGradient) {
26001
26218
  const gradient = this._createGradientNode(strokeStyle);
26002
26219
  this._defs.children.push(gradient);
26003
26220
  currentElement.attrs.fill = `url(#${gradient.attrs.id})`;
@@ -26258,7 +26475,9 @@ PDFPageProxy.prototype.getAnnotations = async function(params) {
26258
26475
 
26259
26476
  // src/lib/WasmFactory.ts
26260
26477
  var WasmFactory = class {
26261
- async fetch({ filename }) {
26478
+ async fetch({
26479
+ filename
26480
+ }) {
26262
26481
  switch (filename) {
26263
26482
  case "openjpeg.wasm":
26264
26483
  return import("./openjpeg-B2WN24QZ.js").then(
@@ -26284,7 +26503,9 @@ var StandardFontDataFactory = class extends BaseStandardFontDataFactory {
26284
26503
  * Fetch the corresponding standard font data.
26285
26504
  * We need to use specific dynamic imports for each font file for the bundler to include them.
26286
26505
  */
26287
- async fetch({ filename }) {
26506
+ async fetch({
26507
+ filename
26508
+ }) {
26288
26509
  switch (filename) {
26289
26510
  case "FoxitDingbats.pfb":
26290
26511
  return import("./FoxitDingbats-65AZ2Z2V.js").then((module) => module.default);