pdfjs-dist 2.0.943 → 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 (159) hide show
  1. package/bower.json +1 -1
  2. package/build/pdf.js +15329 -11095
  3. package/build/pdf.js.map +1 -1
  4. package/build/pdf.min.js +1 -1
  5. package/build/pdf.worker.js +12497 -4184
  6. package/build/pdf.worker.js.map +1 -1
  7. package/build/pdf.worker.min.js +1 -1
  8. package/image_decoders/pdf.image_decoders.js +3438 -1209
  9. package/image_decoders/pdf.image_decoders.js.map +1 -1
  10. package/image_decoders/pdf.image_decoders.min.js +1 -1
  11. package/lib/core/annotation.js +335 -109
  12. package/lib/core/arithmetic_decoder.js +274 -244
  13. package/lib/core/bidi.js +64 -5
  14. package/lib/core/ccitt.js +172 -17
  15. package/lib/core/ccitt_stream.js +14 -5
  16. package/lib/core/cff_parser.js +304 -28
  17. package/lib/core/charsets.js +4 -3
  18. package/lib/core/chunked_stream.js +379 -149
  19. package/lib/core/cmap.js +210 -40
  20. package/lib/core/colorspace.js +332 -187
  21. package/lib/core/crypto.js +289 -44
  22. package/lib/core/document.js +508 -249
  23. package/lib/core/encodings.js +18 -9
  24. package/lib/core/evaluator.js +657 -119
  25. package/lib/core/font_renderer.js +217 -34
  26. package/lib/core/fonts.js +632 -41
  27. package/lib/core/function.js +252 -26
  28. package/lib/core/glyphlist.js +2 -1
  29. package/lib/core/image.js +124 -27
  30. package/lib/core/jbig2.js +425 -65
  31. package/lib/core/jbig2_stream.js +18 -7
  32. package/lib/core/jpeg_stream.js +24 -8
  33. package/lib/core/jpg.js +208 -16
  34. package/lib/core/jpx.js +395 -5
  35. package/lib/core/jpx_stream.js +17 -5
  36. package/lib/core/metrics.js +3 -3
  37. package/lib/core/murmurhash3.js +23 -5
  38. package/lib/core/obj.js +625 -132
  39. package/lib/core/operator_list.js +104 -3
  40. package/lib/core/parser.js +262 -25
  41. package/lib/core/pattern.js +144 -12
  42. package/lib/core/pdf_manager.js +104 -70
  43. package/lib/core/primitives.js +74 -21
  44. package/lib/core/ps_parser.js +133 -44
  45. package/lib/core/standard_fonts.js +9 -9
  46. package/lib/core/stream.js +283 -31
  47. package/lib/core/type1_parser.js +138 -6
  48. package/lib/core/unicode.js +28 -1
  49. package/lib/core/worker.js +192 -57
  50. package/lib/display/annotation_layer.js +303 -123
  51. package/lib/display/api.js +1073 -574
  52. package/lib/display/api_compatibility.js +4 -1
  53. package/lib/display/canvas.js +314 -18
  54. package/lib/display/content_disposition.js +70 -23
  55. package/lib/display/dom_utils.js +112 -59
  56. package/lib/display/fetch_stream.js +95 -50
  57. package/lib/display/font_loader.js +250 -132
  58. package/lib/display/metadata.js +37 -15
  59. package/lib/display/network.js +123 -34
  60. package/lib/display/network_utils.js +23 -10
  61. package/lib/display/node_stream.js +162 -65
  62. package/lib/display/pattern_helper.js +57 -6
  63. package/lib/display/svg.js +194 -18
  64. package/lib/display/text_layer.js +128 -14
  65. package/lib/display/transport_stream.js +83 -27
  66. package/lib/display/webgl.js +63 -17
  67. package/lib/display/worker_options.js +4 -3
  68. package/lib/display/xml_parser.js +162 -52
  69. package/lib/examples/node/domstubs.js +56 -3
  70. package/lib/pdf.js +15 -2
  71. package/lib/pdf.worker.js +4 -2
  72. package/lib/shared/compatibility.js +129 -26
  73. package/lib/shared/global_scope.js +1 -1
  74. package/lib/shared/is_node.js +3 -3
  75. package/lib/shared/message_handler.js +103 -45
  76. package/lib/shared/streams_polyfill.js +20 -16
  77. package/lib/shared/url_polyfill.js +8 -2
  78. package/lib/shared/util.js +246 -84
  79. package/lib/test/unit/annotation_spec.js +99 -73
  80. package/lib/test/unit/api_spec.js +347 -113
  81. package/lib/test/unit/bidi_spec.js +6 -6
  82. package/lib/test/unit/cff_parser_spec.js +17 -5
  83. package/lib/test/unit/clitests_helper.js +7 -8
  84. package/lib/test/unit/cmap_spec.js +79 -25
  85. package/lib/test/unit/colorspace_spec.js +65 -18
  86. package/lib/test/unit/crypto_spec.js +16 -4
  87. package/lib/test/unit/custom_spec.js +40 -52
  88. package/lib/test/unit/display_svg_spec.js +32 -16
  89. package/lib/test/unit/document_spec.js +2 -2
  90. package/lib/test/unit/dom_utils_spec.js +8 -8
  91. package/lib/test/unit/encodings_spec.js +24 -44
  92. package/lib/test/unit/evaluator_spec.js +15 -8
  93. package/lib/test/unit/function_spec.js +16 -4
  94. package/lib/test/unit/jasmine-boot.js +29 -16
  95. package/lib/test/unit/message_handler_spec.js +19 -6
  96. package/lib/test/unit/metadata_spec.js +64 -11
  97. package/lib/test/unit/murmurhash3_spec.js +2 -2
  98. package/lib/test/unit/network_spec.js +19 -4
  99. package/lib/test/unit/network_utils_spec.js +6 -4
  100. package/lib/test/unit/node_stream_spec.js +50 -26
  101. package/lib/test/unit/parser_spec.js +13 -29
  102. package/lib/test/unit/pdf_find_controller_spec.js +144 -32
  103. package/lib/test/unit/pdf_find_utils_spec.js +10 -9
  104. package/lib/test/unit/pdf_history_spec.js +20 -8
  105. package/lib/test/unit/primitives_spec.js +23 -3
  106. package/lib/test/unit/stream_spec.js +8 -3
  107. package/lib/test/unit/test_utils.js +89 -26
  108. package/lib/test/unit/testreporter.js +19 -1
  109. package/lib/test/unit/type1_parser_spec.js +7 -5
  110. package/lib/test/unit/ui_utils_spec.js +162 -38
  111. package/lib/test/unit/unicode_spec.js +13 -10
  112. package/lib/test/unit/util_spec.js +89 -9
  113. package/lib/web/annotation_layer_builder.js +38 -21
  114. package/lib/web/app.js +610 -245
  115. package/lib/web/app_options.js +54 -34
  116. package/lib/web/base_viewer.js +359 -162
  117. package/lib/web/chromecom.js +159 -80
  118. package/lib/web/debugger.js +161 -17
  119. package/lib/web/download_manager.js +29 -11
  120. package/lib/web/firefox_print_service.js +16 -8
  121. package/lib/web/firefoxcom.js +127 -91
  122. package/lib/web/genericcom.js +50 -31
  123. package/lib/web/genericl10n.js +46 -34
  124. package/lib/web/grab_to_pan.js +25 -3
  125. package/lib/web/interfaces.js +108 -61
  126. package/lib/web/overlay_manager.js +67 -45
  127. package/lib/web/password_prompt.js +20 -12
  128. package/lib/web/pdf_attachment_viewer.js +37 -17
  129. package/lib/web/pdf_cursor_tools.js +38 -15
  130. package/lib/web/pdf_document_properties.js +65 -24
  131. package/lib/web/pdf_find_bar.js +48 -20
  132. package/lib/web/pdf_find_controller.js +290 -89
  133. package/lib/web/pdf_find_utils.js +19 -3
  134. package/lib/web/pdf_history.js +186 -49
  135. package/lib/web/pdf_link_service.js +127 -52
  136. package/lib/web/pdf_outline_viewer.js +71 -21
  137. package/lib/web/pdf_page_view.js +188 -63
  138. package/lib/web/pdf_presentation_mode.js +98 -33
  139. package/lib/web/pdf_print_service.js +54 -10
  140. package/lib/web/pdf_rendering_queue.js +26 -4
  141. package/lib/web/pdf_sidebar.js +116 -62
  142. package/lib/web/pdf_sidebar_resizer.js +41 -15
  143. package/lib/web/pdf_single_page_viewer.js +65 -68
  144. package/lib/web/pdf_thumbnail_view.js +102 -31
  145. package/lib/web/pdf_thumbnail_viewer.js +62 -22
  146. package/lib/web/pdf_viewer.component.js +111 -31
  147. package/lib/web/pdf_viewer.js +80 -60
  148. package/lib/web/preferences.js +61 -39
  149. package/lib/web/secondary_toolbar.js +101 -82
  150. package/lib/web/text_layer_builder.js +124 -69
  151. package/lib/web/toolbar.js +67 -27
  152. package/lib/web/ui_utils.js +284 -128
  153. package/lib/web/view_history.js +75 -51
  154. package/lib/web/viewer_compatibility.js +2 -1
  155. package/package.json +1 -1
  156. package/web/pdf_viewer.css +1 -1
  157. package/web/pdf_viewer.js +2200 -973
  158. package/web/pdf_viewer.js.map +1 -1
  159. package/lib/web/dom_events.js +0 -140
@@ -19,72 +19,81 @@
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.NetworkManager = exports.PDFNetworkStream = undefined;
28
-
29
- var _regenerator = require('babel-runtime/regenerator');
30
-
31
- var _regenerator2 = _interopRequireDefault(_regenerator);
27
+ exports.PDFNetworkStream = PDFNetworkStream;
28
+ exports.NetworkManager = NetworkManager;
32
29
 
33
- var _util = require('../shared/util');
30
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
34
31
 
35
- var _network_utils = require('./network_utils');
32
+ var _util = require("../shared/util");
36
33
 
37
- var _global_scope = require('../shared/global_scope');
34
+ var _network_utils = require("./network_utils");
38
35
 
39
- var _global_scope2 = _interopRequireDefault(_global_scope);
36
+ var _global_scope = _interopRequireDefault(require("../shared/global_scope"));
40
37
 
41
38
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
42
39
 
43
- function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
40
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
41
+
42
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
44
43
 
45
44
  ;
46
45
  var OK_RESPONSE = 200;
47
46
  var PARTIAL_CONTENT_RESPONSE = 206;
47
+
48
48
  function NetworkManager(url, args) {
49
49
  this.url = url;
50
50
  args = args || {};
51
51
  this.isHttp = /^https?:/i.test(url);
52
52
  this.httpHeaders = this.isHttp && args.httpHeaders || {};
53
53
  this.withCredentials = args.withCredentials || false;
54
+
54
55
  this.getXhr = args.getXhr || function NetworkManager_getXhr() {
55
56
  return new XMLHttpRequest();
56
57
  };
58
+
57
59
  this.currXhrId = 0;
58
60
  this.pendingRequests = Object.create(null);
59
61
  this.loadedRequests = Object.create(null);
60
62
  }
63
+
61
64
  function getArrayBuffer(xhr) {
62
65
  var data = xhr.response;
66
+
63
67
  if (typeof data !== 'string') {
64
68
  return data;
65
69
  }
70
+
66
71
  var array = (0, _util.stringToBytes)(data);
67
72
  return array.buffer;
68
73
  }
74
+
69
75
  var supportsMozChunked = function supportsMozChunkedClosure() {
70
76
  try {
71
77
  var x = new XMLHttpRequest();
72
- x.open('GET', _global_scope2.default.location.href);
78
+ x.open('GET', _global_scope.default.location.href);
73
79
  x.responseType = 'moz-chunked-arraybuffer';
74
80
  return x.responseType === 'moz-chunked-arraybuffer';
75
81
  } catch (e) {
76
82
  return false;
77
83
  }
78
84
  }();
85
+
79
86
  NetworkManager.prototype = {
80
87
  requestRange: function NetworkManager_requestRange(begin, end, listeners) {
81
88
  var args = {
82
89
  begin: begin,
83
90
  end: end
84
91
  };
92
+
85
93
  for (var prop in listeners) {
86
94
  args[prop] = listeners[prop];
87
95
  }
96
+
88
97
  return this.request(args);
89
98
  },
90
99
  requestFull: function NetworkManager_requestFull(listeners) {
@@ -93,16 +102,22 @@ NetworkManager.prototype = {
93
102
  request: function NetworkManager_request(args) {
94
103
  var xhr = this.getXhr();
95
104
  var xhrId = this.currXhrId++;
96
- var pendingRequest = this.pendingRequests[xhrId] = { xhr: xhr };
105
+ var pendingRequest = this.pendingRequests[xhrId] = {
106
+ xhr: xhr
107
+ };
97
108
  xhr.open('GET', this.url);
98
109
  xhr.withCredentials = this.withCredentials;
110
+
99
111
  for (var property in this.httpHeaders) {
100
112
  var value = this.httpHeaders[property];
113
+
101
114
  if (typeof value === 'undefined') {
102
115
  continue;
103
116
  }
117
+
104
118
  xhr.setRequestHeader(property, value);
105
119
  }
120
+
106
121
  if (this.isHttp && 'begin' in args && 'end' in args) {
107
122
  var rangeStr = args.begin + '-' + (args.end - 1);
108
123
  xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
@@ -110,7 +125,9 @@ NetworkManager.prototype = {
110
125
  } else {
111
126
  pendingRequest.expectedStatus = 200;
112
127
  }
128
+
113
129
  var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
130
+
114
131
  if (useMozChunkedLoading) {
115
132
  xhr.responseType = 'moz-chunked-arraybuffer';
116
133
  pendingRequest.onProgressiveData = args.onProgressiveData;
@@ -118,11 +135,13 @@ NetworkManager.prototype = {
118
135
  } else {
119
136
  xhr.responseType = 'arraybuffer';
120
137
  }
138
+
121
139
  if (args.onError) {
122
140
  xhr.onerror = function (evt) {
123
141
  args.onError(xhr.status);
124
142
  };
125
143
  }
144
+
126
145
  xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
127
146
  xhr.onprogress = this.onProgress.bind(this, xhrId);
128
147
  pendingRequest.onHeadersReceived = args.onHeadersReceived;
@@ -134,51 +153,68 @@ NetworkManager.prototype = {
134
153
  },
135
154
  onProgress: function NetworkManager_onProgress(xhrId, evt) {
136
155
  var pendingRequest = this.pendingRequests[xhrId];
156
+
137
157
  if (!pendingRequest) {
138
158
  return;
139
159
  }
160
+
140
161
  if (pendingRequest.mozChunked) {
141
162
  var chunk = getArrayBuffer(pendingRequest.xhr);
142
163
  pendingRequest.onProgressiveData(chunk);
143
164
  }
165
+
144
166
  var onProgress = pendingRequest.onProgress;
167
+
145
168
  if (onProgress) {
146
169
  onProgress(evt);
147
170
  }
148
171
  },
149
172
  onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
150
173
  var pendingRequest = this.pendingRequests[xhrId];
174
+
151
175
  if (!pendingRequest) {
152
176
  return;
153
177
  }
178
+
154
179
  var xhr = pendingRequest.xhr;
180
+
155
181
  if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
156
182
  pendingRequest.onHeadersReceived();
157
183
  delete pendingRequest.onHeadersReceived;
158
184
  }
185
+
159
186
  if (xhr.readyState !== 4) {
160
187
  return;
161
188
  }
189
+
162
190
  if (!(xhrId in this.pendingRequests)) {
163
191
  return;
164
192
  }
193
+
165
194
  delete this.pendingRequests[xhrId];
195
+
166
196
  if (xhr.status === 0 && this.isHttp) {
167
197
  if (pendingRequest.onError) {
168
198
  pendingRequest.onError(xhr.status);
169
199
  }
200
+
170
201
  return;
171
202
  }
203
+
172
204
  var xhrStatus = xhr.status || OK_RESPONSE;
173
205
  var ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
206
+
174
207
  if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
175
208
  if (pendingRequest.onError) {
176
209
  pendingRequest.onError(xhr.status);
177
210
  }
211
+
178
212
  return;
179
213
  }
214
+
180
215
  this.loadedRequests[xhrId] = true;
181
216
  var chunk = getArrayBuffer(xhr);
217
+
182
218
  if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
183
219
  var rangeHeader = xhr.getResponseHeader('Content-Range');
184
220
  var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
@@ -202,6 +238,7 @@ NetworkManager.prototype = {
202
238
  for (var xhrId in this.pendingRequests) {
203
239
  return true;
204
240
  }
241
+
205
242
  return false;
206
243
  },
207
244
  getRequestXhr: function NetworkManager_getXhr(xhrId) {
@@ -227,6 +264,7 @@ NetworkManager.prototype = {
227
264
  xhr.abort();
228
265
  }
229
266
  };
267
+
230
268
  function PDFNetworkStream(source) {
231
269
  this._source = source;
232
270
  this._manager = new NetworkManager(source.url, {
@@ -237,9 +275,11 @@ function PDFNetworkStream(source) {
237
275
  this._fullRequestReader = null;
238
276
  this._rangeRequestReaders = [];
239
277
  }
278
+
240
279
  PDFNetworkStream.prototype = {
241
280
  _onRangeRequestReaderClosed: function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
242
281
  var i = this._rangeRequestReaders.indexOf(reader);
282
+
243
283
  if (i >= 0) {
244
284
  this._rangeRequestReaders.splice(i, 1);
245
285
  }
@@ -252,19 +292,24 @@ PDFNetworkStream.prototype = {
252
292
  getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
253
293
  var reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
254
294
  reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
295
+
255
296
  this._rangeRequestReaders.push(reader);
297
+
256
298
  return reader;
257
299
  },
258
300
  cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
259
301
  if (this._fullRequestReader) {
260
302
  this._fullRequestReader.cancel(reason);
261
303
  }
304
+
262
305
  var readers = this._rangeRequestReaders.slice(0);
306
+
263
307
  readers.forEach(function (reader) {
264
308
  reader.cancel(reason);
265
309
  });
266
310
  }
267
311
  };
312
+
268
313
  function PDFNetworkStreamFullRequestReader(manager, source) {
269
314
  this._manager = manager;
270
315
  var args = {
@@ -280,9 +325,11 @@ function PDFNetworkStreamFullRequestReader(manager, source) {
280
325
  this._disableRange = source.disableRange || false;
281
326
  this._contentLength = source.length;
282
327
  this._rangeChunkSize = source.rangeChunkSize;
328
+
283
329
  if (!this._rangeChunkSize && !this._disableRange) {
284
330
  this._disableRange = true;
285
331
  }
332
+
286
333
  this._isStreamingSupported = false;
287
334
  this._isRangeSupported = false;
288
335
  this._cachedChunks = [];
@@ -292,10 +339,13 @@ function PDFNetworkStreamFullRequestReader(manager, source) {
292
339
  this._filename = null;
293
340
  this.onProgress = null;
294
341
  }
342
+
295
343
  PDFNetworkStreamFullRequestReader.prototype = {
296
344
  _onHeadersReceived: function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
297
345
  var fullRequestXhrId = this._fullRequestId;
346
+
298
347
  var fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
348
+
299
349
  var getResponseHeader = function getResponseHeader(name) {
300
350
  return fullRequestXhr.getResponseHeader(name);
301
351
  };
@@ -312,19 +362,23 @@ PDFNetworkStreamFullRequestReader.prototype = {
312
362
  if (allowRangeRequests) {
313
363
  this._isRangeSupported = true;
314
364
  }
365
+
315
366
  this._contentLength = suggestedLength || this._contentLength;
316
367
  this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
317
368
  var networkManager = this._manager;
369
+
318
370
  if (networkManager.isStreamingRequest(fullRequestXhrId)) {
319
371
  this._isStreamingSupported = true;
320
372
  } else if (this._isRangeSupported) {
321
373
  networkManager.abortRequest(fullRequestXhrId);
322
374
  }
375
+
323
376
  this._headersReceivedCapability.resolve();
324
377
  },
325
378
  _onProgressiveData: function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
326
379
  if (this._requests.length > 0) {
327
380
  var requestCapability = this._requests.shift();
381
+
328
382
  requestCapability.resolve({
329
383
  value: chunk,
330
384
  done: false
@@ -337,26 +391,33 @@ PDFNetworkStreamFullRequestReader.prototype = {
337
391
  if (args) {
338
392
  this._onProgressiveData(args.chunk);
339
393
  }
394
+
340
395
  this._done = true;
396
+
341
397
  if (this._cachedChunks.length > 0) {
342
398
  return;
343
399
  }
400
+
344
401
  this._requests.forEach(function (requestCapability) {
345
402
  requestCapability.resolve({
346
403
  value: undefined,
347
404
  done: true
348
405
  });
349
406
  });
407
+
350
408
  this._requests = [];
351
409
  },
352
410
  _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
353
411
  var url = this._url;
354
412
  var exception = (0, _network_utils.createResponseStatusError)(status, url);
355
413
  this._storedError = exception;
414
+
356
415
  this._headersReceivedCapability.reject(exception);
416
+
357
417
  this._requests.forEach(function (requestCapability) {
358
418
  requestCapability.reject(exception);
359
419
  });
420
+
360
421
  this._requests = [];
361
422
  this._cachedChunks = [];
362
423
  },
@@ -368,25 +429,33 @@ PDFNetworkStreamFullRequestReader.prototype = {
368
429
  });
369
430
  }
370
431
  },
432
+
371
433
  get filename() {
372
434
  return this._filename;
373
435
  },
436
+
374
437
  get isRangeSupported() {
375
438
  return this._isRangeSupported;
376
439
  },
440
+
377
441
  get isStreamingSupported() {
378
442
  return this._isStreamingSupported;
379
443
  },
444
+
380
445
  get contentLength() {
381
446
  return this._contentLength;
382
447
  },
448
+
383
449
  get headersReady() {
384
450
  return this._headersReceivedCapability.promise;
385
451
  },
452
+
386
453
  read: function () {
387
- var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
454
+ var _read = _asyncToGenerator(
455
+ /*#__PURE__*/
456
+ _regenerator.default.mark(function _callee() {
388
457
  var chunk, requestCapability;
389
- return _regenerator2.default.wrap(function _callee$(_context) {
458
+ return _regenerator.default.wrap(function _callee$(_context) {
390
459
  while (1) {
391
460
  switch (_context.prev = _context.next) {
392
461
  case 0:
@@ -404,7 +473,7 @@ PDFNetworkStreamFullRequestReader.prototype = {
404
473
  }
405
474
 
406
475
  chunk = this._cachedChunks.shift();
407
- return _context.abrupt('return', {
476
+ return _context.abrupt("return", {
408
477
  value: chunk,
409
478
  done: false
410
479
  });
@@ -415,7 +484,7 @@ PDFNetworkStreamFullRequestReader.prototype = {
415
484
  break;
416
485
  }
417
486
 
418
- return _context.abrupt('return', {
487
+ return _context.abrupt("return", {
419
488
  value: undefined,
420
489
  done: true
421
490
  });
@@ -424,10 +493,11 @@ PDFNetworkStreamFullRequestReader.prototype = {
424
493
  requestCapability = (0, _util.createPromiseCapability)();
425
494
 
426
495
  this._requests.push(requestCapability);
427
- return _context.abrupt('return', requestCapability.promise);
496
+
497
+ return _context.abrupt("return", requestCapability.promise);
428
498
 
429
499
  case 10:
430
- case 'end':
500
+ case "end":
431
501
  return _context.stop();
432
502
  }
433
503
  }
@@ -435,28 +505,33 @@ PDFNetworkStreamFullRequestReader.prototype = {
435
505
  }));
436
506
 
437
507
  function read() {
438
- return _ref.apply(this, arguments);
508
+ return _read.apply(this, arguments);
439
509
  }
440
510
 
441
511
  return read;
442
512
  }(),
443
-
444
513
  cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
445
514
  this._done = true;
515
+
446
516
  this._headersReceivedCapability.reject(reason);
517
+
447
518
  this._requests.forEach(function (requestCapability) {
448
519
  requestCapability.resolve({
449
520
  value: undefined,
450
521
  done: true
451
522
  });
452
523
  });
524
+
453
525
  this._requests = [];
526
+
454
527
  if (this._manager.isPendingRequest(this._fullRequestId)) {
455
528
  this._manager.abortRequest(this._fullRequestId);
456
529
  }
530
+
457
531
  this._fullRequestReader = null;
458
532
  }
459
533
  };
534
+
460
535
  function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
461
536
  this._manager = manager;
462
537
  var args = {
@@ -470,6 +545,7 @@ function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
470
545
  this.onProgress = null;
471
546
  this.onClosed = null;
472
547
  }
548
+
473
549
  PDFNetworkStreamRangeRequestReader.prototype = {
474
550
  _close: function PDFNetworkStreamRangeRequestReader_close() {
475
551
  if (this.onClosed) {
@@ -478,8 +554,10 @@ PDFNetworkStreamRangeRequestReader.prototype = {
478
554
  },
479
555
  _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
480
556
  var chunk = data.chunk;
557
+
481
558
  if (this._requests.length > 0) {
482
559
  var requestCapability = this._requests.shift();
560
+
483
561
  requestCapability.resolve({
484
562
  value: chunk,
485
563
  done: false
@@ -487,28 +565,38 @@ PDFNetworkStreamRangeRequestReader.prototype = {
487
565
  } else {
488
566
  this._queuedChunk = chunk;
489
567
  }
568
+
490
569
  this._done = true;
570
+
491
571
  this._requests.forEach(function (requestCapability) {
492
572
  requestCapability.resolve({
493
573
  value: undefined,
494
574
  done: true
495
575
  });
496
576
  });
577
+
497
578
  this._requests = [];
579
+
498
580
  this._close();
499
581
  },
500
582
  _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
501
583
  if (!this.isStreamingSupported && this.onProgress) {
502
- this.onProgress({ loaded: evt.loaded });
584
+ this.onProgress({
585
+ loaded: evt.loaded
586
+ });
503
587
  }
504
588
  },
589
+
505
590
  get isStreamingSupported() {
506
591
  return false;
507
592
  },
593
+
508
594
  read: function () {
509
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
595
+ var _read2 = _asyncToGenerator(
596
+ /*#__PURE__*/
597
+ _regenerator.default.mark(function _callee2() {
510
598
  var chunk, requestCapability;
511
- return _regenerator2.default.wrap(function _callee2$(_context2) {
599
+ return _regenerator.default.wrap(function _callee2$(_context2) {
512
600
  while (1) {
513
601
  switch (_context2.prev = _context2.next) {
514
602
  case 0:
@@ -518,9 +606,8 @@ PDFNetworkStreamRangeRequestReader.prototype = {
518
606
  }
519
607
 
520
608
  chunk = this._queuedChunk;
521
-
522
609
  this._queuedChunk = null;
523
- return _context2.abrupt('return', {
610
+ return _context2.abrupt("return", {
524
611
  value: chunk,
525
612
  done: false
526
613
  });
@@ -531,7 +618,7 @@ PDFNetworkStreamRangeRequestReader.prototype = {
531
618
  break;
532
619
  }
533
620
 
534
- return _context2.abrupt('return', {
621
+ return _context2.abrupt("return", {
535
622
  value: undefined,
536
623
  done: true
537
624
  });
@@ -540,10 +627,11 @@ PDFNetworkStreamRangeRequestReader.prototype = {
540
627
  requestCapability = (0, _util.createPromiseCapability)();
541
628
 
542
629
  this._requests.push(requestCapability);
543
- return _context2.abrupt('return', requestCapability.promise);
630
+
631
+ return _context2.abrupt("return", requestCapability.promise);
544
632
 
545
633
  case 9:
546
- case 'end':
634
+ case "end":
547
635
  return _context2.stop();
548
636
  }
549
637
  }
@@ -551,26 +639,27 @@ PDFNetworkStreamRangeRequestReader.prototype = {
551
639
  }));
552
640
 
553
641
  function read() {
554
- return _ref2.apply(this, arguments);
642
+ return _read2.apply(this, arguments);
555
643
  }
556
644
 
557
645
  return read;
558
646
  }(),
559
-
560
647
  cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
561
648
  this._done = true;
649
+
562
650
  this._requests.forEach(function (requestCapability) {
563
651
  requestCapability.resolve({
564
652
  value: undefined,
565
653
  done: true
566
654
  });
567
655
  });
656
+
568
657
  this._requests = [];
658
+
569
659
  if (this._manager.isPendingRequest(this._requestId)) {
570
660
  this._manager.abortRequest(this._requestId);
571
661
  }
662
+
572
663
  this._close();
573
664
  }
574
- };
575
- exports.PDFNetworkStream = PDFNetworkStream;
576
- exports.NetworkManager = NetworkManager;
665
+ };
@@ -19,69 +19,82 @@
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.validateResponseStatus = exports.validateRangeRequestCapabilities = exports.extractFilenameFromHeader = exports.createResponseStatusError = undefined;
27
+ exports.createResponseStatusError = createResponseStatusError;
28
+ exports.extractFilenameFromHeader = extractFilenameFromHeader;
29
+ exports.validateRangeRequestCapabilities = validateRangeRequestCapabilities;
30
+ exports.validateResponseStatus = validateResponseStatus;
28
31
 
29
- var _util = require('../shared/util');
32
+ var _util = require("../shared/util");
30
33
 
31
- var _content_disposition = require('./content_disposition');
34
+ var _content_disposition = require("./content_disposition");
32
35
 
33
36
  function validateRangeRequestCapabilities(_ref) {
34
37
  var getResponseHeader = _ref.getResponseHeader,
35
38
  isHttp = _ref.isHttp,
36
39
  rangeChunkSize = _ref.rangeChunkSize,
37
40
  disableRange = _ref.disableRange;
38
-
39
41
  (0, _util.assert)(rangeChunkSize > 0, 'Range chunk size must be larger than zero');
40
42
  var returnValues = {
41
43
  allowRangeRequests: false,
42
44
  suggestedLength: undefined
43
45
  };
44
46
  var length = parseInt(getResponseHeader('Content-Length'), 10);
47
+
45
48
  if (!Number.isInteger(length)) {
46
49
  return returnValues;
47
50
  }
51
+
48
52
  returnValues.suggestedLength = length;
53
+
49
54
  if (length <= 2 * rangeChunkSize) {
50
55
  return returnValues;
51
56
  }
57
+
52
58
  if (disableRange || !isHttp) {
53
59
  return returnValues;
54
60
  }
61
+
55
62
  if (getResponseHeader('Accept-Ranges') !== 'bytes') {
56
63
  return returnValues;
57
64
  }
65
+
58
66
  var contentEncoding = getResponseHeader('Content-Encoding') || 'identity';
67
+
59
68
  if (contentEncoding !== 'identity') {
60
69
  return returnValues;
61
70
  }
71
+
62
72
  returnValues.allowRangeRequests = true;
63
73
  return returnValues;
64
74
  }
75
+
65
76
  function extractFilenameFromHeader(getResponseHeader) {
66
77
  var contentDisposition = getResponseHeader('Content-Disposition');
78
+
67
79
  if (contentDisposition) {
68
80
  var filename = (0, _content_disposition.getFilenameFromContentDispositionHeader)(contentDisposition);
81
+
69
82
  if (/\.pdf$/i.test(filename)) {
70
83
  return filename;
71
84
  }
72
85
  }
86
+
73
87
  return null;
74
88
  }
89
+
75
90
  function createResponseStatusError(status, url) {
76
91
  if (status === 404 || status === 0 && /^file:/.test(url)) {
77
92
  return new _util.MissingPDFException('Missing PDF "' + url + '".');
78
93
  }
94
+
79
95
  return new _util.UnexpectedResponseException('Unexpected server response (' + status + ') while retrieving PDF "' + url + '".', status);
80
96
  }
97
+
81
98
  function validateResponseStatus(status) {
82
99
  return status === 200 || status === 206;
83
- }
84
- exports.createResponseStatusError = createResponseStatusError;
85
- exports.extractFilenameFromHeader = extractFilenameFromHeader;
86
- exports.validateRangeRequestCapabilities = validateRangeRequestCapabilities;
87
- exports.validateResponseStatus = validateResponseStatus;
100
+ }