pdfjs-dist 2.0.943 → 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 (192) 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 +8286 -14230
  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 +25500 -26628
  9. package/build/pdf.worker.js.map +1 -1
  10. package/build/pdf.worker.min.js +22 -1
  11. package/es5/build/pdf.js +25473 -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 +57878 -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 +407 -0
  29. package/es5/web/pdf_viewer.js +7757 -0
  30. package/es5/web/pdf_viewer.js.map +1 -0
  31. package/image_decoders/pdf.image_decoders.js +2887 -4094
  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 +855 -778
  36. package/lib/core/arithmetic_decoder.js +325 -311
  37. package/lib/core/bidi.js +117 -50
  38. package/lib/core/ccitt.js +251 -89
  39. package/lib/core/ccitt_stream.js +26 -16
  40. package/lib/core/cff_parser.js +525 -197
  41. package/lib/core/charsets.js +6 -5
  42. package/lib/core/chunked_stream.js +541 -406
  43. package/lib/core/cmap.js +368 -253
  44. package/lib/core/colorspace.js +781 -800
  45. package/lib/core/core_utils.js +152 -0
  46. package/lib/core/crypto.js +609 -422
  47. package/lib/core/document.js +649 -481
  48. package/lib/core/encodings.js +33 -24
  49. package/lib/core/evaluator.js +1471 -736
  50. package/lib/core/font_renderer.js +289 -149
  51. package/lib/core/fonts.js +1067 -413
  52. package/lib/core/function.js +517 -287
  53. package/lib/core/glyphlist.js +4529 -4527
  54. package/lib/core/image.js +232 -114
  55. package/lib/core/image_utils.js +94 -0
  56. package/lib/core/jbig2.js +711 -342
  57. package/lib/core/jbig2_stream.js +31 -19
  58. package/lib/core/jpeg_stream.js +151 -26
  59. package/lib/core/jpg.js +433 -181
  60. package/lib/core/jpx.js +551 -143
  61. package/lib/core/jpx_stream.js +40 -28
  62. package/lib/core/metrics.js +2931 -2931
  63. package/lib/core/murmurhash3.js +104 -97
  64. package/lib/core/obj.js +1561 -1053
  65. package/lib/core/operator_list.js +192 -64
  66. package/lib/core/parser.js +1162 -864
  67. package/lib/core/pattern.js +224 -75
  68. package/lib/core/pdf_manager.js +154 -285
  69. package/lib/core/primitives.js +145 -69
  70. package/lib/core/ps_parser.js +212 -162
  71. package/lib/core/standard_fonts.js +245 -244
  72. package/lib/core/stream.js +353 -81
  73. package/lib/core/type1_parser.js +218 -68
  74. package/lib/core/unicode.js +1682 -1655
  75. package/lib/core/worker.js +233 -302
  76. package/lib/core/worker_stream.js +168 -0
  77. package/lib/display/annotation_layer.js +808 -862
  78. package/lib/display/api.js +1778 -1462
  79. package/lib/display/api_compatibility.js +14 -9
  80. package/lib/display/canvas.js +463 -140
  81. package/lib/display/content_disposition.js +86 -58
  82. package/lib/display/display_utils.js +524 -0
  83. package/lib/display/fetch_stream.js +202 -274
  84. package/lib/display/font_loader.js +311 -333
  85. package/lib/display/metadata.js +98 -88
  86. package/lib/display/network.js +343 -347
  87. package/lib/display/network_utils.js +46 -26
  88. package/lib/display/node_stream.js +326 -404
  89. package/lib/display/pattern_helper.js +168 -69
  90. package/lib/display/svg.js +1296 -885
  91. package/lib/display/text_layer.js +229 -103
  92. package/lib/display/transport_stream.js +290 -250
  93. package/lib/display/webgl.js +116 -83
  94. package/lib/display/worker_options.js +6 -5
  95. package/lib/display/xml_parser.js +358 -337
  96. package/lib/examples/node/domstubs.js +95 -39
  97. package/lib/pdf.js +49 -31
  98. package/lib/pdf.worker.js +7 -5
  99. package/lib/shared/compatibility.js +3 -145
  100. package/lib/shared/is_node.js +8 -7
  101. package/lib/shared/message_handler.js +367 -314
  102. package/lib/shared/util.js +421 -415
  103. package/lib/test/unit/annotation_spec.js +1570 -690
  104. package/lib/test/unit/api_spec.js +855 -493
  105. package/lib/test/unit/bidi_spec.js +12 -12
  106. package/lib/test/unit/cff_parser_spec.js +88 -61
  107. package/lib/test/unit/clitests_helper.js +9 -12
  108. package/lib/test/unit/cmap_spec.js +140 -88
  109. package/lib/test/unit/colorspace_spec.js +204 -152
  110. package/lib/test/unit/core_utils_spec.js +211 -0
  111. package/lib/test/unit/crypto_spec.js +194 -182
  112. package/lib/test/unit/custom_spec.js +50 -64
  113. package/lib/test/unit/display_svg_spec.js +53 -38
  114. package/lib/test/unit/display_utils_spec.js +263 -0
  115. package/lib/test/unit/document_spec.js +17 -22
  116. package/lib/test/unit/encodings_spec.js +15 -57
  117. package/lib/test/unit/evaluator_spec.js +90 -83
  118. package/lib/test/unit/fetch_stream_spec.js +111 -0
  119. package/lib/test/unit/function_spec.js +219 -205
  120. package/lib/test/unit/jasmine-boot.js +68 -39
  121. package/lib/test/unit/message_handler_spec.js +187 -160
  122. package/lib/test/unit/metadata_spec.js +87 -34
  123. package/lib/test/unit/murmurhash3_spec.js +13 -13
  124. package/lib/test/unit/network_spec.js +26 -59
  125. package/lib/test/unit/network_utils_spec.js +187 -121
  126. package/lib/test/unit/node_stream_spec.js +98 -90
  127. package/lib/test/unit/parser_spec.js +173 -131
  128. package/lib/test/unit/pdf_find_controller_spec.js +148 -67
  129. package/lib/test/unit/pdf_find_utils_spec.js +35 -34
  130. package/lib/test/unit/pdf_history_spec.js +45 -33
  131. package/lib/test/unit/primitives_spec.js +161 -126
  132. package/lib/test/unit/stream_spec.js +22 -15
  133. package/lib/test/unit/test_utils.js +149 -98
  134. package/lib/test/unit/testreporter.js +36 -18
  135. package/lib/test/unit/type1_parser_spec.js +46 -44
  136. package/lib/test/unit/ui_utils_spec.js +388 -372
  137. package/lib/test/unit/unicode_spec.js +49 -46
  138. package/lib/test/unit/util_spec.js +144 -248
  139. package/lib/web/annotation_layer_builder.js +75 -95
  140. package/lib/web/app.js +1538 -1147
  141. package/lib/web/app_options.js +116 -104
  142. package/lib/web/base_viewer.js +950 -775
  143. package/lib/web/chromecom.js +217 -225
  144. package/lib/web/debugger.js +236 -148
  145. package/lib/web/download_manager.js +50 -50
  146. package/lib/web/firefox_print_service.js +51 -33
  147. package/lib/web/firefoxcom.js +225 -352
  148. package/lib/web/genericcom.js +30 -93
  149. package/lib/web/genericl10n.js +26 -143
  150. package/lib/web/grab_to_pan.js +57 -33
  151. package/lib/web/interfaces.js +105 -232
  152. package/lib/web/overlay_manager.js +73 -227
  153. package/lib/web/password_prompt.js +44 -62
  154. package/lib/web/pdf_attachment_viewer.js +118 -123
  155. package/lib/web/pdf_cursor_tools.js +89 -93
  156. package/lib/web/pdf_document_properties.js +242 -281
  157. package/lib/web/pdf_find_bar.js +157 -163
  158. package/lib/web/pdf_find_controller.js +598 -454
  159. package/lib/web/pdf_find_utils.js +32 -16
  160. package/lib/web/pdf_history.js +481 -355
  161. package/lib/web/pdf_link_service.js +355 -323
  162. package/lib/web/pdf_outline_viewer.js +167 -152
  163. package/lib/web/pdf_page_view.js +511 -457
  164. package/lib/web/pdf_presentation_mode.js +347 -335
  165. package/lib/web/pdf_print_service.js +133 -103
  166. package/lib/web/pdf_rendering_queue.js +98 -100
  167. package/lib/web/pdf_sidebar.js +323 -299
  168. package/lib/web/pdf_sidebar_resizer.js +107 -108
  169. package/lib/web/pdf_single_page_viewer.js +94 -146
  170. package/lib/web/pdf_thumbnail_view.js +319 -269
  171. package/lib/web/pdf_thumbnail_viewer.js +219 -199
  172. package/lib/web/pdf_viewer.component.js +111 -32
  173. package/lib/web/pdf_viewer.js +61 -101
  174. package/lib/web/preferences.js +87 -272
  175. package/lib/web/secondary_toolbar.js +207 -220
  176. package/lib/web/text_layer_builder.js +322 -322
  177. package/lib/web/toolbar.js +227 -180
  178. package/lib/web/ui_utils.js +476 -421
  179. package/lib/web/view_history.js +59 -208
  180. package/lib/web/viewer_compatibility.js +9 -6
  181. package/package.json +2 -9
  182. package/web/pdf_viewer.css +36 -22
  183. package/web/pdf_viewer.js +4407 -4516
  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 -441
  189. package/lib/shared/streams_polyfill.js +0 -39
  190. package/lib/shared/url_polyfill.js +0 -50
  191. package/lib/test/unit/dom_utils_spec.js +0 -89
  192. package/lib/web/dom_events.js +0 -140
@@ -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.
@@ -19,72 +19,73 @@
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.js");
32
32
 
33
- var _ui_utils = require('./ui_utils');
33
+ var _pdf_rendering_queue = require("./pdf_rendering_queue.js");
34
34
 
35
- var _pdf_rendering_queue = require('./pdf_rendering_queue');
35
+ const MAX_NUM_SCALING_STEPS = 3;
36
+ const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
37
+ const THUMBNAIL_WIDTH = 98;
36
38
 
37
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
38
-
39
- var MAX_NUM_SCALING_STEPS = 3;
40
- var THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
41
- var THUMBNAIL_WIDTH = 98;
42
- var TempImageFactory = function TempImageFactoryClosure() {
43
- var tempCanvasCache = null;
39
+ const TempImageFactory = function TempImageFactoryClosure() {
40
+ let tempCanvasCache = null;
44
41
  return {
45
- getCanvas: function getCanvas(width, height) {
46
- var tempCanvas = tempCanvasCache;
42
+ getCanvas(width, height) {
43
+ let tempCanvas = tempCanvasCache;
44
+
47
45
  if (!tempCanvas) {
48
- tempCanvas = document.createElement('canvas');
46
+ tempCanvas = document.createElement("canvas");
49
47
  tempCanvasCache = tempCanvas;
50
48
  }
49
+
51
50
  tempCanvas.width = width;
52
51
  tempCanvas.height = height;
53
52
  tempCanvas.mozOpaque = true;
54
- var ctx = tempCanvas.getContext('2d', { alpha: false });
53
+ const ctx = tempCanvas.getContext("2d", {
54
+ alpha: false
55
+ });
55
56
  ctx.save();
56
- ctx.fillStyle = 'rgb(255, 255, 255)';
57
+ ctx.fillStyle = "rgb(255, 255, 255)";
57
58
  ctx.fillRect(0, 0, width, height);
58
59
  ctx.restore();
59
60
  return tempCanvas;
60
61
  },
61
- destroyCanvas: function destroyCanvas() {
62
- var tempCanvas = tempCanvasCache;
62
+
63
+ destroyCanvas() {
64
+ const tempCanvas = tempCanvasCache;
65
+
63
66
  if (tempCanvas) {
64
67
  tempCanvas.width = 0;
65
68
  tempCanvas.height = 0;
66
69
  }
70
+
67
71
  tempCanvasCache = null;
68
72
  }
73
+
69
74
  };
70
75
  }();
71
76
 
72
- var PDFThumbnailView = function () {
73
- function PDFThumbnailView(_ref) {
74
- var container = _ref.container,
75
- id = _ref.id,
76
- defaultViewport = _ref.defaultViewport,
77
- linkService = _ref.linkService,
78
- renderingQueue = _ref.renderingQueue,
79
- _ref$disableCanvasToI = _ref.disableCanvasToImageConversion,
80
- disableCanvasToImageConversion = _ref$disableCanvasToI === undefined ? false : _ref$disableCanvasToI,
81
- _ref$l10n = _ref.l10n,
82
- l10n = _ref$l10n === undefined ? _ui_utils.NullL10n : _ref$l10n;
83
-
84
- _classCallCheck(this, PDFThumbnailView);
85
-
77
+ class PDFThumbnailView {
78
+ constructor({
79
+ container,
80
+ id,
81
+ defaultViewport,
82
+ linkService,
83
+ renderingQueue,
84
+ disableCanvasToImageConversion = false,
85
+ l10n = _ui_utils.NullL10n
86
+ }) {
86
87
  this.id = id;
87
- this.renderingId = 'thumbnail' + id;
88
+ this.renderingId = "thumbnail" + id;
88
89
  this.pageLabel = null;
89
90
  this.pdfPage = null;
90
91
  this.rotation = 0;
@@ -103,273 +104,322 @@ var PDFThumbnailView = function () {
103
104
  this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
104
105
  this.scale = this.canvasWidth / this.pageWidth;
105
106
  this.l10n = l10n;
106
- var anchor = document.createElement('a');
107
- anchor.href = linkService.getAnchorUrl('#page=' + id);
108
- this.l10n.get('thumb_page_title', { page: id }, 'Page {{page}}').then(function (msg) {
107
+ const anchor = document.createElement("a");
108
+ anchor.href = linkService.getAnchorUrl("#page=" + id);
109
+
110
+ this._thumbPageTitle.then(msg => {
109
111
  anchor.title = msg;
110
112
  });
113
+
111
114
  anchor.onclick = function () {
112
115
  linkService.page = id;
113
116
  return false;
114
117
  };
118
+
115
119
  this.anchor = anchor;
116
- var div = document.createElement('div');
117
- div.className = 'thumbnail';
118
- 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);
119
123
  this.div = div;
120
- var ring = document.createElement('div');
121
- ring.className = 'thumbnailSelectionRing';
122
- var borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
123
- ring.style.width = this.canvasWidth + borderAdjustment + 'px';
124
- 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";
125
129
  this.ring = ring;
126
130
  div.appendChild(ring);
127
131
  anchor.appendChild(div);
128
132
  container.appendChild(anchor);
129
133
  }
130
134
 
131
- _createClass(PDFThumbnailView, [{
132
- key: 'setPdfPage',
133
- value: function setPdfPage(pdfPage) {
134
- this.pdfPage = pdfPage;
135
- this.pdfPageRotate = pdfPage.rotate;
136
- var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
137
- this.viewport = pdfPage.getViewport(1, totalRotation);
138
- this.reset();
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
+ }
145
+
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;
157
+
158
+ for (let i = childNodes.length - 1; i >= 0; i--) {
159
+ ring.removeChild(childNodes[i]);
139
160
  }
140
- }, {
141
- key: 'reset',
142
- value: function reset() {
143
- this.cancelRendering();
144
- this.pageWidth = this.viewport.width;
145
- this.pageHeight = this.viewport.height;
146
- this.pageRatio = this.pageWidth / this.pageHeight;
147
- this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
148
- this.scale = this.canvasWidth / this.pageWidth;
149
- this.div.removeAttribute('data-loaded');
150
- var ring = this.ring;
151
- var childNodes = ring.childNodes;
152
- for (var i = childNodes.length - 1; i >= 0; i--) {
153
- ring.removeChild(childNodes[i]);
154
- }
155
- var borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
156
- ring.style.width = this.canvasWidth + borderAdjustment + 'px';
157
- ring.style.height = this.canvasHeight + borderAdjustment + 'px';
158
- if (this.canvas) {
159
- this.canvas.width = 0;
160
- this.canvas.height = 0;
161
- delete this.canvas;
162
- }
163
- if (this.image) {
164
- this.image.removeAttribute('src');
165
- delete this.image;
166
- }
161
+
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;
167
170
  }
168
- }, {
169
- key: 'update',
170
- value: function update(rotation) {
171
- if (typeof rotation !== 'undefined') {
172
- this.rotation = rotation;
173
- }
174
- var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
175
- this.viewport = this.viewport.clone({
176
- scale: 1,
177
- rotation: totalRotation
178
- });
179
- this.reset();
171
+
172
+ if (this.image) {
173
+ this.image.removeAttribute("src");
174
+ delete this.image;
180
175
  }
181
- }, {
182
- key: 'cancelRendering',
183
- value: function cancelRendering() {
184
- if (this.renderTask) {
185
- this.renderTask.cancel();
186
- this.renderTask = null;
187
- }
188
- this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
189
- this.resume = null;
176
+ }
177
+
178
+ update(rotation) {
179
+ if (typeof rotation !== "undefined") {
180
+ this.rotation = rotation;
190
181
  }
191
- }, {
192
- key: '_getPageDrawContext',
193
- value: function _getPageDrawContext() {
194
- var noCtxScale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
195
-
196
- var canvas = document.createElement('canvas');
197
- this.canvas = canvas;
198
- canvas.mozOpaque = true;
199
- var ctx = canvas.getContext('2d', { alpha: false });
200
- var outputScale = (0, _ui_utils.getOutputScale)(ctx);
201
- canvas.width = this.canvasWidth * outputScale.sx | 0;
202
- canvas.height = this.canvasHeight * outputScale.sy | 0;
203
- canvas.style.width = this.canvasWidth + 'px';
204
- canvas.style.height = this.canvasHeight + 'px';
205
- if (!noCtxScale && outputScale.scaled) {
206
- ctx.scale(outputScale.sx, outputScale.sy);
207
- }
208
- return ctx;
182
+
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;
209
195
  }
210
- }, {
211
- key: '_convertCanvasToImage',
212
- value: function _convertCanvasToImage() {
213
- var _this = this;
214
196
 
215
- if (!this.canvas) {
216
- return;
217
- }
218
- if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
219
- return;
220
- }
221
- var id = this.renderingId;
222
- var className = 'thumbnailImage';
223
- if (this.disableCanvasToImageConversion) {
224
- this.canvas.id = id;
225
- this.canvas.className = className;
226
- this.l10n.get('thumb_page_canvas', { page: this.pageId }, 'Thumbnail of Page {{page}}').then(function (msg) {
227
- _this.canvas.setAttribute('aria-label', msg);
228
- });
229
- this.div.setAttribute('data-loaded', true);
230
- this.ring.appendChild(this.canvas);
231
- return;
232
- }
233
- var image = document.createElement('img');
234
- image.id = id;
235
- image.className = className;
236
- this.l10n.get('thumb_page_canvas', { page: this.pageId }, 'Thumbnail of Page {{page}}').then(function (msg) {
237
- image.setAttribute('aria-label', msg);
238
- });
239
- image.style.width = this.canvasWidth + 'px';
240
- image.style.height = this.canvasHeight + 'px';
241
- image.src = this.canvas.toDataURL();
242
- this.image = image;
243
- this.div.setAttribute('data-loaded', true);
244
- this.ring.appendChild(image);
245
- this.canvas.width = 0;
246
- this.canvas.height = 0;
247
- delete this.canvas;
197
+ this.resume = null;
198
+ }
199
+
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);
248
215
  }
249
- }, {
250
- key: 'draw',
251
- value: function draw() {
252
- var _this2 = this;
253
-
254
- if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
255
- console.error('Must be in new state before drawing');
256
- return Promise.resolve(undefined);
257
- }
258
- this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
259
- var renderCapability = (0, _pdf.createPromiseCapability)();
260
- var finishRenderTask = function finishRenderTask(error) {
261
- if (renderTask === _this2.renderTask) {
262
- _this2.renderTask = null;
263
- }
264
- if (error instanceof _pdf.RenderingCancelledException) {
265
- renderCapability.resolve(undefined);
266
- return;
267
- }
268
- _this2.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
269
- _this2._convertCanvasToImage();
270
- if (!error) {
271
- renderCapability.resolve(undefined);
272
- } else {
273
- renderCapability.reject(error);
274
- }
275
- };
276
- var ctx = this._getPageDrawContext();
277
- var drawViewport = this.viewport.clone({ scale: this.scale });
278
- var renderContinueCallback = function renderContinueCallback(cont) {
279
- if (!_this2.renderingQueue.isHighestPriority(_this2)) {
280
- _this2.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
281
- _this2.resume = function () {
282
- _this2.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
283
- cont();
284
- };
285
- return;
286
- }
287
- cont();
288
- };
289
- var renderContext = {
290
- canvasContext: ctx,
291
- viewport: drawViewport
292
- };
293
- var renderTask = this.renderTask = this.pdfPage.render(renderContext);
294
- renderTask.onContinue = renderContinueCallback;
295
- renderTask.promise.then(function () {
296
- finishRenderTask(null);
297
- }, function (error) {
298
- finishRenderTask(error);
216
+
217
+ return ctx;
218
+ }
219
+
220
+ _convertCanvasToImage() {
221
+ if (!this.canvas) {
222
+ return;
223
+ }
224
+
225
+ if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
226
+ return;
227
+ }
228
+
229
+ const className = "thumbnailImage";
230
+
231
+ if (this.disableCanvasToImageConversion) {
232
+ this.canvas.className = className;
233
+
234
+ this._thumbPageCanvas.then(msg => {
235
+ this.canvas.setAttribute("aria-label", msg);
299
236
  });
300
- return renderCapability.promise;
237
+
238
+ this.div.setAttribute("data-loaded", true);
239
+ this.ring.appendChild(this.canvas);
240
+ return;
301
241
  }
302
- }, {
303
- key: 'setImage',
304
- value: function setImage(pageView) {
305
- if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
306
- return;
242
+
243
+ const image = document.createElement("img");
244
+ image.className = className;
245
+
246
+ this._thumbPageCanvas.then(msg => {
247
+ image.setAttribute("aria-label", msg);
248
+ });
249
+
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
+ }
260
+
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);
265
+ }
266
+
267
+ const {
268
+ pdfPage
269
+ } = this;
270
+
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;
307
282
  }
308
- var img = pageView.canvas;
309
- if (!img) {
283
+
284
+ if (error instanceof _pdf.RenderingCancelledException) {
285
+ renderCapability.resolve(undefined);
310
286
  return;
311
287
  }
312
- if (!this.pdfPage) {
313
- this.setPdfPage(pageView.pdfPage);
314
- }
288
+
315
289
  this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
316
- var ctx = this._getPageDrawContext(true);
317
- var canvas = ctx.canvas;
318
- if (img.width <= 2 * canvas.width) {
319
- ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
320
- this._convertCanvasToImage();
321
- return;
322
- }
323
- var reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
324
- var reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
325
- var reducedImage = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
326
- var reducedImageCtx = reducedImage.getContext('2d');
327
- while (reducedWidth > img.width || reducedHeight > img.height) {
328
- reducedWidth >>= 1;
329
- reducedHeight >>= 1;
290
+
291
+ this._convertCanvasToImage();
292
+
293
+ if (!error) {
294
+ renderCapability.resolve(undefined);
295
+ } else {
296
+ renderCapability.reject(error);
330
297
  }
331
- reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
332
- while (reducedWidth > 2 * canvas.width) {
333
- reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
334
- reducedWidth >>= 1;
335
- reducedHeight >>= 1;
298
+ };
299
+
300
+ const ctx = this._getPageDrawContext();
301
+
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
+ };
314
+
315
+ return;
336
316
  }
337
- ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
317
+
318
+ cont();
319
+ };
320
+
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
+ }
334
+
335
+ setImage(pageView) {
336
+ if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
337
+ return;
338
+ }
339
+
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;
351
+
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);
358
+
338
359
  this._convertCanvasToImage();
360
+
361
+ return;
339
362
  }
340
- }, {
341
- key: 'setPageLabel',
342
- value: function setPageLabel(label) {
343
- var _this3 = this;
344
-
345
- this.pageLabel = typeof label === 'string' ? label : null;
346
- this.l10n.get('thumb_page_title', { page: this.pageId }, 'Page {{page}}').then(function (msg) {
347
- _this3.anchor.title = msg;
348
- });
349
- if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
350
- return;
351
- }
352
- this.l10n.get('thumb_page_canvas', { page: this.pageId }, 'Thumbnail of Page {{page}}').then(function (ariaLabel) {
353
- if (_this3.image) {
354
- _this3.image.setAttribute('aria-label', ariaLabel);
355
- } else if (_this3.disableCanvasToImageConversion && _this3.canvas) {
356
- _this3.canvas.setAttribute('aria-label', ariaLabel);
357
- }
358
- });
363
+
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");
368
+
369
+ while (reducedWidth > img.width || reducedHeight > img.height) {
370
+ reducedWidth >>= 1;
371
+ reducedHeight >>= 1;
359
372
  }
360
- }, {
361
- key: 'pageId',
362
- get: function get() {
363
- 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;
364
380
  }
365
- }], [{
366
- key: 'cleanup',
367
- value: function cleanup() {
368
- 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;
369
408
  }
370
- }]);
371
409
 
372
- return PDFThumbnailView;
373
- }();
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
+ }
374
424
 
375
425
  exports.PDFThumbnailView = PDFThumbnailView;