@file-viewer/core 2.0.11 → 2.1.1

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