pdfjs-dist 2.0.487 → 2.1.266

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 (161) hide show
  1. package/bower.json +1 -1
  2. package/build/pdf.js +15564 -9476
  3. package/build/pdf.js.map +1 -1
  4. package/build/pdf.min.js +1 -1
  5. package/build/pdf.worker.js +46644 -36309
  6. package/build/pdf.worker.js.map +1 -1
  7. package/build/pdf.worker.min.js +1 -1
  8. package/external/url/url-lib.js +627 -0
  9. package/image_decoders/pdf.image_decoders.js +11430 -0
  10. package/image_decoders/pdf.image_decoders.js.map +1 -0
  11. package/image_decoders/pdf.image_decoders.min.js +1 -0
  12. package/lib/core/annotation.js +406 -131
  13. package/lib/core/arithmetic_decoder.js +275 -245
  14. package/lib/core/bidi.js +65 -6
  15. package/lib/core/ccitt.js +173 -18
  16. package/lib/core/ccitt_stream.js +15 -6
  17. package/lib/core/cff_parser.js +376 -53
  18. package/lib/core/charsets.js +5 -4
  19. package/lib/core/chunked_stream.js +387 -149
  20. package/lib/core/cmap.js +310 -75
  21. package/lib/core/colorspace.js +874 -594
  22. package/lib/core/crypto.js +290 -45
  23. package/lib/core/document.js +545 -260
  24. package/lib/core/encodings.js +19 -10
  25. package/lib/core/evaluator.js +725 -147
  26. package/lib/core/font_renderer.js +360 -91
  27. package/lib/core/fonts.js +791 -186
  28. package/lib/core/function.js +284 -71
  29. package/lib/core/glyphlist.js +3 -2
  30. package/lib/core/image.js +168 -61
  31. package/lib/core/jbig2.js +479 -66
  32. package/lib/core/jbig2_stream.js +19 -8
  33. package/lib/core/jpeg_stream.js +38 -13
  34. package/lib/core/jpg.js +252 -29
  35. package/lib/core/jpx.js +396 -6
  36. package/lib/core/jpx_stream.js +18 -6
  37. package/lib/core/metrics.js +4 -4
  38. package/lib/core/murmurhash3.js +24 -6
  39. package/lib/core/obj.js +1137 -475
  40. package/lib/core/operator_list.js +108 -6
  41. package/lib/core/parser.js +321 -68
  42. package/lib/core/pattern.js +145 -13
  43. package/lib/core/pdf_manager.js +321 -133
  44. package/lib/core/primitives.js +75 -22
  45. package/lib/core/ps_parser.js +134 -45
  46. package/lib/core/standard_fonts.js +10 -10
  47. package/lib/core/stream.js +313 -34
  48. package/lib/core/type1_parser.js +143 -13
  49. package/lib/core/unicode.js +31 -4
  50. package/lib/core/worker.js +210 -66
  51. package/lib/display/annotation_layer.js +361 -123
  52. package/lib/display/api.js +1454 -729
  53. package/lib/display/api_compatibility.js +11 -13
  54. package/lib/display/canvas.js +324 -29
  55. package/lib/display/content_disposition.js +83 -32
  56. package/lib/display/dom_utils.js +226 -41
  57. package/lib/display/fetch_stream.js +208 -84
  58. package/lib/display/font_loader.js +465 -236
  59. package/lib/display/metadata.js +38 -16
  60. package/lib/display/network.js +216 -51
  61. package/lib/display/network_utils.js +32 -19
  62. package/lib/display/node_stream.js +352 -169
  63. package/lib/display/pattern_helper.js +58 -7
  64. package/lib/display/svg.js +242 -29
  65. package/lib/display/text_layer.js +132 -18
  66. package/lib/display/transport_stream.js +171 -42
  67. package/lib/display/webgl.js +64 -18
  68. package/lib/display/worker_options.js +5 -4
  69. package/lib/display/xml_parser.js +166 -53
  70. package/lib/examples/node/domstubs.js +57 -4
  71. package/lib/pdf.js +21 -4
  72. package/lib/pdf.worker.js +5 -3
  73. package/lib/shared/compatibility.js +158 -564
  74. package/lib/shared/global_scope.js +2 -2
  75. package/lib/shared/is_node.js +4 -4
  76. package/lib/shared/message_handler.js +521 -0
  77. package/lib/shared/streams_polyfill.js +21 -17
  78. package/lib/shared/url_polyfill.js +56 -0
  79. package/lib/shared/util.js +295 -650
  80. package/lib/test/unit/annotation_spec.js +629 -345
  81. package/lib/test/unit/api_spec.js +555 -253
  82. package/lib/test/unit/bidi_spec.js +7 -7
  83. package/lib/test/unit/cff_parser_spec.js +40 -11
  84. package/lib/test/unit/clitests_helper.js +9 -7
  85. package/lib/test/unit/cmap_spec.js +80 -26
  86. package/lib/test/unit/colorspace_spec.js +99 -52
  87. package/lib/test/unit/crypto_spec.js +17 -5
  88. package/lib/test/unit/custom_spec.js +41 -53
  89. package/lib/test/unit/display_svg_spec.js +33 -17
  90. package/lib/test/unit/document_spec.js +3 -3
  91. package/lib/test/unit/dom_utils_spec.js +9 -9
  92. package/lib/test/unit/encodings_spec.js +25 -45
  93. package/lib/test/unit/evaluator_spec.js +34 -9
  94. package/lib/test/unit/function_spec.js +17 -5
  95. package/lib/test/unit/jasmine-boot.js +31 -18
  96. package/lib/test/unit/{util_stream_spec.js → message_handler_spec.js} +41 -69
  97. package/lib/test/unit/metadata_spec.js +71 -11
  98. package/lib/test/unit/murmurhash3_spec.js +3 -3
  99. package/lib/test/unit/network_spec.js +20 -5
  100. package/lib/test/unit/network_utils_spec.js +41 -14
  101. package/lib/test/unit/node_stream_spec.js +51 -27
  102. package/lib/test/unit/parser_spec.js +35 -8
  103. package/lib/test/unit/pdf_find_controller_spec.js +230 -0
  104. package/lib/test/unit/pdf_find_utils_spec.js +63 -0
  105. package/lib/test/unit/pdf_history_spec.js +21 -9
  106. package/lib/test/unit/primitives_spec.js +24 -4
  107. package/lib/test/unit/stream_spec.js +12 -4
  108. package/lib/test/unit/test_utils.js +90 -27
  109. package/lib/test/unit/testreporter.js +21 -3
  110. package/lib/test/unit/type1_parser_spec.js +8 -6
  111. package/lib/test/unit/ui_utils_spec.js +452 -14
  112. package/lib/test/unit/unicode_spec.js +14 -11
  113. package/lib/test/unit/util_spec.js +131 -9
  114. package/lib/web/annotation_layer_builder.js +39 -22
  115. package/lib/web/app.js +1240 -582
  116. package/lib/web/app_options.js +71 -41
  117. package/lib/web/base_viewer.js +508 -179
  118. package/lib/web/chromecom.js +261 -117
  119. package/lib/web/debugger.js +166 -22
  120. package/lib/web/download_manager.js +31 -13
  121. package/lib/web/firefox_print_service.js +17 -9
  122. package/lib/web/firefoxcom.js +283 -79
  123. package/lib/web/genericcom.js +89 -30
  124. package/lib/web/genericl10n.js +142 -30
  125. package/lib/web/grab_to_pan.js +26 -4
  126. package/lib/web/interfaces.js +170 -47
  127. package/lib/web/overlay_manager.js +235 -85
  128. package/lib/web/password_prompt.js +21 -13
  129. package/lib/web/pdf_attachment_viewer.js +38 -18
  130. package/lib/web/pdf_cursor_tools.js +39 -16
  131. package/lib/web/pdf_document_properties.js +80 -30
  132. package/lib/web/pdf_find_bar.js +84 -40
  133. package/lib/web/pdf_find_controller.js +495 -184
  134. package/lib/web/pdf_find_utils.js +111 -0
  135. package/lib/web/pdf_history.js +190 -53
  136. package/lib/web/pdf_link_service.js +137 -76
  137. package/lib/web/pdf_outline_viewer.js +73 -22
  138. package/lib/web/pdf_page_view.js +196 -63
  139. package/lib/web/pdf_presentation_mode.js +99 -34
  140. package/lib/web/pdf_print_service.js +57 -11
  141. package/lib/web/pdf_rendering_queue.js +27 -5
  142. package/lib/web/pdf_sidebar.js +120 -67
  143. package/lib/web/pdf_sidebar_resizer.js +42 -16
  144. package/lib/web/pdf_single_page_viewer.js +74 -66
  145. package/lib/web/pdf_thumbnail_view.js +103 -32
  146. package/lib/web/pdf_thumbnail_viewer.js +64 -24
  147. package/lib/web/pdf_viewer.component.js +112 -32
  148. package/lib/web/pdf_viewer.js +91 -52
  149. package/lib/web/preferences.js +275 -80
  150. package/lib/web/secondary_toolbar.js +165 -40
  151. package/lib/web/text_layer_builder.js +162 -65
  152. package/lib/web/toolbar.js +78 -43
  153. package/lib/web/ui_utils.js +462 -136
  154. package/lib/web/view_history.js +215 -67
  155. package/lib/web/viewer_compatibility.js +4 -13
  156. package/package.json +5 -4
  157. package/web/pdf_viewer.css +58 -1
  158. package/web/pdf_viewer.js +6346 -3919
  159. package/web/pdf_viewer.js.map +1 -1
  160. package/lib/test/unit/fonts_spec.js +0 -81
  161. package/lib/web/dom_events.js +0 -137
@@ -2,7 +2,7 @@
2
2
  * @licstart The following is the entire license notice for the
3
3
  * Javascript code in this page
4
4
  *
5
- * Copyright 2017 Mozilla Foundation
5
+ * Copyright 2018 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,30 +19,40 @@
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.PDFPageView = undefined;
27
+ exports.PDFPageView = 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 _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
30
30
 
31
- var _ui_utils = require('./ui_utils');
31
+ var _ui_utils = require("./ui_utils");
32
32
 
33
- var _pdf = require('../pdf');
33
+ var _pdf = require("../pdf");
34
34
 
35
- var _dom_events = require('./dom_events');
35
+ var _pdf_rendering_queue = require("./pdf_rendering_queue");
36
36
 
37
- var _pdf_rendering_queue = require('./pdf_rendering_queue');
37
+ var _viewer_compatibility = require("./viewer_compatibility");
38
38
 
39
- var _viewer_compatibility = require('./viewer_compatibility');
39
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
40
+
41
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
42
+
43
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
40
44
 
41
45
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
42
46
 
47
+ 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); } }
48
+
49
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
50
+
43
51
  var MAX_CANVAS_PIXELS = _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels || 16777216;
44
52
 
45
- var PDFPageView = function () {
53
+ var PDFPageView =
54
+ /*#__PURE__*/
55
+ function () {
46
56
  function PDFPageView(options) {
47
57
  _classCallCheck(this, PDFPageView);
48
58
 
@@ -62,7 +72,7 @@ var PDFPageView = function () {
62
72
  this.renderInteractiveForms = options.renderInteractiveForms || false;
63
73
  this.useOnlyCssZoom = options.useOnlyCssZoom || false;
64
74
  this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
65
- this.eventBus = options.eventBus || (0, _dom_events.getGlobalEventBus)();
75
+ this.eventBus = options.eventBus || (0, _ui_utils.getGlobalEventBus)();
66
76
  this.renderingQueue = options.renderingQueue;
67
77
  this.textLayerFactory = options.textLayerFactory;
68
78
  this.annotationLayerFactory = options.annotationLayerFactory;
@@ -89,46 +99,52 @@ var PDFPageView = function () {
89
99
  }
90
100
 
91
101
  _createClass(PDFPageView, [{
92
- key: 'setPdfPage',
102
+ key: "setPdfPage",
93
103
  value: function setPdfPage(pdfPage) {
94
104
  this.pdfPage = pdfPage;
95
105
  this.pdfPageRotate = pdfPage.rotate;
96
106
  var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
97
- this.viewport = pdfPage.getViewport(this.scale * _ui_utils.CSS_UNITS, totalRotation);
107
+ this.viewport = pdfPage.getViewport({
108
+ scale: this.scale * _ui_utils.CSS_UNITS,
109
+ rotation: totalRotation
110
+ });
98
111
  this.stats = pdfPage.stats;
99
112
  this.reset();
100
113
  }
101
114
  }, {
102
- key: 'destroy',
115
+ key: "destroy",
103
116
  value: function destroy() {
104
117
  this.reset();
118
+
105
119
  if (this.pdfPage) {
106
120
  this.pdfPage.cleanup();
107
121
  }
108
122
  }
109
123
  }, {
110
- key: '_resetZoomLayer',
124
+ key: "_resetZoomLayer",
111
125
  value: function _resetZoomLayer() {
112
126
  var removeFromDOM = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
113
127
 
114
128
  if (!this.zoomLayer) {
115
129
  return;
116
130
  }
131
+
117
132
  var zoomLayerCanvas = this.zoomLayer.firstChild;
118
133
  this.paintedViewportMap.delete(zoomLayerCanvas);
119
134
  zoomLayerCanvas.width = 0;
120
135
  zoomLayerCanvas.height = 0;
136
+
121
137
  if (removeFromDOM) {
122
138
  this.zoomLayer.remove();
123
139
  }
140
+
124
141
  this.zoomLayer = null;
125
142
  }
126
143
  }, {
127
- key: 'reset',
144
+ key: "reset",
128
145
  value: function reset() {
129
146
  var keepZoomLayer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
130
147
  var keepAnnotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
131
-
132
148
  this.cancelRendering(keepAnnotations);
133
149
  var div = this.div;
134
150
  div.style.width = Math.floor(this.viewport.width) + 'px';
@@ -136,20 +152,26 @@ var PDFPageView = function () {
136
152
  var childNodes = div.childNodes;
137
153
  var currentZoomLayerNode = keepZoomLayer && this.zoomLayer || null;
138
154
  var currentAnnotationNode = keepAnnotations && this.annotationLayer && this.annotationLayer.div || null;
155
+
139
156
  for (var i = childNodes.length - 1; i >= 0; i--) {
140
157
  var node = childNodes[i];
158
+
141
159
  if (currentZoomLayerNode === node || currentAnnotationNode === node) {
142
160
  continue;
143
161
  }
162
+
144
163
  div.removeChild(node);
145
164
  }
165
+
146
166
  div.removeAttribute('data-loaded');
167
+
147
168
  if (currentAnnotationNode) {
148
169
  this.annotationLayer.hide();
149
170
  } else if (this.annotationLayer) {
150
171
  this.annotationLayer.cancel();
151
172
  this.annotationLayer = null;
152
173
  }
174
+
153
175
  if (!currentZoomLayerNode) {
154
176
  if (this.canvas) {
155
177
  this.paintedViewportMap.delete(this.canvas);
@@ -157,28 +179,34 @@ var PDFPageView = function () {
157
179
  this.canvas.height = 0;
158
180
  delete this.canvas;
159
181
  }
182
+
160
183
  this._resetZoomLayer();
161
184
  }
185
+
162
186
  if (this.svg) {
163
187
  this.paintedViewportMap.delete(this.svg);
164
188
  delete this.svg;
165
189
  }
190
+
166
191
  this.loadingIconDiv = document.createElement('div');
167
192
  this.loadingIconDiv.className = 'loadingIcon';
168
193
  div.appendChild(this.loadingIconDiv);
169
194
  }
170
195
  }, {
171
- key: 'update',
196
+ key: "update",
172
197
  value: function update(scale, rotation) {
173
198
  this.scale = scale || this.scale;
199
+
174
200
  if (typeof rotation !== 'undefined') {
175
201
  this.rotation = rotation;
176
202
  }
203
+
177
204
  var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
178
205
  this.viewport = this.viewport.clone({
179
206
  scale: this.scale * _ui_utils.CSS_UNITS,
180
207
  rotation: totalRotation
181
208
  });
209
+
182
210
  if (this.svg) {
183
211
  this.cssTransform(this.svg, true);
184
212
  this.eventBus.dispatch('pagerendered', {
@@ -188,13 +216,17 @@ var PDFPageView = function () {
188
216
  });
189
217
  return;
190
218
  }
219
+
191
220
  var isScalingRestricted = false;
221
+
192
222
  if (this.canvas && this.maxCanvasPixels > 0) {
193
223
  var outputScale = this.outputScale;
224
+
194
225
  if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
195
226
  isScalingRestricted = true;
196
227
  }
197
228
  }
229
+
198
230
  if (this.canvas) {
199
231
  if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
200
232
  this.cssTransform(this.canvas, true);
@@ -205,41 +237,55 @@ var PDFPageView = function () {
205
237
  });
206
238
  return;
207
239
  }
240
+
208
241
  if (!this.zoomLayer && !this.canvas.hasAttribute('hidden')) {
209
242
  this.zoomLayer = this.canvas.parentNode;
210
243
  this.zoomLayer.style.position = 'absolute';
211
244
  }
212
245
  }
246
+
213
247
  if (this.zoomLayer) {
214
248
  this.cssTransform(this.zoomLayer.firstChild);
215
249
  }
250
+
216
251
  this.reset(true, true);
217
252
  }
218
253
  }, {
219
- key: 'cancelRendering',
254
+ key: "cancelRendering",
220
255
  value: function cancelRendering() {
221
256
  var keepAnnotations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
257
+ var renderingState = this.renderingState;
222
258
 
223
259
  if (this.paintTask) {
224
260
  this.paintTask.cancel();
225
261
  this.paintTask = null;
226
262
  }
263
+
227
264
  this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
228
265
  this.resume = null;
266
+
229
267
  if (this.textLayer) {
230
268
  this.textLayer.cancel();
231
269
  this.textLayer = null;
232
270
  }
271
+
233
272
  if (!keepAnnotations && this.annotationLayer) {
234
273
  this.annotationLayer.cancel();
235
274
  this.annotationLayer = null;
236
275
  }
276
+
277
+ if (renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
278
+ this.eventBus.dispatch('pagecancelled', {
279
+ source: this,
280
+ pageNumber: this.id,
281
+ renderingState: renderingState
282
+ });
283
+ }
237
284
  }
238
285
  }, {
239
- key: 'cssTransform',
286
+ key: "cssTransform",
240
287
  value: function cssTransform(target) {
241
288
  var redrawAnnotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
242
-
243
289
  var width = this.viewport.width;
244
290
  var height = this.viewport.height;
245
291
  var div = this.div;
@@ -249,57 +295,68 @@ var PDFPageView = function () {
249
295
  var absRotation = Math.abs(relativeRotation);
250
296
  var scaleX = 1,
251
297
  scaleY = 1;
298
+
252
299
  if (absRotation === 90 || absRotation === 270) {
253
300
  scaleX = height / width;
254
301
  scaleY = width / height;
255
302
  }
303
+
256
304
  var cssTransform = 'rotate(' + relativeRotation + 'deg) ' + 'scale(' + scaleX + ',' + scaleY + ')';
257
305
  target.style.transform = cssTransform;
306
+
258
307
  if (this.textLayer) {
259
308
  var textLayerViewport = this.textLayer.viewport;
260
309
  var textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
261
310
  var textAbsRotation = Math.abs(textRelativeRotation);
262
311
  var scale = width / textLayerViewport.width;
312
+
263
313
  if (textAbsRotation === 90 || textAbsRotation === 270) {
264
314
  scale = width / textLayerViewport.height;
265
315
  }
316
+
266
317
  var textLayerDiv = this.textLayer.textLayerDiv;
267
- var transX = void 0,
268
- transY = void 0;
318
+ var transX, transY;
319
+
269
320
  switch (textAbsRotation) {
270
321
  case 0:
271
322
  transX = transY = 0;
272
323
  break;
324
+
273
325
  case 90:
274
326
  transX = 0;
275
327
  transY = '-' + textLayerDiv.style.height;
276
328
  break;
329
+
277
330
  case 180:
278
331
  transX = '-' + textLayerDiv.style.width;
279
332
  transY = '-' + textLayerDiv.style.height;
280
333
  break;
334
+
281
335
  case 270:
282
336
  transX = '-' + textLayerDiv.style.width;
283
337
  transY = 0;
284
338
  break;
339
+
285
340
  default:
286
341
  console.error('Bad rotation value.');
287
342
  break;
288
343
  }
344
+
289
345
  textLayerDiv.style.transform = 'rotate(' + textAbsRotation + 'deg) ' + 'scale(' + scale + ', ' + scale + ') ' + 'translate(' + transX + ', ' + transY + ')';
290
346
  textLayerDiv.style.transformOrigin = '0% 0%';
291
347
  }
348
+
292
349
  if (redrawAnnotations && this.annotationLayer) {
293
350
  this.annotationLayer.render(this.viewport, 'display');
294
351
  }
295
352
  }
296
353
  }, {
297
- key: 'getPagePoint',
354
+ key: "getPagePoint",
298
355
  value: function getPagePoint(x, y) {
299
356
  return this.viewport.convertToPdfPoint(x, y);
300
357
  }
301
358
  }, {
302
- key: 'draw',
359
+ key: "draw",
303
360
  value: function draw() {
304
361
  var _this = this;
305
362
 
@@ -307,10 +364,12 @@ var PDFPageView = function () {
307
364
  console.error('Must be in new state before drawing');
308
365
  this.reset();
309
366
  }
367
+
310
368
  if (!this.pdfPage) {
311
369
  this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
312
370
  return Promise.reject(new Error('Page is not loaded'));
313
371
  }
372
+
314
373
  this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
315
374
  var pdfPage = this.pdfPage;
316
375
  var div = this.div;
@@ -318,75 +377,124 @@ var PDFPageView = function () {
318
377
  canvasWrapper.style.width = div.style.width;
319
378
  canvasWrapper.style.height = div.style.height;
320
379
  canvasWrapper.classList.add('canvasWrapper');
380
+
321
381
  if (this.annotationLayer && this.annotationLayer.div) {
322
382
  div.insertBefore(canvasWrapper, this.annotationLayer.div);
323
383
  } else {
324
384
  div.appendChild(canvasWrapper);
325
385
  }
386
+
326
387
  var textLayer = null;
388
+
327
389
  if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
328
390
  var textLayerDiv = document.createElement('div');
329
391
  textLayerDiv.className = 'textLayer';
330
392
  textLayerDiv.style.width = canvasWrapper.style.width;
331
393
  textLayerDiv.style.height = canvasWrapper.style.height;
394
+
332
395
  if (this.annotationLayer && this.annotationLayer.div) {
333
396
  div.insertBefore(textLayerDiv, this.annotationLayer.div);
334
397
  } else {
335
398
  div.appendChild(textLayerDiv);
336
399
  }
400
+
337
401
  textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE);
338
402
  }
403
+
339
404
  this.textLayer = textLayer;
340
405
  var renderContinueCallback = null;
406
+
341
407
  if (this.renderingQueue) {
342
408
  renderContinueCallback = function renderContinueCallback(cont) {
343
409
  if (!_this.renderingQueue.isHighestPriority(_this)) {
344
410
  _this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
411
+
345
412
  _this.resume = function () {
346
413
  _this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
347
414
  cont();
348
415
  };
416
+
349
417
  return;
350
418
  }
419
+
351
420
  cont();
352
421
  };
353
422
  }
354
- var finishPaintTask = function finishPaintTask(error) {
355
- if (paintTask === _this.paintTask) {
356
- _this.paintTask = null;
357
- }
358
- if (error instanceof _pdf.RenderingCancelledException) {
359
- _this.error = null;
360
- return Promise.resolve(undefined);
361
- }
362
- _this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
363
- if (_this.loadingIconDiv) {
364
- div.removeChild(_this.loadingIconDiv);
365
- delete _this.loadingIconDiv;
366
- }
367
- _this._resetZoomLayer(true);
368
- _this.error = error;
369
- _this.stats = pdfPage.stats;
370
- if (_this.onAfterDraw) {
371
- _this.onAfterDraw();
372
- }
373
- _this.eventBus.dispatch('pagerendered', {
374
- source: _this,
375
- pageNumber: _this.id,
376
- cssTransform: false
377
- });
378
- if (error) {
379
- return Promise.reject(error);
380
- }
381
- return Promise.resolve(undefined);
382
- };
423
+
424
+ var finishPaintTask =
425
+ /*#__PURE__*/
426
+ function () {
427
+ var _ref = _asyncToGenerator(
428
+ /*#__PURE__*/
429
+ _regenerator.default.mark(function _callee(error) {
430
+ return _regenerator.default.wrap(function _callee$(_context) {
431
+ while (1) {
432
+ switch (_context.prev = _context.next) {
433
+ case 0:
434
+ if (paintTask === _this.paintTask) {
435
+ _this.paintTask = null;
436
+ }
437
+
438
+ if (!(error instanceof _pdf.RenderingCancelledException)) {
439
+ _context.next = 4;
440
+ break;
441
+ }
442
+
443
+ _this.error = null;
444
+ return _context.abrupt("return");
445
+
446
+ case 4:
447
+ _this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
448
+
449
+ if (_this.loadingIconDiv) {
450
+ div.removeChild(_this.loadingIconDiv);
451
+ delete _this.loadingIconDiv;
452
+ }
453
+
454
+ _this._resetZoomLayer(true);
455
+
456
+ _this.error = error;
457
+ _this.stats = pdfPage.stats;
458
+
459
+ if (_this.onAfterDraw) {
460
+ _this.onAfterDraw();
461
+ }
462
+
463
+ _this.eventBus.dispatch('pagerendered', {
464
+ source: _this,
465
+ pageNumber: _this.id,
466
+ cssTransform: false
467
+ });
468
+
469
+ if (!error) {
470
+ _context.next = 13;
471
+ break;
472
+ }
473
+
474
+ throw error;
475
+
476
+ case 13:
477
+ case "end":
478
+ return _context.stop();
479
+ }
480
+ }
481
+ }, _callee, this);
482
+ }));
483
+
484
+ return function finishPaintTask(_x) {
485
+ return _ref.apply(this, arguments);
486
+ };
487
+ }();
488
+
383
489
  var paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
384
490
  paintTask.onRenderContinue = renderContinueCallback;
385
491
  this.paintTask = paintTask;
386
492
  var resultPromise = paintTask.promise.then(function () {
387
493
  return finishPaintTask(null).then(function () {
388
494
  if (textLayer) {
389
- var readableStream = pdfPage.streamTextContent({ normalizeWhitespace: true });
495
+ var readableStream = pdfPage.streamTextContent({
496
+ normalizeWhitespace: true
497
+ });
390
498
  textLayer.setTextContentStream(readableStream);
391
499
  textLayer.render();
392
500
  }
@@ -394,20 +502,25 @@ var PDFPageView = function () {
394
502
  }, function (reason) {
395
503
  return finishPaintTask(reason);
396
504
  });
505
+
397
506
  if (this.annotationLayerFactory) {
398
507
  if (!this.annotationLayer) {
399
508
  this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, this.imageResourcesPath, this.renderInteractiveForms, this.l10n);
400
509
  }
510
+
401
511
  this.annotationLayer.render(this.viewport, 'display');
402
512
  }
513
+
403
514
  div.setAttribute('data-loaded', true);
515
+
404
516
  if (this.onBeforeDraw) {
405
517
  this.onBeforeDraw();
406
518
  }
519
+
407
520
  return resultPromise;
408
521
  }
409
522
  }, {
410
- key: 'paintOnCanvas',
523
+ key: "paintOnCanvas",
411
524
  value: function paintOnCanvas(canvasWrapper) {
412
525
  var renderCapability = (0, _pdf.createPromiseCapability)();
413
526
  var result = {
@@ -424,27 +537,36 @@ var PDFPageView = function () {
424
537
  canvas.id = this.renderingId;
425
538
  canvas.setAttribute('hidden', 'hidden');
426
539
  var isCanvasHidden = true;
540
+
427
541
  var showCanvas = function showCanvas() {
428
542
  if (isCanvasHidden) {
429
543
  canvas.removeAttribute('hidden');
430
544
  isCanvasHidden = false;
431
545
  }
432
546
  };
547
+
433
548
  canvasWrapper.appendChild(canvas);
434
549
  this.canvas = canvas;
435
550
  canvas.mozOpaque = true;
436
- var ctx = canvas.getContext('2d', { alpha: false });
551
+ var ctx = canvas.getContext('2d', {
552
+ alpha: false
553
+ });
437
554
  var outputScale = (0, _ui_utils.getOutputScale)(ctx);
438
555
  this.outputScale = outputScale;
556
+
439
557
  if (this.useOnlyCssZoom) {
440
- var actualSizeViewport = viewport.clone({ scale: _ui_utils.CSS_UNITS });
558
+ var actualSizeViewport = viewport.clone({
559
+ scale: _ui_utils.CSS_UNITS
560
+ });
441
561
  outputScale.sx *= actualSizeViewport.width / viewport.width;
442
562
  outputScale.sy *= actualSizeViewport.height / viewport.height;
443
563
  outputScale.scaled = true;
444
564
  }
565
+
445
566
  if (this.maxCanvasPixels > 0) {
446
567
  var pixelsInViewport = viewport.width * viewport.height;
447
568
  var maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
569
+
448
570
  if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
449
571
  outputScale.sx = maxScale;
450
572
  outputScale.sy = maxScale;
@@ -454,6 +576,7 @@ var PDFPageView = function () {
454
576
  this.hasRestrictedScaling = false;
455
577
  }
456
578
  }
579
+
457
580
  var sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
458
581
  var sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
459
582
  canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
@@ -470,14 +593,17 @@ var PDFPageView = function () {
470
593
  renderInteractiveForms: this.renderInteractiveForms
471
594
  };
472
595
  var renderTask = this.pdfPage.render(renderContext);
596
+
473
597
  renderTask.onContinue = function (cont) {
474
598
  showCanvas();
599
+
475
600
  if (result.onRenderContinue) {
476
601
  result.onRenderContinue(cont);
477
602
  } else {
478
603
  cont();
479
604
  }
480
605
  };
606
+
481
607
  renderTask.promise.then(function () {
482
608
  showCanvas();
483
609
  renderCapability.resolve(undefined);
@@ -488,25 +614,31 @@ var PDFPageView = function () {
488
614
  return result;
489
615
  }
490
616
  }, {
491
- key: 'paintOnSvg',
617
+ key: "paintOnSvg",
492
618
  value: function paintOnSvg(wrapper) {
493
619
  var _this2 = this;
494
620
 
495
621
  var cancelled = false;
622
+
496
623
  var ensureNotCancelled = function ensureNotCancelled() {
497
624
  if (cancelled) {
498
625
  throw new _pdf.RenderingCancelledException('Rendering cancelled, page ' + _this2.id, 'svg');
499
626
  }
500
627
  };
628
+
501
629
  var pdfPage = this.pdfPage;
502
- var actualSizeViewport = this.viewport.clone({ scale: _ui_utils.CSS_UNITS });
630
+ var actualSizeViewport = this.viewport.clone({
631
+ scale: _ui_utils.CSS_UNITS
632
+ });
503
633
  var promise = pdfPage.getOperatorList().then(function (opList) {
504
634
  ensureNotCancelled();
505
635
  var svgGfx = new _pdf.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
506
636
  return svgGfx.getSVG(opList, actualSizeViewport).then(function (svg) {
507
637
  ensureNotCancelled();
508
638
  _this2.svg = svg;
639
+
509
640
  _this2.paintedViewportMap.set(svg, actualSizeViewport);
641
+
510
642
  svg.style.width = wrapper.style.width;
511
643
  svg.style.height = wrapper.style.height;
512
644
  _this2.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
@@ -524,9 +656,10 @@ var PDFPageView = function () {
524
656
  };
525
657
  }
526
658
  }, {
527
- key: 'setPageLabel',
659
+ key: "setPageLabel",
528
660
  value: function setPageLabel(label) {
529
661
  this.pageLabel = typeof label === 'string' ? label : null;
662
+
530
663
  if (this.pageLabel !== null) {
531
664
  this.div.setAttribute('data-page-label', this.pageLabel);
532
665
  } else {
@@ -534,12 +667,12 @@ var PDFPageView = function () {
534
667
  }
535
668
  }
536
669
  }, {
537
- key: 'width',
670
+ key: "width",
538
671
  get: function get() {
539
672
  return this.viewport.width;
540
673
  }
541
674
  }, {
542
- key: 'height',
675
+ key: "height",
543
676
  get: function get() {
544
677
  return this.viewport.height;
545
678
  }