pdfjs-dist 2.2.228 → 2.6.347

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