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.

Files changed (192) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/README.md +4 -0
  3. package/bower.json +1 -1
  4. package/build/pdf.js +8286 -14230
  5. package/build/pdf.js.map +1 -1
  6. package/build/pdf.min.js +22 -1
  7. package/build/pdf.worker.entry.js +5 -3
  8. package/build/pdf.worker.js +25500 -26628
  9. package/build/pdf.worker.js.map +1 -1
  10. package/build/pdf.worker.min.js +22 -1
  11. package/es5/build/pdf.js +25473 -0
  12. package/es5/build/pdf.js.map +1 -0
  13. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  14. package/es5/build/pdf.worker.js +57878 -0
  15. package/es5/build/pdf.worker.js.map +1 -0
  16. package/es5/web/images/annotation-check.svg +11 -0
  17. package/es5/web/images/annotation-comment.svg +16 -0
  18. package/es5/web/images/annotation-help.svg +26 -0
  19. package/es5/web/images/annotation-insert.svg +10 -0
  20. package/es5/web/images/annotation-key.svg +11 -0
  21. package/es5/web/images/annotation-newparagraph.svg +11 -0
  22. package/es5/web/images/annotation-noicon.svg +7 -0
  23. package/es5/web/images/annotation-note.svg +42 -0
  24. package/es5/web/images/annotation-paragraph.svg +16 -0
  25. package/es5/web/images/loading-icon.gif +0 -0
  26. package/es5/web/images/shadow.png +0 -0
  27. package/es5/web/images/texture.png +0 -0
  28. package/es5/web/pdf_viewer.css +407 -0
  29. package/es5/web/pdf_viewer.js +7757 -0
  30. package/es5/web/pdf_viewer.js.map +1 -0
  31. package/image_decoders/pdf.image_decoders.js +2887 -4094
  32. package/image_decoders/pdf.image_decoders.js.map +1 -1
  33. package/image_decoders/pdf.image_decoders.min.js +22 -1
  34. package/lib/README.md +7 -0
  35. package/lib/core/annotation.js +855 -778
  36. package/lib/core/arithmetic_decoder.js +325 -311
  37. package/lib/core/bidi.js +117 -50
  38. package/lib/core/ccitt.js +251 -89
  39. package/lib/core/ccitt_stream.js +26 -16
  40. package/lib/core/cff_parser.js +525 -197
  41. package/lib/core/charsets.js +6 -5
  42. package/lib/core/chunked_stream.js +541 -406
  43. package/lib/core/cmap.js +368 -253
  44. package/lib/core/colorspace.js +781 -800
  45. package/lib/core/core_utils.js +152 -0
  46. package/lib/core/crypto.js +609 -422
  47. package/lib/core/document.js +649 -481
  48. package/lib/core/encodings.js +33 -24
  49. package/lib/core/evaluator.js +1471 -736
  50. package/lib/core/font_renderer.js +289 -149
  51. package/lib/core/fonts.js +1067 -413
  52. package/lib/core/function.js +517 -287
  53. package/lib/core/glyphlist.js +4529 -4527
  54. package/lib/core/image.js +232 -114
  55. package/lib/core/image_utils.js +94 -0
  56. package/lib/core/jbig2.js +711 -342
  57. package/lib/core/jbig2_stream.js +31 -19
  58. package/lib/core/jpeg_stream.js +151 -26
  59. package/lib/core/jpg.js +433 -181
  60. package/lib/core/jpx.js +551 -143
  61. package/lib/core/jpx_stream.js +40 -28
  62. package/lib/core/metrics.js +2931 -2931
  63. package/lib/core/murmurhash3.js +104 -97
  64. package/lib/core/obj.js +1561 -1053
  65. package/lib/core/operator_list.js +192 -64
  66. package/lib/core/parser.js +1162 -864
  67. package/lib/core/pattern.js +224 -75
  68. package/lib/core/pdf_manager.js +154 -285
  69. package/lib/core/primitives.js +145 -69
  70. package/lib/core/ps_parser.js +212 -162
  71. package/lib/core/standard_fonts.js +245 -244
  72. package/lib/core/stream.js +353 -81
  73. package/lib/core/type1_parser.js +218 -68
  74. package/lib/core/unicode.js +1682 -1655
  75. package/lib/core/worker.js +233 -302
  76. package/lib/core/worker_stream.js +168 -0
  77. package/lib/display/annotation_layer.js +808 -862
  78. package/lib/display/api.js +1778 -1462
  79. package/lib/display/api_compatibility.js +14 -9
  80. package/lib/display/canvas.js +463 -140
  81. package/lib/display/content_disposition.js +86 -58
  82. package/lib/display/display_utils.js +524 -0
  83. package/lib/display/fetch_stream.js +202 -274
  84. package/lib/display/font_loader.js +311 -333
  85. package/lib/display/metadata.js +98 -88
  86. package/lib/display/network.js +343 -347
  87. package/lib/display/network_utils.js +46 -26
  88. package/lib/display/node_stream.js +326 -404
  89. package/lib/display/pattern_helper.js +168 -69
  90. package/lib/display/svg.js +1296 -885
  91. package/lib/display/text_layer.js +229 -103
  92. package/lib/display/transport_stream.js +290 -250
  93. package/lib/display/webgl.js +116 -83
  94. package/lib/display/worker_options.js +6 -5
  95. package/lib/display/xml_parser.js +358 -337
  96. package/lib/examples/node/domstubs.js +95 -39
  97. package/lib/pdf.js +49 -31
  98. package/lib/pdf.worker.js +7 -5
  99. package/lib/shared/compatibility.js +3 -145
  100. package/lib/shared/is_node.js +8 -7
  101. package/lib/shared/message_handler.js +367 -314
  102. package/lib/shared/util.js +421 -415
  103. package/lib/test/unit/annotation_spec.js +1570 -690
  104. package/lib/test/unit/api_spec.js +855 -493
  105. package/lib/test/unit/bidi_spec.js +12 -12
  106. package/lib/test/unit/cff_parser_spec.js +88 -61
  107. package/lib/test/unit/clitests_helper.js +9 -12
  108. package/lib/test/unit/cmap_spec.js +140 -88
  109. package/lib/test/unit/colorspace_spec.js +204 -152
  110. package/lib/test/unit/core_utils_spec.js +211 -0
  111. package/lib/test/unit/crypto_spec.js +194 -182
  112. package/lib/test/unit/custom_spec.js +50 -64
  113. package/lib/test/unit/display_svg_spec.js +53 -38
  114. package/lib/test/unit/display_utils_spec.js +263 -0
  115. package/lib/test/unit/document_spec.js +17 -22
  116. package/lib/test/unit/encodings_spec.js +15 -57
  117. package/lib/test/unit/evaluator_spec.js +90 -83
  118. package/lib/test/unit/fetch_stream_spec.js +111 -0
  119. package/lib/test/unit/function_spec.js +219 -205
  120. package/lib/test/unit/jasmine-boot.js +68 -39
  121. package/lib/test/unit/message_handler_spec.js +187 -160
  122. package/lib/test/unit/metadata_spec.js +87 -34
  123. package/lib/test/unit/murmurhash3_spec.js +13 -13
  124. package/lib/test/unit/network_spec.js +26 -59
  125. package/lib/test/unit/network_utils_spec.js +187 -121
  126. package/lib/test/unit/node_stream_spec.js +98 -90
  127. package/lib/test/unit/parser_spec.js +173 -131
  128. package/lib/test/unit/pdf_find_controller_spec.js +148 -67
  129. package/lib/test/unit/pdf_find_utils_spec.js +35 -34
  130. package/lib/test/unit/pdf_history_spec.js +45 -33
  131. package/lib/test/unit/primitives_spec.js +161 -126
  132. package/lib/test/unit/stream_spec.js +22 -15
  133. package/lib/test/unit/test_utils.js +149 -98
  134. package/lib/test/unit/testreporter.js +36 -18
  135. package/lib/test/unit/type1_parser_spec.js +46 -44
  136. package/lib/test/unit/ui_utils_spec.js +388 -372
  137. package/lib/test/unit/unicode_spec.js +49 -46
  138. package/lib/test/unit/util_spec.js +144 -248
  139. package/lib/web/annotation_layer_builder.js +75 -95
  140. package/lib/web/app.js +1538 -1147
  141. package/lib/web/app_options.js +116 -104
  142. package/lib/web/base_viewer.js +950 -775
  143. package/lib/web/chromecom.js +217 -225
  144. package/lib/web/debugger.js +236 -148
  145. package/lib/web/download_manager.js +50 -50
  146. package/lib/web/firefox_print_service.js +51 -33
  147. package/lib/web/firefoxcom.js +225 -352
  148. package/lib/web/genericcom.js +30 -93
  149. package/lib/web/genericl10n.js +26 -143
  150. package/lib/web/grab_to_pan.js +57 -33
  151. package/lib/web/interfaces.js +105 -232
  152. package/lib/web/overlay_manager.js +73 -227
  153. package/lib/web/password_prompt.js +44 -62
  154. package/lib/web/pdf_attachment_viewer.js +118 -123
  155. package/lib/web/pdf_cursor_tools.js +89 -93
  156. package/lib/web/pdf_document_properties.js +242 -281
  157. package/lib/web/pdf_find_bar.js +157 -163
  158. package/lib/web/pdf_find_controller.js +598 -454
  159. package/lib/web/pdf_find_utils.js +32 -16
  160. package/lib/web/pdf_history.js +481 -355
  161. package/lib/web/pdf_link_service.js +355 -323
  162. package/lib/web/pdf_outline_viewer.js +167 -152
  163. package/lib/web/pdf_page_view.js +511 -457
  164. package/lib/web/pdf_presentation_mode.js +347 -335
  165. package/lib/web/pdf_print_service.js +133 -103
  166. package/lib/web/pdf_rendering_queue.js +98 -100
  167. package/lib/web/pdf_sidebar.js +323 -299
  168. package/lib/web/pdf_sidebar_resizer.js +107 -108
  169. package/lib/web/pdf_single_page_viewer.js +94 -146
  170. package/lib/web/pdf_thumbnail_view.js +319 -269
  171. package/lib/web/pdf_thumbnail_viewer.js +219 -199
  172. package/lib/web/pdf_viewer.component.js +111 -32
  173. package/lib/web/pdf_viewer.js +61 -101
  174. package/lib/web/preferences.js +87 -272
  175. package/lib/web/secondary_toolbar.js +207 -220
  176. package/lib/web/text_layer_builder.js +322 -322
  177. package/lib/web/toolbar.js +227 -180
  178. package/lib/web/ui_utils.js +476 -421
  179. package/lib/web/view_history.js +59 -208
  180. package/lib/web/viewer_compatibility.js +9 -6
  181. package/package.json +2 -9
  182. package/web/pdf_viewer.css +36 -22
  183. package/web/pdf_viewer.js +4407 -4516
  184. package/web/pdf_viewer.js.map +1 -1
  185. package/webpack.js +14 -5
  186. package/external/streams/streams-lib.js +0 -3962
  187. package/external/url/url-lib.js +0 -627
  188. package/lib/display/dom_utils.js +0 -441
  189. package/lib/shared/streams_polyfill.js +0 -39
  190. package/lib/shared/url_polyfill.js +0 -50
  191. package/lib/test/unit/dom_utils_spec.js +0 -89
  192. package/lib/web/dom_events.js +0 -140
@@ -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 2018 Mozilla Foundation
5
+ * Copyright 2020 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -19,17 +19,19 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
- exports.ChunkedStreamManager = exports.ChunkedStream = undefined;
27
+ exports.ChunkedStreamManager = exports.ChunkedStream = void 0;
28
28
 
29
- var _util = require('../shared/util');
29
+ var _util = require("../shared/util.js");
30
30
 
31
- var ChunkedStream = function ChunkedStreamClosure() {
32
- function ChunkedStream(length, chunkSize, manager) {
31
+ var _core_utils = require("./core_utils.js");
32
+
33
+ class ChunkedStream {
34
+ constructor(length, chunkSize, manager) {
33
35
  this.bytes = new Uint8Array(length);
34
36
  this.start = 0;
35
37
  this.pos = 0;
@@ -42,211 +44,297 @@ var ChunkedStream = function ChunkedStreamClosure() {
42
44
  this.progressiveDataLength = 0;
43
45
  this.lastSuccessfulEnsureByteChunk = -1;
44
46
  }
45
- ChunkedStream.prototype = {
46
- getMissingChunks: function ChunkedStream_getMissingChunks() {
47
- var chunks = [];
48
- for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
49
- if (!this.loadedChunks[chunk]) {
50
- chunks.push(chunk);
51
- }
52
- }
53
- return chunks;
54
- },
55
- getBaseStreams: function ChunkedStream_getBaseStreams() {
56
- return [this];
57
- },
58
- allChunksLoaded: function ChunkedStream_allChunksLoaded() {
59
- return this.numChunksLoaded === this.numChunks;
60
- },
61
- onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
62
- var end = begin + chunk.byteLength;
63
- if (begin % this.chunkSize !== 0) {
64
- throw new Error('Bad begin offset: ' + begin);
65
- }
66
- var length = this.bytes.length;
67
- if (end % this.chunkSize !== 0 && end !== length) {
68
- throw new Error('Bad end offset: ' + end);
69
- }
70
- this.bytes.set(new Uint8Array(chunk), begin);
71
- var chunkSize = this.chunkSize;
72
- var beginChunk = Math.floor(begin / chunkSize);
73
- var endChunk = Math.floor((end - 1) / chunkSize) + 1;
74
- var curChunk;
75
- for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
76
- if (!this.loadedChunks[curChunk]) {
77
- this.loadedChunks[curChunk] = true;
78
- ++this.numChunksLoaded;
79
- }
80
- }
81
- },
82
- onReceiveProgressiveData: function ChunkedStream_onReceiveProgressiveData(data) {
83
- var position = this.progressiveDataLength;
84
- var beginChunk = Math.floor(position / this.chunkSize);
85
- this.bytes.set(new Uint8Array(data), position);
86
- position += data.byteLength;
87
- this.progressiveDataLength = position;
88
- var endChunk = position >= this.end ? this.numChunks : Math.floor(position / this.chunkSize);
89
- var curChunk;
90
- for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
91
- if (!this.loadedChunks[curChunk]) {
92
- this.loadedChunks[curChunk] = true;
93
- ++this.numChunksLoaded;
94
- }
95
- }
96
- },
97
- ensureByte: function ChunkedStream_ensureByte(pos) {
98
- var chunk = Math.floor(pos / this.chunkSize);
99
- if (chunk === this.lastSuccessfulEnsureByteChunk) {
100
- return;
101
- }
47
+
48
+ getMissingChunks() {
49
+ const chunks = [];
50
+
51
+ for (let chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
102
52
  if (!this.loadedChunks[chunk]) {
103
- throw new _util.MissingDataException(pos, pos + 1);
104
- }
105
- this.lastSuccessfulEnsureByteChunk = chunk;
106
- },
107
- ensureRange: function ChunkedStream_ensureRange(begin, end) {
108
- if (begin >= end) {
109
- return;
53
+ chunks.push(chunk);
110
54
  }
111
- if (end <= this.progressiveDataLength) {
112
- return;
55
+ }
56
+
57
+ return chunks;
58
+ }
59
+
60
+ getBaseStreams() {
61
+ return [this];
62
+ }
63
+
64
+ allChunksLoaded() {
65
+ return this.numChunksLoaded === this.numChunks;
66
+ }
67
+
68
+ onReceiveData(begin, chunk) {
69
+ const chunkSize = this.chunkSize;
70
+
71
+ if (begin % chunkSize !== 0) {
72
+ throw new Error(`Bad begin offset: ${begin}`);
73
+ }
74
+
75
+ const end = begin + chunk.byteLength;
76
+
77
+ if (end % chunkSize !== 0 && end !== this.bytes.length) {
78
+ throw new Error(`Bad end offset: ${end}`);
79
+ }
80
+
81
+ this.bytes.set(new Uint8Array(chunk), begin);
82
+ const beginChunk = Math.floor(begin / chunkSize);
83
+ const endChunk = Math.floor((end - 1) / chunkSize) + 1;
84
+
85
+ for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
86
+ if (!this.loadedChunks[curChunk]) {
87
+ this.loadedChunks[curChunk] = true;
88
+ ++this.numChunksLoaded;
113
89
  }
114
- var chunkSize = this.chunkSize;
115
- var beginChunk = Math.floor(begin / chunkSize);
116
- var endChunk = Math.floor((end - 1) / chunkSize) + 1;
117
- for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
118
- if (!this.loadedChunks[chunk]) {
119
- throw new _util.MissingDataException(begin, end);
120
- }
90
+ }
91
+ }
92
+
93
+ onReceiveProgressiveData(data) {
94
+ let position = this.progressiveDataLength;
95
+ const beginChunk = Math.floor(position / this.chunkSize);
96
+ this.bytes.set(new Uint8Array(data), position);
97
+ position += data.byteLength;
98
+ this.progressiveDataLength = position;
99
+ const endChunk = position >= this.end ? this.numChunks : Math.floor(position / this.chunkSize);
100
+
101
+ for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
102
+ if (!this.loadedChunks[curChunk]) {
103
+ this.loadedChunks[curChunk] = true;
104
+ ++this.numChunksLoaded;
121
105
  }
122
- },
123
- nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
124
- var chunk,
125
- numChunks = this.numChunks;
126
- for (var i = 0; i < numChunks; ++i) {
127
- chunk = (beginChunk + i) % numChunks;
128
- if (!this.loadedChunks[chunk]) {
129
- return chunk;
130
- }
106
+ }
107
+ }
108
+
109
+ ensureByte(pos) {
110
+ if (pos < this.progressiveDataLength) {
111
+ return;
112
+ }
113
+
114
+ const chunk = Math.floor(pos / this.chunkSize);
115
+
116
+ if (chunk === this.lastSuccessfulEnsureByteChunk) {
117
+ return;
118
+ }
119
+
120
+ if (!this.loadedChunks[chunk]) {
121
+ throw new _core_utils.MissingDataException(pos, pos + 1);
122
+ }
123
+
124
+ this.lastSuccessfulEnsureByteChunk = chunk;
125
+ }
126
+
127
+ ensureRange(begin, end) {
128
+ if (begin >= end) {
129
+ return;
130
+ }
131
+
132
+ if (end <= this.progressiveDataLength) {
133
+ return;
134
+ }
135
+
136
+ const chunkSize = this.chunkSize;
137
+ const beginChunk = Math.floor(begin / chunkSize);
138
+ const endChunk = Math.floor((end - 1) / chunkSize) + 1;
139
+
140
+ for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
141
+ if (!this.loadedChunks[chunk]) {
142
+ throw new _core_utils.MissingDataException(begin, end);
131
143
  }
132
- return null;
133
- },
134
- hasChunk: function ChunkedStream_hasChunk(chunk) {
135
- return !!this.loadedChunks[chunk];
136
- },
137
- get length() {
138
- return this.end - this.start;
139
- },
140
- get isEmpty() {
141
- return this.length === 0;
142
- },
143
- getByte: function ChunkedStream_getByte() {
144
- var pos = this.pos;
145
- if (pos >= this.end) {
146
- return -1;
144
+ }
145
+ }
146
+
147
+ nextEmptyChunk(beginChunk) {
148
+ const numChunks = this.numChunks;
149
+
150
+ for (let i = 0; i < numChunks; ++i) {
151
+ const chunk = (beginChunk + i) % numChunks;
152
+
153
+ if (!this.loadedChunks[chunk]) {
154
+ return chunk;
147
155
  }
156
+ }
157
+
158
+ return null;
159
+ }
160
+
161
+ hasChunk(chunk) {
162
+ return !!this.loadedChunks[chunk];
163
+ }
164
+
165
+ get length() {
166
+ return this.end - this.start;
167
+ }
168
+
169
+ get isEmpty() {
170
+ return this.length === 0;
171
+ }
172
+
173
+ getByte() {
174
+ const pos = this.pos;
175
+
176
+ if (pos >= this.end) {
177
+ return -1;
178
+ }
179
+
180
+ if (pos >= this.progressiveDataLength) {
148
181
  this.ensureByte(pos);
149
- return this.bytes[this.pos++];
150
- },
151
- getUint16: function ChunkedStream_getUint16() {
152
- var b0 = this.getByte();
153
- var b1 = this.getByte();
154
- if (b0 === -1 || b1 === -1) {
155
- return -1;
156
- }
157
- return (b0 << 8) + b1;
158
- },
159
- getInt32: function ChunkedStream_getInt32() {
160
- var b0 = this.getByte();
161
- var b1 = this.getByte();
162
- var b2 = this.getByte();
163
- var b3 = this.getByte();
164
- return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
165
- },
166
- getBytes: function getBytes(length) {
167
- var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
168
-
169
- var bytes = this.bytes;
170
- var pos = this.pos;
171
- var strEnd = this.end;
172
- if (!length) {
182
+ }
183
+
184
+ return this.bytes[this.pos++];
185
+ }
186
+
187
+ getUint16() {
188
+ const b0 = this.getByte();
189
+ const b1 = this.getByte();
190
+
191
+ if (b0 === -1 || b1 === -1) {
192
+ return -1;
193
+ }
194
+
195
+ return (b0 << 8) + b1;
196
+ }
197
+
198
+ getInt32() {
199
+ const b0 = this.getByte();
200
+ const b1 = this.getByte();
201
+ const b2 = this.getByte();
202
+ const b3 = this.getByte();
203
+ return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
204
+ }
205
+
206
+ getBytes(length, forceClamped = false) {
207
+ const bytes = this.bytes;
208
+ const pos = this.pos;
209
+ const strEnd = this.end;
210
+
211
+ if (!length) {
212
+ if (strEnd > this.progressiveDataLength) {
173
213
  this.ensureRange(pos, strEnd);
174
- var _subarray = bytes.subarray(pos, strEnd);
175
- return forceClamped ? new Uint8ClampedArray(_subarray) : _subarray;
176
214
  }
177
- var end = pos + length;
178
- if (end > strEnd) {
179
- end = strEnd;
180
- }
181
- this.ensureRange(pos, end);
182
- this.pos = end;
183
- var subarray = bytes.subarray(pos, end);
215
+
216
+ const subarray = bytes.subarray(pos, strEnd);
184
217
  return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
185
- },
218
+ }
219
+
220
+ let end = pos + length;
221
+
222
+ if (end > strEnd) {
223
+ end = strEnd;
224
+ }
225
+
226
+ if (end > this.progressiveDataLength) {
227
+ this.ensureRange(pos, end);
228
+ }
186
229
 
187
- peekByte: function ChunkedStream_peekByte() {
188
- var peekedByte = this.getByte();
230
+ this.pos = end;
231
+ const subarray = bytes.subarray(pos, end);
232
+ return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
233
+ }
234
+
235
+ peekByte() {
236
+ const peekedByte = this.getByte();
237
+
238
+ if (peekedByte !== -1) {
189
239
  this.pos--;
190
- return peekedByte;
191
- },
192
- peekBytes: function peekBytes(length) {
193
- var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
240
+ }
194
241
 
195
- var bytes = this.getBytes(length, forceClamped);
196
- this.pos -= bytes.length;
197
- return bytes;
198
- },
242
+ return peekedByte;
243
+ }
244
+
245
+ peekBytes(length, forceClamped = false) {
246
+ const bytes = this.getBytes(length, forceClamped);
247
+ this.pos -= bytes.length;
248
+ return bytes;
249
+ }
250
+
251
+ getByteRange(begin, end) {
252
+ if (begin < 0) {
253
+ begin = 0;
254
+ }
199
255
 
200
- getByteRange: function ChunkedStream_getBytes(begin, end) {
256
+ if (end > this.end) {
257
+ end = this.end;
258
+ }
259
+
260
+ if (end > this.progressiveDataLength) {
201
261
  this.ensureRange(begin, end);
202
- return this.bytes.subarray(begin, end);
203
- },
204
- skip: function ChunkedStream_skip(n) {
205
- if (!n) {
206
- n = 1;
262
+ }
263
+
264
+ return this.bytes.subarray(begin, end);
265
+ }
266
+
267
+ skip(n) {
268
+ if (!n) {
269
+ n = 1;
270
+ }
271
+
272
+ this.pos += n;
273
+ }
274
+
275
+ reset() {
276
+ this.pos = this.start;
277
+ }
278
+
279
+ moveStart() {
280
+ this.start = this.pos;
281
+ }
282
+
283
+ makeSubStream(start, length, dict) {
284
+ if (length) {
285
+ if (start + length > this.progressiveDataLength) {
286
+ this.ensureRange(start, start + length);
207
287
  }
208
- this.pos += n;
209
- },
210
- reset: function ChunkedStream_reset() {
211
- this.pos = this.start;
212
- },
213
- moveStart: function ChunkedStream_moveStart() {
214
- this.start = this.pos;
215
- },
216
- makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
217
- this.ensureRange(start, start + length);
218
- function ChunkedStreamSubstream() {}
219
- ChunkedStreamSubstream.prototype = Object.create(this);
220
- ChunkedStreamSubstream.prototype.getMissingChunks = function () {
221
- var chunkSize = this.chunkSize;
222
- var beginChunk = Math.floor(this.start / chunkSize);
223
- var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
224
- var missingChunks = [];
225
- for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
226
- if (!this.loadedChunks[chunk]) {
227
- missingChunks.push(chunk);
228
- }
288
+ } else {
289
+ if (start >= this.progressiveDataLength) {
290
+ this.ensureByte(start);
291
+ }
292
+ }
293
+
294
+ function ChunkedStreamSubstream() {}
295
+
296
+ ChunkedStreamSubstream.prototype = Object.create(this);
297
+
298
+ ChunkedStreamSubstream.prototype.getMissingChunks = function () {
299
+ const chunkSize = this.chunkSize;
300
+ const beginChunk = Math.floor(this.start / chunkSize);
301
+ const endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
302
+ const missingChunks = [];
303
+
304
+ for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
305
+ if (!this.loadedChunks[chunk]) {
306
+ missingChunks.push(chunk);
229
307
  }
230
- return missingChunks;
231
- };
232
- var subStream = new ChunkedStreamSubstream();
233
- subStream.pos = subStream.start = start;
234
- subStream.end = start + length || this.end;
235
- subStream.dict = dict;
236
- return subStream;
237
- }
238
- };
239
- return ChunkedStream;
240
- }();
241
- var ChunkedStreamManager = function ChunkedStreamManagerClosure() {
242
- function ChunkedStreamManager(pdfNetworkStream, args) {
243
- var chunkSize = args.rangeChunkSize;
244
- var length = args.length;
245
- this.stream = new ChunkedStream(length, chunkSize, this);
246
- this.length = length;
247
- this.chunkSize = chunkSize;
308
+ }
309
+
310
+ return missingChunks;
311
+ };
312
+
313
+ ChunkedStreamSubstream.prototype.allChunksLoaded = function () {
314
+ if (this.numChunksLoaded === this.numChunks) {
315
+ return true;
316
+ }
317
+
318
+ return this.getMissingChunks().length === 0;
319
+ };
320
+
321
+ const subStream = new ChunkedStreamSubstream();
322
+ subStream.pos = subStream.start = start;
323
+ subStream.end = start + length || this.end;
324
+ subStream.dict = dict;
325
+ return subStream;
326
+ }
327
+
328
+ }
329
+
330
+ exports.ChunkedStream = ChunkedStream;
331
+
332
+ class ChunkedStreamManager {
333
+ constructor(pdfNetworkStream, args) {
334
+ this.length = args.length;
335
+ this.chunkSize = args.rangeChunkSize;
336
+ this.stream = new ChunkedStream(this.length, this.chunkSize, this);
248
337
  this.pdfNetworkStream = pdfNetworkStream;
249
- this.url = args.url;
250
338
  this.disableAutoFetch = args.disableAutoFetch;
251
339
  this.msgHandler = args.msgHandler;
252
340
  this.currRequestId = 0;
@@ -257,237 +345,284 @@ var ChunkedStreamManager = function ChunkedStreamManagerClosure() {
257
345
  this.aborted = false;
258
346
  this._loadedStreamCapability = (0, _util.createPromiseCapability)();
259
347
  }
260
- ChunkedStreamManager.prototype = {
261
- onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
262
- return this._loadedStreamCapability.promise;
263
- },
264
- sendRequest: function ChunkedStreamManager_sendRequest(begin, end) {
265
- var _this = this;
266
348
 
267
- var rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
268
- if (!rangeReader.isStreamingSupported) {
269
- rangeReader.onProgress = this.onProgress.bind(this);
270
- }
271
- var chunks = [],
272
- loaded = 0;
273
- var manager = this;
274
- var promise = new Promise(function (resolve, reject) {
275
- var readChunk = function readChunk(chunk) {
276
- try {
277
- if (!chunk.done) {
278
- var data = chunk.value;
279
- chunks.push(data);
280
- loaded += (0, _util.arrayByteLength)(data);
281
- if (rangeReader.isStreamingSupported) {
282
- manager.onProgress({ loaded: loaded });
283
- }
284
- rangeReader.read().then(readChunk, reject);
285
- return;
349
+ onLoadedStream() {
350
+ return this._loadedStreamCapability.promise;
351
+ }
352
+
353
+ sendRequest(begin, end) {
354
+ const rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
355
+
356
+ if (!rangeReader.isStreamingSupported) {
357
+ rangeReader.onProgress = this.onProgress.bind(this);
358
+ }
359
+
360
+ let chunks = [],
361
+ loaded = 0;
362
+ const promise = new Promise((resolve, reject) => {
363
+ const readChunk = chunk => {
364
+ try {
365
+ if (!chunk.done) {
366
+ const data = chunk.value;
367
+ chunks.push(data);
368
+ loaded += (0, _util.arrayByteLength)(data);
369
+
370
+ if (rangeReader.isStreamingSupported) {
371
+ this.onProgress({
372
+ loaded
373
+ });
286
374
  }
287
- var chunkData = (0, _util.arraysToBytes)(chunks);
288
- chunks = null;
289
- resolve(chunkData);
290
- } catch (e) {
291
- reject(e);
375
+
376
+ rangeReader.read().then(readChunk, reject);
377
+ return;
292
378
  }
293
- };
294
- rangeReader.read().then(readChunk, reject);
295
- });
296
- promise.then(function (data) {
297
- if (_this.aborted) {
298
- return;
379
+
380
+ const chunkData = (0, _util.arraysToBytes)(chunks);
381
+ chunks = null;
382
+ resolve(chunkData);
383
+ } catch (e) {
384
+ reject(e);
299
385
  }
300
- _this.onReceiveData({
301
- chunk: data,
302
- begin: begin
303
- });
386
+ };
387
+
388
+ rangeReader.read().then(readChunk, reject);
389
+ });
390
+ promise.then(data => {
391
+ if (this.aborted) {
392
+ return;
393
+ }
394
+
395
+ this.onReceiveData({
396
+ chunk: data,
397
+ begin
304
398
  });
305
- },
306
- requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
307
- var missingChunks = this.stream.getMissingChunks();
308
- this._requestChunks(missingChunks);
309
- return this._loadedStreamCapability.promise;
310
- },
311
- _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
312
- var requestId = this.currRequestId++;
313
- var i, ii;
314
- var chunksNeeded = Object.create(null);
315
- this.chunksNeededByRequest[requestId] = chunksNeeded;
316
- for (i = 0, ii = chunks.length; i < ii; i++) {
317
- if (!this.stream.hasChunk(chunks[i])) {
318
- chunksNeeded[chunks[i]] = true;
319
- }
399
+ });
400
+ }
401
+
402
+ requestAllChunks() {
403
+ const missingChunks = this.stream.getMissingChunks();
404
+
405
+ this._requestChunks(missingChunks);
406
+
407
+ return this._loadedStreamCapability.promise;
408
+ }
409
+
410
+ _requestChunks(chunks) {
411
+ const requestId = this.currRequestId++;
412
+ const chunksNeeded = Object.create(null);
413
+ this.chunksNeededByRequest[requestId] = chunksNeeded;
414
+
415
+ for (const chunk of chunks) {
416
+ if (!this.stream.hasChunk(chunk)) {
417
+ chunksNeeded[chunk] = true;
320
418
  }
321
- if ((0, _util.isEmptyObj)(chunksNeeded)) {
322
- return Promise.resolve();
419
+ }
420
+
421
+ if ((0, _util.isEmptyObj)(chunksNeeded)) {
422
+ return Promise.resolve();
423
+ }
424
+
425
+ const capability = (0, _util.createPromiseCapability)();
426
+ this.promisesByRequest[requestId] = capability;
427
+ const chunksToRequest = [];
428
+
429
+ for (let chunk in chunksNeeded) {
430
+ chunk = chunk | 0;
431
+
432
+ if (!(chunk in this.requestsByChunk)) {
433
+ this.requestsByChunk[chunk] = [];
434
+ chunksToRequest.push(chunk);
323
435
  }
324
- var capability = (0, _util.createPromiseCapability)();
325
- this.promisesByRequest[requestId] = capability;
326
- var chunksToRequest = [];
327
- for (var chunk in chunksNeeded) {
328
- chunk = chunk | 0;
329
- if (!(chunk in this.requestsByChunk)) {
330
- this.requestsByChunk[chunk] = [];
436
+
437
+ this.requestsByChunk[chunk].push(requestId);
438
+ }
439
+
440
+ if (!chunksToRequest.length) {
441
+ return capability.promise;
442
+ }
443
+
444
+ const groupedChunksToRequest = this.groupChunks(chunksToRequest);
445
+
446
+ for (const groupedChunk of groupedChunksToRequest) {
447
+ const begin = groupedChunk.beginChunk * this.chunkSize;
448
+ const end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
449
+ this.sendRequest(begin, end);
450
+ }
451
+
452
+ return capability.promise;
453
+ }
454
+
455
+ getStream() {
456
+ return this.stream;
457
+ }
458
+
459
+ requestRange(begin, end) {
460
+ end = Math.min(end, this.length);
461
+ const beginChunk = this.getBeginChunk(begin);
462
+ const endChunk = this.getEndChunk(end);
463
+ const chunks = [];
464
+
465
+ for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
466
+ chunks.push(chunk);
467
+ }
468
+
469
+ return this._requestChunks(chunks);
470
+ }
471
+
472
+ requestRanges(ranges = []) {
473
+ const chunksToRequest = [];
474
+
475
+ for (const range of ranges) {
476
+ const beginChunk = this.getBeginChunk(range.begin);
477
+ const endChunk = this.getEndChunk(range.end);
478
+
479
+ for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
480
+ if (!chunksToRequest.includes(chunk)) {
331
481
  chunksToRequest.push(chunk);
332
482
  }
333
- this.requestsByChunk[chunk].push(requestId);
334
483
  }
335
- if (!chunksToRequest.length) {
336
- return capability.promise;
337
- }
338
- var groupedChunksToRequest = this.groupChunks(chunksToRequest);
339
- for (i = 0; i < groupedChunksToRequest.length; ++i) {
340
- var groupedChunk = groupedChunksToRequest[i];
341
- var begin = groupedChunk.beginChunk * this.chunkSize;
342
- var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
343
- this.sendRequest(begin, end);
484
+ }
485
+
486
+ chunksToRequest.sort(function (a, b) {
487
+ return a - b;
488
+ });
489
+ return this._requestChunks(chunksToRequest);
490
+ }
491
+
492
+ groupChunks(chunks) {
493
+ const groupedChunks = [];
494
+ let beginChunk = -1;
495
+ let prevChunk = -1;
496
+
497
+ for (let i = 0, ii = chunks.length; i < ii; ++i) {
498
+ const chunk = chunks[i];
499
+
500
+ if (beginChunk < 0) {
501
+ beginChunk = chunk;
344
502
  }
345
- return capability.promise;
346
- },
347
- getStream: function ChunkedStreamManager_getStream() {
348
- return this.stream;
349
- },
350
- requestRange: function ChunkedStreamManager_requestRange(begin, end) {
351
- end = Math.min(end, this.length);
352
- var beginChunk = this.getBeginChunk(begin);
353
- var endChunk = this.getEndChunk(end);
354
- var chunks = [];
355
- for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
356
- chunks.push(chunk);
503
+
504
+ if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
505
+ groupedChunks.push({
506
+ beginChunk,
507
+ endChunk: prevChunk + 1
508
+ });
509
+ beginChunk = chunk;
357
510
  }
358
- return this._requestChunks(chunks);
359
- },
360
- requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
361
- ranges = ranges || [];
362
- var chunksToRequest = [];
363
- for (var i = 0; i < ranges.length; i++) {
364
- var beginChunk = this.getBeginChunk(ranges[i].begin);
365
- var endChunk = this.getEndChunk(ranges[i].end);
366
- for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
367
- if (!chunksToRequest.includes(chunk)) {
368
- chunksToRequest.push(chunk);
369
- }
370
- }
511
+
512
+ if (i + 1 === chunks.length) {
513
+ groupedChunks.push({
514
+ beginChunk,
515
+ endChunk: chunk + 1
516
+ });
371
517
  }
372
- chunksToRequest.sort(function (a, b) {
373
- return a - b;
374
- });
375
- return this._requestChunks(chunksToRequest);
376
- },
377
- groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
378
- var groupedChunks = [];
379
- var beginChunk = -1;
380
- var prevChunk = -1;
381
- for (var i = 0; i < chunks.length; ++i) {
382
- var chunk = chunks[i];
383
- if (beginChunk < 0) {
384
- beginChunk = chunk;
385
- }
386
- if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
387
- groupedChunks.push({
388
- beginChunk: beginChunk,
389
- endChunk: prevChunk + 1
390
- });
391
- beginChunk = chunk;
392
- }
393
- if (i + 1 === chunks.length) {
394
- groupedChunks.push({
395
- beginChunk: beginChunk,
396
- endChunk: chunk + 1
397
- });
518
+
519
+ prevChunk = chunk;
520
+ }
521
+
522
+ return groupedChunks;
523
+ }
524
+
525
+ onProgress(args) {
526
+ this.msgHandler.send("DocProgress", {
527
+ loaded: this.stream.numChunksLoaded * this.chunkSize + args.loaded,
528
+ total: this.length
529
+ });
530
+ }
531
+
532
+ onReceiveData(args) {
533
+ const chunk = args.chunk;
534
+ const isProgressive = args.begin === undefined;
535
+ const begin = isProgressive ? this.progressiveDataLength : args.begin;
536
+ const end = begin + chunk.byteLength;
537
+ const beginChunk = Math.floor(begin / this.chunkSize);
538
+ const endChunk = end < this.length ? Math.floor(end / this.chunkSize) : Math.ceil(end / this.chunkSize);
539
+
540
+ if (isProgressive) {
541
+ this.stream.onReceiveProgressiveData(chunk);
542
+ this.progressiveDataLength = end;
543
+ } else {
544
+ this.stream.onReceiveData(begin, chunk);
545
+ }
546
+
547
+ if (this.stream.allChunksLoaded()) {
548
+ this._loadedStreamCapability.resolve(this.stream);
549
+ }
550
+
551
+ const loadedRequests = [];
552
+
553
+ for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
554
+ const requestIds = this.requestsByChunk[chunk] || [];
555
+ delete this.requestsByChunk[chunk];
556
+
557
+ for (const requestId of requestIds) {
558
+ const chunksNeeded = this.chunksNeededByRequest[requestId];
559
+
560
+ if (chunk in chunksNeeded) {
561
+ delete chunksNeeded[chunk];
398
562
  }
399
- prevChunk = chunk;
400
- }
401
- return groupedChunks;
402
- },
403
- onProgress: function ChunkedStreamManager_onProgress(args) {
404
- var bytesLoaded = this.stream.numChunksLoaded * this.chunkSize + args.loaded;
405
- this.msgHandler.send('DocProgress', {
406
- loaded: bytesLoaded,
407
- total: this.length
408
- });
409
- },
410
- onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
411
- var chunk = args.chunk;
412
- var isProgressive = args.begin === undefined;
413
- var begin = isProgressive ? this.progressiveDataLength : args.begin;
414
- var end = begin + chunk.byteLength;
415
- var beginChunk = Math.floor(begin / this.chunkSize);
416
- var endChunk = end < this.length ? Math.floor(end / this.chunkSize) : Math.ceil(end / this.chunkSize);
417
- if (isProgressive) {
418
- this.stream.onReceiveProgressiveData(chunk);
419
- this.progressiveDataLength = end;
420
- } else {
421
- this.stream.onReceiveData(begin, chunk);
422
- }
423
- if (this.stream.allChunksLoaded()) {
424
- this._loadedStreamCapability.resolve(this.stream);
425
- }
426
- var loadedRequests = [];
427
- var i, requestId;
428
- for (chunk = beginChunk; chunk < endChunk; ++chunk) {
429
- var requestIds = this.requestsByChunk[chunk] || [];
430
- delete this.requestsByChunk[chunk];
431
- for (i = 0; i < requestIds.length; ++i) {
432
- requestId = requestIds[i];
433
- var chunksNeeded = this.chunksNeededByRequest[requestId];
434
- if (chunk in chunksNeeded) {
435
- delete chunksNeeded[chunk];
436
- }
437
- if (!(0, _util.isEmptyObj)(chunksNeeded)) {
438
- continue;
439
- }
440
- loadedRequests.push(requestId);
563
+
564
+ if (!(0, _util.isEmptyObj)(chunksNeeded)) {
565
+ continue;
441
566
  }
567
+
568
+ loadedRequests.push(requestId);
442
569
  }
443
- if (!this.disableAutoFetch && (0, _util.isEmptyObj)(this.requestsByChunk)) {
444
- var nextEmptyChunk;
445
- if (this.stream.numChunksLoaded === 1) {
446
- var lastChunk = this.stream.numChunks - 1;
447
- if (!this.stream.hasChunk(lastChunk)) {
448
- nextEmptyChunk = lastChunk;
449
- }
450
- } else {
451
- nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
452
- }
453
- if (Number.isInteger(nextEmptyChunk)) {
454
- this._requestChunks([nextEmptyChunk]);
570
+ }
571
+
572
+ if (!this.disableAutoFetch && (0, _util.isEmptyObj)(this.requestsByChunk)) {
573
+ let nextEmptyChunk;
574
+
575
+ if (this.stream.numChunksLoaded === 1) {
576
+ const lastChunk = this.stream.numChunks - 1;
577
+
578
+ if (!this.stream.hasChunk(lastChunk)) {
579
+ nextEmptyChunk = lastChunk;
455
580
  }
581
+ } else {
582
+ nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
456
583
  }
457
- for (i = 0; i < loadedRequests.length; ++i) {
458
- requestId = loadedRequests[i];
459
- var capability = this.promisesByRequest[requestId];
460
- delete this.promisesByRequest[requestId];
461
- capability.resolve();
462
- }
463
- this.msgHandler.send('DocProgress', {
464
- loaded: this.stream.numChunksLoaded * this.chunkSize,
465
- total: this.length
466
- });
467
- },
468
- onError: function ChunkedStreamManager_onError(err) {
469
- this._loadedStreamCapability.reject(err);
470
- },
471
- getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
472
- var chunk = Math.floor(begin / this.chunkSize);
473
- return chunk;
474
- },
475
- getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
476
- var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
477
- return chunk;
478
- },
479
- abort: function ChunkedStreamManager_abort() {
480
- this.aborted = true;
481
- if (this.pdfNetworkStream) {
482
- this.pdfNetworkStream.cancelAllRequests('abort');
483
- }
484
- for (var requestId in this.promisesByRequest) {
485
- var capability = this.promisesByRequest[requestId];
486
- capability.reject(new Error('Request was aborted'));
584
+
585
+ if (Number.isInteger(nextEmptyChunk)) {
586
+ this._requestChunks([nextEmptyChunk]);
487
587
  }
488
588
  }
489
- };
490
- return ChunkedStreamManager;
491
- }();
492
- exports.ChunkedStream = ChunkedStream;
589
+
590
+ for (const requestId of loadedRequests) {
591
+ const capability = this.promisesByRequest[requestId];
592
+ delete this.promisesByRequest[requestId];
593
+ capability.resolve();
594
+ }
595
+
596
+ this.msgHandler.send("DocProgress", {
597
+ loaded: this.stream.numChunksLoaded * this.chunkSize,
598
+ total: this.length
599
+ });
600
+ }
601
+
602
+ onError(err) {
603
+ this._loadedStreamCapability.reject(err);
604
+ }
605
+
606
+ getBeginChunk(begin) {
607
+ return Math.floor(begin / this.chunkSize);
608
+ }
609
+
610
+ getEndChunk(end) {
611
+ return Math.floor((end - 1) / this.chunkSize) + 1;
612
+ }
613
+
614
+ abort(reason) {
615
+ this.aborted = true;
616
+
617
+ if (this.pdfNetworkStream) {
618
+ this.pdfNetworkStream.cancelAllRequests(reason);
619
+ }
620
+
621
+ for (const requestId in this.promisesByRequest) {
622
+ this.promisesByRequest[requestId].reject(reason);
623
+ }
624
+ }
625
+
626
+ }
627
+
493
628
  exports.ChunkedStreamManager = ChunkedStreamManager;