pdfjs-dist 2.6.347 → 2.7.570

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.

Potentially problematic release.


This version of pdfjs-dist might be problematic. Click here for more details.

Files changed (158) hide show
  1. package/README.md +3 -3
  2. package/bower.json +1 -1
  3. package/build/pdf.js +2050 -1087
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +18219 -10436
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/es5/build/pdf.d.ts +1 -0
  10. package/es5/build/pdf.js +6623 -6654
  11. package/es5/build/pdf.js.map +1 -1
  12. package/es5/build/pdf.min.js +1 -1
  13. package/es5/build/pdf.worker.js +20815 -13888
  14. package/es5/build/pdf.worker.js.map +1 -1
  15. package/es5/build/pdf.worker.min.js +1 -1
  16. package/es5/image_decoders/pdf.image_decoders.js +3817 -4946
  17. package/es5/image_decoders/pdf.image_decoders.js.map +1 -1
  18. package/es5/image_decoders/pdf.image_decoders.min.js +1 -1
  19. package/es5/web/pdf_viewer.css +18 -15
  20. package/es5/web/pdf_viewer.js +1094 -514
  21. package/es5/web/pdf_viewer.js.map +1 -1
  22. package/image_decoders/pdf.image_decoders.js +774 -168
  23. package/image_decoders/pdf.image_decoders.js.map +1 -1
  24. package/image_decoders/pdf.image_decoders.min.js +1 -1
  25. package/lib/core/annotation.js +556 -108
  26. package/lib/core/cff_parser.js +7 -1
  27. package/lib/core/charsets.js +1 -1
  28. package/lib/core/cmap.js +20 -1
  29. package/lib/core/core_utils.js +162 -3
  30. package/lib/core/crypto.js +1 -1
  31. package/lib/core/default_appearance.js +132 -0
  32. package/lib/core/document.js +115 -9
  33. package/lib/core/encodings.js +1 -1
  34. package/lib/core/evaluator.js +168 -74
  35. package/lib/core/fonts.js +97 -11
  36. package/lib/core/function.js +5 -10
  37. package/lib/core/glyphlist.js +11 -4529
  38. package/lib/core/image_utils.js +30 -1
  39. package/lib/core/jpg.js +1 -1
  40. package/lib/core/jpx.js +5 -5
  41. package/lib/core/murmurhash3.js +1 -1
  42. package/lib/core/obj.js +123 -39
  43. package/lib/core/pattern.js +4 -4
  44. package/lib/core/primitives.js +24 -5
  45. package/lib/core/standard_fonts.js +1 -1
  46. package/lib/core/stream.js +5 -1
  47. package/lib/core/unicode.js +15 -1387
  48. package/lib/core/worker.js +58 -17
  49. package/lib/core/writer.js +68 -4
  50. package/lib/display/annotation_layer.js +712 -119
  51. package/lib/display/annotation_storage.js +21 -4
  52. package/lib/display/api.js +88 -18
  53. package/lib/display/canvas.js +414 -375
  54. package/lib/display/display_utils.js +11 -4
  55. package/lib/display/fetch_stream.js +3 -3
  56. package/lib/display/font_loader.js +2 -3
  57. package/lib/display/metadata.js +54 -20
  58. package/lib/display/node_stream.js +1 -1
  59. package/lib/display/optional_content_config.js +1 -1
  60. package/lib/display/pattern_helper.js +109 -113
  61. package/lib/display/svg.js +5 -5
  62. package/lib/display/text_layer.js +54 -54
  63. package/lib/display/transport_stream.js +4 -4
  64. package/lib/display/webgl.js +65 -68
  65. package/lib/examples/node/domstubs.js +9 -4
  66. package/lib/pdf.js +2 -2
  67. package/lib/pdf.sandbox.js +311 -0
  68. package/lib/pdf.worker.js +2 -2
  69. package/lib/shared/scripting_utils.js +84 -0
  70. package/lib/shared/util.js +129 -14
  71. package/lib/{display → shared}/xml_parser.js +112 -4
  72. package/lib/test/unit/annotation_spec.js +831 -109
  73. package/lib/test/unit/annotation_storage_spec.js +28 -10
  74. package/lib/test/unit/api_spec.js +190 -160
  75. package/lib/test/unit/bidi_spec.js +6 -6
  76. package/lib/test/unit/cff_parser_spec.js +73 -73
  77. package/lib/test/unit/clitests_helper.js +2 -0
  78. package/lib/test/unit/cmap_spec.js +48 -74
  79. package/lib/test/unit/core_utils_spec.js +34 -0
  80. package/lib/test/unit/crypto_spec.js +162 -199
  81. package/lib/test/unit/custom_spec.js +7 -18
  82. package/lib/test/unit/default_appearance_spec.js +54 -0
  83. package/lib/test/unit/display_svg_spec.js +24 -19
  84. package/lib/test/unit/display_utils_spec.js +1 -1
  85. package/lib/test/unit/document_spec.js +187 -20
  86. package/lib/test/unit/evaluator_spec.js +30 -30
  87. package/lib/test/unit/function_spec.js +165 -165
  88. package/lib/test/unit/jasmine-boot.js +52 -53
  89. package/lib/test/unit/metadata_spec.js +2 -2
  90. package/lib/test/unit/murmurhash3_spec.js +29 -16
  91. package/lib/test/unit/network_spec.js +21 -21
  92. package/lib/test/unit/pdf_find_controller_spec.js +131 -69
  93. package/lib/test/unit/pdf_find_utils_spec.js +10 -10
  94. package/lib/test/unit/scripting_spec.js +1104 -0
  95. package/lib/test/unit/stream_spec.js +8 -8
  96. package/lib/test/unit/test_utils.js +16 -19
  97. package/lib/test/unit/testreporter.js +11 -4
  98. package/lib/test/unit/type1_parser_spec.js +23 -23
  99. package/lib/test/unit/ui_utils_spec.js +78 -35
  100. package/lib/test/unit/unicode_spec.js +7 -7
  101. package/lib/test/unit/util_spec.js +26 -3
  102. package/lib/test/unit/writer_spec.js +16 -1
  103. package/lib/test/unit/xml_spec.js +117 -0
  104. package/lib/web/annotation_layer_builder.js +18 -6
  105. package/lib/web/app.js +579 -161
  106. package/lib/web/app_options.js +14 -0
  107. package/lib/web/base_tree_viewer.js +50 -0
  108. package/lib/web/base_viewer.js +350 -14
  109. package/lib/web/chromecom.js +9 -1
  110. package/lib/web/debugger.js +1 -2
  111. package/lib/web/download_manager.js +0 -15
  112. package/lib/web/firefox_print_service.js +6 -4
  113. package/lib/web/firefoxcom.js +84 -69
  114. package/lib/web/generic_scripting.js +55 -0
  115. package/lib/web/genericcom.js +9 -1
  116. package/lib/web/grab_to_pan.js +1 -1
  117. package/lib/web/interfaces.js +9 -3
  118. package/lib/web/pdf_attachment_viewer.js +1 -3
  119. package/lib/web/pdf_cursor_tools.js +20 -13
  120. package/lib/web/pdf_document_properties.js +48 -61
  121. package/lib/web/pdf_find_bar.js +1 -3
  122. package/lib/web/pdf_find_controller.js +58 -12
  123. package/lib/web/pdf_history.js +43 -21
  124. package/lib/web/pdf_layer_viewer.js +1 -9
  125. package/lib/web/pdf_link_service.js +108 -78
  126. package/lib/web/pdf_outline_viewer.js +166 -10
  127. package/lib/web/pdf_page_view.js +14 -14
  128. package/lib/web/pdf_presentation_mode.js +21 -31
  129. package/lib/web/pdf_rendering_queue.js +8 -1
  130. package/lib/web/pdf_sidebar.js +62 -107
  131. package/lib/web/pdf_sidebar_resizer.js +11 -21
  132. package/lib/web/pdf_single_page_viewer.js +8 -0
  133. package/lib/web/pdf_thumbnail_view.js +26 -26
  134. package/lib/web/pdf_thumbnail_viewer.js +13 -2
  135. package/lib/web/pdf_viewer.component.js +2 -2
  136. package/lib/web/pdf_viewer.js +3 -1
  137. package/lib/web/preferences.js +33 -44
  138. package/lib/web/text_layer_builder.js +2 -9
  139. package/lib/web/ui_utils.js +78 -46
  140. package/lib/web/viewer_compatibility.js +1 -2
  141. package/package.json +4 -1
  142. package/types/display/annotation_layer.d.ts +18 -3
  143. package/types/display/api.d.ts +110 -54
  144. package/types/display/canvas.d.ts +1 -1
  145. package/types/display/display_utils.d.ts +96 -95
  146. package/types/display/fetch_stream.d.ts +2 -2
  147. package/types/display/metadata.d.ts +4 -0
  148. package/types/display/pattern_helper.d.ts +1 -1
  149. package/types/display/text_layer.d.ts +7 -7
  150. package/types/display/transport_stream.d.ts +1 -1
  151. package/types/shared/scripting_utils.d.ts +12 -0
  152. package/types/shared/util.d.ts +281 -250
  153. package/types/shared/xml_parser.d.ts +64 -0
  154. package/web/pdf_viewer.css +18 -15
  155. package/web/pdf_viewer.js +809 -408
  156. package/web/pdf_viewer.js.map +1 -1
  157. package/webpack.js +1 -1
  158. package/types/display/xml_parser.d.ts +0 -35
@@ -63,9 +63,43 @@ function normalize(text) {
63
63
  normalizationRegex = new RegExp(`[${replace}]`, "g");
64
64
  }
65
65
 
66
- return text.replace(normalizationRegex, function (ch) {
67
- return CHARACTERS_TO_NORMALIZE[ch];
66
+ let diffs = null;
67
+ const normalizedText = text.replace(normalizationRegex, function (ch, index) {
68
+ const normalizedCh = CHARACTERS_TO_NORMALIZE[ch],
69
+ diff = normalizedCh.length - ch.length;
70
+
71
+ if (diff !== 0) {
72
+ (diffs || (diffs = [])).push([index, diff]);
73
+ }
74
+
75
+ return normalizedCh;
68
76
  });
77
+ return [normalizedText, diffs];
78
+ }
79
+
80
+ function getOriginalIndex(matchIndex, diffs = null) {
81
+ if (!diffs) {
82
+ return matchIndex;
83
+ }
84
+
85
+ let totalDiff = 0;
86
+
87
+ for (const [index, diff] of diffs) {
88
+ const currentIndex = index + totalDiff;
89
+
90
+ if (currentIndex >= matchIndex) {
91
+ break;
92
+ }
93
+
94
+ if (currentIndex + diff > matchIndex) {
95
+ totalDiff += matchIndex - currentIndex;
96
+ break;
97
+ }
98
+
99
+ totalDiff += diff;
100
+ }
101
+
102
+ return matchIndex - totalDiff;
69
103
  }
70
104
 
71
105
  class PDFFindController {
@@ -214,6 +248,7 @@ class PDFFindController {
214
248
  };
215
249
  this._extractTextPromises = [];
216
250
  this._pageContents = [];
251
+ this._pageDiffs = [];
217
252
  this._matchesCountTotal = 0;
218
253
  this._pagesToSearch = null;
219
254
  this._pendingFindMatches = Object.create(null);
@@ -227,7 +262,7 @@ class PDFFindController {
227
262
  get _query() {
228
263
  if (this._state.query !== this._rawQuery) {
229
264
  this._rawQuery = this._state.query;
230
- this._normalizedQuery = normalize(this._state.query);
265
+ [this._normalizedQuery] = normalize(this._state.query);
231
266
  }
232
267
 
233
268
  return this._normalizedQuery;
@@ -324,8 +359,9 @@ class PDFFindController {
324
359
  return true;
325
360
  }
326
361
 
327
- _calculatePhraseMatch(query, pageIndex, pageContent, entireWord) {
328
- const matches = [];
362
+ _calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord) {
363
+ const matches = [],
364
+ matchesLength = [];
329
365
  const queryLen = query.length;
330
366
  let matchIdx = -queryLen;
331
367
 
@@ -340,13 +376,18 @@ class PDFFindController {
340
376
  continue;
341
377
  }
342
378
 
343
- matches.push(matchIdx);
379
+ const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
380
+ matchEnd = matchIdx + queryLen - 1,
381
+ originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
382
+ matches.push(originalMatchIdx);
383
+ matchesLength.push(originalQueryLen);
344
384
  }
345
385
 
346
386
  this._pageMatches[pageIndex] = matches;
387
+ this._pageMatchesLength[pageIndex] = matchesLength;
347
388
  }
348
389
 
349
- _calculateWordMatch(query, pageIndex, pageContent, entireWord) {
390
+ _calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord) {
350
391
  const matchesWithLength = [];
351
392
  const queryArray = query.match(/\S+/g);
352
393
 
@@ -366,9 +407,12 @@ class PDFFindController {
366
407
  continue;
367
408
  }
368
409
 
410
+ const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
411
+ matchEnd = matchIdx + subqueryLen - 1,
412
+ originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
369
413
  matchesWithLength.push({
370
- match: matchIdx,
371
- matchLength: subqueryLen,
414
+ match: originalMatchIdx,
415
+ matchLength: originalQueryLen,
372
416
  skipped: false
373
417
  });
374
418
  }
@@ -382,6 +426,7 @@ class PDFFindController {
382
426
 
383
427
  _calculateMatch(pageIndex) {
384
428
  let pageContent = this._pageContents[pageIndex];
429
+ const pageDiffs = this._pageDiffs[pageIndex];
385
430
  let query = this._query;
386
431
  const {
387
432
  caseSensitive,
@@ -399,9 +444,9 @@ class PDFFindController {
399
444
  }
400
445
 
401
446
  if (phraseSearch) {
402
- this._calculatePhraseMatch(query, pageIndex, pageContent, entireWord);
447
+ this._calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord);
403
448
  } else {
404
- this._calculateWordMatch(query, pageIndex, pageContent, entireWord);
449
+ this._calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord);
405
450
  }
406
451
 
407
452
  if (this._state.highlightAll) {
@@ -446,11 +491,12 @@ class PDFFindController {
446
491
  strBuf.push(textItems[j].str);
447
492
  }
448
493
 
449
- this._pageContents[i] = normalize(strBuf.join(""));
494
+ [this._pageContents[i], this._pageDiffs[i]] = normalize(strBuf.join(""));
450
495
  extractTextCapability.resolve(i);
451
496
  }, reason => {
452
497
  console.error(`Unable to get text content for page ${i + 1}`, reason);
453
498
  this._pageContents[i] = "";
499
+ this._pageDiffs[i] = null;
454
500
  extractTextCapability.resolve(i);
455
501
  });
456
502
  });
@@ -24,8 +24,8 @@
24
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
- exports.isDestHashesEqual = isDestHashesEqual;
28
27
  exports.isDestArraysEqual = isDestArraysEqual;
28
+ exports.isDestHashesEqual = isDestHashesEqual;
29
29
  exports.PDFHistory = void 0;
30
30
 
31
31
  var _ui_utils = require("./ui_utils.js");
@@ -52,19 +52,17 @@ class PDFHistory {
52
52
  this._isViewerInPresentationMode = false;
53
53
 
54
54
  this.eventBus._on("presentationmodechanged", evt => {
55
- this._isViewerInPresentationMode = evt.active || evt.switchInProgress;
55
+ this._isViewerInPresentationMode = evt.state !== _ui_utils.PresentationModeState.NORMAL;
56
56
  });
57
57
 
58
58
  this.eventBus._on("pagesinit", () => {
59
59
  this._isPagesLoaded = false;
60
60
 
61
- const onPagesLoaded = evt => {
62
- this.eventBus._off("pagesloaded", onPagesLoaded);
63
-
61
+ this.eventBus._on("pagesloaded", evt => {
64
62
  this._isPagesLoaded = !!evt.pagesCount;
65
- };
66
-
67
- this.eventBus._on("pagesloaded", onPagesLoaded);
63
+ }, {
64
+ once: true
65
+ });
68
66
  });
69
67
  }
70
68
 
@@ -124,10 +122,6 @@ class PDFHistory {
124
122
 
125
123
  this._updateInternalState(destination, state.uid, true);
126
124
 
127
- if (this._uid > this._maxUid) {
128
- this._maxUid = this._uid;
129
- }
130
-
131
125
  if (destination.rotation !== undefined) {
132
126
  this._initialRotation = destination.rotation;
133
127
  }
@@ -217,6 +211,38 @@ class PDFHistory {
217
211
  }
218
212
  }
219
213
 
214
+ pushPage(pageNumber) {
215
+ if (!this._initialized) {
216
+ return;
217
+ }
218
+
219
+ if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.linkService.pagesCount)) {
220
+ console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
221
+ return;
222
+ }
223
+
224
+ if (this._destination?.page === pageNumber) {
225
+ return;
226
+ }
227
+
228
+ if (this._popStateInProgress) {
229
+ return;
230
+ }
231
+
232
+ this._pushOrReplaceState({
233
+ hash: `page=${pageNumber}`,
234
+ page: pageNumber,
235
+ rotation: this.linkService.rotation
236
+ });
237
+
238
+ if (!this._popStateInProgress) {
239
+ this._popStateInProgress = true;
240
+ Promise.resolve().then(() => {
241
+ this._popStateInProgress = false;
242
+ });
243
+ }
244
+ }
245
+
220
246
  pushCurrentPosition() {
221
247
  if (!this._initialized || this._popStateInProgress) {
222
248
  return;
@@ -273,7 +299,7 @@ class PDFHistory {
273
299
 
274
300
  let newUrl;
275
301
 
276
- if (this._updateUrl && destination && destination.hash) {
302
+ if (this._updateUrl && destination?.hash) {
277
303
  const baseUrl = document.location.href.split("#")[0];
278
304
 
279
305
  if (!baseUrl.startsWith("file://")) {
@@ -284,7 +310,6 @@ class PDFHistory {
284
310
  if (shouldReplace) {
285
311
  window.history.replaceState(newState, "", newUrl);
286
312
  } else {
287
- this._maxUid = this._uid;
288
313
  window.history.pushState(newState, "", newUrl);
289
314
  }
290
315
  }
@@ -347,7 +372,7 @@ class PDFHistory {
347
372
 
348
373
  const [perfEntry] = performance.getEntriesByType("navigation");
349
374
 
350
- if (!perfEntry || perfEntry.type !== "reload") {
375
+ if (perfEntry?.type !== "reload") {
351
376
  return false;
352
377
  }
353
378
  } else {
@@ -372,12 +397,13 @@ class PDFHistory {
372
397
  this._updateViewareaTimeout = null;
373
398
  }
374
399
 
375
- if (removeTemporary && destination && destination.temporary) {
400
+ if (removeTemporary && destination?.temporary) {
376
401
  delete destination.temporary;
377
402
  }
378
403
 
379
404
  this._destination = destination;
380
405
  this._uid = uid;
406
+ this._maxUid = Math.max(this._maxUid, uid);
381
407
  this._numPositionUpdates = 0;
382
408
  }
383
409
 
@@ -478,16 +504,12 @@ class PDFHistory {
478
504
 
479
505
  this._updateInternalState(destination, state.uid, true);
480
506
 
481
- if (this._uid > this._maxUid) {
482
- this._maxUid = this._uid;
483
- }
484
-
485
507
  if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
486
508
  this.linkService.rotation = destination.rotation;
487
509
  }
488
510
 
489
511
  if (destination.dest) {
490
- this.linkService.navigateTo(destination.dest);
512
+ this.linkService.goToDestination(destination.dest);
491
513
  } else if (destination.hash) {
492
514
  this.linkService.setHash(destination.hash);
493
515
  } else if (destination.page) {
@@ -41,7 +41,6 @@ class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
41
41
  reset() {
42
42
  super.reset();
43
43
  this._optionalContentConfig = null;
44
- this._pdfDocument = null;
45
44
  }
46
45
 
47
46
  _dispatchEvent(layersCount) {
@@ -177,14 +176,7 @@ class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
177
176
  }
178
177
  }
179
178
 
180
- if (hasAnyNesting) {
181
- this.container.classList.add("treeWithDeepNesting");
182
- this._lastToggleIsShow = fragment.querySelectorAll(".treeItemsHidden").length === 0;
183
- }
184
-
185
- this.container.appendChild(fragment);
186
-
187
- this._dispatchEvent(layersCount);
179
+ this._finishRendering(fragment, layersCount, hasAnyNesting);
188
180
  }
189
181
 
190
182
  async _resetLayers() {
@@ -83,89 +83,111 @@ class PDFLinkService {
83
83
  }
84
84
 
85
85
  navigateTo(dest) {
86
- const goToDestination = ({
87
- namedDest,
88
- explicitDest
89
- }) => {
90
- const destRef = explicitDest[0];
91
- let pageNumber;
92
-
93
- if (destRef instanceof Object) {
94
- pageNumber = this._cachedPageNumber(destRef);
95
-
96
- if (pageNumber === null) {
97
- this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
98
- this.cachePageRef(pageIndex + 1, destRef);
99
- goToDestination({
100
- namedDest,
101
- explicitDest
102
- });
103
- }).catch(() => {
104
- console.error(`PDFLinkService.navigateTo: "${destRef}" is not ` + `a valid page reference, for dest="${dest}".`);
105
- });
106
- return;
107
- }
108
- } else if (Number.isInteger(destRef)) {
109
- pageNumber = destRef + 1;
110
- } else {
111
- console.error(`PDFLinkService.navigateTo: "${destRef}" is not ` + `a valid destination reference, for dest="${dest}".`);
112
- return;
113
- }
86
+ console.error("Deprecated method: `navigateTo`, use `goToDestination` instead.");
87
+ this.goToDestination(dest);
88
+ }
114
89
 
115
- if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
116
- console.error(`PDFLinkService.navigateTo: "${pageNumber}" is not ` + `a valid page number, for dest="${dest}".`);
117
- return;
118
- }
90
+ _goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
91
+ const destRef = explicitDest[0];
92
+ let pageNumber;
119
93
 
120
- if (this.pdfHistory) {
121
- this.pdfHistory.pushCurrentPosition();
122
- this.pdfHistory.push({
123
- namedDest,
124
- explicitDest,
125
- pageNumber
126
- });
127
- }
94
+ if (destRef instanceof Object) {
95
+ pageNumber = this._cachedPageNumber(destRef);
128
96
 
129
- this.pdfViewer.scrollPageIntoView({
130
- pageNumber,
131
- destArray: explicitDest,
132
- ignoreDestinationZoom: this._ignoreDestinationZoom
133
- });
134
- };
135
-
136
- new Promise((resolve, reject) => {
137
- if (typeof dest === "string") {
138
- this.pdfDocument.getDestination(dest).then(destArray => {
139
- resolve({
140
- namedDest: dest,
141
- explicitDest: destArray
142
- });
97
+ if (pageNumber === null) {
98
+ this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
99
+ this.cachePageRef(pageIndex + 1, destRef);
100
+
101
+ this._goToDestinationHelper(rawDest, namedDest, explicitDest);
102
+ }).catch(() => {
103
+ console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
143
104
  });
144
105
  return;
145
106
  }
107
+ } else if (Number.isInteger(destRef)) {
108
+ pageNumber = destRef + 1;
109
+ } else {
110
+ console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
111
+ return;
112
+ }
113
+
114
+ if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
115
+ console.error(`PDFLinkService._goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
116
+ return;
117
+ }
146
118
 
147
- resolve({
148
- namedDest: "",
149
- explicitDest: dest
119
+ if (this.pdfHistory) {
120
+ this.pdfHistory.pushCurrentPosition();
121
+ this.pdfHistory.push({
122
+ namedDest,
123
+ explicitDest,
124
+ pageNumber
150
125
  });
151
- }).then(data => {
152
- if (!Array.isArray(data.explicitDest)) {
153
- console.error(`PDFLinkService.navigateTo: "${data.explicitDest}" is` + ` not a valid destination array, for dest="${dest}".`);
154
- return;
155
- }
126
+ }
156
127
 
157
- goToDestination(data);
128
+ this.pdfViewer.scrollPageIntoView({
129
+ pageNumber,
130
+ destArray: explicitDest,
131
+ ignoreDestinationZoom: this._ignoreDestinationZoom
158
132
  });
159
133
  }
160
134
 
161
- getDestinationHash(dest) {
135
+ async goToDestination(dest) {
136
+ if (!this.pdfDocument) {
137
+ return;
138
+ }
139
+
140
+ let namedDest, explicitDest;
141
+
162
142
  if (typeof dest === "string") {
163
- return this.getAnchorUrl("#" + escape(dest));
143
+ namedDest = dest;
144
+ explicitDest = await this.pdfDocument.getDestination(dest);
145
+ } else {
146
+ namedDest = null;
147
+ explicitDest = await dest;
148
+ }
149
+
150
+ if (!Array.isArray(explicitDest)) {
151
+ console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
152
+ return;
153
+ }
154
+
155
+ this._goToDestinationHelper(dest, namedDest, explicitDest);
156
+ }
157
+
158
+ goToPage(val) {
159
+ if (!this.pdfDocument) {
160
+ return;
161
+ }
162
+
163
+ const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
164
+
165
+ if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
166
+ console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
167
+ return;
164
168
  }
165
169
 
166
- if (Array.isArray(dest)) {
170
+ if (this.pdfHistory) {
171
+ this.pdfHistory.pushCurrentPosition();
172
+ this.pdfHistory.pushPage(pageNumber);
173
+ }
174
+
175
+ this.pdfViewer.scrollPageIntoView({
176
+ pageNumber
177
+ });
178
+ }
179
+
180
+ getDestinationHash(dest) {
181
+ if (typeof dest === "string") {
182
+ if (dest.length > 0) {
183
+ return this.getAnchorUrl("#" + escape(dest));
184
+ }
185
+ } else if (Array.isArray(dest)) {
167
186
  const str = JSON.stringify(dest);
168
- return this.getAnchorUrl("#" + escape(str));
187
+
188
+ if (str.length > 0) {
189
+ return this.getAnchorUrl("#" + escape(str));
190
+ }
169
191
  }
170
192
 
171
193
  return this.getAnchorUrl("");
@@ -176,6 +198,10 @@ class PDFLinkService {
176
198
  }
177
199
 
178
200
  setHash(hash) {
201
+ if (!this.pdfDocument) {
202
+ return;
203
+ }
204
+
179
205
  let pageNumber, dest;
180
206
 
181
207
  if (hash.includes("=")) {
@@ -243,7 +269,7 @@ class PDFLinkService {
243
269
  }
244
270
 
245
271
  if ("nameddest" in params) {
246
- this.navigateTo(params.nameddest);
272
+ this.goToDestination(params.nameddest);
247
273
  }
248
274
  } else {
249
275
  dest = unescape(hash);
@@ -257,7 +283,7 @@ class PDFLinkService {
257
283
  } catch (ex) {}
258
284
 
259
285
  if (typeof dest === "string" || isValidExplicitDestination(dest)) {
260
- this.navigateTo(dest);
286
+ this.goToDestination(dest);
261
287
  return;
262
288
  }
263
289
 
@@ -282,17 +308,11 @@ class PDFLinkService {
282
308
  break;
283
309
 
284
310
  case "NextPage":
285
- if (this.page < this.pagesCount) {
286
- this.page++;
287
- }
288
-
311
+ this.pdfViewer.nextPage();
289
312
  break;
290
313
 
291
314
  case "PrevPage":
292
- if (this.page > 1) {
293
- this.page--;
294
- }
295
-
315
+ this.pdfViewer.previousPage();
296
316
  break;
297
317
 
298
318
  case "LastPage":
@@ -331,6 +351,10 @@ class PDFLinkService {
331
351
  return this.pdfViewer.isPageVisible(pageNumber);
332
352
  }
333
353
 
354
+ isPageCached(pageNumber) {
355
+ return this.pdfViewer.isPageCached(pageNumber);
356
+ }
357
+
334
358
  }
335
359
 
336
360
  exports.PDFLinkService = PDFLinkService;
@@ -429,7 +453,9 @@ class SimpleLinkService {
429
453
 
430
454
  set rotation(value) {}
431
455
 
432
- navigateTo(dest) {}
456
+ async goToDestination(dest) {}
457
+
458
+ goToPage(val) {}
433
459
 
434
460
  getDestinationHash(dest) {
435
461
  return "#";
@@ -449,6 +475,10 @@ class SimpleLinkService {
449
475
  return true;
450
476
  }
451
477
 
478
+ isPageCached(pageNumber) {
479
+ return true;
480
+ }
481
+
452
482
  }
453
483
 
454
484
  exports.SimpleLinkService = SimpleLinkService;