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.
- package/CODE_OF_CONDUCT.md +15 -0
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8286 -14230
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +25500 -26628
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25473 -0
- package/es5/build/pdf.js.map +1 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +57878 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/images/texture.png +0 -0
- package/es5/web/pdf_viewer.css +407 -0
- package/es5/web/pdf_viewer.js +7757 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +2887 -4094
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +855 -778
- package/lib/core/arithmetic_decoder.js +325 -311
- package/lib/core/bidi.js +117 -50
- package/lib/core/ccitt.js +251 -89
- package/lib/core/ccitt_stream.js +26 -16
- package/lib/core/cff_parser.js +525 -197
- package/lib/core/charsets.js +6 -5
- package/lib/core/chunked_stream.js +541 -406
- package/lib/core/cmap.js +368 -253
- package/lib/core/colorspace.js +781 -800
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +609 -422
- package/lib/core/document.js +649 -481
- package/lib/core/encodings.js +33 -24
- package/lib/core/evaluator.js +1471 -736
- package/lib/core/font_renderer.js +289 -149
- package/lib/core/fonts.js +1067 -413
- package/lib/core/function.js +517 -287
- package/lib/core/glyphlist.js +4529 -4527
- package/lib/core/image.js +232 -114
- package/lib/core/image_utils.js +94 -0
- package/lib/core/jbig2.js +711 -342
- package/lib/core/jbig2_stream.js +31 -19
- package/lib/core/jpeg_stream.js +151 -26
- package/lib/core/jpg.js +433 -181
- package/lib/core/jpx.js +551 -143
- package/lib/core/jpx_stream.js +40 -28
- package/lib/core/metrics.js +2931 -2931
- package/lib/core/murmurhash3.js +104 -97
- package/lib/core/obj.js +1561 -1053
- package/lib/core/operator_list.js +192 -64
- package/lib/core/parser.js +1162 -864
- package/lib/core/pattern.js +224 -75
- package/lib/core/pdf_manager.js +154 -285
- package/lib/core/primitives.js +145 -69
- package/lib/core/ps_parser.js +212 -162
- package/lib/core/standard_fonts.js +245 -244
- package/lib/core/stream.js +353 -81
- package/lib/core/type1_parser.js +218 -68
- package/lib/core/unicode.js +1682 -1655
- package/lib/core/worker.js +233 -302
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +808 -862
- package/lib/display/api.js +1778 -1462
- package/lib/display/api_compatibility.js +14 -9
- package/lib/display/canvas.js +463 -140
- package/lib/display/content_disposition.js +86 -58
- package/lib/display/display_utils.js +524 -0
- package/lib/display/fetch_stream.js +202 -274
- package/lib/display/font_loader.js +311 -333
- package/lib/display/metadata.js +98 -88
- package/lib/display/network.js +343 -347
- package/lib/display/network_utils.js +46 -26
- package/lib/display/node_stream.js +326 -404
- package/lib/display/pattern_helper.js +168 -69
- package/lib/display/svg.js +1296 -885
- package/lib/display/text_layer.js +229 -103
- package/lib/display/transport_stream.js +290 -250
- package/lib/display/webgl.js +116 -83
- package/lib/display/worker_options.js +6 -5
- package/lib/display/xml_parser.js +358 -337
- package/lib/examples/node/domstubs.js +95 -39
- package/lib/pdf.js +49 -31
- package/lib/pdf.worker.js +7 -5
- package/lib/shared/compatibility.js +3 -145
- package/lib/shared/is_node.js +8 -7
- package/lib/shared/message_handler.js +367 -314
- package/lib/shared/util.js +421 -415
- package/lib/test/unit/annotation_spec.js +1570 -690
- package/lib/test/unit/api_spec.js +855 -493
- package/lib/test/unit/bidi_spec.js +12 -12
- package/lib/test/unit/cff_parser_spec.js +88 -61
- package/lib/test/unit/clitests_helper.js +9 -12
- package/lib/test/unit/cmap_spec.js +140 -88
- package/lib/test/unit/colorspace_spec.js +204 -152
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +194 -182
- package/lib/test/unit/custom_spec.js +50 -64
- package/lib/test/unit/display_svg_spec.js +53 -38
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +17 -22
- package/lib/test/unit/encodings_spec.js +15 -57
- package/lib/test/unit/evaluator_spec.js +90 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +219 -205
- package/lib/test/unit/jasmine-boot.js +68 -39
- package/lib/test/unit/message_handler_spec.js +187 -160
- package/lib/test/unit/metadata_spec.js +87 -34
- package/lib/test/unit/murmurhash3_spec.js +13 -13
- package/lib/test/unit/network_spec.js +26 -59
- package/lib/test/unit/network_utils_spec.js +187 -121
- package/lib/test/unit/node_stream_spec.js +98 -90
- package/lib/test/unit/parser_spec.js +173 -131
- package/lib/test/unit/pdf_find_controller_spec.js +148 -67
- package/lib/test/unit/pdf_find_utils_spec.js +35 -34
- package/lib/test/unit/pdf_history_spec.js +45 -33
- package/lib/test/unit/primitives_spec.js +161 -126
- package/lib/test/unit/stream_spec.js +22 -15
- package/lib/test/unit/test_utils.js +149 -98
- package/lib/test/unit/testreporter.js +36 -18
- package/lib/test/unit/type1_parser_spec.js +46 -44
- package/lib/test/unit/ui_utils_spec.js +388 -372
- package/lib/test/unit/unicode_spec.js +49 -46
- package/lib/test/unit/util_spec.js +144 -248
- package/lib/web/annotation_layer_builder.js +75 -95
- package/lib/web/app.js +1538 -1147
- package/lib/web/app_options.js +116 -104
- package/lib/web/base_viewer.js +950 -775
- package/lib/web/chromecom.js +217 -225
- package/lib/web/debugger.js +236 -148
- package/lib/web/download_manager.js +50 -50
- package/lib/web/firefox_print_service.js +51 -33
- package/lib/web/firefoxcom.js +225 -352
- package/lib/web/genericcom.js +30 -93
- package/lib/web/genericl10n.js +26 -143
- package/lib/web/grab_to_pan.js +57 -33
- package/lib/web/interfaces.js +105 -232
- package/lib/web/overlay_manager.js +73 -227
- package/lib/web/password_prompt.js +44 -62
- package/lib/web/pdf_attachment_viewer.js +118 -123
- package/lib/web/pdf_cursor_tools.js +89 -93
- package/lib/web/pdf_document_properties.js +242 -281
- package/lib/web/pdf_find_bar.js +157 -163
- package/lib/web/pdf_find_controller.js +598 -454
- package/lib/web/pdf_find_utils.js +32 -16
- package/lib/web/pdf_history.js +481 -355
- package/lib/web/pdf_link_service.js +355 -323
- package/lib/web/pdf_outline_viewer.js +167 -152
- package/lib/web/pdf_page_view.js +511 -457
- package/lib/web/pdf_presentation_mode.js +347 -335
- package/lib/web/pdf_print_service.js +133 -103
- package/lib/web/pdf_rendering_queue.js +98 -100
- package/lib/web/pdf_sidebar.js +323 -299
- package/lib/web/pdf_sidebar_resizer.js +107 -108
- package/lib/web/pdf_single_page_viewer.js +94 -146
- package/lib/web/pdf_thumbnail_view.js +319 -269
- package/lib/web/pdf_thumbnail_viewer.js +219 -199
- package/lib/web/pdf_viewer.component.js +111 -32
- package/lib/web/pdf_viewer.js +61 -101
- package/lib/web/preferences.js +87 -272
- package/lib/web/secondary_toolbar.js +207 -220
- package/lib/web/text_layer_builder.js +322 -322
- package/lib/web/toolbar.js +227 -180
- package/lib/web/ui_utils.js +476 -421
- package/lib/web/view_history.js +59 -208
- package/lib/web/viewer_compatibility.js +9 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +36 -22
- package/web/pdf_viewer.js +4407 -4516
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/display/dom_utils.js +0 -441
- package/lib/shared/streams_polyfill.js +0 -39
- package/lib/shared/url_polyfill.js +0 -50
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/web/dom_events.js +0 -140
package/lib/web/pdf_history.js
CHANGED
@@ -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
|
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
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
exports.
|
28
|
-
|
29
|
-
|
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
|
31
|
+
var _ui_utils = require("./ui_utils.js");
|
36
32
|
|
37
|
-
|
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,
|
70
|
-
this.
|
71
|
-
this.
|
72
|
-
this.
|
73
|
-
this._boundEvents =
|
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
|
-
|
76
|
-
this.eventBus.
|
77
|
-
|
53
|
+
|
54
|
+
this.eventBus._on("presentationmodechanged", evt => {
|
55
|
+
this._isViewerInPresentationMode = evt.active || evt.switchInProgress;
|
78
56
|
});
|
79
|
-
|
80
|
-
|
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
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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
|
-
|
90
|
-
|
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
|
-
|
149
|
-
|
150
|
-
|
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
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
this.
|
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
|
-
|
196
|
-
|
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
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
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
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
this.
|
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
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
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
|
-
|
253
|
-
|
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
|
-
|
257
|
-
|
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
|
-
|
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
|
-
|
263
|
-
|
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
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
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
|
-
|
294
|
-
|
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
|
-
|
362
|
+
if (state.destination === null || typeof state.destination !== "object") {
|
363
|
+
return false;
|
364
|
+
}
|
310
365
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
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
|
-
|
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
|
-
|
433
|
+
_popState({
|
434
|
+
state
|
435
|
+
}) {
|
436
|
+
const newHash = getCurrentHash(),
|
344
437
|
hashChanged = this._currentHash !== newHash;
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
}
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
this.
|
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
|
-
|
400
|
-
eventBus = this.eventBus;
|
475
|
+
const destination = state.destination;
|
401
476
|
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
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
|
-
|
415
|
-
|
416
|
-
|
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
|
-
|
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 !==
|
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
|
-
|
432
|
-
|
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 (
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
+
}
|