pdfjs-dist 2.3.200 → 2.4.456

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pdfjs-dist might be problematic. Click here for more details.

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