pdfjs-dist 2.3.200 → 2.4.456

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 (185) hide show
  1. package/README.md +4 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +6499 -17971
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +22 -1
  6. package/build/pdf.worker.entry.js +5 -3
  7. package/build/pdf.worker.js +19303 -29896
  8. package/build/pdf.worker.js.map +1 -1
  9. package/build/pdf.worker.min.js +22 -1
  10. package/es5/build/pdf.js +25473 -0
  11. package/es5/build/pdf.js.map +1 -0
  12. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  13. package/es5/build/pdf.worker.js +57878 -0
  14. package/es5/build/pdf.worker.js.map +1 -0
  15. package/es5/web/images/annotation-check.svg +11 -0
  16. package/es5/web/images/annotation-comment.svg +16 -0
  17. package/es5/web/images/annotation-help.svg +26 -0
  18. package/es5/web/images/annotation-insert.svg +10 -0
  19. package/es5/web/images/annotation-key.svg +11 -0
  20. package/es5/web/images/annotation-newparagraph.svg +11 -0
  21. package/es5/web/images/annotation-noicon.svg +7 -0
  22. package/es5/web/images/annotation-note.svg +42 -0
  23. package/es5/web/images/annotation-paragraph.svg +16 -0
  24. package/es5/web/images/loading-icon.gif +0 -0
  25. package/es5/web/images/shadow.png +0 -0
  26. package/es5/web/images/texture.png +0 -0
  27. package/es5/web/pdf_viewer.css +407 -0
  28. package/es5/web/pdf_viewer.js +7757 -0
  29. package/es5/web/pdf_viewer.js.map +1 -0
  30. package/image_decoders/pdf.image_decoders.js +1333 -4839
  31. package/image_decoders/pdf.image_decoders.js.map +1 -1
  32. package/image_decoders/pdf.image_decoders.min.js +22 -1
  33. package/lib/README.md +7 -0
  34. package/lib/core/annotation.js +683 -1066
  35. package/lib/core/arithmetic_decoder.js +81 -97
  36. package/lib/core/bidi.js +54 -46
  37. package/lib/core/ccitt.js +88 -81
  38. package/lib/core/ccitt_stream.js +15 -14
  39. package/lib/core/cff_parser.js +196 -193
  40. package/lib/core/charsets.js +4 -4
  41. package/lib/core/chunked_stream.js +441 -569
  42. package/lib/core/cmap.js +220 -279
  43. package/lib/core/colorspace.js +699 -863
  44. package/lib/core/core_utils.js +59 -80
  45. package/lib/core/crypto.js +379 -437
  46. package/lib/core/document.js +564 -673
  47. package/lib/core/encodings.js +15 -15
  48. package/lib/core/evaluator.js +983 -889
  49. package/lib/core/font_renderer.js +128 -171
  50. package/lib/core/fonts.js +451 -400
  51. package/lib/core/function.js +289 -285
  52. package/lib/core/glyphlist.js +4527 -4527
  53. package/lib/core/image.js +138 -117
  54. package/lib/core/image_utils.js +46 -63
  55. package/lib/core/jbig2.js +324 -332
  56. package/lib/core/jbig2_stream.js +18 -17
  57. package/lib/core/jpeg_stream.js +133 -24
  58. package/lib/core/jpg.js +238 -210
  59. package/lib/core/jpx.js +158 -157
  60. package/lib/core/jpx_stream.js +28 -28
  61. package/lib/core/metrics.js +2928 -2928
  62. package/lib/core/murmurhash3.js +87 -102
  63. package/lib/core/obj.js +1111 -1302
  64. package/lib/core/operator_list.js +55 -42
  65. package/lib/core/parser.js +956 -987
  66. package/lib/core/pattern.js +69 -69
  67. package/lib/core/pdf_manager.js +149 -316
  68. package/lib/core/primitives.js +45 -77
  69. package/lib/core/ps_parser.js +175 -214
  70. package/lib/core/standard_fonts.js +237 -236
  71. package/lib/core/stream.js +83 -77
  72. package/lib/core/type1_parser.js +78 -68
  73. package/lib/core/unicode.js +1654 -1654
  74. package/lib/core/worker.js +148 -196
  75. package/lib/core/worker_stream.js +101 -210
  76. package/lib/display/annotation_layer.js +733 -1155
  77. package/lib/display/api.js +1539 -1928
  78. package/lib/display/api_compatibility.js +10 -8
  79. package/lib/display/canvas.js +159 -158
  80. package/lib/display/content_disposition.js +36 -55
  81. package/lib/display/display_utils.js +298 -551
  82. package/lib/display/fetch_stream.js +181 -305
  83. package/lib/display/font_loader.js +273 -416
  84. package/lib/display/metadata.js +86 -98
  85. package/lib/display/network.js +376 -511
  86. package/lib/display/network_utils.js +20 -19
  87. package/lib/display/node_stream.js +276 -460
  88. package/lib/display/pattern_helper.js +76 -44
  89. package/lib/display/svg.js +1137 -1405
  90. package/lib/display/text_layer.js +75 -82
  91. package/lib/display/transport_stream.js +236 -374
  92. package/lib/display/webgl.js +70 -83
  93. package/lib/display/worker_options.js +3 -3
  94. package/lib/display/xml_parser.js +303 -392
  95. package/lib/examples/node/domstubs.js +37 -37
  96. package/lib/pdf.js +22 -21
  97. package/lib/pdf.worker.js +5 -5
  98. package/lib/shared/compatibility.js +2 -251
  99. package/lib/shared/is_node.js +7 -6
  100. package/lib/shared/message_handler.js +222 -194
  101. package/lib/shared/util.js +269 -405
  102. package/lib/test/unit/annotation_spec.js +1089 -1014
  103. package/lib/test/unit/api_spec.js +617 -544
  104. package/lib/test/unit/bidi_spec.js +7 -7
  105. package/lib/test/unit/cff_parser_spec.js +63 -62
  106. package/lib/test/unit/clitests_helper.js +7 -9
  107. package/lib/test/unit/cmap_spec.js +84 -86
  108. package/lib/test/unit/colorspace_spec.js +154 -154
  109. package/lib/test/unit/core_utils_spec.js +125 -105
  110. package/lib/test/unit/crypto_spec.js +181 -181
  111. package/lib/test/unit/custom_spec.js +22 -24
  112. package/lib/test/unit/display_svg_spec.js +35 -36
  113. package/lib/test/unit/display_utils_spec.js +139 -149
  114. package/lib/test/unit/document_spec.js +16 -16
  115. package/lib/test/unit/encodings_spec.js +12 -34
  116. package/lib/test/unit/evaluator_spec.js +81 -95
  117. package/lib/test/unit/fetch_stream_spec.js +30 -30
  118. package/lib/test/unit/function_spec.js +206 -204
  119. package/lib/test/unit/jasmine-boot.js +48 -32
  120. package/lib/test/unit/message_handler_spec.js +172 -162
  121. package/lib/test/unit/metadata_spec.js +69 -69
  122. package/lib/test/unit/murmurhash3_spec.js +12 -12
  123. package/lib/test/unit/network_spec.js +12 -12
  124. package/lib/test/unit/network_utils_spec.js +152 -152
  125. package/lib/test/unit/node_stream_spec.js +74 -90
  126. package/lib/test/unit/parser_spec.js +107 -113
  127. package/lib/test/unit/pdf_find_controller_spec.js +55 -86
  128. package/lib/test/unit/pdf_find_utils_spec.js +32 -32
  129. package/lib/test/unit/pdf_history_spec.js +32 -32
  130. package/lib/test/unit/primitives_spec.js +117 -115
  131. package/lib/test/unit/stream_spec.js +16 -14
  132. package/lib/test/unit/test_utils.js +119 -285
  133. package/lib/test/unit/testreporter.js +19 -19
  134. package/lib/test/unit/type1_parser_spec.js +41 -41
  135. package/lib/test/unit/ui_utils_spec.js +318 -426
  136. package/lib/test/unit/unicode_spec.js +42 -42
  137. package/lib/test/unit/util_spec.js +122 -143
  138. package/lib/web/annotation_layer_builder.js +66 -103
  139. package/lib/web/app.js +1166 -1196
  140. package/lib/web/app_options.js +61 -77
  141. package/lib/web/base_viewer.js +804 -850
  142. package/lib/web/chromecom.js +164 -249
  143. package/lib/web/debugger.js +149 -205
  144. package/lib/web/download_manager.js +38 -57
  145. package/lib/web/firefox_print_service.js +35 -30
  146. package/lib/web/firefoxcom.js +175 -374
  147. package/lib/web/genericcom.js +26 -108
  148. package/lib/web/genericl10n.js +24 -153
  149. package/lib/web/grab_to_pan.js +30 -30
  150. package/lib/web/interfaces.js +80 -258
  151. package/lib/web/overlay_manager.js +70 -246
  152. package/lib/web/password_prompt.js +38 -64
  153. package/lib/web/pdf_attachment_viewer.js +105 -130
  154. package/lib/web/pdf_cursor_tools.js +75 -102
  155. package/lib/web/pdf_document_properties.js +227 -376
  156. package/lib/web/pdf_find_bar.js +137 -171
  157. package/lib/web/pdf_find_controller.js +492 -549
  158. package/lib/web/pdf_find_utils.js +13 -13
  159. package/lib/web/pdf_history.js +395 -406
  160. package/lib/web/pdf_link_service.js +302 -349
  161. package/lib/web/pdf_outline_viewer.js +148 -209
  162. package/lib/web/pdf_page_view.js +449 -507
  163. package/lib/web/pdf_presentation_mode.js +304 -357
  164. package/lib/web/pdf_print_service.js +90 -104
  165. package/lib/web/pdf_rendering_queue.js +87 -108
  166. package/lib/web/pdf_sidebar.js +264 -304
  167. package/lib/web/pdf_sidebar_resizer.js +92 -119
  168. package/lib/web/pdf_single_page_viewer.js +77 -126
  169. package/lib/web/pdf_thumbnail_view.js +276 -297
  170. package/lib/web/pdf_thumbnail_viewer.js +186 -206
  171. package/lib/web/pdf_viewer.component.js +20 -21
  172. package/lib/web/pdf_viewer.js +55 -115
  173. package/lib/web/preferences.js +66 -273
  174. package/lib/web/secondary_toolbar.js +164 -196
  175. package/lib/web/text_layer_builder.js +284 -317
  176. package/lib/web/toolbar.js +216 -211
  177. package/lib/web/ui_utils.js +303 -404
  178. package/lib/web/view_history.js +49 -222
  179. package/lib/web/viewer_compatibility.js +7 -5
  180. package/package.json +2 -9
  181. package/web/pdf_viewer.css +25 -18
  182. package/web/pdf_viewer.js +3481 -4764
  183. package/web/pdf_viewer.js.map +1 -1
  184. package/webpack.js +14 -5
  185. package/lib/shared/streams_polyfill.js +0 -43
@@ -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 2019 Mozilla Foundation
5
+ * Copyright 2020 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.
@@ -28,528 +28,516 @@ exports.isDestHashesEqual = isDestHashesEqual;
28
28
  exports.isDestArraysEqual = isDestArraysEqual;
29
29
  exports.PDFHistory = void 0;
30
30
 
31
- var _ui_utils = require("./ui_utils");
31
+ var _ui_utils = require("./ui_utils.js");
32
32
 
33
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
33
+ const HASH_CHANGE_TIMEOUT = 1000;
34
+ const POSITION_UPDATED_THRESHOLD = 50;
35
+ const UPDATE_VIEWAREA_TIMEOUT = 1000;
34
36
 
35
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
36
-
37
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
37
+ function getCurrentHash() {
38
+ return document.location.hash;
39
+ }
38
40
 
39
- function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
41
+ class PDFHistory {
42
+ constructor({
43
+ linkService,
44
+ eventBus
45
+ }) {
46
+ this.linkService = linkService;
47
+ this.eventBus = eventBus || (0, _ui_utils.getGlobalEventBus)();
48
+ this._initialized = false;
49
+ this._fingerprint = "";
50
+ this.reset();
51
+ this._boundEvents = null;
52
+ this._isViewerInPresentationMode = false;
40
53
 
41
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
54
+ this.eventBus._on("presentationmodechanged", evt => {
55
+ this._isViewerInPresentationMode = evt.active || evt.switchInProgress;
56
+ });
42
57
 
43
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
58
+ this.eventBus._on("pagesinit", () => {
59
+ this._isPagesLoaded = false;
44
60
 
45
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
61
+ const onPagesLoaded = evt => {
62
+ this.eventBus._off("pagesloaded", onPagesLoaded);
46
63
 
47
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
64
+ this._isPagesLoaded = !!evt.pagesCount;
65
+ };
48
66
 
49
- var HASH_CHANGE_TIMEOUT = 1000;
50
- var POSITION_UPDATED_THRESHOLD = 50;
51
- var UPDATE_VIEWAREA_TIMEOUT = 1000;
67
+ this.eventBus._on("pagesloaded", onPagesLoaded);
68
+ });
69
+ }
52
70
 
53
- function getCurrentHash() {
54
- return document.location.hash;
55
- }
71
+ initialize({
72
+ fingerprint,
73
+ resetHistory = false,
74
+ updateUrl = false
75
+ }) {
76
+ if (!fingerprint || typeof fingerprint !== "string") {
77
+ console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
78
+ return;
79
+ }
56
80
 
57
- function parseCurrentHash(linkService) {
58
- var hash = unescape(getCurrentHash()).substring(1);
59
- var params = (0, _ui_utils.parseQueryString)(hash);
60
- var page = params.page | 0;
81
+ if (this._initialized) {
82
+ this.reset();
83
+ }
61
84
 
62
- if (!(Number.isInteger(page) && page > 0 && page <= linkService.pagesCount)) {
63
- page = null;
64
- }
85
+ const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
86
+ this._fingerprint = fingerprint;
87
+ this._updateUrl = updateUrl === true;
88
+ this._initialized = true;
65
89
 
66
- return {
67
- hash: hash,
68
- page: page,
69
- rotation: linkService.rotation
70
- };
71
- }
90
+ this._bindEvents();
72
91
 
73
- var PDFHistory =
74
- /*#__PURE__*/
75
- function () {
76
- function PDFHistory(_ref) {
77
- var _this = this;
92
+ const state = window.history.state;
93
+ this._popStateInProgress = false;
94
+ this._blockHashChange = 0;
95
+ this._currentHash = getCurrentHash();
96
+ this._numPositionUpdates = 0;
97
+ this._uid = this._maxUid = 0;
98
+ this._destination = null;
99
+ this._position = null;
78
100
 
79
- var linkService = _ref.linkService,
80
- eventBus = _ref.eventBus;
101
+ if (!this._isValidState(state, true) || resetHistory) {
102
+ const {
103
+ hash,
104
+ page,
105
+ rotation
106
+ } = this._parseCurrentHash();
81
107
 
82
- _classCallCheck(this, PDFHistory);
108
+ if (!hash || reInitialized || resetHistory) {
109
+ this._pushOrReplaceState(null, true);
83
110
 
84
- this.linkService = linkService;
85
- this.eventBus = eventBus || (0, _ui_utils.getGlobalEventBus)();
86
- this.initialized = false;
87
- this.initialBookmark = null;
88
- this.initialRotation = null;
89
- this._boundEvents = Object.create(null);
90
- this._isViewerInPresentationMode = false;
91
- this._isPagesLoaded = false;
92
- this.eventBus.on('presentationmodechanged', function (evt) {
93
- _this._isViewerInPresentationMode = evt.active || evt.switchInProgress;
94
- });
95
- this.eventBus.on('pagesloaded', function (evt) {
96
- _this._isPagesLoaded = !!evt.pagesCount;
97
- });
98
- }
99
-
100
- _createClass(PDFHistory, [{
101
- key: "initialize",
102
- value: function initialize(_ref2) {
103
- var fingerprint = _ref2.fingerprint,
104
- _ref2$resetHistory = _ref2.resetHistory,
105
- resetHistory = _ref2$resetHistory === void 0 ? false : _ref2$resetHistory,
106
- _ref2$updateUrl = _ref2.updateUrl,
107
- updateUrl = _ref2$updateUrl === void 0 ? false : _ref2$updateUrl;
108
-
109
- if (!fingerprint || typeof fingerprint !== 'string') {
110
- console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
111
111
  return;
112
112
  }
113
113
 
114
- var reInitialized = this.initialized && this.fingerprint !== fingerprint;
115
- this.fingerprint = fingerprint;
116
- this._updateUrl = updateUrl === true;
114
+ this._pushOrReplaceState({
115
+ hash,
116
+ page,
117
+ rotation
118
+ }, true);
117
119
 
118
- if (!this.initialized) {
119
- this._bindEvents();
120
- }
120
+ return;
121
+ }
121
122
 
122
- var state = window.history.state;
123
- this.initialized = true;
124
- this.initialBookmark = null;
125
- this.initialRotation = null;
126
- this._popStateInProgress = false;
127
- this._blockHashChange = 0;
128
- this._currentHash = getCurrentHash();
129
- this._numPositionUpdates = 0;
130
- this._uid = this._maxUid = 0;
131
- this._destination = null;
132
- this._position = null;
133
-
134
- if (!this._isValidState(state, true) || resetHistory) {
135
- var _parseCurrentHash = parseCurrentHash(this.linkService),
136
- hash = _parseCurrentHash.hash,
137
- page = _parseCurrentHash.page,
138
- rotation = _parseCurrentHash.rotation;
139
-
140
- if (!hash || reInitialized || resetHistory) {
141
- this._pushOrReplaceState(null, true);
142
-
143
- return;
144
- }
123
+ const destination = state.destination;
145
124
 
146
- this._pushOrReplaceState({
147
- hash: hash,
148
- page: page,
149
- rotation: rotation
150
- }, true);
125
+ this._updateInternalState(destination, state.uid, true);
151
126
 
152
- return;
153
- }
127
+ if (this._uid > this._maxUid) {
128
+ this._maxUid = this._uid;
129
+ }
154
130
 
155
- var destination = state.destination;
131
+ if (destination.rotation !== undefined) {
132
+ this._initialRotation = destination.rotation;
133
+ }
156
134
 
157
- this._updateInternalState(destination, state.uid, true);
135
+ if (destination.dest) {
136
+ this._initialBookmark = JSON.stringify(destination.dest);
137
+ this._destination.page = null;
138
+ } else if (destination.hash) {
139
+ this._initialBookmark = destination.hash;
140
+ } else if (destination.page) {
141
+ this._initialBookmark = `page=${destination.page}`;
142
+ }
143
+ }
158
144
 
159
- if (this._uid > this._maxUid) {
160
- this._maxUid = this._uid;
161
- }
145
+ reset() {
146
+ if (this._initialized) {
147
+ this._pageHide();
162
148
 
163
- if (destination.rotation !== undefined) {
164
- this.initialRotation = destination.rotation;
165
- }
149
+ this._initialized = false;
166
150
 
167
- if (destination.dest) {
168
- this.initialBookmark = JSON.stringify(destination.dest);
169
- this._destination.page = null;
170
- } else if (destination.hash) {
171
- this.initialBookmark = destination.hash;
172
- } else if (destination.page) {
173
- this.initialBookmark = "page=".concat(destination.page);
174
- }
151
+ this._unbindEvents();
175
152
  }
176
- }, {
177
- key: "push",
178
- value: function push(_ref3) {
179
- var _this2 = this;
180
153
 
181
- var _ref3$namedDest = _ref3.namedDest,
182
- namedDest = _ref3$namedDest === void 0 ? null : _ref3$namedDest,
183
- explicitDest = _ref3.explicitDest,
184
- pageNumber = _ref3.pageNumber;
154
+ if (this._updateViewareaTimeout) {
155
+ clearTimeout(this._updateViewareaTimeout);
156
+ this._updateViewareaTimeout = null;
157
+ }
185
158
 
186
- if (!this.initialized) {
187
- return;
188
- }
159
+ this._initialBookmark = null;
160
+ this._initialRotation = null;
161
+ }
189
162
 
190
- if (namedDest && typeof namedDest !== 'string') {
191
- console.error('PDFHistory.push: ' + "\"".concat(namedDest, "\" is not a valid namedDest parameter."));
192
- return;
193
- } else if (!Array.isArray(explicitDest)) {
194
- console.error('PDFHistory.push: ' + "\"".concat(explicitDest, "\" is not a valid explicitDest parameter."));
163
+ push({
164
+ namedDest = null,
165
+ explicitDest,
166
+ pageNumber
167
+ }) {
168
+ if (!this._initialized) {
169
+ return;
170
+ }
171
+
172
+ if (namedDest && typeof namedDest !== "string") {
173
+ console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
174
+ return;
175
+ } else if (!Array.isArray(explicitDest)) {
176
+ console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
177
+ return;
178
+ } else if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.linkService.pagesCount)) {
179
+ if (pageNumber !== null || this._destination) {
180
+ console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
195
181
  return;
196
- } else if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.linkService.pagesCount)) {
197
- if (pageNumber !== null || this._destination) {
198
- console.error('PDFHistory.push: ' + "\"".concat(pageNumber, "\" is not a valid pageNumber parameter."));
199
- return;
200
- }
201
182
  }
183
+ }
184
+
185
+ const hash = namedDest || JSON.stringify(explicitDest);
186
+
187
+ if (!hash) {
188
+ return;
189
+ }
202
190
 
203
- var hash = namedDest || JSON.stringify(explicitDest);
191
+ let forceReplace = false;
204
192
 
205
- if (!hash) {
193
+ if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
194
+ if (this._destination.page) {
206
195
  return;
207
196
  }
208
197
 
209
- var forceReplace = false;
198
+ forceReplace = true;
199
+ }
210
200
 
211
- if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
212
- if (this._destination.page) {
213
- return;
214
- }
201
+ if (this._popStateInProgress && !forceReplace) {
202
+ return;
203
+ }
215
204
 
216
- forceReplace = true;
217
- }
205
+ this._pushOrReplaceState({
206
+ dest: explicitDest,
207
+ hash,
208
+ page: pageNumber,
209
+ rotation: this.linkService.rotation
210
+ }, forceReplace);
218
211
 
219
- if (this._popStateInProgress && !forceReplace) {
220
- return;
221
- }
212
+ if (!this._popStateInProgress) {
213
+ this._popStateInProgress = true;
214
+ Promise.resolve().then(() => {
215
+ this._popStateInProgress = false;
216
+ });
217
+ }
218
+ }
222
219
 
223
- this._pushOrReplaceState({
224
- dest: explicitDest,
225
- hash: hash,
226
- page: pageNumber,
227
- rotation: this.linkService.rotation
228
- }, forceReplace);
229
-
230
- if (!this._popStateInProgress) {
231
- this._popStateInProgress = true;
232
- Promise.resolve().then(function () {
233
- _this2._popStateInProgress = false;
234
- });
235
- }
220
+ pushCurrentPosition() {
221
+ if (!this._initialized || this._popStateInProgress) {
222
+ return;
236
223
  }
237
- }, {
238
- key: "pushCurrentPosition",
239
- value: function pushCurrentPosition() {
240
- if (!this.initialized || this._popStateInProgress) {
241
- return;
242
- }
243
224
 
244
- this._tryPushCurrentPosition();
225
+ this._tryPushCurrentPosition();
226
+ }
227
+
228
+ back() {
229
+ if (!this._initialized || this._popStateInProgress) {
230
+ return;
245
231
  }
246
- }, {
247
- key: "back",
248
- value: function back() {
249
- if (!this.initialized || this._popStateInProgress) {
250
- return;
251
- }
252
232
 
253
- var state = window.history.state;
233
+ const state = window.history.state;
254
234
 
255
- if (this._isValidState(state) && state.uid > 0) {
256
- window.history.back();
257
- }
235
+ if (this._isValidState(state) && state.uid > 0) {
236
+ window.history.back();
258
237
  }
259
- }, {
260
- key: "forward",
261
- value: function forward() {
262
- if (!this.initialized || this._popStateInProgress) {
263
- return;
264
- }
238
+ }
265
239
 
266
- var state = window.history.state;
240
+ forward() {
241
+ if (!this._initialized || this._popStateInProgress) {
242
+ return;
243
+ }
267
244
 
268
- if (this._isValidState(state) && state.uid < this._maxUid) {
269
- window.history.forward();
270
- }
245
+ const state = window.history.state;
246
+
247
+ if (this._isValidState(state) && state.uid < this._maxUid) {
248
+ window.history.forward();
271
249
  }
272
- }, {
273
- key: "_pushOrReplaceState",
274
- value: function _pushOrReplaceState(destination) {
275
- var forceReplace = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
276
- var shouldReplace = forceReplace || !this._destination;
277
- var newState = {
278
- fingerprint: this.fingerprint,
279
- uid: shouldReplace ? this._uid : this._uid + 1,
280
- destination: destination
281
- };
250
+ }
282
251
 
283
- this._updateInternalState(destination, newState.uid);
252
+ get popStateInProgress() {
253
+ return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
254
+ }
284
255
 
285
- var newUrl;
256
+ get initialBookmark() {
257
+ return this._initialized ? this._initialBookmark : null;
258
+ }
286
259
 
287
- if (this._updateUrl && destination && destination.hash) {
288
- var baseUrl = document.location.href.split('#')[0];
260
+ get initialRotation() {
261
+ return this._initialized ? this._initialRotation : null;
262
+ }
289
263
 
290
- if (!baseUrl.startsWith('file://')) {
291
- newUrl = "".concat(baseUrl, "#").concat(destination.hash);
292
- }
293
- }
264
+ _pushOrReplaceState(destination, forceReplace = false) {
265
+ const shouldReplace = forceReplace || !this._destination;
266
+ const newState = {
267
+ fingerprint: this._fingerprint,
268
+ uid: shouldReplace ? this._uid : this._uid + 1,
269
+ destination
270
+ };
294
271
 
295
- if (shouldReplace) {
296
- if (newUrl) {
297
- window.history.replaceState(newState, '', newUrl);
298
- } else {
299
- window.history.replaceState(newState, '');
300
- }
301
- } else {
302
- this._maxUid = this._uid;
272
+ this._updateInternalState(destination, newState.uid);
303
273
 
304
- if (newUrl) {
305
- window.history.pushState(newState, '', newUrl);
306
- } else {
307
- window.history.pushState(newState, '');
308
- }
274
+ let newUrl;
275
+
276
+ if (this._updateUrl && destination && destination.hash) {
277
+ const baseUrl = document.location.href.split("#")[0];
278
+
279
+ if (!baseUrl.startsWith("file://")) {
280
+ newUrl = `${baseUrl}#${destination.hash}`;
309
281
  }
310
282
  }
311
- }, {
312
- key: "_tryPushCurrentPosition",
313
- value: function _tryPushCurrentPosition() {
314
- var temporary = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
315
283
 
316
- if (!this._position) {
317
- return;
318
- }
284
+ if (shouldReplace) {
285
+ window.history.replaceState(newState, "", newUrl);
286
+ } else {
287
+ this._maxUid = this._uid;
288
+ window.history.pushState(newState, "", newUrl);
289
+ }
290
+ }
319
291
 
320
- var position = this._position;
292
+ _tryPushCurrentPosition(temporary = false) {
293
+ if (!this._position) {
294
+ return;
295
+ }
321
296
 
322
- if (temporary) {
323
- position = Object.assign(Object.create(null), this._position);
324
- position.temporary = true;
325
- }
297
+ let position = this._position;
326
298
 
327
- if (!this._destination) {
328
- this._pushOrReplaceState(position);
299
+ if (temporary) {
300
+ position = Object.assign(Object.create(null), this._position);
301
+ position.temporary = true;
302
+ }
329
303
 
330
- return;
331
- }
304
+ if (!this._destination) {
305
+ this._pushOrReplaceState(position);
332
306
 
333
- if (this._destination.temporary) {
334
- this._pushOrReplaceState(position, true);
307
+ return;
308
+ }
335
309
 
336
- return;
337
- }
310
+ if (this._destination.temporary) {
311
+ this._pushOrReplaceState(position, true);
338
312
 
339
- if (this._destination.hash === position.hash) {
340
- return;
341
- }
313
+ return;
314
+ }
342
315
 
343
- if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
344
- return;
345
- }
316
+ if (this._destination.hash === position.hash) {
317
+ return;
318
+ }
346
319
 
347
- var forceReplace = false;
320
+ if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
321
+ return;
322
+ }
348
323
 
349
- if (this._destination.page >= position.first && this._destination.page <= position.page) {
350
- if (this._destination.dest || !this._destination.first) {
351
- return;
352
- }
324
+ let forceReplace = false;
353
325
 
354
- forceReplace = true;
326
+ if (this._destination.page >= position.first && this._destination.page <= position.page) {
327
+ if (this._destination.dest || !this._destination.first) {
328
+ return;
355
329
  }
356
330
 
357
- this._pushOrReplaceState(position, forceReplace);
331
+ forceReplace = true;
358
332
  }
359
- }, {
360
- key: "_isValidState",
361
- value: function _isValidState(state) {
362
- var checkReload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
363
-
364
- if (!state) {
365
- return false;
366
- }
367
333
 
368
- if (state.fingerprint !== this.fingerprint) {
369
- if (checkReload) {
370
- if (typeof state.fingerprint !== 'string' || state.fingerprint.length !== this.fingerprint.length) {
371
- return false;
372
- }
334
+ this._pushOrReplaceState(position, forceReplace);
335
+ }
373
336
 
374
- var _performance$getEntri = performance.getEntriesByType('navigation'),
375
- _performance$getEntri2 = _slicedToArray(_performance$getEntri, 1),
376
- perfEntry = _performance$getEntri2[0];
337
+ _isValidState(state, checkReload = false) {
338
+ if (!state) {
339
+ return false;
340
+ }
377
341
 
378
- if (!perfEntry || perfEntry.type !== 'reload') {
379
- return false;
380
- }
381
- } else {
342
+ if (state.fingerprint !== this._fingerprint) {
343
+ if (checkReload) {
344
+ if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
382
345
  return false;
383
346
  }
384
- }
385
347
 
386
- if (!Number.isInteger(state.uid) || state.uid < 0) {
387
- return false;
388
- }
348
+ const [perfEntry] = performance.getEntriesByType("navigation");
389
349
 
390
- if (state.destination === null || _typeof(state.destination) !== 'object') {
350
+ if (!perfEntry || perfEntry.type !== "reload") {
351
+ return false;
352
+ }
353
+ } else {
391
354
  return false;
392
355
  }
356
+ }
393
357
 
394
- return true;
358
+ if (!Number.isInteger(state.uid) || state.uid < 0) {
359
+ return false;
395
360
  }
396
- }, {
397
- key: "_updateInternalState",
398
- value: function _updateInternalState(destination, uid) {
399
- var removeTemporary = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
400
361
 
401
- if (this._updateViewareaTimeout) {
402
- clearTimeout(this._updateViewareaTimeout);
403
- this._updateViewareaTimeout = null;
404
- }
362
+ if (state.destination === null || typeof state.destination !== "object") {
363
+ return false;
364
+ }
405
365
 
406
- if (removeTemporary && destination && destination.temporary) {
407
- delete destination.temporary;
408
- }
366
+ return true;
367
+ }
409
368
 
410
- this._destination = destination;
411
- this._uid = uid;
412
- this._numPositionUpdates = 0;
369
+ _updateInternalState(destination, uid, removeTemporary = false) {
370
+ if (this._updateViewareaTimeout) {
371
+ clearTimeout(this._updateViewareaTimeout);
372
+ this._updateViewareaTimeout = null;
413
373
  }
414
- }, {
415
- key: "_updateViewarea",
416
- value: function _updateViewarea(_ref4) {
417
- var _this3 = this;
418
374
 
419
- var location = _ref4.location;
375
+ if (removeTemporary && destination && destination.temporary) {
376
+ delete destination.temporary;
377
+ }
420
378
 
421
- if (this._updateViewareaTimeout) {
422
- clearTimeout(this._updateViewareaTimeout);
423
- this._updateViewareaTimeout = null;
424
- }
379
+ this._destination = destination;
380
+ this._uid = uid;
381
+ this._numPositionUpdates = 0;
382
+ }
425
383
 
426
- this._position = {
427
- hash: this._isViewerInPresentationMode ? "page=".concat(location.pageNumber) : location.pdfOpenParams.substring(1),
428
- page: this.linkService.page,
429
- first: location.pageNumber,
430
- rotation: location.rotation
431
- };
384
+ _parseCurrentHash() {
385
+ const hash = unescape(getCurrentHash()).substring(1);
386
+ let page = (0, _ui_utils.parseQueryString)(hash).page | 0;
432
387
 
433
- if (this._popStateInProgress) {
434
- return;
435
- }
388
+ if (!(Number.isInteger(page) && page > 0 && page <= this.linkService.pagesCount)) {
389
+ page = null;
390
+ }
436
391
 
437
- if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
438
- this._numPositionUpdates++;
439
- }
392
+ return {
393
+ hash,
394
+ page,
395
+ rotation: this.linkService.rotation
396
+ };
397
+ }
440
398
 
441
- if (UPDATE_VIEWAREA_TIMEOUT > 0) {
442
- this._updateViewareaTimeout = setTimeout(function () {
443
- if (!_this3._popStateInProgress) {
444
- _this3._tryPushCurrentPosition(true);
445
- }
399
+ _updateViewarea({
400
+ location
401
+ }) {
402
+ if (this._updateViewareaTimeout) {
403
+ clearTimeout(this._updateViewareaTimeout);
404
+ this._updateViewareaTimeout = null;
405
+ }
446
406
 
447
- _this3._updateViewareaTimeout = null;
448
- }, UPDATE_VIEWAREA_TIMEOUT);
449
- }
407
+ this._position = {
408
+ hash: this._isViewerInPresentationMode ? `page=${location.pageNumber}` : location.pdfOpenParams.substring(1),
409
+ page: this.linkService.page,
410
+ first: location.pageNumber,
411
+ rotation: location.rotation
412
+ };
413
+
414
+ if (this._popStateInProgress) {
415
+ return;
450
416
  }
451
- }, {
452
- key: "_popState",
453
- value: function _popState(_ref5) {
454
- var _this4 = this;
455
417
 
456
- var state = _ref5.state;
457
- var newHash = getCurrentHash(),
458
- hashChanged = this._currentHash !== newHash;
459
- this._currentHash = newHash;
418
+ if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
419
+ this._numPositionUpdates++;
420
+ }
460
421
 
461
- if (!state || false) {
462
- this._uid++;
422
+ if (UPDATE_VIEWAREA_TIMEOUT > 0) {
423
+ this._updateViewareaTimeout = setTimeout(() => {
424
+ if (!this._popStateInProgress) {
425
+ this._tryPushCurrentPosition(true);
426
+ }
463
427
 
464
- var _parseCurrentHash2 = parseCurrentHash(this.linkService),
465
- hash = _parseCurrentHash2.hash,
466
- page = _parseCurrentHash2.page,
467
- rotation = _parseCurrentHash2.rotation;
428
+ this._updateViewareaTimeout = null;
429
+ }, UPDATE_VIEWAREA_TIMEOUT);
430
+ }
431
+ }
468
432
 
469
- this._pushOrReplaceState({
470
- hash: hash,
471
- page: page,
472
- rotation: rotation
473
- }, true);
433
+ _popState({
434
+ state
435
+ }) {
436
+ const newHash = getCurrentHash(),
437
+ hashChanged = this._currentHash !== newHash;
438
+ this._currentHash = newHash;
474
439
 
475
- return;
476
- }
440
+ if (!state) {
441
+ this._uid++;
477
442
 
478
- if (!this._isValidState(state)) {
479
- return;
480
- }
443
+ const {
444
+ hash,
445
+ page,
446
+ rotation
447
+ } = this._parseCurrentHash();
481
448
 
482
- this._popStateInProgress = true;
449
+ this._pushOrReplaceState({
450
+ hash,
451
+ page,
452
+ rotation
453
+ }, true);
483
454
 
484
- if (hashChanged) {
485
- this._blockHashChange++;
486
- (0, _ui_utils.waitOnEventOrTimeout)({
487
- target: window,
488
- name: 'hashchange',
489
- delay: HASH_CHANGE_TIMEOUT
490
- }).then(function () {
491
- _this4._blockHashChange--;
492
- });
493
- }
455
+ return;
456
+ }
494
457
 
495
- var destination = state.destination;
458
+ if (!this._isValidState(state)) {
459
+ return;
460
+ }
496
461
 
497
- this._updateInternalState(destination, state.uid, true);
462
+ this._popStateInProgress = true;
498
463
 
499
- if (this._uid > this._maxUid) {
500
- this._maxUid = this._uid;
501
- }
464
+ if (hashChanged) {
465
+ this._blockHashChange++;
466
+ (0, _ui_utils.waitOnEventOrTimeout)({
467
+ target: window,
468
+ name: "hashchange",
469
+ delay: HASH_CHANGE_TIMEOUT
470
+ }).then(() => {
471
+ this._blockHashChange--;
472
+ });
473
+ }
502
474
 
503
- if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
504
- this.linkService.rotation = destination.rotation;
505
- }
475
+ const destination = state.destination;
506
476
 
507
- if (destination.dest) {
508
- this.linkService.navigateTo(destination.dest);
509
- } else if (destination.hash) {
510
- this.linkService.setHash(destination.hash);
511
- } else if (destination.page) {
512
- this.linkService.page = destination.page;
513
- }
477
+ this._updateInternalState(destination, state.uid, true);
514
478
 
515
- Promise.resolve().then(function () {
516
- _this4._popStateInProgress = false;
517
- });
479
+ if (this._uid > this._maxUid) {
480
+ this._maxUid = this._uid;
518
481
  }
519
- }, {
520
- key: "_bindEvents",
521
- value: function _bindEvents() {
522
- var _this5 = this;
523
482
 
524
- var _boundEvents = this._boundEvents,
525
- eventBus = this.eventBus;
526
- _boundEvents.updateViewarea = this._updateViewarea.bind(this);
527
- _boundEvents.popState = this._popState.bind(this);
483
+ if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
484
+ this.linkService.rotation = destination.rotation;
485
+ }
528
486
 
529
- _boundEvents.pageHide = function (evt) {
530
- if (!_this5._destination || _this5._destination.temporary) {
531
- _this5._tryPushCurrentPosition();
532
- }
533
- };
487
+ if (destination.dest) {
488
+ this.linkService.navigateTo(destination.dest);
489
+ } else if (destination.hash) {
490
+ this.linkService.setHash(destination.hash);
491
+ } else if (destination.page) {
492
+ this.linkService.page = destination.page;
493
+ }
534
494
 
535
- eventBus.on('updateviewarea', _boundEvents.updateViewarea);
536
- window.addEventListener('popstate', _boundEvents.popState);
537
- window.addEventListener('pagehide', _boundEvents.pageHide);
495
+ Promise.resolve().then(() => {
496
+ this._popStateInProgress = false;
497
+ });
498
+ }
499
+
500
+ _pageHide() {
501
+ if (!this._destination || this._destination.temporary) {
502
+ this._tryPushCurrentPosition();
538
503
  }
539
- }, {
540
- key: "popStateInProgress",
541
- get: function get() {
542
- return this.initialized && (this._popStateInProgress || this._blockHashChange > 0);
504
+ }
505
+
506
+ _bindEvents() {
507
+ if (this._boundEvents) {
508
+ return;
543
509
  }
544
- }]);
545
510
 
546
- return PDFHistory;
547
- }();
511
+ this._boundEvents = {
512
+ updateViewarea: this._updateViewarea.bind(this),
513
+ popState: this._popState.bind(this),
514
+ pageHide: this._pageHide.bind(this)
515
+ };
516
+
517
+ this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
518
+
519
+ window.addEventListener("popstate", this._boundEvents.popState);
520
+ window.addEventListener("pagehide", this._boundEvents.pageHide);
521
+ }
522
+
523
+ _unbindEvents() {
524
+ if (!this._boundEvents) {
525
+ return;
526
+ }
527
+
528
+ this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
529
+
530
+ window.removeEventListener("popstate", this._boundEvents.popState);
531
+ window.removeEventListener("pagehide", this._boundEvents.pageHide);
532
+ this._boundEvents = null;
533
+ }
534
+
535
+ }
548
536
 
549
537
  exports.PDFHistory = PDFHistory;
550
538
 
551
539
  function isDestHashesEqual(destHash, pushHash) {
552
- if (typeof destHash !== 'string' || typeof pushHash !== 'string') {
540
+ if (typeof destHash !== "string" || typeof pushHash !== "string") {
553
541
  return false;
554
542
  }
555
543
 
@@ -557,8 +545,9 @@ function isDestHashesEqual(destHash, pushHash) {
557
545
  return true;
558
546
  }
559
547
 
560
- var _parseQueryString = (0, _ui_utils.parseQueryString)(destHash),
561
- nameddest = _parseQueryString.nameddest;
548
+ const {
549
+ nameddest
550
+ } = (0, _ui_utils.parseQueryString)(destHash);
562
551
 
563
552
  if (nameddest === pushHash) {
564
553
  return true;
@@ -569,7 +558,7 @@ function isDestHashesEqual(destHash, pushHash) {
569
558
 
570
559
  function isDestArraysEqual(firstDest, secondDest) {
571
560
  function isEntryEqual(first, second) {
572
- if (_typeof(first) !== _typeof(second)) {
561
+ if (typeof first !== typeof second) {
573
562
  return false;
574
563
  }
575
564
 
@@ -577,12 +566,12 @@ function isDestArraysEqual(firstDest, secondDest) {
577
566
  return false;
578
567
  }
579
568
 
580
- if (first !== null && _typeof(first) === 'object' && second !== null) {
569
+ if (first !== null && typeof first === "object" && second !== null) {
581
570
  if (Object.keys(first).length !== Object.keys(second).length) {
582
571
  return false;
583
572
  }
584
573
 
585
- for (var key in first) {
574
+ for (const key in first) {
586
575
  if (!isEntryEqual(first[key], second[key])) {
587
576
  return false;
588
577
  }
@@ -602,7 +591,7 @@ function isDestArraysEqual(firstDest, secondDest) {
602
591
  return false;
603
592
  }
604
593
 
605
- for (var i = 0, ii = firstDest.length; i < ii; i++) {
594
+ for (let i = 0, ii = firstDest.length; i < ii; i++) {
606
595
  if (!isEntryEqual(firstDest[i], secondDest[i])) {
607
596
  return false;
608
597
  }