pdfjs-dist 2.3.200 → 2.4.456
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +6499 -17971
- 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 +19303 -29896
- 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 +1333 -4839
- 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 +683 -1066
- 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 +196 -193
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +441 -569
- package/lib/core/cmap.js +220 -279
- package/lib/core/colorspace.js +699 -863
- package/lib/core/core_utils.js +59 -80
- package/lib/core/crypto.js +379 -437
- package/lib/core/document.js +564 -673
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +983 -889
- package/lib/core/font_renderer.js +128 -171
- package/lib/core/fonts.js +451 -400
- package/lib/core/function.js +289 -285
- package/lib/core/glyphlist.js +4527 -4527
- package/lib/core/image.js +138 -117
- package/lib/core/image_utils.js +46 -63
- package/lib/core/jbig2.js +324 -332
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +133 -24
- package/lib/core/jpg.js +238 -210
- package/lib/core/jpx.js +158 -157
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2928 -2928
- package/lib/core/murmurhash3.js +87 -102
- package/lib/core/obj.js +1111 -1302
- package/lib/core/operator_list.js +55 -42
- package/lib/core/parser.js +956 -987
- package/lib/core/pattern.js +69 -69
- package/lib/core/pdf_manager.js +149 -316
- package/lib/core/primitives.js +45 -77
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +83 -77
- package/lib/core/type1_parser.js +78 -68
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +148 -196
- package/lib/core/worker_stream.js +101 -210
- package/lib/display/annotation_layer.js +733 -1155
- package/lib/display/api.js +1539 -1928
- package/lib/display/api_compatibility.js +10 -8
- package/lib/display/canvas.js +159 -158
- package/lib/display/content_disposition.js +36 -55
- package/lib/display/display_utils.js +298 -551
- package/lib/display/fetch_stream.js +181 -305
- package/lib/display/font_loader.js +273 -416
- package/lib/display/metadata.js +86 -98
- package/lib/display/network.js +376 -511
- package/lib/display/network_utils.js +20 -19
- package/lib/display/node_stream.js +276 -460
- package/lib/display/pattern_helper.js +76 -44
- package/lib/display/svg.js +1137 -1405
- package/lib/display/text_layer.js +75 -82
- package/lib/display/transport_stream.js +236 -374
- 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 +37 -37
- package/lib/pdf.js +22 -21
- package/lib/pdf.worker.js +5 -5
- package/lib/shared/compatibility.js +2 -251
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +222 -194
- package/lib/shared/util.js +269 -405
- package/lib/test/unit/annotation_spec.js +1089 -1014
- package/lib/test/unit/api_spec.js +617 -544
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +63 -62
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +84 -86
- package/lib/test/unit/colorspace_spec.js +154 -154
- package/lib/test/unit/core_utils_spec.js +125 -105
- package/lib/test/unit/crypto_spec.js +181 -181
- package/lib/test/unit/custom_spec.js +22 -24
- package/lib/test/unit/display_svg_spec.js +35 -36
- package/lib/test/unit/display_utils_spec.js +139 -149
- package/lib/test/unit/document_spec.js +16 -16
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +81 -95
- package/lib/test/unit/fetch_stream_spec.js +30 -30
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +48 -32
- package/lib/test/unit/message_handler_spec.js +172 -162
- 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 +12 -12
- package/lib/test/unit/network_utils_spec.js +152 -152
- package/lib/test/unit/node_stream_spec.js +74 -90
- package/lib/test/unit/parser_spec.js +107 -113
- 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 +117 -115
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +119 -285
- package/lib/test/unit/testreporter.js +19 -19
- package/lib/test/unit/type1_parser_spec.js +41 -41
- package/lib/test/unit/ui_utils_spec.js +318 -426
- package/lib/test/unit/unicode_spec.js +42 -42
- package/lib/test/unit/util_spec.js +122 -143
- package/lib/web/annotation_layer_builder.js +66 -103
- package/lib/web/app.js +1166 -1196
- package/lib/web/app_options.js +61 -77
- package/lib/web/base_viewer.js +804 -850
- package/lib/web/chromecom.js +164 -249
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +38 -57
- package/lib/web/firefox_print_service.js +35 -30
- package/lib/web/firefoxcom.js +175 -374
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +30 -30
- package/lib/web/interfaces.js +80 -258
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +105 -130
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +227 -376
- package/lib/web/pdf_find_bar.js +137 -171
- package/lib/web/pdf_find_controller.js +492 -549
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +395 -406
- package/lib/web/pdf_link_service.js +302 -349
- package/lib/web/pdf_outline_viewer.js +148 -209
- package/lib/web/pdf_page_view.js +449 -507
- package/lib/web/pdf_presentation_mode.js +304 -357
- package/lib/web/pdf_print_service.js +90 -104
- package/lib/web/pdf_rendering_queue.js +87 -108
- package/lib/web/pdf_sidebar.js +264 -304
- 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 +66 -273
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +284 -317
- package/lib/web/toolbar.js +216 -211
- package/lib/web/ui_utils.js +303 -404
- package/lib/web/view_history.js +49 -222
- package/lib/web/viewer_compatibility.js +7 -5
- package/package.json +2 -9
- package/web/pdf_viewer.css +25 -18
- package/web/pdf_viewer.js +3481 -4764
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/lib/shared/streams_polyfill.js +0 -43
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,516 @@ exports.isDestHashesEqual = isDestHashesEqual;
|
|
28
28
|
exports.isDestArraysEqual = isDestArraysEqual;
|
29
29
|
exports.PDFHistory = void 0;
|
30
30
|
|
31
|
-
var _ui_utils = require("./ui_utils");
|
31
|
+
var _ui_utils = require("./ui_utils.js");
|
32
32
|
|
33
|
-
|
33
|
+
const HASH_CHANGE_TIMEOUT = 1000;
|
34
|
+
const POSITION_UPDATED_THRESHOLD = 50;
|
35
|
+
const UPDATE_VIEWAREA_TIMEOUT = 1000;
|
34
36
|
|
35
|
-
function
|
36
|
-
|
37
|
-
|
37
|
+
function getCurrentHash() {
|
38
|
+
return document.location.hash;
|
39
|
+
}
|
38
40
|
|
39
|
-
|
41
|
+
class PDFHistory {
|
42
|
+
constructor({
|
43
|
+
linkService,
|
44
|
+
eventBus
|
45
|
+
}) {
|
46
|
+
this.linkService = linkService;
|
47
|
+
this.eventBus = eventBus || (0, _ui_utils.getGlobalEventBus)();
|
48
|
+
this._initialized = false;
|
49
|
+
this._fingerprint = "";
|
50
|
+
this.reset();
|
51
|
+
this._boundEvents = null;
|
52
|
+
this._isViewerInPresentationMode = false;
|
40
53
|
|
41
|
-
|
54
|
+
this.eventBus._on("presentationmodechanged", evt => {
|
55
|
+
this._isViewerInPresentationMode = evt.active || evt.switchInProgress;
|
56
|
+
});
|
42
57
|
|
43
|
-
|
58
|
+
this.eventBus._on("pagesinit", () => {
|
59
|
+
this._isPagesLoaded = false;
|
44
60
|
|
45
|
-
|
61
|
+
const onPagesLoaded = evt => {
|
62
|
+
this.eventBus._off("pagesloaded", onPagesLoaded);
|
46
63
|
|
47
|
-
|
64
|
+
this._isPagesLoaded = !!evt.pagesCount;
|
65
|
+
};
|
48
66
|
|
49
|
-
|
50
|
-
|
51
|
-
|
67
|
+
this.eventBus._on("pagesloaded", onPagesLoaded);
|
68
|
+
});
|
69
|
+
}
|
52
70
|
|
53
|
-
|
54
|
-
|
55
|
-
|
71
|
+
initialize({
|
72
|
+
fingerprint,
|
73
|
+
resetHistory = false,
|
74
|
+
updateUrl = false
|
75
|
+
}) {
|
76
|
+
if (!fingerprint || typeof fingerprint !== "string") {
|
77
|
+
console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
|
78
|
+
return;
|
79
|
+
}
|
56
80
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
var page = params.page | 0;
|
81
|
+
if (this._initialized) {
|
82
|
+
this.reset();
|
83
|
+
}
|
61
84
|
|
62
|
-
|
63
|
-
|
64
|
-
|
85
|
+
const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
|
86
|
+
this._fingerprint = fingerprint;
|
87
|
+
this._updateUrl = updateUrl === true;
|
88
|
+
this._initialized = true;
|
65
89
|
|
66
|
-
|
67
|
-
hash: hash,
|
68
|
-
page: page,
|
69
|
-
rotation: linkService.rotation
|
70
|
-
};
|
71
|
-
}
|
90
|
+
this._bindEvents();
|
72
91
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
92
|
+
const state = window.history.state;
|
93
|
+
this._popStateInProgress = false;
|
94
|
+
this._blockHashChange = 0;
|
95
|
+
this._currentHash = getCurrentHash();
|
96
|
+
this._numPositionUpdates = 0;
|
97
|
+
this._uid = this._maxUid = 0;
|
98
|
+
this._destination = null;
|
99
|
+
this._position = null;
|
78
100
|
|
79
|
-
|
80
|
-
|
101
|
+
if (!this._isValidState(state, true) || resetHistory) {
|
102
|
+
const {
|
103
|
+
hash,
|
104
|
+
page,
|
105
|
+
rotation
|
106
|
+
} = this._parseCurrentHash();
|
81
107
|
|
82
|
-
|
108
|
+
if (!hash || reInitialized || resetHistory) {
|
109
|
+
this._pushOrReplaceState(null, true);
|
83
110
|
|
84
|
-
this.linkService = linkService;
|
85
|
-
this.eventBus = eventBus || (0, _ui_utils.getGlobalEventBus)();
|
86
|
-
this.initialized = false;
|
87
|
-
this.initialBookmark = null;
|
88
|
-
this.initialRotation = null;
|
89
|
-
this._boundEvents = Object.create(null);
|
90
|
-
this._isViewerInPresentationMode = false;
|
91
|
-
this._isPagesLoaded = false;
|
92
|
-
this.eventBus.on('presentationmodechanged', function (evt) {
|
93
|
-
_this._isViewerInPresentationMode = evt.active || evt.switchInProgress;
|
94
|
-
});
|
95
|
-
this.eventBus.on('pagesloaded', function (evt) {
|
96
|
-
_this._isPagesLoaded = !!evt.pagesCount;
|
97
|
-
});
|
98
|
-
}
|
99
|
-
|
100
|
-
_createClass(PDFHistory, [{
|
101
|
-
key: "initialize",
|
102
|
-
value: function initialize(_ref2) {
|
103
|
-
var fingerprint = _ref2.fingerprint,
|
104
|
-
_ref2$resetHistory = _ref2.resetHistory,
|
105
|
-
resetHistory = _ref2$resetHistory === void 0 ? false : _ref2$resetHistory,
|
106
|
-
_ref2$updateUrl = _ref2.updateUrl,
|
107
|
-
updateUrl = _ref2$updateUrl === void 0 ? false : _ref2$updateUrl;
|
108
|
-
|
109
|
-
if (!fingerprint || typeof fingerprint !== 'string') {
|
110
|
-
console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
|
111
111
|
return;
|
112
112
|
}
|
113
113
|
|
114
|
-
|
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
|
+
}
|
184
|
+
|
185
|
+
const hash = namedDest || JSON.stringify(explicitDest);
|
186
|
+
|
187
|
+
if (!hash) {
|
188
|
+
return;
|
189
|
+
}
|
202
190
|
|
203
|
-
|
191
|
+
let forceReplace = false;
|
204
192
|
|
205
|
-
|
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();
|
258
237
|
}
|
259
|
-
}
|
260
|
-
key: "forward",
|
261
|
-
value: function forward() {
|
262
|
-
if (!this.initialized || this._popStateInProgress) {
|
263
|
-
return;
|
264
|
-
}
|
238
|
+
}
|
265
239
|
|
266
|
-
|
240
|
+
forward() {
|
241
|
+
if (!this._initialized || this._popStateInProgress) {
|
242
|
+
return;
|
243
|
+
}
|
267
244
|
|
268
|
-
|
269
|
-
|
270
|
-
|
245
|
+
const state = window.history.state;
|
246
|
+
|
247
|
+
if (this._isValidState(state) && state.uid < this._maxUid) {
|
248
|
+
window.history.forward();
|
271
249
|
}
|
272
|
-
}
|
273
|
-
key: "_pushOrReplaceState",
|
274
|
-
value: function _pushOrReplaceState(destination) {
|
275
|
-
var forceReplace = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
276
|
-
var shouldReplace = forceReplace || !this._destination;
|
277
|
-
var newState = {
|
278
|
-
fingerprint: this.fingerprint,
|
279
|
-
uid: shouldReplace ? this._uid : this._uid + 1,
|
280
|
-
destination: destination
|
281
|
-
};
|
250
|
+
}
|
282
251
|
|
283
|
-
|
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
|
-
first: location.pageNumber,
|
430
|
-
rotation: location.rotation
|
431
|
-
};
|
384
|
+
_parseCurrentHash() {
|
385
|
+
const hash = unescape(getCurrentHash()).substring(1);
|
386
|
+
let page = (0, _ui_utils.parseQueryString)(hash).page | 0;
|
432
387
|
|
433
|
-
|
434
|
-
|
435
|
-
|
388
|
+
if (!(Number.isInteger(page) && page > 0 && page <= this.linkService.pagesCount)) {
|
389
|
+
page = null;
|
390
|
+
}
|
436
391
|
|
437
|
-
|
438
|
-
|
439
|
-
|
392
|
+
return {
|
393
|
+
hash,
|
394
|
+
page,
|
395
|
+
rotation: this.linkService.rotation
|
396
|
+
};
|
397
|
+
}
|
440
398
|
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
399
|
+
_updateViewarea({
|
400
|
+
location
|
401
|
+
}) {
|
402
|
+
if (this._updateViewareaTimeout) {
|
403
|
+
clearTimeout(this._updateViewareaTimeout);
|
404
|
+
this._updateViewareaTimeout = null;
|
405
|
+
}
|
446
406
|
|
447
|
-
|
448
|
-
|
449
|
-
|
407
|
+
this._position = {
|
408
|
+
hash: this._isViewerInPresentationMode ? `page=${location.pageNumber}` : location.pdfOpenParams.substring(1),
|
409
|
+
page: this.linkService.page,
|
410
|
+
first: location.pageNumber,
|
411
|
+
rotation: location.rotation
|
412
|
+
};
|
413
|
+
|
414
|
+
if (this._popStateInProgress) {
|
415
|
+
return;
|
450
416
|
}
|
451
|
-
}, {
|
452
|
-
key: "_popState",
|
453
|
-
value: function _popState(_ref5) {
|
454
|
-
var _this4 = this;
|
455
417
|
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
this._currentHash = newHash;
|
418
|
+
if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
|
419
|
+
this._numPositionUpdates++;
|
420
|
+
}
|
460
421
|
|
461
|
-
|
462
|
-
|
422
|
+
if (UPDATE_VIEWAREA_TIMEOUT > 0) {
|
423
|
+
this._updateViewareaTimeout = setTimeout(() => {
|
424
|
+
if (!this._popStateInProgress) {
|
425
|
+
this._tryPushCurrentPosition(true);
|
426
|
+
}
|
463
427
|
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
428
|
+
this._updateViewareaTimeout = null;
|
429
|
+
}, UPDATE_VIEWAREA_TIMEOUT);
|
430
|
+
}
|
431
|
+
}
|
468
432
|
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
433
|
+
_popState({
|
434
|
+
state
|
435
|
+
}) {
|
436
|
+
const newHash = getCurrentHash(),
|
437
|
+
hashChanged = this._currentHash !== newHash;
|
438
|
+
this._currentHash = newHash;
|
474
439
|
|
475
|
-
|
476
|
-
|
440
|
+
if (!state) {
|
441
|
+
this._uid++;
|
477
442
|
|
478
|
-
|
479
|
-
|
480
|
-
|
443
|
+
const {
|
444
|
+
hash,
|
445
|
+
page,
|
446
|
+
rotation
|
447
|
+
} = this._parseCurrentHash();
|
481
448
|
|
482
|
-
this.
|
449
|
+
this._pushOrReplaceState({
|
450
|
+
hash,
|
451
|
+
page,
|
452
|
+
rotation
|
453
|
+
}, true);
|
483
454
|
|
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
|
-
}
|
455
|
+
return;
|
456
|
+
}
|
494
457
|
|
495
|
-
|
458
|
+
if (!this._isValidState(state)) {
|
459
|
+
return;
|
460
|
+
}
|
496
461
|
|
497
|
-
|
462
|
+
this._popStateInProgress = true;
|
498
463
|
|
499
|
-
|
500
|
-
|
501
|
-
|
464
|
+
if (hashChanged) {
|
465
|
+
this._blockHashChange++;
|
466
|
+
(0, _ui_utils.waitOnEventOrTimeout)({
|
467
|
+
target: window,
|
468
|
+
name: "hashchange",
|
469
|
+
delay: HASH_CHANGE_TIMEOUT
|
470
|
+
}).then(() => {
|
471
|
+
this._blockHashChange--;
|
472
|
+
});
|
473
|
+
}
|
502
474
|
|
503
|
-
|
504
|
-
this.linkService.rotation = destination.rotation;
|
505
|
-
}
|
475
|
+
const destination = state.destination;
|
506
476
|
|
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
|
-
}
|
477
|
+
this._updateInternalState(destination, state.uid, true);
|
514
478
|
|
515
|
-
|
516
|
-
|
517
|
-
});
|
479
|
+
if (this._uid > this._maxUid) {
|
480
|
+
this._maxUid = this._uid;
|
518
481
|
}
|
519
|
-
}, {
|
520
|
-
key: "_bindEvents",
|
521
|
-
value: function _bindEvents() {
|
522
|
-
var _this5 = this;
|
523
482
|
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
_boundEvents.popState = this._popState.bind(this);
|
483
|
+
if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
|
484
|
+
this.linkService.rotation = destination.rotation;
|
485
|
+
}
|
528
486
|
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
487
|
+
if (destination.dest) {
|
488
|
+
this.linkService.navigateTo(destination.dest);
|
489
|
+
} else if (destination.hash) {
|
490
|
+
this.linkService.setHash(destination.hash);
|
491
|
+
} else if (destination.page) {
|
492
|
+
this.linkService.page = destination.page;
|
493
|
+
}
|
534
494
|
|
535
|
-
|
536
|
-
|
537
|
-
|
495
|
+
Promise.resolve().then(() => {
|
496
|
+
this._popStateInProgress = false;
|
497
|
+
});
|
498
|
+
}
|
499
|
+
|
500
|
+
_pageHide() {
|
501
|
+
if (!this._destination || this._destination.temporary) {
|
502
|
+
this._tryPushCurrentPosition();
|
538
503
|
}
|
539
|
-
}
|
540
|
-
|
541
|
-
|
542
|
-
|
504
|
+
}
|
505
|
+
|
506
|
+
_bindEvents() {
|
507
|
+
if (this._boundEvents) {
|
508
|
+
return;
|
543
509
|
}
|
544
|
-
}]);
|
545
510
|
|
546
|
-
|
547
|
-
|
511
|
+
this._boundEvents = {
|
512
|
+
updateViewarea: this._updateViewarea.bind(this),
|
513
|
+
popState: this._popState.bind(this),
|
514
|
+
pageHide: this._pageHide.bind(this)
|
515
|
+
};
|
516
|
+
|
517
|
+
this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
|
518
|
+
|
519
|
+
window.addEventListener("popstate", this._boundEvents.popState);
|
520
|
+
window.addEventListener("pagehide", this._boundEvents.pageHide);
|
521
|
+
}
|
522
|
+
|
523
|
+
_unbindEvents() {
|
524
|
+
if (!this._boundEvents) {
|
525
|
+
return;
|
526
|
+
}
|
527
|
+
|
528
|
+
this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
|
529
|
+
|
530
|
+
window.removeEventListener("popstate", this._boundEvents.popState);
|
531
|
+
window.removeEventListener("pagehide", this._boundEvents.pageHide);
|
532
|
+
this._boundEvents = null;
|
533
|
+
}
|
534
|
+
|
535
|
+
}
|
548
536
|
|
549
537
|
exports.PDFHistory = PDFHistory;
|
550
538
|
|
551
539
|
function isDestHashesEqual(destHash, pushHash) {
|
552
|
-
if (typeof destHash !==
|
540
|
+
if (typeof destHash !== "string" || typeof pushHash !== "string") {
|
553
541
|
return false;
|
554
542
|
}
|
555
543
|
|
@@ -557,8 +545,9 @@ function isDestHashesEqual(destHash, pushHash) {
|
|
557
545
|
return true;
|
558
546
|
}
|
559
547
|
|
560
|
-
|
561
|
-
|
548
|
+
const {
|
549
|
+
nameddest
|
550
|
+
} = (0, _ui_utils.parseQueryString)(destHash);
|
562
551
|
|
563
552
|
if (nameddest === pushHash) {
|
564
553
|
return true;
|
@@ -569,7 +558,7 @@ function isDestHashesEqual(destHash, pushHash) {
|
|
569
558
|
|
570
559
|
function isDestArraysEqual(firstDest, secondDest) {
|
571
560
|
function isEntryEqual(first, second) {
|
572
|
-
if (
|
561
|
+
if (typeof first !== typeof second) {
|
573
562
|
return false;
|
574
563
|
}
|
575
564
|
|
@@ -577,12 +566,12 @@ function isDestArraysEqual(firstDest, secondDest) {
|
|
577
566
|
return false;
|
578
567
|
}
|
579
568
|
|
580
|
-
if (first !== null &&
|
569
|
+
if (first !== null && typeof first === "object" && second !== null) {
|
581
570
|
if (Object.keys(first).length !== Object.keys(second).length) {
|
582
571
|
return false;
|
583
572
|
}
|
584
573
|
|
585
|
-
for (
|
574
|
+
for (const key in first) {
|
586
575
|
if (!isEntryEqual(first[key], second[key])) {
|
587
576
|
return false;
|
588
577
|
}
|
@@ -602,7 +591,7 @@ function isDestArraysEqual(firstDest, secondDest) {
|
|
602
591
|
return false;
|
603
592
|
}
|
604
593
|
|
605
|
-
for (
|
594
|
+
for (let i = 0, ii = firstDest.length; i < ii; i++) {
|
606
595
|
if (!isEntryEqual(firstDest[i], secondDest[i])) {
|
607
596
|
return false;
|
608
597
|
}
|