pdfjs-dist 2.0.550 → 2.3.200

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 (168) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +21618 -14369
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +22758 -11399
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/image_decoders/pdf.image_decoders.js +11500 -0
  10. package/image_decoders/pdf.image_decoders.js.map +1 -0
  11. package/image_decoders/pdf.image_decoders.min.js +1 -0
  12. package/lib/core/annotation.js +767 -258
  13. package/lib/core/arithmetic_decoder.js +275 -245
  14. package/lib/core/bidi.js +65 -6
  15. package/lib/core/ccitt.js +173 -18
  16. package/lib/core/ccitt_stream.js +15 -6
  17. package/lib/core/cff_parser.js +433 -61
  18. package/lib/core/charsets.js +5 -4
  19. package/lib/core/chunked_stream.js +428 -157
  20. package/lib/core/cmap.js +326 -87
  21. package/lib/core/colorspace.js +874 -594
  22. package/lib/core/core_utils.js +173 -0
  23. package/lib/core/crypto.js +290 -45
  24. package/lib/core/document.js +575 -272
  25. package/lib/core/encodings.js +19 -10
  26. package/lib/core/evaluator.js +1032 -351
  27. package/lib/core/font_renderer.js +331 -97
  28. package/lib/core/fonts.js +813 -196
  29. package/lib/core/function.js +253 -27
  30. package/lib/core/glyphlist.js +5 -3
  31. package/lib/core/image.js +169 -62
  32. package/lib/core/image_utils.js +111 -0
  33. package/lib/core/jbig2.js +502 -72
  34. package/lib/core/jbig2_stream.js +19 -8
  35. package/lib/core/jpeg_stream.js +38 -13
  36. package/lib/core/jpg.js +293 -52
  37. package/lib/core/jpx.js +419 -12
  38. package/lib/core/jpx_stream.js +18 -6
  39. package/lib/core/metrics.js +15 -15
  40. package/lib/core/murmurhash3.js +56 -34
  41. package/lib/core/obj.js +1368 -500
  42. package/lib/core/operator_list.js +159 -43
  43. package/lib/core/parser.js +544 -199
  44. package/lib/core/pattern.js +170 -21
  45. package/lib/core/pdf_manager.js +324 -134
  46. package/lib/core/primitives.js +169 -61
  47. package/lib/core/ps_parser.js +134 -45
  48. package/lib/core/standard_fonts.js +17 -17
  49. package/lib/core/stream.js +327 -34
  50. package/lib/core/type1_parser.js +148 -8
  51. package/lib/core/unicode.js +32 -5
  52. package/lib/core/worker.js +215 -229
  53. package/lib/core/worker_stream.js +277 -0
  54. package/lib/display/annotation_layer.js +618 -192
  55. package/lib/display/api.js +1798 -882
  56. package/lib/display/api_compatibility.js +5 -10
  57. package/lib/display/canvas.js +366 -45
  58. package/lib/display/content_disposition.js +71 -24
  59. package/lib/display/display_utils.js +777 -0
  60. package/lib/display/fetch_stream.js +205 -87
  61. package/lib/display/font_loader.js +468 -236
  62. package/lib/display/metadata.js +38 -16
  63. package/lib/display/network.js +635 -428
  64. package/lib/display/network_utils.js +38 -19
  65. package/lib/display/node_stream.js +367 -175
  66. package/lib/display/pattern_helper.js +103 -36
  67. package/lib/display/svg.js +1232 -519
  68. package/lib/display/text_layer.js +208 -75
  69. package/lib/display/transport_stream.js +345 -94
  70. package/lib/display/webgl.js +64 -18
  71. package/lib/display/worker_options.js +5 -4
  72. package/lib/display/xml_parser.js +166 -53
  73. package/lib/examples/node/domstubs.js +60 -4
  74. package/lib/pdf.js +35 -14
  75. package/lib/pdf.worker.js +5 -3
  76. package/lib/shared/compatibility.js +170 -572
  77. package/lib/shared/global_scope.js +2 -2
  78. package/lib/shared/is_node.js +4 -4
  79. package/lib/shared/message_handler.js +216 -163
  80. package/lib/shared/streams_polyfill.js +21 -17
  81. package/lib/shared/util.js +495 -385
  82. package/lib/test/unit/annotation_spec.js +1464 -401
  83. package/lib/test/unit/api_spec.js +718 -361
  84. package/lib/test/unit/bidi_spec.js +7 -7
  85. package/lib/test/unit/cff_parser_spec.js +54 -11
  86. package/lib/test/unit/clitests_helper.js +9 -10
  87. package/lib/test/unit/cmap_spec.js +95 -41
  88. package/lib/test/unit/colorspace_spec.js +115 -63
  89. package/lib/test/unit/core_utils_spec.js +191 -0
  90. package/lib/test/unit/crypto_spec.js +17 -5
  91. package/lib/test/unit/custom_spec.js +43 -55
  92. package/lib/test/unit/display_svg_spec.js +34 -18
  93. package/lib/test/unit/display_utils_spec.js +273 -0
  94. package/lib/test/unit/document_spec.js +8 -13
  95. package/lib/test/unit/encodings_spec.js +25 -45
  96. package/lib/test/unit/evaluator_spec.js +59 -20
  97. package/lib/test/unit/fetch_stream_spec.js +111 -0
  98. package/lib/test/unit/function_spec.js +17 -5
  99. package/lib/test/unit/jasmine-boot.js +33 -20
  100. package/lib/test/unit/message_handler_spec.js +30 -13
  101. package/lib/test/unit/metadata_spec.js +71 -11
  102. package/lib/test/unit/murmurhash3_spec.js +3 -3
  103. package/lib/test/unit/network_spec.js +22 -55
  104. package/lib/test/unit/network_utils_spec.js +105 -14
  105. package/lib/test/unit/node_stream_spec.js +58 -34
  106. package/lib/test/unit/parser_spec.js +162 -71
  107. package/lib/test/unit/pdf_find_controller_spec.js +230 -0
  108. package/lib/test/unit/pdf_find_utils_spec.js +63 -0
  109. package/lib/test/unit/pdf_history_spec.js +21 -9
  110. package/lib/test/unit/primitives_spec.js +55 -22
  111. package/lib/test/unit/stream_spec.js +12 -4
  112. package/lib/test/unit/test_utils.js +273 -56
  113. package/lib/test/unit/testreporter.js +21 -3
  114. package/lib/test/unit/type1_parser_spec.js +9 -7
  115. package/lib/test/unit/ui_utils_spec.js +236 -36
  116. package/lib/test/unit/unicode_spec.js +18 -15
  117. package/lib/test/unit/util_spec.js +87 -128
  118. package/lib/web/annotation_layer_builder.js +39 -22
  119. package/lib/web/app.js +1252 -609
  120. package/lib/web/app_options.js +103 -65
  121. package/lib/web/base_viewer.js +522 -242
  122. package/lib/web/chromecom.js +259 -117
  123. package/lib/web/debugger.js +166 -22
  124. package/lib/web/download_manager.js +31 -12
  125. package/lib/web/firefox_print_service.js +27 -14
  126. package/lib/web/firefoxcom.js +318 -78
  127. package/lib/web/genericcom.js +89 -30
  128. package/lib/web/genericl10n.js +142 -30
  129. package/lib/web/grab_to_pan.js +28 -4
  130. package/lib/web/interfaces.js +174 -47
  131. package/lib/web/overlay_manager.js +235 -85
  132. package/lib/web/password_prompt.js +22 -14
  133. package/lib/web/pdf_attachment_viewer.js +38 -18
  134. package/lib/web/pdf_cursor_tools.js +39 -16
  135. package/lib/web/pdf_document_properties.js +255 -136
  136. package/lib/web/pdf_find_bar.js +84 -40
  137. package/lib/web/pdf_find_controller.js +495 -184
  138. package/lib/web/pdf_find_utils.js +111 -0
  139. package/lib/web/pdf_history.js +190 -53
  140. package/lib/web/pdf_link_service.js +144 -79
  141. package/lib/web/pdf_outline_viewer.js +124 -47
  142. package/lib/web/pdf_page_view.js +194 -74
  143. package/lib/web/pdf_presentation_mode.js +99 -34
  144. package/lib/web/pdf_print_service.js +59 -13
  145. package/lib/web/pdf_rendering_queue.js +28 -9
  146. package/lib/web/pdf_sidebar.js +144 -81
  147. package/lib/web/pdf_sidebar_resizer.js +42 -16
  148. package/lib/web/pdf_single_page_viewer.js +74 -66
  149. package/lib/web/pdf_thumbnail_view.js +104 -33
  150. package/lib/web/pdf_thumbnail_viewer.js +66 -26
  151. package/lib/web/pdf_viewer.component.js +112 -32
  152. package/lib/web/pdf_viewer.js +82 -87
  153. package/lib/web/preferences.js +284 -91
  154. package/lib/web/secondary_toolbar.js +132 -59
  155. package/lib/web/text_layer_builder.js +134 -59
  156. package/lib/web/toolbar.js +80 -43
  157. package/lib/web/ui_utils.js +400 -134
  158. package/lib/web/view_history.js +215 -67
  159. package/lib/web/viewer_compatibility.js +3 -8
  160. package/package.json +3 -2
  161. package/web/pdf_viewer.css +23 -15
  162. package/web/pdf_viewer.js +3429 -1245
  163. package/web/pdf_viewer.js.map +1 -1
  164. package/external/streams/streams-lib.js +0 -3962
  165. package/lib/display/dom_utils.js +0 -429
  166. package/lib/test/unit/dom_utils_spec.js +0 -89
  167. package/lib/test/unit/fonts_spec.js +0 -81
  168. package/lib/web/dom_events.js +0 -137
@@ -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,32 +19,46 @@
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.PDFSidebar = exports.SidebarView = undefined;
27
+ exports.PDFSidebar = exports.SidebarView = void 0;
28
28
 
29
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
29
+ var _ui_utils = require("./ui_utils");
30
30
 
31
- var _ui_utils = require('./ui_utils');
32
-
33
- var _pdf_rendering_queue = require('./pdf_rendering_queue');
31
+ var _pdf_rendering_queue = require("./pdf_rendering_queue");
34
32
 
35
33
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
36
34
 
35
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
36
+
37
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
38
+
37
39
  var UI_NOTIFICATION_CLASS = 'pdfSidebarNotification';
38
40
  var SidebarView = {
41
+ UNKNOWN: -1,
39
42
  NONE: 0,
40
43
  THUMBS: 1,
41
44
  OUTLINE: 2,
42
- ATTACHMENTS: 3
45
+ ATTACHMENTS: 3,
46
+ LAYERS: 4
43
47
  };
48
+ exports.SidebarView = SidebarView;
44
49
 
45
- var PDFSidebar = function () {
46
- function PDFSidebar(options) {
47
- var l10n = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _ui_utils.NullL10n;
50
+ var PDFSidebar =
51
+ /*#__PURE__*/
52
+ function () {
53
+ function PDFSidebar(_ref) {
54
+ var elements = _ref.elements,
55
+ pdfViewer = _ref.pdfViewer,
56
+ pdfThumbnailViewer = _ref.pdfThumbnailViewer,
57
+ eventBus = _ref.eventBus,
58
+ _ref$l10n = _ref.l10n,
59
+ l10n = _ref$l10n === void 0 ? _ui_utils.NullL10n : _ref$l10n,
60
+ _ref$disableNotificat = _ref.disableNotification,
61
+ disableNotification = _ref$disableNotificat === void 0 ? false : _ref$disableNotificat;
48
62
 
49
63
  _classCallCheck(this, PDFSidebar);
50
64
 
@@ -52,147 +66,171 @@ var PDFSidebar = function () {
52
66
  this.active = SidebarView.THUMBS;
53
67
  this.isInitialViewSet = false;
54
68
  this.onToggled = null;
55
- this.pdfViewer = options.pdfViewer;
56
- this.pdfThumbnailViewer = options.pdfThumbnailViewer;
57
- this.pdfOutlineViewer = options.pdfOutlineViewer;
58
- this.outerContainer = options.outerContainer;
59
- this.viewerContainer = options.viewerContainer;
60
- this.eventBus = options.eventBus;
61
- this.toggleButton = options.toggleButton;
62
- this.thumbnailButton = options.thumbnailButton;
63
- this.outlineButton = options.outlineButton;
64
- this.attachmentsButton = options.attachmentsButton;
65
- this.thumbnailView = options.thumbnailView;
66
- this.outlineView = options.outlineView;
67
- this.attachmentsView = options.attachmentsView;
68
- this.disableNotification = options.disableNotification || false;
69
+ this.pdfViewer = pdfViewer;
70
+ this.pdfThumbnailViewer = pdfThumbnailViewer;
71
+ this.outerContainer = elements.outerContainer;
72
+ this.viewerContainer = elements.viewerContainer;
73
+ this.toggleButton = elements.toggleButton;
74
+ this.thumbnailButton = elements.thumbnailButton;
75
+ this.outlineButton = elements.outlineButton;
76
+ this.attachmentsButton = elements.attachmentsButton;
77
+ this.thumbnailView = elements.thumbnailView;
78
+ this.outlineView = elements.outlineView;
79
+ this.attachmentsView = elements.attachmentsView;
80
+ this.eventBus = eventBus;
69
81
  this.l10n = l10n;
82
+ this._disableNotification = disableNotification;
83
+
70
84
  this._addEventListeners();
71
85
  }
72
86
 
73
87
  _createClass(PDFSidebar, [{
74
- key: 'reset',
88
+ key: "reset",
75
89
  value: function reset() {
76
90
  this.isInitialViewSet = false;
91
+
77
92
  this._hideUINotification(null);
93
+
78
94
  this.switchView(SidebarView.THUMBS);
79
95
  this.outlineButton.disabled = false;
80
96
  this.attachmentsButton.disabled = false;
81
97
  }
82
98
  }, {
83
- key: 'setInitialView',
99
+ key: "setInitialView",
84
100
  value: function setInitialView() {
85
101
  var view = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : SidebarView.NONE;
86
102
 
87
103
  if (this.isInitialViewSet) {
88
104
  return;
89
105
  }
106
+
90
107
  this.isInitialViewSet = true;
91
- if (this.isOpen && view === SidebarView.NONE) {
108
+
109
+ if (view === SidebarView.NONE || view === SidebarView.UNKNOWN) {
92
110
  this._dispatchEvent();
111
+
93
112
  return;
94
113
  }
95
- var isViewPreserved = view === this.visibleView;
96
- this.switchView(view, true);
97
- if (isViewPreserved) {
114
+
115
+ if (!this._switchView(view, true)) {
98
116
  this._dispatchEvent();
99
117
  }
100
118
  }
101
119
  }, {
102
- key: 'switchView',
120
+ key: "switchView",
103
121
  value: function switchView(view) {
104
122
  var forceOpen = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
105
123
 
106
- if (view === SidebarView.NONE) {
107
- this.close();
108
- return;
109
- }
124
+ this._switchView(view, forceOpen);
125
+ }
126
+ }, {
127
+ key: "_switchView",
128
+ value: function _switchView(view) {
129
+ var forceOpen = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
110
130
  var isViewChanged = view !== this.active;
111
131
  var shouldForceRendering = false;
132
+
112
133
  switch (view) {
134
+ case SidebarView.NONE:
135
+ if (this.isOpen) {
136
+ this.close();
137
+ return true;
138
+ }
139
+
140
+ return false;
141
+
113
142
  case SidebarView.THUMBS:
114
- this.thumbnailButton.classList.add('toggled');
115
- this.outlineButton.classList.remove('toggled');
116
- this.attachmentsButton.classList.remove('toggled');
117
- this.thumbnailView.classList.remove('hidden');
118
- this.outlineView.classList.add('hidden');
119
- this.attachmentsView.classList.add('hidden');
120
143
  if (this.isOpen && isViewChanged) {
121
- this._updateThumbnailViewer();
122
144
  shouldForceRendering = true;
123
145
  }
146
+
124
147
  break;
148
+
125
149
  case SidebarView.OUTLINE:
126
150
  if (this.outlineButton.disabled) {
127
- return;
151
+ return false;
128
152
  }
129
- this.thumbnailButton.classList.remove('toggled');
130
- this.outlineButton.classList.add('toggled');
131
- this.attachmentsButton.classList.remove('toggled');
132
- this.thumbnailView.classList.add('hidden');
133
- this.outlineView.classList.remove('hidden');
134
- this.attachmentsView.classList.add('hidden');
153
+
135
154
  break;
155
+
136
156
  case SidebarView.ATTACHMENTS:
137
157
  if (this.attachmentsButton.disabled) {
138
- return;
158
+ return false;
139
159
  }
140
- this.thumbnailButton.classList.remove('toggled');
141
- this.outlineButton.classList.remove('toggled');
142
- this.attachmentsButton.classList.add('toggled');
143
- this.thumbnailView.classList.add('hidden');
144
- this.outlineView.classList.add('hidden');
145
- this.attachmentsView.classList.remove('hidden');
160
+
146
161
  break;
162
+
147
163
  default:
148
- console.error('PDFSidebar_switchView: "' + view + '" is an unsupported value.');
149
- return;
164
+ console.error("PDFSidebar._switchView: \"".concat(view, "\" is not a valid view."));
165
+ return false;
150
166
  }
151
- this.active = view | 0;
167
+
168
+ this.active = view;
169
+ this.thumbnailButton.classList.toggle('toggled', view === SidebarView.THUMBS);
170
+ this.outlineButton.classList.toggle('toggled', view === SidebarView.OUTLINE);
171
+ this.attachmentsButton.classList.toggle('toggled', view === SidebarView.ATTACHMENTS);
172
+ this.thumbnailView.classList.toggle('hidden', view !== SidebarView.THUMBS);
173
+ this.outlineView.classList.toggle('hidden', view !== SidebarView.OUTLINE);
174
+ this.attachmentsView.classList.toggle('hidden', view !== SidebarView.ATTACHMENTS);
175
+
152
176
  if (forceOpen && !this.isOpen) {
153
177
  this.open();
154
- return;
178
+ return true;
155
179
  }
180
+
156
181
  if (shouldForceRendering) {
182
+ this._updateThumbnailViewer();
183
+
157
184
  this._forceRendering();
158
185
  }
186
+
159
187
  if (isViewChanged) {
160
188
  this._dispatchEvent();
161
189
  }
190
+
162
191
  this._hideUINotification(this.active);
192
+
193
+ return isViewChanged;
163
194
  }
164
195
  }, {
165
- key: 'open',
196
+ key: "open",
166
197
  value: function open() {
167
198
  if (this.isOpen) {
168
199
  return;
169
200
  }
201
+
170
202
  this.isOpen = true;
171
203
  this.toggleButton.classList.add('toggled');
172
- this.outerContainer.classList.add('sidebarMoving');
173
- this.outerContainer.classList.add('sidebarOpen');
204
+ this.outerContainer.classList.add('sidebarMoving', 'sidebarOpen');
205
+
174
206
  if (this.active === SidebarView.THUMBS) {
175
207
  this._updateThumbnailViewer();
176
208
  }
209
+
177
210
  this._forceRendering();
211
+
178
212
  this._dispatchEvent();
213
+
179
214
  this._hideUINotification(this.active);
180
215
  }
181
216
  }, {
182
- key: 'close',
217
+ key: "close",
183
218
  value: function close() {
184
219
  if (!this.isOpen) {
185
220
  return;
186
221
  }
222
+
187
223
  this.isOpen = false;
188
224
  this.toggleButton.classList.remove('toggled');
189
225
  this.outerContainer.classList.add('sidebarMoving');
190
226
  this.outerContainer.classList.remove('sidebarOpen');
227
+
191
228
  this._forceRendering();
229
+
192
230
  this._dispatchEvent();
193
231
  }
194
232
  }, {
195
- key: 'toggle',
233
+ key: "toggle",
196
234
  value: function toggle() {
197
235
  if (this.isOpen) {
198
236
  this.close();
@@ -201,7 +239,7 @@ var PDFSidebar = function () {
201
239
  }
202
240
  }
203
241
  }, {
204
- key: '_dispatchEvent',
242
+ key: "_dispatchEvent",
205
243
  value: function _dispatchEvent() {
206
244
  this.eventBus.dispatch('sidebarviewchanged', {
207
245
  source: this,
@@ -209,7 +247,7 @@ var PDFSidebar = function () {
209
247
  });
210
248
  }
211
249
  }, {
212
- key: '_forceRendering',
250
+ key: "_forceRendering",
213
251
  value: function _forceRendering() {
214
252
  if (this.onToggled) {
215
253
  this.onToggled();
@@ -219,81 +257,96 @@ var PDFSidebar = function () {
219
257
  }
220
258
  }
221
259
  }, {
222
- key: '_updateThumbnailViewer',
260
+ key: "_updateThumbnailViewer",
223
261
  value: function _updateThumbnailViewer() {
224
262
  var pdfViewer = this.pdfViewer,
225
263
  pdfThumbnailViewer = this.pdfThumbnailViewer;
226
-
227
264
  var pagesCount = pdfViewer.pagesCount;
265
+
228
266
  for (var pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
229
267
  var pageView = pdfViewer.getPageView(pageIndex);
268
+
230
269
  if (pageView && pageView.renderingState === _pdf_rendering_queue.RenderingStates.FINISHED) {
231
270
  var thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
232
271
  thumbnailView.setImage(pageView);
233
272
  }
234
273
  }
274
+
235
275
  pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
236
276
  }
237
277
  }, {
238
- key: '_showUINotification',
278
+ key: "_showUINotification",
239
279
  value: function _showUINotification(view) {
240
280
  var _this = this;
241
281
 
242
- if (this.disableNotification) {
282
+ if (this._disableNotification) {
243
283
  return;
244
284
  }
285
+
245
286
  this.l10n.get('toggle_sidebar_notification.title', null, 'Toggle Sidebar (document contains outline/attachments)').then(function (msg) {
246
287
  _this.toggleButton.title = msg;
247
288
  });
289
+
248
290
  if (!this.isOpen) {
249
291
  this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
250
292
  } else if (view === this.active) {
251
293
  return;
252
294
  }
295
+
253
296
  switch (view) {
254
297
  case SidebarView.OUTLINE:
255
298
  this.outlineButton.classList.add(UI_NOTIFICATION_CLASS);
256
299
  break;
300
+
257
301
  case SidebarView.ATTACHMENTS:
258
302
  this.attachmentsButton.classList.add(UI_NOTIFICATION_CLASS);
259
303
  break;
260
304
  }
261
305
  }
262
306
  }, {
263
- key: '_hideUINotification',
307
+ key: "_hideUINotification",
264
308
  value: function _hideUINotification(view) {
265
309
  var _this2 = this;
266
310
 
267
- if (this.disableNotification) {
311
+ if (this._disableNotification) {
268
312
  return;
269
313
  }
314
+
270
315
  var removeNotification = function removeNotification(view) {
271
316
  switch (view) {
272
317
  case SidebarView.OUTLINE:
273
318
  _this2.outlineButton.classList.remove(UI_NOTIFICATION_CLASS);
319
+
274
320
  break;
321
+
275
322
  case SidebarView.ATTACHMENTS:
276
323
  _this2.attachmentsButton.classList.remove(UI_NOTIFICATION_CLASS);
324
+
277
325
  break;
278
326
  }
279
327
  };
328
+
280
329
  if (!this.isOpen && view !== null) {
281
330
  return;
282
331
  }
332
+
283
333
  this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
334
+
284
335
  if (view !== null) {
285
336
  removeNotification(view);
286
337
  return;
287
338
  }
339
+
288
340
  for (view in SidebarView) {
289
341
  removeNotification(SidebarView[view]);
290
342
  }
343
+
291
344
  this.l10n.get('toggle_sidebar.title', null, 'Toggle Sidebar').then(function (msg) {
292
345
  _this2.toggleButton.title = msg;
293
346
  });
294
347
  }
295
348
  }, {
296
- key: '_addEventListeners',
349
+ key: "_addEventListeners",
297
350
  value: function _addEventListeners() {
298
351
  var _this3 = this;
299
352
 
@@ -302,6 +355,9 @@ var PDFSidebar = function () {
302
355
  _this3.outerContainer.classList.remove('sidebarMoving');
303
356
  }
304
357
  });
358
+ this.toggleButton.addEventListener('click', function () {
359
+ _this3.toggle();
360
+ });
305
361
  this.thumbnailButton.addEventListener('click', function () {
306
362
  _this3.switchView(SidebarView.THUMBS);
307
363
  });
@@ -309,7 +365,9 @@ var PDFSidebar = function () {
309
365
  _this3.switchView(SidebarView.OUTLINE);
310
366
  });
311
367
  this.outlineButton.addEventListener('dblclick', function () {
312
- _this3.pdfOutlineViewer.toggleOutlineTree();
368
+ _this3.eventBus.dispatch('toggleoutlinetree', {
369
+ source: _this3
370
+ });
313
371
  });
314
372
  this.attachmentsButton.addEventListener('click', function () {
315
373
  _this3.switchView(SidebarView.ATTACHMENTS);
@@ -317,6 +375,7 @@ var PDFSidebar = function () {
317
375
  this.eventBus.on('outlineloaded', function (evt) {
318
376
  var outlineCount = evt.outlineCount;
319
377
  _this3.outlineButton.disabled = !outlineCount;
378
+
320
379
  if (outlineCount) {
321
380
  _this3._showUINotification(SidebarView.OUTLINE);
322
381
  } else if (_this3.active === SidebarView.OUTLINE) {
@@ -326,14 +385,19 @@ var PDFSidebar = function () {
326
385
  this.eventBus.on('attachmentsloaded', function (evt) {
327
386
  if (evt.attachmentsCount) {
328
387
  _this3.attachmentsButton.disabled = false;
388
+
329
389
  _this3._showUINotification(SidebarView.ATTACHMENTS);
390
+
330
391
  return;
331
392
  }
393
+
332
394
  Promise.resolve().then(function () {
333
395
  if (_this3.attachmentsView.hasChildNodes()) {
334
396
  return;
335
397
  }
398
+
336
399
  _this3.attachmentsButton.disabled = true;
400
+
337
401
  if (_this3.active === SidebarView.ATTACHMENTS) {
338
402
  _this3.switchView(SidebarView.THUMBS);
339
403
  }
@@ -346,22 +410,22 @@ var PDFSidebar = function () {
346
410
  });
347
411
  }
348
412
  }, {
349
- key: 'visibleView',
413
+ key: "visibleView",
350
414
  get: function get() {
351
415
  return this.isOpen ? this.active : SidebarView.NONE;
352
416
  }
353
417
  }, {
354
- key: 'isThumbnailViewVisible',
418
+ key: "isThumbnailViewVisible",
355
419
  get: function get() {
356
420
  return this.isOpen && this.active === SidebarView.THUMBS;
357
421
  }
358
422
  }, {
359
- key: 'isOutlineViewVisible',
423
+ key: "isOutlineViewVisible",
360
424
  get: function get() {
361
425
  return this.isOpen && this.active === SidebarView.OUTLINE;
362
426
  }
363
427
  }, {
364
- key: 'isAttachmentsViewVisible',
428
+ key: "isAttachmentsViewVisible",
365
429
  get: function get() {
366
430
  return this.isOpen && this.active === SidebarView.ATTACHMENTS;
367
431
  }
@@ -370,5 +434,4 @@ var PDFSidebar = function () {
370
434
  return PDFSidebar;
371
435
  }();
372
436
 
373
- exports.SidebarView = SidebarView;
374
437
  exports.PDFSidebar = PDFSidebar;
@@ -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,24 +19,28 @@
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.PDFSidebarResizer = undefined;
27
+ exports.PDFSidebarResizer = void 0;
28
28
 
29
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
30
-
31
- var _ui_utils = require('./ui_utils');
29
+ var _ui_utils = require("./ui_utils");
32
30
 
33
31
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
34
32
 
33
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
34
+
35
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
36
+
35
37
  var SIDEBAR_WIDTH_VAR = '--sidebar-width';
36
38
  var SIDEBAR_MIN_WIDTH = 200;
37
39
  var SIDEBAR_RESIZING_CLASS = 'sidebarResizing';
38
40
 
39
- var PDFSidebarResizer = function () {
41
+ var PDFSidebarResizer =
42
+ /*#__PURE__*/
43
+ function () {
40
44
  function PDFSidebarResizer(options, eventBus) {
41
45
  var _this = this;
42
46
 
@@ -55,66 +59,79 @@ var PDFSidebarResizer = function () {
55
59
  this.resizer = options.resizer;
56
60
  this.eventBus = eventBus;
57
61
  this.l10n = l10n;
58
- if (typeof CSS === 'undefined' || typeof CSS.supports !== 'function' || !CSS.supports(SIDEBAR_WIDTH_VAR, 'calc(-1 * ' + SIDEBAR_MIN_WIDTH + 'px)')) {
62
+
63
+ if (typeof CSS === 'undefined' || typeof CSS.supports !== 'function' || !CSS.supports(SIDEBAR_WIDTH_VAR, "calc(-1 * ".concat(SIDEBAR_MIN_WIDTH, "px)"))) {
59
64
  console.warn('PDFSidebarResizer: ' + 'The browser does not support resizing of the sidebar.');
60
65
  return;
61
66
  }
67
+
62
68
  this.enabled = true;
63
69
  this.resizer.classList.remove('hidden');
64
70
  this.l10n.getDirection().then(function (dir) {
65
71
  _this.isRTL = dir === 'rtl';
66
72
  });
73
+
67
74
  this._addEventListeners();
68
75
  }
69
76
 
70
77
  _createClass(PDFSidebarResizer, [{
71
- key: '_updateWidth',
78
+ key: "_updateWidth",
72
79
  value: function _updateWidth() {
73
80
  var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
74
81
 
75
82
  if (!this.enabled) {
76
83
  return false;
77
84
  }
85
+
78
86
  var maxWidth = Math.floor(this.outerContainerWidth / 2);
87
+
79
88
  if (width > maxWidth) {
80
89
  width = maxWidth;
81
90
  }
91
+
82
92
  if (width < SIDEBAR_MIN_WIDTH) {
83
93
  width = SIDEBAR_MIN_WIDTH;
84
94
  }
95
+
85
96
  if (width === this._width) {
86
97
  return false;
87
98
  }
99
+
88
100
  this._width = width;
89
- this.doc.style.setProperty(SIDEBAR_WIDTH_VAR, width + 'px');
101
+ this.doc.style.setProperty(SIDEBAR_WIDTH_VAR, "".concat(width, "px"));
90
102
  return true;
91
103
  }
92
104
  }, {
93
- key: '_mouseMove',
105
+ key: "_mouseMove",
94
106
  value: function _mouseMove(evt) {
95
107
  var width = evt.clientX;
108
+
96
109
  if (this.isRTL) {
97
110
  width = this.outerContainerWidth - width;
98
111
  }
112
+
99
113
  this._updateWidth(width);
100
114
  }
101
115
  }, {
102
- key: '_mouseUp',
116
+ key: "_mouseUp",
103
117
  value: function _mouseUp(evt) {
104
118
  this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
105
- this.eventBus.dispatch('resize', { source: this });
119
+ this.eventBus.dispatch('resize', {
120
+ source: this
121
+ });
106
122
  var _boundEvents = this._boundEvents;
107
123
  window.removeEventListener('mousemove', _boundEvents.mouseMove);
108
124
  window.removeEventListener('mouseup', _boundEvents.mouseUp);
109
125
  }
110
126
  }, {
111
- key: '_addEventListeners',
127
+ key: "_addEventListeners",
112
128
  value: function _addEventListeners() {
113
129
  var _this2 = this;
114
130
 
115
131
  if (!this.enabled) {
116
132
  return;
117
133
  }
134
+
118
135
  var _boundEvents = this._boundEvents;
119
136
  _boundEvents.mouseMove = this._mouseMove.bind(this);
120
137
  _boundEvents.mouseUp = this._mouseUp.bind(this);
@@ -122,7 +139,9 @@ var PDFSidebarResizer = function () {
122
139
  if (evt.button !== 0) {
123
140
  return;
124
141
  }
142
+
125
143
  _this2.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
144
+
126
145
  window.addEventListener('mousemove', _boundEvents.mouseMove);
127
146
  window.addEventListener('mouseup', _boundEvents.mouseUp);
128
147
  });
@@ -132,14 +151,20 @@ var PDFSidebarResizer = function () {
132
151
  this.eventBus.on('resize', function (evt) {
133
152
  if (evt && evt.source === window) {
134
153
  _this2._outerContainerWidth = null;
154
+
135
155
  if (_this2._width) {
136
156
  if (_this2.sidebarOpen) {
137
157
  _this2.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
158
+
138
159
  var updated = _this2._updateWidth(_this2._width);
160
+
139
161
  Promise.resolve().then(function () {
140
162
  _this2.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
163
+
141
164
  if (updated) {
142
- _this2.eventBus.dispatch('resize', { source: _this2 });
165
+ _this2.eventBus.dispatch('resize', {
166
+ source: _this2
167
+ });
143
168
  }
144
169
  });
145
170
  } else {
@@ -150,11 +175,12 @@ var PDFSidebarResizer = function () {
150
175
  });
151
176
  }
152
177
  }, {
153
- key: 'outerContainerWidth',
178
+ key: "outerContainerWidth",
154
179
  get: function get() {
155
180
  if (!this._outerContainerWidth) {
156
181
  this._outerContainerWidth = this.outerContainer.clientWidth;
157
182
  }
183
+
158
184
  return this._outerContainerWidth;
159
185
  }
160
186
  }]);