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,318 +26,308 @@ Object.defineProperty(exports, "__esModule", {
26
26
  });
27
27
  exports.ChunkedStreamManager = exports.ChunkedStream = void 0;
28
28
 
29
- var _util = require("../shared/util");
29
+ var _util = require("../shared/util.js");
30
30
 
31
- var _core_utils = require("./core_utils");
32
-
33
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
34
-
35
- 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); } }
36
-
37
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
38
-
39
- var ChunkedStream =
40
- /*#__PURE__*/
41
- function () {
42
- function ChunkedStream(length, chunkSize, manager) {
43
- _classCallCheck(this, ChunkedStream);
31
+ var _core_utils = require("./core_utils.js");
44
32
 
33
+ class ChunkedStream {
34
+ constructor(length, chunkSize, manager) {
45
35
  this.bytes = new Uint8Array(length);
46
36
  this.start = 0;
47
37
  this.pos = 0;
48
38
  this.end = length;
49
39
  this.chunkSize = chunkSize;
50
- this.loadedChunks = [];
51
- this.numChunksLoaded = 0;
40
+ this._loadedChunks = new Set();
52
41
  this.numChunks = Math.ceil(length / chunkSize);
53
42
  this.manager = manager;
54
43
  this.progressiveDataLength = 0;
55
44
  this.lastSuccessfulEnsureByteChunk = -1;
56
45
  }
57
46
 
58
- _createClass(ChunkedStream, [{
59
- key: "getMissingChunks",
60
- value: function getMissingChunks() {
61
- var chunks = [];
47
+ getMissingChunks() {
48
+ const chunks = [];
62
49
 
63
- for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
64
- if (!this.loadedChunks[chunk]) {
65
- chunks.push(chunk);
66
- }
50
+ for (let chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
51
+ if (!this._loadedChunks.has(chunk)) {
52
+ chunks.push(chunk);
67
53
  }
68
-
69
- return chunks;
70
54
  }
71
- }, {
72
- key: "getBaseStreams",
73
- value: function getBaseStreams() {
74
- return [this];
55
+
56
+ return chunks;
57
+ }
58
+
59
+ getBaseStreams() {
60
+ return [this];
61
+ }
62
+
63
+ get numChunksLoaded() {
64
+ return this._loadedChunks.size;
65
+ }
66
+
67
+ allChunksLoaded() {
68
+ return this.numChunksLoaded === this.numChunks;
69
+ }
70
+
71
+ onReceiveData(begin, chunk) {
72
+ const chunkSize = this.chunkSize;
73
+
74
+ if (begin % chunkSize !== 0) {
75
+ throw new Error(`Bad begin offset: ${begin}`);
75
76
  }
76
- }, {
77
- key: "allChunksLoaded",
78
- value: function allChunksLoaded() {
79
- return this.numChunksLoaded === this.numChunks;
77
+
78
+ const end = begin + chunk.byteLength;
79
+
80
+ if (end % chunkSize !== 0 && end !== this.bytes.length) {
81
+ throw new Error(`Bad end offset: ${end}`);
80
82
  }
81
- }, {
82
- key: "onReceiveData",
83
- value: function onReceiveData(begin, chunk) {
84
- var chunkSize = this.chunkSize;
85
83
 
86
- if (begin % chunkSize !== 0) {
87
- throw new Error("Bad begin offset: ".concat(begin));
88
- }
84
+ this.bytes.set(new Uint8Array(chunk), begin);
85
+ const beginChunk = Math.floor(begin / chunkSize);
86
+ const endChunk = Math.floor((end - 1) / chunkSize) + 1;
89
87
 
90
- var end = begin + chunk.byteLength;
88
+ for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
89
+ this._loadedChunks.add(curChunk);
90
+ }
91
+ }
91
92
 
92
- if (end % chunkSize !== 0 && end !== this.bytes.length) {
93
- throw new Error("Bad end offset: ".concat(end));
94
- }
93
+ onReceiveProgressiveData(data) {
94
+ let position = this.progressiveDataLength;
95
+ const beginChunk = Math.floor(position / this.chunkSize);
96
+ this.bytes.set(new Uint8Array(data), position);
97
+ position += data.byteLength;
98
+ this.progressiveDataLength = position;
99
+ const endChunk = position >= this.end ? this.numChunks : Math.floor(position / this.chunkSize);
95
100
 
96
- this.bytes.set(new Uint8Array(chunk), begin);
97
- var beginChunk = Math.floor(begin / chunkSize);
98
- var endChunk = Math.floor((end - 1) / chunkSize) + 1;
101
+ for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
102
+ this._loadedChunks.add(curChunk);
103
+ }
104
+ }
99
105
 
100
- for (var curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
101
- if (!this.loadedChunks[curChunk]) {
102
- this.loadedChunks[curChunk] = true;
103
- ++this.numChunksLoaded;
104
- }
105
- }
106
+ ensureByte(pos) {
107
+ if (pos < this.progressiveDataLength) {
108
+ return;
106
109
  }
107
- }, {
108
- key: "onReceiveProgressiveData",
109
- value: function onReceiveProgressiveData(data) {
110
- var position = this.progressiveDataLength;
111
- var beginChunk = Math.floor(position / this.chunkSize);
112
- this.bytes.set(new Uint8Array(data), position);
113
- position += data.byteLength;
114
- this.progressiveDataLength = position;
115
- var endChunk = position >= this.end ? this.numChunks : Math.floor(position / this.chunkSize);
116
-
117
- for (var curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
118
- if (!this.loadedChunks[curChunk]) {
119
- this.loadedChunks[curChunk] = true;
120
- ++this.numChunksLoaded;
121
- }
122
- }
110
+
111
+ const chunk = Math.floor(pos / this.chunkSize);
112
+
113
+ if (chunk === this.lastSuccessfulEnsureByteChunk) {
114
+ return;
123
115
  }
124
- }, {
125
- key: "ensureByte",
126
- value: function ensureByte(pos) {
127
- if (pos < this.progressiveDataLength) {
128
- return;
129
- }
130
116
 
131
- var chunk = Math.floor(pos / this.chunkSize);
117
+ if (!this._loadedChunks.has(chunk)) {
118
+ throw new _core_utils.MissingDataException(pos, pos + 1);
119
+ }
132
120
 
133
- if (chunk === this.lastSuccessfulEnsureByteChunk) {
134
- return;
135
- }
121
+ this.lastSuccessfulEnsureByteChunk = chunk;
122
+ }
136
123
 
137
- if (!this.loadedChunks[chunk]) {
138
- throw new _core_utils.MissingDataException(pos, pos + 1);
139
- }
124
+ ensureRange(begin, end) {
125
+ if (begin >= end) {
126
+ return;
127
+ }
140
128
 
141
- this.lastSuccessfulEnsureByteChunk = chunk;
129
+ if (end <= this.progressiveDataLength) {
130
+ return;
142
131
  }
143
- }, {
144
- key: "ensureRange",
145
- value: function ensureRange(begin, end) {
146
- if (begin >= end) {
147
- return;
148
- }
149
132
 
150
- if (end <= this.progressiveDataLength) {
151
- return;
133
+ const chunkSize = this.chunkSize;
134
+ const beginChunk = Math.floor(begin / chunkSize);
135
+ const endChunk = Math.floor((end - 1) / chunkSize) + 1;
136
+
137
+ for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
138
+ if (!this._loadedChunks.has(chunk)) {
139
+ throw new _core_utils.MissingDataException(begin, end);
152
140
  }
141
+ }
142
+ }
153
143
 
154
- var chunkSize = this.chunkSize;
155
- var beginChunk = Math.floor(begin / chunkSize);
156
- var endChunk = Math.floor((end - 1) / chunkSize) + 1;
144
+ nextEmptyChunk(beginChunk) {
145
+ const numChunks = this.numChunks;
157
146
 
158
- for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
159
- if (!this.loadedChunks[chunk]) {
160
- throw new _core_utils.MissingDataException(begin, end);
161
- }
147
+ for (let i = 0; i < numChunks; ++i) {
148
+ const chunk = (beginChunk + i) % numChunks;
149
+
150
+ if (!this._loadedChunks.has(chunk)) {
151
+ return chunk;
162
152
  }
163
153
  }
164
- }, {
165
- key: "nextEmptyChunk",
166
- value: function nextEmptyChunk(beginChunk) {
167
- var numChunks = this.numChunks;
168
154
 
169
- for (var i = 0; i < numChunks; ++i) {
170
- var chunk = (beginChunk + i) % numChunks;
155
+ return null;
156
+ }
171
157
 
172
- if (!this.loadedChunks[chunk]) {
173
- return chunk;
174
- }
175
- }
158
+ hasChunk(chunk) {
159
+ return this._loadedChunks.has(chunk);
160
+ }
161
+
162
+ get length() {
163
+ return this.end - this.start;
164
+ }
165
+
166
+ get isEmpty() {
167
+ return this.length === 0;
168
+ }
169
+
170
+ getByte() {
171
+ const pos = this.pos;
176
172
 
177
- return null;
173
+ if (pos >= this.end) {
174
+ return -1;
178
175
  }
179
- }, {
180
- key: "hasChunk",
181
- value: function hasChunk(chunk) {
182
- return !!this.loadedChunks[chunk];
176
+
177
+ if (pos >= this.progressiveDataLength) {
178
+ this.ensureByte(pos);
183
179
  }
184
- }, {
185
- key: "getByte",
186
- value: function getByte() {
187
- var pos = this.pos;
188
180
 
189
- if (pos >= this.end) {
190
- return -1;
191
- }
181
+ return this.bytes[this.pos++];
182
+ }
192
183
 
193
- this.ensureByte(pos);
194
- return this.bytes[this.pos++];
184
+ getUint16() {
185
+ const b0 = this.getByte();
186
+ const b1 = this.getByte();
187
+
188
+ if (b0 === -1 || b1 === -1) {
189
+ return -1;
195
190
  }
196
- }, {
197
- key: "getUint16",
198
- value: function getUint16() {
199
- var b0 = this.getByte();
200
- var b1 = this.getByte();
201
191
 
202
- if (b0 === -1 || b1 === -1) {
203
- return -1;
204
- }
192
+ return (b0 << 8) + b1;
193
+ }
205
194
 
206
- return (b0 << 8) + b1;
207
- }
208
- }, {
209
- key: "getInt32",
210
- value: function getInt32() {
211
- var b0 = this.getByte();
212
- var b1 = this.getByte();
213
- var b2 = this.getByte();
214
- var b3 = this.getByte();
215
- return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
216
- }
217
- }, {
218
- key: "getBytes",
219
- value: function getBytes(length) {
220
- var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
221
- var bytes = this.bytes;
222
- var pos = this.pos;
223
- var strEnd = this.end;
224
-
225
- if (!length) {
226
- this.ensureRange(pos, strEnd);
195
+ getInt32() {
196
+ const b0 = this.getByte();
197
+ const b1 = this.getByte();
198
+ const b2 = this.getByte();
199
+ const b3 = this.getByte();
200
+ return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
201
+ }
227
202
 
228
- var _subarray = bytes.subarray(pos, strEnd);
203
+ getBytes(length, forceClamped = false) {
204
+ const bytes = this.bytes;
205
+ const pos = this.pos;
206
+ const strEnd = this.end;
229
207
 
230
- return forceClamped ? new Uint8ClampedArray(_subarray) : _subarray;
208
+ if (!length) {
209
+ if (strEnd > this.progressiveDataLength) {
210
+ this.ensureRange(pos, strEnd);
231
211
  }
232
212
 
233
- var end = pos + length;
213
+ const subarray = bytes.subarray(pos, strEnd);
214
+ return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
215
+ }
234
216
 
235
- if (end > strEnd) {
236
- end = strEnd;
237
- }
217
+ let end = pos + length;
238
218
 
219
+ if (end > strEnd) {
220
+ end = strEnd;
221
+ }
222
+
223
+ if (end > this.progressiveDataLength) {
239
224
  this.ensureRange(pos, end);
240
- this.pos = end;
241
- var subarray = bytes.subarray(pos, end);
242
- return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
243
225
  }
244
- }, {
245
- key: "peekByte",
246
- value: function peekByte() {
247
- var peekedByte = this.getByte();
226
+
227
+ this.pos = end;
228
+ const subarray = bytes.subarray(pos, end);
229
+ return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
230
+ }
231
+
232
+ peekByte() {
233
+ const peekedByte = this.getByte();
234
+
235
+ if (peekedByte !== -1) {
248
236
  this.pos--;
249
- return peekedByte;
250
- }
251
- }, {
252
- key: "peekBytes",
253
- value: function peekBytes(length) {
254
- var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
255
- var bytes = this.getBytes(length, forceClamped);
256
- this.pos -= bytes.length;
257
- return bytes;
258
- }
259
- }, {
260
- key: "getByteRange",
261
- value: function getByteRange(begin, end) {
262
- this.ensureRange(begin, end);
263
- return this.bytes.subarray(begin, end);
264
237
  }
265
- }, {
266
- key: "skip",
267
- value: function skip(n) {
268
- if (!n) {
269
- n = 1;
270
- }
271
238
 
272
- this.pos += n;
239
+ return peekedByte;
240
+ }
241
+
242
+ peekBytes(length, forceClamped = false) {
243
+ const bytes = this.getBytes(length, forceClamped);
244
+ this.pos -= bytes.length;
245
+ return bytes;
246
+ }
247
+
248
+ getByteRange(begin, end) {
249
+ if (begin < 0) {
250
+ begin = 0;
251
+ }
252
+
253
+ if (end > this.end) {
254
+ end = this.end;
273
255
  }
274
- }, {
275
- key: "reset",
276
- value: function reset() {
277
- this.pos = this.start;
256
+
257
+ if (end > this.progressiveDataLength) {
258
+ this.ensureRange(begin, end);
278
259
  }
279
- }, {
280
- key: "moveStart",
281
- value: function moveStart() {
282
- this.start = this.pos;
260
+
261
+ return this.bytes.subarray(begin, end);
262
+ }
263
+
264
+ skip(n) {
265
+ if (!n) {
266
+ n = 1;
283
267
  }
284
- }, {
285
- key: "makeSubStream",
286
- value: function makeSubStream(start, length, dict) {
287
- if (length) {
268
+
269
+ this.pos += n;
270
+ }
271
+
272
+ reset() {
273
+ this.pos = this.start;
274
+ }
275
+
276
+ moveStart() {
277
+ this.start = this.pos;
278
+ }
279
+
280
+ makeSubStream(start, length, dict) {
281
+ if (length) {
282
+ if (start + length > this.progressiveDataLength) {
288
283
  this.ensureRange(start, start + length);
289
- } else {
284
+ }
285
+ } else {
286
+ if (start >= this.progressiveDataLength) {
290
287
  this.ensureByte(start);
291
288
  }
289
+ }
292
290
 
293
- function ChunkedStreamSubstream() {}
291
+ function ChunkedStreamSubstream() {}
294
292
 
295
- ChunkedStreamSubstream.prototype = Object.create(this);
293
+ ChunkedStreamSubstream.prototype = Object.create(this);
296
294
 
297
- ChunkedStreamSubstream.prototype.getMissingChunks = function () {
298
- var chunkSize = this.chunkSize;
299
- var beginChunk = Math.floor(this.start / chunkSize);
300
- var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
301
- var missingChunks = [];
295
+ ChunkedStreamSubstream.prototype.getMissingChunks = function () {
296
+ const chunkSize = this.chunkSize;
297
+ const beginChunk = Math.floor(this.start / chunkSize);
298
+ const endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
299
+ const missingChunks = [];
302
300
 
303
- for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
304
- if (!this.loadedChunks[chunk]) {
305
- missingChunks.push(chunk);
306
- }
301
+ for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
302
+ if (!this._loadedChunks.has(chunk)) {
303
+ missingChunks.push(chunk);
307
304
  }
305
+ }
308
306
 
309
- return missingChunks;
310
- };
307
+ return missingChunks;
308
+ };
311
309
 
312
- var subStream = new ChunkedStreamSubstream();
313
- subStream.pos = subStream.start = start;
314
- subStream.end = start + length || this.end;
315
- subStream.dict = dict;
316
- return subStream;
317
- }
318
- }, {
319
- key: "length",
320
- get: function get() {
321
- return this.end - this.start;
322
- }
323
- }, {
324
- key: "isEmpty",
325
- get: function get() {
326
- return this.length === 0;
327
- }
328
- }]);
310
+ ChunkedStreamSubstream.prototype.allChunksLoaded = function () {
311
+ if (this.numChunksLoaded === this.numChunks) {
312
+ return true;
313
+ }
329
314
 
330
- return ChunkedStream;
331
- }();
315
+ return this.getMissingChunks().length === 0;
316
+ };
332
317
 
333
- exports.ChunkedStream = ChunkedStream;
318
+ const subStream = new ChunkedStreamSubstream();
319
+ subStream.pos = subStream.start = start;
320
+ subStream.end = start + length || this.end;
321
+ subStream.dict = dict;
322
+ return subStream;
323
+ }
334
324
 
335
- var ChunkedStreamManager =
336
- /*#__PURE__*/
337
- function () {
338
- function ChunkedStreamManager(pdfNetworkStream, args) {
339
- _classCallCheck(this, ChunkedStreamManager);
325
+ }
340
326
 
327
+ exports.ChunkedStream = ChunkedStream;
328
+
329
+ class ChunkedStreamManager {
330
+ constructor(pdfNetworkStream, args) {
341
331
  this.length = args.length;
342
332
  this.chunkSize = args.rangeChunkSize;
343
333
  this.stream = new ChunkedStream(this.length, this.chunkSize, this);
@@ -345,389 +335,308 @@ function () {
345
335
  this.disableAutoFetch = args.disableAutoFetch;
346
336
  this.msgHandler = args.msgHandler;
347
337
  this.currRequestId = 0;
348
- this.chunksNeededByRequest = Object.create(null);
349
- this.requestsByChunk = Object.create(null);
350
- this.promisesByRequest = Object.create(null);
338
+ this._chunksNeededByRequest = new Map();
339
+ this._requestsByChunk = new Map();
340
+ this._promisesByRequest = new Map();
351
341
  this.progressiveDataLength = 0;
352
342
  this.aborted = false;
353
343
  this._loadedStreamCapability = (0, _util.createPromiseCapability)();
354
344
  }
355
345
 
356
- _createClass(ChunkedStreamManager, [{
357
- key: "onLoadedStream",
358
- value: function onLoadedStream() {
359
- return this._loadedStreamCapability.promise;
360
- }
361
- }, {
362
- key: "sendRequest",
363
- value: function sendRequest(begin, end) {
364
- var _this = this;
346
+ onLoadedStream() {
347
+ return this._loadedStreamCapability.promise;
348
+ }
365
349
 
366
- var rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
350
+ sendRequest(begin, end) {
351
+ const rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
367
352
 
368
- if (!rangeReader.isStreamingSupported) {
369
- rangeReader.onProgress = this.onProgress.bind(this);
370
- }
353
+ if (!rangeReader.isStreamingSupported) {
354
+ rangeReader.onProgress = this.onProgress.bind(this);
355
+ }
371
356
 
372
- var chunks = [],
373
- loaded = 0;
374
- var promise = new Promise(function (resolve, reject) {
375
- var readChunk = function readChunk(chunk) {
376
- try {
377
- if (!chunk.done) {
378
- var data = chunk.value;
379
- chunks.push(data);
380
- loaded += (0, _util.arrayByteLength)(data);
381
-
382
- if (rangeReader.isStreamingSupported) {
383
- _this.onProgress({
384
- loaded: loaded
385
- });
386
- }
387
-
388
- rangeReader.read().then(readChunk, reject);
389
- return;
357
+ let chunks = [],
358
+ loaded = 0;
359
+ const promise = new Promise((resolve, reject) => {
360
+ const readChunk = chunk => {
361
+ try {
362
+ if (!chunk.done) {
363
+ const data = chunk.value;
364
+ chunks.push(data);
365
+ loaded += (0, _util.arrayByteLength)(data);
366
+
367
+ if (rangeReader.isStreamingSupported) {
368
+ this.onProgress({
369
+ loaded
370
+ });
390
371
  }
391
372
 
392
- var chunkData = (0, _util.arraysToBytes)(chunks);
393
- chunks = null;
394
- resolve(chunkData);
395
- } catch (e) {
396
- reject(e);
373
+ rangeReader.read().then(readChunk, reject);
374
+ return;
397
375
  }
398
- };
399
376
 
400
- rangeReader.read().then(readChunk, reject);
401
- });
402
- promise.then(function (data) {
403
- if (_this.aborted) {
404
- return;
377
+ const chunkData = (0, _util.arraysToBytes)(chunks);
378
+ chunks = null;
379
+ resolve(chunkData);
380
+ } catch (e) {
381
+ reject(e);
405
382
  }
383
+ };
406
384
 
407
- _this.onReceiveData({
408
- chunk: data,
409
- begin: begin
410
- });
385
+ rangeReader.read().then(readChunk, reject);
386
+ });
387
+ promise.then(data => {
388
+ if (this.aborted) {
389
+ return;
390
+ }
391
+
392
+ this.onReceiveData({
393
+ chunk: data,
394
+ begin
411
395
  });
412
- }
413
- }, {
414
- key: "requestAllChunks",
415
- value: function requestAllChunks() {
416
- var missingChunks = this.stream.getMissingChunks();
396
+ });
397
+ }
417
398
 
418
- this._requestChunks(missingChunks);
399
+ requestAllChunks() {
400
+ const missingChunks = this.stream.getMissingChunks();
419
401
 
420
- return this._loadedStreamCapability.promise;
421
- }
422
- }, {
423
- key: "_requestChunks",
424
- value: function _requestChunks(chunks) {
425
- var requestId = this.currRequestId++;
426
- var chunksNeeded = Object.create(null);
427
- this.chunksNeededByRequest[requestId] = chunksNeeded;
428
- var _iteratorNormalCompletion = true;
429
- var _didIteratorError = false;
430
- var _iteratorError = undefined;
402
+ this._requestChunks(missingChunks);
403
+
404
+ return this._loadedStreamCapability.promise;
405
+ }
431
406
 
432
- try {
433
- for (var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
434
- var _chunk = _step.value;
407
+ _requestChunks(chunks) {
408
+ const requestId = this.currRequestId++;
409
+ const chunksNeeded = new Set();
435
410
 
436
- if (!this.stream.hasChunk(_chunk)) {
437
- chunksNeeded[_chunk] = true;
438
- }
439
- }
440
- } catch (err) {
441
- _didIteratorError = true;
442
- _iteratorError = err;
443
- } finally {
444
- try {
445
- if (!_iteratorNormalCompletion && _iterator["return"] != null) {
446
- _iterator["return"]();
447
- }
448
- } finally {
449
- if (_didIteratorError) {
450
- throw _iteratorError;
451
- }
452
- }
453
- }
411
+ this._chunksNeededByRequest.set(requestId, chunksNeeded);
454
412
 
455
- if ((0, _util.isEmptyObj)(chunksNeeded)) {
456
- return Promise.resolve();
413
+ for (const chunk of chunks) {
414
+ if (!this.stream.hasChunk(chunk)) {
415
+ chunksNeeded.add(chunk);
457
416
  }
417
+ }
458
418
 
459
- var capability = (0, _util.createPromiseCapability)();
460
- this.promisesByRequest[requestId] = capability;
461
- var chunksToRequest = [];
419
+ if (chunksNeeded.size === 0) {
420
+ return Promise.resolve();
421
+ }
462
422
 
463
- for (var chunk in chunksNeeded) {
464
- chunk = chunk | 0;
423
+ const capability = (0, _util.createPromiseCapability)();
465
424
 
466
- if (!(chunk in this.requestsByChunk)) {
467
- this.requestsByChunk[chunk] = [];
468
- chunksToRequest.push(chunk);
469
- }
425
+ this._promisesByRequest.set(requestId, capability);
470
426
 
471
- this.requestsByChunk[chunk].push(requestId);
472
- }
427
+ const chunksToRequest = [];
473
428
 
474
- if (!chunksToRequest.length) {
475
- return capability.promise;
476
- }
429
+ for (const chunk of chunksNeeded) {
430
+ let requestIds = this._requestsByChunk.get(chunk);
477
431
 
478
- var groupedChunksToRequest = this.groupChunks(chunksToRequest);
479
- var _iteratorNormalCompletion2 = true;
480
- var _didIteratorError2 = false;
481
- var _iteratorError2 = undefined;
482
-
483
- try {
484
- for (var _iterator2 = groupedChunksToRequest[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
485
- var groupedChunk = _step2.value;
486
- var begin = groupedChunk.beginChunk * this.chunkSize;
487
- var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
488
- this.sendRequest(begin, end);
489
- }
490
- } catch (err) {
491
- _didIteratorError2 = true;
492
- _iteratorError2 = err;
493
- } finally {
494
- try {
495
- if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
496
- _iterator2["return"]();
497
- }
498
- } finally {
499
- if (_didIteratorError2) {
500
- throw _iteratorError2;
501
- }
502
- }
432
+ if (!requestIds) {
433
+ requestIds = [];
434
+
435
+ this._requestsByChunk.set(chunk, requestIds);
436
+
437
+ chunksToRequest.push(chunk);
503
438
  }
504
439
 
505
- return capability.promise;
440
+ requestIds.push(requestId);
506
441
  }
507
- }, {
508
- key: "getStream",
509
- value: function getStream() {
510
- return this.stream;
511
- }
512
- }, {
513
- key: "requestRange",
514
- value: function requestRange(begin, end) {
515
- end = Math.min(end, this.length);
516
- var beginChunk = this.getBeginChunk(begin);
517
- var endChunk = this.getEndChunk(end);
518
- var chunks = [];
519
442
 
520
- for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
521
- chunks.push(chunk);
443
+ if (chunksToRequest.length > 0) {
444
+ const groupedChunksToRequest = this.groupChunks(chunksToRequest);
445
+
446
+ for (const groupedChunk of groupedChunksToRequest) {
447
+ const begin = groupedChunk.beginChunk * this.chunkSize;
448
+ const end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
449
+ this.sendRequest(begin, end);
522
450
  }
451
+ }
523
452
 
524
- return this._requestChunks(chunks);
525
- }
526
- }, {
527
- key: "requestRanges",
528
- value: function requestRanges() {
529
- var ranges = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
530
- var chunksToRequest = [];
531
- var _iteratorNormalCompletion3 = true;
532
- var _didIteratorError3 = false;
533
- var _iteratorError3 = undefined;
534
-
535
- try {
536
- for (var _iterator3 = ranges[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
537
- var range = _step3.value;
538
- var beginChunk = this.getBeginChunk(range.begin);
539
- var endChunk = this.getEndChunk(range.end);
540
-
541
- for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
542
- if (!chunksToRequest.includes(chunk)) {
543
- chunksToRequest.push(chunk);
544
- }
545
- }
546
- }
547
- } catch (err) {
548
- _didIteratorError3 = true;
549
- _iteratorError3 = err;
550
- } finally {
551
- try {
552
- if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) {
553
- _iterator3["return"]();
554
- }
555
- } finally {
556
- if (_didIteratorError3) {
557
- throw _iteratorError3;
558
- }
559
- }
453
+ return capability.promise.catch(reason => {
454
+ if (this.aborted) {
455
+ return;
560
456
  }
561
457
 
562
- chunksToRequest.sort(function (a, b) {
563
- return a - b;
564
- });
565
- return this._requestChunks(chunksToRequest);
458
+ throw reason;
459
+ });
460
+ }
461
+
462
+ getStream() {
463
+ return this.stream;
464
+ }
465
+
466
+ requestRange(begin, end) {
467
+ end = Math.min(end, this.length);
468
+ const beginChunk = this.getBeginChunk(begin);
469
+ const endChunk = this.getEndChunk(end);
470
+ const chunks = [];
471
+
472
+ for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
473
+ chunks.push(chunk);
566
474
  }
567
- }, {
568
- key: "groupChunks",
569
- value: function groupChunks(chunks) {
570
- var groupedChunks = [];
571
- var beginChunk = -1;
572
- var prevChunk = -1;
573
475
 
574
- for (var i = 0, ii = chunks.length; i < ii; ++i) {
575
- var chunk = chunks[i];
476
+ return this._requestChunks(chunks);
477
+ }
576
478
 
577
- if (beginChunk < 0) {
578
- beginChunk = chunk;
579
- }
479
+ requestRanges(ranges = []) {
480
+ const chunksToRequest = [];
580
481
 
581
- if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
582
- groupedChunks.push({
583
- beginChunk: beginChunk,
584
- endChunk: prevChunk + 1
585
- });
586
- beginChunk = chunk;
587
- }
482
+ for (const range of ranges) {
483
+ const beginChunk = this.getBeginChunk(range.begin);
484
+ const endChunk = this.getEndChunk(range.end);
588
485
 
589
- if (i + 1 === chunks.length) {
590
- groupedChunks.push({
591
- beginChunk: beginChunk,
592
- endChunk: chunk + 1
593
- });
486
+ for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
487
+ if (!chunksToRequest.includes(chunk)) {
488
+ chunksToRequest.push(chunk);
594
489
  }
490
+ }
491
+ }
492
+
493
+ chunksToRequest.sort(function (a, b) {
494
+ return a - b;
495
+ });
496
+ return this._requestChunks(chunksToRequest);
497
+ }
498
+
499
+ groupChunks(chunks) {
500
+ const groupedChunks = [];
501
+ let beginChunk = -1;
502
+ let prevChunk = -1;
503
+
504
+ for (let i = 0, ii = chunks.length; i < ii; ++i) {
505
+ const chunk = chunks[i];
595
506
 
596
- prevChunk = chunk;
507
+ if (beginChunk < 0) {
508
+ beginChunk = chunk;
597
509
  }
598
510
 
599
- return groupedChunks;
600
- }
601
- }, {
602
- key: "onProgress",
603
- value: function onProgress(args) {
604
- this.msgHandler.send('DocProgress', {
605
- loaded: this.stream.numChunksLoaded * this.chunkSize + args.loaded,
606
- total: this.length
607
- });
608
- }
609
- }, {
610
- key: "onReceiveData",
611
- value: function onReceiveData(args) {
612
- var chunk = args.chunk;
613
- var isProgressive = args.begin === undefined;
614
- var begin = isProgressive ? this.progressiveDataLength : args.begin;
615
- var end = begin + chunk.byteLength;
616
- var beginChunk = Math.floor(begin / this.chunkSize);
617
- var endChunk = end < this.length ? Math.floor(end / this.chunkSize) : Math.ceil(end / this.chunkSize);
618
-
619
- if (isProgressive) {
620
- this.stream.onReceiveProgressiveData(chunk);
621
- this.progressiveDataLength = end;
622
- } else {
623
- this.stream.onReceiveData(begin, chunk);
511
+ if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
512
+ groupedChunks.push({
513
+ beginChunk,
514
+ endChunk: prevChunk + 1
515
+ });
516
+ beginChunk = chunk;
624
517
  }
625
518
 
626
- if (this.stream.allChunksLoaded()) {
627
- this._loadedStreamCapability.resolve(this.stream);
519
+ if (i + 1 === chunks.length) {
520
+ groupedChunks.push({
521
+ beginChunk,
522
+ endChunk: chunk + 1
523
+ });
628
524
  }
629
525
 
630
- var loadedRequests = [];
526
+ prevChunk = chunk;
527
+ }
528
+
529
+ return groupedChunks;
530
+ }
631
531
 
632
- for (var _chunk2 = beginChunk; _chunk2 < endChunk; ++_chunk2) {
633
- var requestIds = this.requestsByChunk[_chunk2] || [];
634
- delete this.requestsByChunk[_chunk2];
635
- var _iteratorNormalCompletion4 = true;
636
- var _didIteratorError4 = false;
637
- var _iteratorError4 = undefined;
532
+ onProgress(args) {
533
+ this.msgHandler.send("DocProgress", {
534
+ loaded: this.stream.numChunksLoaded * this.chunkSize + args.loaded,
535
+ total: this.length
536
+ });
537
+ }
638
538
 
639
- try {
640
- for (var _iterator4 = requestIds[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
641
- var requestId = _step4.value;
642
- var chunksNeeded = this.chunksNeededByRequest[requestId];
539
+ onReceiveData(args) {
540
+ const chunk = args.chunk;
541
+ const isProgressive = args.begin === undefined;
542
+ const begin = isProgressive ? this.progressiveDataLength : args.begin;
543
+ const end = begin + chunk.byteLength;
544
+ const beginChunk = Math.floor(begin / this.chunkSize);
545
+ const endChunk = end < this.length ? Math.floor(end / this.chunkSize) : Math.ceil(end / this.chunkSize);
643
546
 
644
- if (_chunk2 in chunksNeeded) {
645
- delete chunksNeeded[_chunk2];
646
- }
547
+ if (isProgressive) {
548
+ this.stream.onReceiveProgressiveData(chunk);
549
+ this.progressiveDataLength = end;
550
+ } else {
551
+ this.stream.onReceiveData(begin, chunk);
552
+ }
647
553
 
648
- if (!(0, _util.isEmptyObj)(chunksNeeded)) {
649
- continue;
650
- }
554
+ if (this.stream.allChunksLoaded()) {
555
+ this._loadedStreamCapability.resolve(this.stream);
556
+ }
651
557
 
652
- loadedRequests.push(requestId);
653
- }
654
- } catch (err) {
655
- _didIteratorError4 = true;
656
- _iteratorError4 = err;
657
- } finally {
658
- try {
659
- if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) {
660
- _iterator4["return"]();
661
- }
662
- } finally {
663
- if (_didIteratorError4) {
664
- throw _iteratorError4;
665
- }
666
- }
667
- }
558
+ const loadedRequests = [];
559
+
560
+ for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
561
+ const requestIds = this._requestsByChunk.get(curChunk);
562
+
563
+ if (!requestIds) {
564
+ continue;
668
565
  }
669
566
 
670
- if (!this.disableAutoFetch && (0, _util.isEmptyObj)(this.requestsByChunk)) {
671
- var nextEmptyChunk;
567
+ this._requestsByChunk.delete(curChunk);
672
568
 
673
- if (this.stream.numChunksLoaded === 1) {
674
- var lastChunk = this.stream.numChunks - 1;
569
+ for (const requestId of requestIds) {
570
+ const chunksNeeded = this._chunksNeededByRequest.get(requestId);
675
571
 
676
- if (!this.stream.hasChunk(lastChunk)) {
677
- nextEmptyChunk = lastChunk;
678
- }
679
- } else {
680
- nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
572
+ if (chunksNeeded.has(curChunk)) {
573
+ chunksNeeded.delete(curChunk);
681
574
  }
682
575
 
683
- if (Number.isInteger(nextEmptyChunk)) {
684
- this._requestChunks([nextEmptyChunk]);
576
+ if (chunksNeeded.size > 0) {
577
+ continue;
685
578
  }
579
+
580
+ loadedRequests.push(requestId);
686
581
  }
582
+ }
687
583
 
688
- for (var _i = 0, _loadedRequests = loadedRequests; _i < _loadedRequests.length; _i++) {
689
- var _requestId = _loadedRequests[_i];
690
- var capability = this.promisesByRequest[_requestId];
691
- delete this.promisesByRequest[_requestId];
692
- capability.resolve();
584
+ if (!this.disableAutoFetch && this._requestsByChunk.size === 0) {
585
+ let nextEmptyChunk;
586
+
587
+ if (this.stream.numChunksLoaded === 1) {
588
+ const lastChunk = this.stream.numChunks - 1;
589
+
590
+ if (!this.stream.hasChunk(lastChunk)) {
591
+ nextEmptyChunk = lastChunk;
592
+ }
593
+ } else {
594
+ nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
693
595
  }
694
596
 
695
- this.msgHandler.send('DocProgress', {
696
- loaded: this.stream.numChunksLoaded * this.chunkSize,
697
- total: this.length
698
- });
699
- }
700
- }, {
701
- key: "onError",
702
- value: function onError(err) {
703
- this._loadedStreamCapability.reject(err);
704
- }
705
- }, {
706
- key: "getBeginChunk",
707
- value: function getBeginChunk(begin) {
708
- return Math.floor(begin / this.chunkSize);
597
+ if (Number.isInteger(nextEmptyChunk)) {
598
+ this._requestChunks([nextEmptyChunk]);
599
+ }
709
600
  }
710
- }, {
711
- key: "getEndChunk",
712
- value: function getEndChunk(end) {
713
- return Math.floor((end - 1) / this.chunkSize) + 1;
601
+
602
+ for (const requestId of loadedRequests) {
603
+ const capability = this._promisesByRequest.get(requestId);
604
+
605
+ this._promisesByRequest.delete(requestId);
606
+
607
+ capability.resolve();
714
608
  }
715
- }, {
716
- key: "abort",
717
- value: function abort() {
718
- this.aborted = true;
719
609
 
720
- if (this.pdfNetworkStream) {
721
- this.pdfNetworkStream.cancelAllRequests('abort');
722
- }
610
+ this.msgHandler.send("DocProgress", {
611
+ loaded: this.stream.numChunksLoaded * this.chunkSize,
612
+ total: this.length
613
+ });
614
+ }
723
615
 
724
- for (var requestId in this.promisesByRequest) {
725
- this.promisesByRequest[requestId].reject(new Error('Request was aborted'));
726
- }
616
+ onError(err) {
617
+ this._loadedStreamCapability.reject(err);
618
+ }
619
+
620
+ getBeginChunk(begin) {
621
+ return Math.floor(begin / this.chunkSize);
622
+ }
623
+
624
+ getEndChunk(end) {
625
+ return Math.floor((end - 1) / this.chunkSize) + 1;
626
+ }
627
+
628
+ abort(reason) {
629
+ this.aborted = true;
630
+
631
+ if (this.pdfNetworkStream) {
632
+ this.pdfNetworkStream.cancelAllRequests(reason);
727
633
  }
728
- }]);
729
634
 
730
- return ChunkedStreamManager;
731
- }();
635
+ for (const capability of this._promisesByRequest.values()) {
636
+ capability.reject(reason);
637
+ }
638
+ }
639
+
640
+ }
732
641
 
733
642
  exports.ChunkedStreamManager = ChunkedStreamManager;