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