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