pdfjs-dist 2.0.489 → 2.2.228

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