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.
- package/CODE_OF_CONDUCT.md +15 -0
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8382 -18492
- 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 +20417 -29816
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25688 -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 +58239 -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 +403 -0
- package/es5/web/pdf_viewer.js +7742 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1475 -4897
- 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 +750 -899
- package/lib/core/arithmetic_decoder.js +81 -97
- package/lib/core/bidi.js +54 -46
- package/lib/core/ccitt.js +88 -81
- package/lib/core/ccitt_stream.js +15 -14
- package/lib/core/cff_parser.js +235 -183
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +447 -542
- package/lib/core/cmap.js +222 -264
- package/lib/core/colorspace.js +699 -863
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +379 -437
- package/lib/core/document.js +573 -660
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +1103 -868
- package/lib/core/font_renderer.js +135 -178
- package/lib/core/fonts.js +570 -491
- package/lib/core/function.js +291 -288
- package/lib/core/glyphlist.js +4527 -4526
- package/lib/core/image.js +145 -149
- package/lib/core/image_utils.js +170 -0
- package/lib/core/jbig2.js +325 -316
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +21 -26
- package/lib/core/jpg.js +284 -232
- package/lib/core/jpx.js +161 -143
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2929 -2929
- package/lib/core/murmurhash3.js +90 -101
- package/lib/core/obj.js +1183 -1157
- package/lib/core/operator_list.js +99 -67
- package/lib/core/parser.js +972 -911
- package/lib/core/pattern.js +87 -70
- package/lib/core/pdf_manager.js +150 -315
- package/lib/core/primitives.js +83 -56
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +94 -74
- package/lib/core/type1_parser.js +87 -69
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +193 -390
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +741 -972
- package/lib/display/api.js +1500 -1791
- package/lib/display/api_compatibility.js +12 -17
- package/lib/display/canvas.js +165 -165
- package/lib/display/content_disposition.js +40 -59
- package/lib/display/display_utils.js +515 -0
- package/lib/display/fetch_stream.js +183 -298
- package/lib/display/font_loader.js +273 -413
- package/lib/display/metadata.js +86 -98
- package/lib/display/network.js +266 -359
- package/lib/display/network_utils.js +25 -18
- package/lib/display/node_stream.js +285 -458
- package/lib/display/pattern_helper.js +113 -65
- package/lib/display/svg.js +1166 -901
- package/lib/display/text_layer.js +156 -132
- package/lib/display/transport_stream.js +262 -278
- package/lib/display/webgl.js +70 -83
- package/lib/display/worker_options.js +3 -3
- package/lib/display/xml_parser.js +303 -392
- package/lib/examples/node/domstubs.js +40 -37
- package/lib/pdf.js +226 -59
- package/lib/pdf.worker.js +14 -6
- package/lib/shared/compatibility.js +3 -246
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +327 -332
- package/lib/shared/util.js +266 -416
- package/lib/test/unit/annotation_spec.js +1555 -701
- package/lib/test/unit/api_spec.js +802 -604
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +84 -69
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +74 -76
- package/lib/test/unit/colorspace_spec.js +166 -161
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +181 -181
- package/lib/test/unit/custom_spec.js +20 -22
- package/lib/test/unit/display_svg_spec.js +34 -39
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +16 -21
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +83 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +46 -30
- package/lib/test/unit/message_handler_spec.js +173 -159
- package/lib/test/unit/metadata_spec.js +69 -69
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +13 -61
- package/lib/test/unit/network_utils_spec.js +183 -119
- package/lib/test/unit/node_stream_spec.js +78 -92
- package/lib/test/unit/parser_spec.js +172 -114
- package/lib/test/unit/pdf_find_controller_spec.js +55 -86
- package/lib/test/unit/pdf_find_utils_spec.js +32 -32
- package/lib/test/unit/pdf_history_spec.js +32 -32
- package/lib/test/unit/primitives_spec.js +140 -125
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +131 -143
- package/lib/test/unit/testreporter.js +19 -19
- package/lib/test/unit/type1_parser_spec.js +42 -42
- package/lib/test/unit/ui_utils_spec.js +297 -459
- package/lib/test/unit/unicode_spec.js +38 -38
- package/lib/test/unit/util_spec.js +121 -305
- package/lib/web/annotation_layer_builder.js +66 -103
- package/lib/web/app.js +1328 -1214
- package/lib/web/app_options.js +105 -107
- package/lib/web/base_viewer.js +824 -838
- package/lib/web/chromecom.js +165 -252
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +39 -55
- package/lib/web/firefox_print_service.js +37 -27
- package/lib/web/firefoxcom.js +212 -363
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +32 -30
- package/lib/web/interfaces.js +80 -254
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +113 -131
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +221 -306
- package/lib/web/pdf_find_bar.js +136 -170
- package/lib/web/pdf_find_controller.js +491 -548
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +397 -406
- package/lib/web/pdf_link_service.js +304 -348
- package/lib/web/pdf_outline_viewer.js +140 -175
- package/lib/web/pdf_page_view.js +452 -523
- package/lib/web/pdf_presentation_mode.js +308 -357
- package/lib/web/pdf_print_service.js +90 -104
- package/lib/web/pdf_rendering_queue.js +84 -108
- package/lib/web/pdf_sidebar.js +276 -306
- package/lib/web/pdf_sidebar_resizer.js +92 -119
- package/lib/web/pdf_single_page_viewer.js +77 -126
- package/lib/web/pdf_thumbnail_view.js +276 -297
- package/lib/web/pdf_thumbnail_viewer.js +186 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +82 -286
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +282 -339
- package/lib/web/toolbar.js +217 -210
- package/lib/web/ui_utils.js +267 -420
- package/lib/web/view_history.js +52 -226
- package/lib/web/viewer_compatibility.js +21 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +35 -25
- package/web/pdf_viewer.js +3489 -4855
- 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 -494
- package/lib/shared/streams_polyfill.js +0 -43
- package/lib/shared/url_polyfill.js +0 -56
- package/lib/test/unit/dom_utils_spec.js +0 -89
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.
|
@@ -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
|
-
|
33
|
+
const HASH_CHANGE_TIMEOUT = 1000;
|
34
|
+
const POSITION_UPDATED_THRESHOLD = 50;
|
35
|
+
const UPDATE_VIEWAREA_TIMEOUT = 1000;
|
34
36
|
|
35
|
-
function
|
36
|
-
|
37
|
-
|
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
|
-
|
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
|
-
|
54
|
+
this.eventBus._on("presentationmodechanged", evt => {
|
55
|
+
this._isViewerInPresentationMode = evt.active || evt.switchInProgress;
|
56
|
+
});
|
44
57
|
|
45
|
-
|
58
|
+
this.eventBus._on("pagesinit", () => {
|
59
|
+
this._isPagesLoaded = false;
|
46
60
|
|
47
|
-
|
61
|
+
const onPagesLoaded = evt => {
|
62
|
+
this.eventBus._off("pagesloaded", onPagesLoaded);
|
48
63
|
|
49
|
-
|
50
|
-
|
51
|
-
var UPDATE_VIEWAREA_TIMEOUT = 1000;
|
64
|
+
this._isPagesLoaded = !!evt.pagesCount;
|
65
|
+
};
|
52
66
|
|
53
|
-
|
54
|
-
|
55
|
-
}
|
67
|
+
this.eventBus._on("pagesloaded", onPagesLoaded);
|
68
|
+
});
|
69
|
+
}
|
56
70
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
81
|
+
if (this._initialized) {
|
82
|
+
this.reset();
|
83
|
+
}
|
65
84
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
74
|
-
/*#__PURE__*/
|
75
|
-
function () {
|
76
|
-
function PDFHistory(_ref) {
|
77
|
-
var _this = this;
|
90
|
+
this._bindEvents();
|
78
91
|
|
79
|
-
|
80
|
-
|
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
|
-
|
101
|
+
if (!this._isValidState(state, true) || resetHistory) {
|
102
|
+
const {
|
103
|
+
hash,
|
104
|
+
page,
|
105
|
+
rotation
|
106
|
+
} = this._parseCurrentHash(true);
|
83
107
|
|
84
|
-
|
85
|
-
|
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
|
-
|
115
|
-
|
116
|
-
|
114
|
+
this._pushOrReplaceState({
|
115
|
+
hash,
|
116
|
+
page,
|
117
|
+
rotation
|
118
|
+
}, true);
|
117
119
|
|
118
|
-
|
119
|
-
|
120
|
-
}
|
120
|
+
return;
|
121
|
+
}
|
121
122
|
|
122
|
-
|
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
|
-
|
147
|
-
hash: hash,
|
148
|
-
page: page,
|
149
|
-
rotation: rotation
|
150
|
-
}, true);
|
125
|
+
this._updateInternalState(destination, state.uid, true);
|
151
126
|
|
152
|
-
|
153
|
-
|
127
|
+
if (this._uid > this._maxUid) {
|
128
|
+
this._maxUid = this._uid;
|
129
|
+
}
|
154
130
|
|
155
|
-
|
131
|
+
if (destination.rotation !== undefined) {
|
132
|
+
this._initialRotation = destination.rotation;
|
133
|
+
}
|
156
134
|
|
157
|
-
|
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
|
-
|
160
|
-
|
161
|
-
|
145
|
+
reset() {
|
146
|
+
if (this._initialized) {
|
147
|
+
this._pageHide();
|
162
148
|
|
163
|
-
|
164
|
-
this.initialRotation = destination.rotation;
|
165
|
-
}
|
149
|
+
this._initialized = false;
|
166
150
|
|
167
|
-
|
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
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
154
|
+
if (this._updateViewareaTimeout) {
|
155
|
+
clearTimeout(this._updateViewareaTimeout);
|
156
|
+
this._updateViewareaTimeout = null;
|
157
|
+
}
|
185
158
|
|
186
|
-
|
187
|
-
|
188
|
-
|
159
|
+
this._initialBookmark = null;
|
160
|
+
this._initialRotation = null;
|
161
|
+
}
|
189
162
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
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
|
-
|
185
|
+
const hash = namedDest || JSON.stringify(explicitDest);
|
204
186
|
|
205
|
-
|
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
|
-
|
198
|
+
forceReplace = true;
|
199
|
+
}
|
210
200
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
}
|
201
|
+
if (this._popStateInProgress && !forceReplace) {
|
202
|
+
return;
|
203
|
+
}
|
215
204
|
|
216
|
-
|
217
|
-
|
205
|
+
this._pushOrReplaceState({
|
206
|
+
dest: explicitDest,
|
207
|
+
hash,
|
208
|
+
page: pageNumber,
|
209
|
+
rotation: this.linkService.rotation
|
210
|
+
}, forceReplace);
|
218
211
|
|
219
|
-
|
220
|
-
|
221
|
-
|
212
|
+
if (!this._popStateInProgress) {
|
213
|
+
this._popStateInProgress = true;
|
214
|
+
Promise.resolve().then(() => {
|
215
|
+
this._popStateInProgress = false;
|
216
|
+
});
|
217
|
+
}
|
218
|
+
}
|
222
219
|
|
223
|
-
|
224
|
-
|
225
|
-
|
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
|
-
|
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
|
-
|
233
|
+
const state = window.history.state;
|
254
234
|
|
255
|
-
|
256
|
-
|
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
|
-
|
245
|
+
const state = window.history.state;
|
267
246
|
|
268
|
-
|
269
|
-
|
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
|
-
|
252
|
+
get popStateInProgress() {
|
253
|
+
return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
|
254
|
+
}
|
284
255
|
|
285
|
-
|
256
|
+
get initialBookmark() {
|
257
|
+
return this._initialized ? this._initialBookmark : null;
|
258
|
+
}
|
286
259
|
|
287
|
-
|
288
|
-
|
260
|
+
get initialRotation() {
|
261
|
+
return this._initialized ? this._initialRotation : null;
|
262
|
+
}
|
289
263
|
|
290
|
-
|
291
|
-
|
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
|
-
|
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
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
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
|
-
|
317
|
-
|
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
|
-
|
292
|
+
_tryPushCurrentPosition(temporary = false) {
|
293
|
+
if (!this._position) {
|
294
|
+
return;
|
295
|
+
}
|
321
296
|
|
322
|
-
|
323
|
-
position = Object.assign(Object.create(null), this._position);
|
324
|
-
position.temporary = true;
|
325
|
-
}
|
297
|
+
let position = this._position;
|
326
298
|
|
327
|
-
|
328
|
-
|
299
|
+
if (temporary) {
|
300
|
+
position = Object.assign(Object.create(null), this._position);
|
301
|
+
position.temporary = true;
|
302
|
+
}
|
329
303
|
|
330
|
-
|
331
|
-
|
304
|
+
if (!this._destination) {
|
305
|
+
this._pushOrReplaceState(position);
|
332
306
|
|
333
|
-
|
334
|
-
|
307
|
+
return;
|
308
|
+
}
|
335
309
|
|
336
|
-
|
337
|
-
|
310
|
+
if (this._destination.temporary) {
|
311
|
+
this._pushOrReplaceState(position, true);
|
338
312
|
|
339
|
-
|
340
|
-
|
341
|
-
}
|
313
|
+
return;
|
314
|
+
}
|
342
315
|
|
343
|
-
|
344
|
-
|
345
|
-
|
316
|
+
if (this._destination.hash === position.hash) {
|
317
|
+
return;
|
318
|
+
}
|
346
319
|
|
347
|
-
|
320
|
+
if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
|
321
|
+
return;
|
322
|
+
}
|
348
323
|
|
349
|
-
|
350
|
-
if (this._destination.dest || !this._destination.first) {
|
351
|
-
return;
|
352
|
-
}
|
324
|
+
let forceReplace = false;
|
353
325
|
|
354
|
-
|
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
|
-
|
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
|
-
|
369
|
-
|
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
|
-
|
375
|
-
|
376
|
-
|
337
|
+
_isValidState(state, checkReload = false) {
|
338
|
+
if (!state) {
|
339
|
+
return false;
|
340
|
+
}
|
377
341
|
|
378
|
-
|
379
|
-
|
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
|
-
|
387
|
-
return false;
|
388
|
-
}
|
348
|
+
const [perfEntry] = performance.getEntriesByType("navigation");
|
389
349
|
|
390
|
-
|
350
|
+
if (!perfEntry || perfEntry.type !== "reload") {
|
351
|
+
return false;
|
352
|
+
}
|
353
|
+
} else {
|
391
354
|
return false;
|
392
355
|
}
|
356
|
+
}
|
393
357
|
|
394
|
-
|
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
|
-
|
402
|
-
|
403
|
-
|
404
|
-
}
|
362
|
+
if (state.destination === null || typeof state.destination !== "object") {
|
363
|
+
return false;
|
364
|
+
}
|
405
365
|
|
406
|
-
|
407
|
-
|
408
|
-
}
|
366
|
+
return true;
|
367
|
+
}
|
409
368
|
|
410
|
-
|
411
|
-
|
412
|
-
this.
|
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
|
-
|
375
|
+
if (removeTemporary && destination && destination.temporary) {
|
376
|
+
delete destination.temporary;
|
377
|
+
}
|
420
378
|
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
379
|
+
this._destination = destination;
|
380
|
+
this._uid = uid;
|
381
|
+
this._numPositionUpdates = 0;
|
382
|
+
}
|
425
383
|
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
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
|
-
|
434
|
-
|
435
|
-
|
390
|
+
if (!(Number.isInteger(page) && page > 0 && page <= this.linkService.pagesCount) || checkNameddest && nameddest.length > 0) {
|
391
|
+
page = null;
|
392
|
+
}
|
436
393
|
|
437
|
-
|
438
|
-
|
439
|
-
|
394
|
+
return {
|
395
|
+
hash,
|
396
|
+
page,
|
397
|
+
rotation: this.linkService.rotation
|
398
|
+
};
|
399
|
+
}
|
440
400
|
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
401
|
+
_updateViewarea({
|
402
|
+
location
|
403
|
+
}) {
|
404
|
+
if (this._updateViewareaTimeout) {
|
405
|
+
clearTimeout(this._updateViewareaTimeout);
|
406
|
+
this._updateViewareaTimeout = null;
|
407
|
+
}
|
446
408
|
|
447
|
-
|
448
|
-
|
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
|
-
|
457
|
-
|
458
|
-
|
459
|
-
this._currentHash = newHash;
|
420
|
+
if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
|
421
|
+
this._numPositionUpdates++;
|
422
|
+
}
|
460
423
|
|
461
|
-
|
462
|
-
|
424
|
+
if (UPDATE_VIEWAREA_TIMEOUT > 0) {
|
425
|
+
this._updateViewareaTimeout = setTimeout(() => {
|
426
|
+
if (!this._popStateInProgress) {
|
427
|
+
this._tryPushCurrentPosition(true);
|
428
|
+
}
|
463
429
|
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
430
|
+
this._updateViewareaTimeout = null;
|
431
|
+
}, UPDATE_VIEWAREA_TIMEOUT);
|
432
|
+
}
|
433
|
+
}
|
468
434
|
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
435
|
+
_popState({
|
436
|
+
state
|
437
|
+
}) {
|
438
|
+
const newHash = getCurrentHash(),
|
439
|
+
hashChanged = this._currentHash !== newHash;
|
440
|
+
this._currentHash = newHash;
|
474
441
|
|
475
|
-
|
476
|
-
|
442
|
+
if (!state) {
|
443
|
+
this._uid++;
|
477
444
|
|
478
|
-
|
479
|
-
|
480
|
-
|
445
|
+
const {
|
446
|
+
hash,
|
447
|
+
page,
|
448
|
+
rotation
|
449
|
+
} = this._parseCurrentHash();
|
481
450
|
|
482
|
-
this.
|
451
|
+
this._pushOrReplaceState({
|
452
|
+
hash,
|
453
|
+
page,
|
454
|
+
rotation
|
455
|
+
}, true);
|
483
456
|
|
484
|
-
|
485
|
-
|
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
|
-
|
460
|
+
if (!this._isValidState(state)) {
|
461
|
+
return;
|
462
|
+
}
|
496
463
|
|
497
|
-
|
464
|
+
this._popStateInProgress = true;
|
498
465
|
|
499
|
-
|
500
|
-
|
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
|
-
|
504
|
-
this.linkService.rotation = destination.rotation;
|
505
|
-
}
|
477
|
+
const destination = state.destination;
|
506
478
|
|
507
|
-
|
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
|
-
|
516
|
-
|
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
|
-
|
525
|
-
|
526
|
-
|
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
|
-
|
530
|
-
|
531
|
-
|
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
|
-
|
536
|
-
|
537
|
-
|
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
|
-
|
541
|
-
|
542
|
-
|
506
|
+
}
|
507
|
+
|
508
|
+
_bindEvents() {
|
509
|
+
if (this._boundEvents) {
|
510
|
+
return;
|
543
511
|
}
|
544
|
-
}]);
|
545
512
|
|
546
|
-
|
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 !==
|
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
|
-
|
561
|
-
|
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 (
|
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 &&
|
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 (
|
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 (
|
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
|
}
|