pdfjs-dist 2.1.266 → 2.5.207

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

Potentially problematic release.


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

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