pdfjs-dist 2.3.200 → 2.4.456

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

Potentially problematic release.


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

Files changed (185) hide show
  1. package/README.md +4 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +6499 -17971
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +22 -1
  6. package/build/pdf.worker.entry.js +5 -3
  7. package/build/pdf.worker.js +19303 -29896
  8. package/build/pdf.worker.js.map +1 -1
  9. package/build/pdf.worker.min.js +22 -1
  10. package/es5/build/pdf.js +25473 -0
  11. package/es5/build/pdf.js.map +1 -0
  12. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  13. package/es5/build/pdf.worker.js +57878 -0
  14. package/es5/build/pdf.worker.js.map +1 -0
  15. package/es5/web/images/annotation-check.svg +11 -0
  16. package/es5/web/images/annotation-comment.svg +16 -0
  17. package/es5/web/images/annotation-help.svg +26 -0
  18. package/es5/web/images/annotation-insert.svg +10 -0
  19. package/es5/web/images/annotation-key.svg +11 -0
  20. package/es5/web/images/annotation-newparagraph.svg +11 -0
  21. package/es5/web/images/annotation-noicon.svg +7 -0
  22. package/es5/web/images/annotation-note.svg +42 -0
  23. package/es5/web/images/annotation-paragraph.svg +16 -0
  24. package/es5/web/images/loading-icon.gif +0 -0
  25. package/es5/web/images/shadow.png +0 -0
  26. package/es5/web/images/texture.png +0 -0
  27. package/es5/web/pdf_viewer.css +407 -0
  28. package/es5/web/pdf_viewer.js +7757 -0
  29. package/es5/web/pdf_viewer.js.map +1 -0
  30. package/image_decoders/pdf.image_decoders.js +1333 -4839
  31. package/image_decoders/pdf.image_decoders.js.map +1 -1
  32. package/image_decoders/pdf.image_decoders.min.js +22 -1
  33. package/lib/README.md +7 -0
  34. package/lib/core/annotation.js +683 -1066
  35. package/lib/core/arithmetic_decoder.js +81 -97
  36. package/lib/core/bidi.js +54 -46
  37. package/lib/core/ccitt.js +88 -81
  38. package/lib/core/ccitt_stream.js +15 -14
  39. package/lib/core/cff_parser.js +196 -193
  40. package/lib/core/charsets.js +4 -4
  41. package/lib/core/chunked_stream.js +441 -569
  42. package/lib/core/cmap.js +220 -279
  43. package/lib/core/colorspace.js +699 -863
  44. package/lib/core/core_utils.js +59 -80
  45. package/lib/core/crypto.js +379 -437
  46. package/lib/core/document.js +564 -673
  47. package/lib/core/encodings.js +15 -15
  48. package/lib/core/evaluator.js +983 -889
  49. package/lib/core/font_renderer.js +128 -171
  50. package/lib/core/fonts.js +451 -400
  51. package/lib/core/function.js +289 -285
  52. package/lib/core/glyphlist.js +4527 -4527
  53. package/lib/core/image.js +138 -117
  54. package/lib/core/image_utils.js +46 -63
  55. package/lib/core/jbig2.js +324 -332
  56. package/lib/core/jbig2_stream.js +18 -17
  57. package/lib/core/jpeg_stream.js +133 -24
  58. package/lib/core/jpg.js +238 -210
  59. package/lib/core/jpx.js +158 -157
  60. package/lib/core/jpx_stream.js +28 -28
  61. package/lib/core/metrics.js +2928 -2928
  62. package/lib/core/murmurhash3.js +87 -102
  63. package/lib/core/obj.js +1111 -1302
  64. package/lib/core/operator_list.js +55 -42
  65. package/lib/core/parser.js +956 -987
  66. package/lib/core/pattern.js +69 -69
  67. package/lib/core/pdf_manager.js +149 -316
  68. package/lib/core/primitives.js +45 -77
  69. package/lib/core/ps_parser.js +175 -214
  70. package/lib/core/standard_fonts.js +237 -236
  71. package/lib/core/stream.js +83 -77
  72. package/lib/core/type1_parser.js +78 -68
  73. package/lib/core/unicode.js +1654 -1654
  74. package/lib/core/worker.js +148 -196
  75. package/lib/core/worker_stream.js +101 -210
  76. package/lib/display/annotation_layer.js +733 -1155
  77. package/lib/display/api.js +1539 -1928
  78. package/lib/display/api_compatibility.js +10 -8
  79. package/lib/display/canvas.js +159 -158
  80. package/lib/display/content_disposition.js +36 -55
  81. package/lib/display/display_utils.js +298 -551
  82. package/lib/display/fetch_stream.js +181 -305
  83. package/lib/display/font_loader.js +273 -416
  84. package/lib/display/metadata.js +86 -98
  85. package/lib/display/network.js +376 -511
  86. package/lib/display/network_utils.js +20 -19
  87. package/lib/display/node_stream.js +276 -460
  88. package/lib/display/pattern_helper.js +76 -44
  89. package/lib/display/svg.js +1137 -1405
  90. package/lib/display/text_layer.js +75 -82
  91. package/lib/display/transport_stream.js +236 -374
  92. package/lib/display/webgl.js +70 -83
  93. package/lib/display/worker_options.js +3 -3
  94. package/lib/display/xml_parser.js +303 -392
  95. package/lib/examples/node/domstubs.js +37 -37
  96. package/lib/pdf.js +22 -21
  97. package/lib/pdf.worker.js +5 -5
  98. package/lib/shared/compatibility.js +2 -251
  99. package/lib/shared/is_node.js +7 -6
  100. package/lib/shared/message_handler.js +222 -194
  101. package/lib/shared/util.js +269 -405
  102. package/lib/test/unit/annotation_spec.js +1089 -1014
  103. package/lib/test/unit/api_spec.js +617 -544
  104. package/lib/test/unit/bidi_spec.js +7 -7
  105. package/lib/test/unit/cff_parser_spec.js +63 -62
  106. package/lib/test/unit/clitests_helper.js +7 -9
  107. package/lib/test/unit/cmap_spec.js +84 -86
  108. package/lib/test/unit/colorspace_spec.js +154 -154
  109. package/lib/test/unit/core_utils_spec.js +125 -105
  110. package/lib/test/unit/crypto_spec.js +181 -181
  111. package/lib/test/unit/custom_spec.js +22 -24
  112. package/lib/test/unit/display_svg_spec.js +35 -36
  113. package/lib/test/unit/display_utils_spec.js +139 -149
  114. package/lib/test/unit/document_spec.js +16 -16
  115. package/lib/test/unit/encodings_spec.js +12 -34
  116. package/lib/test/unit/evaluator_spec.js +81 -95
  117. package/lib/test/unit/fetch_stream_spec.js +30 -30
  118. package/lib/test/unit/function_spec.js +206 -204
  119. package/lib/test/unit/jasmine-boot.js +48 -32
  120. package/lib/test/unit/message_handler_spec.js +172 -162
  121. package/lib/test/unit/metadata_spec.js +69 -69
  122. package/lib/test/unit/murmurhash3_spec.js +12 -12
  123. package/lib/test/unit/network_spec.js +12 -12
  124. package/lib/test/unit/network_utils_spec.js +152 -152
  125. package/lib/test/unit/node_stream_spec.js +74 -90
  126. package/lib/test/unit/parser_spec.js +107 -113
  127. package/lib/test/unit/pdf_find_controller_spec.js +55 -86
  128. package/lib/test/unit/pdf_find_utils_spec.js +32 -32
  129. package/lib/test/unit/pdf_history_spec.js +32 -32
  130. package/lib/test/unit/primitives_spec.js +117 -115
  131. package/lib/test/unit/stream_spec.js +16 -14
  132. package/lib/test/unit/test_utils.js +119 -285
  133. package/lib/test/unit/testreporter.js +19 -19
  134. package/lib/test/unit/type1_parser_spec.js +41 -41
  135. package/lib/test/unit/ui_utils_spec.js +318 -426
  136. package/lib/test/unit/unicode_spec.js +42 -42
  137. package/lib/test/unit/util_spec.js +122 -143
  138. package/lib/web/annotation_layer_builder.js +66 -103
  139. package/lib/web/app.js +1166 -1196
  140. package/lib/web/app_options.js +61 -77
  141. package/lib/web/base_viewer.js +804 -850
  142. package/lib/web/chromecom.js +164 -249
  143. package/lib/web/debugger.js +149 -205
  144. package/lib/web/download_manager.js +38 -57
  145. package/lib/web/firefox_print_service.js +35 -30
  146. package/lib/web/firefoxcom.js +175 -374
  147. package/lib/web/genericcom.js +26 -108
  148. package/lib/web/genericl10n.js +24 -153
  149. package/lib/web/grab_to_pan.js +30 -30
  150. package/lib/web/interfaces.js +80 -258
  151. package/lib/web/overlay_manager.js +70 -246
  152. package/lib/web/password_prompt.js +38 -64
  153. package/lib/web/pdf_attachment_viewer.js +105 -130
  154. package/lib/web/pdf_cursor_tools.js +75 -102
  155. package/lib/web/pdf_document_properties.js +227 -376
  156. package/lib/web/pdf_find_bar.js +137 -171
  157. package/lib/web/pdf_find_controller.js +492 -549
  158. package/lib/web/pdf_find_utils.js +13 -13
  159. package/lib/web/pdf_history.js +395 -406
  160. package/lib/web/pdf_link_service.js +302 -349
  161. package/lib/web/pdf_outline_viewer.js +148 -209
  162. package/lib/web/pdf_page_view.js +449 -507
  163. package/lib/web/pdf_presentation_mode.js +304 -357
  164. package/lib/web/pdf_print_service.js +90 -104
  165. package/lib/web/pdf_rendering_queue.js +87 -108
  166. package/lib/web/pdf_sidebar.js +264 -304
  167. package/lib/web/pdf_sidebar_resizer.js +92 -119
  168. package/lib/web/pdf_single_page_viewer.js +77 -126
  169. package/lib/web/pdf_thumbnail_view.js +276 -297
  170. package/lib/web/pdf_thumbnail_viewer.js +186 -206
  171. package/lib/web/pdf_viewer.component.js +20 -21
  172. package/lib/web/pdf_viewer.js +55 -115
  173. package/lib/web/preferences.js +66 -273
  174. package/lib/web/secondary_toolbar.js +164 -196
  175. package/lib/web/text_layer_builder.js +284 -317
  176. package/lib/web/toolbar.js +216 -211
  177. package/lib/web/ui_utils.js +303 -404
  178. package/lib/web/view_history.js +49 -222
  179. package/lib/web/viewer_compatibility.js +7 -5
  180. package/package.json +2 -9
  181. package/web/pdf_viewer.css +25 -18
  182. package/web/pdf_viewer.js +3481 -4764
  183. package/web/pdf_viewer.js.map +1 -1
  184. package/webpack.js +14 -5
  185. package/lib/shared/streams_polyfill.js +0 -43
@@ -2,7 +2,7 @@
2
2
  * @licstart The following is the entire license notice for the
3
3
  * Javascript code in this page
4
4
  *
5
- * Copyright 2019 Mozilla Foundation
5
+ * Copyright 2020 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -26,22 +26,12 @@ 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;
@@ -55,312 +45,292 @@ function () {
55
45
  this.lastSuccessfulEnsureByteChunk = -1;
56
46
  }
57
47
 
58
- _createClass(ChunkedStream, [{
59
- key: "getMissingChunks",
60
- value: function getMissingChunks() {
61
- var chunks = [];
48
+ getMissingChunks() {
49
+ const chunks = [];
62
50
 
63
- for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
64
- if (!this.loadedChunks[chunk]) {
65
- chunks.push(chunk);
66
- }
51
+ for (let chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
52
+ if (!this.loadedChunks[chunk]) {
53
+ chunks.push(chunk);
67
54
  }
68
-
69
- return chunks;
70
55
  }
71
- }, {
72
- key: "getBaseStreams",
73
- value: function getBaseStreams() {
74
- return [this];
56
+
57
+ return chunks;
58
+ }
59
+
60
+ getBaseStreams() {
61
+ return [this];
62
+ }
63
+
64
+ allChunksLoaded() {
65
+ return this.numChunksLoaded === this.numChunks;
66
+ }
67
+
68
+ onReceiveData(begin, chunk) {
69
+ const chunkSize = this.chunkSize;
70
+
71
+ if (begin % chunkSize !== 0) {
72
+ throw new Error(`Bad begin offset: ${begin}`);
75
73
  }
76
- }, {
77
- key: "allChunksLoaded",
78
- value: function allChunksLoaded() {
79
- return this.numChunksLoaded === this.numChunks;
74
+
75
+ const end = begin + chunk.byteLength;
76
+
77
+ if (end % chunkSize !== 0 && end !== this.bytes.length) {
78
+ throw new Error(`Bad end offset: ${end}`);
80
79
  }
81
- }, {
82
- key: "onReceiveData",
83
- value: function onReceiveData(begin, chunk) {
84
- var chunkSize = this.chunkSize;
85
80
 
86
- if (begin % chunkSize !== 0) {
87
- throw new Error("Bad begin offset: ".concat(begin));
81
+ this.bytes.set(new Uint8Array(chunk), begin);
82
+ const beginChunk = Math.floor(begin / chunkSize);
83
+ const endChunk = Math.floor((end - 1) / chunkSize) + 1;
84
+
85
+ for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
86
+ if (!this.loadedChunks[curChunk]) {
87
+ this.loadedChunks[curChunk] = true;
88
+ ++this.numChunksLoaded;
88
89
  }
90
+ }
91
+ }
89
92
 
90
- var end = begin + chunk.byteLength;
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);
91
100
 
92
- if (end % chunkSize !== 0 && end !== this.bytes.length) {
93
- throw new Error("Bad end offset: ".concat(end));
101
+ for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
102
+ if (!this.loadedChunks[curChunk]) {
103
+ this.loadedChunks[curChunk] = true;
104
+ ++this.numChunksLoaded;
94
105
  }
106
+ }
107
+ }
95
108
 
96
- this.bytes.set(new Uint8Array(chunk), begin);
97
- var beginChunk = Math.floor(begin / chunkSize);
98
- var endChunk = Math.floor((end - 1) / chunkSize) + 1;
109
+ ensureByte(pos) {
110
+ if (pos < this.progressiveDataLength) {
111
+ return;
112
+ }
99
113
 
100
- for (var curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
101
- if (!this.loadedChunks[curChunk]) {
102
- this.loadedChunks[curChunk] = true;
103
- ++this.numChunksLoaded;
104
- }
105
- }
114
+ const chunk = Math.floor(pos / this.chunkSize);
115
+
116
+ if (chunk === this.lastSuccessfulEnsureByteChunk) {
117
+ return;
106
118
  }
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
- }
119
+
120
+ if (!this.loadedChunks[chunk]) {
121
+ throw new _core_utils.MissingDataException(pos, pos + 1);
123
122
  }
124
- }, {
125
- key: "ensureByte",
126
- value: function ensureByte(pos) {
127
- if (pos < this.progressiveDataLength) {
128
- return;
129
- }
130
123
 
131
- var chunk = Math.floor(pos / this.chunkSize);
124
+ this.lastSuccessfulEnsureByteChunk = chunk;
125
+ }
132
126
 
133
- if (chunk === this.lastSuccessfulEnsureByteChunk) {
134
- return;
135
- }
127
+ ensureRange(begin, end) {
128
+ if (begin >= end) {
129
+ return;
130
+ }
131
+
132
+ if (end <= this.progressiveDataLength) {
133
+ return;
134
+ }
136
135
 
136
+ const chunkSize = this.chunkSize;
137
+ const beginChunk = Math.floor(begin / chunkSize);
138
+ const endChunk = Math.floor((end - 1) / chunkSize) + 1;
139
+
140
+ for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
137
141
  if (!this.loadedChunks[chunk]) {
138
- throw new _core_utils.MissingDataException(pos, pos + 1);
142
+ throw new _core_utils.MissingDataException(begin, end);
139
143
  }
140
-
141
- this.lastSuccessfulEnsureByteChunk = chunk;
142
144
  }
143
- }, {
144
- key: "ensureRange",
145
- value: function ensureRange(begin, end) {
146
- if (begin >= end) {
147
- return;
148
- }
145
+ }
149
146
 
150
- if (end <= this.progressiveDataLength) {
151
- return;
152
- }
147
+ nextEmptyChunk(beginChunk) {
148
+ const numChunks = this.numChunks;
153
149
 
154
- var chunkSize = this.chunkSize;
155
- var beginChunk = Math.floor(begin / chunkSize);
156
- var endChunk = Math.floor((end - 1) / chunkSize) + 1;
150
+ for (let i = 0; i < numChunks; ++i) {
151
+ const chunk = (beginChunk + i) % numChunks;
157
152
 
158
- for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
159
- if (!this.loadedChunks[chunk]) {
160
- throw new _core_utils.MissingDataException(begin, end);
161
- }
153
+ if (!this.loadedChunks[chunk]) {
154
+ return chunk;
162
155
  }
163
156
  }
164
- }, {
165
- key: "nextEmptyChunk",
166
- value: function nextEmptyChunk(beginChunk) {
167
- var numChunks = this.numChunks;
168
157
 
169
- for (var i = 0; i < numChunks; ++i) {
170
- var chunk = (beginChunk + i) % numChunks;
158
+ return null;
159
+ }
171
160
 
172
- if (!this.loadedChunks[chunk]) {
173
- return chunk;
174
- }
175
- }
161
+ hasChunk(chunk) {
162
+ return !!this.loadedChunks[chunk];
163
+ }
164
+
165
+ get length() {
166
+ return this.end - this.start;
167
+ }
168
+
169
+ get isEmpty() {
170
+ return this.length === 0;
171
+ }
172
+
173
+ getByte() {
174
+ const pos = this.pos;
176
175
 
177
- return null;
176
+ if (pos >= this.end) {
177
+ return -1;
178
178
  }
179
- }, {
180
- key: "hasChunk",
181
- value: function hasChunk(chunk) {
182
- return !!this.loadedChunks[chunk];
179
+
180
+ if (pos >= this.progressiveDataLength) {
181
+ this.ensureByte(pos);
183
182
  }
184
- }, {
185
- key: "getByte",
186
- value: function getByte() {
187
- var pos = this.pos;
188
183
 
189
- if (pos >= this.end) {
190
- return -1;
191
- }
184
+ return this.bytes[this.pos++];
185
+ }
192
186
 
193
- if (pos >= this.progressiveDataLength) {
194
- this.ensureByte(pos);
195
- }
187
+ getUint16() {
188
+ const b0 = this.getByte();
189
+ const b1 = this.getByte();
196
190
 
197
- return this.bytes[this.pos++];
191
+ if (b0 === -1 || b1 === -1) {
192
+ return -1;
198
193
  }
199
- }, {
200
- key: "getUint16",
201
- value: function getUint16() {
202
- var b0 = this.getByte();
203
- var b1 = this.getByte();
204
194
 
205
- if (b0 === -1 || b1 === -1) {
206
- return -1;
207
- }
195
+ return (b0 << 8) + b1;
196
+ }
208
197
 
209
- return (b0 << 8) + b1;
210
- }
211
- }, {
212
- key: "getInt32",
213
- value: function getInt32() {
214
- var b0 = this.getByte();
215
- var b1 = this.getByte();
216
- var b2 = this.getByte();
217
- var b3 = this.getByte();
218
- return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
219
- }
220
- }, {
221
- key: "getBytes",
222
- value: function getBytes(length) {
223
- var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
224
- var bytes = this.bytes;
225
- var pos = this.pos;
226
- var strEnd = this.end;
227
-
228
- if (!length) {
229
- if (strEnd > this.progressiveDataLength) {
230
- this.ensureRange(pos, strEnd);
231
- }
198
+ getInt32() {
199
+ const b0 = this.getByte();
200
+ const b1 = this.getByte();
201
+ const b2 = this.getByte();
202
+ const b3 = this.getByte();
203
+ return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
204
+ }
232
205
 
233
- var _subarray = bytes.subarray(pos, strEnd);
206
+ getBytes(length, forceClamped = false) {
207
+ const bytes = this.bytes;
208
+ const pos = this.pos;
209
+ const strEnd = this.end;
234
210
 
235
- return forceClamped ? new Uint8ClampedArray(_subarray) : _subarray;
211
+ if (!length) {
212
+ if (strEnd > this.progressiveDataLength) {
213
+ this.ensureRange(pos, strEnd);
236
214
  }
237
215
 
238
- var end = pos + length;
216
+ const subarray = bytes.subarray(pos, strEnd);
217
+ return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
218
+ }
239
219
 
240
- if (end > strEnd) {
241
- end = strEnd;
242
- }
220
+ let end = pos + length;
243
221
 
244
- if (end > this.progressiveDataLength) {
245
- this.ensureRange(pos, end);
246
- }
222
+ if (end > strEnd) {
223
+ end = strEnd;
224
+ }
247
225
 
248
- this.pos = end;
249
- var subarray = bytes.subarray(pos, end);
250
- return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
226
+ if (end > this.progressiveDataLength) {
227
+ this.ensureRange(pos, end);
251
228
  }
252
- }, {
253
- key: "peekByte",
254
- value: function peekByte() {
255
- var peekedByte = this.getByte();
229
+
230
+ this.pos = end;
231
+ const subarray = bytes.subarray(pos, end);
232
+ return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
233
+ }
234
+
235
+ peekByte() {
236
+ const peekedByte = this.getByte();
237
+
238
+ if (peekedByte !== -1) {
256
239
  this.pos--;
257
- return peekedByte;
258
- }
259
- }, {
260
- key: "peekBytes",
261
- value: function peekBytes(length) {
262
- var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
263
- var bytes = this.getBytes(length, forceClamped);
264
- this.pos -= bytes.length;
265
- return bytes;
266
- }
267
- }, {
268
- key: "getByteRange",
269
- value: function getByteRange(begin, end) {
270
- if (begin < 0) {
271
- begin = 0;
272
- }
240
+ }
273
241
 
274
- if (end > this.end) {
275
- end = this.end;
276
- }
242
+ return peekedByte;
243
+ }
277
244
 
278
- if (end > this.progressiveDataLength) {
279
- this.ensureRange(begin, end);
280
- }
245
+ peekBytes(length, forceClamped = false) {
246
+ const bytes = this.getBytes(length, forceClamped);
247
+ this.pos -= bytes.length;
248
+ return bytes;
249
+ }
281
250
 
282
- return this.bytes.subarray(begin, end);
251
+ getByteRange(begin, end) {
252
+ if (begin < 0) {
253
+ begin = 0;
283
254
  }
284
- }, {
285
- key: "skip",
286
- value: function skip(n) {
287
- if (!n) {
288
- n = 1;
289
- }
290
255
 
291
- this.pos += n;
256
+ if (end > this.end) {
257
+ end = this.end;
292
258
  }
293
- }, {
294
- key: "reset",
295
- value: function reset() {
296
- this.pos = this.start;
259
+
260
+ if (end > this.progressiveDataLength) {
261
+ this.ensureRange(begin, end);
297
262
  }
298
- }, {
299
- key: "moveStart",
300
- value: function moveStart() {
301
- this.start = this.pos;
263
+
264
+ return this.bytes.subarray(begin, end);
265
+ }
266
+
267
+ skip(n) {
268
+ if (!n) {
269
+ n = 1;
302
270
  }
303
- }, {
304
- key: "makeSubStream",
305
- value: function makeSubStream(start, length, dict) {
306
- if (length) {
307
- if (start + length > this.progressiveDataLength) {
308
- this.ensureRange(start, start + length);
309
- }
310
- } else {
311
- if (start >= this.progressiveDataLength) {
312
- this.ensureByte(start);
313
- }
271
+
272
+ this.pos += n;
273
+ }
274
+
275
+ reset() {
276
+ this.pos = this.start;
277
+ }
278
+
279
+ moveStart() {
280
+ this.start = this.pos;
281
+ }
282
+
283
+ makeSubStream(start, length, dict) {
284
+ if (length) {
285
+ if (start + length > this.progressiveDataLength) {
286
+ this.ensureRange(start, start + length);
287
+ }
288
+ } else {
289
+ if (start >= this.progressiveDataLength) {
290
+ this.ensureByte(start);
314
291
  }
292
+ }
315
293
 
316
- function ChunkedStreamSubstream() {}
294
+ function ChunkedStreamSubstream() {}
317
295
 
318
- ChunkedStreamSubstream.prototype = Object.create(this);
296
+ ChunkedStreamSubstream.prototype = Object.create(this);
319
297
 
320
- ChunkedStreamSubstream.prototype.getMissingChunks = function () {
321
- var chunkSize = this.chunkSize;
322
- var beginChunk = Math.floor(this.start / chunkSize);
323
- var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
324
- var missingChunks = [];
298
+ ChunkedStreamSubstream.prototype.getMissingChunks = function () {
299
+ const chunkSize = this.chunkSize;
300
+ const beginChunk = Math.floor(this.start / chunkSize);
301
+ const endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
302
+ const missingChunks = [];
325
303
 
326
- for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
327
- if (!this.loadedChunks[chunk]) {
328
- missingChunks.push(chunk);
329
- }
304
+ for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
305
+ if (!this.loadedChunks[chunk]) {
306
+ missingChunks.push(chunk);
330
307
  }
308
+ }
331
309
 
332
- return missingChunks;
333
- };
310
+ return missingChunks;
311
+ };
334
312
 
335
- var subStream = new ChunkedStreamSubstream();
336
- subStream.pos = subStream.start = start;
337
- subStream.end = start + length || this.end;
338
- subStream.dict = dict;
339
- return subStream;
340
- }
341
- }, {
342
- key: "length",
343
- get: function get() {
344
- return this.end - this.start;
345
- }
346
- }, {
347
- key: "isEmpty",
348
- get: function get() {
349
- return this.length === 0;
350
- }
351
- }]);
313
+ ChunkedStreamSubstream.prototype.allChunksLoaded = function () {
314
+ if (this.numChunksLoaded === this.numChunks) {
315
+ return true;
316
+ }
352
317
 
353
- return ChunkedStream;
354
- }();
318
+ return this.getMissingChunks().length === 0;
319
+ };
355
320
 
356
- exports.ChunkedStream = ChunkedStream;
321
+ const subStream = new ChunkedStreamSubstream();
322
+ subStream.pos = subStream.start = start;
323
+ subStream.end = start + length || this.end;
324
+ subStream.dict = dict;
325
+ return subStream;
326
+ }
357
327
 
358
- var ChunkedStreamManager =
359
- /*#__PURE__*/
360
- function () {
361
- function ChunkedStreamManager(pdfNetworkStream, args) {
362
- _classCallCheck(this, ChunkedStreamManager);
328
+ }
363
329
 
330
+ exports.ChunkedStream = ChunkedStream;
331
+
332
+ class ChunkedStreamManager {
333
+ constructor(pdfNetworkStream, args) {
364
334
  this.length = args.length;
365
335
  this.chunkSize = args.rangeChunkSize;
366
336
  this.stream = new ChunkedStream(this.length, this.chunkSize, this);
@@ -376,381 +346,283 @@ function () {
376
346
  this._loadedStreamCapability = (0, _util.createPromiseCapability)();
377
347
  }
378
348
 
379
- _createClass(ChunkedStreamManager, [{
380
- key: "onLoadedStream",
381
- value: function onLoadedStream() {
382
- return this._loadedStreamCapability.promise;
383
- }
384
- }, {
385
- key: "sendRequest",
386
- value: function sendRequest(begin, end) {
387
- var _this = this;
349
+ onLoadedStream() {
350
+ return this._loadedStreamCapability.promise;
351
+ }
388
352
 
389
- var rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
353
+ sendRequest(begin, end) {
354
+ const rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
390
355
 
391
- if (!rangeReader.isStreamingSupported) {
392
- rangeReader.onProgress = this.onProgress.bind(this);
393
- }
356
+ if (!rangeReader.isStreamingSupported) {
357
+ rangeReader.onProgress = this.onProgress.bind(this);
358
+ }
394
359
 
395
- var chunks = [],
396
- loaded = 0;
397
- var promise = new Promise(function (resolve, reject) {
398
- var readChunk = function readChunk(chunk) {
399
- try {
400
- if (!chunk.done) {
401
- var data = chunk.value;
402
- chunks.push(data);
403
- loaded += (0, _util.arrayByteLength)(data);
404
-
405
- if (rangeReader.isStreamingSupported) {
406
- _this.onProgress({
407
- loaded: loaded
408
- });
409
- }
410
-
411
- rangeReader.read().then(readChunk, reject);
412
- return;
360
+ let chunks = [],
361
+ loaded = 0;
362
+ const promise = new Promise((resolve, reject) => {
363
+ const readChunk = chunk => {
364
+ try {
365
+ if (!chunk.done) {
366
+ const data = chunk.value;
367
+ chunks.push(data);
368
+ loaded += (0, _util.arrayByteLength)(data);
369
+
370
+ if (rangeReader.isStreamingSupported) {
371
+ this.onProgress({
372
+ loaded
373
+ });
413
374
  }
414
375
 
415
- var chunkData = (0, _util.arraysToBytes)(chunks);
416
- chunks = null;
417
- resolve(chunkData);
418
- } catch (e) {
419
- reject(e);
376
+ rangeReader.read().then(readChunk, reject);
377
+ return;
420
378
  }
421
- };
422
379
 
423
- rangeReader.read().then(readChunk, reject);
424
- });
425
- promise.then(function (data) {
426
- if (_this.aborted) {
427
- return;
380
+ const chunkData = (0, _util.arraysToBytes)(chunks);
381
+ chunks = null;
382
+ resolve(chunkData);
383
+ } catch (e) {
384
+ reject(e);
428
385
  }
386
+ };
429
387
 
430
- _this.onReceiveData({
431
- chunk: data,
432
- begin: begin
433
- });
388
+ rangeReader.read().then(readChunk, reject);
389
+ });
390
+ promise.then(data => {
391
+ if (this.aborted) {
392
+ return;
393
+ }
394
+
395
+ this.onReceiveData({
396
+ chunk: data,
397
+ begin
434
398
  });
435
- }
436
- }, {
437
- key: "requestAllChunks",
438
- value: function requestAllChunks() {
439
- var missingChunks = this.stream.getMissingChunks();
399
+ });
400
+ }
440
401
 
441
- this._requestChunks(missingChunks);
402
+ requestAllChunks() {
403
+ const missingChunks = this.stream.getMissingChunks();
442
404
 
443
- return this._loadedStreamCapability.promise;
444
- }
445
- }, {
446
- key: "_requestChunks",
447
- value: function _requestChunks(chunks) {
448
- var requestId = this.currRequestId++;
449
- var chunksNeeded = Object.create(null);
450
- this.chunksNeededByRequest[requestId] = chunksNeeded;
451
- var _iteratorNormalCompletion = true;
452
- var _didIteratorError = false;
453
- var _iteratorError = undefined;
405
+ this._requestChunks(missingChunks);
454
406
 
455
- try {
456
- for (var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
457
- var _chunk = _step.value;
407
+ return this._loadedStreamCapability.promise;
408
+ }
458
409
 
459
- if (!this.stream.hasChunk(_chunk)) {
460
- chunksNeeded[_chunk] = true;
461
- }
462
- }
463
- } catch (err) {
464
- _didIteratorError = true;
465
- _iteratorError = err;
466
- } finally {
467
- try {
468
- if (!_iteratorNormalCompletion && _iterator["return"] != null) {
469
- _iterator["return"]();
470
- }
471
- } finally {
472
- if (_didIteratorError) {
473
- throw _iteratorError;
474
- }
475
- }
476
- }
410
+ _requestChunks(chunks) {
411
+ const requestId = this.currRequestId++;
412
+ const chunksNeeded = Object.create(null);
413
+ this.chunksNeededByRequest[requestId] = chunksNeeded;
477
414
 
478
- if ((0, _util.isEmptyObj)(chunksNeeded)) {
479
- return Promise.resolve();
415
+ for (const chunk of chunks) {
416
+ if (!this.stream.hasChunk(chunk)) {
417
+ chunksNeeded[chunk] = true;
480
418
  }
419
+ }
481
420
 
482
- var capability = (0, _util.createPromiseCapability)();
483
- this.promisesByRequest[requestId] = capability;
484
- var chunksToRequest = [];
421
+ if ((0, _util.isEmptyObj)(chunksNeeded)) {
422
+ return Promise.resolve();
423
+ }
485
424
 
486
- for (var chunk in chunksNeeded) {
487
- chunk = chunk | 0;
425
+ const capability = (0, _util.createPromiseCapability)();
426
+ this.promisesByRequest[requestId] = capability;
427
+ const chunksToRequest = [];
488
428
 
489
- if (!(chunk in this.requestsByChunk)) {
490
- this.requestsByChunk[chunk] = [];
491
- chunksToRequest.push(chunk);
492
- }
429
+ for (let chunk in chunksNeeded) {
430
+ chunk = chunk | 0;
493
431
 
494
- this.requestsByChunk[chunk].push(requestId);
432
+ if (!(chunk in this.requestsByChunk)) {
433
+ this.requestsByChunk[chunk] = [];
434
+ chunksToRequest.push(chunk);
495
435
  }
496
436
 
497
- if (!chunksToRequest.length) {
498
- return capability.promise;
499
- }
500
-
501
- var groupedChunksToRequest = this.groupChunks(chunksToRequest);
502
- var _iteratorNormalCompletion2 = true;
503
- var _didIteratorError2 = false;
504
- var _iteratorError2 = undefined;
505
-
506
- try {
507
- for (var _iterator2 = groupedChunksToRequest[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
508
- var groupedChunk = _step2.value;
509
- var begin = groupedChunk.beginChunk * this.chunkSize;
510
- var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
511
- this.sendRequest(begin, end);
512
- }
513
- } catch (err) {
514
- _didIteratorError2 = true;
515
- _iteratorError2 = err;
516
- } finally {
517
- try {
518
- if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
519
- _iterator2["return"]();
520
- }
521
- } finally {
522
- if (_didIteratorError2) {
523
- throw _iteratorError2;
524
- }
525
- }
526
- }
437
+ this.requestsByChunk[chunk].push(requestId);
438
+ }
527
439
 
440
+ if (!chunksToRequest.length) {
528
441
  return capability.promise;
529
442
  }
530
- }, {
531
- key: "getStream",
532
- value: function getStream() {
533
- return this.stream;
443
+
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);
534
450
  }
535
- }, {
536
- key: "requestRange",
537
- value: function requestRange(begin, end) {
538
- end = Math.min(end, this.length);
539
- var beginChunk = this.getBeginChunk(begin);
540
- var endChunk = this.getEndChunk(end);
541
- var chunks = [];
542
451
 
543
- for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
544
- chunks.push(chunk);
545
- }
452
+ return capability.promise;
453
+ }
546
454
 
547
- return this._requestChunks(chunks);
548
- }
549
- }, {
550
- key: "requestRanges",
551
- value: function requestRanges() {
552
- var ranges = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
553
- var chunksToRequest = [];
554
- var _iteratorNormalCompletion3 = true;
555
- var _didIteratorError3 = false;
556
- var _iteratorError3 = undefined;
557
-
558
- try {
559
- for (var _iterator3 = ranges[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
560
- var range = _step3.value;
561
- var beginChunk = this.getBeginChunk(range.begin);
562
- var endChunk = this.getEndChunk(range.end);
563
-
564
- for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
565
- if (!chunksToRequest.includes(chunk)) {
566
- chunksToRequest.push(chunk);
567
- }
568
- }
569
- }
570
- } catch (err) {
571
- _didIteratorError3 = true;
572
- _iteratorError3 = err;
573
- } finally {
574
- try {
575
- if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) {
576
- _iterator3["return"]();
577
- }
578
- } finally {
579
- if (_didIteratorError3) {
580
- throw _iteratorError3;
581
- }
582
- }
583
- }
455
+ getStream() {
456
+ return this.stream;
457
+ }
584
458
 
585
- chunksToRequest.sort(function (a, b) {
586
- return a - b;
587
- });
588
- return this._requestChunks(chunksToRequest);
459
+ requestRange(begin, end) {
460
+ end = Math.min(end, this.length);
461
+ const beginChunk = this.getBeginChunk(begin);
462
+ const endChunk = this.getEndChunk(end);
463
+ const chunks = [];
464
+
465
+ for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
466
+ chunks.push(chunk);
589
467
  }
590
- }, {
591
- key: "groupChunks",
592
- value: function groupChunks(chunks) {
593
- var groupedChunks = [];
594
- var beginChunk = -1;
595
- var prevChunk = -1;
596
468
 
597
- for (var i = 0, ii = chunks.length; i < ii; ++i) {
598
- var chunk = chunks[i];
469
+ return this._requestChunks(chunks);
470
+ }
599
471
 
600
- if (beginChunk < 0) {
601
- beginChunk = chunk;
602
- }
472
+ requestRanges(ranges = []) {
473
+ const chunksToRequest = [];
603
474
 
604
- if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
605
- groupedChunks.push({
606
- beginChunk: beginChunk,
607
- endChunk: prevChunk + 1
608
- });
609
- beginChunk = chunk;
610
- }
475
+ for (const range of ranges) {
476
+ const beginChunk = this.getBeginChunk(range.begin);
477
+ const endChunk = this.getEndChunk(range.end);
611
478
 
612
- if (i + 1 === chunks.length) {
613
- groupedChunks.push({
614
- beginChunk: beginChunk,
615
- endChunk: chunk + 1
616
- });
479
+ for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
480
+ if (!chunksToRequest.includes(chunk)) {
481
+ chunksToRequest.push(chunk);
617
482
  }
483
+ }
484
+ }
485
+
486
+ chunksToRequest.sort(function (a, b) {
487
+ return a - b;
488
+ });
489
+ return this._requestChunks(chunksToRequest);
490
+ }
491
+
492
+ groupChunks(chunks) {
493
+ const groupedChunks = [];
494
+ let beginChunk = -1;
495
+ let prevChunk = -1;
618
496
 
619
- prevChunk = chunk;
497
+ for (let i = 0, ii = chunks.length; i < ii; ++i) {
498
+ const chunk = chunks[i];
499
+
500
+ if (beginChunk < 0) {
501
+ beginChunk = chunk;
620
502
  }
621
503
 
622
- return groupedChunks;
623
- }
624
- }, {
625
- key: "onProgress",
626
- value: function onProgress(args) {
627
- this.msgHandler.send('DocProgress', {
628
- loaded: this.stream.numChunksLoaded * this.chunkSize + args.loaded,
629
- total: this.length
630
- });
631
- }
632
- }, {
633
- key: "onReceiveData",
634
- value: function onReceiveData(args) {
635
- var chunk = args.chunk;
636
- var isProgressive = args.begin === undefined;
637
- var begin = isProgressive ? this.progressiveDataLength : args.begin;
638
- var end = begin + chunk.byteLength;
639
- var beginChunk = Math.floor(begin / this.chunkSize);
640
- var endChunk = end < this.length ? Math.floor(end / this.chunkSize) : Math.ceil(end / this.chunkSize);
641
-
642
- if (isProgressive) {
643
- this.stream.onReceiveProgressiveData(chunk);
644
- this.progressiveDataLength = end;
645
- } else {
646
- this.stream.onReceiveData(begin, chunk);
504
+ if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
505
+ groupedChunks.push({
506
+ beginChunk,
507
+ endChunk: prevChunk + 1
508
+ });
509
+ beginChunk = chunk;
647
510
  }
648
511
 
649
- if (this.stream.allChunksLoaded()) {
650
- this._loadedStreamCapability.resolve(this.stream);
512
+ if (i + 1 === chunks.length) {
513
+ groupedChunks.push({
514
+ beginChunk,
515
+ endChunk: chunk + 1
516
+ });
651
517
  }
652
518
 
653
- var loadedRequests = [];
519
+ prevChunk = chunk;
520
+ }
654
521
 
655
- for (var _chunk2 = beginChunk; _chunk2 < endChunk; ++_chunk2) {
656
- var requestIds = this.requestsByChunk[_chunk2] || [];
657
- delete this.requestsByChunk[_chunk2];
658
- var _iteratorNormalCompletion4 = true;
659
- var _didIteratorError4 = false;
660
- var _iteratorError4 = undefined;
522
+ return groupedChunks;
523
+ }
661
524
 
662
- try {
663
- for (var _iterator4 = requestIds[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
664
- var requestId = _step4.value;
665
- var chunksNeeded = this.chunksNeededByRequest[requestId];
525
+ onProgress(args) {
526
+ this.msgHandler.send("DocProgress", {
527
+ loaded: this.stream.numChunksLoaded * this.chunkSize + args.loaded,
528
+ total: this.length
529
+ });
530
+ }
666
531
 
667
- if (_chunk2 in chunksNeeded) {
668
- delete chunksNeeded[_chunk2];
669
- }
532
+ onReceiveData(args) {
533
+ const chunk = args.chunk;
534
+ const isProgressive = args.begin === undefined;
535
+ const begin = isProgressive ? this.progressiveDataLength : args.begin;
536
+ const end = begin + chunk.byteLength;
537
+ const beginChunk = Math.floor(begin / this.chunkSize);
538
+ const endChunk = end < this.length ? Math.floor(end / this.chunkSize) : Math.ceil(end / this.chunkSize);
670
539
 
671
- if (!(0, _util.isEmptyObj)(chunksNeeded)) {
672
- continue;
673
- }
540
+ if (isProgressive) {
541
+ this.stream.onReceiveProgressiveData(chunk);
542
+ this.progressiveDataLength = end;
543
+ } else {
544
+ this.stream.onReceiveData(begin, chunk);
545
+ }
674
546
 
675
- loadedRequests.push(requestId);
676
- }
677
- } catch (err) {
678
- _didIteratorError4 = true;
679
- _iteratorError4 = err;
680
- } finally {
681
- try {
682
- if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) {
683
- _iterator4["return"]();
684
- }
685
- } finally {
686
- if (_didIteratorError4) {
687
- throw _iteratorError4;
688
- }
689
- }
690
- }
691
- }
547
+ if (this.stream.allChunksLoaded()) {
548
+ this._loadedStreamCapability.resolve(this.stream);
549
+ }
692
550
 
693
- if (!this.disableAutoFetch && (0, _util.isEmptyObj)(this.requestsByChunk)) {
694
- var nextEmptyChunk;
551
+ const loadedRequests = [];
695
552
 
696
- if (this.stream.numChunksLoaded === 1) {
697
- var lastChunk = this.stream.numChunks - 1;
553
+ for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
554
+ const requestIds = this.requestsByChunk[chunk] || [];
555
+ delete this.requestsByChunk[chunk];
698
556
 
699
- if (!this.stream.hasChunk(lastChunk)) {
700
- nextEmptyChunk = lastChunk;
701
- }
702
- } else {
703
- nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
557
+ for (const requestId of requestIds) {
558
+ const chunksNeeded = this.chunksNeededByRequest[requestId];
559
+
560
+ if (chunk in chunksNeeded) {
561
+ delete chunksNeeded[chunk];
704
562
  }
705
563
 
706
- if (Number.isInteger(nextEmptyChunk)) {
707
- this._requestChunks([nextEmptyChunk]);
564
+ if (!(0, _util.isEmptyObj)(chunksNeeded)) {
565
+ continue;
708
566
  }
567
+
568
+ loadedRequests.push(requestId);
709
569
  }
570
+ }
571
+
572
+ if (!this.disableAutoFetch && (0, _util.isEmptyObj)(this.requestsByChunk)) {
573
+ let nextEmptyChunk;
574
+
575
+ if (this.stream.numChunksLoaded === 1) {
576
+ const lastChunk = this.stream.numChunks - 1;
710
577
 
711
- for (var _i = 0, _loadedRequests = loadedRequests; _i < _loadedRequests.length; _i++) {
712
- var _requestId = _loadedRequests[_i];
713
- var capability = this.promisesByRequest[_requestId];
714
- delete this.promisesByRequest[_requestId];
715
- capability.resolve();
578
+ if (!this.stream.hasChunk(lastChunk)) {
579
+ nextEmptyChunk = lastChunk;
580
+ }
581
+ } else {
582
+ nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
716
583
  }
717
584
 
718
- this.msgHandler.send('DocProgress', {
719
- loaded: this.stream.numChunksLoaded * this.chunkSize,
720
- total: this.length
721
- });
722
- }
723
- }, {
724
- key: "onError",
725
- value: function onError(err) {
726
- this._loadedStreamCapability.reject(err);
727
- }
728
- }, {
729
- key: "getBeginChunk",
730
- value: function getBeginChunk(begin) {
731
- return Math.floor(begin / this.chunkSize);
585
+ if (Number.isInteger(nextEmptyChunk)) {
586
+ this._requestChunks([nextEmptyChunk]);
587
+ }
732
588
  }
733
- }, {
734
- key: "getEndChunk",
735
- value: function getEndChunk(end) {
736
- return Math.floor((end - 1) / this.chunkSize) + 1;
589
+
590
+ for (const requestId of loadedRequests) {
591
+ const capability = this.promisesByRequest[requestId];
592
+ delete this.promisesByRequest[requestId];
593
+ capability.resolve();
737
594
  }
738
- }, {
739
- key: "abort",
740
- value: function abort(reason) {
741
- this.aborted = true;
742
595
 
743
- if (this.pdfNetworkStream) {
744
- this.pdfNetworkStream.cancelAllRequests(reason);
745
- }
596
+ this.msgHandler.send("DocProgress", {
597
+ loaded: this.stream.numChunksLoaded * this.chunkSize,
598
+ total: this.length
599
+ });
600
+ }
746
601
 
747
- for (var requestId in this.promisesByRequest) {
748
- this.promisesByRequest[requestId].reject(reason);
749
- }
602
+ onError(err) {
603
+ this._loadedStreamCapability.reject(err);
604
+ }
605
+
606
+ getBeginChunk(begin) {
607
+ return Math.floor(begin / this.chunkSize);
608
+ }
609
+
610
+ getEndChunk(end) {
611
+ return Math.floor((end - 1) / this.chunkSize) + 1;
612
+ }
613
+
614
+ abort(reason) {
615
+ this.aborted = true;
616
+
617
+ if (this.pdfNetworkStream) {
618
+ this.pdfNetworkStream.cancelAllRequests(reason);
750
619
  }
751
- }]);
752
620
 
753
- return ChunkedStreamManager;
754
- }();
621
+ for (const requestId in this.promisesByRequest) {
622
+ this.promisesByRequest[requestId].reject(reason);
623
+ }
624
+ }
625
+
626
+ }
755
627
 
756
628
  exports.ChunkedStreamManager = ChunkedStreamManager;