pdfjs-dist 2.0.489 → 2.2.228

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