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
@@ -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,157 +19,165 @@
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.PDFSinglePageViewer = undefined;
27
+ exports.PDFSinglePageViewer = 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 _base_viewer = require("./base_viewer");
30
30
 
31
- var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
31
+ var _pdf = require("../pdf");
32
32
 
33
- var _base_viewer = require('./base_viewer');
33
+ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
34
34
 
35
- var _ui_utils = require('./ui_utils');
35
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
36
36
 
37
- var _pdf = require('../pdf');
37
+ 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); } }
38
38
 
39
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
39
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
40
+
41
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
42
+
43
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
44
+
45
+ function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
40
46
 
41
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
47
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
42
48
 
43
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
49
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
44
50
 
45
- var PDFSinglePageViewer = function (_BaseViewer) {
51
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
52
+
53
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
54
+
55
+ var PDFSinglePageViewer =
56
+ /*#__PURE__*/
57
+ function (_BaseViewer) {
46
58
  _inherits(PDFSinglePageViewer, _BaseViewer);
47
59
 
48
60
  function PDFSinglePageViewer(options) {
61
+ var _this;
62
+
49
63
  _classCallCheck(this, PDFSinglePageViewer);
50
64
 
51
- var _this = _possibleConstructorReturn(this, (PDFSinglePageViewer.__proto__ || Object.getPrototypeOf(PDFSinglePageViewer)).call(this, options));
65
+ _this = _possibleConstructorReturn(this, _getPrototypeOf(PDFSinglePageViewer).call(this, options));
52
66
 
53
67
  _this.eventBus.on('pagesinit', function (evt) {
54
68
  _this._ensurePageViewVisible();
55
69
  });
70
+
56
71
  return _this;
57
72
  }
58
73
 
59
74
  _createClass(PDFSinglePageViewer, [{
60
- key: '_resetView',
75
+ key: "_resetView",
61
76
  value: function _resetView() {
62
- _get(PDFSinglePageViewer.prototype.__proto__ || Object.getPrototypeOf(PDFSinglePageViewer.prototype), '_resetView', this).call(this);
77
+ _get(_getPrototypeOf(PDFSinglePageViewer.prototype), "_resetView", this).call(this);
78
+
63
79
  this._previousPageNumber = 1;
64
80
  this._shadowViewer = document.createDocumentFragment();
81
+ this._updateScrollDown = null;
65
82
  }
66
83
  }, {
67
- key: '_ensurePageViewVisible',
84
+ key: "_ensurePageViewVisible",
68
85
  value: function _ensurePageViewVisible() {
69
86
  var pageView = this._pages[this._currentPageNumber - 1];
70
87
  var previousPageView = this._pages[this._previousPageNumber - 1];
71
88
  var viewerNodes = this.viewer.childNodes;
89
+
72
90
  switch (viewerNodes.length) {
73
91
  case 0:
74
92
  this.viewer.appendChild(pageView.div);
75
93
  break;
94
+
76
95
  case 1:
77
96
  if (viewerNodes[0] !== previousPageView.div) {
78
97
  throw new Error('_ensurePageViewVisible: Unexpected previously visible page.');
79
98
  }
99
+
80
100
  if (pageView === previousPageView) {
81
101
  break;
82
102
  }
103
+
83
104
  this._shadowViewer.appendChild(previousPageView.div);
105
+
84
106
  this.viewer.appendChild(pageView.div);
85
107
  this.container.scrollTop = 0;
86
108
  break;
109
+
87
110
  default:
88
111
  throw new Error('_ensurePageViewVisible: Only one page should be visible at a time.');
89
112
  }
113
+
90
114
  this._previousPageNumber = this._currentPageNumber;
91
115
  }
92
116
  }, {
93
- key: '_scrollUpdate',
117
+ key: "_scrollUpdate",
94
118
  value: function _scrollUpdate() {
95
119
  if (this._updateScrollDown) {
96
120
  this._updateScrollDown();
97
121
  }
98
- _get(PDFSinglePageViewer.prototype.__proto__ || Object.getPrototypeOf(PDFSinglePageViewer.prototype), '_scrollUpdate', this).call(this);
122
+
123
+ _get(_getPrototypeOf(PDFSinglePageViewer.prototype), "_scrollUpdate", this).call(this);
99
124
  }
100
125
  }, {
101
- key: '_scrollIntoView',
126
+ key: "_scrollIntoView",
102
127
  value: function _scrollIntoView(_ref) {
103
128
  var _this2 = this;
104
129
 
105
130
  var pageDiv = _ref.pageDiv,
106
131
  _ref$pageSpot = _ref.pageSpot,
107
- pageSpot = _ref$pageSpot === undefined ? null : _ref$pageSpot,
132
+ pageSpot = _ref$pageSpot === void 0 ? null : _ref$pageSpot,
108
133
  _ref$pageNumber = _ref.pageNumber,
109
- pageNumber = _ref$pageNumber === undefined ? null : _ref$pageNumber;
134
+ pageNumber = _ref$pageNumber === void 0 ? null : _ref$pageNumber;
110
135
 
111
136
  if (pageNumber) {
112
137
  this._setCurrentPageNumber(pageNumber);
113
138
  }
139
+
114
140
  var scrolledDown = this._currentPageNumber >= this._previousPageNumber;
115
- var previousLocation = this._location;
141
+
116
142
  this._ensurePageViewVisible();
117
- (0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
143
+
144
+ this.update();
145
+
146
+ _get(_getPrototypeOf(PDFSinglePageViewer.prototype), "_scrollIntoView", this).call(this, {
147
+ pageDiv: pageDiv,
148
+ pageSpot: pageSpot,
149
+ pageNumber: pageNumber
150
+ });
151
+
118
152
  this._updateScrollDown = function () {
119
153
  _this2.scroll.down = scrolledDown;
120
- delete _this2._updateScrollDown;
154
+ _this2._updateScrollDown = null;
121
155
  };
122
- setTimeout(function () {
123
- if (_this2._location === previousLocation) {
124
- if (_this2._updateScrollDown) {
125
- _this2._updateScrollDown();
126
- }
127
- _this2.update();
128
- }
129
- }, 0);
130
156
  }
131
157
  }, {
132
- key: '_getVisiblePages',
158
+ key: "_getVisiblePages",
133
159
  value: function _getVisiblePages() {
134
- if (!this.pagesCount) {
135
- return { views: [] };
136
- }
137
- var pageView = this._pages[this._currentPageNumber - 1];
138
- var element = pageView.div;
139
- var view = {
140
- id: pageView.id,
141
- x: element.offsetLeft + element.clientLeft,
142
- y: element.offsetTop + element.clientTop,
143
- view: pageView
144
- };
145
- return {
146
- first: view,
147
- last: view,
148
- views: [view]
149
- };
160
+ return this._getCurrentVisiblePage();
150
161
  }
151
162
  }, {
152
- key: 'update',
153
- value: function update() {
154
- var visible = this._getVisiblePages();
155
- var visiblePages = visible.views,
156
- numVisiblePages = visiblePages.length;
157
- if (numVisiblePages === 0) {
158
- return;
159
- }
160
- this._resizeBuffer(numVisiblePages);
161
- this.renderingQueue.renderHighestPriority(visible);
162
- this._updateLocation(visible.first);
163
- this.eventBus.dispatch('updateviewarea', {
164
- source: this,
165
- location: this._location
166
- });
167
- }
163
+ key: "_updateHelper",
164
+ value: function _updateHelper(visiblePages) {}
165
+ }, {
166
+ key: "_updateScrollMode",
167
+ value: function _updateScrollMode() {}
168
168
  }, {
169
- key: '_setDocumentViewerElement',
169
+ key: "_updateSpreadMode",
170
+ value: function _updateSpreadMode() {}
171
+ }, {
172
+ key: "_setDocumentViewerElement",
170
173
  get: function get() {
171
174
  return (0, _pdf.shadow)(this, '_setDocumentViewerElement', this._shadowViewer);
172
175
  }
176
+ }, {
177
+ key: "_isScrollModeHorizontal",
178
+ get: function get() {
179
+ return (0, _pdf.shadow)(this, '_isScrollModeHorizontal', false);
180
+ }
173
181
  }]);
174
182
 
175
183
  return PDFSinglePageViewer;
@@ -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,39 +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.PDFThumbnailView = undefined;
27
+ exports.PDFThumbnailView = 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 _pdf = require("../pdf");
30
30
 
31
- var _pdf = require('../pdf');
31
+ var _ui_utils = require("./ui_utils");
32
32
 
33
- var _ui_utils = require('./ui_utils');
34
-
35
- var _pdf_rendering_queue = require('./pdf_rendering_queue');
33
+ var _pdf_rendering_queue = require("./pdf_rendering_queue");
36
34
 
37
35
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
38
36
 
37
+ 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); } }
38
+
39
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
40
+
39
41
  var MAX_NUM_SCALING_STEPS = 3;
40
42
  var THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
41
43
  var THUMBNAIL_WIDTH = 98;
44
+
42
45
  var TempImageFactory = function TempImageFactoryClosure() {
43
46
  var tempCanvasCache = null;
44
47
  return {
45
48
  getCanvas: function getCanvas(width, height) {
46
49
  var tempCanvas = tempCanvasCache;
50
+
47
51
  if (!tempCanvas) {
48
52
  tempCanvas = document.createElement('canvas');
49
53
  tempCanvasCache = tempCanvas;
50
54
  }
55
+
51
56
  tempCanvas.width = width;
52
57
  tempCanvas.height = height;
53
58
  tempCanvas.mozOpaque = true;
54
- var ctx = tempCanvas.getContext('2d', { alpha: false });
59
+ var ctx = tempCanvas.getContext('2d', {
60
+ alpha: false
61
+ });
55
62
  ctx.save();
56
63
  ctx.fillStyle = 'rgb(255, 255, 255)';
57
64
  ctx.fillRect(0, 0, width, height);
@@ -60,16 +67,20 @@ var TempImageFactory = function TempImageFactoryClosure() {
60
67
  },
61
68
  destroyCanvas: function destroyCanvas() {
62
69
  var tempCanvas = tempCanvasCache;
70
+
63
71
  if (tempCanvas) {
64
72
  tempCanvas.width = 0;
65
73
  tempCanvas.height = 0;
66
74
  }
75
+
67
76
  tempCanvasCache = null;
68
77
  }
69
78
  };
70
79
  }();
71
80
 
72
- var PDFThumbnailView = function () {
81
+ var PDFThumbnailView =
82
+ /*#__PURE__*/
83
+ function () {
73
84
  function PDFThumbnailView(_ref) {
74
85
  var container = _ref.container,
75
86
  id = _ref.id,
@@ -77,9 +88,9 @@ var PDFThumbnailView = function () {
77
88
  linkService = _ref.linkService,
78
89
  renderingQueue = _ref.renderingQueue,
79
90
  _ref$disableCanvasToI = _ref.disableCanvasToImageConversion,
80
- disableCanvasToImageConversion = _ref$disableCanvasToI === undefined ? false : _ref$disableCanvasToI,
91
+ disableCanvasToImageConversion = _ref$disableCanvasToI === void 0 ? false : _ref$disableCanvasToI,
81
92
  _ref$l10n = _ref.l10n,
82
- l10n = _ref$l10n === undefined ? _ui_utils.NullL10n : _ref$l10n;
93
+ l10n = _ref$l10n === void 0 ? _ui_utils.NullL10n : _ref$l10n;
83
94
 
84
95
  _classCallCheck(this, PDFThumbnailView);
85
96
 
@@ -105,13 +116,17 @@ var PDFThumbnailView = function () {
105
116
  this.l10n = l10n;
106
117
  var anchor = document.createElement('a');
107
118
  anchor.href = linkService.getAnchorUrl('#page=' + id);
108
- this.l10n.get('thumb_page_title', { page: id }, 'Page {{page}}').then(function (msg) {
119
+ this.l10n.get('thumb_page_title', {
120
+ page: id
121
+ }, 'Page {{page}}').then(function (msg) {
109
122
  anchor.title = msg;
110
123
  });
124
+
111
125
  anchor.onclick = function () {
112
126
  linkService.page = id;
113
127
  return false;
114
128
  };
129
+
115
130
  this.anchor = anchor;
116
131
  var div = document.createElement('div');
117
132
  div.className = 'thumbnail';
@@ -129,18 +144,22 @@ var PDFThumbnailView = function () {
129
144
  }
130
145
 
131
146
  _createClass(PDFThumbnailView, [{
132
- key: 'setPdfPage',
147
+ key: "setPdfPage",
133
148
  value: function setPdfPage(pdfPage) {
134
149
  this.pdfPage = pdfPage;
135
150
  this.pdfPageRotate = pdfPage.rotate;
136
151
  var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
137
- this.viewport = pdfPage.getViewport(1, totalRotation);
152
+ this.viewport = pdfPage.getViewport({
153
+ scale: 1,
154
+ rotation: totalRotation
155
+ });
138
156
  this.reset();
139
157
  }
140
158
  }, {
141
- key: 'reset',
159
+ key: "reset",
142
160
  value: function reset() {
143
161
  this.cancelRendering();
162
+ this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
144
163
  this.pageWidth = this.viewport.width;
145
164
  this.pageHeight = this.viewport.height;
146
165
  this.pageRatio = this.pageWidth / this.pageHeight;
@@ -149,28 +168,33 @@ var PDFThumbnailView = function () {
149
168
  this.div.removeAttribute('data-loaded');
150
169
  var ring = this.ring;
151
170
  var childNodes = ring.childNodes;
171
+
152
172
  for (var i = childNodes.length - 1; i >= 0; i--) {
153
173
  ring.removeChild(childNodes[i]);
154
174
  }
175
+
155
176
  var borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
156
177
  ring.style.width = this.canvasWidth + borderAdjustment + 'px';
157
178
  ring.style.height = this.canvasHeight + borderAdjustment + 'px';
179
+
158
180
  if (this.canvas) {
159
181
  this.canvas.width = 0;
160
182
  this.canvas.height = 0;
161
183
  delete this.canvas;
162
184
  }
185
+
163
186
  if (this.image) {
164
187
  this.image.removeAttribute('src');
165
188
  delete this.image;
166
189
  }
167
190
  }
168
191
  }, {
169
- key: 'update',
192
+ key: "update",
170
193
  value: function update(rotation) {
171
194
  if (typeof rotation !== 'undefined') {
172
195
  this.rotation = rotation;
173
196
  }
197
+
174
198
  var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
175
199
  this.viewport = this.viewport.clone({
176
200
  scale: 1,
@@ -179,61 +203,72 @@ var PDFThumbnailView = function () {
179
203
  this.reset();
180
204
  }
181
205
  }, {
182
- key: 'cancelRendering',
206
+ key: "cancelRendering",
183
207
  value: function cancelRendering() {
184
208
  if (this.renderTask) {
185
209
  this.renderTask.cancel();
186
210
  this.renderTask = null;
187
211
  }
188
- this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
212
+
189
213
  this.resume = null;
190
214
  }
191
215
  }, {
192
- key: '_getPageDrawContext',
216
+ key: "_getPageDrawContext",
193
217
  value: function _getPageDrawContext() {
194
218
  var noCtxScale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
195
-
196
219
  var canvas = document.createElement('canvas');
197
220
  this.canvas = canvas;
198
221
  canvas.mozOpaque = true;
199
- var ctx = canvas.getContext('2d', { alpha: false });
222
+ var ctx = canvas.getContext('2d', {
223
+ alpha: false
224
+ });
200
225
  var outputScale = (0, _ui_utils.getOutputScale)(ctx);
201
226
  canvas.width = this.canvasWidth * outputScale.sx | 0;
202
227
  canvas.height = this.canvasHeight * outputScale.sy | 0;
203
228
  canvas.style.width = this.canvasWidth + 'px';
204
229
  canvas.style.height = this.canvasHeight + 'px';
230
+
205
231
  if (!noCtxScale && outputScale.scaled) {
206
232
  ctx.scale(outputScale.sx, outputScale.sy);
207
233
  }
234
+
208
235
  return ctx;
209
236
  }
210
237
  }, {
211
- key: '_convertCanvasToImage',
238
+ key: "_convertCanvasToImage",
212
239
  value: function _convertCanvasToImage() {
213
240
  var _this = this;
214
241
 
215
242
  if (!this.canvas) {
216
243
  return;
217
244
  }
245
+
218
246
  if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
219
247
  return;
220
248
  }
249
+
221
250
  var id = this.renderingId;
222
251
  var className = 'thumbnailImage';
252
+
223
253
  if (this.disableCanvasToImageConversion) {
224
254
  this.canvas.id = id;
225
255
  this.canvas.className = className;
226
- this.l10n.get('thumb_page_canvas', { page: this.pageId }, 'Thumbnail of Page {{page}}').then(function (msg) {
256
+ this.l10n.get('thumb_page_canvas', {
257
+ page: this.pageId
258
+ }, 'Thumbnail of Page {{page}}').then(function (msg) {
227
259
  _this.canvas.setAttribute('aria-label', msg);
228
260
  });
229
261
  this.div.setAttribute('data-loaded', true);
230
262
  this.ring.appendChild(this.canvas);
231
263
  return;
232
264
  }
265
+
233
266
  var image = document.createElement('img');
234
267
  image.id = id;
235
268
  image.className = className;
236
- this.l10n.get('thumb_page_canvas', { page: this.pageId }, 'Thumbnail of Page {{page}}').then(function (msg) {
269
+ this.l10n.get('thumb_page_canvas', {
270
+ page: this.pageId
271
+ }, 'Thumbnail of Page {{page}}').then(function (msg) {
237
272
  image.setAttribute('aria-label', msg);
238
273
  });
239
274
  image.style.width = this.canvasWidth + 'px';
@@ -247,7 +282,7 @@ var PDFThumbnailView = function () {
247
282
  delete this.canvas;
248
283
  }
249
284
  }, {
250
- key: 'draw',
285
+ key: "draw",
251
286
  value: function draw() {
252
287
  var _this2 = this;
253
288
 
@@ -255,37 +290,52 @@ var PDFThumbnailView = function () {
255
290
  console.error('Must be in new state before drawing');
256
291
  return Promise.resolve(undefined);
257
292
  }
293
+
258
294
  this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
259
295
  var renderCapability = (0, _pdf.createPromiseCapability)();
296
+
260
297
  var finishRenderTask = function finishRenderTask(error) {
261
298
  if (renderTask === _this2.renderTask) {
262
299
  _this2.renderTask = null;
263
300
  }
301
+
264
302
  if (error instanceof _pdf.RenderingCancelledException) {
265
303
  renderCapability.resolve(undefined);
266
304
  return;
267
305
  }
306
+
268
307
  _this2.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
308
+
269
309
  _this2._convertCanvasToImage();
310
+
270
311
  if (!error) {
271
312
  renderCapability.resolve(undefined);
272
313
  } else {
273
314
  renderCapability.reject(error);
274
315
  }
275
316
  };
317
+
276
318
  var ctx = this._getPageDrawContext();
277
- var drawViewport = this.viewport.clone({ scale: this.scale });
319
+
320
+ var drawViewport = this.viewport.clone({
321
+ scale: this.scale
322
+ });
323
+
278
324
  var renderContinueCallback = function renderContinueCallback(cont) {
279
325
  if (!_this2.renderingQueue.isHighestPriority(_this2)) {
280
326
  _this2.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
327
+
281
328
  _this2.resume = function () {
282
329
  _this2.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
283
330
  cont();
284
331
  };
332
+
285
333
  return;
286
334
  }
335
+
287
336
  cont();
288
337
  };
338
+
289
339
  var renderContext = {
290
340
  canvasContext: ctx,
291
341
  viewport: drawViewport
@@ -300,56 +350,77 @@ var PDFThumbnailView = function () {
300
350
  return renderCapability.promise;
301
351
  }
302
352
  }, {
303
- key: 'setImage',
353
+ key: "setImage",
304
354
  value: function setImage(pageView) {
305
355
  if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
306
356
  return;
307
357
  }
358
+
308
359
  var img = pageView.canvas;
360
+
309
361
  if (!img) {
310
362
  return;
311
363
  }
364
+
312
365
  if (!this.pdfPage) {
313
366
  this.setPdfPage(pageView.pdfPage);
314
367
  }
368
+
315
369
  this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
370
+
316
371
  var ctx = this._getPageDrawContext(true);
372
+
317
373
  var canvas = ctx.canvas;
374
+
318
375
  if (img.width <= 2 * canvas.width) {
319
376
  ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
377
+
320
378
  this._convertCanvasToImage();
379
+
321
380
  return;
322
381
  }
382
+
323
383
  var reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
324
384
  var reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
325
385
  var reducedImage = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
326
386
  var reducedImageCtx = reducedImage.getContext('2d');
387
+
327
388
  while (reducedWidth > img.width || reducedHeight > img.height) {
328
389
  reducedWidth >>= 1;
329
390
  reducedHeight >>= 1;
330
391
  }
392
+
331
393
  reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
394
+
332
395
  while (reducedWidth > 2 * canvas.width) {
333
396
  reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
334
397
  reducedWidth >>= 1;
335
398
  reducedHeight >>= 1;
336
399
  }
400
+
337
401
  ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
402
+
338
403
  this._convertCanvasToImage();
339
404
  }
340
405
  }, {
341
- key: 'setPageLabel',
406
+ key: "setPageLabel",
342
407
  value: function setPageLabel(label) {
343
408
  var _this3 = this;
344
409
 
345
410
  this.pageLabel = typeof label === 'string' ? label : null;
346
- this.l10n.get('thumb_page_title', { page: this.pageId }, 'Page {{page}}').then(function (msg) {
411
+ this.l10n.get('thumb_page_title', {
412
+ page: this.pageId
413
+ }, 'Page {{page}}').then(function (msg) {
347
414
  _this3.anchor.title = msg;
348
415
  });
416
+
349
417
  if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
350
418
  return;
351
419
  }
352
- this.l10n.get('thumb_page_canvas', { page: this.pageId }, 'Thumbnail of Page {{page}}').then(function (ariaLabel) {
420
+
421
+ this.l10n.get('thumb_page_canvas', {
422
+ page: this.pageId
423
+ }, 'Thumbnail of Page {{page}}').then(function (ariaLabel) {
353
424
  if (_this3.image) {
354
425
  _this3.image.setAttribute('aria-label', ariaLabel);
355
426
  } else if (_this3.disableCanvasToImageConversion && _this3.canvas) {
@@ -358,12 +429,12 @@ var PDFThumbnailView = function () {
358
429
  });
359
430
  }
360
431
  }, {
361
- key: 'pageId',
432
+ key: "pageId",
362
433
  get: function get() {
363
434
  return this.pageLabel !== null ? this.pageLabel : this.id;
364
435
  }
365
436
  }], [{
366
- key: 'cleanup',
437
+ key: "cleanup",
367
438
  value: function cleanup() {
368
439
  TempImageFactory.destroyCanvas();
369
440
  }