pdfjs-dist 2.1.266 → 2.5.207

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 (191) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/README.md +4 -0
  3. package/bower.json +1 -1
  4. package/build/pdf.js +8382 -18492
  5. package/build/pdf.js.map +1 -1
  6. package/build/pdf.min.js +22 -1
  7. package/build/pdf.worker.entry.js +5 -3
  8. package/build/pdf.worker.js +20417 -29816
  9. package/build/pdf.worker.js.map +1 -1
  10. package/build/pdf.worker.min.js +22 -1
  11. package/es5/build/pdf.js +25688 -0
  12. package/es5/build/pdf.js.map +1 -0
  13. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  14. package/es5/build/pdf.worker.js +58239 -0
  15. package/es5/build/pdf.worker.js.map +1 -0
  16. package/es5/web/images/annotation-check.svg +11 -0
  17. package/es5/web/images/annotation-comment.svg +16 -0
  18. package/es5/web/images/annotation-help.svg +26 -0
  19. package/es5/web/images/annotation-insert.svg +10 -0
  20. package/es5/web/images/annotation-key.svg +11 -0
  21. package/es5/web/images/annotation-newparagraph.svg +11 -0
  22. package/es5/web/images/annotation-noicon.svg +7 -0
  23. package/es5/web/images/annotation-note.svg +42 -0
  24. package/es5/web/images/annotation-paragraph.svg +16 -0
  25. package/es5/web/images/loading-icon.gif +0 -0
  26. package/es5/web/images/shadow.png +0 -0
  27. package/es5/web/images/texture.png +0 -0
  28. package/es5/web/pdf_viewer.css +403 -0
  29. package/es5/web/pdf_viewer.js +7742 -0
  30. package/es5/web/pdf_viewer.js.map +1 -0
  31. package/image_decoders/pdf.image_decoders.js +1475 -4897
  32. package/image_decoders/pdf.image_decoders.js.map +1 -1
  33. package/image_decoders/pdf.image_decoders.min.js +22 -1
  34. package/lib/README.md +7 -0
  35. package/lib/core/annotation.js +750 -899
  36. package/lib/core/arithmetic_decoder.js +81 -97
  37. package/lib/core/bidi.js +54 -46
  38. package/lib/core/ccitt.js +88 -81
  39. package/lib/core/ccitt_stream.js +15 -14
  40. package/lib/core/cff_parser.js +235 -183
  41. package/lib/core/charsets.js +4 -4
  42. package/lib/core/chunked_stream.js +447 -542
  43. package/lib/core/cmap.js +222 -264
  44. package/lib/core/colorspace.js +699 -863
  45. package/lib/core/core_utils.js +152 -0
  46. package/lib/core/crypto.js +379 -437
  47. package/lib/core/document.js +573 -660
  48. package/lib/core/encodings.js +15 -15
  49. package/lib/core/evaluator.js +1103 -868
  50. package/lib/core/font_renderer.js +135 -178
  51. package/lib/core/fonts.js +570 -491
  52. package/lib/core/function.js +291 -288
  53. package/lib/core/glyphlist.js +4527 -4526
  54. package/lib/core/image.js +145 -149
  55. package/lib/core/image_utils.js +170 -0
  56. package/lib/core/jbig2.js +325 -316
  57. package/lib/core/jbig2_stream.js +18 -17
  58. package/lib/core/jpeg_stream.js +21 -26
  59. package/lib/core/jpg.js +284 -232
  60. package/lib/core/jpx.js +161 -143
  61. package/lib/core/jpx_stream.js +28 -28
  62. package/lib/core/metrics.js +2929 -2929
  63. package/lib/core/murmurhash3.js +90 -101
  64. package/lib/core/obj.js +1183 -1157
  65. package/lib/core/operator_list.js +99 -67
  66. package/lib/core/parser.js +972 -911
  67. package/lib/core/pattern.js +87 -70
  68. package/lib/core/pdf_manager.js +150 -315
  69. package/lib/core/primitives.js +83 -56
  70. package/lib/core/ps_parser.js +175 -214
  71. package/lib/core/standard_fonts.js +237 -236
  72. package/lib/core/stream.js +94 -74
  73. package/lib/core/type1_parser.js +87 -69
  74. package/lib/core/unicode.js +1654 -1654
  75. package/lib/core/worker.js +193 -390
  76. package/lib/core/worker_stream.js +168 -0
  77. package/lib/display/annotation_layer.js +741 -972
  78. package/lib/display/api.js +1500 -1791
  79. package/lib/display/api_compatibility.js +12 -17
  80. package/lib/display/canvas.js +165 -165
  81. package/lib/display/content_disposition.js +40 -59
  82. package/lib/display/display_utils.js +515 -0
  83. package/lib/display/fetch_stream.js +183 -298
  84. package/lib/display/font_loader.js +273 -413
  85. package/lib/display/metadata.js +86 -98
  86. package/lib/display/network.js +266 -359
  87. package/lib/display/network_utils.js +25 -18
  88. package/lib/display/node_stream.js +285 -458
  89. package/lib/display/pattern_helper.js +113 -65
  90. package/lib/display/svg.js +1166 -901
  91. package/lib/display/text_layer.js +156 -132
  92. package/lib/display/transport_stream.js +262 -278
  93. package/lib/display/webgl.js +70 -83
  94. package/lib/display/worker_options.js +3 -3
  95. package/lib/display/xml_parser.js +303 -392
  96. package/lib/examples/node/domstubs.js +40 -37
  97. package/lib/pdf.js +226 -59
  98. package/lib/pdf.worker.js +14 -6
  99. package/lib/shared/compatibility.js +3 -246
  100. package/lib/shared/is_node.js +7 -6
  101. package/lib/shared/message_handler.js +327 -332
  102. package/lib/shared/util.js +266 -416
  103. package/lib/test/unit/annotation_spec.js +1555 -701
  104. package/lib/test/unit/api_spec.js +802 -604
  105. package/lib/test/unit/bidi_spec.js +7 -7
  106. package/lib/test/unit/cff_parser_spec.js +84 -69
  107. package/lib/test/unit/clitests_helper.js +7 -9
  108. package/lib/test/unit/cmap_spec.js +74 -76
  109. package/lib/test/unit/colorspace_spec.js +166 -161
  110. package/lib/test/unit/core_utils_spec.js +211 -0
  111. package/lib/test/unit/crypto_spec.js +181 -181
  112. package/lib/test/unit/custom_spec.js +20 -22
  113. package/lib/test/unit/display_svg_spec.js +34 -39
  114. package/lib/test/unit/display_utils_spec.js +263 -0
  115. package/lib/test/unit/document_spec.js +16 -21
  116. package/lib/test/unit/encodings_spec.js +12 -34
  117. package/lib/test/unit/evaluator_spec.js +83 -83
  118. package/lib/test/unit/fetch_stream_spec.js +111 -0
  119. package/lib/test/unit/function_spec.js +206 -204
  120. package/lib/test/unit/jasmine-boot.js +46 -30
  121. package/lib/test/unit/message_handler_spec.js +173 -159
  122. package/lib/test/unit/metadata_spec.js +69 -69
  123. package/lib/test/unit/murmurhash3_spec.js +12 -12
  124. package/lib/test/unit/network_spec.js +13 -61
  125. package/lib/test/unit/network_utils_spec.js +183 -119
  126. package/lib/test/unit/node_stream_spec.js +78 -92
  127. package/lib/test/unit/parser_spec.js +172 -114
  128. package/lib/test/unit/pdf_find_controller_spec.js +55 -86
  129. package/lib/test/unit/pdf_find_utils_spec.js +32 -32
  130. package/lib/test/unit/pdf_history_spec.js +32 -32
  131. package/lib/test/unit/primitives_spec.js +140 -125
  132. package/lib/test/unit/stream_spec.js +16 -14
  133. package/lib/test/unit/test_utils.js +131 -143
  134. package/lib/test/unit/testreporter.js +19 -19
  135. package/lib/test/unit/type1_parser_spec.js +42 -42
  136. package/lib/test/unit/ui_utils_spec.js +297 -459
  137. package/lib/test/unit/unicode_spec.js +38 -38
  138. package/lib/test/unit/util_spec.js +121 -305
  139. package/lib/web/annotation_layer_builder.js +66 -103
  140. package/lib/web/app.js +1328 -1214
  141. package/lib/web/app_options.js +105 -107
  142. package/lib/web/base_viewer.js +824 -838
  143. package/lib/web/chromecom.js +165 -252
  144. package/lib/web/debugger.js +149 -205
  145. package/lib/web/download_manager.js +39 -55
  146. package/lib/web/firefox_print_service.js +37 -27
  147. package/lib/web/firefoxcom.js +212 -363
  148. package/lib/web/genericcom.js +26 -108
  149. package/lib/web/genericl10n.js +24 -153
  150. package/lib/web/grab_to_pan.js +32 -30
  151. package/lib/web/interfaces.js +80 -254
  152. package/lib/web/overlay_manager.js +70 -246
  153. package/lib/web/password_prompt.js +38 -64
  154. package/lib/web/pdf_attachment_viewer.js +113 -131
  155. package/lib/web/pdf_cursor_tools.js +75 -102
  156. package/lib/web/pdf_document_properties.js +221 -306
  157. package/lib/web/pdf_find_bar.js +136 -170
  158. package/lib/web/pdf_find_controller.js +491 -548
  159. package/lib/web/pdf_find_utils.js +13 -13
  160. package/lib/web/pdf_history.js +397 -406
  161. package/lib/web/pdf_link_service.js +304 -348
  162. package/lib/web/pdf_outline_viewer.js +140 -175
  163. package/lib/web/pdf_page_view.js +452 -523
  164. package/lib/web/pdf_presentation_mode.js +308 -357
  165. package/lib/web/pdf_print_service.js +90 -104
  166. package/lib/web/pdf_rendering_queue.js +84 -108
  167. package/lib/web/pdf_sidebar.js +276 -306
  168. package/lib/web/pdf_sidebar_resizer.js +92 -119
  169. package/lib/web/pdf_single_page_viewer.js +77 -126
  170. package/lib/web/pdf_thumbnail_view.js +276 -297
  171. package/lib/web/pdf_thumbnail_viewer.js +186 -206
  172. package/lib/web/pdf_viewer.component.js +20 -21
  173. package/lib/web/pdf_viewer.js +55 -115
  174. package/lib/web/preferences.js +82 -286
  175. package/lib/web/secondary_toolbar.js +164 -196
  176. package/lib/web/text_layer_builder.js +282 -339
  177. package/lib/web/toolbar.js +217 -210
  178. package/lib/web/ui_utils.js +267 -420
  179. package/lib/web/view_history.js +52 -226
  180. package/lib/web/viewer_compatibility.js +21 -6
  181. package/package.json +2 -9
  182. package/web/pdf_viewer.css +35 -25
  183. package/web/pdf_viewer.js +3489 -4855
  184. package/web/pdf_viewer.js.map +1 -1
  185. package/webpack.js +14 -5
  186. package/external/streams/streams-lib.js +0 -3962
  187. package/external/url/url-lib.js +0 -627
  188. package/lib/display/dom_utils.js +0 -494
  189. package/lib/shared/streams_polyfill.js +0 -43
  190. package/lib/shared/url_polyfill.js +0 -56
  191. package/lib/test/unit/dom_utils_spec.js +0 -89
@@ -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 2018 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.pageWidth = this.viewport.width;
163
- this.pageHeight = this.viewport.height;
164
- this.pageRatio = this.pageWidth / this.pageHeight;
165
- this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
166
- this.scale = this.canvasWidth / this.pageWidth;
167
- this.div.removeAttribute('data-loaded');
168
- var ring = this.ring;
169
- var childNodes = ring.childNodes;
170
-
171
- for (var i = childNodes.length - 1; i >= 0; i--) {
172
- ring.removeChild(childNodes[i]);
173
- }
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
+ }
174
145
 
175
- var borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
176
- ring.style.width = this.canvasWidth + borderAdjustment + 'px';
177
- 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;
178
157
 
179
- if (this.canvas) {
180
- this.canvas.width = 0;
181
- this.canvas.height = 0;
182
- delete this.canvas;
183
- }
158
+ for (let i = childNodes.length - 1; i >= 0; i--) {
159
+ ring.removeChild(childNodes[i]);
160
+ }
184
161
 
185
- if (this.image) {
186
- this.image.removeAttribute('src');
187
- delete this.image;
188
- }
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;
189
170
  }
190
- }, {
191
- key: "update",
192
- value: function update(rotation) {
193
- if (typeof rotation !== 'undefined') {
194
- this.rotation = rotation;
195
- }
196
171
 
197
- var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
198
- this.viewport = this.viewport.clone({
199
- scale: 1,
200
- rotation: totalRotation
201
- });
202
- this.reset();
172
+ if (this.image) {
173
+ this.image.removeAttribute("src");
174
+ delete this.image;
203
175
  }
204
- }, {
205
- key: "cancelRendering",
206
- value: function cancelRendering() {
207
- if (this.renderTask) {
208
- this.renderTask.cancel();
209
- this.renderTask = null;
210
- }
176
+ }
211
177
 
212
- this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
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;