pdfjs-dist 2.1.266 → 2.5.207

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

Potentially problematic release.


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

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