locar-tiler 0.0.2
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.
- package/LICENSE +21 -0
- package/dist/locar-tiler.d.ts +92 -0
- package/dist/locar-tiler.mjs +2420 -0
- package/dist/locar-tiler.umd.js +1 -0
- package/package.json +30 -0
|
@@ -0,0 +1,2420 @@
|
|
|
1
|
+
class N {
|
|
2
|
+
static EARTH = 4007501668e-2;
|
|
3
|
+
static HALF_EARTH = 2003750834e-2;
|
|
4
|
+
}
|
|
5
|
+
class q {
|
|
6
|
+
x;
|
|
7
|
+
y;
|
|
8
|
+
z;
|
|
9
|
+
constructor(e, t, n) {
|
|
10
|
+
this.x = e, this.y = t, this.z = n;
|
|
11
|
+
}
|
|
12
|
+
getMetresInTile() {
|
|
13
|
+
return N.EARTH / Math.pow(2, this.z);
|
|
14
|
+
}
|
|
15
|
+
getBottomLeft() {
|
|
16
|
+
var e = this.getMetresInTile();
|
|
17
|
+
return { e: this.x * e - N.HALF_EARTH, n: N.HALF_EARTH - (this.y + 1) * e };
|
|
18
|
+
}
|
|
19
|
+
getTopRight() {
|
|
20
|
+
var e = this.getBottomLeft(), t = this.getMetresInTile();
|
|
21
|
+
return e.e += t, e.n += t, e;
|
|
22
|
+
}
|
|
23
|
+
getIndex() {
|
|
24
|
+
return `${this.z}/${this.x}/${this.y}`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
class Ue {
|
|
28
|
+
project(e) {
|
|
29
|
+
return { e: this.#t(e.lon), n: this.#e(e.lat) };
|
|
30
|
+
}
|
|
31
|
+
unproject(e) {
|
|
32
|
+
return { lon: this.#i(e[0]), lat: this.#n(e[1]) };
|
|
33
|
+
}
|
|
34
|
+
#t(e) {
|
|
35
|
+
return e / 180 * N.HALF_EARTH;
|
|
36
|
+
}
|
|
37
|
+
#e(e) {
|
|
38
|
+
var t = Math.log(Math.tan((90 + e) * Math.PI / 360)) / (Math.PI / 180);
|
|
39
|
+
return t * N.HALF_EARTH / 180;
|
|
40
|
+
}
|
|
41
|
+
#i(e) {
|
|
42
|
+
return e / N.HALF_EARTH * 180;
|
|
43
|
+
}
|
|
44
|
+
#n(e) {
|
|
45
|
+
var t = e / N.HALF_EARTH * 180;
|
|
46
|
+
return t = 180 / Math.PI * (2 * Math.atan(Math.exp(t * Math.PI / 180)) - Math.PI / 2), t;
|
|
47
|
+
}
|
|
48
|
+
getTile(e, t) {
|
|
49
|
+
var n = new q(-1, -1, t), a = n.getMetresInTile();
|
|
50
|
+
return n.x = Math.floor((N.HALF_EARTH + e.e) / a), n.y = Math.floor((N.HALF_EARTH - e.n) / a), n;
|
|
51
|
+
}
|
|
52
|
+
getTileFromLonLat(e, t) {
|
|
53
|
+
return this.getTile(this.project(e), t);
|
|
54
|
+
}
|
|
55
|
+
getID() {
|
|
56
|
+
return "epsg:3857";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
class ee {
|
|
60
|
+
tile;
|
|
61
|
+
url;
|
|
62
|
+
sphMerc;
|
|
63
|
+
dataTiles;
|
|
64
|
+
constructor(e) {
|
|
65
|
+
this.tile = new q(0, 0, 13), this.url = e, this.sphMerc = new Ue(), this.dataTiles = /* @__PURE__ */ new Map();
|
|
66
|
+
}
|
|
67
|
+
setZoom(e) {
|
|
68
|
+
this.tile.z = e;
|
|
69
|
+
}
|
|
70
|
+
lonLatToSphMerc(e) {
|
|
71
|
+
return this.sphMerc.project(e);
|
|
72
|
+
}
|
|
73
|
+
getTile(e, t) {
|
|
74
|
+
return this.sphMerc.getTile(e, t);
|
|
75
|
+
}
|
|
76
|
+
async update(e) {
|
|
77
|
+
const t = [];
|
|
78
|
+
let n = null;
|
|
79
|
+
if (n = this.updateTile(e)) {
|
|
80
|
+
this.tile = n;
|
|
81
|
+
const a = [n.x, n.x - 1, n.x + 1], s = [n.y, n.y - 1, n.y + 1];
|
|
82
|
+
for (let l = 0; l < a.length; l++)
|
|
83
|
+
for (let h = 0; h < s.length; h++) {
|
|
84
|
+
const _ = new q(a[l], s[h], n.z), r = await this.loadTile(_);
|
|
85
|
+
r !== null && t.push({ data: r.data, tile: _ });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return t;
|
|
89
|
+
}
|
|
90
|
+
async updateByLonLat(e) {
|
|
91
|
+
return this.update(this.lonLatToSphMerc(e));
|
|
92
|
+
}
|
|
93
|
+
getCurrentTiles() {
|
|
94
|
+
const e = [], t = [this.tile.x, this.tile.x - 1, this.tile.x + 1], n = [this.tile.y, this.tile.y - 1, this.tile.y + 1];
|
|
95
|
+
for (let a = 0; a < t.length; a++)
|
|
96
|
+
for (let s = 0; s < n.length; s++) {
|
|
97
|
+
const l = new q(t[a], n[s], this.tile.z), h = this.dataTiles[l.getIndex()];
|
|
98
|
+
h !== null && e.push({ data: h, tile: l });
|
|
99
|
+
}
|
|
100
|
+
return e;
|
|
101
|
+
}
|
|
102
|
+
updateTile(e) {
|
|
103
|
+
if (this.tile) {
|
|
104
|
+
const t = this.sphMerc.getTile(e, this.tile.z);
|
|
105
|
+
return t.x != this.tile.x || t.y != this.tile.y ? t : null;
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
async loadTile(e) {
|
|
110
|
+
const t = e.getIndex();
|
|
111
|
+
if (this.dataTiles[t] === void 0) {
|
|
112
|
+
const n = await this.readTile(
|
|
113
|
+
this.url.replace("{x}", e.x.toString()).replace("{y}", e.y.toString()).replace("{z}", e.z.toString())
|
|
114
|
+
);
|
|
115
|
+
return this.dataTiles[t] = n, this.dataTiles[t];
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
// for a given sphmerc pos, downloads data if necessary and returns
|
|
120
|
+
// the data at the tile corresponding to that position
|
|
121
|
+
async getData(e, t = 13) {
|
|
122
|
+
await this.update(e);
|
|
123
|
+
const n = this.sphMerc.getTile(e, t);
|
|
124
|
+
return this.dataTiles[`${t}/${n.x}/${n.y}`];
|
|
125
|
+
}
|
|
126
|
+
// can be overridden if we want to store something other than the raw data
|
|
127
|
+
// (for example DEM objects if we are dealing with DEM tiles)
|
|
128
|
+
rawTileToStoredTile(e, t) {
|
|
129
|
+
return { tile: e, data: t };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function bt(i, e = "utf8") {
|
|
133
|
+
return new TextDecoder(e).decode(i);
|
|
134
|
+
}
|
|
135
|
+
const Se = new TextEncoder();
|
|
136
|
+
function Ie(i) {
|
|
137
|
+
return Se.encode(i);
|
|
138
|
+
}
|
|
139
|
+
const Oe = 1024 * 8, Re = (() => {
|
|
140
|
+
const i = new Uint8Array(4), e = new Uint32Array(i.buffer);
|
|
141
|
+
return !((e[0] = 1) & i[0]);
|
|
142
|
+
})(), et = {
|
|
143
|
+
int8: globalThis.Int8Array,
|
|
144
|
+
uint8: globalThis.Uint8Array,
|
|
145
|
+
int16: globalThis.Int16Array,
|
|
146
|
+
uint16: globalThis.Uint16Array,
|
|
147
|
+
int32: globalThis.Int32Array,
|
|
148
|
+
uint32: globalThis.Uint32Array,
|
|
149
|
+
uint64: globalThis.BigUint64Array,
|
|
150
|
+
int64: globalThis.BigInt64Array,
|
|
151
|
+
float32: globalThis.Float32Array,
|
|
152
|
+
float64: globalThis.Float64Array
|
|
153
|
+
};
|
|
154
|
+
class wt {
|
|
155
|
+
/**
|
|
156
|
+
* Reference to the internal ArrayBuffer object.
|
|
157
|
+
*/
|
|
158
|
+
buffer;
|
|
159
|
+
/**
|
|
160
|
+
* Byte length of the internal ArrayBuffer.
|
|
161
|
+
*/
|
|
162
|
+
byteLength;
|
|
163
|
+
/**
|
|
164
|
+
* Byte offset of the internal ArrayBuffer.
|
|
165
|
+
*/
|
|
166
|
+
byteOffset;
|
|
167
|
+
/**
|
|
168
|
+
* Byte length of the internal ArrayBuffer.
|
|
169
|
+
*/
|
|
170
|
+
length;
|
|
171
|
+
/**
|
|
172
|
+
* The current offset of the buffer's pointer.
|
|
173
|
+
*/
|
|
174
|
+
offset;
|
|
175
|
+
lastWrittenByte;
|
|
176
|
+
littleEndian;
|
|
177
|
+
_data;
|
|
178
|
+
_mark;
|
|
179
|
+
_marks;
|
|
180
|
+
/**
|
|
181
|
+
* Create a new IOBuffer.
|
|
182
|
+
* @param data - The data to construct the IOBuffer with.
|
|
183
|
+
* If data is a number, it will be the new buffer's length<br>
|
|
184
|
+
* If data is `undefined`, the buffer will be initialized with a default length of 8Kb<br>
|
|
185
|
+
* If data is an ArrayBuffer, SharedArrayBuffer, an ArrayBufferView (Typed Array), an IOBuffer instance,
|
|
186
|
+
* or a Node.js Buffer, a view will be created over the underlying ArrayBuffer.
|
|
187
|
+
* @param options - An object for the options.
|
|
188
|
+
* @returns A new IOBuffer instance.
|
|
189
|
+
*/
|
|
190
|
+
constructor(e = Oe, t = {}) {
|
|
191
|
+
let n = !1;
|
|
192
|
+
typeof e == "number" ? e = new ArrayBuffer(e) : (n = !0, this.lastWrittenByte = e.byteLength);
|
|
193
|
+
const a = t.offset ? t.offset >>> 0 : 0, s = e.byteLength - a;
|
|
194
|
+
let l = a;
|
|
195
|
+
(ArrayBuffer.isView(e) || e instanceof wt) && (e.byteLength !== e.buffer.byteLength && (l = e.byteOffset + a), e = e.buffer), n ? this.lastWrittenByte = s : this.lastWrittenByte = 0, this.buffer = e, this.length = s, this.byteLength = s, this.byteOffset = l, this.offset = 0, this.littleEndian = !0, this._data = new DataView(this.buffer, l, s), this._mark = 0, this._marks = [];
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Checks if the memory allocated to the buffer is sufficient to store more
|
|
199
|
+
* bytes after the offset.
|
|
200
|
+
* @param byteLength - The needed memory in bytes.
|
|
201
|
+
* @returns `true` if there is sufficient space and `false` otherwise.
|
|
202
|
+
*/
|
|
203
|
+
available(e = 1) {
|
|
204
|
+
return this.offset + e <= this.length;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Check if little-endian mode is used for reading and writing multi-byte
|
|
208
|
+
* values.
|
|
209
|
+
* @returns `true` if little-endian mode is used, `false` otherwise.
|
|
210
|
+
*/
|
|
211
|
+
isLittleEndian() {
|
|
212
|
+
return this.littleEndian;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Set little-endian mode for reading and writing multi-byte values.
|
|
216
|
+
* @returns This.
|
|
217
|
+
*/
|
|
218
|
+
setLittleEndian() {
|
|
219
|
+
return this.littleEndian = !0, this;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Check if big-endian mode is used for reading and writing multi-byte values.
|
|
223
|
+
* @returns `true` if big-endian mode is used, `false` otherwise.
|
|
224
|
+
*/
|
|
225
|
+
isBigEndian() {
|
|
226
|
+
return !this.littleEndian;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Switches to big-endian mode for reading and writing multi-byte values.
|
|
230
|
+
* @returns This.
|
|
231
|
+
*/
|
|
232
|
+
setBigEndian() {
|
|
233
|
+
return this.littleEndian = !1, this;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Move the pointer n bytes forward.
|
|
237
|
+
* @param n - Number of bytes to skip.
|
|
238
|
+
* @returns This.
|
|
239
|
+
*/
|
|
240
|
+
skip(e = 1) {
|
|
241
|
+
return this.offset += e, this;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Move the pointer n bytes backward.
|
|
245
|
+
* @param n - Number of bytes to move back.
|
|
246
|
+
* @returns This.
|
|
247
|
+
*/
|
|
248
|
+
back(e = 1) {
|
|
249
|
+
return this.offset -= e, this;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Move the pointer to the given offset.
|
|
253
|
+
* @param offset - The offset to move to.
|
|
254
|
+
* @returns This.
|
|
255
|
+
*/
|
|
256
|
+
seek(e) {
|
|
257
|
+
return this.offset = e, this;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Store the current pointer offset.
|
|
261
|
+
* @see {@link IOBuffer#reset}
|
|
262
|
+
* @returns This.
|
|
263
|
+
*/
|
|
264
|
+
mark() {
|
|
265
|
+
return this._mark = this.offset, this;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Move the pointer back to the last pointer offset set by mark.
|
|
269
|
+
* @see {@link IOBuffer#mark}
|
|
270
|
+
* @returns This.
|
|
271
|
+
*/
|
|
272
|
+
reset() {
|
|
273
|
+
return this.offset = this._mark, this;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Push the current pointer offset to the mark stack.
|
|
277
|
+
* @see {@link IOBuffer#popMark}
|
|
278
|
+
* @returns This.
|
|
279
|
+
*/
|
|
280
|
+
pushMark() {
|
|
281
|
+
return this._marks.push(this.offset), this;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Pop the last pointer offset from the mark stack, and set the current
|
|
285
|
+
* pointer offset to the popped value.
|
|
286
|
+
* @see {@link IOBuffer#pushMark}
|
|
287
|
+
* @returns This.
|
|
288
|
+
*/
|
|
289
|
+
popMark() {
|
|
290
|
+
const e = this._marks.pop();
|
|
291
|
+
if (e === void 0)
|
|
292
|
+
throw new Error("Mark stack empty");
|
|
293
|
+
return this.seek(e), this;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Move the pointer offset back to 0.
|
|
297
|
+
* @returns This.
|
|
298
|
+
*/
|
|
299
|
+
rewind() {
|
|
300
|
+
return this.offset = 0, this;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Make sure the buffer has sufficient memory to write a given byteLength at
|
|
304
|
+
* the current pointer offset.
|
|
305
|
+
* If the buffer's memory is insufficient, this method will create a new
|
|
306
|
+
* buffer (a copy) with a length that is twice (byteLength + current offset).
|
|
307
|
+
* @param byteLength - The needed memory in bytes.
|
|
308
|
+
* @returns This.
|
|
309
|
+
*/
|
|
310
|
+
ensureAvailable(e = 1) {
|
|
311
|
+
if (!this.available(e)) {
|
|
312
|
+
const n = (this.offset + e) * 2, a = new Uint8Array(n);
|
|
313
|
+
a.set(new Uint8Array(this.buffer)), this.buffer = a.buffer, this.length = n, this.byteLength = n, this._data = new DataView(this.buffer);
|
|
314
|
+
}
|
|
315
|
+
return this;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Read a byte and return false if the byte's value is 0, or true otherwise.
|
|
319
|
+
* Moves pointer forward by one byte.
|
|
320
|
+
* @returns The read boolean.
|
|
321
|
+
*/
|
|
322
|
+
readBoolean() {
|
|
323
|
+
return this.readUint8() !== 0;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Read a signed 8-bit integer and move pointer forward by 1 byte.
|
|
327
|
+
* @returns The read byte.
|
|
328
|
+
*/
|
|
329
|
+
readInt8() {
|
|
330
|
+
return this._data.getInt8(this.offset++);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Read an unsigned 8-bit integer and move pointer forward by 1 byte.
|
|
334
|
+
* @returns The read byte.
|
|
335
|
+
*/
|
|
336
|
+
readUint8() {
|
|
337
|
+
return this._data.getUint8(this.offset++);
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Alias for {@link IOBuffer#readUint8}.
|
|
341
|
+
* @returns The read byte.
|
|
342
|
+
*/
|
|
343
|
+
readByte() {
|
|
344
|
+
return this.readUint8();
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Read `n` bytes and move pointer forward by `n` bytes.
|
|
348
|
+
* @param n - Number of bytes to read.
|
|
349
|
+
* @returns The read bytes.
|
|
350
|
+
*/
|
|
351
|
+
readBytes(e = 1) {
|
|
352
|
+
return this.readArray(e, "uint8");
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Creates an array of corresponding to the type `type` and size `size`.
|
|
356
|
+
* For example, type `uint8` will create a `Uint8Array`.
|
|
357
|
+
* @param size - size of the resulting array
|
|
358
|
+
* @param type - number type of elements to read
|
|
359
|
+
* @returns The read array.
|
|
360
|
+
*/
|
|
361
|
+
readArray(e, t) {
|
|
362
|
+
const n = et[t].BYTES_PER_ELEMENT * e, a = this.byteOffset + this.offset, s = this.buffer.slice(a, a + n);
|
|
363
|
+
if (this.littleEndian === Re && t !== "uint8" && t !== "int8") {
|
|
364
|
+
const h = new Uint8Array(this.buffer.slice(a, a + n));
|
|
365
|
+
h.reverse();
|
|
366
|
+
const _ = new et[t](h.buffer);
|
|
367
|
+
return this.offset += n, _.reverse(), _;
|
|
368
|
+
}
|
|
369
|
+
const l = new et[t](s);
|
|
370
|
+
return this.offset += n, l;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Read a 16-bit signed integer and move pointer forward by 2 bytes.
|
|
374
|
+
* @returns The read value.
|
|
375
|
+
*/
|
|
376
|
+
readInt16() {
|
|
377
|
+
const e = this._data.getInt16(this.offset, this.littleEndian);
|
|
378
|
+
return this.offset += 2, e;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Read a 16-bit unsigned integer and move pointer forward by 2 bytes.
|
|
382
|
+
* @returns The read value.
|
|
383
|
+
*/
|
|
384
|
+
readUint16() {
|
|
385
|
+
const e = this._data.getUint16(this.offset, this.littleEndian);
|
|
386
|
+
return this.offset += 2, e;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Read a 32-bit signed integer and move pointer forward by 4 bytes.
|
|
390
|
+
* @returns The read value.
|
|
391
|
+
*/
|
|
392
|
+
readInt32() {
|
|
393
|
+
const e = this._data.getInt32(this.offset, this.littleEndian);
|
|
394
|
+
return this.offset += 4, e;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Read a 32-bit unsigned integer and move pointer forward by 4 bytes.
|
|
398
|
+
* @returns The read value.
|
|
399
|
+
*/
|
|
400
|
+
readUint32() {
|
|
401
|
+
const e = this._data.getUint32(this.offset, this.littleEndian);
|
|
402
|
+
return this.offset += 4, e;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Read a 32-bit floating number and move pointer forward by 4 bytes.
|
|
406
|
+
* @returns The read value.
|
|
407
|
+
*/
|
|
408
|
+
readFloat32() {
|
|
409
|
+
const e = this._data.getFloat32(this.offset, this.littleEndian);
|
|
410
|
+
return this.offset += 4, e;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Read a 64-bit floating number and move pointer forward by 8 bytes.
|
|
414
|
+
* @returns The read value.
|
|
415
|
+
*/
|
|
416
|
+
readFloat64() {
|
|
417
|
+
const e = this._data.getFloat64(this.offset, this.littleEndian);
|
|
418
|
+
return this.offset += 8, e;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Read a 64-bit signed integer number and move pointer forward by 8 bytes.
|
|
422
|
+
* @returns The read value.
|
|
423
|
+
*/
|
|
424
|
+
readBigInt64() {
|
|
425
|
+
const e = this._data.getBigInt64(this.offset, this.littleEndian);
|
|
426
|
+
return this.offset += 8, e;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Read a 64-bit unsigned integer number and move pointer forward by 8 bytes.
|
|
430
|
+
* @returns The read value.
|
|
431
|
+
*/
|
|
432
|
+
readBigUint64() {
|
|
433
|
+
const e = this._data.getBigUint64(this.offset, this.littleEndian);
|
|
434
|
+
return this.offset += 8, e;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Read a 1-byte ASCII character and move pointer forward by 1 byte.
|
|
438
|
+
* @returns The read character.
|
|
439
|
+
*/
|
|
440
|
+
readChar() {
|
|
441
|
+
return String.fromCharCode(this.readInt8());
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Read `n` 1-byte ASCII characters and move pointer forward by `n` bytes.
|
|
445
|
+
* @param n - Number of characters to read.
|
|
446
|
+
* @returns The read characters.
|
|
447
|
+
*/
|
|
448
|
+
readChars(e = 1) {
|
|
449
|
+
let t = "";
|
|
450
|
+
for (let n = 0; n < e; n++)
|
|
451
|
+
t += this.readChar();
|
|
452
|
+
return t;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Read the next `n` bytes, return a UTF-8 decoded string and move pointer
|
|
456
|
+
* forward by `n` bytes.
|
|
457
|
+
* @param n - Number of bytes to read.
|
|
458
|
+
* @returns The decoded string.
|
|
459
|
+
*/
|
|
460
|
+
readUtf8(e = 1) {
|
|
461
|
+
return bt(this.readBytes(e));
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Read the next `n` bytes, return a string decoded with `encoding` and move pointer
|
|
465
|
+
* forward by `n` bytes.
|
|
466
|
+
* If no encoding is passed, the function is equivalent to @see {@link IOBuffer#readUtf8}
|
|
467
|
+
* @param n - Number of bytes to read.
|
|
468
|
+
* @param encoding - The encoding to use. Default is 'utf8'.
|
|
469
|
+
* @returns The decoded string.
|
|
470
|
+
*/
|
|
471
|
+
decodeText(e = 1, t = "utf8") {
|
|
472
|
+
return bt(this.readBytes(e), t);
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Write 0xff if the passed value is truthy, 0x00 otherwise and move pointer
|
|
476
|
+
* forward by 1 byte.
|
|
477
|
+
* @param value - The value to write.
|
|
478
|
+
* @returns This.
|
|
479
|
+
*/
|
|
480
|
+
writeBoolean(e) {
|
|
481
|
+
return this.writeUint8(e ? 255 : 0), this;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Write `value` as an 8-bit signed integer and move pointer forward by 1 byte.
|
|
485
|
+
* @param value - The value to write.
|
|
486
|
+
* @returns This.
|
|
487
|
+
*/
|
|
488
|
+
writeInt8(e) {
|
|
489
|
+
return this.ensureAvailable(1), this._data.setInt8(this.offset++, e), this._updateLastWrittenByte(), this;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Write `value` as an 8-bit unsigned integer and move pointer forward by 1
|
|
493
|
+
* byte.
|
|
494
|
+
* @param value - The value to write.
|
|
495
|
+
* @returns This.
|
|
496
|
+
*/
|
|
497
|
+
writeUint8(e) {
|
|
498
|
+
return this.ensureAvailable(1), this._data.setUint8(this.offset++, e), this._updateLastWrittenByte(), this;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* An alias for {@link IOBuffer#writeUint8}.
|
|
502
|
+
* @param value - The value to write.
|
|
503
|
+
* @returns This.
|
|
504
|
+
*/
|
|
505
|
+
writeByte(e) {
|
|
506
|
+
return this.writeUint8(e);
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Write all elements of `bytes` as uint8 values and move pointer forward by
|
|
510
|
+
* `bytes.length` bytes.
|
|
511
|
+
* @param bytes - The array of bytes to write.
|
|
512
|
+
* @returns This.
|
|
513
|
+
*/
|
|
514
|
+
writeBytes(e) {
|
|
515
|
+
this.ensureAvailable(e.length);
|
|
516
|
+
for (let t = 0; t < e.length; t++)
|
|
517
|
+
this._data.setUint8(this.offset++, e[t]);
|
|
518
|
+
return this._updateLastWrittenByte(), this;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Write `value` as a 16-bit signed integer and move pointer forward by 2
|
|
522
|
+
* bytes.
|
|
523
|
+
* @param value - The value to write.
|
|
524
|
+
* @returns This.
|
|
525
|
+
*/
|
|
526
|
+
writeInt16(e) {
|
|
527
|
+
return this.ensureAvailable(2), this._data.setInt16(this.offset, e, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this;
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Write `value` as a 16-bit unsigned integer and move pointer forward by 2
|
|
531
|
+
* bytes.
|
|
532
|
+
* @param value - The value to write.
|
|
533
|
+
* @returns This.
|
|
534
|
+
*/
|
|
535
|
+
writeUint16(e) {
|
|
536
|
+
return this.ensureAvailable(2), this._data.setUint16(this.offset, e, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Write `value` as a 32-bit signed integer and move pointer forward by 4
|
|
540
|
+
* bytes.
|
|
541
|
+
* @param value - The value to write.
|
|
542
|
+
* @returns This.
|
|
543
|
+
*/
|
|
544
|
+
writeInt32(e) {
|
|
545
|
+
return this.ensureAvailable(4), this._data.setInt32(this.offset, e, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this;
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Write `value` as a 32-bit unsigned integer and move pointer forward by 4
|
|
549
|
+
* bytes.
|
|
550
|
+
* @param value - The value to write.
|
|
551
|
+
* @returns This.
|
|
552
|
+
*/
|
|
553
|
+
writeUint32(e) {
|
|
554
|
+
return this.ensureAvailable(4), this._data.setUint32(this.offset, e, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Write `value` as a 32-bit floating number and move pointer forward by 4
|
|
558
|
+
* bytes.
|
|
559
|
+
* @param value - The value to write.
|
|
560
|
+
* @returns This.
|
|
561
|
+
*/
|
|
562
|
+
writeFloat32(e) {
|
|
563
|
+
return this.ensureAvailable(4), this._data.setFloat32(this.offset, e, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this;
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Write `value` as a 64-bit floating number and move pointer forward by 8
|
|
567
|
+
* bytes.
|
|
568
|
+
* @param value - The value to write.
|
|
569
|
+
* @returns This.
|
|
570
|
+
*/
|
|
571
|
+
writeFloat64(e) {
|
|
572
|
+
return this.ensureAvailable(8), this._data.setFloat64(this.offset, e, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this;
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Write `value` as a 64-bit signed bigint and move pointer forward by 8
|
|
576
|
+
* bytes.
|
|
577
|
+
* @param value - The value to write.
|
|
578
|
+
* @returns This.
|
|
579
|
+
*/
|
|
580
|
+
writeBigInt64(e) {
|
|
581
|
+
return this.ensureAvailable(8), this._data.setBigInt64(this.offset, e, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Write `value` as a 64-bit unsigned bigint and move pointer forward by 8
|
|
585
|
+
* bytes.
|
|
586
|
+
* @param value - The value to write.
|
|
587
|
+
* @returns This.
|
|
588
|
+
*/
|
|
589
|
+
writeBigUint64(e) {
|
|
590
|
+
return this.ensureAvailable(8), this._data.setBigUint64(this.offset, e, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this;
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Write the charCode of `str`'s first character as an 8-bit unsigned integer
|
|
594
|
+
* and move pointer forward by 1 byte.
|
|
595
|
+
* @param str - The character to write.
|
|
596
|
+
* @returns This.
|
|
597
|
+
*/
|
|
598
|
+
writeChar(e) {
|
|
599
|
+
return this.writeUint8(e.charCodeAt(0));
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Write the charCodes of all `str`'s characters as 8-bit unsigned integers
|
|
603
|
+
* and move pointer forward by `str.length` bytes.
|
|
604
|
+
* @param str - The characters to write.
|
|
605
|
+
* @returns This.
|
|
606
|
+
*/
|
|
607
|
+
writeChars(e) {
|
|
608
|
+
for (let t = 0; t < e.length; t++)
|
|
609
|
+
this.writeUint8(e.charCodeAt(t));
|
|
610
|
+
return this;
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* UTF-8 encode and write `str` to the current pointer offset and move pointer
|
|
614
|
+
* forward according to the encoded length.
|
|
615
|
+
* @param str - The string to write.
|
|
616
|
+
* @returns This.
|
|
617
|
+
*/
|
|
618
|
+
writeUtf8(e) {
|
|
619
|
+
return this.writeBytes(Ie(e));
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* Export a Uint8Array view of the internal buffer.
|
|
623
|
+
* The view starts at the byte offset and its length
|
|
624
|
+
* is calculated to stop at the last written byte or the original length.
|
|
625
|
+
* @returns A new Uint8Array view.
|
|
626
|
+
*/
|
|
627
|
+
toArray() {
|
|
628
|
+
return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte);
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Get the total number of bytes written so far, regardless of the current offset.
|
|
632
|
+
* @returns - Total number of bytes.
|
|
633
|
+
*/
|
|
634
|
+
getWrittenByteLength() {
|
|
635
|
+
return this.lastWrittenByte - this.byteOffset;
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Update the last written byte offset
|
|
639
|
+
* @private
|
|
640
|
+
*/
|
|
641
|
+
_updateLastWrittenByte() {
|
|
642
|
+
this.offset > this.lastWrittenByte && (this.lastWrittenByte = this.offset);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
function H(i) {
|
|
646
|
+
let e = i.length;
|
|
647
|
+
for (; --e >= 0; )
|
|
648
|
+
i[e] = 0;
|
|
649
|
+
}
|
|
650
|
+
const Ce = 3, Ne = 258, ie = 29, De = 256, Me = De + 1 + ie, ne = 30, Le = 512, Be = new Array((Me + 2) * 2);
|
|
651
|
+
H(Be);
|
|
652
|
+
const $e = new Array(ne * 2);
|
|
653
|
+
H($e);
|
|
654
|
+
const He = new Array(Le);
|
|
655
|
+
H(He);
|
|
656
|
+
const Fe = new Array(Ne - Ce + 1);
|
|
657
|
+
H(Fe);
|
|
658
|
+
const We = new Array(ie);
|
|
659
|
+
H(We);
|
|
660
|
+
const Ze = new Array(ne);
|
|
661
|
+
H(Ze);
|
|
662
|
+
const ze = (i, e, t, n) => {
|
|
663
|
+
let a = i & 65535 | 0, s = i >>> 16 & 65535 | 0, l = 0;
|
|
664
|
+
for (; t !== 0; ) {
|
|
665
|
+
l = t > 2e3 ? 2e3 : t, t -= l;
|
|
666
|
+
do
|
|
667
|
+
a = a + e[n++] | 0, s = s + a | 0;
|
|
668
|
+
while (--l);
|
|
669
|
+
a %= 65521, s %= 65521;
|
|
670
|
+
}
|
|
671
|
+
return a | s << 16 | 0;
|
|
672
|
+
};
|
|
673
|
+
var ut = ze;
|
|
674
|
+
const Pe = () => {
|
|
675
|
+
let i, e = [];
|
|
676
|
+
for (var t = 0; t < 256; t++) {
|
|
677
|
+
i = t;
|
|
678
|
+
for (var n = 0; n < 8; n++)
|
|
679
|
+
i = i & 1 ? 3988292384 ^ i >>> 1 : i >>> 1;
|
|
680
|
+
e[t] = i;
|
|
681
|
+
}
|
|
682
|
+
return e;
|
|
683
|
+
}, Ge = new Uint32Array(Pe()), Ke = (i, e, t, n) => {
|
|
684
|
+
const a = Ge, s = n + t;
|
|
685
|
+
i ^= -1;
|
|
686
|
+
for (let l = n; l < s; l++)
|
|
687
|
+
i = i >>> 8 ^ a[(i ^ e[l]) & 255];
|
|
688
|
+
return i ^ -1;
|
|
689
|
+
};
|
|
690
|
+
var R = Ke, _t = {
|
|
691
|
+
2: "need dictionary",
|
|
692
|
+
/* Z_NEED_DICT 2 */
|
|
693
|
+
1: "stream end",
|
|
694
|
+
/* Z_STREAM_END 1 */
|
|
695
|
+
0: "",
|
|
696
|
+
/* Z_OK 0 */
|
|
697
|
+
"-1": "file error",
|
|
698
|
+
/* Z_ERRNO (-1) */
|
|
699
|
+
"-2": "stream error",
|
|
700
|
+
/* Z_STREAM_ERROR (-2) */
|
|
701
|
+
"-3": "data error",
|
|
702
|
+
/* Z_DATA_ERROR (-3) */
|
|
703
|
+
"-4": "insufficient memory",
|
|
704
|
+
/* Z_MEM_ERROR (-4) */
|
|
705
|
+
"-5": "buffer error",
|
|
706
|
+
/* Z_BUF_ERROR (-5) */
|
|
707
|
+
"-6": "incompatible version"
|
|
708
|
+
/* Z_VERSION_ERROR (-6) */
|
|
709
|
+
}, se = {
|
|
710
|
+
/* Allowed flush values; see deflate() and inflate() below for details */
|
|
711
|
+
Z_NO_FLUSH: 0,
|
|
712
|
+
Z_FINISH: 4,
|
|
713
|
+
Z_BLOCK: 5,
|
|
714
|
+
Z_TREES: 6,
|
|
715
|
+
/* Return codes for the compression/decompression functions. Negative values
|
|
716
|
+
* are errors, positive values are used for special but normal events.
|
|
717
|
+
*/
|
|
718
|
+
Z_OK: 0,
|
|
719
|
+
Z_STREAM_END: 1,
|
|
720
|
+
Z_NEED_DICT: 2,
|
|
721
|
+
Z_STREAM_ERROR: -2,
|
|
722
|
+
Z_DATA_ERROR: -3,
|
|
723
|
+
Z_MEM_ERROR: -4,
|
|
724
|
+
Z_BUF_ERROR: -5,
|
|
725
|
+
/* The deflate compression method */
|
|
726
|
+
Z_DEFLATED: 8
|
|
727
|
+
//Z_NULL: null // Use -1 or null inline, depending on var type
|
|
728
|
+
};
|
|
729
|
+
const Ye = (i, e) => Object.prototype.hasOwnProperty.call(i, e);
|
|
730
|
+
var Xe = function(i) {
|
|
731
|
+
const e = Array.prototype.slice.call(arguments, 1);
|
|
732
|
+
for (; e.length; ) {
|
|
733
|
+
const t = e.shift();
|
|
734
|
+
if (t) {
|
|
735
|
+
if (typeof t != "object")
|
|
736
|
+
throw new TypeError(t + "must be non-object");
|
|
737
|
+
for (const n in t)
|
|
738
|
+
Ye(t, n) && (i[n] = t[n]);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
return i;
|
|
742
|
+
}, je = (i) => {
|
|
743
|
+
let e = 0;
|
|
744
|
+
for (let n = 0, a = i.length; n < a; n++)
|
|
745
|
+
e += i[n].length;
|
|
746
|
+
const t = new Uint8Array(e);
|
|
747
|
+
for (let n = 0, a = 0, s = i.length; n < s; n++) {
|
|
748
|
+
let l = i[n];
|
|
749
|
+
t.set(l, a), a += l.length;
|
|
750
|
+
}
|
|
751
|
+
return t;
|
|
752
|
+
}, ae = {
|
|
753
|
+
assign: Xe,
|
|
754
|
+
flattenChunks: je
|
|
755
|
+
};
|
|
756
|
+
let re = !0;
|
|
757
|
+
try {
|
|
758
|
+
String.fromCharCode.apply(null, new Uint8Array(1));
|
|
759
|
+
} catch {
|
|
760
|
+
re = !1;
|
|
761
|
+
}
|
|
762
|
+
const W = new Uint8Array(256);
|
|
763
|
+
for (let i = 0; i < 256; i++)
|
|
764
|
+
W[i] = i >= 252 ? 6 : i >= 248 ? 5 : i >= 240 ? 4 : i >= 224 ? 3 : i >= 192 ? 2 : 1;
|
|
765
|
+
W[254] = W[254] = 1;
|
|
766
|
+
var Ve = (i) => {
|
|
767
|
+
if (typeof TextEncoder == "function" && TextEncoder.prototype.encode)
|
|
768
|
+
return new TextEncoder().encode(i);
|
|
769
|
+
let e, t, n, a, s, l = i.length, h = 0;
|
|
770
|
+
for (a = 0; a < l; a++)
|
|
771
|
+
t = i.charCodeAt(a), (t & 64512) === 55296 && a + 1 < l && (n = i.charCodeAt(a + 1), (n & 64512) === 56320 && (t = 65536 + (t - 55296 << 10) + (n - 56320), a++)), h += t < 128 ? 1 : t < 2048 ? 2 : t < 65536 ? 3 : 4;
|
|
772
|
+
for (e = new Uint8Array(h), s = 0, a = 0; s < h; a++)
|
|
773
|
+
t = i.charCodeAt(a), (t & 64512) === 55296 && a + 1 < l && (n = i.charCodeAt(a + 1), (n & 64512) === 56320 && (t = 65536 + (t - 55296 << 10) + (n - 56320), a++)), t < 128 ? e[s++] = t : t < 2048 ? (e[s++] = 192 | t >>> 6, e[s++] = 128 | t & 63) : t < 65536 ? (e[s++] = 224 | t >>> 12, e[s++] = 128 | t >>> 6 & 63, e[s++] = 128 | t & 63) : (e[s++] = 240 | t >>> 18, e[s++] = 128 | t >>> 12 & 63, e[s++] = 128 | t >>> 6 & 63, e[s++] = 128 | t & 63);
|
|
774
|
+
return e;
|
|
775
|
+
};
|
|
776
|
+
const qe = (i, e) => {
|
|
777
|
+
if (e < 65534 && i.subarray && re)
|
|
778
|
+
return String.fromCharCode.apply(null, i.length === e ? i : i.subarray(0, e));
|
|
779
|
+
let t = "";
|
|
780
|
+
for (let n = 0; n < e; n++)
|
|
781
|
+
t += String.fromCharCode(i[n]);
|
|
782
|
+
return t;
|
|
783
|
+
};
|
|
784
|
+
var Je = (i, e) => {
|
|
785
|
+
const t = e || i.length;
|
|
786
|
+
if (typeof TextDecoder == "function" && TextDecoder.prototype.decode)
|
|
787
|
+
return new TextDecoder().decode(i.subarray(0, e));
|
|
788
|
+
let n, a;
|
|
789
|
+
const s = new Array(t * 2);
|
|
790
|
+
for (a = 0, n = 0; n < t; ) {
|
|
791
|
+
let l = i[n++];
|
|
792
|
+
if (l < 128) {
|
|
793
|
+
s[a++] = l;
|
|
794
|
+
continue;
|
|
795
|
+
}
|
|
796
|
+
let h = W[l];
|
|
797
|
+
if (h > 4) {
|
|
798
|
+
s[a++] = 65533, n += h - 1;
|
|
799
|
+
continue;
|
|
800
|
+
}
|
|
801
|
+
for (l &= h === 2 ? 31 : h === 3 ? 15 : 7; h > 1 && n < t; )
|
|
802
|
+
l = l << 6 | i[n++] & 63, h--;
|
|
803
|
+
if (h > 1) {
|
|
804
|
+
s[a++] = 65533;
|
|
805
|
+
continue;
|
|
806
|
+
}
|
|
807
|
+
l < 65536 ? s[a++] = l : (l -= 65536, s[a++] = 55296 | l >> 10 & 1023, s[a++] = 56320 | l & 1023);
|
|
808
|
+
}
|
|
809
|
+
return qe(s, a);
|
|
810
|
+
}, Qe = (i, e) => {
|
|
811
|
+
e = e || i.length, e > i.length && (e = i.length);
|
|
812
|
+
let t = e - 1;
|
|
813
|
+
for (; t >= 0 && (i[t] & 192) === 128; )
|
|
814
|
+
t--;
|
|
815
|
+
return t < 0 || t === 0 ? e : t + W[i[t]] > e ? t : e;
|
|
816
|
+
}, pt = {
|
|
817
|
+
string2buf: Ve,
|
|
818
|
+
buf2string: Je,
|
|
819
|
+
utf8border: Qe
|
|
820
|
+
};
|
|
821
|
+
function ti() {
|
|
822
|
+
this.input = null, this.next_in = 0, this.avail_in = 0, this.total_in = 0, this.output = null, this.next_out = 0, this.avail_out = 0, this.total_out = 0, this.msg = "", this.state = null, this.data_type = 2, this.adler = 0;
|
|
823
|
+
}
|
|
824
|
+
var ei = ti;
|
|
825
|
+
const K = 16209, ii = 16191;
|
|
826
|
+
var ni = function(e, t) {
|
|
827
|
+
let n, a, s, l, h, _, r, o, w, d, f, u, U, x, g, T, y, c, E, S, p, m, A, b;
|
|
828
|
+
const k = e.state;
|
|
829
|
+
n = e.next_in, A = e.input, a = n + (e.avail_in - 5), s = e.next_out, b = e.output, l = s - (t - e.avail_out), h = s + (e.avail_out - 257), _ = k.dmax, r = k.wsize, o = k.whave, w = k.wnext, d = k.window, f = k.hold, u = k.bits, U = k.lencode, x = k.distcode, g = (1 << k.lenbits) - 1, T = (1 << k.distbits) - 1;
|
|
830
|
+
t:
|
|
831
|
+
do {
|
|
832
|
+
u < 15 && (f += A[n++] << u, u += 8, f += A[n++] << u, u += 8), y = U[f & g];
|
|
833
|
+
e:
|
|
834
|
+
for (; ; ) {
|
|
835
|
+
if (c = y >>> 24, f >>>= c, u -= c, c = y >>> 16 & 255, c === 0)
|
|
836
|
+
b[s++] = y & 65535;
|
|
837
|
+
else if (c & 16) {
|
|
838
|
+
E = y & 65535, c &= 15, c && (u < c && (f += A[n++] << u, u += 8), E += f & (1 << c) - 1, f >>>= c, u -= c), u < 15 && (f += A[n++] << u, u += 8, f += A[n++] << u, u += 8), y = x[f & T];
|
|
839
|
+
i:
|
|
840
|
+
for (; ; ) {
|
|
841
|
+
if (c = y >>> 24, f >>>= c, u -= c, c = y >>> 16 & 255, c & 16) {
|
|
842
|
+
if (S = y & 65535, c &= 15, u < c && (f += A[n++] << u, u += 8, u < c && (f += A[n++] << u, u += 8)), S += f & (1 << c) - 1, S > _) {
|
|
843
|
+
e.msg = "invalid distance too far back", k.mode = K;
|
|
844
|
+
break t;
|
|
845
|
+
}
|
|
846
|
+
if (f >>>= c, u -= c, c = s - l, S > c) {
|
|
847
|
+
if (c = S - c, c > o && k.sane) {
|
|
848
|
+
e.msg = "invalid distance too far back", k.mode = K;
|
|
849
|
+
break t;
|
|
850
|
+
}
|
|
851
|
+
if (p = 0, m = d, w === 0) {
|
|
852
|
+
if (p += r - c, c < E) {
|
|
853
|
+
E -= c;
|
|
854
|
+
do
|
|
855
|
+
b[s++] = d[p++];
|
|
856
|
+
while (--c);
|
|
857
|
+
p = s - S, m = b;
|
|
858
|
+
}
|
|
859
|
+
} else if (w < c) {
|
|
860
|
+
if (p += r + w - c, c -= w, c < E) {
|
|
861
|
+
E -= c;
|
|
862
|
+
do
|
|
863
|
+
b[s++] = d[p++];
|
|
864
|
+
while (--c);
|
|
865
|
+
if (p = 0, w < E) {
|
|
866
|
+
c = w, E -= c;
|
|
867
|
+
do
|
|
868
|
+
b[s++] = d[p++];
|
|
869
|
+
while (--c);
|
|
870
|
+
p = s - S, m = b;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
} else if (p += w - c, c < E) {
|
|
874
|
+
E -= c;
|
|
875
|
+
do
|
|
876
|
+
b[s++] = d[p++];
|
|
877
|
+
while (--c);
|
|
878
|
+
p = s - S, m = b;
|
|
879
|
+
}
|
|
880
|
+
for (; E > 2; )
|
|
881
|
+
b[s++] = m[p++], b[s++] = m[p++], b[s++] = m[p++], E -= 3;
|
|
882
|
+
E && (b[s++] = m[p++], E > 1 && (b[s++] = m[p++]));
|
|
883
|
+
} else {
|
|
884
|
+
p = s - S;
|
|
885
|
+
do
|
|
886
|
+
b[s++] = b[p++], b[s++] = b[p++], b[s++] = b[p++], E -= 3;
|
|
887
|
+
while (E > 2);
|
|
888
|
+
E && (b[s++] = b[p++], E > 1 && (b[s++] = b[p++]));
|
|
889
|
+
}
|
|
890
|
+
} else if ((c & 64) === 0) {
|
|
891
|
+
y = x[(y & 65535) + (f & (1 << c) - 1)];
|
|
892
|
+
continue i;
|
|
893
|
+
} else {
|
|
894
|
+
e.msg = "invalid distance code", k.mode = K;
|
|
895
|
+
break t;
|
|
896
|
+
}
|
|
897
|
+
break;
|
|
898
|
+
}
|
|
899
|
+
} else if ((c & 64) === 0) {
|
|
900
|
+
y = U[(y & 65535) + (f & (1 << c) - 1)];
|
|
901
|
+
continue e;
|
|
902
|
+
} else if (c & 32) {
|
|
903
|
+
k.mode = ii;
|
|
904
|
+
break t;
|
|
905
|
+
} else {
|
|
906
|
+
e.msg = "invalid literal/length code", k.mode = K;
|
|
907
|
+
break t;
|
|
908
|
+
}
|
|
909
|
+
break;
|
|
910
|
+
}
|
|
911
|
+
} while (n < a && s < h);
|
|
912
|
+
E = u >> 3, n -= E, u -= E << 3, f &= (1 << u) - 1, e.next_in = n, e.next_out = s, e.avail_in = n < a ? 5 + (a - n) : 5 - (n - a), e.avail_out = s < h ? 257 + (h - s) : 257 - (s - h), k.hold = f, k.bits = u;
|
|
913
|
+
};
|
|
914
|
+
const $ = 15, xt = 852, yt = 592, kt = 0, it = 1, Et = 2, si = new Uint16Array([
|
|
915
|
+
/* Length codes 257..285 base */
|
|
916
|
+
3,
|
|
917
|
+
4,
|
|
918
|
+
5,
|
|
919
|
+
6,
|
|
920
|
+
7,
|
|
921
|
+
8,
|
|
922
|
+
9,
|
|
923
|
+
10,
|
|
924
|
+
11,
|
|
925
|
+
13,
|
|
926
|
+
15,
|
|
927
|
+
17,
|
|
928
|
+
19,
|
|
929
|
+
23,
|
|
930
|
+
27,
|
|
931
|
+
31,
|
|
932
|
+
35,
|
|
933
|
+
43,
|
|
934
|
+
51,
|
|
935
|
+
59,
|
|
936
|
+
67,
|
|
937
|
+
83,
|
|
938
|
+
99,
|
|
939
|
+
115,
|
|
940
|
+
131,
|
|
941
|
+
163,
|
|
942
|
+
195,
|
|
943
|
+
227,
|
|
944
|
+
258,
|
|
945
|
+
0,
|
|
946
|
+
0
|
|
947
|
+
]), ai = new Uint8Array([
|
|
948
|
+
/* Length codes 257..285 extra */
|
|
949
|
+
16,
|
|
950
|
+
16,
|
|
951
|
+
16,
|
|
952
|
+
16,
|
|
953
|
+
16,
|
|
954
|
+
16,
|
|
955
|
+
16,
|
|
956
|
+
16,
|
|
957
|
+
17,
|
|
958
|
+
17,
|
|
959
|
+
17,
|
|
960
|
+
17,
|
|
961
|
+
18,
|
|
962
|
+
18,
|
|
963
|
+
18,
|
|
964
|
+
18,
|
|
965
|
+
19,
|
|
966
|
+
19,
|
|
967
|
+
19,
|
|
968
|
+
19,
|
|
969
|
+
20,
|
|
970
|
+
20,
|
|
971
|
+
20,
|
|
972
|
+
20,
|
|
973
|
+
21,
|
|
974
|
+
21,
|
|
975
|
+
21,
|
|
976
|
+
21,
|
|
977
|
+
16,
|
|
978
|
+
72,
|
|
979
|
+
78
|
|
980
|
+
]), ri = new Uint16Array([
|
|
981
|
+
/* Distance codes 0..29 base */
|
|
982
|
+
1,
|
|
983
|
+
2,
|
|
984
|
+
3,
|
|
985
|
+
4,
|
|
986
|
+
5,
|
|
987
|
+
7,
|
|
988
|
+
9,
|
|
989
|
+
13,
|
|
990
|
+
17,
|
|
991
|
+
25,
|
|
992
|
+
33,
|
|
993
|
+
49,
|
|
994
|
+
65,
|
|
995
|
+
97,
|
|
996
|
+
129,
|
|
997
|
+
193,
|
|
998
|
+
257,
|
|
999
|
+
385,
|
|
1000
|
+
513,
|
|
1001
|
+
769,
|
|
1002
|
+
1025,
|
|
1003
|
+
1537,
|
|
1004
|
+
2049,
|
|
1005
|
+
3073,
|
|
1006
|
+
4097,
|
|
1007
|
+
6145,
|
|
1008
|
+
8193,
|
|
1009
|
+
12289,
|
|
1010
|
+
16385,
|
|
1011
|
+
24577,
|
|
1012
|
+
0,
|
|
1013
|
+
0
|
|
1014
|
+
]), oi = new Uint8Array([
|
|
1015
|
+
/* Distance codes 0..29 extra */
|
|
1016
|
+
16,
|
|
1017
|
+
16,
|
|
1018
|
+
16,
|
|
1019
|
+
16,
|
|
1020
|
+
17,
|
|
1021
|
+
17,
|
|
1022
|
+
18,
|
|
1023
|
+
18,
|
|
1024
|
+
19,
|
|
1025
|
+
19,
|
|
1026
|
+
20,
|
|
1027
|
+
20,
|
|
1028
|
+
21,
|
|
1029
|
+
21,
|
|
1030
|
+
22,
|
|
1031
|
+
22,
|
|
1032
|
+
23,
|
|
1033
|
+
23,
|
|
1034
|
+
24,
|
|
1035
|
+
24,
|
|
1036
|
+
25,
|
|
1037
|
+
25,
|
|
1038
|
+
26,
|
|
1039
|
+
26,
|
|
1040
|
+
27,
|
|
1041
|
+
27,
|
|
1042
|
+
28,
|
|
1043
|
+
28,
|
|
1044
|
+
29,
|
|
1045
|
+
29,
|
|
1046
|
+
64,
|
|
1047
|
+
64
|
|
1048
|
+
]), hi = (i, e, t, n, a, s, l, h) => {
|
|
1049
|
+
const _ = h.bits;
|
|
1050
|
+
let r = 0, o = 0, w = 0, d = 0, f = 0, u = 0, U = 0, x = 0, g = 0, T = 0, y, c, E, S, p, m = null, A;
|
|
1051
|
+
const b = new Uint16Array($ + 1), k = new Uint16Array($ + 1);
|
|
1052
|
+
let M = null, gt, P, G;
|
|
1053
|
+
for (r = 0; r <= $; r++)
|
|
1054
|
+
b[r] = 0;
|
|
1055
|
+
for (o = 0; o < n; o++)
|
|
1056
|
+
b[e[t + o]]++;
|
|
1057
|
+
for (f = _, d = $; d >= 1 && b[d] === 0; d--)
|
|
1058
|
+
;
|
|
1059
|
+
if (f > d && (f = d), d === 0)
|
|
1060
|
+
return a[s++] = 1 << 24 | 64 << 16 | 0, a[s++] = 1 << 24 | 64 << 16 | 0, h.bits = 1, 0;
|
|
1061
|
+
for (w = 1; w < d && b[w] === 0; w++)
|
|
1062
|
+
;
|
|
1063
|
+
for (f < w && (f = w), x = 1, r = 1; r <= $; r++)
|
|
1064
|
+
if (x <<= 1, x -= b[r], x < 0)
|
|
1065
|
+
return -1;
|
|
1066
|
+
if (x > 0 && (i === kt || d !== 1))
|
|
1067
|
+
return -1;
|
|
1068
|
+
for (k[1] = 0, r = 1; r < $; r++)
|
|
1069
|
+
k[r + 1] = k[r] + b[r];
|
|
1070
|
+
for (o = 0; o < n; o++)
|
|
1071
|
+
e[t + o] !== 0 && (l[k[e[t + o]]++] = o);
|
|
1072
|
+
if (i === kt ? (m = M = l, A = 20) : i === it ? (m = si, M = ai, A = 257) : (m = ri, M = oi, A = 0), T = 0, o = 0, r = w, p = s, u = f, U = 0, E = -1, g = 1 << f, S = g - 1, i === it && g > xt || i === Et && g > yt)
|
|
1073
|
+
return 1;
|
|
1074
|
+
for (; ; ) {
|
|
1075
|
+
gt = r - U, l[o] + 1 < A ? (P = 0, G = l[o]) : l[o] >= A ? (P = M[l[o] - A], G = m[l[o] - A]) : (P = 96, G = 0), y = 1 << r - U, c = 1 << u, w = c;
|
|
1076
|
+
do
|
|
1077
|
+
c -= y, a[p + (T >> U) + c] = gt << 24 | P << 16 | G | 0;
|
|
1078
|
+
while (c !== 0);
|
|
1079
|
+
for (y = 1 << r - 1; T & y; )
|
|
1080
|
+
y >>= 1;
|
|
1081
|
+
if (y !== 0 ? (T &= y - 1, T += y) : T = 0, o++, --b[r] === 0) {
|
|
1082
|
+
if (r === d)
|
|
1083
|
+
break;
|
|
1084
|
+
r = e[t + l[o]];
|
|
1085
|
+
}
|
|
1086
|
+
if (r > f && (T & S) !== E) {
|
|
1087
|
+
for (U === 0 && (U = f), p += w, u = r - U, x = 1 << u; u + U < d && (x -= b[u + U], !(x <= 0)); )
|
|
1088
|
+
u++, x <<= 1;
|
|
1089
|
+
if (g += 1 << u, i === it && g > xt || i === Et && g > yt)
|
|
1090
|
+
return 1;
|
|
1091
|
+
E = T & S, a[E] = f << 24 | u << 16 | p - s | 0;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
return T !== 0 && (a[p + T] = r - U << 24 | 64 << 16 | 0), h.bits = f, 0;
|
|
1095
|
+
};
|
|
1096
|
+
var F = hi;
|
|
1097
|
+
const fi = 0, oe = 1, he = 2, {
|
|
1098
|
+
Z_FINISH: At,
|
|
1099
|
+
Z_BLOCK: li,
|
|
1100
|
+
Z_TREES: Y,
|
|
1101
|
+
Z_OK: L,
|
|
1102
|
+
Z_STREAM_END: ci,
|
|
1103
|
+
Z_NEED_DICT: di,
|
|
1104
|
+
Z_STREAM_ERROR: O,
|
|
1105
|
+
Z_DATA_ERROR: fe,
|
|
1106
|
+
Z_MEM_ERROR: le,
|
|
1107
|
+
Z_BUF_ERROR: ui,
|
|
1108
|
+
Z_DEFLATED: Tt
|
|
1109
|
+
} = se, tt = 16180, mt = 16181, vt = 16182, Ut = 16183, St = 16184, It = 16185, Ot = 16186, Rt = 16187, Ct = 16188, Nt = 16189, Q = 16190, C = 16191, nt = 16192, Dt = 16193, st = 16194, Mt = 16195, Lt = 16196, Bt = 16197, $t = 16198, X = 16199, j = 16200, Ht = 16201, Ft = 16202, Wt = 16203, Zt = 16204, zt = 16205, at = 16206, Pt = 16207, Gt = 16208, v = 16209, ce = 16210, de = 16211, _i = 852, pi = 592, wi = 15, gi = wi, Kt = (i) => (i >>> 24 & 255) + (i >>> 8 & 65280) + ((i & 65280) << 8) + ((i & 255) << 24);
|
|
1110
|
+
function bi() {
|
|
1111
|
+
this.strm = null, this.mode = 0, this.last = !1, this.wrap = 0, this.havedict = !1, this.flags = 0, this.dmax = 0, this.check = 0, this.total = 0, this.head = null, this.wbits = 0, this.wsize = 0, this.whave = 0, this.wnext = 0, this.window = null, this.hold = 0, this.bits = 0, this.length = 0, this.offset = 0, this.extra = 0, this.lencode = null, this.distcode = null, this.lenbits = 0, this.distbits = 0, this.ncode = 0, this.nlen = 0, this.ndist = 0, this.have = 0, this.next = null, this.lens = new Uint16Array(320), this.work = new Uint16Array(288), this.lendyn = null, this.distdyn = null, this.sane = 0, this.back = 0, this.was = 0;
|
|
1112
|
+
}
|
|
1113
|
+
const B = (i) => {
|
|
1114
|
+
if (!i)
|
|
1115
|
+
return 1;
|
|
1116
|
+
const e = i.state;
|
|
1117
|
+
return !e || e.strm !== i || e.mode < tt || e.mode > de ? 1 : 0;
|
|
1118
|
+
}, ue = (i) => {
|
|
1119
|
+
if (B(i))
|
|
1120
|
+
return O;
|
|
1121
|
+
const e = i.state;
|
|
1122
|
+
return i.total_in = i.total_out = e.total = 0, i.msg = "", e.wrap && (i.adler = e.wrap & 1), e.mode = tt, e.last = 0, e.havedict = 0, e.flags = -1, e.dmax = 32768, e.head = null, e.hold = 0, e.bits = 0, e.lencode = e.lendyn = new Int32Array(_i), e.distcode = e.distdyn = new Int32Array(pi), e.sane = 1, e.back = -1, L;
|
|
1123
|
+
}, _e = (i) => {
|
|
1124
|
+
if (B(i))
|
|
1125
|
+
return O;
|
|
1126
|
+
const e = i.state;
|
|
1127
|
+
return e.wsize = 0, e.whave = 0, e.wnext = 0, ue(i);
|
|
1128
|
+
}, pe = (i, e) => {
|
|
1129
|
+
let t;
|
|
1130
|
+
if (B(i))
|
|
1131
|
+
return O;
|
|
1132
|
+
const n = i.state;
|
|
1133
|
+
return e < 0 ? (t = 0, e = -e) : (t = (e >> 4) + 5, e < 48 && (e &= 15)), e && (e < 8 || e > 15) ? O : (n.window !== null && n.wbits !== e && (n.window = null), n.wrap = t, n.wbits = e, _e(i));
|
|
1134
|
+
}, we = (i, e) => {
|
|
1135
|
+
if (!i)
|
|
1136
|
+
return O;
|
|
1137
|
+
const t = new bi();
|
|
1138
|
+
i.state = t, t.strm = i, t.window = null, t.mode = tt;
|
|
1139
|
+
const n = pe(i, e);
|
|
1140
|
+
return n !== L && (i.state = null), n;
|
|
1141
|
+
}, xi = (i) => we(i, gi);
|
|
1142
|
+
let Yt = !0, rt, ot;
|
|
1143
|
+
const yi = (i) => {
|
|
1144
|
+
if (Yt) {
|
|
1145
|
+
rt = new Int32Array(512), ot = new Int32Array(32);
|
|
1146
|
+
let e = 0;
|
|
1147
|
+
for (; e < 144; )
|
|
1148
|
+
i.lens[e++] = 8;
|
|
1149
|
+
for (; e < 256; )
|
|
1150
|
+
i.lens[e++] = 9;
|
|
1151
|
+
for (; e < 280; )
|
|
1152
|
+
i.lens[e++] = 7;
|
|
1153
|
+
for (; e < 288; )
|
|
1154
|
+
i.lens[e++] = 8;
|
|
1155
|
+
for (F(oe, i.lens, 0, 288, rt, 0, i.work, { bits: 9 }), e = 0; e < 32; )
|
|
1156
|
+
i.lens[e++] = 5;
|
|
1157
|
+
F(he, i.lens, 0, 32, ot, 0, i.work, { bits: 5 }), Yt = !1;
|
|
1158
|
+
}
|
|
1159
|
+
i.lencode = rt, i.lenbits = 9, i.distcode = ot, i.distbits = 5;
|
|
1160
|
+
}, ge = (i, e, t, n) => {
|
|
1161
|
+
let a;
|
|
1162
|
+
const s = i.state;
|
|
1163
|
+
return s.window === null && (s.wsize = 1 << s.wbits, s.wnext = 0, s.whave = 0, s.window = new Uint8Array(s.wsize)), n >= s.wsize ? (s.window.set(e.subarray(t - s.wsize, t), 0), s.wnext = 0, s.whave = s.wsize) : (a = s.wsize - s.wnext, a > n && (a = n), s.window.set(e.subarray(t - n, t - n + a), s.wnext), n -= a, n ? (s.window.set(e.subarray(t - n, t), 0), s.wnext = n, s.whave = s.wsize) : (s.wnext += a, s.wnext === s.wsize && (s.wnext = 0), s.whave < s.wsize && (s.whave += a))), 0;
|
|
1164
|
+
}, ki = (i, e) => {
|
|
1165
|
+
let t, n, a, s, l, h, _, r, o, w, d, f, u, U, x = 0, g, T, y, c, E, S, p, m;
|
|
1166
|
+
const A = new Uint8Array(4);
|
|
1167
|
+
let b, k;
|
|
1168
|
+
const M = (
|
|
1169
|
+
/* permutation of code lengths */
|
|
1170
|
+
new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15])
|
|
1171
|
+
);
|
|
1172
|
+
if (B(i) || !i.output || !i.input && i.avail_in !== 0)
|
|
1173
|
+
return O;
|
|
1174
|
+
t = i.state, t.mode === C && (t.mode = nt), l = i.next_out, a = i.output, _ = i.avail_out, s = i.next_in, n = i.input, h = i.avail_in, r = t.hold, o = t.bits, w = h, d = _, m = L;
|
|
1175
|
+
t:
|
|
1176
|
+
for (; ; )
|
|
1177
|
+
switch (t.mode) {
|
|
1178
|
+
case tt:
|
|
1179
|
+
if (t.wrap === 0) {
|
|
1180
|
+
t.mode = nt;
|
|
1181
|
+
break;
|
|
1182
|
+
}
|
|
1183
|
+
for (; o < 16; ) {
|
|
1184
|
+
if (h === 0)
|
|
1185
|
+
break t;
|
|
1186
|
+
h--, r += n[s++] << o, o += 8;
|
|
1187
|
+
}
|
|
1188
|
+
if (t.wrap & 2 && r === 35615) {
|
|
1189
|
+
t.wbits === 0 && (t.wbits = 15), t.check = 0, A[0] = r & 255, A[1] = r >>> 8 & 255, t.check = R(t.check, A, 2, 0), r = 0, o = 0, t.mode = mt;
|
|
1190
|
+
break;
|
|
1191
|
+
}
|
|
1192
|
+
if (t.head && (t.head.done = !1), !(t.wrap & 1) || /* check if zlib header allowed */
|
|
1193
|
+
(((r & 255) << 8) + (r >> 8)) % 31) {
|
|
1194
|
+
i.msg = "incorrect header check", t.mode = v;
|
|
1195
|
+
break;
|
|
1196
|
+
}
|
|
1197
|
+
if ((r & 15) !== Tt) {
|
|
1198
|
+
i.msg = "unknown compression method", t.mode = v;
|
|
1199
|
+
break;
|
|
1200
|
+
}
|
|
1201
|
+
if (r >>>= 4, o -= 4, p = (r & 15) + 8, t.wbits === 0 && (t.wbits = p), p > 15 || p > t.wbits) {
|
|
1202
|
+
i.msg = "invalid window size", t.mode = v;
|
|
1203
|
+
break;
|
|
1204
|
+
}
|
|
1205
|
+
t.dmax = 1 << t.wbits, t.flags = 0, i.adler = t.check = 1, t.mode = r & 512 ? Nt : C, r = 0, o = 0;
|
|
1206
|
+
break;
|
|
1207
|
+
case mt:
|
|
1208
|
+
for (; o < 16; ) {
|
|
1209
|
+
if (h === 0)
|
|
1210
|
+
break t;
|
|
1211
|
+
h--, r += n[s++] << o, o += 8;
|
|
1212
|
+
}
|
|
1213
|
+
if (t.flags = r, (t.flags & 255) !== Tt) {
|
|
1214
|
+
i.msg = "unknown compression method", t.mode = v;
|
|
1215
|
+
break;
|
|
1216
|
+
}
|
|
1217
|
+
if (t.flags & 57344) {
|
|
1218
|
+
i.msg = "unknown header flags set", t.mode = v;
|
|
1219
|
+
break;
|
|
1220
|
+
}
|
|
1221
|
+
t.head && (t.head.text = r >> 8 & 1), t.flags & 512 && t.wrap & 4 && (A[0] = r & 255, A[1] = r >>> 8 & 255, t.check = R(t.check, A, 2, 0)), r = 0, o = 0, t.mode = vt;
|
|
1222
|
+
/* falls through */
|
|
1223
|
+
case vt:
|
|
1224
|
+
for (; o < 32; ) {
|
|
1225
|
+
if (h === 0)
|
|
1226
|
+
break t;
|
|
1227
|
+
h--, r += n[s++] << o, o += 8;
|
|
1228
|
+
}
|
|
1229
|
+
t.head && (t.head.time = r), t.flags & 512 && t.wrap & 4 && (A[0] = r & 255, A[1] = r >>> 8 & 255, A[2] = r >>> 16 & 255, A[3] = r >>> 24 & 255, t.check = R(t.check, A, 4, 0)), r = 0, o = 0, t.mode = Ut;
|
|
1230
|
+
/* falls through */
|
|
1231
|
+
case Ut:
|
|
1232
|
+
for (; o < 16; ) {
|
|
1233
|
+
if (h === 0)
|
|
1234
|
+
break t;
|
|
1235
|
+
h--, r += n[s++] << o, o += 8;
|
|
1236
|
+
}
|
|
1237
|
+
t.head && (t.head.xflags = r & 255, t.head.os = r >> 8), t.flags & 512 && t.wrap & 4 && (A[0] = r & 255, A[1] = r >>> 8 & 255, t.check = R(t.check, A, 2, 0)), r = 0, o = 0, t.mode = St;
|
|
1238
|
+
/* falls through */
|
|
1239
|
+
case St:
|
|
1240
|
+
if (t.flags & 1024) {
|
|
1241
|
+
for (; o < 16; ) {
|
|
1242
|
+
if (h === 0)
|
|
1243
|
+
break t;
|
|
1244
|
+
h--, r += n[s++] << o, o += 8;
|
|
1245
|
+
}
|
|
1246
|
+
t.length = r, t.head && (t.head.extra_len = r), t.flags & 512 && t.wrap & 4 && (A[0] = r & 255, A[1] = r >>> 8 & 255, t.check = R(t.check, A, 2, 0)), r = 0, o = 0;
|
|
1247
|
+
} else t.head && (t.head.extra = null);
|
|
1248
|
+
t.mode = It;
|
|
1249
|
+
/* falls through */
|
|
1250
|
+
case It:
|
|
1251
|
+
if (t.flags & 1024 && (f = t.length, f > h && (f = h), f && (t.head && (p = t.head.extra_len - t.length, t.head.extra || (t.head.extra = new Uint8Array(t.head.extra_len)), t.head.extra.set(
|
|
1252
|
+
n.subarray(
|
|
1253
|
+
s,
|
|
1254
|
+
// extra field is limited to 65536 bytes
|
|
1255
|
+
// - no need for additional size check
|
|
1256
|
+
s + f
|
|
1257
|
+
),
|
|
1258
|
+
/*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/
|
|
1259
|
+
p
|
|
1260
|
+
)), t.flags & 512 && t.wrap & 4 && (t.check = R(t.check, n, f, s)), h -= f, s += f, t.length -= f), t.length))
|
|
1261
|
+
break t;
|
|
1262
|
+
t.length = 0, t.mode = Ot;
|
|
1263
|
+
/* falls through */
|
|
1264
|
+
case Ot:
|
|
1265
|
+
if (t.flags & 2048) {
|
|
1266
|
+
if (h === 0)
|
|
1267
|
+
break t;
|
|
1268
|
+
f = 0;
|
|
1269
|
+
do
|
|
1270
|
+
p = n[s + f++], t.head && p && t.length < 65536 && (t.head.name += String.fromCharCode(p));
|
|
1271
|
+
while (p && f < h);
|
|
1272
|
+
if (t.flags & 512 && t.wrap & 4 && (t.check = R(t.check, n, f, s)), h -= f, s += f, p)
|
|
1273
|
+
break t;
|
|
1274
|
+
} else t.head && (t.head.name = null);
|
|
1275
|
+
t.length = 0, t.mode = Rt;
|
|
1276
|
+
/* falls through */
|
|
1277
|
+
case Rt:
|
|
1278
|
+
if (t.flags & 4096) {
|
|
1279
|
+
if (h === 0)
|
|
1280
|
+
break t;
|
|
1281
|
+
f = 0;
|
|
1282
|
+
do
|
|
1283
|
+
p = n[s + f++], t.head && p && t.length < 65536 && (t.head.comment += String.fromCharCode(p));
|
|
1284
|
+
while (p && f < h);
|
|
1285
|
+
if (t.flags & 512 && t.wrap & 4 && (t.check = R(t.check, n, f, s)), h -= f, s += f, p)
|
|
1286
|
+
break t;
|
|
1287
|
+
} else t.head && (t.head.comment = null);
|
|
1288
|
+
t.mode = Ct;
|
|
1289
|
+
/* falls through */
|
|
1290
|
+
case Ct:
|
|
1291
|
+
if (t.flags & 512) {
|
|
1292
|
+
for (; o < 16; ) {
|
|
1293
|
+
if (h === 0)
|
|
1294
|
+
break t;
|
|
1295
|
+
h--, r += n[s++] << o, o += 8;
|
|
1296
|
+
}
|
|
1297
|
+
if (t.wrap & 4 && r !== (t.check & 65535)) {
|
|
1298
|
+
i.msg = "header crc mismatch", t.mode = v;
|
|
1299
|
+
break;
|
|
1300
|
+
}
|
|
1301
|
+
r = 0, o = 0;
|
|
1302
|
+
}
|
|
1303
|
+
t.head && (t.head.hcrc = t.flags >> 9 & 1, t.head.done = !0), i.adler = t.check = 0, t.mode = C;
|
|
1304
|
+
break;
|
|
1305
|
+
case Nt:
|
|
1306
|
+
for (; o < 32; ) {
|
|
1307
|
+
if (h === 0)
|
|
1308
|
+
break t;
|
|
1309
|
+
h--, r += n[s++] << o, o += 8;
|
|
1310
|
+
}
|
|
1311
|
+
i.adler = t.check = Kt(r), r = 0, o = 0, t.mode = Q;
|
|
1312
|
+
/* falls through */
|
|
1313
|
+
case Q:
|
|
1314
|
+
if (t.havedict === 0)
|
|
1315
|
+
return i.next_out = l, i.avail_out = _, i.next_in = s, i.avail_in = h, t.hold = r, t.bits = o, di;
|
|
1316
|
+
i.adler = t.check = 1, t.mode = C;
|
|
1317
|
+
/* falls through */
|
|
1318
|
+
case C:
|
|
1319
|
+
if (e === li || e === Y)
|
|
1320
|
+
break t;
|
|
1321
|
+
/* falls through */
|
|
1322
|
+
case nt:
|
|
1323
|
+
if (t.last) {
|
|
1324
|
+
r >>>= o & 7, o -= o & 7, t.mode = at;
|
|
1325
|
+
break;
|
|
1326
|
+
}
|
|
1327
|
+
for (; o < 3; ) {
|
|
1328
|
+
if (h === 0)
|
|
1329
|
+
break t;
|
|
1330
|
+
h--, r += n[s++] << o, o += 8;
|
|
1331
|
+
}
|
|
1332
|
+
switch (t.last = r & 1, r >>>= 1, o -= 1, r & 3) {
|
|
1333
|
+
case 0:
|
|
1334
|
+
t.mode = Dt;
|
|
1335
|
+
break;
|
|
1336
|
+
case 1:
|
|
1337
|
+
if (yi(t), t.mode = X, e === Y) {
|
|
1338
|
+
r >>>= 2, o -= 2;
|
|
1339
|
+
break t;
|
|
1340
|
+
}
|
|
1341
|
+
break;
|
|
1342
|
+
case 2:
|
|
1343
|
+
t.mode = Lt;
|
|
1344
|
+
break;
|
|
1345
|
+
case 3:
|
|
1346
|
+
i.msg = "invalid block type", t.mode = v;
|
|
1347
|
+
}
|
|
1348
|
+
r >>>= 2, o -= 2;
|
|
1349
|
+
break;
|
|
1350
|
+
case Dt:
|
|
1351
|
+
for (r >>>= o & 7, o -= o & 7; o < 32; ) {
|
|
1352
|
+
if (h === 0)
|
|
1353
|
+
break t;
|
|
1354
|
+
h--, r += n[s++] << o, o += 8;
|
|
1355
|
+
}
|
|
1356
|
+
if ((r & 65535) !== (r >>> 16 ^ 65535)) {
|
|
1357
|
+
i.msg = "invalid stored block lengths", t.mode = v;
|
|
1358
|
+
break;
|
|
1359
|
+
}
|
|
1360
|
+
if (t.length = r & 65535, r = 0, o = 0, t.mode = st, e === Y)
|
|
1361
|
+
break t;
|
|
1362
|
+
/* falls through */
|
|
1363
|
+
case st:
|
|
1364
|
+
t.mode = Mt;
|
|
1365
|
+
/* falls through */
|
|
1366
|
+
case Mt:
|
|
1367
|
+
if (f = t.length, f) {
|
|
1368
|
+
if (f > h && (f = h), f > _ && (f = _), f === 0)
|
|
1369
|
+
break t;
|
|
1370
|
+
a.set(n.subarray(s, s + f), l), h -= f, s += f, _ -= f, l += f, t.length -= f;
|
|
1371
|
+
break;
|
|
1372
|
+
}
|
|
1373
|
+
t.mode = C;
|
|
1374
|
+
break;
|
|
1375
|
+
case Lt:
|
|
1376
|
+
for (; o < 14; ) {
|
|
1377
|
+
if (h === 0)
|
|
1378
|
+
break t;
|
|
1379
|
+
h--, r += n[s++] << o, o += 8;
|
|
1380
|
+
}
|
|
1381
|
+
if (t.nlen = (r & 31) + 257, r >>>= 5, o -= 5, t.ndist = (r & 31) + 1, r >>>= 5, o -= 5, t.ncode = (r & 15) + 4, r >>>= 4, o -= 4, t.nlen > 286 || t.ndist > 30) {
|
|
1382
|
+
i.msg = "too many length or distance symbols", t.mode = v;
|
|
1383
|
+
break;
|
|
1384
|
+
}
|
|
1385
|
+
t.have = 0, t.mode = Bt;
|
|
1386
|
+
/* falls through */
|
|
1387
|
+
case Bt:
|
|
1388
|
+
for (; t.have < t.ncode; ) {
|
|
1389
|
+
for (; o < 3; ) {
|
|
1390
|
+
if (h === 0)
|
|
1391
|
+
break t;
|
|
1392
|
+
h--, r += n[s++] << o, o += 8;
|
|
1393
|
+
}
|
|
1394
|
+
t.lens[M[t.have++]] = r & 7, r >>>= 3, o -= 3;
|
|
1395
|
+
}
|
|
1396
|
+
for (; t.have < 19; )
|
|
1397
|
+
t.lens[M[t.have++]] = 0;
|
|
1398
|
+
if (t.lencode = t.lendyn, t.lenbits = 7, b = { bits: t.lenbits }, m = F(fi, t.lens, 0, 19, t.lencode, 0, t.work, b), t.lenbits = b.bits, m) {
|
|
1399
|
+
i.msg = "invalid code lengths set", t.mode = v;
|
|
1400
|
+
break;
|
|
1401
|
+
}
|
|
1402
|
+
t.have = 0, t.mode = $t;
|
|
1403
|
+
/* falls through */
|
|
1404
|
+
case $t:
|
|
1405
|
+
for (; t.have < t.nlen + t.ndist; ) {
|
|
1406
|
+
for (; x = t.lencode[r & (1 << t.lenbits) - 1], g = x >>> 24, T = x >>> 16 & 255, y = x & 65535, !(g <= o); ) {
|
|
1407
|
+
if (h === 0)
|
|
1408
|
+
break t;
|
|
1409
|
+
h--, r += n[s++] << o, o += 8;
|
|
1410
|
+
}
|
|
1411
|
+
if (y < 16)
|
|
1412
|
+
r >>>= g, o -= g, t.lens[t.have++] = y;
|
|
1413
|
+
else {
|
|
1414
|
+
if (y === 16) {
|
|
1415
|
+
for (k = g + 2; o < k; ) {
|
|
1416
|
+
if (h === 0)
|
|
1417
|
+
break t;
|
|
1418
|
+
h--, r += n[s++] << o, o += 8;
|
|
1419
|
+
}
|
|
1420
|
+
if (r >>>= g, o -= g, t.have === 0) {
|
|
1421
|
+
i.msg = "invalid bit length repeat", t.mode = v;
|
|
1422
|
+
break;
|
|
1423
|
+
}
|
|
1424
|
+
p = t.lens[t.have - 1], f = 3 + (r & 3), r >>>= 2, o -= 2;
|
|
1425
|
+
} else if (y === 17) {
|
|
1426
|
+
for (k = g + 3; o < k; ) {
|
|
1427
|
+
if (h === 0)
|
|
1428
|
+
break t;
|
|
1429
|
+
h--, r += n[s++] << o, o += 8;
|
|
1430
|
+
}
|
|
1431
|
+
r >>>= g, o -= g, p = 0, f = 3 + (r & 7), r >>>= 3, o -= 3;
|
|
1432
|
+
} else {
|
|
1433
|
+
for (k = g + 7; o < k; ) {
|
|
1434
|
+
if (h === 0)
|
|
1435
|
+
break t;
|
|
1436
|
+
h--, r += n[s++] << o, o += 8;
|
|
1437
|
+
}
|
|
1438
|
+
r >>>= g, o -= g, p = 0, f = 11 + (r & 127), r >>>= 7, o -= 7;
|
|
1439
|
+
}
|
|
1440
|
+
if (t.have + f > t.nlen + t.ndist) {
|
|
1441
|
+
i.msg = "invalid bit length repeat", t.mode = v;
|
|
1442
|
+
break;
|
|
1443
|
+
}
|
|
1444
|
+
for (; f--; )
|
|
1445
|
+
t.lens[t.have++] = p;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
if (t.mode === v)
|
|
1449
|
+
break;
|
|
1450
|
+
if (t.lens[256] === 0) {
|
|
1451
|
+
i.msg = "invalid code -- missing end-of-block", t.mode = v;
|
|
1452
|
+
break;
|
|
1453
|
+
}
|
|
1454
|
+
if (t.lenbits = 9, b = { bits: t.lenbits }, m = F(oe, t.lens, 0, t.nlen, t.lencode, 0, t.work, b), t.lenbits = b.bits, m) {
|
|
1455
|
+
i.msg = "invalid literal/lengths set", t.mode = v;
|
|
1456
|
+
break;
|
|
1457
|
+
}
|
|
1458
|
+
if (t.distbits = 6, t.distcode = t.distdyn, b = { bits: t.distbits }, m = F(he, t.lens, t.nlen, t.ndist, t.distcode, 0, t.work, b), t.distbits = b.bits, m) {
|
|
1459
|
+
i.msg = "invalid distances set", t.mode = v;
|
|
1460
|
+
break;
|
|
1461
|
+
}
|
|
1462
|
+
if (t.mode = X, e === Y)
|
|
1463
|
+
break t;
|
|
1464
|
+
/* falls through */
|
|
1465
|
+
case X:
|
|
1466
|
+
t.mode = j;
|
|
1467
|
+
/* falls through */
|
|
1468
|
+
case j:
|
|
1469
|
+
if (h >= 6 && _ >= 258) {
|
|
1470
|
+
i.next_out = l, i.avail_out = _, i.next_in = s, i.avail_in = h, t.hold = r, t.bits = o, ni(i, d), l = i.next_out, a = i.output, _ = i.avail_out, s = i.next_in, n = i.input, h = i.avail_in, r = t.hold, o = t.bits, t.mode === C && (t.back = -1);
|
|
1471
|
+
break;
|
|
1472
|
+
}
|
|
1473
|
+
for (t.back = 0; x = t.lencode[r & (1 << t.lenbits) - 1], g = x >>> 24, T = x >>> 16 & 255, y = x & 65535, !(g <= o); ) {
|
|
1474
|
+
if (h === 0)
|
|
1475
|
+
break t;
|
|
1476
|
+
h--, r += n[s++] << o, o += 8;
|
|
1477
|
+
}
|
|
1478
|
+
if (T && (T & 240) === 0) {
|
|
1479
|
+
for (c = g, E = T, S = y; x = t.lencode[S + ((r & (1 << c + E) - 1) >> c)], g = x >>> 24, T = x >>> 16 & 255, y = x & 65535, !(c + g <= o); ) {
|
|
1480
|
+
if (h === 0)
|
|
1481
|
+
break t;
|
|
1482
|
+
h--, r += n[s++] << o, o += 8;
|
|
1483
|
+
}
|
|
1484
|
+
r >>>= c, o -= c, t.back += c;
|
|
1485
|
+
}
|
|
1486
|
+
if (r >>>= g, o -= g, t.back += g, t.length = y, T === 0) {
|
|
1487
|
+
t.mode = zt;
|
|
1488
|
+
break;
|
|
1489
|
+
}
|
|
1490
|
+
if (T & 32) {
|
|
1491
|
+
t.back = -1, t.mode = C;
|
|
1492
|
+
break;
|
|
1493
|
+
}
|
|
1494
|
+
if (T & 64) {
|
|
1495
|
+
i.msg = "invalid literal/length code", t.mode = v;
|
|
1496
|
+
break;
|
|
1497
|
+
}
|
|
1498
|
+
t.extra = T & 15, t.mode = Ht;
|
|
1499
|
+
/* falls through */
|
|
1500
|
+
case Ht:
|
|
1501
|
+
if (t.extra) {
|
|
1502
|
+
for (k = t.extra; o < k; ) {
|
|
1503
|
+
if (h === 0)
|
|
1504
|
+
break t;
|
|
1505
|
+
h--, r += n[s++] << o, o += 8;
|
|
1506
|
+
}
|
|
1507
|
+
t.length += r & (1 << t.extra) - 1, r >>>= t.extra, o -= t.extra, t.back += t.extra;
|
|
1508
|
+
}
|
|
1509
|
+
t.was = t.length, t.mode = Ft;
|
|
1510
|
+
/* falls through */
|
|
1511
|
+
case Ft:
|
|
1512
|
+
for (; x = t.distcode[r & (1 << t.distbits) - 1], g = x >>> 24, T = x >>> 16 & 255, y = x & 65535, !(g <= o); ) {
|
|
1513
|
+
if (h === 0)
|
|
1514
|
+
break t;
|
|
1515
|
+
h--, r += n[s++] << o, o += 8;
|
|
1516
|
+
}
|
|
1517
|
+
if ((T & 240) === 0) {
|
|
1518
|
+
for (c = g, E = T, S = y; x = t.distcode[S + ((r & (1 << c + E) - 1) >> c)], g = x >>> 24, T = x >>> 16 & 255, y = x & 65535, !(c + g <= o); ) {
|
|
1519
|
+
if (h === 0)
|
|
1520
|
+
break t;
|
|
1521
|
+
h--, r += n[s++] << o, o += 8;
|
|
1522
|
+
}
|
|
1523
|
+
r >>>= c, o -= c, t.back += c;
|
|
1524
|
+
}
|
|
1525
|
+
if (r >>>= g, o -= g, t.back += g, T & 64) {
|
|
1526
|
+
i.msg = "invalid distance code", t.mode = v;
|
|
1527
|
+
break;
|
|
1528
|
+
}
|
|
1529
|
+
t.offset = y, t.extra = T & 15, t.mode = Wt;
|
|
1530
|
+
/* falls through */
|
|
1531
|
+
case Wt:
|
|
1532
|
+
if (t.extra) {
|
|
1533
|
+
for (k = t.extra; o < k; ) {
|
|
1534
|
+
if (h === 0)
|
|
1535
|
+
break t;
|
|
1536
|
+
h--, r += n[s++] << o, o += 8;
|
|
1537
|
+
}
|
|
1538
|
+
t.offset += r & (1 << t.extra) - 1, r >>>= t.extra, o -= t.extra, t.back += t.extra;
|
|
1539
|
+
}
|
|
1540
|
+
if (t.offset > t.dmax) {
|
|
1541
|
+
i.msg = "invalid distance too far back", t.mode = v;
|
|
1542
|
+
break;
|
|
1543
|
+
}
|
|
1544
|
+
t.mode = Zt;
|
|
1545
|
+
/* falls through */
|
|
1546
|
+
case Zt:
|
|
1547
|
+
if (_ === 0)
|
|
1548
|
+
break t;
|
|
1549
|
+
if (f = d - _, t.offset > f) {
|
|
1550
|
+
if (f = t.offset - f, f > t.whave && t.sane) {
|
|
1551
|
+
i.msg = "invalid distance too far back", t.mode = v;
|
|
1552
|
+
break;
|
|
1553
|
+
}
|
|
1554
|
+
f > t.wnext ? (f -= t.wnext, u = t.wsize - f) : u = t.wnext - f, f > t.length && (f = t.length), U = t.window;
|
|
1555
|
+
} else
|
|
1556
|
+
U = a, u = l - t.offset, f = t.length;
|
|
1557
|
+
f > _ && (f = _), _ -= f, t.length -= f;
|
|
1558
|
+
do
|
|
1559
|
+
a[l++] = U[u++];
|
|
1560
|
+
while (--f);
|
|
1561
|
+
t.length === 0 && (t.mode = j);
|
|
1562
|
+
break;
|
|
1563
|
+
case zt:
|
|
1564
|
+
if (_ === 0)
|
|
1565
|
+
break t;
|
|
1566
|
+
a[l++] = t.length, _--, t.mode = j;
|
|
1567
|
+
break;
|
|
1568
|
+
case at:
|
|
1569
|
+
if (t.wrap) {
|
|
1570
|
+
for (; o < 32; ) {
|
|
1571
|
+
if (h === 0)
|
|
1572
|
+
break t;
|
|
1573
|
+
h--, r |= n[s++] << o, o += 8;
|
|
1574
|
+
}
|
|
1575
|
+
if (d -= _, i.total_out += d, t.total += d, t.wrap & 4 && d && (i.adler = t.check = /*UPDATE_CHECK(state.check, put - _out, _out);*/
|
|
1576
|
+
t.flags ? R(t.check, a, d, l - d) : ut(t.check, a, d, l - d)), d = _, t.wrap & 4 && (t.flags ? r : Kt(r)) !== t.check) {
|
|
1577
|
+
i.msg = "incorrect data check", t.mode = v;
|
|
1578
|
+
break;
|
|
1579
|
+
}
|
|
1580
|
+
r = 0, o = 0;
|
|
1581
|
+
}
|
|
1582
|
+
t.mode = Pt;
|
|
1583
|
+
/* falls through */
|
|
1584
|
+
case Pt:
|
|
1585
|
+
if (t.wrap && t.flags) {
|
|
1586
|
+
for (; o < 32; ) {
|
|
1587
|
+
if (h === 0)
|
|
1588
|
+
break t;
|
|
1589
|
+
h--, r += n[s++] << o, o += 8;
|
|
1590
|
+
}
|
|
1591
|
+
if (t.wrap & 4 && r !== (t.total & 4294967295)) {
|
|
1592
|
+
i.msg = "incorrect length check", t.mode = v;
|
|
1593
|
+
break;
|
|
1594
|
+
}
|
|
1595
|
+
r = 0, o = 0;
|
|
1596
|
+
}
|
|
1597
|
+
t.mode = Gt;
|
|
1598
|
+
/* falls through */
|
|
1599
|
+
case Gt:
|
|
1600
|
+
m = ci;
|
|
1601
|
+
break t;
|
|
1602
|
+
case v:
|
|
1603
|
+
m = fe;
|
|
1604
|
+
break t;
|
|
1605
|
+
case ce:
|
|
1606
|
+
return le;
|
|
1607
|
+
case de:
|
|
1608
|
+
/* falls through */
|
|
1609
|
+
default:
|
|
1610
|
+
return O;
|
|
1611
|
+
}
|
|
1612
|
+
return i.next_out = l, i.avail_out = _, i.next_in = s, i.avail_in = h, t.hold = r, t.bits = o, (t.wsize || d !== i.avail_out && t.mode < v && (t.mode < at || e !== At)) && ge(i, i.output, i.next_out, d - i.avail_out), w -= i.avail_in, d -= i.avail_out, i.total_in += w, i.total_out += d, t.total += d, t.wrap & 4 && d && (i.adler = t.check = /*UPDATE_CHECK(state.check, strm.next_out - _out, _out);*/
|
|
1613
|
+
t.flags ? R(t.check, a, d, i.next_out - d) : ut(t.check, a, d, i.next_out - d)), i.data_type = t.bits + (t.last ? 64 : 0) + (t.mode === C ? 128 : 0) + (t.mode === X || t.mode === st ? 256 : 0), (w === 0 && d === 0 || e === At) && m === L && (m = ui), m;
|
|
1614
|
+
}, Ei = (i) => {
|
|
1615
|
+
if (B(i))
|
|
1616
|
+
return O;
|
|
1617
|
+
let e = i.state;
|
|
1618
|
+
return e.window && (e.window = null), i.state = null, L;
|
|
1619
|
+
}, Ai = (i, e) => {
|
|
1620
|
+
if (B(i))
|
|
1621
|
+
return O;
|
|
1622
|
+
const t = i.state;
|
|
1623
|
+
return (t.wrap & 2) === 0 ? O : (t.head = e, e.done = !1, L);
|
|
1624
|
+
}, Ti = (i, e) => {
|
|
1625
|
+
const t = e.length;
|
|
1626
|
+
let n, a, s;
|
|
1627
|
+
return B(i) || (n = i.state, n.wrap !== 0 && n.mode !== Q) ? O : n.mode === Q && (a = 1, a = ut(a, e, t, 0), a !== n.check) ? fe : (s = ge(i, e, t, t), s ? (n.mode = ce, le) : (n.havedict = 1, L));
|
|
1628
|
+
};
|
|
1629
|
+
var mi = _e, vi = pe, Ui = ue, Si = xi, Ii = we, Oi = ki, Ri = Ei, Ci = Ai, Ni = Ti, Di = "pako inflate (from Nodeca project)", D = {
|
|
1630
|
+
inflateReset: mi,
|
|
1631
|
+
inflateReset2: vi,
|
|
1632
|
+
inflateResetKeep: Ui,
|
|
1633
|
+
inflateInit: Si,
|
|
1634
|
+
inflateInit2: Ii,
|
|
1635
|
+
inflate: Oi,
|
|
1636
|
+
inflateEnd: Ri,
|
|
1637
|
+
inflateGetHeader: Ci,
|
|
1638
|
+
inflateSetDictionary: Ni,
|
|
1639
|
+
inflateInfo: Di
|
|
1640
|
+
};
|
|
1641
|
+
function Mi() {
|
|
1642
|
+
this.text = 0, this.time = 0, this.xflags = 0, this.os = 0, this.extra = null, this.extra_len = 0, this.name = "", this.comment = "", this.hcrc = 0, this.done = !1;
|
|
1643
|
+
}
|
|
1644
|
+
var Li = Mi;
|
|
1645
|
+
const be = Object.prototype.toString, {
|
|
1646
|
+
Z_NO_FLUSH: Bi,
|
|
1647
|
+
Z_FINISH: $i,
|
|
1648
|
+
Z_OK: Z,
|
|
1649
|
+
Z_STREAM_END: ht,
|
|
1650
|
+
Z_NEED_DICT: ft,
|
|
1651
|
+
Z_STREAM_ERROR: Hi,
|
|
1652
|
+
Z_DATA_ERROR: Xt,
|
|
1653
|
+
Z_MEM_ERROR: Fi
|
|
1654
|
+
} = se;
|
|
1655
|
+
function z(i) {
|
|
1656
|
+
this.options = ae.assign({
|
|
1657
|
+
chunkSize: 1024 * 64,
|
|
1658
|
+
windowBits: 15,
|
|
1659
|
+
to: ""
|
|
1660
|
+
}, i || {});
|
|
1661
|
+
const e = this.options;
|
|
1662
|
+
e.raw && e.windowBits >= 0 && e.windowBits < 16 && (e.windowBits = -e.windowBits, e.windowBits === 0 && (e.windowBits = -15)), e.windowBits >= 0 && e.windowBits < 16 && !(i && i.windowBits) && (e.windowBits += 32), e.windowBits > 15 && e.windowBits < 48 && (e.windowBits & 15) === 0 && (e.windowBits |= 15), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new ei(), this.strm.avail_out = 0;
|
|
1663
|
+
let t = D.inflateInit2(
|
|
1664
|
+
this.strm,
|
|
1665
|
+
e.windowBits
|
|
1666
|
+
);
|
|
1667
|
+
if (t !== Z)
|
|
1668
|
+
throw new Error(_t[t]);
|
|
1669
|
+
if (this.header = new Li(), D.inflateGetHeader(this.strm, this.header), e.dictionary && (typeof e.dictionary == "string" ? e.dictionary = pt.string2buf(e.dictionary) : be.call(e.dictionary) === "[object ArrayBuffer]" && (e.dictionary = new Uint8Array(e.dictionary)), e.raw && (t = D.inflateSetDictionary(this.strm, e.dictionary), t !== Z)))
|
|
1670
|
+
throw new Error(_t[t]);
|
|
1671
|
+
}
|
|
1672
|
+
z.prototype.push = function(i, e) {
|
|
1673
|
+
const t = this.strm, n = this.options.chunkSize, a = this.options.dictionary;
|
|
1674
|
+
let s, l, h;
|
|
1675
|
+
if (this.ended) return !1;
|
|
1676
|
+
for (e === ~~e ? l = e : l = e === !0 ? $i : Bi, be.call(i) === "[object ArrayBuffer]" ? t.input = new Uint8Array(i) : t.input = i, t.next_in = 0, t.avail_in = t.input.length; ; ) {
|
|
1677
|
+
for (t.avail_out === 0 && (t.output = new Uint8Array(n), t.next_out = 0, t.avail_out = n), s = D.inflate(t, l), s === ft && a && (s = D.inflateSetDictionary(t, a), s === Z ? s = D.inflate(t, l) : s === Xt && (s = ft)); t.avail_in > 0 && s === ht && t.state.wrap > 0 && i[t.next_in] !== 0; )
|
|
1678
|
+
D.inflateReset(t), s = D.inflate(t, l);
|
|
1679
|
+
switch (s) {
|
|
1680
|
+
case Hi:
|
|
1681
|
+
case Xt:
|
|
1682
|
+
case ft:
|
|
1683
|
+
case Fi:
|
|
1684
|
+
return this.onEnd(s), this.ended = !0, !1;
|
|
1685
|
+
}
|
|
1686
|
+
if (h = t.avail_out, t.next_out && (t.avail_out === 0 || s === ht))
|
|
1687
|
+
if (this.options.to === "string") {
|
|
1688
|
+
let _ = pt.utf8border(t.output, t.next_out), r = t.next_out - _, o = pt.buf2string(t.output, _);
|
|
1689
|
+
t.next_out = r, t.avail_out = n - r, r && t.output.set(t.output.subarray(_, _ + r), 0), this.onData(o);
|
|
1690
|
+
} else
|
|
1691
|
+
this.onData(t.output.length === t.next_out ? t.output : t.output.subarray(0, t.next_out));
|
|
1692
|
+
if (!(s === Z && h === 0)) {
|
|
1693
|
+
if (s === ht)
|
|
1694
|
+
return s = D.inflateEnd(this.strm), this.onEnd(s), this.ended = !0, !0;
|
|
1695
|
+
if (t.avail_in === 0) break;
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
return !0;
|
|
1699
|
+
};
|
|
1700
|
+
z.prototype.onData = function(i) {
|
|
1701
|
+
this.chunks.push(i);
|
|
1702
|
+
};
|
|
1703
|
+
z.prototype.onEnd = function(i) {
|
|
1704
|
+
i === Z && (this.options.to === "string" ? this.result = this.chunks.join("") : this.result = ae.flattenChunks(this.chunks)), this.chunks = [], this.err = i, this.msg = this.strm.msg;
|
|
1705
|
+
};
|
|
1706
|
+
function Wi(i, e) {
|
|
1707
|
+
const t = new z(e);
|
|
1708
|
+
if (t.push(i), t.err) throw t.msg || _t[t.err];
|
|
1709
|
+
return t.result;
|
|
1710
|
+
}
|
|
1711
|
+
var Zi = z, zi = Wi, Pi = {
|
|
1712
|
+
Inflate: Zi,
|
|
1713
|
+
inflate: zi
|
|
1714
|
+
};
|
|
1715
|
+
const { Inflate: Gi, inflate: Ki } = Pi;
|
|
1716
|
+
var jt = Gi, Yi = Ki;
|
|
1717
|
+
const xe = [];
|
|
1718
|
+
for (let i = 0; i < 256; i++) {
|
|
1719
|
+
let e = i;
|
|
1720
|
+
for (let t = 0; t < 8; t++)
|
|
1721
|
+
e & 1 ? e = 3988292384 ^ e >>> 1 : e = e >>> 1;
|
|
1722
|
+
xe[i] = e;
|
|
1723
|
+
}
|
|
1724
|
+
const Vt = 4294967295;
|
|
1725
|
+
function Xi(i, e, t) {
|
|
1726
|
+
let n = i;
|
|
1727
|
+
for (let a = 0; a < t; a++)
|
|
1728
|
+
n = xe[(n ^ e[a]) & 255] ^ n >>> 8;
|
|
1729
|
+
return n;
|
|
1730
|
+
}
|
|
1731
|
+
function ji(i, e) {
|
|
1732
|
+
return (Xi(Vt, i, e) ^ Vt) >>> 0;
|
|
1733
|
+
}
|
|
1734
|
+
function qt(i, e, t) {
|
|
1735
|
+
const n = i.readUint32(), a = ji(new Uint8Array(i.buffer, i.byteOffset + i.offset - e - 4, e), e);
|
|
1736
|
+
if (a !== n)
|
|
1737
|
+
throw new Error(`CRC mismatch for chunk ${t}. Expected ${n}, found ${a}`);
|
|
1738
|
+
}
|
|
1739
|
+
function ye(i, e, t) {
|
|
1740
|
+
for (let n = 0; n < t; n++)
|
|
1741
|
+
e[n] = i[n];
|
|
1742
|
+
}
|
|
1743
|
+
function ke(i, e, t, n) {
|
|
1744
|
+
let a = 0;
|
|
1745
|
+
for (; a < n; a++)
|
|
1746
|
+
e[a] = i[a];
|
|
1747
|
+
for (; a < t; a++)
|
|
1748
|
+
e[a] = i[a] + e[a - n] & 255;
|
|
1749
|
+
}
|
|
1750
|
+
function Ee(i, e, t, n) {
|
|
1751
|
+
let a = 0;
|
|
1752
|
+
if (t.length === 0)
|
|
1753
|
+
for (; a < n; a++)
|
|
1754
|
+
e[a] = i[a];
|
|
1755
|
+
else
|
|
1756
|
+
for (; a < n; a++)
|
|
1757
|
+
e[a] = i[a] + t[a] & 255;
|
|
1758
|
+
}
|
|
1759
|
+
function Ae(i, e, t, n, a) {
|
|
1760
|
+
let s = 0;
|
|
1761
|
+
if (t.length === 0) {
|
|
1762
|
+
for (; s < a; s++)
|
|
1763
|
+
e[s] = i[s];
|
|
1764
|
+
for (; s < n; s++)
|
|
1765
|
+
e[s] = i[s] + (e[s - a] >> 1) & 255;
|
|
1766
|
+
} else {
|
|
1767
|
+
for (; s < a; s++)
|
|
1768
|
+
e[s] = i[s] + (t[s] >> 1) & 255;
|
|
1769
|
+
for (; s < n; s++)
|
|
1770
|
+
e[s] = i[s] + (e[s - a] + t[s] >> 1) & 255;
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
function Te(i, e, t, n, a) {
|
|
1774
|
+
let s = 0;
|
|
1775
|
+
if (t.length === 0) {
|
|
1776
|
+
for (; s < a; s++)
|
|
1777
|
+
e[s] = i[s];
|
|
1778
|
+
for (; s < n; s++)
|
|
1779
|
+
e[s] = i[s] + e[s - a] & 255;
|
|
1780
|
+
} else {
|
|
1781
|
+
for (; s < a; s++)
|
|
1782
|
+
e[s] = i[s] + t[s] & 255;
|
|
1783
|
+
for (; s < n; s++)
|
|
1784
|
+
e[s] = i[s] + Vi(e[s - a], t[s], t[s - a]) & 255;
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
function Vi(i, e, t) {
|
|
1788
|
+
const n = i + e - t, a = Math.abs(n - i), s = Math.abs(n - e), l = Math.abs(n - t);
|
|
1789
|
+
return a <= s && a <= l ? i : s <= l ? e : t;
|
|
1790
|
+
}
|
|
1791
|
+
function qi(i, e, t, n, a, s) {
|
|
1792
|
+
switch (i) {
|
|
1793
|
+
case 0:
|
|
1794
|
+
ye(e, t, a);
|
|
1795
|
+
break;
|
|
1796
|
+
case 1:
|
|
1797
|
+
ke(e, t, a, s);
|
|
1798
|
+
break;
|
|
1799
|
+
case 2:
|
|
1800
|
+
Ee(e, t, n, a);
|
|
1801
|
+
break;
|
|
1802
|
+
case 3:
|
|
1803
|
+
Ae(e, t, n, a, s);
|
|
1804
|
+
break;
|
|
1805
|
+
case 4:
|
|
1806
|
+
Te(e, t, n, a, s);
|
|
1807
|
+
break;
|
|
1808
|
+
default:
|
|
1809
|
+
throw new Error(`Unsupported filter: ${i}`);
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
const Ji = new Uint16Array([255]), Qi = new Uint8Array(Ji.buffer), tn = Qi[0] === 255;
|
|
1813
|
+
function en(i) {
|
|
1814
|
+
const { data: e, width: t, height: n, channels: a, depth: s } = i, l = [
|
|
1815
|
+
{ x: 0, y: 0, xStep: 8, yStep: 8 },
|
|
1816
|
+
// Pass 1
|
|
1817
|
+
{ x: 4, y: 0, xStep: 8, yStep: 8 },
|
|
1818
|
+
// Pass 2
|
|
1819
|
+
{ x: 0, y: 4, xStep: 4, yStep: 8 },
|
|
1820
|
+
// Pass 3
|
|
1821
|
+
{ x: 2, y: 0, xStep: 4, yStep: 4 },
|
|
1822
|
+
// Pass 4
|
|
1823
|
+
{ x: 0, y: 2, xStep: 2, yStep: 4 },
|
|
1824
|
+
// Pass 5
|
|
1825
|
+
{ x: 1, y: 0, xStep: 2, yStep: 2 },
|
|
1826
|
+
// Pass 6
|
|
1827
|
+
{ x: 0, y: 1, xStep: 1, yStep: 2 }
|
|
1828
|
+
// Pass 7
|
|
1829
|
+
], h = Math.ceil(s / 8) * a, _ = new Uint8Array(n * t * h);
|
|
1830
|
+
let r = 0;
|
|
1831
|
+
for (let o = 0; o < 7; o++) {
|
|
1832
|
+
const w = l[o], d = Math.ceil((t - w.x) / w.xStep), f = Math.ceil((n - w.y) / w.yStep);
|
|
1833
|
+
if (d <= 0 || f <= 0)
|
|
1834
|
+
continue;
|
|
1835
|
+
const u = d * h, U = new Uint8Array(u);
|
|
1836
|
+
for (let x = 0; x < f; x++) {
|
|
1837
|
+
const g = e[r++], T = e.subarray(r, r + u);
|
|
1838
|
+
r += u;
|
|
1839
|
+
const y = new Uint8Array(u);
|
|
1840
|
+
qi(g, T, y, U, u, h), U.set(y);
|
|
1841
|
+
for (let c = 0; c < d; c++) {
|
|
1842
|
+
const E = w.x + c * w.xStep, S = w.y + x * w.yStep;
|
|
1843
|
+
if (!(E >= t || S >= n))
|
|
1844
|
+
for (let p = 0; p < h; p++)
|
|
1845
|
+
_[(S * t + E) * h + p] = y[c * h + p];
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
if (s === 16) {
|
|
1850
|
+
const o = new Uint16Array(_.buffer);
|
|
1851
|
+
if (tn)
|
|
1852
|
+
for (let w = 0; w < o.length; w++)
|
|
1853
|
+
o[w] = nn(o[w]);
|
|
1854
|
+
return o;
|
|
1855
|
+
} else
|
|
1856
|
+
return _;
|
|
1857
|
+
}
|
|
1858
|
+
function nn(i) {
|
|
1859
|
+
return (i & 255) << 8 | i >> 8 & 255;
|
|
1860
|
+
}
|
|
1861
|
+
const sn = new Uint16Array([255]), an = new Uint8Array(sn.buffer), rn = an[0] === 255, on = new Uint8Array(0);
|
|
1862
|
+
function Jt(i) {
|
|
1863
|
+
const { data: e, width: t, height: n, channels: a, depth: s } = i, l = Math.ceil(s / 8) * a, h = Math.ceil(s / 8 * a * t), _ = new Uint8Array(n * h);
|
|
1864
|
+
let r = on, o = 0, w, d;
|
|
1865
|
+
for (let f = 0; f < n; f++) {
|
|
1866
|
+
switch (w = e.subarray(o + 1, o + 1 + h), d = _.subarray(f * h, (f + 1) * h), e[o]) {
|
|
1867
|
+
case 0:
|
|
1868
|
+
ye(w, d, h);
|
|
1869
|
+
break;
|
|
1870
|
+
case 1:
|
|
1871
|
+
ke(w, d, h, l);
|
|
1872
|
+
break;
|
|
1873
|
+
case 2:
|
|
1874
|
+
Ee(w, d, r, h);
|
|
1875
|
+
break;
|
|
1876
|
+
case 3:
|
|
1877
|
+
Ae(w, d, r, h, l);
|
|
1878
|
+
break;
|
|
1879
|
+
case 4:
|
|
1880
|
+
Te(w, d, r, h, l);
|
|
1881
|
+
break;
|
|
1882
|
+
default:
|
|
1883
|
+
throw new Error(`Unsupported filter: ${e[o]}`);
|
|
1884
|
+
}
|
|
1885
|
+
r = d, o += h + 1;
|
|
1886
|
+
}
|
|
1887
|
+
if (s === 16) {
|
|
1888
|
+
const f = new Uint16Array(_.buffer);
|
|
1889
|
+
if (rn)
|
|
1890
|
+
for (let u = 0; u < f.length; u++)
|
|
1891
|
+
f[u] = hn(f[u]);
|
|
1892
|
+
return f;
|
|
1893
|
+
} else
|
|
1894
|
+
return _;
|
|
1895
|
+
}
|
|
1896
|
+
function hn(i) {
|
|
1897
|
+
return (i & 255) << 8 | i >> 8 & 255;
|
|
1898
|
+
}
|
|
1899
|
+
const J = Uint8Array.of(137, 80, 78, 71, 13, 10, 26, 10);
|
|
1900
|
+
function Qt(i) {
|
|
1901
|
+
if (!fn(i.readBytes(J.length)))
|
|
1902
|
+
throw new Error("wrong PNG signature");
|
|
1903
|
+
}
|
|
1904
|
+
function fn(i) {
|
|
1905
|
+
if (i.length < J.length)
|
|
1906
|
+
return !1;
|
|
1907
|
+
for (let e = 0; e < J.length; e++)
|
|
1908
|
+
if (i[e] !== J[e])
|
|
1909
|
+
return !1;
|
|
1910
|
+
return !0;
|
|
1911
|
+
}
|
|
1912
|
+
const ln = "tEXt", cn = 0, me = new TextDecoder("latin1");
|
|
1913
|
+
function dn(i) {
|
|
1914
|
+
if (_n(i), i.length === 0 || i.length > 79)
|
|
1915
|
+
throw new Error("keyword length must be between 1 and 79");
|
|
1916
|
+
}
|
|
1917
|
+
const un = /^[\u0000-\u00FF]*$/;
|
|
1918
|
+
function _n(i) {
|
|
1919
|
+
if (!un.test(i))
|
|
1920
|
+
throw new Error("invalid latin1 text");
|
|
1921
|
+
}
|
|
1922
|
+
function pn(i, e, t) {
|
|
1923
|
+
const n = ve(e);
|
|
1924
|
+
i[n] = wn(e, t - n.length - 1);
|
|
1925
|
+
}
|
|
1926
|
+
function ve(i) {
|
|
1927
|
+
for (i.mark(); i.readByte() !== cn; )
|
|
1928
|
+
;
|
|
1929
|
+
const e = i.offset;
|
|
1930
|
+
i.reset();
|
|
1931
|
+
const t = me.decode(i.readBytes(e - i.offset - 1));
|
|
1932
|
+
return i.skip(1), dn(t), t;
|
|
1933
|
+
}
|
|
1934
|
+
function wn(i, e) {
|
|
1935
|
+
return me.decode(i.readBytes(e));
|
|
1936
|
+
}
|
|
1937
|
+
const I = {
|
|
1938
|
+
UNKNOWN: -1,
|
|
1939
|
+
GREYSCALE: 0,
|
|
1940
|
+
TRUECOLOUR: 2,
|
|
1941
|
+
INDEXED_COLOUR: 3,
|
|
1942
|
+
GREYSCALE_ALPHA: 4,
|
|
1943
|
+
TRUECOLOUR_ALPHA: 6
|
|
1944
|
+
}, lt = {
|
|
1945
|
+
UNKNOWN: -1,
|
|
1946
|
+
DEFLATE: 0
|
|
1947
|
+
}, te = {
|
|
1948
|
+
UNKNOWN: -1,
|
|
1949
|
+
ADAPTIVE: 0
|
|
1950
|
+
}, ct = {
|
|
1951
|
+
UNKNOWN: -1,
|
|
1952
|
+
NO_INTERLACE: 0,
|
|
1953
|
+
ADAM7: 1
|
|
1954
|
+
}, V = {
|
|
1955
|
+
NONE: 0,
|
|
1956
|
+
BACKGROUND: 1,
|
|
1957
|
+
PREVIOUS: 2
|
|
1958
|
+
}, dt = {
|
|
1959
|
+
SOURCE: 0,
|
|
1960
|
+
OVER: 1
|
|
1961
|
+
};
|
|
1962
|
+
class gn extends wt {
|
|
1963
|
+
_checkCrc;
|
|
1964
|
+
_inflator;
|
|
1965
|
+
_png;
|
|
1966
|
+
_apng;
|
|
1967
|
+
_end;
|
|
1968
|
+
_hasPalette;
|
|
1969
|
+
_palette;
|
|
1970
|
+
_hasTransparency;
|
|
1971
|
+
_transparency;
|
|
1972
|
+
_compressionMethod;
|
|
1973
|
+
_filterMethod;
|
|
1974
|
+
_interlaceMethod;
|
|
1975
|
+
_colorType;
|
|
1976
|
+
_isAnimated;
|
|
1977
|
+
_numberOfFrames;
|
|
1978
|
+
_numberOfPlays;
|
|
1979
|
+
_frames;
|
|
1980
|
+
_writingDataChunks;
|
|
1981
|
+
constructor(e, t = {}) {
|
|
1982
|
+
super(e);
|
|
1983
|
+
const { checkCrc: n = !1 } = t;
|
|
1984
|
+
this._checkCrc = n, this._inflator = new jt(), this._png = {
|
|
1985
|
+
width: -1,
|
|
1986
|
+
height: -1,
|
|
1987
|
+
channels: -1,
|
|
1988
|
+
data: new Uint8Array(0),
|
|
1989
|
+
depth: 1,
|
|
1990
|
+
text: {}
|
|
1991
|
+
}, this._apng = {
|
|
1992
|
+
width: -1,
|
|
1993
|
+
height: -1,
|
|
1994
|
+
channels: -1,
|
|
1995
|
+
depth: 1,
|
|
1996
|
+
numberOfFrames: 1,
|
|
1997
|
+
numberOfPlays: 0,
|
|
1998
|
+
text: {},
|
|
1999
|
+
frames: []
|
|
2000
|
+
}, this._end = !1, this._hasPalette = !1, this._palette = [], this._hasTransparency = !1, this._transparency = new Uint16Array(0), this._compressionMethod = lt.UNKNOWN, this._filterMethod = te.UNKNOWN, this._interlaceMethod = ct.UNKNOWN, this._colorType = I.UNKNOWN, this._isAnimated = !1, this._numberOfFrames = 1, this._numberOfPlays = 0, this._frames = [], this._writingDataChunks = !1, this.setBigEndian();
|
|
2001
|
+
}
|
|
2002
|
+
decode() {
|
|
2003
|
+
for (Qt(this); !this._end; ) {
|
|
2004
|
+
const e = this.readUint32(), t = this.readChars(4);
|
|
2005
|
+
this.decodeChunk(e, t);
|
|
2006
|
+
}
|
|
2007
|
+
return this.decodeImage(), this._png;
|
|
2008
|
+
}
|
|
2009
|
+
decodeApng() {
|
|
2010
|
+
for (Qt(this); !this._end; ) {
|
|
2011
|
+
const e = this.readUint32(), t = this.readChars(4);
|
|
2012
|
+
this.decodeApngChunk(e, t);
|
|
2013
|
+
}
|
|
2014
|
+
return this.decodeApngImage(), this._apng;
|
|
2015
|
+
}
|
|
2016
|
+
// https://www.w3.org/TR/PNG/#5Chunk-layout
|
|
2017
|
+
decodeChunk(e, t) {
|
|
2018
|
+
const n = this.offset;
|
|
2019
|
+
switch (t) {
|
|
2020
|
+
// 11.2 Critical chunks
|
|
2021
|
+
case "IHDR":
|
|
2022
|
+
this.decodeIHDR();
|
|
2023
|
+
break;
|
|
2024
|
+
case "PLTE":
|
|
2025
|
+
this.decodePLTE(e);
|
|
2026
|
+
break;
|
|
2027
|
+
case "IDAT":
|
|
2028
|
+
this.decodeIDAT(e);
|
|
2029
|
+
break;
|
|
2030
|
+
case "IEND":
|
|
2031
|
+
this._end = !0;
|
|
2032
|
+
break;
|
|
2033
|
+
// 11.3 Ancillary chunks
|
|
2034
|
+
case "tRNS":
|
|
2035
|
+
this.decodetRNS(e);
|
|
2036
|
+
break;
|
|
2037
|
+
case "iCCP":
|
|
2038
|
+
this.decodeiCCP(e);
|
|
2039
|
+
break;
|
|
2040
|
+
case ln:
|
|
2041
|
+
pn(this._png.text, this, e);
|
|
2042
|
+
break;
|
|
2043
|
+
case "pHYs":
|
|
2044
|
+
this.decodepHYs();
|
|
2045
|
+
break;
|
|
2046
|
+
default:
|
|
2047
|
+
this.skip(e);
|
|
2048
|
+
break;
|
|
2049
|
+
}
|
|
2050
|
+
if (this.offset - n !== e)
|
|
2051
|
+
throw new Error(`Length mismatch while decoding chunk ${t}`);
|
|
2052
|
+
this._checkCrc ? qt(this, e + 4, t) : this.skip(4);
|
|
2053
|
+
}
|
|
2054
|
+
decodeApngChunk(e, t) {
|
|
2055
|
+
const n = this.offset;
|
|
2056
|
+
switch (t !== "fdAT" && t !== "IDAT" && this._writingDataChunks && this.pushDataToFrame(), t) {
|
|
2057
|
+
case "acTL":
|
|
2058
|
+
this.decodeACTL();
|
|
2059
|
+
break;
|
|
2060
|
+
case "fcTL":
|
|
2061
|
+
this.decodeFCTL();
|
|
2062
|
+
break;
|
|
2063
|
+
case "fdAT":
|
|
2064
|
+
this.decodeFDAT(e);
|
|
2065
|
+
break;
|
|
2066
|
+
default:
|
|
2067
|
+
this.decodeChunk(e, t), this.offset = n + e;
|
|
2068
|
+
break;
|
|
2069
|
+
}
|
|
2070
|
+
if (this.offset - n !== e)
|
|
2071
|
+
throw new Error(`Length mismatch while decoding chunk ${t}`);
|
|
2072
|
+
this._checkCrc ? qt(this, e + 4, t) : this.skip(4);
|
|
2073
|
+
}
|
|
2074
|
+
// https://www.w3.org/TR/PNG/#11IHDR
|
|
2075
|
+
decodeIHDR() {
|
|
2076
|
+
const e = this._png;
|
|
2077
|
+
e.width = this.readUint32(), e.height = this.readUint32(), e.depth = bn(this.readUint8());
|
|
2078
|
+
const t = this.readUint8();
|
|
2079
|
+
this._colorType = t;
|
|
2080
|
+
let n;
|
|
2081
|
+
switch (t) {
|
|
2082
|
+
case I.GREYSCALE:
|
|
2083
|
+
n = 1;
|
|
2084
|
+
break;
|
|
2085
|
+
case I.TRUECOLOUR:
|
|
2086
|
+
n = 3;
|
|
2087
|
+
break;
|
|
2088
|
+
case I.INDEXED_COLOUR:
|
|
2089
|
+
n = 1;
|
|
2090
|
+
break;
|
|
2091
|
+
case I.GREYSCALE_ALPHA:
|
|
2092
|
+
n = 2;
|
|
2093
|
+
break;
|
|
2094
|
+
case I.TRUECOLOUR_ALPHA:
|
|
2095
|
+
n = 4;
|
|
2096
|
+
break;
|
|
2097
|
+
// Kept for exhaustiveness.
|
|
2098
|
+
// eslint-disable-next-line unicorn/no-useless-switch-case
|
|
2099
|
+
case I.UNKNOWN:
|
|
2100
|
+
default:
|
|
2101
|
+
throw new Error(`Unknown color type: ${t}`);
|
|
2102
|
+
}
|
|
2103
|
+
if (this._png.channels = n, this._compressionMethod = this.readUint8(), this._compressionMethod !== lt.DEFLATE)
|
|
2104
|
+
throw new Error(`Unsupported compression method: ${this._compressionMethod}`);
|
|
2105
|
+
this._filterMethod = this.readUint8(), this._interlaceMethod = this.readUint8();
|
|
2106
|
+
}
|
|
2107
|
+
decodeACTL() {
|
|
2108
|
+
this._numberOfFrames = this.readUint32(), this._numberOfPlays = this.readUint32(), this._isAnimated = !0;
|
|
2109
|
+
}
|
|
2110
|
+
decodeFCTL() {
|
|
2111
|
+
const e = {
|
|
2112
|
+
sequenceNumber: this.readUint32(),
|
|
2113
|
+
width: this.readUint32(),
|
|
2114
|
+
height: this.readUint32(),
|
|
2115
|
+
xOffset: this.readUint32(),
|
|
2116
|
+
yOffset: this.readUint32(),
|
|
2117
|
+
delayNumber: this.readUint16(),
|
|
2118
|
+
delayDenominator: this.readUint16(),
|
|
2119
|
+
disposeOp: this.readUint8(),
|
|
2120
|
+
blendOp: this.readUint8(),
|
|
2121
|
+
data: new Uint8Array(0)
|
|
2122
|
+
};
|
|
2123
|
+
this._frames.push(e);
|
|
2124
|
+
}
|
|
2125
|
+
// https://www.w3.org/TR/PNG/#11PLTE
|
|
2126
|
+
decodePLTE(e) {
|
|
2127
|
+
if (e % 3 !== 0)
|
|
2128
|
+
throw new RangeError(`PLTE field length must be a multiple of 3. Got ${e}`);
|
|
2129
|
+
const t = e / 3;
|
|
2130
|
+
this._hasPalette = !0;
|
|
2131
|
+
const n = [];
|
|
2132
|
+
this._palette = n;
|
|
2133
|
+
for (let a = 0; a < t; a++)
|
|
2134
|
+
n.push([this.readUint8(), this.readUint8(), this.readUint8()]);
|
|
2135
|
+
}
|
|
2136
|
+
// https://www.w3.org/TR/PNG/#11IDAT
|
|
2137
|
+
decodeIDAT(e) {
|
|
2138
|
+
this._writingDataChunks = !0;
|
|
2139
|
+
const t = e, n = this.offset + this.byteOffset;
|
|
2140
|
+
if (this._inflator.push(new Uint8Array(this.buffer, n, t)), this._inflator.err)
|
|
2141
|
+
throw new Error(`Error while decompressing the data: ${this._inflator.err}`);
|
|
2142
|
+
this.skip(e);
|
|
2143
|
+
}
|
|
2144
|
+
decodeFDAT(e) {
|
|
2145
|
+
this._writingDataChunks = !0;
|
|
2146
|
+
let t = e, n = this.offset + this.byteOffset;
|
|
2147
|
+
if (n += 4, t -= 4, this._inflator.push(new Uint8Array(this.buffer, n, t)), this._inflator.err)
|
|
2148
|
+
throw new Error(`Error while decompressing the data: ${this._inflator.err}`);
|
|
2149
|
+
this.skip(e);
|
|
2150
|
+
}
|
|
2151
|
+
// https://www.w3.org/TR/PNG/#11tRNS
|
|
2152
|
+
decodetRNS(e) {
|
|
2153
|
+
switch (this._colorType) {
|
|
2154
|
+
case I.GREYSCALE:
|
|
2155
|
+
case I.TRUECOLOUR: {
|
|
2156
|
+
if (e % 2 !== 0)
|
|
2157
|
+
throw new RangeError(`tRNS chunk length must be a multiple of 2. Got ${e}`);
|
|
2158
|
+
if (e / 2 > this._png.width * this._png.height)
|
|
2159
|
+
throw new Error(`tRNS chunk contains more alpha values than there are pixels (${e / 2} vs ${this._png.width * this._png.height})`);
|
|
2160
|
+
this._hasTransparency = !0, this._transparency = new Uint16Array(e / 2);
|
|
2161
|
+
for (let t = 0; t < e / 2; t++)
|
|
2162
|
+
this._transparency[t] = this.readUint16();
|
|
2163
|
+
break;
|
|
2164
|
+
}
|
|
2165
|
+
case I.INDEXED_COLOUR: {
|
|
2166
|
+
if (e > this._palette.length)
|
|
2167
|
+
throw new Error(`tRNS chunk contains more alpha values than there are palette colors (${e} vs ${this._palette.length})`);
|
|
2168
|
+
let t = 0;
|
|
2169
|
+
for (; t < e; t++) {
|
|
2170
|
+
const n = this.readByte();
|
|
2171
|
+
this._palette[t].push(n);
|
|
2172
|
+
}
|
|
2173
|
+
for (; t < this._palette.length; t++)
|
|
2174
|
+
this._palette[t].push(255);
|
|
2175
|
+
break;
|
|
2176
|
+
}
|
|
2177
|
+
// Kept for exhaustiveness.
|
|
2178
|
+
/* eslint-disable unicorn/no-useless-switch-case */
|
|
2179
|
+
case I.UNKNOWN:
|
|
2180
|
+
case I.GREYSCALE_ALPHA:
|
|
2181
|
+
case I.TRUECOLOUR_ALPHA:
|
|
2182
|
+
default:
|
|
2183
|
+
throw new Error(`tRNS chunk is not supported for color type ${this._colorType}`);
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
// https://www.w3.org/TR/PNG/#11iCCP
|
|
2187
|
+
decodeiCCP(e) {
|
|
2188
|
+
const t = ve(this), n = this.readUint8();
|
|
2189
|
+
if (n !== lt.DEFLATE)
|
|
2190
|
+
throw new Error(`Unsupported iCCP compression method: ${n}`);
|
|
2191
|
+
const a = this.readBytes(e - t.length - 2);
|
|
2192
|
+
this._png.iccEmbeddedProfile = {
|
|
2193
|
+
name: t,
|
|
2194
|
+
profile: Yi(a)
|
|
2195
|
+
};
|
|
2196
|
+
}
|
|
2197
|
+
// https://www.w3.org/TR/PNG/#11pHYs
|
|
2198
|
+
decodepHYs() {
|
|
2199
|
+
const e = this.readUint32(), t = this.readUint32(), n = this.readByte();
|
|
2200
|
+
this._png.resolution = {
|
|
2201
|
+
x: e,
|
|
2202
|
+
y: t,
|
|
2203
|
+
unit: n
|
|
2204
|
+
};
|
|
2205
|
+
}
|
|
2206
|
+
decodeApngImage() {
|
|
2207
|
+
this._apng.width = this._png.width, this._apng.height = this._png.height, this._apng.channels = this._png.channels, this._apng.depth = this._png.depth, this._apng.numberOfFrames = this._numberOfFrames, this._apng.numberOfPlays = this._numberOfPlays, this._apng.text = this._png.text, this._apng.resolution = this._png.resolution;
|
|
2208
|
+
for (let e = 0; e < this._numberOfFrames; e++) {
|
|
2209
|
+
const t = {
|
|
2210
|
+
sequenceNumber: this._frames[e].sequenceNumber,
|
|
2211
|
+
delayNumber: this._frames[e].delayNumber,
|
|
2212
|
+
delayDenominator: this._frames[e].delayDenominator,
|
|
2213
|
+
data: this._apng.depth === 8 ? new Uint8Array(this._apng.width * this._apng.height * this._apng.channels) : new Uint16Array(this._apng.width * this._apng.height * this._apng.channels)
|
|
2214
|
+
}, n = this._frames.at(e);
|
|
2215
|
+
if (n) {
|
|
2216
|
+
if (n.data = Jt({
|
|
2217
|
+
data: n.data,
|
|
2218
|
+
width: n.width,
|
|
2219
|
+
height: n.height,
|
|
2220
|
+
channels: this._apng.channels,
|
|
2221
|
+
depth: this._apng.depth
|
|
2222
|
+
}), this._hasPalette && (this._apng.palette = this._palette), this._hasTransparency && (this._apng.transparency = this._transparency), e === 0 || n.xOffset === 0 && n.yOffset === 0 && n.width === this._png.width && n.height === this._png.height)
|
|
2223
|
+
t.data = n.data;
|
|
2224
|
+
else {
|
|
2225
|
+
const a = this._apng.frames.at(e - 1);
|
|
2226
|
+
this.disposeFrame(n, a, t), this.addFrameDataToCanvas(t, n);
|
|
2227
|
+
}
|
|
2228
|
+
this._apng.frames.push(t);
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
2231
|
+
return this._apng;
|
|
2232
|
+
}
|
|
2233
|
+
disposeFrame(e, t, n) {
|
|
2234
|
+
switch (e.disposeOp) {
|
|
2235
|
+
case V.NONE:
|
|
2236
|
+
break;
|
|
2237
|
+
case V.BACKGROUND:
|
|
2238
|
+
for (let a = 0; a < this._png.height; a++)
|
|
2239
|
+
for (let s = 0; s < this._png.width; s++) {
|
|
2240
|
+
const l = (a * e.width + s) * this._png.channels;
|
|
2241
|
+
for (let h = 0; h < this._png.channels; h++)
|
|
2242
|
+
n.data[l + h] = 0;
|
|
2243
|
+
}
|
|
2244
|
+
break;
|
|
2245
|
+
case V.PREVIOUS:
|
|
2246
|
+
n.data.set(t.data);
|
|
2247
|
+
break;
|
|
2248
|
+
default:
|
|
2249
|
+
throw new Error("Unknown disposeOp");
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
addFrameDataToCanvas(e, t) {
|
|
2253
|
+
const n = 1 << this._png.depth, a = (s, l) => {
|
|
2254
|
+
const h = ((s + t.yOffset) * this._png.width + t.xOffset + l) * this._png.channels, _ = (s * t.width + l) * this._png.channels;
|
|
2255
|
+
return { index: h, frameIndex: _ };
|
|
2256
|
+
};
|
|
2257
|
+
switch (t.blendOp) {
|
|
2258
|
+
case dt.SOURCE:
|
|
2259
|
+
for (let s = 0; s < t.height; s++)
|
|
2260
|
+
for (let l = 0; l < t.width; l++) {
|
|
2261
|
+
const { index: h, frameIndex: _ } = a(s, l);
|
|
2262
|
+
for (let r = 0; r < this._png.channels; r++)
|
|
2263
|
+
e.data[h + r] = t.data[_ + r];
|
|
2264
|
+
}
|
|
2265
|
+
break;
|
|
2266
|
+
// https://www.w3.org/TR/png-3/#13Alpha-channel-processing
|
|
2267
|
+
case dt.OVER:
|
|
2268
|
+
for (let s = 0; s < t.height; s++)
|
|
2269
|
+
for (let l = 0; l < t.width; l++) {
|
|
2270
|
+
const { index: h, frameIndex: _ } = a(s, l);
|
|
2271
|
+
for (let r = 0; r < this._png.channels; r++) {
|
|
2272
|
+
const o = t.data[_ + this._png.channels - 1] / n, w = r % (this._png.channels - 1) === 0 ? 1 : t.data[_ + r], d = Math.floor(o * w + (1 - o) * e.data[h + r]);
|
|
2273
|
+
e.data[h + r] += d;
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
break;
|
|
2277
|
+
default:
|
|
2278
|
+
throw new Error("Unknown blendOp");
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
decodeImage() {
|
|
2282
|
+
if (this._inflator.err)
|
|
2283
|
+
throw new Error(`Error while decompressing the data: ${this._inflator.err}`);
|
|
2284
|
+
const e = this._isAnimated ? (this._frames?.at(0)).data : this._inflator.result;
|
|
2285
|
+
if (this._filterMethod !== te.ADAPTIVE)
|
|
2286
|
+
throw new Error(`Filter method ${this._filterMethod} not supported`);
|
|
2287
|
+
if (this._interlaceMethod === ct.NO_INTERLACE)
|
|
2288
|
+
this._png.data = Jt({
|
|
2289
|
+
data: e,
|
|
2290
|
+
width: this._png.width,
|
|
2291
|
+
height: this._png.height,
|
|
2292
|
+
channels: this._png.channels,
|
|
2293
|
+
depth: this._png.depth
|
|
2294
|
+
});
|
|
2295
|
+
else if (this._interlaceMethod === ct.ADAM7)
|
|
2296
|
+
this._png.data = en({
|
|
2297
|
+
data: e,
|
|
2298
|
+
width: this._png.width,
|
|
2299
|
+
height: this._png.height,
|
|
2300
|
+
channels: this._png.channels,
|
|
2301
|
+
depth: this._png.depth
|
|
2302
|
+
});
|
|
2303
|
+
else
|
|
2304
|
+
throw new Error(`Interlace method ${this._interlaceMethod} not supported`);
|
|
2305
|
+
this._hasPalette && (this._png.palette = this._palette), this._hasTransparency && (this._png.transparency = this._transparency);
|
|
2306
|
+
}
|
|
2307
|
+
pushDataToFrame() {
|
|
2308
|
+
const e = this._inflator.result, t = this._frames.at(-1);
|
|
2309
|
+
t ? t.data = e : this._frames.push({
|
|
2310
|
+
sequenceNumber: 0,
|
|
2311
|
+
width: this._png.width,
|
|
2312
|
+
height: this._png.height,
|
|
2313
|
+
xOffset: 0,
|
|
2314
|
+
yOffset: 0,
|
|
2315
|
+
delayNumber: 0,
|
|
2316
|
+
delayDenominator: 0,
|
|
2317
|
+
disposeOp: V.NONE,
|
|
2318
|
+
blendOp: dt.SOURCE,
|
|
2319
|
+
data: e
|
|
2320
|
+
}), this._inflator = new jt(), this._writingDataChunks = !1;
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
function bn(i) {
|
|
2324
|
+
if (i !== 1 && i !== 2 && i !== 4 && i !== 8 && i !== 16)
|
|
2325
|
+
throw new Error(`invalid bit depth: ${i}`);
|
|
2326
|
+
return i;
|
|
2327
|
+
}
|
|
2328
|
+
function xn(i, e) {
|
|
2329
|
+
return new gn(i, e).decode();
|
|
2330
|
+
}
|
|
2331
|
+
class yn {
|
|
2332
|
+
bottomLeft;
|
|
2333
|
+
ptWidth;
|
|
2334
|
+
ptHeight;
|
|
2335
|
+
xSpacing;
|
|
2336
|
+
ySpacing;
|
|
2337
|
+
elevs;
|
|
2338
|
+
constructor(e, t, n, a, s, l) {
|
|
2339
|
+
this.bottomLeft = t, this.ptWidth = n, this.ptHeight = a, this.elevs = e, this.xSpacing = s, this.ySpacing = l;
|
|
2340
|
+
}
|
|
2341
|
+
// Uses bilinear interpolation
|
|
2342
|
+
// Based on Footnav code
|
|
2343
|
+
// x,y must be in projection of the geometry with scaling factor
|
|
2344
|
+
// already applied
|
|
2345
|
+
getHeight(e, t) {
|
|
2346
|
+
let n = [e, t], a = Math.floor((n[0] - this.bottomLeft.e) / this.xSpacing), s = this.ptHeight - Math.ceil((n[1] - this.bottomLeft.n) / this.ySpacing), l, h, _, r, o, w, d, f = Number.NEGATIVE_INFINITY;
|
|
2347
|
+
if (a >= 0 && s >= 0 && a < this.ptWidth - 1 && s < this.ptHeight - 1) {
|
|
2348
|
+
r = this.elevs[s * this.ptWidth + a], o = this.elevs[s * this.ptWidth + a + 1], w = this.elevs[s * this.ptWidth + a + this.ptWidth], d = this.elevs[s * this.ptWidth + a + this.ptWidth + 1], l = this.bottomLeft[0] + a * this.xSpacing, l + this.xSpacing, h = this.bottomLeft[1] + (this.ptHeight - 1 - s) * this.ySpacing, _ = h - this.ySpacing;
|
|
2349
|
+
let u = (n[0] - l) / this.xSpacing, U = r * (1 - u) + o * u, x = w * (1 - u) + d * u, g = (n[1] - _) / this.ySpacing;
|
|
2350
|
+
f = x * (1 - g) + U * g;
|
|
2351
|
+
}
|
|
2352
|
+
return f;
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
class kn extends ee {
|
|
2356
|
+
constructor(e) {
|
|
2357
|
+
super(e);
|
|
2358
|
+
}
|
|
2359
|
+
async readTile(e) {
|
|
2360
|
+
const n = await (await fetch(e)).arrayBuffer(), a = xn(n);
|
|
2361
|
+
let s, l = 0;
|
|
2362
|
+
const h = new Array(a.width * a.height);
|
|
2363
|
+
for (let _ = 0; _ < a.height; _++)
|
|
2364
|
+
for (let r = 0; r < a.width; r++)
|
|
2365
|
+
s = (_ * a.width + r) * a.channels, h[l++] = Math.round(a.data[s] * 256 + a.data[s + 1] + a.data[s + 2] / 256 - 32768);
|
|
2366
|
+
return { w: a.width, h: a.height, elevs: h };
|
|
2367
|
+
}
|
|
2368
|
+
getElevation(e) {
|
|
2369
|
+
const t = this.getTile(e, this.tile.z), n = this.dataTiles[`${t.z}/${t.x}/${t.y}`];
|
|
2370
|
+
return n ? n.getHeight(e[0], e[1]) : Number.NEGATIVE_INFINITY;
|
|
2371
|
+
}
|
|
2372
|
+
getElevationFromLonLat(e) {
|
|
2373
|
+
return this.getElevation(this.sphMerc.project(e));
|
|
2374
|
+
}
|
|
2375
|
+
// Overridden to store each tile as a DEM object
|
|
2376
|
+
rawTileToStoredTile(e, t) {
|
|
2377
|
+
const n = e.getTopRight(), a = e.getBottomLeft(), s = (n.e - a.e) / (t.w - 1), l = (n.n - a.n) / (t.h - 1), h = new yn(
|
|
2378
|
+
t.elevs,
|
|
2379
|
+
a,
|
|
2380
|
+
t.w,
|
|
2381
|
+
t.h,
|
|
2382
|
+
s,
|
|
2383
|
+
l
|
|
2384
|
+
);
|
|
2385
|
+
return { tile: e, data: h };
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
class En extends ee {
|
|
2389
|
+
constructor(e) {
|
|
2390
|
+
super(e);
|
|
2391
|
+
}
|
|
2392
|
+
async readTile(e) {
|
|
2393
|
+
return await (await fetch(e)).json();
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
class An {
|
|
2397
|
+
e;
|
|
2398
|
+
n;
|
|
2399
|
+
constructor(e, t) {
|
|
2400
|
+
this.e = e, this.n = t;
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
class Tn {
|
|
2404
|
+
lon;
|
|
2405
|
+
lat;
|
|
2406
|
+
constructor(e, t) {
|
|
2407
|
+
this.lon = e, this.lat = t;
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
export {
|
|
2411
|
+
N as Constants,
|
|
2412
|
+
yn as DEM,
|
|
2413
|
+
kn as DemTiler,
|
|
2414
|
+
An as EastNorth,
|
|
2415
|
+
En as JsonTiler,
|
|
2416
|
+
Tn as LonLat,
|
|
2417
|
+
Ue as SphMercProjection,
|
|
2418
|
+
q as Tile,
|
|
2419
|
+
ee as Tiler
|
|
2420
|
+
};
|