@4tw/vue-cli-plugin-pdfjs-viewer 1.6.0 → 1.7.0

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.
@@ -2,7 +2,7 @@
2
2
  * @licstart The following is the entire license notice for the
3
3
  * JavaScript code in this page
4
4
  *
5
- * Copyright 2023 Mozilla Foundation
5
+ * Copyright 2024 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -63,7 +63,6 @@ __webpack_require__.d(__webpack_exports__, {
63
63
  InvalidPDFException: () => (/* reexport */ InvalidPDFException),
64
64
  MissingPDFException: () => (/* reexport */ MissingPDFException),
65
65
  OPS: () => (/* reexport */ OPS),
66
- Outliner: () => (/* reexport */ Outliner),
67
66
  PDFDataRangeTransport: () => (/* reexport */ PDFDataRangeTransport),
68
67
  PDFDateString: () => (/* reexport */ PDFDateString),
69
68
  PDFWorker: () => (/* reexport */ PDFWorker),
@@ -87,10 +86,8 @@ __webpack_require__.d(__webpack_exports__, {
87
86
  isPdfFile: () => (/* reexport */ isPdfFile),
88
87
  noContextMenu: () => (/* reexport */ noContextMenu),
89
88
  normalizeUnicode: () => (/* reexport */ normalizeUnicode),
90
- renderTextLayer: () => (/* reexport */ renderTextLayer),
91
89
  setLayerDimensions: () => (/* reexport */ setLayerDimensions),
92
90
  shadow: () => (/* reexport */ shadow),
93
- updateTextLayer: () => (/* reexport */ updateTextLayer),
94
91
  version: () => (/* reexport */ version)
95
92
  });
96
93
 
@@ -110,6 +107,7 @@ const RenderingIntentFlag = {
110
107
  ANNOTATIONS_FORMS: 0x10,
111
108
  ANNOTATIONS_STORAGE: 0x20,
112
109
  ANNOTATIONS_DISABLE: 0x40,
110
+ IS_EDITING: 0x80,
113
111
  OPLIST: 0x100
114
112
  };
115
113
  const AnnotationMode = {
@@ -365,7 +363,9 @@ const OPS = {
365
363
  paintImageXObjectRepeat: 88,
366
364
  paintImageMaskXObjectRepeat: 89,
367
365
  paintSolidColorImageMask: 90,
368
- constructPath: 91
366
+ constructPath: 91,
367
+ setStrokeTransparent: 92,
368
+ setFillTransparent: 93
369
369
  };
370
370
  const PasswordResponses = {
371
371
  NEED_PASSWORD: 1,
@@ -998,6 +998,7 @@ class PixelsPerInch {
998
998
  static PDF_TO_CSS_UNITS = this.CSS / this.PDF;
999
999
  }
1000
1000
  class DOMFilterFactory extends BaseFilterFactory {
1001
+ #baseUrl;
1001
1002
  #_cache;
1002
1003
  #_defs;
1003
1004
  #docId;
@@ -1061,6 +1062,20 @@ class DOMFilterFactory extends BaseFilterFactory {
1061
1062
  }
1062
1063
  return [bufferR.join(","), bufferG.join(","), bufferB.join(",")];
1063
1064
  }
1065
+ #createUrl(id) {
1066
+ if (this.#baseUrl === undefined) {
1067
+ this.#baseUrl = "";
1068
+ const url = this.#document.URL;
1069
+ if (url !== this.#document.baseURI) {
1070
+ if (isDataScheme(url)) {
1071
+ warn('#createUrl: ignore "data:"-URL for performance reasons.');
1072
+ } else {
1073
+ this.#baseUrl = url.split("#", 1)[0];
1074
+ }
1075
+ }
1076
+ }
1077
+ return `url(${this.#baseUrl}#${id})`;
1078
+ }
1064
1079
  addFilter(maps) {
1065
1080
  if (!maps) {
1066
1081
  return "none";
@@ -1077,7 +1092,7 @@ class DOMFilterFactory extends BaseFilterFactory {
1077
1092
  return value;
1078
1093
  }
1079
1094
  const id = `g_${this.#docId}_transfer_map_${this.#id++}`;
1080
- const url = `url(#${id})`;
1095
+ const url = this.#createUrl(id);
1081
1096
  this.#cache.set(maps, url);
1082
1097
  this.#cache.set(key, url);
1083
1098
  const filter = this.#createFilter(id);
@@ -1135,7 +1150,7 @@ class DOMFilterFactory extends BaseFilterFactory {
1135
1150
  return arr.join(",");
1136
1151
  };
1137
1152
  this.#addTransferMapConversion(getSteps(0, 5), getSteps(1, 5), getSteps(2, 5), filter);
1138
- info.url = `url(#${id})`;
1153
+ info.url = this.#createUrl(id);
1139
1154
  return info.url;
1140
1155
  }
1141
1156
  addAlphaFilter(map) {
@@ -1151,7 +1166,7 @@ class DOMFilterFactory extends BaseFilterFactory {
1151
1166
  return value;
1152
1167
  }
1153
1168
  const id = `g_${this.#docId}_alpha_map_${this.#id++}`;
1154
- const url = `url(#${id})`;
1169
+ const url = this.#createUrl(id);
1155
1170
  this.#cache.set(map, url);
1156
1171
  this.#cache.set(key, url);
1157
1172
  const filter = this.#createFilter(id);
@@ -1176,7 +1191,7 @@ class DOMFilterFactory extends BaseFilterFactory {
1176
1191
  return value;
1177
1192
  }
1178
1193
  const id = `g_${this.#docId}_luminosity_map_${this.#id++}`;
1179
- const url = `url(#${id})`;
1194
+ const url = this.#createUrl(id);
1180
1195
  this.#cache.set(map, url);
1181
1196
  this.#cache.set(key, url);
1182
1197
  const filter = this.#createFilter(id);
@@ -1239,7 +1254,7 @@ class DOMFilterFactory extends BaseFilterFactory {
1239
1254
  const filter = info.filter = this.#createFilter(id);
1240
1255
  this.#addGrayConversion(filter);
1241
1256
  this.#addTransferMapConversion(getSteps(newFgRGB[0], newBgRGB[0], 5), getSteps(newFgRGB[1], newBgRGB[1], 5), getSteps(newFgRGB[2], newBgRGB[2], 5), filter);
1242
- info.url = `url(#${id})`;
1257
+ info.url = this.#createUrl(id);
1243
1258
  return info.url;
1244
1259
  }
1245
1260
  destroy(keepHCM = false) {
@@ -2234,6 +2249,7 @@ class AnnotationEditorUIManager {
2234
2249
  #editorTypes = null;
2235
2250
  #editorsToRescale = new Set();
2236
2251
  #enableHighlightFloatingButton = false;
2252
+ #enableUpdatedAddImage = false;
2237
2253
  #filterFactory = null;
2238
2254
  #focusMainContainerTimeoutId = null;
2239
2255
  #highlightColors = null;
@@ -2333,7 +2349,7 @@ class AnnotationEditorUIManager {
2333
2349
  checker: arrowChecker
2334
2350
  }]]));
2335
2351
  }
2336
- constructor(container, viewer, altTextManager, eventBus, pdfDocument, pageColors, highlightColors, enableHighlightFloatingButton, mlManager) {
2352
+ constructor(container, viewer, altTextManager, eventBus, pdfDocument, pageColors, highlightColors, enableHighlightFloatingButton, enableUpdatedAddImage, mlManager) {
2337
2353
  this._signal = this.#abortController.signal;
2338
2354
  this.#container = container;
2339
2355
  this.#viewer = viewer;
@@ -2351,6 +2367,7 @@ class AnnotationEditorUIManager {
2351
2367
  this.#pageColors = pageColors;
2352
2368
  this.#highlightColors = highlightColors || null;
2353
2369
  this.#enableHighlightFloatingButton = enableHighlightFloatingButton;
2370
+ this.#enableUpdatedAddImage = enableUpdatedAddImage;
2354
2371
  this.#mlManager = mlManager || null;
2355
2372
  this.viewParameters = {
2356
2373
  realScale: PixelsPerInch.PDF_TO_CSS_UNITS,
@@ -2390,8 +2407,11 @@ class AnnotationEditorUIManager {
2390
2407
  async mlGuess(data) {
2391
2408
  return this.#mlManager?.guess(data) || null;
2392
2409
  }
2393
- get hasMLManager() {
2394
- return !!this.#mlManager;
2410
+ async isMLEnabledFor(name) {
2411
+ return !!(await this.#mlManager?.isEnabledFor(name));
2412
+ }
2413
+ get useNewAltTextFlow() {
2414
+ return this.#enableUpdatedAddImage;
2395
2415
  }
2396
2416
  get hcmFilter() {
2397
2417
  return shadow(this, "hcmFilter", this.#pageColors ? this.#filterFactory.addHCMFilter(this.#pageColors.foreground, this.#pageColors.background) : "none");
@@ -2411,6 +2431,23 @@ class AnnotationEditorUIManager {
2411
2431
  editAltText(editor) {
2412
2432
  this.#altTextManager?.editAltText(this, editor);
2413
2433
  }
2434
+ switchToMode(mode, callback) {
2435
+ this._eventBus.on("annotationeditormodechanged", callback, {
2436
+ once: true,
2437
+ signal: this._signal
2438
+ });
2439
+ this._eventBus.dispatch("showannotationeditorui", {
2440
+ source: this,
2441
+ mode
2442
+ });
2443
+ }
2444
+ setPreference(name, value) {
2445
+ this._eventBus.dispatch("setpreference", {
2446
+ source: this,
2447
+ name,
2448
+ value
2449
+ });
2450
+ }
2414
2451
  onPageChanging({
2415
2452
  pageNumber
2416
2453
  }) {
@@ -2462,6 +2499,20 @@ class AnnotationEditorUIManager {
2462
2499
  }) {
2463
2500
  return anchorNode.nodeType === Node.TEXT_NODE ? anchorNode.parentElement : anchorNode;
2464
2501
  }
2502
+ #getLayerForTextLayer(textLayer) {
2503
+ const {
2504
+ currentLayer
2505
+ } = this;
2506
+ if (currentLayer.hasTextLayer(textLayer)) {
2507
+ return currentLayer;
2508
+ }
2509
+ for (const layer of this.#allLayers.values()) {
2510
+ if (layer.hasTextLayer(textLayer)) {
2511
+ return layer;
2512
+ }
2513
+ }
2514
+ return null;
2515
+ }
2465
2516
  highlightSelection(methodOfCreation = "") {
2466
2517
  const selection = document.getSelection();
2467
2518
  if (!selection || selection.isCollapsed) {
@@ -2481,30 +2532,30 @@ class AnnotationEditorUIManager {
2481
2532
  return;
2482
2533
  }
2483
2534
  selection.empty();
2484
- if (this.#mode === AnnotationEditorType.NONE) {
2485
- this._eventBus.dispatch("showannotationeditorui", {
2486
- source: this,
2487
- mode: AnnotationEditorType.HIGHLIGHT
2535
+ const layer = this.#getLayerForTextLayer(textLayer);
2536
+ const isNoneMode = this.#mode === AnnotationEditorType.NONE;
2537
+ const callback = () => {
2538
+ layer?.createAndAddNewEditor({
2539
+ x: 0,
2540
+ y: 0
2541
+ }, false, {
2542
+ methodOfCreation,
2543
+ boxes,
2544
+ anchorNode,
2545
+ anchorOffset,
2546
+ focusNode,
2547
+ focusOffset,
2548
+ text
2488
2549
  });
2489
- this.showAllEditors("highlight", true, true);
2490
- }
2491
- for (const layer of this.#allLayers.values()) {
2492
- if (layer.hasTextLayer(textLayer)) {
2493
- layer.createAndAddNewEditor({
2494
- x: 0,
2495
- y: 0
2496
- }, false, {
2497
- methodOfCreation,
2498
- boxes,
2499
- anchorNode,
2500
- anchorOffset,
2501
- focusNode,
2502
- focusOffset,
2503
- text
2504
- });
2505
- break;
2550
+ if (isNoneMode) {
2551
+ this.showAllEditors("highlight", true, true);
2506
2552
  }
2553
+ };
2554
+ if (isNoneMode) {
2555
+ this.switchToMode(AnnotationEditorType.HIGHLIGHT, callback);
2556
+ return;
2507
2557
  }
2558
+ callback();
2508
2559
  }
2509
2560
  #displayHighlightToolbar() {
2510
2561
  const selection = document.getSelection();
@@ -2568,11 +2619,14 @@ class AnnotationEditorUIManager {
2568
2619
  }
2569
2620
  this.#highlightWhenShiftUp = this.isShiftKeyDown;
2570
2621
  if (!this.isShiftKeyDown) {
2622
+ const activeLayer = this.#mode === AnnotationEditorType.HIGHLIGHT ? this.#getLayerForTextLayer(textLayer) : null;
2623
+ activeLayer?.toggleDrawing();
2571
2624
  const signal = this._signal;
2572
2625
  const pointerup = e => {
2573
2626
  if (e.type === "pointerup" && e.button !== 0) {
2574
2627
  return;
2575
2628
  }
2629
+ activeLayer?.toggleDrawing(true);
2576
2630
  window.removeEventListener("pointerup", pointerup);
2577
2631
  window.removeEventListener("blur", pointerup);
2578
2632
  if (e.type === "pointerup") {
@@ -4927,6 +4981,7 @@ const SerializableEmpty = Object.freeze({
4927
4981
  });
4928
4982
  class AnnotationStorage {
4929
4983
  #modified = false;
4984
+ #modifiedIds = null;
4930
4985
  #storage = new Map();
4931
4986
  constructor() {
4932
4987
  this.onSetModified = null;
@@ -5078,6 +5133,25 @@ class AnnotationStorage {
5078
5133
  }
5079
5134
  return stats;
5080
5135
  }
5136
+ resetModifiedIds() {
5137
+ this.#modifiedIds = null;
5138
+ }
5139
+ get modifiedIds() {
5140
+ if (this.#modifiedIds) {
5141
+ return this.#modifiedIds;
5142
+ }
5143
+ const ids = [];
5144
+ for (const value of this.#storage.values()) {
5145
+ if (!(value instanceof AnnotationEditor) || !value.annotationElementId || !value.serialize()) {
5146
+ continue;
5147
+ }
5148
+ ids.push(value.annotationElementId);
5149
+ }
5150
+ return this.#modifiedIds = {
5151
+ ids: new Set(ids),
5152
+ hash: ids.join(",")
5153
+ };
5154
+ }
5081
5155
  }
5082
5156
  class PrintAnnotationStorage extends AnnotationStorage {
5083
5157
  #serializable;
@@ -5103,6 +5177,12 @@ class PrintAnnotationStorage extends AnnotationStorage {
5103
5177
  get serializable() {
5104
5178
  return this.#serializable;
5105
5179
  }
5180
+ get modifiedIds() {
5181
+ return shadow(this, "modifiedIds", {
5182
+ ids: new Set(),
5183
+ hash: ""
5184
+ });
5185
+ }
5106
5186
  }
5107
5187
 
5108
5188
  ;// CONCATENATED MODULE: ./src/display/font_loader.js
@@ -6749,6 +6829,7 @@ class CanvasGraphics {
6749
6829
  while (this.stateStack.length || this.inSMaskMode) {
6750
6830
  this.restore();
6751
6831
  }
6832
+ this.current.activeSMask = null;
6752
6833
  this.ctx.restore();
6753
6834
  if (this.transparentCanvas) {
6754
6835
  this.ctx = this.compositeCtx;
@@ -7655,14 +7736,17 @@ class CanvasGraphics {
7655
7736
  this.current.patternFill = true;
7656
7737
  }
7657
7738
  setStrokeRGBColor(r, g, b) {
7658
- const color = Util.makeHexColor(r, g, b);
7659
- this.ctx.strokeStyle = color;
7660
- this.current.strokeColor = color;
7739
+ this.ctx.strokeStyle = this.current.strokeColor = Util.makeHexColor(r, g, b);
7740
+ }
7741
+ setStrokeTransparent() {
7742
+ this.ctx.strokeStyle = this.current.strokeColor = "transparent";
7661
7743
  }
7662
7744
  setFillRGBColor(r, g, b) {
7663
- const color = Util.makeHexColor(r, g, b);
7664
- this.ctx.fillStyle = color;
7665
- this.current.fillColor = color;
7745
+ this.ctx.fillStyle = this.current.fillColor = Util.makeHexColor(r, g, b);
7746
+ this.current.patternFill = false;
7747
+ }
7748
+ setFillTransparent() {
7749
+ this.ctx.fillStyle = this.current.fillColor = "transparent";
7666
7750
  this.current.patternFill = false;
7667
7751
  }
7668
7752
  _getPattern(objId, matrix = null) {
@@ -10657,6 +10741,7 @@ class TextLayer {
10657
10741
  div.style.opacity = 0;
10658
10742
  div.style.lineHeight = 1;
10659
10743
  div.style.fontSize = "1px";
10744
+ div.style.position = "absolute";
10660
10745
  div.textContent = "X";
10661
10746
  document.body.append(div);
10662
10747
  this.#minFontSize = div.getBoundingClientRect().height;
@@ -10709,37 +10794,6 @@ class TextLayer {
10709
10794
  return ratio;
10710
10795
  }
10711
10796
  }
10712
- function renderTextLayer() {
10713
- deprecated("`renderTextLayer`, please use `TextLayer` instead.");
10714
- const {
10715
- textContentSource,
10716
- container,
10717
- viewport,
10718
- ...rest
10719
- } = arguments[0];
10720
- const restKeys = Object.keys(rest);
10721
- if (restKeys.length > 0) {
10722
- warn("Ignoring `renderTextLayer` parameters: " + restKeys.join(", "));
10723
- }
10724
- const textLayer = new TextLayer({
10725
- textContentSource,
10726
- container,
10727
- viewport
10728
- });
10729
- const {
10730
- textDivs,
10731
- textContentItemsStr
10732
- } = textLayer;
10733
- const promise = textLayer.render();
10734
- return {
10735
- promise,
10736
- textDivs,
10737
- textContentItemsStr
10738
- };
10739
- }
10740
- function updateTextLayer() {
10741
- deprecated("`updateTextLayer`, please use `TextLayer` instead.");
10742
- }
10743
10797
 
10744
10798
  ;// CONCATENATED MODULE: ./src/display/xfa_text.js
10745
10799
  class XfaText {
@@ -10887,7 +10941,7 @@ function getDocument(src = {}) {
10887
10941
  }
10888
10942
  const docParams = {
10889
10943
  docId,
10890
- apiVersion: "4.4.168",
10944
+ apiVersion: "4.5.136",
10891
10945
  data,
10892
10946
  password,
10893
10947
  disableAutoFetch,
@@ -11280,10 +11334,11 @@ class PDFPageProxy {
11280
11334
  optionalContentConfigPromise = null,
11281
11335
  annotationCanvasMap = null,
11282
11336
  pageColors = null,
11283
- printAnnotationStorage = null
11337
+ printAnnotationStorage = null,
11338
+ isEditing = false
11284
11339
  }) {
11285
11340
  this._stats?.time("Overall");
11286
- const intentArgs = this._transport.getRenderingIntent(intent, annotationMode, printAnnotationStorage);
11341
+ const intentArgs = this._transport.getRenderingIntent(intent, annotationMode, printAnnotationStorage, isEditing);
11287
11342
  const {
11288
11343
  renderingIntent,
11289
11344
  cacheKey
@@ -11376,7 +11431,8 @@ class PDFPageProxy {
11376
11431
  getOperatorList({
11377
11432
  intent = "display",
11378
11433
  annotationMode = AnnotationMode.ENABLE,
11379
- printAnnotationStorage = null
11434
+ printAnnotationStorage = null,
11435
+ isEditing = false
11380
11436
  } = {}) {
11381
11437
  function operatorListChanged() {
11382
11438
  if (intentState.operatorList.lastChunk) {
@@ -11384,7 +11440,7 @@ class PDFPageProxy {
11384
11440
  intentState.renderTasks.delete(opListTask);
11385
11441
  }
11386
11442
  }
11387
- const intentArgs = this._transport.getRenderingIntent(intent, annotationMode, printAnnotationStorage, true);
11443
+ const intentArgs = this._transport.getRenderingIntent(intent, annotationMode, printAnnotationStorage, isEditing, true);
11388
11444
  let intentState = this._intentStates.get(intentArgs.cacheKey);
11389
11445
  if (!intentState) {
11390
11446
  intentState = Object.create(null);
@@ -11542,7 +11598,8 @@ class PDFPageProxy {
11542
11598
  _pumpOperatorList({
11543
11599
  renderingIntent,
11544
11600
  cacheKey,
11545
- annotationStorageSerializable
11601
+ annotationStorageSerializable,
11602
+ modifiedIds
11546
11603
  }) {
11547
11604
  const {
11548
11605
  map,
@@ -11552,7 +11609,8 @@ class PDFPageProxy {
11552
11609
  pageIndex: this._pageIndex,
11553
11610
  intent: renderingIntent,
11554
11611
  cacheKey,
11555
- annotationStorage: map
11612
+ annotationStorage: map,
11613
+ modifiedIds
11556
11614
  }, transfer);
11557
11615
  const reader = readableStream.getReader();
11558
11616
  const intentState = this._intentStates.get(cacheKey);
@@ -11924,7 +11982,7 @@ class WorkerTransport {
11924
11982
  get annotationStorage() {
11925
11983
  return shadow(this, "annotationStorage", new AnnotationStorage());
11926
11984
  }
11927
- getRenderingIntent(intent, annotationMode = AnnotationMode.ENABLE, printAnnotationStorage = null, isOpList = false) {
11985
+ getRenderingIntent(intent, annotationMode = AnnotationMode.ENABLE, printAnnotationStorage = null, isEditing = false, isOpList = false) {
11928
11986
  let renderingIntent = RenderingIntentFlag.DISPLAY;
11929
11987
  let annotationStorageSerializable = SerializableEmpty;
11930
11988
  switch (intent) {
@@ -11939,6 +11997,7 @@ class WorkerTransport {
11939
11997
  default:
11940
11998
  warn(`getRenderingIntent - invalid intent: ${intent}`);
11941
11999
  }
12000
+ const annotationStorage = renderingIntent & RenderingIntentFlag.PRINT && printAnnotationStorage instanceof PrintAnnotationStorage ? printAnnotationStorage : this.annotationStorage;
11942
12001
  switch (annotationMode) {
11943
12002
  case AnnotationMode.DISABLE:
11944
12003
  renderingIntent += RenderingIntentFlag.ANNOTATIONS_DISABLE;
@@ -11950,19 +12009,27 @@ class WorkerTransport {
11950
12009
  break;
11951
12010
  case AnnotationMode.ENABLE_STORAGE:
11952
12011
  renderingIntent += RenderingIntentFlag.ANNOTATIONS_STORAGE;
11953
- const annotationStorage = renderingIntent & RenderingIntentFlag.PRINT && printAnnotationStorage instanceof PrintAnnotationStorage ? printAnnotationStorage : this.annotationStorage;
11954
12012
  annotationStorageSerializable = annotationStorage.serializable;
11955
12013
  break;
11956
12014
  default:
11957
12015
  warn(`getRenderingIntent - invalid annotationMode: ${annotationMode}`);
11958
12016
  }
12017
+ if (isEditing) {
12018
+ renderingIntent += RenderingIntentFlag.IS_EDITING;
12019
+ }
11959
12020
  if (isOpList) {
11960
12021
  renderingIntent += RenderingIntentFlag.OPLIST;
11961
12022
  }
12023
+ const {
12024
+ ids: modifiedIds,
12025
+ hash: modifiedIdsHash
12026
+ } = annotationStorage.modifiedIds;
12027
+ const cacheKeyBuf = [renderingIntent, annotationStorageSerializable.hash, modifiedIdsHash];
11962
12028
  return {
11963
12029
  renderingIntent,
11964
- cacheKey: `${renderingIntent}_${annotationStorageSerializable.hash}`,
11965
- annotationStorageSerializable
12030
+ cacheKey: cacheKeyBuf.join("_"),
12031
+ annotationStorageSerializable,
12032
+ modifiedIds
11966
12033
  };
11967
12034
  }
11968
12035
  destroy() {
@@ -12657,8 +12724,8 @@ class InternalRenderTask {
12657
12724
  }
12658
12725
  }
12659
12726
  }
12660
- const version = "4.4.168";
12661
- const build = "19fbc8998";
12727
+ const version = "4.5.136";
12728
+ const build = "3a21f03b0";
12662
12729
 
12663
12730
  ;// CONCATENATED MODULE: ./src/shared/scripting_utils.js
12664
12731
  function makeColorComp(n) {
@@ -13042,6 +13109,9 @@ class AnnotationElement {
13042
13109
  }) {
13043
13110
  return !!(titleObj?.str || contentsObj?.str || richText?.str);
13044
13111
  }
13112
+ get _isEditable() {
13113
+ return this.data.isEditable;
13114
+ }
13045
13115
  get hasPopupData() {
13046
13116
  return AnnotationElement._hasPopupData(this.data);
13047
13117
  }
@@ -13502,9 +13572,6 @@ class AnnotationElement {
13502
13572
  triggers.classList.add("highlightArea");
13503
13573
  }
13504
13574
  }
13505
- get _isEditable() {
13506
- return false;
13507
- }
13508
13575
  _editOnDoubleClick() {
13509
13576
  if (!this._isEditable) {
13510
13577
  return;
@@ -14962,9 +15029,6 @@ class FreeTextAnnotationElement extends AnnotationElement {
14962
15029
  this._editOnDoubleClick();
14963
15030
  return this.container;
14964
15031
  }
14965
- get _isEditable() {
14966
- return this.data.hasOwnCanvas;
14967
- }
14968
15032
  }
14969
15033
  class LineAnnotationElement extends AnnotationElement {
14970
15034
  #line = null;
@@ -15372,6 +15436,9 @@ class AnnotationLayer {
15372
15436
  this.zIndex = 0;
15373
15437
  this._annotationEditorUIManager = annotationEditorUIManager;
15374
15438
  }
15439
+ hasEditableAnnotations() {
15440
+ return this.#editableAnnotations.size > 0;
15441
+ }
15375
15442
  #appendElement(element, id) {
15376
15443
  const contentElement = element.firstChild || element;
15377
15444
  contentElement.id = `${AnnotationPrefix}${id}`;
@@ -15438,7 +15505,7 @@ class AnnotationLayer {
15438
15505
  rendered.style.visibility = "hidden";
15439
15506
  }
15440
15507
  this.#appendElement(rendered, data.id);
15441
- if (element.annotationEditorType > 0) {
15508
+ if (element._isEditable) {
15442
15509
  this.#editableAnnotations.set(element.data.id, element);
15443
15510
  this._annotationEditorUIManager?.renderAnnotationElement(element);
15444
15511
  }
@@ -17426,6 +17493,7 @@ class HighlightEditor extends AnnotationEditor {
17426
17493
  return null;
17427
17494
  }
17428
17495
  const [pageWidth, pageHeight] = this.pageDimensions;
17496
+ const [pageX, pageY] = this.pageTranslation;
17429
17497
  const boxes = this.#boxes;
17430
17498
  const quadPoints = new Float32Array(boxes.length * 8);
17431
17499
  let i = 0;
@@ -17435,8 +17503,8 @@ class HighlightEditor extends AnnotationEditor {
17435
17503
  width,
17436
17504
  height
17437
17505
  } of boxes) {
17438
- const sx = x * pageWidth;
17439
- const sy = (1 - y - height) * pageHeight;
17506
+ const sx = x * pageWidth + pageX;
17507
+ const sy = (1 - y - height) * pageHeight + pageY;
17440
17508
  quadPoints[i] = quadPoints[i + 4] = sx;
17441
17509
  quadPoints[i + 1] = quadPoints[i + 3] = sy;
17442
17510
  quadPoints[i + 2] = quadPoints[i + 6] = sx + width * pageWidth;
@@ -18398,6 +18466,7 @@ class StampEditor extends AnnotationEditor {
18398
18466
  #bitmapFile = null;
18399
18467
  #bitmapFileName = "";
18400
18468
  #canvas = null;
18469
+ #hasMLBeenQueried = false;
18401
18470
  #observer = null;
18402
18471
  #resizeTimeoutId = null;
18403
18472
  #isSvg = false;
@@ -18645,6 +18714,37 @@ class StampEditor extends AnnotationEditor {
18645
18714
  }
18646
18715
  return bitmap;
18647
18716
  }
18717
+ async #mlGuessAltText(bitmap, width, height) {
18718
+ if (this.#hasMLBeenQueried) {
18719
+ return;
18720
+ }
18721
+ this.#hasMLBeenQueried = true;
18722
+ const isMLEnabled = await this._uiManager.isMLEnabledFor("altText");
18723
+ if (!isMLEnabled || this.hasAltText()) {
18724
+ return;
18725
+ }
18726
+ const offscreen = new OffscreenCanvas(width, height);
18727
+ const ctx = offscreen.getContext("2d", {
18728
+ willReadFrequently: true
18729
+ });
18730
+ ctx.drawImage(bitmap, 0, 0, bitmap.width, bitmap.height, 0, 0, width, height);
18731
+ const response = await this._uiManager.mlGuess({
18732
+ service: "moz-image-to-text",
18733
+ request: {
18734
+ data: ctx.getImageData(0, 0, width, height).data,
18735
+ width,
18736
+ height,
18737
+ channels: 4
18738
+ }
18739
+ });
18740
+ const altText = response?.output || "";
18741
+ if (this.parent && altText && !this.hasAltText()) {
18742
+ this.altTextData = {
18743
+ altText,
18744
+ decorative: false
18745
+ };
18746
+ }
18747
+ }
18648
18748
  #drawBitmap(width, height) {
18649
18749
  width = Math.ceil(width);
18650
18750
  height = Math.ceil(height);
@@ -18655,28 +18755,7 @@ class StampEditor extends AnnotationEditor {
18655
18755
  canvas.width = width;
18656
18756
  canvas.height = height;
18657
18757
  const bitmap = this.#isSvg ? this.#bitmap : this.#scaleBitmap(width, height);
18658
- if (this._uiManager.hasMLManager && !this.hasAltText()) {
18659
- const offscreen = new OffscreenCanvas(width, height);
18660
- const ctx = offscreen.getContext("2d");
18661
- ctx.drawImage(bitmap, 0, 0, bitmap.width, bitmap.height, 0, 0, width, height);
18662
- this._uiManager.mlGuess({
18663
- service: "image-to-text",
18664
- request: {
18665
- data: ctx.getImageData(0, 0, width, height).data,
18666
- width,
18667
- height,
18668
- channels: 4
18669
- }
18670
- }).then(response => {
18671
- const altText = response?.output || "";
18672
- if (this.parent && altText && !this.hasAltText()) {
18673
- this.altTextData = {
18674
- altText,
18675
- decorative: false
18676
- };
18677
- }
18678
- });
18679
- }
18758
+ this.#mlGuessAltText(bitmap, width, height);
18680
18759
  const ctx = canvas.getContext("2d");
18681
18760
  ctx.filter = this._uiManager.hcmFilter;
18682
18761
  ctx.drawImage(bitmap, 0, 0, bitmap.width, bitmap.height, 0, 0, width, height);
@@ -18930,6 +19009,9 @@ class AnnotationEditorLayer {
18930
19009
  addCommands(params) {
18931
19010
  this.#uiManager.addCommands(params);
18932
19011
  }
19012
+ toggleDrawing(enabled = false) {
19013
+ this.div.classList.toggle("drawing", !enabled);
19014
+ }
18933
19015
  togglePointerEvents(enabled = false) {
18934
19016
  this.div.classList.toggle("disabled", !enabled);
18935
19017
  }
@@ -19057,7 +19139,10 @@ class AnnotationEditorLayer {
19057
19139
  }
19058
19140
  #textLayerPointerDown(event) {
19059
19141
  this.#uiManager.unselectAll();
19060
- if (event.target === this.#textLayer.div) {
19142
+ const {
19143
+ target
19144
+ } = event;
19145
+ if (target === this.#textLayer.div || target.classList.contains("endOfContent") && this.#textLayer.div.contains(target)) {
19061
19146
  const {
19062
19147
  isMac
19063
19148
  } = util_FeatureTest.platform;
@@ -19066,9 +19151,11 @@ class AnnotationEditorLayer {
19066
19151
  }
19067
19152
  this.#uiManager.showAllEditors("highlight", true, true);
19068
19153
  this.#textLayer.div.classList.add("free");
19154
+ this.toggleDrawing();
19069
19155
  HighlightEditor.startHighlighting(this, this.#uiManager.direction === "ltr", event);
19070
19156
  this.#textLayer.div.addEventListener("pointerup", () => {
19071
19157
  this.#textLayer.div.classList.remove("free");
19158
+ this.toggleDrawing(true);
19072
19159
  }, {
19073
19160
  once: true,
19074
19161
  signal: this.#uiManager._signal
@@ -19624,8 +19711,8 @@ class DrawLayer {
19624
19711
 
19625
19712
 
19626
19713
 
19627
- const pdfjsVersion = "4.4.168";
19628
- const pdfjsBuild = "19fbc8998";
19714
+ const pdfjsVersion = "4.5.136";
19715
+ const pdfjsBuild = "3a21f03b0";
19629
19716
 
19630
19717
  var __webpack_exports__AbortException = __webpack_exports__.AbortException;
19631
19718
  var __webpack_exports__AnnotationEditorLayer = __webpack_exports__.AnnotationEditorLayer;
@@ -19644,7 +19731,6 @@ var __webpack_exports__ImageKind = __webpack_exports__.ImageKind;
19644
19731
  var __webpack_exports__InvalidPDFException = __webpack_exports__.InvalidPDFException;
19645
19732
  var __webpack_exports__MissingPDFException = __webpack_exports__.MissingPDFException;
19646
19733
  var __webpack_exports__OPS = __webpack_exports__.OPS;
19647
- var __webpack_exports__Outliner = __webpack_exports__.Outliner;
19648
19734
  var __webpack_exports__PDFDataRangeTransport = __webpack_exports__.PDFDataRangeTransport;
19649
19735
  var __webpack_exports__PDFDateString = __webpack_exports__.PDFDateString;
19650
19736
  var __webpack_exports__PDFWorker = __webpack_exports__.PDFWorker;
@@ -19668,11 +19754,9 @@ var __webpack_exports__isDataScheme = __webpack_exports__.isDataScheme;
19668
19754
  var __webpack_exports__isPdfFile = __webpack_exports__.isPdfFile;
19669
19755
  var __webpack_exports__noContextMenu = __webpack_exports__.noContextMenu;
19670
19756
  var __webpack_exports__normalizeUnicode = __webpack_exports__.normalizeUnicode;
19671
- var __webpack_exports__renderTextLayer = __webpack_exports__.renderTextLayer;
19672
19757
  var __webpack_exports__setLayerDimensions = __webpack_exports__.setLayerDimensions;
19673
19758
  var __webpack_exports__shadow = __webpack_exports__.shadow;
19674
- var __webpack_exports__updateTextLayer = __webpack_exports__.updateTextLayer;
19675
19759
  var __webpack_exports__version = __webpack_exports__.version;
19676
- export { __webpack_exports__AbortException as AbortException, __webpack_exports__AnnotationEditorLayer as AnnotationEditorLayer, __webpack_exports__AnnotationEditorParamsType as AnnotationEditorParamsType, __webpack_exports__AnnotationEditorType as AnnotationEditorType, __webpack_exports__AnnotationEditorUIManager as AnnotationEditorUIManager, __webpack_exports__AnnotationLayer as AnnotationLayer, __webpack_exports__AnnotationMode as AnnotationMode, __webpack_exports__CMapCompressionType as CMapCompressionType, __webpack_exports__ColorPicker as ColorPicker, __webpack_exports__DOMSVGFactory as DOMSVGFactory, __webpack_exports__DrawLayer as DrawLayer, __webpack_exports__FeatureTest as FeatureTest, __webpack_exports__GlobalWorkerOptions as GlobalWorkerOptions, __webpack_exports__ImageKind as ImageKind, __webpack_exports__InvalidPDFException as InvalidPDFException, __webpack_exports__MissingPDFException as MissingPDFException, __webpack_exports__OPS as OPS, __webpack_exports__Outliner as Outliner, __webpack_exports__PDFDataRangeTransport as PDFDataRangeTransport, __webpack_exports__PDFDateString as PDFDateString, __webpack_exports__PDFWorker as PDFWorker, __webpack_exports__PasswordResponses as PasswordResponses, __webpack_exports__PermissionFlag as PermissionFlag, __webpack_exports__PixelsPerInch as PixelsPerInch, __webpack_exports__RenderingCancelledException as RenderingCancelledException, __webpack_exports__TextLayer as TextLayer, __webpack_exports__UnexpectedResponseException as UnexpectedResponseException, __webpack_exports__Util as Util, __webpack_exports__VerbosityLevel as VerbosityLevel, __webpack_exports__XfaLayer as XfaLayer, __webpack_exports__build as build, __webpack_exports__createValidAbsoluteUrl as createValidAbsoluteUrl, __webpack_exports__fetchData as fetchData, __webpack_exports__getDocument as getDocument, __webpack_exports__getFilenameFromUrl as getFilenameFromUrl, __webpack_exports__getPdfFilenameFromUrl as getPdfFilenameFromUrl, __webpack_exports__getXfaPageViewport as getXfaPageViewport, __webpack_exports__isDataScheme as isDataScheme, __webpack_exports__isPdfFile as isPdfFile, __webpack_exports__noContextMenu as noContextMenu, __webpack_exports__normalizeUnicode as normalizeUnicode, __webpack_exports__renderTextLayer as renderTextLayer, __webpack_exports__setLayerDimensions as setLayerDimensions, __webpack_exports__shadow as shadow, __webpack_exports__updateTextLayer as updateTextLayer, __webpack_exports__version as version };
19760
+ export { __webpack_exports__AbortException as AbortException, __webpack_exports__AnnotationEditorLayer as AnnotationEditorLayer, __webpack_exports__AnnotationEditorParamsType as AnnotationEditorParamsType, __webpack_exports__AnnotationEditorType as AnnotationEditorType, __webpack_exports__AnnotationEditorUIManager as AnnotationEditorUIManager, __webpack_exports__AnnotationLayer as AnnotationLayer, __webpack_exports__AnnotationMode as AnnotationMode, __webpack_exports__CMapCompressionType as CMapCompressionType, __webpack_exports__ColorPicker as ColorPicker, __webpack_exports__DOMSVGFactory as DOMSVGFactory, __webpack_exports__DrawLayer as DrawLayer, __webpack_exports__FeatureTest as FeatureTest, __webpack_exports__GlobalWorkerOptions as GlobalWorkerOptions, __webpack_exports__ImageKind as ImageKind, __webpack_exports__InvalidPDFException as InvalidPDFException, __webpack_exports__MissingPDFException as MissingPDFException, __webpack_exports__OPS as OPS, __webpack_exports__PDFDataRangeTransport as PDFDataRangeTransport, __webpack_exports__PDFDateString as PDFDateString, __webpack_exports__PDFWorker as PDFWorker, __webpack_exports__PasswordResponses as PasswordResponses, __webpack_exports__PermissionFlag as PermissionFlag, __webpack_exports__PixelsPerInch as PixelsPerInch, __webpack_exports__RenderingCancelledException as RenderingCancelledException, __webpack_exports__TextLayer as TextLayer, __webpack_exports__UnexpectedResponseException as UnexpectedResponseException, __webpack_exports__Util as Util, __webpack_exports__VerbosityLevel as VerbosityLevel, __webpack_exports__XfaLayer as XfaLayer, __webpack_exports__build as build, __webpack_exports__createValidAbsoluteUrl as createValidAbsoluteUrl, __webpack_exports__fetchData as fetchData, __webpack_exports__getDocument as getDocument, __webpack_exports__getFilenameFromUrl as getFilenameFromUrl, __webpack_exports__getPdfFilenameFromUrl as getPdfFilenameFromUrl, __webpack_exports__getXfaPageViewport as getXfaPageViewport, __webpack_exports__isDataScheme as isDataScheme, __webpack_exports__isPdfFile as isPdfFile, __webpack_exports__noContextMenu as noContextMenu, __webpack_exports__normalizeUnicode as normalizeUnicode, __webpack_exports__setLayerDimensions as setLayerDimensions, __webpack_exports__shadow as shadow, __webpack_exports__version as version };
19677
19761
 
19678
19762
  //# sourceMappingURL=pdf.mjs.map