@aguacerowx/mapsgl 0.0.31 → 0.0.41

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 (33) hide show
  1. package/index.js +34 -2
  2. package/package.json +13 -3
  3. package/src/GridRenderLayer.js +105 -86
  4. package/src/MapManager.js +47 -15
  5. package/src/NexradSitesOverlay.js +148 -0
  6. package/src/NexradWeatherController.js +491 -0
  7. package/src/NwsWatchesWarningsOverlay.js +768 -0
  8. package/src/SatelliteShaderManager.js +999 -0
  9. package/src/WeatherLayerManager.js +800 -110
  10. package/src/WorkerPool.js +340 -0
  11. package/src/nexrad/MapboxRadarLayer.bundled.js +810 -0
  12. package/src/nexrad/MapboxRadarLayer.ts +784 -0
  13. package/src/nexrad/PreprocessedSweepParser.ts +226 -0
  14. package/src/nexrad/buildRadarRayGeometry.ts +97 -0
  15. package/src/nexrad/level3StormRelative.ts +116 -0
  16. package/src/nexrad/loadNexradSites.ts +41 -0
  17. package/src/nexrad/nexradArchiveCache.ts +64 -0
  18. package/src/nexrad/nexradCrossSectionSampleAtLatLon.ts +121 -0
  19. package/src/nexrad/nexradLevel3Products.ts +549 -0
  20. package/src/nexrad/nexradMapboxFrameOpts.js +106 -0
  21. package/src/nexrad/radarArchiveCore.bundled.js +4206 -0
  22. package/src/nexrad/radarArchiveCore.bundled.js.map +7 -0
  23. package/src/nexrad/radarArchiveCore.ts +1737 -0
  24. package/src/nexrad/radarDecode.worker.bundled.js +809 -0
  25. package/src/nexrad/radarDecode.worker.ts +227 -0
  26. package/src/nexrad/radarFrameGpuMatch.ts +111 -0
  27. package/src/nwsAlertsSupport.js +860 -0
  28. package/src/nwsEventColorsDefaults.js +133 -0
  29. package/src/nwsSdkConstants.js +360 -0
  30. package/src/nwsWarningCustomizationKey.gen.js +496 -0
  31. package/src/satelliteDefaultColormaps.js +37 -0
  32. package/src/satelliteKtxWorker.js +225 -0
  33. package/src/satelliteShader.js +17 -0
@@ -0,0 +1,4206 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ // ../../node_modules/base64-js/index.js
28
+ var require_base64_js = __commonJS({
29
+ "../../node_modules/base64-js/index.js"(exports) {
30
+ "use strict";
31
+ exports.byteLength = byteLength;
32
+ exports.toByteArray = toByteArray;
33
+ exports.fromByteArray = fromByteArray;
34
+ var lookup = [];
35
+ var revLookup = [];
36
+ var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
37
+ var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
38
+ for (i = 0, len = code.length; i < len; ++i) {
39
+ lookup[i] = code[i];
40
+ revLookup[code.charCodeAt(i)] = i;
41
+ }
42
+ var i;
43
+ var len;
44
+ revLookup["-".charCodeAt(0)] = 62;
45
+ revLookup["_".charCodeAt(0)] = 63;
46
+ function getLens(b64) {
47
+ var len2 = b64.length;
48
+ if (len2 % 4 > 0) {
49
+ throw new Error("Invalid string. Length must be a multiple of 4");
50
+ }
51
+ var validLen = b64.indexOf("=");
52
+ if (validLen === -1) validLen = len2;
53
+ var placeHoldersLen = validLen === len2 ? 0 : 4 - validLen % 4;
54
+ return [validLen, placeHoldersLen];
55
+ }
56
+ function byteLength(b64) {
57
+ var lens = getLens(b64);
58
+ var validLen = lens[0];
59
+ var placeHoldersLen = lens[1];
60
+ return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
61
+ }
62
+ function _byteLength(b64, validLen, placeHoldersLen) {
63
+ return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
64
+ }
65
+ function toByteArray(b64) {
66
+ var tmp;
67
+ var lens = getLens(b64);
68
+ var validLen = lens[0];
69
+ var placeHoldersLen = lens[1];
70
+ var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
71
+ var curByte = 0;
72
+ var len2 = placeHoldersLen > 0 ? validLen - 4 : validLen;
73
+ var i2;
74
+ for (i2 = 0; i2 < len2; i2 += 4) {
75
+ tmp = revLookup[b64.charCodeAt(i2)] << 18 | revLookup[b64.charCodeAt(i2 + 1)] << 12 | revLookup[b64.charCodeAt(i2 + 2)] << 6 | revLookup[b64.charCodeAt(i2 + 3)];
76
+ arr[curByte++] = tmp >> 16 & 255;
77
+ arr[curByte++] = tmp >> 8 & 255;
78
+ arr[curByte++] = tmp & 255;
79
+ }
80
+ if (placeHoldersLen === 2) {
81
+ tmp = revLookup[b64.charCodeAt(i2)] << 2 | revLookup[b64.charCodeAt(i2 + 1)] >> 4;
82
+ arr[curByte++] = tmp & 255;
83
+ }
84
+ if (placeHoldersLen === 1) {
85
+ tmp = revLookup[b64.charCodeAt(i2)] << 10 | revLookup[b64.charCodeAt(i2 + 1)] << 4 | revLookup[b64.charCodeAt(i2 + 2)] >> 2;
86
+ arr[curByte++] = tmp >> 8 & 255;
87
+ arr[curByte++] = tmp & 255;
88
+ }
89
+ return arr;
90
+ }
91
+ function tripletToBase64(num) {
92
+ return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
93
+ }
94
+ function encodeChunk(uint8, start, end) {
95
+ var tmp;
96
+ var output = [];
97
+ for (var i2 = start; i2 < end; i2 += 3) {
98
+ tmp = (uint8[i2] << 16 & 16711680) + (uint8[i2 + 1] << 8 & 65280) + (uint8[i2 + 2] & 255);
99
+ output.push(tripletToBase64(tmp));
100
+ }
101
+ return output.join("");
102
+ }
103
+ function fromByteArray(uint8) {
104
+ var tmp;
105
+ var len2 = uint8.length;
106
+ var extraBytes = len2 % 3;
107
+ var parts = [];
108
+ var maxChunkLength = 16383;
109
+ for (var i2 = 0, len22 = len2 - extraBytes; i2 < len22; i2 += maxChunkLength) {
110
+ parts.push(encodeChunk(uint8, i2, i2 + maxChunkLength > len22 ? len22 : i2 + maxChunkLength));
111
+ }
112
+ if (extraBytes === 1) {
113
+ tmp = uint8[len2 - 1];
114
+ parts.push(
115
+ lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "=="
116
+ );
117
+ } else if (extraBytes === 2) {
118
+ tmp = (uint8[len2 - 2] << 8) + uint8[len2 - 1];
119
+ parts.push(
120
+ lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "="
121
+ );
122
+ }
123
+ return parts.join("");
124
+ }
125
+ }
126
+ });
127
+
128
+ // ../../node_modules/ieee754/index.js
129
+ var require_ieee754 = __commonJS({
130
+ "../../node_modules/ieee754/index.js"(exports) {
131
+ exports.read = function(buffer, offset, isLE, mLen, nBytes) {
132
+ var e, m;
133
+ var eLen = nBytes * 8 - mLen - 1;
134
+ var eMax = (1 << eLen) - 1;
135
+ var eBias = eMax >> 1;
136
+ var nBits = -7;
137
+ var i = isLE ? nBytes - 1 : 0;
138
+ var d = isLE ? -1 : 1;
139
+ var s = buffer[offset + i];
140
+ i += d;
141
+ e = s & (1 << -nBits) - 1;
142
+ s >>= -nBits;
143
+ nBits += eLen;
144
+ for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {
145
+ }
146
+ m = e & (1 << -nBits) - 1;
147
+ e >>= -nBits;
148
+ nBits += mLen;
149
+ for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {
150
+ }
151
+ if (e === 0) {
152
+ e = 1 - eBias;
153
+ } else if (e === eMax) {
154
+ return m ? NaN : (s ? -1 : 1) * Infinity;
155
+ } else {
156
+ m = m + Math.pow(2, mLen);
157
+ e = e - eBias;
158
+ }
159
+ return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
160
+ };
161
+ exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
162
+ var e, m, c;
163
+ var eLen = nBytes * 8 - mLen - 1;
164
+ var eMax = (1 << eLen) - 1;
165
+ var eBias = eMax >> 1;
166
+ var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
167
+ var i = isLE ? 0 : nBytes - 1;
168
+ var d = isLE ? 1 : -1;
169
+ var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
170
+ value = Math.abs(value);
171
+ if (isNaN(value) || value === Infinity) {
172
+ m = isNaN(value) ? 1 : 0;
173
+ e = eMax;
174
+ } else {
175
+ e = Math.floor(Math.log(value) / Math.LN2);
176
+ if (value * (c = Math.pow(2, -e)) < 1) {
177
+ e--;
178
+ c *= 2;
179
+ }
180
+ if (e + eBias >= 1) {
181
+ value += rt / c;
182
+ } else {
183
+ value += rt * Math.pow(2, 1 - eBias);
184
+ }
185
+ if (value * c >= 2) {
186
+ e++;
187
+ c /= 2;
188
+ }
189
+ if (e + eBias >= eMax) {
190
+ m = 0;
191
+ e = eMax;
192
+ } else if (e + eBias >= 1) {
193
+ m = (value * c - 1) * Math.pow(2, mLen);
194
+ e = e + eBias;
195
+ } else {
196
+ m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
197
+ e = 0;
198
+ }
199
+ }
200
+ for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) {
201
+ }
202
+ e = e << mLen | m;
203
+ eLen += mLen;
204
+ for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) {
205
+ }
206
+ buffer[offset + i - d] |= s * 128;
207
+ };
208
+ }
209
+ });
210
+
211
+ // node_modules/buffer/index.js
212
+ var require_buffer = __commonJS({
213
+ "node_modules/buffer/index.js"(exports) {
214
+ "use strict";
215
+ var base64 = require_base64_js();
216
+ var ieee754 = require_ieee754();
217
+ var customInspectSymbol = typeof Symbol === "function" && typeof Symbol["for"] === "function" ? Symbol["for"]("nodejs.util.inspect.custom") : null;
218
+ exports.Buffer = Buffer3;
219
+ exports.SlowBuffer = SlowBuffer;
220
+ exports.INSPECT_MAX_BYTES = 50;
221
+ var K_MAX_LENGTH = 2147483647;
222
+ exports.kMaxLength = K_MAX_LENGTH;
223
+ Buffer3.TYPED_ARRAY_SUPPORT = typedArraySupport();
224
+ if (!Buffer3.TYPED_ARRAY_SUPPORT && typeof console !== "undefined" && typeof console.error === "function") {
225
+ console.error(
226
+ "This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."
227
+ );
228
+ }
229
+ function typedArraySupport() {
230
+ try {
231
+ const arr = new Uint8Array(1);
232
+ const proto = { foo: function() {
233
+ return 42;
234
+ } };
235
+ Object.setPrototypeOf(proto, Uint8Array.prototype);
236
+ Object.setPrototypeOf(arr, proto);
237
+ return arr.foo() === 42;
238
+ } catch (e) {
239
+ return false;
240
+ }
241
+ }
242
+ Object.defineProperty(Buffer3.prototype, "parent", {
243
+ enumerable: true,
244
+ get: function() {
245
+ if (!Buffer3.isBuffer(this)) return void 0;
246
+ return this.buffer;
247
+ }
248
+ });
249
+ Object.defineProperty(Buffer3.prototype, "offset", {
250
+ enumerable: true,
251
+ get: function() {
252
+ if (!Buffer3.isBuffer(this)) return void 0;
253
+ return this.byteOffset;
254
+ }
255
+ });
256
+ function createBuffer(length) {
257
+ if (length > K_MAX_LENGTH) {
258
+ throw new RangeError('The value "' + length + '" is invalid for option "size"');
259
+ }
260
+ const buf = new Uint8Array(length);
261
+ Object.setPrototypeOf(buf, Buffer3.prototype);
262
+ return buf;
263
+ }
264
+ function Buffer3(arg, encodingOrOffset, length) {
265
+ if (typeof arg === "number") {
266
+ if (typeof encodingOrOffset === "string") {
267
+ throw new TypeError(
268
+ 'The "string" argument must be of type string. Received type number'
269
+ );
270
+ }
271
+ return allocUnsafe(arg);
272
+ }
273
+ return from(arg, encodingOrOffset, length);
274
+ }
275
+ Buffer3.poolSize = 8192;
276
+ function from(value, encodingOrOffset, length) {
277
+ if (typeof value === "string") {
278
+ return fromString(value, encodingOrOffset);
279
+ }
280
+ if (ArrayBuffer.isView(value)) {
281
+ return fromArrayView(value);
282
+ }
283
+ if (value == null) {
284
+ throw new TypeError(
285
+ "The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value
286
+ );
287
+ }
288
+ if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) {
289
+ return fromArrayBuffer(value, encodingOrOffset, length);
290
+ }
291
+ if (typeof SharedArrayBuffer !== "undefined" && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) {
292
+ return fromArrayBuffer(value, encodingOrOffset, length);
293
+ }
294
+ if (typeof value === "number") {
295
+ throw new TypeError(
296
+ 'The "value" argument must not be of type number. Received type number'
297
+ );
298
+ }
299
+ const valueOf = value.valueOf && value.valueOf();
300
+ if (valueOf != null && valueOf !== value) {
301
+ return Buffer3.from(valueOf, encodingOrOffset, length);
302
+ }
303
+ const b = fromObject(value);
304
+ if (b) return b;
305
+ if (typeof Symbol !== "undefined" && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === "function") {
306
+ return Buffer3.from(value[Symbol.toPrimitive]("string"), encodingOrOffset, length);
307
+ }
308
+ throw new TypeError(
309
+ "The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value
310
+ );
311
+ }
312
+ Buffer3.from = function(value, encodingOrOffset, length) {
313
+ return from(value, encodingOrOffset, length);
314
+ };
315
+ Object.setPrototypeOf(Buffer3.prototype, Uint8Array.prototype);
316
+ Object.setPrototypeOf(Buffer3, Uint8Array);
317
+ function assertSize(size) {
318
+ if (typeof size !== "number") {
319
+ throw new TypeError('"size" argument must be of type number');
320
+ } else if (size < 0) {
321
+ throw new RangeError('The value "' + size + '" is invalid for option "size"');
322
+ }
323
+ }
324
+ function alloc(size, fill, encoding) {
325
+ assertSize(size);
326
+ if (size <= 0) {
327
+ return createBuffer(size);
328
+ }
329
+ if (fill !== void 0) {
330
+ return typeof encoding === "string" ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill);
331
+ }
332
+ return createBuffer(size);
333
+ }
334
+ Buffer3.alloc = function(size, fill, encoding) {
335
+ return alloc(size, fill, encoding);
336
+ };
337
+ function allocUnsafe(size) {
338
+ assertSize(size);
339
+ return createBuffer(size < 0 ? 0 : checked(size) | 0);
340
+ }
341
+ Buffer3.allocUnsafe = function(size) {
342
+ return allocUnsafe(size);
343
+ };
344
+ Buffer3.allocUnsafeSlow = function(size) {
345
+ return allocUnsafe(size);
346
+ };
347
+ function fromString(string, encoding) {
348
+ if (typeof encoding !== "string" || encoding === "") {
349
+ encoding = "utf8";
350
+ }
351
+ if (!Buffer3.isEncoding(encoding)) {
352
+ throw new TypeError("Unknown encoding: " + encoding);
353
+ }
354
+ const length = byteLength(string, encoding) | 0;
355
+ let buf = createBuffer(length);
356
+ const actual = buf.write(string, encoding);
357
+ if (actual !== length) {
358
+ buf = buf.slice(0, actual);
359
+ }
360
+ return buf;
361
+ }
362
+ function fromArrayLike(array) {
363
+ const length = array.length < 0 ? 0 : checked(array.length) | 0;
364
+ const buf = createBuffer(length);
365
+ for (let i = 0; i < length; i += 1) {
366
+ buf[i] = array[i] & 255;
367
+ }
368
+ return buf;
369
+ }
370
+ function fromArrayView(arrayView) {
371
+ if (isInstance(arrayView, Uint8Array)) {
372
+ const copy = new Uint8Array(arrayView);
373
+ return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength);
374
+ }
375
+ return fromArrayLike(arrayView);
376
+ }
377
+ function fromArrayBuffer(array, byteOffset, length) {
378
+ if (byteOffset < 0 || array.byteLength < byteOffset) {
379
+ throw new RangeError('"offset" is outside of buffer bounds');
380
+ }
381
+ if (array.byteLength < byteOffset + (length || 0)) {
382
+ throw new RangeError('"length" is outside of buffer bounds');
383
+ }
384
+ let buf;
385
+ if (byteOffset === void 0 && length === void 0) {
386
+ buf = new Uint8Array(array);
387
+ } else if (length === void 0) {
388
+ buf = new Uint8Array(array, byteOffset);
389
+ } else {
390
+ buf = new Uint8Array(array, byteOffset, length);
391
+ }
392
+ Object.setPrototypeOf(buf, Buffer3.prototype);
393
+ return buf;
394
+ }
395
+ function fromObject(obj) {
396
+ if (Buffer3.isBuffer(obj)) {
397
+ const len = checked(obj.length) | 0;
398
+ const buf = createBuffer(len);
399
+ if (buf.length === 0) {
400
+ return buf;
401
+ }
402
+ obj.copy(buf, 0, 0, len);
403
+ return buf;
404
+ }
405
+ if (obj.length !== void 0) {
406
+ if (typeof obj.length !== "number" || numberIsNaN(obj.length)) {
407
+ return createBuffer(0);
408
+ }
409
+ return fromArrayLike(obj);
410
+ }
411
+ if (obj.type === "Buffer" && Array.isArray(obj.data)) {
412
+ return fromArrayLike(obj.data);
413
+ }
414
+ }
415
+ function checked(length) {
416
+ if (length >= K_MAX_LENGTH) {
417
+ throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + K_MAX_LENGTH.toString(16) + " bytes");
418
+ }
419
+ return length | 0;
420
+ }
421
+ function SlowBuffer(length) {
422
+ if (+length != length) {
423
+ length = 0;
424
+ }
425
+ return Buffer3.alloc(+length);
426
+ }
427
+ Buffer3.isBuffer = function isBuffer(b) {
428
+ return b != null && b._isBuffer === true && b !== Buffer3.prototype;
429
+ };
430
+ Buffer3.compare = function compare(a, b) {
431
+ if (isInstance(a, Uint8Array)) a = Buffer3.from(a, a.offset, a.byteLength);
432
+ if (isInstance(b, Uint8Array)) b = Buffer3.from(b, b.offset, b.byteLength);
433
+ if (!Buffer3.isBuffer(a) || !Buffer3.isBuffer(b)) {
434
+ throw new TypeError(
435
+ 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
436
+ );
437
+ }
438
+ if (a === b) return 0;
439
+ let x = a.length;
440
+ let y = b.length;
441
+ for (let i = 0, len = Math.min(x, y); i < len; ++i) {
442
+ if (a[i] !== b[i]) {
443
+ x = a[i];
444
+ y = b[i];
445
+ break;
446
+ }
447
+ }
448
+ if (x < y) return -1;
449
+ if (y < x) return 1;
450
+ return 0;
451
+ };
452
+ Buffer3.isEncoding = function isEncoding(encoding) {
453
+ switch (String(encoding).toLowerCase()) {
454
+ case "hex":
455
+ case "utf8":
456
+ case "utf-8":
457
+ case "ascii":
458
+ case "latin1":
459
+ case "binary":
460
+ case "base64":
461
+ case "ucs2":
462
+ case "ucs-2":
463
+ case "utf16le":
464
+ case "utf-16le":
465
+ return true;
466
+ default:
467
+ return false;
468
+ }
469
+ };
470
+ Buffer3.concat = function concat(list, length) {
471
+ if (!Array.isArray(list)) {
472
+ throw new TypeError('"list" argument must be an Array of Buffers');
473
+ }
474
+ if (list.length === 0) {
475
+ return Buffer3.alloc(0);
476
+ }
477
+ let i;
478
+ if (length === void 0) {
479
+ length = 0;
480
+ for (i = 0; i < list.length; ++i) {
481
+ length += list[i].length;
482
+ }
483
+ }
484
+ const buffer = Buffer3.allocUnsafe(length);
485
+ let pos = 0;
486
+ for (i = 0; i < list.length; ++i) {
487
+ let buf = list[i];
488
+ if (isInstance(buf, Uint8Array)) {
489
+ if (pos + buf.length > buffer.length) {
490
+ if (!Buffer3.isBuffer(buf)) buf = Buffer3.from(buf);
491
+ buf.copy(buffer, pos);
492
+ } else {
493
+ Uint8Array.prototype.set.call(
494
+ buffer,
495
+ buf,
496
+ pos
497
+ );
498
+ }
499
+ } else if (!Buffer3.isBuffer(buf)) {
500
+ throw new TypeError('"list" argument must be an Array of Buffers');
501
+ } else {
502
+ buf.copy(buffer, pos);
503
+ }
504
+ pos += buf.length;
505
+ }
506
+ return buffer;
507
+ };
508
+ function byteLength(string, encoding) {
509
+ if (Buffer3.isBuffer(string)) {
510
+ return string.length;
511
+ }
512
+ if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
513
+ return string.byteLength;
514
+ }
515
+ if (typeof string !== "string") {
516
+ throw new TypeError(
517
+ 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof string
518
+ );
519
+ }
520
+ const len = string.length;
521
+ const mustMatch = arguments.length > 2 && arguments[2] === true;
522
+ if (!mustMatch && len === 0) return 0;
523
+ let loweredCase = false;
524
+ for (; ; ) {
525
+ switch (encoding) {
526
+ case "ascii":
527
+ case "latin1":
528
+ case "binary":
529
+ return len;
530
+ case "utf8":
531
+ case "utf-8":
532
+ return utf8ToBytes(string).length;
533
+ case "ucs2":
534
+ case "ucs-2":
535
+ case "utf16le":
536
+ case "utf-16le":
537
+ return len * 2;
538
+ case "hex":
539
+ return len >>> 1;
540
+ case "base64":
541
+ return base64ToBytes(string).length;
542
+ default:
543
+ if (loweredCase) {
544
+ return mustMatch ? -1 : utf8ToBytes(string).length;
545
+ }
546
+ encoding = ("" + encoding).toLowerCase();
547
+ loweredCase = true;
548
+ }
549
+ }
550
+ }
551
+ Buffer3.byteLength = byteLength;
552
+ function slowToString(encoding, start, end) {
553
+ let loweredCase = false;
554
+ if (start === void 0 || start < 0) {
555
+ start = 0;
556
+ }
557
+ if (start > this.length) {
558
+ return "";
559
+ }
560
+ if (end === void 0 || end > this.length) {
561
+ end = this.length;
562
+ }
563
+ if (end <= 0) {
564
+ return "";
565
+ }
566
+ end >>>= 0;
567
+ start >>>= 0;
568
+ if (end <= start) {
569
+ return "";
570
+ }
571
+ if (!encoding) encoding = "utf8";
572
+ while (true) {
573
+ switch (encoding) {
574
+ case "hex":
575
+ return hexSlice(this, start, end);
576
+ case "utf8":
577
+ case "utf-8":
578
+ return utf8Slice(this, start, end);
579
+ case "ascii":
580
+ return asciiSlice(this, start, end);
581
+ case "latin1":
582
+ case "binary":
583
+ return latin1Slice(this, start, end);
584
+ case "base64":
585
+ return base64Slice(this, start, end);
586
+ case "ucs2":
587
+ case "ucs-2":
588
+ case "utf16le":
589
+ case "utf-16le":
590
+ return utf16leSlice(this, start, end);
591
+ default:
592
+ if (loweredCase) throw new TypeError("Unknown encoding: " + encoding);
593
+ encoding = (encoding + "").toLowerCase();
594
+ loweredCase = true;
595
+ }
596
+ }
597
+ }
598
+ Buffer3.prototype._isBuffer = true;
599
+ function swap(b, n, m) {
600
+ const i = b[n];
601
+ b[n] = b[m];
602
+ b[m] = i;
603
+ }
604
+ Buffer3.prototype.swap16 = function swap16() {
605
+ const len = this.length;
606
+ if (len % 2 !== 0) {
607
+ throw new RangeError("Buffer size must be a multiple of 16-bits");
608
+ }
609
+ for (let i = 0; i < len; i += 2) {
610
+ swap(this, i, i + 1);
611
+ }
612
+ return this;
613
+ };
614
+ Buffer3.prototype.swap32 = function swap32() {
615
+ const len = this.length;
616
+ if (len % 4 !== 0) {
617
+ throw new RangeError("Buffer size must be a multiple of 32-bits");
618
+ }
619
+ for (let i = 0; i < len; i += 4) {
620
+ swap(this, i, i + 3);
621
+ swap(this, i + 1, i + 2);
622
+ }
623
+ return this;
624
+ };
625
+ Buffer3.prototype.swap64 = function swap64() {
626
+ const len = this.length;
627
+ if (len % 8 !== 0) {
628
+ throw new RangeError("Buffer size must be a multiple of 64-bits");
629
+ }
630
+ for (let i = 0; i < len; i += 8) {
631
+ swap(this, i, i + 7);
632
+ swap(this, i + 1, i + 6);
633
+ swap(this, i + 2, i + 5);
634
+ swap(this, i + 3, i + 4);
635
+ }
636
+ return this;
637
+ };
638
+ Buffer3.prototype.toString = function toString() {
639
+ const length = this.length;
640
+ if (length === 0) return "";
641
+ if (arguments.length === 0) return utf8Slice(this, 0, length);
642
+ return slowToString.apply(this, arguments);
643
+ };
644
+ Buffer3.prototype.toLocaleString = Buffer3.prototype.toString;
645
+ Buffer3.prototype.equals = function equals(b) {
646
+ if (!Buffer3.isBuffer(b)) throw new TypeError("Argument must be a Buffer");
647
+ if (this === b) return true;
648
+ return Buffer3.compare(this, b) === 0;
649
+ };
650
+ Buffer3.prototype.inspect = function inspect() {
651
+ let str = "";
652
+ const max = exports.INSPECT_MAX_BYTES;
653
+ str = this.toString("hex", 0, max).replace(/(.{2})/g, "$1 ").trim();
654
+ if (this.length > max) str += " ... ";
655
+ return "<Buffer " + str + ">";
656
+ };
657
+ if (customInspectSymbol) {
658
+ Buffer3.prototype[customInspectSymbol] = Buffer3.prototype.inspect;
659
+ }
660
+ Buffer3.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
661
+ if (isInstance(target, Uint8Array)) {
662
+ target = Buffer3.from(target, target.offset, target.byteLength);
663
+ }
664
+ if (!Buffer3.isBuffer(target)) {
665
+ throw new TypeError(
666
+ 'The "target" argument must be one of type Buffer or Uint8Array. Received type ' + typeof target
667
+ );
668
+ }
669
+ if (start === void 0) {
670
+ start = 0;
671
+ }
672
+ if (end === void 0) {
673
+ end = target ? target.length : 0;
674
+ }
675
+ if (thisStart === void 0) {
676
+ thisStart = 0;
677
+ }
678
+ if (thisEnd === void 0) {
679
+ thisEnd = this.length;
680
+ }
681
+ if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
682
+ throw new RangeError("out of range index");
683
+ }
684
+ if (thisStart >= thisEnd && start >= end) {
685
+ return 0;
686
+ }
687
+ if (thisStart >= thisEnd) {
688
+ return -1;
689
+ }
690
+ if (start >= end) {
691
+ return 1;
692
+ }
693
+ start >>>= 0;
694
+ end >>>= 0;
695
+ thisStart >>>= 0;
696
+ thisEnd >>>= 0;
697
+ if (this === target) return 0;
698
+ let x = thisEnd - thisStart;
699
+ let y = end - start;
700
+ const len = Math.min(x, y);
701
+ const thisCopy = this.slice(thisStart, thisEnd);
702
+ const targetCopy = target.slice(start, end);
703
+ for (let i = 0; i < len; ++i) {
704
+ if (thisCopy[i] !== targetCopy[i]) {
705
+ x = thisCopy[i];
706
+ y = targetCopy[i];
707
+ break;
708
+ }
709
+ }
710
+ if (x < y) return -1;
711
+ if (y < x) return 1;
712
+ return 0;
713
+ };
714
+ function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
715
+ if (buffer.length === 0) return -1;
716
+ if (typeof byteOffset === "string") {
717
+ encoding = byteOffset;
718
+ byteOffset = 0;
719
+ } else if (byteOffset > 2147483647) {
720
+ byteOffset = 2147483647;
721
+ } else if (byteOffset < -2147483648) {
722
+ byteOffset = -2147483648;
723
+ }
724
+ byteOffset = +byteOffset;
725
+ if (numberIsNaN(byteOffset)) {
726
+ byteOffset = dir ? 0 : buffer.length - 1;
727
+ }
728
+ if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
729
+ if (byteOffset >= buffer.length) {
730
+ if (dir) return -1;
731
+ else byteOffset = buffer.length - 1;
732
+ } else if (byteOffset < 0) {
733
+ if (dir) byteOffset = 0;
734
+ else return -1;
735
+ }
736
+ if (typeof val === "string") {
737
+ val = Buffer3.from(val, encoding);
738
+ }
739
+ if (Buffer3.isBuffer(val)) {
740
+ if (val.length === 0) {
741
+ return -1;
742
+ }
743
+ return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
744
+ } else if (typeof val === "number") {
745
+ val = val & 255;
746
+ if (typeof Uint8Array.prototype.indexOf === "function") {
747
+ if (dir) {
748
+ return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
749
+ } else {
750
+ return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
751
+ }
752
+ }
753
+ return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
754
+ }
755
+ throw new TypeError("val must be string, number or Buffer");
756
+ }
757
+ function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
758
+ let indexSize = 1;
759
+ let arrLength = arr.length;
760
+ let valLength = val.length;
761
+ if (encoding !== void 0) {
762
+ encoding = String(encoding).toLowerCase();
763
+ if (encoding === "ucs2" || encoding === "ucs-2" || encoding === "utf16le" || encoding === "utf-16le") {
764
+ if (arr.length < 2 || val.length < 2) {
765
+ return -1;
766
+ }
767
+ indexSize = 2;
768
+ arrLength /= 2;
769
+ valLength /= 2;
770
+ byteOffset /= 2;
771
+ }
772
+ }
773
+ function read(buf, i2) {
774
+ if (indexSize === 1) {
775
+ return buf[i2];
776
+ } else {
777
+ return buf.readUInt16BE(i2 * indexSize);
778
+ }
779
+ }
780
+ let i;
781
+ if (dir) {
782
+ let foundIndex = -1;
783
+ for (i = byteOffset; i < arrLength; i++) {
784
+ if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
785
+ if (foundIndex === -1) foundIndex = i;
786
+ if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
787
+ } else {
788
+ if (foundIndex !== -1) i -= i - foundIndex;
789
+ foundIndex = -1;
790
+ }
791
+ }
792
+ } else {
793
+ if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
794
+ for (i = byteOffset; i >= 0; i--) {
795
+ let found = true;
796
+ for (let j = 0; j < valLength; j++) {
797
+ if (read(arr, i + j) !== read(val, j)) {
798
+ found = false;
799
+ break;
800
+ }
801
+ }
802
+ if (found) return i;
803
+ }
804
+ }
805
+ return -1;
806
+ }
807
+ Buffer3.prototype.includes = function includes(val, byteOffset, encoding) {
808
+ return this.indexOf(val, byteOffset, encoding) !== -1;
809
+ };
810
+ Buffer3.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
811
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
812
+ };
813
+ Buffer3.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
814
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
815
+ };
816
+ function hexWrite(buf, string, offset, length) {
817
+ offset = Number(offset) || 0;
818
+ const remaining = buf.length - offset;
819
+ if (!length) {
820
+ length = remaining;
821
+ } else {
822
+ length = Number(length);
823
+ if (length > remaining) {
824
+ length = remaining;
825
+ }
826
+ }
827
+ const strLen = string.length;
828
+ if (length > strLen / 2) {
829
+ length = strLen / 2;
830
+ }
831
+ let i;
832
+ for (i = 0; i < length; ++i) {
833
+ const parsed = parseInt(string.substr(i * 2, 2), 16);
834
+ if (numberIsNaN(parsed)) return i;
835
+ buf[offset + i] = parsed;
836
+ }
837
+ return i;
838
+ }
839
+ function utf8Write(buf, string, offset, length) {
840
+ return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
841
+ }
842
+ function asciiWrite(buf, string, offset, length) {
843
+ return blitBuffer(asciiToBytes(string), buf, offset, length);
844
+ }
845
+ function base64Write(buf, string, offset, length) {
846
+ return blitBuffer(base64ToBytes(string), buf, offset, length);
847
+ }
848
+ function ucs2Write(buf, string, offset, length) {
849
+ return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
850
+ }
851
+ Buffer3.prototype.write = function write(string, offset, length, encoding) {
852
+ if (offset === void 0) {
853
+ encoding = "utf8";
854
+ length = this.length;
855
+ offset = 0;
856
+ } else if (length === void 0 && typeof offset === "string") {
857
+ encoding = offset;
858
+ length = this.length;
859
+ offset = 0;
860
+ } else if (isFinite(offset)) {
861
+ offset = offset >>> 0;
862
+ if (isFinite(length)) {
863
+ length = length >>> 0;
864
+ if (encoding === void 0) encoding = "utf8";
865
+ } else {
866
+ encoding = length;
867
+ length = void 0;
868
+ }
869
+ } else {
870
+ throw new Error(
871
+ "Buffer.write(string, encoding, offset[, length]) is no longer supported"
872
+ );
873
+ }
874
+ const remaining = this.length - offset;
875
+ if (length === void 0 || length > remaining) length = remaining;
876
+ if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
877
+ throw new RangeError("Attempt to write outside buffer bounds");
878
+ }
879
+ if (!encoding) encoding = "utf8";
880
+ let loweredCase = false;
881
+ for (; ; ) {
882
+ switch (encoding) {
883
+ case "hex":
884
+ return hexWrite(this, string, offset, length);
885
+ case "utf8":
886
+ case "utf-8":
887
+ return utf8Write(this, string, offset, length);
888
+ case "ascii":
889
+ case "latin1":
890
+ case "binary":
891
+ return asciiWrite(this, string, offset, length);
892
+ case "base64":
893
+ return base64Write(this, string, offset, length);
894
+ case "ucs2":
895
+ case "ucs-2":
896
+ case "utf16le":
897
+ case "utf-16le":
898
+ return ucs2Write(this, string, offset, length);
899
+ default:
900
+ if (loweredCase) throw new TypeError("Unknown encoding: " + encoding);
901
+ encoding = ("" + encoding).toLowerCase();
902
+ loweredCase = true;
903
+ }
904
+ }
905
+ };
906
+ Buffer3.prototype.toJSON = function toJSON() {
907
+ return {
908
+ type: "Buffer",
909
+ data: Array.prototype.slice.call(this._arr || this, 0)
910
+ };
911
+ };
912
+ function base64Slice(buf, start, end) {
913
+ if (start === 0 && end === buf.length) {
914
+ return base64.fromByteArray(buf);
915
+ } else {
916
+ return base64.fromByteArray(buf.slice(start, end));
917
+ }
918
+ }
919
+ function utf8Slice(buf, start, end) {
920
+ end = Math.min(buf.length, end);
921
+ const res = [];
922
+ let i = start;
923
+ while (i < end) {
924
+ const firstByte = buf[i];
925
+ let codePoint = null;
926
+ let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
927
+ if (i + bytesPerSequence <= end) {
928
+ let secondByte, thirdByte, fourthByte, tempCodePoint;
929
+ switch (bytesPerSequence) {
930
+ case 1:
931
+ if (firstByte < 128) {
932
+ codePoint = firstByte;
933
+ }
934
+ break;
935
+ case 2:
936
+ secondByte = buf[i + 1];
937
+ if ((secondByte & 192) === 128) {
938
+ tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;
939
+ if (tempCodePoint > 127) {
940
+ codePoint = tempCodePoint;
941
+ }
942
+ }
943
+ break;
944
+ case 3:
945
+ secondByte = buf[i + 1];
946
+ thirdByte = buf[i + 2];
947
+ if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
948
+ tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
949
+ if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {
950
+ codePoint = tempCodePoint;
951
+ }
952
+ }
953
+ break;
954
+ case 4:
955
+ secondByte = buf[i + 1];
956
+ thirdByte = buf[i + 2];
957
+ fourthByte = buf[i + 3];
958
+ if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
959
+ tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;
960
+ if (tempCodePoint > 65535 && tempCodePoint < 1114112) {
961
+ codePoint = tempCodePoint;
962
+ }
963
+ }
964
+ }
965
+ }
966
+ if (codePoint === null) {
967
+ codePoint = 65533;
968
+ bytesPerSequence = 1;
969
+ } else if (codePoint > 65535) {
970
+ codePoint -= 65536;
971
+ res.push(codePoint >>> 10 & 1023 | 55296);
972
+ codePoint = 56320 | codePoint & 1023;
973
+ }
974
+ res.push(codePoint);
975
+ i += bytesPerSequence;
976
+ }
977
+ return decodeCodePointsArray(res);
978
+ }
979
+ var MAX_ARGUMENTS_LENGTH = 4096;
980
+ function decodeCodePointsArray(codePoints) {
981
+ const len = codePoints.length;
982
+ if (len <= MAX_ARGUMENTS_LENGTH) {
983
+ return String.fromCharCode.apply(String, codePoints);
984
+ }
985
+ let res = "";
986
+ let i = 0;
987
+ while (i < len) {
988
+ res += String.fromCharCode.apply(
989
+ String,
990
+ codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
991
+ );
992
+ }
993
+ return res;
994
+ }
995
+ function asciiSlice(buf, start, end) {
996
+ let ret = "";
997
+ end = Math.min(buf.length, end);
998
+ for (let i = start; i < end; ++i) {
999
+ ret += String.fromCharCode(buf[i] & 127);
1000
+ }
1001
+ return ret;
1002
+ }
1003
+ function latin1Slice(buf, start, end) {
1004
+ let ret = "";
1005
+ end = Math.min(buf.length, end);
1006
+ for (let i = start; i < end; ++i) {
1007
+ ret += String.fromCharCode(buf[i]);
1008
+ }
1009
+ return ret;
1010
+ }
1011
+ function hexSlice(buf, start, end) {
1012
+ const len = buf.length;
1013
+ if (!start || start < 0) start = 0;
1014
+ if (!end || end < 0 || end > len) end = len;
1015
+ let out = "";
1016
+ for (let i = start; i < end; ++i) {
1017
+ out += hexSliceLookupTable[buf[i]];
1018
+ }
1019
+ return out;
1020
+ }
1021
+ function utf16leSlice(buf, start, end) {
1022
+ const bytes = buf.slice(start, end);
1023
+ let res = "";
1024
+ for (let i = 0; i < bytes.length - 1; i += 2) {
1025
+ res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
1026
+ }
1027
+ return res;
1028
+ }
1029
+ Buffer3.prototype.slice = function slice(start, end) {
1030
+ const len = this.length;
1031
+ start = ~~start;
1032
+ end = end === void 0 ? len : ~~end;
1033
+ if (start < 0) {
1034
+ start += len;
1035
+ if (start < 0) start = 0;
1036
+ } else if (start > len) {
1037
+ start = len;
1038
+ }
1039
+ if (end < 0) {
1040
+ end += len;
1041
+ if (end < 0) end = 0;
1042
+ } else if (end > len) {
1043
+ end = len;
1044
+ }
1045
+ if (end < start) end = start;
1046
+ const newBuf = this.subarray(start, end);
1047
+ Object.setPrototypeOf(newBuf, Buffer3.prototype);
1048
+ return newBuf;
1049
+ };
1050
+ function checkOffset(offset, ext, length) {
1051
+ if (offset % 1 !== 0 || offset < 0) throw new RangeError("offset is not uint");
1052
+ if (offset + ext > length) throw new RangeError("Trying to access beyond buffer length");
1053
+ }
1054
+ Buffer3.prototype.readUintLE = Buffer3.prototype.readUIntLE = function readUIntLE(offset, byteLength2, noAssert) {
1055
+ offset = offset >>> 0;
1056
+ byteLength2 = byteLength2 >>> 0;
1057
+ if (!noAssert) checkOffset(offset, byteLength2, this.length);
1058
+ let val = this[offset];
1059
+ let mul = 1;
1060
+ let i = 0;
1061
+ while (++i < byteLength2 && (mul *= 256)) {
1062
+ val += this[offset + i] * mul;
1063
+ }
1064
+ return val;
1065
+ };
1066
+ Buffer3.prototype.readUintBE = Buffer3.prototype.readUIntBE = function readUIntBE(offset, byteLength2, noAssert) {
1067
+ offset = offset >>> 0;
1068
+ byteLength2 = byteLength2 >>> 0;
1069
+ if (!noAssert) {
1070
+ checkOffset(offset, byteLength2, this.length);
1071
+ }
1072
+ let val = this[offset + --byteLength2];
1073
+ let mul = 1;
1074
+ while (byteLength2 > 0 && (mul *= 256)) {
1075
+ val += this[offset + --byteLength2] * mul;
1076
+ }
1077
+ return val;
1078
+ };
1079
+ Buffer3.prototype.readUint8 = Buffer3.prototype.readUInt8 = function readUInt8(offset, noAssert) {
1080
+ offset = offset >>> 0;
1081
+ if (!noAssert) checkOffset(offset, 1, this.length);
1082
+ return this[offset];
1083
+ };
1084
+ Buffer3.prototype.readUint16LE = Buffer3.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
1085
+ offset = offset >>> 0;
1086
+ if (!noAssert) checkOffset(offset, 2, this.length);
1087
+ return this[offset] | this[offset + 1] << 8;
1088
+ };
1089
+ Buffer3.prototype.readUint16BE = Buffer3.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
1090
+ offset = offset >>> 0;
1091
+ if (!noAssert) checkOffset(offset, 2, this.length);
1092
+ return this[offset] << 8 | this[offset + 1];
1093
+ };
1094
+ Buffer3.prototype.readUint32LE = Buffer3.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
1095
+ offset = offset >>> 0;
1096
+ if (!noAssert) checkOffset(offset, 4, this.length);
1097
+ return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216;
1098
+ };
1099
+ Buffer3.prototype.readUint32BE = Buffer3.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
1100
+ offset = offset >>> 0;
1101
+ if (!noAssert) checkOffset(offset, 4, this.length);
1102
+ return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
1103
+ };
1104
+ Buffer3.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE(offset) {
1105
+ offset = offset >>> 0;
1106
+ validateNumber(offset, "offset");
1107
+ const first = this[offset];
1108
+ const last = this[offset + 7];
1109
+ if (first === void 0 || last === void 0) {
1110
+ boundsError(offset, this.length - 8);
1111
+ }
1112
+ const lo = first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24;
1113
+ const hi = this[++offset] + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + last * 2 ** 24;
1114
+ return BigInt(lo) + (BigInt(hi) << BigInt(32));
1115
+ });
1116
+ Buffer3.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE(offset) {
1117
+ offset = offset >>> 0;
1118
+ validateNumber(offset, "offset");
1119
+ const first = this[offset];
1120
+ const last = this[offset + 7];
1121
+ if (first === void 0 || last === void 0) {
1122
+ boundsError(offset, this.length - 8);
1123
+ }
1124
+ const hi = first * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];
1125
+ const lo = this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last;
1126
+ return (BigInt(hi) << BigInt(32)) + BigInt(lo);
1127
+ });
1128
+ Buffer3.prototype.readIntLE = function readIntLE(offset, byteLength2, noAssert) {
1129
+ offset = offset >>> 0;
1130
+ byteLength2 = byteLength2 >>> 0;
1131
+ if (!noAssert) checkOffset(offset, byteLength2, this.length);
1132
+ let val = this[offset];
1133
+ let mul = 1;
1134
+ let i = 0;
1135
+ while (++i < byteLength2 && (mul *= 256)) {
1136
+ val += this[offset + i] * mul;
1137
+ }
1138
+ mul *= 128;
1139
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength2);
1140
+ return val;
1141
+ };
1142
+ Buffer3.prototype.readIntBE = function readIntBE(offset, byteLength2, noAssert) {
1143
+ offset = offset >>> 0;
1144
+ byteLength2 = byteLength2 >>> 0;
1145
+ if (!noAssert) checkOffset(offset, byteLength2, this.length);
1146
+ let i = byteLength2;
1147
+ let mul = 1;
1148
+ let val = this[offset + --i];
1149
+ while (i > 0 && (mul *= 256)) {
1150
+ val += this[offset + --i] * mul;
1151
+ }
1152
+ mul *= 128;
1153
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength2);
1154
+ return val;
1155
+ };
1156
+ Buffer3.prototype.readInt8 = function readInt8(offset, noAssert) {
1157
+ offset = offset >>> 0;
1158
+ if (!noAssert) checkOffset(offset, 1, this.length);
1159
+ if (!(this[offset] & 128)) return this[offset];
1160
+ return (255 - this[offset] + 1) * -1;
1161
+ };
1162
+ Buffer3.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
1163
+ offset = offset >>> 0;
1164
+ if (!noAssert) checkOffset(offset, 2, this.length);
1165
+ const val = this[offset] | this[offset + 1] << 8;
1166
+ return val & 32768 ? val | 4294901760 : val;
1167
+ };
1168
+ Buffer3.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
1169
+ offset = offset >>> 0;
1170
+ if (!noAssert) checkOffset(offset, 2, this.length);
1171
+ const val = this[offset + 1] | this[offset] << 8;
1172
+ return val & 32768 ? val | 4294901760 : val;
1173
+ };
1174
+ Buffer3.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
1175
+ offset = offset >>> 0;
1176
+ if (!noAssert) checkOffset(offset, 4, this.length);
1177
+ return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
1178
+ };
1179
+ Buffer3.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
1180
+ offset = offset >>> 0;
1181
+ if (!noAssert) checkOffset(offset, 4, this.length);
1182
+ return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
1183
+ };
1184
+ Buffer3.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE(offset) {
1185
+ offset = offset >>> 0;
1186
+ validateNumber(offset, "offset");
1187
+ const first = this[offset];
1188
+ const last = this[offset + 7];
1189
+ if (first === void 0 || last === void 0) {
1190
+ boundsError(offset, this.length - 8);
1191
+ }
1192
+ const val = this[offset + 4] + this[offset + 5] * 2 ** 8 + this[offset + 6] * 2 ** 16 + (last << 24);
1193
+ return (BigInt(val) << BigInt(32)) + BigInt(first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24);
1194
+ });
1195
+ Buffer3.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE(offset) {
1196
+ offset = offset >>> 0;
1197
+ validateNumber(offset, "offset");
1198
+ const first = this[offset];
1199
+ const last = this[offset + 7];
1200
+ if (first === void 0 || last === void 0) {
1201
+ boundsError(offset, this.length - 8);
1202
+ }
1203
+ const val = (first << 24) + // Overflow
1204
+ this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];
1205
+ return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last);
1206
+ });
1207
+ Buffer3.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
1208
+ offset = offset >>> 0;
1209
+ if (!noAssert) checkOffset(offset, 4, this.length);
1210
+ return ieee754.read(this, offset, true, 23, 4);
1211
+ };
1212
+ Buffer3.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
1213
+ offset = offset >>> 0;
1214
+ if (!noAssert) checkOffset(offset, 4, this.length);
1215
+ return ieee754.read(this, offset, false, 23, 4);
1216
+ };
1217
+ Buffer3.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
1218
+ offset = offset >>> 0;
1219
+ if (!noAssert) checkOffset(offset, 8, this.length);
1220
+ return ieee754.read(this, offset, true, 52, 8);
1221
+ };
1222
+ Buffer3.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
1223
+ offset = offset >>> 0;
1224
+ if (!noAssert) checkOffset(offset, 8, this.length);
1225
+ return ieee754.read(this, offset, false, 52, 8);
1226
+ };
1227
+ function checkInt(buf, value, offset, ext, max, min) {
1228
+ if (!Buffer3.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance');
1229
+ if (value > max || value < min) throw new RangeError('"value" argument is out of bounds');
1230
+ if (offset + ext > buf.length) throw new RangeError("Index out of range");
1231
+ }
1232
+ Buffer3.prototype.writeUintLE = Buffer3.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength2, noAssert) {
1233
+ value = +value;
1234
+ offset = offset >>> 0;
1235
+ byteLength2 = byteLength2 >>> 0;
1236
+ if (!noAssert) {
1237
+ const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
1238
+ checkInt(this, value, offset, byteLength2, maxBytes, 0);
1239
+ }
1240
+ let mul = 1;
1241
+ let i = 0;
1242
+ this[offset] = value & 255;
1243
+ while (++i < byteLength2 && (mul *= 256)) {
1244
+ this[offset + i] = value / mul & 255;
1245
+ }
1246
+ return offset + byteLength2;
1247
+ };
1248
+ Buffer3.prototype.writeUintBE = Buffer3.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength2, noAssert) {
1249
+ value = +value;
1250
+ offset = offset >>> 0;
1251
+ byteLength2 = byteLength2 >>> 0;
1252
+ if (!noAssert) {
1253
+ const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
1254
+ checkInt(this, value, offset, byteLength2, maxBytes, 0);
1255
+ }
1256
+ let i = byteLength2 - 1;
1257
+ let mul = 1;
1258
+ this[offset + i] = value & 255;
1259
+ while (--i >= 0 && (mul *= 256)) {
1260
+ this[offset + i] = value / mul & 255;
1261
+ }
1262
+ return offset + byteLength2;
1263
+ };
1264
+ Buffer3.prototype.writeUint8 = Buffer3.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
1265
+ value = +value;
1266
+ offset = offset >>> 0;
1267
+ if (!noAssert) checkInt(this, value, offset, 1, 255, 0);
1268
+ this[offset] = value & 255;
1269
+ return offset + 1;
1270
+ };
1271
+ Buffer3.prototype.writeUint16LE = Buffer3.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
1272
+ value = +value;
1273
+ offset = offset >>> 0;
1274
+ if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);
1275
+ this[offset] = value & 255;
1276
+ this[offset + 1] = value >>> 8;
1277
+ return offset + 2;
1278
+ };
1279
+ Buffer3.prototype.writeUint16BE = Buffer3.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
1280
+ value = +value;
1281
+ offset = offset >>> 0;
1282
+ if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);
1283
+ this[offset] = value >>> 8;
1284
+ this[offset + 1] = value & 255;
1285
+ return offset + 2;
1286
+ };
1287
+ Buffer3.prototype.writeUint32LE = Buffer3.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
1288
+ value = +value;
1289
+ offset = offset >>> 0;
1290
+ if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);
1291
+ this[offset + 3] = value >>> 24;
1292
+ this[offset + 2] = value >>> 16;
1293
+ this[offset + 1] = value >>> 8;
1294
+ this[offset] = value & 255;
1295
+ return offset + 4;
1296
+ };
1297
+ Buffer3.prototype.writeUint32BE = Buffer3.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
1298
+ value = +value;
1299
+ offset = offset >>> 0;
1300
+ if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);
1301
+ this[offset] = value >>> 24;
1302
+ this[offset + 1] = value >>> 16;
1303
+ this[offset + 2] = value >>> 8;
1304
+ this[offset + 3] = value & 255;
1305
+ return offset + 4;
1306
+ };
1307
+ function wrtBigUInt64LE(buf, value, offset, min, max) {
1308
+ checkIntBI(value, min, max, buf, offset, 7);
1309
+ let lo = Number(value & BigInt(4294967295));
1310
+ buf[offset++] = lo;
1311
+ lo = lo >> 8;
1312
+ buf[offset++] = lo;
1313
+ lo = lo >> 8;
1314
+ buf[offset++] = lo;
1315
+ lo = lo >> 8;
1316
+ buf[offset++] = lo;
1317
+ let hi = Number(value >> BigInt(32) & BigInt(4294967295));
1318
+ buf[offset++] = hi;
1319
+ hi = hi >> 8;
1320
+ buf[offset++] = hi;
1321
+ hi = hi >> 8;
1322
+ buf[offset++] = hi;
1323
+ hi = hi >> 8;
1324
+ buf[offset++] = hi;
1325
+ return offset;
1326
+ }
1327
+ function wrtBigUInt64BE(buf, value, offset, min, max) {
1328
+ checkIntBI(value, min, max, buf, offset, 7);
1329
+ let lo = Number(value & BigInt(4294967295));
1330
+ buf[offset + 7] = lo;
1331
+ lo = lo >> 8;
1332
+ buf[offset + 6] = lo;
1333
+ lo = lo >> 8;
1334
+ buf[offset + 5] = lo;
1335
+ lo = lo >> 8;
1336
+ buf[offset + 4] = lo;
1337
+ let hi = Number(value >> BigInt(32) & BigInt(4294967295));
1338
+ buf[offset + 3] = hi;
1339
+ hi = hi >> 8;
1340
+ buf[offset + 2] = hi;
1341
+ hi = hi >> 8;
1342
+ buf[offset + 1] = hi;
1343
+ hi = hi >> 8;
1344
+ buf[offset] = hi;
1345
+ return offset + 8;
1346
+ }
1347
+ Buffer3.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE(value, offset = 0) {
1348
+ return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
1349
+ });
1350
+ Buffer3.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE(value, offset = 0) {
1351
+ return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
1352
+ });
1353
+ Buffer3.prototype.writeIntLE = function writeIntLE(value, offset, byteLength2, noAssert) {
1354
+ value = +value;
1355
+ offset = offset >>> 0;
1356
+ if (!noAssert) {
1357
+ const limit = Math.pow(2, 8 * byteLength2 - 1);
1358
+ checkInt(this, value, offset, byteLength2, limit - 1, -limit);
1359
+ }
1360
+ let i = 0;
1361
+ let mul = 1;
1362
+ let sub = 0;
1363
+ this[offset] = value & 255;
1364
+ while (++i < byteLength2 && (mul *= 256)) {
1365
+ if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
1366
+ sub = 1;
1367
+ }
1368
+ this[offset + i] = (value / mul >> 0) - sub & 255;
1369
+ }
1370
+ return offset + byteLength2;
1371
+ };
1372
+ Buffer3.prototype.writeIntBE = function writeIntBE(value, offset, byteLength2, noAssert) {
1373
+ value = +value;
1374
+ offset = offset >>> 0;
1375
+ if (!noAssert) {
1376
+ const limit = Math.pow(2, 8 * byteLength2 - 1);
1377
+ checkInt(this, value, offset, byteLength2, limit - 1, -limit);
1378
+ }
1379
+ let i = byteLength2 - 1;
1380
+ let mul = 1;
1381
+ let sub = 0;
1382
+ this[offset + i] = value & 255;
1383
+ while (--i >= 0 && (mul *= 256)) {
1384
+ if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
1385
+ sub = 1;
1386
+ }
1387
+ this[offset + i] = (value / mul >> 0) - sub & 255;
1388
+ }
1389
+ return offset + byteLength2;
1390
+ };
1391
+ Buffer3.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
1392
+ value = +value;
1393
+ offset = offset >>> 0;
1394
+ if (!noAssert) checkInt(this, value, offset, 1, 127, -128);
1395
+ if (value < 0) value = 255 + value + 1;
1396
+ this[offset] = value & 255;
1397
+ return offset + 1;
1398
+ };
1399
+ Buffer3.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
1400
+ value = +value;
1401
+ offset = offset >>> 0;
1402
+ if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);
1403
+ this[offset] = value & 255;
1404
+ this[offset + 1] = value >>> 8;
1405
+ return offset + 2;
1406
+ };
1407
+ Buffer3.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
1408
+ value = +value;
1409
+ offset = offset >>> 0;
1410
+ if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);
1411
+ this[offset] = value >>> 8;
1412
+ this[offset + 1] = value & 255;
1413
+ return offset + 2;
1414
+ };
1415
+ Buffer3.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
1416
+ value = +value;
1417
+ offset = offset >>> 0;
1418
+ if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);
1419
+ this[offset] = value & 255;
1420
+ this[offset + 1] = value >>> 8;
1421
+ this[offset + 2] = value >>> 16;
1422
+ this[offset + 3] = value >>> 24;
1423
+ return offset + 4;
1424
+ };
1425
+ Buffer3.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
1426
+ value = +value;
1427
+ offset = offset >>> 0;
1428
+ if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);
1429
+ if (value < 0) value = 4294967295 + value + 1;
1430
+ this[offset] = value >>> 24;
1431
+ this[offset + 1] = value >>> 16;
1432
+ this[offset + 2] = value >>> 8;
1433
+ this[offset + 3] = value & 255;
1434
+ return offset + 4;
1435
+ };
1436
+ Buffer3.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE(value, offset = 0) {
1437
+ return wrtBigUInt64LE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
1438
+ });
1439
+ Buffer3.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE(value, offset = 0) {
1440
+ return wrtBigUInt64BE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
1441
+ });
1442
+ function checkIEEE754(buf, value, offset, ext, max, min) {
1443
+ if (offset + ext > buf.length) throw new RangeError("Index out of range");
1444
+ if (offset < 0) throw new RangeError("Index out of range");
1445
+ }
1446
+ function writeFloat(buf, value, offset, littleEndian, noAssert) {
1447
+ value = +value;
1448
+ offset = offset >>> 0;
1449
+ if (!noAssert) {
1450
+ checkIEEE754(buf, value, offset, 4, 34028234663852886e22, -34028234663852886e22);
1451
+ }
1452
+ ieee754.write(buf, value, offset, littleEndian, 23, 4);
1453
+ return offset + 4;
1454
+ }
1455
+ Buffer3.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
1456
+ return writeFloat(this, value, offset, true, noAssert);
1457
+ };
1458
+ Buffer3.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
1459
+ return writeFloat(this, value, offset, false, noAssert);
1460
+ };
1461
+ function writeDouble(buf, value, offset, littleEndian, noAssert) {
1462
+ value = +value;
1463
+ offset = offset >>> 0;
1464
+ if (!noAssert) {
1465
+ checkIEEE754(buf, value, offset, 8, 17976931348623157e292, -17976931348623157e292);
1466
+ }
1467
+ ieee754.write(buf, value, offset, littleEndian, 52, 8);
1468
+ return offset + 8;
1469
+ }
1470
+ Buffer3.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
1471
+ return writeDouble(this, value, offset, true, noAssert);
1472
+ };
1473
+ Buffer3.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
1474
+ return writeDouble(this, value, offset, false, noAssert);
1475
+ };
1476
+ Buffer3.prototype.copy = function copy(target, targetStart, start, end) {
1477
+ if (!Buffer3.isBuffer(target)) throw new TypeError("argument should be a Buffer");
1478
+ if (!start) start = 0;
1479
+ if (!end && end !== 0) end = this.length;
1480
+ if (targetStart >= target.length) targetStart = target.length;
1481
+ if (!targetStart) targetStart = 0;
1482
+ if (end > 0 && end < start) end = start;
1483
+ if (end === start) return 0;
1484
+ if (target.length === 0 || this.length === 0) return 0;
1485
+ if (targetStart < 0) {
1486
+ throw new RangeError("targetStart out of bounds");
1487
+ }
1488
+ if (start < 0 || start >= this.length) throw new RangeError("Index out of range");
1489
+ if (end < 0) throw new RangeError("sourceEnd out of bounds");
1490
+ if (end > this.length) end = this.length;
1491
+ if (target.length - targetStart < end - start) {
1492
+ end = target.length - targetStart + start;
1493
+ }
1494
+ const len = end - start;
1495
+ if (this === target && typeof Uint8Array.prototype.copyWithin === "function") {
1496
+ this.copyWithin(targetStart, start, end);
1497
+ } else {
1498
+ Uint8Array.prototype.set.call(
1499
+ target,
1500
+ this.subarray(start, end),
1501
+ targetStart
1502
+ );
1503
+ }
1504
+ return len;
1505
+ };
1506
+ Buffer3.prototype.fill = function fill(val, start, end, encoding) {
1507
+ if (typeof val === "string") {
1508
+ if (typeof start === "string") {
1509
+ encoding = start;
1510
+ start = 0;
1511
+ end = this.length;
1512
+ } else if (typeof end === "string") {
1513
+ encoding = end;
1514
+ end = this.length;
1515
+ }
1516
+ if (encoding !== void 0 && typeof encoding !== "string") {
1517
+ throw new TypeError("encoding must be a string");
1518
+ }
1519
+ if (typeof encoding === "string" && !Buffer3.isEncoding(encoding)) {
1520
+ throw new TypeError("Unknown encoding: " + encoding);
1521
+ }
1522
+ if (val.length === 1) {
1523
+ const code = val.charCodeAt(0);
1524
+ if (encoding === "utf8" && code < 128 || encoding === "latin1") {
1525
+ val = code;
1526
+ }
1527
+ }
1528
+ } else if (typeof val === "number") {
1529
+ val = val & 255;
1530
+ } else if (typeof val === "boolean") {
1531
+ val = Number(val);
1532
+ }
1533
+ if (start < 0 || this.length < start || this.length < end) {
1534
+ throw new RangeError("Out of range index");
1535
+ }
1536
+ if (end <= start) {
1537
+ return this;
1538
+ }
1539
+ start = start >>> 0;
1540
+ end = end === void 0 ? this.length : end >>> 0;
1541
+ if (!val) val = 0;
1542
+ let i;
1543
+ if (typeof val === "number") {
1544
+ for (i = start; i < end; ++i) {
1545
+ this[i] = val;
1546
+ }
1547
+ } else {
1548
+ const bytes = Buffer3.isBuffer(val) ? val : Buffer3.from(val, encoding);
1549
+ const len = bytes.length;
1550
+ if (len === 0) {
1551
+ throw new TypeError('The value "' + val + '" is invalid for argument "value"');
1552
+ }
1553
+ for (i = 0; i < end - start; ++i) {
1554
+ this[i + start] = bytes[i % len];
1555
+ }
1556
+ }
1557
+ return this;
1558
+ };
1559
+ var errors = {};
1560
+ function E(sym, getMessage, Base) {
1561
+ errors[sym] = class NodeError extends Base {
1562
+ constructor() {
1563
+ super();
1564
+ Object.defineProperty(this, "message", {
1565
+ value: getMessage.apply(this, arguments),
1566
+ writable: true,
1567
+ configurable: true
1568
+ });
1569
+ this.name = `${this.name} [${sym}]`;
1570
+ this.stack;
1571
+ delete this.name;
1572
+ }
1573
+ get code() {
1574
+ return sym;
1575
+ }
1576
+ set code(value) {
1577
+ Object.defineProperty(this, "code", {
1578
+ configurable: true,
1579
+ enumerable: true,
1580
+ value,
1581
+ writable: true
1582
+ });
1583
+ }
1584
+ toString() {
1585
+ return `${this.name} [${sym}]: ${this.message}`;
1586
+ }
1587
+ };
1588
+ }
1589
+ E(
1590
+ "ERR_BUFFER_OUT_OF_BOUNDS",
1591
+ function(name) {
1592
+ if (name) {
1593
+ return `${name} is outside of buffer bounds`;
1594
+ }
1595
+ return "Attempt to access memory outside buffer bounds";
1596
+ },
1597
+ RangeError
1598
+ );
1599
+ E(
1600
+ "ERR_INVALID_ARG_TYPE",
1601
+ function(name, actual) {
1602
+ return `The "${name}" argument must be of type number. Received type ${typeof actual}`;
1603
+ },
1604
+ TypeError
1605
+ );
1606
+ E(
1607
+ "ERR_OUT_OF_RANGE",
1608
+ function(str, range, input) {
1609
+ let msg = `The value of "${str}" is out of range.`;
1610
+ let received = input;
1611
+ if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
1612
+ received = addNumericalSeparator(String(input));
1613
+ } else if (typeof input === "bigint") {
1614
+ received = String(input);
1615
+ if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
1616
+ received = addNumericalSeparator(received);
1617
+ }
1618
+ received += "n";
1619
+ }
1620
+ msg += ` It must be ${range}. Received ${received}`;
1621
+ return msg;
1622
+ },
1623
+ RangeError
1624
+ );
1625
+ function addNumericalSeparator(val) {
1626
+ let res = "";
1627
+ let i = val.length;
1628
+ const start = val[0] === "-" ? 1 : 0;
1629
+ for (; i >= start + 4; i -= 3) {
1630
+ res = `_${val.slice(i - 3, i)}${res}`;
1631
+ }
1632
+ return `${val.slice(0, i)}${res}`;
1633
+ }
1634
+ function checkBounds(buf, offset, byteLength2) {
1635
+ validateNumber(offset, "offset");
1636
+ if (buf[offset] === void 0 || buf[offset + byteLength2] === void 0) {
1637
+ boundsError(offset, buf.length - (byteLength2 + 1));
1638
+ }
1639
+ }
1640
+ function checkIntBI(value, min, max, buf, offset, byteLength2) {
1641
+ if (value > max || value < min) {
1642
+ const n = typeof min === "bigint" ? "n" : "";
1643
+ let range;
1644
+ if (byteLength2 > 3) {
1645
+ if (min === 0 || min === BigInt(0)) {
1646
+ range = `>= 0${n} and < 2${n} ** ${(byteLength2 + 1) * 8}${n}`;
1647
+ } else {
1648
+ range = `>= -(2${n} ** ${(byteLength2 + 1) * 8 - 1}${n}) and < 2 ** ${(byteLength2 + 1) * 8 - 1}${n}`;
1649
+ }
1650
+ } else {
1651
+ range = `>= ${min}${n} and <= ${max}${n}`;
1652
+ }
1653
+ throw new errors.ERR_OUT_OF_RANGE("value", range, value);
1654
+ }
1655
+ checkBounds(buf, offset, byteLength2);
1656
+ }
1657
+ function validateNumber(value, name) {
1658
+ if (typeof value !== "number") {
1659
+ throw new errors.ERR_INVALID_ARG_TYPE(name, "number", value);
1660
+ }
1661
+ }
1662
+ function boundsError(value, length, type) {
1663
+ if (Math.floor(value) !== value) {
1664
+ validateNumber(value, type);
1665
+ throw new errors.ERR_OUT_OF_RANGE(type || "offset", "an integer", value);
1666
+ }
1667
+ if (length < 0) {
1668
+ throw new errors.ERR_BUFFER_OUT_OF_BOUNDS();
1669
+ }
1670
+ throw new errors.ERR_OUT_OF_RANGE(
1671
+ type || "offset",
1672
+ `>= ${type ? 1 : 0} and <= ${length}`,
1673
+ value
1674
+ );
1675
+ }
1676
+ var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
1677
+ function base64clean(str) {
1678
+ str = str.split("=")[0];
1679
+ str = str.trim().replace(INVALID_BASE64_RE, "");
1680
+ if (str.length < 2) return "";
1681
+ while (str.length % 4 !== 0) {
1682
+ str = str + "=";
1683
+ }
1684
+ return str;
1685
+ }
1686
+ function utf8ToBytes(string, units) {
1687
+ units = units || Infinity;
1688
+ let codePoint;
1689
+ const length = string.length;
1690
+ let leadSurrogate = null;
1691
+ const bytes = [];
1692
+ for (let i = 0; i < length; ++i) {
1693
+ codePoint = string.charCodeAt(i);
1694
+ if (codePoint > 55295 && codePoint < 57344) {
1695
+ if (!leadSurrogate) {
1696
+ if (codePoint > 56319) {
1697
+ if ((units -= 3) > -1) bytes.push(239, 191, 189);
1698
+ continue;
1699
+ } else if (i + 1 === length) {
1700
+ if ((units -= 3) > -1) bytes.push(239, 191, 189);
1701
+ continue;
1702
+ }
1703
+ leadSurrogate = codePoint;
1704
+ continue;
1705
+ }
1706
+ if (codePoint < 56320) {
1707
+ if ((units -= 3) > -1) bytes.push(239, 191, 189);
1708
+ leadSurrogate = codePoint;
1709
+ continue;
1710
+ }
1711
+ codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;
1712
+ } else if (leadSurrogate) {
1713
+ if ((units -= 3) > -1) bytes.push(239, 191, 189);
1714
+ }
1715
+ leadSurrogate = null;
1716
+ if (codePoint < 128) {
1717
+ if ((units -= 1) < 0) break;
1718
+ bytes.push(codePoint);
1719
+ } else if (codePoint < 2048) {
1720
+ if ((units -= 2) < 0) break;
1721
+ bytes.push(
1722
+ codePoint >> 6 | 192,
1723
+ codePoint & 63 | 128
1724
+ );
1725
+ } else if (codePoint < 65536) {
1726
+ if ((units -= 3) < 0) break;
1727
+ bytes.push(
1728
+ codePoint >> 12 | 224,
1729
+ codePoint >> 6 & 63 | 128,
1730
+ codePoint & 63 | 128
1731
+ );
1732
+ } else if (codePoint < 1114112) {
1733
+ if ((units -= 4) < 0) break;
1734
+ bytes.push(
1735
+ codePoint >> 18 | 240,
1736
+ codePoint >> 12 & 63 | 128,
1737
+ codePoint >> 6 & 63 | 128,
1738
+ codePoint & 63 | 128
1739
+ );
1740
+ } else {
1741
+ throw new Error("Invalid code point");
1742
+ }
1743
+ }
1744
+ return bytes;
1745
+ }
1746
+ function asciiToBytes(str) {
1747
+ const byteArray = [];
1748
+ for (let i = 0; i < str.length; ++i) {
1749
+ byteArray.push(str.charCodeAt(i) & 255);
1750
+ }
1751
+ return byteArray;
1752
+ }
1753
+ function utf16leToBytes(str, units) {
1754
+ let c, hi, lo;
1755
+ const byteArray = [];
1756
+ for (let i = 0; i < str.length; ++i) {
1757
+ if ((units -= 2) < 0) break;
1758
+ c = str.charCodeAt(i);
1759
+ hi = c >> 8;
1760
+ lo = c % 256;
1761
+ byteArray.push(lo);
1762
+ byteArray.push(hi);
1763
+ }
1764
+ return byteArray;
1765
+ }
1766
+ function base64ToBytes(str) {
1767
+ return base64.toByteArray(base64clean(str));
1768
+ }
1769
+ function blitBuffer(src, dst, offset, length) {
1770
+ let i;
1771
+ for (i = 0; i < length; ++i) {
1772
+ if (i + offset >= dst.length || i >= src.length) break;
1773
+ dst[i + offset] = src[i];
1774
+ }
1775
+ return i;
1776
+ }
1777
+ function isInstance(obj, type) {
1778
+ return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;
1779
+ }
1780
+ function numberIsNaN(obj) {
1781
+ return obj !== obj;
1782
+ }
1783
+ var hexSliceLookupTable = function() {
1784
+ const alphabet = "0123456789abcdef";
1785
+ const table = new Array(256);
1786
+ for (let i = 0; i < 16; ++i) {
1787
+ const i16 = i * 16;
1788
+ for (let j = 0; j < 16; ++j) {
1789
+ table[i16 + j] = alphabet[i] + alphabet[j];
1790
+ }
1791
+ }
1792
+ return table;
1793
+ }();
1794
+ function defineBigIntMethod(fn) {
1795
+ return typeof BigInt === "undefined" ? BufferBigIntNotDefined : fn;
1796
+ }
1797
+ function BufferBigIntNotDefined() {
1798
+ throw new Error("BigInt not supported");
1799
+ }
1800
+ }
1801
+ });
1802
+
1803
+ // ../../node_modules/seek-bzip/lib/bitreader.js
1804
+ var require_bitreader = __commonJS({
1805
+ "../../node_modules/seek-bzip/lib/bitreader.js"(exports, module) {
1806
+ var BITMASK = [0, 1, 3, 7, 15, 31, 63, 127, 255];
1807
+ var BitReader = function(stream) {
1808
+ this.stream = stream;
1809
+ this.bitOffset = 0;
1810
+ this.curByte = 0;
1811
+ this.hasByte = false;
1812
+ };
1813
+ BitReader.prototype._ensureByte = function() {
1814
+ if (!this.hasByte) {
1815
+ this.curByte = this.stream.readByte();
1816
+ this.hasByte = true;
1817
+ }
1818
+ };
1819
+ BitReader.prototype.read = function(bits) {
1820
+ var result = 0;
1821
+ while (bits > 0) {
1822
+ this._ensureByte();
1823
+ var remaining = 8 - this.bitOffset;
1824
+ if (bits >= remaining) {
1825
+ result <<= remaining;
1826
+ result |= BITMASK[remaining] & this.curByte;
1827
+ this.hasByte = false;
1828
+ this.bitOffset = 0;
1829
+ bits -= remaining;
1830
+ } else {
1831
+ result <<= bits;
1832
+ var shift = remaining - bits;
1833
+ result |= (this.curByte & BITMASK[bits] << shift) >> shift;
1834
+ this.bitOffset += bits;
1835
+ bits = 0;
1836
+ }
1837
+ }
1838
+ return result;
1839
+ };
1840
+ BitReader.prototype.seek = function(pos) {
1841
+ var n_bit = pos % 8;
1842
+ var n_byte = (pos - n_bit) / 8;
1843
+ this.bitOffset = n_bit;
1844
+ this.stream.seek(n_byte);
1845
+ this.hasByte = false;
1846
+ };
1847
+ BitReader.prototype.pi = function() {
1848
+ var buf = new Buffer(6), i;
1849
+ for (i = 0; i < buf.length; i++) {
1850
+ buf[i] = this.read(8);
1851
+ }
1852
+ return buf.toString("hex");
1853
+ };
1854
+ module.exports = BitReader;
1855
+ }
1856
+ });
1857
+
1858
+ // ../../node_modules/seek-bzip/lib/stream.js
1859
+ var require_stream = __commonJS({
1860
+ "../../node_modules/seek-bzip/lib/stream.js"(exports, module) {
1861
+ var Stream = function() {
1862
+ };
1863
+ Stream.prototype.readByte = function() {
1864
+ throw new Error("abstract method readByte() not implemented");
1865
+ };
1866
+ Stream.prototype.read = function(buffer, bufOffset, length) {
1867
+ var bytesRead = 0;
1868
+ while (bytesRead < length) {
1869
+ var c = this.readByte();
1870
+ if (c < 0) {
1871
+ return bytesRead === 0 ? -1 : bytesRead;
1872
+ }
1873
+ buffer[bufOffset++] = c;
1874
+ bytesRead++;
1875
+ }
1876
+ return bytesRead;
1877
+ };
1878
+ Stream.prototype.seek = function(new_pos) {
1879
+ throw new Error("abstract method seek() not implemented");
1880
+ };
1881
+ Stream.prototype.writeByte = function(_byte) {
1882
+ throw new Error("abstract method readByte() not implemented");
1883
+ };
1884
+ Stream.prototype.write = function(buffer, bufOffset, length) {
1885
+ var i;
1886
+ for (i = 0; i < length; i++) {
1887
+ this.writeByte(buffer[bufOffset++]);
1888
+ }
1889
+ return length;
1890
+ };
1891
+ Stream.prototype.flush = function() {
1892
+ };
1893
+ module.exports = Stream;
1894
+ }
1895
+ });
1896
+
1897
+ // ../../node_modules/seek-bzip/lib/crc32.js
1898
+ var require_crc32 = __commonJS({
1899
+ "../../node_modules/seek-bzip/lib/crc32.js"(exports, module) {
1900
+ module.exports = function() {
1901
+ var crc32Lookup = new Uint32Array([
1902
+ 0,
1903
+ 79764919,
1904
+ 159529838,
1905
+ 222504665,
1906
+ 319059676,
1907
+ 398814059,
1908
+ 445009330,
1909
+ 507990021,
1910
+ 638119352,
1911
+ 583659535,
1912
+ 797628118,
1913
+ 726387553,
1914
+ 890018660,
1915
+ 835552979,
1916
+ 1015980042,
1917
+ 944750013,
1918
+ 1276238704,
1919
+ 1221641927,
1920
+ 1167319070,
1921
+ 1095957929,
1922
+ 1595256236,
1923
+ 1540665371,
1924
+ 1452775106,
1925
+ 1381403509,
1926
+ 1780037320,
1927
+ 1859660671,
1928
+ 1671105958,
1929
+ 1733955601,
1930
+ 2031960084,
1931
+ 2111593891,
1932
+ 1889500026,
1933
+ 1952343757,
1934
+ 2552477408,
1935
+ 2632100695,
1936
+ 2443283854,
1937
+ 2506133561,
1938
+ 2334638140,
1939
+ 2414271883,
1940
+ 2191915858,
1941
+ 2254759653,
1942
+ 3190512472,
1943
+ 3135915759,
1944
+ 3081330742,
1945
+ 3009969537,
1946
+ 2905550212,
1947
+ 2850959411,
1948
+ 2762807018,
1949
+ 2691435357,
1950
+ 3560074640,
1951
+ 3505614887,
1952
+ 3719321342,
1953
+ 3648080713,
1954
+ 3342211916,
1955
+ 3287746299,
1956
+ 3467911202,
1957
+ 3396681109,
1958
+ 4063920168,
1959
+ 4143685023,
1960
+ 4223187782,
1961
+ 4286162673,
1962
+ 3779000052,
1963
+ 3858754371,
1964
+ 3904687514,
1965
+ 3967668269,
1966
+ 881225847,
1967
+ 809987520,
1968
+ 1023691545,
1969
+ 969234094,
1970
+ 662832811,
1971
+ 591600412,
1972
+ 771767749,
1973
+ 717299826,
1974
+ 311336399,
1975
+ 374308984,
1976
+ 453813921,
1977
+ 533576470,
1978
+ 25881363,
1979
+ 88864420,
1980
+ 134795389,
1981
+ 214552010,
1982
+ 2023205639,
1983
+ 2086057648,
1984
+ 1897238633,
1985
+ 1976864222,
1986
+ 1804852699,
1987
+ 1867694188,
1988
+ 1645340341,
1989
+ 1724971778,
1990
+ 1587496639,
1991
+ 1516133128,
1992
+ 1461550545,
1993
+ 1406951526,
1994
+ 1302016099,
1995
+ 1230646740,
1996
+ 1142491917,
1997
+ 1087903418,
1998
+ 2896545431,
1999
+ 2825181984,
2000
+ 2770861561,
2001
+ 2716262478,
2002
+ 3215044683,
2003
+ 3143675388,
2004
+ 3055782693,
2005
+ 3001194130,
2006
+ 2326604591,
2007
+ 2389456536,
2008
+ 2200899649,
2009
+ 2280525302,
2010
+ 2578013683,
2011
+ 2640855108,
2012
+ 2418763421,
2013
+ 2498394922,
2014
+ 3769900519,
2015
+ 3832873040,
2016
+ 3912640137,
2017
+ 3992402750,
2018
+ 4088425275,
2019
+ 4151408268,
2020
+ 4197601365,
2021
+ 4277358050,
2022
+ 3334271071,
2023
+ 3263032808,
2024
+ 3476998961,
2025
+ 3422541446,
2026
+ 3585640067,
2027
+ 3514407732,
2028
+ 3694837229,
2029
+ 3640369242,
2030
+ 1762451694,
2031
+ 1842216281,
2032
+ 1619975040,
2033
+ 1682949687,
2034
+ 2047383090,
2035
+ 2127137669,
2036
+ 1938468188,
2037
+ 2001449195,
2038
+ 1325665622,
2039
+ 1271206113,
2040
+ 1183200824,
2041
+ 1111960463,
2042
+ 1543535498,
2043
+ 1489069629,
2044
+ 1434599652,
2045
+ 1363369299,
2046
+ 622672798,
2047
+ 568075817,
2048
+ 748617968,
2049
+ 677256519,
2050
+ 907627842,
2051
+ 853037301,
2052
+ 1067152940,
2053
+ 995781531,
2054
+ 51762726,
2055
+ 131386257,
2056
+ 177728840,
2057
+ 240578815,
2058
+ 269590778,
2059
+ 349224269,
2060
+ 429104020,
2061
+ 491947555,
2062
+ 4046411278,
2063
+ 4126034873,
2064
+ 4172115296,
2065
+ 4234965207,
2066
+ 3794477266,
2067
+ 3874110821,
2068
+ 3953728444,
2069
+ 4016571915,
2070
+ 3609705398,
2071
+ 3555108353,
2072
+ 3735388376,
2073
+ 3664026991,
2074
+ 3290680682,
2075
+ 3236090077,
2076
+ 3449943556,
2077
+ 3378572211,
2078
+ 3174993278,
2079
+ 3120533705,
2080
+ 3032266256,
2081
+ 2961025959,
2082
+ 2923101090,
2083
+ 2868635157,
2084
+ 2813903052,
2085
+ 2742672763,
2086
+ 2604032198,
2087
+ 2683796849,
2088
+ 2461293480,
2089
+ 2524268063,
2090
+ 2284983834,
2091
+ 2364738477,
2092
+ 2175806836,
2093
+ 2238787779,
2094
+ 1569362073,
2095
+ 1498123566,
2096
+ 1409854455,
2097
+ 1355396672,
2098
+ 1317987909,
2099
+ 1246755826,
2100
+ 1192025387,
2101
+ 1137557660,
2102
+ 2072149281,
2103
+ 2135122070,
2104
+ 1912620623,
2105
+ 1992383480,
2106
+ 1753615357,
2107
+ 1816598090,
2108
+ 1627664531,
2109
+ 1707420964,
2110
+ 295390185,
2111
+ 358241886,
2112
+ 404320391,
2113
+ 483945776,
2114
+ 43990325,
2115
+ 106832002,
2116
+ 186451547,
2117
+ 266083308,
2118
+ 932423249,
2119
+ 861060070,
2120
+ 1041341759,
2121
+ 986742920,
2122
+ 613929101,
2123
+ 542559546,
2124
+ 756411363,
2125
+ 701822548,
2126
+ 3316196985,
2127
+ 3244833742,
2128
+ 3425377559,
2129
+ 3370778784,
2130
+ 3601682597,
2131
+ 3530312978,
2132
+ 3744426955,
2133
+ 3689838204,
2134
+ 3819031489,
2135
+ 3881883254,
2136
+ 3928223919,
2137
+ 4007849240,
2138
+ 4037393693,
2139
+ 4100235434,
2140
+ 4180117107,
2141
+ 4259748804,
2142
+ 2310601993,
2143
+ 2373574846,
2144
+ 2151335527,
2145
+ 2231098320,
2146
+ 2596047829,
2147
+ 2659030626,
2148
+ 2470359227,
2149
+ 2550115596,
2150
+ 2947551409,
2151
+ 2876312838,
2152
+ 2788305887,
2153
+ 2733848168,
2154
+ 3165939309,
2155
+ 3094707162,
2156
+ 3040238851,
2157
+ 2985771188
2158
+ ]);
2159
+ var CRC32 = function() {
2160
+ var crc = 4294967295;
2161
+ this.getCRC = function() {
2162
+ return ~crc >>> 0;
2163
+ };
2164
+ this.updateCRC = function(value) {
2165
+ crc = crc << 8 ^ crc32Lookup[(crc >>> 24 ^ value) & 255];
2166
+ };
2167
+ this.updateCRCRun = function(value, count) {
2168
+ while (count-- > 0) {
2169
+ crc = crc << 8 ^ crc32Lookup[(crc >>> 24 ^ value) & 255];
2170
+ }
2171
+ };
2172
+ };
2173
+ return CRC32;
2174
+ }();
2175
+ }
2176
+ });
2177
+
2178
+ // ../../node_modules/seek-bzip/package.json
2179
+ var require_package = __commonJS({
2180
+ "../../node_modules/seek-bzip/package.json"(exports, module) {
2181
+ module.exports = {
2182
+ name: "seek-bzip",
2183
+ version: "2.0.0",
2184
+ contributors: [
2185
+ "C. Scott Ananian (http://cscott.net)",
2186
+ "Eli Skeggs",
2187
+ "Kevin Kwok",
2188
+ "Rob Landley (http://landley.net)"
2189
+ ],
2190
+ description: "a pure-JavaScript Node.JS module for random-access decoding bzip2 data",
2191
+ main: "./lib/index.js",
2192
+ repository: {
2193
+ type: "git",
2194
+ url: "https://github.com/cscott/seek-bzip.git"
2195
+ },
2196
+ license: "MIT",
2197
+ bin: {
2198
+ "seek-bunzip": "./bin/seek-bunzip",
2199
+ "seek-table": "./bin/seek-bzip-table"
2200
+ },
2201
+ directories: {
2202
+ test: "test"
2203
+ },
2204
+ dependencies: {
2205
+ commander: "^6.0.0"
2206
+ },
2207
+ devDependencies: {
2208
+ fibers: "^5.0.0",
2209
+ mocha: "^8.1.0"
2210
+ },
2211
+ scripts: {
2212
+ test: "mocha"
2213
+ }
2214
+ };
2215
+ }
2216
+ });
2217
+
2218
+ // ../../node_modules/seek-bzip/lib/index.js
2219
+ var require_lib = __commonJS({
2220
+ "../../node_modules/seek-bzip/lib/index.js"(exports, module) {
2221
+ var BitReader = require_bitreader();
2222
+ var Stream = require_stream();
2223
+ var CRC32 = require_crc32();
2224
+ var pjson = require_package();
2225
+ var MAX_HUFCODE_BITS = 20;
2226
+ var MAX_SYMBOLS = 258;
2227
+ var SYMBOL_RUNA = 0;
2228
+ var SYMBOL_RUNB = 1;
2229
+ var MIN_GROUPS = 2;
2230
+ var MAX_GROUPS = 6;
2231
+ var GROUP_SIZE = 50;
2232
+ var WHOLEPI = "314159265359";
2233
+ var SQRTPI = "177245385090";
2234
+ var mtf = function(array, index) {
2235
+ var src = array[index], i;
2236
+ for (i = index; i > 0; i--) {
2237
+ array[i] = array[i - 1];
2238
+ }
2239
+ array[0] = src;
2240
+ return src;
2241
+ };
2242
+ var Err = {
2243
+ OK: 0,
2244
+ LAST_BLOCK: -1,
2245
+ NOT_BZIP_DATA: -2,
2246
+ UNEXPECTED_INPUT_EOF: -3,
2247
+ UNEXPECTED_OUTPUT_EOF: -4,
2248
+ DATA_ERROR: -5,
2249
+ OUT_OF_MEMORY: -6,
2250
+ OBSOLETE_INPUT: -7,
2251
+ END_OF_BLOCK: -8
2252
+ };
2253
+ var ErrorMessages = {};
2254
+ ErrorMessages[Err.LAST_BLOCK] = "Bad file checksum";
2255
+ ErrorMessages[Err.NOT_BZIP_DATA] = "Not bzip data";
2256
+ ErrorMessages[Err.UNEXPECTED_INPUT_EOF] = "Unexpected input EOF";
2257
+ ErrorMessages[Err.UNEXPECTED_OUTPUT_EOF] = "Unexpected output EOF";
2258
+ ErrorMessages[Err.DATA_ERROR] = "Data error";
2259
+ ErrorMessages[Err.OUT_OF_MEMORY] = "Out of memory";
2260
+ ErrorMessages[Err.OBSOLETE_INPUT] = "Obsolete (pre 0.9.5) bzip format not supported.";
2261
+ var _throw = function(status, optDetail) {
2262
+ var msg = ErrorMessages[status] || "unknown error";
2263
+ if (optDetail) {
2264
+ msg += ": " + optDetail;
2265
+ }
2266
+ var e = new TypeError(msg);
2267
+ e.errorCode = status;
2268
+ throw e;
2269
+ };
2270
+ var Bunzip = function(inputStream, outputStream) {
2271
+ this.writePos = this.writeCurrent = this.writeCount = 0;
2272
+ this._start_bunzip(inputStream, outputStream);
2273
+ };
2274
+ Bunzip.prototype._init_block = function() {
2275
+ var moreBlocks = this._get_next_block();
2276
+ if (!moreBlocks) {
2277
+ this.writeCount = -1;
2278
+ return false;
2279
+ }
2280
+ this.blockCRC = new CRC32();
2281
+ return true;
2282
+ };
2283
+ Bunzip.prototype._start_bunzip = function(inputStream, outputStream) {
2284
+ var buf = new Buffer(4);
2285
+ if (inputStream.read(buf, 0, 4) !== 4 || String.fromCharCode(buf[0], buf[1], buf[2]) !== "BZh")
2286
+ _throw(Err.NOT_BZIP_DATA, "bad magic");
2287
+ var level = buf[3] - 48;
2288
+ if (level < 1 || level > 9)
2289
+ _throw(Err.NOT_BZIP_DATA, "level out of range");
2290
+ this.reader = new BitReader(inputStream);
2291
+ this.dbufSize = 1e5 * level;
2292
+ this.nextoutput = 0;
2293
+ this.outputStream = outputStream;
2294
+ this.streamCRC = 0;
2295
+ };
2296
+ Bunzip.prototype._get_next_block = function() {
2297
+ var i, j, k;
2298
+ var reader = this.reader;
2299
+ var h = reader.pi();
2300
+ if (h === SQRTPI) {
2301
+ return false;
2302
+ }
2303
+ if (h !== WHOLEPI)
2304
+ _throw(Err.NOT_BZIP_DATA);
2305
+ this.targetBlockCRC = reader.read(32) >>> 0;
2306
+ this.streamCRC = (this.targetBlockCRC ^ (this.streamCRC << 1 | this.streamCRC >>> 31)) >>> 0;
2307
+ if (reader.read(1))
2308
+ _throw(Err.OBSOLETE_INPUT);
2309
+ var origPointer = reader.read(24);
2310
+ if (origPointer > this.dbufSize)
2311
+ _throw(Err.DATA_ERROR, "initial position out of bounds");
2312
+ var t = reader.read(16);
2313
+ var symToByte = new Buffer(256), symTotal = 0;
2314
+ for (i = 0; i < 16; i++) {
2315
+ if (t & 1 << 15 - i) {
2316
+ var o = i * 16;
2317
+ k = reader.read(16);
2318
+ for (j = 0; j < 16; j++)
2319
+ if (k & 1 << 15 - j)
2320
+ symToByte[symTotal++] = o + j;
2321
+ }
2322
+ }
2323
+ var groupCount = reader.read(3);
2324
+ if (groupCount < MIN_GROUPS || groupCount > MAX_GROUPS)
2325
+ _throw(Err.DATA_ERROR);
2326
+ var nSelectors = reader.read(15);
2327
+ if (nSelectors === 0)
2328
+ _throw(Err.DATA_ERROR);
2329
+ var mtfSymbol = new Buffer(256);
2330
+ for (i = 0; i < groupCount; i++)
2331
+ mtfSymbol[i] = i;
2332
+ var selectors = new Buffer(nSelectors);
2333
+ for (i = 0; i < nSelectors; i++) {
2334
+ for (j = 0; reader.read(1); j++)
2335
+ if (j >= groupCount) _throw(Err.DATA_ERROR);
2336
+ selectors[i] = mtf(mtfSymbol, j);
2337
+ }
2338
+ var symCount = symTotal + 2;
2339
+ var groups = [], hufGroup;
2340
+ for (j = 0; j < groupCount; j++) {
2341
+ var length = new Buffer(symCount), temp = new Uint16Array(MAX_HUFCODE_BITS + 1);
2342
+ t = reader.read(5);
2343
+ for (i = 0; i < symCount; i++) {
2344
+ for (; ; ) {
2345
+ if (t < 1 || t > MAX_HUFCODE_BITS) _throw(Err.DATA_ERROR);
2346
+ if (!reader.read(1))
2347
+ break;
2348
+ if (!reader.read(1))
2349
+ t++;
2350
+ else
2351
+ t--;
2352
+ }
2353
+ length[i] = t;
2354
+ }
2355
+ var minLen, maxLen;
2356
+ minLen = maxLen = length[0];
2357
+ for (i = 1; i < symCount; i++) {
2358
+ if (length[i] > maxLen)
2359
+ maxLen = length[i];
2360
+ else if (length[i] < minLen)
2361
+ minLen = length[i];
2362
+ }
2363
+ hufGroup = {};
2364
+ groups.push(hufGroup);
2365
+ hufGroup.permute = new Uint16Array(MAX_SYMBOLS);
2366
+ hufGroup.limit = new Uint32Array(MAX_HUFCODE_BITS + 2);
2367
+ hufGroup.base = new Uint32Array(MAX_HUFCODE_BITS + 1);
2368
+ hufGroup.minLen = minLen;
2369
+ hufGroup.maxLen = maxLen;
2370
+ var pp = 0;
2371
+ for (i = minLen; i <= maxLen; i++) {
2372
+ temp[i] = hufGroup.limit[i] = 0;
2373
+ for (t = 0; t < symCount; t++)
2374
+ if (length[t] === i)
2375
+ hufGroup.permute[pp++] = t;
2376
+ }
2377
+ for (i = 0; i < symCount; i++)
2378
+ temp[length[i]]++;
2379
+ pp = t = 0;
2380
+ for (i = minLen; i < maxLen; i++) {
2381
+ pp += temp[i];
2382
+ hufGroup.limit[i] = pp - 1;
2383
+ pp <<= 1;
2384
+ t += temp[i];
2385
+ hufGroup.base[i + 1] = pp - t;
2386
+ }
2387
+ hufGroup.limit[maxLen + 1] = Number.MAX_VALUE;
2388
+ hufGroup.limit[maxLen] = pp + temp[maxLen] - 1;
2389
+ hufGroup.base[minLen] = 0;
2390
+ }
2391
+ var byteCount = new Uint32Array(256);
2392
+ for (i = 0; i < 256; i++)
2393
+ mtfSymbol[i] = i;
2394
+ var runPos = 0, dbufCount = 0, selector = 0, uc;
2395
+ var dbuf = this.dbuf = new Uint32Array(this.dbufSize);
2396
+ symCount = 0;
2397
+ for (; ; ) {
2398
+ if (!symCount--) {
2399
+ symCount = GROUP_SIZE - 1;
2400
+ if (selector >= nSelectors) {
2401
+ _throw(Err.DATA_ERROR);
2402
+ }
2403
+ hufGroup = groups[selectors[selector++]];
2404
+ }
2405
+ i = hufGroup.minLen;
2406
+ j = reader.read(i);
2407
+ for (; ; i++) {
2408
+ if (i > hufGroup.maxLen) {
2409
+ _throw(Err.DATA_ERROR);
2410
+ }
2411
+ if (j <= hufGroup.limit[i])
2412
+ break;
2413
+ j = j << 1 | reader.read(1);
2414
+ }
2415
+ j -= hufGroup.base[i];
2416
+ if (j < 0 || j >= MAX_SYMBOLS) {
2417
+ _throw(Err.DATA_ERROR);
2418
+ }
2419
+ var nextSym = hufGroup.permute[j];
2420
+ if (nextSym === SYMBOL_RUNA || nextSym === SYMBOL_RUNB) {
2421
+ if (!runPos) {
2422
+ runPos = 1;
2423
+ t = 0;
2424
+ }
2425
+ if (nextSym === SYMBOL_RUNA)
2426
+ t += runPos;
2427
+ else
2428
+ t += 2 * runPos;
2429
+ runPos <<= 1;
2430
+ continue;
2431
+ }
2432
+ if (runPos) {
2433
+ runPos = 0;
2434
+ if (dbufCount + t > this.dbufSize) {
2435
+ _throw(Err.DATA_ERROR);
2436
+ }
2437
+ uc = symToByte[mtfSymbol[0]];
2438
+ byteCount[uc] += t;
2439
+ while (t--)
2440
+ dbuf[dbufCount++] = uc;
2441
+ }
2442
+ if (nextSym > symTotal)
2443
+ break;
2444
+ if (dbufCount >= this.dbufSize) {
2445
+ _throw(Err.DATA_ERROR);
2446
+ }
2447
+ i = nextSym - 1;
2448
+ uc = mtf(mtfSymbol, i);
2449
+ uc = symToByte[uc];
2450
+ byteCount[uc]++;
2451
+ dbuf[dbufCount++] = uc;
2452
+ }
2453
+ if (origPointer < 0 || origPointer >= dbufCount) {
2454
+ _throw(Err.DATA_ERROR);
2455
+ }
2456
+ j = 0;
2457
+ for (i = 0; i < 256; i++) {
2458
+ k = j + byteCount[i];
2459
+ byteCount[i] = j;
2460
+ j = k;
2461
+ }
2462
+ for (i = 0; i < dbufCount; i++) {
2463
+ uc = dbuf[i] & 255;
2464
+ dbuf[byteCount[uc]] |= i << 8;
2465
+ byteCount[uc]++;
2466
+ }
2467
+ var pos = 0, current = 0, run = 0;
2468
+ if (dbufCount) {
2469
+ pos = dbuf[origPointer];
2470
+ current = pos & 255;
2471
+ pos >>= 8;
2472
+ run = -1;
2473
+ }
2474
+ this.writePos = pos;
2475
+ this.writeCurrent = current;
2476
+ this.writeCount = dbufCount;
2477
+ this.writeRun = run;
2478
+ return true;
2479
+ };
2480
+ Bunzip.prototype._read_bunzip = function(outputBuffer, len) {
2481
+ var copies, previous, outbyte;
2482
+ if (this.writeCount < 0) {
2483
+ return 0;
2484
+ }
2485
+ var gotcount = 0;
2486
+ var dbuf = this.dbuf, pos = this.writePos, current = this.writeCurrent;
2487
+ var dbufCount = this.writeCount, outputsize = this.outputsize;
2488
+ var run = this.writeRun;
2489
+ while (dbufCount) {
2490
+ dbufCount--;
2491
+ previous = current;
2492
+ pos = dbuf[pos];
2493
+ current = pos & 255;
2494
+ pos >>= 8;
2495
+ if (run++ === 3) {
2496
+ copies = current;
2497
+ outbyte = previous;
2498
+ current = -1;
2499
+ } else {
2500
+ copies = 1;
2501
+ outbyte = current;
2502
+ }
2503
+ this.blockCRC.updateCRCRun(outbyte, copies);
2504
+ while (copies--) {
2505
+ this.outputStream.writeByte(outbyte);
2506
+ this.nextoutput++;
2507
+ }
2508
+ if (current != previous)
2509
+ run = 0;
2510
+ }
2511
+ this.writeCount = dbufCount;
2512
+ if (this.blockCRC.getCRC() !== this.targetBlockCRC) {
2513
+ _throw(Err.DATA_ERROR, "Bad block CRC (got " + this.blockCRC.getCRC().toString(16) + " expected " + this.targetBlockCRC.toString(16) + ")");
2514
+ }
2515
+ return this.nextoutput;
2516
+ };
2517
+ var coerceInputStream = function(input) {
2518
+ if ("readByte" in input) {
2519
+ return input;
2520
+ }
2521
+ var inputStream = new Stream();
2522
+ inputStream.pos = 0;
2523
+ inputStream.readByte = function() {
2524
+ return input[this.pos++];
2525
+ };
2526
+ inputStream.seek = function(pos) {
2527
+ this.pos = pos;
2528
+ };
2529
+ inputStream.eof = function() {
2530
+ return this.pos >= input.length;
2531
+ };
2532
+ return inputStream;
2533
+ };
2534
+ var coerceOutputStream = function(output) {
2535
+ var outputStream = new Stream();
2536
+ var resizeOk = true;
2537
+ if (output) {
2538
+ if (typeof output === "number") {
2539
+ outputStream.buffer = new Buffer(output);
2540
+ resizeOk = false;
2541
+ } else if ("writeByte" in output) {
2542
+ return output;
2543
+ } else {
2544
+ outputStream.buffer = output;
2545
+ resizeOk = false;
2546
+ }
2547
+ } else {
2548
+ outputStream.buffer = new Buffer(16384);
2549
+ }
2550
+ outputStream.pos = 0;
2551
+ outputStream.writeByte = function(_byte) {
2552
+ if (resizeOk && this.pos >= this.buffer.length) {
2553
+ var newBuffer = new Buffer(this.buffer.length * 2);
2554
+ this.buffer.copy(newBuffer);
2555
+ this.buffer = newBuffer;
2556
+ }
2557
+ this.buffer[this.pos++] = _byte;
2558
+ };
2559
+ outputStream.getBuffer = function() {
2560
+ if (this.pos !== this.buffer.length) {
2561
+ if (!resizeOk)
2562
+ throw new TypeError("outputsize does not match decoded input");
2563
+ var newBuffer = new Buffer(this.pos);
2564
+ this.buffer.copy(newBuffer, 0, 0, this.pos);
2565
+ this.buffer = newBuffer;
2566
+ }
2567
+ return this.buffer;
2568
+ };
2569
+ outputStream._coerced = true;
2570
+ return outputStream;
2571
+ };
2572
+ Bunzip.Err = Err;
2573
+ Bunzip.decode = function(input, output, multistream) {
2574
+ var inputStream = coerceInputStream(input);
2575
+ var outputStream = coerceOutputStream(output);
2576
+ var bz = new Bunzip(inputStream, outputStream);
2577
+ while (true) {
2578
+ if ("eof" in inputStream && inputStream.eof()) break;
2579
+ if (bz._init_block()) {
2580
+ bz._read_bunzip();
2581
+ } else {
2582
+ var targetStreamCRC = bz.reader.read(32) >>> 0;
2583
+ if (targetStreamCRC !== bz.streamCRC) {
2584
+ _throw(Err.DATA_ERROR, "Bad stream CRC (got " + bz.streamCRC.toString(16) + " expected " + targetStreamCRC.toString(16) + ")");
2585
+ }
2586
+ if (multistream && "eof" in inputStream && !inputStream.eof()) {
2587
+ bz._start_bunzip(inputStream, outputStream);
2588
+ } else break;
2589
+ }
2590
+ }
2591
+ if ("getBuffer" in outputStream)
2592
+ return outputStream.getBuffer();
2593
+ };
2594
+ Bunzip.decodeBlock = function(input, pos, output) {
2595
+ var inputStream = coerceInputStream(input);
2596
+ var outputStream = coerceOutputStream(output);
2597
+ var bz = new Bunzip(inputStream, outputStream);
2598
+ bz.reader.seek(pos);
2599
+ var moreBlocks = bz._get_next_block();
2600
+ if (moreBlocks) {
2601
+ bz.blockCRC = new CRC32();
2602
+ bz.writeCopies = 0;
2603
+ bz._read_bunzip();
2604
+ }
2605
+ if ("getBuffer" in outputStream)
2606
+ return outputStream.getBuffer();
2607
+ };
2608
+ Bunzip.table = function(input, callback, multistream) {
2609
+ var inputStream = new Stream();
2610
+ inputStream.delegate = coerceInputStream(input);
2611
+ inputStream.pos = 0;
2612
+ inputStream.readByte = function() {
2613
+ this.pos++;
2614
+ return this.delegate.readByte();
2615
+ };
2616
+ if (inputStream.delegate.eof) {
2617
+ inputStream.eof = inputStream.delegate.eof.bind(inputStream.delegate);
2618
+ }
2619
+ var outputStream = new Stream();
2620
+ outputStream.pos = 0;
2621
+ outputStream.writeByte = function() {
2622
+ this.pos++;
2623
+ };
2624
+ var bz = new Bunzip(inputStream, outputStream);
2625
+ var blockSize = bz.dbufSize;
2626
+ while (true) {
2627
+ if ("eof" in inputStream && inputStream.eof()) break;
2628
+ var position = inputStream.pos * 8 + bz.reader.bitOffset;
2629
+ if (bz.reader.hasByte) {
2630
+ position -= 8;
2631
+ }
2632
+ if (bz._init_block()) {
2633
+ var start = outputStream.pos;
2634
+ bz._read_bunzip();
2635
+ callback(position, outputStream.pos - start);
2636
+ } else {
2637
+ var crc = bz.reader.read(32);
2638
+ if (multistream && "eof" in inputStream && !inputStream.eof()) {
2639
+ bz._start_bunzip(inputStream, outputStream);
2640
+ console.assert(
2641
+ bz.dbufSize === blockSize,
2642
+ "shouldn't change block size within multistream file"
2643
+ );
2644
+ } else break;
2645
+ }
2646
+ }
2647
+ };
2648
+ Bunzip.Stream = Stream;
2649
+ Bunzip.version = pjson.version;
2650
+ Bunzip.license = pjson.license;
2651
+ module.exports = Bunzip;
2652
+ }
2653
+ });
2654
+
2655
+ // src/nexrad/radarArchiveCore.ts
2656
+ var import_buffer = __toESM(require_buffer(), 1);
2657
+ var bzip = __toESM(require_lib(), 1);
2658
+
2659
+ // src/nexrad/nexradLevel3Products.ts
2660
+ import {
2661
+ clampNexradTiltForVariable,
2662
+ formatTiltForApi,
2663
+ getDefaultRadarTilt,
2664
+ getRadarTilts,
2665
+ isTerminalRadar
2666
+ } from "@aguacerowx/javascript-sdk";
2667
+ var NEXRAD_LEVEL3_MENU = [
2668
+ {
2669
+ radarKey: "VEL",
2670
+ product: "N0G",
2671
+ menuLabel: "Storm Relative Velocity",
2672
+ fldKey: "nexrad_vel",
2673
+ cmapPropertyKey: "nexrad_vel",
2674
+ decodeMode: "velocity",
2675
+ stormRelativeVelocity: true
2676
+ },
2677
+ {
2678
+ radarKey: "KDP",
2679
+ product: "N0K",
2680
+ menuLabel: "Specific Differential Phase",
2681
+ fldKey: "nexrad_l3_n0k",
2682
+ cmapPropertyKey: "nexrad_kdp",
2683
+ defaultUnit: "deg/km",
2684
+ decodeMode: "generic_physical"
2685
+ },
2686
+ {
2687
+ radarKey: "N0H",
2688
+ product: "N0H",
2689
+ menuLabel: "Hydrometeor Classification",
2690
+ fldKey: "nexrad_l3_n0h",
2691
+ cmapPropertyKey: "nexrad_l3_n0h",
2692
+ defaultUnit: "None",
2693
+ decodeMode: "categorical"
2694
+ },
2695
+ {
2696
+ radarKey: "HHC",
2697
+ product: "HHC",
2698
+ menuLabel: "Hybrid Hydrometeor Classification",
2699
+ fldKey: "nexrad_l3_hhc",
2700
+ cmapPropertyKey: "nexrad_l3_hhc",
2701
+ defaultUnit: "None",
2702
+ decodeMode: "categorical"
2703
+ },
2704
+ {
2705
+ radarKey: "EET",
2706
+ product: "EET",
2707
+ menuLabel: "Enhanced Echo Tops",
2708
+ fldKey: "nexrad_l3_eet",
2709
+ cmapPropertyKey: "nexrad_l3_eet",
2710
+ defaultUnit: "kft",
2711
+ decodeMode: "tops_kft"
2712
+ },
2713
+ {
2714
+ radarKey: "DVL",
2715
+ product: "DVL",
2716
+ menuLabel: "Vertically Integrated Liquid",
2717
+ fldKey: "nexrad_l3_dvl",
2718
+ cmapPropertyKey: "nexrad_l3_dvl",
2719
+ defaultUnit: "kg/m\xB2",
2720
+ decodeMode: "vil"
2721
+ },
2722
+ {
2723
+ radarKey: "DAA",
2724
+ product: "DAA",
2725
+ menuLabel: "1-Hour Precipitation",
2726
+ fldKey: "nexrad_l3_daa",
2727
+ cmapPropertyKey: "tp_0_1",
2728
+ defaultUnit: "in",
2729
+ decodeMode: "precip"
2730
+ },
2731
+ {
2732
+ radarKey: "DU3",
2733
+ product: "DU3",
2734
+ menuLabel: "3-Hour Precipitation",
2735
+ fldKey: "nexrad_l3_du3",
2736
+ cmapPropertyKey: "tp_0_total",
2737
+ defaultUnit: "in",
2738
+ decodeMode: "precip"
2739
+ },
2740
+ {
2741
+ radarKey: "DTA",
2742
+ product: "DTA",
2743
+ menuLabel: "Storm Total Precipitation",
2744
+ fldKey: "nexrad_l3_dta",
2745
+ cmapPropertyKey: "tp_0_total",
2746
+ defaultUnit: "in",
2747
+ decodeMode: "precip"
2748
+ }
2749
+ ];
2750
+ var byRadarKey = /* @__PURE__ */ new Map();
2751
+ for (const e of NEXRAD_LEVEL3_MENU) {
2752
+ byRadarKey.set(e.radarKey, e);
2753
+ if (e.radarKey === "DVL") byRadarKey.set("NVL", e);
2754
+ }
2755
+ function getNexradLevel3EntryByRadarKey(radarKey) {
2756
+ return byRadarKey.get(radarKey);
2757
+ }
2758
+ var NEXRAD_LEVEL3_KDP_PRODUCTS = [
2759
+ "NXK",
2760
+ "NYK",
2761
+ "NZK",
2762
+ "N0K",
2763
+ "NAK",
2764
+ "N1K",
2765
+ "NBK",
2766
+ "N2K",
2767
+ "N3K"
2768
+ ];
2769
+ var NEXRAD_LEVEL3_DHC_PRODUCTS = [
2770
+ "NXH",
2771
+ "NYH",
2772
+ "NZH",
2773
+ "N0H",
2774
+ "NAH",
2775
+ "N1H",
2776
+ "NBH",
2777
+ "N2H",
2778
+ "N3H"
2779
+ ];
2780
+ var NEXRAD_LEVEL3_KDP_PRODUCTS_FOR_MANIFEST = NEXRAD_LEVEL3_KDP_PRODUCTS.slice(3);
2781
+ var NEXRAD_LEVEL3_DHC_PRODUCTS_FOR_MANIFEST = NEXRAD_LEVEL3_DHC_PRODUCTS.slice(3);
2782
+ var NEXRAD_LEVEL3_MANIFEST_TILT_COUNT = NEXRAD_LEVEL3_KDP_PRODUCTS_FOR_MANIFEST.length;
2783
+ function level3EetHeightKmFromLevel(level, dataMaskRaw, scaleRaw, offsetRaw) {
2784
+ if (level < 2) return null;
2785
+ const masked = level & (dataMaskRaw & 65535);
2786
+ if (!Number.isFinite(scaleRaw) || scaleRaw === 0) {
2787
+ return level - 2;
2788
+ }
2789
+ const mapped = (masked - offsetRaw) / scaleRaw;
2790
+ if (!Number.isFinite(mapped)) return null;
2791
+ return mapped;
2792
+ }
2793
+ function level3ValuePacking(decodeMode) {
2794
+ switch (decodeMode) {
2795
+ case "velocity":
2796
+ return { valueScale: 0.01, valueOffset: 0 };
2797
+ case "dbz":
2798
+ return { valueScale: 0.5, valueOffset: -32 };
2799
+ case "precip":
2800
+ return { valueScale: 1e-3, valueOffset: 0 };
2801
+ case "categorical":
2802
+ return { valueScale: 1, valueOffset: 0 };
2803
+ case "tops_kft":
2804
+ return { valueScale: 2e-3, valueOffset: 0 };
2805
+ case "vil":
2806
+ return { valueScale: 0.1, valueOffset: 0 };
2807
+ case "generic_physical":
2808
+ return { valueScale: 0.01, valueOffset: 0 };
2809
+ default:
2810
+ return { valueScale: 0.5, valueOffset: -32 };
2811
+ }
2812
+ }
2813
+
2814
+ // src/nexrad/level3StormRelative.ts
2815
+ function parseLevel3StormMotionFromBuffer(buffer) {
2816
+ const bytes = new Uint8Array(buffer);
2817
+ const marker = [83, 68, 85, 83];
2818
+ let start = 0;
2819
+ for (let i = 0; i <= bytes.length - 4; i++) {
2820
+ if (bytes[i] === marker[0] && bytes[i + 1] === marker[1] && bytes[i + 2] === marker[2] && bytes[i + 3] === marker[3]) {
2821
+ start = i;
2822
+ break;
2823
+ }
2824
+ }
2825
+ const dv = new DataView(buffer, start, bytes.length - start);
2826
+ const textLen = 30;
2827
+ const msgHdrLen = 18;
2828
+ const pdbStart = textLen + msgHdrLen;
2829
+ if (pdbStart + 86 > dv.byteLength) return null;
2830
+ if (dv.getInt16(pdbStart, false) !== -1) return null;
2831
+ const dep8Offset = pdbStart + 82;
2832
+ const dep8 = dv.getInt16(dep8Offset, false);
2833
+ const dep9 = dv.getInt16(dep8Offset + 2, false);
2834
+ const stormSpeedKt = dep8 / 10;
2835
+ const speedMs = stormSpeedKt * 0.514444;
2836
+ const directionDeg = dep9 / 10;
2837
+ if (!Number.isFinite(speedMs) || !Number.isFinite(directionDeg)) return null;
2838
+ return { speedMs, directionDeg };
2839
+ }
2840
+ function level3StormRadialComponentMs(stormSpeedMs, stormDirectionDeg, azimuthDeg) {
2841
+ const stormDirRad = stormDirectionDeg * Math.PI / 180;
2842
+ const azRad = azimuthDeg * Math.PI / 180;
2843
+ return stormSpeedMs * Math.cos(stormDirRad - azRad);
2844
+ }
2845
+ function decodeGateRawMs(hi, lo, valueScale, valueOffset) {
2846
+ const raw = lo + hi * 256;
2847
+ let signed = raw;
2848
+ if (raw >= 32768) signed = raw - 65536;
2849
+ if (signed <= -32768) return null;
2850
+ return signed * valueScale + valueOffset;
2851
+ }
2852
+ function encodeGateRawMs(physicalMs, valueScale, valueOffset) {
2853
+ const raw = Math.round((physicalMs - valueOffset) / valueScale);
2854
+ const signed = Math.max(-32768, Math.min(32767, raw));
2855
+ const u = signed < 0 ? signed + 65536 : signed;
2856
+ return [u >> 8 & 255, u & 255];
2857
+ }
2858
+ function applyLevel3StormRelativeToFrame(frame, stormSpeedMs, stormDirectionDeg) {
2859
+ const { nRays, nGates, gateData, rayBoundariesDeg, valueScale, valueOffset } = frame;
2860
+ const out = new Uint8Array(gateData.length);
2861
+ for (let r = 0; r < nRays; r++) {
2862
+ const azLow = rayBoundariesDeg[r];
2863
+ const azHigh = rayBoundariesDeg[r + 1];
2864
+ const azimuthDeg = (Number(azLow) + Number(azHigh)) * 0.5;
2865
+ const stormComp = level3StormRadialComponentMs(stormSpeedMs, stormDirectionDeg, azimuthDeg);
2866
+ for (let g = 0; g < nGates; g++) {
2867
+ const o = (r * nGates + g) * 2;
2868
+ const hi = gateData[o];
2869
+ const lo = gateData[o + 1];
2870
+ const v = decodeGateRawMs(hi, lo, valueScale, valueOffset);
2871
+ if (v == null) {
2872
+ out[o] = hi;
2873
+ out[o + 1] = lo;
2874
+ continue;
2875
+ }
2876
+ const corrected = v + stormComp;
2877
+ const [nh, nl] = encodeGateRawMs(corrected, valueScale, valueOffset);
2878
+ out[o] = nh;
2879
+ out[o + 1] = nl;
2880
+ }
2881
+ }
2882
+ return { ...frame, gateData: out };
2883
+ }
2884
+
2885
+ // src/nexrad/nexradArchiveCache.ts
2886
+ var MAX_ARCHIVE_CACHE_ENTRIES = 5e3;
2887
+ var archiveCache = /* @__PURE__ */ new Map();
2888
+ function setArchiveCache(url, archive) {
2889
+ archiveCache.delete(url);
2890
+ archiveCache.set(url, archive);
2891
+ while (archiveCache.size > MAX_ARCHIVE_CACHE_ENTRIES) {
2892
+ const oldestKey = archiveCache.keys().next().value;
2893
+ if (!oldestKey) break;
2894
+ archiveCache.delete(oldestKey);
2895
+ }
2896
+ }
2897
+
2898
+ // src/nexrad/loadNexradSites.ts
2899
+ var sitesUrl = "/data/nexrad.json";
2900
+ var nexradSitesPayloadPromise = null;
2901
+ function loadNexradSitesPayload() {
2902
+ if (nexradSitesPayloadPromise) {
2903
+ return nexradSitesPayloadPromise;
2904
+ }
2905
+ nexradSitesPayloadPromise = fetch(sitesUrl).then((response) => {
2906
+ if (!response.ok) throw new Error(`nexrad.json fetch failed: HTTP ${response.status}`);
2907
+ return response.json();
2908
+ }).catch((error) => {
2909
+ console.error("[mapsgl] Could not load nexrad.json:", error);
2910
+ nexradSitesPayloadPromise = null;
2911
+ throw error;
2912
+ });
2913
+ return nexradSitesPayloadPromise;
2914
+ }
2915
+ async function loadNexradSites() {
2916
+ const payload = await loadNexradSitesPayload();
2917
+ if (Array.isArray(payload)) return payload;
2918
+ const sites = payload.sites;
2919
+ if (sites && Array.isArray(sites)) return sites;
2920
+ return [];
2921
+ }
2922
+
2923
+ // src/nexrad/radarArchiveCore.ts
2924
+ if (typeof globalThis.Buffer === "undefined") {
2925
+ globalThis.Buffer = import_buffer.Buffer;
2926
+ }
2927
+ var NEXRAD_ARCHIVE_API_KEY = "";
2928
+ function setNexradArchiveApiKey(k) {
2929
+ NEXRAD_ARCHIVE_API_KEY = k || "";
2930
+ }
2931
+ function createRadarDecodeWorker() {
2932
+ return new Worker(new URL("./radarDecode.worker.bundled.js", import.meta.url), { type: "module" });
2933
+ }
2934
+ var LEVEL2_BASE_URL = "https://d3dc62msmxkrd7.cloudfront.net/level-2";
2935
+ var LEVEL3_BASE_URL = "https://unidata-nexrad-level3.s3.amazonaws.com";
2936
+ var DECODE_WORKER_POOL_SIZE = 2;
2937
+ var PREFETCH_WORKER_START_INDEX = 1;
2938
+ var inflightFetches = /* @__PURE__ */ new Map();
2939
+ var inflightFetchMeta = /* @__PURE__ */ new Map();
2940
+ var radarFetchRequestSeq = 0;
2941
+ var radarDecodeWorkers = [];
2942
+ var radarDecodeRequestId = 0;
2943
+ var radarDecodePending = /* @__PURE__ */ new Map();
2944
+ var radarDecodeRequestMeta = /* @__PURE__ */ new Map();
2945
+ var radarDecodePrefetchWorkerIndex = PREFETCH_WORKER_START_INDEX;
2946
+ function createDecodeWorker(workerIndex) {
2947
+ const worker = createRadarDecodeWorker();
2948
+ worker.onmessage = (event) => {
2949
+ const message = event.data;
2950
+ if (!message || message.type !== "DECODE_RESULT") return;
2951
+ const pending = radarDecodePending.get(message.requestId);
2952
+ if (!pending) return;
2953
+ radarDecodePending.delete(message.requestId);
2954
+ radarDecodeRequestMeta.delete(message.requestId);
2955
+ if (message.error) {
2956
+ pending.reject(new Error(message.error));
2957
+ return;
2958
+ }
2959
+ if (!message.gateData || typeof message.nRays !== "number" || typeof message.nGates !== "number" || typeof message.stationLat !== "number" || typeof message.stationLon !== "number" || typeof message.firstGateKm !== "number" || typeof message.gateWidthKm !== "number" || typeof message.valueScale !== "number" || typeof message.valueOffset !== "number" || !(message.rayBoundariesDeg instanceof Float32Array)) {
2960
+ pending.resolve(null);
2961
+ return;
2962
+ }
2963
+ pending.resolve({
2964
+ gateData: message.gateData,
2965
+ nRays: message.nRays,
2966
+ nGates: message.nGates,
2967
+ stationLat: message.stationLat,
2968
+ stationLon: message.stationLon,
2969
+ firstGateKm: message.firstGateKm,
2970
+ gateWidthKm: message.gateWidthKm,
2971
+ valueScale: message.valueScale,
2972
+ valueOffset: message.valueOffset,
2973
+ rayBoundariesDeg: message.rayBoundariesDeg
2974
+ });
2975
+ };
2976
+ worker.onerror = (error) => {
2977
+ radarDecodePending.forEach(({ reject }) => reject(new Error(error.message || "Radar decode worker failed")));
2978
+ radarDecodePending.clear();
2979
+ radarDecodeRequestMeta.clear();
2980
+ };
2981
+ return worker;
2982
+ }
2983
+ function getRadarDecodeWorkers() {
2984
+ if (radarDecodeWorkers.length > 0) return radarDecodeWorkers;
2985
+ radarDecodeWorkers = Array.from({ length: DECODE_WORKER_POOL_SIZE }, (_, idx) => createDecodeWorker(idx));
2986
+ return radarDecodeWorkers;
2987
+ }
2988
+ function getDecodeWorkerForPriority(priority) {
2989
+ const workers = getRadarDecodeWorkers();
2990
+ if (priority === "display" || workers.length === 1) {
2991
+ return { worker: workers[0], workerIndex: 0 };
2992
+ }
2993
+ const prefetchWorkerCount = Math.max(workers.length - PREFETCH_WORKER_START_INDEX, 1);
2994
+ const offset = (radarDecodePrefetchWorkerIndex - PREFETCH_WORKER_START_INDEX + prefetchWorkerCount) % prefetchWorkerCount;
2995
+ const workerIndex = PREFETCH_WORKER_START_INDEX + offset;
2996
+ radarDecodePrefetchWorkerIndex = PREFETCH_WORKER_START_INDEX + (offset + 1) % prefetchWorkerCount;
2997
+ return { worker: workers[Math.min(workerIndex, workers.length - 1)], workerIndex: Math.min(workerIndex, workers.length - 1) };
2998
+ }
2999
+ function objectKeyToUrl(objectKey, radarSource = "level2") {
3000
+ if (objectKey.startsWith("http")) return objectKey;
3001
+ const baseUrl = radarSource === "level3" ? LEVEL3_BASE_URL : LEVEL2_BASE_URL;
3002
+ return `${baseUrl.replace(/\/$/, "")}/${objectKey}`;
3003
+ }
3004
+ var Level3Raf = class {
3005
+ offset = 0;
3006
+ view;
3007
+ bytes;
3008
+ constructor(input) {
3009
+ this.bytes = input instanceof Uint8Array ? input : new Uint8Array(input);
3010
+ this.view = new DataView(this.bytes.buffer, this.bytes.byteOffset, this.bytes.byteLength);
3011
+ }
3012
+ getPos() {
3013
+ return this.offset;
3014
+ }
3015
+ getLength() {
3016
+ return this.bytes.length;
3017
+ }
3018
+ seek(pos) {
3019
+ this.offset = pos;
3020
+ }
3021
+ skip(delta) {
3022
+ this.offset += delta;
3023
+ }
3024
+ read(bytes = 1) {
3025
+ const out = this.bytes.subarray(this.offset, this.offset + bytes);
3026
+ this.offset += bytes;
3027
+ return out;
3028
+ }
3029
+ readByte() {
3030
+ const v = this.view.getUint8(this.offset);
3031
+ this.offset += 1;
3032
+ return v;
3033
+ }
3034
+ readShort() {
3035
+ const v = this.view.getInt16(this.offset, false);
3036
+ this.offset += 2;
3037
+ return v;
3038
+ }
3039
+ readUShort() {
3040
+ const v = this.view.getUint16(this.offset, false);
3041
+ this.offset += 2;
3042
+ return v;
3043
+ }
3044
+ readInt() {
3045
+ const v = this.view.getInt32(this.offset, false);
3046
+ this.offset += 4;
3047
+ return v;
3048
+ }
3049
+ readUInt32() {
3050
+ const v = this.view.getUint32(this.offset, false);
3051
+ this.offset += 4;
3052
+ return v;
3053
+ }
3054
+ readString(bytes) {
3055
+ const slice = this.read(bytes);
3056
+ return String.fromCharCode(...slice);
3057
+ }
3058
+ };
3059
+ function concatUint8(a, b) {
3060
+ const out = new Uint8Array(a.length + b.length);
3061
+ out.set(a, 0);
3062
+ out.set(b, a.length);
3063
+ return out;
3064
+ }
3065
+ var LEVEL3_PRODUCT_RANGE_SCALE_MUL = {
3066
+ 19: 1,
3067
+ 20: 2,
3068
+ 25: 0.25,
3069
+ 27: 1,
3070
+ 28: 0.25,
3071
+ 30: 1,
3072
+ 32: 1,
3073
+ 34: 1,
3074
+ 56: 1,
3075
+ 57: 1e3,
3076
+ 78: 1,
3077
+ 79: 1,
3078
+ 80: 1,
3079
+ 94: 1,
3080
+ 99: 0.25,
3081
+ 134: 1e3,
3082
+ 135: 1e3,
3083
+ 138: 1,
3084
+ 153: 0.25,
3085
+ 154: 0.25,
3086
+ 155: 0.25,
3087
+ 159: 0.25,
3088
+ 161: 0.25,
3089
+ 163: 0.25,
3090
+ 165: 0.25,
3091
+ 166: 0.25,
3092
+ 167: 0.25,
3093
+ 168: 0.25,
3094
+ 169: 1e3,
3095
+ 170: 1e3,
3096
+ 171: 1e3,
3097
+ 172: 1e3,
3098
+ 173: 1e3,
3099
+ 174: 1e3,
3100
+ 175: 1e3,
3101
+ /** Py-ART `PRODUCT_RANGE_RESOLUTION`: 176/177 are digital-style radials (0.25×), not 1 km like 169–175. */
3102
+ 176: 0.25,
3103
+ 177: 0.25,
3104
+ 181: 150,
3105
+ 182: 150,
3106
+ 186: 300
3107
+ };
3108
+ var LEVEL3_GENERIC_DIGITAL_PRODUCT_CODES = /* @__PURE__ */ new Set([
3109
+ 159,
3110
+ 161,
3111
+ 163,
3112
+ 167,
3113
+ 168,
3114
+ 170,
3115
+ 172,
3116
+ 173,
3117
+ 174,
3118
+ 175,
3119
+ 176
3120
+ ]);
3121
+ var LEVEL3_GENERIC_DIGITAL_DEPTH_MM_TO_IN_PRODUCTS = /* @__PURE__ */ new Set([170, 172, 173, 174, 175]);
3122
+ var LEVEL3_DIGITAL_HMC_PRODUCT_CODES = /* @__PURE__ */ new Set([165, 177]);
3123
+ function level3PhysicalFromDigitalHmc(level, precision) {
3124
+ if (!Number.isFinite(level)) return null;
3125
+ if (precision === "nibble") {
3126
+ if (level < 2 || level > 15) return null;
3127
+ return level - 2;
3128
+ }
3129
+ if (level === 150) return null;
3130
+ if (level < 10 || level >= 256) return null;
3131
+ const cls = Math.floor(level / 10) - 1;
3132
+ if (cls < 0 || cls > 11) return null;
3133
+ return cls;
3134
+ }
3135
+ function level3GenericDigitalAccumMmFactor(productCode) {
3136
+ switch (productCode) {
3137
+ case 170:
3138
+ return 0.125;
3139
+ case 172:
3140
+ case 173:
3141
+ case 174:
3142
+ case 175:
3143
+ return 0.25;
3144
+ default:
3145
+ return 1;
3146
+ }
3147
+ }
3148
+ function level3UnpackFloat32FromThresholdPair(short0, short1) {
3149
+ const buf = new ArrayBuffer(4);
3150
+ const view = new DataView(buf);
3151
+ view.setUint16(0, short0 & 65535, false);
3152
+ view.setUint16(2, short1 & 65535, false);
3153
+ return view.getFloat32(0, false);
3154
+ }
3155
+ function parseLevel3GenericDigitalParams(dep) {
3156
+ if (dep.length < 9) return null;
3157
+ const scale = level3UnpackFloat32FromThresholdPair(dep[1], dep[2]);
3158
+ const offset = level3UnpackFloat32FromThresholdPair(dep[3], dep[4]);
3159
+ const maxDataVal = dep[6] & 65535;
3160
+ const leadingFlags = dep[7];
3161
+ const trailingFlags = dep[8];
3162
+ if (!Number.isFinite(scale) || scale === 0 || !Number.isFinite(offset)) return null;
3163
+ if (leadingFlags < 0 || leadingFlags > 255 || trailingFlags < 0 || trailingFlags > 255) return null;
3164
+ if (maxDataVal < leadingFlags) return null;
3165
+ return { scale, offset, leadingFlags, trailingFlags, maxDataVal };
3166
+ }
3167
+ function level3PhysicalFromGenericDigital(level, p, productCode) {
3168
+ if (!Number.isFinite(level)) return null;
3169
+ if (level < p.leadingFlags) return null;
3170
+ const upper = p.maxDataVal - p.trailingFlags;
3171
+ if (level > upper) return null;
3172
+ let out = (level - p.offset) / p.scale;
3173
+ if (!Number.isFinite(out)) return null;
3174
+ if (LEVEL3_GENERIC_DIGITAL_DEPTH_MM_TO_IN_PRODUCTS.has(productCode)) {
3175
+ out *= level3GenericDigitalAccumMmFactor(productCode);
3176
+ out /= 25.4;
3177
+ }
3178
+ return out;
3179
+ }
3180
+ function level3PhysicalFromDataLevel(level, minimumDataValue, dataIncrement, mode, msg134Params) {
3181
+ if (!Number.isFinite(level)) return null;
3182
+ if (mode === "digital_velocity_byte") {
3183
+ if (level < 2) return null;
3184
+ return minimumDataValue + (level - 2) * dataIncrement;
3185
+ }
3186
+ if (mode === "digital_velocity_rle4") {
3187
+ if (level < 2) return null;
3188
+ const MS_PER_STEP = 4;
3189
+ const CENTER_LEVEL = 8;
3190
+ return (level - CENTER_LEVEL) * MS_PER_STEP;
3191
+ }
3192
+ if (msg134Params) {
3193
+ if (level < 2) return null;
3194
+ const { linearScale, linearOffset, logStart, logScale, logOffset } = msg134Params;
3195
+ if (level < logStart) {
3196
+ return (level - linearOffset) / linearScale;
3197
+ } else {
3198
+ return Math.exp((level - logOffset) / logScale);
3199
+ }
3200
+ }
3201
+ if (mode === "standard_digital") {
3202
+ if (level < 2) return null;
3203
+ return minimumDataValue + (level - 2) * dataIncrement;
3204
+ }
3205
+ if (level <= 1) return null;
3206
+ return minimumDataValue + level * dataIncrement;
3207
+ }
3208
+ function parseLevel3Packet0010(raf, minimumDataValue, dataIncrement, levelMode, l3ProductCode, msg134Params, eetThresholds, genericDigital) {
3209
+ const packetCode = raf.readUShort();
3210
+ if (packetCode !== 16) throw new Error(`Unexpected packet code ${packetCode}`);
3211
+ const firstBinMeters = raf.readShort();
3212
+ let numberBins = raf.readShort();
3213
+ raf.readShort();
3214
+ raf.readShort();
3215
+ const rangeScaleRaw = raf.readShort();
3216
+ const numberRadials = raf.readShort();
3217
+ if (numberRadials > 0) {
3218
+ const peek = raf.getPos();
3219
+ const nbytesFirst = raf.readShort();
3220
+ raf.seek(peek);
3221
+ if (nbytesFirst !== numberBins) {
3222
+ numberBins = nbytesFirst;
3223
+ }
3224
+ }
3225
+ const radials = [];
3226
+ for (let r = 0; r < numberRadials; r++) {
3227
+ const bytesInRadial = raf.readShort();
3228
+ const startAngle = raf.readShort() / 10;
3229
+ const angleDelta = raf.readShort() / 10;
3230
+ const bins = [];
3231
+ for (let i = 0; i < numberBins; i++) {
3232
+ const level = raf.readByte();
3233
+ if (eetThresholds) {
3234
+ bins.push(
3235
+ level3EetHeightKmFromLevel(level, eetThresholds.dataMask, eetThresholds.scale, eetThresholds.offset)
3236
+ );
3237
+ } else if (LEVEL3_DIGITAL_HMC_PRODUCT_CODES.has(l3ProductCode)) {
3238
+ bins.push(level3PhysicalFromDigitalHmc(level, "byte"));
3239
+ } else if (genericDigital) {
3240
+ bins.push(level3PhysicalFromGenericDigital(level, genericDigital, l3ProductCode));
3241
+ } else {
3242
+ bins.push(level3PhysicalFromDataLevel(level, minimumDataValue, dataIncrement, levelMode, msg134Params));
3243
+ }
3244
+ }
3245
+ if (bytesInRadial > numberBins) raf.skip(bytesInRadial - numberBins);
3246
+ radials.push({ startAngle, angleDelta, bins });
3247
+ }
3248
+ return { firstBinMeters, numberBins, rangeScaleRaw, numberRadials, radials };
3249
+ }
3250
+ function parseLevel3PacketAF1F(raf, minimumDataValue, dataIncrement, levelMode, l3ProductCode, msg134Params, eetThresholds, genericDigital) {
3251
+ const packetCode = raf.readUShort();
3252
+ if (packetCode !== 44831) throw new Error(`Unexpected packet code ${packetCode}`);
3253
+ const firstBinMeters = raf.readShort();
3254
+ const numberBins = raf.readShort();
3255
+ raf.readShort();
3256
+ raf.readShort();
3257
+ const rangeScaleRaw = raf.readShort();
3258
+ const numRadials = raf.readShort();
3259
+ const radials = [];
3260
+ for (let r = 0; r < numRadials; r++) {
3261
+ const rleBytes = raf.readShort() * 2;
3262
+ const startAngle = raf.readShort() / 10;
3263
+ const angleDelta = raf.readShort() / 10;
3264
+ const bins = [];
3265
+ for (let i = 0; i < rleBytes; i++) {
3266
+ const byte = raf.readByte();
3267
+ const run = byte >> 4;
3268
+ const level = byte & 15;
3269
+ const value = eetThresholds ? level3EetHeightKmFromLevel(level, eetThresholds.dataMask, eetThresholds.scale, eetThresholds.offset) : LEVEL3_DIGITAL_HMC_PRODUCT_CODES.has(l3ProductCode) ? level3PhysicalFromDigitalHmc(level, "nibble") : genericDigital ? level3PhysicalFromGenericDigital(level, genericDigital, l3ProductCode) : level3PhysicalFromDataLevel(level, minimumDataValue, dataIncrement, levelMode, msg134Params);
3270
+ for (let j = 0; j < run; j++) bins.push(value);
3271
+ }
3272
+ if (bins.length > numberBins) bins.length = numberBins;
3273
+ while (bins.length < numberBins) bins.push(null);
3274
+ radials.push({ startAngle, angleDelta, bins });
3275
+ }
3276
+ return { firstBinMeters, numberBins, rangeScaleRaw, numberRadials: numRadials, radials };
3277
+ }
3278
+ function buildRayBoundariesFromLevel3Radials(radials) {
3279
+ const n = radials.length;
3280
+ const boundaries = new Float32Array(n + 1);
3281
+ let prev = -Infinity;
3282
+ for (let i = 0; i < n; i++) {
3283
+ const startAngle = Number(radials[i]?.startAngle);
3284
+ const angleDelta = Number(radials[i]?.angleDelta);
3285
+ const start = Number.isFinite(startAngle) ? startAngle : 0;
3286
+ const delta = Number.isFinite(angleDelta) && angleDelta > 0 ? angleDelta : 1;
3287
+ let lower = start - delta * 0.5;
3288
+ while (lower <= prev) lower += 360;
3289
+ boundaries[i] = lower;
3290
+ prev = lower;
3291
+ }
3292
+ const lastDeltaRaw = Number(radials[n - 1]?.angleDelta);
3293
+ const lastDelta = Number.isFinite(lastDeltaRaw) && lastDeltaRaw > 0 ? lastDeltaRaw : 1;
3294
+ boundaries[n] = boundaries[n - 1] + lastDelta;
3295
+ return boundaries;
3296
+ }
3297
+ function encodeSigned16ToHiLo(value) {
3298
+ const signed = Math.max(-32768, Math.min(32767, value));
3299
+ const raw = signed < 0 ? signed + 65536 : signed;
3300
+ return [raw >> 8 & 255, raw & 255];
3301
+ }
3302
+ function level3RadialSpatialScore(p) {
3303
+ if (!p) return -1;
3304
+ const nb = Number(p.numberBins);
3305
+ const nr = Number(p.numberRadials);
3306
+ if (!Number.isFinite(nb) || !Number.isFinite(nr) || nb <= 0 || nr <= 0) return -1;
3307
+ return nb * nr;
3308
+ }
3309
+ function level3RadialPickIsBetter(cand, prev) {
3310
+ const sC = level3RadialSpatialScore(cand.packet);
3311
+ const sP = level3RadialSpatialScore(prev?.packet);
3312
+ if (sC > sP) return true;
3313
+ if (sC < sP) return false;
3314
+ if (!prev) return true;
3315
+ if (cand.kind === 16 && prev.kind === 44831) return true;
3316
+ return false;
3317
+ }
3318
+ function trySkipLevel3OverlayPacket(raf, packetCode, layerEnd) {
3319
+ const pos0 = raf.getPos();
3320
+ if (packetCode !== 1 && packetCode !== 2 && packetCode !== 8) return false;
3321
+ if (layerEnd - pos0 < 4) return false;
3322
+ const codeRead = raf.readUShort();
3323
+ if (codeRead !== packetCode) {
3324
+ raf.seek(pos0);
3325
+ return false;
3326
+ }
3327
+ const payloadBytes = raf.readUShort();
3328
+ if (payloadBytes > layerEnd - raf.getPos()) {
3329
+ raf.seek(pos0);
3330
+ return false;
3331
+ }
3332
+ raf.skip(payloadBytes);
3333
+ return true;
3334
+ }
3335
+ var LEVEL3_PACKET_RASTER_BA07 = 47623;
3336
+ var LEVEL3_RASTER_INNER_CODE = 2147483840;
3337
+ function unpackLevel3RasterRle(rowBytes) {
3338
+ const unpacked = [];
3339
+ for (let i = 0; i < rowBytes.length; i++) {
3340
+ const b = rowBytes[i];
3341
+ const run = b >> 4;
3342
+ const val = b & 15;
3343
+ for (let j = 0; j < run; j++) unpacked.push(val);
3344
+ }
3345
+ return unpacked;
3346
+ }
3347
+ function level3CombineRasterScale(int16, frac16) {
3348
+ const i = Math.abs(int16);
3349
+ const f = Math.abs(frac16) / 1e4;
3350
+ const s = i + f;
3351
+ return s > 0 ? s : 1;
3352
+ }
3353
+ function parseLevel3PacketRasterBA07(raf, layerEnd, objectKey) {
3354
+ const pos0 = raf.getPos();
3355
+ const packetCode = raf.readUShort();
3356
+ if (packetCode !== LEVEL3_PACKET_RASTER_BA07) {
3357
+ raf.seek(pos0);
3358
+ return null;
3359
+ }
3360
+ const room = layerEnd - raf.getPos();
3361
+ if (room < 20) {
3362
+ raf.seek(layerEnd);
3363
+ return null;
3364
+ }
3365
+ const inner = raf.readUInt32();
3366
+ if (inner !== LEVEL3_RASTER_INNER_CODE) {
3367
+ raf.seek(layerEnd);
3368
+ return null;
3369
+ }
3370
+ const iStart = raf.readShort();
3371
+ const jStart = raf.readShort();
3372
+ const xscaleInt = raf.readShort();
3373
+ const xscaleFrac = raf.readShort();
3374
+ const yscaleInt = raf.readShort();
3375
+ const yscaleFrac = raf.readShort();
3376
+ const numRows = raf.readUShort();
3377
+ const packing = raf.readUShort();
3378
+ if (packing !== 2) {
3379
+ console.warn("[aguacero][nexrad-l3][raster-ba07-packing]", { objectKey, packing, hint: "MetPy expects packing=2; raster parse skipped for this layer" });
3380
+ raf.seek(layerEnd);
3381
+ return null;
3382
+ }
3383
+ if (numRows <= 0 || numRows > 2e3 || raf.getPos() > layerEnd) {
3384
+ raf.seek(layerEnd);
3385
+ return null;
3386
+ }
3387
+ const cellKmX = level3CombineRasterScale(xscaleInt, xscaleFrac);
3388
+ const cellKmY = level3CombineRasterScale(yscaleInt, yscaleFrac);
3389
+ const startXKm = iStart * xscaleInt;
3390
+ const startYKm = jStart * yscaleInt;
3391
+ const rows = [];
3392
+ let nCols = -1;
3393
+ for (let r = 0; r < numRows; r++) {
3394
+ if (raf.getPos() + 2 > layerEnd) {
3395
+ raf.seek(layerEnd);
3396
+ return null;
3397
+ }
3398
+ const rowNumBytes = raf.readUShort();
3399
+ if (rowNumBytes === 0 || raf.getPos() + rowNumBytes > layerEnd) {
3400
+ raf.seek(layerEnd);
3401
+ return null;
3402
+ }
3403
+ const rowBytes = raf.read(rowNumBytes);
3404
+ const expanded = unpackLevel3RasterRle(rowBytes);
3405
+ if (nCols < 0) nCols = expanded.length;
3406
+ else if (expanded.length !== nCols) {
3407
+ raf.seek(layerEnd);
3408
+ return null;
3409
+ }
3410
+ rows.push(expanded);
3411
+ }
3412
+ if (nCols <= 0) {
3413
+ raf.seek(layerEnd);
3414
+ return null;
3415
+ }
3416
+ if (raf.getPos() < layerEnd) {
3417
+ raf.seek(layerEnd);
3418
+ }
3419
+ return {
3420
+ iStart,
3421
+ jStart,
3422
+ cellKmX,
3423
+ cellKmY,
3424
+ startXKm,
3425
+ startYKm,
3426
+ nCols,
3427
+ nRows: numRows,
3428
+ rows
3429
+ };
3430
+ }
3431
+ function level3RasterPdbScales(decodeMode, productCode, minimumDataValue, dataIncrement, depProductDescriptionShorts, objectKey, genericDigital) {
3432
+ const minBad = !Number.isFinite(minimumDataValue) || Math.abs(minimumDataValue) > 500;
3433
+ const incBad = !Number.isFinite(dataIncrement) || dataIncrement <= 0;
3434
+ const bad = minBad || incBad;
3435
+ let minT = minimumDataValue;
3436
+ let dataInc = dataIncrement;
3437
+ let vilLevelThresholds = null;
3438
+ if (decodeMode === "vil" && productCode === 57 && Array.isArray(depProductDescriptionShorts) && depProductDescriptionShorts.length >= 17 && depProductDescriptionShorts[1] <= -3e4) {
3439
+ const byLevel = new Array(16).fill(Number.NaN);
3440
+ let validCount = 0;
3441
+ for (let level = 2; level <= 15; level++) {
3442
+ const raw = depProductDescriptionShorts[level + 1];
3443
+ if (Number.isFinite(raw) && raw > 0) {
3444
+ byLevel[level] = raw;
3445
+ validCount += 1;
3446
+ }
3447
+ }
3448
+ if (validCount >= 8) {
3449
+ vilLevelThresholds = byLevel;
3450
+ }
3451
+ }
3452
+ if (bad) {
3453
+ if (decodeMode === "vil" && minBad && !incBad && dataIncrement >= 0.05 && dataIncrement <= 2) {
3454
+ minT = -dataIncrement;
3455
+ dataInc = dataIncrement;
3456
+ } else if (decodeMode === "vil") {
3457
+ minT = 0;
3458
+ dataInc = 1;
3459
+ } else if (decodeMode === "precip") {
3460
+ minT = 0;
3461
+ dataInc = 0.25;
3462
+ } else if (decodeMode === "tops_kft") {
3463
+ minT = 0;
3464
+ dataInc = 1;
3465
+ } else if (decodeMode === "categorical") {
3466
+ minT = 0;
3467
+ dataInc = 1;
3468
+ } else if (decodeMode === "generic_physical") {
3469
+ minT = -2;
3470
+ dataInc = 0.05;
3471
+ } else {
3472
+ minT = -32;
3473
+ dataInc = 0.5;
3474
+ }
3475
+ }
3476
+ const symMode = decodeMode === "velocity" ? "digital_velocity_byte" : decodeMode === "precip" && !genericDigital ? "standard_digital" : "reflectivity";
3477
+ return { minT, dataInc, symMode, vilLevelThresholds };
3478
+ }
3479
+ function level3RasterToPolarFrame(raster, stationLat, stationLon, decodeMode, minT, dataInc, symMode, vilLevelThresholds, eetThresholds, valueScale, valueOffset, objectKey, genericDigital = null, l3ProductCode = 0) {
3480
+ const { rows, nCols, nRows, startXKm, startYKm, cellKmX, cellKmY, iStart, jStart } = raster;
3481
+ const widthKm = nCols * cellKmX;
3482
+ const heightKm = nRows * cellKmY;
3483
+ let originXK = startXKm;
3484
+ let originYK = startYKm;
3485
+ if (iStart === 0 && jStart === 0 && nCols === nRows && nCols >= 16) {
3486
+ originXK = startXKm - widthKm / 2;
3487
+ originYK = startYKm - heightKm / 2;
3488
+ }
3489
+ const xMin = originXK;
3490
+ const xMax = originXK + widthKm;
3491
+ const yMin = originYK;
3492
+ const yMax = originYK + heightKm;
3493
+ const corner = (x, y) => Math.hypot(x, y);
3494
+ let maxR = corner(xMin, yMin);
3495
+ maxR = Math.max(maxR, corner(xMax, yMin));
3496
+ maxR = Math.max(maxR, corner(xMin, yMax));
3497
+ maxR = Math.max(maxR, corner(xMax, yMax));
3498
+ maxR = Math.min(460, Math.max(50, maxR * 1.02));
3499
+ const nRays = 720;
3500
+ const gateWidthKm = 0.5;
3501
+ const nGates = Math.min(920, Math.max(64, Math.ceil(maxR / gateWidthKm)));
3502
+ const firstGateKm = 0;
3503
+ const gateData = new Uint8Array(nRays * nGates * 2);
3504
+ const rayBoundariesDeg = new Float32Array(nRays + 1);
3505
+ const deltaAz = 360 / nRays;
3506
+ for (let i = 0; i <= nRays; i++) {
3507
+ rayBoundariesDeg[i] = i * deltaAz - deltaAz * 0.5;
3508
+ }
3509
+ let samples = 0;
3510
+ let nodata = 0;
3511
+ for (let rayIdx = 0; rayIdx < nRays; rayIdx++) {
3512
+ const azDeg = (rayIdx + 0.5) * deltaAz;
3513
+ const azRad = azDeg * Math.PI / 180;
3514
+ const sinAz = Math.sin(azRad);
3515
+ const cosAz = Math.cos(azRad);
3516
+ for (let g = 0; g < nGates; g++) {
3517
+ const rKm = firstGateKm + (g + 0.5) * gateWidthKm;
3518
+ const xKm = rKm * sinAz;
3519
+ const yKm = rKm * cosAz;
3520
+ const fc = (xKm - originXK) / cellKmX;
3521
+ const fr = (yKm - originYK) / cellKmY;
3522
+ const c = Math.floor(fc);
3523
+ const r = Math.floor(fr);
3524
+ let level = null;
3525
+ if (c >= 0 && c < nCols && r >= 0 && r < nRows) {
3526
+ level = rows[r][c] ?? null;
3527
+ }
3528
+ let phys = null;
3529
+ if (level != null && Number.isFinite(level)) {
3530
+ if (decodeMode === "vil" && vilLevelThresholds && level >= 0 && level < vilLevelThresholds.length && Number.isFinite(vilLevelThresholds[level])) {
3531
+ phys = vilLevelThresholds[level];
3532
+ } else if (decodeMode === "tops_kft" && eetThresholds) {
3533
+ phys = level3EetHeightKmFromLevel(
3534
+ level,
3535
+ eetThresholds.dataMask,
3536
+ eetThresholds.scale,
3537
+ eetThresholds.offset
3538
+ );
3539
+ } else if (LEVEL3_DIGITAL_HMC_PRODUCT_CODES.has(l3ProductCode)) {
3540
+ phys = level3PhysicalFromDigitalHmc(level, "nibble");
3541
+ } else if (genericDigital) {
3542
+ phys = level3PhysicalFromGenericDigital(level, genericDigital, l3ProductCode);
3543
+ } else {
3544
+ phys = level3PhysicalFromDataLevel(level, minT, dataInc, symMode);
3545
+ }
3546
+ }
3547
+ if (phys == null || !Number.isFinite(phys)) {
3548
+ nodata++;
3549
+ const offset2 = (rayIdx * nGates + g) * 2;
3550
+ gateData[offset2] = 128;
3551
+ gateData[offset2 + 1] = 0;
3552
+ continue;
3553
+ }
3554
+ samples++;
3555
+ const rawSigned = Math.round((phys - valueOffset) / valueScale);
3556
+ const [hi, lo] = encodeSigned16ToHiLo(rawSigned);
3557
+ const offset = (rayIdx * nGates + g) * 2;
3558
+ gateData[offset] = hi;
3559
+ gateData[offset + 1] = lo;
3560
+ }
3561
+ }
3562
+ if (samples < 8) {
3563
+ console.warn("[aguacero][nexrad-l3][raster-nearly-empty]", { objectKey, samples, nodata });
3564
+ return null;
3565
+ }
3566
+ return {
3567
+ gateData,
3568
+ nRays,
3569
+ nGates,
3570
+ stationLat,
3571
+ stationLon,
3572
+ firstGateKm,
3573
+ gateWidthKm,
3574
+ valueScale,
3575
+ valueOffset,
3576
+ rayBoundariesDeg
3577
+ };
3578
+ }
3579
+ function isValidLevel3PdbStart(bytes, pos) {
3580
+ const len = bytes.length;
3581
+ if (pos + 14 > len) return false;
3582
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
3583
+ const latLonPlausible = (latMilli, lonMilli) => {
3584
+ const lat = latMilli / 1e3;
3585
+ const lon = lonMilli / 1e3;
3586
+ return lat >= -60 && lat <= 72 && lon >= -180 && lon <= 180 && Math.abs(lat) > 1 && Math.abs(lon) > 1;
3587
+ };
3588
+ if (bytes[pos] === 255 && bytes[pos + 1] === 255) {
3589
+ const latMilli = view.getInt32(pos + 2, false);
3590
+ const lonMilli = view.getInt32(pos + 6, false);
3591
+ return latLonPlausible(latMilli, lonMilli);
3592
+ }
3593
+ if (pos + 28 <= len) {
3594
+ const productCode = view.getUint16(pos, false);
3595
+ const divider = view.getInt16(pos + 18, false);
3596
+ if (productCode >= 1 && productCode <= 499 && divider === -1) {
3597
+ const latMilli = view.getInt32(pos + 20, false);
3598
+ const lonMilli = view.getInt32(pos + 24, false);
3599
+ if (latLonPlausible(latMilli, lonMilli)) return true;
3600
+ }
3601
+ }
3602
+ return false;
3603
+ }
3604
+ function findLevel3PdbByteOffset(bytes) {
3605
+ const len = bytes.length;
3606
+ let pos = 0;
3607
+ while (pos < len) {
3608
+ let lineEnd = pos;
3609
+ while (lineEnd < len && bytes[lineEnd] !== 10 && bytes[lineEnd] !== 13) lineEnd++;
3610
+ while (lineEnd < len && (bytes[lineEnd] === 10 || bytes[lineEnd] === 13)) lineEnd++;
3611
+ const nextStart = lineEnd;
3612
+ if (nextStart >= len - 2) break;
3613
+ if (isValidLevel3PdbStart(bytes, nextStart)) return nextStart;
3614
+ pos = nextStart;
3615
+ }
3616
+ if (len < 30) return 30;
3617
+ const end = Math.min(len - 14, 900);
3618
+ for (let i = 16; i <= end; i++) {
3619
+ if (isValidLevel3PdbStart(bytes, i)) return i;
3620
+ }
3621
+ return 30;
3622
+ }
3623
+ function decodeLevel3RasterProduct(buffer, objectKey, radarVariable) {
3624
+ try {
3625
+ const bytes = new Uint8Array(buffer);
3626
+ const marker = [83, 68, 85, 83];
3627
+ let startIndex = 0;
3628
+ for (let i = 0; i <= bytes.length - marker.length; i++) {
3629
+ if (bytes[i] === marker[0] && bytes[i + 1] === marker[1] && bytes[i + 2] === marker[2] && bytes[i + 3] === marker[3]) {
3630
+ startIndex = i;
3631
+ break;
3632
+ }
3633
+ }
3634
+ const trimmed = startIndex > 0 ? bytes.subarray(startIndex) : bytes;
3635
+ const raf = new Level3Raf(trimmed);
3636
+ const fileType = raf.readString(6);
3637
+ if (!fileType.startsWith("SDUS")) {
3638
+ throw new Error(`Unexpected Level3 header ${fileType}`);
3639
+ }
3640
+ const pdbByteOffset = findLevel3PdbByteOffset(trimmed);
3641
+ raf.seek(pdbByteOffset);
3642
+ const headerWord0 = raf.readShort();
3643
+ let stationLat;
3644
+ let stationLon;
3645
+ let productCode;
3646
+ if (headerWord0 === -1) {
3647
+ stationLat = raf.readInt() / 1e3;
3648
+ stationLon = raf.readInt() / 1e3;
3649
+ raf.readShort();
3650
+ productCode = raf.readUShort();
3651
+ } else {
3652
+ raf.seek(pdbByteOffset);
3653
+ productCode = raf.readUShort();
3654
+ raf.readShort();
3655
+ raf.readInt();
3656
+ raf.readInt();
3657
+ raf.readShort();
3658
+ raf.readShort();
3659
+ raf.readShort();
3660
+ const divider = raf.readShort();
3661
+ if (divider !== -1) throw new Error(`Invalid product divider ${divider}`);
3662
+ stationLat = raf.readInt() / 1e3;
3663
+ stationLon = raf.readInt() / 1e3;
3664
+ raf.readShort();
3665
+ raf.readShort();
3666
+ }
3667
+ raf.readShort();
3668
+ raf.readShort();
3669
+ raf.readShort();
3670
+ raf.readShort();
3671
+ raf.readShort();
3672
+ raf.readInt();
3673
+ raf.readShort();
3674
+ raf.readInt();
3675
+ raf.read(4);
3676
+ raf.readShort();
3677
+ const dep30_53 = new Level3Raf(raf.read(48));
3678
+ const depProductDescriptionShorts = [];
3679
+ for (let i = 0; i < 24; i++) {
3680
+ depProductDescriptionShorts.push(dep30_53.readShort());
3681
+ }
3682
+ const minimumDataValue = depProductDescriptionShorts[1] / 10;
3683
+ const dataIncrement = depProductDescriptionShorts[2] / 10;
3684
+ const compressionMethod = depProductDescriptionShorts[21];
3685
+ const genericDigitalParams = LEVEL3_GENERIC_DIGITAL_PRODUCT_CODES.has(productCode) ? parseLevel3GenericDigitalParams(depProductDescriptionShorts) : null;
3686
+ if (LEVEL3_GENERIC_DIGITAL_PRODUCT_CODES.has(productCode) && !genericDigitalParams) {
3687
+ console.warn("[aguacero][nexrad-l3][generic-digital-params-null]", {
3688
+ objectKey,
3689
+ radarVariable,
3690
+ productCode,
3691
+ depHead: depProductDescriptionShorts.slice(0, 12),
3692
+ hint: "Continuing with legacy min/inc; precip values may be wrong \xE2\u20AC\u201D check dep alignment / PDB offset."
3693
+ });
3694
+ }
3695
+ let msg134Params = null;
3696
+ if (productCode === 134 && depProductDescriptionShorts.length >= 6) {
3697
+ const hw31 = depProductDescriptionShorts[1];
3698
+ const hw32 = depProductDescriptionShorts[2];
3699
+ const hw33 = depProductDescriptionShorts[3];
3700
+ const hw34 = depProductDescriptionShorts[4];
3701
+ const hw35 = depProductDescriptionShorts[5];
3702
+ msg134Params = {
3703
+ linearScale: int16ToFloat16(hw31),
3704
+ linearOffset: int16ToFloat16(hw32),
3705
+ logStart: hw33,
3706
+ logScale: int16ToFloat16(hw34),
3707
+ logOffset: int16ToFloat16(hw35)
3708
+ };
3709
+ }
3710
+ const l3Entry = getNexradLevel3EntryByRadarKey(radarVariable);
3711
+ const decodeMode = l3Entry?.decodeMode ?? (radarVariable === "VEL" || radarVariable === "N0G" || radarVariable === "SW" || radarVariable === "N0W" ? "velocity" : "dbz");
3712
+ const isVelSw = decodeMode === "velocity";
3713
+ let minThreshold = minimumDataValue;
3714
+ let dataInc = dataIncrement;
3715
+ if (isVelSw) {
3716
+ const pdbLooksInvalid = !Number.isFinite(dataInc) || dataInc <= 0 || dataInc > 25 || !Number.isFinite(minThreshold) || Math.abs(minThreshold) > 130;
3717
+ if (pdbLooksInvalid) {
3718
+ minThreshold = -63.5;
3719
+ dataInc = 0.5;
3720
+ }
3721
+ }
3722
+ if (decodeMode === "precip" && productCode === 138) {
3723
+ dataInc = depProductDescriptionShorts[2] * 0.01;
3724
+ }
3725
+ const eetRadialThresholds = decodeMode === "tops_kft" && productCode === 135 ? {
3726
+ dataMask: depProductDescriptionShorts[1],
3727
+ scale: depProductDescriptionShorts[2],
3728
+ offset: depProductDescriptionShorts[3]
3729
+ } : null;
3730
+ raf.readByte();
3731
+ raf.readByte();
3732
+ const offsetSymbology = raf.readInt();
3733
+ raf.readInt();
3734
+ raf.readInt();
3735
+ let parseBytes = trimmed;
3736
+ if (compressionMethod > 0) {
3737
+ const headerBytes = trimmed.subarray(0, raf.getPos());
3738
+ const compressedTail = trimmed.subarray(raf.getPos());
3739
+ const decompressedTail = bzip.decode(compressedTail);
3740
+ parseBytes = concatUint8(headerBytes, decompressedTail);
3741
+ }
3742
+ const parseRaf = new Level3Raf(parseBytes);
3743
+ const symbologyOffsetBytes = pdbByteOffset + offsetSymbology * 2;
3744
+ parseRaf.seek(symbologyOffsetBytes);
3745
+ const blockDivider = parseRaf.readShort();
3746
+ const blockId = parseRaf.readShort();
3747
+ if (blockDivider !== -1 || blockId !== 1) {
3748
+ const oob = symbologyOffsetBytes < 0 || symbologyOffsetBytes >= parseBytes.length;
3749
+ console.warn("[aguacero][nexrad-l3][symbology-header-bad]", {
3750
+ objectKey,
3751
+ radarVariable,
3752
+ productCode,
3753
+ blockDivider,
3754
+ blockId,
3755
+ symbologyOffsetBytes,
3756
+ parseBytesLength: parseBytes.length,
3757
+ seekOob: oob,
3758
+ hint: "Usually wrong PDB byte offset; check [sym-offset] and findLevel3PdbByteOffset."
3759
+ });
3760
+ throw new Error(`Invalid symbology header ${blockDivider}/${blockId}`);
3761
+ }
3762
+ parseRaf.readInt();
3763
+ const numberLayers = parseRaf.readShort();
3764
+ let bestRadial = null;
3765
+ let rasterParsed = null;
3766
+ const symbologyPacketCodes = [];
3767
+ for (let layerIndex = 0; layerIndex < numberLayers; layerIndex++) {
3768
+ const layerStart = parseRaf.getPos();
3769
+ const layerDivider = parseRaf.readShort();
3770
+ const layerPayloadLength = parseRaf.readInt();
3771
+ if (layerDivider !== -1) {
3772
+ parseRaf.seek(layerStart + 6 + layerPayloadLength);
3773
+ continue;
3774
+ }
3775
+ const layerEnd = parseRaf.getPos() + layerPayloadLength;
3776
+ while (parseRaf.getPos() < layerEnd) {
3777
+ const packetPos = parseRaf.getPos();
3778
+ const packetCode = parseRaf.readUShort();
3779
+ symbologyPacketCodes.push(packetCode);
3780
+ parseRaf.seek(packetPos);
3781
+ if (packetCode === 16) {
3782
+ const symMode = isVelSw ? "digital_velocity_byte" : decodeMode === "precip" && !genericDigitalParams ? "standard_digital" : "reflectivity";
3783
+ const p = parseLevel3Packet0010(
3784
+ parseRaf,
3785
+ minThreshold,
3786
+ dataInc,
3787
+ symMode,
3788
+ productCode,
3789
+ msg134Params,
3790
+ eetRadialThresholds,
3791
+ genericDigitalParams
3792
+ );
3793
+ const cand = { kind: 16, packet: p };
3794
+ if (level3RadialPickIsBetter(cand, bestRadial)) bestRadial = cand;
3795
+ continue;
3796
+ }
3797
+ if (packetCode === 44831) {
3798
+ const symMode = isVelSw ? "digital_velocity_rle4" : decodeMode === "precip" && !genericDigitalParams ? "standard_digital" : "reflectivity";
3799
+ const p = parseLevel3PacketAF1F(
3800
+ parseRaf,
3801
+ minThreshold,
3802
+ dataInc,
3803
+ symMode,
3804
+ productCode,
3805
+ msg134Params,
3806
+ eetRadialThresholds,
3807
+ genericDigitalParams
3808
+ );
3809
+ const cand = { kind: 44831, packet: p };
3810
+ if (level3RadialPickIsBetter(cand, bestRadial)) bestRadial = cand;
3811
+ continue;
3812
+ }
3813
+ if (packetCode === LEVEL3_PACKET_RASTER_BA07) {
3814
+ parseRaf.seek(packetPos);
3815
+ const parsed = parseLevel3PacketRasterBA07(parseRaf, layerEnd, objectKey);
3816
+ if (parsed && rasterParsed === null) rasterParsed = parsed;
3817
+ else if (!parsed) parseRaf.seek(layerEnd);
3818
+ continue;
3819
+ }
3820
+ if (trySkipLevel3OverlayPacket(parseRaf, packetCode, layerEnd)) {
3821
+ continue;
3822
+ }
3823
+ parseRaf.seek(layerEnd);
3824
+ break;
3825
+ }
3826
+ parseRaf.seek(layerEnd);
3827
+ }
3828
+ const shouldPreferRaster = rasterParsed != null && (decodeMode === "tops_kft" && productCode !== 135 || decodeMode === "precip");
3829
+ if (bestRadial && !shouldPreferRaster) {
3830
+ const radialPacket = bestRadial.packet;
3831
+ const radials = radialPacket?.radials;
3832
+ const nRays = Number(radialPacket?.numberRadials);
3833
+ const nGates = Number(radialPacket?.numberBins);
3834
+ if (!Array.isArray(radials) || !Number.isFinite(nRays) || !Number.isFinite(nGates) || !Number.isFinite(stationLat) || !Number.isFinite(stationLon)) {
3835
+ console.warn("[aguacero][nexrad-l3][invalid-radial-packet]", { objectKey, radarVariable, nRays, nGates, stationLat, stationLon });
3836
+ } else {
3837
+ const gateData = new Uint8Array(nRays * nGates * 2);
3838
+ const { valueScale, valueOffset } = level3ValuePacking(decodeMode);
3839
+ for (let r = 0; r < nRays; r++) {
3840
+ const bins = radials[r]?.bins;
3841
+ for (let g = 0; g < nGates; g++) {
3842
+ const v = bins?.[g];
3843
+ const isNoData = v == null || !Number.isFinite(v);
3844
+ const rawSigned = isNoData ? -32768 : Math.round((Number(v) - valueOffset) / valueScale);
3845
+ const [hi, lo] = encodeSigned16ToHiLo(rawSigned);
3846
+ const offset = (r * nGates + g) * 2;
3847
+ gateData[offset] = hi;
3848
+ gateData[offset + 1] = lo;
3849
+ }
3850
+ }
3851
+ const rangeMul = LEVEL3_PRODUCT_RANGE_SCALE_MUL[productCode] ?? 1;
3852
+ const rangeScaleRaw = Number(radialPacket?.rangeScaleRaw);
3853
+ const gateSpacingM = Number.isFinite(rangeScaleRaw) && rangeScaleRaw > 0 ? rangeScaleRaw * rangeMul : 250;
3854
+ let gateWidthKm = gateSpacingM / 1e3;
3855
+ const firstBinM = Number(radialPacket?.firstBinMeters);
3856
+ let firstGateKm = Number.isFinite(firstBinM) && firstBinM >= 0 ? firstBinM / 1e3 : 0;
3857
+ const decodedCoverageKm = firstGateKm + nGates * gateWidthKm;
3858
+ if (decodedCoverageKm > 0 && decodedCoverageKm < 20 && nGates >= 100) {
3859
+ gateWidthKm *= 1e3;
3860
+ firstGateKm *= 1e3;
3861
+ }
3862
+ if (decodeMode === "precip" && decodedCoverageKm > 1500) {
3863
+ gateWidthKm /= 1e3;
3864
+ firstGateKm /= 1e3;
3865
+ }
3866
+ const rayBoundariesDeg = buildRayBoundariesFromLevel3Radials(radials);
3867
+ return {
3868
+ gateData,
3869
+ nRays,
3870
+ nGates,
3871
+ stationLat,
3872
+ stationLon,
3873
+ firstGateKm,
3874
+ gateWidthKm,
3875
+ valueScale,
3876
+ valueOffset,
3877
+ rayBoundariesDeg
3878
+ };
3879
+ }
3880
+ }
3881
+ if (rasterParsed) {
3882
+ const { valueScale, valueOffset } = level3ValuePacking(decodeMode);
3883
+ const { minT, dataInc: rasterDataInc, symMode, vilLevelThresholds } = level3RasterPdbScales(
3884
+ decodeMode,
3885
+ productCode,
3886
+ minThreshold,
3887
+ dataInc,
3888
+ depProductDescriptionShorts,
3889
+ objectKey,
3890
+ genericDigitalParams
3891
+ );
3892
+ const eetThresholds = decodeMode === "tops_kft" && productCode === 135 ? {
3893
+ dataMask: depProductDescriptionShorts[1],
3894
+ scale: depProductDescriptionShorts[2],
3895
+ offset: depProductDescriptionShorts[3]
3896
+ } : null;
3897
+ const rasterFrame = level3RasterToPolarFrame(
3898
+ rasterParsed,
3899
+ stationLat,
3900
+ stationLon,
3901
+ decodeMode,
3902
+ minT,
3903
+ rasterDataInc,
3904
+ symMode,
3905
+ vilLevelThresholds,
3906
+ eetThresholds,
3907
+ valueScale,
3908
+ valueOffset,
3909
+ objectKey,
3910
+ genericDigitalParams,
3911
+ productCode
3912
+ );
3913
+ if (rasterFrame) {
3914
+ return rasterFrame;
3915
+ }
3916
+ }
3917
+ const hex = symbologyPacketCodes.map((c) => `0x${c.toString(16)}`);
3918
+ if (!bestRadial) {
3919
+ console.warn("[aguacero][nexrad-l3][no-radial-symbology]", {
3920
+ objectKey,
3921
+ radarVariable,
3922
+ messageCode: productCode,
3923
+ numberLayers,
3924
+ symbologyPacketCodes,
3925
+ symbologyPacketCodesHex: hex,
3926
+ hint: "Radial: packets 0x10 / 0xAF1F. Raster: 0xBA07 is supported; if rasterParsed failed, check parseLevel3PacketRasterBA07 / inner code logs."
3927
+ });
3928
+ }
3929
+ return null;
3930
+ } catch (err) {
3931
+ console.warn("[aguacero][nexrad-l3][decode-throw]", { objectKey, radarVariable, err });
3932
+ return null;
3933
+ }
3934
+ }
3935
+ var GROUP2_VARS = ["VEL", "SW"];
3936
+ var GROUP1_VARS = ["REF", "ZDR", "RHO", "PHI"];
3937
+ var GROUP2_COMBINED_7_VARS = ["REF", "ZDR", "RHO", "PHI", "KDP", "VEL", "SW"];
3938
+ var GROUP2_COMBINED_VARS = ["REF", "ZDR", "RHO", "PHI", "VEL", "SW"];
3939
+ var FILE_HDR_BYTES = 64;
3940
+ var AZ_BLOCK_BYTES = 720 * 4;
3941
+ var SLOT_INDEX_ENTRY = 18;
3942
+ var MAX_SLOTS = 6;
3943
+ function int16ToFloat16(val) {
3944
+ const sign = (val & 32768) / 32768;
3945
+ const exponent = (val & 31744) / 1024;
3946
+ const fraction = val & 1023;
3947
+ if (exponent === 0) {
3948
+ return Math.pow(-1, sign) * 2 * (0 + fraction / Math.pow(2, 10));
3949
+ }
3950
+ return Math.pow(-1, sign) * Math.pow(2, exponent - 16) * (1 + fraction / Math.pow(2, 10));
3951
+ }
3952
+ function parseFileHeader(buffer) {
3953
+ const view = new DataView(buffer);
3954
+ const magic = view.getUint32(0, false);
3955
+ if (magic !== 1314406980) throw new Error(`Bad magic: 0x${magic.toString(16)}`);
3956
+ const unixTime = view.getUint32(4, false);
3957
+ const nRays = view.getUint16(8, false);
3958
+ const nGates = view.getUint16(10, false);
3959
+ const elevAngle = view.getFloat32(12, false);
3960
+ const firstGateKm = view.getFloat32(16, false);
3961
+ const gateWidthKm = view.getFloat32(20, false);
3962
+ const nSlots = view.getUint16(24, false);
3963
+ const azimuthsBuffer = buffer.slice(FILE_HDR_BYTES, FILE_HDR_BYTES + AZ_BLOCK_BYTES);
3964
+ const idxStart = FILE_HDR_BYTES + AZ_BLOCK_BYTES;
3965
+ const slots = [];
3966
+ for (let i = 0; i < nSlots; i++) {
3967
+ const base = idxStart + i * SLOT_INDEX_ENTRY;
3968
+ const offsetHigh = view.getUint32(base, false);
3969
+ const offsetLow = view.getUint32(base + 4, false);
3970
+ const offset = offsetHigh * 2 ** 32 + offsetLow;
3971
+ const compressedSize = view.getUint32(base + 8, false);
3972
+ const uncompressedSize = view.getUint32(base + 12, false);
3973
+ slots.push({ offset, compressedSize, uncompressedSize });
3974
+ }
3975
+ return {
3976
+ unixTime,
3977
+ nRays,
3978
+ nGates,
3979
+ elevAngle,
3980
+ firstGateKm,
3981
+ gateWidthKm,
3982
+ nSlots,
3983
+ azimuthsBuffer,
3984
+ slots
3985
+ };
3986
+ }
3987
+ function decodeSweepInWorker(objectKey, slotBuffer, header, sites, priority, signal) {
3988
+ if (signal?.aborted) return Promise.reject(new DOMException("Aborted", "AbortError"));
3989
+ const { worker } = getDecodeWorkerForPriority(priority);
3990
+ const requestId = ++radarDecodeRequestId;
3991
+ const azCopy = header.azimuthsBuffer.slice(0);
3992
+ return new Promise((resolve, reject) => {
3993
+ let isSettled = false;
3994
+ const onAbort = () => {
3995
+ if (isSettled) return;
3996
+ isSettled = true;
3997
+ radarDecodePending.delete(requestId);
3998
+ radarDecodeRequestMeta.delete(requestId);
3999
+ signal?.removeEventListener("abort", onAbort);
4000
+ reject(new DOMException("Aborted", "AbortError"));
4001
+ };
4002
+ radarDecodePending.set(requestId, {
4003
+ resolve: (frame) => {
4004
+ if (!isSettled) {
4005
+ isSettled = true;
4006
+ signal?.removeEventListener("abort", onAbort);
4007
+ resolve(frame);
4008
+ }
4009
+ },
4010
+ reject: (err) => {
4011
+ if (!isSettled) {
4012
+ isSettled = true;
4013
+ signal?.removeEventListener("abort", onAbort);
4014
+ reject(err);
4015
+ }
4016
+ }
4017
+ });
4018
+ if (signal) signal.addEventListener("abort", onAbort, { once: true });
4019
+ worker.postMessage({
4020
+ type: "DECODE_SLOT",
4021
+ requestId,
4022
+ objectKey,
4023
+ slotBuffer,
4024
+ nRays: header.nRays,
4025
+ nGates: header.nGates,
4026
+ firstGateKm: header.firstGateKm,
4027
+ gateWidthKm: header.gateWidthKm,
4028
+ azimuthsBuffer: azCopy,
4029
+ sites
4030
+ }, [slotBuffer, azCopy]);
4031
+ });
4032
+ }
4033
+ async function applyStormMotionFromN0sObjectKey(frame, motionObjectKey, logLabel) {
4034
+ const motionUrl = objectKeyToUrl(motionObjectKey, "level3");
4035
+ try {
4036
+ const motionResp = await fetch(motionUrl);
4037
+ if (motionResp.ok) {
4038
+ const motionBuf = await motionResp.arrayBuffer();
4039
+ const motion = parseLevel3StormMotionFromBuffer(motionBuf);
4040
+ if (motion) {
4041
+ return applyLevel3StormRelativeToFrame(frame, motion.speedMs, motion.directionDeg);
4042
+ }
4043
+ }
4044
+ } catch (e) {
4045
+ console.log(`${logLabel}:srvMotionFetchError`, { motionObjectKey, err: e });
4046
+ }
4047
+ return frame;
4048
+ }
4049
+ async function fetchAndParseArchive(url, objectKey, radarVariable, groupId, radarSource, options) {
4050
+ const mot = options?.level3MotionObjectKey ? `|${options.level3MotionObjectKey}` : "";
4051
+ const cacheKey = `${url}:${radarVariable}:${radarSource}${mot}`;
4052
+ const priority = options?.priority ?? "display";
4053
+ if (archiveCache.has(cacheKey)) {
4054
+ const cached = archiveCache.get(cacheKey);
4055
+ setArchiveCache(cacheKey, cached);
4056
+ return cached;
4057
+ }
4058
+ const existingInflight = inflightFetches.get(cacheKey);
4059
+ if (existingInflight) {
4060
+ const meta = inflightFetchMeta.get(cacheKey);
4061
+ if (meta) {
4062
+ meta.callers += 1;
4063
+ }
4064
+ return existingInflight;
4065
+ }
4066
+ if (options?.signal?.aborted) {
4067
+ return null;
4068
+ }
4069
+ const requestId = ++radarFetchRequestSeq;
4070
+ const startedAt = performance.now();
4071
+ inflightFetchMeta.set(cacheKey, {
4072
+ requestId,
4073
+ startedAt,
4074
+ callers: 1,
4075
+ objectKey,
4076
+ radarVariable,
4077
+ radarSource,
4078
+ priority
4079
+ });
4080
+ const promise = (async () => {
4081
+ try {
4082
+ if (radarSource === "level3") {
4083
+ const response = await fetch(url);
4084
+ if (!response.ok) throw new Error(`HTTP ${response.status} fetching level3 ${url}`);
4085
+ const buffer = await response.arrayBuffer();
4086
+ let decoded2 = decodeLevel3RasterProduct(buffer, objectKey, radarVariable);
4087
+ const motionKey = options?.level3MotionObjectKey;
4088
+ if (decoded2 && motionKey && radarVariable === "VEL") {
4089
+ decoded2 = await applyStormMotionFromN0sObjectKey(
4090
+ decoded2,
4091
+ motionKey,
4092
+ "fetchAndParseArchive:level3"
4093
+ );
4094
+ }
4095
+ if (!decoded2) {
4096
+ console.warn("[aguacero][nexrad-l3][fetch-ok-decode-null]", {
4097
+ objectKey,
4098
+ radarVariable,
4099
+ byteLength: buffer.byteLength,
4100
+ filterConsole: "Also check [aguacero][nexrad-l3][no-radial-symbology] or decode catch logs"
4101
+ });
4102
+ } else {
4103
+ setArchiveCache(cacheKey, decoded2);
4104
+ }
4105
+ return decoded2;
4106
+ }
4107
+ const INDEX_FETCH_BYTES = FILE_HDR_BYTES + AZ_BLOCK_BYTES + MAX_SLOTS * SLOT_INDEX_ENTRY;
4108
+ const indexResp = await fetch(url, {
4109
+ headers: {
4110
+ "x-api-key": NEXRAD_ARCHIVE_API_KEY,
4111
+ "Range": `bytes=0-${INDEX_FETCH_BYTES - 1}`
4112
+ }
4113
+ });
4114
+ if (!indexResp.ok && indexResp.status !== 206) {
4115
+ throw new Error(`HTTP ${indexResp.status} fetching level2 index ${url}`);
4116
+ }
4117
+ const indexBuffer = await indexResp.arrayBuffer();
4118
+ const header = parseFileHeader(indexBuffer);
4119
+ let varList;
4120
+ if (groupId === 2 && header.nSlots === 7) {
4121
+ varList = GROUP2_COMBINED_7_VARS;
4122
+ } else if (groupId === 2 && header.nSlots === 6) {
4123
+ varList = GROUP2_COMBINED_VARS;
4124
+ } else if (groupId === 2) {
4125
+ varList = GROUP2_VARS;
4126
+ } else {
4127
+ varList = [...GROUP1_VARS];
4128
+ }
4129
+ const slotIdx = varList.indexOf(radarVariable);
4130
+ if (slotIdx < 0 || slotIdx >= header.slots.length) {
4131
+ console.warn(`[RadarLayer] ${radarVariable} not in group ${groupId} (nSlots=${header.nSlots})`);
4132
+ setArchiveCache(cacheKey, null);
4133
+ return null;
4134
+ }
4135
+ const slot = header.slots[slotIdx];
4136
+ if (slot.compressedSize === 0) {
4137
+ console.warn(`[RadarLayer] ${radarVariable} slot ${slotIdx} has compressedSize=0`);
4138
+ setArchiveCache(cacheKey, null);
4139
+ return null;
4140
+ }
4141
+ const slotRangeEnd = slot.offset + slot.compressedSize - 1;
4142
+ const slotResp = await fetch(url, {
4143
+ headers: {
4144
+ "x-api-key": NEXRAD_ARCHIVE_API_KEY,
4145
+ "Range": `bytes=${slot.offset}-${slotRangeEnd}`
4146
+ }
4147
+ });
4148
+ if (!slotResp.ok && slotResp.status !== 206) {
4149
+ throw new Error(`HTTP ${slotResp.status} fetching level2 slot ${url}`);
4150
+ }
4151
+ const slotBuffer = await slotResp.arrayBuffer();
4152
+ const sites = await loadNexradSites();
4153
+ let decoded = await decodeSweepInWorker(
4154
+ objectKey,
4155
+ slotBuffer,
4156
+ header,
4157
+ sites,
4158
+ options?.priority ?? "display",
4159
+ void 0
4160
+ );
4161
+ if (!decoded) {
4162
+ setArchiveCache(cacheKey, null);
4163
+ return null;
4164
+ }
4165
+ const l2MotionKey = options?.level3MotionObjectKey;
4166
+ if (l2MotionKey && radarVariable === "VEL") {
4167
+ decoded = await applyStormMotionFromN0sObjectKey(
4168
+ decoded,
4169
+ l2MotionKey,
4170
+ "fetchAndParseArchive:level2"
4171
+ );
4172
+ }
4173
+ setArchiveCache(cacheKey, decoded);
4174
+ return decoded;
4175
+ } catch (err) {
4176
+ if (err instanceof DOMException && err.name === "AbortError") {
4177
+ return null;
4178
+ }
4179
+ console.error(`[RadarLayer] fetchAndParseArchive failed for ${objectKey}:`, err);
4180
+ return null;
4181
+ } finally {
4182
+ inflightFetches.delete(cacheKey);
4183
+ inflightFetchMeta.delete(cacheKey);
4184
+ }
4185
+ })();
4186
+ inflightFetches.set(cacheKey, promise);
4187
+ return promise;
4188
+ }
4189
+ export {
4190
+ fetchAndParseArchive,
4191
+ objectKeyToUrl,
4192
+ setNexradArchiveApiKey
4193
+ };
4194
+ /*! Bundled license information:
4195
+
4196
+ ieee754/index.js:
4197
+ (*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *)
4198
+
4199
+ buffer/index.js:
4200
+ (*!
4201
+ * The buffer module from node.js, for the browser.
4202
+ *
4203
+ * @author Feross Aboukhadijeh <https://feross.org>
4204
+ * @license MIT
4205
+ *)
4206
+ */