pdfjs-dist 2.0.487 → 2.1.266

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