pdfjs-dist 2.0.550 → 2.3.200
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/bower.json +1 -1
- package/build/pdf.js +21618 -14369
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +22758 -11399
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +1 -1
- package/image_decoders/pdf.image_decoders.js +11500 -0
- package/image_decoders/pdf.image_decoders.js.map +1 -0
- package/image_decoders/pdf.image_decoders.min.js +1 -0
- package/lib/core/annotation.js +767 -258
- package/lib/core/arithmetic_decoder.js +275 -245
- package/lib/core/bidi.js +65 -6
- package/lib/core/ccitt.js +173 -18
- package/lib/core/ccitt_stream.js +15 -6
- package/lib/core/cff_parser.js +433 -61
- package/lib/core/charsets.js +5 -4
- package/lib/core/chunked_stream.js +428 -157
- package/lib/core/cmap.js +326 -87
- package/lib/core/colorspace.js +874 -594
- package/lib/core/core_utils.js +173 -0
- package/lib/core/crypto.js +290 -45
- package/lib/core/document.js +575 -272
- package/lib/core/encodings.js +19 -10
- package/lib/core/evaluator.js +1032 -351
- package/lib/core/font_renderer.js +331 -97
- package/lib/core/fonts.js +813 -196
- package/lib/core/function.js +253 -27
- package/lib/core/glyphlist.js +5 -3
- package/lib/core/image.js +169 -62
- package/lib/core/image_utils.js +111 -0
- package/lib/core/jbig2.js +502 -72
- package/lib/core/jbig2_stream.js +19 -8
- package/lib/core/jpeg_stream.js +38 -13
- package/lib/core/jpg.js +293 -52
- package/lib/core/jpx.js +419 -12
- package/lib/core/jpx_stream.js +18 -6
- package/lib/core/metrics.js +15 -15
- package/lib/core/murmurhash3.js +56 -34
- package/lib/core/obj.js +1368 -500
- package/lib/core/operator_list.js +159 -43
- package/lib/core/parser.js +544 -199
- package/lib/core/pattern.js +170 -21
- package/lib/core/pdf_manager.js +324 -134
- package/lib/core/primitives.js +169 -61
- package/lib/core/ps_parser.js +134 -45
- package/lib/core/standard_fonts.js +17 -17
- package/lib/core/stream.js +327 -34
- package/lib/core/type1_parser.js +148 -8
- package/lib/core/unicode.js +32 -5
- package/lib/core/worker.js +215 -229
- package/lib/core/worker_stream.js +277 -0
- package/lib/display/annotation_layer.js +618 -192
- package/lib/display/api.js +1798 -882
- package/lib/display/api_compatibility.js +5 -10
- package/lib/display/canvas.js +366 -45
- package/lib/display/content_disposition.js +71 -24
- package/lib/display/display_utils.js +777 -0
- package/lib/display/fetch_stream.js +205 -87
- package/lib/display/font_loader.js +468 -236
- package/lib/display/metadata.js +38 -16
- package/lib/display/network.js +635 -428
- package/lib/display/network_utils.js +38 -19
- package/lib/display/node_stream.js +367 -175
- package/lib/display/pattern_helper.js +103 -36
- package/lib/display/svg.js +1232 -519
- package/lib/display/text_layer.js +208 -75
- package/lib/display/transport_stream.js +345 -94
- package/lib/display/webgl.js +64 -18
- package/lib/display/worker_options.js +5 -4
- package/lib/display/xml_parser.js +166 -53
- package/lib/examples/node/domstubs.js +60 -4
- package/lib/pdf.js +35 -14
- package/lib/pdf.worker.js +5 -3
- package/lib/shared/compatibility.js +170 -572
- package/lib/shared/global_scope.js +2 -2
- package/lib/shared/is_node.js +4 -4
- package/lib/shared/message_handler.js +216 -163
- package/lib/shared/streams_polyfill.js +21 -17
- package/lib/shared/util.js +495 -385
- package/lib/test/unit/annotation_spec.js +1464 -401
- package/lib/test/unit/api_spec.js +718 -361
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +54 -11
- package/lib/test/unit/clitests_helper.js +9 -10
- package/lib/test/unit/cmap_spec.js +95 -41
- package/lib/test/unit/colorspace_spec.js +115 -63
- package/lib/test/unit/core_utils_spec.js +191 -0
- package/lib/test/unit/crypto_spec.js +17 -5
- package/lib/test/unit/custom_spec.js +43 -55
- package/lib/test/unit/display_svg_spec.js +34 -18
- package/lib/test/unit/display_utils_spec.js +273 -0
- package/lib/test/unit/document_spec.js +8 -13
- package/lib/test/unit/encodings_spec.js +25 -45
- package/lib/test/unit/evaluator_spec.js +59 -20
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +17 -5
- package/lib/test/unit/jasmine-boot.js +33 -20
- package/lib/test/unit/message_handler_spec.js +30 -13
- package/lib/test/unit/metadata_spec.js +71 -11
- package/lib/test/unit/murmurhash3_spec.js +3 -3
- package/lib/test/unit/network_spec.js +22 -55
- package/lib/test/unit/network_utils_spec.js +105 -14
- package/lib/test/unit/node_stream_spec.js +58 -34
- package/lib/test/unit/parser_spec.js +162 -71
- package/lib/test/unit/pdf_find_controller_spec.js +230 -0
- package/lib/test/unit/pdf_find_utils_spec.js +63 -0
- package/lib/test/unit/pdf_history_spec.js +21 -9
- package/lib/test/unit/primitives_spec.js +55 -22
- package/lib/test/unit/stream_spec.js +12 -4
- package/lib/test/unit/test_utils.js +273 -56
- package/lib/test/unit/testreporter.js +21 -3
- package/lib/test/unit/type1_parser_spec.js +9 -7
- package/lib/test/unit/ui_utils_spec.js +236 -36
- package/lib/test/unit/unicode_spec.js +18 -15
- package/lib/test/unit/util_spec.js +87 -128
- package/lib/web/annotation_layer_builder.js +39 -22
- package/lib/web/app.js +1252 -609
- package/lib/web/app_options.js +103 -65
- package/lib/web/base_viewer.js +522 -242
- package/lib/web/chromecom.js +259 -117
- package/lib/web/debugger.js +166 -22
- package/lib/web/download_manager.js +31 -12
- package/lib/web/firefox_print_service.js +27 -14
- package/lib/web/firefoxcom.js +318 -78
- package/lib/web/genericcom.js +89 -30
- package/lib/web/genericl10n.js +142 -30
- package/lib/web/grab_to_pan.js +28 -4
- package/lib/web/interfaces.js +174 -47
- package/lib/web/overlay_manager.js +235 -85
- package/lib/web/password_prompt.js +22 -14
- package/lib/web/pdf_attachment_viewer.js +38 -18
- package/lib/web/pdf_cursor_tools.js +39 -16
- package/lib/web/pdf_document_properties.js +255 -136
- package/lib/web/pdf_find_bar.js +84 -40
- package/lib/web/pdf_find_controller.js +495 -184
- package/lib/web/pdf_find_utils.js +111 -0
- package/lib/web/pdf_history.js +190 -53
- package/lib/web/pdf_link_service.js +144 -79
- package/lib/web/pdf_outline_viewer.js +124 -47
- package/lib/web/pdf_page_view.js +194 -74
- package/lib/web/pdf_presentation_mode.js +99 -34
- package/lib/web/pdf_print_service.js +59 -13
- package/lib/web/pdf_rendering_queue.js +28 -9
- package/lib/web/pdf_sidebar.js +144 -81
- package/lib/web/pdf_sidebar_resizer.js +42 -16
- package/lib/web/pdf_single_page_viewer.js +74 -66
- package/lib/web/pdf_thumbnail_view.js +104 -33
- package/lib/web/pdf_thumbnail_viewer.js +66 -26
- package/lib/web/pdf_viewer.component.js +112 -32
- package/lib/web/pdf_viewer.js +82 -87
- package/lib/web/preferences.js +284 -91
- package/lib/web/secondary_toolbar.js +132 -59
- package/lib/web/text_layer_builder.js +134 -59
- package/lib/web/toolbar.js +80 -43
- package/lib/web/ui_utils.js +400 -134
- package/lib/web/view_history.js +215 -67
- package/lib/web/viewer_compatibility.js +3 -8
- package/package.json +3 -2
- package/web/pdf_viewer.css +23 -15
- package/web/pdf_viewer.js +3429 -1245
- package/web/pdf_viewer.js.map +1 -1
- package/external/streams/streams-lib.js +0 -3962
- package/lib/display/dom_utils.js +0 -429
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/test/unit/fonts_spec.js +0 -81
- package/lib/web/dom_events.js +0 -137
@@ -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 2019 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,17 +19,29 @@
|
|
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.ChunkedStreamManager = exports.ChunkedStream =
|
27
|
+
exports.ChunkedStreamManager = exports.ChunkedStream = void 0;
|
28
28
|
|
29
|
-
var _util = require(
|
29
|
+
var _util = require("../shared/util");
|
30
30
|
|
31
|
-
var
|
31
|
+
var _core_utils = require("./core_utils");
|
32
|
+
|
33
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
34
|
+
|
35
|
+
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); } }
|
36
|
+
|
37
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
38
|
+
|
39
|
+
var ChunkedStream =
|
40
|
+
/*#__PURE__*/
|
41
|
+
function () {
|
32
42
|
function ChunkedStream(length, chunkSize, manager) {
|
43
|
+
_classCallCheck(this, ChunkedStream);
|
44
|
+
|
33
45
|
this.bytes = new Uint8Array(length);
|
34
46
|
this.start = 0;
|
35
47
|
this.pos = 0;
|
@@ -42,203 +54,317 @@ var ChunkedStream = function ChunkedStreamClosure() {
|
|
42
54
|
this.progressiveDataLength = 0;
|
43
55
|
this.lastSuccessfulEnsureByteChunk = -1;
|
44
56
|
}
|
45
|
-
|
46
|
-
|
57
|
+
|
58
|
+
_createClass(ChunkedStream, [{
|
59
|
+
key: "getMissingChunks",
|
60
|
+
value: function getMissingChunks() {
|
47
61
|
var chunks = [];
|
62
|
+
|
48
63
|
for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
|
49
64
|
if (!this.loadedChunks[chunk]) {
|
50
65
|
chunks.push(chunk);
|
51
66
|
}
|
52
67
|
}
|
68
|
+
|
53
69
|
return chunks;
|
54
|
-
}
|
55
|
-
|
70
|
+
}
|
71
|
+
}, {
|
72
|
+
key: "getBaseStreams",
|
73
|
+
value: function getBaseStreams() {
|
56
74
|
return [this];
|
57
|
-
}
|
58
|
-
|
75
|
+
}
|
76
|
+
}, {
|
77
|
+
key: "allChunksLoaded",
|
78
|
+
value: function allChunksLoaded() {
|
59
79
|
return this.numChunksLoaded === this.numChunks;
|
60
|
-
}
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
80
|
+
}
|
81
|
+
}, {
|
82
|
+
key: "onReceiveData",
|
83
|
+
value: function onReceiveData(begin, chunk) {
|
84
|
+
var chunkSize = this.chunkSize;
|
85
|
+
|
86
|
+
if (begin % chunkSize !== 0) {
|
87
|
+
throw new Error("Bad begin offset: ".concat(begin));
|
65
88
|
}
|
66
|
-
|
67
|
-
|
68
|
-
|
89
|
+
|
90
|
+
var end = begin + chunk.byteLength;
|
91
|
+
|
92
|
+
if (end % chunkSize !== 0 && end !== this.bytes.length) {
|
93
|
+
throw new Error("Bad end offset: ".concat(end));
|
69
94
|
}
|
95
|
+
|
70
96
|
this.bytes.set(new Uint8Array(chunk), begin);
|
71
|
-
var chunkSize = this.chunkSize;
|
72
97
|
var beginChunk = Math.floor(begin / chunkSize);
|
73
98
|
var endChunk = Math.floor((end - 1) / chunkSize) + 1;
|
74
|
-
|
75
|
-
for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
|
99
|
+
|
100
|
+
for (var curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
|
76
101
|
if (!this.loadedChunks[curChunk]) {
|
77
102
|
this.loadedChunks[curChunk] = true;
|
78
103
|
++this.numChunksLoaded;
|
79
104
|
}
|
80
105
|
}
|
81
|
-
}
|
82
|
-
|
106
|
+
}
|
107
|
+
}, {
|
108
|
+
key: "onReceiveProgressiveData",
|
109
|
+
value: function onReceiveProgressiveData(data) {
|
83
110
|
var position = this.progressiveDataLength;
|
84
111
|
var beginChunk = Math.floor(position / this.chunkSize);
|
85
112
|
this.bytes.set(new Uint8Array(data), position);
|
86
113
|
position += data.byteLength;
|
87
114
|
this.progressiveDataLength = position;
|
88
115
|
var endChunk = position >= this.end ? this.numChunks : Math.floor(position / this.chunkSize);
|
89
|
-
|
90
|
-
for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
|
116
|
+
|
117
|
+
for (var curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
|
91
118
|
if (!this.loadedChunks[curChunk]) {
|
92
119
|
this.loadedChunks[curChunk] = true;
|
93
120
|
++this.numChunksLoaded;
|
94
121
|
}
|
95
122
|
}
|
96
|
-
}
|
97
|
-
|
123
|
+
}
|
124
|
+
}, {
|
125
|
+
key: "ensureByte",
|
126
|
+
value: function ensureByte(pos) {
|
127
|
+
if (pos < this.progressiveDataLength) {
|
128
|
+
return;
|
129
|
+
}
|
130
|
+
|
98
131
|
var chunk = Math.floor(pos / this.chunkSize);
|
132
|
+
|
99
133
|
if (chunk === this.lastSuccessfulEnsureByteChunk) {
|
100
134
|
return;
|
101
135
|
}
|
136
|
+
|
102
137
|
if (!this.loadedChunks[chunk]) {
|
103
|
-
throw new
|
138
|
+
throw new _core_utils.MissingDataException(pos, pos + 1);
|
104
139
|
}
|
140
|
+
|
105
141
|
this.lastSuccessfulEnsureByteChunk = chunk;
|
106
|
-
}
|
107
|
-
|
142
|
+
}
|
143
|
+
}, {
|
144
|
+
key: "ensureRange",
|
145
|
+
value: function ensureRange(begin, end) {
|
108
146
|
if (begin >= end) {
|
109
147
|
return;
|
110
148
|
}
|
149
|
+
|
111
150
|
if (end <= this.progressiveDataLength) {
|
112
151
|
return;
|
113
152
|
}
|
153
|
+
|
114
154
|
var chunkSize = this.chunkSize;
|
115
155
|
var beginChunk = Math.floor(begin / chunkSize);
|
116
156
|
var endChunk = Math.floor((end - 1) / chunkSize) + 1;
|
157
|
+
|
117
158
|
for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
|
118
159
|
if (!this.loadedChunks[chunk]) {
|
119
|
-
throw new
|
160
|
+
throw new _core_utils.MissingDataException(begin, end);
|
120
161
|
}
|
121
162
|
}
|
122
|
-
}
|
123
|
-
|
124
|
-
|
125
|
-
|
163
|
+
}
|
164
|
+
}, {
|
165
|
+
key: "nextEmptyChunk",
|
166
|
+
value: function nextEmptyChunk(beginChunk) {
|
167
|
+
var numChunks = this.numChunks;
|
168
|
+
|
126
169
|
for (var i = 0; i < numChunks; ++i) {
|
127
|
-
chunk = (beginChunk + i) % numChunks;
|
170
|
+
var chunk = (beginChunk + i) % numChunks;
|
171
|
+
|
128
172
|
if (!this.loadedChunks[chunk]) {
|
129
173
|
return chunk;
|
130
174
|
}
|
131
175
|
}
|
176
|
+
|
132
177
|
return null;
|
133
|
-
}
|
134
|
-
|
178
|
+
}
|
179
|
+
}, {
|
180
|
+
key: "hasChunk",
|
181
|
+
value: function hasChunk(chunk) {
|
135
182
|
return !!this.loadedChunks[chunk];
|
136
|
-
}
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
get isEmpty() {
|
141
|
-
return this.length === 0;
|
142
|
-
},
|
143
|
-
getByte: function ChunkedStream_getByte() {
|
183
|
+
}
|
184
|
+
}, {
|
185
|
+
key: "getByte",
|
186
|
+
value: function getByte() {
|
144
187
|
var pos = this.pos;
|
188
|
+
|
145
189
|
if (pos >= this.end) {
|
146
190
|
return -1;
|
147
191
|
}
|
148
|
-
|
192
|
+
|
193
|
+
if (pos >= this.progressiveDataLength) {
|
194
|
+
this.ensureByte(pos);
|
195
|
+
}
|
196
|
+
|
149
197
|
return this.bytes[this.pos++];
|
150
|
-
}
|
151
|
-
|
198
|
+
}
|
199
|
+
}, {
|
200
|
+
key: "getUint16",
|
201
|
+
value: function getUint16() {
|
152
202
|
var b0 = this.getByte();
|
153
203
|
var b1 = this.getByte();
|
204
|
+
|
154
205
|
if (b0 === -1 || b1 === -1) {
|
155
206
|
return -1;
|
156
207
|
}
|
208
|
+
|
157
209
|
return (b0 << 8) + b1;
|
158
|
-
}
|
159
|
-
|
210
|
+
}
|
211
|
+
}, {
|
212
|
+
key: "getInt32",
|
213
|
+
value: function getInt32() {
|
160
214
|
var b0 = this.getByte();
|
161
215
|
var b1 = this.getByte();
|
162
216
|
var b2 = this.getByte();
|
163
217
|
var b3 = this.getByte();
|
164
218
|
return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
|
165
|
-
}
|
166
|
-
|
219
|
+
}
|
220
|
+
}, {
|
221
|
+
key: "getBytes",
|
222
|
+
value: function getBytes(length) {
|
223
|
+
var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
167
224
|
var bytes = this.bytes;
|
168
225
|
var pos = this.pos;
|
169
226
|
var strEnd = this.end;
|
227
|
+
|
170
228
|
if (!length) {
|
171
|
-
this.
|
172
|
-
|
229
|
+
if (strEnd > this.progressiveDataLength) {
|
230
|
+
this.ensureRange(pos, strEnd);
|
231
|
+
}
|
232
|
+
|
233
|
+
var _subarray = bytes.subarray(pos, strEnd);
|
234
|
+
|
235
|
+
return forceClamped ? new Uint8ClampedArray(_subarray) : _subarray;
|
173
236
|
}
|
237
|
+
|
174
238
|
var end = pos + length;
|
239
|
+
|
175
240
|
if (end > strEnd) {
|
176
241
|
end = strEnd;
|
177
242
|
}
|
178
|
-
|
243
|
+
|
244
|
+
if (end > this.progressiveDataLength) {
|
245
|
+
this.ensureRange(pos, end);
|
246
|
+
}
|
247
|
+
|
179
248
|
this.pos = end;
|
180
|
-
|
181
|
-
|
182
|
-
|
249
|
+
var subarray = bytes.subarray(pos, end);
|
250
|
+
return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
|
251
|
+
}
|
252
|
+
}, {
|
253
|
+
key: "peekByte",
|
254
|
+
value: function peekByte() {
|
183
255
|
var peekedByte = this.getByte();
|
184
256
|
this.pos--;
|
185
257
|
return peekedByte;
|
186
|
-
}
|
187
|
-
|
188
|
-
|
258
|
+
}
|
259
|
+
}, {
|
260
|
+
key: "peekBytes",
|
261
|
+
value: function peekBytes(length) {
|
262
|
+
var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
263
|
+
var bytes = this.getBytes(length, forceClamped);
|
189
264
|
this.pos -= bytes.length;
|
190
265
|
return bytes;
|
191
|
-
}
|
192
|
-
|
193
|
-
|
266
|
+
}
|
267
|
+
}, {
|
268
|
+
key: "getByteRange",
|
269
|
+
value: function getByteRange(begin, end) {
|
270
|
+
if (begin < 0) {
|
271
|
+
begin = 0;
|
272
|
+
}
|
273
|
+
|
274
|
+
if (end > this.end) {
|
275
|
+
end = this.end;
|
276
|
+
}
|
277
|
+
|
278
|
+
if (end > this.progressiveDataLength) {
|
279
|
+
this.ensureRange(begin, end);
|
280
|
+
}
|
281
|
+
|
194
282
|
return this.bytes.subarray(begin, end);
|
195
|
-
}
|
196
|
-
|
283
|
+
}
|
284
|
+
}, {
|
285
|
+
key: "skip",
|
286
|
+
value: function skip(n) {
|
197
287
|
if (!n) {
|
198
288
|
n = 1;
|
199
289
|
}
|
290
|
+
|
200
291
|
this.pos += n;
|
201
|
-
}
|
202
|
-
|
292
|
+
}
|
293
|
+
}, {
|
294
|
+
key: "reset",
|
295
|
+
value: function reset() {
|
203
296
|
this.pos = this.start;
|
204
|
-
}
|
205
|
-
|
297
|
+
}
|
298
|
+
}, {
|
299
|
+
key: "moveStart",
|
300
|
+
value: function moveStart() {
|
206
301
|
this.start = this.pos;
|
207
|
-
}
|
208
|
-
|
209
|
-
|
302
|
+
}
|
303
|
+
}, {
|
304
|
+
key: "makeSubStream",
|
305
|
+
value: function makeSubStream(start, length, dict) {
|
306
|
+
if (length) {
|
307
|
+
if (start + length > this.progressiveDataLength) {
|
308
|
+
this.ensureRange(start, start + length);
|
309
|
+
}
|
310
|
+
} else {
|
311
|
+
if (start >= this.progressiveDataLength) {
|
312
|
+
this.ensureByte(start);
|
313
|
+
}
|
314
|
+
}
|
315
|
+
|
210
316
|
function ChunkedStreamSubstream() {}
|
317
|
+
|
211
318
|
ChunkedStreamSubstream.prototype = Object.create(this);
|
319
|
+
|
212
320
|
ChunkedStreamSubstream.prototype.getMissingChunks = function () {
|
213
321
|
var chunkSize = this.chunkSize;
|
214
322
|
var beginChunk = Math.floor(this.start / chunkSize);
|
215
323
|
var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
|
216
324
|
var missingChunks = [];
|
325
|
+
|
217
326
|
for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
|
218
327
|
if (!this.loadedChunks[chunk]) {
|
219
328
|
missingChunks.push(chunk);
|
220
329
|
}
|
221
330
|
}
|
331
|
+
|
222
332
|
return missingChunks;
|
223
333
|
};
|
334
|
+
|
224
335
|
var subStream = new ChunkedStreamSubstream();
|
225
336
|
subStream.pos = subStream.start = start;
|
226
337
|
subStream.end = start + length || this.end;
|
227
338
|
subStream.dict = dict;
|
228
339
|
return subStream;
|
229
340
|
}
|
230
|
-
}
|
341
|
+
}, {
|
342
|
+
key: "length",
|
343
|
+
get: function get() {
|
344
|
+
return this.end - this.start;
|
345
|
+
}
|
346
|
+
}, {
|
347
|
+
key: "isEmpty",
|
348
|
+
get: function get() {
|
349
|
+
return this.length === 0;
|
350
|
+
}
|
351
|
+
}]);
|
352
|
+
|
231
353
|
return ChunkedStream;
|
232
354
|
}();
|
233
|
-
|
355
|
+
|
356
|
+
exports.ChunkedStream = ChunkedStream;
|
357
|
+
|
358
|
+
var ChunkedStreamManager =
|
359
|
+
/*#__PURE__*/
|
360
|
+
function () {
|
234
361
|
function ChunkedStreamManager(pdfNetworkStream, args) {
|
235
|
-
|
236
|
-
|
237
|
-
this.
|
238
|
-
this.
|
239
|
-
this.
|
362
|
+
_classCallCheck(this, ChunkedStreamManager);
|
363
|
+
|
364
|
+
this.length = args.length;
|
365
|
+
this.chunkSize = args.rangeChunkSize;
|
366
|
+
this.stream = new ChunkedStream(this.length, this.chunkSize, this);
|
240
367
|
this.pdfNetworkStream = pdfNetworkStream;
|
241
|
-
this.url = args.url;
|
242
368
|
this.disableAutoFetch = args.disableAutoFetch;
|
243
369
|
this.msgHandler = args.msgHandler;
|
244
370
|
this.currRequestId = 0;
|
@@ -249,20 +375,25 @@ var ChunkedStreamManager = function ChunkedStreamManagerClosure() {
|
|
249
375
|
this.aborted = false;
|
250
376
|
this._loadedStreamCapability = (0, _util.createPromiseCapability)();
|
251
377
|
}
|
252
|
-
|
253
|
-
|
378
|
+
|
379
|
+
_createClass(ChunkedStreamManager, [{
|
380
|
+
key: "onLoadedStream",
|
381
|
+
value: function onLoadedStream() {
|
254
382
|
return this._loadedStreamCapability.promise;
|
255
|
-
}
|
256
|
-
|
383
|
+
}
|
384
|
+
}, {
|
385
|
+
key: "sendRequest",
|
386
|
+
value: function sendRequest(begin, end) {
|
257
387
|
var _this = this;
|
258
388
|
|
259
389
|
var rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
|
390
|
+
|
260
391
|
if (!rangeReader.isStreamingSupported) {
|
261
392
|
rangeReader.onProgress = this.onProgress.bind(this);
|
262
393
|
}
|
394
|
+
|
263
395
|
var chunks = [],
|
264
396
|
loaded = 0;
|
265
|
-
var manager = this;
|
266
397
|
var promise = new Promise(function (resolve, reject) {
|
267
398
|
var readChunk = function readChunk(chunk) {
|
268
399
|
try {
|
@@ -270,12 +401,17 @@ var ChunkedStreamManager = function ChunkedStreamManagerClosure() {
|
|
270
401
|
var data = chunk.value;
|
271
402
|
chunks.push(data);
|
272
403
|
loaded += (0, _util.arrayByteLength)(data);
|
404
|
+
|
273
405
|
if (rangeReader.isStreamingSupported) {
|
274
|
-
|
406
|
+
_this.onProgress({
|
407
|
+
loaded: loaded
|
408
|
+
});
|
275
409
|
}
|
410
|
+
|
276
411
|
rangeReader.read().then(readChunk, reject);
|
277
412
|
return;
|
278
413
|
}
|
414
|
+
|
279
415
|
var chunkData = (0, _util.arraysToBytes)(chunks);
|
280
416
|
chunks = null;
|
281
417
|
resolve(chunkData);
|
@@ -283,98 +419,188 @@ var ChunkedStreamManager = function ChunkedStreamManagerClosure() {
|
|
283
419
|
reject(e);
|
284
420
|
}
|
285
421
|
};
|
422
|
+
|
286
423
|
rangeReader.read().then(readChunk, reject);
|
287
424
|
});
|
288
425
|
promise.then(function (data) {
|
289
426
|
if (_this.aborted) {
|
290
427
|
return;
|
291
428
|
}
|
429
|
+
|
292
430
|
_this.onReceiveData({
|
293
431
|
chunk: data,
|
294
432
|
begin: begin
|
295
433
|
});
|
296
434
|
});
|
297
|
-
}
|
298
|
-
|
435
|
+
}
|
436
|
+
}, {
|
437
|
+
key: "requestAllChunks",
|
438
|
+
value: function requestAllChunks() {
|
299
439
|
var missingChunks = this.stream.getMissingChunks();
|
440
|
+
|
300
441
|
this._requestChunks(missingChunks);
|
442
|
+
|
301
443
|
return this._loadedStreamCapability.promise;
|
302
|
-
}
|
303
|
-
|
444
|
+
}
|
445
|
+
}, {
|
446
|
+
key: "_requestChunks",
|
447
|
+
value: function _requestChunks(chunks) {
|
304
448
|
var requestId = this.currRequestId++;
|
305
|
-
var i, ii;
|
306
449
|
var chunksNeeded = Object.create(null);
|
307
450
|
this.chunksNeededByRequest[requestId] = chunksNeeded;
|
308
|
-
|
309
|
-
|
310
|
-
|
451
|
+
var _iteratorNormalCompletion = true;
|
452
|
+
var _didIteratorError = false;
|
453
|
+
var _iteratorError = undefined;
|
454
|
+
|
455
|
+
try {
|
456
|
+
for (var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
457
|
+
var _chunk = _step.value;
|
458
|
+
|
459
|
+
if (!this.stream.hasChunk(_chunk)) {
|
460
|
+
chunksNeeded[_chunk] = true;
|
461
|
+
}
|
462
|
+
}
|
463
|
+
} catch (err) {
|
464
|
+
_didIteratorError = true;
|
465
|
+
_iteratorError = err;
|
466
|
+
} finally {
|
467
|
+
try {
|
468
|
+
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
469
|
+
_iterator["return"]();
|
470
|
+
}
|
471
|
+
} finally {
|
472
|
+
if (_didIteratorError) {
|
473
|
+
throw _iteratorError;
|
474
|
+
}
|
311
475
|
}
|
312
476
|
}
|
477
|
+
|
313
478
|
if ((0, _util.isEmptyObj)(chunksNeeded)) {
|
314
479
|
return Promise.resolve();
|
315
480
|
}
|
481
|
+
|
316
482
|
var capability = (0, _util.createPromiseCapability)();
|
317
483
|
this.promisesByRequest[requestId] = capability;
|
318
484
|
var chunksToRequest = [];
|
485
|
+
|
319
486
|
for (var chunk in chunksNeeded) {
|
320
487
|
chunk = chunk | 0;
|
488
|
+
|
321
489
|
if (!(chunk in this.requestsByChunk)) {
|
322
490
|
this.requestsByChunk[chunk] = [];
|
323
491
|
chunksToRequest.push(chunk);
|
324
492
|
}
|
493
|
+
|
325
494
|
this.requestsByChunk[chunk].push(requestId);
|
326
495
|
}
|
496
|
+
|
327
497
|
if (!chunksToRequest.length) {
|
328
498
|
return capability.promise;
|
329
499
|
}
|
500
|
+
|
330
501
|
var groupedChunksToRequest = this.groupChunks(chunksToRequest);
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
502
|
+
var _iteratorNormalCompletion2 = true;
|
503
|
+
var _didIteratorError2 = false;
|
504
|
+
var _iteratorError2 = undefined;
|
505
|
+
|
506
|
+
try {
|
507
|
+
for (var _iterator2 = groupedChunksToRequest[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
508
|
+
var groupedChunk = _step2.value;
|
509
|
+
var begin = groupedChunk.beginChunk * this.chunkSize;
|
510
|
+
var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
|
511
|
+
this.sendRequest(begin, end);
|
512
|
+
}
|
513
|
+
} catch (err) {
|
514
|
+
_didIteratorError2 = true;
|
515
|
+
_iteratorError2 = err;
|
516
|
+
} finally {
|
517
|
+
try {
|
518
|
+
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
|
519
|
+
_iterator2["return"]();
|
520
|
+
}
|
521
|
+
} finally {
|
522
|
+
if (_didIteratorError2) {
|
523
|
+
throw _iteratorError2;
|
524
|
+
}
|
525
|
+
}
|
336
526
|
}
|
527
|
+
|
337
528
|
return capability.promise;
|
338
|
-
}
|
339
|
-
|
529
|
+
}
|
530
|
+
}, {
|
531
|
+
key: "getStream",
|
532
|
+
value: function getStream() {
|
340
533
|
return this.stream;
|
341
|
-
}
|
342
|
-
|
534
|
+
}
|
535
|
+
}, {
|
536
|
+
key: "requestRange",
|
537
|
+
value: function requestRange(begin, end) {
|
343
538
|
end = Math.min(end, this.length);
|
344
539
|
var beginChunk = this.getBeginChunk(begin);
|
345
540
|
var endChunk = this.getEndChunk(end);
|
346
541
|
var chunks = [];
|
542
|
+
|
347
543
|
for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
|
348
544
|
chunks.push(chunk);
|
349
545
|
}
|
546
|
+
|
350
547
|
return this._requestChunks(chunks);
|
351
|
-
}
|
352
|
-
|
353
|
-
|
548
|
+
}
|
549
|
+
}, {
|
550
|
+
key: "requestRanges",
|
551
|
+
value: function requestRanges() {
|
552
|
+
var ranges = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
354
553
|
var chunksToRequest = [];
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
554
|
+
var _iteratorNormalCompletion3 = true;
|
555
|
+
var _didIteratorError3 = false;
|
556
|
+
var _iteratorError3 = undefined;
|
557
|
+
|
558
|
+
try {
|
559
|
+
for (var _iterator3 = ranges[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
560
|
+
var range = _step3.value;
|
561
|
+
var beginChunk = this.getBeginChunk(range.begin);
|
562
|
+
var endChunk = this.getEndChunk(range.end);
|
563
|
+
|
564
|
+
for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
|
565
|
+
if (!chunksToRequest.includes(chunk)) {
|
566
|
+
chunksToRequest.push(chunk);
|
567
|
+
}
|
568
|
+
}
|
569
|
+
}
|
570
|
+
} catch (err) {
|
571
|
+
_didIteratorError3 = true;
|
572
|
+
_iteratorError3 = err;
|
573
|
+
} finally {
|
574
|
+
try {
|
575
|
+
if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) {
|
576
|
+
_iterator3["return"]();
|
577
|
+
}
|
578
|
+
} finally {
|
579
|
+
if (_didIteratorError3) {
|
580
|
+
throw _iteratorError3;
|
361
581
|
}
|
362
582
|
}
|
363
583
|
}
|
584
|
+
|
364
585
|
chunksToRequest.sort(function (a, b) {
|
365
586
|
return a - b;
|
366
587
|
});
|
367
588
|
return this._requestChunks(chunksToRequest);
|
368
|
-
}
|
369
|
-
|
589
|
+
}
|
590
|
+
}, {
|
591
|
+
key: "groupChunks",
|
592
|
+
value: function groupChunks(chunks) {
|
370
593
|
var groupedChunks = [];
|
371
594
|
var beginChunk = -1;
|
372
595
|
var prevChunk = -1;
|
373
|
-
|
596
|
+
|
597
|
+
for (var i = 0, ii = chunks.length; i < ii; ++i) {
|
374
598
|
var chunk = chunks[i];
|
599
|
+
|
375
600
|
if (beginChunk < 0) {
|
376
601
|
beginChunk = chunk;
|
377
602
|
}
|
603
|
+
|
378
604
|
if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
|
379
605
|
groupedChunks.push({
|
380
606
|
beginChunk: beginChunk,
|
@@ -382,104 +608,149 @@ var ChunkedStreamManager = function ChunkedStreamManagerClosure() {
|
|
382
608
|
});
|
383
609
|
beginChunk = chunk;
|
384
610
|
}
|
611
|
+
|
385
612
|
if (i + 1 === chunks.length) {
|
386
613
|
groupedChunks.push({
|
387
614
|
beginChunk: beginChunk,
|
388
615
|
endChunk: chunk + 1
|
389
616
|
});
|
390
617
|
}
|
618
|
+
|
391
619
|
prevChunk = chunk;
|
392
620
|
}
|
621
|
+
|
393
622
|
return groupedChunks;
|
394
|
-
}
|
395
|
-
|
396
|
-
|
623
|
+
}
|
624
|
+
}, {
|
625
|
+
key: "onProgress",
|
626
|
+
value: function onProgress(args) {
|
397
627
|
this.msgHandler.send('DocProgress', {
|
398
|
-
loaded:
|
628
|
+
loaded: this.stream.numChunksLoaded * this.chunkSize + args.loaded,
|
399
629
|
total: this.length
|
400
630
|
});
|
401
|
-
}
|
402
|
-
|
631
|
+
}
|
632
|
+
}, {
|
633
|
+
key: "onReceiveData",
|
634
|
+
value: function onReceiveData(args) {
|
403
635
|
var chunk = args.chunk;
|
404
636
|
var isProgressive = args.begin === undefined;
|
405
637
|
var begin = isProgressive ? this.progressiveDataLength : args.begin;
|
406
638
|
var end = begin + chunk.byteLength;
|
407
639
|
var beginChunk = Math.floor(begin / this.chunkSize);
|
408
640
|
var endChunk = end < this.length ? Math.floor(end / this.chunkSize) : Math.ceil(end / this.chunkSize);
|
641
|
+
|
409
642
|
if (isProgressive) {
|
410
643
|
this.stream.onReceiveProgressiveData(chunk);
|
411
644
|
this.progressiveDataLength = end;
|
412
645
|
} else {
|
413
646
|
this.stream.onReceiveData(begin, chunk);
|
414
647
|
}
|
648
|
+
|
415
649
|
if (this.stream.allChunksLoaded()) {
|
416
650
|
this._loadedStreamCapability.resolve(this.stream);
|
417
651
|
}
|
652
|
+
|
418
653
|
var loadedRequests = [];
|
419
|
-
|
420
|
-
for (
|
421
|
-
var requestIds = this.requestsByChunk[
|
422
|
-
delete this.requestsByChunk[
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
654
|
+
|
655
|
+
for (var _chunk2 = beginChunk; _chunk2 < endChunk; ++_chunk2) {
|
656
|
+
var requestIds = this.requestsByChunk[_chunk2] || [];
|
657
|
+
delete this.requestsByChunk[_chunk2];
|
658
|
+
var _iteratorNormalCompletion4 = true;
|
659
|
+
var _didIteratorError4 = false;
|
660
|
+
var _iteratorError4 = undefined;
|
661
|
+
|
662
|
+
try {
|
663
|
+
for (var _iterator4 = requestIds[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
664
|
+
var requestId = _step4.value;
|
665
|
+
var chunksNeeded = this.chunksNeededByRequest[requestId];
|
666
|
+
|
667
|
+
if (_chunk2 in chunksNeeded) {
|
668
|
+
delete chunksNeeded[_chunk2];
|
669
|
+
}
|
670
|
+
|
671
|
+
if (!(0, _util.isEmptyObj)(chunksNeeded)) {
|
672
|
+
continue;
|
673
|
+
}
|
674
|
+
|
675
|
+
loadedRequests.push(requestId);
|
428
676
|
}
|
429
|
-
|
430
|
-
|
677
|
+
} catch (err) {
|
678
|
+
_didIteratorError4 = true;
|
679
|
+
_iteratorError4 = err;
|
680
|
+
} finally {
|
681
|
+
try {
|
682
|
+
if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) {
|
683
|
+
_iterator4["return"]();
|
684
|
+
}
|
685
|
+
} finally {
|
686
|
+
if (_didIteratorError4) {
|
687
|
+
throw _iteratorError4;
|
688
|
+
}
|
431
689
|
}
|
432
|
-
loadedRequests.push(requestId);
|
433
690
|
}
|
434
691
|
}
|
692
|
+
|
435
693
|
if (!this.disableAutoFetch && (0, _util.isEmptyObj)(this.requestsByChunk)) {
|
436
694
|
var nextEmptyChunk;
|
695
|
+
|
437
696
|
if (this.stream.numChunksLoaded === 1) {
|
438
697
|
var lastChunk = this.stream.numChunks - 1;
|
698
|
+
|
439
699
|
if (!this.stream.hasChunk(lastChunk)) {
|
440
700
|
nextEmptyChunk = lastChunk;
|
441
701
|
}
|
442
702
|
} else {
|
443
703
|
nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
|
444
704
|
}
|
705
|
+
|
445
706
|
if (Number.isInteger(nextEmptyChunk)) {
|
446
707
|
this._requestChunks([nextEmptyChunk]);
|
447
708
|
}
|
448
709
|
}
|
449
|
-
|
450
|
-
|
451
|
-
var
|
452
|
-
|
710
|
+
|
711
|
+
for (var _i = 0, _loadedRequests = loadedRequests; _i < _loadedRequests.length; _i++) {
|
712
|
+
var _requestId = _loadedRequests[_i];
|
713
|
+
var capability = this.promisesByRequest[_requestId];
|
714
|
+
delete this.promisesByRequest[_requestId];
|
453
715
|
capability.resolve();
|
454
716
|
}
|
717
|
+
|
455
718
|
this.msgHandler.send('DocProgress', {
|
456
719
|
loaded: this.stream.numChunksLoaded * this.chunkSize,
|
457
720
|
total: this.length
|
458
721
|
});
|
459
|
-
}
|
460
|
-
|
722
|
+
}
|
723
|
+
}, {
|
724
|
+
key: "onError",
|
725
|
+
value: function onError(err) {
|
461
726
|
this._loadedStreamCapability.reject(err);
|
462
|
-
}
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
727
|
+
}
|
728
|
+
}, {
|
729
|
+
key: "getBeginChunk",
|
730
|
+
value: function getBeginChunk(begin) {
|
731
|
+
return Math.floor(begin / this.chunkSize);
|
732
|
+
}
|
733
|
+
}, {
|
734
|
+
key: "getEndChunk",
|
735
|
+
value: function getEndChunk(end) {
|
736
|
+
return Math.floor((end - 1) / this.chunkSize) + 1;
|
737
|
+
}
|
738
|
+
}, {
|
739
|
+
key: "abort",
|
740
|
+
value: function abort(reason) {
|
472
741
|
this.aborted = true;
|
742
|
+
|
473
743
|
if (this.pdfNetworkStream) {
|
474
|
-
this.pdfNetworkStream.cancelAllRequests(
|
744
|
+
this.pdfNetworkStream.cancelAllRequests(reason);
|
475
745
|
}
|
746
|
+
|
476
747
|
for (var requestId in this.promisesByRequest) {
|
477
|
-
|
478
|
-
capability.reject(new Error('Request was aborted'));
|
748
|
+
this.promisesByRequest[requestId].reject(reason);
|
479
749
|
}
|
480
750
|
}
|
481
|
-
};
|
751
|
+
}]);
|
752
|
+
|
482
753
|
return ChunkedStreamManager;
|
483
754
|
}();
|
484
|
-
|
755
|
+
|
485
756
|
exports.ChunkedStreamManager = ChunkedStreamManager;
|