pdfjs-dist 2.3.200 → 2.4.456

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 (185) hide show
  1. package/README.md +4 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +6499 -17971
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +22 -1
  6. package/build/pdf.worker.entry.js +5 -3
  7. package/build/pdf.worker.js +19303 -29896
  8. package/build/pdf.worker.js.map +1 -1
  9. package/build/pdf.worker.min.js +22 -1
  10. package/es5/build/pdf.js +25473 -0
  11. package/es5/build/pdf.js.map +1 -0
  12. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  13. package/es5/build/pdf.worker.js +57878 -0
  14. package/es5/build/pdf.worker.js.map +1 -0
  15. package/es5/web/images/annotation-check.svg +11 -0
  16. package/es5/web/images/annotation-comment.svg +16 -0
  17. package/es5/web/images/annotation-help.svg +26 -0
  18. package/es5/web/images/annotation-insert.svg +10 -0
  19. package/es5/web/images/annotation-key.svg +11 -0
  20. package/es5/web/images/annotation-newparagraph.svg +11 -0
  21. package/es5/web/images/annotation-noicon.svg +7 -0
  22. package/es5/web/images/annotation-note.svg +42 -0
  23. package/es5/web/images/annotation-paragraph.svg +16 -0
  24. package/es5/web/images/loading-icon.gif +0 -0
  25. package/es5/web/images/shadow.png +0 -0
  26. package/es5/web/images/texture.png +0 -0
  27. package/es5/web/pdf_viewer.css +407 -0
  28. package/es5/web/pdf_viewer.js +7757 -0
  29. package/es5/web/pdf_viewer.js.map +1 -0
  30. package/image_decoders/pdf.image_decoders.js +1333 -4839
  31. package/image_decoders/pdf.image_decoders.js.map +1 -1
  32. package/image_decoders/pdf.image_decoders.min.js +22 -1
  33. package/lib/README.md +7 -0
  34. package/lib/core/annotation.js +683 -1066
  35. package/lib/core/arithmetic_decoder.js +81 -97
  36. package/lib/core/bidi.js +54 -46
  37. package/lib/core/ccitt.js +88 -81
  38. package/lib/core/ccitt_stream.js +15 -14
  39. package/lib/core/cff_parser.js +196 -193
  40. package/lib/core/charsets.js +4 -4
  41. package/lib/core/chunked_stream.js +441 -569
  42. package/lib/core/cmap.js +220 -279
  43. package/lib/core/colorspace.js +699 -863
  44. package/lib/core/core_utils.js +59 -80
  45. package/lib/core/crypto.js +379 -437
  46. package/lib/core/document.js +564 -673
  47. package/lib/core/encodings.js +15 -15
  48. package/lib/core/evaluator.js +983 -889
  49. package/lib/core/font_renderer.js +128 -171
  50. package/lib/core/fonts.js +451 -400
  51. package/lib/core/function.js +289 -285
  52. package/lib/core/glyphlist.js +4527 -4527
  53. package/lib/core/image.js +138 -117
  54. package/lib/core/image_utils.js +46 -63
  55. package/lib/core/jbig2.js +324 -332
  56. package/lib/core/jbig2_stream.js +18 -17
  57. package/lib/core/jpeg_stream.js +133 -24
  58. package/lib/core/jpg.js +238 -210
  59. package/lib/core/jpx.js +158 -157
  60. package/lib/core/jpx_stream.js +28 -28
  61. package/lib/core/metrics.js +2928 -2928
  62. package/lib/core/murmurhash3.js +87 -102
  63. package/lib/core/obj.js +1111 -1302
  64. package/lib/core/operator_list.js +55 -42
  65. package/lib/core/parser.js +956 -987
  66. package/lib/core/pattern.js +69 -69
  67. package/lib/core/pdf_manager.js +149 -316
  68. package/lib/core/primitives.js +45 -77
  69. package/lib/core/ps_parser.js +175 -214
  70. package/lib/core/standard_fonts.js +237 -236
  71. package/lib/core/stream.js +83 -77
  72. package/lib/core/type1_parser.js +78 -68
  73. package/lib/core/unicode.js +1654 -1654
  74. package/lib/core/worker.js +148 -196
  75. package/lib/core/worker_stream.js +101 -210
  76. package/lib/display/annotation_layer.js +733 -1155
  77. package/lib/display/api.js +1539 -1928
  78. package/lib/display/api_compatibility.js +10 -8
  79. package/lib/display/canvas.js +159 -158
  80. package/lib/display/content_disposition.js +36 -55
  81. package/lib/display/display_utils.js +298 -551
  82. package/lib/display/fetch_stream.js +181 -305
  83. package/lib/display/font_loader.js +273 -416
  84. package/lib/display/metadata.js +86 -98
  85. package/lib/display/network.js +376 -511
  86. package/lib/display/network_utils.js +20 -19
  87. package/lib/display/node_stream.js +276 -460
  88. package/lib/display/pattern_helper.js +76 -44
  89. package/lib/display/svg.js +1137 -1405
  90. package/lib/display/text_layer.js +75 -82
  91. package/lib/display/transport_stream.js +236 -374
  92. package/lib/display/webgl.js +70 -83
  93. package/lib/display/worker_options.js +3 -3
  94. package/lib/display/xml_parser.js +303 -392
  95. package/lib/examples/node/domstubs.js +37 -37
  96. package/lib/pdf.js +22 -21
  97. package/lib/pdf.worker.js +5 -5
  98. package/lib/shared/compatibility.js +2 -251
  99. package/lib/shared/is_node.js +7 -6
  100. package/lib/shared/message_handler.js +222 -194
  101. package/lib/shared/util.js +269 -405
  102. package/lib/test/unit/annotation_spec.js +1089 -1014
  103. package/lib/test/unit/api_spec.js +617 -544
  104. package/lib/test/unit/bidi_spec.js +7 -7
  105. package/lib/test/unit/cff_parser_spec.js +63 -62
  106. package/lib/test/unit/clitests_helper.js +7 -9
  107. package/lib/test/unit/cmap_spec.js +84 -86
  108. package/lib/test/unit/colorspace_spec.js +154 -154
  109. package/lib/test/unit/core_utils_spec.js +125 -105
  110. package/lib/test/unit/crypto_spec.js +181 -181
  111. package/lib/test/unit/custom_spec.js +22 -24
  112. package/lib/test/unit/display_svg_spec.js +35 -36
  113. package/lib/test/unit/display_utils_spec.js +139 -149
  114. package/lib/test/unit/document_spec.js +16 -16
  115. package/lib/test/unit/encodings_spec.js +12 -34
  116. package/lib/test/unit/evaluator_spec.js +81 -95
  117. package/lib/test/unit/fetch_stream_spec.js +30 -30
  118. package/lib/test/unit/function_spec.js +206 -204
  119. package/lib/test/unit/jasmine-boot.js +48 -32
  120. package/lib/test/unit/message_handler_spec.js +172 -162
  121. package/lib/test/unit/metadata_spec.js +69 -69
  122. package/lib/test/unit/murmurhash3_spec.js +12 -12
  123. package/lib/test/unit/network_spec.js +12 -12
  124. package/lib/test/unit/network_utils_spec.js +152 -152
  125. package/lib/test/unit/node_stream_spec.js +74 -90
  126. package/lib/test/unit/parser_spec.js +107 -113
  127. package/lib/test/unit/pdf_find_controller_spec.js +55 -86
  128. package/lib/test/unit/pdf_find_utils_spec.js +32 -32
  129. package/lib/test/unit/pdf_history_spec.js +32 -32
  130. package/lib/test/unit/primitives_spec.js +117 -115
  131. package/lib/test/unit/stream_spec.js +16 -14
  132. package/lib/test/unit/test_utils.js +119 -285
  133. package/lib/test/unit/testreporter.js +19 -19
  134. package/lib/test/unit/type1_parser_spec.js +41 -41
  135. package/lib/test/unit/ui_utils_spec.js +318 -426
  136. package/lib/test/unit/unicode_spec.js +42 -42
  137. package/lib/test/unit/util_spec.js +122 -143
  138. package/lib/web/annotation_layer_builder.js +66 -103
  139. package/lib/web/app.js +1166 -1196
  140. package/lib/web/app_options.js +61 -77
  141. package/lib/web/base_viewer.js +804 -850
  142. package/lib/web/chromecom.js +164 -249
  143. package/lib/web/debugger.js +149 -205
  144. package/lib/web/download_manager.js +38 -57
  145. package/lib/web/firefox_print_service.js +35 -30
  146. package/lib/web/firefoxcom.js +175 -374
  147. package/lib/web/genericcom.js +26 -108
  148. package/lib/web/genericl10n.js +24 -153
  149. package/lib/web/grab_to_pan.js +30 -30
  150. package/lib/web/interfaces.js +80 -258
  151. package/lib/web/overlay_manager.js +70 -246
  152. package/lib/web/password_prompt.js +38 -64
  153. package/lib/web/pdf_attachment_viewer.js +105 -130
  154. package/lib/web/pdf_cursor_tools.js +75 -102
  155. package/lib/web/pdf_document_properties.js +227 -376
  156. package/lib/web/pdf_find_bar.js +137 -171
  157. package/lib/web/pdf_find_controller.js +492 -549
  158. package/lib/web/pdf_find_utils.js +13 -13
  159. package/lib/web/pdf_history.js +395 -406
  160. package/lib/web/pdf_link_service.js +302 -349
  161. package/lib/web/pdf_outline_viewer.js +148 -209
  162. package/lib/web/pdf_page_view.js +449 -507
  163. package/lib/web/pdf_presentation_mode.js +304 -357
  164. package/lib/web/pdf_print_service.js +90 -104
  165. package/lib/web/pdf_rendering_queue.js +87 -108
  166. package/lib/web/pdf_sidebar.js +264 -304
  167. package/lib/web/pdf_sidebar_resizer.js +92 -119
  168. package/lib/web/pdf_single_page_viewer.js +77 -126
  169. package/lib/web/pdf_thumbnail_view.js +276 -297
  170. package/lib/web/pdf_thumbnail_viewer.js +186 -206
  171. package/lib/web/pdf_viewer.component.js +20 -21
  172. package/lib/web/pdf_viewer.js +55 -115
  173. package/lib/web/preferences.js +66 -273
  174. package/lib/web/secondary_toolbar.js +164 -196
  175. package/lib/web/text_layer_builder.js +284 -317
  176. package/lib/web/toolbar.js +216 -211
  177. package/lib/web/ui_utils.js +303 -404
  178. package/lib/web/view_history.js +49 -222
  179. package/lib/web/viewer_compatibility.js +7 -5
  180. package/package.json +2 -9
  181. package/web/pdf_viewer.css +25 -18
  182. package/web/pdf_viewer.js +3481 -4764
  183. package/web/pdf_viewer.js.map +1 -1
  184. package/webpack.js +14 -5
  185. package/lib/shared/streams_polyfill.js +0 -43
@@ -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 2019 Mozilla Foundation
5
+ * Copyright 2020 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.
@@ -28,45 +28,40 @@ exports.PDFThumbnailView = void 0;
28
28
 
29
29
  var _pdf = require("../pdf");
30
30
 
31
- var _ui_utils = require("./ui_utils");
31
+ var _ui_utils = require("./ui_utils.js");
32
32
 
33
- var _pdf_rendering_queue = require("./pdf_rendering_queue");
33
+ var _pdf_rendering_queue = require("./pdf_rendering_queue.js");
34
34
 
35
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
35
+ const MAX_NUM_SCALING_STEPS = 3;
36
+ const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
37
+ const THUMBNAIL_WIDTH = 98;
36
38
 
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
-
41
- var MAX_NUM_SCALING_STEPS = 3;
42
- var THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
43
- var THUMBNAIL_WIDTH = 98;
44
-
45
- var TempImageFactory = function TempImageFactoryClosure() {
46
- var tempCanvasCache = null;
39
+ const TempImageFactory = function TempImageFactoryClosure() {
40
+ let tempCanvasCache = null;
47
41
  return {
48
- getCanvas: function getCanvas(width, height) {
49
- var tempCanvas = tempCanvasCache;
42
+ getCanvas(width, height) {
43
+ let tempCanvas = tempCanvasCache;
50
44
 
51
45
  if (!tempCanvas) {
52
- tempCanvas = document.createElement('canvas');
46
+ tempCanvas = document.createElement("canvas");
53
47
  tempCanvasCache = tempCanvas;
54
48
  }
55
49
 
56
50
  tempCanvas.width = width;
57
51
  tempCanvas.height = height;
58
52
  tempCanvas.mozOpaque = true;
59
- var ctx = tempCanvas.getContext('2d', {
53
+ const ctx = tempCanvas.getContext("2d", {
60
54
  alpha: false
61
55
  });
62
56
  ctx.save();
63
- ctx.fillStyle = 'rgb(255, 255, 255)';
57
+ ctx.fillStyle = "rgb(255, 255, 255)";
64
58
  ctx.fillRect(0, 0, width, height);
65
59
  ctx.restore();
66
60
  return tempCanvas;
67
61
  },
68
- destroyCanvas: function destroyCanvas() {
69
- var tempCanvas = tempCanvasCache;
62
+
63
+ destroyCanvas() {
64
+ const tempCanvas = tempCanvasCache;
70
65
 
71
66
  if (tempCanvas) {
72
67
  tempCanvas.width = 0;
@@ -75,27 +70,22 @@ var TempImageFactory = function TempImageFactoryClosure() {
75
70
 
76
71
  tempCanvasCache = null;
77
72
  }
73
+
78
74
  };
79
75
  }();
80
76
 
81
- var PDFThumbnailView =
82
- /*#__PURE__*/
83
- function () {
84
- function PDFThumbnailView(_ref) {
85
- var container = _ref.container,
86
- id = _ref.id,
87
- defaultViewport = _ref.defaultViewport,
88
- linkService = _ref.linkService,
89
- renderingQueue = _ref.renderingQueue,
90
- _ref$disableCanvasToI = _ref.disableCanvasToImageConversion,
91
- disableCanvasToImageConversion = _ref$disableCanvasToI === void 0 ? false : _ref$disableCanvasToI,
92
- _ref$l10n = _ref.l10n,
93
- l10n = _ref$l10n === void 0 ? _ui_utils.NullL10n : _ref$l10n;
94
-
95
- _classCallCheck(this, PDFThumbnailView);
96
-
77
+ class PDFThumbnailView {
78
+ constructor({
79
+ container,
80
+ id,
81
+ defaultViewport,
82
+ linkService,
83
+ renderingQueue,
84
+ disableCanvasToImageConversion = false,
85
+ l10n = _ui_utils.NullL10n
86
+ }) {
97
87
  this.id = id;
98
- this.renderingId = 'thumbnail' + id;
88
+ this.renderingId = "thumbnail" + id;
99
89
  this.pageLabel = null;
100
90
  this.pdfPage = null;
101
91
  this.rotation = 0;
@@ -114,11 +104,10 @@ function () {
114
104
  this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
115
105
  this.scale = this.canvasWidth / this.pageWidth;
116
106
  this.l10n = l10n;
117
- var anchor = document.createElement('a');
118
- anchor.href = linkService.getAnchorUrl('#page=' + id);
119
- this.l10n.get('thumb_page_title', {
120
- page: id
121
- }, 'Page {{page}}').then(function (msg) {
107
+ const anchor = document.createElement("a");
108
+ anchor.href = linkService.getAnchorUrl("#page=" + id);
109
+
110
+ this._thumbPageTitle.then(msg => {
122
111
  anchor.title = msg;
123
112
  });
124
113
 
@@ -128,319 +117,309 @@ function () {
128
117
  };
129
118
 
130
119
  this.anchor = anchor;
131
- var div = document.createElement('div');
132
- div.className = 'thumbnail';
133
- div.setAttribute('data-page-number', this.id);
120
+ const div = document.createElement("div");
121
+ div.className = "thumbnail";
122
+ div.setAttribute("data-page-number", this.id);
134
123
  this.div = div;
135
- var ring = document.createElement('div');
136
- ring.className = 'thumbnailSelectionRing';
137
- var borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
138
- ring.style.width = this.canvasWidth + borderAdjustment + 'px';
139
- ring.style.height = this.canvasHeight + borderAdjustment + 'px';
124
+ const ring = document.createElement("div");
125
+ ring.className = "thumbnailSelectionRing";
126
+ const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
127
+ ring.style.width = this.canvasWidth + borderAdjustment + "px";
128
+ ring.style.height = this.canvasHeight + borderAdjustment + "px";
140
129
  this.ring = ring;
141
130
  div.appendChild(ring);
142
131
  anchor.appendChild(div);
143
132
  container.appendChild(anchor);
144
133
  }
145
134
 
146
- _createClass(PDFThumbnailView, [{
147
- key: "setPdfPage",
148
- value: function setPdfPage(pdfPage) {
149
- this.pdfPage = pdfPage;
150
- this.pdfPageRotate = pdfPage.rotate;
151
- var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
152
- this.viewport = pdfPage.getViewport({
153
- scale: 1,
154
- rotation: totalRotation
155
- });
156
- this.reset();
157
- }
158
- }, {
159
- key: "reset",
160
- value: function reset() {
161
- this.cancelRendering();
162
- this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
163
- this.pageWidth = this.viewport.width;
164
- this.pageHeight = this.viewport.height;
165
- this.pageRatio = this.pageWidth / this.pageHeight;
166
- this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
167
- this.scale = this.canvasWidth / this.pageWidth;
168
- this.div.removeAttribute('data-loaded');
169
- var ring = this.ring;
170
- var childNodes = ring.childNodes;
171
-
172
- for (var i = childNodes.length - 1; i >= 0; i--) {
173
- ring.removeChild(childNodes[i]);
174
- }
135
+ setPdfPage(pdfPage) {
136
+ this.pdfPage = pdfPage;
137
+ this.pdfPageRotate = pdfPage.rotate;
138
+ const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
139
+ this.viewport = pdfPage.getViewport({
140
+ scale: 1,
141
+ rotation: totalRotation
142
+ });
143
+ this.reset();
144
+ }
175
145
 
176
- var borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
177
- ring.style.width = this.canvasWidth + borderAdjustment + 'px';
178
- ring.style.height = this.canvasHeight + borderAdjustment + 'px';
146
+ reset() {
147
+ this.cancelRendering();
148
+ this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
149
+ this.pageWidth = this.viewport.width;
150
+ this.pageHeight = this.viewport.height;
151
+ this.pageRatio = this.pageWidth / this.pageHeight;
152
+ this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
153
+ this.scale = this.canvasWidth / this.pageWidth;
154
+ this.div.removeAttribute("data-loaded");
155
+ const ring = this.ring;
156
+ const childNodes = ring.childNodes;
179
157
 
180
- if (this.canvas) {
181
- this.canvas.width = 0;
182
- this.canvas.height = 0;
183
- delete this.canvas;
184
- }
158
+ for (let i = childNodes.length - 1; i >= 0; i--) {
159
+ ring.removeChild(childNodes[i]);
160
+ }
185
161
 
186
- if (this.image) {
187
- this.image.removeAttribute('src');
188
- delete this.image;
189
- }
162
+ const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
163
+ ring.style.width = this.canvasWidth + borderAdjustment + "px";
164
+ ring.style.height = this.canvasHeight + borderAdjustment + "px";
165
+
166
+ if (this.canvas) {
167
+ this.canvas.width = 0;
168
+ this.canvas.height = 0;
169
+ delete this.canvas;
190
170
  }
191
- }, {
192
- key: "update",
193
- value: function update(rotation) {
194
- if (typeof rotation !== 'undefined') {
195
- this.rotation = rotation;
196
- }
197
171
 
198
- var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
199
- this.viewport = this.viewport.clone({
200
- scale: 1,
201
- rotation: totalRotation
202
- });
203
- this.reset();
172
+ if (this.image) {
173
+ this.image.removeAttribute("src");
174
+ delete this.image;
204
175
  }
205
- }, {
206
- key: "cancelRendering",
207
- value: function cancelRendering() {
208
- if (this.renderTask) {
209
- this.renderTask.cancel();
210
- this.renderTask = null;
211
- }
176
+ }
212
177
 
213
- this.resume = null;
178
+ update(rotation) {
179
+ if (typeof rotation !== "undefined") {
180
+ this.rotation = rotation;
214
181
  }
215
- }, {
216
- key: "_getPageDrawContext",
217
- value: function _getPageDrawContext() {
218
- var noCtxScale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
219
- var canvas = document.createElement('canvas');
220
- this.canvas = canvas;
221
- canvas.mozOpaque = true;
222
- var ctx = canvas.getContext('2d', {
223
- alpha: false
224
- });
225
- var outputScale = (0, _ui_utils.getOutputScale)(ctx);
226
- canvas.width = this.canvasWidth * outputScale.sx | 0;
227
- canvas.height = this.canvasHeight * outputScale.sy | 0;
228
- canvas.style.width = this.canvasWidth + 'px';
229
- canvas.style.height = this.canvasHeight + 'px';
230
-
231
- if (!noCtxScale && outputScale.scaled) {
232
- ctx.scale(outputScale.sx, outputScale.sy);
233
- }
234
182
 
235
- return ctx;
183
+ const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
184
+ this.viewport = this.viewport.clone({
185
+ scale: 1,
186
+ rotation: totalRotation
187
+ });
188
+ this.reset();
189
+ }
190
+
191
+ cancelRendering() {
192
+ if (this.renderTask) {
193
+ this.renderTask.cancel();
194
+ this.renderTask = null;
236
195
  }
237
- }, {
238
- key: "_convertCanvasToImage",
239
- value: function _convertCanvasToImage() {
240
- var _this = this;
241
196
 
242
- if (!this.canvas) {
243
- return;
244
- }
197
+ this.resume = null;
198
+ }
245
199
 
246
- if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
247
- return;
248
- }
200
+ _getPageDrawContext(noCtxScale = false) {
201
+ const canvas = document.createElement("canvas");
202
+ this.canvas = canvas;
203
+ canvas.mozOpaque = true;
204
+ const ctx = canvas.getContext("2d", {
205
+ alpha: false
206
+ });
207
+ const outputScale = (0, _ui_utils.getOutputScale)(ctx);
208
+ canvas.width = this.canvasWidth * outputScale.sx | 0;
209
+ canvas.height = this.canvasHeight * outputScale.sy | 0;
210
+ canvas.style.width = this.canvasWidth + "px";
211
+ canvas.style.height = this.canvasHeight + "px";
212
+
213
+ if (!noCtxScale && outputScale.scaled) {
214
+ ctx.scale(outputScale.sx, outputScale.sy);
215
+ }
249
216
 
250
- var id = this.renderingId;
251
- var className = 'thumbnailImage';
252
-
253
- if (this.disableCanvasToImageConversion) {
254
- this.canvas.id = id;
255
- this.canvas.className = className;
256
- this.l10n.get('thumb_page_canvas', {
257
- page: this.pageId
258
- }, 'Thumbnail of Page {{page}}').then(function (msg) {
259
- _this.canvas.setAttribute('aria-label', msg);
260
- });
261
- this.div.setAttribute('data-loaded', true);
262
- this.ring.appendChild(this.canvas);
263
- return;
264
- }
217
+ return ctx;
218
+ }
265
219
 
266
- var image = document.createElement('img');
267
- image.id = id;
268
- image.className = className;
269
- this.l10n.get('thumb_page_canvas', {
270
- page: this.pageId
271
- }, 'Thumbnail of Page {{page}}').then(function (msg) {
272
- image.setAttribute('aria-label', msg);
273
- });
274
- image.style.width = this.canvasWidth + 'px';
275
- image.style.height = this.canvasHeight + 'px';
276
- image.src = this.canvas.toDataURL();
277
- this.image = image;
278
- this.div.setAttribute('data-loaded', true);
279
- this.ring.appendChild(image);
280
- this.canvas.width = 0;
281
- this.canvas.height = 0;
282
- delete this.canvas;
220
+ _convertCanvasToImage() {
221
+ if (!this.canvas) {
222
+ return;
283
223
  }
284
- }, {
285
- key: "draw",
286
- value: function draw() {
287
- var _this2 = this;
288
-
289
- if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
290
- console.error('Must be in new state before drawing');
291
- return Promise.resolve(undefined);
292
- }
293
224
 
294
- this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
295
- var renderCapability = (0, _pdf.createPromiseCapability)();
225
+ if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
226
+ return;
227
+ }
296
228
 
297
- var finishRenderTask = function finishRenderTask(error) {
298
- if (renderTask === _this2.renderTask) {
299
- _this2.renderTask = null;
300
- }
229
+ const className = "thumbnailImage";
301
230
 
302
- if (error instanceof _pdf.RenderingCancelledException) {
303
- renderCapability.resolve(undefined);
304
- return;
305
- }
231
+ if (this.disableCanvasToImageConversion) {
232
+ this.canvas.className = className;
306
233
 
307
- _this2.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
234
+ this._thumbPageCanvas.then(msg => {
235
+ this.canvas.setAttribute("aria-label", msg);
236
+ });
308
237
 
309
- _this2._convertCanvasToImage();
238
+ this.div.setAttribute("data-loaded", true);
239
+ this.ring.appendChild(this.canvas);
240
+ return;
241
+ }
310
242
 
311
- if (!error) {
312
- renderCapability.resolve(undefined);
313
- } else {
314
- renderCapability.reject(error);
315
- }
316
- };
243
+ const image = document.createElement("img");
244
+ image.className = className;
317
245
 
318
- var ctx = this._getPageDrawContext();
246
+ this._thumbPageCanvas.then(msg => {
247
+ image.setAttribute("aria-label", msg);
248
+ });
319
249
 
320
- var drawViewport = this.viewport.clone({
321
- scale: this.scale
322
- });
250
+ image.style.width = this.canvasWidth + "px";
251
+ image.style.height = this.canvasHeight + "px";
252
+ image.src = this.canvas.toDataURL();
253
+ this.image = image;
254
+ this.div.setAttribute("data-loaded", true);
255
+ this.ring.appendChild(image);
256
+ this.canvas.width = 0;
257
+ this.canvas.height = 0;
258
+ delete this.canvas;
259
+ }
323
260
 
324
- var renderContinueCallback = function renderContinueCallback(cont) {
325
- if (!_this2.renderingQueue.isHighestPriority(_this2)) {
326
- _this2.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
327
-
328
- _this2.resume = function () {
329
- _this2.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
330
- cont();
331
- };
332
-
333
- return;
334
- }
335
-
336
- cont();
337
- };
338
-
339
- var renderContext = {
340
- canvasContext: ctx,
341
- viewport: drawViewport
342
- };
343
- var renderTask = this.renderTask = this.pdfPage.render(renderContext);
344
- renderTask.onContinue = renderContinueCallback;
345
- renderTask.promise.then(function () {
346
- finishRenderTask(null);
347
- }, function (error) {
348
- finishRenderTask(error);
349
- });
350
- return renderCapability.promise;
261
+ draw() {
262
+ if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
263
+ console.error("Must be in new state before drawing");
264
+ return Promise.resolve(undefined);
351
265
  }
352
- }, {
353
- key: "setImage",
354
- value: function setImage(pageView) {
355
- if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
356
- return;
357
- }
358
266
 
359
- var img = pageView.canvas;
267
+ const {
268
+ pdfPage
269
+ } = this;
360
270
 
361
- if (!img) {
362
- return;
271
+ if (!pdfPage) {
272
+ this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
273
+ return Promise.reject(new Error("pdfPage is not loaded"));
274
+ }
275
+
276
+ this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
277
+ const renderCapability = (0, _pdf.createPromiseCapability)();
278
+
279
+ const finishRenderTask = error => {
280
+ if (renderTask === this.renderTask) {
281
+ this.renderTask = null;
363
282
  }
364
283
 
365
- if (!this.pdfPage) {
366
- this.setPdfPage(pageView.pdfPage);
284
+ if (error instanceof _pdf.RenderingCancelledException) {
285
+ renderCapability.resolve(undefined);
286
+ return;
367
287
  }
368
288
 
369
289
  this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
370
290
 
371
- var ctx = this._getPageDrawContext(true);
291
+ this._convertCanvasToImage();
372
292
 
373
- var canvas = ctx.canvas;
293
+ if (!error) {
294
+ renderCapability.resolve(undefined);
295
+ } else {
296
+ renderCapability.reject(error);
297
+ }
298
+ };
374
299
 
375
- if (img.width <= 2 * canvas.width) {
376
- ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
300
+ const ctx = this._getPageDrawContext();
377
301
 
378
- this._convertCanvasToImage();
302
+ const drawViewport = this.viewport.clone({
303
+ scale: this.scale
304
+ });
305
+
306
+ const renderContinueCallback = cont => {
307
+ if (!this.renderingQueue.isHighestPriority(this)) {
308
+ this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
309
+
310
+ this.resume = () => {
311
+ this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
312
+ cont();
313
+ };
379
314
 
380
315
  return;
381
316
  }
382
317
 
383
- var reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
384
- var reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
385
- var reducedImage = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
386
- var reducedImageCtx = reducedImage.getContext('2d');
318
+ cont();
319
+ };
387
320
 
388
- while (reducedWidth > img.width || reducedHeight > img.height) {
389
- reducedWidth >>= 1;
390
- reducedHeight >>= 1;
391
- }
321
+ const renderContext = {
322
+ canvasContext: ctx,
323
+ viewport: drawViewport
324
+ };
325
+ const renderTask = this.renderTask = pdfPage.render(renderContext);
326
+ renderTask.onContinue = renderContinueCallback;
327
+ renderTask.promise.then(function () {
328
+ finishRenderTask(null);
329
+ }, function (error) {
330
+ finishRenderTask(error);
331
+ });
332
+ return renderCapability.promise;
333
+ }
392
334
 
393
- reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
335
+ setImage(pageView) {
336
+ if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
337
+ return;
338
+ }
394
339
 
395
- while (reducedWidth > 2 * canvas.width) {
396
- reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
397
- reducedWidth >>= 1;
398
- reducedHeight >>= 1;
399
- }
340
+ const img = pageView.canvas;
341
+
342
+ if (!img) {
343
+ return;
344
+ }
345
+
346
+ if (!this.pdfPage) {
347
+ this.setPdfPage(pageView.pdfPage);
348
+ }
349
+
350
+ this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
400
351
 
401
- ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
352
+ const ctx = this._getPageDrawContext(true);
353
+
354
+ const canvas = ctx.canvas;
355
+
356
+ if (img.width <= 2 * canvas.width) {
357
+ ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
402
358
 
403
359
  this._convertCanvasToImage();
360
+
361
+ return;
404
362
  }
405
- }, {
406
- key: "setPageLabel",
407
- value: function setPageLabel(label) {
408
- var _this3 = this;
409
-
410
- this.pageLabel = typeof label === 'string' ? label : null;
411
- this.l10n.get('thumb_page_title', {
412
- page: this.pageId
413
- }, 'Page {{page}}').then(function (msg) {
414
- _this3.anchor.title = msg;
415
- });
416
363
 
417
- if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
418
- return;
419
- }
364
+ let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
365
+ let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
366
+ const reducedImage = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
367
+ const reducedImageCtx = reducedImage.getContext("2d");
420
368
 
421
- this.l10n.get('thumb_page_canvas', {
422
- page: this.pageId
423
- }, 'Thumbnail of Page {{page}}').then(function (ariaLabel) {
424
- if (_this3.image) {
425
- _this3.image.setAttribute('aria-label', ariaLabel);
426
- } else if (_this3.disableCanvasToImageConversion && _this3.canvas) {
427
- _this3.canvas.setAttribute('aria-label', ariaLabel);
428
- }
429
- });
369
+ while (reducedWidth > img.width || reducedHeight > img.height) {
370
+ reducedWidth >>= 1;
371
+ reducedHeight >>= 1;
430
372
  }
431
- }, {
432
- key: "pageId",
433
- get: function get() {
434
- return this.pageLabel !== null ? this.pageLabel : this.id;
373
+
374
+ reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
375
+
376
+ while (reducedWidth > 2 * canvas.width) {
377
+ reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
378
+ reducedWidth >>= 1;
379
+ reducedHeight >>= 1;
435
380
  }
436
- }], [{
437
- key: "cleanup",
438
- value: function cleanup() {
439
- TempImageFactory.destroyCanvas();
381
+
382
+ ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
383
+
384
+ this._convertCanvasToImage();
385
+ }
386
+
387
+ get _thumbPageTitle() {
388
+ return this.l10n.get("thumb_page_title", {
389
+ page: this.pageLabel !== null ? this.pageLabel : this.id
390
+ }, "Page {{page}}");
391
+ }
392
+
393
+ get _thumbPageCanvas() {
394
+ return this.l10n.get("thumb_page_canvas", {
395
+ page: this.pageLabel !== null ? this.pageLabel : this.id
396
+ }, "Thumbnail of Page {{page}}");
397
+ }
398
+
399
+ setPageLabel(label) {
400
+ this.pageLabel = typeof label === "string" ? label : null;
401
+
402
+ this._thumbPageTitle.then(msg => {
403
+ this.anchor.title = msg;
404
+ });
405
+
406
+ if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
407
+ return;
440
408
  }
441
- }]);
442
409
 
443
- return PDFThumbnailView;
444
- }();
410
+ this._thumbPageCanvas.then(msg => {
411
+ if (this.image) {
412
+ this.image.setAttribute("aria-label", msg);
413
+ } else if (this.disableCanvasToImageConversion && this.canvas) {
414
+ this.canvas.setAttribute("aria-label", msg);
415
+ }
416
+ });
417
+ }
418
+
419
+ static cleanup() {
420
+ TempImageFactory.destroyCanvas();
421
+ }
422
+
423
+ }
445
424
 
446
425
  exports.PDFThumbnailView = PDFThumbnailView;