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