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