pdfjs-dist 2.0.943 → 2.4.456

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

Potentially problematic release.


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

Files changed (192) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/README.md +4 -0
  3. package/bower.json +1 -1
  4. package/build/pdf.js +8286 -14230
  5. package/build/pdf.js.map +1 -1
  6. package/build/pdf.min.js +22 -1
  7. package/build/pdf.worker.entry.js +5 -3
  8. package/build/pdf.worker.js +25500 -26628
  9. package/build/pdf.worker.js.map +1 -1
  10. package/build/pdf.worker.min.js +22 -1
  11. package/es5/build/pdf.js +25473 -0
  12. package/es5/build/pdf.js.map +1 -0
  13. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  14. package/es5/build/pdf.worker.js +57878 -0
  15. package/es5/build/pdf.worker.js.map +1 -0
  16. package/es5/web/images/annotation-check.svg +11 -0
  17. package/es5/web/images/annotation-comment.svg +16 -0
  18. package/es5/web/images/annotation-help.svg +26 -0
  19. package/es5/web/images/annotation-insert.svg +10 -0
  20. package/es5/web/images/annotation-key.svg +11 -0
  21. package/es5/web/images/annotation-newparagraph.svg +11 -0
  22. package/es5/web/images/annotation-noicon.svg +7 -0
  23. package/es5/web/images/annotation-note.svg +42 -0
  24. package/es5/web/images/annotation-paragraph.svg +16 -0
  25. package/es5/web/images/loading-icon.gif +0 -0
  26. package/es5/web/images/shadow.png +0 -0
  27. package/es5/web/images/texture.png +0 -0
  28. package/es5/web/pdf_viewer.css +407 -0
  29. package/es5/web/pdf_viewer.js +7757 -0
  30. package/es5/web/pdf_viewer.js.map +1 -0
  31. package/image_decoders/pdf.image_decoders.js +2887 -4094
  32. package/image_decoders/pdf.image_decoders.js.map +1 -1
  33. package/image_decoders/pdf.image_decoders.min.js +22 -1
  34. package/lib/README.md +7 -0
  35. package/lib/core/annotation.js +855 -778
  36. package/lib/core/arithmetic_decoder.js +325 -311
  37. package/lib/core/bidi.js +117 -50
  38. package/lib/core/ccitt.js +251 -89
  39. package/lib/core/ccitt_stream.js +26 -16
  40. package/lib/core/cff_parser.js +525 -197
  41. package/lib/core/charsets.js +6 -5
  42. package/lib/core/chunked_stream.js +541 -406
  43. package/lib/core/cmap.js +368 -253
  44. package/lib/core/colorspace.js +781 -800
  45. package/lib/core/core_utils.js +152 -0
  46. package/lib/core/crypto.js +609 -422
  47. package/lib/core/document.js +649 -481
  48. package/lib/core/encodings.js +33 -24
  49. package/lib/core/evaluator.js +1471 -736
  50. package/lib/core/font_renderer.js +289 -149
  51. package/lib/core/fonts.js +1067 -413
  52. package/lib/core/function.js +517 -287
  53. package/lib/core/glyphlist.js +4529 -4527
  54. package/lib/core/image.js +232 -114
  55. package/lib/core/image_utils.js +94 -0
  56. package/lib/core/jbig2.js +711 -342
  57. package/lib/core/jbig2_stream.js +31 -19
  58. package/lib/core/jpeg_stream.js +151 -26
  59. package/lib/core/jpg.js +433 -181
  60. package/lib/core/jpx.js +551 -143
  61. package/lib/core/jpx_stream.js +40 -28
  62. package/lib/core/metrics.js +2931 -2931
  63. package/lib/core/murmurhash3.js +104 -97
  64. package/lib/core/obj.js +1561 -1053
  65. package/lib/core/operator_list.js +192 -64
  66. package/lib/core/parser.js +1162 -864
  67. package/lib/core/pattern.js +224 -75
  68. package/lib/core/pdf_manager.js +154 -285
  69. package/lib/core/primitives.js +145 -69
  70. package/lib/core/ps_parser.js +212 -162
  71. package/lib/core/standard_fonts.js +245 -244
  72. package/lib/core/stream.js +353 -81
  73. package/lib/core/type1_parser.js +218 -68
  74. package/lib/core/unicode.js +1682 -1655
  75. package/lib/core/worker.js +233 -302
  76. package/lib/core/worker_stream.js +168 -0
  77. package/lib/display/annotation_layer.js +808 -862
  78. package/lib/display/api.js +1778 -1462
  79. package/lib/display/api_compatibility.js +14 -9
  80. package/lib/display/canvas.js +463 -140
  81. package/lib/display/content_disposition.js +86 -58
  82. package/lib/display/display_utils.js +524 -0
  83. package/lib/display/fetch_stream.js +202 -274
  84. package/lib/display/font_loader.js +311 -333
  85. package/lib/display/metadata.js +98 -88
  86. package/lib/display/network.js +343 -347
  87. package/lib/display/network_utils.js +46 -26
  88. package/lib/display/node_stream.js +326 -404
  89. package/lib/display/pattern_helper.js +168 -69
  90. package/lib/display/svg.js +1296 -885
  91. package/lib/display/text_layer.js +229 -103
  92. package/lib/display/transport_stream.js +290 -250
  93. package/lib/display/webgl.js +116 -83
  94. package/lib/display/worker_options.js +6 -5
  95. package/lib/display/xml_parser.js +358 -337
  96. package/lib/examples/node/domstubs.js +95 -39
  97. package/lib/pdf.js +49 -31
  98. package/lib/pdf.worker.js +7 -5
  99. package/lib/shared/compatibility.js +3 -145
  100. package/lib/shared/is_node.js +8 -7
  101. package/lib/shared/message_handler.js +367 -314
  102. package/lib/shared/util.js +421 -415
  103. package/lib/test/unit/annotation_spec.js +1570 -690
  104. package/lib/test/unit/api_spec.js +855 -493
  105. package/lib/test/unit/bidi_spec.js +12 -12
  106. package/lib/test/unit/cff_parser_spec.js +88 -61
  107. package/lib/test/unit/clitests_helper.js +9 -12
  108. package/lib/test/unit/cmap_spec.js +140 -88
  109. package/lib/test/unit/colorspace_spec.js +204 -152
  110. package/lib/test/unit/core_utils_spec.js +211 -0
  111. package/lib/test/unit/crypto_spec.js +194 -182
  112. package/lib/test/unit/custom_spec.js +50 -64
  113. package/lib/test/unit/display_svg_spec.js +53 -38
  114. package/lib/test/unit/display_utils_spec.js +263 -0
  115. package/lib/test/unit/document_spec.js +17 -22
  116. package/lib/test/unit/encodings_spec.js +15 -57
  117. package/lib/test/unit/evaluator_spec.js +90 -83
  118. package/lib/test/unit/fetch_stream_spec.js +111 -0
  119. package/lib/test/unit/function_spec.js +219 -205
  120. package/lib/test/unit/jasmine-boot.js +68 -39
  121. package/lib/test/unit/message_handler_spec.js +187 -160
  122. package/lib/test/unit/metadata_spec.js +87 -34
  123. package/lib/test/unit/murmurhash3_spec.js +13 -13
  124. package/lib/test/unit/network_spec.js +26 -59
  125. package/lib/test/unit/network_utils_spec.js +187 -121
  126. package/lib/test/unit/node_stream_spec.js +98 -90
  127. package/lib/test/unit/parser_spec.js +173 -131
  128. package/lib/test/unit/pdf_find_controller_spec.js +148 -67
  129. package/lib/test/unit/pdf_find_utils_spec.js +35 -34
  130. package/lib/test/unit/pdf_history_spec.js +45 -33
  131. package/lib/test/unit/primitives_spec.js +161 -126
  132. package/lib/test/unit/stream_spec.js +22 -15
  133. package/lib/test/unit/test_utils.js +149 -98
  134. package/lib/test/unit/testreporter.js +36 -18
  135. package/lib/test/unit/type1_parser_spec.js +46 -44
  136. package/lib/test/unit/ui_utils_spec.js +388 -372
  137. package/lib/test/unit/unicode_spec.js +49 -46
  138. package/lib/test/unit/util_spec.js +144 -248
  139. package/lib/web/annotation_layer_builder.js +75 -95
  140. package/lib/web/app.js +1538 -1147
  141. package/lib/web/app_options.js +116 -104
  142. package/lib/web/base_viewer.js +950 -775
  143. package/lib/web/chromecom.js +217 -225
  144. package/lib/web/debugger.js +236 -148
  145. package/lib/web/download_manager.js +50 -50
  146. package/lib/web/firefox_print_service.js +51 -33
  147. package/lib/web/firefoxcom.js +225 -352
  148. package/lib/web/genericcom.js +30 -93
  149. package/lib/web/genericl10n.js +26 -143
  150. package/lib/web/grab_to_pan.js +57 -33
  151. package/lib/web/interfaces.js +105 -232
  152. package/lib/web/overlay_manager.js +73 -227
  153. package/lib/web/password_prompt.js +44 -62
  154. package/lib/web/pdf_attachment_viewer.js +118 -123
  155. package/lib/web/pdf_cursor_tools.js +89 -93
  156. package/lib/web/pdf_document_properties.js +242 -281
  157. package/lib/web/pdf_find_bar.js +157 -163
  158. package/lib/web/pdf_find_controller.js +598 -454
  159. package/lib/web/pdf_find_utils.js +32 -16
  160. package/lib/web/pdf_history.js +481 -355
  161. package/lib/web/pdf_link_service.js +355 -323
  162. package/lib/web/pdf_outline_viewer.js +167 -152
  163. package/lib/web/pdf_page_view.js +511 -457
  164. package/lib/web/pdf_presentation_mode.js +347 -335
  165. package/lib/web/pdf_print_service.js +133 -103
  166. package/lib/web/pdf_rendering_queue.js +98 -100
  167. package/lib/web/pdf_sidebar.js +323 -299
  168. package/lib/web/pdf_sidebar_resizer.js +107 -108
  169. package/lib/web/pdf_single_page_viewer.js +94 -146
  170. package/lib/web/pdf_thumbnail_view.js +319 -269
  171. package/lib/web/pdf_thumbnail_viewer.js +219 -199
  172. package/lib/web/pdf_viewer.component.js +111 -32
  173. package/lib/web/pdf_viewer.js +61 -101
  174. package/lib/web/preferences.js +87 -272
  175. package/lib/web/secondary_toolbar.js +207 -220
  176. package/lib/web/text_layer_builder.js +322 -322
  177. package/lib/web/toolbar.js +227 -180
  178. package/lib/web/ui_utils.js +476 -421
  179. package/lib/web/view_history.js +59 -208
  180. package/lib/web/viewer_compatibility.js +9 -6
  181. package/package.json +2 -9
  182. package/web/pdf_viewer.css +36 -22
  183. package/web/pdf_viewer.js +4407 -4516
  184. package/web/pdf_viewer.js.map +1 -1
  185. package/webpack.js +14 -5
  186. package/external/streams/streams-lib.js +0 -3962
  187. package/external/url/url-lib.js +0 -627
  188. package/lib/display/dom_utils.js +0 -441
  189. package/lib/shared/streams_polyfill.js +0 -39
  190. package/lib/shared/url_polyfill.js +0 -50
  191. package/lib/test/unit/dom_utils_spec.js +0 -89
  192. package/lib/web/dom_events.js +0 -140
@@ -2,7 +2,7 @@
2
2
  * @licstart The following is the entire license notice for the
3
3
  * Javascript code in this page
4
4
  *
5
- * Copyright 2018 Mozilla Foundation
5
+ * Copyright 2020 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -19,110 +19,99 @@
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;
27
+ exports.PDFNetworkStream = void 0;
28
28
 
29
- var _regenerator = require('babel-runtime/regenerator');
29
+ var _util = require("../shared/util.js");
30
30
 
31
- var _regenerator2 = _interopRequireDefault(_regenerator);
32
-
33
- var _util = require('../shared/util');
34
-
35
- var _network_utils = require('./network_utils');
36
-
37
- var _global_scope = require('../shared/global_scope');
38
-
39
- var _global_scope2 = _interopRequireDefault(_global_scope);
40
-
41
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
42
-
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"); }); }; }
31
+ var _network_utils = require("./network_utils.js");
44
32
 
45
33
  ;
46
- var OK_RESPONSE = 200;
47
- var PARTIAL_CONTENT_RESPONSE = 206;
48
- function NetworkManager(url, args) {
49
- this.url = url;
50
- args = args || {};
51
- this.isHttp = /^https?:/i.test(url);
52
- this.httpHeaders = this.isHttp && args.httpHeaders || {};
53
- this.withCredentials = args.withCredentials || false;
54
- this.getXhr = args.getXhr || function NetworkManager_getXhr() {
55
- return new XMLHttpRequest();
56
- };
57
- this.currXhrId = 0;
58
- this.pendingRequests = Object.create(null);
59
- this.loadedRequests = Object.create(null);
60
- }
34
+ const OK_RESPONSE = 200;
35
+ const PARTIAL_CONTENT_RESPONSE = 206;
36
+
61
37
  function getArrayBuffer(xhr) {
62
- var data = xhr.response;
63
- if (typeof data !== 'string') {
38
+ const data = xhr.response;
39
+
40
+ if (typeof data !== "string") {
64
41
  return data;
65
42
  }
66
- var array = (0, _util.stringToBytes)(data);
43
+
44
+ const array = (0, _util.stringToBytes)(data);
67
45
  return array.buffer;
68
46
  }
69
- var supportsMozChunked = function supportsMozChunkedClosure() {
70
- try {
71
- var x = new XMLHttpRequest();
72
- x.open('GET', _global_scope2.default.location.href);
73
- x.responseType = 'moz-chunked-arraybuffer';
74
- return x.responseType === 'moz-chunked-arraybuffer';
75
- } catch (e) {
76
- return false;
47
+
48
+ class NetworkManager {
49
+ constructor(url, args) {
50
+ this.url = url;
51
+ args = args || {};
52
+ this.isHttp = /^https?:/i.test(url);
53
+ this.httpHeaders = this.isHttp && args.httpHeaders || {};
54
+ this.withCredentials = args.withCredentials || false;
55
+
56
+ this.getXhr = args.getXhr || function NetworkManager_getXhr() {
57
+ return new XMLHttpRequest();
58
+ };
59
+
60
+ this.currXhrId = 0;
61
+ this.pendingRequests = Object.create(null);
77
62
  }
78
- }();
79
- NetworkManager.prototype = {
80
- requestRange: function NetworkManager_requestRange(begin, end, listeners) {
81
- var args = {
82
- begin: begin,
83
- end: end
63
+
64
+ requestRange(begin, end, listeners) {
65
+ const args = {
66
+ begin,
67
+ end
84
68
  };
85
- for (var prop in listeners) {
69
+
70
+ for (const prop in listeners) {
86
71
  args[prop] = listeners[prop];
87
72
  }
73
+
88
74
  return this.request(args);
89
- },
90
- requestFull: function NetworkManager_requestFull(listeners) {
75
+ }
76
+
77
+ requestFull(listeners) {
91
78
  return this.request(listeners);
92
- },
93
- request: function NetworkManager_request(args) {
94
- var xhr = this.getXhr();
95
- var xhrId = this.currXhrId++;
96
- var pendingRequest = this.pendingRequests[xhrId] = { xhr: xhr };
97
- xhr.open('GET', this.url);
79
+ }
80
+
81
+ request(args) {
82
+ const xhr = this.getXhr();
83
+ const xhrId = this.currXhrId++;
84
+ const pendingRequest = this.pendingRequests[xhrId] = {
85
+ xhr
86
+ };
87
+ xhr.open("GET", this.url);
98
88
  xhr.withCredentials = this.withCredentials;
99
- for (var property in this.httpHeaders) {
100
- var value = this.httpHeaders[property];
101
- if (typeof value === 'undefined') {
89
+
90
+ for (const property in this.httpHeaders) {
91
+ const value = this.httpHeaders[property];
92
+
93
+ if (typeof value === "undefined") {
102
94
  continue;
103
95
  }
96
+
104
97
  xhr.setRequestHeader(property, value);
105
98
  }
106
- if (this.isHttp && 'begin' in args && 'end' in args) {
107
- var rangeStr = args.begin + '-' + (args.end - 1);
108
- xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
109
- pendingRequest.expectedStatus = 206;
110
- } else {
111
- pendingRequest.expectedStatus = 200;
112
- }
113
- var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
114
- if (useMozChunkedLoading) {
115
- xhr.responseType = 'moz-chunked-arraybuffer';
116
- pendingRequest.onProgressiveData = args.onProgressiveData;
117
- pendingRequest.mozChunked = true;
99
+
100
+ if (this.isHttp && "begin" in args && "end" in args) {
101
+ xhr.setRequestHeader("Range", `bytes=${args.begin}-${args.end - 1}`);
102
+ pendingRequest.expectedStatus = PARTIAL_CONTENT_RESPONSE;
118
103
  } else {
119
- xhr.responseType = 'arraybuffer';
104
+ pendingRequest.expectedStatus = OK_RESPONSE;
120
105
  }
106
+
107
+ xhr.responseType = "arraybuffer";
108
+
121
109
  if (args.onError) {
122
110
  xhr.onerror = function (evt) {
123
111
  args.onError(xhr.status);
124
112
  };
125
113
  }
114
+
126
115
  xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
127
116
  xhr.onprogress = this.onProgress.bind(this, xhrId);
128
117
  pendingRequest.onHeadersReceived = args.onHeadersReceived;
@@ -131,355 +120,378 @@ NetworkManager.prototype = {
131
120
  pendingRequest.onProgress = args.onProgress;
132
121
  xhr.send(null);
133
122
  return xhrId;
134
- },
135
- onProgress: function NetworkManager_onProgress(xhrId, evt) {
136
- var pendingRequest = this.pendingRequests[xhrId];
123
+ }
124
+
125
+ onProgress(xhrId, evt) {
126
+ const pendingRequest = this.pendingRequests[xhrId];
127
+
137
128
  if (!pendingRequest) {
138
129
  return;
139
130
  }
140
- if (pendingRequest.mozChunked) {
141
- var chunk = getArrayBuffer(pendingRequest.xhr);
142
- pendingRequest.onProgressiveData(chunk);
143
- }
144
- var onProgress = pendingRequest.onProgress;
145
- if (onProgress) {
146
- onProgress(evt);
131
+
132
+ if (pendingRequest.onProgress) {
133
+ pendingRequest.onProgress(evt);
147
134
  }
148
- },
149
- onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
150
- var pendingRequest = this.pendingRequests[xhrId];
135
+ }
136
+
137
+ onStateChange(xhrId, evt) {
138
+ const pendingRequest = this.pendingRequests[xhrId];
139
+
151
140
  if (!pendingRequest) {
152
141
  return;
153
142
  }
154
- var xhr = pendingRequest.xhr;
143
+
144
+ const xhr = pendingRequest.xhr;
145
+
155
146
  if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
156
147
  pendingRequest.onHeadersReceived();
157
148
  delete pendingRequest.onHeadersReceived;
158
149
  }
150
+
159
151
  if (xhr.readyState !== 4) {
160
152
  return;
161
153
  }
154
+
162
155
  if (!(xhrId in this.pendingRequests)) {
163
156
  return;
164
157
  }
158
+
165
159
  delete this.pendingRequests[xhrId];
160
+
166
161
  if (xhr.status === 0 && this.isHttp) {
167
162
  if (pendingRequest.onError) {
168
163
  pendingRequest.onError(xhr.status);
169
164
  }
165
+
170
166
  return;
171
167
  }
172
- var xhrStatus = xhr.status || OK_RESPONSE;
173
- var ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
168
+
169
+ const xhrStatus = xhr.status || OK_RESPONSE;
170
+ const ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
171
+
174
172
  if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
175
173
  if (pendingRequest.onError) {
176
174
  pendingRequest.onError(xhr.status);
177
175
  }
176
+
178
177
  return;
179
178
  }
180
- this.loadedRequests[xhrId] = true;
181
- var chunk = getArrayBuffer(xhr);
179
+
180
+ const chunk = getArrayBuffer(xhr);
181
+
182
182
  if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
183
- var rangeHeader = xhr.getResponseHeader('Content-Range');
184
- var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
185
- var begin = parseInt(matches[1], 10);
183
+ const rangeHeader = xhr.getResponseHeader("Content-Range");
184
+ const matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
186
185
  pendingRequest.onDone({
187
- begin: begin,
188
- chunk: chunk
186
+ begin: parseInt(matches[1], 10),
187
+ chunk
189
188
  });
190
- } else if (pendingRequest.onProgressiveData) {
191
- pendingRequest.onDone(null);
192
189
  } else if (chunk) {
193
190
  pendingRequest.onDone({
194
191
  begin: 0,
195
- chunk: chunk
192
+ chunk
196
193
  });
197
194
  } else if (pendingRequest.onError) {
198
195
  pendingRequest.onError(xhr.status);
199
196
  }
200
- },
201
- hasPendingRequests: function NetworkManager_hasPendingRequests() {
202
- for (var xhrId in this.pendingRequests) {
197
+ }
198
+
199
+ hasPendingRequests() {
200
+ for (const xhrId in this.pendingRequests) {
203
201
  return true;
204
202
  }
203
+
205
204
  return false;
206
- },
207
- getRequestXhr: function NetworkManager_getXhr(xhrId) {
205
+ }
206
+
207
+ getRequestXhr(xhrId) {
208
208
  return this.pendingRequests[xhrId].xhr;
209
- },
210
- isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
211
- return !!this.pendingRequests[xhrId].onProgressiveData;
212
- },
213
- isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
209
+ }
210
+
211
+ isPendingRequest(xhrId) {
214
212
  return xhrId in this.pendingRequests;
215
- },
216
- isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
217
- return xhrId in this.loadedRequests;
218
- },
219
- abortAllRequests: function NetworkManager_abortAllRequests() {
220
- for (var xhrId in this.pendingRequests) {
213
+ }
214
+
215
+ abortAllRequests() {
216
+ for (const xhrId in this.pendingRequests) {
221
217
  this.abortRequest(xhrId | 0);
222
218
  }
223
- },
224
- abortRequest: function NetworkManager_abortRequest(xhrId) {
225
- var xhr = this.pendingRequests[xhrId].xhr;
219
+ }
220
+
221
+ abortRequest(xhrId) {
222
+ const xhr = this.pendingRequests[xhrId].xhr;
226
223
  delete this.pendingRequests[xhrId];
227
224
  xhr.abort();
228
225
  }
229
- };
230
- function PDFNetworkStream(source) {
231
- this._source = source;
232
- this._manager = new NetworkManager(source.url, {
233
- httpHeaders: source.httpHeaders,
234
- withCredentials: source.withCredentials
235
- });
236
- this._rangeChunkSize = source.rangeChunkSize;
237
- this._fullRequestReader = null;
238
- this._rangeRequestReaders = [];
226
+
239
227
  }
240
- PDFNetworkStream.prototype = {
241
- _onRangeRequestReaderClosed: function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
242
- var i = this._rangeRequestReaders.indexOf(reader);
228
+
229
+ class PDFNetworkStream {
230
+ constructor(source) {
231
+ this._source = source;
232
+ this._manager = new NetworkManager(source.url, {
233
+ httpHeaders: source.httpHeaders,
234
+ withCredentials: source.withCredentials
235
+ });
236
+ this._rangeChunkSize = source.rangeChunkSize;
237
+ this._fullRequestReader = null;
238
+ this._rangeRequestReaders = [];
239
+ }
240
+
241
+ _onRangeRequestReaderClosed(reader) {
242
+ const i = this._rangeRequestReaders.indexOf(reader);
243
+
243
244
  if (i >= 0) {
244
245
  this._rangeRequestReaders.splice(i, 1);
245
246
  }
246
- },
247
- getFullReader: function PDFNetworkStream_getFullReader() {
247
+ }
248
+
249
+ getFullReader() {
248
250
  (0, _util.assert)(!this._fullRequestReader);
249
251
  this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source);
250
252
  return this._fullRequestReader;
251
- },
252
- getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
253
- var reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
253
+ }
254
+
255
+ getRangeReader(begin, end) {
256
+ const reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
254
257
  reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
258
+
255
259
  this._rangeRequestReaders.push(reader);
260
+
256
261
  return reader;
257
- },
258
- cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
262
+ }
263
+
264
+ cancelAllRequests(reason) {
259
265
  if (this._fullRequestReader) {
260
266
  this._fullRequestReader.cancel(reason);
261
267
  }
262
- var readers = this._rangeRequestReaders.slice(0);
268
+
269
+ const readers = this._rangeRequestReaders.slice(0);
270
+
263
271
  readers.forEach(function (reader) {
264
272
  reader.cancel(reason);
265
273
  });
266
274
  }
267
- };
268
- function PDFNetworkStreamFullRequestReader(manager, source) {
269
- this._manager = manager;
270
- var args = {
271
- onHeadersReceived: this._onHeadersReceived.bind(this),
272
- onProgressiveData: source.disableStream ? null : this._onProgressiveData.bind(this),
273
- onDone: this._onDone.bind(this),
274
- onError: this._onError.bind(this),
275
- onProgress: this._onProgress.bind(this)
276
- };
277
- this._url = source.url;
278
- this._fullRequestId = manager.requestFull(args);
279
- this._headersReceivedCapability = (0, _util.createPromiseCapability)();
280
- this._disableRange = source.disableRange || false;
281
- this._contentLength = source.length;
282
- this._rangeChunkSize = source.rangeChunkSize;
283
- if (!this._rangeChunkSize && !this._disableRange) {
284
- this._disableRange = true;
285
- }
286
- this._isStreamingSupported = false;
287
- this._isRangeSupported = false;
288
- this._cachedChunks = [];
289
- this._requests = [];
290
- this._done = false;
291
- this._storedError = undefined;
292
- this._filename = null;
293
- this.onProgress = null;
275
+
294
276
  }
295
- PDFNetworkStreamFullRequestReader.prototype = {
296
- _onHeadersReceived: function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
297
- var fullRequestXhrId = this._fullRequestId;
298
- var fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
299
- var getResponseHeader = function getResponseHeader(name) {
277
+
278
+ exports.PDFNetworkStream = PDFNetworkStream;
279
+
280
+ class PDFNetworkStreamFullRequestReader {
281
+ constructor(manager, source) {
282
+ this._manager = manager;
283
+ const args = {
284
+ onHeadersReceived: this._onHeadersReceived.bind(this),
285
+ onDone: this._onDone.bind(this),
286
+ onError: this._onError.bind(this),
287
+ onProgress: this._onProgress.bind(this)
288
+ };
289
+ this._url = source.url;
290
+ this._fullRequestId = manager.requestFull(args);
291
+ this._headersReceivedCapability = (0, _util.createPromiseCapability)();
292
+ this._disableRange = source.disableRange || false;
293
+ this._contentLength = source.length;
294
+ this._rangeChunkSize = source.rangeChunkSize;
295
+
296
+ if (!this._rangeChunkSize && !this._disableRange) {
297
+ this._disableRange = true;
298
+ }
299
+
300
+ this._isStreamingSupported = false;
301
+ this._isRangeSupported = false;
302
+ this._cachedChunks = [];
303
+ this._requests = [];
304
+ this._done = false;
305
+ this._storedError = undefined;
306
+ this._filename = null;
307
+ this.onProgress = null;
308
+ }
309
+
310
+ _onHeadersReceived() {
311
+ const fullRequestXhrId = this._fullRequestId;
312
+
313
+ const fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
314
+
315
+ const getResponseHeader = name => {
300
316
  return fullRequestXhr.getResponseHeader(name);
301
317
  };
302
318
 
303
- var _validateRangeRequest = (0, _network_utils.validateRangeRequestCapabilities)({
304
- getResponseHeader: getResponseHeader,
319
+ const {
320
+ allowRangeRequests,
321
+ suggestedLength
322
+ } = (0, _network_utils.validateRangeRequestCapabilities)({
323
+ getResponseHeader,
305
324
  isHttp: this._manager.isHttp,
306
325
  rangeChunkSize: this._rangeChunkSize,
307
326
  disableRange: this._disableRange
308
- }),
309
- allowRangeRequests = _validateRangeRequest.allowRangeRequests,
310
- suggestedLength = _validateRangeRequest.suggestedLength;
327
+ });
311
328
 
312
329
  if (allowRangeRequests) {
313
330
  this._isRangeSupported = true;
314
331
  }
332
+
315
333
  this._contentLength = suggestedLength || this._contentLength;
316
334
  this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
317
- var networkManager = this._manager;
318
- if (networkManager.isStreamingRequest(fullRequestXhrId)) {
319
- this._isStreamingSupported = true;
320
- } else if (this._isRangeSupported) {
321
- networkManager.abortRequest(fullRequestXhrId);
335
+
336
+ if (this._isRangeSupported) {
337
+ this._manager.abortRequest(fullRequestXhrId);
322
338
  }
339
+
323
340
  this._headersReceivedCapability.resolve();
324
- },
325
- _onProgressiveData: function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
326
- if (this._requests.length > 0) {
327
- var requestCapability = this._requests.shift();
328
- requestCapability.resolve({
329
- value: chunk,
330
- done: false
331
- });
332
- } else {
333
- this._cachedChunks.push(chunk);
334
- }
335
- },
336
- _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
341
+ }
342
+
343
+ _onDone(args) {
337
344
  if (args) {
338
- this._onProgressiveData(args.chunk);
345
+ if (this._requests.length > 0) {
346
+ const requestCapability = this._requests.shift();
347
+
348
+ requestCapability.resolve({
349
+ value: args.chunk,
350
+ done: false
351
+ });
352
+ } else {
353
+ this._cachedChunks.push(args.chunk);
354
+ }
339
355
  }
356
+
340
357
  this._done = true;
358
+
341
359
  if (this._cachedChunks.length > 0) {
342
360
  return;
343
361
  }
362
+
344
363
  this._requests.forEach(function (requestCapability) {
345
364
  requestCapability.resolve({
346
365
  value: undefined,
347
366
  done: true
348
367
  });
349
368
  });
369
+
350
370
  this._requests = [];
351
- },
352
- _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
353
- var url = this._url;
354
- var exception = (0, _network_utils.createResponseStatusError)(status, url);
371
+ }
372
+
373
+ _onError(status) {
374
+ const url = this._url;
375
+ const exception = (0, _network_utils.createResponseStatusError)(status, url);
355
376
  this._storedError = exception;
377
+
356
378
  this._headersReceivedCapability.reject(exception);
379
+
357
380
  this._requests.forEach(function (requestCapability) {
358
381
  requestCapability.reject(exception);
359
382
  });
383
+
360
384
  this._requests = [];
361
385
  this._cachedChunks = [];
362
- },
363
- _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
386
+ }
387
+
388
+ _onProgress(data) {
364
389
  if (this.onProgress) {
365
390
  this.onProgress({
366
391
  loaded: data.loaded,
367
392
  total: data.lengthComputable ? data.total : this._contentLength
368
393
  });
369
394
  }
370
- },
395
+ }
396
+
371
397
  get filename() {
372
398
  return this._filename;
373
- },
399
+ }
400
+
374
401
  get isRangeSupported() {
375
402
  return this._isRangeSupported;
376
- },
403
+ }
404
+
377
405
  get isStreamingSupported() {
378
406
  return this._isStreamingSupported;
379
- },
407
+ }
408
+
380
409
  get contentLength() {
381
410
  return this._contentLength;
382
- },
411
+ }
412
+
383
413
  get headersReady() {
384
414
  return this._headersReceivedCapability.promise;
385
- },
386
- read: function () {
387
- var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
388
- var chunk, requestCapability;
389
- return _regenerator2.default.wrap(function _callee$(_context) {
390
- while (1) {
391
- switch (_context.prev = _context.next) {
392
- case 0:
393
- if (!this._storedError) {
394
- _context.next = 2;
395
- break;
396
- }
397
-
398
- throw this._storedError;
399
-
400
- case 2:
401
- if (!(this._cachedChunks.length > 0)) {
402
- _context.next = 5;
403
- break;
404
- }
405
-
406
- chunk = this._cachedChunks.shift();
407
- return _context.abrupt('return', {
408
- value: chunk,
409
- done: false
410
- });
411
-
412
- case 5:
413
- if (!this._done) {
414
- _context.next = 7;
415
- break;
416
- }
417
-
418
- return _context.abrupt('return', {
419
- value: undefined,
420
- done: true
421
- });
422
-
423
- case 7:
424
- requestCapability = (0, _util.createPromiseCapability)();
425
-
426
- this._requests.push(requestCapability);
427
- return _context.abrupt('return', requestCapability.promise);
428
-
429
- case 10:
430
- case 'end':
431
- return _context.stop();
432
- }
433
- }
434
- }, _callee, this);
435
- }));
436
-
437
- function read() {
438
- return _ref.apply(this, arguments);
439
- }
440
-
441
- return read;
442
- }(),
443
-
444
- cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
415
+ }
416
+
417
+ async read() {
418
+ if (this._storedError) {
419
+ throw this._storedError;
420
+ }
421
+
422
+ if (this._cachedChunks.length > 0) {
423
+ const chunk = this._cachedChunks.shift();
424
+
425
+ return {
426
+ value: chunk,
427
+ done: false
428
+ };
429
+ }
430
+
431
+ if (this._done) {
432
+ return {
433
+ value: undefined,
434
+ done: true
435
+ };
436
+ }
437
+
438
+ const requestCapability = (0, _util.createPromiseCapability)();
439
+
440
+ this._requests.push(requestCapability);
441
+
442
+ return requestCapability.promise;
443
+ }
444
+
445
+ cancel(reason) {
445
446
  this._done = true;
447
+
446
448
  this._headersReceivedCapability.reject(reason);
449
+
447
450
  this._requests.forEach(function (requestCapability) {
448
451
  requestCapability.resolve({
449
452
  value: undefined,
450
453
  done: true
451
454
  });
452
455
  });
456
+
453
457
  this._requests = [];
458
+
454
459
  if (this._manager.isPendingRequest(this._fullRequestId)) {
455
460
  this._manager.abortRequest(this._fullRequestId);
456
461
  }
462
+
457
463
  this._fullRequestReader = null;
458
464
  }
459
- };
460
- function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
461
- this._manager = manager;
462
- var args = {
463
- onDone: this._onDone.bind(this),
464
- onProgress: this._onProgress.bind(this)
465
- };
466
- this._requestId = manager.requestRange(begin, end, args);
467
- this._requests = [];
468
- this._queuedChunk = null;
469
- this._done = false;
470
- this.onProgress = null;
471
- this.onClosed = null;
465
+
472
466
  }
473
- PDFNetworkStreamRangeRequestReader.prototype = {
474
- _close: function PDFNetworkStreamRangeRequestReader_close() {
467
+
468
+ class PDFNetworkStreamRangeRequestReader {
469
+ constructor(manager, begin, end) {
470
+ this._manager = manager;
471
+ const args = {
472
+ onDone: this._onDone.bind(this),
473
+ onProgress: this._onProgress.bind(this)
474
+ };
475
+ this._requestId = manager.requestRange(begin, end, args);
476
+ this._requests = [];
477
+ this._queuedChunk = null;
478
+ this._done = false;
479
+ this.onProgress = null;
480
+ this.onClosed = null;
481
+ }
482
+
483
+ _close() {
475
484
  if (this.onClosed) {
476
485
  this.onClosed(this);
477
486
  }
478
- },
479
- _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
480
- var chunk = data.chunk;
487
+ }
488
+
489
+ _onDone(data) {
490
+ const chunk = data.chunk;
491
+
481
492
  if (this._requests.length > 0) {
482
- var requestCapability = this._requests.shift();
493
+ const requestCapability = this._requests.shift();
494
+
483
495
  requestCapability.resolve({
484
496
  value: chunk,
485
497
  done: false
@@ -487,90 +499,74 @@ PDFNetworkStreamRangeRequestReader.prototype = {
487
499
  } else {
488
500
  this._queuedChunk = chunk;
489
501
  }
502
+
490
503
  this._done = true;
504
+
491
505
  this._requests.forEach(function (requestCapability) {
492
506
  requestCapability.resolve({
493
507
  value: undefined,
494
508
  done: true
495
509
  });
496
510
  });
511
+
497
512
  this._requests = [];
513
+
498
514
  this._close();
499
- },
500
- _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
515
+ }
516
+
517
+ _onProgress(evt) {
501
518
  if (!this.isStreamingSupported && this.onProgress) {
502
- this.onProgress({ loaded: evt.loaded });
519
+ this.onProgress({
520
+ loaded: evt.loaded
521
+ });
503
522
  }
504
- },
523
+ }
524
+
505
525
  get isStreamingSupported() {
506
526
  return false;
507
- },
508
- read: function () {
509
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
510
- var chunk, requestCapability;
511
- return _regenerator2.default.wrap(function _callee2$(_context2) {
512
- while (1) {
513
- switch (_context2.prev = _context2.next) {
514
- case 0:
515
- if (!(this._queuedChunk !== null)) {
516
- _context2.next = 4;
517
- break;
518
- }
519
-
520
- chunk = this._queuedChunk;
521
-
522
- this._queuedChunk = null;
523
- return _context2.abrupt('return', {
524
- value: chunk,
525
- done: false
526
- });
527
-
528
- case 4:
529
- if (!this._done) {
530
- _context2.next = 6;
531
- break;
532
- }
533
-
534
- return _context2.abrupt('return', {
535
- value: undefined,
536
- done: true
537
- });
538
-
539
- case 6:
540
- requestCapability = (0, _util.createPromiseCapability)();
541
-
542
- this._requests.push(requestCapability);
543
- return _context2.abrupt('return', requestCapability.promise);
544
-
545
- case 9:
546
- case 'end':
547
- return _context2.stop();
548
- }
549
- }
550
- }, _callee2, this);
551
- }));
552
-
553
- function read() {
554
- return _ref2.apply(this, arguments);
555
- }
556
-
557
- return read;
558
- }(),
559
-
560
- cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
527
+ }
528
+
529
+ async read() {
530
+ if (this._queuedChunk !== null) {
531
+ const chunk = this._queuedChunk;
532
+ this._queuedChunk = null;
533
+ return {
534
+ value: chunk,
535
+ done: false
536
+ };
537
+ }
538
+
539
+ if (this._done) {
540
+ return {
541
+ value: undefined,
542
+ done: true
543
+ };
544
+ }
545
+
546
+ const requestCapability = (0, _util.createPromiseCapability)();
547
+
548
+ this._requests.push(requestCapability);
549
+
550
+ return requestCapability.promise;
551
+ }
552
+
553
+ cancel(reason) {
561
554
  this._done = true;
555
+
562
556
  this._requests.forEach(function (requestCapability) {
563
557
  requestCapability.resolve({
564
558
  value: undefined,
565
559
  done: true
566
560
  });
567
561
  });
562
+
568
563
  this._requests = [];
564
+
569
565
  if (this._manager.isPendingRequest(this._requestId)) {
570
566
  this._manager.abortRequest(this._requestId);
571
567
  }
568
+
572
569
  this._close();
573
570
  }
574
- };
575
- exports.PDFNetworkStream = PDFNetworkStream;
576
- exports.NetworkManager = NetworkManager;
571
+
572
+ }