taxonium-component
Version:
React component for exploring large phylogenetic trees in the browser
1,497 lines • 54.1 kB
JavaScript
import { bT as lt, aX as ht, a2 as dt, a3 as ut } from "./JBrowsePanel-uJIA-L6s.js";
import { A as gt } from "./AbortablePromiseCache-CcuMrnn7.js";
import { Q as wt } from "./index-BOYufR2k.js";
import { O as bt } from "./Observable-D5EkXphs.js";
const Ke = BigInt(32);
function xt(i, t, e) {
const a = +!!e, o = +!e;
return BigInt(i.getInt32(t, e) * o + i.getInt32(t + 4, e) * a) << Ke | BigInt(i.getUint32(t, e) * a + i.getUint32(t + 4, e) * o);
}
function mt(i, t, e) {
const a = i.getUint32(t, e), o = i.getUint32(t + 4, e), n = +!!e, s = +!e;
return BigInt(a * s + o * n) << Ke | BigInt(a * n + o * s);
}
"getBigInt64" in DataView || (DataView.prototype.getBigInt64 = function(i, t) {
return xt(this, i, t);
});
"getBigUint64" in DataView || (DataView.prototype.getBigUint64 = function(i, t) {
return mt(this, i, t);
});
class z {
constructor(t) {
this.ranges = t;
}
get min() {
return this.ranges[0].min;
}
get max() {
return this.ranges.at(-1).max;
}
contains(t) {
for (const e of this.ranges)
if (e.min <= t && e.max >= t)
return !0;
return !1;
}
isContiguous() {
return this.ranges.length > 1;
}
getRanges() {
return this.ranges.map((t) => new z([{ min: t.min, max: t.max }]));
}
toString() {
return this.ranges.map((t) => `[${t.min}-${t.max}]`).join(",");
}
union(t) {
const e = [...this.getRanges(), ...t.getRanges()].sort((n, s) => n.min < s.min ? -1 : n.min > s.min ? 1 : n.max < s.max ? -1 : s.max > n.max ? 1 : 0), a = [];
let o = e[0];
for (const n of e)
n.min > o.max + 1 ? (a.push(o), o = n) : n.max > o.max && (o = new z([{ min: o.min, max: n.max }]));
return a.push(o), a.length === 1 ? a[0] : new z(a);
}
}
function H(i) {
let t = i.length;
for (; --t >= 0; )
i[t] = 0;
}
const _t = 3, kt = 258, je = 29, pt = 256, yt = pt + 1 + je, We = 30, Et = 512, vt = new Array((yt + 2) * 2);
H(vt);
const St = new Array(We * 2);
H(St);
const Rt = new Array(Et);
H(Rt);
const Bt = new Array(kt - _t + 1);
H(Bt);
const Tt = new Array(je);
H(Tt);
const At = new Array(We);
H(At);
const Ut = (i, t, e, a) => {
let o = i & 65535 | 0, n = i >>> 16 & 65535 | 0, s = 0;
for (; e !== 0; ) {
s = e > 2e3 ? 2e3 : e, e -= s;
do
o = o + t[a++] | 0, n = n + o | 0;
while (--s);
o %= 65521, n %= 65521;
}
return o | n << 16 | 0;
};
var de = Ut;
const Dt = () => {
let i, t = [];
for (var e = 0; e < 256; e++) {
i = e;
for (var a = 0; a < 8; a++)
i = i & 1 ? 3988292384 ^ i >>> 1 : i >>> 1;
t[e] = i;
}
return t;
}, It = new Uint32Array(Dt()), Ot = (i, t, e, a) => {
const o = It, n = a + e;
i ^= -1;
for (let s = a; s < n; s++)
i = i >>> 8 ^ o[(i ^ t[s]) & 255];
return i ^ -1;
};
var I = Ot, ue = {
2: "need dictionary",
/* Z_NEED_DICT 2 */
1: "stream end",
/* Z_STREAM_END 1 */
0: "",
/* Z_OK 0 */
"-1": "file error",
/* Z_ERRNO (-1) */
"-2": "stream error",
/* Z_STREAM_ERROR (-2) */
"-3": "data error",
/* Z_DATA_ERROR (-3) */
"-4": "insufficient memory",
/* Z_MEM_ERROR (-4) */
"-5": "buffer error",
/* Z_BUF_ERROR (-5) */
"-6": "incompatible version"
/* Z_VERSION_ERROR (-6) */
}, Xe = {
/* Allowed flush values; see deflate() and inflate() below for details */
Z_NO_FLUSH: 0,
Z_FINISH: 4,
Z_BLOCK: 5,
Z_TREES: 6,
/* Return codes for the compression/decompression functions. Negative values
* are errors, positive values are used for special but normal events.
*/
Z_OK: 0,
Z_STREAM_END: 1,
Z_NEED_DICT: 2,
Z_STREAM_ERROR: -2,
Z_DATA_ERROR: -3,
Z_MEM_ERROR: -4,
Z_BUF_ERROR: -5,
/* The deflate compression method */
Z_DEFLATED: 8
//Z_NULL: null // Use -1 or null inline, depending on var type
};
const Nt = (i, t) => Object.prototype.hasOwnProperty.call(i, t);
var Ct = function(i) {
const t = Array.prototype.slice.call(arguments, 1);
for (; t.length; ) {
const e = t.shift();
if (e) {
if (typeof e != "object")
throw new TypeError(e + "must be non-object");
for (const a in e)
Nt(e, a) && (i[a] = e[a]);
}
}
return i;
}, Ft = (i) => {
let t = 0;
for (let a = 0, o = i.length; a < o; a++)
t += i[a].length;
const e = new Uint8Array(t);
for (let a = 0, o = 0, n = i.length; a < n; a++) {
let s = i[a];
e.set(s, o), o += s.length;
}
return e;
}, Ye = {
assign: Ct,
flattenChunks: Ft
};
let Qe = !0;
try {
String.fromCharCode.apply(null, new Uint8Array(1));
} catch {
Qe = !1;
}
const P = new Uint8Array(256);
for (let i = 0; i < 256; i++)
P[i] = i >= 252 ? 6 : i >= 248 ? 5 : i >= 240 ? 4 : i >= 224 ? 3 : i >= 192 ? 2 : 1;
P[254] = P[254] = 1;
var Mt = (i) => {
if (typeof TextEncoder == "function" && TextEncoder.prototype.encode)
return new TextEncoder().encode(i);
let t, e, a, o, n, s = i.length, l = 0;
for (o = 0; o < s; o++)
e = i.charCodeAt(o), (e & 64512) === 55296 && o + 1 < s && (a = i.charCodeAt(o + 1), (a & 64512) === 56320 && (e = 65536 + (e - 55296 << 10) + (a - 56320), o++)), l += e < 128 ? 1 : e < 2048 ? 2 : e < 65536 ? 3 : 4;
for (t = new Uint8Array(l), n = 0, o = 0; n < l; o++)
e = i.charCodeAt(o), (e & 64512) === 55296 && o + 1 < s && (a = i.charCodeAt(o + 1), (a & 64512) === 56320 && (e = 65536 + (e - 55296 << 10) + (a - 56320), o++)), e < 128 ? t[n++] = e : e < 2048 ? (t[n++] = 192 | e >>> 6, t[n++] = 128 | e & 63) : e < 65536 ? (t[n++] = 224 | e >>> 12, t[n++] = 128 | e >>> 6 & 63, t[n++] = 128 | e & 63) : (t[n++] = 240 | e >>> 18, t[n++] = 128 | e >>> 12 & 63, t[n++] = 128 | e >>> 6 & 63, t[n++] = 128 | e & 63);
return t;
};
const Zt = (i, t) => {
if (t < 65534 && i.subarray && Qe)
return String.fromCharCode.apply(null, i.length === t ? i : i.subarray(0, t));
let e = "";
for (let a = 0; a < t; a++)
e += String.fromCharCode(i[a]);
return e;
};
var $t = (i, t) => {
const e = t || i.length;
if (typeof TextDecoder == "function" && TextDecoder.prototype.decode)
return new TextDecoder().decode(i.subarray(0, t));
let a, o;
const n = new Array(e * 2);
for (o = 0, a = 0; a < e; ) {
let s = i[a++];
if (s < 128) {
n[o++] = s;
continue;
}
let l = P[s];
if (l > 4) {
n[o++] = 65533, a += l - 1;
continue;
}
for (s &= l === 2 ? 31 : l === 3 ? 15 : 7; l > 1 && a < e; )
s = s << 6 | i[a++] & 63, l--;
if (l > 1) {
n[o++] = 65533;
continue;
}
s < 65536 ? n[o++] = s : (s -= 65536, n[o++] = 55296 | s >> 10 & 1023, n[o++] = 56320 | s & 1023);
}
return Zt(n, o);
}, Lt = (i, t) => {
t = t || i.length, t > i.length && (t = i.length);
let e = t - 1;
for (; e >= 0 && (i[e] & 192) === 128; )
e--;
return e < 0 || e === 0 ? t : e + P[i[e]] > t ? e : t;
}, ge = {
string2buf: Mt,
buf2string: $t,
utf8border: Lt
};
function zt() {
this.input = null, this.next_in = 0, this.avail_in = 0, this.total_in = 0, this.output = null, this.next_out = 0, this.avail_out = 0, this.total_out = 0, this.msg = "", this.state = null, this.data_type = 2, this.adler = 0;
}
var Ht = zt;
const K = 16209, Vt = 16191;
var Pt = function(t, e) {
let a, o, n, s, l, x, r, f, R, g, c, u, m, E, w, p, _, h, b, B, d, v, S, k;
const y = t.state;
a = t.next_in, S = t.input, o = a + (t.avail_in - 5), n = t.next_out, k = t.output, s = n - (e - t.avail_out), l = n + (t.avail_out - 257), x = y.dmax, r = y.wsize, f = y.whave, R = y.wnext, g = y.window, c = y.hold, u = y.bits, m = y.lencode, E = y.distcode, w = (1 << y.lenbits) - 1, p = (1 << y.distbits) - 1;
e:
do {
u < 15 && (c += S[a++] << u, u += 8, c += S[a++] << u, u += 8), _ = m[c & w];
t:
for (; ; ) {
if (h = _ >>> 24, c >>>= h, u -= h, h = _ >>> 16 & 255, h === 0)
k[n++] = _ & 65535;
else if (h & 16) {
b = _ & 65535, h &= 15, h && (u < h && (c += S[a++] << u, u += 8), b += c & (1 << h) - 1, c >>>= h, u -= h), u < 15 && (c += S[a++] << u, u += 8, c += S[a++] << u, u += 8), _ = E[c & p];
i:
for (; ; ) {
if (h = _ >>> 24, c >>>= h, u -= h, h = _ >>> 16 & 255, h & 16) {
if (B = _ & 65535, h &= 15, u < h && (c += S[a++] << u, u += 8, u < h && (c += S[a++] << u, u += 8)), B += c & (1 << h) - 1, B > x) {
t.msg = "invalid distance too far back", y.mode = K;
break e;
}
if (c >>>= h, u -= h, h = n - s, B > h) {
if (h = B - h, h > f && y.sane) {
t.msg = "invalid distance too far back", y.mode = K;
break e;
}
if (d = 0, v = g, R === 0) {
if (d += r - h, h < b) {
b -= h;
do
k[n++] = g[d++];
while (--h);
d = n - B, v = k;
}
} else if (R < h) {
if (d += r + R - h, h -= R, h < b) {
b -= h;
do
k[n++] = g[d++];
while (--h);
if (d = 0, R < b) {
h = R, b -= h;
do
k[n++] = g[d++];
while (--h);
d = n - B, v = k;
}
}
} else if (d += R - h, h < b) {
b -= h;
do
k[n++] = g[d++];
while (--h);
d = n - B, v = k;
}
for (; b > 2; )
k[n++] = v[d++], k[n++] = v[d++], k[n++] = v[d++], b -= 3;
b && (k[n++] = v[d++], b > 1 && (k[n++] = v[d++]));
} else {
d = n - B;
do
k[n++] = k[d++], k[n++] = k[d++], k[n++] = k[d++], b -= 3;
while (b > 2);
b && (k[n++] = k[d++], b > 1 && (k[n++] = k[d++]));
}
} else if ((h & 64) === 0) {
_ = E[(_ & 65535) + (c & (1 << h) - 1)];
continue i;
} else {
t.msg = "invalid distance code", y.mode = K;
break e;
}
break;
}
} else if ((h & 64) === 0) {
_ = m[(_ & 65535) + (c & (1 << h) - 1)];
continue t;
} else if (h & 32) {
y.mode = Vt;
break e;
} else {
t.msg = "invalid literal/length code", y.mode = K;
break e;
}
break;
}
} while (a < o && n < l);
b = u >> 3, a -= b, u -= b << 3, c &= (1 << u) - 1, t.next_in = a, t.next_out = n, t.avail_in = a < o ? 5 + (o - a) : 5 - (a - o), t.avail_out = n < l ? 257 + (l - n) : 257 - (n - l), y.hold = c, y.bits = u;
};
const $ = 15, we = 852, be = 592, xe = 0, ie = 1, me = 2, Gt = new Uint16Array([
/* Length codes 257..285 base */
3,
4,
5,
6,
7,
8,
9,
10,
11,
13,
15,
17,
19,
23,
27,
31,
35,
43,
51,
59,
67,
83,
99,
115,
131,
163,
195,
227,
258,
0,
0
]), Kt = new Uint8Array([
/* Length codes 257..285 extra */
16,
16,
16,
16,
16,
16,
16,
16,
17,
17,
17,
17,
18,
18,
18,
18,
19,
19,
19,
19,
20,
20,
20,
20,
21,
21,
21,
21,
16,
72,
78
]), jt = new Uint16Array([
/* Distance codes 0..29 base */
1,
2,
3,
4,
5,
7,
9,
13,
17,
25,
33,
49,
65,
97,
129,
193,
257,
385,
513,
769,
1025,
1537,
2049,
3073,
4097,
6145,
8193,
12289,
16385,
24577,
0,
0
]), Wt = new Uint8Array([
/* Distance codes 0..29 extra */
16,
16,
16,
16,
17,
17,
18,
18,
19,
19,
20,
20,
21,
21,
22,
22,
23,
23,
24,
24,
25,
25,
26,
26,
27,
27,
28,
28,
29,
29,
64,
64
]), Xt = (i, t, e, a, o, n, s, l) => {
const x = l.bits;
let r = 0, f = 0, R = 0, g = 0, c = 0, u = 0, m = 0, E = 0, w = 0, p = 0, _, h, b, B, d, v = null, S;
const k = new Uint16Array($ + 1), y = new Uint16Array($ + 1);
let A = null, C, D, F;
for (r = 0; r <= $; r++)
k[r] = 0;
for (f = 0; f < a; f++)
k[t[e + f]]++;
for (c = x, g = $; g >= 1 && k[g] === 0; g--)
;
if (c > g && (c = g), g === 0)
return o[n++] = 1 << 24 | 64 << 16 | 0, o[n++] = 1 << 24 | 64 << 16 | 0, l.bits = 1, 0;
for (R = 1; R < g && k[R] === 0; R++)
;
for (c < R && (c = R), E = 1, r = 1; r <= $; r++)
if (E <<= 1, E -= k[r], E < 0)
return -1;
if (E > 0 && (i === xe || g !== 1))
return -1;
for (y[1] = 0, r = 1; r < $; r++)
y[r + 1] = y[r] + k[r];
for (f = 0; f < a; f++)
t[e + f] !== 0 && (s[y[t[e + f]]++] = f);
if (i === xe ? (v = A = s, S = 20) : i === ie ? (v = Gt, A = Kt, S = 257) : (v = jt, A = Wt, S = 0), p = 0, f = 0, r = R, d = n, u = c, m = 0, b = -1, w = 1 << c, B = w - 1, i === ie && w > we || i === me && w > be)
return 1;
for (; ; ) {
C = r - m, s[f] + 1 < S ? (D = 0, F = s[f]) : s[f] >= S ? (D = A[s[f] - S], F = v[s[f] - S]) : (D = 96, F = 0), _ = 1 << r - m, h = 1 << u, R = h;
do
h -= _, o[d + (p >> m) + h] = C << 24 | D << 16 | F | 0;
while (h !== 0);
for (_ = 1 << r - 1; p & _; )
_ >>= 1;
if (_ !== 0 ? (p &= _ - 1, p += _) : p = 0, f++, --k[r] === 0) {
if (r === g)
break;
r = t[e + s[f]];
}
if (r > c && (p & B) !== b) {
for (m === 0 && (m = c), d += R, u = r - m, E = 1 << u; u + m < g && (E -= k[u + m], !(E <= 0)); )
u++, E <<= 1;
if (w += 1 << u, i === ie && w > we || i === me && w > be)
return 1;
b = p & B, o[b] = c << 24 | u << 16 | d - n | 0;
}
}
return p !== 0 && (o[d + p] = r - m << 24 | 64 << 16 | 0), l.bits = c, 0;
};
var V = Xt;
const Yt = 0, Je = 1, qe = 2, {
Z_FINISH: _e,
Z_BLOCK: Qt,
Z_TREES: j,
Z_OK: M,
Z_STREAM_END: Jt,
Z_NEED_DICT: qt,
Z_STREAM_ERROR: U,
Z_DATA_ERROR: et,
Z_MEM_ERROR: tt,
Z_BUF_ERROR: ei,
Z_DEFLATED: ke
} = Xe, J = 16180, pe = 16181, ye = 16182, Ee = 16183, ve = 16184, Se = 16185, Re = 16186, Be = 16187, Te = 16188, Ae = 16189, Q = 16190, O = 16191, ne = 16192, Ue = 16193, ae = 16194, De = 16195, Ie = 16196, Oe = 16197, Ne = 16198, W = 16199, X = 16200, Ce = 16201, Fe = 16202, Me = 16203, Ze = 16204, $e = 16205, se = 16206, Le = 16207, ze = 16208, T = 16209, it = 16210, nt = 16211, ti = 852, ii = 592, ni = 15, ai = ni, He = (i) => (i >>> 24 & 255) + (i >>> 8 & 65280) + ((i & 65280) << 8) + ((i & 255) << 24);
function si() {
this.strm = null, this.mode = 0, this.last = !1, this.wrap = 0, this.havedict = !1, this.flags = 0, this.dmax = 0, this.check = 0, this.total = 0, this.head = null, this.wbits = 0, this.wsize = 0, this.whave = 0, this.wnext = 0, this.window = null, this.hold = 0, this.bits = 0, this.length = 0, this.offset = 0, this.extra = 0, this.lencode = null, this.distcode = null, this.lenbits = 0, this.distbits = 0, this.ncode = 0, this.nlen = 0, this.ndist = 0, this.have = 0, this.next = null, this.lens = new Uint16Array(320), this.work = new Uint16Array(288), this.lendyn = null, this.distdyn = null, this.sane = 0, this.back = 0, this.was = 0;
}
const Z = (i) => {
if (!i)
return 1;
const t = i.state;
return !t || t.strm !== i || t.mode < J || t.mode > nt ? 1 : 0;
}, at = (i) => {
if (Z(i))
return U;
const t = i.state;
return i.total_in = i.total_out = t.total = 0, i.msg = "", t.wrap && (i.adler = t.wrap & 1), t.mode = J, t.last = 0, t.havedict = 0, t.flags = -1, t.dmax = 32768, t.head = null, t.hold = 0, t.bits = 0, t.lencode = t.lendyn = new Int32Array(ti), t.distcode = t.distdyn = new Int32Array(ii), t.sane = 1, t.back = -1, M;
}, st = (i) => {
if (Z(i))
return U;
const t = i.state;
return t.wsize = 0, t.whave = 0, t.wnext = 0, at(i);
}, rt = (i, t) => {
let e;
if (Z(i))
return U;
const a = i.state;
return t < 0 ? (e = 0, t = -t) : (e = (t >> 4) + 5, t < 48 && (t &= 15)), t && (t < 8 || t > 15) ? U : (a.window !== null && a.wbits !== t && (a.window = null), a.wrap = e, a.wbits = t, st(i));
}, ot = (i, t) => {
if (!i)
return U;
const e = new si();
i.state = e, e.strm = i, e.window = null, e.mode = J;
const a = rt(i, t);
return a !== M && (i.state = null), a;
}, ri = (i) => ot(i, ai);
let Ve = !0, re, oe;
const oi = (i) => {
if (Ve) {
re = new Int32Array(512), oe = new Int32Array(32);
let t = 0;
for (; t < 144; )
i.lens[t++] = 8;
for (; t < 256; )
i.lens[t++] = 9;
for (; t < 280; )
i.lens[t++] = 7;
for (; t < 288; )
i.lens[t++] = 8;
for (V(Je, i.lens, 0, 288, re, 0, i.work, { bits: 9 }), t = 0; t < 32; )
i.lens[t++] = 5;
V(qe, i.lens, 0, 32, oe, 0, i.work, { bits: 5 }), Ve = !1;
}
i.lencode = re, i.lenbits = 9, i.distcode = oe, i.distbits = 5;
}, ft = (i, t, e, a) => {
let o;
const n = i.state;
return n.window === null && (n.wsize = 1 << n.wbits, n.wnext = 0, n.whave = 0, n.window = new Uint8Array(n.wsize)), a >= n.wsize ? (n.window.set(t.subarray(e - n.wsize, e), 0), n.wnext = 0, n.whave = n.wsize) : (o = n.wsize - n.wnext, o > a && (o = a), n.window.set(t.subarray(e - a, e - a + o), n.wnext), a -= o, a ? (n.window.set(t.subarray(e - a, e), 0), n.wnext = a, n.whave = n.wsize) : (n.wnext += o, n.wnext === n.wsize && (n.wnext = 0), n.whave < n.wsize && (n.whave += o))), 0;
}, fi = (i, t) => {
let e, a, o, n, s, l, x, r, f, R, g, c, u, m, E = 0, w, p, _, h, b, B, d, v;
const S = new Uint8Array(4);
let k, y;
const A = (
/* permutation of code lengths */
new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15])
);
if (Z(i) || !i.output || !i.input && i.avail_in !== 0)
return U;
e = i.state, e.mode === O && (e.mode = ne), s = i.next_out, o = i.output, x = i.avail_out, n = i.next_in, a = i.input, l = i.avail_in, r = e.hold, f = e.bits, R = l, g = x, v = M;
e:
for (; ; )
switch (e.mode) {
case J:
if (e.wrap === 0) {
e.mode = ne;
break;
}
for (; f < 16; ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
if (e.wrap & 2 && r === 35615) {
e.wbits === 0 && (e.wbits = 15), e.check = 0, S[0] = r & 255, S[1] = r >>> 8 & 255, e.check = I(e.check, S, 2, 0), r = 0, f = 0, e.mode = pe;
break;
}
if (e.head && (e.head.done = !1), !(e.wrap & 1) || /* check if zlib header allowed */
(((r & 255) << 8) + (r >> 8)) % 31) {
i.msg = "incorrect header check", e.mode = T;
break;
}
if ((r & 15) !== ke) {
i.msg = "unknown compression method", e.mode = T;
break;
}
if (r >>>= 4, f -= 4, d = (r & 15) + 8, e.wbits === 0 && (e.wbits = d), d > 15 || d > e.wbits) {
i.msg = "invalid window size", e.mode = T;
break;
}
e.dmax = 1 << e.wbits, e.flags = 0, i.adler = e.check = 1, e.mode = r & 512 ? Ae : O, r = 0, f = 0;
break;
case pe:
for (; f < 16; ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
if (e.flags = r, (e.flags & 255) !== ke) {
i.msg = "unknown compression method", e.mode = T;
break;
}
if (e.flags & 57344) {
i.msg = "unknown header flags set", e.mode = T;
break;
}
e.head && (e.head.text = r >> 8 & 1), e.flags & 512 && e.wrap & 4 && (S[0] = r & 255, S[1] = r >>> 8 & 255, e.check = I(e.check, S, 2, 0)), r = 0, f = 0, e.mode = ye;
/* falls through */
case ye:
for (; f < 32; ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
e.head && (e.head.time = r), e.flags & 512 && e.wrap & 4 && (S[0] = r & 255, S[1] = r >>> 8 & 255, S[2] = r >>> 16 & 255, S[3] = r >>> 24 & 255, e.check = I(e.check, S, 4, 0)), r = 0, f = 0, e.mode = Ee;
/* falls through */
case Ee:
for (; f < 16; ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
e.head && (e.head.xflags = r & 255, e.head.os = r >> 8), e.flags & 512 && e.wrap & 4 && (S[0] = r & 255, S[1] = r >>> 8 & 255, e.check = I(e.check, S, 2, 0)), r = 0, f = 0, e.mode = ve;
/* falls through */
case ve:
if (e.flags & 1024) {
for (; f < 16; ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
e.length = r, e.head && (e.head.extra_len = r), e.flags & 512 && e.wrap & 4 && (S[0] = r & 255, S[1] = r >>> 8 & 255, e.check = I(e.check, S, 2, 0)), r = 0, f = 0;
} else e.head && (e.head.extra = null);
e.mode = Se;
/* falls through */
case Se:
if (e.flags & 1024 && (c = e.length, c > l && (c = l), c && (e.head && (d = e.head.extra_len - e.length, e.head.extra || (e.head.extra = new Uint8Array(e.head.extra_len)), e.head.extra.set(
a.subarray(
n,
// extra field is limited to 65536 bytes
// - no need for additional size check
n + c
),
/*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/
d
)), e.flags & 512 && e.wrap & 4 && (e.check = I(e.check, a, c, n)), l -= c, n += c, e.length -= c), e.length))
break e;
e.length = 0, e.mode = Re;
/* falls through */
case Re:
if (e.flags & 2048) {
if (l === 0)
break e;
c = 0;
do
d = a[n + c++], e.head && d && e.length < 65536 && (e.head.name += String.fromCharCode(d));
while (d && c < l);
if (e.flags & 512 && e.wrap & 4 && (e.check = I(e.check, a, c, n)), l -= c, n += c, d)
break e;
} else e.head && (e.head.name = null);
e.length = 0, e.mode = Be;
/* falls through */
case Be:
if (e.flags & 4096) {
if (l === 0)
break e;
c = 0;
do
d = a[n + c++], e.head && d && e.length < 65536 && (e.head.comment += String.fromCharCode(d));
while (d && c < l);
if (e.flags & 512 && e.wrap & 4 && (e.check = I(e.check, a, c, n)), l -= c, n += c, d)
break e;
} else e.head && (e.head.comment = null);
e.mode = Te;
/* falls through */
case Te:
if (e.flags & 512) {
for (; f < 16; ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
if (e.wrap & 4 && r !== (e.check & 65535)) {
i.msg = "header crc mismatch", e.mode = T;
break;
}
r = 0, f = 0;
}
e.head && (e.head.hcrc = e.flags >> 9 & 1, e.head.done = !0), i.adler = e.check = 0, e.mode = O;
break;
case Ae:
for (; f < 32; ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
i.adler = e.check = He(r), r = 0, f = 0, e.mode = Q;
/* falls through */
case Q:
if (e.havedict === 0)
return i.next_out = s, i.avail_out = x, i.next_in = n, i.avail_in = l, e.hold = r, e.bits = f, qt;
i.adler = e.check = 1, e.mode = O;
/* falls through */
case O:
if (t === Qt || t === j)
break e;
/* falls through */
case ne:
if (e.last) {
r >>>= f & 7, f -= f & 7, e.mode = se;
break;
}
for (; f < 3; ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
switch (e.last = r & 1, r >>>= 1, f -= 1, r & 3) {
case 0:
e.mode = Ue;
break;
case 1:
if (oi(e), e.mode = W, t === j) {
r >>>= 2, f -= 2;
break e;
}
break;
case 2:
e.mode = Ie;
break;
case 3:
i.msg = "invalid block type", e.mode = T;
}
r >>>= 2, f -= 2;
break;
case Ue:
for (r >>>= f & 7, f -= f & 7; f < 32; ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
if ((r & 65535) !== (r >>> 16 ^ 65535)) {
i.msg = "invalid stored block lengths", e.mode = T;
break;
}
if (e.length = r & 65535, r = 0, f = 0, e.mode = ae, t === j)
break e;
/* falls through */
case ae:
e.mode = De;
/* falls through */
case De:
if (c = e.length, c) {
if (c > l && (c = l), c > x && (c = x), c === 0)
break e;
o.set(a.subarray(n, n + c), s), l -= c, n += c, x -= c, s += c, e.length -= c;
break;
}
e.mode = O;
break;
case Ie:
for (; f < 14; ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
if (e.nlen = (r & 31) + 257, r >>>= 5, f -= 5, e.ndist = (r & 31) + 1, r >>>= 5, f -= 5, e.ncode = (r & 15) + 4, r >>>= 4, f -= 4, e.nlen > 286 || e.ndist > 30) {
i.msg = "too many length or distance symbols", e.mode = T;
break;
}
e.have = 0, e.mode = Oe;
/* falls through */
case Oe:
for (; e.have < e.ncode; ) {
for (; f < 3; ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
e.lens[A[e.have++]] = r & 7, r >>>= 3, f -= 3;
}
for (; e.have < 19; )
e.lens[A[e.have++]] = 0;
if (e.lencode = e.lendyn, e.lenbits = 7, k = { bits: e.lenbits }, v = V(Yt, e.lens, 0, 19, e.lencode, 0, e.work, k), e.lenbits = k.bits, v) {
i.msg = "invalid code lengths set", e.mode = T;
break;
}
e.have = 0, e.mode = Ne;
/* falls through */
case Ne:
for (; e.have < e.nlen + e.ndist; ) {
for (; E = e.lencode[r & (1 << e.lenbits) - 1], w = E >>> 24, p = E >>> 16 & 255, _ = E & 65535, !(w <= f); ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
if (_ < 16)
r >>>= w, f -= w, e.lens[e.have++] = _;
else {
if (_ === 16) {
for (y = w + 2; f < y; ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
if (r >>>= w, f -= w, e.have === 0) {
i.msg = "invalid bit length repeat", e.mode = T;
break;
}
d = e.lens[e.have - 1], c = 3 + (r & 3), r >>>= 2, f -= 2;
} else if (_ === 17) {
for (y = w + 3; f < y; ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
r >>>= w, f -= w, d = 0, c = 3 + (r & 7), r >>>= 3, f -= 3;
} else {
for (y = w + 7; f < y; ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
r >>>= w, f -= w, d = 0, c = 11 + (r & 127), r >>>= 7, f -= 7;
}
if (e.have + c > e.nlen + e.ndist) {
i.msg = "invalid bit length repeat", e.mode = T;
break;
}
for (; c--; )
e.lens[e.have++] = d;
}
}
if (e.mode === T)
break;
if (e.lens[256] === 0) {
i.msg = "invalid code -- missing end-of-block", e.mode = T;
break;
}
if (e.lenbits = 9, k = { bits: e.lenbits }, v = V(Je, e.lens, 0, e.nlen, e.lencode, 0, e.work, k), e.lenbits = k.bits, v) {
i.msg = "invalid literal/lengths set", e.mode = T;
break;
}
if (e.distbits = 6, e.distcode = e.distdyn, k = { bits: e.distbits }, v = V(qe, e.lens, e.nlen, e.ndist, e.distcode, 0, e.work, k), e.distbits = k.bits, v) {
i.msg = "invalid distances set", e.mode = T;
break;
}
if (e.mode = W, t === j)
break e;
/* falls through */
case W:
e.mode = X;
/* falls through */
case X:
if (l >= 6 && x >= 258) {
i.next_out = s, i.avail_out = x, i.next_in = n, i.avail_in = l, e.hold = r, e.bits = f, Pt(i, g), s = i.next_out, o = i.output, x = i.avail_out, n = i.next_in, a = i.input, l = i.avail_in, r = e.hold, f = e.bits, e.mode === O && (e.back = -1);
break;
}
for (e.back = 0; E = e.lencode[r & (1 << e.lenbits) - 1], w = E >>> 24, p = E >>> 16 & 255, _ = E & 65535, !(w <= f); ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
if (p && (p & 240) === 0) {
for (h = w, b = p, B = _; E = e.lencode[B + ((r & (1 << h + b) - 1) >> h)], w = E >>> 24, p = E >>> 16 & 255, _ = E & 65535, !(h + w <= f); ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
r >>>= h, f -= h, e.back += h;
}
if (r >>>= w, f -= w, e.back += w, e.length = _, p === 0) {
e.mode = $e;
break;
}
if (p & 32) {
e.back = -1, e.mode = O;
break;
}
if (p & 64) {
i.msg = "invalid literal/length code", e.mode = T;
break;
}
e.extra = p & 15, e.mode = Ce;
/* falls through */
case Ce:
if (e.extra) {
for (y = e.extra; f < y; ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
e.length += r & (1 << e.extra) - 1, r >>>= e.extra, f -= e.extra, e.back += e.extra;
}
e.was = e.length, e.mode = Fe;
/* falls through */
case Fe:
for (; E = e.distcode[r & (1 << e.distbits) - 1], w = E >>> 24, p = E >>> 16 & 255, _ = E & 65535, !(w <= f); ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
if ((p & 240) === 0) {
for (h = w, b = p, B = _; E = e.distcode[B + ((r & (1 << h + b) - 1) >> h)], w = E >>> 24, p = E >>> 16 & 255, _ = E & 65535, !(h + w <= f); ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
r >>>= h, f -= h, e.back += h;
}
if (r >>>= w, f -= w, e.back += w, p & 64) {
i.msg = "invalid distance code", e.mode = T;
break;
}
e.offset = _, e.extra = p & 15, e.mode = Me;
/* falls through */
case Me:
if (e.extra) {
for (y = e.extra; f < y; ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
e.offset += r & (1 << e.extra) - 1, r >>>= e.extra, f -= e.extra, e.back += e.extra;
}
if (e.offset > e.dmax) {
i.msg = "invalid distance too far back", e.mode = T;
break;
}
e.mode = Ze;
/* falls through */
case Ze:
if (x === 0)
break e;
if (c = g - x, e.offset > c) {
if (c = e.offset - c, c > e.whave && e.sane) {
i.msg = "invalid distance too far back", e.mode = T;
break;
}
c > e.wnext ? (c -= e.wnext, u = e.wsize - c) : u = e.wnext - c, c > e.length && (c = e.length), m = e.window;
} else
m = o, u = s - e.offset, c = e.length;
c > x && (c = x), x -= c, e.length -= c;
do
o[s++] = m[u++];
while (--c);
e.length === 0 && (e.mode = X);
break;
case $e:
if (x === 0)
break e;
o[s++] = e.length, x--, e.mode = X;
break;
case se:
if (e.wrap) {
for (; f < 32; ) {
if (l === 0)
break e;
l--, r |= a[n++] << f, f += 8;
}
if (g -= x, i.total_out += g, e.total += g, e.wrap & 4 && g && (i.adler = e.check = /*UPDATE_CHECK(state.check, put - _out, _out);*/
e.flags ? I(e.check, o, g, s - g) : de(e.check, o, g, s - g)), g = x, e.wrap & 4 && (e.flags ? r : He(r)) !== e.check) {
i.msg = "incorrect data check", e.mode = T;
break;
}
r = 0, f = 0;
}
e.mode = Le;
/* falls through */
case Le:
if (e.wrap && e.flags) {
for (; f < 32; ) {
if (l === 0)
break e;
l--, r += a[n++] << f, f += 8;
}
if (e.wrap & 4 && r !== (e.total & 4294967295)) {
i.msg = "incorrect length check", e.mode = T;
break;
}
r = 0, f = 0;
}
e.mode = ze;
/* falls through */
case ze:
v = Jt;
break e;
case T:
v = et;
break e;
case it:
return tt;
case nt:
/* falls through */
default:
return U;
}
return i.next_out = s, i.avail_out = x, i.next_in = n, i.avail_in = l, e.hold = r, e.bits = f, (e.wsize || g !== i.avail_out && e.mode < T && (e.mode < se || t !== _e)) && ft(i, i.output, i.next_out, g - i.avail_out), R -= i.avail_in, g -= i.avail_out, i.total_in += R, i.total_out += g, e.total += g, e.wrap & 4 && g && (i.adler = e.check = /*UPDATE_CHECK(state.check, strm.next_out - _out, _out);*/
e.flags ? I(e.check, o, g, i.next_out - g) : de(e.check, o, g, i.next_out - g)), i.data_type = e.bits + (e.last ? 64 : 0) + (e.mode === O ? 128 : 0) + (e.mode === W || e.mode === ae ? 256 : 0), (R === 0 && g === 0 || t === _e) && v === M && (v = ei), v;
}, ci = (i) => {
if (Z(i))
return U;
let t = i.state;
return t.window && (t.window = null), i.state = null, M;
}, li = (i, t) => {
if (Z(i))
return U;
const e = i.state;
return (e.wrap & 2) === 0 ? U : (e.head = t, t.done = !1, M);
}, hi = (i, t) => {
const e = t.length;
let a, o, n;
return Z(i) || (a = i.state, a.wrap !== 0 && a.mode !== Q) ? U : a.mode === Q && (o = 1, o = de(o, t, e, 0), o !== a.check) ? et : (n = ft(i, t, e, e), n ? (a.mode = it, tt) : (a.havedict = 1, M));
};
var di = st, ui = rt, gi = at, wi = ri, bi = ot, xi = fi, mi = ci, _i = li, ki = hi, pi = "pako inflate (from Nodeca project)", N = {
inflateReset: di,
inflateReset2: ui,
inflateResetKeep: gi,
inflateInit: wi,
inflateInit2: bi,
inflate: xi,
inflateEnd: mi,
inflateGetHeader: _i,
inflateSetDictionary: ki,
inflateInfo: pi
};
function yi() {
this.text = 0, this.time = 0, this.xflags = 0, this.os = 0, this.extra = null, this.extra_len = 0, this.name = "", this.comment = "", this.hcrc = 0, this.done = !1;
}
var Ei = yi;
const ct = Object.prototype.toString, {
Z_NO_FLUSH: vi,
Z_FINISH: Si,
Z_OK: G,
Z_STREAM_END: fe,
Z_NEED_DICT: ce,
Z_STREAM_ERROR: Ri,
Z_DATA_ERROR: Pe,
Z_MEM_ERROR: Bi
} = Xe;
function q(i) {
this.options = Ye.assign({
chunkSize: 1024 * 64,
windowBits: 15,
to: ""
}, i || {});
const t = this.options;
t.raw && t.windowBits >= 0 && t.windowBits < 16 && (t.windowBits = -t.windowBits, t.windowBits === 0 && (t.windowBits = -15)), t.windowBits >= 0 && t.windowBits < 16 && !(i && i.windowBits) && (t.windowBits += 32), t.windowBits > 15 && t.windowBits < 48 && (t.windowBits & 15) === 0 && (t.windowBits |= 15), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Ht(), this.strm.avail_out = 0;
let e = N.inflateInit2(
this.strm,
t.windowBits
);
if (e !== G)
throw new Error(ue[e]);
if (this.header = new Ei(), N.inflateGetHeader(this.strm, this.header), t.dictionary && (typeof t.dictionary == "string" ? t.dictionary = ge.string2buf(t.dictionary) : ct.call(t.dictionary) === "[object ArrayBuffer]" && (t.dictionary = new Uint8Array(t.dictionary)), t.raw && (e = N.inflateSetDictionary(this.strm, t.dictionary), e !== G)))
throw new Error(ue[e]);
}
q.prototype.push = function(i, t) {
const e = this.strm, a = this.options.chunkSize, o = this.options.dictionary;
let n, s, l;
if (this.ended) return !1;
for (t === ~~t ? s = t : s = t === !0 ? Si : vi, ct.call(i) === "[object ArrayBuffer]" ? e.input = new Uint8Array(i) : e.input = i, e.next_in = 0, e.avail_in = e.input.length; ; ) {
for (e.avail_out === 0 && (e.output = new Uint8Array(a), e.next_out = 0, e.avail_out = a), n = N.inflate(e, s), n === ce && o && (n = N.inflateSetDictionary(e, o), n === G ? n = N.inflate(e, s) : n === Pe && (n = ce)); e.avail_in > 0 && n === fe && e.state.wrap > 0 && i[e.next_in] !== 0; )
N.inflateReset(e), n = N.inflate(e, s);
switch (n) {
case Ri:
case Pe:
case ce:
case Bi:
return this.onEnd(n), this.ended = !0, !1;
}
if (l = e.avail_out, e.next_out && (e.avail_out === 0 || n === fe))
if (this.options.to === "string") {
let x = ge.utf8border(e.output, e.next_out), r = e.next_out - x, f = ge.buf2string(e.output, x);
e.next_out = r, e.avail_out = a - r, r && e.output.set(e.output.subarray(x, x + r), 0), this.onData(f);
} else
this.onData(e.output.length === e.next_out ? e.output : e.output.subarray(0, e.next_out));
if (!(n === G && l === 0)) {
if (n === fe)
return n = N.inflateEnd(this.strm), this.onEnd(n), this.ended = !0, !0;
if (e.avail_in === 0) break;
}
}
return !0;
};
q.prototype.onData = function(i) {
this.chunks.push(i);
};
q.prototype.onEnd = function(i) {
i === G && (this.options.to === "string" ? this.result = this.chunks.join("") : this.result = Ye.flattenChunks(this.chunks)), this.chunks = [], this.err = i, this.msg = this.strm.msg;
};
function Ti(i, t) {
const e = new q(t);
if (e.push(i), e.err) throw e.msg || ue[e.err];
return e.result;
}
function Ai(i, t) {
return t = t || {}, t.raw = !0, Ti(i, t);
}
var Ui = Ai, Di = {
inflateRaw: Ui
};
const { inflateRaw: Ii } = Di;
var Oi = Ii;
function Ni(i) {
return Oi(i.subarray(2));
}
class Ci extends Error {
constructor(t) {
super(t), this.code = "ERR_ABORTED";
}
}
function Fi(i) {
i.sort((o, n) => o.offset - n.offset);
const t = [];
let e, a;
for (const o of i)
e && a && o.offset - a <= 2e3 ? (e.length = e.length + o.length - a + o.offset, e.blocks.push(o)) : t.push(e = {
blocks: [o],
length: o.length,
offset: o.offset
}), a = e.offset + e.length;
return t;
}
function Y(i) {
if (i && i.aborted)
if (typeof DOMException > "u") {
const t = new Ci("aborted");
throw t.code = "ERR_ABORTED", t;
} else
throw new DOMException("aborted", "AbortError");
}
const le = typeof TextDecoder < "u" ? new TextDecoder("utf8") : void 0;
function he(i, t, e, a) {
return i < a && t >= e;
}
class Mi {
constructor(t, e, a, o, n) {
if (this.bbi = t, this.refsByName = e, this.cirTreeOffset = a, this.isCompressed = o, this.blockType = n, this.featureCache = new gt({
cache: new wt({ maxSize: 1e3 }),
fill: async ({ length: s, offset: l }, x) => this.bbi.read(s, l, { signal: x })
}), !(a >= 0))
throw new Error("invalid cirTreeOffset!");
}
async readWigData(t, e, a, o, n) {
try {
const s = this.refsByName[t];
s === void 0 && o.complete();
const l = { chrId: s, start: e, end: a };
this.cirTreePromise || (this.cirTreePromise = this.bbi.read(48, this.cirTreeOffset, n));
const x = await this.cirTreePromise, f = new DataView(x.buffer).getUint32(4, !0);
let R = [], g = 0;
const c = (w, p, _) => {
try {
const b = w.subarray(p), B = new DataView(b.buffer, b.byteOffset, b.length);
let d = 0;
const v = B.getUint8(d);
d += 2;
const S = B.getUint16(d, !0);
if (d += 2, v === 1) {
const k = [];
for (let y = 0; y < S; y++) {
const A = B.getUint32(d, !0);
d += 4;
const C = B.getUint32(d, !0);
d += 4;
const D = B.getUint32(d, !0);
d += 4;
const F = B.getUint32(d, !0);
d += 4;
const ee = Number(B.getBigUint64(d, !0));
d += 8;
const te = Number(B.getBigUint64(d, !0));
d += 8, k.push({
startChrom: A,
startBase: C,
endBase: F,
endChrom: D,
blockOffset: ee,
blockSize: te,
offset: d
});
}
R = R.concat(k.filter((y) => u(y)).map((y) => ({
offset: y.blockOffset,
length: y.blockSize
})));
} else if (v === 0) {
const k = [];
for (let A = 0; A < S; A++) {
const C = B.getUint32(d, !0);
d += 4;
const D = B.getUint32(d, !0);
d += 4;
const F = B.getUint32(d, !0);
d += 4;
const ee = B.getUint32(d, !0);
d += 4;
const te = Number(B.getBigUint64(d, !0));
d += 8, k.push({
startChrom: C,
startBase: D,
endChrom: F,
endBase: ee,
blockOffset: te,
offset: d
});
}
const y = k.filter((A) => u(A)).map((A) => A.blockOffset);
y.length > 0 && E(y, _ + 1);
}
} catch (h) {
o.error(h);
}
}, u = (w) => {
const { startChrom: p, startBase: _, endChrom: h, endBase: b } = w;
return (p < s || p === s && _ <= a) && (h > s || h === s && b >= e);
}, m = async (w, p, _) => {
try {
const h = p.max - p.min, b = p.min, B = await this.featureCache.get(`${h}_${b}`, { length: h, offset: b }, n == null ? void 0 : n.signal);
for (const d of w)
p.contains(d) && (c(B, d - b, _), g -= 1, g === 0 && this.readFeatures(o, R, {
...n,
request: l
}).catch((v) => {
o.error(v);
}));
} catch (h) {
o.error(h);
}
}, E = (w, p) => {
try {
g += w.length;
const _ = 4 + f * 32;
let h = new z([
{
min: w[0],
max: w[0] + _
}
]);
for (let b = 1; b < w.length; b += 1) {
const B = new z([
{
min: w[b],
max: w[b] + _
}
]);
h = h.union(B);
}
h.getRanges().map((b) => m(w, b, p));
} catch (_) {
o.error(_);
}
};
E([Number(this.cirTreeOffset) + 48], 1);
return;
} catch (s) {
o.error(s);
}
}
parseSummaryBlock(t, e, a) {
const o = [];
let n = e;
const s = new DataView(t.buffer, t.byteOffset, t.length);
for (; n < t.byteLength; ) {
const l = s.getUint32(n, !0);
n += 4;
const x = s.getUint32(n, !0);
n += 4;
const r = s.getUint32(n, !0);
n += 4;
const f = s.getUint32(n, !0);
n += 4;
const R = s.getFloat32(n, !0);
n += 4;
const g = s.getFloat32(n, !0);
n += 4;
const c = s.getFloat32(n, !0);
n += 4, n += 4, (!a || l === a.chrId && he(x, r, a.start, a.end)) && o.push({
start: x,
end: r,
maxScore: g,
minScore: R,
summary: !0,
score: c / (f || 1)
});
}
return o;
}
parseBigBedBlock(t, e, a, o) {
const n = [];
let s = e;
const l = t, x = new DataView(l.buffer, l.byteOffset, l.length);
for (; s < t.byteLength; ) {
const r = s, f = x.getUint32(s, !0);
s += 4;
const R = x.getInt32(s, !0);
s += 4;
const g = x.getInt32(s, !0);
s += 4;
let c = s;
for (; c < t.length && t[c] !== 0; c++)
;
const u = t.subarray(s, c), m = (le == null ? void 0 : le.decode(u)) ?? u.toString();
s = c + 1, n.push({
chromId: f,
start: R,
end: g,
rest: m,
uniqueId: `bb-${a + r}`
});
}
return o ? n.filter((r) => he(r.start, r.end, o.start, o.end)) : n;
}
parseBigWigBlock(t, e, a) {
const o = t.subarray(e), n = new DataView(o.buffer, o.byteOffset, o.length);
let s = 0;
s += 4;
const l = n.getInt32(s, !0);
s += 8;
const x = n.getUint32(s, !0);
s += 4;
const r = n.getUint32(s, !0);
s += 4;
const f = n.getUint8(s);
s += 2;
const R = n.getUint16(s, !0);
s += 2;
const g = new Array(R);
switch (f) {
case 1: {
for (let c = 0; c < R; c++) {
const u = n.getInt32(s, !0);
s += 4;
const m = n.getInt32(s, !0);
s += 4;
const E = n.getFloat32(s, !0);
s += 4, g[c] = {
start: u,
end: m,
score: E
};
}
break;
}
case 2: {
for (let c = 0; c < R; c++) {
const u = n.getInt32(s, !0);
s += 4;
const m = n.getFloat32(s, !0);
s += 4, g[c] = {
score: m,
start: u,
end: u + r
};
}
break;
}
case 3: {
for (let c = 0; c < R; c++) {
const u = n.getFloat32(s, !0);
s += 4;
const m = l + c * x;
g[c] = {
score: u,
start: m,
end: m + r
};
}
break;
}
}
return a ? g.filter((c) => he(c.start, c.end, a.start, a.end)) : g;
}
async readFeatures(t, e, a = {}) {
try {
const { blockType: o, isCompressed: n } = this, { signal: s, request: l } = a, x = Fi(e);
Y(s), await Promise.all(x.map(async (r) => {
Y(s);
const { length: f, offset: R } = r, g = await this.featureCache.get(`${f}_${R}`, r, s);
for (const c of r.blocks) {
Y(s);
let u = g.subarray(Number(c.offset) - Number(r.offset));
switch (n && (u = Ni(u)), Y(s), o) {
case "summary": {
t.next(this.parseSummaryBlock(u, 0, l));
break;
}
case "bigwig": {
t.next(this.parseBigWigBlock(u, 0, l));
break;
}
case "bigbed": {
t.next(this.parseBigBedBlock(u, 0, Number(c.offset) * 256, l));
break;
}
default:
console.warn(`Don't know what to do with ${o}`);
}
}
})), t.complete();
} catch (o) {
t.error(o);
}
}
}
const Zi = -2003829722, Ge = -2021002517;
function L(i) {
return new DataView(i.buffer, i.byteOffset, i.length);
}
class Vi {
getHeader(t) {
return this.headerP || (this.headerP = this._getHeader(t).catch((e) => {
throw this.headerP = void 0, e;
})), this.headerP;
}
/*
* @param filehandle - a filehandle from generic-filehandle2
*
* @param path - a Local file path as a string
*
* @param url - a URL string
*
* @param renameRefSeqs - an optional method to rename the internal reference
* sequences using a mapping function
*/
constructor(t) {
const { filehandle: e, renameRefSeqs: a = (s) => s, path: o, url: n } = t;
if (this.renameRefSeqs = a, e)
this.bbi = e;
else if (n)
this.bbi = new lt(n);
else if (o)
this.bbi = new ht(o);
else
throw new Error("no file given");
}
async _getHeader(t) {
const e = await this._getMainHeader(t), a = await this._readChromTree(e, t);
return {
...e,
...a
};
}
async _getMainHeader(t, e = 2e3) {
const a = await this.bbi.read(e, 0, t), o = L(a), n = o.getInt32(0, !0);
if (n !== Zi && n !== Ge)
throw new Error("not a BigWig/BigBed file");
let s = 0;
const l = o.getInt32(s, !0);
s += 4;
const x = o.getUint16(s, !0);
s += 2;
const r = o.getUint16(s, !0);
s += 2;
const f = Number(o.getBigUint64(s, !0));
s += 8;
const R = Number(o.getBigUint64(s, !0));
s += 8;
const g = Number(o.getBigUint64(s, !0));
s += 8;
const c = o.getUint16(s, !0);
s += 2;
const u = o.getUint16(s, !0);
s += 2;
const m = Number(o.getBigUint64(s, !0));
s += 8;
const E = Number(o.getBigUint64(s, !0));
s += 8;
const w = o.getUint32(s, !0);
s += 4;
const p = Number(o.getBigUint64(s, !0));
s += 8;
const _ = [];
for (let d = 0; d < r;