UNPKG

66.4 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * Javascript code in this page
4 *
5 * Copyright 2017 Mozilla Foundation
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * @licend The above is the entire license notice for the
20 * Javascript code in this page
21 */
22'use strict';
23
24Object.defineProperty(exports, "__esModule", {
25 value: true
26});
27exports.PDFPrintServiceFactory = exports.DefaultExternalServices = exports.PDFViewerApplication = undefined;
28
29var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
30
31var _ui_utils = require('./ui_utils');
32
33var _pdf = require('../pdf');
34
35var _pdf_cursor_tools = require('./pdf_cursor_tools');
36
37var _pdf_rendering_queue = require('./pdf_rendering_queue');
38
39var _pdf_sidebar = require('./pdf_sidebar');
40
41var _app_options = require('./app_options');
42
43var _dom_events = require('./dom_events');
44
45var _overlay_manager = require('./overlay_manager');
46
47var _password_prompt = require('./password_prompt');
48
49var _pdf_attachment_viewer = require('./pdf_attachment_viewer');
50
51var _pdf_document_properties = require('./pdf_document_properties');
52
53var _pdf_find_bar = require('./pdf_find_bar');
54
55var _pdf_find_controller = require('./pdf_find_controller');
56
57var _pdf_history = require('./pdf_history');
58
59var _pdf_link_service = require('./pdf_link_service');
60
61var _pdf_outline_viewer = require('./pdf_outline_viewer');
62
63var _pdf_presentation_mode = require('./pdf_presentation_mode');
64
65var _pdf_sidebar_resizer = require('./pdf_sidebar_resizer');
66
67var _pdf_thumbnail_viewer = require('./pdf_thumbnail_viewer');
68
69var _pdf_viewer = require('./pdf_viewer');
70
71var _secondary_toolbar = require('./secondary_toolbar');
72
73var _toolbar = require('./toolbar');
74
75var _view_history = require('./view_history');
76
77var DEFAULT_SCALE_DELTA = 1.1;
78var DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
79var DefaultExternalServices = {
80 updateFindControlState: function updateFindControlState(data) {},
81 initPassiveLoading: function initPassiveLoading(callbacks) {},
82 fallback: function fallback(data, callback) {},
83 reportTelemetry: function reportTelemetry(data) {},
84 createDownloadManager: function createDownloadManager(options) {
85 throw new Error('Not implemented: createDownloadManager');
86 },
87 createPreferences: function createPreferences() {
88 throw new Error('Not implemented: createPreferences');
89 },
90 createL10n: function createL10n(options) {
91 throw new Error('Not implemented: createL10n');
92 },
93
94 supportsIntegratedFind: false,
95 supportsDocumentFonts: true,
96 supportsDocumentColors: true,
97 supportedMouseWheelZoomModifierKeys: {
98 ctrlKey: true,
99 metaKey: true
100 }
101};
102var PDFViewerApplication = {
103 initialBookmark: document.location.hash.substring(1),
104 initialized: false,
105 fellback: false,
106 appConfig: null,
107 pdfDocument: null,
108 pdfLoadingTask: null,
109 printService: null,
110 pdfViewer: null,
111 pdfThumbnailViewer: null,
112 pdfRenderingQueue: null,
113 pdfPresentationMode: null,
114 pdfDocumentProperties: null,
115 pdfLinkService: null,
116 pdfHistory: null,
117 pdfSidebar: null,
118 pdfSidebarResizer: null,
119 pdfOutlineViewer: null,
120 pdfAttachmentViewer: null,
121 pdfCursorTools: null,
122 store: null,
123 downloadManager: null,
124 overlayManager: null,
125 preferences: null,
126 toolbar: null,
127 secondaryToolbar: null,
128 eventBus: null,
129 l10n: null,
130 isInitialViewSet: false,
131 downloadComplete: false,
132 isViewerEmbedded: window.parent !== window,
133 url: '',
134 baseUrl: '',
135 externalServices: DefaultExternalServices,
136 _boundEvents: {},
137 contentDispositionFilename: null,
138 initialize: function initialize(appConfig) {
139 var _this = this;
140
141 this.preferences = this.externalServices.createPreferences();
142 this.appConfig = appConfig;
143 return this._readPreferences().then(function () {
144 return _this._parseHashParameters();
145 }).then(function () {
146 return _this._initializeL10n();
147 }).then(function () {
148 return _this._initializeViewerComponents();
149 }).then(function () {
150 _this.bindEvents();
151 _this.bindWindowEvents();
152 var appContainer = appConfig.appContainer || document.documentElement;
153 _this.l10n.translate(appContainer).then(function () {
154 _this.eventBus.dispatch('localized');
155 });
156 if (_this.isViewerEmbedded && _app_options.AppOptions.get('externalLinkTarget') === _pdf.LinkTarget.NONE) {
157 _app_options.AppOptions.set('externalLinkTarget', _pdf.LinkTarget.TOP);
158 }
159 _this.initialized = true;
160 });
161 },
162 _readPreferences: function _readPreferences() {
163 var preferences = this.preferences;
164
165 return Promise.all([preferences.get('enableWebGL').then(function resolved(value) {
166 _app_options.AppOptions.set('enableWebGL', value);
167 }), preferences.get('sidebarViewOnLoad').then(function resolved(value) {
168 _app_options.AppOptions.set('sidebarViewOnLoad', value);
169 }), preferences.get('cursorToolOnLoad').then(function resolved(value) {
170 _app_options.AppOptions.set('cursorToolOnLoad', value);
171 }), preferences.get('pdfBugEnabled').then(function resolved(value) {
172 _app_options.AppOptions.set('pdfBugEnabled', value);
173 }), preferences.get('showPreviousViewOnLoad').then(function resolved(value) {
174 _app_options.AppOptions.set('showPreviousViewOnLoad', value);
175 }), preferences.get('defaultZoomValue').then(function resolved(value) {
176 _app_options.AppOptions.set('defaultZoomValue', value);
177 }), preferences.get('textLayerMode').then(function resolved(value) {
178 if (_app_options.AppOptions.get('textLayerMode') === _ui_utils.TextLayerMode.DISABLE) {
179 return;
180 }
181 _app_options.AppOptions.set('textLayerMode', value);
182 }), preferences.get('disableRange').then(function resolved(value) {
183 if (_app_options.AppOptions.get('disableRange') === true) {
184 return;
185 }
186 _app_options.AppOptions.set('disableRange', value);
187 }), preferences.get('disableStream').then(function resolved(value) {
188 if (_app_options.AppOptions.get('disableStream') === true) {
189 return;
190 }
191 _app_options.AppOptions.set('disableStream', value);
192 }), preferences.get('disableAutoFetch').then(function resolved(value) {
193 _app_options.AppOptions.set('disableAutoFetch', value);
194 }), preferences.get('disableFontFace').then(function resolved(value) {
195 if (_app_options.AppOptions.get('disableFontFace') === true) {
196 return;
197 }
198 _app_options.AppOptions.set('disableFontFace', value);
199 }), preferences.get('useOnlyCssZoom').then(function resolved(value) {
200 _app_options.AppOptions.set('useOnlyCssZoom', value);
201 }), preferences.get('externalLinkTarget').then(function resolved(value) {
202 if (_app_options.AppOptions.get('externalLinkTarget') !== _pdf.LinkTarget.NONE) {
203 return;
204 }
205 _app_options.AppOptions.set('externalLinkTarget', value);
206 }), preferences.get('renderer').then(function resolved(value) {
207 _app_options.AppOptions.set('renderer', value);
208 }), preferences.get('renderInteractiveForms').then(function resolved(value) {
209 _app_options.AppOptions.set('renderInteractiveForms', value);
210 }), preferences.get('disablePageMode').then(function resolved(value) {
211 _app_options.AppOptions.set('disablePageMode', value);
212 }), preferences.get('disablePageLabels').then(function resolved(value) {
213 _app_options.AppOptions.set('disablePageLabels', value);
214 }), preferences.get('enablePrintAutoRotate').then(function resolved(value) {
215 _app_options.AppOptions.set('enablePrintAutoRotate', value);
216 })]).catch(function (reason) {});
217 },
218 _parseHashParameters: function _parseHashParameters() {
219 var appConfig = this.appConfig;
220
221 var waitOn = [];
222 if (_app_options.AppOptions.get('pdfBugEnabled')) {
223 var hash = document.location.hash.substring(1);
224 var hashParams = (0, _ui_utils.parseQueryString)(hash);
225 if ('disableworker' in hashParams && hashParams['disableworker'] === 'true') {
226 waitOn.push(loadFakeWorker());
227 }
228 if ('disablerange' in hashParams) {
229 _app_options.AppOptions.set('disableRange', hashParams['disablerange'] === 'true');
230 }
231 if ('disablestream' in hashParams) {
232 _app_options.AppOptions.set('disableStream', hashParams['disablestream'] === 'true');
233 }
234 if ('disableautofetch' in hashParams) {
235 _app_options.AppOptions.set('disableAutoFetch', hashParams['disableautofetch'] === 'true');
236 }
237 if ('disablefontface' in hashParams) {
238 _app_options.AppOptions.set('disableFontFace', hashParams['disablefontface'] === 'true');
239 }
240 if ('disablehistory' in hashParams) {
241 _app_options.AppOptions.set('disableHistory', hashParams['disablehistory'] === 'true');
242 }
243 if ('webgl' in hashParams) {
244 _app_options.AppOptions.set('enableWebGL', hashParams['webgl'] === 'true');
245 }
246 if ('useonlycsszoom' in hashParams) {
247 _app_options.AppOptions.set('useOnlyCssZoom', hashParams['useonlycsszoom'] === 'true');
248 }
249 if ('verbosity' in hashParams) {
250 _app_options.AppOptions.set('verbosity', hashParams['verbosity'] | 0);
251 }
252 if ('textlayer' in hashParams) {
253 switch (hashParams['textlayer']) {
254 case 'off':
255 _app_options.AppOptions.set('textLayerMode', _ui_utils.TextLayerMode.DISABLE);
256 break;
257 case 'visible':
258 case 'shadow':
259 case 'hover':
260 var viewer = appConfig.viewerContainer;
261 viewer.classList.add('textLayer-' + hashParams['textlayer']);
262 break;
263 }
264 }
265 if ('pdfbug' in hashParams) {
266 _app_options.AppOptions.set('pdfBug', true);
267 var enabled = hashParams['pdfbug'].split(',');
268 waitOn.push(loadAndEnablePDFBug(enabled));
269 }
270 if ('locale' in hashParams) {
271 _app_options.AppOptions.set('locale', hashParams['locale']);
272 }
273 }
274 return Promise.all(waitOn);
275 },
276 _initializeL10n: function _initializeL10n() {
277 this.l10n = this.externalServices.createL10n({ locale: _app_options.AppOptions.get('locale') });
278 return this.l10n.getDirection().then(function (dir) {
279 document.getElementsByTagName('html')[0].dir = dir;
280 });
281 },
282 _initializeViewerComponents: function _initializeViewerComponents() {
283 var _this2 = this;
284
285 var appConfig = this.appConfig;
286
287 return new Promise(function (resolve, reject) {
288 _this2.overlayManager = new _overlay_manager.OverlayManager();
289 var eventBus = appConfig.eventBus || (0, _dom_events.getGlobalEventBus)();
290 _this2.eventBus = eventBus;
291 var pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
292 pdfRenderingQueue.onIdle = _this2.cleanup.bind(_this2);
293 _this2.pdfRenderingQueue = pdfRenderingQueue;
294 var pdfLinkService = new _pdf_link_service.PDFLinkService({
295 eventBus: eventBus,
296 externalLinkTarget: _app_options.AppOptions.get('externalLinkTarget'),
297 externalLinkRel: _app_options.AppOptions.get('externalLinkRel')
298 });
299 _this2.pdfLinkService = pdfLinkService;
300 var downloadManager = _this2.externalServices.createDownloadManager({ disableCreateObjectURL: _app_options.AppOptions.get('disableCreateObjectURL') });
301 _this2.downloadManager = downloadManager;
302 var container = appConfig.mainContainer;
303 var viewer = appConfig.viewerContainer;
304 _this2.pdfViewer = new _pdf_viewer.PDFViewer({
305 container: container,
306 viewer: viewer,
307 eventBus: eventBus,
308 renderingQueue: pdfRenderingQueue,
309 linkService: pdfLinkService,
310 downloadManager: downloadManager,
311 renderer: _app_options.AppOptions.get('renderer'),
312 enableWebGL: _app_options.AppOptions.get('enableWebGL'),
313 l10n: _this2.l10n,
314 textLayerMode: _app_options.AppOptions.get('textLayerMode'),
315 imageResourcesPath: _app_options.AppOptions.get('imageResourcesPath'),
316 renderInteractiveForms: _app_options.AppOptions.get('renderInteractiveForms'),
317 enablePrintAutoRotate: _app_options.AppOptions.get('enablePrintAutoRotate'),
318 useOnlyCssZoom: _app_options.AppOptions.get('useOnlyCssZoom'),
319 maxCanvasPixels: _app_options.AppOptions.get('maxCanvasPixels')
320 });
321 pdfRenderingQueue.setViewer(_this2.pdfViewer);
322 pdfLinkService.setViewer(_this2.pdfViewer);
323 var thumbnailContainer = appConfig.sidebar.thumbnailView;
324 _this2.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
325 container: thumbnailContainer,
326 renderingQueue: pdfRenderingQueue,
327 linkService: pdfLinkService,
328 l10n: _this2.l10n
329 });
330 pdfRenderingQueue.setThumbnailViewer(_this2.pdfThumbnailViewer);
331 _this2.pdfHistory = new _pdf_history.PDFHistory({
332 linkService: pdfLinkService,
333 eventBus: eventBus
334 });
335 pdfLinkService.setHistory(_this2.pdfHistory);
336 _this2.findController = new _pdf_find_controller.PDFFindController({ pdfViewer: _this2.pdfViewer });
337 _this2.findController.onUpdateResultsCount = function (matchCount) {
338 if (_this2.supportsIntegratedFind) {
339 return;
340 }
341 _this2.findBar.updateResultsCount(matchCount);
342 };
343 _this2.findController.onUpdateState = function (state, previous, matchCount) {
344 if (_this2.supportsIntegratedFind) {
345 _this2.externalServices.updateFindControlState({
346 result: state,
347 findPrevious: previous
348 });
349 } else {
350 _this2.findBar.updateUIState(state, previous, matchCount);
351 }
352 };
353 _this2.pdfViewer.setFindController(_this2.findController);
354 var findBarConfig = Object.create(appConfig.findBar);
355 findBarConfig.findController = _this2.findController;
356 findBarConfig.eventBus = eventBus;
357 _this2.findBar = new _pdf_find_bar.PDFFindBar(findBarConfig, _this2.l10n);
358 _this2.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, _this2.overlayManager, eventBus, _this2.l10n);
359 _this2.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
360 container: container,
361 eventBus: eventBus,
362 cursorToolOnLoad: _app_options.AppOptions.get('cursorToolOnLoad')
363 });
364 _this2.toolbar = new _toolbar.Toolbar(appConfig.toolbar, container, eventBus, _this2.l10n);
365 _this2.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
366 if (_this2.supportsFullscreen) {
367 _this2.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
368 container: container,
369 viewer: viewer,
370 pdfViewer: _this2.pdfViewer,
371 eventBus: eventBus,
372 contextMenuItems: appConfig.fullscreen
373 });
374 }
375 _this2.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, _this2.overlayManager, _this2.l10n);
376 _this2.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
377 container: appConfig.sidebar.outlineView,
378 eventBus: eventBus,
379 linkService: pdfLinkService
380 });
381 _this2.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
382 container: appConfig.sidebar.attachmentsView,
383 eventBus: eventBus,
384 downloadManager: downloadManager
385 });
386 var sidebarConfig = Object.create(appConfig.sidebar);
387 sidebarConfig.pdfViewer = _this2.pdfViewer;
388 sidebarConfig.pdfThumbnailViewer = _this2.pdfThumbnailViewer;
389 sidebarConfig.pdfOutlineViewer = _this2.pdfOutlineViewer;
390 sidebarConfig.eventBus = eventBus;
391 _this2.pdfSidebar = new _pdf_sidebar.PDFSidebar(sidebarConfig, _this2.l10n);
392 _this2.pdfSidebar.onToggled = _this2.forceRendering.bind(_this2);
393 _this2.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, _this2.l10n);
394 resolve(undefined);
395 });
396 },
397 run: function run(config) {
398 this.initialize(config).then(webViewerInitialized);
399 },
400 zoomIn: function zoomIn(ticks) {
401 var newScale = this.pdfViewer.currentScale;
402 do {
403 newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
404 newScale = Math.ceil(newScale * 10) / 10;
405 newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
406 } while (--ticks > 0 && newScale < _ui_utils.MAX_SCALE);
407 this.pdfViewer.currentScaleValue = newScale;
408 },
409 zoomOut: function zoomOut(ticks) {
410 var newScale = this.pdfViewer.currentScale;
411 do {
412 newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
413 newScale = Math.floor(newScale * 10) / 10;
414 newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
415 } while (--ticks > 0 && newScale > _ui_utils.MIN_SCALE);
416 this.pdfViewer.currentScaleValue = newScale;
417 },
418
419 get pagesCount() {
420 return this.pdfDocument ? this.pdfDocument.numPages : 0;
421 },
422 set page(val) {
423 this.pdfViewer.currentPageNumber = val;
424 },
425 get page() {
426 return this.pdfViewer.currentPageNumber;
427 },
428 get printing() {
429 return !!this.printService;
430 },
431 get supportsPrinting() {
432 return PDFPrintServiceFactory.instance.supportsPrinting;
433 },
434 get supportsFullscreen() {
435 var support = void 0;
436 var doc = document.documentElement;
437 support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen || doc.msRequestFullscreen);
438 if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false || document.msFullscreenEnabled === false) {
439 support = false;
440 }
441 if (support && _app_options.AppOptions.get('disableFullscreen') === true) {
442 support = false;
443 }
444 return (0, _pdf.shadow)(this, 'supportsFullscreen', support);
445 },
446 get supportsIntegratedFind() {
447 return this.externalServices.supportsIntegratedFind;
448 },
449 get supportsDocumentFonts() {
450 return this.externalServices.supportsDocumentFonts;
451 },
452 get supportsDocumentColors() {
453 return this.externalServices.supportsDocumentColors;
454 },
455 get loadingBar() {
456 var bar = new _ui_utils.ProgressBar('#loadingBar');
457 return (0, _pdf.shadow)(this, 'loadingBar', bar);
458 },
459 get supportedMouseWheelZoomModifierKeys() {
460 return this.externalServices.supportedMouseWheelZoomModifierKeys;
461 },
462 initPassiveLoading: function initPassiveLoading() {
463 throw new Error('Not implemented: initPassiveLoading');
464 },
465 setTitleUsingUrl: function setTitleUsingUrl(url) {
466 this.url = url;
467 this.baseUrl = url.split('#')[0];
468 var title = (0, _ui_utils.getPDFFileNameFromURL)(url, '');
469 if (!title) {
470 try {
471 title = decodeURIComponent((0, _pdf.getFilenameFromUrl)(url)) || url;
472 } catch (ex) {
473 title = url;
474 }
475 }
476 this.setTitle(title);
477 },
478 setTitle: function setTitle(title) {
479 if (this.isViewerEmbedded) {
480 return;
481 }
482 document.title = title;
483 },
484 close: function close() {
485 var errorWrapper = this.appConfig.errorWrapper.container;
486 errorWrapper.setAttribute('hidden', 'true');
487 if (!this.pdfLoadingTask) {
488 return Promise.resolve();
489 }
490 var promise = this.pdfLoadingTask.destroy();
491 this.pdfLoadingTask = null;
492 if (this.pdfDocument) {
493 this.pdfDocument = null;
494 this.pdfThumbnailViewer.setDocument(null);
495 this.pdfViewer.setDocument(null);
496 this.pdfLinkService.setDocument(null, null);
497 this.pdfDocumentProperties.setDocument(null, null);
498 }
499 this.store = null;
500 this.isInitialViewSet = false;
501 this.downloadComplete = false;
502 this.url = '';
503 this.baseUrl = '';
504 this.contentDispositionFilename = null;
505 this.pdfSidebar.reset();
506 this.pdfOutlineViewer.reset();
507 this.pdfAttachmentViewer.reset();
508 this.findController.reset();
509 this.findBar.reset();
510 this.toolbar.reset();
511 this.secondaryToolbar.reset();
512 if (typeof PDFBug !== 'undefined') {
513 PDFBug.cleanup();
514 }
515 return promise;
516 },
517 open: function open(file, args) {
518 var _this3 = this;
519
520 if (this.pdfLoadingTask) {
521 return this.close().then(function () {
522 _this3.preferences.reload();
523 return _this3.open(file, args);
524 });
525 }
526 var workerParameters = _app_options.AppOptions.getAll('worker');
527 for (var key in workerParameters) {
528 _pdf.GlobalWorkerOptions[key] = workerParameters[key];
529 }
530 var parameters = Object.create(null);
531 if (typeof file === 'string') {
532 this.setTitleUsingUrl(file);
533 parameters.url = file;
534 } else if (file && 'byteLength' in file) {
535 parameters.data = file;
536 } else if (file.url && file.originalUrl) {
537 this.setTitleUsingUrl(file.originalUrl);
538 parameters.url = file.url;
539 }
540 var apiParameters = _app_options.AppOptions.getAll('api');
541 for (var _key in apiParameters) {
542 parameters[_key] = apiParameters[_key];
543 }
544 if (args) {
545 for (var prop in args) {
546 if (prop === 'length') {
547 this.pdfDocumentProperties.setFileSize(args[prop]);
548 }
549 parameters[prop] = args[prop];
550 }
551 }
552 if (this.url && (0, _ui_utils.isFileSchema)(this.url)) {
553 var appConfig = this.appConfig;
554 appConfig.toolbar.download.setAttribute('hidden', 'true');
555 appConfig.secondaryToolbar.downloadButton.setAttribute('hidden', 'true');
556 }
557 var loadingTask = (0, _pdf.getDocument)(parameters);
558 this.pdfLoadingTask = loadingTask;
559 loadingTask.onPassword = function (updateCallback, reason) {
560 _this3.passwordPrompt.setUpdateCallback(updateCallback, reason);
561 _this3.passwordPrompt.open();
562 };
563 loadingTask.onProgress = function (_ref) {
564 var loaded = _ref.loaded,
565 total = _ref.total;
566
567 _this3.progress(loaded / total);
568 };
569 loadingTask.onUnsupportedFeature = this.fallback.bind(this);
570 return loadingTask.promise.then(function (pdfDocument) {
571 _this3.load(pdfDocument);
572 }, function (exception) {
573 if (loadingTask !== _this3.pdfLoadingTask) {
574 return;
575 }
576 var message = exception && exception.message;
577 var loadingErrorMessage = void 0;
578 if (exception instanceof _pdf.InvalidPDFException) {
579 loadingErrorMessage = _this3.l10n.get('invalid_file_error', null, 'Invalid or corrupted PDF file.');
580 } else if (exception instanceof _pdf.MissingPDFException) {
581 loadingErrorMessage = _this3.l10n.get('missing_file_error', null, 'Missing PDF file.');
582 } else if (exception instanceof _pdf.UnexpectedResponseException) {
583 loadingErrorMessage = _this3.l10n.get('unexpected_response_error', null, 'Unexpected server response.');
584 } else {
585 loadingErrorMessage = _this3.l10n.get('loading_error', null, 'An error occurred while loading the PDF.');
586 }
587 return loadingErrorMessage.then(function (msg) {
588 _this3.error(msg, { message: message });
589 throw new Error(msg);
590 });
591 });
592 },
593 download: function download() {
594 var _this4 = this;
595
596 function downloadByUrl() {
597 downloadManager.downloadUrl(url, filename);
598 }
599 var url = this.baseUrl;
600 var filename = this.contentDispositionFilename || (0, _ui_utils.getPDFFileNameFromURL)(this.url);
601 var downloadManager = this.downloadManager;
602 downloadManager.onerror = function (err) {
603 _this4.error('PDF failed to download: ' + err);
604 };
605 if (!this.pdfDocument || !this.downloadComplete) {
606 downloadByUrl();
607 return;
608 }
609 this.pdfDocument.getData().then(function (data) {
610 var blob = (0, _pdf.createBlob)(data, 'application/pdf');
611 downloadManager.download(blob, url, filename);
612 }).catch(downloadByUrl);
613 },
614 fallback: function fallback(featureId) {},
615 error: function error(message, moreInfo) {
616 var moreInfoText = [this.l10n.get('error_version_info', {
617 version: _pdf.version || '?',
618 build: _pdf.build || '?'
619 }, 'PDF.js v{{version}} (build: {{build}})')];
620 if (moreInfo) {
621 moreInfoText.push(this.l10n.get('error_message', { message: moreInfo.message }, 'Message: {{message}}'));
622 if (moreInfo.stack) {
623 moreInfoText.push(this.l10n.get('error_stack', { stack: moreInfo.stack }, 'Stack: {{stack}}'));
624 } else {
625 if (moreInfo.filename) {
626 moreInfoText.push(this.l10n.get('error_file', { file: moreInfo.filename }, 'File: {{file}}'));
627 }
628 if (moreInfo.lineNumber) {
629 moreInfoText.push(this.l10n.get('error_line', { line: moreInfo.lineNumber }, 'Line: {{line}}'));
630 }
631 }
632 }
633 var errorWrapperConfig = this.appConfig.errorWrapper;
634 var errorWrapper = errorWrapperConfig.container;
635 errorWrapper.removeAttribute('hidden');
636 var errorMessage = errorWrapperConfig.errorMessage;
637 errorMessage.textContent = message;
638 var closeButton = errorWrapperConfig.closeButton;
639 closeButton.onclick = function () {
640 errorWrapper.setAttribute('hidden', 'true');
641 };
642 var errorMoreInfo = errorWrapperConfig.errorMoreInfo;
643 var moreInfoButton = errorWrapperConfig.moreInfoButton;
644 var lessInfoButton = errorWrapperConfig.lessInfoButton;
645 moreInfoButton.onclick = function () {
646 errorMoreInfo.removeAttribute('hidden');
647 moreInfoButton.setAttribute('hidden', 'true');
648 lessInfoButton.removeAttribute('hidden');
649 errorMoreInfo.style.height = errorMoreInfo.scrollHeight + 'px';
650 };
651 lessInfoButton.onclick = function () {
652 errorMoreInfo.setAttribute('hidden', 'true');
653 moreInfoButton.removeAttribute('hidden');
654 lessInfoButton.setAttribute('hidden', 'true');
655 };
656 moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
657 lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
658 closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
659 moreInfoButton.removeAttribute('hidden');
660 lessInfoButton.setAttribute('hidden', 'true');
661 Promise.all(moreInfoText).then(function (parts) {
662 errorMoreInfo.value = parts.join('\n');
663 });
664 },
665 progress: function progress(level) {
666 var _this5 = this;
667
668 if (this.downloadComplete) {
669 return;
670 }
671 var percent = Math.round(level * 100);
672 if (percent > this.loadingBar.percent || isNaN(percent)) {
673 this.loadingBar.percent = percent;
674 var disableAutoFetch = this.pdfDocument ? this.pdfDocument.loadingParams['disableAutoFetch'] : _app_options.AppOptions.get('disableAutoFetch');
675 if (disableAutoFetch && percent) {
676 if (this.disableAutoFetchLoadingBarTimeout) {
677 clearTimeout(this.disableAutoFetchLoadingBarTimeout);
678 this.disableAutoFetchLoadingBarTimeout = null;
679 }
680 this.loadingBar.show();
681 this.disableAutoFetchLoadingBarTimeout = setTimeout(function () {
682 _this5.loadingBar.hide();
683 _this5.disableAutoFetchLoadingBarTimeout = null;
684 }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
685 }
686 }
687 },
688 load: function load(pdfDocument) {
689 var _this6 = this;
690
691 this.pdfDocument = pdfDocument;
692 pdfDocument.getDownloadInfo().then(function () {
693 _this6.downloadComplete = true;
694 _this6.loadingBar.hide();
695 firstPagePromise.then(function () {
696 _this6.eventBus.dispatch('documentload', { source: _this6 });
697 });
698 });
699 var pageModePromise = pdfDocument.getPageMode().catch(function () {});
700 this.toolbar.setPagesCount(pdfDocument.numPages, false);
701 this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
702 var id = this.documentFingerprint = pdfDocument.fingerprint;
703 var store = this.store = new _view_history.ViewHistory(id);
704 var baseDocumentUrl = void 0;
705 baseDocumentUrl = null;
706 this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
707 this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
708 var pdfViewer = this.pdfViewer;
709 pdfViewer.setDocument(pdfDocument);
710 var firstPagePromise = pdfViewer.firstPagePromise;
711 var pagesPromise = pdfViewer.pagesPromise;
712 var onePageRendered = pdfViewer.onePageRendered;
713 var pdfThumbnailViewer = this.pdfThumbnailViewer;
714 pdfThumbnailViewer.setDocument(pdfDocument);
715 firstPagePromise.then(function (pdfPage) {
716 _this6.loadingBar.setWidth(_this6.appConfig.viewerContainer);
717 if (!_app_options.AppOptions.get('disableHistory') && !_this6.isViewerEmbedded) {
718 var resetHistory = !_app_options.AppOptions.get('showPreviousViewOnLoad');
719 _this6.pdfHistory.initialize(id, resetHistory);
720 if (_this6.pdfHistory.initialBookmark) {
721 _this6.initialBookmark = _this6.pdfHistory.initialBookmark;
722 _this6.initialRotation = _this6.pdfHistory.initialRotation;
723 }
724 }
725 var initialParams = {
726 bookmark: null,
727 hash: null
728 };
729 var storePromise = store.getMultiple({
730 exists: false,
731 page: '1',
732 zoom: _ui_utils.DEFAULT_SCALE_VALUE,
733 scrollLeft: '0',
734 scrollTop: '0',
735 rotation: null,
736 sidebarView: _pdf_sidebar.SidebarView.NONE
737 }).catch(function () {});
738 Promise.all([storePromise, pageModePromise]).then(function (_ref2) {
739 var _ref3 = _slicedToArray(_ref2, 2),
740 _ref3$ = _ref3[0],
741 values = _ref3$ === undefined ? {} : _ref3$,
742 pageMode = _ref3[1];
743
744 var hash = _app_options.AppOptions.get('defaultZoomValue') ? 'zoom=' + _app_options.AppOptions.get('defaultZoomValue') : null;
745 var rotation = null;
746 var sidebarView = _app_options.AppOptions.get('sidebarViewOnLoad');
747 if (values.exists && _app_options.AppOptions.get('showPreviousViewOnLoad')) {
748 hash = 'page=' + values.page + '&zoom=' + (_app_options.AppOptions.get('defaultZoomValue') || values.zoom) + ',' + values.scrollLeft + ',' + values.scrollTop;
749 rotation = parseInt(values.rotation, 10);
750 sidebarView = sidebarView || values.sidebarView | 0;
751 }
752 if (pageMode && !_app_options.AppOptions.get('disablePageMode')) {
753 sidebarView = sidebarView || apiPageModeToSidebarView(pageMode);
754 }
755 return {
756 hash: hash,
757 rotation: rotation,
758 sidebarView: sidebarView
759 };
760 }).then(function (_ref4) {
761 var hash = _ref4.hash,
762 rotation = _ref4.rotation,
763 sidebarView = _ref4.sidebarView;
764
765 initialParams.bookmark = _this6.initialBookmark;
766 initialParams.hash = hash;
767 _this6.setInitialView(hash, {
768 rotation: rotation,
769 sidebarView: sidebarView
770 });
771 if (!_this6.isViewerEmbedded) {
772 pdfViewer.focus();
773 }
774 return pagesPromise;
775 }).then(function () {
776 if (!initialParams.bookmark && !initialParams.hash) {
777 return;
778 }
779 if (pdfViewer.hasEqualPageSizes) {
780 return;
781 }
782 _this6.initialBookmark = initialParams.bookmark;
783 pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
784 _this6.setInitialView(initialParams.hash);
785 }).then(function () {
786 pdfViewer.update();
787 });
788 });
789 pdfDocument.getPageLabels().then(function (labels) {
790 if (!labels || _app_options.AppOptions.get('disablePageLabels')) {
791 return;
792 }
793 var i = 0,
794 numLabels = labels.length;
795 if (numLabels !== _this6.pagesCount) {
796 console.error('The number of Page Labels does not match ' + 'the number of pages in the document.');
797 return;
798 }
799 while (i < numLabels && labels[i] === (i + 1).toString()) {
800 i++;
801 }
802 if (i === numLabels) {
803 return;
804 }
805 pdfViewer.setPageLabels(labels);
806 pdfThumbnailViewer.setPageLabels(labels);
807 _this6.toolbar.setPagesCount(pdfDocument.numPages, true);
808 _this6.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
809 });
810 pagesPromise.then(function () {
811 if (!_this6.supportsPrinting) {
812 return;
813 }
814 pdfDocument.getJavaScript().then(function (javaScript) {
815 if (!javaScript) {
816 return;
817 }
818 javaScript.some(function (js) {
819 if (!js) {
820 return false;
821 }
822 console.warn('Warning: JavaScript is not supported');
823 _this6.fallback(_pdf.UNSUPPORTED_FEATURES.javaScript);
824 return true;
825 });
826 var regex = /\bprint\s*\(/;
827 for (var i = 0, ii = javaScript.length; i < ii; i++) {
828 var js = javaScript[i];
829 if (js && regex.test(js)) {
830 setTimeout(function () {
831 window.print();
832 });
833 return;
834 }
835 }
836 });
837 });
838 Promise.all([onePageRendered, _ui_utils.animationStarted]).then(function () {
839 pdfDocument.getOutline().then(function (outline) {
840 _this6.pdfOutlineViewer.render({ outline: outline });
841 });
842 pdfDocument.getAttachments().then(function (attachments) {
843 _this6.pdfAttachmentViewer.render({ attachments: attachments });
844 });
845 });
846 pdfDocument.getMetadata().then(function (_ref5) {
847 var info = _ref5.info,
848 metadata = _ref5.metadata,
849 contentDispositionFilename = _ref5.contentDispositionFilename;
850
851 _this6.documentInfo = info;
852 _this6.metadata = metadata;
853 _this6.contentDispositionFilename = contentDispositionFilename;
854 console.log('PDF ' + pdfDocument.fingerprint + ' [' + info.PDFFormatVersion + ' ' + (info.Producer || '-').trim() + ' / ' + (info.Creator || '-').trim() + ']' + ' (PDF.js: ' + (_pdf.version || '-') + (_app_options.AppOptions.get('enableWebGL') ? ' [WebGL]' : '') + ')');
855 var pdfTitle = void 0;
856 if (metadata && metadata.has('dc:title')) {
857 var title = metadata.get('dc:title');
858 if (title !== 'Untitled') {
859 pdfTitle = title;
860 }
861 }
862 if (!pdfTitle && info && info['Title']) {
863 pdfTitle = info['Title'];
864 }
865 if (pdfTitle) {
866 _this6.setTitle(pdfTitle + ' - ' + (contentDispositionFilename || document.title));
867 } else if (contentDispositionFilename) {
868 _this6.setTitle(contentDispositionFilename);
869 }
870 if (info.IsAcroFormPresent) {
871 console.warn('Warning: AcroForm/XFA is not supported');
872 _this6.fallback(_pdf.UNSUPPORTED_FEATURES.forms);
873 }
874 });
875 },
876 setInitialView: function setInitialView(storedHash) {
877 var _this7 = this;
878
879 var _ref6 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
880 rotation = _ref6.rotation,
881 sidebarView = _ref6.sidebarView;
882
883 var setRotation = function setRotation(angle) {
884 if ((0, _ui_utils.isValidRotation)(angle)) {
885 _this7.pdfViewer.pagesRotation = angle;
886 }
887 };
888 this.isInitialViewSet = true;
889 this.pdfSidebar.setInitialView(sidebarView);
890 if (this.initialBookmark) {
891 setRotation(this.initialRotation);
892 delete this.initialRotation;
893 this.pdfLinkService.setHash(this.initialBookmark);
894 this.initialBookmark = null;
895 } else if (storedHash) {
896 setRotation(rotation);
897 this.pdfLinkService.setHash(storedHash);
898 }
899 this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
900 this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
901 if (!this.pdfViewer.currentScaleValue) {
902 this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
903 }
904 },
905 cleanup: function cleanup() {
906 if (!this.pdfDocument) {
907 return;
908 }
909 this.pdfViewer.cleanup();
910 this.pdfThumbnailViewer.cleanup();
911 if (this.pdfViewer.renderer !== _ui_utils.RendererType.SVG) {
912 this.pdfDocument.cleanup();
913 }
914 },
915 forceRendering: function forceRendering() {
916 this.pdfRenderingQueue.printing = this.printing;
917 this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
918 this.pdfRenderingQueue.renderHighestPriority();
919 },
920 beforePrint: function beforePrint() {
921 var _this8 = this;
922
923 if (this.printService) {
924 return;
925 }
926 if (!this.supportsPrinting) {
927 this.l10n.get('printing_not_supported', null, 'Warning: Printing is not fully supported by ' + 'this browser.').then(function (printMessage) {
928 _this8.error(printMessage);
929 });
930 return;
931 }
932 if (!this.pdfViewer.pageViewsReady) {
933 this.l10n.get('printing_not_ready', null, 'Warning: The PDF is not fully loaded for printing.').then(function (notReadyMessage) {
934 window.alert(notReadyMessage);
935 });
936 return;
937 }
938 var pagesOverview = this.pdfViewer.getPagesOverview();
939 var printContainer = this.appConfig.printContainer;
940 var printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, this.l10n);
941 this.printService = printService;
942 this.forceRendering();
943 printService.layout();
944 },
945
946 afterPrint: function pdfViewSetupAfterPrint() {
947 if (this.printService) {
948 this.printService.destroy();
949 this.printService = null;
950 }
951 this.forceRendering();
952 },
953 rotatePages: function rotatePages(delta) {
954 if (!this.pdfDocument) {
955 return;
956 }
957 var newRotation = (this.pdfViewer.pagesRotation + 360 + delta) % 360;
958 this.pdfViewer.pagesRotation = newRotation;
959 },
960 requestPresentationMode: function requestPresentationMode() {
961 if (!this.pdfPresentationMode) {
962 return;
963 }
964 this.pdfPresentationMode.request();
965 },
966 bindEvents: function bindEvents() {
967 var eventBus = this.eventBus,
968 _boundEvents = this._boundEvents;
969
970 _boundEvents.beforePrint = this.beforePrint.bind(this);
971 _boundEvents.afterPrint = this.afterPrint.bind(this);
972 eventBus.on('resize', webViewerResize);
973 eventBus.on('hashchange', webViewerHashchange);
974 eventBus.on('beforeprint', _boundEvents.beforePrint);
975 eventBus.on('afterprint', _boundEvents.afterPrint);
976 eventBus.on('pagerendered', webViewerPageRendered);
977 eventBus.on('textlayerrendered', webViewerTextLayerRendered);
978 eventBus.on('updateviewarea', webViewerUpdateViewarea);
979 eventBus.on('pagechanging', webViewerPageChanging);
980 eventBus.on('scalechanging', webViewerScaleChanging);
981 eventBus.on('rotationchanging', webViewerRotationChanging);
982 eventBus.on('sidebarviewchanged', webViewerSidebarViewChanged);
983 eventBus.on('pagemode', webViewerPageMode);
984 eventBus.on('namedaction', webViewerNamedAction);
985 eventBus.on('presentationmodechanged', webViewerPresentationModeChanged);
986 eventBus.on('presentationmode', webViewerPresentationMode);
987 eventBus.on('openfile', webViewerOpenFile);
988 eventBus.on('print', webViewerPrint);
989 eventBus.on('download', webViewerDownload);
990 eventBus.on('firstpage', webViewerFirstPage);
991 eventBus.on('lastpage', webViewerLastPage);
992 eventBus.on('nextpage', webViewerNextPage);
993 eventBus.on('previouspage', webViewerPreviousPage);
994 eventBus.on('zoomin', webViewerZoomIn);
995 eventBus.on('zoomout', webViewerZoomOut);
996 eventBus.on('pagenumberchanged', webViewerPageNumberChanged);
997 eventBus.on('scalechanged', webViewerScaleChanged);
998 eventBus.on('rotatecw', webViewerRotateCw);
999 eventBus.on('rotateccw', webViewerRotateCcw);
1000 eventBus.on('documentproperties', webViewerDocumentProperties);
1001 eventBus.on('find', webViewerFind);
1002 eventBus.on('findfromurlhash', webViewerFindFromUrlHash);
1003 eventBus.on('fileinputchange', webViewerFileInputChange);
1004 },
1005 bindWindowEvents: function bindWindowEvents() {
1006 var eventBus = this.eventBus,
1007 _boundEvents = this._boundEvents;
1008
1009 _boundEvents.windowResize = function () {
1010 eventBus.dispatch('resize', { source: window });
1011 };
1012 _boundEvents.windowHashChange = function () {
1013 eventBus.dispatch('hashchange', { hash: document.location.hash.substring(1) });
1014 };
1015 _boundEvents.windowBeforePrint = function () {
1016 eventBus.dispatch('beforeprint');
1017 };
1018 _boundEvents.windowAfterPrint = function () {
1019 eventBus.dispatch('afterprint');
1020 };
1021 window.addEventListener('wheel', webViewerWheel);
1022 window.addEventListener('click', webViewerClick);
1023 window.addEventListener('keydown', webViewerKeyDown);
1024 window.addEventListener('resize', _boundEvents.windowResize);
1025 window.addEventListener('hashchange', _boundEvents.windowHashChange);
1026 window.addEventListener('beforeprint', _boundEvents.windowBeforePrint);
1027 window.addEventListener('afterprint', _boundEvents.windowAfterPrint);
1028 },
1029 unbindEvents: function unbindEvents() {
1030 var eventBus = this.eventBus,
1031 _boundEvents = this._boundEvents;
1032
1033 eventBus.off('resize', webViewerResize);
1034 eventBus.off('hashchange', webViewerHashchange);
1035 eventBus.off('beforeprint', _boundEvents.beforePrint);
1036 eventBus.off('afterprint', _boundEvents.afterPrint);
1037 eventBus.off('pagerendered', webViewerPageRendered);
1038 eventBus.off('textlayerrendered', webViewerTextLayerRendered);
1039 eventBus.off('updateviewarea', webViewerUpdateViewarea);
1040 eventBus.off('pagechanging', webViewerPageChanging);
1041 eventBus.off('scalechanging', webViewerScaleChanging);
1042 eventBus.off('rotationchanging', webViewerRotationChanging);
1043 eventBus.off('sidebarviewchanged', webViewerSidebarViewChanged);
1044 eventBus.off('pagemode', webViewerPageMode);
1045 eventBus.off('namedaction', webViewerNamedAction);
1046 eventBus.off('presentationmodechanged', webViewerPresentationModeChanged);
1047 eventBus.off('presentationmode', webViewerPresentationMode);
1048 eventBus.off('openfile', webViewerOpenFile);
1049 eventBus.off('print', webViewerPrint);
1050 eventBus.off('download', webViewerDownload);
1051 eventBus.off('firstpage', webViewerFirstPage);
1052 eventBus.off('lastpage', webViewerLastPage);
1053 eventBus.off('nextpage', webViewerNextPage);
1054 eventBus.off('previouspage', webViewerPreviousPage);
1055 eventBus.off('zoomin', webViewerZoomIn);
1056 eventBus.off('zoomout', webViewerZoomOut);
1057 eventBus.off('pagenumberchanged', webViewerPageNumberChanged);
1058 eventBus.off('scalechanged', webViewerScaleChanged);
1059 eventBus.off('rotatecw', webViewerRotateCw);
1060 eventBus.off('rotateccw', webViewerRotateCcw);
1061 eventBus.off('documentproperties', webViewerDocumentProperties);
1062 eventBus.off('find', webViewerFind);
1063 eventBus.off('findfromurlhash', webViewerFindFromUrlHash);
1064 eventBus.off('fileinputchange', webViewerFileInputChange);
1065 _boundEvents.beforePrint = null;
1066 _boundEvents.afterPrint = null;
1067 },
1068 unbindWindowEvents: function unbindWindowEvents() {
1069 var _boundEvents = this._boundEvents;
1070
1071 window.removeEventListener('wheel', webViewerWheel);
1072 window.removeEventListener('click', webViewerClick);
1073 window.removeEventListener('keydown', webViewerKeyDown);
1074 window.removeEventListener('resize', _boundEvents.windowResize);
1075 window.removeEventListener('hashchange', _boundEvents.windowHashChange);
1076 window.removeEventListener('beforeprint', _boundEvents.windowBeforePrint);
1077 window.removeEventListener('afterprint', _boundEvents.windowAfterPrint);
1078 _boundEvents.windowResize = null;
1079 _boundEvents.windowHashChange = null;
1080 _boundEvents.windowBeforePrint = null;
1081 _boundEvents.windowAfterPrint = null;
1082 }
1083};
1084var validateFileURL = void 0;
1085{
1086 var HOSTED_VIEWER_ORIGINS = ['null', 'http://mozilla.github.io', 'https://mozilla.github.io'];
1087 validateFileURL = function validateFileURL(file) {
1088 if (file === undefined) {
1089 return;
1090 }
1091 try {
1092 var viewerOrigin = new URL(window.location.href).origin || 'null';
1093 if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
1094 return;
1095 }
1096
1097 var _ref7 = new URL(file, window.location.href),
1098 origin = _ref7.origin,
1099 protocol = _ref7.protocol;
1100
1101 if (origin !== viewerOrigin && protocol !== 'blob:') {
1102 throw new Error('file origin does not match viewer\'s');
1103 }
1104 } catch (ex) {
1105 var message = ex && ex.message;
1106 PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (loadingErrorMessage) {
1107 PDFViewerApplication.error(loadingErrorMessage, { message: message });
1108 });
1109 throw ex;
1110 }
1111 };
1112}
1113function loadFakeWorker() {
1114 return new Promise(function (resolve, reject) {
1115 if (!_pdf.GlobalWorkerOptions.workerSrc) {
1116 _pdf.GlobalWorkerOptions.workerSrc = _app_options.AppOptions.get('workerSrc');
1117 }
1118 var script = document.createElement('script');
1119 script.src = _pdf.PDFWorker.getWorkerSrc();
1120 script.onload = function () {
1121 resolve();
1122 };
1123 script.onerror = function () {
1124 reject(new Error('Cannot load fake worker at: ' + script.src));
1125 };
1126 (document.head || document.documentElement).appendChild(script);
1127 });
1128}
1129function loadAndEnablePDFBug(enabledTabs) {
1130 return new Promise(function (resolve, reject) {
1131 var appConfig = PDFViewerApplication.appConfig;
1132 var script = document.createElement('script');
1133 script.src = appConfig.debuggerScriptPath;
1134 script.onload = function () {
1135 PDFBug.enable(enabledTabs);
1136 PDFBug.init({ OPS: _pdf.OPS }, appConfig.mainContainer);
1137 resolve();
1138 };
1139 script.onerror = function () {
1140 reject(new Error('Cannot load debugger at ' + script.src));
1141 };
1142 (document.getElementsByTagName('head')[0] || document.body).appendChild(script);
1143 });
1144}
1145function webViewerInitialized() {
1146 var appConfig = PDFViewerApplication.appConfig;
1147 var file = void 0;
1148 var queryString = document.location.search.substring(1);
1149 var params = (0, _ui_utils.parseQueryString)(queryString);
1150 file = 'file' in params ? params.file : _app_options.AppOptions.get('defaultUrl');
1151 validateFileURL(file);
1152 var fileInput = document.createElement('input');
1153 fileInput.id = appConfig.openFileInputName;
1154 fileInput.className = 'fileInput';
1155 fileInput.setAttribute('type', 'file');
1156 fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
1157 document.body.appendChild(fileInput);
1158 if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
1159 appConfig.toolbar.openFile.setAttribute('hidden', 'true');
1160 appConfig.secondaryToolbar.openFileButton.setAttribute('hidden', 'true');
1161 } else {
1162 fileInput.value = null;
1163 }
1164 fileInput.addEventListener('change', function (evt) {
1165 var files = evt.target.files;
1166 if (!files || files.length === 0) {
1167 return;
1168 }
1169 PDFViewerApplication.eventBus.dispatch('fileinputchange', { fileInput: evt.target });
1170 });
1171 if (!PDFViewerApplication.supportsPrinting) {
1172 appConfig.toolbar.print.classList.add('hidden');
1173 appConfig.secondaryToolbar.printButton.classList.add('hidden');
1174 }
1175 if (!PDFViewerApplication.supportsFullscreen) {
1176 appConfig.toolbar.presentationModeButton.classList.add('hidden');
1177 appConfig.secondaryToolbar.presentationModeButton.classList.add('hidden');
1178 }
1179 if (PDFViewerApplication.supportsIntegratedFind) {
1180 appConfig.toolbar.viewFind.classList.add('hidden');
1181 }
1182 appConfig.mainContainer.addEventListener('transitionend', function (evt) {
1183 if (evt.target === this) {
1184 PDFViewerApplication.eventBus.dispatch('resize', { source: this });
1185 }
1186 }, true);
1187 appConfig.sidebar.toggleButton.addEventListener('click', function () {
1188 PDFViewerApplication.pdfSidebar.toggle();
1189 });
1190 Promise.resolve().then(function () {
1191 webViewerOpenFileViaURL(file);
1192 }).catch(function (reason) {
1193 PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (msg) {
1194 PDFViewerApplication.error(msg, reason);
1195 });
1196 });
1197}
1198var webViewerOpenFileViaURL = void 0;
1199{
1200 webViewerOpenFileViaURL = function webViewerOpenFileViaURL(file) {
1201 if (file && file.lastIndexOf('file:', 0) === 0) {
1202 PDFViewerApplication.setTitleUsingUrl(file);
1203 var xhr = new XMLHttpRequest();
1204 xhr.onload = function () {
1205 PDFViewerApplication.open(new Uint8Array(xhr.response));
1206 };
1207 try {
1208 xhr.open('GET', file);
1209 xhr.responseType = 'arraybuffer';
1210 xhr.send();
1211 } catch (ex) {
1212 throw ex;
1213 }
1214 return;
1215 }
1216 if (file) {
1217 PDFViewerApplication.open(file);
1218 }
1219 };
1220}
1221function webViewerPageRendered(evt) {
1222 var pageNumber = evt.pageNumber;
1223 var pageIndex = pageNumber - 1;
1224 var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
1225 if (pageNumber === PDFViewerApplication.page) {
1226 PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
1227 }
1228 if (!pageView) {
1229 return;
1230 }
1231 if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
1232 var thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageIndex);
1233 thumbnailView.setImage(pageView);
1234 }
1235 if (typeof Stats !== 'undefined' && Stats.enabled && pageView.stats) {
1236 Stats.add(pageNumber, pageView.stats);
1237 }
1238 if (pageView.error) {
1239 PDFViewerApplication.l10n.get('rendering_error', null, 'An error occurred while rendering the page.').then(function (msg) {
1240 PDFViewerApplication.error(msg, pageView.error);
1241 });
1242 }
1243}
1244function webViewerTextLayerRendered(evt) {}
1245function webViewerPageMode(evt) {
1246 var mode = evt.mode,
1247 view = void 0;
1248 switch (mode) {
1249 case 'thumbs':
1250 view = _pdf_sidebar.SidebarView.THUMBS;
1251 break;
1252 case 'bookmarks':
1253 case 'outline':
1254 view = _pdf_sidebar.SidebarView.OUTLINE;
1255 break;
1256 case 'attachments':
1257 view = _pdf_sidebar.SidebarView.ATTACHMENTS;
1258 break;
1259 case 'none':
1260 view = _pdf_sidebar.SidebarView.NONE;
1261 break;
1262 default:
1263 console.error('Invalid "pagemode" hash parameter: ' + mode);
1264 return;
1265 }
1266 PDFViewerApplication.pdfSidebar.switchView(view, true);
1267}
1268function webViewerNamedAction(evt) {
1269 var action = evt.action;
1270 switch (action) {
1271 case 'GoToPage':
1272 PDFViewerApplication.appConfig.toolbar.pageNumber.select();
1273 break;
1274 case 'Find':
1275 if (!PDFViewerApplication.supportsIntegratedFind) {
1276 PDFViewerApplication.findBar.toggle();
1277 }
1278 break;
1279 }
1280}
1281function webViewerPresentationModeChanged(evt) {
1282 var active = evt.active,
1283 switchInProgress = evt.switchInProgress;
1284
1285 PDFViewerApplication.pdfViewer.presentationModeState = switchInProgress ? _ui_utils.PresentationModeState.CHANGING : active ? _ui_utils.PresentationModeState.FULLSCREEN : _ui_utils.PresentationModeState.NORMAL;
1286}
1287function webViewerSidebarViewChanged(evt) {
1288 PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
1289 var store = PDFViewerApplication.store;
1290 if (store && PDFViewerApplication.isInitialViewSet) {
1291 store.set('sidebarView', evt.view).catch(function () {});
1292 }
1293}
1294function webViewerUpdateViewarea(evt) {
1295 var location = evt.location,
1296 store = PDFViewerApplication.store;
1297 if (store && PDFViewerApplication.isInitialViewSet) {
1298 store.setMultiple({
1299 'exists': true,
1300 'page': location.pageNumber,
1301 'zoom': location.scale,
1302 'scrollLeft': location.left,
1303 'scrollTop': location.top,
1304 'rotation': location.rotation
1305 }).catch(function () {});
1306 }
1307 var href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
1308 PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
1309 PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
1310 var currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
1311 var loading = currentPage.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
1312 PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
1313}
1314function webViewerResize() {
1315 var pdfDocument = PDFViewerApplication.pdfDocument,
1316 pdfViewer = PDFViewerApplication.pdfViewer;
1317
1318 if (!pdfDocument) {
1319 return;
1320 }
1321 var currentScaleValue = pdfViewer.currentScaleValue;
1322 if (currentScaleValue === 'auto' || currentScaleValue === 'page-fit' || currentScaleValue === 'page-width') {
1323 pdfViewer.currentScaleValue = currentScaleValue;
1324 }
1325 pdfViewer.update();
1326}
1327function webViewerHashchange(evt) {
1328 var hash = evt.hash;
1329 if (!hash) {
1330 return;
1331 }
1332 if (!PDFViewerApplication.isInitialViewSet) {
1333 PDFViewerApplication.initialBookmark = hash;
1334 } else if (!PDFViewerApplication.pdfHistory.popStateInProgress) {
1335 PDFViewerApplication.pdfLinkService.setHash(hash);
1336 }
1337}
1338var webViewerFileInputChange = void 0;
1339{
1340 webViewerFileInputChange = function webViewerFileInputChange(evt) {
1341 var file = evt.fileInput.files[0];
1342 if (URL.createObjectURL && !_app_options.AppOptions.get('disableCreateObjectURL')) {
1343 PDFViewerApplication.open(URL.createObjectURL(file));
1344 } else {
1345 var fileReader = new FileReader();
1346 fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
1347 var buffer = evt.target.result;
1348 PDFViewerApplication.open(new Uint8Array(buffer));
1349 };
1350 fileReader.readAsArrayBuffer(file);
1351 }
1352 PDFViewerApplication.setTitleUsingUrl(file.name);
1353 var appConfig = PDFViewerApplication.appConfig;
1354 appConfig.toolbar.viewBookmark.setAttribute('hidden', 'true');
1355 appConfig.secondaryToolbar.viewBookmarkButton.setAttribute('hidden', 'true');
1356 appConfig.toolbar.download.setAttribute('hidden', 'true');
1357 appConfig.secondaryToolbar.downloadButton.setAttribute('hidden', 'true');
1358 };
1359}
1360function webViewerPresentationMode() {
1361 PDFViewerApplication.requestPresentationMode();
1362}
1363function webViewerOpenFile() {
1364 var openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
1365 document.getElementById(openFileInputName).click();
1366}
1367function webViewerPrint() {
1368 window.print();
1369}
1370function webViewerDownload() {
1371 PDFViewerApplication.download();
1372}
1373function webViewerFirstPage() {
1374 if (PDFViewerApplication.pdfDocument) {
1375 PDFViewerApplication.page = 1;
1376 }
1377}
1378function webViewerLastPage() {
1379 if (PDFViewerApplication.pdfDocument) {
1380 PDFViewerApplication.page = PDFViewerApplication.pagesCount;
1381 }
1382}
1383function webViewerNextPage() {
1384 PDFViewerApplication.page++;
1385}
1386function webViewerPreviousPage() {
1387 PDFViewerApplication.page--;
1388}
1389function webViewerZoomIn() {
1390 PDFViewerApplication.zoomIn();
1391}
1392function webViewerZoomOut() {
1393 PDFViewerApplication.zoomOut();
1394}
1395function webViewerPageNumberChanged(evt) {
1396 var pdfViewer = PDFViewerApplication.pdfViewer;
1397 pdfViewer.currentPageLabel = evt.value;
1398 if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
1399 PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
1400 }
1401}
1402function webViewerScaleChanged(evt) {
1403 PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
1404}
1405function webViewerRotateCw() {
1406 PDFViewerApplication.rotatePages(90);
1407}
1408function webViewerRotateCcw() {
1409 PDFViewerApplication.rotatePages(-90);
1410}
1411function webViewerDocumentProperties() {
1412 PDFViewerApplication.pdfDocumentProperties.open();
1413}
1414function webViewerFind(evt) {
1415 PDFViewerApplication.findController.executeCommand('find' + evt.type, {
1416 query: evt.query,
1417 phraseSearch: evt.phraseSearch,
1418 caseSensitive: evt.caseSensitive,
1419 highlightAll: evt.highlightAll,
1420 findPrevious: evt.findPrevious
1421 });
1422}
1423function webViewerFindFromUrlHash(evt) {
1424 PDFViewerApplication.findController.executeCommand('find', {
1425 query: evt.query,
1426 phraseSearch: evt.phraseSearch,
1427 caseSensitive: false,
1428 highlightAll: true,
1429 findPrevious: false
1430 });
1431}
1432function webViewerScaleChanging(evt) {
1433 PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
1434 PDFViewerApplication.pdfViewer.update();
1435}
1436function webViewerRotationChanging(evt) {
1437 PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
1438 PDFViewerApplication.forceRendering();
1439 PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
1440}
1441function webViewerPageChanging(evt) {
1442 var page = evt.pageNumber;
1443 PDFViewerApplication.toolbar.setPageNumber(page, evt.pageLabel || null);
1444 PDFViewerApplication.secondaryToolbar.setPageNumber(page);
1445 if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
1446 PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
1447 }
1448 if (typeof Stats !== 'undefined' && Stats.enabled) {
1449 var pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
1450 if (pageView && pageView.stats) {
1451 Stats.add(page, pageView.stats);
1452 }
1453 }
1454}
1455var zoomDisabled = false,
1456 zoomDisabledTimeout = void 0;
1457function webViewerWheel(evt) {
1458 var pdfViewer = PDFViewerApplication.pdfViewer;
1459 if (pdfViewer.isInPresentationMode) {
1460 return;
1461 }
1462 if (evt.ctrlKey || evt.metaKey) {
1463 var support = PDFViewerApplication.supportedMouseWheelZoomModifierKeys;
1464 if (evt.ctrlKey && !support.ctrlKey || evt.metaKey && !support.metaKey) {
1465 return;
1466 }
1467 evt.preventDefault();
1468 if (zoomDisabled) {
1469 return;
1470 }
1471 var previousScale = pdfViewer.currentScale;
1472 var delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
1473 var MOUSE_WHEEL_DELTA_PER_PAGE_SCALE = 3.0;
1474 var ticks = delta * MOUSE_WHEEL_DELTA_PER_PAGE_SCALE;
1475 if (ticks < 0) {
1476 PDFViewerApplication.zoomOut(-ticks);
1477 } else {
1478 PDFViewerApplication.zoomIn(ticks);
1479 }
1480 var currentScale = pdfViewer.currentScale;
1481 if (previousScale !== currentScale) {
1482 var scaleCorrectionFactor = currentScale / previousScale - 1;
1483 var rect = pdfViewer.container.getBoundingClientRect();
1484 var dx = evt.clientX - rect.left;
1485 var dy = evt.clientY - rect.top;
1486 pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
1487 pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
1488 }
1489 } else {
1490 zoomDisabled = true;
1491 clearTimeout(zoomDisabledTimeout);
1492 zoomDisabledTimeout = setTimeout(function () {
1493 zoomDisabled = false;
1494 }, 1000);
1495 }
1496}
1497function webViewerClick(evt) {
1498 if (!PDFViewerApplication.secondaryToolbar.isOpen) {
1499 return;
1500 }
1501 var appConfig = PDFViewerApplication.appConfig;
1502 if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
1503 PDFViewerApplication.secondaryToolbar.close();
1504 }
1505}
1506function webViewerKeyDown(evt) {
1507 if (PDFViewerApplication.overlayManager.active) {
1508 return;
1509 }
1510 var handled = false,
1511 ensureViewerFocused = false;
1512 var cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
1513 var pdfViewer = PDFViewerApplication.pdfViewer;
1514 var isViewerInPresentationMode = pdfViewer && pdfViewer.isInPresentationMode;
1515 if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
1516 switch (evt.keyCode) {
1517 case 70:
1518 if (!PDFViewerApplication.supportsIntegratedFind) {
1519 PDFViewerApplication.findBar.open();
1520 handled = true;
1521 }
1522 break;
1523 case 71:
1524 if (!PDFViewerApplication.supportsIntegratedFind) {
1525 var findState = PDFViewerApplication.findController.state;
1526 if (findState) {
1527 PDFViewerApplication.findController.executeCommand('findagain', {
1528 query: findState.query,
1529 phraseSearch: findState.phraseSearch,
1530 caseSensitive: findState.caseSensitive,
1531 highlightAll: findState.highlightAll,
1532 findPrevious: cmd === 5 || cmd === 12
1533 });
1534 }
1535 handled = true;
1536 }
1537 break;
1538 case 61:
1539 case 107:
1540 case 187:
1541 case 171:
1542 if (!isViewerInPresentationMode) {
1543 PDFViewerApplication.zoomIn();
1544 }
1545 handled = true;
1546 break;
1547 case 173:
1548 case 109:
1549 case 189:
1550 if (!isViewerInPresentationMode) {
1551 PDFViewerApplication.zoomOut();
1552 }
1553 handled = true;
1554 break;
1555 case 48:
1556 case 96:
1557 if (!isViewerInPresentationMode) {
1558 setTimeout(function () {
1559 pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
1560 });
1561 handled = false;
1562 }
1563 break;
1564 case 38:
1565 if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
1566 PDFViewerApplication.page = 1;
1567 handled = true;
1568 ensureViewerFocused = true;
1569 }
1570 break;
1571 case 40:
1572 if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
1573 PDFViewerApplication.page = PDFViewerApplication.pagesCount;
1574 handled = true;
1575 ensureViewerFocused = true;
1576 }
1577 break;
1578 }
1579 }
1580 if (cmd === 1 || cmd === 8) {
1581 switch (evt.keyCode) {
1582 case 83:
1583 PDFViewerApplication.download();
1584 handled = true;
1585 break;
1586 }
1587 }
1588 if (cmd === 3 || cmd === 10) {
1589 switch (evt.keyCode) {
1590 case 80:
1591 PDFViewerApplication.requestPresentationMode();
1592 handled = true;
1593 break;
1594 case 71:
1595 PDFViewerApplication.appConfig.toolbar.pageNumber.select();
1596 handled = true;
1597 break;
1598 }
1599 }
1600 if (handled) {
1601 if (ensureViewerFocused && !isViewerInPresentationMode) {
1602 pdfViewer.focus();
1603 }
1604 evt.preventDefault();
1605 return;
1606 }
1607 var curElement = document.activeElement || document.querySelector(':focus');
1608 var curElementTagName = curElement && curElement.tagName.toUpperCase();
1609 if (curElementTagName === 'INPUT' || curElementTagName === 'TEXTAREA' || curElementTagName === 'SELECT') {
1610 if (evt.keyCode !== 27) {
1611 return;
1612 }
1613 }
1614 if (cmd === 0) {
1615 switch (evt.keyCode) {
1616 case 38:
1617 case 33:
1618 case 8:
1619 if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
1620 break;
1621 }
1622 case 37:
1623 if (pdfViewer.isHorizontalScrollbarEnabled) {
1624 break;
1625 }
1626 case 75:
1627 case 80:
1628 if (PDFViewerApplication.page > 1) {
1629 PDFViewerApplication.page--;
1630 }
1631 handled = true;
1632 break;
1633 case 27:
1634 if (PDFViewerApplication.secondaryToolbar.isOpen) {
1635 PDFViewerApplication.secondaryToolbar.close();
1636 handled = true;
1637 }
1638 if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
1639 PDFViewerApplication.findBar.close();
1640 handled = true;
1641 }
1642 break;
1643 case 13:
1644 case 40:
1645 case 34:
1646 case 32:
1647 if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
1648 break;
1649 }
1650 case 39:
1651 if (pdfViewer.isHorizontalScrollbarEnabled) {
1652 break;
1653 }
1654 case 74:
1655 case 78:
1656 if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
1657 PDFViewerApplication.page++;
1658 }
1659 handled = true;
1660 break;
1661 case 36:
1662 if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
1663 PDFViewerApplication.page = 1;
1664 handled = true;
1665 ensureViewerFocused = true;
1666 }
1667 break;
1668 case 35:
1669 if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
1670 PDFViewerApplication.page = PDFViewerApplication.pagesCount;
1671 handled = true;
1672 ensureViewerFocused = true;
1673 }
1674 break;
1675 case 83:
1676 PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
1677 break;
1678 case 72:
1679 PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
1680 break;
1681 case 82:
1682 PDFViewerApplication.rotatePages(90);
1683 break;
1684 }
1685 }
1686 if (cmd === 4) {
1687 switch (evt.keyCode) {
1688 case 13:
1689 case 32:
1690 if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
1691 break;
1692 }
1693 if (PDFViewerApplication.page > 1) {
1694 PDFViewerApplication.page--;
1695 }
1696 handled = true;
1697 break;
1698 case 82:
1699 PDFViewerApplication.rotatePages(-90);
1700 break;
1701 }
1702 }
1703 if (!handled && !isViewerInPresentationMode) {
1704 if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== 'BUTTON') {
1705 ensureViewerFocused = true;
1706 }
1707 }
1708 if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
1709 pdfViewer.focus();
1710 }
1711 if (handled) {
1712 evt.preventDefault();
1713 }
1714}
1715function apiPageModeToSidebarView(mode) {
1716 switch (mode) {
1717 case 'UseNone':
1718 return _pdf_sidebar.SidebarView.NONE;
1719 case 'UseThumbs':
1720 return _pdf_sidebar.SidebarView.THUMBS;
1721 case 'UseOutlines':
1722 return _pdf_sidebar.SidebarView.OUTLINE;
1723 case 'UseAttachments':
1724 return _pdf_sidebar.SidebarView.ATTACHMENTS;
1725 case 'UseOC':
1726 }
1727 return _pdf_sidebar.SidebarView.NONE;
1728}
1729var PDFPrintServiceFactory = {
1730 instance: {
1731 supportsPrinting: false,
1732 createPrintService: function createPrintService() {
1733 throw new Error('Not implemented: createPrintService');
1734 }
1735 }
1736};
1737exports.PDFViewerApplication = PDFViewerApplication;
1738exports.DefaultExternalServices = DefaultExternalServices;
1739exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
\No newline at end of file