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/base_viewer.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.
|
@@ -26,33 +26,27 @@ Object.defineProperty(exports, "__esModule", {
|
|
26
26
|
});
|
27
27
|
exports.BaseViewer = void 0;
|
28
28
|
|
29
|
-
var _ui_utils = require("./ui_utils");
|
29
|
+
var _ui_utils = require("./ui_utils.js");
|
30
30
|
|
31
|
-
var _pdf_rendering_queue = require("./pdf_rendering_queue");
|
31
|
+
var _pdf_rendering_queue = require("./pdf_rendering_queue.js");
|
32
32
|
|
33
|
-
var _annotation_layer_builder = require("./annotation_layer_builder");
|
33
|
+
var _annotation_layer_builder = require("./annotation_layer_builder.js");
|
34
34
|
|
35
35
|
var _pdf = require("../pdf");
|
36
36
|
|
37
|
-
var _pdf_page_view = require("./pdf_page_view");
|
37
|
+
var _pdf_page_view = require("./pdf_page_view.js");
|
38
38
|
|
39
|
-
var _pdf_link_service = require("./pdf_link_service");
|
39
|
+
var _pdf_link_service = require("./pdf_link_service.js");
|
40
40
|
|
41
|
-
var _text_layer_builder = require("./text_layer_builder");
|
41
|
+
var _text_layer_builder = require("./text_layer_builder.js");
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
46
|
-
|
47
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
48
|
-
|
49
|
-
var DEFAULT_CACHE_SIZE = 10;
|
43
|
+
const DEFAULT_CACHE_SIZE = 10;
|
50
44
|
|
51
45
|
function PDFPageViewBuffer(size) {
|
52
|
-
|
46
|
+
const data = [];
|
53
47
|
|
54
48
|
this.push = function (view) {
|
55
|
-
|
49
|
+
const i = data.indexOf(view);
|
56
50
|
|
57
51
|
if (i >= 0) {
|
58
52
|
data.splice(i, 1);
|
@@ -69,9 +63,9 @@ function PDFPageViewBuffer(size) {
|
|
69
63
|
size = newSize;
|
70
64
|
|
71
65
|
if (pagesToKeep) {
|
72
|
-
|
66
|
+
const pageIdsToKeep = new Set();
|
73
67
|
|
74
|
-
for (
|
68
|
+
for (let i = 0, iMax = pagesToKeep.length; i < iMax; ++i) {
|
75
69
|
pageIdsToKeep.add(pagesToKeep[i].id);
|
76
70
|
}
|
77
71
|
|
@@ -98,16 +92,10 @@ function isSameScale(oldScale, newScale) {
|
|
98
92
|
return false;
|
99
93
|
}
|
100
94
|
|
101
|
-
|
102
|
-
|
103
|
-
function () {
|
104
|
-
function BaseViewer(options) {
|
105
|
-
var _this = this;
|
106
|
-
|
107
|
-
_classCallCheck(this, BaseViewer);
|
108
|
-
|
95
|
+
class BaseViewer {
|
96
|
+
constructor(options) {
|
109
97
|
if (this.constructor === BaseViewer) {
|
110
|
-
throw new Error(
|
98
|
+
throw new Error("Cannot initialize BaseViewer.");
|
111
99
|
}
|
112
100
|
|
113
101
|
this._name = this.constructor.name;
|
@@ -119,7 +107,7 @@ function () {
|
|
119
107
|
this.findController = options.findController || null;
|
120
108
|
this.removePageBorders = options.removePageBorders || false;
|
121
109
|
this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
|
122
|
-
this.imageResourcesPath = options.imageResourcesPath ||
|
110
|
+
this.imageResourcesPath = options.imageResourcesPath || "";
|
123
111
|
this.renderInteractiveForms = options.renderInteractiveForms || false;
|
124
112
|
this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
|
125
113
|
this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
|
@@ -143,1031 +131,997 @@ function () {
|
|
143
131
|
this._resetView();
|
144
132
|
|
145
133
|
if (this.removePageBorders) {
|
146
|
-
this.viewer.classList.add(
|
134
|
+
this.viewer.classList.add("removePageBorders");
|
147
135
|
}
|
148
136
|
|
149
|
-
Promise.resolve().then(
|
150
|
-
|
151
|
-
source:
|
137
|
+
Promise.resolve().then(() => {
|
138
|
+
this.eventBus.dispatch("baseviewerinit", {
|
139
|
+
source: this
|
152
140
|
});
|
153
141
|
});
|
154
142
|
}
|
155
143
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
144
|
+
get pagesCount() {
|
145
|
+
return this._pages.length;
|
146
|
+
}
|
147
|
+
|
148
|
+
getPageView(index) {
|
149
|
+
return this._pages[index];
|
150
|
+
}
|
151
|
+
|
152
|
+
get pageViewsReady() {
|
153
|
+
if (!this._pagesCapability.settled) {
|
154
|
+
return false;
|
160
155
|
}
|
161
|
-
}, {
|
162
|
-
key: "_setCurrentPageNumber",
|
163
|
-
value: function _setCurrentPageNumber(val) {
|
164
|
-
var resetCurrentPageView = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
165
156
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
157
|
+
return this._pages.every(function (pageView) {
|
158
|
+
return pageView && pageView.pdfPage;
|
159
|
+
});
|
160
|
+
}
|
170
161
|
|
171
|
-
|
172
|
-
|
162
|
+
get currentPageNumber() {
|
163
|
+
return this._currentPageNumber;
|
164
|
+
}
|
173
165
|
|
174
|
-
|
175
|
-
|
176
|
-
|
166
|
+
set currentPageNumber(val) {
|
167
|
+
if (!Number.isInteger(val)) {
|
168
|
+
throw new Error("Invalid page number.");
|
169
|
+
}
|
177
170
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
});
|
171
|
+
if (!this.pdfDocument) {
|
172
|
+
return;
|
173
|
+
}
|
174
|
+
|
175
|
+
if (!this._setCurrentPageNumber(val, true)) {
|
176
|
+
console.error(`${this._name}.currentPageNumber: "${val}" is not a valid page.`);
|
177
|
+
}
|
178
|
+
}
|
184
179
|
|
180
|
+
_setCurrentPageNumber(val, resetCurrentPageView = false) {
|
181
|
+
if (this._currentPageNumber === val) {
|
185
182
|
if (resetCurrentPageView) {
|
186
183
|
this._resetCurrentPageView();
|
187
184
|
}
|
188
185
|
|
189
186
|
return true;
|
190
187
|
}
|
191
|
-
}, {
|
192
|
-
key: "setDocument",
|
193
|
-
value: function setDocument(pdfDocument) {
|
194
|
-
var _this2 = this;
|
195
188
|
|
196
|
-
|
197
|
-
|
189
|
+
if (!(0 < val && val <= this.pagesCount)) {
|
190
|
+
return false;
|
191
|
+
}
|
198
192
|
|
199
|
-
|
193
|
+
this._currentPageNumber = val;
|
194
|
+
this.eventBus.dispatch("pagechanging", {
|
195
|
+
source: this,
|
196
|
+
pageNumber: val,
|
197
|
+
pageLabel: this._pageLabels && this._pageLabels[val - 1]
|
198
|
+
});
|
200
199
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
200
|
+
if (resetCurrentPageView) {
|
201
|
+
this._resetCurrentPageView();
|
202
|
+
}
|
203
|
+
|
204
|
+
return true;
|
205
|
+
}
|
205
206
|
|
206
|
-
|
207
|
+
get currentPageLabel() {
|
208
|
+
return this._pageLabels && this._pageLabels[this._currentPageNumber - 1];
|
209
|
+
}
|
207
210
|
|
208
|
-
|
209
|
-
|
211
|
+
set currentPageLabel(val) {
|
212
|
+
if (!this.pdfDocument) {
|
213
|
+
return;
|
214
|
+
}
|
215
|
+
|
216
|
+
let page = val | 0;
|
217
|
+
|
218
|
+
if (this._pageLabels) {
|
219
|
+
const i = this._pageLabels.indexOf(val);
|
220
|
+
|
221
|
+
if (i >= 0) {
|
222
|
+
page = i + 1;
|
210
223
|
}
|
224
|
+
}
|
211
225
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
_this2._pageViewsReady = true;
|
226
|
+
if (!this._setCurrentPageNumber(page, true)) {
|
227
|
+
console.error(`${this._name}.currentPageLabel: "${val}" is not a valid page.`);
|
228
|
+
}
|
229
|
+
}
|
217
230
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
});
|
222
|
-
});
|
223
|
-
var onePageRenderedCapability = (0, _pdf.createPromiseCapability)();
|
224
|
-
this.onePageRendered = onePageRenderedCapability.promise;
|
225
|
-
var firstPagePromise = pdfDocument.getPage(1);
|
226
|
-
this.firstPagePromise = firstPagePromise;
|
231
|
+
get currentScale() {
|
232
|
+
return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
|
233
|
+
}
|
227
234
|
|
228
|
-
|
229
|
-
|
235
|
+
set currentScale(val) {
|
236
|
+
if (isNaN(val)) {
|
237
|
+
throw new Error("Invalid numeric scale.");
|
238
|
+
}
|
230
239
|
|
231
|
-
|
232
|
-
|
233
|
-
|
240
|
+
if (!this.pdfDocument) {
|
241
|
+
return;
|
242
|
+
}
|
234
243
|
|
235
|
-
|
236
|
-
|
244
|
+
this._setScale(val, false);
|
245
|
+
}
|
237
246
|
|
238
|
-
|
247
|
+
get currentScaleValue() {
|
248
|
+
return this._currentScaleValue;
|
249
|
+
}
|
239
250
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
251
|
+
set currentScaleValue(val) {
|
252
|
+
if (!this.pdfDocument) {
|
253
|
+
return;
|
254
|
+
}
|
244
255
|
|
245
|
-
|
256
|
+
this._setScale(val, false);
|
257
|
+
}
|
246
258
|
|
247
|
-
|
259
|
+
get pagesRotation() {
|
260
|
+
return this._pagesRotation;
|
261
|
+
}
|
248
262
|
|
249
|
-
|
250
|
-
|
263
|
+
set pagesRotation(rotation) {
|
264
|
+
if (!(0, _ui_utils.isValidRotation)(rotation)) {
|
265
|
+
throw new Error("Invalid pages rotation angle.");
|
266
|
+
}
|
251
267
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
var viewport = pdfPage.getViewport({
|
256
|
-
scale: scale * _ui_utils.CSS_UNITS
|
257
|
-
});
|
268
|
+
if (!this.pdfDocument) {
|
269
|
+
return;
|
270
|
+
}
|
258
271
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
if (_this2.textLayerMode !== _ui_utils.TextLayerMode.DISABLE) {
|
263
|
-
textLayerFactory = _this2;
|
264
|
-
}
|
265
|
-
|
266
|
-
var pageView = new _pdf_page_view.PDFPageView({
|
267
|
-
container: _this2._setDocumentViewerElement,
|
268
|
-
eventBus: _this2.eventBus,
|
269
|
-
id: pageNum,
|
270
|
-
scale: scale,
|
271
|
-
defaultViewport: viewport.clone(),
|
272
|
-
renderingQueue: _this2.renderingQueue,
|
273
|
-
textLayerFactory: textLayerFactory,
|
274
|
-
textLayerMode: _this2.textLayerMode,
|
275
|
-
annotationLayerFactory: _this2,
|
276
|
-
imageResourcesPath: _this2.imageResourcesPath,
|
277
|
-
renderInteractiveForms: _this2.renderInteractiveForms,
|
278
|
-
renderer: _this2.renderer,
|
279
|
-
enableWebGL: _this2.enableWebGL,
|
280
|
-
useOnlyCssZoom: _this2.useOnlyCssZoom,
|
281
|
-
maxCanvasPixels: _this2.maxCanvasPixels,
|
282
|
-
l10n: _this2.l10n
|
283
|
-
});
|
272
|
+
if (this._pagesRotation === rotation) {
|
273
|
+
return;
|
274
|
+
}
|
284
275
|
|
285
|
-
|
286
|
-
|
276
|
+
this._pagesRotation = rotation;
|
277
|
+
const pageNumber = this._currentPageNumber;
|
287
278
|
|
288
|
-
|
289
|
-
|
290
|
-
|
279
|
+
for (let i = 0, ii = this._pages.length; i < ii; i++) {
|
280
|
+
const pageView = this._pages[i];
|
281
|
+
pageView.update(pageView.scale, rotation);
|
282
|
+
}
|
283
|
+
|
284
|
+
if (this._currentScaleValue) {
|
285
|
+
this._setScale(this._currentScaleValue, true);
|
286
|
+
}
|
287
|
+
|
288
|
+
this.eventBus.dispatch("rotationchanging", {
|
289
|
+
source: this,
|
290
|
+
pagesRotation: rotation,
|
291
|
+
pageNumber
|
292
|
+
});
|
293
|
+
|
294
|
+
if (this.defaultRenderingQueue) {
|
295
|
+
this.update();
|
296
|
+
}
|
297
|
+
}
|
291
298
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
}
|
299
|
+
get firstPagePromise() {
|
300
|
+
return this.pdfDocument ? this._firstPageCapability.promise : null;
|
301
|
+
}
|
296
302
|
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
}
|
303
|
+
get onePageRendered() {
|
304
|
+
return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
|
305
|
+
}
|
301
306
|
|
302
|
-
|
307
|
+
get pagesPromise() {
|
308
|
+
return this.pdfDocument ? this._pagesCapability.promise : null;
|
309
|
+
}
|
303
310
|
|
304
|
-
|
305
|
-
|
306
|
-
|
311
|
+
get _setDocumentViewerElement() {
|
312
|
+
throw new Error("Not implemented: _setDocumentViewerElement");
|
313
|
+
}
|
307
314
|
|
308
|
-
|
309
|
-
|
310
|
-
|
315
|
+
setDocument(pdfDocument) {
|
316
|
+
if (this.pdfDocument) {
|
317
|
+
this._cancelRendering();
|
311
318
|
|
312
|
-
|
319
|
+
this._resetView();
|
313
320
|
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
console.error("Unable to get page ".concat(_pageNum, " to initialize viewer"), reason);
|
321
|
+
if (this.findController) {
|
322
|
+
this.findController.setDocument(null);
|
323
|
+
}
|
324
|
+
}
|
319
325
|
|
320
|
-
|
321
|
-
pagesCapability.resolve();
|
322
|
-
}
|
323
|
-
});
|
324
|
-
};
|
326
|
+
this.pdfDocument = pdfDocument;
|
325
327
|
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
});
|
328
|
+
if (!pdfDocument) {
|
329
|
+
return;
|
330
|
+
}
|
330
331
|
|
331
|
-
|
332
|
-
|
333
|
-
});
|
332
|
+
const pagesCount = pdfDocument.numPages;
|
333
|
+
const firstPagePromise = pdfDocument.getPage(1);
|
334
334
|
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
console.error('Unable to initialize viewer', reason);
|
335
|
+
this._pagesCapability.promise.then(() => {
|
336
|
+
this.eventBus.dispatch("pagesloaded", {
|
337
|
+
source: this,
|
338
|
+
pagesCount
|
340
339
|
});
|
341
|
-
}
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
340
|
+
});
|
341
|
+
|
342
|
+
this._onBeforeDraw = evt => {
|
343
|
+
const pageView = this._pages[evt.pageNumber - 1];
|
344
|
+
|
345
|
+
if (!pageView) {
|
346
346
|
return;
|
347
347
|
}
|
348
348
|
|
349
|
-
|
350
|
-
|
351
|
-
} else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
|
352
|
-
this._pageLabels = null;
|
353
|
-
console.error("".concat(this._name, ".setPageLabels: Invalid page labels."));
|
354
|
-
} else {
|
355
|
-
this._pageLabels = labels;
|
356
|
-
}
|
349
|
+
this._buffer.push(pageView);
|
350
|
+
};
|
357
351
|
|
358
|
-
|
359
|
-
var pageView = this._pages[i];
|
360
|
-
var label = this._pageLabels && this._pageLabels[i];
|
361
|
-
pageView.setPageLabel(label);
|
362
|
-
}
|
363
|
-
}
|
364
|
-
}, {
|
365
|
-
key: "_resetView",
|
366
|
-
value: function _resetView() {
|
367
|
-
this._pages = [];
|
368
|
-
this._currentPageNumber = 1;
|
369
|
-
this._currentScale = _ui_utils.UNKNOWN_SCALE;
|
370
|
-
this._currentScaleValue = null;
|
371
|
-
this._pageLabels = null;
|
372
|
-
this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
|
373
|
-
this._location = null;
|
374
|
-
this._pagesRotation = 0;
|
375
|
-
this._pagesRequests = [];
|
376
|
-
this._pageViewsReady = false;
|
377
|
-
this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
|
378
|
-
this._spreadMode = _ui_utils.SpreadMode.NONE;
|
379
|
-
|
380
|
-
if (this._onBeforeDraw) {
|
381
|
-
this.eventBus.off('pagerender', this._onBeforeDraw);
|
382
|
-
this._onBeforeDraw = null;
|
383
|
-
}
|
352
|
+
this.eventBus._on("pagerender", this._onBeforeDraw);
|
384
353
|
|
385
|
-
|
386
|
-
|
387
|
-
|
354
|
+
this._onAfterDraw = evt => {
|
355
|
+
if (evt.cssTransform || this._onePageRenderedCapability.settled) {
|
356
|
+
return;
|
388
357
|
}
|
389
358
|
|
390
|
-
this.
|
359
|
+
this._onePageRenderedCapability.resolve();
|
391
360
|
|
392
|
-
this.
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
361
|
+
this.eventBus._off("pagerendered", this._onAfterDraw);
|
362
|
+
|
363
|
+
this._onAfterDraw = null;
|
364
|
+
};
|
365
|
+
|
366
|
+
this.eventBus._on("pagerendered", this._onAfterDraw);
|
367
|
+
|
368
|
+
firstPagePromise.then(firstPdfPage => {
|
369
|
+
this._firstPageCapability.resolve(firstPdfPage);
|
370
|
+
|
371
|
+
const scale = this.currentScale;
|
372
|
+
const viewport = firstPdfPage.getViewport({
|
373
|
+
scale: scale * _ui_utils.CSS_UNITS
|
374
|
+
});
|
375
|
+
const textLayerFactory = this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE ? this : null;
|
376
|
+
|
377
|
+
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
|
378
|
+
const pageView = new _pdf_page_view.PDFPageView({
|
379
|
+
container: this._setDocumentViewerElement,
|
380
|
+
eventBus: this.eventBus,
|
381
|
+
id: pageNum,
|
382
|
+
scale,
|
383
|
+
defaultViewport: viewport.clone(),
|
384
|
+
renderingQueue: this.renderingQueue,
|
385
|
+
textLayerFactory,
|
386
|
+
textLayerMode: this.textLayerMode,
|
387
|
+
annotationLayerFactory: this,
|
388
|
+
imageResourcesPath: this.imageResourcesPath,
|
389
|
+
renderInteractiveForms: this.renderInteractiveForms,
|
390
|
+
renderer: this.renderer,
|
391
|
+
enableWebGL: this.enableWebGL,
|
392
|
+
useOnlyCssZoom: this.useOnlyCssZoom,
|
393
|
+
maxCanvasPixels: this.maxCanvasPixels,
|
394
|
+
l10n: this.l10n
|
395
|
+
});
|
396
|
+
|
397
|
+
this._pages.push(pageView);
|
399
398
|
}
|
400
399
|
|
401
|
-
this.
|
402
|
-
}
|
403
|
-
}, {
|
404
|
-
key: "_scrollIntoView",
|
405
|
-
value: function _scrollIntoView(_ref) {
|
406
|
-
var pageDiv = _ref.pageDiv,
|
407
|
-
_ref$pageSpot = _ref.pageSpot,
|
408
|
-
pageSpot = _ref$pageSpot === void 0 ? null : _ref$pageSpot,
|
409
|
-
_ref$pageNumber = _ref.pageNumber,
|
410
|
-
pageNumber = _ref$pageNumber === void 0 ? null : _ref$pageNumber;
|
411
|
-
(0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
|
412
|
-
}
|
413
|
-
}, {
|
414
|
-
key: "_setScaleUpdatePages",
|
415
|
-
value: function _setScaleUpdatePages(newScale, newValue) {
|
416
|
-
var noScroll = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
417
|
-
var preset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
418
|
-
this._currentScaleValue = newValue.toString();
|
419
|
-
|
420
|
-
if (isSameScale(this._currentScale, newScale)) {
|
421
|
-
if (preset) {
|
422
|
-
this.eventBus.dispatch('scalechanging', {
|
423
|
-
source: this,
|
424
|
-
scale: newScale,
|
425
|
-
presetValue: newValue
|
426
|
-
});
|
427
|
-
}
|
400
|
+
const firstPageView = this._pages[0];
|
428
401
|
|
429
|
-
|
402
|
+
if (firstPageView) {
|
403
|
+
firstPageView.setPdfPage(firstPdfPage);
|
404
|
+
this.linkService.cachePageRef(1, firstPdfPage.ref);
|
430
405
|
}
|
431
406
|
|
432
|
-
|
433
|
-
this.
|
407
|
+
if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
|
408
|
+
this._updateSpreadMode();
|
434
409
|
}
|
435
410
|
|
436
|
-
this.
|
411
|
+
this._onePageRenderedCapability.promise.then(() => {
|
412
|
+
if (this.findController) {
|
413
|
+
this.findController.setDocument(pdfDocument);
|
414
|
+
}
|
437
415
|
|
438
|
-
|
439
|
-
|
440
|
-
dest;
|
416
|
+
if (pdfDocument.loadingParams["disableAutoFetch"] || pagesCount > 7500) {
|
417
|
+
this._pagesCapability.resolve();
|
441
418
|
|
442
|
-
|
443
|
-
page = this._location.pageNumber;
|
444
|
-
dest = [null, {
|
445
|
-
name: 'XYZ'
|
446
|
-
}, this._location.left, this._location.top, null];
|
419
|
+
return;
|
447
420
|
}
|
448
421
|
|
449
|
-
|
450
|
-
pageNumber: page,
|
451
|
-
destArray: dest,
|
452
|
-
allowNegativeOffset: true
|
453
|
-
});
|
454
|
-
}
|
422
|
+
let getPagesLeft = pagesCount - 1;
|
455
423
|
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
424
|
+
if (getPagesLeft <= 0) {
|
425
|
+
this._pagesCapability.resolve();
|
426
|
+
|
427
|
+
return;
|
428
|
+
}
|
429
|
+
|
430
|
+
for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
|
431
|
+
pdfDocument.getPage(pageNum).then(pdfPage => {
|
432
|
+
const pageView = this._pages[pageNum - 1];
|
433
|
+
|
434
|
+
if (!pageView.pdfPage) {
|
435
|
+
pageView.setPdfPage(pdfPage);
|
436
|
+
}
|
437
|
+
|
438
|
+
this.linkService.cachePageRef(pageNum, pdfPage.ref);
|
439
|
+
|
440
|
+
if (--getPagesLeft === 0) {
|
441
|
+
this._pagesCapability.resolve();
|
442
|
+
}
|
443
|
+
}, reason => {
|
444
|
+
console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
|
445
|
+
|
446
|
+
if (--getPagesLeft === 0) {
|
447
|
+
this._pagesCapability.resolve();
|
448
|
+
}
|
449
|
+
});
|
450
|
+
}
|
451
|
+
});
|
452
|
+
|
453
|
+
this.eventBus.dispatch("pagesinit", {
|
454
|
+
source: this
|
460
455
|
});
|
461
456
|
|
462
457
|
if (this.defaultRenderingQueue) {
|
463
458
|
this.update();
|
464
459
|
}
|
460
|
+
}).catch(reason => {
|
461
|
+
console.error("Unable to initialize viewer", reason);
|
462
|
+
});
|
463
|
+
}
|
464
|
+
|
465
|
+
setPageLabels(labels) {
|
466
|
+
if (!this.pdfDocument) {
|
467
|
+
return;
|
465
468
|
}
|
466
|
-
}, {
|
467
|
-
key: "_setScale",
|
468
|
-
value: function _setScale(value) {
|
469
|
-
var noScroll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
470
|
-
var scale = parseFloat(value);
|
471
469
|
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
470
|
+
if (!labels) {
|
471
|
+
this._pageLabels = null;
|
472
|
+
} else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
|
473
|
+
this._pageLabels = null;
|
474
|
+
console.error(`${this._name}.setPageLabels: Invalid page labels.`);
|
475
|
+
} else {
|
476
|
+
this._pageLabels = labels;
|
477
|
+
}
|
476
478
|
|
477
|
-
|
478
|
-
|
479
|
-
|
479
|
+
for (let i = 0, ii = this._pages.length; i < ii; i++) {
|
480
|
+
const pageView = this._pages[i];
|
481
|
+
const label = this._pageLabels && this._pageLabels[i];
|
482
|
+
pageView.setPageLabel(label);
|
483
|
+
}
|
484
|
+
}
|
480
485
|
|
481
|
-
|
482
|
-
|
483
|
-
|
486
|
+
_resetView() {
|
487
|
+
this._pages = [];
|
488
|
+
this._currentPageNumber = 1;
|
489
|
+
this._currentScale = _ui_utils.UNKNOWN_SCALE;
|
490
|
+
this._currentScaleValue = null;
|
491
|
+
this._pageLabels = null;
|
492
|
+
this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
|
493
|
+
this._location = null;
|
494
|
+
this._pagesRotation = 0;
|
495
|
+
this._pagesRequests = new WeakMap();
|
496
|
+
this._firstPageCapability = (0, _pdf.createPromiseCapability)();
|
497
|
+
this._onePageRenderedCapability = (0, _pdf.createPromiseCapability)();
|
498
|
+
this._pagesCapability = (0, _pdf.createPromiseCapability)();
|
499
|
+
this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
|
500
|
+
this._spreadMode = _ui_utils.SpreadMode.NONE;
|
501
|
+
|
502
|
+
if (this._onBeforeDraw) {
|
503
|
+
this.eventBus._off("pagerender", this._onBeforeDraw);
|
504
|
+
|
505
|
+
this._onBeforeDraw = null;
|
506
|
+
}
|
484
507
|
|
485
|
-
|
486
|
-
|
487
|
-
hPadding = _ref2[0];
|
488
|
-
vPadding = _ref2[1];
|
489
|
-
}
|
508
|
+
if (this._onAfterDraw) {
|
509
|
+
this.eventBus._off("pagerendered", this._onAfterDraw);
|
490
510
|
|
491
|
-
|
492
|
-
|
511
|
+
this._onAfterDraw = null;
|
512
|
+
}
|
493
513
|
|
494
|
-
|
495
|
-
case 'page-actual':
|
496
|
-
scale = 1;
|
497
|
-
break;
|
514
|
+
this.viewer.textContent = "";
|
498
515
|
|
499
|
-
|
500
|
-
|
501
|
-
break;
|
516
|
+
this._updateScrollMode();
|
517
|
+
}
|
502
518
|
|
503
|
-
|
504
|
-
|
505
|
-
|
519
|
+
_scrollUpdate() {
|
520
|
+
if (this.pagesCount === 0) {
|
521
|
+
return;
|
522
|
+
}
|
506
523
|
|
507
|
-
|
508
|
-
|
509
|
-
break;
|
524
|
+
this.update();
|
525
|
+
}
|
510
526
|
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
527
|
+
_scrollIntoView({
|
528
|
+
pageDiv,
|
529
|
+
pageSpot = null,
|
530
|
+
pageNumber = null
|
531
|
+
}) {
|
532
|
+
(0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
|
533
|
+
}
|
515
534
|
|
516
|
-
|
517
|
-
|
518
|
-
return;
|
519
|
-
}
|
535
|
+
_setScaleUpdatePages(newScale, newValue, noScroll = false, preset = false) {
|
536
|
+
this._currentScaleValue = newValue.toString();
|
520
537
|
|
521
|
-
|
538
|
+
if (isSameScale(this._currentScale, newScale)) {
|
539
|
+
if (preset) {
|
540
|
+
this.eventBus.dispatch("scalechanging", {
|
541
|
+
source: this,
|
542
|
+
scale: newScale,
|
543
|
+
presetValue: newValue
|
544
|
+
});
|
522
545
|
}
|
546
|
+
|
547
|
+
return;
|
548
|
+
}
|
549
|
+
|
550
|
+
for (let i = 0, ii = this._pages.length; i < ii; i++) {
|
551
|
+
this._pages[i].update(newScale);
|
523
552
|
}
|
524
|
-
}, {
|
525
|
-
key: "_resetCurrentPageView",
|
526
|
-
value: function _resetCurrentPageView() {
|
527
|
-
if (this.isInPresentationMode) {
|
528
|
-
this._setScale(this._currentScaleValue, true);
|
529
|
-
}
|
530
553
|
|
531
|
-
|
554
|
+
this._currentScale = newScale;
|
532
555
|
|
533
|
-
|
534
|
-
|
556
|
+
if (!noScroll) {
|
557
|
+
let page = this._currentPageNumber,
|
558
|
+
dest;
|
559
|
+
|
560
|
+
if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
|
561
|
+
page = this._location.pageNumber;
|
562
|
+
dest = [null, {
|
563
|
+
name: "XYZ"
|
564
|
+
}, this._location.left, this._location.top, null];
|
565
|
+
}
|
566
|
+
|
567
|
+
this.scrollPageIntoView({
|
568
|
+
pageNumber: page,
|
569
|
+
destArray: dest,
|
570
|
+
allowNegativeOffset: true
|
535
571
|
});
|
536
572
|
}
|
537
|
-
}, {
|
538
|
-
key: "scrollPageIntoView",
|
539
|
-
value: function scrollPageIntoView(_ref3) {
|
540
|
-
var pageNumber = _ref3.pageNumber,
|
541
|
-
_ref3$destArray = _ref3.destArray,
|
542
|
-
destArray = _ref3$destArray === void 0 ? null : _ref3$destArray,
|
543
|
-
_ref3$allowNegativeOf = _ref3.allowNegativeOffset,
|
544
|
-
allowNegativeOffset = _ref3$allowNegativeOf === void 0 ? false : _ref3$allowNegativeOf;
|
545
573
|
|
546
|
-
|
547
|
-
|
548
|
-
|
574
|
+
this.eventBus.dispatch("scalechanging", {
|
575
|
+
source: this,
|
576
|
+
scale: newScale,
|
577
|
+
presetValue: preset ? newValue : undefined
|
578
|
+
});
|
579
|
+
|
580
|
+
if (this.defaultRenderingQueue) {
|
581
|
+
this.update();
|
582
|
+
}
|
583
|
+
}
|
549
584
|
|
550
|
-
|
585
|
+
_setScale(value, noScroll = false) {
|
586
|
+
let scale = parseFloat(value);
|
551
587
|
|
552
|
-
|
553
|
-
|
588
|
+
if (scale > 0) {
|
589
|
+
this._setScaleUpdatePages(scale, value, noScroll, false);
|
590
|
+
} else {
|
591
|
+
const currentPage = this._pages[this._currentPageNumber - 1];
|
592
|
+
|
593
|
+
if (!currentPage) {
|
554
594
|
return;
|
555
595
|
}
|
556
596
|
|
557
|
-
|
558
|
-
|
597
|
+
const noPadding = this.isInPresentationMode || this.removePageBorders;
|
598
|
+
let hPadding = noPadding ? 0 : _ui_utils.SCROLLBAR_PADDING;
|
599
|
+
let vPadding = noPadding ? 0 : _ui_utils.VERTICAL_PADDING;
|
559
600
|
|
560
|
-
|
601
|
+
if (!noPadding && this._isScrollModeHorizontal) {
|
602
|
+
[hPadding, vPadding] = [vPadding, hPadding];
|
561
603
|
}
|
562
604
|
|
563
|
-
|
564
|
-
|
565
|
-
var width = 0,
|
566
|
-
height = 0,
|
567
|
-
widthScale,
|
568
|
-
heightScale;
|
569
|
-
var changeOrientation = pageView.rotation % 180 === 0 ? false : true;
|
570
|
-
var pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _ui_utils.CSS_UNITS;
|
571
|
-
var pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _ui_utils.CSS_UNITS;
|
572
|
-
var scale = 0;
|
573
|
-
|
574
|
-
switch (destArray[1].name) {
|
575
|
-
case 'XYZ':
|
576
|
-
x = destArray[2];
|
577
|
-
y = destArray[3];
|
578
|
-
scale = destArray[4];
|
579
|
-
x = x !== null ? x : 0;
|
580
|
-
y = y !== null ? y : pageHeight;
|
581
|
-
break;
|
605
|
+
const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale;
|
606
|
+
const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
|
582
607
|
|
583
|
-
|
584
|
-
case
|
585
|
-
scale =
|
608
|
+
switch (value) {
|
609
|
+
case "page-actual":
|
610
|
+
scale = 1;
|
586
611
|
break;
|
587
612
|
|
588
|
-
case
|
589
|
-
|
590
|
-
|
591
|
-
scale = 'page-width';
|
592
|
-
|
593
|
-
if (y === null && this._location) {
|
594
|
-
x = this._location.left;
|
595
|
-
y = this._location.top;
|
596
|
-
}
|
613
|
+
case "page-width":
|
614
|
+
scale = pageWidthScale;
|
615
|
+
break;
|
597
616
|
|
617
|
+
case "page-height":
|
618
|
+
scale = pageHeightScale;
|
598
619
|
break;
|
599
620
|
|
600
|
-
case
|
601
|
-
|
602
|
-
x = destArray[2];
|
603
|
-
width = pageWidth;
|
604
|
-
height = pageHeight;
|
605
|
-
scale = 'page-height';
|
621
|
+
case "page-fit":
|
622
|
+
scale = Math.min(pageWidthScale, pageHeightScale);
|
606
623
|
break;
|
607
624
|
|
608
|
-
case
|
609
|
-
|
610
|
-
|
611
|
-
width = destArray[4] - x;
|
612
|
-
height = destArray[5] - y;
|
613
|
-
var hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
|
614
|
-
var vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
|
615
|
-
widthScale = (this.container.clientWidth - hPadding) / width / _ui_utils.CSS_UNITS;
|
616
|
-
heightScale = (this.container.clientHeight - vPadding) / height / _ui_utils.CSS_UNITS;
|
617
|
-
scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
|
625
|
+
case "auto":
|
626
|
+
const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
|
627
|
+
scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
|
618
628
|
break;
|
619
629
|
|
620
630
|
default:
|
621
|
-
console.error(
|
631
|
+
console.error(`${this._name}._setScale: "${value}" is an unknown zoom value.`);
|
622
632
|
return;
|
623
633
|
}
|
624
634
|
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
|
629
|
-
}
|
635
|
+
this._setScaleUpdatePages(scale, value, noScroll, true);
|
636
|
+
}
|
637
|
+
}
|
630
638
|
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
});
|
639
|
+
_resetCurrentPageView() {
|
640
|
+
if (this.isInPresentationMode) {
|
641
|
+
this._setScale(this._currentScaleValue, true);
|
642
|
+
}
|
636
643
|
|
637
|
-
|
638
|
-
}
|
644
|
+
const pageView = this._pages[this._currentPageNumber - 1];
|
639
645
|
|
640
|
-
|
641
|
-
|
642
|
-
|
646
|
+
this._scrollIntoView({
|
647
|
+
pageDiv: pageView.div
|
648
|
+
});
|
649
|
+
}
|
650
|
+
|
651
|
+
scrollPageIntoView({
|
652
|
+
pageNumber,
|
653
|
+
destArray = null,
|
654
|
+
allowNegativeOffset = false,
|
655
|
+
ignoreDestinationZoom = false
|
656
|
+
}) {
|
657
|
+
if (!this.pdfDocument) {
|
658
|
+
return;
|
659
|
+
}
|
660
|
+
|
661
|
+
const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
|
662
|
+
|
663
|
+
if (!pageView) {
|
664
|
+
console.error(`${this._name}.scrollPageIntoView: ` + `"${pageNumber}" is not a valid pageNumber parameter.`);
|
665
|
+
return;
|
666
|
+
}
|
643
667
|
|
644
|
-
|
645
|
-
|
646
|
-
|
668
|
+
if (this.isInPresentationMode || !destArray) {
|
669
|
+
this._setCurrentPageNumber(pageNumber, true);
|
670
|
+
|
671
|
+
return;
|
672
|
+
}
|
673
|
+
|
674
|
+
let x = 0,
|
675
|
+
y = 0;
|
676
|
+
let width = 0,
|
677
|
+
height = 0,
|
678
|
+
widthScale,
|
679
|
+
heightScale;
|
680
|
+
const changeOrientation = pageView.rotation % 180 !== 0;
|
681
|
+
const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _ui_utils.CSS_UNITS;
|
682
|
+
const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _ui_utils.CSS_UNITS;
|
683
|
+
let scale = 0;
|
684
|
+
|
685
|
+
switch (destArray[1].name) {
|
686
|
+
case "XYZ":
|
687
|
+
x = destArray[2];
|
688
|
+
y = destArray[3];
|
689
|
+
scale = destArray[4];
|
690
|
+
x = x !== null ? x : 0;
|
691
|
+
y = y !== null ? y : pageHeight;
|
692
|
+
break;
|
693
|
+
|
694
|
+
case "Fit":
|
695
|
+
case "FitB":
|
696
|
+
scale = "page-fit";
|
697
|
+
break;
|
698
|
+
|
699
|
+
case "FitH":
|
700
|
+
case "FitBH":
|
701
|
+
y = destArray[2];
|
702
|
+
scale = "page-width";
|
703
|
+
|
704
|
+
if (y === null && this._location) {
|
705
|
+
x = this._location.left;
|
706
|
+
y = this._location.top;
|
707
|
+
}
|
708
|
+
|
709
|
+
break;
|
710
|
+
|
711
|
+
case "FitV":
|
712
|
+
case "FitBV":
|
713
|
+
x = destArray[2];
|
714
|
+
width = pageWidth;
|
715
|
+
height = pageHeight;
|
716
|
+
scale = "page-height";
|
717
|
+
break;
|
718
|
+
|
719
|
+
case "FitR":
|
720
|
+
x = destArray[2];
|
721
|
+
y = destArray[3];
|
722
|
+
width = destArray[4] - x;
|
723
|
+
height = destArray[5] - y;
|
724
|
+
const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
|
725
|
+
const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
|
726
|
+
widthScale = (this.container.clientWidth - hPadding) / width / _ui_utils.CSS_UNITS;
|
727
|
+
heightScale = (this.container.clientHeight - vPadding) / height / _ui_utils.CSS_UNITS;
|
728
|
+
scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
|
729
|
+
break;
|
730
|
+
|
731
|
+
default:
|
732
|
+
console.error(`${this._name}.scrollPageIntoView: ` + `"${destArray[1].name}" is not a valid destination type.`);
|
733
|
+
return;
|
734
|
+
}
|
735
|
+
|
736
|
+
if (!ignoreDestinationZoom) {
|
737
|
+
if (scale && scale !== this._currentScale) {
|
738
|
+
this.currentScaleValue = scale;
|
739
|
+
} else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
|
740
|
+
this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
|
647
741
|
}
|
742
|
+
}
|
648
743
|
|
744
|
+
if (scale === "page-fit" && !destArray[4]) {
|
649
745
|
this._scrollIntoView({
|
650
746
|
pageDiv: pageView.div,
|
651
|
-
|
652
|
-
left: left,
|
653
|
-
top: top
|
654
|
-
},
|
655
|
-
pageNumber: pageNumber
|
747
|
+
pageNumber
|
656
748
|
});
|
749
|
+
|
750
|
+
return;
|
657
751
|
}
|
658
|
-
}, {
|
659
|
-
key: "_updateLocation",
|
660
|
-
value: function _updateLocation(firstPage) {
|
661
|
-
var currentScale = this._currentScale;
|
662
|
-
var currentScaleValue = this._currentScaleValue;
|
663
|
-
var normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
|
664
|
-
var pageNumber = firstPage.id;
|
665
|
-
var pdfOpenParams = '#page=' + pageNumber;
|
666
|
-
pdfOpenParams += '&zoom=' + normalizedScaleValue;
|
667
|
-
var currentPageView = this._pages[pageNumber - 1];
|
668
|
-
var container = this.container;
|
669
|
-
var topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
|
670
|
-
var intLeft = Math.round(topLeft[0]);
|
671
|
-
var intTop = Math.round(topLeft[1]);
|
672
|
-
pdfOpenParams += ',' + intLeft + ',' + intTop;
|
673
|
-
this._location = {
|
674
|
-
pageNumber: pageNumber,
|
675
|
-
scale: normalizedScaleValue,
|
676
|
-
top: intTop,
|
677
|
-
left: intLeft,
|
678
|
-
rotation: this._pagesRotation,
|
679
|
-
pdfOpenParams: pdfOpenParams
|
680
|
-
};
|
681
|
-
}
|
682
|
-
}, {
|
683
|
-
key: "_updateHelper",
|
684
|
-
value: function _updateHelper(visiblePages) {
|
685
|
-
throw new Error('Not implemented: _updateHelper');
|
686
|
-
}
|
687
|
-
}, {
|
688
|
-
key: "update",
|
689
|
-
value: function update() {
|
690
|
-
var visible = this._getVisiblePages();
|
691
752
|
|
692
|
-
|
693
|
-
|
753
|
+
const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
|
754
|
+
let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
|
755
|
+
let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
|
694
756
|
|
695
|
-
|
696
|
-
|
697
|
-
|
757
|
+
if (!allowNegativeOffset) {
|
758
|
+
left = Math.max(left, 0);
|
759
|
+
top = Math.max(top, 0);
|
760
|
+
}
|
698
761
|
|
699
|
-
|
762
|
+
this._scrollIntoView({
|
763
|
+
pageDiv: pageView.div,
|
764
|
+
pageSpot: {
|
765
|
+
left,
|
766
|
+
top
|
767
|
+
},
|
768
|
+
pageNumber
|
769
|
+
});
|
770
|
+
}
|
700
771
|
|
701
|
-
|
772
|
+
_updateLocation(firstPage) {
|
773
|
+
const currentScale = this._currentScale;
|
774
|
+
const currentScaleValue = this._currentScaleValue;
|
775
|
+
const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
|
776
|
+
const pageNumber = firstPage.id;
|
777
|
+
let pdfOpenParams = "#page=" + pageNumber;
|
778
|
+
pdfOpenParams += "&zoom=" + normalizedScaleValue;
|
779
|
+
const currentPageView = this._pages[pageNumber - 1];
|
780
|
+
const container = this.container;
|
781
|
+
const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
|
782
|
+
const intLeft = Math.round(topLeft[0]);
|
783
|
+
const intTop = Math.round(topLeft[1]);
|
784
|
+
pdfOpenParams += "," + intLeft + "," + intTop;
|
785
|
+
this._location = {
|
786
|
+
pageNumber,
|
787
|
+
scale: normalizedScaleValue,
|
788
|
+
top: intTop,
|
789
|
+
left: intLeft,
|
790
|
+
rotation: this._pagesRotation,
|
791
|
+
pdfOpenParams
|
792
|
+
};
|
793
|
+
}
|
702
794
|
|
703
|
-
|
795
|
+
_updateHelper(visiblePages) {
|
796
|
+
throw new Error("Not implemented: _updateHelper");
|
797
|
+
}
|
704
798
|
|
705
|
-
|
799
|
+
update() {
|
800
|
+
const visible = this._getVisiblePages();
|
706
801
|
|
707
|
-
|
802
|
+
const visiblePages = visible.views,
|
803
|
+
numVisiblePages = visiblePages.length;
|
708
804
|
|
709
|
-
|
710
|
-
|
711
|
-
location: this._location
|
712
|
-
});
|
805
|
+
if (numVisiblePages === 0) {
|
806
|
+
return;
|
713
807
|
}
|
714
|
-
}, {
|
715
|
-
key: "containsElement",
|
716
|
-
value: function containsElement(element) {
|
717
|
-
return this.container.contains(element);
|
718
|
-
}
|
719
|
-
}, {
|
720
|
-
key: "focus",
|
721
|
-
value: function focus() {
|
722
|
-
this.container.focus();
|
723
|
-
}
|
724
|
-
}, {
|
725
|
-
key: "_getCurrentVisiblePage",
|
726
|
-
value: function _getCurrentVisiblePage() {
|
727
|
-
if (!this.pagesCount) {
|
728
|
-
return {
|
729
|
-
views: []
|
730
|
-
};
|
731
|
-
}
|
732
808
|
|
733
|
-
|
734
|
-
var element = pageView.div;
|
735
|
-
var view = {
|
736
|
-
id: pageView.id,
|
737
|
-
x: element.offsetLeft + element.clientLeft,
|
738
|
-
y: element.offsetTop + element.clientTop,
|
739
|
-
view: pageView
|
740
|
-
};
|
741
|
-
return {
|
742
|
-
first: view,
|
743
|
-
last: view,
|
744
|
-
views: [view]
|
745
|
-
};
|
746
|
-
}
|
747
|
-
}, {
|
748
|
-
key: "_getVisiblePages",
|
749
|
-
value: function _getVisiblePages() {
|
750
|
-
return (0, _ui_utils.getVisibleElements)(this.container, this._pages, true, this._isScrollModeHorizontal);
|
751
|
-
}
|
752
|
-
}, {
|
753
|
-
key: "isPageVisible",
|
754
|
-
value: function isPageVisible(pageNumber) {
|
755
|
-
if (!this.pdfDocument) {
|
756
|
-
return false;
|
757
|
-
}
|
809
|
+
const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
|
758
810
|
|
759
|
-
|
760
|
-
console.error("".concat(this._name, ".isPageVisible: \"").concat(pageNumber, "\" is out of bounds."));
|
761
|
-
return false;
|
762
|
-
}
|
811
|
+
this._buffer.resize(newCacheSize, visiblePages);
|
763
812
|
|
764
|
-
|
765
|
-
return view.id === pageNumber;
|
766
|
-
});
|
767
|
-
}
|
768
|
-
}, {
|
769
|
-
key: "cleanup",
|
770
|
-
value: function cleanup() {
|
771
|
-
for (var i = 0, ii = this._pages.length; i < ii; i++) {
|
772
|
-
if (this._pages[i] && this._pages[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
|
773
|
-
this._pages[i].reset();
|
774
|
-
}
|
775
|
-
}
|
776
|
-
}
|
777
|
-
}, {
|
778
|
-
key: "_cancelRendering",
|
779
|
-
value: function _cancelRendering() {
|
780
|
-
for (var i = 0, ii = this._pages.length; i < ii; i++) {
|
781
|
-
if (this._pages[i]) {
|
782
|
-
this._pages[i].cancelRendering();
|
783
|
-
}
|
784
|
-
}
|
785
|
-
}
|
786
|
-
}, {
|
787
|
-
key: "_ensurePdfPageLoaded",
|
788
|
-
value: function _ensurePdfPageLoaded(pageView) {
|
789
|
-
var _this3 = this;
|
813
|
+
this.renderingQueue.renderHighestPriority(visible);
|
790
814
|
|
791
|
-
|
792
|
-
return Promise.resolve(pageView.pdfPage);
|
793
|
-
}
|
815
|
+
this._updateHelper(visiblePages);
|
794
816
|
|
795
|
-
|
817
|
+
this._updateLocation(visible.first);
|
796
818
|
|
797
|
-
|
798
|
-
|
799
|
-
|
819
|
+
this.eventBus.dispatch("updateviewarea", {
|
820
|
+
source: this,
|
821
|
+
location: this._location
|
822
|
+
});
|
823
|
+
}
|
800
824
|
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
}
|
825
|
+
containsElement(element) {
|
826
|
+
return this.container.contains(element);
|
827
|
+
}
|
805
828
|
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
console.error('Unable to get page for page view', reason);
|
810
|
-
_this3._pagesRequests[pageNumber] = null;
|
811
|
-
});
|
812
|
-
this._pagesRequests[pageNumber] = promise;
|
813
|
-
return promise;
|
814
|
-
}
|
815
|
-
}, {
|
816
|
-
key: "forceRendering",
|
817
|
-
value: function forceRendering(currentlyVisiblePages) {
|
818
|
-
var _this4 = this;
|
829
|
+
focus() {
|
830
|
+
this.container.focus();
|
831
|
+
}
|
819
832
|
|
820
|
-
|
833
|
+
get _isScrollModeHorizontal() {
|
834
|
+
return this.isInPresentationMode ? false : this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL;
|
835
|
+
}
|
821
836
|
|
822
|
-
|
823
|
-
|
837
|
+
get isInPresentationMode() {
|
838
|
+
return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
|
839
|
+
}
|
824
840
|
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
});
|
841
|
+
get isChangingPresentationMode() {
|
842
|
+
return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
|
843
|
+
}
|
829
844
|
|
830
|
-
|
831
|
-
|
845
|
+
get isHorizontalScrollbarEnabled() {
|
846
|
+
return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
|
847
|
+
}
|
848
|
+
|
849
|
+
get isVerticalScrollbarEnabled() {
|
850
|
+
return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
|
851
|
+
}
|
852
|
+
|
853
|
+
_getCurrentVisiblePage() {
|
854
|
+
if (!this.pagesCount) {
|
855
|
+
return {
|
856
|
+
views: []
|
857
|
+
};
|
858
|
+
}
|
859
|
+
|
860
|
+
const pageView = this._pages[this._currentPageNumber - 1];
|
861
|
+
const element = pageView.div;
|
862
|
+
const view = {
|
863
|
+
id: pageView.id,
|
864
|
+
x: element.offsetLeft + element.clientLeft,
|
865
|
+
y: element.offsetTop + element.clientTop,
|
866
|
+
view: pageView
|
867
|
+
};
|
868
|
+
return {
|
869
|
+
first: view,
|
870
|
+
last: view,
|
871
|
+
views: [view]
|
872
|
+
};
|
873
|
+
}
|
874
|
+
|
875
|
+
_getVisiblePages() {
|
876
|
+
return (0, _ui_utils.getVisibleElements)(this.container, this._pages, true, this._isScrollModeHorizontal);
|
877
|
+
}
|
832
878
|
|
879
|
+
isPageVisible(pageNumber) {
|
880
|
+
if (!this.pdfDocument) {
|
833
881
|
return false;
|
834
882
|
}
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
return new _text_layer_builder.TextLayerBuilder({
|
840
|
-
textLayerDiv: textLayerDiv,
|
841
|
-
eventBus: this.eventBus,
|
842
|
-
pageIndex: pageIndex,
|
843
|
-
viewport: viewport,
|
844
|
-
findController: this.isInPresentationMode ? null : this.findController,
|
845
|
-
enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection
|
846
|
-
});
|
883
|
+
|
884
|
+
if (pageNumber < 1 || pageNumber > this.pagesCount) {
|
885
|
+
console.error(`${this._name}.isPageVisible: "${pageNumber}" is out of bounds.`);
|
886
|
+
return false;
|
847
887
|
}
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
linkService: this.linkService,
|
860
|
-
downloadManager: this.downloadManager,
|
861
|
-
l10n: l10n
|
862
|
-
});
|
888
|
+
|
889
|
+
return this._getVisiblePages().views.some(function (view) {
|
890
|
+
return view.id === pageNumber;
|
891
|
+
});
|
892
|
+
}
|
893
|
+
|
894
|
+
cleanup() {
|
895
|
+
for (let i = 0, ii = this._pages.length; i < ii; i++) {
|
896
|
+
if (this._pages[i] && this._pages[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
|
897
|
+
this._pages[i].reset();
|
898
|
+
}
|
863
899
|
}
|
864
|
-
}
|
865
|
-
key: "getPagesOverview",
|
866
|
-
value: function getPagesOverview() {
|
867
|
-
var pagesOverview = this._pages.map(function (pageView) {
|
868
|
-
var viewport = pageView.pdfPage.getViewport({
|
869
|
-
scale: 1
|
870
|
-
});
|
871
|
-
return {
|
872
|
-
width: viewport.width,
|
873
|
-
height: viewport.height,
|
874
|
-
rotation: viewport.rotation
|
875
|
-
};
|
876
|
-
});
|
900
|
+
}
|
877
901
|
|
878
|
-
|
879
|
-
|
902
|
+
_cancelRendering() {
|
903
|
+
for (let i = 0, ii = this._pages.length; i < ii; i++) {
|
904
|
+
if (this._pages[i]) {
|
905
|
+
this._pages[i].cancelRendering();
|
880
906
|
}
|
907
|
+
}
|
908
|
+
}
|
881
909
|
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
}
|
910
|
+
_ensurePdfPageLoaded(pageView) {
|
911
|
+
if (pageView.pdfPage) {
|
912
|
+
return Promise.resolve(pageView.pdfPage);
|
913
|
+
}
|
887
914
|
|
888
|
-
|
889
|
-
|
890
|
-
height: size.width,
|
891
|
-
rotation: (size.rotation + 90) % 360
|
892
|
-
};
|
893
|
-
});
|
915
|
+
if (this._pagesRequests.has(pageView)) {
|
916
|
+
return this._pagesRequests.get(pageView);
|
894
917
|
}
|
895
|
-
}, {
|
896
|
-
key: "_updateScrollMode",
|
897
|
-
value: function _updateScrollMode() {
|
898
|
-
var pageNumber = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
899
|
-
var scrollMode = this._scrollMode,
|
900
|
-
viewer = this.viewer;
|
901
|
-
viewer.classList.toggle('scrollHorizontal', scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
|
902
|
-
viewer.classList.toggle('scrollWrapped', scrollMode === _ui_utils.ScrollMode.WRAPPED);
|
903
918
|
|
904
|
-
|
905
|
-
|
919
|
+
const promise = this.pdfDocument.getPage(pageView.id).then(pdfPage => {
|
920
|
+
if (!pageView.pdfPage) {
|
921
|
+
pageView.setPdfPage(pdfPage);
|
906
922
|
}
|
907
923
|
|
908
|
-
|
909
|
-
this._setScale(this._currentScaleValue, true);
|
910
|
-
}
|
924
|
+
this._pagesRequests.delete(pageView);
|
911
925
|
|
912
|
-
|
926
|
+
return pdfPage;
|
927
|
+
}).catch(reason => {
|
928
|
+
console.error("Unable to get page for page view", reason);
|
913
929
|
|
914
|
-
this.
|
915
|
-
}
|
916
|
-
}, {
|
917
|
-
key: "_updateSpreadMode",
|
918
|
-
value: function _updateSpreadMode() {
|
919
|
-
var pageNumber = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
930
|
+
this._pagesRequests.delete(pageView);
|
931
|
+
});
|
920
932
|
|
921
|
-
|
922
|
-
return;
|
923
|
-
}
|
933
|
+
this._pagesRequests.set(pageView, promise);
|
924
934
|
|
925
|
-
|
926
|
-
|
927
|
-
viewer.textContent = '';
|
935
|
+
return promise;
|
936
|
+
}
|
928
937
|
|
929
|
-
|
930
|
-
|
931
|
-
viewer.appendChild(pages[i].div);
|
932
|
-
}
|
933
|
-
} else {
|
934
|
-
var parity = this._spreadMode - 1;
|
935
|
-
var spread = null;
|
936
|
-
|
937
|
-
for (var _i = 0, _iMax = pages.length; _i < _iMax; ++_i) {
|
938
|
-
if (spread === null) {
|
939
|
-
spread = document.createElement('div');
|
940
|
-
spread.className = 'spread';
|
941
|
-
viewer.appendChild(spread);
|
942
|
-
} else if (_i % 2 === parity) {
|
943
|
-
spread = spread.cloneNode(false);
|
944
|
-
viewer.appendChild(spread);
|
945
|
-
}
|
946
|
-
|
947
|
-
spread.appendChild(pages[_i].div);
|
948
|
-
}
|
949
|
-
}
|
938
|
+
forceRendering(currentlyVisiblePages) {
|
939
|
+
const visiblePages = currentlyVisiblePages || this._getVisiblePages();
|
950
940
|
|
951
|
-
|
952
|
-
|
953
|
-
}
|
941
|
+
const scrollAhead = this._isScrollModeHorizontal ? this.scroll.right : this.scroll.down;
|
942
|
+
const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead);
|
954
943
|
|
955
|
-
|
944
|
+
if (pageView) {
|
945
|
+
this._ensurePdfPageLoaded(pageView).then(() => {
|
946
|
+
this.renderingQueue.renderView(pageView);
|
947
|
+
});
|
956
948
|
|
957
|
-
|
949
|
+
return true;
|
958
950
|
}
|
959
|
-
}, {
|
960
|
-
key: "pagesCount",
|
961
|
-
get: function get() {
|
962
|
-
return this._pages.length;
|
963
|
-
}
|
964
|
-
}, {
|
965
|
-
key: "pageViewsReady",
|
966
|
-
get: function get() {
|
967
|
-
return this._pageViewsReady;
|
968
|
-
}
|
969
|
-
}, {
|
970
|
-
key: "currentPageNumber",
|
971
|
-
get: function get() {
|
972
|
-
return this._currentPageNumber;
|
973
|
-
},
|
974
|
-
set: function set(val) {
|
975
|
-
if (!Number.isInteger(val)) {
|
976
|
-
throw new Error('Invalid page number.');
|
977
|
-
}
|
978
951
|
|
979
|
-
|
980
|
-
|
981
|
-
}
|
952
|
+
return false;
|
953
|
+
}
|
982
954
|
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
}
|
992
|
-
|
993
|
-
if (!this.pdfDocument) {
|
994
|
-
return;
|
995
|
-
}
|
955
|
+
createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus) {
|
956
|
+
return new _text_layer_builder.TextLayerBuilder({
|
957
|
+
textLayerDiv,
|
958
|
+
eventBus,
|
959
|
+
pageIndex,
|
960
|
+
viewport,
|
961
|
+
findController: this.isInPresentationMode ? null : this.findController,
|
962
|
+
enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection
|
963
|
+
});
|
964
|
+
}
|
996
965
|
|
997
|
-
|
966
|
+
createAnnotationLayerBuilder(pageDiv, pdfPage, imageResourcesPath = "", renderInteractiveForms = false, l10n = _ui_utils.NullL10n) {
|
967
|
+
return new _annotation_layer_builder.AnnotationLayerBuilder({
|
968
|
+
pageDiv,
|
969
|
+
pdfPage,
|
970
|
+
imageResourcesPath,
|
971
|
+
renderInteractiveForms,
|
972
|
+
linkService: this.linkService,
|
973
|
+
downloadManager: this.downloadManager,
|
974
|
+
l10n
|
975
|
+
});
|
976
|
+
}
|
998
977
|
|
999
|
-
|
1000
|
-
|
978
|
+
get hasEqualPageSizes() {
|
979
|
+
const firstPageView = this._pages[0];
|
1001
980
|
|
1002
|
-
|
1003
|
-
|
1004
|
-
}
|
1005
|
-
}
|
981
|
+
for (let i = 1, ii = this._pages.length; i < ii; ++i) {
|
982
|
+
const pageView = this._pages[i];
|
1006
983
|
|
1007
|
-
if (
|
1008
|
-
|
984
|
+
if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
|
985
|
+
return false;
|
1009
986
|
}
|
1010
987
|
}
|
1011
|
-
}, {
|
1012
|
-
key: "currentScale",
|
1013
|
-
get: function get() {
|
1014
|
-
return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
|
1015
|
-
},
|
1016
|
-
set: function set(val) {
|
1017
|
-
if (isNaN(val)) {
|
1018
|
-
throw new Error('Invalid numeric scale.');
|
1019
|
-
}
|
1020
988
|
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
989
|
+
return true;
|
990
|
+
}
|
991
|
+
|
992
|
+
getPagesOverview() {
|
993
|
+
const pagesOverview = this._pages.map(function (pageView) {
|
994
|
+
const viewport = pageView.pdfPage.getViewport({
|
995
|
+
scale: 1
|
996
|
+
});
|
997
|
+
return {
|
998
|
+
width: viewport.width,
|
999
|
+
height: viewport.height,
|
1000
|
+
rotation: viewport.rotation
|
1001
|
+
};
|
1002
|
+
});
|
1024
1003
|
|
1025
|
-
|
1004
|
+
if (!this.enablePrintAutoRotate) {
|
1005
|
+
return pagesOverview;
|
1026
1006
|
}
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
set: function set(val) {
|
1033
|
-
if (!this.pdfDocument) {
|
1034
|
-
return;
|
1007
|
+
|
1008
|
+
const isFirstPagePortrait = (0, _ui_utils.isPortraitOrientation)(pagesOverview[0]);
|
1009
|
+
return pagesOverview.map(function (size) {
|
1010
|
+
if (isFirstPagePortrait === (0, _ui_utils.isPortraitOrientation)(size)) {
|
1011
|
+
return size;
|
1035
1012
|
}
|
1036
1013
|
|
1037
|
-
|
1014
|
+
return {
|
1015
|
+
width: size.height,
|
1016
|
+
height: size.width,
|
1017
|
+
rotation: (size.rotation + 90) % 360
|
1018
|
+
};
|
1019
|
+
});
|
1020
|
+
}
|
1021
|
+
|
1022
|
+
get scrollMode() {
|
1023
|
+
return this._scrollMode;
|
1024
|
+
}
|
1025
|
+
|
1026
|
+
set scrollMode(mode) {
|
1027
|
+
if (this._scrollMode === mode) {
|
1028
|
+
return;
|
1038
1029
|
}
|
1039
|
-
}, {
|
1040
|
-
key: "pagesRotation",
|
1041
|
-
get: function get() {
|
1042
|
-
return this._pagesRotation;
|
1043
|
-
},
|
1044
|
-
set: function set(rotation) {
|
1045
|
-
if (!(0, _ui_utils.isValidRotation)(rotation)) {
|
1046
|
-
throw new Error('Invalid pages rotation angle.');
|
1047
|
-
}
|
1048
1030
|
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1031
|
+
if (!(0, _ui_utils.isValidScrollMode)(mode)) {
|
1032
|
+
throw new Error(`Invalid scroll mode: ${mode}`);
|
1033
|
+
}
|
1052
1034
|
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1035
|
+
this._scrollMode = mode;
|
1036
|
+
this.eventBus.dispatch("scrollmodechanged", {
|
1037
|
+
source: this,
|
1038
|
+
mode
|
1039
|
+
});
|
1056
1040
|
|
1057
|
-
|
1058
|
-
|
1041
|
+
this._updateScrollMode(this._currentPageNumber);
|
1042
|
+
}
|
1059
1043
|
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1044
|
+
_updateScrollMode(pageNumber = null) {
|
1045
|
+
const scrollMode = this._scrollMode,
|
1046
|
+
viewer = this.viewer;
|
1047
|
+
viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
|
1048
|
+
viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
|
1064
1049
|
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1050
|
+
if (!this.pdfDocument || !pageNumber) {
|
1051
|
+
return;
|
1052
|
+
}
|
1068
1053
|
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
pageNumber: pageNumber
|
1073
|
-
});
|
1054
|
+
if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
|
1055
|
+
this._setScale(this._currentScaleValue, true);
|
1056
|
+
}
|
1074
1057
|
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1058
|
+
this._setCurrentPageNumber(pageNumber, true);
|
1059
|
+
|
1060
|
+
this.update();
|
1061
|
+
}
|
1062
|
+
|
1063
|
+
get spreadMode() {
|
1064
|
+
return this._spreadMode;
|
1065
|
+
}
|
1066
|
+
|
1067
|
+
set spreadMode(mode) {
|
1068
|
+
if (this._spreadMode === mode) {
|
1069
|
+
return;
|
1078
1070
|
}
|
1079
|
-
}, {
|
1080
|
-
key: "_setDocumentViewerElement",
|
1081
|
-
get: function get() {
|
1082
|
-
throw new Error('Not implemented: _setDocumentViewerElement');
|
1083
|
-
}
|
1084
|
-
}, {
|
1085
|
-
key: "_isScrollModeHorizontal",
|
1086
|
-
get: function get() {
|
1087
|
-
return this.isInPresentationMode ? false : this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL;
|
1088
|
-
}
|
1089
|
-
}, {
|
1090
|
-
key: "isInPresentationMode",
|
1091
|
-
get: function get() {
|
1092
|
-
return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
|
1093
|
-
}
|
1094
|
-
}, {
|
1095
|
-
key: "isChangingPresentationMode",
|
1096
|
-
get: function get() {
|
1097
|
-
return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
|
1098
|
-
}
|
1099
|
-
}, {
|
1100
|
-
key: "isHorizontalScrollbarEnabled",
|
1101
|
-
get: function get() {
|
1102
|
-
return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
|
1103
|
-
}
|
1104
|
-
}, {
|
1105
|
-
key: "isVerticalScrollbarEnabled",
|
1106
|
-
get: function get() {
|
1107
|
-
return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
|
1108
|
-
}
|
1109
|
-
}, {
|
1110
|
-
key: "hasEqualPageSizes",
|
1111
|
-
get: function get() {
|
1112
|
-
var firstPageView = this._pages[0];
|
1113
|
-
|
1114
|
-
for (var i = 1, ii = this._pages.length; i < ii; ++i) {
|
1115
|
-
var pageView = this._pages[i];
|
1116
|
-
|
1117
|
-
if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
|
1118
|
-
return false;
|
1119
|
-
}
|
1120
|
-
}
|
1121
1071
|
|
1122
|
-
|
1072
|
+
if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
|
1073
|
+
throw new Error(`Invalid spread mode: ${mode}`);
|
1123
1074
|
}
|
1124
|
-
}, {
|
1125
|
-
key: "scrollMode",
|
1126
|
-
get: function get() {
|
1127
|
-
return this._scrollMode;
|
1128
|
-
},
|
1129
|
-
set: function set(mode) {
|
1130
|
-
if (this._scrollMode === mode) {
|
1131
|
-
return;
|
1132
|
-
}
|
1133
1075
|
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1076
|
+
this._spreadMode = mode;
|
1077
|
+
this.eventBus.dispatch("spreadmodechanged", {
|
1078
|
+
source: this,
|
1079
|
+
mode
|
1080
|
+
});
|
1137
1081
|
|
1138
|
-
|
1139
|
-
|
1140
|
-
source: this,
|
1141
|
-
mode: mode
|
1142
|
-
});
|
1082
|
+
this._updateSpreadMode(this._currentPageNumber);
|
1083
|
+
}
|
1143
1084
|
|
1144
|
-
|
1085
|
+
_updateSpreadMode(pageNumber = null) {
|
1086
|
+
if (!this.pdfDocument) {
|
1087
|
+
return;
|
1145
1088
|
}
|
1146
|
-
}, {
|
1147
|
-
key: "spreadMode",
|
1148
|
-
get: function get() {
|
1149
|
-
return this._spreadMode;
|
1150
|
-
},
|
1151
|
-
set: function set(mode) {
|
1152
|
-
if (this._spreadMode === mode) {
|
1153
|
-
return;
|
1154
|
-
}
|
1155
1089
|
|
1156
|
-
|
1157
|
-
|
1090
|
+
const viewer = this.viewer,
|
1091
|
+
pages = this._pages;
|
1092
|
+
viewer.textContent = "";
|
1093
|
+
|
1094
|
+
if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
|
1095
|
+
for (let i = 0, iMax = pages.length; i < iMax; ++i) {
|
1096
|
+
viewer.appendChild(pages[i].div);
|
1158
1097
|
}
|
1098
|
+
} else {
|
1099
|
+
const parity = this._spreadMode - 1;
|
1100
|
+
let spread = null;
|
1101
|
+
|
1102
|
+
for (let i = 0, iMax = pages.length; i < iMax; ++i) {
|
1103
|
+
if (spread === null) {
|
1104
|
+
spread = document.createElement("div");
|
1105
|
+
spread.className = "spread";
|
1106
|
+
viewer.appendChild(spread);
|
1107
|
+
} else if (i % 2 === parity) {
|
1108
|
+
spread = spread.cloneNode(false);
|
1109
|
+
viewer.appendChild(spread);
|
1110
|
+
}
|
1159
1111
|
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
mode: mode
|
1164
|
-
});
|
1112
|
+
spread.appendChild(pages[i].div);
|
1113
|
+
}
|
1114
|
+
}
|
1165
1115
|
|
1166
|
-
|
1116
|
+
if (!pageNumber) {
|
1117
|
+
return;
|
1167
1118
|
}
|
1168
|
-
}]);
|
1169
1119
|
|
1170
|
-
|
1171
|
-
|
1120
|
+
this._setCurrentPageNumber(pageNumber, true);
|
1121
|
+
|
1122
|
+
this.update();
|
1123
|
+
}
|
1124
|
+
|
1125
|
+
}
|
1172
1126
|
|
1173
1127
|
exports.BaseViewer = BaseViewer;
|