pdfjs-dist 2.1.266 → 2.5.207

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 (191) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/README.md +4 -0
  3. package/bower.json +1 -1
  4. package/build/pdf.js +8382 -18492
  5. package/build/pdf.js.map +1 -1
  6. package/build/pdf.min.js +22 -1
  7. package/build/pdf.worker.entry.js +5 -3
  8. package/build/pdf.worker.js +20417 -29816
  9. package/build/pdf.worker.js.map +1 -1
  10. package/build/pdf.worker.min.js +22 -1
  11. package/es5/build/pdf.js +25688 -0
  12. package/es5/build/pdf.js.map +1 -0
  13. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  14. package/es5/build/pdf.worker.js +58239 -0
  15. package/es5/build/pdf.worker.js.map +1 -0
  16. package/es5/web/images/annotation-check.svg +11 -0
  17. package/es5/web/images/annotation-comment.svg +16 -0
  18. package/es5/web/images/annotation-help.svg +26 -0
  19. package/es5/web/images/annotation-insert.svg +10 -0
  20. package/es5/web/images/annotation-key.svg +11 -0
  21. package/es5/web/images/annotation-newparagraph.svg +11 -0
  22. package/es5/web/images/annotation-noicon.svg +7 -0
  23. package/es5/web/images/annotation-note.svg +42 -0
  24. package/es5/web/images/annotation-paragraph.svg +16 -0
  25. package/es5/web/images/loading-icon.gif +0 -0
  26. package/es5/web/images/shadow.png +0 -0
  27. package/es5/web/images/texture.png +0 -0
  28. package/es5/web/pdf_viewer.css +403 -0
  29. package/es5/web/pdf_viewer.js +7742 -0
  30. package/es5/web/pdf_viewer.js.map +1 -0
  31. package/image_decoders/pdf.image_decoders.js +1475 -4897
  32. package/image_decoders/pdf.image_decoders.js.map +1 -1
  33. package/image_decoders/pdf.image_decoders.min.js +22 -1
  34. package/lib/README.md +7 -0
  35. package/lib/core/annotation.js +750 -899
  36. package/lib/core/arithmetic_decoder.js +81 -97
  37. package/lib/core/bidi.js +54 -46
  38. package/lib/core/ccitt.js +88 -81
  39. package/lib/core/ccitt_stream.js +15 -14
  40. package/lib/core/cff_parser.js +235 -183
  41. package/lib/core/charsets.js +4 -4
  42. package/lib/core/chunked_stream.js +447 -542
  43. package/lib/core/cmap.js +222 -264
  44. package/lib/core/colorspace.js +699 -863
  45. package/lib/core/core_utils.js +152 -0
  46. package/lib/core/crypto.js +379 -437
  47. package/lib/core/document.js +573 -660
  48. package/lib/core/encodings.js +15 -15
  49. package/lib/core/evaluator.js +1103 -868
  50. package/lib/core/font_renderer.js +135 -178
  51. package/lib/core/fonts.js +570 -491
  52. package/lib/core/function.js +291 -288
  53. package/lib/core/glyphlist.js +4527 -4526
  54. package/lib/core/image.js +145 -149
  55. package/lib/core/image_utils.js +170 -0
  56. package/lib/core/jbig2.js +325 -316
  57. package/lib/core/jbig2_stream.js +18 -17
  58. package/lib/core/jpeg_stream.js +21 -26
  59. package/lib/core/jpg.js +284 -232
  60. package/lib/core/jpx.js +161 -143
  61. package/lib/core/jpx_stream.js +28 -28
  62. package/lib/core/metrics.js +2929 -2929
  63. package/lib/core/murmurhash3.js +90 -101
  64. package/lib/core/obj.js +1183 -1157
  65. package/lib/core/operator_list.js +99 -67
  66. package/lib/core/parser.js +972 -911
  67. package/lib/core/pattern.js +87 -70
  68. package/lib/core/pdf_manager.js +150 -315
  69. package/lib/core/primitives.js +83 -56
  70. package/lib/core/ps_parser.js +175 -214
  71. package/lib/core/standard_fonts.js +237 -236
  72. package/lib/core/stream.js +94 -74
  73. package/lib/core/type1_parser.js +87 -69
  74. package/lib/core/unicode.js +1654 -1654
  75. package/lib/core/worker.js +193 -390
  76. package/lib/core/worker_stream.js +168 -0
  77. package/lib/display/annotation_layer.js +741 -972
  78. package/lib/display/api.js +1500 -1791
  79. package/lib/display/api_compatibility.js +12 -17
  80. package/lib/display/canvas.js +165 -165
  81. package/lib/display/content_disposition.js +40 -59
  82. package/lib/display/display_utils.js +515 -0
  83. package/lib/display/fetch_stream.js +183 -298
  84. package/lib/display/font_loader.js +273 -413
  85. package/lib/display/metadata.js +86 -98
  86. package/lib/display/network.js +266 -359
  87. package/lib/display/network_utils.js +25 -18
  88. package/lib/display/node_stream.js +285 -458
  89. package/lib/display/pattern_helper.js +113 -65
  90. package/lib/display/svg.js +1166 -901
  91. package/lib/display/text_layer.js +156 -132
  92. package/lib/display/transport_stream.js +262 -278
  93. package/lib/display/webgl.js +70 -83
  94. package/lib/display/worker_options.js +3 -3
  95. package/lib/display/xml_parser.js +303 -392
  96. package/lib/examples/node/domstubs.js +40 -37
  97. package/lib/pdf.js +226 -59
  98. package/lib/pdf.worker.js +14 -6
  99. package/lib/shared/compatibility.js +3 -246
  100. package/lib/shared/is_node.js +7 -6
  101. package/lib/shared/message_handler.js +327 -332
  102. package/lib/shared/util.js +266 -416
  103. package/lib/test/unit/annotation_spec.js +1555 -701
  104. package/lib/test/unit/api_spec.js +802 -604
  105. package/lib/test/unit/bidi_spec.js +7 -7
  106. package/lib/test/unit/cff_parser_spec.js +84 -69
  107. package/lib/test/unit/clitests_helper.js +7 -9
  108. package/lib/test/unit/cmap_spec.js +74 -76
  109. package/lib/test/unit/colorspace_spec.js +166 -161
  110. package/lib/test/unit/core_utils_spec.js +211 -0
  111. package/lib/test/unit/crypto_spec.js +181 -181
  112. package/lib/test/unit/custom_spec.js +20 -22
  113. package/lib/test/unit/display_svg_spec.js +34 -39
  114. package/lib/test/unit/display_utils_spec.js +263 -0
  115. package/lib/test/unit/document_spec.js +16 -21
  116. package/lib/test/unit/encodings_spec.js +12 -34
  117. package/lib/test/unit/evaluator_spec.js +83 -83
  118. package/lib/test/unit/fetch_stream_spec.js +111 -0
  119. package/lib/test/unit/function_spec.js +206 -204
  120. package/lib/test/unit/jasmine-boot.js +46 -30
  121. package/lib/test/unit/message_handler_spec.js +173 -159
  122. package/lib/test/unit/metadata_spec.js +69 -69
  123. package/lib/test/unit/murmurhash3_spec.js +12 -12
  124. package/lib/test/unit/network_spec.js +13 -61
  125. package/lib/test/unit/network_utils_spec.js +183 -119
  126. package/lib/test/unit/node_stream_spec.js +78 -92
  127. package/lib/test/unit/parser_spec.js +172 -114
  128. package/lib/test/unit/pdf_find_controller_spec.js +55 -86
  129. package/lib/test/unit/pdf_find_utils_spec.js +32 -32
  130. package/lib/test/unit/pdf_history_spec.js +32 -32
  131. package/lib/test/unit/primitives_spec.js +140 -125
  132. package/lib/test/unit/stream_spec.js +16 -14
  133. package/lib/test/unit/test_utils.js +131 -143
  134. package/lib/test/unit/testreporter.js +19 -19
  135. package/lib/test/unit/type1_parser_spec.js +42 -42
  136. package/lib/test/unit/ui_utils_spec.js +297 -459
  137. package/lib/test/unit/unicode_spec.js +38 -38
  138. package/lib/test/unit/util_spec.js +121 -305
  139. package/lib/web/annotation_layer_builder.js +66 -103
  140. package/lib/web/app.js +1328 -1214
  141. package/lib/web/app_options.js +105 -107
  142. package/lib/web/base_viewer.js +824 -838
  143. package/lib/web/chromecom.js +165 -252
  144. package/lib/web/debugger.js +149 -205
  145. package/lib/web/download_manager.js +39 -55
  146. package/lib/web/firefox_print_service.js +37 -27
  147. package/lib/web/firefoxcom.js +212 -363
  148. package/lib/web/genericcom.js +26 -108
  149. package/lib/web/genericl10n.js +24 -153
  150. package/lib/web/grab_to_pan.js +32 -30
  151. package/lib/web/interfaces.js +80 -254
  152. package/lib/web/overlay_manager.js +70 -246
  153. package/lib/web/password_prompt.js +38 -64
  154. package/lib/web/pdf_attachment_viewer.js +113 -131
  155. package/lib/web/pdf_cursor_tools.js +75 -102
  156. package/lib/web/pdf_document_properties.js +221 -306
  157. package/lib/web/pdf_find_bar.js +136 -170
  158. package/lib/web/pdf_find_controller.js +491 -548
  159. package/lib/web/pdf_find_utils.js +13 -13
  160. package/lib/web/pdf_history.js +397 -406
  161. package/lib/web/pdf_link_service.js +304 -348
  162. package/lib/web/pdf_outline_viewer.js +140 -175
  163. package/lib/web/pdf_page_view.js +452 -523
  164. package/lib/web/pdf_presentation_mode.js +308 -357
  165. package/lib/web/pdf_print_service.js +90 -104
  166. package/lib/web/pdf_rendering_queue.js +84 -108
  167. package/lib/web/pdf_sidebar.js +276 -306
  168. package/lib/web/pdf_sidebar_resizer.js +92 -119
  169. package/lib/web/pdf_single_page_viewer.js +77 -126
  170. package/lib/web/pdf_thumbnail_view.js +276 -297
  171. package/lib/web/pdf_thumbnail_viewer.js +186 -206
  172. package/lib/web/pdf_viewer.component.js +20 -21
  173. package/lib/web/pdf_viewer.js +55 -115
  174. package/lib/web/preferences.js +82 -286
  175. package/lib/web/secondary_toolbar.js +164 -196
  176. package/lib/web/text_layer_builder.js +282 -339
  177. package/lib/web/toolbar.js +217 -210
  178. package/lib/web/ui_utils.js +267 -420
  179. package/lib/web/view_history.js +52 -226
  180. package/lib/web/viewer_compatibility.js +21 -6
  181. package/package.json +2 -9
  182. package/web/pdf_viewer.css +35 -25
  183. package/web/pdf_viewer.js +3489 -4855
  184. package/web/pdf_viewer.js.map +1 -1
  185. package/webpack.js +14 -5
  186. package/external/streams/streams-lib.js +0 -3962
  187. package/external/url/url-lib.js +0 -627
  188. package/lib/display/dom_utils.js +0 -494
  189. package/lib/shared/streams_polyfill.js +0 -43
  190. package/lib/shared/url_polyfill.js +0 -56
  191. package/lib/test/unit/dom_utils_spec.js +0 -89
@@ -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 2018 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,518 @@ 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"); }
38
-
39
- function _iterableToArrayLimit(arr, i) { 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; }
37
+ function getCurrentHash() {
38
+ return document.location.hash;
39
+ }
40
40
 
41
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
41
+ class PDFHistory {
42
+ constructor({
43
+ linkService,
44
+ eventBus
45
+ }) {
46
+ this.linkService = linkService;
47
+ this.eventBus = eventBus;
48
+ this._initialized = false;
49
+ this._fingerprint = "";
50
+ this.reset();
51
+ this._boundEvents = null;
52
+ this._isViewerInPresentationMode = false;
42
53
 
43
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
54
+ this.eventBus._on("presentationmodechanged", evt => {
55
+ this._isViewerInPresentationMode = evt.active || evt.switchInProgress;
56
+ });
44
57
 
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); } }
58
+ this.eventBus._on("pagesinit", () => {
59
+ this._isPagesLoaded = false;
46
60
 
47
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
61
+ const onPagesLoaded = evt => {
62
+ this.eventBus._off("pagesloaded", onPagesLoaded);
48
63
 
49
- var HASH_CHANGE_TIMEOUT = 1000;
50
- var POSITION_UPDATED_THRESHOLD = 50;
51
- var UPDATE_VIEWAREA_TIMEOUT = 1000;
64
+ this._isPagesLoaded = !!evt.pagesCount;
65
+ };
52
66
 
53
- function getCurrentHash() {
54
- return document.location.hash;
55
- }
67
+ this.eventBus._on("pagesloaded", onPagesLoaded);
68
+ });
69
+ }
56
70
 
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;
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
+ }
61
80
 
62
- if (!(Number.isInteger(page) && page > 0 && page <= linkService.pagesCount)) {
63
- page = null;
64
- }
81
+ if (this._initialized) {
82
+ this.reset();
83
+ }
65
84
 
66
- return {
67
- hash: hash,
68
- page: page,
69
- rotation: linkService.rotation
70
- };
71
- }
85
+ const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
86
+ this._fingerprint = fingerprint;
87
+ this._updateUrl = updateUrl === true;
88
+ this._initialized = true;
72
89
 
73
- var PDFHistory =
74
- /*#__PURE__*/
75
- function () {
76
- function PDFHistory(_ref) {
77
- var _this = this;
90
+ this._bindEvents();
78
91
 
79
- var linkService = _ref.linkService,
80
- eventBus = _ref.eventBus;
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;
81
100
 
82
- _classCallCheck(this, PDFHistory);
101
+ if (!this._isValidState(state, true) || resetHistory) {
102
+ const {
103
+ hash,
104
+ page,
105
+ rotation
106
+ } = this._parseCurrentHash(true);
83
107
 
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
- }
108
+ if (!hash || reInitialized || resetHistory) {
109
+ this._pushOrReplaceState(null, true);
99
110
 
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
+ }
202
184
 
203
- var hash = namedDest || JSON.stringify(explicitDest);
185
+ const hash = namedDest || JSON.stringify(explicitDest);
204
186
 
205
- if (!hash) {
187
+ if (!hash) {
188
+ return;
189
+ }
190
+
191
+ let forceReplace = false;
192
+
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();
237
+ }
238
+ }
239
+
240
+ forward() {
241
+ if (!this._initialized || this._popStateInProgress) {
242
+ return;
258
243
  }
259
- }, {
260
- key: "forward",
261
- value: function forward() {
262
- if (!this.initialized || this._popStateInProgress) {
263
- return;
264
- }
265
244
 
266
- var state = window.history.state;
245
+ const state = window.history.state;
267
246
 
268
- if (this._isValidState(state) && state.uid < this._maxUid) {
269
- window.history.forward();
270
- }
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(checkNameddest = false) {
385
+ const hash = unescape(getCurrentHash()).substring(1);
386
+ const params = (0, _ui_utils.parseQueryString)(hash);
387
+ const nameddest = params.nameddest || "";
388
+ let page = params.page | 0;
432
389
 
433
- if (this._popStateInProgress) {
434
- return;
435
- }
390
+ if (!(Number.isInteger(page) && page > 0 && page <= this.linkService.pagesCount) || checkNameddest && nameddest.length > 0) {
391
+ page = null;
392
+ }
436
393
 
437
- if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
438
- this._numPositionUpdates++;
439
- }
394
+ return {
395
+ hash,
396
+ page,
397
+ rotation: this.linkService.rotation
398
+ };
399
+ }
440
400
 
441
- if (UPDATE_VIEWAREA_TIMEOUT > 0) {
442
- this._updateViewareaTimeout = setTimeout(function () {
443
- if (!_this3._popStateInProgress) {
444
- _this3._tryPushCurrentPosition(true);
445
- }
401
+ _updateViewarea({
402
+ location
403
+ }) {
404
+ if (this._updateViewareaTimeout) {
405
+ clearTimeout(this._updateViewareaTimeout);
406
+ this._updateViewareaTimeout = null;
407
+ }
446
408
 
447
- _this3._updateViewareaTimeout = null;
448
- }, UPDATE_VIEWAREA_TIMEOUT);
449
- }
409
+ this._position = {
410
+ hash: this._isViewerInPresentationMode ? `page=${location.pageNumber}` : location.pdfOpenParams.substring(1),
411
+ page: this.linkService.page,
412
+ first: location.pageNumber,
413
+ rotation: location.rotation
414
+ };
415
+
416
+ if (this._popStateInProgress) {
417
+ return;
450
418
  }
451
- }, {
452
- key: "_popState",
453
- value: function _popState(_ref5) {
454
- var _this4 = this;
455
419
 
456
- var state = _ref5.state;
457
- var newHash = getCurrentHash(),
458
- hashChanged = this._currentHash !== newHash;
459
- this._currentHash = newHash;
420
+ if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
421
+ this._numPositionUpdates++;
422
+ }
460
423
 
461
- if (!state || false) {
462
- this._uid++;
424
+ if (UPDATE_VIEWAREA_TIMEOUT > 0) {
425
+ this._updateViewareaTimeout = setTimeout(() => {
426
+ if (!this._popStateInProgress) {
427
+ this._tryPushCurrentPosition(true);
428
+ }
463
429
 
464
- var _parseCurrentHash2 = parseCurrentHash(this.linkService),
465
- hash = _parseCurrentHash2.hash,
466
- page = _parseCurrentHash2.page,
467
- rotation = _parseCurrentHash2.rotation;
430
+ this._updateViewareaTimeout = null;
431
+ }, UPDATE_VIEWAREA_TIMEOUT);
432
+ }
433
+ }
468
434
 
469
- this._pushOrReplaceState({
470
- hash: hash,
471
- page: page,
472
- rotation: rotation
473
- }, true);
435
+ _popState({
436
+ state
437
+ }) {
438
+ const newHash = getCurrentHash(),
439
+ hashChanged = this._currentHash !== newHash;
440
+ this._currentHash = newHash;
474
441
 
475
- return;
476
- }
442
+ if (!state) {
443
+ this._uid++;
477
444
 
478
- if (!this._isValidState(state)) {
479
- return;
480
- }
445
+ const {
446
+ hash,
447
+ page,
448
+ rotation
449
+ } = this._parseCurrentHash();
481
450
 
482
- this._popStateInProgress = true;
451
+ this._pushOrReplaceState({
452
+ hash,
453
+ page,
454
+ rotation
455
+ }, true);
483
456
 
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
- }
457
+ return;
458
+ }
494
459
 
495
- var destination = state.destination;
460
+ if (!this._isValidState(state)) {
461
+ return;
462
+ }
496
463
 
497
- this._updateInternalState(destination, state.uid, true);
464
+ this._popStateInProgress = true;
498
465
 
499
- if (this._uid > this._maxUid) {
500
- this._maxUid = this._uid;
501
- }
466
+ if (hashChanged) {
467
+ this._blockHashChange++;
468
+ (0, _ui_utils.waitOnEventOrTimeout)({
469
+ target: window,
470
+ name: "hashchange",
471
+ delay: HASH_CHANGE_TIMEOUT
472
+ }).then(() => {
473
+ this._blockHashChange--;
474
+ });
475
+ }
502
476
 
503
- if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
504
- this.linkService.rotation = destination.rotation;
505
- }
477
+ const destination = state.destination;
506
478
 
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
- }
479
+ this._updateInternalState(destination, state.uid, true);
514
480
 
515
- Promise.resolve().then(function () {
516
- _this4._popStateInProgress = false;
517
- });
481
+ if (this._uid > this._maxUid) {
482
+ this._maxUid = this._uid;
518
483
  }
519
- }, {
520
- key: "_bindEvents",
521
- value: function _bindEvents() {
522
- var _this5 = this;
523
484
 
524
- var _boundEvents = this._boundEvents,
525
- eventBus = this.eventBus;
526
- _boundEvents.updateViewarea = this._updateViewarea.bind(this);
527
- _boundEvents.popState = this._popState.bind(this);
485
+ if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
486
+ this.linkService.rotation = destination.rotation;
487
+ }
528
488
 
529
- _boundEvents.pageHide = function (evt) {
530
- if (!_this5._destination || _this5._destination.temporary) {
531
- _this5._tryPushCurrentPosition();
532
- }
533
- };
489
+ if (destination.dest) {
490
+ this.linkService.navigateTo(destination.dest);
491
+ } else if (destination.hash) {
492
+ this.linkService.setHash(destination.hash);
493
+ } else if (destination.page) {
494
+ this.linkService.page = destination.page;
495
+ }
534
496
 
535
- eventBus.on('updateviewarea', _boundEvents.updateViewarea);
536
- window.addEventListener('popstate', _boundEvents.popState);
537
- window.addEventListener('pagehide', _boundEvents.pageHide);
497
+ Promise.resolve().then(() => {
498
+ this._popStateInProgress = false;
499
+ });
500
+ }
501
+
502
+ _pageHide() {
503
+ if (!this._destination || this._destination.temporary) {
504
+ this._tryPushCurrentPosition();
538
505
  }
539
- }, {
540
- key: "popStateInProgress",
541
- get: function get() {
542
- return this.initialized && (this._popStateInProgress || this._blockHashChange > 0);
506
+ }
507
+
508
+ _bindEvents() {
509
+ if (this._boundEvents) {
510
+ return;
543
511
  }
544
- }]);
545
512
 
546
- return PDFHistory;
547
- }();
513
+ this._boundEvents = {
514
+ updateViewarea: this._updateViewarea.bind(this),
515
+ popState: this._popState.bind(this),
516
+ pageHide: this._pageHide.bind(this)
517
+ };
518
+
519
+ this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
520
+
521
+ window.addEventListener("popstate", this._boundEvents.popState);
522
+ window.addEventListener("pagehide", this._boundEvents.pageHide);
523
+ }
524
+
525
+ _unbindEvents() {
526
+ if (!this._boundEvents) {
527
+ return;
528
+ }
529
+
530
+ this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
531
+
532
+ window.removeEventListener("popstate", this._boundEvents.popState);
533
+ window.removeEventListener("pagehide", this._boundEvents.pageHide);
534
+ this._boundEvents = null;
535
+ }
536
+
537
+ }
548
538
 
549
539
  exports.PDFHistory = PDFHistory;
550
540
 
551
541
  function isDestHashesEqual(destHash, pushHash) {
552
- if (typeof destHash !== 'string' || typeof pushHash !== 'string') {
542
+ if (typeof destHash !== "string" || typeof pushHash !== "string") {
553
543
  return false;
554
544
  }
555
545
 
@@ -557,8 +547,9 @@ function isDestHashesEqual(destHash, pushHash) {
557
547
  return true;
558
548
  }
559
549
 
560
- var _parseQueryString = (0, _ui_utils.parseQueryString)(destHash),
561
- nameddest = _parseQueryString.nameddest;
550
+ const {
551
+ nameddest
552
+ } = (0, _ui_utils.parseQueryString)(destHash);
562
553
 
563
554
  if (nameddest === pushHash) {
564
555
  return true;
@@ -569,7 +560,7 @@ function isDestHashesEqual(destHash, pushHash) {
569
560
 
570
561
  function isDestArraysEqual(firstDest, secondDest) {
571
562
  function isEntryEqual(first, second) {
572
- if (_typeof(first) !== _typeof(second)) {
563
+ if (typeof first !== typeof second) {
573
564
  return false;
574
565
  }
575
566
 
@@ -577,12 +568,12 @@ function isDestArraysEqual(firstDest, secondDest) {
577
568
  return false;
578
569
  }
579
570
 
580
- if (first !== null && _typeof(first) === 'object' && second !== null) {
571
+ if (first !== null && typeof first === "object" && second !== null) {
581
572
  if (Object.keys(first).length !== Object.keys(second).length) {
582
573
  return false;
583
574
  }
584
575
 
585
- for (var key in first) {
576
+ for (const key in first) {
586
577
  if (!isEntryEqual(first[key], second[key])) {
587
578
  return false;
588
579
  }
@@ -602,7 +593,7 @@ function isDestArraysEqual(firstDest, secondDest) {
602
593
  return false;
603
594
  }
604
595
 
605
- for (var i = 0, ii = firstDest.length; i < ii; i++) {
596
+ for (let i = 0, ii = firstDest.length; i < ii; i++) {
606
597
  if (!isEntryEqual(firstDest[i], secondDest[i])) {
607
598
  return false;
608
599
  }