pdfjs-dist 2.1.266 → 2.5.207

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

Potentially problematic release.


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

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