pdfjs-dist 2.0.487 → 2.1.266

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.

Files changed (161) hide show
  1. package/bower.json +1 -1
  2. package/build/pdf.js +15564 -9476
  3. package/build/pdf.js.map +1 -1
  4. package/build/pdf.min.js +1 -1
  5. package/build/pdf.worker.js +46644 -36309
  6. package/build/pdf.worker.js.map +1 -1
  7. package/build/pdf.worker.min.js +1 -1
  8. package/external/url/url-lib.js +627 -0
  9. package/image_decoders/pdf.image_decoders.js +11430 -0
  10. package/image_decoders/pdf.image_decoders.js.map +1 -0
  11. package/image_decoders/pdf.image_decoders.min.js +1 -0
  12. package/lib/core/annotation.js +406 -131
  13. package/lib/core/arithmetic_decoder.js +275 -245
  14. package/lib/core/bidi.js +65 -6
  15. package/lib/core/ccitt.js +173 -18
  16. package/lib/core/ccitt_stream.js +15 -6
  17. package/lib/core/cff_parser.js +376 -53
  18. package/lib/core/charsets.js +5 -4
  19. package/lib/core/chunked_stream.js +387 -149
  20. package/lib/core/cmap.js +310 -75
  21. package/lib/core/colorspace.js +874 -594
  22. package/lib/core/crypto.js +290 -45
  23. package/lib/core/document.js +545 -260
  24. package/lib/core/encodings.js +19 -10
  25. package/lib/core/evaluator.js +725 -147
  26. package/lib/core/font_renderer.js +360 -91
  27. package/lib/core/fonts.js +791 -186
  28. package/lib/core/function.js +284 -71
  29. package/lib/core/glyphlist.js +3 -2
  30. package/lib/core/image.js +168 -61
  31. package/lib/core/jbig2.js +479 -66
  32. package/lib/core/jbig2_stream.js +19 -8
  33. package/lib/core/jpeg_stream.js +38 -13
  34. package/lib/core/jpg.js +252 -29
  35. package/lib/core/jpx.js +396 -6
  36. package/lib/core/jpx_stream.js +18 -6
  37. package/lib/core/metrics.js +4 -4
  38. package/lib/core/murmurhash3.js +24 -6
  39. package/lib/core/obj.js +1137 -475
  40. package/lib/core/operator_list.js +108 -6
  41. package/lib/core/parser.js +321 -68
  42. package/lib/core/pattern.js +145 -13
  43. package/lib/core/pdf_manager.js +321 -133
  44. package/lib/core/primitives.js +75 -22
  45. package/lib/core/ps_parser.js +134 -45
  46. package/lib/core/standard_fonts.js +10 -10
  47. package/lib/core/stream.js +313 -34
  48. package/lib/core/type1_parser.js +143 -13
  49. package/lib/core/unicode.js +31 -4
  50. package/lib/core/worker.js +210 -66
  51. package/lib/display/annotation_layer.js +361 -123
  52. package/lib/display/api.js +1454 -729
  53. package/lib/display/api_compatibility.js +11 -13
  54. package/lib/display/canvas.js +324 -29
  55. package/lib/display/content_disposition.js +83 -32
  56. package/lib/display/dom_utils.js +226 -41
  57. package/lib/display/fetch_stream.js +208 -84
  58. package/lib/display/font_loader.js +465 -236
  59. package/lib/display/metadata.js +38 -16
  60. package/lib/display/network.js +216 -51
  61. package/lib/display/network_utils.js +32 -19
  62. package/lib/display/node_stream.js +352 -169
  63. package/lib/display/pattern_helper.js +58 -7
  64. package/lib/display/svg.js +242 -29
  65. package/lib/display/text_layer.js +132 -18
  66. package/lib/display/transport_stream.js +171 -42
  67. package/lib/display/webgl.js +64 -18
  68. package/lib/display/worker_options.js +5 -4
  69. package/lib/display/xml_parser.js +166 -53
  70. package/lib/examples/node/domstubs.js +57 -4
  71. package/lib/pdf.js +21 -4
  72. package/lib/pdf.worker.js +5 -3
  73. package/lib/shared/compatibility.js +158 -564
  74. package/lib/shared/global_scope.js +2 -2
  75. package/lib/shared/is_node.js +4 -4
  76. package/lib/shared/message_handler.js +521 -0
  77. package/lib/shared/streams_polyfill.js +21 -17
  78. package/lib/shared/url_polyfill.js +56 -0
  79. package/lib/shared/util.js +295 -650
  80. package/lib/test/unit/annotation_spec.js +629 -345
  81. package/lib/test/unit/api_spec.js +555 -253
  82. package/lib/test/unit/bidi_spec.js +7 -7
  83. package/lib/test/unit/cff_parser_spec.js +40 -11
  84. package/lib/test/unit/clitests_helper.js +9 -7
  85. package/lib/test/unit/cmap_spec.js +80 -26
  86. package/lib/test/unit/colorspace_spec.js +99 -52
  87. package/lib/test/unit/crypto_spec.js +17 -5
  88. package/lib/test/unit/custom_spec.js +41 -53
  89. package/lib/test/unit/display_svg_spec.js +33 -17
  90. package/lib/test/unit/document_spec.js +3 -3
  91. package/lib/test/unit/dom_utils_spec.js +9 -9
  92. package/lib/test/unit/encodings_spec.js +25 -45
  93. package/lib/test/unit/evaluator_spec.js +34 -9
  94. package/lib/test/unit/function_spec.js +17 -5
  95. package/lib/test/unit/jasmine-boot.js +31 -18
  96. package/lib/test/unit/{util_stream_spec.js → message_handler_spec.js} +41 -69
  97. package/lib/test/unit/metadata_spec.js +71 -11
  98. package/lib/test/unit/murmurhash3_spec.js +3 -3
  99. package/lib/test/unit/network_spec.js +20 -5
  100. package/lib/test/unit/network_utils_spec.js +41 -14
  101. package/lib/test/unit/node_stream_spec.js +51 -27
  102. package/lib/test/unit/parser_spec.js +35 -8
  103. package/lib/test/unit/pdf_find_controller_spec.js +230 -0
  104. package/lib/test/unit/pdf_find_utils_spec.js +63 -0
  105. package/lib/test/unit/pdf_history_spec.js +21 -9
  106. package/lib/test/unit/primitives_spec.js +24 -4
  107. package/lib/test/unit/stream_spec.js +12 -4
  108. package/lib/test/unit/test_utils.js +90 -27
  109. package/lib/test/unit/testreporter.js +21 -3
  110. package/lib/test/unit/type1_parser_spec.js +8 -6
  111. package/lib/test/unit/ui_utils_spec.js +452 -14
  112. package/lib/test/unit/unicode_spec.js +14 -11
  113. package/lib/test/unit/util_spec.js +131 -9
  114. package/lib/web/annotation_layer_builder.js +39 -22
  115. package/lib/web/app.js +1240 -582
  116. package/lib/web/app_options.js +71 -41
  117. package/lib/web/base_viewer.js +508 -179
  118. package/lib/web/chromecom.js +261 -117
  119. package/lib/web/debugger.js +166 -22
  120. package/lib/web/download_manager.js +31 -13
  121. package/lib/web/firefox_print_service.js +17 -9
  122. package/lib/web/firefoxcom.js +283 -79
  123. package/lib/web/genericcom.js +89 -30
  124. package/lib/web/genericl10n.js +142 -30
  125. package/lib/web/grab_to_pan.js +26 -4
  126. package/lib/web/interfaces.js +170 -47
  127. package/lib/web/overlay_manager.js +235 -85
  128. package/lib/web/password_prompt.js +21 -13
  129. package/lib/web/pdf_attachment_viewer.js +38 -18
  130. package/lib/web/pdf_cursor_tools.js +39 -16
  131. package/lib/web/pdf_document_properties.js +80 -30
  132. package/lib/web/pdf_find_bar.js +84 -40
  133. package/lib/web/pdf_find_controller.js +495 -184
  134. package/lib/web/pdf_find_utils.js +111 -0
  135. package/lib/web/pdf_history.js +190 -53
  136. package/lib/web/pdf_link_service.js +137 -76
  137. package/lib/web/pdf_outline_viewer.js +73 -22
  138. package/lib/web/pdf_page_view.js +196 -63
  139. package/lib/web/pdf_presentation_mode.js +99 -34
  140. package/lib/web/pdf_print_service.js +57 -11
  141. package/lib/web/pdf_rendering_queue.js +27 -5
  142. package/lib/web/pdf_sidebar.js +120 -67
  143. package/lib/web/pdf_sidebar_resizer.js +42 -16
  144. package/lib/web/pdf_single_page_viewer.js +74 -66
  145. package/lib/web/pdf_thumbnail_view.js +103 -32
  146. package/lib/web/pdf_thumbnail_viewer.js +64 -24
  147. package/lib/web/pdf_viewer.component.js +112 -32
  148. package/lib/web/pdf_viewer.js +91 -52
  149. package/lib/web/preferences.js +275 -80
  150. package/lib/web/secondary_toolbar.js +165 -40
  151. package/lib/web/text_layer_builder.js +162 -65
  152. package/lib/web/toolbar.js +78 -43
  153. package/lib/web/ui_utils.js +462 -136
  154. package/lib/web/view_history.js +215 -67
  155. package/lib/web/viewer_compatibility.js +4 -13
  156. package/package.json +5 -4
  157. package/web/pdf_viewer.css +58 -1
  158. package/web/pdf_viewer.js +6346 -3919
  159. package/web/pdf_viewer.js.map +1 -1
  160. package/lib/test/unit/fonts_spec.js +0 -81
  161. package/lib/web/dom_events.js +0 -137
package/lib/web/app.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 2017 Mozilla Foundation
5
+ * Copyright 2018 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -19,65 +19,85 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
- exports.PDFPrintServiceFactory = exports.DefaultExternalServices = exports.PDFViewerApplication = undefined;
27
+ exports.PDFPrintServiceFactory = exports.DefaultExternalServices = exports.PDFViewerApplication = void 0;
28
28
 
29
- var _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"); } }; }();
29
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
30
30
 
31
- var _ui_utils = require('./ui_utils');
31
+ var _ui_utils = require("./ui_utils");
32
32
 
33
- var _pdf = require('../pdf');
33
+ var _pdf = require("../pdf");
34
34
 
35
- var _pdf_cursor_tools = require('./pdf_cursor_tools');
35
+ var _pdf_cursor_tools = require("./pdf_cursor_tools");
36
36
 
37
- var _pdf_rendering_queue = require('./pdf_rendering_queue');
37
+ var _pdf_rendering_queue = require("./pdf_rendering_queue");
38
38
 
39
- var _pdf_sidebar = require('./pdf_sidebar');
39
+ var _pdf_sidebar = require("./pdf_sidebar");
40
40
 
41
- var _app_options = require('./app_options');
41
+ var _app_options = require("./app_options");
42
42
 
43
- var _dom_events = require('./dom_events');
43
+ var _overlay_manager = require("./overlay_manager");
44
44
 
45
- var _overlay_manager = require('./overlay_manager');
45
+ var _password_prompt = require("./password_prompt");
46
46
 
47
- var _password_prompt = require('./password_prompt');
47
+ var _pdf_attachment_viewer = require("./pdf_attachment_viewer");
48
48
 
49
- var _pdf_attachment_viewer = require('./pdf_attachment_viewer');
49
+ var _pdf_document_properties = require("./pdf_document_properties");
50
50
 
51
- var _pdf_document_properties = require('./pdf_document_properties');
51
+ var _pdf_find_bar = require("./pdf_find_bar");
52
52
 
53
- var _pdf_find_bar = require('./pdf_find_bar');
53
+ var _pdf_find_controller = require("./pdf_find_controller");
54
54
 
55
- var _pdf_find_controller = require('./pdf_find_controller');
55
+ var _pdf_history = require("./pdf_history");
56
56
 
57
- var _pdf_history = require('./pdf_history');
57
+ var _pdf_link_service = require("./pdf_link_service");
58
58
 
59
- var _pdf_link_service = require('./pdf_link_service');
59
+ var _pdf_outline_viewer = require("./pdf_outline_viewer");
60
60
 
61
- var _pdf_outline_viewer = require('./pdf_outline_viewer');
61
+ var _pdf_presentation_mode = require("./pdf_presentation_mode");
62
62
 
63
- var _pdf_presentation_mode = require('./pdf_presentation_mode');
63
+ var _pdf_sidebar_resizer = require("./pdf_sidebar_resizer");
64
64
 
65
- var _pdf_sidebar_resizer = require('./pdf_sidebar_resizer');
65
+ var _pdf_thumbnail_viewer = require("./pdf_thumbnail_viewer");
66
66
 
67
- var _pdf_thumbnail_viewer = require('./pdf_thumbnail_viewer');
67
+ var _pdf_viewer = require("./pdf_viewer");
68
68
 
69
- var _pdf_viewer = require('./pdf_viewer');
69
+ var _secondary_toolbar = require("./secondary_toolbar");
70
70
 
71
- var _secondary_toolbar = require('./secondary_toolbar');
71
+ var _toolbar = require("./toolbar");
72
72
 
73
- var _toolbar = require('./toolbar');
73
+ var _view_history = require("./view_history");
74
74
 
75
- var _view_history = require('./view_history');
75
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
76
+
77
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
78
+
79
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
80
+
81
+ function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
82
+
83
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
84
+
85
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
86
+
87
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
76
88
 
77
89
  var DEFAULT_SCALE_DELTA = 1.1;
78
90
  var DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
91
+ var FORCE_PAGES_LOADED_TIMEOUT = 10000;
92
+ var WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
93
+ var ViewOnLoad = {
94
+ UNKNOWN: -1,
95
+ PREVIOUS: 0,
96
+ INITIAL: 1
97
+ };
79
98
  var DefaultExternalServices = {
80
99
  updateFindControlState: function updateFindControlState(data) {},
100
+ updateFindMatchesCount: function updateFindMatchesCount(data) {},
81
101
  initPassiveLoading: function initPassiveLoading(callbacks) {},
82
102
  fallback: function fallback(data, callback) {},
83
103
  reportTelemetry: function reportTelemetry(data) {},
@@ -90,7 +110,6 @@ var DefaultExternalServices = {
90
110
  createL10n: function createL10n(options) {
91
111
  throw new Error('Not implemented: createL10n');
92
112
  },
93
-
94
113
  supportsIntegratedFind: false,
95
114
  supportsDocumentFonts: true,
96
115
  supportsDocumentColors: true,
@@ -99,6 +118,7 @@ var DefaultExternalServices = {
99
118
  metaKey: true
100
119
  }
101
120
  };
121
+ exports.DefaultExternalServices = DefaultExternalServices;
102
122
  var PDFViewerApplication = {
103
123
  initialBookmark: document.location.hash.substring(1),
104
124
  initialized: false,
@@ -135,337 +155,458 @@ var PDFViewerApplication = {
135
155
  externalServices: DefaultExternalServices,
136
156
  _boundEvents: {},
137
157
  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;
158
+ initialize: function () {
159
+ var _initialize = _asyncToGenerator(
160
+ /*#__PURE__*/
161
+ _regenerator.default.mark(function _callee(appConfig) {
162
+ var _this = this;
163
+
164
+ var appContainer;
165
+ return _regenerator.default.wrap(function _callee$(_context) {
166
+ while (1) {
167
+ switch (_context.prev = _context.next) {
168
+ case 0:
169
+ this.preferences = this.externalServices.createPreferences();
170
+ this.appConfig = appConfig;
171
+ _context.next = 4;
172
+ return this._readPreferences();
173
+
174
+ case 4:
175
+ _context.next = 6;
176
+ return this._parseHashParameters();
177
+
178
+ case 6:
179
+ _context.next = 8;
180
+ return this._initializeL10n();
181
+
182
+ case 8:
183
+ if (this.isViewerEmbedded && _app_options.AppOptions.get('externalLinkTarget') === _pdf.LinkTarget.NONE) {
184
+ _app_options.AppOptions.set('externalLinkTarget', _pdf.LinkTarget.TOP);
185
+ }
186
+
187
+ _context.next = 11;
188
+ return this._initializeViewerComponents();
189
+
190
+ case 11:
191
+ this.bindEvents();
192
+ this.bindWindowEvents();
193
+ appContainer = appConfig.appContainer || document.documentElement;
194
+ this.l10n.translate(appContainer).then(function () {
195
+ _this.eventBus.dispatch('localized', {
196
+ source: _this
197
+ });
198
+ });
199
+ this.initialized = true;
200
+
201
+ case 16:
202
+ case "end":
203
+ return _context.stop();
204
+ }
263
205
  }
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
- }
206
+ }, _callee, this);
207
+ }));
208
+
209
+ function initialize(_x) {
210
+ return _initialize.apply(this, arguments);
273
211
  }
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;
212
+
213
+ return initialize;
214
+ }(),
215
+ _readPreferences: function () {
216
+ var _readPreferences2 = _asyncToGenerator(
217
+ /*#__PURE__*/
218
+ _regenerator.default.mark(function _callee2() {
219
+ var prefs, name;
220
+ return _regenerator.default.wrap(function _callee2$(_context2) {
221
+ while (1) {
222
+ switch (_context2.prev = _context2.next) {
223
+ case 0:
224
+ if (!(_app_options.AppOptions.get('disablePreferences') === true)) {
225
+ _context2.next = 2;
226
+ break;
227
+ }
228
+
229
+ return _context2.abrupt("return");
230
+
231
+ case 2:
232
+ _context2.prev = 2;
233
+ _context2.next = 5;
234
+ return this.preferences.getAll();
235
+
236
+ case 5:
237
+ prefs = _context2.sent;
238
+
239
+ for (name in prefs) {
240
+ _app_options.AppOptions.set(name, prefs[name]);
241
+ }
242
+
243
+ _context2.next = 11;
244
+ break;
245
+
246
+ case 9:
247
+ _context2.prev = 9;
248
+ _context2.t0 = _context2["catch"](2);
249
+
250
+ case 11:
251
+ case "end":
252
+ return _context2.stop();
253
+ }
340
254
  }
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);
255
+ }, _callee2, this, [[2, 9]]);
256
+ }));
257
+
258
+ function _readPreferences() {
259
+ return _readPreferences2.apply(this, arguments);
260
+ }
261
+
262
+ return _readPreferences;
263
+ }(),
264
+ _parseHashParameters: function () {
265
+ var _parseHashParameters2 = _asyncToGenerator(
266
+ /*#__PURE__*/
267
+ _regenerator.default.mark(function _callee3() {
268
+ var waitOn, hash, hashParams, viewer, enabled;
269
+ return _regenerator.default.wrap(function _callee3$(_context3) {
270
+ while (1) {
271
+ switch (_context3.prev = _context3.next) {
272
+ case 0:
273
+ if (_app_options.AppOptions.get('pdfBugEnabled')) {
274
+ _context3.next = 2;
275
+ break;
276
+ }
277
+
278
+ return _context3.abrupt("return");
279
+
280
+ case 2:
281
+ waitOn = [];
282
+ hash = document.location.hash.substring(1);
283
+ hashParams = (0, _ui_utils.parseQueryString)(hash);
284
+
285
+ if ('disableworker' in hashParams && hashParams['disableworker'] === 'true') {
286
+ waitOn.push(loadFakeWorker());
287
+ }
288
+
289
+ if ('disablerange' in hashParams) {
290
+ _app_options.AppOptions.set('disableRange', hashParams['disablerange'] === 'true');
291
+ }
292
+
293
+ if ('disablestream' in hashParams) {
294
+ _app_options.AppOptions.set('disableStream', hashParams['disablestream'] === 'true');
295
+ }
296
+
297
+ if ('disableautofetch' in hashParams) {
298
+ _app_options.AppOptions.set('disableAutoFetch', hashParams['disableautofetch'] === 'true');
299
+ }
300
+
301
+ if ('disablefontface' in hashParams) {
302
+ _app_options.AppOptions.set('disableFontFace', hashParams['disablefontface'] === 'true');
303
+ }
304
+
305
+ if ('disablehistory' in hashParams) {
306
+ _app_options.AppOptions.set('disableHistory', hashParams['disablehistory'] === 'true');
307
+ }
308
+
309
+ if ('webgl' in hashParams) {
310
+ _app_options.AppOptions.set('enableWebGL', hashParams['webgl'] === 'true');
311
+ }
312
+
313
+ if ('useonlycsszoom' in hashParams) {
314
+ _app_options.AppOptions.set('useOnlyCssZoom', hashParams['useonlycsszoom'] === 'true');
315
+ }
316
+
317
+ if ('verbosity' in hashParams) {
318
+ _app_options.AppOptions.set('verbosity', hashParams['verbosity'] | 0);
319
+ }
320
+
321
+ if (!('textlayer' in hashParams)) {
322
+ _context3.next = 23;
323
+ break;
324
+ }
325
+
326
+ _context3.t0 = hashParams['textlayer'];
327
+ _context3.next = _context3.t0 === 'off' ? 18 : _context3.t0 === 'visible' ? 20 : _context3.t0 === 'shadow' ? 20 : _context3.t0 === 'hover' ? 20 : 23;
328
+ break;
329
+
330
+ case 18:
331
+ _app_options.AppOptions.set('textLayerMode', _ui_utils.TextLayerMode.DISABLE);
332
+
333
+ return _context3.abrupt("break", 23);
334
+
335
+ case 20:
336
+ viewer = this.appConfig.viewerContainer;
337
+ viewer.classList.add('textLayer-' + hashParams['textlayer']);
338
+ return _context3.abrupt("break", 23);
339
+
340
+ case 23:
341
+ if ('pdfbug' in hashParams) {
342
+ _app_options.AppOptions.set('pdfBug', true);
343
+
344
+ enabled = hashParams['pdfbug'].split(',');
345
+ waitOn.push(loadAndEnablePDFBug(enabled));
346
+ }
347
+
348
+ if ('locale' in hashParams) {
349
+ _app_options.AppOptions.set('locale', hashParams['locale']);
350
+ }
351
+
352
+ return _context3.abrupt("return", Promise.all(waitOn).catch(function (reason) {
353
+ console.error("_parseHashParameters: \"".concat(reason.message, "\"."));
354
+ }));
355
+
356
+ case 26:
357
+ case "end":
358
+ return _context3.stop();
359
+ }
351
360
  }
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
- },
361
+ }, _callee3, this);
362
+ }));
363
+
364
+ function _parseHashParameters() {
365
+ return _parseHashParameters2.apply(this, arguments);
366
+ }
367
+
368
+ return _parseHashParameters;
369
+ }(),
370
+ _initializeL10n: function () {
371
+ var _initializeL10n2 = _asyncToGenerator(
372
+ /*#__PURE__*/
373
+ _regenerator.default.mark(function _callee4() {
374
+ var dir;
375
+ return _regenerator.default.wrap(function _callee4$(_context4) {
376
+ while (1) {
377
+ switch (_context4.prev = _context4.next) {
378
+ case 0:
379
+ this.l10n = this.externalServices.createL10n({
380
+ locale: _app_options.AppOptions.get('locale')
381
+ });
382
+ _context4.next = 3;
383
+ return this.l10n.getDirection();
384
+
385
+ case 3:
386
+ dir = _context4.sent;
387
+ document.getElementsByTagName('html')[0].dir = dir;
388
+
389
+ case 5:
390
+ case "end":
391
+ return _context4.stop();
392
+ }
393
+ }
394
+ }, _callee4, this);
395
+ }));
396
+
397
+ function _initializeL10n() {
398
+ return _initializeL10n2.apply(this, arguments);
399
+ }
400
+
401
+ return _initializeL10n;
402
+ }(),
403
+ _initializeViewerComponents: function () {
404
+ var _initializeViewerComponents2 = _asyncToGenerator(
405
+ /*#__PURE__*/
406
+ _regenerator.default.mark(function _callee5() {
407
+ var appConfig, dispatchToDOM, eventBus, pdfRenderingQueue, pdfLinkService, downloadManager, findController, container, viewer, thumbnailContainer, sidebarConfig;
408
+ return _regenerator.default.wrap(function _callee5$(_context5) {
409
+ while (1) {
410
+ switch (_context5.prev = _context5.next) {
411
+ case 0:
412
+ appConfig = this.appConfig;
413
+ this.overlayManager = new _overlay_manager.OverlayManager();
414
+ dispatchToDOM = _app_options.AppOptions.get('eventBusDispatchToDOM');
415
+ eventBus = appConfig.eventBus || (0, _ui_utils.getGlobalEventBus)(dispatchToDOM);
416
+ this.eventBus = eventBus;
417
+ pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
418
+ pdfRenderingQueue.onIdle = this.cleanup.bind(this);
419
+ this.pdfRenderingQueue = pdfRenderingQueue;
420
+ pdfLinkService = new _pdf_link_service.PDFLinkService({
421
+ eventBus: eventBus,
422
+ externalLinkTarget: _app_options.AppOptions.get('externalLinkTarget'),
423
+ externalLinkRel: _app_options.AppOptions.get('externalLinkRel')
424
+ });
425
+ this.pdfLinkService = pdfLinkService;
426
+ downloadManager = this.externalServices.createDownloadManager({
427
+ disableCreateObjectURL: _app_options.AppOptions.get('disableCreateObjectURL')
428
+ });
429
+ this.downloadManager = downloadManager;
430
+ findController = new _pdf_find_controller.PDFFindController({
431
+ linkService: pdfLinkService,
432
+ eventBus: eventBus
433
+ });
434
+ this.findController = findController;
435
+ container = appConfig.mainContainer;
436
+ viewer = appConfig.viewerContainer;
437
+ this.pdfViewer = new _pdf_viewer.PDFViewer({
438
+ container: container,
439
+ viewer: viewer,
440
+ eventBus: eventBus,
441
+ renderingQueue: pdfRenderingQueue,
442
+ linkService: pdfLinkService,
443
+ downloadManager: downloadManager,
444
+ findController: findController,
445
+ renderer: _app_options.AppOptions.get('renderer'),
446
+ enableWebGL: _app_options.AppOptions.get('enableWebGL'),
447
+ l10n: this.l10n,
448
+ textLayerMode: _app_options.AppOptions.get('textLayerMode'),
449
+ imageResourcesPath: _app_options.AppOptions.get('imageResourcesPath'),
450
+ renderInteractiveForms: _app_options.AppOptions.get('renderInteractiveForms'),
451
+ enablePrintAutoRotate: _app_options.AppOptions.get('enablePrintAutoRotate'),
452
+ useOnlyCssZoom: _app_options.AppOptions.get('useOnlyCssZoom'),
453
+ maxCanvasPixels: _app_options.AppOptions.get('maxCanvasPixels')
454
+ });
455
+ pdfRenderingQueue.setViewer(this.pdfViewer);
456
+ pdfLinkService.setViewer(this.pdfViewer);
457
+ thumbnailContainer = appConfig.sidebar.thumbnailView;
458
+ this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
459
+ container: thumbnailContainer,
460
+ renderingQueue: pdfRenderingQueue,
461
+ linkService: pdfLinkService,
462
+ l10n: this.l10n
463
+ });
464
+ pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
465
+ this.pdfHistory = new _pdf_history.PDFHistory({
466
+ linkService: pdfLinkService,
467
+ eventBus: eventBus
468
+ });
469
+ pdfLinkService.setHistory(this.pdfHistory);
470
+ this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
471
+ this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n);
472
+ this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
473
+ container: container,
474
+ eventBus: eventBus,
475
+ cursorToolOnLoad: _app_options.AppOptions.get('cursorToolOnLoad')
476
+ });
477
+ this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
478
+ this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
479
+
480
+ if (this.supportsFullscreen) {
481
+ this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
482
+ container: container,
483
+ viewer: viewer,
484
+ pdfViewer: this.pdfViewer,
485
+ eventBus: eventBus,
486
+ contextMenuItems: appConfig.fullscreen
487
+ });
488
+ }
489
+
490
+ this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n);
491
+ this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
492
+ container: appConfig.sidebar.outlineView,
493
+ eventBus: eventBus,
494
+ linkService: pdfLinkService
495
+ });
496
+ this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
497
+ container: appConfig.sidebar.attachmentsView,
498
+ eventBus: eventBus,
499
+ downloadManager: downloadManager
500
+ });
501
+ sidebarConfig = Object.create(appConfig.sidebar);
502
+ sidebarConfig.pdfViewer = this.pdfViewer;
503
+ sidebarConfig.pdfThumbnailViewer = this.pdfThumbnailViewer;
504
+ this.pdfSidebar = new _pdf_sidebar.PDFSidebar(sidebarConfig, eventBus, this.l10n);
505
+ this.pdfSidebar.onToggled = this.forceRendering.bind(this);
506
+ this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
507
+
508
+ case 39:
509
+ case "end":
510
+ return _context5.stop();
511
+ }
512
+ }
513
+ }, _callee5, this);
514
+ }));
515
+
516
+ function _initializeViewerComponents() {
517
+ return _initializeViewerComponents2.apply(this, arguments);
518
+ }
519
+
520
+ return _initializeViewerComponents;
521
+ }(),
397
522
  run: function run(config) {
398
523
  this.initialize(config).then(webViewerInitialized);
399
524
  },
400
525
  zoomIn: function zoomIn(ticks) {
401
526
  var newScale = this.pdfViewer.currentScale;
527
+
402
528
  do {
403
529
  newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
404
530
  newScale = Math.ceil(newScale * 10) / 10;
405
531
  newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
406
532
  } while (--ticks > 0 && newScale < _ui_utils.MAX_SCALE);
533
+
407
534
  this.pdfViewer.currentScaleValue = newScale;
408
535
  },
409
536
  zoomOut: function zoomOut(ticks) {
410
537
  var newScale = this.pdfViewer.currentScale;
538
+
411
539
  do {
412
540
  newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
413
541
  newScale = Math.floor(newScale * 10) / 10;
414
542
  newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
415
543
  } while (--ticks > 0 && newScale > _ui_utils.MIN_SCALE);
544
+
416
545
  this.pdfViewer.currentScaleValue = newScale;
417
546
  },
418
547
 
419
548
  get pagesCount() {
420
549
  return this.pdfDocument ? this.pdfDocument.numPages : 0;
421
550
  },
551
+
422
552
  set page(val) {
423
553
  this.pdfViewer.currentPageNumber = val;
424
554
  },
555
+
425
556
  get page() {
426
557
  return this.pdfViewer.currentPageNumber;
427
558
  },
559
+
428
560
  get printing() {
429
561
  return !!this.printService;
430
562
  },
563
+
431
564
  get supportsPrinting() {
432
565
  return PDFPrintServiceFactory.instance.supportsPrinting;
433
566
  },
567
+
434
568
  get supportsFullscreen() {
435
- var support = void 0;
569
+ var support;
436
570
  var doc = document.documentElement;
437
571
  support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen || doc.msRequestFullscreen);
572
+
438
573
  if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false || document.msFullscreenEnabled === false) {
439
574
  support = false;
440
575
  }
441
- if (support && _app_options.AppOptions.get('disableFullscreen') === true) {
442
- support = false;
443
- }
576
+
444
577
  return (0, _pdf.shadow)(this, 'supportsFullscreen', support);
445
578
  },
579
+
446
580
  get supportsIntegratedFind() {
447
581
  return this.externalServices.supportsIntegratedFind;
448
582
  },
583
+
449
584
  get supportsDocumentFonts() {
450
585
  return this.externalServices.supportsDocumentFonts;
451
586
  },
587
+
452
588
  get supportsDocumentColors() {
453
589
  return this.externalServices.supportsDocumentColors;
454
590
  },
591
+
455
592
  get loadingBar() {
456
593
  var bar = new _ui_utils.ProgressBar('#loadingBar');
457
594
  return (0, _pdf.shadow)(this, 'loadingBar', bar);
458
595
  },
596
+
459
597
  get supportedMouseWheelZoomModifierKeys() {
460
598
  return this.externalServices.supportedMouseWheelZoomModifierKeys;
461
599
  },
600
+
462
601
  initPassiveLoading: function initPassiveLoading() {
463
602
  throw new Error('Not implemented: initPassiveLoading');
464
603
  },
465
- setTitleUsingUrl: function setTitleUsingUrl(url) {
604
+ setTitleUsingUrl: function setTitleUsingUrl() {
605
+ var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
466
606
  this.url = url;
467
607
  this.baseUrl = url.split('#')[0];
468
608
  var title = (0, _ui_utils.getPDFFileNameFromURL)(url, '');
609
+
469
610
  if (!title) {
470
611
  try {
471
612
  title = decodeURIComponent((0, _pdf.getFilenameFromUrl)(url)) || url;
@@ -473,141 +614,219 @@ var PDFViewerApplication = {
473
614
  title = url;
474
615
  }
475
616
  }
617
+
476
618
  this.setTitle(title);
477
619
  },
478
620
  setTitle: function setTitle(title) {
479
621
  if (this.isViewerEmbedded) {
480
622
  return;
481
623
  }
624
+
482
625
  document.title = title;
483
626
  },
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;
627
+ close: function () {
628
+ var _close = _asyncToGenerator(
629
+ /*#__PURE__*/
630
+ _regenerator.default.mark(function _callee6() {
631
+ var errorWrapper, promise;
632
+ return _regenerator.default.wrap(function _callee6$(_context6) {
633
+ while (1) {
634
+ switch (_context6.prev = _context6.next) {
635
+ case 0:
636
+ errorWrapper = this.appConfig.errorWrapper.container;
637
+ errorWrapper.setAttribute('hidden', 'true');
519
638
 
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]);
639
+ if (this.pdfLoadingTask) {
640
+ _context6.next = 4;
641
+ break;
642
+ }
643
+
644
+ return _context6.abrupt("return");
645
+
646
+ case 4:
647
+ promise = this.pdfLoadingTask.destroy();
648
+ this.pdfLoadingTask = null;
649
+
650
+ if (this.pdfDocument) {
651
+ this.pdfDocument = null;
652
+ this.pdfThumbnailViewer.setDocument(null);
653
+ this.pdfViewer.setDocument(null);
654
+ this.pdfLinkService.setDocument(null);
655
+ this.pdfDocumentProperties.setDocument(null);
656
+ }
657
+
658
+ this.store = null;
659
+ this.isInitialViewSet = false;
660
+ this.downloadComplete = false;
661
+ this.url = '';
662
+ this.baseUrl = '';
663
+ this.contentDispositionFilename = null;
664
+ this.pdfSidebar.reset();
665
+ this.pdfOutlineViewer.reset();
666
+ this.pdfAttachmentViewer.reset();
667
+ this.findBar.reset();
668
+ this.toolbar.reset();
669
+ this.secondaryToolbar.reset();
670
+
671
+ if (typeof PDFBug !== 'undefined') {
672
+ PDFBug.cleanup();
673
+ }
674
+
675
+ return _context6.abrupt("return", promise);
676
+
677
+ case 21:
678
+ case "end":
679
+ return _context6.stop();
680
+ }
548
681
  }
549
- parameters[prop] = args[prop];
550
- }
682
+ }, _callee6, this);
683
+ }));
684
+
685
+ function close() {
686
+ return _close.apply(this, arguments);
551
687
  }
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');
688
+
689
+ return close;
690
+ }(),
691
+ open: function () {
692
+ var _open = _asyncToGenerator(
693
+ /*#__PURE__*/
694
+ _regenerator.default.mark(function _callee7(file, args) {
695
+ var _this2 = this;
696
+
697
+ var workerParameters, key, parameters, apiParameters, _key, prop, loadingTask;
698
+
699
+ return _regenerator.default.wrap(function _callee7$(_context7) {
700
+ while (1) {
701
+ switch (_context7.prev = _context7.next) {
702
+ case 0:
703
+ if (!this.pdfLoadingTask) {
704
+ _context7.next = 3;
705
+ break;
706
+ }
707
+
708
+ _context7.next = 3;
709
+ return this.close();
710
+
711
+ case 3:
712
+ workerParameters = _app_options.AppOptions.getAll('worker');
713
+
714
+ for (key in workerParameters) {
715
+ _pdf.GlobalWorkerOptions[key] = workerParameters[key];
716
+ }
717
+
718
+ parameters = Object.create(null);
719
+
720
+ if (typeof file === 'string') {
721
+ this.setTitleUsingUrl(file);
722
+ parameters.url = file;
723
+ } else if (file && 'byteLength' in file) {
724
+ parameters.data = file;
725
+ } else if (file.url && file.originalUrl) {
726
+ this.setTitleUsingUrl(file.originalUrl);
727
+ parameters.url = file.url;
728
+ }
729
+
730
+ apiParameters = _app_options.AppOptions.getAll('api');
731
+
732
+ for (_key in apiParameters) {
733
+ parameters[_key] = apiParameters[_key];
734
+ }
735
+
736
+ if (args) {
737
+ for (prop in args) {
738
+ if (prop === 'length') {
739
+ this.pdfDocumentProperties.setFileSize(args[prop]);
740
+ }
741
+
742
+ parameters[prop] = args[prop];
743
+ }
744
+ }
745
+
746
+ loadingTask = (0, _pdf.getDocument)(parameters);
747
+ this.pdfLoadingTask = loadingTask;
748
+
749
+ loadingTask.onPassword = function (updateCallback, reason) {
750
+ _this2.passwordPrompt.setUpdateCallback(updateCallback, reason);
751
+
752
+ _this2.passwordPrompt.open();
753
+ };
754
+
755
+ loadingTask.onProgress = function (_ref) {
756
+ var loaded = _ref.loaded,
757
+ total = _ref.total;
758
+
759
+ _this2.progress(loaded / total);
760
+ };
761
+
762
+ loadingTask.onUnsupportedFeature = this.fallback.bind(this);
763
+ return _context7.abrupt("return", loadingTask.promise.then(function (pdfDocument) {
764
+ _this2.load(pdfDocument);
765
+ }, function (exception) {
766
+ if (loadingTask !== _this2.pdfLoadingTask) {
767
+ return;
768
+ }
769
+
770
+ var message = exception && exception.message;
771
+ var loadingErrorMessage;
772
+
773
+ if (exception instanceof _pdf.InvalidPDFException) {
774
+ loadingErrorMessage = _this2.l10n.get('invalid_file_error', null, 'Invalid or corrupted PDF file.');
775
+ } else if (exception instanceof _pdf.MissingPDFException) {
776
+ loadingErrorMessage = _this2.l10n.get('missing_file_error', null, 'Missing PDF file.');
777
+ } else if (exception instanceof _pdf.UnexpectedResponseException) {
778
+ loadingErrorMessage = _this2.l10n.get('unexpected_response_error', null, 'Unexpected server response.');
779
+ } else {
780
+ loadingErrorMessage = _this2.l10n.get('loading_error', null, 'An error occurred while loading the PDF.');
781
+ }
782
+
783
+ return loadingErrorMessage.then(function (msg) {
784
+ _this2.error(msg, {
785
+ message: message
786
+ });
787
+
788
+ throw new Error(msg);
789
+ });
790
+ }));
791
+
792
+ case 16:
793
+ case "end":
794
+ return _context7.stop();
795
+ }
796
+ }
797
+ }, _callee7, this);
798
+ }));
799
+
800
+ function open(_x2, _x3) {
801
+ return _open.apply(this, arguments);
556
802
  }
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
803
 
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
- },
804
+ return open;
805
+ }(),
593
806
  download: function download() {
594
- var _this4 = this;
807
+ var _this3 = this;
595
808
 
596
809
  function downloadByUrl() {
597
810
  downloadManager.downloadUrl(url, filename);
598
811
  }
812
+
599
813
  var url = this.baseUrl;
600
814
  var filename = this.contentDispositionFilename || (0, _ui_utils.getPDFFileNameFromURL)(this.url);
601
815
  var downloadManager = this.downloadManager;
816
+
602
817
  downloadManager.onerror = function (err) {
603
- _this4.error('PDF failed to download: ' + err);
818
+ _this3.error("PDF failed to download: ".concat(err));
604
819
  };
820
+
605
821
  if (!this.pdfDocument || !this.downloadComplete) {
606
822
  downloadByUrl();
607
823
  return;
608
824
  }
825
+
609
826
  this.pdfDocument.getData().then(function (data) {
610
- var blob = (0, _pdf.createBlob)(data, 'application/pdf');
827
+ var blob = new Blob([data], {
828
+ type: 'application/pdf'
829
+ });
611
830
  downloadManager.download(blob, url, filename);
612
831
  }).catch(downloadByUrl);
613
832
  },
@@ -617,42 +836,59 @@ var PDFViewerApplication = {
617
836
  version: _pdf.version || '?',
618
837
  build: _pdf.build || '?'
619
838
  }, 'PDF.js v{{version}} (build: {{build}})')];
839
+
620
840
  if (moreInfo) {
621
- moreInfoText.push(this.l10n.get('error_message', { message: moreInfo.message }, 'Message: {{message}}'));
841
+ moreInfoText.push(this.l10n.get('error_message', {
842
+ message: moreInfo.message
843
+ }, 'Message: {{message}}'));
844
+
622
845
  if (moreInfo.stack) {
623
- moreInfoText.push(this.l10n.get('error_stack', { stack: moreInfo.stack }, 'Stack: {{stack}}'));
846
+ moreInfoText.push(this.l10n.get('error_stack', {
847
+ stack: moreInfo.stack
848
+ }, 'Stack: {{stack}}'));
624
849
  } else {
625
850
  if (moreInfo.filename) {
626
- moreInfoText.push(this.l10n.get('error_file', { file: moreInfo.filename }, 'File: {{file}}'));
851
+ moreInfoText.push(this.l10n.get('error_file', {
852
+ file: moreInfo.filename
853
+ }, 'File: {{file}}'));
627
854
  }
855
+
628
856
  if (moreInfo.lineNumber) {
629
- moreInfoText.push(this.l10n.get('error_line', { line: moreInfo.lineNumber }, 'Line: {{line}}'));
857
+ moreInfoText.push(this.l10n.get('error_line', {
858
+ line: moreInfo.lineNumber
859
+ }, 'Line: {{line}}'));
630
860
  }
631
861
  }
632
862
  }
863
+
633
864
  var errorWrapperConfig = this.appConfig.errorWrapper;
634
865
  var errorWrapper = errorWrapperConfig.container;
635
866
  errorWrapper.removeAttribute('hidden');
636
867
  var errorMessage = errorWrapperConfig.errorMessage;
637
868
  errorMessage.textContent = message;
638
869
  var closeButton = errorWrapperConfig.closeButton;
870
+
639
871
  closeButton.onclick = function () {
640
872
  errorWrapper.setAttribute('hidden', 'true');
641
873
  };
874
+
642
875
  var errorMoreInfo = errorWrapperConfig.errorMoreInfo;
643
876
  var moreInfoButton = errorWrapperConfig.moreInfoButton;
644
877
  var lessInfoButton = errorWrapperConfig.lessInfoButton;
878
+
645
879
  moreInfoButton.onclick = function () {
646
880
  errorMoreInfo.removeAttribute('hidden');
647
881
  moreInfoButton.setAttribute('hidden', 'true');
648
882
  lessInfoButton.removeAttribute('hidden');
649
883
  errorMoreInfo.style.height = errorMoreInfo.scrollHeight + 'px';
650
884
  };
885
+
651
886
  lessInfoButton.onclick = function () {
652
887
  errorMoreInfo.setAttribute('hidden', 'true');
653
888
  moreInfoButton.removeAttribute('hidden');
654
889
  lessInfoButton.setAttribute('hidden', 'true');
655
890
  };
891
+
656
892
  moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
657
893
  lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
658
894
  closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
@@ -663,45 +899,54 @@ var PDFViewerApplication = {
663
899
  });
664
900
  },
665
901
  progress: function progress(level) {
666
- var _this5 = this;
902
+ var _this4 = this;
667
903
 
668
904
  if (this.downloadComplete) {
669
905
  return;
670
906
  }
907
+
671
908
  var percent = Math.round(level * 100);
909
+
672
910
  if (percent > this.loadingBar.percent || isNaN(percent)) {
673
911
  this.loadingBar.percent = percent;
674
912
  var disableAutoFetch = this.pdfDocument ? this.pdfDocument.loadingParams['disableAutoFetch'] : _app_options.AppOptions.get('disableAutoFetch');
913
+
675
914
  if (disableAutoFetch && percent) {
676
915
  if (this.disableAutoFetchLoadingBarTimeout) {
677
916
  clearTimeout(this.disableAutoFetchLoadingBarTimeout);
678
917
  this.disableAutoFetchLoadingBarTimeout = null;
679
918
  }
919
+
680
920
  this.loadingBar.show();
681
921
  this.disableAutoFetchLoadingBarTimeout = setTimeout(function () {
682
- _this5.loadingBar.hide();
683
- _this5.disableAutoFetchLoadingBarTimeout = null;
922
+ _this4.loadingBar.hide();
923
+
924
+ _this4.disableAutoFetchLoadingBarTimeout = null;
684
925
  }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
685
926
  }
686
927
  }
687
928
  },
688
929
  load: function load(pdfDocument) {
689
- var _this6 = this;
930
+ var _this5 = this;
690
931
 
691
932
  this.pdfDocument = pdfDocument;
692
933
  pdfDocument.getDownloadInfo().then(function () {
693
- _this6.downloadComplete = true;
694
- _this6.loadingBar.hide();
934
+ _this5.downloadComplete = true;
935
+
936
+ _this5.loadingBar.hide();
937
+
695
938
  firstPagePromise.then(function () {
696
- _this6.eventBus.dispatch('documentload', { source: _this6 });
939
+ _this5.eventBus.dispatch('documentloaded', {
940
+ source: _this5
941
+ });
697
942
  });
698
943
  });
699
944
  var pageModePromise = pdfDocument.getPageMode().catch(function () {});
945
+ var openActionDestPromise = pdfDocument.getOpenActionDestination().catch(function () {});
700
946
  this.toolbar.setPagesCount(pdfDocument.numPages, false);
701
947
  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;
948
+ var store = this.store = new _view_history.ViewHistory(pdfDocument.fingerprint);
949
+ var baseDocumentUrl;
705
950
  baseDocumentUrl = null;
706
951
  this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
707
952
  this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
@@ -713,75 +958,123 @@ var PDFViewerApplication = {
713
958
  var pdfThumbnailViewer = this.pdfThumbnailViewer;
714
959
  pdfThumbnailViewer.setDocument(pdfDocument);
715
960
  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
- };
961
+ _this5.loadingBar.setWidth(_this5.appConfig.viewerContainer);
962
+
729
963
  var storePromise = store.getMultiple({
730
- exists: false,
731
- page: '1',
964
+ page: null,
732
965
  zoom: _ui_utils.DEFAULT_SCALE_VALUE,
733
966
  scrollLeft: '0',
734
967
  scrollTop: '0',
735
968
  rotation: null,
736
- sidebarView: _pdf_sidebar.SidebarView.NONE
969
+ sidebarView: _pdf_sidebar.SidebarView.UNKNOWN,
970
+ scrollMode: _ui_utils.ScrollMode.UNKNOWN,
971
+ spreadMode: _ui_utils.SpreadMode.UNKNOWN
737
972
  }).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
973
+ Promise.all([storePromise, pageModePromise, openActionDestPromise]).then(
974
+ /*#__PURE__*/
975
+ function () {
976
+ var _ref3 = _asyncToGenerator(
977
+ /*#__PURE__*/
978
+ _regenerator.default.mark(function _callee8(_ref2) {
979
+ var _ref4, _ref4$, values, pageMode, openActionDest, viewOnLoad, initialBookmark, zoom, hash, rotation, sidebarView, scrollMode, spreadMode;
980
+
981
+ return _regenerator.default.wrap(function _callee8$(_context8) {
982
+ while (1) {
983
+ switch (_context8.prev = _context8.next) {
984
+ case 0:
985
+ _ref4 = _slicedToArray(_ref2, 3), _ref4$ = _ref4[0], values = _ref4$ === void 0 ? {} : _ref4$, pageMode = _ref4[1], openActionDest = _ref4[2];
986
+ viewOnLoad = _app_options.AppOptions.get('viewOnLoad');
987
+
988
+ _this5._initializePdfHistory({
989
+ fingerprint: pdfDocument.fingerprint,
990
+ viewOnLoad: viewOnLoad,
991
+ initialDest: openActionDest
992
+ });
993
+
994
+ initialBookmark = _this5.initialBookmark;
995
+ zoom = _app_options.AppOptions.get('defaultZoomValue');
996
+ hash = zoom ? "zoom=".concat(zoom) : null;
997
+ rotation = null;
998
+ sidebarView = _app_options.AppOptions.get('sidebarViewOnLoad');
999
+ scrollMode = _app_options.AppOptions.get('scrollModeOnLoad');
1000
+ spreadMode = _app_options.AppOptions.get('spreadModeOnLoad');
1001
+
1002
+ if (values.page && viewOnLoad !== ViewOnLoad.INITIAL) {
1003
+ hash = "page=".concat(values.page, "&zoom=").concat(zoom || values.zoom, ",") + "".concat(values.scrollLeft, ",").concat(values.scrollTop);
1004
+ rotation = parseInt(values.rotation, 10);
1005
+
1006
+ if (sidebarView === _pdf_sidebar.SidebarView.UNKNOWN) {
1007
+ sidebarView = values.sidebarView | 0;
1008
+ }
1009
+
1010
+ if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
1011
+ scrollMode = values.scrollMode | 0;
1012
+ }
1013
+
1014
+ if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
1015
+ spreadMode = values.spreadMode | 0;
1016
+ }
1017
+ }
1018
+
1019
+ if (pageMode && sidebarView === _pdf_sidebar.SidebarView.UNKNOWN) {
1020
+ sidebarView = apiPageModeToSidebarView(pageMode);
1021
+ }
1022
+
1023
+ _this5.setInitialView(hash, {
1024
+ rotation: rotation,
1025
+ sidebarView: sidebarView,
1026
+ scrollMode: scrollMode,
1027
+ spreadMode: spreadMode
1028
+ });
1029
+
1030
+ _this5.eventBus.dispatch('documentinit', {
1031
+ source: _this5
1032
+ });
1033
+
1034
+ if (!_this5.isViewerEmbedded) {
1035
+ pdfViewer.focus();
1036
+ }
1037
+
1038
+ _context8.next = 17;
1039
+ return Promise.race([pagesPromise, new Promise(function (resolve) {
1040
+ setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
1041
+ })]);
1042
+
1043
+ case 17:
1044
+ if (!(!initialBookmark && !hash)) {
1045
+ _context8.next = 19;
1046
+ break;
1047
+ }
1048
+
1049
+ return _context8.abrupt("return");
1050
+
1051
+ case 19:
1052
+ if (!pdfViewer.hasEqualPageSizes) {
1053
+ _context8.next = 21;
1054
+ break;
1055
+ }
1056
+
1057
+ return _context8.abrupt("return");
1058
+
1059
+ case 21:
1060
+ _this5.initialBookmark = initialBookmark;
1061
+ pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
1062
+
1063
+ _this5.setInitialView(hash);
1064
+
1065
+ case 24:
1066
+ case "end":
1067
+ return _context8.stop();
1068
+ }
1069
+ }
1070
+ }, _callee8, this);
1071
+ }));
1072
+
1073
+ return function (_x4) {
1074
+ return _ref3.apply(this, arguments);
759
1075
  };
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);
1076
+ }()).catch(function () {
1077
+ _this5.setInitialView();
785
1078
  }).then(function () {
786
1079
  pdfViewer.update();
787
1080
  });
@@ -790,42 +1083,56 @@ var PDFViewerApplication = {
790
1083
  if (!labels || _app_options.AppOptions.get('disablePageLabels')) {
791
1084
  return;
792
1085
  }
1086
+
793
1087
  var i = 0,
794
1088
  numLabels = labels.length;
795
- if (numLabels !== _this6.pagesCount) {
1089
+
1090
+ if (numLabels !== _this5.pagesCount) {
796
1091
  console.error('The number of Page Labels does not match ' + 'the number of pages in the document.');
797
1092
  return;
798
1093
  }
1094
+
799
1095
  while (i < numLabels && labels[i] === (i + 1).toString()) {
800
1096
  i++;
801
1097
  }
1098
+
802
1099
  if (i === numLabels) {
803
1100
  return;
804
1101
  }
1102
+
805
1103
  pdfViewer.setPageLabels(labels);
806
1104
  pdfThumbnailViewer.setPageLabels(labels);
807
- _this6.toolbar.setPagesCount(pdfDocument.numPages, true);
808
- _this6.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
1105
+
1106
+ _this5.toolbar.setPagesCount(pdfDocument.numPages, true);
1107
+
1108
+ _this5.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
809
1109
  });
810
1110
  pagesPromise.then(function () {
811
- if (!_this6.supportsPrinting) {
1111
+ if (!_this5.supportsPrinting) {
812
1112
  return;
813
1113
  }
1114
+
814
1115
  pdfDocument.getJavaScript().then(function (javaScript) {
815
1116
  if (!javaScript) {
816
1117
  return;
817
1118
  }
1119
+
818
1120
  javaScript.some(function (js) {
819
1121
  if (!js) {
820
1122
  return false;
821
1123
  }
1124
+
822
1125
  console.warn('Warning: JavaScript is not supported');
823
- _this6.fallback(_pdf.UNSUPPORTED_FEATURES.javaScript);
1126
+
1127
+ _this5.fallback(_pdf.UNSUPPORTED_FEATURES.javaScript);
1128
+
824
1129
  return true;
825
1130
  });
826
1131
  var regex = /\bprint\s*\(/;
1132
+
827
1133
  for (var i = 0, ii = javaScript.length; i < ii; i++) {
828
1134
  var js = javaScript[i];
1135
+
829
1136
  if (js && regex.test(js)) {
830
1137
  setTimeout(function () {
831
1138
  window.print();
@@ -837,56 +1144,109 @@ var PDFViewerApplication = {
837
1144
  });
838
1145
  Promise.all([onePageRendered, _ui_utils.animationStarted]).then(function () {
839
1146
  pdfDocument.getOutline().then(function (outline) {
840
- _this6.pdfOutlineViewer.render({ outline: outline });
1147
+ _this5.pdfOutlineViewer.render({
1148
+ outline: outline
1149
+ });
841
1150
  });
842
1151
  pdfDocument.getAttachments().then(function (attachments) {
843
- _this6.pdfAttachmentViewer.render({ attachments: attachments });
1152
+ _this5.pdfAttachmentViewer.render({
1153
+ attachments: attachments
1154
+ });
844
1155
  });
845
1156
  });
846
1157
  pdfDocument.getMetadata().then(function (_ref5) {
847
1158
  var info = _ref5.info,
848
1159
  metadata = _ref5.metadata,
849
1160
  contentDispositionFilename = _ref5.contentDispositionFilename;
850
-
851
- _this6.documentInfo = info;
852
- _this6.metadata = metadata;
853
- _this6.contentDispositionFilename = contentDispositionFilename;
1161
+ _this5.documentInfo = info;
1162
+ _this5.metadata = metadata;
1163
+ _this5.contentDispositionFilename = contentDispositionFilename;
854
1164
  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;
1165
+ var pdfTitle;
1166
+
856
1167
  if (metadata && metadata.has('dc:title')) {
857
1168
  var title = metadata.get('dc:title');
1169
+
858
1170
  if (title !== 'Untitled') {
859
1171
  pdfTitle = title;
860
1172
  }
861
1173
  }
1174
+
862
1175
  if (!pdfTitle && info && info['Title']) {
863
1176
  pdfTitle = info['Title'];
864
1177
  }
1178
+
865
1179
  if (pdfTitle) {
866
- _this6.setTitle(pdfTitle + ' - ' + (contentDispositionFilename || document.title));
1180
+ _this5.setTitle("".concat(pdfTitle, " - ").concat(contentDispositionFilename || document.title));
867
1181
  } else if (contentDispositionFilename) {
868
- _this6.setTitle(contentDispositionFilename);
1182
+ _this5.setTitle(contentDispositionFilename);
869
1183
  }
1184
+
870
1185
  if (info.IsAcroFormPresent) {
871
1186
  console.warn('Warning: AcroForm/XFA is not supported');
872
- _this6.fallback(_pdf.UNSUPPORTED_FEATURES.forms);
1187
+
1188
+ _this5.fallback(_pdf.UNSUPPORTED_FEATURES.forms);
873
1189
  }
874
1190
  });
875
1191
  },
1192
+ _initializePdfHistory: function _initializePdfHistory(_ref6) {
1193
+ var fingerprint = _ref6.fingerprint,
1194
+ viewOnLoad = _ref6.viewOnLoad,
1195
+ _ref6$initialDest = _ref6.initialDest,
1196
+ initialDest = _ref6$initialDest === void 0 ? null : _ref6$initialDest;
1197
+
1198
+ if (_app_options.AppOptions.get('disableHistory') || this.isViewerEmbedded) {
1199
+ return;
1200
+ }
1201
+
1202
+ this.pdfHistory.initialize({
1203
+ fingerprint: fingerprint,
1204
+ resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
1205
+ updateUrl: _app_options.AppOptions.get('historyUpdateUrl')
1206
+ });
1207
+
1208
+ if (this.pdfHistory.initialBookmark) {
1209
+ this.initialBookmark = this.pdfHistory.initialBookmark;
1210
+ this.initialRotation = this.pdfHistory.initialRotation;
1211
+ }
1212
+
1213
+ if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
1214
+ this.initialBookmark = JSON.stringify(initialDest);
1215
+ this.pdfHistory.push({
1216
+ explicitDest: initialDest,
1217
+ pageNumber: null
1218
+ });
1219
+ }
1220
+ },
876
1221
  setInitialView: function setInitialView(storedHash) {
877
- var _this7 = this;
1222
+ var _this6 = this;
878
1223
 
879
- var _ref6 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
880
- rotation = _ref6.rotation,
881
- sidebarView = _ref6.sidebarView;
1224
+ var _ref7 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
1225
+ rotation = _ref7.rotation,
1226
+ sidebarView = _ref7.sidebarView,
1227
+ scrollMode = _ref7.scrollMode,
1228
+ spreadMode = _ref7.spreadMode;
882
1229
 
883
1230
  var setRotation = function setRotation(angle) {
884
1231
  if ((0, _ui_utils.isValidRotation)(angle)) {
885
- _this7.pdfViewer.pagesRotation = angle;
1232
+ _this6.pdfViewer.pagesRotation = angle;
1233
+ }
1234
+ };
1235
+
1236
+ var setViewerModes = function setViewerModes(scroll, spread) {
1237
+ if ((0, _ui_utils.isValidScrollMode)(scroll)) {
1238
+ _this6.pdfViewer.scrollMode = scroll;
1239
+ }
1240
+
1241
+ if ((0, _ui_utils.isValidSpreadMode)(spread)) {
1242
+ _this6.pdfViewer.spreadMode = spread;
886
1243
  }
887
1244
  };
1245
+
888
1246
  this.isInitialViewSet = true;
889
1247
  this.pdfSidebar.setInitialView(sidebarView);
1248
+ setViewerModes(scrollMode, spreadMode);
1249
+
890
1250
  if (this.initialBookmark) {
891
1251
  setRotation(this.initialRotation);
892
1252
  delete this.initialRotation;
@@ -896,8 +1256,10 @@ var PDFViewerApplication = {
896
1256
  setRotation(rotation);
897
1257
  this.pdfLinkService.setHash(storedHash);
898
1258
  }
1259
+
899
1260
  this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
900
1261
  this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
1262
+
901
1263
  if (!this.pdfViewer.currentScaleValue) {
902
1264
  this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
903
1265
  }
@@ -906,8 +1268,10 @@ var PDFViewerApplication = {
906
1268
  if (!this.pdfDocument) {
907
1269
  return;
908
1270
  }
1271
+
909
1272
  this.pdfViewer.cleanup();
910
1273
  this.pdfThumbnailViewer.cleanup();
1274
+
911
1275
  if (this.pdfViewer.renderer !== _ui_utils.RendererType.SVG) {
912
1276
  this.pdfDocument.cleanup();
913
1277
  }
@@ -918,23 +1282,26 @@ var PDFViewerApplication = {
918
1282
  this.pdfRenderingQueue.renderHighestPriority();
919
1283
  },
920
1284
  beforePrint: function beforePrint() {
921
- var _this8 = this;
1285
+ var _this7 = this;
922
1286
 
923
1287
  if (this.printService) {
924
1288
  return;
925
1289
  }
1290
+
926
1291
  if (!this.supportsPrinting) {
927
1292
  this.l10n.get('printing_not_supported', null, 'Warning: Printing is not fully supported by ' + 'this browser.').then(function (printMessage) {
928
- _this8.error(printMessage);
1293
+ _this7.error(printMessage);
929
1294
  });
930
1295
  return;
931
1296
  }
1297
+
932
1298
  if (!this.pdfViewer.pageViewsReady) {
933
1299
  this.l10n.get('printing_not_ready', null, 'Warning: The PDF is not fully loaded for printing.').then(function (notReadyMessage) {
934
1300
  window.alert(notReadyMessage);
935
1301
  });
936
1302
  return;
937
1303
  }
1304
+
938
1305
  var pagesOverview = this.pdfViewer.getPagesOverview();
939
1306
  var printContainer = this.appConfig.printContainer;
940
1307
  var printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, this.l10n);
@@ -942,18 +1309,19 @@ var PDFViewerApplication = {
942
1309
  this.forceRendering();
943
1310
  printService.layout();
944
1311
  },
945
-
946
1312
  afterPrint: function pdfViewSetupAfterPrint() {
947
1313
  if (this.printService) {
948
1314
  this.printService.destroy();
949
1315
  this.printService = null;
950
1316
  }
1317
+
951
1318
  this.forceRendering();
952
1319
  },
953
1320
  rotatePages: function rotatePages(delta) {
954
1321
  if (!this.pdfDocument) {
955
1322
  return;
956
1323
  }
1324
+
957
1325
  var newRotation = (this.pdfViewer.pagesRotation + 360 + delta) % 360;
958
1326
  this.pdfViewer.pagesRotation = newRotation;
959
1327
  },
@@ -961,12 +1329,12 @@ var PDFViewerApplication = {
961
1329
  if (!this.pdfPresentationMode) {
962
1330
  return;
963
1331
  }
1332
+
964
1333
  this.pdfPresentationMode.request();
965
1334
  },
966
1335
  bindEvents: function bindEvents() {
967
1336
  var eventBus = this.eventBus,
968
1337
  _boundEvents = this._boundEvents;
969
-
970
1338
  _boundEvents.beforePrint = this.beforePrint.bind(this);
971
1339
  _boundEvents.afterPrint = this.afterPrint.bind(this);
972
1340
  eventBus.on('resize', webViewerResize);
@@ -997,9 +1365,15 @@ var PDFViewerApplication = {
997
1365
  eventBus.on('scalechanged', webViewerScaleChanged);
998
1366
  eventBus.on('rotatecw', webViewerRotateCw);
999
1367
  eventBus.on('rotateccw', webViewerRotateCcw);
1368
+ eventBus.on('switchscrollmode', webViewerSwitchScrollMode);
1369
+ eventBus.on('scrollmodechanged', webViewerScrollModeChanged);
1370
+ eventBus.on('switchspreadmode', webViewerSwitchSpreadMode);
1371
+ eventBus.on('spreadmodechanged', webViewerSpreadModeChanged);
1000
1372
  eventBus.on('documentproperties', webViewerDocumentProperties);
1001
1373
  eventBus.on('find', webViewerFind);
1002
1374
  eventBus.on('findfromurlhash', webViewerFindFromUrlHash);
1375
+ eventBus.on('updatefindmatchescount', webViewerUpdateFindMatchesCount);
1376
+ eventBus.on('updatefindcontrolstate', webViewerUpdateFindControlState);
1003
1377
  eventBus.on('fileinputchange', webViewerFileInputChange);
1004
1378
  },
1005
1379
  bindWindowEvents: function bindWindowEvents() {
@@ -1007,17 +1381,31 @@ var PDFViewerApplication = {
1007
1381
  _boundEvents = this._boundEvents;
1008
1382
 
1009
1383
  _boundEvents.windowResize = function () {
1010
- eventBus.dispatch('resize', { source: window });
1384
+ eventBus.dispatch('resize', {
1385
+ source: window
1386
+ });
1011
1387
  };
1388
+
1012
1389
  _boundEvents.windowHashChange = function () {
1013
- eventBus.dispatch('hashchange', { hash: document.location.hash.substring(1) });
1390
+ eventBus.dispatch('hashchange', {
1391
+ source: window,
1392
+ hash: document.location.hash.substring(1)
1393
+ });
1014
1394
  };
1395
+
1015
1396
  _boundEvents.windowBeforePrint = function () {
1016
- eventBus.dispatch('beforeprint');
1397
+ eventBus.dispatch('beforeprint', {
1398
+ source: window
1399
+ });
1017
1400
  };
1401
+
1018
1402
  _boundEvents.windowAfterPrint = function () {
1019
- eventBus.dispatch('afterprint');
1403
+ eventBus.dispatch('afterprint', {
1404
+ source: window
1405
+ });
1020
1406
  };
1407
+
1408
+ window.addEventListener('visibilitychange', webViewerVisibilityChange);
1021
1409
  window.addEventListener('wheel', webViewerWheel);
1022
1410
  window.addEventListener('click', webViewerClick);
1023
1411
  window.addEventListener('keydown', webViewerKeyDown);
@@ -1029,7 +1417,6 @@ var PDFViewerApplication = {
1029
1417
  unbindEvents: function unbindEvents() {
1030
1418
  var eventBus = this.eventBus,
1031
1419
  _boundEvents = this._boundEvents;
1032
-
1033
1420
  eventBus.off('resize', webViewerResize);
1034
1421
  eventBus.off('hashchange', webViewerHashchange);
1035
1422
  eventBus.off('beforeprint', _boundEvents.beforePrint);
@@ -1058,16 +1445,22 @@ var PDFViewerApplication = {
1058
1445
  eventBus.off('scalechanged', webViewerScaleChanged);
1059
1446
  eventBus.off('rotatecw', webViewerRotateCw);
1060
1447
  eventBus.off('rotateccw', webViewerRotateCcw);
1448
+ eventBus.off('switchscrollmode', webViewerSwitchScrollMode);
1449
+ eventBus.off('scrollmodechanged', webViewerScrollModeChanged);
1450
+ eventBus.off('switchspreadmode', webViewerSwitchSpreadMode);
1451
+ eventBus.off('spreadmodechanged', webViewerSpreadModeChanged);
1061
1452
  eventBus.off('documentproperties', webViewerDocumentProperties);
1062
1453
  eventBus.off('find', webViewerFind);
1063
1454
  eventBus.off('findfromurlhash', webViewerFindFromUrlHash);
1455
+ eventBus.off('updatefindmatchescount', webViewerUpdateFindMatchesCount);
1456
+ eventBus.off('updatefindcontrolstate', webViewerUpdateFindControlState);
1064
1457
  eventBus.off('fileinputchange', webViewerFileInputChange);
1065
1458
  _boundEvents.beforePrint = null;
1066
1459
  _boundEvents.afterPrint = null;
1067
1460
  },
1068
1461
  unbindWindowEvents: function unbindWindowEvents() {
1069
1462
  var _boundEvents = this._boundEvents;
1070
-
1463
+ window.removeEventListener('visibilitychange', webViewerVisibilityChange);
1071
1464
  window.removeEventListener('wheel', webViewerWheel);
1072
1465
  window.removeEventListener('click', webViewerClick);
1073
1466
  window.removeEventListener('keydown', webViewerKeyDown);
@@ -1081,22 +1474,26 @@ var PDFViewerApplication = {
1081
1474
  _boundEvents.windowAfterPrint = null;
1082
1475
  }
1083
1476
  };
1084
- var validateFileURL = void 0;
1477
+ exports.PDFViewerApplication = PDFViewerApplication;
1478
+ var validateFileURL;
1085
1479
  {
1086
1480
  var HOSTED_VIEWER_ORIGINS = ['null', 'http://mozilla.github.io', 'https://mozilla.github.io'];
1481
+
1087
1482
  validateFileURL = function validateFileURL(file) {
1088
1483
  if (file === undefined) {
1089
1484
  return;
1090
1485
  }
1486
+
1091
1487
  try {
1092
- var viewerOrigin = new URL(window.location.href).origin || 'null';
1488
+ var viewerOrigin = new _pdf.URL(window.location.href).origin || 'null';
1489
+
1093
1490
  if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
1094
1491
  return;
1095
1492
  }
1096
1493
 
1097
- var _ref7 = new URL(file, window.location.href),
1098
- origin = _ref7.origin,
1099
- protocol = _ref7.protocol;
1494
+ var _ref8 = new _pdf.URL(file, window.location.href),
1495
+ origin = _ref8.origin,
1496
+ protocol = _ref8.protocol;
1100
1497
 
1101
1498
  if (origin !== viewerOrigin && protocol !== 'blob:') {
1102
1499
  throw new Error('file origin does not match viewer\'s');
@@ -1104,47 +1501,37 @@ var validateFileURL = void 0;
1104
1501
  } catch (ex) {
1105
1502
  var message = ex && ex.message;
1106
1503
  PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (loadingErrorMessage) {
1107
- PDFViewerApplication.error(loadingErrorMessage, { message: message });
1504
+ PDFViewerApplication.error(loadingErrorMessage, {
1505
+ message: message
1506
+ });
1108
1507
  });
1109
1508
  throw ex;
1110
1509
  }
1111
1510
  };
1112
1511
  }
1512
+
1113
1513
  function 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
- });
1514
+ if (!_pdf.GlobalWorkerOptions.workerSrc) {
1515
+ _pdf.GlobalWorkerOptions.workerSrc = _app_options.AppOptions.get('workerSrc');
1516
+ }
1517
+
1518
+ return (0, _pdf.loadScript)(_pdf.PDFWorker.getWorkerSrc());
1128
1519
  }
1129
- function 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);
1520
+
1521
+ function loadAndEnablePDFBug(enabledTabs) {
1522
+ var appConfig = PDFViewerApplication.appConfig;
1523
+ return (0, _pdf.loadScript)(appConfig.debuggerScriptPath).then(function () {
1524
+ PDFBug.enable(enabledTabs);
1525
+ PDFBug.init({
1526
+ OPS: _pdf.OPS,
1527
+ createObjectURL: _pdf.createObjectURL
1528
+ }, appConfig.mainContainer);
1143
1529
  });
1144
1530
  }
1531
+
1145
1532
  function webViewerInitialized() {
1146
1533
  var appConfig = PDFViewerApplication.appConfig;
1147
- var file = void 0;
1534
+ var file;
1148
1535
  var queryString = document.location.search.substring(1);
1149
1536
  var params = (0, _ui_utils.parseQueryString)(queryString);
1150
1537
  file = 'file' in params ? params.file : _app_options.AppOptions.get('defaultUrl');
@@ -1155,148 +1542,200 @@ function webViewerInitialized() {
1155
1542
  fileInput.setAttribute('type', 'file');
1156
1543
  fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
1157
1544
  document.body.appendChild(fileInput);
1545
+
1158
1546
  if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
1159
1547
  appConfig.toolbar.openFile.setAttribute('hidden', 'true');
1160
1548
  appConfig.secondaryToolbar.openFileButton.setAttribute('hidden', 'true');
1161
1549
  } else {
1162
1550
  fileInput.value = null;
1163
1551
  }
1552
+
1164
1553
  fileInput.addEventListener('change', function (evt) {
1165
1554
  var files = evt.target.files;
1555
+
1556
+ if (!files || files.length === 0) {
1557
+ return;
1558
+ }
1559
+
1560
+ PDFViewerApplication.eventBus.dispatch('fileinputchange', {
1561
+ source: this,
1562
+ fileInput: evt.target
1563
+ });
1564
+ });
1565
+ appConfig.mainContainer.addEventListener('dragover', function (evt) {
1566
+ evt.preventDefault();
1567
+ evt.dataTransfer.dropEffect = 'move';
1568
+ });
1569
+ appConfig.mainContainer.addEventListener('drop', function (evt) {
1570
+ evt.preventDefault();
1571
+ var files = evt.dataTransfer.files;
1572
+
1166
1573
  if (!files || files.length === 0) {
1167
1574
  return;
1168
1575
  }
1169
- PDFViewerApplication.eventBus.dispatch('fileinputchange', { fileInput: evt.target });
1576
+
1577
+ PDFViewerApplication.eventBus.dispatch('fileinputchange', {
1578
+ source: this,
1579
+ fileInput: evt.dataTransfer
1580
+ });
1170
1581
  });
1582
+
1171
1583
  if (!PDFViewerApplication.supportsPrinting) {
1172
1584
  appConfig.toolbar.print.classList.add('hidden');
1173
1585
  appConfig.secondaryToolbar.printButton.classList.add('hidden');
1174
1586
  }
1587
+
1175
1588
  if (!PDFViewerApplication.supportsFullscreen) {
1176
1589
  appConfig.toolbar.presentationModeButton.classList.add('hidden');
1177
1590
  appConfig.secondaryToolbar.presentationModeButton.classList.add('hidden');
1178
1591
  }
1592
+
1179
1593
  if (PDFViewerApplication.supportsIntegratedFind) {
1180
1594
  appConfig.toolbar.viewFind.classList.add('hidden');
1181
1595
  }
1596
+
1182
1597
  appConfig.mainContainer.addEventListener('transitionend', function (evt) {
1183
1598
  if (evt.target === this) {
1184
- PDFViewerApplication.eventBus.dispatch('resize', { source: this });
1599
+ PDFViewerApplication.eventBus.dispatch('resize', {
1600
+ source: this
1601
+ });
1185
1602
  }
1186
1603
  }, true);
1187
1604
  appConfig.sidebar.toggleButton.addEventListener('click', function () {
1188
1605
  PDFViewerApplication.pdfSidebar.toggle();
1189
1606
  });
1190
- Promise.resolve().then(function () {
1607
+
1608
+ try {
1191
1609
  webViewerOpenFileViaURL(file);
1192
- }).catch(function (reason) {
1610
+ } catch (reason) {
1193
1611
  PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (msg) {
1194
1612
  PDFViewerApplication.error(msg, reason);
1195
1613
  });
1196
- });
1614
+ }
1197
1615
  }
1198
- var webViewerOpenFileViaURL = void 0;
1616
+
1617
+ var webViewerOpenFileViaURL;
1199
1618
  {
1200
1619
  webViewerOpenFileViaURL = function webViewerOpenFileViaURL(file) {
1201
1620
  if (file && file.lastIndexOf('file:', 0) === 0) {
1202
1621
  PDFViewerApplication.setTitleUsingUrl(file);
1203
1622
  var xhr = new XMLHttpRequest();
1623
+
1204
1624
  xhr.onload = function () {
1205
1625
  PDFViewerApplication.open(new Uint8Array(xhr.response));
1206
1626
  };
1207
- try {
1208
- xhr.open('GET', file);
1209
- xhr.responseType = 'arraybuffer';
1210
- xhr.send();
1211
- } catch (ex) {
1212
- throw ex;
1213
- }
1627
+
1628
+ xhr.open('GET', file);
1629
+ xhr.responseType = 'arraybuffer';
1630
+ xhr.send();
1214
1631
  return;
1215
1632
  }
1633
+
1216
1634
  if (file) {
1217
1635
  PDFViewerApplication.open(file);
1218
1636
  }
1219
1637
  };
1220
1638
  }
1639
+
1221
1640
  function webViewerPageRendered(evt) {
1222
1641
  var pageNumber = evt.pageNumber;
1223
1642
  var pageIndex = pageNumber - 1;
1224
1643
  var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
1644
+
1225
1645
  if (pageNumber === PDFViewerApplication.page) {
1226
1646
  PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
1227
1647
  }
1648
+
1228
1649
  if (!pageView) {
1229
1650
  return;
1230
1651
  }
1652
+
1231
1653
  if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
1232
1654
  var thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageIndex);
1233
1655
  thumbnailView.setImage(pageView);
1234
1656
  }
1657
+
1235
1658
  if (typeof Stats !== 'undefined' && Stats.enabled && pageView.stats) {
1236
1659
  Stats.add(pageNumber, pageView.stats);
1237
1660
  }
1661
+
1238
1662
  if (pageView.error) {
1239
1663
  PDFViewerApplication.l10n.get('rendering_error', null, 'An error occurred while rendering the page.').then(function (msg) {
1240
1664
  PDFViewerApplication.error(msg, pageView.error);
1241
1665
  });
1242
1666
  }
1243
1667
  }
1668
+
1244
1669
  function webViewerTextLayerRendered(evt) {}
1670
+
1245
1671
  function webViewerPageMode(evt) {
1246
1672
  var mode = evt.mode,
1247
- view = void 0;
1673
+ view;
1674
+
1248
1675
  switch (mode) {
1249
1676
  case 'thumbs':
1250
1677
  view = _pdf_sidebar.SidebarView.THUMBS;
1251
1678
  break;
1679
+
1252
1680
  case 'bookmarks':
1253
1681
  case 'outline':
1254
1682
  view = _pdf_sidebar.SidebarView.OUTLINE;
1255
1683
  break;
1684
+
1256
1685
  case 'attachments':
1257
1686
  view = _pdf_sidebar.SidebarView.ATTACHMENTS;
1258
1687
  break;
1688
+
1259
1689
  case 'none':
1260
1690
  view = _pdf_sidebar.SidebarView.NONE;
1261
1691
  break;
1692
+
1262
1693
  default:
1263
1694
  console.error('Invalid "pagemode" hash parameter: ' + mode);
1264
1695
  return;
1265
1696
  }
1697
+
1266
1698
  PDFViewerApplication.pdfSidebar.switchView(view, true);
1267
1699
  }
1700
+
1268
1701
  function webViewerNamedAction(evt) {
1269
1702
  var action = evt.action;
1703
+
1270
1704
  switch (action) {
1271
1705
  case 'GoToPage':
1272
1706
  PDFViewerApplication.appConfig.toolbar.pageNumber.select();
1273
1707
  break;
1708
+
1274
1709
  case 'Find':
1275
1710
  if (!PDFViewerApplication.supportsIntegratedFind) {
1276
1711
  PDFViewerApplication.findBar.toggle();
1277
1712
  }
1713
+
1278
1714
  break;
1279
1715
  }
1280
1716
  }
1717
+
1281
1718
  function webViewerPresentationModeChanged(evt) {
1282
1719
  var active = evt.active,
1283
1720
  switchInProgress = evt.switchInProgress;
1284
-
1285
1721
  PDFViewerApplication.pdfViewer.presentationModeState = switchInProgress ? _ui_utils.PresentationModeState.CHANGING : active ? _ui_utils.PresentationModeState.FULLSCREEN : _ui_utils.PresentationModeState.NORMAL;
1286
1722
  }
1723
+
1287
1724
  function webViewerSidebarViewChanged(evt) {
1288
1725
  PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
1289
1726
  var store = PDFViewerApplication.store;
1727
+
1290
1728
  if (store && PDFViewerApplication.isInitialViewSet) {
1291
1729
  store.set('sidebarView', evt.view).catch(function () {});
1292
1730
  }
1293
1731
  }
1732
+
1294
1733
  function webViewerUpdateViewarea(evt) {
1295
1734
  var location = evt.location,
1296
1735
  store = PDFViewerApplication.store;
1736
+
1297
1737
  if (store && PDFViewerApplication.isInitialViewSet) {
1298
1738
  store.setMultiple({
1299
- 'exists': true,
1300
1739
  'page': location.pageNumber,
1301
1740
  'zoom': location.scale,
1302
1741
  'scrollLeft': location.left,
@@ -1304,6 +1743,7 @@ function webViewerUpdateViewarea(evt) {
1304
1743
  'rotation': location.rotation
1305
1744
  }).catch(function () {});
1306
1745
  }
1746
+
1307
1747
  var href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
1308
1748
  PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
1309
1749
  PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
@@ -1311,6 +1751,23 @@ function webViewerUpdateViewarea(evt) {
1311
1751
  var loading = currentPage.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
1312
1752
  PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
1313
1753
  }
1754
+
1755
+ function webViewerScrollModeChanged(evt) {
1756
+ var store = PDFViewerApplication.store;
1757
+
1758
+ if (store && PDFViewerApplication.isInitialViewSet) {
1759
+ store.set('scrollMode', evt.mode).catch(function () {});
1760
+ }
1761
+ }
1762
+
1763
+ function webViewerSpreadModeChanged(evt) {
1764
+ var store = PDFViewerApplication.store;
1765
+
1766
+ if (store && PDFViewerApplication.isInitialViewSet) {
1767
+ store.set('spreadMode', evt.mode).catch(function () {});
1768
+ }
1769
+ }
1770
+
1314
1771
  function webViewerResize() {
1315
1772
  var pdfDocument = PDFViewerApplication.pdfDocument,
1316
1773
  pdfViewer = PDFViewerApplication.pdfViewer;
@@ -1318,38 +1775,62 @@ function webViewerResize() {
1318
1775
  if (!pdfDocument) {
1319
1776
  return;
1320
1777
  }
1778
+
1321
1779
  var currentScaleValue = pdfViewer.currentScaleValue;
1780
+
1322
1781
  if (currentScaleValue === 'auto' || currentScaleValue === 'page-fit' || currentScaleValue === 'page-width') {
1323
1782
  pdfViewer.currentScaleValue = currentScaleValue;
1324
1783
  }
1784
+
1325
1785
  pdfViewer.update();
1326
1786
  }
1787
+
1327
1788
  function webViewerHashchange(evt) {
1328
1789
  var hash = evt.hash;
1790
+
1329
1791
  if (!hash) {
1330
1792
  return;
1331
1793
  }
1794
+
1332
1795
  if (!PDFViewerApplication.isInitialViewSet) {
1333
1796
  PDFViewerApplication.initialBookmark = hash;
1334
1797
  } else if (!PDFViewerApplication.pdfHistory.popStateInProgress) {
1335
1798
  PDFViewerApplication.pdfLinkService.setHash(hash);
1336
1799
  }
1337
1800
  }
1338
- var webViewerFileInputChange = void 0;
1801
+
1802
+ var webViewerFileInputChange;
1339
1803
  {
1340
1804
  webViewerFileInputChange = function webViewerFileInputChange(evt) {
1805
+ if (PDFViewerApplication.pdfViewer && PDFViewerApplication.pdfViewer.isInPresentationMode) {
1806
+ return;
1807
+ }
1808
+
1341
1809
  var file = evt.fileInput.files[0];
1342
- if (URL.createObjectURL && !_app_options.AppOptions.get('disableCreateObjectURL')) {
1343
- PDFViewerApplication.open(URL.createObjectURL(file));
1810
+
1811
+ if (_pdf.URL.createObjectURL && !_app_options.AppOptions.get('disableCreateObjectURL')) {
1812
+ var url = _pdf.URL.createObjectURL(file);
1813
+
1814
+ if (file.name) {
1815
+ url = {
1816
+ url: url,
1817
+ originalUrl: file.name
1818
+ };
1819
+ }
1820
+
1821
+ PDFViewerApplication.open(url);
1344
1822
  } else {
1823
+ PDFViewerApplication.setTitleUsingUrl(file.name);
1345
1824
  var fileReader = new FileReader();
1825
+
1346
1826
  fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
1347
1827
  var buffer = evt.target.result;
1348
1828
  PDFViewerApplication.open(new Uint8Array(buffer));
1349
1829
  };
1830
+
1350
1831
  fileReader.readAsArrayBuffer(file);
1351
1832
  }
1352
- PDFViewerApplication.setTitleUsingUrl(file.name);
1833
+
1353
1834
  var appConfig = PDFViewerApplication.appConfig;
1354
1835
  appConfig.toolbar.viewBookmark.setAttribute('hidden', 'true');
1355
1836
  appConfig.secondaryToolbar.viewBookmarkButton.setAttribute('hidden', 'true');
@@ -1357,127 +1838,216 @@ var webViewerFileInputChange = void 0;
1357
1838
  appConfig.secondaryToolbar.downloadButton.setAttribute('hidden', 'true');
1358
1839
  };
1359
1840
  }
1841
+
1360
1842
  function webViewerPresentationMode() {
1361
1843
  PDFViewerApplication.requestPresentationMode();
1362
1844
  }
1845
+
1363
1846
  function webViewerOpenFile() {
1364
1847
  var openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
1365
1848
  document.getElementById(openFileInputName).click();
1366
1849
  }
1850
+
1367
1851
  function webViewerPrint() {
1368
1852
  window.print();
1369
1853
  }
1854
+
1370
1855
  function webViewerDownload() {
1371
1856
  PDFViewerApplication.download();
1372
1857
  }
1858
+
1373
1859
  function webViewerFirstPage() {
1374
1860
  if (PDFViewerApplication.pdfDocument) {
1375
1861
  PDFViewerApplication.page = 1;
1376
1862
  }
1377
1863
  }
1864
+
1378
1865
  function webViewerLastPage() {
1379
1866
  if (PDFViewerApplication.pdfDocument) {
1380
1867
  PDFViewerApplication.page = PDFViewerApplication.pagesCount;
1381
1868
  }
1382
1869
  }
1870
+
1383
1871
  function webViewerNextPage() {
1384
1872
  PDFViewerApplication.page++;
1385
1873
  }
1874
+
1386
1875
  function webViewerPreviousPage() {
1387
1876
  PDFViewerApplication.page--;
1388
1877
  }
1878
+
1389
1879
  function webViewerZoomIn() {
1390
1880
  PDFViewerApplication.zoomIn();
1391
1881
  }
1882
+
1392
1883
  function webViewerZoomOut() {
1393
1884
  PDFViewerApplication.zoomOut();
1394
1885
  }
1886
+
1395
1887
  function webViewerPageNumberChanged(evt) {
1396
1888
  var pdfViewer = PDFViewerApplication.pdfViewer;
1397
- pdfViewer.currentPageLabel = evt.value;
1889
+
1890
+ if (evt.value !== '') {
1891
+ pdfViewer.currentPageLabel = evt.value;
1892
+ }
1893
+
1398
1894
  if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
1399
1895
  PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
1400
1896
  }
1401
1897
  }
1898
+
1402
1899
  function webViewerScaleChanged(evt) {
1403
1900
  PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
1404
1901
  }
1902
+
1405
1903
  function webViewerRotateCw() {
1406
1904
  PDFViewerApplication.rotatePages(90);
1407
1905
  }
1906
+
1408
1907
  function webViewerRotateCcw() {
1409
1908
  PDFViewerApplication.rotatePages(-90);
1410
1909
  }
1910
+
1911
+ function webViewerSwitchScrollMode(evt) {
1912
+ PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
1913
+ }
1914
+
1915
+ function webViewerSwitchSpreadMode(evt) {
1916
+ PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
1917
+ }
1918
+
1411
1919
  function webViewerDocumentProperties() {
1412
1920
  PDFViewerApplication.pdfDocumentProperties.open();
1413
1921
  }
1922
+
1414
1923
  function webViewerFind(evt) {
1415
1924
  PDFViewerApplication.findController.executeCommand('find' + evt.type, {
1416
1925
  query: evt.query,
1417
1926
  phraseSearch: evt.phraseSearch,
1418
1927
  caseSensitive: evt.caseSensitive,
1928
+ entireWord: evt.entireWord,
1419
1929
  highlightAll: evt.highlightAll,
1420
1930
  findPrevious: evt.findPrevious
1421
1931
  });
1422
1932
  }
1933
+
1423
1934
  function webViewerFindFromUrlHash(evt) {
1424
1935
  PDFViewerApplication.findController.executeCommand('find', {
1425
1936
  query: evt.query,
1426
1937
  phraseSearch: evt.phraseSearch,
1427
1938
  caseSensitive: false,
1939
+ entireWord: false,
1428
1940
  highlightAll: true,
1429
1941
  findPrevious: false
1430
1942
  });
1431
1943
  }
1944
+
1945
+ function webViewerUpdateFindMatchesCount(_ref9) {
1946
+ var matchesCount = _ref9.matchesCount;
1947
+
1948
+ if (PDFViewerApplication.supportsIntegratedFind) {
1949
+ PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
1950
+ } else {
1951
+ PDFViewerApplication.findBar.updateResultsCount(matchesCount);
1952
+ }
1953
+ }
1954
+
1955
+ function webViewerUpdateFindControlState(_ref10) {
1956
+ var state = _ref10.state,
1957
+ previous = _ref10.previous,
1958
+ matchesCount = _ref10.matchesCount;
1959
+
1960
+ if (PDFViewerApplication.supportsIntegratedFind) {
1961
+ PDFViewerApplication.externalServices.updateFindControlState({
1962
+ result: state,
1963
+ findPrevious: previous,
1964
+ matchesCount: matchesCount
1965
+ });
1966
+ } else {
1967
+ PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
1968
+ }
1969
+ }
1970
+
1432
1971
  function webViewerScaleChanging(evt) {
1433
1972
  PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
1434
1973
  PDFViewerApplication.pdfViewer.update();
1435
1974
  }
1975
+
1436
1976
  function webViewerRotationChanging(evt) {
1437
1977
  PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
1438
1978
  PDFViewerApplication.forceRendering();
1439
1979
  PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
1440
1980
  }
1981
+
1441
1982
  function webViewerPageChanging(evt) {
1442
1983
  var page = evt.pageNumber;
1443
1984
  PDFViewerApplication.toolbar.setPageNumber(page, evt.pageLabel || null);
1444
1985
  PDFViewerApplication.secondaryToolbar.setPageNumber(page);
1986
+
1445
1987
  if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
1446
1988
  PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
1447
1989
  }
1990
+
1448
1991
  if (typeof Stats !== 'undefined' && Stats.enabled) {
1449
1992
  var pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
1993
+
1450
1994
  if (pageView && pageView.stats) {
1451
1995
  Stats.add(page, pageView.stats);
1452
1996
  }
1453
1997
  }
1454
1998
  }
1455
- var zoomDisabled = false,
1456
- zoomDisabledTimeout = void 0;
1999
+
2000
+ function webViewerVisibilityChange(evt) {
2001
+ if (document.visibilityState === 'visible') {
2002
+ setZoomDisabledTimeout();
2003
+ }
2004
+ }
2005
+
2006
+ var zoomDisabledTimeout = null;
2007
+
2008
+ function setZoomDisabledTimeout() {
2009
+ if (zoomDisabledTimeout) {
2010
+ clearTimeout(zoomDisabledTimeout);
2011
+ }
2012
+
2013
+ zoomDisabledTimeout = setTimeout(function () {
2014
+ zoomDisabledTimeout = null;
2015
+ }, WHEEL_ZOOM_DISABLED_TIMEOUT);
2016
+ }
2017
+
1457
2018
  function webViewerWheel(evt) {
1458
2019
  var pdfViewer = PDFViewerApplication.pdfViewer;
2020
+
1459
2021
  if (pdfViewer.isInPresentationMode) {
1460
2022
  return;
1461
2023
  }
2024
+
1462
2025
  if (evt.ctrlKey || evt.metaKey) {
1463
2026
  var support = PDFViewerApplication.supportedMouseWheelZoomModifierKeys;
2027
+
1464
2028
  if (evt.ctrlKey && !support.ctrlKey || evt.metaKey && !support.metaKey) {
1465
2029
  return;
1466
2030
  }
2031
+
1467
2032
  evt.preventDefault();
1468
- if (zoomDisabled) {
2033
+
2034
+ if (zoomDisabledTimeout || document.visibilityState === 'hidden') {
1469
2035
  return;
1470
2036
  }
2037
+
1471
2038
  var previousScale = pdfViewer.currentScale;
1472
2039
  var delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
1473
2040
  var MOUSE_WHEEL_DELTA_PER_PAGE_SCALE = 3.0;
1474
2041
  var ticks = delta * MOUSE_WHEEL_DELTA_PER_PAGE_SCALE;
2042
+
1475
2043
  if (ticks < 0) {
1476
2044
  PDFViewerApplication.zoomOut(-ticks);
1477
2045
  } else {
1478
2046
  PDFViewerApplication.zoomIn(ticks);
1479
2047
  }
2048
+
1480
2049
  var currentScale = pdfViewer.currentScale;
2050
+
1481
2051
  if (previousScale !== currentScale) {
1482
2052
  var scaleCorrectionFactor = currentScale / previousScale - 1;
1483
2053
  var rect = pdfViewer.container.getBoundingClientRect();
@@ -1487,31 +2057,33 @@ function webViewerWheel(evt) {
1487
2057
  pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
1488
2058
  }
1489
2059
  } else {
1490
- zoomDisabled = true;
1491
- clearTimeout(zoomDisabledTimeout);
1492
- zoomDisabledTimeout = setTimeout(function () {
1493
- zoomDisabled = false;
1494
- }, 1000);
2060
+ setZoomDisabledTimeout();
1495
2061
  }
1496
2062
  }
2063
+
1497
2064
  function webViewerClick(evt) {
1498
2065
  if (!PDFViewerApplication.secondaryToolbar.isOpen) {
1499
2066
  return;
1500
2067
  }
2068
+
1501
2069
  var appConfig = PDFViewerApplication.appConfig;
2070
+
1502
2071
  if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
1503
2072
  PDFViewerApplication.secondaryToolbar.close();
1504
2073
  }
1505
2074
  }
2075
+
1506
2076
  function webViewerKeyDown(evt) {
1507
2077
  if (PDFViewerApplication.overlayManager.active) {
1508
2078
  return;
1509
2079
  }
2080
+
1510
2081
  var handled = false,
1511
2082
  ensureViewerFocused = false;
1512
2083
  var cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
1513
2084
  var pdfViewer = PDFViewerApplication.pdfViewer;
1514
2085
  var isViewerInPresentationMode = pdfViewer && pdfViewer.isInPresentationMode;
2086
+
1515
2087
  if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
1516
2088
  switch (evt.keyCode) {
1517
2089
  case 70:
@@ -1519,22 +2091,29 @@ function webViewerKeyDown(evt) {
1519
2091
  PDFViewerApplication.findBar.open();
1520
2092
  handled = true;
1521
2093
  }
2094
+
1522
2095
  break;
2096
+
1523
2097
  case 71:
1524
2098
  if (!PDFViewerApplication.supportsIntegratedFind) {
1525
2099
  var findState = PDFViewerApplication.findController.state;
2100
+
1526
2101
  if (findState) {
1527
2102
  PDFViewerApplication.findController.executeCommand('findagain', {
1528
2103
  query: findState.query,
1529
2104
  phraseSearch: findState.phraseSearch,
1530
2105
  caseSensitive: findState.caseSensitive,
2106
+ entireWord: findState.entireWord,
1531
2107
  highlightAll: findState.highlightAll,
1532
2108
  findPrevious: cmd === 5 || cmd === 12
1533
2109
  });
1534
2110
  }
2111
+
1535
2112
  handled = true;
1536
2113
  }
2114
+
1537
2115
  break;
2116
+
1538
2117
  case 61:
1539
2118
  case 107:
1540
2119
  case 187:
@@ -1542,16 +2121,20 @@ function webViewerKeyDown(evt) {
1542
2121
  if (!isViewerInPresentationMode) {
1543
2122
  PDFViewerApplication.zoomIn();
1544
2123
  }
2124
+
1545
2125
  handled = true;
1546
2126
  break;
2127
+
1547
2128
  case 173:
1548
2129
  case 109:
1549
2130
  case 189:
1550
2131
  if (!isViewerInPresentationMode) {
1551
2132
  PDFViewerApplication.zoomOut();
1552
2133
  }
2134
+
1553
2135
  handled = true;
1554
2136
  break;
2137
+
1555
2138
  case 48:
1556
2139
  case 96:
1557
2140
  if (!isViewerInPresentationMode) {
@@ -1560,23 +2143,29 @@ function webViewerKeyDown(evt) {
1560
2143
  });
1561
2144
  handled = false;
1562
2145
  }
2146
+
1563
2147
  break;
2148
+
1564
2149
  case 38:
1565
2150
  if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
1566
2151
  PDFViewerApplication.page = 1;
1567
2152
  handled = true;
1568
2153
  ensureViewerFocused = true;
1569
2154
  }
2155
+
1570
2156
  break;
2157
+
1571
2158
  case 40:
1572
2159
  if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
1573
2160
  PDFViewerApplication.page = PDFViewerApplication.pagesCount;
1574
2161
  handled = true;
1575
2162
  ensureViewerFocused = true;
1576
2163
  }
2164
+
1577
2165
  break;
1578
2166
  }
1579
2167
  }
2168
+
1580
2169
  if (cmd === 1 || cmd === 8) {
1581
2170
  switch (evt.keyCode) {
1582
2171
  case 83:
@@ -1585,104 +2174,162 @@ function webViewerKeyDown(evt) {
1585
2174
  break;
1586
2175
  }
1587
2176
  }
2177
+
1588
2178
  if (cmd === 3 || cmd === 10) {
1589
2179
  switch (evt.keyCode) {
1590
2180
  case 80:
1591
2181
  PDFViewerApplication.requestPresentationMode();
1592
2182
  handled = true;
1593
2183
  break;
2184
+
1594
2185
  case 71:
1595
2186
  PDFViewerApplication.appConfig.toolbar.pageNumber.select();
1596
2187
  handled = true;
1597
2188
  break;
1598
2189
  }
1599
2190
  }
2191
+
1600
2192
  if (handled) {
1601
2193
  if (ensureViewerFocused && !isViewerInPresentationMode) {
1602
2194
  pdfViewer.focus();
1603
2195
  }
2196
+
1604
2197
  evt.preventDefault();
1605
2198
  return;
1606
2199
  }
2200
+
1607
2201
  var curElement = document.activeElement || document.querySelector(':focus');
1608
2202
  var curElementTagName = curElement && curElement.tagName.toUpperCase();
2203
+
1609
2204
  if (curElementTagName === 'INPUT' || curElementTagName === 'TEXTAREA' || curElementTagName === 'SELECT') {
1610
2205
  if (evt.keyCode !== 27) {
1611
2206
  return;
1612
2207
  }
1613
2208
  }
2209
+
1614
2210
  if (cmd === 0) {
2211
+ var turnPage = 0,
2212
+ turnOnlyIfPageFit = false;
2213
+
1615
2214
  switch (evt.keyCode) {
1616
2215
  case 38:
1617
2216
  case 33:
2217
+ if (pdfViewer.isVerticalScrollbarEnabled) {
2218
+ turnOnlyIfPageFit = true;
2219
+ }
2220
+
2221
+ turnPage = -1;
2222
+ break;
2223
+
1618
2224
  case 8:
1619
- if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
1620
- break;
2225
+ if (!isViewerInPresentationMode) {
2226
+ turnOnlyIfPageFit = true;
1621
2227
  }
2228
+
2229
+ turnPage = -1;
2230
+ break;
2231
+
1622
2232
  case 37:
1623
2233
  if (pdfViewer.isHorizontalScrollbarEnabled) {
1624
- break;
2234
+ turnOnlyIfPageFit = true;
1625
2235
  }
2236
+
1626
2237
  case 75:
1627
2238
  case 80:
1628
- if (PDFViewerApplication.page > 1) {
1629
- PDFViewerApplication.page--;
1630
- }
1631
- handled = true;
2239
+ turnPage = -1;
1632
2240
  break;
2241
+
1633
2242
  case 27:
1634
2243
  if (PDFViewerApplication.secondaryToolbar.isOpen) {
1635
2244
  PDFViewerApplication.secondaryToolbar.close();
1636
2245
  handled = true;
1637
2246
  }
2247
+
1638
2248
  if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
1639
2249
  PDFViewerApplication.findBar.close();
1640
2250
  handled = true;
1641
2251
  }
2252
+
1642
2253
  break;
1643
- case 13:
2254
+
1644
2255
  case 40:
1645
2256
  case 34:
2257
+ if (pdfViewer.isVerticalScrollbarEnabled) {
2258
+ turnOnlyIfPageFit = true;
2259
+ }
2260
+
2261
+ turnPage = 1;
2262
+ break;
2263
+
2264
+ case 13:
1646
2265
  case 32:
1647
- if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
1648
- break;
2266
+ if (!isViewerInPresentationMode) {
2267
+ turnOnlyIfPageFit = true;
1649
2268
  }
2269
+
2270
+ turnPage = 1;
2271
+ break;
2272
+
1650
2273
  case 39:
1651
2274
  if (pdfViewer.isHorizontalScrollbarEnabled) {
1652
- break;
2275
+ turnOnlyIfPageFit = true;
1653
2276
  }
2277
+
1654
2278
  case 74:
1655
2279
  case 78:
1656
- if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
1657
- PDFViewerApplication.page++;
1658
- }
1659
- handled = true;
2280
+ turnPage = 1;
1660
2281
  break;
2282
+
1661
2283
  case 36:
1662
2284
  if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
1663
2285
  PDFViewerApplication.page = 1;
1664
2286
  handled = true;
1665
2287
  ensureViewerFocused = true;
1666
2288
  }
2289
+
1667
2290
  break;
2291
+
1668
2292
  case 35:
1669
2293
  if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
1670
2294
  PDFViewerApplication.page = PDFViewerApplication.pagesCount;
1671
2295
  handled = true;
1672
2296
  ensureViewerFocused = true;
1673
2297
  }
2298
+
1674
2299
  break;
2300
+
1675
2301
  case 83:
1676
2302
  PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
1677
2303
  break;
2304
+
1678
2305
  case 72:
1679
2306
  PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
1680
2307
  break;
2308
+
1681
2309
  case 82:
1682
2310
  PDFViewerApplication.rotatePages(90);
1683
2311
  break;
2312
+
2313
+ case 115:
2314
+ PDFViewerApplication.pdfSidebar.toggle();
2315
+ break;
2316
+ }
2317
+
2318
+ if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === 'page-fit')) {
2319
+ if (turnPage > 0) {
2320
+ if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
2321
+ PDFViewerApplication.page++;
2322
+ }
2323
+ } else {
2324
+ if (PDFViewerApplication.page > 1) {
2325
+ PDFViewerApplication.page--;
2326
+ }
2327
+ }
2328
+
2329
+ handled = true;
1684
2330
  }
1685
2331
  }
2332
+
1686
2333
  if (cmd === 4) {
1687
2334
  switch (evt.keyCode) {
1688
2335
  case 13:
@@ -1690,42 +2337,55 @@ function webViewerKeyDown(evt) {
1690
2337
  if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
1691
2338
  break;
1692
2339
  }
2340
+
1693
2341
  if (PDFViewerApplication.page > 1) {
1694
2342
  PDFViewerApplication.page--;
1695
2343
  }
2344
+
1696
2345
  handled = true;
1697
2346
  break;
2347
+
1698
2348
  case 82:
1699
2349
  PDFViewerApplication.rotatePages(-90);
1700
2350
  break;
1701
2351
  }
1702
2352
  }
2353
+
1703
2354
  if (!handled && !isViewerInPresentationMode) {
1704
2355
  if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== 'BUTTON') {
1705
2356
  ensureViewerFocused = true;
1706
2357
  }
1707
2358
  }
2359
+
1708
2360
  if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
1709
2361
  pdfViewer.focus();
1710
2362
  }
2363
+
1711
2364
  if (handled) {
1712
2365
  evt.preventDefault();
1713
2366
  }
1714
2367
  }
2368
+
1715
2369
  function apiPageModeToSidebarView(mode) {
1716
2370
  switch (mode) {
1717
2371
  case 'UseNone':
1718
2372
  return _pdf_sidebar.SidebarView.NONE;
2373
+
1719
2374
  case 'UseThumbs':
1720
2375
  return _pdf_sidebar.SidebarView.THUMBS;
2376
+
1721
2377
  case 'UseOutlines':
1722
2378
  return _pdf_sidebar.SidebarView.OUTLINE;
2379
+
1723
2380
  case 'UseAttachments':
1724
2381
  return _pdf_sidebar.SidebarView.ATTACHMENTS;
2382
+
1725
2383
  case 'UseOC':
1726
2384
  }
2385
+
1727
2386
  return _pdf_sidebar.SidebarView.NONE;
1728
2387
  }
2388
+
1729
2389
  var PDFPrintServiceFactory = {
1730
2390
  instance: {
1731
2391
  supportsPrinting: false,
@@ -1734,6 +2394,4 @@ var PDFPrintServiceFactory = {
1734
2394
  }
1735
2395
  }
1736
2396
  };
1737
- exports.PDFViewerApplication = PDFViewerApplication;
1738
- exports.DefaultExternalServices = DefaultExternalServices;
1739
2397
  exports.PDFPrintServiceFactory = PDFPrintServiceFactory;