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,37 +19,29 @@
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 _ui_utils = require("./ui_utils.js");
30
30
 
31
- var _ui_utils = require('./ui_utils');
31
+ var _pdf = require("../pdf");
32
32
 
33
- var _pdf = require('../pdf');
33
+ var _pdf_rendering_queue = require("./pdf_rendering_queue.js");
34
34
 
35
- var _dom_events = require('./dom_events');
35
+ var _viewer_compatibility = require("./viewer_compatibility.js");
36
36
 
37
- var _pdf_rendering_queue = require('./pdf_rendering_queue');
37
+ const MAX_CANVAS_PIXELS = _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels || 16777216;
38
38
 
39
- var _viewer_compatibility = require('./viewer_compatibility');
40
-
41
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
42
-
43
- var MAX_CANVAS_PIXELS = _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels || 16777216;
44
-
45
- var PDFPageView = function () {
46
- function PDFPageView(options) {
47
- _classCallCheck(this, PDFPageView);
48
-
49
- var container = options.container;
50
- var defaultViewport = options.defaultViewport;
39
+ class PDFPageView {
40
+ constructor(options) {
41
+ const container = options.container;
42
+ const defaultViewport = options.defaultViewport;
51
43
  this.id = options.id;
52
- this.renderingId = 'page' + this.id;
44
+ this.renderingId = "page" + this.id;
53
45
  this.pdfPage = null;
54
46
  this.pageLabel = null;
55
47
  this.rotation = 0;
@@ -58,11 +50,11 @@ var PDFPageView = function () {
58
50
  this.pdfPageRotate = defaultViewport.rotation;
59
51
  this.hasRestrictedScaling = false;
60
52
  this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
61
- this.imageResourcesPath = options.imageResourcesPath || '';
53
+ this.imageResourcesPath = options.imageResourcesPath || "";
62
54
  this.renderInteractiveForms = options.renderInteractiveForms || false;
63
55
  this.useOnlyCssZoom = options.useOnlyCssZoom || false;
64
56
  this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
65
- this.eventBus = options.eventBus || (0, _dom_events.getGlobalEventBus)();
57
+ this.eventBus = options.eventBus || (0, _ui_utils.getGlobalEventBus)();
66
58
  this.renderingQueue = options.renderingQueue;
67
59
  this.textLayerFactory = options.textLayerFactory;
68
60
  this.annotationLayerFactory = options.annotationLayerFactory;
@@ -74,486 +66,548 @@ var PDFPageView = function () {
74
66
  this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
75
67
  this.resume = null;
76
68
  this.error = null;
77
- this.onBeforeDraw = null;
78
- this.onAfterDraw = null;
79
69
  this.annotationLayer = null;
80
70
  this.textLayer = null;
81
71
  this.zoomLayer = null;
82
- var div = document.createElement('div');
83
- div.className = 'page';
84
- div.style.width = Math.floor(this.viewport.width) + 'px';
85
- div.style.height = Math.floor(this.viewport.height) + 'px';
86
- 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);
87
77
  this.div = div;
88
78
  container.appendChild(div);
89
79
  }
90
80
 
91
- _createClass(PDFPageView, [{
92
- key: 'setPdfPage',
93
- value: function setPdfPage(pdfPage) {
94
- this.pdfPage = pdfPage;
95
- this.pdfPageRotate = pdfPage.rotate;
96
- var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
97
- this.viewport = pdfPage.getViewport(this.scale * _ui_utils.CSS_UNITS, totalRotation);
98
- this.stats = pdfPage.stats;
99
- 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();
100
98
  }
101
- }, {
102
- key: 'destroy',
103
- value: function destroy() {
104
- this.reset();
105
- if (this.pdfPage) {
106
- this.pdfPage.cleanup();
107
- }
99
+ }
100
+
101
+ _resetZoomLayer(removeFromDOM = false) {
102
+ if (!this.zoomLayer) {
103
+ return;
108
104
  }
109
- }, {
110
- key: '_resetZoomLayer',
111
- value: function _resetZoomLayer() {
112
- var removeFromDOM = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
113
105
 
114
- if (!this.zoomLayer) {
115
- return;
116
- }
117
- var zoomLayerCanvas = this.zoomLayer.firstChild;
118
- this.paintedViewportMap.delete(zoomLayerCanvas);
119
- zoomLayerCanvas.width = 0;
120
- zoomLayerCanvas.height = 0;
121
- if (removeFromDOM) {
122
- this.zoomLayer.remove();
123
- }
124
- this.zoomLayer = null;
106
+ const zoomLayerCanvas = this.zoomLayer.firstChild;
107
+ this.paintedViewportMap.delete(zoomLayerCanvas);
108
+ zoomLayerCanvas.width = 0;
109
+ zoomLayerCanvas.height = 0;
110
+
111
+ if (removeFromDOM) {
112
+ this.zoomLayer.remove();
125
113
  }
126
- }, {
127
- key: 'reset',
128
- value: function reset() {
129
- var keepZoomLayer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
130
- var keepAnnotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
131
-
132
- this.cancelRendering(keepAnnotations);
133
- var div = this.div;
134
- div.style.width = Math.floor(this.viewport.width) + 'px';
135
- div.style.height = Math.floor(this.viewport.height) + 'px';
136
- var childNodes = div.childNodes;
137
- var currentZoomLayerNode = keepZoomLayer && this.zoomLayer || null;
138
- var currentAnnotationNode = keepAnnotations && this.annotationLayer && this.annotationLayer.div || null;
139
- for (var i = childNodes.length - 1; i >= 0; i--) {
140
- var node = childNodes[i];
141
- if (currentZoomLayerNode === node || currentAnnotationNode === node) {
142
- continue;
143
- }
144
- div.removeChild(node);
145
- }
146
- div.removeAttribute('data-loaded');
147
- if (currentAnnotationNode) {
148
- this.annotationLayer.hide();
149
- } else if (this.annotationLayer) {
150
- this.annotationLayer.cancel();
151
- this.annotationLayer = null;
152
- }
153
- if (!currentZoomLayerNode) {
154
- if (this.canvas) {
155
- this.paintedViewportMap.delete(this.canvas);
156
- this.canvas.width = 0;
157
- this.canvas.height = 0;
158
- delete this.canvas;
159
- }
160
- this._resetZoomLayer();
161
- }
162
- if (this.svg) {
163
- this.paintedViewportMap.delete(this.svg);
164
- delete this.svg;
114
+
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;
165
133
  }
166
- this.loadingIconDiv = document.createElement('div');
167
- this.loadingIconDiv.className = 'loadingIcon';
168
- div.appendChild(this.loadingIconDiv);
134
+
135
+ div.removeChild(node);
169
136
  }
170
- }, {
171
- key: 'update',
172
- value: function update(scale, rotation) {
173
- this.scale = scale || this.scale;
174
- if (typeof rotation !== 'undefined') {
175
- this.rotation = rotation;
137
+
138
+ div.removeAttribute("data-loaded");
139
+
140
+ if (currentAnnotationNode) {
141
+ this.annotationLayer.hide();
142
+ } else if (this.annotationLayer) {
143
+ this.annotationLayer.cancel();
144
+ this.annotationLayer = null;
145
+ }
146
+
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;
176
153
  }
177
- var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
178
- this.viewport = this.viewport.clone({
179
- scale: this.scale * _ui_utils.CSS_UNITS,
180
- rotation: totalRotation
154
+
155
+ this._resetZoomLayer();
156
+ }
157
+
158
+ if (this.svg) {
159
+ this.paintedViewportMap.delete(this.svg);
160
+ delete this.svg;
161
+ }
162
+
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;
170
+
171
+ if (typeof rotation !== "undefined") {
172
+ this.rotation = rotation;
173
+ }
174
+
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
+ });
180
+
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()
181
188
  });
182
- if (this.svg) {
183
- this.cssTransform(this.svg, true);
184
- this.eventBus.dispatch('pagerendered', {
189
+ return;
190
+ }
191
+
192
+ let isScalingRestricted = false;
193
+
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", {
185
206
  source: this,
186
207
  pageNumber: this.id,
187
- cssTransform: true
208
+ cssTransform: true,
209
+ timestamp: performance.now()
188
210
  });
189
211
  return;
190
212
  }
191
- var isScalingRestricted = false;
192
- if (this.canvas && this.maxCanvasPixels > 0) {
193
- var outputScale = this.outputScale;
194
- if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
195
- isScalingRestricted = true;
196
- }
197
- }
198
- if (this.canvas) {
199
- if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
200
- this.cssTransform(this.canvas, true);
201
- this.eventBus.dispatch('pagerendered', {
202
- source: this,
203
- pageNumber: this.id,
204
- cssTransform: true
205
- });
206
- return;
207
- }
208
- if (!this.zoomLayer && !this.canvas.hasAttribute('hidden')) {
209
- this.zoomLayer = this.canvas.parentNode;
210
- this.zoomLayer.style.position = 'absolute';
211
- }
212
- }
213
- if (this.zoomLayer) {
214
- this.cssTransform(this.zoomLayer.firstChild);
213
+
214
+ if (!this.zoomLayer && !this.canvas.hasAttribute("hidden")) {
215
+ this.zoomLayer = this.canvas.parentNode;
216
+ this.zoomLayer.style.position = "absolute";
215
217
  }
216
- this.reset(true, true);
217
218
  }
218
- }, {
219
- key: 'cancelRendering',
220
- value: function cancelRendering() {
221
- var keepAnnotations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
222
-
223
- var renderingState = this.renderingState;
224
- if (this.paintTask) {
225
- this.paintTask.cancel();
226
- this.paintTask = null;
227
- }
228
- this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
229
- this.resume = null;
230
- if (this.textLayer) {
231
- this.textLayer.cancel();
232
- this.textLayer = null;
233
- }
234
- if (!keepAnnotations && this.annotationLayer) {
235
- this.annotationLayer.cancel();
236
- this.annotationLayer = null;
237
- }
238
- if (renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
239
- this.eventBus.dispatch('pagecancelled', {
240
- source: this,
241
- pageNumber: this.id,
242
- renderingState: renderingState
243
- });
244
- }
219
+
220
+ if (this.zoomLayer) {
221
+ this.cssTransform(this.zoomLayer.firstChild);
245
222
  }
246
- }, {
247
- key: 'cssTransform',
248
- value: function cssTransform(target) {
249
- var redrawAnnotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
250
-
251
- var width = this.viewport.width;
252
- var height = this.viewport.height;
253
- var div = this.div;
254
- target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + 'px';
255
- target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + 'px';
256
- var relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
257
- var absRotation = Math.abs(relativeRotation);
258
- var scaleX = 1,
259
- scaleY = 1;
260
- if (absRotation === 90 || absRotation === 270) {
261
- scaleX = height / width;
262
- scaleY = width / height;
263
- }
264
- var cssTransform = 'rotate(' + relativeRotation + 'deg) ' + 'scale(' + scaleX + ',' + scaleY + ')';
265
- target.style.transform = cssTransform;
266
- if (this.textLayer) {
267
- var textLayerViewport = this.textLayer.viewport;
268
- var textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
269
- var textAbsRotation = Math.abs(textRelativeRotation);
270
- var scale = width / textLayerViewport.width;
271
- if (textAbsRotation === 90 || textAbsRotation === 270) {
272
- scale = width / textLayerViewport.height;
273
- }
274
- var textLayerDiv = this.textLayer.textLayerDiv;
275
- var transX = void 0,
276
- transY = void 0;
277
- switch (textAbsRotation) {
278
- case 0:
279
- transX = transY = 0;
280
- break;
281
- case 90:
282
- transX = 0;
283
- transY = '-' + textLayerDiv.style.height;
284
- break;
285
- case 180:
286
- transX = '-' + textLayerDiv.style.width;
287
- transY = '-' + textLayerDiv.style.height;
288
- break;
289
- case 270:
290
- transX = '-' + textLayerDiv.style.width;
291
- transY = 0;
292
- break;
293
- default:
294
- console.error('Bad rotation value.');
295
- break;
296
- }
297
- textLayerDiv.style.transform = 'rotate(' + textAbsRotation + 'deg) ' + 'scale(' + scale + ', ' + scale + ') ' + 'translate(' + transX + ', ' + transY + ')';
298
- textLayerDiv.style.transformOrigin = '0% 0%';
223
+
224
+ this.reset(true, true);
225
+ }
226
+
227
+ cancelRendering(keepAnnotations = false) {
228
+ if (this.paintTask) {
229
+ this.paintTask.cancel();
230
+ this.paintTask = null;
231
+ }
232
+
233
+ this.resume = null;
234
+
235
+ if (this.textLayer) {
236
+ this.textLayer.cancel();
237
+ this.textLayer = null;
238
+ }
239
+
240
+ if (!keepAnnotations && this.annotationLayer) {
241
+ this.annotationLayer.cancel();
242
+ this.annotationLayer = null;
243
+ }
244
+ }
245
+
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
+ }
261
+
262
+ const cssTransform = "rotate(" + relativeRotation + "deg) " + "scale(" + scaleX + "," + scaleY + ")";
263
+ target.style.transform = cssTransform;
264
+
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
+
271
+ if (textAbsRotation === 90 || textAbsRotation === 270) {
272
+ scale = width / textLayerViewport.height;
299
273
  }
300
- if (redrawAnnotations && this.annotationLayer) {
301
- this.annotationLayer.render(this.viewport, 'display');
274
+
275
+ const textLayerDiv = this.textLayer.textLayerDiv;
276
+ let transX, transY;
277
+
278
+ switch (textAbsRotation) {
279
+ case 0:
280
+ transX = transY = 0;
281
+ break;
282
+
283
+ case 90:
284
+ transX = 0;
285
+ transY = "-" + textLayerDiv.style.height;
286
+ break;
287
+
288
+ case 180:
289
+ transX = "-" + textLayerDiv.style.width;
290
+ transY = "-" + textLayerDiv.style.height;
291
+ break;
292
+
293
+ case 270:
294
+ transX = "-" + textLayerDiv.style.width;
295
+ transY = 0;
296
+ break;
297
+
298
+ default:
299
+ console.error("Bad rotation value.");
300
+ break;
302
301
  }
302
+
303
+ textLayerDiv.style.transform = "rotate(" + textAbsRotation + "deg) " + "scale(" + scale + ", " + scale + ") " + "translate(" + transX + ", " + transY + ")";
304
+ textLayerDiv.style.transformOrigin = "0% 0%";
303
305
  }
304
- }, {
305
- key: 'getPagePoint',
306
- value: function getPagePoint(x, y) {
307
- return this.viewport.convertToPdfPoint(x, y);
306
+
307
+ if (redrawAnnotations && this.annotationLayer) {
308
+ this.annotationLayer.render(this.viewport, "display");
308
309
  }
309
- }, {
310
- key: 'draw',
311
- value: function draw() {
312
- var _this = this;
313
-
314
- if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
315
- console.error('Must be in new state before drawing');
316
- this.reset();
317
- }
318
- if (!this.pdfPage) {
319
- this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
320
- return Promise.reject(new Error('Page is not loaded'));
310
+ }
311
+
312
+ get width() {
313
+ return this.viewport.width;
314
+ }
315
+
316
+ get height() {
317
+ return this.viewport.height;
318
+ }
319
+
320
+ getPagePoint(x, y) {
321
+ return this.viewport.convertToPdfPoint(x, y);
322
+ }
323
+
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;
321
341
  }
322
- this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
323
- var pdfPage = this.pdfPage;
324
- var div = this.div;
325
- var canvasWrapper = document.createElement('div');
326
- canvasWrapper.style.width = div.style.width;
327
- canvasWrapper.style.height = div.style.height;
328
- canvasWrapper.classList.add('canvasWrapper');
342
+
343
+ return Promise.reject(new Error("pdfPage is not loaded"));
344
+ }
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);
356
+ }
357
+
358
+ let textLayer = null;
359
+
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;
365
+
329
366
  if (this.annotationLayer && this.annotationLayer.div) {
330
- div.insertBefore(canvasWrapper, this.annotationLayer.div);
367
+ div.insertBefore(textLayerDiv, this.annotationLayer.div);
331
368
  } else {
332
- div.appendChild(canvasWrapper);
369
+ div.appendChild(textLayerDiv);
333
370
  }
334
- var textLayer = null;
335
- if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
336
- var textLayerDiv = document.createElement('div');
337
- textLayerDiv.className = 'textLayer';
338
- textLayerDiv.style.width = canvasWrapper.style.width;
339
- textLayerDiv.style.height = canvasWrapper.style.height;
340
- if (this.annotationLayer && this.annotationLayer.div) {
341
- div.insertBefore(textLayerDiv, this.annotationLayer.div);
342
- } else {
343
- div.appendChild(textLayerDiv);
344
- }
345
- textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE);
346
- }
347
- this.textLayer = textLayer;
348
- var renderContinueCallback = null;
349
- if (this.renderingQueue) {
350
- renderContinueCallback = function renderContinueCallback(cont) {
351
- if (!_this.renderingQueue.isHighestPriority(_this)) {
352
- _this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
353
- _this.resume = function () {
354
- _this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
355
- cont();
356
- };
357
- return;
358
- }
359
- cont();
360
- };
361
- }
362
- var finishPaintTask = function finishPaintTask(error) {
363
- if (paintTask === _this.paintTask) {
364
- _this.paintTask = null;
365
- }
366
- if (error instanceof _pdf.RenderingCancelledException) {
367
- _this.error = null;
368
- return Promise.resolve(undefined);
369
- }
370
- _this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
371
- if (_this.loadingIconDiv) {
372
- div.removeChild(_this.loadingIconDiv);
373
- delete _this.loadingIconDiv;
374
- }
375
- _this._resetZoomLayer(true);
376
- _this.error = error;
377
- _this.stats = pdfPage.stats;
378
- if (_this.onAfterDraw) {
379
- _this.onAfterDraw();
380
- }
381
- _this.eventBus.dispatch('pagerendered', {
382
- source: _this,
383
- pageNumber: _this.id,
384
- cssTransform: false
385
- });
386
- if (error) {
387
- return Promise.reject(error);
371
+
372
+ textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE, this.eventBus);
373
+ }
374
+
375
+ this.textLayer = textLayer;
376
+ let renderContinueCallback = null;
377
+
378
+ if (this.renderingQueue) {
379
+ renderContinueCallback = cont => {
380
+ if (!this.renderingQueue.isHighestPriority(this)) {
381
+ this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
382
+
383
+ this.resume = () => {
384
+ this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
385
+ cont();
386
+ };
387
+
388
+ return;
388
389
  }
389
- return Promise.resolve(undefined);
390
+
391
+ cont();
390
392
  };
391
- var paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
392
- paintTask.onRenderContinue = renderContinueCallback;
393
- this.paintTask = paintTask;
394
- var resultPromise = paintTask.promise.then(function () {
395
- return finishPaintTask(null).then(function () {
396
- if (textLayer) {
397
- var readableStream = pdfPage.streamTextContent({ normalizeWhitespace: true });
398
- textLayer.setTextContentStream(readableStream);
399
- textLayer.render();
400
- }
401
- });
402
- }, function (reason) {
403
- return finishPaintTask(reason);
404
- });
405
- if (this.annotationLayerFactory) {
406
- if (!this.annotationLayer) {
407
- this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, this.imageResourcesPath, this.renderInteractiveForms, this.l10n);
408
- }
409
- this.annotationLayer.render(this.viewport, 'display');
393
+ }
394
+
395
+ const finishPaintTask = async error => {
396
+ if (paintTask === this.paintTask) {
397
+ this.paintTask = null;
410
398
  }
411
- div.setAttribute('data-loaded', true);
412
- if (this.onBeforeDraw) {
413
- this.onBeforeDraw();
399
+
400
+ if (error instanceof _pdf.RenderingCancelledException) {
401
+ this.error = null;
402
+ return;
414
403
  }
415
- return resultPromise;
416
- }
417
- }, {
418
- key: 'paintOnCanvas',
419
- value: function paintOnCanvas(canvasWrapper) {
420
- var renderCapability = (0, _pdf.createPromiseCapability)();
421
- var result = {
422
- promise: renderCapability.promise,
423
- onRenderContinue: function onRenderContinue(cont) {
424
- cont();
425
- },
426
- cancel: function cancel() {
427
- renderTask.cancel();
428
- }
429
- };
430
- var viewport = this.viewport;
431
- var canvas = document.createElement('canvas');
432
- canvas.id = this.renderingId;
433
- canvas.setAttribute('hidden', 'hidden');
434
- var isCanvasHidden = true;
435
- var showCanvas = function showCanvas() {
436
- if (isCanvasHidden) {
437
- canvas.removeAttribute('hidden');
438
- isCanvasHidden = false;
439
- }
440
- };
441
- canvasWrapper.appendChild(canvas);
442
- this.canvas = canvas;
443
- canvas.mozOpaque = true;
444
- var ctx = canvas.getContext('2d', { alpha: false });
445
- var outputScale = (0, _ui_utils.getOutputScale)(ctx);
446
- this.outputScale = outputScale;
447
- if (this.useOnlyCssZoom) {
448
- var actualSizeViewport = viewport.clone({ scale: _ui_utils.CSS_UNITS });
449
- outputScale.sx *= actualSizeViewport.width / viewport.width;
450
- outputScale.sy *= actualSizeViewport.height / viewport.height;
451
- outputScale.scaled = true;
404
+
405
+ this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
406
+
407
+ if (this.loadingIconDiv) {
408
+ div.removeChild(this.loadingIconDiv);
409
+ delete this.loadingIconDiv;
452
410
  }
453
- if (this.maxCanvasPixels > 0) {
454
- var pixelsInViewport = viewport.width * viewport.height;
455
- var maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
456
- if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
457
- outputScale.sx = maxScale;
458
- outputScale.sy = maxScale;
459
- outputScale.scaled = true;
460
- this.hasRestrictedScaling = true;
461
- } else {
462
- this.hasRestrictedScaling = false;
463
- }
411
+
412
+ this._resetZoomLayer(true);
413
+
414
+ this.error = error;
415
+ this.stats = pdfPage.stats;
416
+ this.eventBus.dispatch("pagerendered", {
417
+ source: this,
418
+ pageNumber: this.id,
419
+ cssTransform: false,
420
+ timestamp: performance.now()
421
+ });
422
+
423
+ if (error) {
424
+ throw error;
464
425
  }
465
- var sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
466
- var sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
467
- canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
468
- canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
469
- canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + 'px';
470
- canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + 'px';
471
- this.paintedViewportMap.set(canvas, viewport);
472
- var transform = !outputScale.scaled ? null : [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
473
- var renderContext = {
474
- canvasContext: ctx,
475
- transform: transform,
476
- viewport: this.viewport,
477
- enableWebGL: this.enableWebGL,
478
- renderInteractiveForms: this.renderInteractiveForms
479
- };
480
- var renderTask = this.pdfPage.render(renderContext);
481
- renderTask.onContinue = function (cont) {
482
- showCanvas();
483
- if (result.onRenderContinue) {
484
- result.onRenderContinue(cont);
485
- } else {
486
- cont();
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();
487
439
  }
488
- };
489
- renderTask.promise.then(function () {
490
- showCanvas();
491
- renderCapability.resolve(undefined);
492
- }, function (error) {
493
- showCanvas();
494
- renderCapability.reject(error);
495
440
  });
496
- return result;
441
+ }, function (reason) {
442
+ return finishPaintTask(reason);
443
+ });
444
+
445
+ if (this.annotationLayerFactory) {
446
+ if (!this.annotationLayer) {
447
+ this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, this.imageResourcesPath, this.renderInteractiveForms, this.l10n);
448
+ }
449
+
450
+ this.annotationLayer.render(this.viewport, "display");
497
451
  }
498
- }, {
499
- key: 'paintOnSvg',
500
- value: function paintOnSvg(wrapper) {
501
- var _this2 = this;
502
-
503
- var cancelled = false;
504
- var ensureNotCancelled = function ensureNotCancelled() {
505
- if (cancelled) {
506
- throw new _pdf.RenderingCancelledException('Rendering cancelled, page ' + _this2.id, 'svg');
507
- }
508
- };
509
- var pdfPage = this.pdfPage;
510
- var actualSizeViewport = this.viewport.clone({ scale: _ui_utils.CSS_UNITS });
511
- var promise = pdfPage.getOperatorList().then(function (opList) {
512
- ensureNotCancelled();
513
- var svgGfx = new _pdf.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
514
- return svgGfx.getSVG(opList, actualSizeViewport).then(function (svg) {
515
- ensureNotCancelled();
516
- _this2.svg = svg;
517
- _this2.paintedViewportMap.set(svg, actualSizeViewport);
518
- svg.style.width = wrapper.style.width;
519
- svg.style.height = wrapper.style.height;
520
- _this2.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
521
- wrapper.appendChild(svg);
522
- });
452
+
453
+ div.setAttribute("data-loaded", true);
454
+ this.eventBus.dispatch("pagerender", {
455
+ source: this,
456
+ pageNumber: this.id
457
+ });
458
+ return resultPromise;
459
+ }
460
+
461
+ paintOnCanvas(canvasWrapper) {
462
+ const renderCapability = (0, _pdf.createPromiseCapability)();
463
+ const result = {
464
+ promise: renderCapability.promise,
465
+
466
+ onRenderContinue(cont) {
467
+ cont();
468
+ },
469
+
470
+ cancel() {
471
+ renderTask.cancel();
472
+ }
473
+
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
523
504
  });
524
- return {
525
- promise: promise,
526
- onRenderContinue: function onRenderContinue(cont) {
527
- cont();
528
- },
529
- cancel: function cancel() {
530
- cancelled = true;
531
- }
532
- };
505
+ outputScale.sx *= actualSizeViewport.width / viewport.width;
506
+ outputScale.sy *= actualSizeViewport.height / viewport.height;
507
+ outputScale.scaled = true;
533
508
  }
534
- }, {
535
- key: 'setPageLabel',
536
- value: function setPageLabel(label) {
537
- this.pageLabel = typeof label === 'string' ? label : null;
538
- if (this.pageLabel !== null) {
539
- this.div.setAttribute('data-page-label', this.pageLabel);
509
+
510
+ if (this.maxCanvasPixels > 0) {
511
+ const pixelsInViewport = viewport.width * viewport.height;
512
+ const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
513
+
514
+ if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
515
+ outputScale.sx = maxScale;
516
+ outputScale.sy = maxScale;
517
+ outputScale.scaled = true;
518
+ this.hasRestrictedScaling = true;
540
519
  } else {
541
- this.div.removeAttribute('data-page-label');
520
+ this.hasRestrictedScaling = false;
542
521
  }
543
522
  }
544
- }, {
545
- key: 'width',
546
- get: function get() {
547
- return this.viewport.width;
548
- }
549
- }, {
550
- key: 'height',
551
- get: function get() {
552
- return this.viewport.height;
523
+
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
+ }
560
+
561
+ paintOnSvg(wrapper) {
562
+ let cancelled = false;
563
+
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);
585
+ });
586
+ });
587
+ return {
588
+ promise,
589
+
590
+ onRenderContinue(cont) {
591
+ cont();
592
+ },
593
+
594
+ cancel() {
595
+ cancelled = true;
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");
553
608
  }
554
- }]);
609
+ }
555
610
 
556
- return PDFPageView;
557
- }();
611
+ }
558
612
 
559
613
  exports.PDFPageView = PDFPageView;