@vitrosoftware/common-ui-ts 1.1.226 → 1.1.228

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/css/std/controls/lookup-picker/lookup-picker-selected-item.css +0 -1
  2. package/css/std/controls/lookup-picker/lookup-picker-value-list.css +0 -1
  3. package/css/std/controls/lookup-picker/lookup-picker.css +1 -6
  4. package/css/std/controls/pdf-viewer/img/compare-dlg-separator.svg +3 -1
  5. package/css/std/controls/pdf-viewer/img/compare-dlg-title.svg +12 -0
  6. package/css/std/controls/pdf-viewer/pdf-viewer-index.css +148 -0
  7. package/css/std/controls/pdf-viewer/pdf-viewer.css +148 -0
  8. package/css/std/controls/select/select.css +2 -2
  9. package/css/std/controls/table-view/table-view-custom-lookup-edit.css +1 -1
  10. package/css/std/controls/table-view/treegrid-cell.css +4 -0
  11. package/css/std/controls/table-view/treegrid-context-menu.css +3 -3
  12. package/dist/index.css +3 -10
  13. package/dist/index.js +894 -1126
  14. package/dist/index.js.map +1 -1
  15. package/dist/src/controls/LookupPicker/LookupPicker.d.ts +2 -0
  16. package/dist/src/controls/LookupPicker/ValueList.d.ts +2 -0
  17. package/dist/src/controls/PdfViewer/services/PdfViewerService.d.ts +6 -0
  18. package/dist/src/controls/ScrollBar/ScrollBar.d.ts +1 -1
  19. package/dist/src/controls/TableView/TableViewConstants.d.ts +2 -1
  20. package/dist/src/controls/TableView/services/TableViewService.d.ts +1 -0
  21. package/dist/src/controls/TableView/services/impl/TableViewServiceImpl.d.ts +1 -0
  22. package/dist/src/controls/ViewPart/ViewPart.d.ts +2 -1
  23. package/dist/src/models/ItemCopyRequest.d.ts +5 -1
  24. package/dist/src/services/FileService.d.ts +8 -0
  25. package/lib/dxf-viewer/parser/DxfArrayScanner.js +27 -1
  26. package/lib/dxf-viewer/parser/DxfParser.js +7 -4
  27. package/lib/fflate/fflate.module.js +2672 -0
  28. package/package.json +1 -1
  29. package/src/controls/BimViewer/js/bim-viewer.js +2 -2
  30. package/src/controls/DxfViewer/js/dxf-viewer.js +100 -29
  31. package/src/controls/PdfViewer/js/pdf-viewer.js +240 -36
@@ -0,0 +1,2672 @@
1
+ /*!
2
+ fflate - fast JavaScript compression/decompression
3
+ <https://101arrowz.github.io/fflate>
4
+ Licensed under MIT. https://github.com/101arrowz/fflate/blob/master/LICENSE
5
+ version 0.8.2
6
+ */
7
+
8
+ // DEFLATE is a complex format; to read this code, you should probably check the RFC first:
9
+ // https://tools.ietf.org/html/rfc1951
10
+ // You may also wish to take a look at the guide I made about this program:
11
+ // https://gist.github.com/101arrowz/253f31eb5abc3d9275ab943003ffecad
12
+ // Some of the following code is similar to that of UZIP.js:
13
+ // https://github.com/photopea/UZIP.js
14
+ // However, the vast majority of the codebase has diverged from UZIP.js to increase performance and reduce bundle size.
15
+ // Sometimes 0 will appear where -1 would be more appropriate. This is because using a uint
16
+ // is better for memory in most engines (I *think*).
17
+ var ch2 = {};
18
+ var wk = (function (c, id, msg, transfer, cb) {
19
+ var w = new Worker(ch2[id] || (ch2[id] = URL.createObjectURL(new Blob([
20
+ c + ';addEventListener("error",function(e){e=e.error;postMessage({$e$:[e.message,e.code,e.stack]})})'
21
+ ], { type: 'text/javascript' }))));
22
+ w.onmessage = function (e) {
23
+ var d = e.data, ed = d.$e$;
24
+ if (ed) {
25
+ var err = new Error(ed[0]);
26
+ err['code'] = ed[1];
27
+ err.stack = ed[2];
28
+ cb(err, null);
29
+ }
30
+ else
31
+ cb(null, d);
32
+ };
33
+ w.postMessage(msg, transfer);
34
+ return w;
35
+ });
36
+
37
+ // aliases for shorter compressed code (most minifers don't do this)
38
+ var u8 = Uint8Array, u16 = Uint16Array, i32 = Int32Array;
39
+ // fixed length extra bits
40
+ var fleb = new u8([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, /* unused */ 0, 0, /* impossible */ 0]);
41
+ // fixed distance extra bits
42
+ var fdeb = new u8([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, /* unused */ 0, 0]);
43
+ // code length index map
44
+ var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
45
+ // get base, reverse index map from extra bits
46
+ var freb = function (eb, start) {
47
+ var b = new u16(31);
48
+ for (var i = 0; i < 31; ++i) {
49
+ b[i] = start += 1 << eb[i - 1];
50
+ }
51
+ // numbers here are at max 18 bits
52
+ var r = new i32(b[30]);
53
+ for (var i = 1; i < 30; ++i) {
54
+ for (var j = b[i]; j < b[i + 1]; ++j) {
55
+ r[j] = ((j - b[i]) << 5) | i;
56
+ }
57
+ }
58
+ return { b: b, r: r };
59
+ };
60
+ var _a = freb(fleb, 2), fl = _a.b, revfl = _a.r;
61
+ // we can ignore the fact that the other numbers are wrong; they never happen anyway
62
+ fl[28] = 258, revfl[258] = 28;
63
+ var _b = freb(fdeb, 0), fd = _b.b, revfd = _b.r;
64
+ // map of value to reverse (assuming 16 bits)
65
+ var rev = new u16(32768);
66
+ for (var i = 0; i < 32768; ++i) {
67
+ // reverse table algorithm from SO
68
+ var x = ((i & 0xAAAA) >> 1) | ((i & 0x5555) << 1);
69
+ x = ((x & 0xCCCC) >> 2) | ((x & 0x3333) << 2);
70
+ x = ((x & 0xF0F0) >> 4) | ((x & 0x0F0F) << 4);
71
+ rev[i] = (((x & 0xFF00) >> 8) | ((x & 0x00FF) << 8)) >> 1;
72
+ }
73
+ // create huffman tree from u8 "map": index -> code length for code index
74
+ // mb (max bits) must be at most 15
75
+ // TODO: optimize/split up?
76
+ var hMap = (function (cd, mb, r) {
77
+ var s = cd.length;
78
+ // index
79
+ var i = 0;
80
+ // u16 "map": index -> # of codes with bit length = index
81
+ var l = new u16(mb);
82
+ // length of cd must be 288 (total # of codes)
83
+ for (; i < s; ++i) {
84
+ if (cd[i])
85
+ ++l[cd[i] - 1];
86
+ }
87
+ // u16 "map": index -> minimum code for bit length = index
88
+ var le = new u16(mb);
89
+ for (i = 1; i < mb; ++i) {
90
+ le[i] = (le[i - 1] + l[i - 1]) << 1;
91
+ }
92
+ var co;
93
+ if (r) {
94
+ // u16 "map": index -> number of actual bits, symbol for code
95
+ co = new u16(1 << mb);
96
+ // bits to remove for reverser
97
+ var rvb = 15 - mb;
98
+ for (i = 0; i < s; ++i) {
99
+ // ignore 0 lengths
100
+ if (cd[i]) {
101
+ // num encoding both symbol and bits read
102
+ var sv = (i << 4) | cd[i];
103
+ // free bits
104
+ var r_1 = mb - cd[i];
105
+ // start value
106
+ var v = le[cd[i] - 1]++ << r_1;
107
+ // m is end value
108
+ for (var m = v | ((1 << r_1) - 1); v <= m; ++v) {
109
+ // every 16 bit value starting with the code yields the same result
110
+ co[rev[v] >> rvb] = sv;
111
+ }
112
+ }
113
+ }
114
+ }
115
+ else {
116
+ co = new u16(s);
117
+ for (i = 0; i < s; ++i) {
118
+ if (cd[i]) {
119
+ co[i] = rev[le[cd[i] - 1]++] >> (15 - cd[i]);
120
+ }
121
+ }
122
+ }
123
+ return co;
124
+ });
125
+ // fixed length tree
126
+ var flt = new u8(288);
127
+ for (var i = 0; i < 144; ++i)
128
+ flt[i] = 8;
129
+ for (var i = 144; i < 256; ++i)
130
+ flt[i] = 9;
131
+ for (var i = 256; i < 280; ++i)
132
+ flt[i] = 7;
133
+ for (var i = 280; i < 288; ++i)
134
+ flt[i] = 8;
135
+ // fixed distance tree
136
+ var fdt = new u8(32);
137
+ for (var i = 0; i < 32; ++i)
138
+ fdt[i] = 5;
139
+ // fixed length map
140
+ var flm = /*#__PURE__*/ hMap(flt, 9, 0), flrm = /*#__PURE__*/ hMap(flt, 9, 1);
141
+ // fixed distance map
142
+ var fdm = /*#__PURE__*/ hMap(fdt, 5, 0), fdrm = /*#__PURE__*/ hMap(fdt, 5, 1);
143
+ // find max of array
144
+ var max = function (a) {
145
+ var m = a[0];
146
+ for (var i = 1; i < a.length; ++i) {
147
+ if (a[i] > m)
148
+ m = a[i];
149
+ }
150
+ return m;
151
+ };
152
+ // read d, starting at bit p and mask with m
153
+ var bits = function (d, p, m) {
154
+ var o = (p / 8) | 0;
155
+ return ((d[o] | (d[o + 1] << 8)) >> (p & 7)) & m;
156
+ };
157
+ // read d, starting at bit p continuing for at least 16 bits
158
+ var bits16 = function (d, p) {
159
+ var o = (p / 8) | 0;
160
+ return ((d[o] | (d[o + 1] << 8) | (d[o + 2] << 16)) >> (p & 7));
161
+ };
162
+ // get end of byte
163
+ var shft = function (p) { return ((p + 7) / 8) | 0; };
164
+ // typed array slice - allows garbage collector to free original reference,
165
+ // while being more compatible than .slice
166
+ var slc = function (v, s, e) {
167
+ if (s == null || s < 0)
168
+ s = 0;
169
+ if (e == null || e > v.length)
170
+ e = v.length;
171
+ // can't use .constructor in case user-supplied
172
+ return new u8(v.subarray(s, e));
173
+ };
174
+ /**
175
+ * Codes for errors generated within this library
176
+ */
177
+ export var FlateErrorCode = {
178
+ UnexpectedEOF: 0,
179
+ InvalidBlockType: 1,
180
+ InvalidLengthLiteral: 2,
181
+ InvalidDistance: 3,
182
+ StreamFinished: 4,
183
+ NoStreamHandler: 5,
184
+ InvalidHeader: 6,
185
+ NoCallback: 7,
186
+ InvalidUTF8: 8,
187
+ ExtraFieldTooLong: 9,
188
+ InvalidDate: 10,
189
+ FilenameTooLong: 11,
190
+ StreamFinishing: 12,
191
+ InvalidZipData: 13,
192
+ UnknownCompressionMethod: 14
193
+ };
194
+ // error codes
195
+ var ec = [
196
+ 'unexpected EOF',
197
+ 'invalid block type',
198
+ 'invalid length/literal',
199
+ 'invalid distance',
200
+ 'stream finished',
201
+ 'no stream handler',
202
+ ,
203
+ 'no callback',
204
+ 'invalid UTF-8 data',
205
+ 'extra field too long',
206
+ 'date not in range 1980-2099',
207
+ 'filename too long',
208
+ 'stream finishing',
209
+ 'invalid zip data'
210
+ // determined by unknown compression method
211
+ ];
212
+ ;
213
+ var err = function (ind, msg, nt) {
214
+ var e = new Error(msg || ec[ind]);
215
+ e.code = ind;
216
+ if (Error.captureStackTrace)
217
+ Error.captureStackTrace(e, err);
218
+ if (!nt)
219
+ throw e;
220
+ return e;
221
+ };
222
+ // expands raw DEFLATE data
223
+ var inflt = function (dat, st, buf, dict) {
224
+ // source length dict length
225
+ var sl = dat.length, dl = dict ? dict.length : 0;
226
+ if (!sl || st.f && !st.l)
227
+ return buf || new u8(0);
228
+ var noBuf = !buf;
229
+ // have to estimate size
230
+ var resize = noBuf || st.i != 2;
231
+ // no state
232
+ var noSt = st.i;
233
+ // Assumes roughly 33% compression ratio average
234
+ if (noBuf)
235
+ buf = new u8(sl * 3);
236
+ // ensure buffer can fit at least l elements
237
+ var cbuf = function (l) {
238
+ var bl = buf.length;
239
+ // need to increase size to fit
240
+ if (l > bl) {
241
+ // Double or set to necessary, whichever is greater
242
+ var nbuf = new u8(Math.max(bl * 2, l));
243
+ nbuf.set(buf);
244
+ buf = nbuf;
245
+ }
246
+ };
247
+ // last chunk bitpos bytes
248
+ var final = st.f || 0, pos = st.p || 0, bt = st.b || 0, lm = st.l, dm = st.d, lbt = st.m, dbt = st.n;
249
+ // total bits
250
+ var tbts = sl * 8;
251
+ do {
252
+ if (!lm) {
253
+ // BFINAL - this is only 1 when last chunk is next
254
+ final = bits(dat, pos, 1);
255
+ // type: 0 = no compression, 1 = fixed huffman, 2 = dynamic huffman
256
+ var type = bits(dat, pos + 1, 3);
257
+ pos += 3;
258
+ if (!type) {
259
+ // go to end of byte boundary
260
+ var s = shft(pos) + 4, l = dat[s - 4] | (dat[s - 3] << 8), t = s + l;
261
+ if (t > sl) {
262
+ if (noSt)
263
+ err(0);
264
+ break;
265
+ }
266
+ // ensure size
267
+ if (resize)
268
+ cbuf(bt + l);
269
+ // Copy over uncompressed data
270
+ buf.set(dat.subarray(s, t), bt);
271
+ // Get new bitpos, update byte count
272
+ st.b = bt += l, st.p = pos = t * 8, st.f = final;
273
+ continue;
274
+ }
275
+ else if (type == 1)
276
+ lm = flrm, dm = fdrm, lbt = 9, dbt = 5;
277
+ else if (type == 2) {
278
+ // literal lengths
279
+ var hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;
280
+ var tl = hLit + bits(dat, pos + 5, 31) + 1;
281
+ pos += 14;
282
+ // length+distance tree
283
+ var ldt = new u8(tl);
284
+ // code length tree
285
+ var clt = new u8(19);
286
+ for (var i = 0; i < hcLen; ++i) {
287
+ // use index map to get real code
288
+ clt[clim[i]] = bits(dat, pos + i * 3, 7);
289
+ }
290
+ pos += hcLen * 3;
291
+ // code lengths bits
292
+ var clb = max(clt), clbmsk = (1 << clb) - 1;
293
+ // code lengths map
294
+ var clm = hMap(clt, clb, 1);
295
+ for (var i = 0; i < tl;) {
296
+ var r = clm[bits(dat, pos, clbmsk)];
297
+ // bits read
298
+ pos += r & 15;
299
+ // symbol
300
+ var s = r >> 4;
301
+ // code length to copy
302
+ if (s < 16) {
303
+ ldt[i++] = s;
304
+ }
305
+ else {
306
+ // copy count
307
+ var c = 0, n = 0;
308
+ if (s == 16)
309
+ n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i - 1];
310
+ else if (s == 17)
311
+ n = 3 + bits(dat, pos, 7), pos += 3;
312
+ else if (s == 18)
313
+ n = 11 + bits(dat, pos, 127), pos += 7;
314
+ while (n--)
315
+ ldt[i++] = c;
316
+ }
317
+ }
318
+ // length tree distance tree
319
+ var lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);
320
+ // max length bits
321
+ lbt = max(lt);
322
+ // max dist bits
323
+ dbt = max(dt);
324
+ lm = hMap(lt, lbt, 1);
325
+ dm = hMap(dt, dbt, 1);
326
+ }
327
+ else
328
+ err(1);
329
+ if (pos > tbts) {
330
+ if (noSt)
331
+ err(0);
332
+ break;
333
+ }
334
+ }
335
+ // Make sure the buffer can hold this + the largest possible addition
336
+ // Maximum chunk size (practically, theoretically infinite) is 2^17
337
+ if (resize)
338
+ cbuf(bt + 131072);
339
+ var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;
340
+ var lpos = pos;
341
+ for (;; lpos = pos) {
342
+ // bits read, code
343
+ var c = lm[bits16(dat, pos) & lms], sym = c >> 4;
344
+ pos += c & 15;
345
+ if (pos > tbts) {
346
+ if (noSt)
347
+ err(0);
348
+ break;
349
+ }
350
+ if (!c)
351
+ err(2);
352
+ if (sym < 256)
353
+ buf[bt++] = sym;
354
+ else if (sym == 256) {
355
+ lpos = pos, lm = null;
356
+ break;
357
+ }
358
+ else {
359
+ var add = sym - 254;
360
+ // no extra bits needed if less
361
+ if (sym > 264) {
362
+ // index
363
+ var i = sym - 257, b = fleb[i];
364
+ add = bits(dat, pos, (1 << b) - 1) + fl[i];
365
+ pos += b;
366
+ }
367
+ // dist
368
+ var d = dm[bits16(dat, pos) & dms], dsym = d >> 4;
369
+ if (!d)
370
+ err(3);
371
+ pos += d & 15;
372
+ var dt = fd[dsym];
373
+ if (dsym > 3) {
374
+ var b = fdeb[dsym];
375
+ dt += bits16(dat, pos) & (1 << b) - 1, pos += b;
376
+ }
377
+ if (pos > tbts) {
378
+ if (noSt)
379
+ err(0);
380
+ break;
381
+ }
382
+ if (resize)
383
+ cbuf(bt + 131072);
384
+ var end = bt + add;
385
+ if (bt < dt) {
386
+ var shift = dl - dt, dend = Math.min(dt, end);
387
+ if (shift + bt < 0)
388
+ err(3);
389
+ for (; bt < dend; ++bt)
390
+ buf[bt] = dict[shift + bt];
391
+ }
392
+ for (; bt < end; ++bt)
393
+ buf[bt] = buf[bt - dt];
394
+ }
395
+ }
396
+ st.l = lm, st.p = lpos, st.b = bt, st.f = final;
397
+ if (lm)
398
+ final = 1, st.m = lbt, st.d = dm, st.n = dbt;
399
+ } while (!final);
400
+ // don't reallocate for streams or user buffers
401
+ return bt != buf.length && noBuf ? slc(buf, 0, bt) : buf.subarray(0, bt);
402
+ };
403
+ // starting at p, write the minimum number of bits that can hold v to d
404
+ var wbits = function (d, p, v) {
405
+ v <<= p & 7;
406
+ var o = (p / 8) | 0;
407
+ d[o] |= v;
408
+ d[o + 1] |= v >> 8;
409
+ };
410
+ // starting at p, write the minimum number of bits (>8) that can hold v to d
411
+ var wbits16 = function (d, p, v) {
412
+ v <<= p & 7;
413
+ var o = (p / 8) | 0;
414
+ d[o] |= v;
415
+ d[o + 1] |= v >> 8;
416
+ d[o + 2] |= v >> 16;
417
+ };
418
+ // creates code lengths from a frequency table
419
+ var hTree = function (d, mb) {
420
+ // Need extra info to make a tree
421
+ var t = [];
422
+ for (var i = 0; i < d.length; ++i) {
423
+ if (d[i])
424
+ t.push({ s: i, f: d[i] });
425
+ }
426
+ var s = t.length;
427
+ var t2 = t.slice();
428
+ if (!s)
429
+ return { t: et, l: 0 };
430
+ if (s == 1) {
431
+ var v = new u8(t[0].s + 1);
432
+ v[t[0].s] = 1;
433
+ return { t: v, l: 1 };
434
+ }
435
+ t.sort(function (a, b) { return a.f - b.f; });
436
+ // after i2 reaches last ind, will be stopped
437
+ // freq must be greater than largest possible number of symbols
438
+ t.push({ s: -1, f: 25001 });
439
+ var l = t[0], r = t[1], i0 = 0, i1 = 1, i2 = 2;
440
+ t[0] = { s: -1, f: l.f + r.f, l: l, r: r };
441
+ // efficient algorithm from UZIP.js
442
+ // i0 is lookbehind, i2 is lookahead - after processing two low-freq
443
+ // symbols that combined have high freq, will start processing i2 (high-freq,
444
+ // non-composite) symbols instead
445
+ // see https://reddit.com/r/photopea/comments/ikekht/uzipjs_questions/
446
+ while (i1 != s - 1) {
447
+ l = t[t[i0].f < t[i2].f ? i0++ : i2++];
448
+ r = t[i0 != i1 && t[i0].f < t[i2].f ? i0++ : i2++];
449
+ t[i1++] = { s: -1, f: l.f + r.f, l: l, r: r };
450
+ }
451
+ var maxSym = t2[0].s;
452
+ for (var i = 1; i < s; ++i) {
453
+ if (t2[i].s > maxSym)
454
+ maxSym = t2[i].s;
455
+ }
456
+ // code lengths
457
+ var tr = new u16(maxSym + 1);
458
+ // max bits in tree
459
+ var mbt = ln(t[i1 - 1], tr, 0);
460
+ if (mbt > mb) {
461
+ // more algorithms from UZIP.js
462
+ // TODO: find out how this code works (debt)
463
+ // ind debt
464
+ var i = 0, dt = 0;
465
+ // left cost
466
+ var lft = mbt - mb, cst = 1 << lft;
467
+ t2.sort(function (a, b) { return tr[b.s] - tr[a.s] || a.f - b.f; });
468
+ for (; i < s; ++i) {
469
+ var i2_1 = t2[i].s;
470
+ if (tr[i2_1] > mb) {
471
+ dt += cst - (1 << (mbt - tr[i2_1]));
472
+ tr[i2_1] = mb;
473
+ }
474
+ else
475
+ break;
476
+ }
477
+ dt >>= lft;
478
+ while (dt > 0) {
479
+ var i2_2 = t2[i].s;
480
+ if (tr[i2_2] < mb)
481
+ dt -= 1 << (mb - tr[i2_2]++ - 1);
482
+ else
483
+ ++i;
484
+ }
485
+ for (; i >= 0 && dt; --i) {
486
+ var i2_3 = t2[i].s;
487
+ if (tr[i2_3] == mb) {
488
+ --tr[i2_3];
489
+ ++dt;
490
+ }
491
+ }
492
+ mbt = mb;
493
+ }
494
+ return { t: new u8(tr), l: mbt };
495
+ };
496
+ // get the max length and assign length codes
497
+ var ln = function (n, l, d) {
498
+ return n.s == -1
499
+ ? Math.max(ln(n.l, l, d + 1), ln(n.r, l, d + 1))
500
+ : (l[n.s] = d);
501
+ };
502
+ // length codes generation
503
+ var lc = function (c) {
504
+ var s = c.length;
505
+ // Note that the semicolon was intentional
506
+ while (s && !c[--s])
507
+ ;
508
+ var cl = new u16(++s);
509
+ // ind num streak
510
+ var cli = 0, cln = c[0], cls = 1;
511
+ var w = function (v) { cl[cli++] = v; };
512
+ for (var i = 1; i <= s; ++i) {
513
+ if (c[i] == cln && i != s)
514
+ ++cls;
515
+ else {
516
+ if (!cln && cls > 2) {
517
+ for (; cls > 138; cls -= 138)
518
+ w(32754);
519
+ if (cls > 2) {
520
+ w(cls > 10 ? ((cls - 11) << 5) | 28690 : ((cls - 3) << 5) | 12305);
521
+ cls = 0;
522
+ }
523
+ }
524
+ else if (cls > 3) {
525
+ w(cln), --cls;
526
+ for (; cls > 6; cls -= 6)
527
+ w(8304);
528
+ if (cls > 2)
529
+ w(((cls - 3) << 5) | 8208), cls = 0;
530
+ }
531
+ while (cls--)
532
+ w(cln);
533
+ cls = 1;
534
+ cln = c[i];
535
+ }
536
+ }
537
+ return { c: cl.subarray(0, cli), n: s };
538
+ };
539
+ // calculate the length of output from tree, code lengths
540
+ var clen = function (cf, cl) {
541
+ var l = 0;
542
+ for (var i = 0; i < cl.length; ++i)
543
+ l += cf[i] * cl[i];
544
+ return l;
545
+ };
546
+ // writes a fixed block
547
+ // returns the new bit pos
548
+ var wfblk = function (out, pos, dat) {
549
+ // no need to write 00 as type: TypedArray defaults to 0
550
+ var s = dat.length;
551
+ var o = shft(pos + 2);
552
+ out[o] = s & 255;
553
+ out[o + 1] = s >> 8;
554
+ out[o + 2] = out[o] ^ 255;
555
+ out[o + 3] = out[o + 1] ^ 255;
556
+ for (var i = 0; i < s; ++i)
557
+ out[o + i + 4] = dat[i];
558
+ return (o + 4 + s) * 8;
559
+ };
560
+ // writes a block
561
+ var wblk = function (dat, out, final, syms, lf, df, eb, li, bs, bl, p) {
562
+ wbits(out, p++, final);
563
+ ++lf[256];
564
+ var _a = hTree(lf, 15), dlt = _a.t, mlb = _a.l;
565
+ var _b = hTree(df, 15), ddt = _b.t, mdb = _b.l;
566
+ var _c = lc(dlt), lclt = _c.c, nlc = _c.n;
567
+ var _d = lc(ddt), lcdt = _d.c, ndc = _d.n;
568
+ var lcfreq = new u16(19);
569
+ for (var i = 0; i < lclt.length; ++i)
570
+ ++lcfreq[lclt[i] & 31];
571
+ for (var i = 0; i < lcdt.length; ++i)
572
+ ++lcfreq[lcdt[i] & 31];
573
+ var _e = hTree(lcfreq, 7), lct = _e.t, mlcb = _e.l;
574
+ var nlcc = 19;
575
+ for (; nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc)
576
+ ;
577
+ var flen = (bl + 5) << 3;
578
+ var ftlen = clen(lf, flt) + clen(df, fdt) + eb;
579
+ var dtlen = clen(lf, dlt) + clen(df, ddt) + eb + 14 + 3 * nlcc + clen(lcfreq, lct) + 2 * lcfreq[16] + 3 * lcfreq[17] + 7 * lcfreq[18];
580
+ if (bs >= 0 && flen <= ftlen && flen <= dtlen)
581
+ return wfblk(out, p, dat.subarray(bs, bs + bl));
582
+ var lm, ll, dm, dl;
583
+ wbits(out, p, 1 + (dtlen < ftlen)), p += 2;
584
+ if (dtlen < ftlen) {
585
+ lm = hMap(dlt, mlb, 0), ll = dlt, dm = hMap(ddt, mdb, 0), dl = ddt;
586
+ var llm = hMap(lct, mlcb, 0);
587
+ wbits(out, p, nlc - 257);
588
+ wbits(out, p + 5, ndc - 1);
589
+ wbits(out, p + 10, nlcc - 4);
590
+ p += 14;
591
+ for (var i = 0; i < nlcc; ++i)
592
+ wbits(out, p + 3 * i, lct[clim[i]]);
593
+ p += 3 * nlcc;
594
+ var lcts = [lclt, lcdt];
595
+ for (var it = 0; it < 2; ++it) {
596
+ var clct = lcts[it];
597
+ for (var i = 0; i < clct.length; ++i) {
598
+ var len = clct[i] & 31;
599
+ wbits(out, p, llm[len]), p += lct[len];
600
+ if (len > 15)
601
+ wbits(out, p, (clct[i] >> 5) & 127), p += clct[i] >> 12;
602
+ }
603
+ }
604
+ }
605
+ else {
606
+ lm = flm, ll = flt, dm = fdm, dl = fdt;
607
+ }
608
+ for (var i = 0; i < li; ++i) {
609
+ var sym = syms[i];
610
+ if (sym > 255) {
611
+ var len = (sym >> 18) & 31;
612
+ wbits16(out, p, lm[len + 257]), p += ll[len + 257];
613
+ if (len > 7)
614
+ wbits(out, p, (sym >> 23) & 31), p += fleb[len];
615
+ var dst = sym & 31;
616
+ wbits16(out, p, dm[dst]), p += dl[dst];
617
+ if (dst > 3)
618
+ wbits16(out, p, (sym >> 5) & 8191), p += fdeb[dst];
619
+ }
620
+ else {
621
+ wbits16(out, p, lm[sym]), p += ll[sym];
622
+ }
623
+ }
624
+ wbits16(out, p, lm[256]);
625
+ return p + ll[256];
626
+ };
627
+ // deflate options (nice << 13) | chain
628
+ var deo = /*#__PURE__*/ new i32([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]);
629
+ // empty
630
+ var et = /*#__PURE__*/ new u8(0);
631
+ // compresses data into a raw DEFLATE buffer
632
+ var dflt = function (dat, lvl, plvl, pre, post, st) {
633
+ var s = st.z || dat.length;
634
+ var o = new u8(pre + s + 5 * (1 + Math.ceil(s / 7000)) + post);
635
+ // writing to this writes to the output buffer
636
+ var w = o.subarray(pre, o.length - post);
637
+ var lst = st.l;
638
+ var pos = (st.r || 0) & 7;
639
+ if (lvl) {
640
+ if (pos)
641
+ w[0] = st.r >> 3;
642
+ var opt = deo[lvl - 1];
643
+ var n = opt >> 13, c = opt & 8191;
644
+ var msk_1 = (1 << plvl) - 1;
645
+ // prev 2-byte val map curr 2-byte val map
646
+ var prev = st.p || new u16(32768), head = st.h || new u16(msk_1 + 1);
647
+ var bs1_1 = Math.ceil(plvl / 3), bs2_1 = 2 * bs1_1;
648
+ var hsh = function (i) { return (dat[i] ^ (dat[i + 1] << bs1_1) ^ (dat[i + 2] << bs2_1)) & msk_1; };
649
+ // 24576 is an arbitrary number of maximum symbols per block
650
+ // 424 buffer for last block
651
+ var syms = new i32(25000);
652
+ // length/literal freq distance freq
653
+ var lf = new u16(288), df = new u16(32);
654
+ // l/lcnt exbits index l/lind waitdx blkpos
655
+ var lc_1 = 0, eb = 0, i = st.i || 0, li = 0, wi = st.w || 0, bs = 0;
656
+ for (; i + 2 < s; ++i) {
657
+ // hash value
658
+ var hv = hsh(i);
659
+ // index mod 32768 previous index mod
660
+ var imod = i & 32767, pimod = head[hv];
661
+ prev[imod] = pimod;
662
+ head[hv] = imod;
663
+ // We always should modify head and prev, but only add symbols if
664
+ // this data is not yet processed ("wait" for wait index)
665
+ if (wi <= i) {
666
+ // bytes remaining
667
+ var rem = s - i;
668
+ if ((lc_1 > 7000 || li > 24576) && (rem > 423 || !lst)) {
669
+ pos = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i - bs, pos);
670
+ li = lc_1 = eb = 0, bs = i;
671
+ for (var j = 0; j < 286; ++j)
672
+ lf[j] = 0;
673
+ for (var j = 0; j < 30; ++j)
674
+ df[j] = 0;
675
+ }
676
+ // len dist chain
677
+ var l = 2, d = 0, ch_1 = c, dif = imod - pimod & 32767;
678
+ if (rem > 2 && hv == hsh(i - dif)) {
679
+ var maxn = Math.min(n, rem) - 1;
680
+ var maxd = Math.min(32767, i);
681
+ // max possible length
682
+ // not capped at dif because decompressors implement "rolling" index population
683
+ var ml = Math.min(258, rem);
684
+ while (dif <= maxd && --ch_1 && imod != pimod) {
685
+ if (dat[i + l] == dat[i + l - dif]) {
686
+ var nl = 0;
687
+ for (; nl < ml && dat[i + nl] == dat[i + nl - dif]; ++nl)
688
+ ;
689
+ if (nl > l) {
690
+ l = nl, d = dif;
691
+ // break out early when we reach "nice" (we are satisfied enough)
692
+ if (nl > maxn)
693
+ break;
694
+ // now, find the rarest 2-byte sequence within this
695
+ // length of literals and search for that instead.
696
+ // Much faster than just using the start
697
+ var mmd = Math.min(dif, nl - 2);
698
+ var md = 0;
699
+ for (var j = 0; j < mmd; ++j) {
700
+ var ti = i - dif + j & 32767;
701
+ var pti = prev[ti];
702
+ var cd = ti - pti & 32767;
703
+ if (cd > md)
704
+ md = cd, pimod = ti;
705
+ }
706
+ }
707
+ }
708
+ // check the previous match
709
+ imod = pimod, pimod = prev[imod];
710
+ dif += imod - pimod & 32767;
711
+ }
712
+ }
713
+ // d will be nonzero only when a match was found
714
+ if (d) {
715
+ // store both dist and len data in one int32
716
+ // Make sure this is recognized as a len/dist with 28th bit (2^28)
717
+ syms[li++] = 268435456 | (revfl[l] << 18) | revfd[d];
718
+ var lin = revfl[l] & 31, din = revfd[d] & 31;
719
+ eb += fleb[lin] + fdeb[din];
720
+ ++lf[257 + lin];
721
+ ++df[din];
722
+ wi = i + l;
723
+ ++lc_1;
724
+ }
725
+ else {
726
+ syms[li++] = dat[i];
727
+ ++lf[dat[i]];
728
+ }
729
+ }
730
+ }
731
+ for (i = Math.max(i, wi); i < s; ++i) {
732
+ syms[li++] = dat[i];
733
+ ++lf[dat[i]];
734
+ }
735
+ pos = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i - bs, pos);
736
+ if (!lst) {
737
+ st.r = (pos & 7) | w[(pos / 8) | 0] << 3;
738
+ // shft(pos) now 1 less if pos & 7 != 0
739
+ pos -= 7;
740
+ st.h = head, st.p = prev, st.i = i, st.w = wi;
741
+ }
742
+ }
743
+ else {
744
+ for (var i = st.w || 0; i < s + lst; i += 65535) {
745
+ // end
746
+ var e = i + 65535;
747
+ if (e >= s) {
748
+ // write final block
749
+ w[(pos / 8) | 0] = lst;
750
+ e = s;
751
+ }
752
+ pos = wfblk(w, pos + 1, dat.subarray(i, e));
753
+ }
754
+ st.i = s;
755
+ }
756
+ return slc(o, 0, pre + shft(pos) + post);
757
+ };
758
+ // CRC32 table
759
+ var crct = /*#__PURE__*/ (function () {
760
+ var t = new Int32Array(256);
761
+ for (var i = 0; i < 256; ++i) {
762
+ var c = i, k = 9;
763
+ while (--k)
764
+ c = ((c & 1) && -306674912) ^ (c >>> 1);
765
+ t[i] = c;
766
+ }
767
+ return t;
768
+ })();
769
+ // CRC32
770
+ var crc = function () {
771
+ var c = -1;
772
+ return {
773
+ p: function (d) {
774
+ // closures have awful performance
775
+ var cr = c;
776
+ for (var i = 0; i < d.length; ++i)
777
+ cr = crct[(cr & 255) ^ d[i]] ^ (cr >>> 8);
778
+ c = cr;
779
+ },
780
+ d: function () { return ~c; }
781
+ };
782
+ };
783
+ // Adler32
784
+ var adler = function () {
785
+ var a = 1, b = 0;
786
+ return {
787
+ p: function (d) {
788
+ // closures have awful performance
789
+ var n = a, m = b;
790
+ var l = d.length | 0;
791
+ for (var i = 0; i != l;) {
792
+ var e = Math.min(i + 2655, l);
793
+ for (; i < e; ++i)
794
+ m += n += d[i];
795
+ n = (n & 65535) + 15 * (n >> 16), m = (m & 65535) + 15 * (m >> 16);
796
+ }
797
+ a = n, b = m;
798
+ },
799
+ d: function () {
800
+ a %= 65521, b %= 65521;
801
+ return (a & 255) << 24 | (a & 0xFF00) << 8 | (b & 255) << 8 | (b >> 8);
802
+ }
803
+ };
804
+ };
805
+ ;
806
+ // deflate with opts
807
+ var dopt = function (dat, opt, pre, post, st) {
808
+ if (!st) {
809
+ st = { l: 1 };
810
+ if (opt.dictionary) {
811
+ var dict = opt.dictionary.subarray(-32768);
812
+ var newDat = new u8(dict.length + dat.length);
813
+ newDat.set(dict);
814
+ newDat.set(dat, dict.length);
815
+ dat = newDat;
816
+ st.w = dict.length;
817
+ }
818
+ }
819
+ return dflt(dat, opt.level == null ? 6 : opt.level, opt.mem == null ? (st.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(dat.length))) * 1.5) : 20) : (12 + opt.mem), pre, post, st);
820
+ };
821
+ // Walmart object spread
822
+ var mrg = function (a, b) {
823
+ var o = {};
824
+ for (var k in a)
825
+ o[k] = a[k];
826
+ for (var k in b)
827
+ o[k] = b[k];
828
+ return o;
829
+ };
830
+ // worker clone
831
+ // This is possibly the craziest part of the entire codebase, despite how simple it may seem.
832
+ // The only parameter to this function is a closure that returns an array of variables outside of the function scope.
833
+ // We're going to try to figure out the variable names used in the closure as strings because that is crucial for workerization.
834
+ // We will return an object mapping of true variable name to value (basically, the current scope as a JS object).
835
+ // The reason we can't just use the original variable names is minifiers mangling the toplevel scope.
836
+ // This took me three weeks to figure out how to do.
837
+ var wcln = function (fn, fnStr, td) {
838
+ var dt = fn();
839
+ var st = fn.toString();
840
+ var ks = st.slice(st.indexOf('[') + 1, st.lastIndexOf(']')).replace(/\s+/g, '').split(',');
841
+ for (var i = 0; i < dt.length; ++i) {
842
+ var v = dt[i], k = ks[i];
843
+ if (typeof v == 'function') {
844
+ fnStr += ';' + k + '=';
845
+ var st_1 = v.toString();
846
+ if (v.prototype) {
847
+ // for global objects
848
+ if (st_1.indexOf('[native code]') != -1) {
849
+ var spInd = st_1.indexOf(' ', 8) + 1;
850
+ fnStr += st_1.slice(spInd, st_1.indexOf('(', spInd));
851
+ }
852
+ else {
853
+ fnStr += st_1;
854
+ for (var t in v.prototype)
855
+ fnStr += ';' + k + '.prototype.' + t + '=' + v.prototype[t].toString();
856
+ }
857
+ }
858
+ else
859
+ fnStr += st_1;
860
+ }
861
+ else
862
+ td[k] = v;
863
+ }
864
+ return fnStr;
865
+ };
866
+ var ch = [];
867
+ // clone bufs
868
+ var cbfs = function (v) {
869
+ var tl = [];
870
+ for (var k in v) {
871
+ if (v[k].buffer) {
872
+ tl.push((v[k] = new v[k].constructor(v[k])).buffer);
873
+ }
874
+ }
875
+ return tl;
876
+ };
877
+ // use a worker to execute code
878
+ var wrkr = function (fns, init, id, cb) {
879
+ if (!ch[id]) {
880
+ var fnStr = '', td_1 = {}, m = fns.length - 1;
881
+ for (var i = 0; i < m; ++i)
882
+ fnStr = wcln(fns[i], fnStr, td_1);
883
+ ch[id] = { c: wcln(fns[m], fnStr, td_1), e: td_1 };
884
+ }
885
+ var td = mrg({}, ch[id].e);
886
+ return wk(ch[id].c + ';onmessage=function(e){for(var k in e.data)self[k]=e.data[k];onmessage=' + init.toString() + '}', id, td, cbfs(td), cb);
887
+ };
888
+ // base async inflate fn
889
+ var bInflt = function () { return [u8, u16, i32, fleb, fdeb, clim, fl, fd, flrm, fdrm, rev, ec, hMap, max, bits, bits16, shft, slc, err, inflt, inflateSync, pbf, gopt]; };
890
+ var bDflt = function () { return [u8, u16, i32, fleb, fdeb, clim, revfl, revfd, flm, flt, fdm, fdt, rev, deo, et, hMap, wbits, wbits16, hTree, ln, lc, clen, wfblk, wblk, shft, slc, dflt, dopt, deflateSync, pbf]; };
891
+ // gzip extra
892
+ var gze = function () { return [gzh, gzhl, wbytes, crc, crct]; };
893
+ // gunzip extra
894
+ var guze = function () { return [gzs, gzl]; };
895
+ // zlib extra
896
+ var zle = function () { return [zlh, wbytes, adler]; };
897
+ // unzlib extra
898
+ var zule = function () { return [zls]; };
899
+ // post buf
900
+ var pbf = function (msg) { return postMessage(msg, [msg.buffer]); };
901
+ // get opts
902
+ var gopt = function (o) { return o && {
903
+ out: o.size && new u8(o.size),
904
+ dictionary: o.dictionary
905
+ }; };
906
+ // async helper
907
+ var cbify = function (dat, opts, fns, init, id, cb) {
908
+ var w = wrkr(fns, init, id, function (err, dat) {
909
+ w.terminate();
910
+ cb(err, dat);
911
+ });
912
+ w.postMessage([dat, opts], opts.consume ? [dat.buffer] : []);
913
+ return function () { w.terminate(); };
914
+ };
915
+ // auto stream
916
+ var astrm = function (strm) {
917
+ strm.ondata = function (dat, final) { return postMessage([dat, final], [dat.buffer]); };
918
+ return function (ev) {
919
+ if (ev.data.length) {
920
+ strm.push(ev.data[0], ev.data[1]);
921
+ postMessage([ev.data[0].length]);
922
+ }
923
+ else
924
+ strm.flush();
925
+ };
926
+ };
927
+ // async stream attach
928
+ var astrmify = function (fns, strm, opts, init, id, flush, ext) {
929
+ var t;
930
+ var w = wrkr(fns, init, id, function (err, dat) {
931
+ if (err)
932
+ w.terminate(), strm.ondata.call(strm, err);
933
+ else if (!Array.isArray(dat))
934
+ ext(dat);
935
+ else if (dat.length == 1) {
936
+ strm.queuedSize -= dat[0];
937
+ if (strm.ondrain)
938
+ strm.ondrain(dat[0]);
939
+ }
940
+ else {
941
+ if (dat[1])
942
+ w.terminate();
943
+ strm.ondata.call(strm, err, dat[0], dat[1]);
944
+ }
945
+ });
946
+ w.postMessage(opts);
947
+ strm.queuedSize = 0;
948
+ strm.push = function (d, f) {
949
+ if (!strm.ondata)
950
+ err(5);
951
+ if (t)
952
+ strm.ondata(err(4, 0, 1), null, !!f);
953
+ strm.queuedSize += d.length;
954
+ w.postMessage([d, t = f], [d.buffer]);
955
+ };
956
+ strm.terminate = function () { w.terminate(); };
957
+ if (flush) {
958
+ strm.flush = function () { w.postMessage([]); };
959
+ }
960
+ };
961
+ // read 2 bytes
962
+ var b2 = function (d, b) { return d[b] | (d[b + 1] << 8); };
963
+ // read 4 bytes
964
+ var b4 = function (d, b) { return (d[b] | (d[b + 1] << 8) | (d[b + 2] << 16) | (d[b + 3] << 24)) >>> 0; };
965
+ var b8 = function (d, b) { return b4(d, b) + (b4(d, b + 4) * 4294967296); };
966
+ // write bytes
967
+ var wbytes = function (d, b, v) {
968
+ for (; v; ++b)
969
+ d[b] = v, v >>>= 8;
970
+ };
971
+ // gzip header
972
+ var gzh = function (c, o) {
973
+ var fn = o.filename;
974
+ c[0] = 31, c[1] = 139, c[2] = 8, c[8] = o.level < 2 ? 4 : o.level == 9 ? 2 : 0, c[9] = 3; // assume Unix
975
+ if (o.mtime != 0)
976
+ wbytes(c, 4, Math.floor(new Date(o.mtime || Date.now()) / 1000));
977
+ if (fn) {
978
+ c[3] = 8;
979
+ for (var i = 0; i <= fn.length; ++i)
980
+ c[i + 10] = fn.charCodeAt(i);
981
+ }
982
+ };
983
+ // gzip footer: -8 to -4 = CRC, -4 to -0 is length
984
+ // gzip start
985
+ var gzs = function (d) {
986
+ if (d[0] != 31 || d[1] != 139 || d[2] != 8)
987
+ err(6, 'invalid gzip data');
988
+ var flg = d[3];
989
+ var st = 10;
990
+ if (flg & 4)
991
+ st += (d[10] | d[11] << 8) + 2;
992
+ for (var zs = (flg >> 3 & 1) + (flg >> 4 & 1); zs > 0; zs -= !d[st++])
993
+ ;
994
+ return st + (flg & 2);
995
+ };
996
+ // gzip length
997
+ var gzl = function (d) {
998
+ var l = d.length;
999
+ return (d[l - 4] | d[l - 3] << 8 | d[l - 2] << 16 | d[l - 1] << 24) >>> 0;
1000
+ };
1001
+ // gzip header length
1002
+ var gzhl = function (o) { return 10 + (o.filename ? o.filename.length + 1 : 0); };
1003
+ // zlib header
1004
+ var zlh = function (c, o) {
1005
+ var lv = o.level, fl = lv == 0 ? 0 : lv < 6 ? 1 : lv == 9 ? 3 : 2;
1006
+ c[0] = 120, c[1] = (fl << 6) | (o.dictionary && 32);
1007
+ c[1] |= 31 - ((c[0] << 8) | c[1]) % 31;
1008
+ if (o.dictionary) {
1009
+ var h = adler();
1010
+ h.p(o.dictionary);
1011
+ wbytes(c, 2, h.d());
1012
+ }
1013
+ };
1014
+ // zlib start
1015
+ var zls = function (d, dict) {
1016
+ if ((d[0] & 15) != 8 || (d[0] >> 4) > 7 || ((d[0] << 8 | d[1]) % 31))
1017
+ err(6, 'invalid zlib data');
1018
+ if ((d[1] >> 5 & 1) == +!dict)
1019
+ err(6, 'invalid zlib data: ' + (d[1] & 32 ? 'need' : 'unexpected') + ' dictionary');
1020
+ return (d[1] >> 3 & 4) + 2;
1021
+ };
1022
+ function StrmOpt(opts, cb) {
1023
+ if (typeof opts == 'function')
1024
+ cb = opts, opts = {};
1025
+ this.ondata = cb;
1026
+ return opts;
1027
+ }
1028
+ /**
1029
+ * Streaming DEFLATE compression
1030
+ */
1031
+ var Deflate = /*#__PURE__*/ (function () {
1032
+ function Deflate(opts, cb) {
1033
+ if (typeof opts == 'function')
1034
+ cb = opts, opts = {};
1035
+ this.ondata = cb;
1036
+ this.o = opts || {};
1037
+ this.s = { l: 0, i: 32768, w: 32768, z: 32768 };
1038
+ // Buffer length must always be 0 mod 32768 for index calculations to be correct when modifying head and prev
1039
+ // 98304 = 32768 (lookback) + 65536 (common chunk size)
1040
+ this.b = new u8(98304);
1041
+ if (this.o.dictionary) {
1042
+ var dict = this.o.dictionary.subarray(-32768);
1043
+ this.b.set(dict, 32768 - dict.length);
1044
+ this.s.i = 32768 - dict.length;
1045
+ }
1046
+ }
1047
+ Deflate.prototype.p = function (c, f) {
1048
+ this.ondata(dopt(c, this.o, 0, 0, this.s), f);
1049
+ };
1050
+ /**
1051
+ * Pushes a chunk to be deflated
1052
+ * @param chunk The chunk to push
1053
+ * @param final Whether this is the last chunk
1054
+ */
1055
+ Deflate.prototype.push = function (chunk, final) {
1056
+ if (!this.ondata)
1057
+ err(5);
1058
+ if (this.s.l)
1059
+ err(4);
1060
+ var endLen = chunk.length + this.s.z;
1061
+ if (endLen > this.b.length) {
1062
+ if (endLen > 2 * this.b.length - 32768) {
1063
+ var newBuf = new u8(endLen & -32768);
1064
+ newBuf.set(this.b.subarray(0, this.s.z));
1065
+ this.b = newBuf;
1066
+ }
1067
+ var split = this.b.length - this.s.z;
1068
+ this.b.set(chunk.subarray(0, split), this.s.z);
1069
+ this.s.z = this.b.length;
1070
+ this.p(this.b, false);
1071
+ this.b.set(this.b.subarray(-32768));
1072
+ this.b.set(chunk.subarray(split), 32768);
1073
+ this.s.z = chunk.length - split + 32768;
1074
+ this.s.i = 32766, this.s.w = 32768;
1075
+ }
1076
+ else {
1077
+ this.b.set(chunk, this.s.z);
1078
+ this.s.z += chunk.length;
1079
+ }
1080
+ this.s.l = final & 1;
1081
+ if (this.s.z > this.s.w + 8191 || final) {
1082
+ this.p(this.b, final || false);
1083
+ this.s.w = this.s.i, this.s.i -= 2;
1084
+ }
1085
+ };
1086
+ /**
1087
+ * Flushes buffered uncompressed data. Useful to immediately retrieve the
1088
+ * deflated output for small inputs.
1089
+ */
1090
+ Deflate.prototype.flush = function () {
1091
+ if (!this.ondata)
1092
+ err(5);
1093
+ if (this.s.l)
1094
+ err(4);
1095
+ this.p(this.b, false);
1096
+ this.s.w = this.s.i, this.s.i -= 2;
1097
+ };
1098
+ return Deflate;
1099
+ }());
1100
+ export { Deflate };
1101
+ /**
1102
+ * Asynchronous streaming DEFLATE compression
1103
+ */
1104
+ var AsyncDeflate = /*#__PURE__*/ (function () {
1105
+ function AsyncDeflate(opts, cb) {
1106
+ astrmify([
1107
+ bDflt,
1108
+ function () { return [astrm, Deflate]; }
1109
+ ], this, StrmOpt.call(this, opts, cb), function (ev) {
1110
+ var strm = new Deflate(ev.data);
1111
+ onmessage = astrm(strm);
1112
+ }, 6, 1);
1113
+ }
1114
+ return AsyncDeflate;
1115
+ }());
1116
+ export { AsyncDeflate };
1117
+ export function deflate(data, opts, cb) {
1118
+ if (!cb)
1119
+ cb = opts, opts = {};
1120
+ if (typeof cb != 'function')
1121
+ err(7);
1122
+ return cbify(data, opts, [
1123
+ bDflt,
1124
+ ], function (ev) { return pbf(deflateSync(ev.data[0], ev.data[1])); }, 0, cb);
1125
+ }
1126
+ /**
1127
+ * Compresses data with DEFLATE without any wrapper
1128
+ * @param data The data to compress
1129
+ * @param opts The compression options
1130
+ * @returns The deflated version of the data
1131
+ */
1132
+ export function deflateSync(data, opts) {
1133
+ return dopt(data, opts || {}, 0, 0);
1134
+ }
1135
+ /**
1136
+ * Streaming DEFLATE decompression
1137
+ */
1138
+ var Inflate = /*#__PURE__*/ (function () {
1139
+ function Inflate(opts, cb) {
1140
+ // no StrmOpt here to avoid adding to workerizer
1141
+ if (typeof opts == 'function')
1142
+ cb = opts, opts = {};
1143
+ this.ondata = cb;
1144
+ var dict = opts && opts.dictionary && opts.dictionary.subarray(-32768);
1145
+ this.s = { i: 0, b: dict ? dict.length : 0 };
1146
+ this.o = new u8(32768);
1147
+ this.p = new u8(0);
1148
+ if (dict)
1149
+ this.o.set(dict);
1150
+ }
1151
+ Inflate.prototype.e = function (c) {
1152
+ if (!this.ondata)
1153
+ err(5);
1154
+ if (this.d)
1155
+ err(4);
1156
+ if (!this.p.length)
1157
+ this.p = c;
1158
+ else if (c.length) {
1159
+ var n = new u8(this.p.length + c.length);
1160
+ n.set(this.p), n.set(c, this.p.length), this.p = n;
1161
+ }
1162
+ };
1163
+ Inflate.prototype.c = function (final) {
1164
+ this.s.i = +(this.d = final || false);
1165
+ var bts = this.s.b;
1166
+ var dt = inflt(this.p, this.s, this.o);
1167
+ this.ondata(slc(dt, bts, this.s.b), this.d);
1168
+ this.o = slc(dt, this.s.b - 32768), this.s.b = this.o.length;
1169
+ this.p = slc(this.p, (this.s.p / 8) | 0), this.s.p &= 7;
1170
+ };
1171
+ /**
1172
+ * Pushes a chunk to be inflated
1173
+ * @param chunk The chunk to push
1174
+ * @param final Whether this is the final chunk
1175
+ */
1176
+ Inflate.prototype.push = function (chunk, final) {
1177
+ this.e(chunk), this.c(final);
1178
+ };
1179
+ return Inflate;
1180
+ }());
1181
+ export { Inflate };
1182
+ /**
1183
+ * Asynchronous streaming DEFLATE decompression
1184
+ */
1185
+ var AsyncInflate = /*#__PURE__*/ (function () {
1186
+ function AsyncInflate(opts, cb) {
1187
+ astrmify([
1188
+ bInflt,
1189
+ function () { return [astrm, Inflate]; }
1190
+ ], this, StrmOpt.call(this, opts, cb), function (ev) {
1191
+ var strm = new Inflate(ev.data);
1192
+ onmessage = astrm(strm);
1193
+ }, 7, 0);
1194
+ }
1195
+ return AsyncInflate;
1196
+ }());
1197
+ export { AsyncInflate };
1198
+ export function inflate(data, opts, cb) {
1199
+ if (!cb)
1200
+ cb = opts, opts = {};
1201
+ if (typeof cb != 'function')
1202
+ err(7);
1203
+ return cbify(data, opts, [
1204
+ bInflt
1205
+ ], function (ev) { return pbf(inflateSync(ev.data[0], gopt(ev.data[1]))); }, 1, cb);
1206
+ }
1207
+ /**
1208
+ * Expands DEFLATE data with no wrapper
1209
+ * @param data The data to decompress
1210
+ * @param opts The decompression options
1211
+ * @returns The decompressed version of the data
1212
+ */
1213
+ export function inflateSync(data, opts) {
1214
+ return inflt(data, { i: 2 }, opts && opts.out, opts && opts.dictionary);
1215
+ }
1216
+ // before you yell at me for not just using extends, my reason is that TS inheritance is hard to workerize.
1217
+ /**
1218
+ * Streaming GZIP compression
1219
+ */
1220
+ var Gzip = /*#__PURE__*/ (function () {
1221
+ function Gzip(opts, cb) {
1222
+ this.c = crc();
1223
+ this.l = 0;
1224
+ this.v = 1;
1225
+ Deflate.call(this, opts, cb);
1226
+ }
1227
+ /**
1228
+ * Pushes a chunk to be GZIPped
1229
+ * @param chunk The chunk to push
1230
+ * @param final Whether this is the last chunk
1231
+ */
1232
+ Gzip.prototype.push = function (chunk, final) {
1233
+ this.c.p(chunk);
1234
+ this.l += chunk.length;
1235
+ Deflate.prototype.push.call(this, chunk, final);
1236
+ };
1237
+ Gzip.prototype.p = function (c, f) {
1238
+ var raw = dopt(c, this.o, this.v && gzhl(this.o), f && 8, this.s);
1239
+ if (this.v)
1240
+ gzh(raw, this.o), this.v = 0;
1241
+ if (f)
1242
+ wbytes(raw, raw.length - 8, this.c.d()), wbytes(raw, raw.length - 4, this.l);
1243
+ this.ondata(raw, f);
1244
+ };
1245
+ /**
1246
+ * Flushes buffered uncompressed data. Useful to immediately retrieve the
1247
+ * GZIPped output for small inputs.
1248
+ */
1249
+ Gzip.prototype.flush = function () {
1250
+ Deflate.prototype.flush.call(this);
1251
+ };
1252
+ return Gzip;
1253
+ }());
1254
+ export { Gzip };
1255
+ /**
1256
+ * Asynchronous streaming GZIP compression
1257
+ */
1258
+ var AsyncGzip = /*#__PURE__*/ (function () {
1259
+ function AsyncGzip(opts, cb) {
1260
+ astrmify([
1261
+ bDflt,
1262
+ gze,
1263
+ function () { return [astrm, Deflate, Gzip]; }
1264
+ ], this, StrmOpt.call(this, opts, cb), function (ev) {
1265
+ var strm = new Gzip(ev.data);
1266
+ onmessage = astrm(strm);
1267
+ }, 8, 1);
1268
+ }
1269
+ return AsyncGzip;
1270
+ }());
1271
+ export { AsyncGzip };
1272
+ export function gzip(data, opts, cb) {
1273
+ if (!cb)
1274
+ cb = opts, opts = {};
1275
+ if (typeof cb != 'function')
1276
+ err(7);
1277
+ return cbify(data, opts, [
1278
+ bDflt,
1279
+ gze,
1280
+ function () { return [gzipSync]; }
1281
+ ], function (ev) { return pbf(gzipSync(ev.data[0], ev.data[1])); }, 2, cb);
1282
+ }
1283
+ /**
1284
+ * Compresses data with GZIP
1285
+ * @param data The data to compress
1286
+ * @param opts The compression options
1287
+ * @returns The gzipped version of the data
1288
+ */
1289
+ export function gzipSync(data, opts) {
1290
+ if (!opts)
1291
+ opts = {};
1292
+ var c = crc(), l = data.length;
1293
+ c.p(data);
1294
+ var d = dopt(data, opts, gzhl(opts), 8), s = d.length;
1295
+ return gzh(d, opts), wbytes(d, s - 8, c.d()), wbytes(d, s - 4, l), d;
1296
+ }
1297
+ /**
1298
+ * Streaming single or multi-member GZIP decompression
1299
+ */
1300
+ var Gunzip = /*#__PURE__*/ (function () {
1301
+ function Gunzip(opts, cb) {
1302
+ this.v = 1;
1303
+ this.r = 0;
1304
+ Inflate.call(this, opts, cb);
1305
+ }
1306
+ /**
1307
+ * Pushes a chunk to be GUNZIPped
1308
+ * @param chunk The chunk to push
1309
+ * @param final Whether this is the last chunk
1310
+ */
1311
+ Gunzip.prototype.push = function (chunk, final) {
1312
+ Inflate.prototype.e.call(this, chunk);
1313
+ this.r += chunk.length;
1314
+ if (this.v) {
1315
+ var p = this.p.subarray(this.v - 1);
1316
+ var s = p.length > 3 ? gzs(p) : 4;
1317
+ if (s > p.length) {
1318
+ if (!final)
1319
+ return;
1320
+ }
1321
+ else if (this.v > 1 && this.onmember) {
1322
+ this.onmember(this.r - p.length);
1323
+ }
1324
+ this.p = p.subarray(s), this.v = 0;
1325
+ }
1326
+ // necessary to prevent TS from using the closure value
1327
+ // This allows for workerization to function correctly
1328
+ Inflate.prototype.c.call(this, final);
1329
+ // process concatenated GZIP
1330
+ if (this.s.f && !this.s.l && !final) {
1331
+ this.v = shft(this.s.p) + 9;
1332
+ this.s = { i: 0 };
1333
+ this.o = new u8(0);
1334
+ this.push(new u8(0), final);
1335
+ }
1336
+ };
1337
+ return Gunzip;
1338
+ }());
1339
+ export { Gunzip };
1340
+ /**
1341
+ * Asynchronous streaming single or multi-member GZIP decompression
1342
+ */
1343
+ var AsyncGunzip = /*#__PURE__*/ (function () {
1344
+ function AsyncGunzip(opts, cb) {
1345
+ var _this = this;
1346
+ astrmify([
1347
+ bInflt,
1348
+ guze,
1349
+ function () { return [astrm, Inflate, Gunzip]; }
1350
+ ], this, StrmOpt.call(this, opts, cb), function (ev) {
1351
+ var strm = new Gunzip(ev.data);
1352
+ strm.onmember = function (offset) { return postMessage(offset); };
1353
+ onmessage = astrm(strm);
1354
+ }, 9, 0, function (offset) { return _this.onmember && _this.onmember(offset); });
1355
+ }
1356
+ return AsyncGunzip;
1357
+ }());
1358
+ export { AsyncGunzip };
1359
+ export function gunzip(data, opts, cb) {
1360
+ if (!cb)
1361
+ cb = opts, opts = {};
1362
+ if (typeof cb != 'function')
1363
+ err(7);
1364
+ return cbify(data, opts, [
1365
+ bInflt,
1366
+ guze,
1367
+ function () { return [gunzipSync]; }
1368
+ ], function (ev) { return pbf(gunzipSync(ev.data[0], ev.data[1])); }, 3, cb);
1369
+ }
1370
+ /**
1371
+ * Expands GZIP data
1372
+ * @param data The data to decompress
1373
+ * @param opts The decompression options
1374
+ * @returns The decompressed version of the data
1375
+ */
1376
+ export function gunzipSync(data, opts) {
1377
+ var st = gzs(data);
1378
+ if (st + 8 > data.length)
1379
+ err(6, 'invalid gzip data');
1380
+ return inflt(data.subarray(st, -8), { i: 2 }, opts && opts.out || new u8(gzl(data)), opts && opts.dictionary);
1381
+ }
1382
+ /**
1383
+ * Streaming Zlib compression
1384
+ */
1385
+ var Zlib = /*#__PURE__*/ (function () {
1386
+ function Zlib(opts, cb) {
1387
+ this.c = adler();
1388
+ this.v = 1;
1389
+ Deflate.call(this, opts, cb);
1390
+ }
1391
+ /**
1392
+ * Pushes a chunk to be zlibbed
1393
+ * @param chunk The chunk to push
1394
+ * @param final Whether this is the last chunk
1395
+ */
1396
+ Zlib.prototype.push = function (chunk, final) {
1397
+ this.c.p(chunk);
1398
+ Deflate.prototype.push.call(this, chunk, final);
1399
+ };
1400
+ Zlib.prototype.p = function (c, f) {
1401
+ var raw = dopt(c, this.o, this.v && (this.o.dictionary ? 6 : 2), f && 4, this.s);
1402
+ if (this.v)
1403
+ zlh(raw, this.o), this.v = 0;
1404
+ if (f)
1405
+ wbytes(raw, raw.length - 4, this.c.d());
1406
+ this.ondata(raw, f);
1407
+ };
1408
+ /**
1409
+ * Flushes buffered uncompressed data. Useful to immediately retrieve the
1410
+ * zlibbed output for small inputs.
1411
+ */
1412
+ Zlib.prototype.flush = function () {
1413
+ Deflate.prototype.flush.call(this);
1414
+ };
1415
+ return Zlib;
1416
+ }());
1417
+ export { Zlib };
1418
+ /**
1419
+ * Asynchronous streaming Zlib compression
1420
+ */
1421
+ var AsyncZlib = /*#__PURE__*/ (function () {
1422
+ function AsyncZlib(opts, cb) {
1423
+ astrmify([
1424
+ bDflt,
1425
+ zle,
1426
+ function () { return [astrm, Deflate, Zlib]; }
1427
+ ], this, StrmOpt.call(this, opts, cb), function (ev) {
1428
+ var strm = new Zlib(ev.data);
1429
+ onmessage = astrm(strm);
1430
+ }, 10, 1);
1431
+ }
1432
+ return AsyncZlib;
1433
+ }());
1434
+ export { AsyncZlib };
1435
+ export function zlib(data, opts, cb) {
1436
+ if (!cb)
1437
+ cb = opts, opts = {};
1438
+ if (typeof cb != 'function')
1439
+ err(7);
1440
+ return cbify(data, opts, [
1441
+ bDflt,
1442
+ zle,
1443
+ function () { return [zlibSync]; }
1444
+ ], function (ev) { return pbf(zlibSync(ev.data[0], ev.data[1])); }, 4, cb);
1445
+ }
1446
+ /**
1447
+ * Compress data with Zlib
1448
+ * @param data The data to compress
1449
+ * @param opts The compression options
1450
+ * @returns The zlib-compressed version of the data
1451
+ */
1452
+ export function zlibSync(data, opts) {
1453
+ if (!opts)
1454
+ opts = {};
1455
+ var a = adler();
1456
+ a.p(data);
1457
+ var d = dopt(data, opts, opts.dictionary ? 6 : 2, 4);
1458
+ return zlh(d, opts), wbytes(d, d.length - 4, a.d()), d;
1459
+ }
1460
+ /**
1461
+ * Streaming Zlib decompression
1462
+ */
1463
+ var Unzlib = /*#__PURE__*/ (function () {
1464
+ function Unzlib(opts, cb) {
1465
+ Inflate.call(this, opts, cb);
1466
+ this.v = opts && opts.dictionary ? 2 : 1;
1467
+ }
1468
+ /**
1469
+ * Pushes a chunk to be unzlibbed
1470
+ * @param chunk The chunk to push
1471
+ * @param final Whether this is the last chunk
1472
+ */
1473
+ Unzlib.prototype.push = function (chunk, final) {
1474
+ Inflate.prototype.e.call(this, chunk);
1475
+ if (this.v) {
1476
+ if (this.p.length < 6 && !final)
1477
+ return;
1478
+ this.p = this.p.subarray(zls(this.p, this.v - 1)), this.v = 0;
1479
+ }
1480
+ if (final) {
1481
+ if (this.p.length < 4)
1482
+ err(6, 'invalid zlib data');
1483
+ this.p = this.p.subarray(0, -4);
1484
+ }
1485
+ // necessary to prevent TS from using the closure value
1486
+ // This allows for workerization to function correctly
1487
+ Inflate.prototype.c.call(this, final);
1488
+ };
1489
+ return Unzlib;
1490
+ }());
1491
+ export { Unzlib };
1492
+ /**
1493
+ * Asynchronous streaming Zlib decompression
1494
+ */
1495
+ var AsyncUnzlib = /*#__PURE__*/ (function () {
1496
+ function AsyncUnzlib(opts, cb) {
1497
+ astrmify([
1498
+ bInflt,
1499
+ zule,
1500
+ function () { return [astrm, Inflate, Unzlib]; }
1501
+ ], this, StrmOpt.call(this, opts, cb), function (ev) {
1502
+ var strm = new Unzlib(ev.data);
1503
+ onmessage = astrm(strm);
1504
+ }, 11, 0);
1505
+ }
1506
+ return AsyncUnzlib;
1507
+ }());
1508
+ export { AsyncUnzlib };
1509
+ export function unzlib(data, opts, cb) {
1510
+ if (!cb)
1511
+ cb = opts, opts = {};
1512
+ if (typeof cb != 'function')
1513
+ err(7);
1514
+ return cbify(data, opts, [
1515
+ bInflt,
1516
+ zule,
1517
+ function () { return [unzlibSync]; }
1518
+ ], function (ev) { return pbf(unzlibSync(ev.data[0], gopt(ev.data[1]))); }, 5, cb);
1519
+ }
1520
+ /**
1521
+ * Expands Zlib data
1522
+ * @param data The data to decompress
1523
+ * @param opts The decompression options
1524
+ * @returns The decompressed version of the data
1525
+ */
1526
+ export function unzlibSync(data, opts) {
1527
+ return inflt(data.subarray(zls(data, opts && opts.dictionary), -4), { i: 2 }, opts && opts.out, opts && opts.dictionary);
1528
+ }
1529
+ // Default algorithm for compression (used because having a known output size allows faster decompression)
1530
+ export { gzip as compress, AsyncGzip as AsyncCompress };
1531
+ export { gzipSync as compressSync, Gzip as Compress };
1532
+ /**
1533
+ * Streaming GZIP, Zlib, or raw DEFLATE decompression
1534
+ */
1535
+ var Decompress = /*#__PURE__*/ (function () {
1536
+ function Decompress(opts, cb) {
1537
+ this.o = StrmOpt.call(this, opts, cb) || {};
1538
+ this.G = Gunzip;
1539
+ this.I = Inflate;
1540
+ this.Z = Unzlib;
1541
+ }
1542
+ // init substream
1543
+ // overriden by AsyncDecompress
1544
+ Decompress.prototype.i = function () {
1545
+ var _this = this;
1546
+ this.s.ondata = function (dat, final) {
1547
+ _this.ondata(dat, final);
1548
+ };
1549
+ };
1550
+ /**
1551
+ * Pushes a chunk to be decompressed
1552
+ * @param chunk The chunk to push
1553
+ * @param final Whether this is the last chunk
1554
+ */
1555
+ Decompress.prototype.push = function (chunk, final) {
1556
+ if (!this.ondata)
1557
+ err(5);
1558
+ if (!this.s) {
1559
+ if (this.p && this.p.length) {
1560
+ var n = new u8(this.p.length + chunk.length);
1561
+ n.set(this.p), n.set(chunk, this.p.length);
1562
+ }
1563
+ else
1564
+ this.p = chunk;
1565
+ if (this.p.length > 2) {
1566
+ this.s = (this.p[0] == 31 && this.p[1] == 139 && this.p[2] == 8)
1567
+ ? new this.G(this.o)
1568
+ : ((this.p[0] & 15) != 8 || (this.p[0] >> 4) > 7 || ((this.p[0] << 8 | this.p[1]) % 31))
1569
+ ? new this.I(this.o)
1570
+ : new this.Z(this.o);
1571
+ this.i();
1572
+ this.s.push(this.p, final);
1573
+ this.p = null;
1574
+ }
1575
+ }
1576
+ else
1577
+ this.s.push(chunk, final);
1578
+ };
1579
+ return Decompress;
1580
+ }());
1581
+ export { Decompress };
1582
+ /**
1583
+ * Asynchronous streaming GZIP, Zlib, or raw DEFLATE decompression
1584
+ */
1585
+ var AsyncDecompress = /*#__PURE__*/ (function () {
1586
+ function AsyncDecompress(opts, cb) {
1587
+ Decompress.call(this, opts, cb);
1588
+ this.queuedSize = 0;
1589
+ this.G = AsyncGunzip;
1590
+ this.I = AsyncInflate;
1591
+ this.Z = AsyncUnzlib;
1592
+ }
1593
+ AsyncDecompress.prototype.i = function () {
1594
+ var _this = this;
1595
+ this.s.ondata = function (err, dat, final) {
1596
+ _this.ondata(err, dat, final);
1597
+ };
1598
+ this.s.ondrain = function (size) {
1599
+ _this.queuedSize -= size;
1600
+ if (_this.ondrain)
1601
+ _this.ondrain(size);
1602
+ };
1603
+ };
1604
+ /**
1605
+ * Pushes a chunk to be decompressed
1606
+ * @param chunk The chunk to push
1607
+ * @param final Whether this is the last chunk
1608
+ */
1609
+ AsyncDecompress.prototype.push = function (chunk, final) {
1610
+ this.queuedSize += chunk.length;
1611
+ Decompress.prototype.push.call(this, chunk, final);
1612
+ };
1613
+ return AsyncDecompress;
1614
+ }());
1615
+ export { AsyncDecompress };
1616
+ export function decompress(data, opts, cb) {
1617
+ if (!cb)
1618
+ cb = opts, opts = {};
1619
+ if (typeof cb != 'function')
1620
+ err(7);
1621
+ return (data[0] == 31 && data[1] == 139 && data[2] == 8)
1622
+ ? gunzip(data, opts, cb)
1623
+ : ((data[0] & 15) != 8 || (data[0] >> 4) > 7 || ((data[0] << 8 | data[1]) % 31))
1624
+ ? inflate(data, opts, cb)
1625
+ : unzlib(data, opts, cb);
1626
+ }
1627
+ /**
1628
+ * Expands compressed GZIP, Zlib, or raw DEFLATE data, automatically detecting the format
1629
+ * @param data The data to decompress
1630
+ * @param opts The decompression options
1631
+ * @returns The decompressed version of the data
1632
+ */
1633
+ export function decompressSync(data, opts) {
1634
+ return (data[0] == 31 && data[1] == 139 && data[2] == 8)
1635
+ ? gunzipSync(data, opts)
1636
+ : ((data[0] & 15) != 8 || (data[0] >> 4) > 7 || ((data[0] << 8 | data[1]) % 31))
1637
+ ? inflateSync(data, opts)
1638
+ : unzlibSync(data, opts);
1639
+ }
1640
+ // flatten a directory structure
1641
+ var fltn = function (d, p, t, o) {
1642
+ for (var k in d) {
1643
+ var val = d[k], n = p + k, op = o;
1644
+ if (Array.isArray(val))
1645
+ op = mrg(o, val[1]), val = val[0];
1646
+ if (val instanceof u8)
1647
+ t[n] = [val, op];
1648
+ else {
1649
+ t[n += '/'] = [new u8(0), op];
1650
+ fltn(val, n, t, o);
1651
+ }
1652
+ }
1653
+ };
1654
+ // text encoder
1655
+ var te = typeof TextEncoder != 'undefined' && /*#__PURE__*/ new TextEncoder();
1656
+ // text decoder
1657
+ var td = typeof TextDecoder != 'undefined' && /*#__PURE__*/ new TextDecoder();
1658
+ // text decoder stream
1659
+ var tds = 0;
1660
+ try {
1661
+ td.decode(et, { stream: true });
1662
+ tds = 1;
1663
+ }
1664
+ catch (e) { }
1665
+ // decode UTF8
1666
+ var dutf8 = function (d) {
1667
+ for (var r = '', i = 0;;) {
1668
+ var c = d[i++];
1669
+ var eb = (c > 127) + (c > 223) + (c > 239);
1670
+ if (i + eb > d.length)
1671
+ return { s: r, r: slc(d, i - 1) };
1672
+ if (!eb)
1673
+ r += String.fromCharCode(c);
1674
+ else if (eb == 3) {
1675
+ c = ((c & 15) << 18 | (d[i++] & 63) << 12 | (d[i++] & 63) << 6 | (d[i++] & 63)) - 65536,
1676
+ r += String.fromCharCode(55296 | (c >> 10), 56320 | (c & 1023));
1677
+ }
1678
+ else if (eb & 1)
1679
+ r += String.fromCharCode((c & 31) << 6 | (d[i++] & 63));
1680
+ else
1681
+ r += String.fromCharCode((c & 15) << 12 | (d[i++] & 63) << 6 | (d[i++] & 63));
1682
+ }
1683
+ };
1684
+ /**
1685
+ * Streaming UTF-8 decoding
1686
+ */
1687
+ var DecodeUTF8 = /*#__PURE__*/ (function () {
1688
+ /**
1689
+ * Creates a UTF-8 decoding stream
1690
+ * @param cb The callback to call whenever data is decoded
1691
+ */
1692
+ function DecodeUTF8(cb) {
1693
+ this.ondata = cb;
1694
+ if (tds)
1695
+ this.t = new TextDecoder();
1696
+ else
1697
+ this.p = et;
1698
+ }
1699
+ /**
1700
+ * Pushes a chunk to be decoded from UTF-8 binary
1701
+ * @param chunk The chunk to push
1702
+ * @param final Whether this is the last chunk
1703
+ */
1704
+ DecodeUTF8.prototype.push = function (chunk, final) {
1705
+ if (!this.ondata)
1706
+ err(5);
1707
+ final = !!final;
1708
+ if (this.t) {
1709
+ this.ondata(this.t.decode(chunk, { stream: true }), final);
1710
+ if (final) {
1711
+ if (this.t.decode().length)
1712
+ err(8);
1713
+ this.t = null;
1714
+ }
1715
+ return;
1716
+ }
1717
+ if (!this.p)
1718
+ err(4);
1719
+ var dat = new u8(this.p.length + chunk.length);
1720
+ dat.set(this.p);
1721
+ dat.set(chunk, this.p.length);
1722
+ var _a = dutf8(dat), s = _a.s, r = _a.r;
1723
+ if (final) {
1724
+ if (r.length)
1725
+ err(8);
1726
+ this.p = null;
1727
+ }
1728
+ else
1729
+ this.p = r;
1730
+ this.ondata(s, final);
1731
+ };
1732
+ return DecodeUTF8;
1733
+ }());
1734
+ export { DecodeUTF8 };
1735
+ /**
1736
+ * Streaming UTF-8 encoding
1737
+ */
1738
+ var EncodeUTF8 = /*#__PURE__*/ (function () {
1739
+ /**
1740
+ * Creates a UTF-8 decoding stream
1741
+ * @param cb The callback to call whenever data is encoded
1742
+ */
1743
+ function EncodeUTF8(cb) {
1744
+ this.ondata = cb;
1745
+ }
1746
+ /**
1747
+ * Pushes a chunk to be encoded to UTF-8
1748
+ * @param chunk The string data to push
1749
+ * @param final Whether this is the last chunk
1750
+ */
1751
+ EncodeUTF8.prototype.push = function (chunk, final) {
1752
+ if (!this.ondata)
1753
+ err(5);
1754
+ if (this.d)
1755
+ err(4);
1756
+ this.ondata(strToU8(chunk), this.d = final || false);
1757
+ };
1758
+ return EncodeUTF8;
1759
+ }());
1760
+ export { EncodeUTF8 };
1761
+ /**
1762
+ * Converts a string into a Uint8Array for use with compression/decompression methods
1763
+ * @param str The string to encode
1764
+ * @param latin1 Whether or not to interpret the data as Latin-1. This should
1765
+ * not need to be true unless decoding a binary string.
1766
+ * @returns The string encoded in UTF-8/Latin-1 binary
1767
+ */
1768
+ export function strToU8(str, latin1) {
1769
+ if (latin1) {
1770
+ var ar_1 = new u8(str.length);
1771
+ for (var i = 0; i < str.length; ++i)
1772
+ ar_1[i] = str.charCodeAt(i);
1773
+ return ar_1;
1774
+ }
1775
+ if (te)
1776
+ return te.encode(str);
1777
+ var l = str.length;
1778
+ var ar = new u8(str.length + (str.length >> 1));
1779
+ var ai = 0;
1780
+ var w = function (v) { ar[ai++] = v; };
1781
+ for (var i = 0; i < l; ++i) {
1782
+ if (ai + 5 > ar.length) {
1783
+ var n = new u8(ai + 8 + ((l - i) << 1));
1784
+ n.set(ar);
1785
+ ar = n;
1786
+ }
1787
+ var c = str.charCodeAt(i);
1788
+ if (c < 128 || latin1)
1789
+ w(c);
1790
+ else if (c < 2048)
1791
+ w(192 | (c >> 6)), w(128 | (c & 63));
1792
+ else if (c > 55295 && c < 57344)
1793
+ c = 65536 + (c & 1023 << 10) | (str.charCodeAt(++i) & 1023),
1794
+ w(240 | (c >> 18)), w(128 | ((c >> 12) & 63)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63));
1795
+ else
1796
+ w(224 | (c >> 12)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63));
1797
+ }
1798
+ return slc(ar, 0, ai);
1799
+ }
1800
+ /**
1801
+ * Converts a Uint8Array to a string
1802
+ * @param dat The data to decode to string
1803
+ * @param latin1 Whether or not to interpret the data as Latin-1. This should
1804
+ * not need to be true unless encoding to binary string.
1805
+ * @returns The original UTF-8/Latin-1 string
1806
+ */
1807
+ export function strFromU8(dat, latin1) {
1808
+ if (latin1) {
1809
+ var r = '';
1810
+ for (var i = 0; i < dat.length; i += 16384)
1811
+ r += String.fromCharCode.apply(null, dat.subarray(i, i + 16384));
1812
+ return r;
1813
+ }
1814
+ else if (td) {
1815
+ return td.decode(dat);
1816
+ }
1817
+ else {
1818
+ var _a = dutf8(dat), s = _a.s, r = _a.r;
1819
+ if (r.length)
1820
+ err(8);
1821
+ return s;
1822
+ }
1823
+ }
1824
+ ;
1825
+ // deflate bit flag
1826
+ var dbf = function (l) { return l == 1 ? 3 : l < 6 ? 2 : l == 9 ? 1 : 0; };
1827
+ // skip local zip header
1828
+ var slzh = function (d, b) { return b + 30 + b2(d, b + 26) + b2(d, b + 28); };
1829
+ // read zip header
1830
+ var zh = function (d, b, z) {
1831
+ var fnl = b2(d, b + 28), fn = strFromU8(d.subarray(b + 46, b + 46 + fnl), !(b2(d, b + 8) & 2048)), es = b + 46 + fnl, bs = b4(d, b + 20);
1832
+ var _a = z && bs == 4294967295 ? z64e(d, es) : [bs, b4(d, b + 24), b4(d, b + 42)], sc = _a[0], su = _a[1], off = _a[2];
1833
+ return [b2(d, b + 10), sc, su, fn, es + b2(d, b + 30) + b2(d, b + 32), off];
1834
+ };
1835
+ // read zip64 extra field
1836
+ var z64e = function (d, b) {
1837
+ for (; b2(d, b) != 1; b += 4 + b2(d, b + 2))
1838
+ ;
1839
+ return [b8(d, b + 12), b8(d, b + 4), b8(d, b + 20)];
1840
+ };
1841
+ // extra field length
1842
+ var exfl = function (ex) {
1843
+ var le = 0;
1844
+ if (ex) {
1845
+ for (var k in ex) {
1846
+ var l = ex[k].length;
1847
+ if (l > 65535)
1848
+ err(9);
1849
+ le += l + 4;
1850
+ }
1851
+ }
1852
+ return le;
1853
+ };
1854
+ // write zip header
1855
+ var wzh = function (d, b, f, fn, u, c, ce, co) {
1856
+ var fl = fn.length, ex = f.extra, col = co && co.length;
1857
+ var exl = exfl(ex);
1858
+ wbytes(d, b, ce != null ? 0x2014B50 : 0x4034B50), b += 4;
1859
+ if (ce != null)
1860
+ d[b++] = 20, d[b++] = f.os;
1861
+ d[b] = 20, b += 2; // spec compliance? what's that?
1862
+ d[b++] = (f.flag << 1) | (c < 0 && 8), d[b++] = u && 8;
1863
+ d[b++] = f.compression & 255, d[b++] = f.compression >> 8;
1864
+ var dt = new Date(f.mtime == null ? Date.now() : f.mtime), y = dt.getFullYear() - 1980;
1865
+ if (y < 0 || y > 119)
1866
+ err(10);
1867
+ wbytes(d, b, (y << 25) | ((dt.getMonth() + 1) << 21) | (dt.getDate() << 16) | (dt.getHours() << 11) | (dt.getMinutes() << 5) | (dt.getSeconds() >> 1)), b += 4;
1868
+ if (c != -1) {
1869
+ wbytes(d, b, f.crc);
1870
+ wbytes(d, b + 4, c < 0 ? -c - 2 : c);
1871
+ wbytes(d, b + 8, f.size);
1872
+ }
1873
+ wbytes(d, b + 12, fl);
1874
+ wbytes(d, b + 14, exl), b += 16;
1875
+ if (ce != null) {
1876
+ wbytes(d, b, col);
1877
+ wbytes(d, b + 6, f.attrs);
1878
+ wbytes(d, b + 10, ce), b += 14;
1879
+ }
1880
+ d.set(fn, b);
1881
+ b += fl;
1882
+ if (exl) {
1883
+ for (var k in ex) {
1884
+ var exf = ex[k], l = exf.length;
1885
+ wbytes(d, b, +k);
1886
+ wbytes(d, b + 2, l);
1887
+ d.set(exf, b + 4), b += 4 + l;
1888
+ }
1889
+ }
1890
+ if (col)
1891
+ d.set(co, b), b += col;
1892
+ return b;
1893
+ };
1894
+ // write zip footer (end of central directory)
1895
+ var wzf = function (o, b, c, d, e) {
1896
+ wbytes(o, b, 0x6054B50); // skip disk
1897
+ wbytes(o, b + 8, c);
1898
+ wbytes(o, b + 10, c);
1899
+ wbytes(o, b + 12, d);
1900
+ wbytes(o, b + 16, e);
1901
+ };
1902
+ /**
1903
+ * A pass-through stream to keep data uncompressed in a ZIP archive.
1904
+ */
1905
+ var ZipPassThrough = /*#__PURE__*/ (function () {
1906
+ /**
1907
+ * Creates a pass-through stream that can be added to ZIP archives
1908
+ * @param filename The filename to associate with this data stream
1909
+ */
1910
+ function ZipPassThrough(filename) {
1911
+ this.filename = filename;
1912
+ this.c = crc();
1913
+ this.size = 0;
1914
+ this.compression = 0;
1915
+ }
1916
+ /**
1917
+ * Processes a chunk and pushes to the output stream. You can override this
1918
+ * method in a subclass for custom behavior, but by default this passes
1919
+ * the data through. You must call this.ondata(err, chunk, final) at some
1920
+ * point in this method.
1921
+ * @param chunk The chunk to process
1922
+ * @param final Whether this is the last chunk
1923
+ */
1924
+ ZipPassThrough.prototype.process = function (chunk, final) {
1925
+ this.ondata(null, chunk, final);
1926
+ };
1927
+ /**
1928
+ * Pushes a chunk to be added. If you are subclassing this with a custom
1929
+ * compression algorithm, note that you must push data from the source
1930
+ * file only, pre-compression.
1931
+ * @param chunk The chunk to push
1932
+ * @param final Whether this is the last chunk
1933
+ */
1934
+ ZipPassThrough.prototype.push = function (chunk, final) {
1935
+ if (!this.ondata)
1936
+ err(5);
1937
+ this.c.p(chunk);
1938
+ this.size += chunk.length;
1939
+ if (final)
1940
+ this.crc = this.c.d();
1941
+ this.process(chunk, final || false);
1942
+ };
1943
+ return ZipPassThrough;
1944
+ }());
1945
+ export { ZipPassThrough };
1946
+ // I don't extend because TypeScript extension adds 1kB of runtime bloat
1947
+ /**
1948
+ * Streaming DEFLATE compression for ZIP archives. Prefer using AsyncZipDeflate
1949
+ * for better performance
1950
+ */
1951
+ var ZipDeflate = /*#__PURE__*/ (function () {
1952
+ /**
1953
+ * Creates a DEFLATE stream that can be added to ZIP archives
1954
+ * @param filename The filename to associate with this data stream
1955
+ * @param opts The compression options
1956
+ */
1957
+ function ZipDeflate(filename, opts) {
1958
+ var _this = this;
1959
+ if (!opts)
1960
+ opts = {};
1961
+ ZipPassThrough.call(this, filename);
1962
+ this.d = new Deflate(opts, function (dat, final) {
1963
+ _this.ondata(null, dat, final);
1964
+ });
1965
+ this.compression = 8;
1966
+ this.flag = dbf(opts.level);
1967
+ }
1968
+ ZipDeflate.prototype.process = function (chunk, final) {
1969
+ try {
1970
+ this.d.push(chunk, final);
1971
+ }
1972
+ catch (e) {
1973
+ this.ondata(e, null, final);
1974
+ }
1975
+ };
1976
+ /**
1977
+ * Pushes a chunk to be deflated
1978
+ * @param chunk The chunk to push
1979
+ * @param final Whether this is the last chunk
1980
+ */
1981
+ ZipDeflate.prototype.push = function (chunk, final) {
1982
+ ZipPassThrough.prototype.push.call(this, chunk, final);
1983
+ };
1984
+ return ZipDeflate;
1985
+ }());
1986
+ export { ZipDeflate };
1987
+ /**
1988
+ * Asynchronous streaming DEFLATE compression for ZIP archives
1989
+ */
1990
+ var AsyncZipDeflate = /*#__PURE__*/ (function () {
1991
+ /**
1992
+ * Creates an asynchronous DEFLATE stream that can be added to ZIP archives
1993
+ * @param filename The filename to associate with this data stream
1994
+ * @param opts The compression options
1995
+ */
1996
+ function AsyncZipDeflate(filename, opts) {
1997
+ var _this = this;
1998
+ if (!opts)
1999
+ opts = {};
2000
+ ZipPassThrough.call(this, filename);
2001
+ this.d = new AsyncDeflate(opts, function (err, dat, final) {
2002
+ _this.ondata(err, dat, final);
2003
+ });
2004
+ this.compression = 8;
2005
+ this.flag = dbf(opts.level);
2006
+ this.terminate = this.d.terminate;
2007
+ }
2008
+ AsyncZipDeflate.prototype.process = function (chunk, final) {
2009
+ this.d.push(chunk, final);
2010
+ };
2011
+ /**
2012
+ * Pushes a chunk to be deflated
2013
+ * @param chunk The chunk to push
2014
+ * @param final Whether this is the last chunk
2015
+ */
2016
+ AsyncZipDeflate.prototype.push = function (chunk, final) {
2017
+ ZipPassThrough.prototype.push.call(this, chunk, final);
2018
+ };
2019
+ return AsyncZipDeflate;
2020
+ }());
2021
+ export { AsyncZipDeflate };
2022
+ // TODO: Better tree shaking
2023
+ /**
2024
+ * A zippable archive to which files can incrementally be added
2025
+ */
2026
+ var Zip = /*#__PURE__*/ (function () {
2027
+ /**
2028
+ * Creates an empty ZIP archive to which files can be added
2029
+ * @param cb The callback to call whenever data for the generated ZIP archive
2030
+ * is available
2031
+ */
2032
+ function Zip(cb) {
2033
+ this.ondata = cb;
2034
+ this.u = [];
2035
+ this.d = 1;
2036
+ }
2037
+ /**
2038
+ * Adds a file to the ZIP archive
2039
+ * @param file The file stream to add
2040
+ */
2041
+ Zip.prototype.add = function (file) {
2042
+ var _this = this;
2043
+ if (!this.ondata)
2044
+ err(5);
2045
+ // finishing or finished
2046
+ if (this.d & 2)
2047
+ this.ondata(err(4 + (this.d & 1) * 8, 0, 1), null, false);
2048
+ else {
2049
+ var f = strToU8(file.filename), fl_1 = f.length;
2050
+ var com = file.comment, o = com && strToU8(com);
2051
+ var u = fl_1 != file.filename.length || (o && (com.length != o.length));
2052
+ var hl_1 = fl_1 + exfl(file.extra) + 30;
2053
+ if (fl_1 > 65535)
2054
+ this.ondata(err(11, 0, 1), null, false);
2055
+ var header = new u8(hl_1);
2056
+ wzh(header, 0, file, f, u, -1);
2057
+ var chks_1 = [header];
2058
+ var pAll_1 = function () {
2059
+ for (var _i = 0, chks_2 = chks_1; _i < chks_2.length; _i++) {
2060
+ var chk = chks_2[_i];
2061
+ _this.ondata(null, chk, false);
2062
+ }
2063
+ chks_1 = [];
2064
+ };
2065
+ var tr_1 = this.d;
2066
+ this.d = 0;
2067
+ var ind_1 = this.u.length;
2068
+ var uf_1 = mrg(file, {
2069
+ f: f,
2070
+ u: u,
2071
+ o: o,
2072
+ t: function () {
2073
+ if (file.terminate)
2074
+ file.terminate();
2075
+ },
2076
+ r: function () {
2077
+ pAll_1();
2078
+ if (tr_1) {
2079
+ var nxt = _this.u[ind_1 + 1];
2080
+ if (nxt)
2081
+ nxt.r();
2082
+ else
2083
+ _this.d = 1;
2084
+ }
2085
+ tr_1 = 1;
2086
+ }
2087
+ });
2088
+ var cl_1 = 0;
2089
+ file.ondata = function (err, dat, final) {
2090
+ if (err) {
2091
+ _this.ondata(err, dat, final);
2092
+ _this.terminate();
2093
+ }
2094
+ else {
2095
+ cl_1 += dat.length;
2096
+ chks_1.push(dat);
2097
+ if (final) {
2098
+ var dd = new u8(16);
2099
+ wbytes(dd, 0, 0x8074B50);
2100
+ wbytes(dd, 4, file.crc);
2101
+ wbytes(dd, 8, cl_1);
2102
+ wbytes(dd, 12, file.size);
2103
+ chks_1.push(dd);
2104
+ uf_1.c = cl_1, uf_1.b = hl_1 + cl_1 + 16, uf_1.crc = file.crc, uf_1.size = file.size;
2105
+ if (tr_1)
2106
+ uf_1.r();
2107
+ tr_1 = 1;
2108
+ }
2109
+ else if (tr_1)
2110
+ pAll_1();
2111
+ }
2112
+ };
2113
+ this.u.push(uf_1);
2114
+ }
2115
+ };
2116
+ /**
2117
+ * Ends the process of adding files and prepares to emit the final chunks.
2118
+ * This *must* be called after adding all desired files for the resulting
2119
+ * ZIP file to work properly.
2120
+ */
2121
+ Zip.prototype.end = function () {
2122
+ var _this = this;
2123
+ if (this.d & 2) {
2124
+ this.ondata(err(4 + (this.d & 1) * 8, 0, 1), null, true);
2125
+ return;
2126
+ }
2127
+ if (this.d)
2128
+ this.e();
2129
+ else
2130
+ this.u.push({
2131
+ r: function () {
2132
+ if (!(_this.d & 1))
2133
+ return;
2134
+ _this.u.splice(-1, 1);
2135
+ _this.e();
2136
+ },
2137
+ t: function () { }
2138
+ });
2139
+ this.d = 3;
2140
+ };
2141
+ Zip.prototype.e = function () {
2142
+ var bt = 0, l = 0, tl = 0;
2143
+ for (var _i = 0, _a = this.u; _i < _a.length; _i++) {
2144
+ var f = _a[_i];
2145
+ tl += 46 + f.f.length + exfl(f.extra) + (f.o ? f.o.length : 0);
2146
+ }
2147
+ var out = new u8(tl + 22);
2148
+ for (var _b = 0, _c = this.u; _b < _c.length; _b++) {
2149
+ var f = _c[_b];
2150
+ wzh(out, bt, f, f.f, f.u, -f.c - 2, l, f.o);
2151
+ bt += 46 + f.f.length + exfl(f.extra) + (f.o ? f.o.length : 0), l += f.b;
2152
+ }
2153
+ wzf(out, bt, this.u.length, tl, l);
2154
+ this.ondata(null, out, true);
2155
+ this.d = 2;
2156
+ };
2157
+ /**
2158
+ * A method to terminate any internal workers used by the stream. Subsequent
2159
+ * calls to add() will fail.
2160
+ */
2161
+ Zip.prototype.terminate = function () {
2162
+ for (var _i = 0, _a = this.u; _i < _a.length; _i++) {
2163
+ var f = _a[_i];
2164
+ f.t();
2165
+ }
2166
+ this.d = 2;
2167
+ };
2168
+ return Zip;
2169
+ }());
2170
+ export { Zip };
2171
+ export function zip(data, opts, cb) {
2172
+ if (!cb)
2173
+ cb = opts, opts = {};
2174
+ if (typeof cb != 'function')
2175
+ err(7);
2176
+ var r = {};
2177
+ fltn(data, '', r, opts);
2178
+ var k = Object.keys(r);
2179
+ var lft = k.length, o = 0, tot = 0;
2180
+ var slft = lft, files = new Array(lft);
2181
+ var term = [];
2182
+ var tAll = function () {
2183
+ for (var i = 0; i < term.length; ++i)
2184
+ term[i]();
2185
+ };
2186
+ var cbd = function (a, b) {
2187
+ mt(function () { cb(a, b); });
2188
+ };
2189
+ mt(function () { cbd = cb; });
2190
+ var cbf = function () {
2191
+ var out = new u8(tot + 22), oe = o, cdl = tot - o;
2192
+ tot = 0;
2193
+ for (var i = 0; i < slft; ++i) {
2194
+ var f = files[i];
2195
+ try {
2196
+ var l = f.c.length;
2197
+ wzh(out, tot, f, f.f, f.u, l);
2198
+ var badd = 30 + f.f.length + exfl(f.extra);
2199
+ var loc = tot + badd;
2200
+ out.set(f.c, loc);
2201
+ wzh(out, o, f, f.f, f.u, l, tot, f.m), o += 16 + badd + (f.m ? f.m.length : 0), tot = loc + l;
2202
+ }
2203
+ catch (e) {
2204
+ return cbd(e, null);
2205
+ }
2206
+ }
2207
+ wzf(out, o, files.length, cdl, oe);
2208
+ cbd(null, out);
2209
+ };
2210
+ if (!lft)
2211
+ cbf();
2212
+ var _loop_1 = function (i) {
2213
+ var fn = k[i];
2214
+ var _a = r[fn], file = _a[0], p = _a[1];
2215
+ var c = crc(), size = file.length;
2216
+ c.p(file);
2217
+ var f = strToU8(fn), s = f.length;
2218
+ var com = p.comment, m = com && strToU8(com), ms = m && m.length;
2219
+ var exl = exfl(p.extra);
2220
+ var compression = p.level == 0 ? 0 : 8;
2221
+ var cbl = function (e, d) {
2222
+ if (e) {
2223
+ tAll();
2224
+ cbd(e, null);
2225
+ }
2226
+ else {
2227
+ var l = d.length;
2228
+ files[i] = mrg(p, {
2229
+ size: size,
2230
+ crc: c.d(),
2231
+ c: d,
2232
+ f: f,
2233
+ m: m,
2234
+ u: s != fn.length || (m && (com.length != ms)),
2235
+ compression: compression
2236
+ });
2237
+ o += 30 + s + exl + l;
2238
+ tot += 76 + 2 * (s + exl) + (ms || 0) + l;
2239
+ if (!--lft)
2240
+ cbf();
2241
+ }
2242
+ };
2243
+ if (s > 65535)
2244
+ cbl(err(11, 0, 1), null);
2245
+ if (!compression)
2246
+ cbl(null, file);
2247
+ else if (size < 160000) {
2248
+ try {
2249
+ cbl(null, deflateSync(file, p));
2250
+ }
2251
+ catch (e) {
2252
+ cbl(e, null);
2253
+ }
2254
+ }
2255
+ else
2256
+ term.push(deflate(file, p, cbl));
2257
+ };
2258
+ // Cannot use lft because it can decrease
2259
+ for (var i = 0; i < slft; ++i) {
2260
+ _loop_1(i);
2261
+ }
2262
+ return tAll;
2263
+ }
2264
+ /**
2265
+ * Synchronously creates a ZIP file. Prefer using `zip` for better performance
2266
+ * with more than one file.
2267
+ * @param data The directory structure for the ZIP archive
2268
+ * @param opts The main options, merged with per-file options
2269
+ * @returns The generated ZIP archive
2270
+ */
2271
+ export function zipSync(data, opts) {
2272
+ if (!opts)
2273
+ opts = {};
2274
+ var r = {};
2275
+ var files = [];
2276
+ fltn(data, '', r, opts);
2277
+ var o = 0;
2278
+ var tot = 0;
2279
+ for (var fn in r) {
2280
+ var _a = r[fn], file = _a[0], p = _a[1];
2281
+ var compression = p.level == 0 ? 0 : 8;
2282
+ var f = strToU8(fn), s = f.length;
2283
+ var com = p.comment, m = com && strToU8(com), ms = m && m.length;
2284
+ var exl = exfl(p.extra);
2285
+ if (s > 65535)
2286
+ err(11);
2287
+ var d = compression ? deflateSync(file, p) : file, l = d.length;
2288
+ var c = crc();
2289
+ c.p(file);
2290
+ files.push(mrg(p, {
2291
+ size: file.length,
2292
+ crc: c.d(),
2293
+ c: d,
2294
+ f: f,
2295
+ m: m,
2296
+ u: s != fn.length || (m && (com.length != ms)),
2297
+ o: o,
2298
+ compression: compression
2299
+ }));
2300
+ o += 30 + s + exl + l;
2301
+ tot += 76 + 2 * (s + exl) + (ms || 0) + l;
2302
+ }
2303
+ var out = new u8(tot + 22), oe = o, cdl = tot - o;
2304
+ for (var i = 0; i < files.length; ++i) {
2305
+ var f = files[i];
2306
+ wzh(out, f.o, f, f.f, f.u, f.c.length);
2307
+ var badd = 30 + f.f.length + exfl(f.extra);
2308
+ out.set(f.c, f.o + badd);
2309
+ wzh(out, o, f, f.f, f.u, f.c.length, f.o, f.m), o += 16 + badd + (f.m ? f.m.length : 0);
2310
+ }
2311
+ wzf(out, o, files.length, cdl, oe);
2312
+ return out;
2313
+ }
2314
+ /**
2315
+ * Streaming pass-through decompression for ZIP archives
2316
+ */
2317
+ var UnzipPassThrough = /*#__PURE__*/ (function () {
2318
+ function UnzipPassThrough() {
2319
+ }
2320
+ UnzipPassThrough.prototype.push = function (data, final) {
2321
+ this.ondata(null, data, final);
2322
+ };
2323
+ UnzipPassThrough.compression = 0;
2324
+ return UnzipPassThrough;
2325
+ }());
2326
+ export { UnzipPassThrough };
2327
+ /**
2328
+ * Streaming DEFLATE decompression for ZIP archives. Prefer AsyncZipInflate for
2329
+ * better performance.
2330
+ */
2331
+ var UnzipInflate = /*#__PURE__*/ (function () {
2332
+ /**
2333
+ * Creates a DEFLATE decompression that can be used in ZIP archives
2334
+ */
2335
+ function UnzipInflate() {
2336
+ var _this = this;
2337
+ this.i = new Inflate(function (dat, final) {
2338
+ _this.ondata(null, dat, final);
2339
+ });
2340
+ }
2341
+ UnzipInflate.prototype.push = function (data, final) {
2342
+ try {
2343
+ this.i.push(data, final);
2344
+ }
2345
+ catch (e) {
2346
+ this.ondata(e, null, final);
2347
+ }
2348
+ };
2349
+ UnzipInflate.compression = 8;
2350
+ return UnzipInflate;
2351
+ }());
2352
+ export { UnzipInflate };
2353
+ /**
2354
+ * Asynchronous streaming DEFLATE decompression for ZIP archives
2355
+ */
2356
+ var AsyncUnzipInflate = /*#__PURE__*/ (function () {
2357
+ /**
2358
+ * Creates a DEFLATE decompression that can be used in ZIP archives
2359
+ */
2360
+ function AsyncUnzipInflate(_, sz) {
2361
+ var _this = this;
2362
+ if (sz < 320000) {
2363
+ this.i = new Inflate(function (dat, final) {
2364
+ _this.ondata(null, dat, final);
2365
+ });
2366
+ }
2367
+ else {
2368
+ this.i = new AsyncInflate(function (err, dat, final) {
2369
+ _this.ondata(err, dat, final);
2370
+ });
2371
+ this.terminate = this.i.terminate;
2372
+ }
2373
+ }
2374
+ AsyncUnzipInflate.prototype.push = function (data, final) {
2375
+ if (this.i.terminate)
2376
+ data = slc(data, 0);
2377
+ this.i.push(data, final);
2378
+ };
2379
+ AsyncUnzipInflate.compression = 8;
2380
+ return AsyncUnzipInflate;
2381
+ }());
2382
+ export { AsyncUnzipInflate };
2383
+ /**
2384
+ * A ZIP archive decompression stream that emits files as they are discovered
2385
+ */
2386
+ var Unzip = /*#__PURE__*/ (function () {
2387
+ /**
2388
+ * Creates a ZIP decompression stream
2389
+ * @param cb The callback to call whenever a file in the ZIP archive is found
2390
+ */
2391
+ function Unzip(cb) {
2392
+ this.onfile = cb;
2393
+ this.k = [];
2394
+ this.o = {
2395
+ 0: UnzipPassThrough
2396
+ };
2397
+ this.p = et;
2398
+ }
2399
+ /**
2400
+ * Pushes a chunk to be unzipped
2401
+ * @param chunk The chunk to push
2402
+ * @param final Whether this is the last chunk
2403
+ */
2404
+ Unzip.prototype.push = function (chunk, final) {
2405
+ var _this = this;
2406
+ if (!this.onfile)
2407
+ err(5);
2408
+ if (!this.p)
2409
+ err(4);
2410
+ if (this.c > 0) {
2411
+ var len = Math.min(this.c, chunk.length);
2412
+ var toAdd = chunk.subarray(0, len);
2413
+ this.c -= len;
2414
+ if (this.d)
2415
+ this.d.push(toAdd, !this.c);
2416
+ else
2417
+ this.k[0].push(toAdd);
2418
+ chunk = chunk.subarray(len);
2419
+ if (chunk.length)
2420
+ return this.push(chunk, final);
2421
+ }
2422
+ else {
2423
+ var f = 0, i = 0, is = void 0, buf = void 0;
2424
+ if (!this.p.length)
2425
+ buf = chunk;
2426
+ else if (!chunk.length)
2427
+ buf = this.p;
2428
+ else {
2429
+ buf = new u8(this.p.length + chunk.length);
2430
+ buf.set(this.p), buf.set(chunk, this.p.length);
2431
+ }
2432
+ var l = buf.length, oc = this.c, add = oc && this.d;
2433
+ var _loop_2 = function () {
2434
+ var _a;
2435
+ var sig = b4(buf, i);
2436
+ if (sig == 0x4034B50) {
2437
+ f = 1, is = i;
2438
+ this_1.d = null;
2439
+ this_1.c = 0;
2440
+ var bf = b2(buf, i + 6), cmp_1 = b2(buf, i + 8), u = bf & 2048, dd = bf & 8, fnl = b2(buf, i + 26), es = b2(buf, i + 28);
2441
+ if (l > i + 30 + fnl + es) {
2442
+ var chks_3 = [];
2443
+ this_1.k.unshift(chks_3);
2444
+ f = 2;
2445
+ var sc_1 = b4(buf, i + 18), su_1 = b4(buf, i + 22);
2446
+ var fn_1 = strFromU8(buf.subarray(i + 30, i += 30 + fnl), !u);
2447
+ if (sc_1 == 4294967295) {
2448
+ _a = dd ? [-2] : z64e(buf, i), sc_1 = _a[0], su_1 = _a[1];
2449
+ }
2450
+ else if (dd)
2451
+ sc_1 = -1;
2452
+ i += es;
2453
+ this_1.c = sc_1;
2454
+ var d_1;
2455
+ var file_1 = {
2456
+ name: fn_1,
2457
+ compression: cmp_1,
2458
+ start: function () {
2459
+ if (!file_1.ondata)
2460
+ err(5);
2461
+ if (!sc_1)
2462
+ file_1.ondata(null, et, true);
2463
+ else {
2464
+ var ctr = _this.o[cmp_1];
2465
+ if (!ctr)
2466
+ file_1.ondata(err(14, 'unknown compression type ' + cmp_1, 1), null, false);
2467
+ d_1 = sc_1 < 0 ? new ctr(fn_1) : new ctr(fn_1, sc_1, su_1);
2468
+ d_1.ondata = function (err, dat, final) { file_1.ondata(err, dat, final); };
2469
+ for (var _i = 0, chks_4 = chks_3; _i < chks_4.length; _i++) {
2470
+ var dat = chks_4[_i];
2471
+ d_1.push(dat, false);
2472
+ }
2473
+ if (_this.k[0] == chks_3 && _this.c)
2474
+ _this.d = d_1;
2475
+ else
2476
+ d_1.push(et, true);
2477
+ }
2478
+ },
2479
+ terminate: function () {
2480
+ if (d_1 && d_1.terminate)
2481
+ d_1.terminate();
2482
+ }
2483
+ };
2484
+ if (sc_1 >= 0)
2485
+ file_1.size = sc_1, file_1.originalSize = su_1;
2486
+ this_1.onfile(file_1);
2487
+ }
2488
+ return "break";
2489
+ }
2490
+ else if (oc) {
2491
+ if (sig == 0x8074B50) {
2492
+ is = i += 12 + (oc == -2 && 8), f = 3, this_1.c = 0;
2493
+ return "break";
2494
+ }
2495
+ else if (sig == 0x2014B50) {
2496
+ is = i -= 4, f = 3, this_1.c = 0;
2497
+ return "break";
2498
+ }
2499
+ }
2500
+ };
2501
+ var this_1 = this;
2502
+ for (; i < l - 4; ++i) {
2503
+ var state_1 = _loop_2();
2504
+ if (state_1 === "break")
2505
+ break;
2506
+ }
2507
+ this.p = et;
2508
+ if (oc < 0) {
2509
+ var dat = f ? buf.subarray(0, is - 12 - (oc == -2 && 8) - (b4(buf, is - 16) == 0x8074B50 && 4)) : buf.subarray(0, i);
2510
+ if (add)
2511
+ add.push(dat, !!f);
2512
+ else
2513
+ this.k[+(f == 2)].push(dat);
2514
+ }
2515
+ if (f & 2)
2516
+ return this.push(buf.subarray(i), final);
2517
+ this.p = buf.subarray(i);
2518
+ }
2519
+ if (final) {
2520
+ if (this.c)
2521
+ err(13);
2522
+ this.p = null;
2523
+ }
2524
+ };
2525
+ /**
2526
+ * Registers a decoder with the stream, allowing for files compressed with
2527
+ * the compression type provided to be expanded correctly
2528
+ * @param decoder The decoder constructor
2529
+ */
2530
+ Unzip.prototype.register = function (decoder) {
2531
+ this.o[decoder.compression] = decoder;
2532
+ };
2533
+ return Unzip;
2534
+ }());
2535
+ export { Unzip };
2536
+ var mt = typeof queueMicrotask == 'function' ? queueMicrotask : typeof setTimeout == 'function' ? setTimeout : function (fn) { fn(); };
2537
+ export function unzip(data, opts, cb) {
2538
+ if (!cb)
2539
+ cb = opts, opts = {};
2540
+ if (typeof cb != 'function')
2541
+ err(7);
2542
+ var term = [];
2543
+ var tAll = function () {
2544
+ for (var i = 0; i < term.length; ++i)
2545
+ term[i]();
2546
+ };
2547
+ var files = {};
2548
+ var cbd = function (a, b) {
2549
+ mt(function () { cb(a, b); });
2550
+ };
2551
+ mt(function () { cbd = cb; });
2552
+ var e = data.length - 22;
2553
+ for (; b4(data, e) != 0x6054B50; --e) {
2554
+ if (!e || data.length - e > 65558) {
2555
+ cbd(err(13, 0, 1), null);
2556
+ return tAll;
2557
+ }
2558
+ }
2559
+ ;
2560
+ var lft = b2(data, e + 8);
2561
+ if (lft) {
2562
+ var c = lft;
2563
+ var o = b4(data, e + 16);
2564
+ var z = o == 4294967295 || c == 65535;
2565
+ if (z) {
2566
+ var ze = b4(data, e - 12);
2567
+ z = b4(data, ze) == 0x6064B50;
2568
+ if (z) {
2569
+ c = lft = b4(data, ze + 32);
2570
+ o = b4(data, ze + 48);
2571
+ }
2572
+ }
2573
+ var fltr = opts && opts.filter;
2574
+ var _loop_3 = function (i) {
2575
+ var _a = zh(data, o, z), c_1 = _a[0], sc = _a[1], su = _a[2], fn = _a[3], no = _a[4], off = _a[5], b = slzh(data, off);
2576
+ o = no;
2577
+ var cbl = function (e, d) {
2578
+ if (e) {
2579
+ tAll();
2580
+ cbd(e, null);
2581
+ }
2582
+ else {
2583
+ if (d)
2584
+ files[fn] = d;
2585
+ if (!--lft)
2586
+ cbd(null, files);
2587
+ }
2588
+ };
2589
+ if (!fltr || fltr({
2590
+ name: fn,
2591
+ size: sc,
2592
+ originalSize: su,
2593
+ compression: c_1
2594
+ })) {
2595
+ if (!c_1)
2596
+ cbl(null, slc(data, b, b + sc));
2597
+ else if (c_1 == 8) {
2598
+ var infl = data.subarray(b, b + sc);
2599
+ // Synchronously decompress under 512KB, or barely-compressed data
2600
+ if (su < 524288 || sc > 0.8 * su) {
2601
+ try {
2602
+ cbl(null, inflateSync(infl, { out: new u8(su) }));
2603
+ }
2604
+ catch (e) {
2605
+ cbl(e, null);
2606
+ }
2607
+ }
2608
+ else
2609
+ term.push(inflate(infl, { size: su }, cbl));
2610
+ }
2611
+ else
2612
+ cbl(err(14, 'unknown compression type ' + c_1, 1), null);
2613
+ }
2614
+ else
2615
+ cbl(null, null);
2616
+ };
2617
+ for (var i = 0; i < c; ++i) {
2618
+ _loop_3(i);
2619
+ }
2620
+ }
2621
+ else
2622
+ cbd(null, {});
2623
+ return tAll;
2624
+ }
2625
+ /**
2626
+ * Synchronously decompresses a ZIP archive. Prefer using `unzip` for better
2627
+ * performance with more than one file.
2628
+ * @param data The raw compressed ZIP file
2629
+ * @param opts The ZIP extraction options
2630
+ * @returns The decompressed files
2631
+ */
2632
+ export function unzipSync(data, opts) {
2633
+ var files = {};
2634
+ var e = data.length - 22;
2635
+ for (; b4(data, e) != 0x6054B50; --e) {
2636
+ if (!e || data.length - e > 65558)
2637
+ err(13);
2638
+ }
2639
+ ;
2640
+ var c = b2(data, e + 8);
2641
+ if (!c)
2642
+ return {};
2643
+ var o = b4(data, e + 16);
2644
+ var z = o == 4294967295 || c == 65535;
2645
+ if (z) {
2646
+ var ze = b4(data, e - 12);
2647
+ z = b4(data, ze) == 0x6064B50;
2648
+ if (z) {
2649
+ c = b4(data, ze + 32);
2650
+ o = b4(data, ze + 48);
2651
+ }
2652
+ }
2653
+ var fltr = opts && opts.filter;
2654
+ for (var i = 0; i < c; ++i) {
2655
+ var _a = zh(data, o, z), c_2 = _a[0], sc = _a[1], su = _a[2], fn = _a[3], no = _a[4], off = _a[5], b = slzh(data, off);
2656
+ o = no;
2657
+ if (!fltr || fltr({
2658
+ name: fn,
2659
+ size: sc,
2660
+ originalSize: su,
2661
+ compression: c_2
2662
+ })) {
2663
+ if (!c_2)
2664
+ files[fn] = slc(data, b, b + sc);
2665
+ else if (c_2 == 8)
2666
+ files[fn] = inflateSync(data.subarray(b, b + sc), { out: new u8(su) });
2667
+ else
2668
+ err(14, 'unknown compression type ' + c_2);
2669
+ }
2670
+ }
2671
+ return files;
2672
+ }