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.
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +6499 -17971
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +19303 -29896
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25473 -0
- package/es5/build/pdf.js.map +1 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +57878 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/images/texture.png +0 -0
- package/es5/web/pdf_viewer.css +407 -0
- package/es5/web/pdf_viewer.js +7757 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1333 -4839
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +683 -1066
- package/lib/core/arithmetic_decoder.js +81 -97
- package/lib/core/bidi.js +54 -46
- package/lib/core/ccitt.js +88 -81
- package/lib/core/ccitt_stream.js +15 -14
- package/lib/core/cff_parser.js +196 -193
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +441 -569
- package/lib/core/cmap.js +220 -279
- package/lib/core/colorspace.js +699 -863
- package/lib/core/core_utils.js +59 -80
- package/lib/core/crypto.js +379 -437
- package/lib/core/document.js +564 -673
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +983 -889
- package/lib/core/font_renderer.js +128 -171
- package/lib/core/fonts.js +451 -400
- package/lib/core/function.js +289 -285
- package/lib/core/glyphlist.js +4527 -4527
- package/lib/core/image.js +138 -117
- package/lib/core/image_utils.js +46 -63
- package/lib/core/jbig2.js +324 -332
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +133 -24
- package/lib/core/jpg.js +238 -210
- package/lib/core/jpx.js +158 -157
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2928 -2928
- package/lib/core/murmurhash3.js +87 -102
- package/lib/core/obj.js +1111 -1302
- package/lib/core/operator_list.js +55 -42
- package/lib/core/parser.js +956 -987
- package/lib/core/pattern.js +69 -69
- package/lib/core/pdf_manager.js +149 -316
- package/lib/core/primitives.js +45 -77
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +83 -77
- package/lib/core/type1_parser.js +78 -68
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +148 -196
- package/lib/core/worker_stream.js +101 -210
- package/lib/display/annotation_layer.js +733 -1155
- package/lib/display/api.js +1539 -1928
- package/lib/display/api_compatibility.js +10 -8
- package/lib/display/canvas.js +159 -158
- package/lib/display/content_disposition.js +36 -55
- package/lib/display/display_utils.js +298 -551
- package/lib/display/fetch_stream.js +181 -305
- package/lib/display/font_loader.js +273 -416
- package/lib/display/metadata.js +86 -98
- package/lib/display/network.js +376 -511
- package/lib/display/network_utils.js +20 -19
- package/lib/display/node_stream.js +276 -460
- package/lib/display/pattern_helper.js +76 -44
- package/lib/display/svg.js +1137 -1405
- package/lib/display/text_layer.js +75 -82
- package/lib/display/transport_stream.js +236 -374
- package/lib/display/webgl.js +70 -83
- package/lib/display/worker_options.js +3 -3
- package/lib/display/xml_parser.js +303 -392
- package/lib/examples/node/domstubs.js +37 -37
- package/lib/pdf.js +22 -21
- package/lib/pdf.worker.js +5 -5
- package/lib/shared/compatibility.js +2 -251
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +222 -194
- package/lib/shared/util.js +269 -405
- package/lib/test/unit/annotation_spec.js +1089 -1014
- package/lib/test/unit/api_spec.js +617 -544
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +63 -62
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +84 -86
- package/lib/test/unit/colorspace_spec.js +154 -154
- package/lib/test/unit/core_utils_spec.js +125 -105
- package/lib/test/unit/crypto_spec.js +181 -181
- package/lib/test/unit/custom_spec.js +22 -24
- package/lib/test/unit/display_svg_spec.js +35 -36
- package/lib/test/unit/display_utils_spec.js +139 -149
- package/lib/test/unit/document_spec.js +16 -16
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +81 -95
- package/lib/test/unit/fetch_stream_spec.js +30 -30
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +48 -32
- package/lib/test/unit/message_handler_spec.js +172 -162
- package/lib/test/unit/metadata_spec.js +69 -69
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +12 -12
- package/lib/test/unit/network_utils_spec.js +152 -152
- package/lib/test/unit/node_stream_spec.js +74 -90
- package/lib/test/unit/parser_spec.js +107 -113
- package/lib/test/unit/pdf_find_controller_spec.js +55 -86
- package/lib/test/unit/pdf_find_utils_spec.js +32 -32
- package/lib/test/unit/pdf_history_spec.js +32 -32
- package/lib/test/unit/primitives_spec.js +117 -115
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +119 -285
- package/lib/test/unit/testreporter.js +19 -19
- package/lib/test/unit/type1_parser_spec.js +41 -41
- package/lib/test/unit/ui_utils_spec.js +318 -426
- package/lib/test/unit/unicode_spec.js +42 -42
- package/lib/test/unit/util_spec.js +122 -143
- package/lib/web/annotation_layer_builder.js +66 -103
- package/lib/web/app.js +1166 -1196
- package/lib/web/app_options.js +61 -77
- package/lib/web/base_viewer.js +804 -850
- package/lib/web/chromecom.js +164 -249
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +38 -57
- package/lib/web/firefox_print_service.js +35 -30
- package/lib/web/firefoxcom.js +175 -374
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +30 -30
- package/lib/web/interfaces.js +80 -258
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +105 -130
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +227 -376
- package/lib/web/pdf_find_bar.js +137 -171
- package/lib/web/pdf_find_controller.js +492 -549
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +395 -406
- package/lib/web/pdf_link_service.js +302 -349
- package/lib/web/pdf_outline_viewer.js +148 -209
- package/lib/web/pdf_page_view.js +449 -507
- package/lib/web/pdf_presentation_mode.js +304 -357
- package/lib/web/pdf_print_service.js +90 -104
- package/lib/web/pdf_rendering_queue.js +87 -108
- package/lib/web/pdf_sidebar.js +264 -304
- package/lib/web/pdf_sidebar_resizer.js +92 -119
- package/lib/web/pdf_single_page_viewer.js +77 -126
- package/lib/web/pdf_thumbnail_view.js +276 -297
- package/lib/web/pdf_thumbnail_viewer.js +186 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +66 -273
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +284 -317
- package/lib/web/toolbar.js +216 -211
- package/lib/web/ui_utils.js +303 -404
- package/lib/web/view_history.js +49 -222
- package/lib/web/viewer_compatibility.js +7 -5
- package/package.json +2 -9
- package/web/pdf_viewer.css +25 -18
- package/web/pdf_viewer.js +3481 -4764
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/lib/shared/streams_polyfill.js +0 -43
package/lib/display/network.js
CHANGED
@@ -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
|
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
|
29
|
+
var _util = require("../shared/util.js");
|
30
30
|
|
31
|
-
var
|
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
|
-
|
49
|
-
|
34
|
+
const OK_RESPONSE = 200;
|
35
|
+
const PARTIAL_CONTENT_RESPONSE = 206;
|
50
36
|
|
51
37
|
function getArrayBuffer(xhr) {
|
52
|
-
|
38
|
+
const data = xhr.response;
|
53
39
|
|
54
|
-
if (typeof data !==
|
40
|
+
if (typeof data !== "string") {
|
55
41
|
return data;
|
56
42
|
}
|
57
43
|
|
58
|
-
|
44
|
+
const array = (0, _util.stringToBytes)(data);
|
59
45
|
return array.buffer;
|
60
46
|
}
|
61
47
|
|
62
|
-
|
63
|
-
|
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
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
-
|
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
|
-
|
116
|
-
|
117
|
-
}
|
74
|
+
return this.request(args);
|
75
|
+
}
|
118
76
|
|
119
|
-
|
120
|
-
|
77
|
+
requestFull(listeners) {
|
78
|
+
return this.request(listeners);
|
79
|
+
}
|
121
80
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|
-
|
90
|
+
for (const property in this.httpHeaders) {
|
91
|
+
const value = this.httpHeaders[property];
|
130
92
|
|
131
|
-
if (
|
132
|
-
|
133
|
-
args.onError(xhr.status);
|
134
|
-
};
|
93
|
+
if (typeof value === "undefined") {
|
94
|
+
continue;
|
135
95
|
}
|
136
96
|
|
137
|
-
xhr.
|
138
|
-
|
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
|
-
|
156
|
-
|
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
|
-
|
165
|
-
return;
|
166
|
-
}
|
107
|
+
xhr.responseType = "arraybuffer";
|
167
108
|
|
168
|
-
|
109
|
+
if (args.onError) {
|
110
|
+
xhr.onerror = function (evt) {
|
111
|
+
args.onError(xhr.status);
|
112
|
+
};
|
113
|
+
}
|
169
114
|
|
170
|
-
|
171
|
-
|
172
|
-
|
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
|
-
|
176
|
-
|
177
|
-
}
|
125
|
+
onProgress(xhrId, evt) {
|
126
|
+
const pendingRequest = this.pendingRequests[xhrId];
|
178
127
|
|
179
|
-
|
180
|
-
|
181
|
-
|
128
|
+
if (!pendingRequest) {
|
129
|
+
return;
|
130
|
+
}
|
182
131
|
|
183
|
-
|
132
|
+
if (pendingRequest.onProgress) {
|
133
|
+
pendingRequest.onProgress(evt);
|
134
|
+
}
|
135
|
+
}
|
184
136
|
|
185
|
-
|
186
|
-
|
187
|
-
pendingRequest.onError(xhr.status);
|
188
|
-
}
|
137
|
+
onStateChange(xhrId, evt) {
|
138
|
+
const pendingRequest = this.pendingRequests[xhrId];
|
189
139
|
|
190
|
-
|
191
|
-
|
140
|
+
if (!pendingRequest) {
|
141
|
+
return;
|
142
|
+
}
|
192
143
|
|
193
|
-
|
194
|
-
var ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
|
144
|
+
const xhr = pendingRequest.xhr;
|
195
145
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
146
|
+
if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
|
147
|
+
pendingRequest.onHeadersReceived();
|
148
|
+
delete pendingRequest.onHeadersReceived;
|
149
|
+
}
|
200
150
|
|
201
|
-
|
202
|
-
|
151
|
+
if (xhr.readyState !== 4) {
|
152
|
+
return;
|
153
|
+
}
|
203
154
|
|
204
|
-
|
155
|
+
if (!(xhrId in this.pendingRequests)) {
|
156
|
+
return;
|
157
|
+
}
|
205
158
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
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
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
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
|
230
|
-
}
|
231
|
-
}, {
|
232
|
-
key: "getRequestXhr",
|
233
|
-
value: function getRequestXhr(xhrId) {
|
234
|
-
return this.pendingRequests[xhrId].xhr;
|
177
|
+
return;
|
235
178
|
}
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
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
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
}
|
197
|
+
}
|
198
|
+
|
199
|
+
hasPendingRequests() {
|
200
|
+
for (const xhrId in this.pendingRequests) {
|
201
|
+
return true;
|
247
202
|
}
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
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
|
-
|
258
|
-
|
221
|
+
abortRequest(xhrId) {
|
222
|
+
const xhr = this.pendingRequests[xhrId].xhr;
|
223
|
+
delete this.pendingRequests[xhrId];
|
224
|
+
xhr.abort();
|
225
|
+
}
|
259
226
|
|
260
|
-
|
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
|
-
|
277
|
-
|
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
|
-
|
282
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
259
|
+
this._rangeRequestReaders.push(reader);
|
310
260
|
|
311
|
-
|
312
|
-
|
313
|
-
|
261
|
+
return reader;
|
262
|
+
}
|
263
|
+
|
264
|
+
cancelAllRequests(reason) {
|
265
|
+
if (this._fullRequestReader) {
|
266
|
+
this._fullRequestReader.cancel(reason);
|
314
267
|
}
|
315
|
-
}]);
|
316
268
|
|
317
|
-
|
318
|
-
}();
|
269
|
+
const readers = this._rangeRequestReaders.slice(0);
|
319
270
|
|
320
|
-
|
271
|
+
readers.forEach(function (reader) {
|
272
|
+
reader.cancel(reason);
|
273
|
+
});
|
274
|
+
}
|
275
|
+
|
276
|
+
}
|
321
277
|
|
322
|
-
|
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
|
-
|
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
|
-
|
357
|
-
|
358
|
-
value: function _onHeadersReceived() {
|
359
|
-
var fullRequestXhrId = this._fullRequestId;
|
310
|
+
_onHeadersReceived() {
|
311
|
+
const fullRequestXhrId = this._fullRequestId;
|
360
312
|
|
361
|
-
|
313
|
+
const fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
|
362
314
|
|
363
|
-
|
364
|
-
|
365
|
-
|
315
|
+
const getResponseHeader = name => {
|
316
|
+
return fullRequestXhr.getResponseHeader(name);
|
317
|
+
};
|
366
318
|
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
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
|
-
|
381
|
-
this.
|
329
|
+
if (allowRangeRequests) {
|
330
|
+
this._isRangeSupported = true;
|
331
|
+
}
|
382
332
|
|
383
|
-
|
384
|
-
|
385
|
-
}
|
333
|
+
this._contentLength = suggestedLength || this._contentLength;
|
334
|
+
this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
|
386
335
|
|
387
|
-
|
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
|
-
|
340
|
+
this._headersReceivedCapability.resolve();
|
341
|
+
}
|
406
342
|
|
407
|
-
|
408
|
-
|
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:
|
414
|
-
done:
|
349
|
+
value: args.chunk,
|
350
|
+
done: false
|
415
351
|
});
|
416
|
-
}
|
417
|
-
|
418
|
-
|
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
|
-
|
357
|
+
this._done = true;
|
358
|
+
|
359
|
+
if (this._cachedChunks.length > 0) {
|
360
|
+
return;
|
361
|
+
}
|
428
362
|
|
429
|
-
|
430
|
-
|
363
|
+
this._requests.forEach(function (requestCapability) {
|
364
|
+
requestCapability.resolve({
|
365
|
+
value: undefined,
|
366
|
+
done: true
|
431
367
|
});
|
368
|
+
});
|
432
369
|
|
433
|
-
|
434
|
-
|
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
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
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
|
-
|
378
|
+
this._headersReceivedCapability.reject(exception);
|
514
379
|
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
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
|
-
|
397
|
+
get filename() {
|
398
|
+
return this._filename;
|
399
|
+
}
|
523
400
|
|
524
|
-
|
525
|
-
|
526
|
-
|
401
|
+
get isRangeSupported() {
|
402
|
+
return this._isRangeSupported;
|
403
|
+
}
|
527
404
|
|
528
|
-
|
529
|
-
|
530
|
-
}
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
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
|
-
|
542
|
-
|
543
|
-
|
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
|
-
|
547
|
-
|
548
|
-
|
430
|
+
|
431
|
+
if (this._done) {
|
432
|
+
return {
|
433
|
+
value: undefined,
|
434
|
+
done: true
|
435
|
+
};
|
549
436
|
}
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
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
|
-
|
558
|
-
}
|
463
|
+
this._fullRequestReader = null;
|
464
|
+
}
|
559
465
|
|
560
|
-
|
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
|
-
|
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
|
-
|
580
|
-
|
581
|
-
|
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
|
-
|
592
|
-
|
489
|
+
_onDone(data) {
|
490
|
+
const chunk = data.chunk;
|
593
491
|
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
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
|
-
|
503
|
+
this._done = true;
|
603
504
|
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
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
|
-
|
514
|
+
this._close();
|
515
|
+
}
|
612
516
|
|
613
|
-
|
517
|
+
_onProgress(evt) {
|
518
|
+
if (!this.isStreamingSupported && this.onProgress) {
|
519
|
+
this.onProgress({
|
520
|
+
loaded: evt.loaded
|
521
|
+
});
|
614
522
|
}
|
615
|
-
}
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
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
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
539
|
+
if (this._done) {
|
540
|
+
return {
|
541
|
+
value: undefined,
|
542
|
+
done: true
|
543
|
+
};
|
544
|
+
}
|
683
545
|
|
684
|
-
|
685
|
-
requestCapability.resolve({
|
686
|
-
value: undefined,
|
687
|
-
done: true
|
688
|
-
});
|
689
|
-
});
|
546
|
+
const requestCapability = (0, _util.createPromiseCapability)();
|
690
547
|
|
691
|
-
|
548
|
+
this._requests.push(requestCapability);
|
692
549
|
|
693
|
-
|
694
|
-
|
695
|
-
}
|
550
|
+
return requestCapability.promise;
|
551
|
+
}
|
696
552
|
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
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
|
-
|
707
|
-
}
|
569
|
+
this._close();
|
570
|
+
}
|
571
|
+
|
572
|
+
}
|