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,18 +19,18 @@
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.LZWStream = exports.StringStream = exports.StreamsSequenceStream = exports.Stream = exports.RunLengthStream = exports.PredictorStream = exports.NullStream = exports.FlateStream = exports.DecodeStream = exports.DecryptStream = exports.AsciiHexStream = exports.Ascii85Stream = undefined;
27
+ exports.LZWStream = exports.StringStream = exports.StreamsSequenceStream = exports.Stream = exports.RunLengthStream = exports.PredictorStream = exports.NullStream = exports.FlateStream = exports.DecodeStream = exports.DecryptStream = exports.AsciiHexStream = exports.Ascii85Stream = void 0;
28
28
 
29
- var _util = require('../shared/util');
29
+ var _util = require("../shared/util.js");
30
30
 
31
- var _primitives = require('./primitives');
31
+ var _primitives = require("./primitives.js");
32
32
 
33
- function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
33
+ var _core_utils = require("./core_utils.js");
34
34
 
35
35
  var Stream = function StreamClosure() {
36
36
  function Stream(arrayBuffer, start, length, dict) {
@@ -40,25 +40,31 @@ var Stream = function StreamClosure() {
40
40
  this.end = start + length || this.bytes.length;
41
41
  this.dict = dict;
42
42
  }
43
+
43
44
  Stream.prototype = {
44
45
  get length() {
45
46
  return this.end - this.start;
46
47
  },
48
+
47
49
  get isEmpty() {
48
50
  return this.length === 0;
49
51
  },
52
+
50
53
  getByte: function Stream_getByte() {
51
54
  if (this.pos >= this.end) {
52
55
  return -1;
53
56
  }
57
+
54
58
  return this.bytes[this.pos++];
55
59
  },
56
60
  getUint16: function Stream_getUint16() {
57
61
  var b0 = this.getByte();
58
62
  var b1 = this.getByte();
63
+
59
64
  if (b0 === -1 || b1 === -1) {
60
65
  return -1;
61
66
  }
67
+
62
68
  return (b0 << 8) + b1;
63
69
  },
64
70
  getInt32: function Stream_getInt32() {
@@ -68,42 +74,61 @@ var Stream = function StreamClosure() {
68
74
  var b3 = this.getByte();
69
75
  return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
70
76
  },
71
- getBytes: function getBytes(length) {
72
- var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
73
77
 
78
+ getBytes(length, forceClamped = false) {
74
79
  var bytes = this.bytes;
75
80
  var pos = this.pos;
76
81
  var strEnd = this.end;
82
+
77
83
  if (!length) {
78
- var _subarray = bytes.subarray(pos, strEnd);
79
- return forceClamped ? new Uint8ClampedArray(_subarray) : _subarray;
84
+ const subarray = bytes.subarray(pos, strEnd);
85
+ return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
80
86
  }
87
+
81
88
  var end = pos + length;
89
+
82
90
  if (end > strEnd) {
83
91
  end = strEnd;
84
92
  }
93
+
85
94
  this.pos = end;
86
- var subarray = bytes.subarray(pos, end);
95
+ const subarray = bytes.subarray(pos, end);
87
96
  return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
88
97
  },
89
98
 
90
99
  peekByte: function Stream_peekByte() {
91
100
  var peekedByte = this.getByte();
92
- this.pos--;
101
+
102
+ if (peekedByte !== -1) {
103
+ this.pos--;
104
+ }
105
+
93
106
  return peekedByte;
94
107
  },
95
- peekBytes: function peekBytes(length) {
96
- var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
97
108
 
109
+ peekBytes(length, forceClamped = false) {
98
110
  var bytes = this.getBytes(length, forceClamped);
99
111
  this.pos -= bytes.length;
100
112
  return bytes;
101
113
  },
102
114
 
115
+ getByteRange(begin, end) {
116
+ if (begin < 0) {
117
+ begin = 0;
118
+ }
119
+
120
+ if (end > this.end) {
121
+ end = this.end;
122
+ }
123
+
124
+ return this.bytes.subarray(begin, end);
125
+ },
126
+
103
127
  skip: function Stream_skip(n) {
104
128
  if (!n) {
105
129
  n = 1;
106
130
  }
131
+
107
132
  this.pos += n;
108
133
  },
109
134
  reset: function Stream_reset() {
@@ -118,16 +143,24 @@ var Stream = function StreamClosure() {
118
143
  };
119
144
  return Stream;
120
145
  }();
146
+
147
+ exports.Stream = Stream;
148
+
121
149
  var StringStream = function StringStreamClosure() {
122
150
  function StringStream(str) {
123
- var bytes = (0, _util.stringToBytes)(str);
151
+ const bytes = (0, _util.stringToBytes)(str);
124
152
  Stream.call(this, bytes);
125
153
  }
154
+
126
155
  StringStream.prototype = Stream.prototype;
127
156
  return StringStream;
128
157
  }();
158
+
159
+ exports.StringStream = StringStream;
160
+
129
161
  var DecodeStream = function DecodeStreamClosure() {
130
162
  var emptyBuffer = new Uint8Array(0);
163
+
131
164
  function DecodeStream(maybeMinBufferLength) {
132
165
  this._rawMinBufferLength = maybeMinBufferLength || 0;
133
166
  this.pos = 0;
@@ -135,48 +168,61 @@ var DecodeStream = function DecodeStreamClosure() {
135
168
  this.eof = false;
136
169
  this.buffer = emptyBuffer;
137
170
  this.minBufferLength = 512;
171
+
138
172
  if (maybeMinBufferLength) {
139
173
  while (this.minBufferLength < maybeMinBufferLength) {
140
174
  this.minBufferLength *= 2;
141
175
  }
142
176
  }
143
177
  }
178
+
144
179
  DecodeStream.prototype = {
145
180
  get isEmpty() {
146
181
  while (!this.eof && this.bufferLength === 0) {
147
182
  this.readBlock();
148
183
  }
184
+
149
185
  return this.bufferLength === 0;
150
186
  },
187
+
151
188
  ensureBuffer: function DecodeStream_ensureBuffer(requested) {
152
189
  var buffer = this.buffer;
190
+
153
191
  if (requested <= buffer.byteLength) {
154
192
  return buffer;
155
193
  }
194
+
156
195
  var size = this.minBufferLength;
196
+
157
197
  while (size < requested) {
158
198
  size *= 2;
159
199
  }
200
+
160
201
  var buffer2 = new Uint8Array(size);
161
202
  buffer2.set(buffer);
162
203
  return this.buffer = buffer2;
163
204
  },
164
205
  getByte: function DecodeStream_getByte() {
165
206
  var pos = this.pos;
207
+
166
208
  while (this.bufferLength <= pos) {
167
209
  if (this.eof) {
168
210
  return -1;
169
211
  }
212
+
170
213
  this.readBlock();
171
214
  }
215
+
172
216
  return this.buffer[this.pos++];
173
217
  },
174
218
  getUint16: function DecodeStream_getUint16() {
175
219
  var b0 = this.getByte();
176
220
  var b1 = this.getByte();
221
+
177
222
  if (b0 === -1 || b1 === -1) {
178
223
  return -1;
179
224
  }
225
+
180
226
  return (b0 << 8) + b1;
181
227
  },
182
228
  getInt32: function DecodeStream_getInt32() {
@@ -186,18 +232,21 @@ var DecodeStream = function DecodeStreamClosure() {
186
232
  var b3 = this.getByte();
187
233
  return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
188
234
  },
189
- getBytes: function getBytes(length) {
190
- var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
191
235
 
236
+ getBytes(length, forceClamped = false) {
192
237
  var end,
193
238
  pos = this.pos;
239
+
194
240
  if (length) {
195
241
  this.ensureBuffer(pos + length);
196
242
  end = pos + length;
243
+
197
244
  while (!this.eof && this.bufferLength < end) {
198
245
  this.readBlock();
199
246
  }
247
+
200
248
  var bufEnd = this.bufferLength;
249
+
201
250
  if (end > bufEnd) {
202
251
  end = bufEnd;
203
252
  }
@@ -205,21 +254,26 @@ var DecodeStream = function DecodeStreamClosure() {
205
254
  while (!this.eof) {
206
255
  this.readBlock();
207
256
  }
257
+
208
258
  end = this.bufferLength;
209
259
  }
260
+
210
261
  this.pos = end;
211
- var subarray = this.buffer.subarray(pos, end);
262
+ const subarray = this.buffer.subarray(pos, end);
212
263
  return forceClamped && !(subarray instanceof Uint8ClampedArray) ? new Uint8ClampedArray(subarray) : subarray;
213
264
  },
214
265
 
215
266
  peekByte: function DecodeStream_peekByte() {
216
267
  var peekedByte = this.getByte();
217
- this.pos--;
268
+
269
+ if (peekedByte !== -1) {
270
+ this.pos--;
271
+ }
272
+
218
273
  return peekedByte;
219
274
  },
220
- peekBytes: function peekBytes(length) {
221
- var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
222
275
 
276
+ peekBytes(length, forceClamped = false) {
223
277
  var bytes = this.getBytes(length, forceClamped);
224
278
  this.pos -= bytes.length;
225
279
  return bytes;
@@ -227,15 +281,23 @@ var DecodeStream = function DecodeStreamClosure() {
227
281
 
228
282
  makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
229
283
  var end = start + length;
284
+
230
285
  while (this.bufferLength <= end && !this.eof) {
231
286
  this.readBlock();
232
287
  }
288
+
233
289
  return new Stream(this.buffer, start, length, dict);
234
290
  },
291
+
292
+ getByteRange(begin, end) {
293
+ (0, _util.unreachable)("Should not call DecodeStream.getByteRange");
294
+ },
295
+
235
296
  skip: function DecodeStream_skip(n) {
236
297
  if (!n) {
237
298
  n = 1;
238
299
  }
300
+
239
301
  this.pos += n;
240
302
  },
241
303
  reset: function DecodeStream_reset() {
@@ -245,32 +307,43 @@ var DecodeStream = function DecodeStreamClosure() {
245
307
  if (this.str && this.str.getBaseStreams) {
246
308
  return this.str.getBaseStreams();
247
309
  }
310
+
248
311
  return [];
249
312
  }
250
313
  };
251
314
  return DecodeStream;
252
315
  }();
316
+
317
+ exports.DecodeStream = DecodeStream;
318
+
253
319
  var StreamsSequenceStream = function StreamsSequenceStreamClosure() {
254
320
  function StreamsSequenceStream(streams) {
255
321
  this.streams = streams;
256
- var maybeLength = 0;
257
- for (var i = 0, ii = streams.length; i < ii; i++) {
258
- var stream = streams[i];
322
+ let maybeLength = 0;
323
+
324
+ for (let i = 0, ii = streams.length; i < ii; i++) {
325
+ const stream = streams[i];
326
+
259
327
  if (stream instanceof DecodeStream) {
260
328
  maybeLength += stream._rawMinBufferLength;
261
329
  } else {
262
330
  maybeLength += stream.length;
263
331
  }
264
332
  }
333
+
265
334
  DecodeStream.call(this, maybeLength);
266
335
  }
336
+
267
337
  StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
338
+
268
339
  StreamsSequenceStream.prototype.readBlock = function streamSequenceStreamReadBlock() {
269
340
  var streams = this.streams;
341
+
270
342
  if (streams.length === 0) {
271
343
  this.eof = true;
272
344
  return;
273
345
  }
346
+
274
347
  var stream = streams.shift();
275
348
  var chunk = stream.getBytes();
276
349
  var bufferLength = this.bufferLength;
@@ -279,63 +352,83 @@ var StreamsSequenceStream = function StreamsSequenceStreamClosure() {
279
352
  buffer.set(chunk, bufferLength);
280
353
  this.bufferLength = newLength;
281
354
  };
355
+
282
356
  StreamsSequenceStream.prototype.getBaseStreams = function StreamsSequenceStream_getBaseStreams() {
283
357
  var baseStreams = [];
358
+
284
359
  for (var i = 0, ii = this.streams.length; i < ii; i++) {
285
360
  var stream = this.streams[i];
361
+
286
362
  if (stream.getBaseStreams) {
287
- baseStreams.push.apply(baseStreams, _toConsumableArray(stream.getBaseStreams()));
363
+ baseStreams.push(...stream.getBaseStreams());
288
364
  }
289
365
  }
366
+
290
367
  return baseStreams;
291
368
  };
369
+
292
370
  return StreamsSequenceStream;
293
371
  }();
372
+
373
+ exports.StreamsSequenceStream = StreamsSequenceStream;
374
+
294
375
  var FlateStream = function FlateStreamClosure() {
295
376
  var codeLenCodeMap = new Int32Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
296
377
  var lengthDecode = new Int32Array([0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a, 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f, 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073, 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102]);
297
378
  var distDecode = new Int32Array([0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d, 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1, 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01, 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001]);
298
379
  var fixedLitCodeTab = [new Int32Array([0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0, 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0, 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0, 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0, 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8, 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8, 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8, 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8, 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4, 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4, 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4, 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4, 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc, 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec, 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc, 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc, 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2, 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2, 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2, 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2, 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca, 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea, 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da, 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa, 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6, 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6, 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6, 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6, 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce, 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee, 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de, 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe, 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1, 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1, 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1, 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1, 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9, 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9, 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9, 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9, 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5, 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5, 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5, 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5, 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd, 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed, 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd, 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd, 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3, 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3, 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3, 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3, 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb, 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb, 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db, 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb, 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7, 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7, 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7, 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7, 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf, 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef, 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df, 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff]), 9];
299
380
  var fixedDistCodeTab = [new Int32Array([0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c, 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000, 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d, 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000]), 5];
381
+
300
382
  function FlateStream(str, maybeLength) {
301
383
  this.str = str;
302
384
  this.dict = str.dict;
303
385
  var cmf = str.getByte();
304
386
  var flg = str.getByte();
387
+
305
388
  if (cmf === -1 || flg === -1) {
306
- throw new _util.FormatError('Invalid header in flate stream: ' + cmf + ', ' + flg);
389
+ throw new _util.FormatError(`Invalid header in flate stream: ${cmf}, ${flg}`);
307
390
  }
391
+
308
392
  if ((cmf & 0x0f) !== 0x08) {
309
- throw new _util.FormatError('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
393
+ throw new _util.FormatError(`Unknown compression method in flate stream: ${cmf}, ${flg}`);
310
394
  }
395
+
311
396
  if (((cmf << 8) + flg) % 31 !== 0) {
312
- throw new _util.FormatError('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
397
+ throw new _util.FormatError(`Bad FCHECK in flate stream: ${cmf}, ${flg}`);
313
398
  }
399
+
314
400
  if (flg & 0x20) {
315
- throw new _util.FormatError('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
401
+ throw new _util.FormatError(`FDICT bit set in flate stream: ${cmf}, ${flg}`);
316
402
  }
403
+
317
404
  this.codeSize = 0;
318
405
  this.codeBuf = 0;
319
406
  DecodeStream.call(this, maybeLength);
320
407
  }
408
+
321
409
  FlateStream.prototype = Object.create(DecodeStream.prototype);
410
+
322
411
  FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
323
412
  var str = this.str;
324
413
  var codeSize = this.codeSize;
325
414
  var codeBuf = this.codeBuf;
326
415
  var b;
416
+
327
417
  while (codeSize < bits) {
328
418
  if ((b = str.getByte()) === -1) {
329
- throw new _util.FormatError('Bad encoding in flate stream');
419
+ throw new _util.FormatError("Bad encoding in flate stream");
330
420
  }
421
+
331
422
  codeBuf |= b << codeSize;
332
423
  codeSize += 8;
333
424
  }
425
+
334
426
  b = codeBuf & (1 << bits) - 1;
335
427
  this.codeBuf = codeBuf >> bits;
336
428
  this.codeSize = codeSize -= bits;
337
429
  return b;
338
430
  };
431
+
339
432
  FlateStream.prototype.getCode = function FlateStream_getCode(table) {
340
433
  var str = this.str;
341
434
  var codes = table[0];
@@ -343,104 +436,134 @@ var FlateStream = function FlateStreamClosure() {
343
436
  var codeSize = this.codeSize;
344
437
  var codeBuf = this.codeBuf;
345
438
  var b;
439
+
346
440
  while (codeSize < maxLen) {
347
441
  if ((b = str.getByte()) === -1) {
348
442
  break;
349
443
  }
444
+
350
445
  codeBuf |= b << codeSize;
351
446
  codeSize += 8;
352
447
  }
448
+
353
449
  var code = codes[codeBuf & (1 << maxLen) - 1];
354
450
  var codeLen = code >> 16;
355
451
  var codeVal = code & 0xffff;
452
+
356
453
  if (codeLen < 1 || codeSize < codeLen) {
357
- throw new _util.FormatError('Bad encoding in flate stream');
454
+ throw new _util.FormatError("Bad encoding in flate stream");
358
455
  }
456
+
359
457
  this.codeBuf = codeBuf >> codeLen;
360
458
  this.codeSize = codeSize - codeLen;
361
459
  return codeVal;
362
460
  };
461
+
363
462
  FlateStream.prototype.generateHuffmanTable = function flateStreamGenerateHuffmanTable(lengths) {
364
463
  var n = lengths.length;
365
464
  var maxLen = 0;
366
465
  var i;
466
+
367
467
  for (i = 0; i < n; ++i) {
368
468
  if (lengths[i] > maxLen) {
369
469
  maxLen = lengths[i];
370
470
  }
371
471
  }
472
+
372
473
  var size = 1 << maxLen;
373
474
  var codes = new Int32Array(size);
475
+
374
476
  for (var len = 1, code = 0, skip = 2; len <= maxLen; ++len, code <<= 1, skip <<= 1) {
375
477
  for (var val = 0; val < n; ++val) {
376
478
  if (lengths[val] === len) {
377
479
  var code2 = 0;
378
480
  var t = code;
481
+
379
482
  for (i = 0; i < len; ++i) {
380
483
  code2 = code2 << 1 | t & 1;
381
484
  t >>= 1;
382
485
  }
486
+
383
487
  for (i = code2; i < size; i += skip) {
384
488
  codes[i] = len << 16 | val;
385
489
  }
490
+
386
491
  ++code;
387
492
  }
388
493
  }
389
494
  }
495
+
390
496
  return [codes, maxLen];
391
497
  };
498
+
392
499
  FlateStream.prototype.readBlock = function FlateStream_readBlock() {
393
500
  var buffer, len;
394
501
  var str = this.str;
395
502
  var hdr = this.getBits(3);
503
+
396
504
  if (hdr & 1) {
397
505
  this.eof = true;
398
506
  }
507
+
399
508
  hdr >>= 1;
509
+
400
510
  if (hdr === 0) {
401
511
  var b;
512
+
402
513
  if ((b = str.getByte()) === -1) {
403
- throw new _util.FormatError('Bad block header in flate stream');
514
+ throw new _util.FormatError("Bad block header in flate stream");
404
515
  }
516
+
405
517
  var blockLen = b;
518
+
406
519
  if ((b = str.getByte()) === -1) {
407
- throw new _util.FormatError('Bad block header in flate stream');
520
+ throw new _util.FormatError("Bad block header in flate stream");
408
521
  }
522
+
409
523
  blockLen |= b << 8;
524
+
410
525
  if ((b = str.getByte()) === -1) {
411
- throw new _util.FormatError('Bad block header in flate stream');
526
+ throw new _util.FormatError("Bad block header in flate stream");
412
527
  }
528
+
413
529
  var check = b;
530
+
414
531
  if ((b = str.getByte()) === -1) {
415
- throw new _util.FormatError('Bad block header in flate stream');
532
+ throw new _util.FormatError("Bad block header in flate stream");
416
533
  }
534
+
417
535
  check |= b << 8;
536
+
418
537
  if (check !== (~blockLen & 0xffff) && (blockLen !== 0 || check !== 0)) {
419
- throw new _util.FormatError('Bad uncompressed block length in flate stream');
538
+ throw new _util.FormatError("Bad uncompressed block length in flate stream");
420
539
  }
540
+
421
541
  this.codeBuf = 0;
422
542
  this.codeSize = 0;
423
- var bufferLength = this.bufferLength;
424
- buffer = this.ensureBuffer(bufferLength + blockLen);
425
- var end = bufferLength + blockLen;
543
+ const bufferLength = this.bufferLength,
544
+ end = bufferLength + blockLen;
545
+ buffer = this.ensureBuffer(end);
426
546
  this.bufferLength = end;
547
+
427
548
  if (blockLen === 0) {
428
549
  if (str.peekByte() === -1) {
429
550
  this.eof = true;
430
551
  }
431
552
  } else {
432
- for (var n = bufferLength; n < end; ++n) {
433
- if ((b = str.getByte()) === -1) {
434
- this.eof = true;
435
- break;
436
- }
437
- buffer[n] = b;
553
+ const block = str.getBytes(blockLen);
554
+ buffer.set(block, bufferLength);
555
+
556
+ if (block.length < blockLen) {
557
+ this.eof = true;
438
558
  }
439
559
  }
560
+
440
561
  return;
441
562
  }
563
+
442
564
  var litCodeTable;
443
565
  var distCodeTable;
566
+
444
567
  if (hdr === 1) {
445
568
  litCodeTable = fixedLitCodeTab;
446
569
  distCodeTable = fixedDistCodeTab;
@@ -450,17 +573,21 @@ var FlateStream = function FlateStreamClosure() {
450
573
  var numCodeLenCodes = this.getBits(4) + 4;
451
574
  var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
452
575
  var i;
576
+
453
577
  for (i = 0; i < numCodeLenCodes; ++i) {
454
578
  codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
455
579
  }
580
+
456
581
  var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
457
582
  len = 0;
458
583
  i = 0;
459
584
  var codes = numLitCodes + numDistCodes;
460
585
  var codeLengths = new Uint8Array(codes);
461
586
  var bitsLength, bitsOffset, what;
587
+
462
588
  while (i < codes) {
463
589
  var code = this.getCode(codeLenCodeTab);
590
+
464
591
  if (code === 16) {
465
592
  bitsLength = 2;
466
593
  bitsOffset = 3;
@@ -477,86 +604,112 @@ var FlateStream = function FlateStreamClosure() {
477
604
  codeLengths[i++] = len = code;
478
605
  continue;
479
606
  }
607
+
480
608
  var repeatLength = this.getBits(bitsLength) + bitsOffset;
609
+
481
610
  while (repeatLength-- > 0) {
482
611
  codeLengths[i++] = what;
483
612
  }
484
613
  }
614
+
485
615
  litCodeTable = this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
486
616
  distCodeTable = this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
487
617
  } else {
488
- throw new _util.FormatError('Unknown block type in flate stream');
618
+ throw new _util.FormatError("Unknown block type in flate stream");
489
619
  }
620
+
490
621
  buffer = this.buffer;
491
622
  var limit = buffer ? buffer.length : 0;
492
623
  var pos = this.bufferLength;
624
+
493
625
  while (true) {
494
626
  var code1 = this.getCode(litCodeTable);
627
+
495
628
  if (code1 < 256) {
496
629
  if (pos + 1 >= limit) {
497
630
  buffer = this.ensureBuffer(pos + 1);
498
631
  limit = buffer.length;
499
632
  }
633
+
500
634
  buffer[pos++] = code1;
501
635
  continue;
502
636
  }
637
+
503
638
  if (code1 === 256) {
504
639
  this.bufferLength = pos;
505
640
  return;
506
641
  }
642
+
507
643
  code1 -= 257;
508
644
  code1 = lengthDecode[code1];
509
645
  var code2 = code1 >> 16;
646
+
510
647
  if (code2 > 0) {
511
648
  code2 = this.getBits(code2);
512
649
  }
650
+
513
651
  len = (code1 & 0xffff) + code2;
514
652
  code1 = this.getCode(distCodeTable);
515
653
  code1 = distDecode[code1];
516
654
  code2 = code1 >> 16;
655
+
517
656
  if (code2 > 0) {
518
657
  code2 = this.getBits(code2);
519
658
  }
659
+
520
660
  var dist = (code1 & 0xffff) + code2;
661
+
521
662
  if (pos + len >= limit) {
522
663
  buffer = this.ensureBuffer(pos + len);
523
664
  limit = buffer.length;
524
665
  }
666
+
525
667
  for (var k = 0; k < len; ++k, ++pos) {
526
668
  buffer[pos] = buffer[pos - dist];
527
669
  }
528
670
  }
529
671
  };
672
+
530
673
  return FlateStream;
531
674
  }();
675
+
676
+ exports.FlateStream = FlateStream;
677
+
532
678
  var PredictorStream = function PredictorStreamClosure() {
533
679
  function PredictorStream(str, maybeLength, params) {
534
680
  if (!(0, _primitives.isDict)(params)) {
535
681
  return str;
536
682
  }
537
- var predictor = this.predictor = params.get('Predictor') || 1;
683
+
684
+ var predictor = this.predictor = params.get("Predictor") || 1;
685
+
538
686
  if (predictor <= 1) {
539
687
  return str;
540
688
  }
689
+
541
690
  if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
542
- throw new _util.FormatError('Unsupported predictor: ' + predictor);
691
+ throw new _util.FormatError(`Unsupported predictor: ${predictor}`);
543
692
  }
693
+
544
694
  if (predictor === 2) {
545
695
  this.readBlock = this.readBlockTiff;
546
696
  } else {
547
697
  this.readBlock = this.readBlockPng;
548
698
  }
699
+
549
700
  this.str = str;
550
701
  this.dict = str.dict;
551
- var colors = this.colors = params.get('Colors') || 1;
552
- var bits = this.bits = params.get('BitsPerComponent') || 8;
553
- var columns = this.columns = params.get('Columns') || 1;
702
+ var colors = this.colors = params.get("Colors") || 1;
703
+ var bits = this.bits = params.get("BitsPerComponent") || 8;
704
+ var columns = this.columns = params.get("Columns") || 1;
554
705
  this.pixBytes = colors * bits + 7 >> 3;
555
706
  this.rowBytes = columns * colors * bits + 7 >> 3;
556
707
  DecodeStream.call(this, maybeLength);
557
708
  return this;
558
709
  }
710
+
559
711
  PredictorStream.prototype = Object.create(DecodeStream.prototype);
712
+
560
713
  PredictorStream.prototype.readBlockTiff = function predictorStreamReadBlockTiff() {
561
714
  var rowBytes = this.rowBytes;
562
715
  var bufferLength = this.bufferLength;
@@ -565,15 +718,18 @@ var PredictorStream = function PredictorStreamClosure() {
565
718
  var colors = this.colors;
566
719
  var rawBytes = this.str.getBytes(rowBytes);
567
720
  this.eof = !rawBytes.length;
721
+
568
722
  if (this.eof) {
569
723
  return;
570
724
  }
725
+
571
726
  var inbuf = 0,
572
727
  outbuf = 0;
573
728
  var inbits = 0,
574
729
  outbits = 0;
575
730
  var pos = bufferLength;
576
731
  var i;
732
+
577
733
  if (bits === 1 && colors === 1) {
578
734
  for (i = 0; i < rowBytes; ++i) {
579
735
  var c = rawBytes[i] ^ inbuf;
@@ -587,19 +743,22 @@ var PredictorStream = function PredictorStreamClosure() {
587
743
  for (i = 0; i < colors; ++i) {
588
744
  buffer[pos++] = rawBytes[i];
589
745
  }
746
+
590
747
  for (; i < rowBytes; ++i) {
591
748
  buffer[pos] = buffer[pos - colors] + rawBytes[i];
592
749
  pos++;
593
750
  }
594
751
  } else if (bits === 16) {
595
752
  var bytesPerPixel = colors * 2;
753
+
596
754
  for (i = 0; i < bytesPerPixel; ++i) {
597
755
  buffer[pos++] = rawBytes[i];
598
756
  }
757
+
599
758
  for (; i < rowBytes; i += 2) {
600
- var sum = ((rawBytes[i] & 0xFF) << 8) + (rawBytes[i + 1] & 0xFF) + ((buffer[pos - bytesPerPixel] & 0xFF) << 8) + (buffer[pos - bytesPerPixel + 1] & 0xFF);
601
- buffer[pos++] = sum >> 8 & 0xFF;
602
- buffer[pos++] = sum & 0xFF;
759
+ var sum = ((rawBytes[i] & 0xff) << 8) + (rawBytes[i + 1] & 0xff) + ((buffer[pos - bytesPerPixel] & 0xff) << 8) + (buffer[pos - bytesPerPixel + 1] & 0xff);
760
+ buffer[pos++] = sum >> 8 & 0xff;
761
+ buffer[pos++] = sum & 0xff;
603
762
  }
604
763
  } else {
605
764
  var compArray = new Uint8Array(colors + 1);
@@ -607,100 +766,129 @@ var PredictorStream = function PredictorStreamClosure() {
607
766
  var j = 0,
608
767
  k = bufferLength;
609
768
  var columns = this.columns;
769
+
610
770
  for (i = 0; i < columns; ++i) {
611
771
  for (var kk = 0; kk < colors; ++kk) {
612
772
  if (inbits < bits) {
613
- inbuf = inbuf << 8 | rawBytes[j++] & 0xFF;
773
+ inbuf = inbuf << 8 | rawBytes[j++] & 0xff;
614
774
  inbits += 8;
615
775
  }
776
+
616
777
  compArray[kk] = compArray[kk] + (inbuf >> inbits - bits) & bitMask;
617
778
  inbits -= bits;
618
779
  outbuf = outbuf << bits | compArray[kk];
619
780
  outbits += bits;
781
+
620
782
  if (outbits >= 8) {
621
- buffer[k++] = outbuf >> outbits - 8 & 0xFF;
783
+ buffer[k++] = outbuf >> outbits - 8 & 0xff;
622
784
  outbits -= 8;
623
785
  }
624
786
  }
625
787
  }
788
+
626
789
  if (outbits > 0) {
627
790
  buffer[k++] = (outbuf << 8 - outbits) + (inbuf & (1 << 8 - outbits) - 1);
628
791
  }
629
792
  }
793
+
630
794
  this.bufferLength += rowBytes;
631
795
  };
796
+
632
797
  PredictorStream.prototype.readBlockPng = function predictorStreamReadBlockPng() {
633
798
  var rowBytes = this.rowBytes;
634
799
  var pixBytes = this.pixBytes;
635
800
  var predictor = this.str.getByte();
636
801
  var rawBytes = this.str.getBytes(rowBytes);
637
802
  this.eof = !rawBytes.length;
803
+
638
804
  if (this.eof) {
639
805
  return;
640
806
  }
807
+
641
808
  var bufferLength = this.bufferLength;
642
809
  var buffer = this.ensureBuffer(bufferLength + rowBytes);
643
810
  var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
811
+
644
812
  if (prevRow.length === 0) {
645
813
  prevRow = new Uint8Array(rowBytes);
646
814
  }
815
+
647
816
  var i,
648
817
  j = bufferLength,
649
818
  up,
650
819
  c;
820
+
651
821
  switch (predictor) {
652
822
  case 0:
653
823
  for (i = 0; i < rowBytes; ++i) {
654
824
  buffer[j++] = rawBytes[i];
655
825
  }
826
+
656
827
  break;
828
+
657
829
  case 1:
658
830
  for (i = 0; i < pixBytes; ++i) {
659
831
  buffer[j++] = rawBytes[i];
660
832
  }
833
+
661
834
  for (; i < rowBytes; ++i) {
662
- buffer[j] = buffer[j - pixBytes] + rawBytes[i] & 0xFF;
835
+ buffer[j] = buffer[j - pixBytes] + rawBytes[i] & 0xff;
663
836
  j++;
664
837
  }
838
+
665
839
  break;
840
+
666
841
  case 2:
667
842
  for (i = 0; i < rowBytes; ++i) {
668
- buffer[j++] = prevRow[i] + rawBytes[i] & 0xFF;
843
+ buffer[j++] = prevRow[i] + rawBytes[i] & 0xff;
669
844
  }
845
+
670
846
  break;
847
+
671
848
  case 3:
672
849
  for (i = 0; i < pixBytes; ++i) {
673
850
  buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
674
851
  }
852
+
675
853
  for (; i < rowBytes; ++i) {
676
- buffer[j] = (prevRow[i] + buffer[j - pixBytes] >> 1) + rawBytes[i] & 0xFF;
854
+ buffer[j] = (prevRow[i] + buffer[j - pixBytes] >> 1) + rawBytes[i] & 0xff;
677
855
  j++;
678
856
  }
857
+
679
858
  break;
859
+
680
860
  case 4:
681
861
  for (i = 0; i < pixBytes; ++i) {
682
862
  up = prevRow[i];
683
863
  c = rawBytes[i];
684
864
  buffer[j++] = up + c;
685
865
  }
866
+
686
867
  for (; i < rowBytes; ++i) {
687
868
  up = prevRow[i];
688
869
  var upLeft = prevRow[i - pixBytes];
689
870
  var left = buffer[j - pixBytes];
690
871
  var p = left + up - upLeft;
691
872
  var pa = p - left;
873
+
692
874
  if (pa < 0) {
693
875
  pa = -pa;
694
876
  }
877
+
695
878
  var pb = p - up;
879
+
696
880
  if (pb < 0) {
697
881
  pb = -pb;
698
882
  }
883
+
699
884
  var pc = p - upLeft;
885
+
700
886
  if (pc < 0) {
701
887
  pc = -pc;
702
888
  }
889
+
703
890
  c = rawBytes[i];
891
+
704
892
  if (pa <= pb && pa <= pc) {
705
893
  buffer[j++] = left + c;
706
894
  } else if (pb <= pc) {
@@ -709,14 +897,21 @@ var PredictorStream = function PredictorStreamClosure() {
709
897
  buffer[j++] = upLeft + c;
710
898
  }
711
899
  }
900
+
712
901
  break;
902
+
713
903
  default:
714
- throw new _util.FormatError('Unsupported predictor: ' + predictor);
904
+ throw new _util.FormatError(`Unsupported predictor: ${predictor}`);
715
905
  }
906
+
716
907
  this.bufferLength += rowBytes;
717
908
  };
909
+
718
910
  return PredictorStream;
719
911
  }();
912
+
913
+ exports.PredictorStream = PredictorStream;
914
+
720
915
  var DecryptStream = function DecryptStreamClosure() {
721
916
  function DecryptStream(str, maybeLength, decrypt) {
722
917
  this.str = str;
@@ -726,20 +921,25 @@ var DecryptStream = function DecryptStreamClosure() {
726
921
  this.initialized = false;
727
922
  DecodeStream.call(this, maybeLength);
728
923
  }
924
+
729
925
  var chunkSize = 512;
730
926
  DecryptStream.prototype = Object.create(DecodeStream.prototype);
927
+
731
928
  DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
732
929
  var chunk;
930
+
733
931
  if (this.initialized) {
734
932
  chunk = this.nextChunk;
735
933
  } else {
736
934
  chunk = this.str.getBytes(chunkSize);
737
935
  this.initialized = true;
738
936
  }
937
+
739
938
  if (!chunk || chunk.length === 0) {
740
939
  this.eof = true;
741
940
  return;
742
941
  }
942
+
743
943
  this.nextChunk = this.str.getBytes(chunkSize);
744
944
  var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
745
945
  var decrypt = this.decrypt;
@@ -748,114 +948,153 @@ var DecryptStream = function DecryptStreamClosure() {
748
948
  var i,
749
949
  n = chunk.length;
750
950
  var buffer = this.ensureBuffer(bufferLength + n);
951
+
751
952
  for (i = 0; i < n; i++) {
752
953
  buffer[bufferLength++] = chunk[i];
753
954
  }
955
+
754
956
  this.bufferLength = bufferLength;
755
957
  };
958
+
756
959
  return DecryptStream;
757
960
  }();
961
+
962
+ exports.DecryptStream = DecryptStream;
963
+
758
964
  var Ascii85Stream = function Ascii85StreamClosure() {
759
965
  function Ascii85Stream(str, maybeLength) {
760
966
  this.str = str;
761
967
  this.dict = str.dict;
762
968
  this.input = new Uint8Array(5);
969
+
763
970
  if (maybeLength) {
764
971
  maybeLength = 0.8 * maybeLength;
765
972
  }
973
+
766
974
  DecodeStream.call(this, maybeLength);
767
975
  }
976
+
768
977
  Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
978
+
769
979
  Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
770
- var TILDA_CHAR = 0x7E;
771
- var Z_LOWER_CHAR = 0x7A;
980
+ var TILDA_CHAR = 0x7e;
981
+ var Z_LOWER_CHAR = 0x7a;
772
982
  var EOF = -1;
773
983
  var str = this.str;
774
984
  var c = str.getByte();
775
- while ((0, _util.isSpace)(c)) {
985
+
986
+ while ((0, _core_utils.isWhiteSpace)(c)) {
776
987
  c = str.getByte();
777
988
  }
989
+
778
990
  if (c === EOF || c === TILDA_CHAR) {
779
991
  this.eof = true;
780
992
  return;
781
993
  }
994
+
782
995
  var bufferLength = this.bufferLength,
783
996
  buffer;
784
997
  var i;
998
+
785
999
  if (c === Z_LOWER_CHAR) {
786
1000
  buffer = this.ensureBuffer(bufferLength + 4);
1001
+
787
1002
  for (i = 0; i < 4; ++i) {
788
1003
  buffer[bufferLength + i] = 0;
789
1004
  }
1005
+
790
1006
  this.bufferLength += 4;
791
1007
  } else {
792
1008
  var input = this.input;
793
1009
  input[0] = c;
1010
+
794
1011
  for (i = 1; i < 5; ++i) {
795
1012
  c = str.getByte();
796
- while ((0, _util.isSpace)(c)) {
1013
+
1014
+ while ((0, _core_utils.isWhiteSpace)(c)) {
797
1015
  c = str.getByte();
798
1016
  }
1017
+
799
1018
  input[i] = c;
1019
+
800
1020
  if (c === EOF || c === TILDA_CHAR) {
801
1021
  break;
802
1022
  }
803
1023
  }
1024
+
804
1025
  buffer = this.ensureBuffer(bufferLength + i - 1);
805
1026
  this.bufferLength += i - 1;
1027
+
806
1028
  if (i < 5) {
807
1029
  for (; i < 5; ++i) {
808
1030
  input[i] = 0x21 + 84;
809
1031
  }
1032
+
810
1033
  this.eof = true;
811
1034
  }
1035
+
812
1036
  var t = 0;
1037
+
813
1038
  for (i = 0; i < 5; ++i) {
814
1039
  t = t * 85 + (input[i] - 0x21);
815
1040
  }
1041
+
816
1042
  for (i = 3; i >= 0; --i) {
817
- buffer[bufferLength + i] = t & 0xFF;
1043
+ buffer[bufferLength + i] = t & 0xff;
818
1044
  t >>= 8;
819
1045
  }
820
1046
  }
821
1047
  };
1048
+
822
1049
  return Ascii85Stream;
823
1050
  }();
1051
+
1052
+ exports.Ascii85Stream = Ascii85Stream;
1053
+
824
1054
  var AsciiHexStream = function AsciiHexStreamClosure() {
825
1055
  function AsciiHexStream(str, maybeLength) {
826
1056
  this.str = str;
827
1057
  this.dict = str.dict;
828
1058
  this.firstDigit = -1;
1059
+
829
1060
  if (maybeLength) {
830
1061
  maybeLength = 0.5 * maybeLength;
831
1062
  }
1063
+
832
1064
  DecodeStream.call(this, maybeLength);
833
1065
  }
1066
+
834
1067
  AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
1068
+
835
1069
  AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
836
1070
  var UPSTREAM_BLOCK_SIZE = 8000;
837
1071
  var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
1072
+
838
1073
  if (!bytes.length) {
839
1074
  this.eof = true;
840
1075
  return;
841
1076
  }
1077
+
842
1078
  var maxDecodeLength = bytes.length + 1 >> 1;
843
1079
  var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
844
1080
  var bufferLength = this.bufferLength;
845
1081
  var firstDigit = this.firstDigit;
1082
+
846
1083
  for (var i = 0, ii = bytes.length; i < ii; i++) {
847
1084
  var ch = bytes[i],
848
1085
  digit;
1086
+
849
1087
  if (ch >= 0x30 && ch <= 0x39) {
850
- digit = ch & 0x0F;
1088
+ digit = ch & 0x0f;
851
1089
  } else if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
852
- digit = (ch & 0x0F) + 9;
853
- } else if (ch === 0x3E) {
1090
+ digit = (ch & 0x0f) + 9;
1091
+ } else if (ch === 0x3e) {
854
1092
  this.eof = true;
855
1093
  break;
856
1094
  } else {
857
1095
  continue;
858
1096
  }
1097
+
859
1098
  if (firstDigit < 0) {
860
1099
  firstDigit = digit;
861
1100
  } else {
@@ -863,34 +1102,46 @@ var AsciiHexStream = function AsciiHexStreamClosure() {
863
1102
  firstDigit = -1;
864
1103
  }
865
1104
  }
1105
+
866
1106
  if (firstDigit >= 0 && this.eof) {
867
1107
  buffer[bufferLength++] = firstDigit << 4;
868
1108
  firstDigit = -1;
869
1109
  }
1110
+
870
1111
  this.firstDigit = firstDigit;
871
1112
  this.bufferLength = bufferLength;
872
1113
  };
1114
+
873
1115
  return AsciiHexStream;
874
1116
  }();
1117
+
1118
+ exports.AsciiHexStream = AsciiHexStream;
1119
+
875
1120
  var RunLengthStream = function RunLengthStreamClosure() {
876
1121
  function RunLengthStream(str, maybeLength) {
877
1122
  this.str = str;
878
1123
  this.dict = str.dict;
879
1124
  DecodeStream.call(this, maybeLength);
880
1125
  }
1126
+
881
1127
  RunLengthStream.prototype = Object.create(DecodeStream.prototype);
1128
+
882
1129
  RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
883
1130
  var repeatHeader = this.str.getBytes(2);
1131
+
884
1132
  if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
885
1133
  this.eof = true;
886
1134
  return;
887
1135
  }
1136
+
888
1137
  var buffer;
889
1138
  var bufferLength = this.bufferLength;
890
1139
  var n = repeatHeader[0];
1140
+
891
1141
  if (n < 128) {
892
1142
  buffer = this.ensureBuffer(bufferLength + n + 1);
893
1143
  buffer[bufferLength++] = repeatHeader[1];
1144
+
894
1145
  if (n > 0) {
895
1146
  var source = this.str.getBytes(n);
896
1147
  buffer.set(source, bufferLength);
@@ -900,14 +1151,20 @@ var RunLengthStream = function RunLengthStreamClosure() {
900
1151
  n = 257 - n;
901
1152
  var b = repeatHeader[1];
902
1153
  buffer = this.ensureBuffer(bufferLength + n + 1);
1154
+
903
1155
  for (var i = 0; i < n; i++) {
904
1156
  buffer[bufferLength++] = b;
905
1157
  }
906
1158
  }
1159
+
907
1160
  this.bufferLength = bufferLength;
908
1161
  };
1162
+
909
1163
  return RunLengthStream;
910
1164
  }();
1165
+
1166
+ exports.RunLengthStream = RunLengthStream;
1167
+
911
1168
  var LZWStream = function LZWStreamClosure() {
912
1169
  function LZWStream(str, maybeLength, earlyChange) {
913
1170
  this.str = str;
@@ -916,7 +1173,7 @@ var LZWStream = function LZWStreamClosure() {
916
1173
  this.bitsCached = 0;
917
1174
  var maxLzwDictionarySize = 4096;
918
1175
  var lzwState = {
919
- earlyChange: earlyChange,
1176
+ earlyChange,
920
1177
  codeLength: 9,
921
1178
  nextCode: 258,
922
1179
  dictionaryValues: new Uint8Array(maxLzwDictionarySize),
@@ -925,40 +1182,51 @@ var LZWStream = function LZWStreamClosure() {
925
1182
  currentSequence: new Uint8Array(maxLzwDictionarySize),
926
1183
  currentSequenceLength: 0
927
1184
  };
1185
+
928
1186
  for (var i = 0; i < 256; ++i) {
929
1187
  lzwState.dictionaryValues[i] = i;
930
1188
  lzwState.dictionaryLengths[i] = 1;
931
1189
  }
1190
+
932
1191
  this.lzwState = lzwState;
933
1192
  DecodeStream.call(this, maybeLength);
934
1193
  }
1194
+
935
1195
  LZWStream.prototype = Object.create(DecodeStream.prototype);
1196
+
936
1197
  LZWStream.prototype.readBits = function LZWStream_readBits(n) {
937
1198
  var bitsCached = this.bitsCached;
938
1199
  var cachedData = this.cachedData;
1200
+
939
1201
  while (bitsCached < n) {
940
1202
  var c = this.str.getByte();
1203
+
941
1204
  if (c === -1) {
942
1205
  this.eof = true;
943
1206
  return null;
944
1207
  }
1208
+
945
1209
  cachedData = cachedData << 8 | c;
946
1210
  bitsCached += 8;
947
1211
  }
1212
+
948
1213
  this.bitsCached = bitsCached -= n;
949
1214
  this.cachedData = cachedData;
950
1215
  this.lastCode = null;
951
1216
  return cachedData >>> bitsCached & (1 << n) - 1;
952
1217
  };
1218
+
953
1219
  LZWStream.prototype.readBlock = function LZWStream_readBlock() {
954
1220
  var blockSize = 512;
955
1221
  var estimatedDecodedSize = blockSize * 2,
956
1222
  decodedSizeDelta = blockSize;
957
1223
  var i, j, q;
958
1224
  var lzwState = this.lzwState;
1225
+
959
1226
  if (!lzwState) {
960
1227
  return;
961
1228
  }
1229
+
962
1230
  var earlyChange = lzwState.earlyChange;
963
1231
  var nextCode = lzwState.nextCode;
964
1232
  var dictionaryValues = lzwState.dictionaryValues;
@@ -971,15 +1239,18 @@ var LZWStream = function LZWStreamClosure() {
971
1239
  var decodedLength = 0;
972
1240
  var currentBufferLength = this.bufferLength;
973
1241
  var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
1242
+
974
1243
  for (i = 0; i < blockSize; i++) {
975
1244
  var code = this.readBits(codeLength);
976
1245
  var hasPrev = currentSequenceLength > 0;
1246
+
977
1247
  if (code < 256) {
978
1248
  currentSequence[0] = code;
979
1249
  currentSequenceLength = 1;
980
1250
  } else if (code >= 258) {
981
1251
  if (code < nextCode) {
982
1252
  currentSequenceLength = dictionaryLengths[code];
1253
+
983
1254
  for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
984
1255
  currentSequence[j] = dictionaryValues[q];
985
1256
  q = dictionaryPrevCodes[q];
@@ -997,6 +1268,7 @@ var LZWStream = function LZWStreamClosure() {
997
1268
  delete this.lzwState;
998
1269
  break;
999
1270
  }
1271
+
1000
1272
  if (hasPrev) {
1001
1273
  dictionaryPrevCodes[nextCode] = prevCode;
1002
1274
  dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
@@ -1004,42 +1276,42 @@ var LZWStream = function LZWStreamClosure() {
1004
1276
  nextCode++;
1005
1277
  codeLength = nextCode + earlyChange & nextCode + earlyChange - 1 ? codeLength : Math.min(Math.log(nextCode + earlyChange) / 0.6931471805599453 + 1, 12) | 0;
1006
1278
  }
1279
+
1007
1280
  prevCode = code;
1008
1281
  decodedLength += currentSequenceLength;
1282
+
1009
1283
  if (estimatedDecodedSize < decodedLength) {
1010
1284
  do {
1011
1285
  estimatedDecodedSize += decodedSizeDelta;
1012
1286
  } while (estimatedDecodedSize < decodedLength);
1287
+
1013
1288
  buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
1014
1289
  }
1290
+
1015
1291
  for (j = 0; j < currentSequenceLength; j++) {
1016
1292
  buffer[currentBufferLength++] = currentSequence[j];
1017
1293
  }
1018
1294
  }
1295
+
1019
1296
  lzwState.nextCode = nextCode;
1020
1297
  lzwState.codeLength = codeLength;
1021
1298
  lzwState.prevCode = prevCode;
1022
1299
  lzwState.currentSequenceLength = currentSequenceLength;
1023
1300
  this.bufferLength = currentBufferLength;
1024
1301
  };
1302
+
1025
1303
  return LZWStream;
1026
1304
  }();
1305
+
1306
+ exports.LZWStream = LZWStream;
1307
+
1027
1308
  var NullStream = function NullStreamClosure() {
1028
1309
  function NullStream() {
1029
1310
  Stream.call(this, new Uint8Array(0));
1030
1311
  }
1312
+
1031
1313
  NullStream.prototype = Stream.prototype;
1032
1314
  return NullStream;
1033
1315
  }();
1034
- exports.Ascii85Stream = Ascii85Stream;
1035
- exports.AsciiHexStream = AsciiHexStream;
1036
- exports.DecryptStream = DecryptStream;
1037
- exports.DecodeStream = DecodeStream;
1038
- exports.FlateStream = FlateStream;
1039
- exports.NullStream = NullStream;
1040
- exports.PredictorStream = PredictorStream;
1041
- exports.RunLengthStream = RunLengthStream;
1042
- exports.Stream = Stream;
1043
- exports.StreamsSequenceStream = StreamsSequenceStream;
1044
- exports.StringStream = StringStream;
1045
- exports.LZWStream = LZWStream;
1316
+
1317
+ exports.NullStream = NullStream;