@genome-spy/app 0.90.0 → 1.1.0

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.
@@ -0,0 +1,791 @@
1
+ import { n as e, r as t } from "./esm-Dndm-NaA.js";
2
+ import { n, r } from "./esm-VFJeyk9i.js";
3
+ import { t as i } from "./SharedReadCache-Ey5QIiPM.js";
4
+ //#region ../../node_modules/@gmod/tabix/esm/chunk.js
5
+ var a = class {
6
+ minv;
7
+ maxv;
8
+ bin;
9
+ endPosition;
10
+ constructor(e, t, n, r = t.blockPosition + 65536) {
11
+ this.minv = e, this.maxv = t, this.bin = n, this.endPosition = r;
12
+ }
13
+ toString() {
14
+ return `${this.minv.toString()}..${this.maxv.toString()} (bin ${this.bin}, fetchedSize ${this.fetchedSize()})`;
15
+ }
16
+ fetchedSize() {
17
+ return this.endPosition - this.minv.blockPosition;
18
+ }
19
+ };
20
+ //#endregion
21
+ //#region ../../node_modules/@gmod/tabix/node_modules/@jbrowse/quick-lru/esm/index.js
22
+ function o(e, t) {
23
+ if (!(t > 0)) throw TypeError(`\`${e}\` must be a number greater than 0`);
24
+ }
25
+ var s = class {
26
+ #e = /* @__PURE__ */ new Map();
27
+ #t = /* @__PURE__ */ new Map();
28
+ #n;
29
+ #r;
30
+ #i;
31
+ constructor(e) {
32
+ let t = e.maxAge ?? Infinity;
33
+ o("maxSize", e.maxSize), o("maxAge", t), this.#n = e.maxSize, this.#r = t, this.#i = e.onEviction;
34
+ }
35
+ #a(e) {
36
+ let t = this.#i;
37
+ if (t) for (let [n, r] of e) t(n, r.value);
38
+ }
39
+ #o(e, t) {
40
+ return t.expiry !== void 0 && t.expiry <= Date.now() && (this.#i?.(e, t.value), this.delete(e), !0);
41
+ }
42
+ #s(e, t) {
43
+ return this.#o(e, t) ? void 0 : t.value;
44
+ }
45
+ #c(e, t) {
46
+ if (this.#t.delete(e), this.#e.set(e, t), this.#e.size >= this.#n) {
47
+ let e = this.#t;
48
+ this.#t = this.#e, this.#e = /* @__PURE__ */ new Map(), this.#a(e);
49
+ }
50
+ }
51
+ #l(e) {
52
+ this.#t = new Map(e), this.#e = /* @__PURE__ */ new Map();
53
+ }
54
+ *#u() {
55
+ for (let e of [this.#t, this.#e]) for (let t of e) this.#o(...t) || (yield t);
56
+ }
57
+ get(e) {
58
+ let t = this.#e.get(e);
59
+ if (t) return this.#s(e, t);
60
+ let n = this.#t.get(e);
61
+ if (n && !this.#o(e, n)) return this.#c(e, n), n.value;
62
+ }
63
+ set(e, t, { maxAge: n = this.#r } = {}) {
64
+ let r = {
65
+ value: t,
66
+ expiry: n === Infinity ? void 0 : Date.now() + n
67
+ };
68
+ return this.#e.has(e) ? this.#e.set(e, r) : this.#c(e, r), this;
69
+ }
70
+ has(e) {
71
+ let t = this.#e.get(e) ?? this.#t.get(e);
72
+ return t !== void 0 && !this.#o(e, t);
73
+ }
74
+ peek(e) {
75
+ let t = this.#e.get(e) ?? this.#t.get(e);
76
+ return t ? this.#s(e, t) : void 0;
77
+ }
78
+ expiresIn(e) {
79
+ let t = this.#e.get(e) ?? this.#t.get(e);
80
+ if (t) return t.expiry === void 0 ? Infinity : t.expiry - Date.now();
81
+ }
82
+ delete(e) {
83
+ return this.#e.delete(e) || this.#t.delete(e);
84
+ }
85
+ clear() {
86
+ this.#e.clear(), this.#t.clear();
87
+ }
88
+ resize(e) {
89
+ o("maxSize", e);
90
+ let t = [...this.#u()], n = t.length - e;
91
+ n < 0 ? (this.#e = new Map(t), this.#t = /* @__PURE__ */ new Map()) : (this.#a(t.slice(0, n)), this.#l(t.slice(n))), this.#n = e;
92
+ }
93
+ evict(e = 1) {
94
+ if (!(e > 0)) return;
95
+ let t = [...this.#u()], n = Math.trunc(Math.min(e, t.length - 1));
96
+ n > 0 && (this.#a(t.slice(0, n)), this.#l(t.slice(n)));
97
+ }
98
+ get size() {
99
+ return Math.min(this.#e.size + this.#t.size, this.#n);
100
+ }
101
+ get maxSize() {
102
+ return this.#n;
103
+ }
104
+ get maxAge() {
105
+ return this.#r;
106
+ }
107
+ *entriesAscending() {
108
+ for (let [e, t] of this.#u()) yield [e, t.value];
109
+ }
110
+ *entriesDescending() {
111
+ for (let e of [this.#e, this.#t]) for (let [t, n] of [...e].reverse()) this.#o(t, n) || (yield [t, n.value]);
112
+ }
113
+ entries() {
114
+ return this.entriesAscending();
115
+ }
116
+ [Symbol.iterator]() {
117
+ return this.entriesAscending();
118
+ }
119
+ *keys() {
120
+ for (let [e] of this) yield e;
121
+ }
122
+ *values() {
123
+ for (let [, e] of this) yield e;
124
+ }
125
+ forEach(e, t = this) {
126
+ for (let [n, r] of this) e.call(t, r, n, this);
127
+ }
128
+ get [Symbol.toStringTag]() {
129
+ return "QuickLRU";
130
+ }
131
+ toString() {
132
+ return `QuickLRU(${this.size}/${this.maxSize})`;
133
+ }
134
+ [Symbol.for("nodejs.util.inspect.custom")]() {
135
+ return this.toString();
136
+ }
137
+ }, c = 2 ** 32;
138
+ function l(e, t = 0) {
139
+ let n = e[t] | e[t + 1] << 8 | e[t + 2] << 16 | e[t + 3] << 24;
140
+ return ((e[t + 4] | e[t + 5] << 8 | e[t + 6] << 16 | e[t + 7] << 24) >>> 0) * c + (n >>> 0);
141
+ }
142
+ //#endregion
143
+ //#region ../../node_modules/@gmod/tabix/esm/virtualOffset.js
144
+ var u = class {
145
+ blockPosition;
146
+ dataPosition;
147
+ constructor(e, t) {
148
+ this.blockPosition = e, this.dataPosition = t;
149
+ }
150
+ toString() {
151
+ return `${this.blockPosition}:${this.dataPosition}`;
152
+ }
153
+ compareTo(e) {
154
+ return this.blockPosition - e.blockPosition || this.dataPosition - e.dataPosition;
155
+ }
156
+ };
157
+ function d(e, t = 0) {
158
+ return new u(e[t + 7] * 1099511627776 + e[t + 6] * 4294967296 + e[t + 5] * 16777216 + e[t + 4] * 65536 + e[t + 3] * 256 + e[t + 2], e[t + 1] << 8 | e[t]);
159
+ }
160
+ //#endregion
161
+ //#region ../../node_modules/@gmod/tabix/esm/util.js
162
+ function f(e, t) {
163
+ let n = e.length;
164
+ if (n === 0) return e;
165
+ let r;
166
+ if (t) {
167
+ let i = t.blockPosition, a = t.dataPosition;
168
+ r = [];
169
+ for (let t = 0; t < n; t++) {
170
+ let n = e[t];
171
+ (n.maxv.blockPosition - i || n.maxv.dataPosition - a) > 0 && r.push(n);
172
+ }
173
+ if (r.length === 0) return r;
174
+ } else r = e;
175
+ r.sort((e, t) => {
176
+ let n = e.minv.blockPosition - t.minv.blockPosition;
177
+ return n === 0 ? e.minv.dataPosition - t.minv.dataPosition : n;
178
+ });
179
+ let i = [r[0]], o = r[0].minv.blockPosition, s = r[0].maxv.blockPosition;
180
+ for (let e = 1; e < r.length; e++) {
181
+ let t = r[e], n = t.minv.blockPosition, c = t.maxv.blockPosition;
182
+ if (n - s < 65e3 && c - o < 5e6) {
183
+ let e = i.at(-1);
184
+ (c - s || t.maxv.dataPosition - e.maxv.dataPosition) > 0 && (i[i.length - 1] = new a(e.minv, t.maxv, e.bin, t.endPosition), s = c);
185
+ } else i.push(t), o = n, s = c;
186
+ }
187
+ return p(i);
188
+ }
189
+ function p(e) {
190
+ let t = [e[0]];
191
+ for (let n = 1; n < e.length; n++) {
192
+ let r = e[n], i = t.at(-1).maxv;
193
+ if ((r.minv.blockPosition - i.blockPosition || r.minv.dataPosition - i.dataPosition) >= 0) {
194
+ t.push(r);
195
+ continue;
196
+ }
197
+ (r.maxv.blockPosition - i.blockPosition || r.maxv.dataPosition - i.dataPosition) > 0 && t.push(new a(i, r.maxv, r.bin, r.endPosition));
198
+ }
199
+ return t;
200
+ }
201
+ function m(e, t = []) {
202
+ let n = [...t];
203
+ for (let t of e) n.push(t.minv.blockPosition, t.maxv.blockPosition);
204
+ n.sort((e, t) => e - t);
205
+ for (let t of e) {
206
+ let e = t.maxv.blockPosition, r = 0, i = n.length;
207
+ for (; r < i;) {
208
+ let t = r + i >>> 1;
209
+ n[t] > e ? i = t : r = t + 1;
210
+ }
211
+ r < n.length && (t.endPosition = Math.min(t.endPosition, n[r]));
212
+ }
213
+ }
214
+ function h(e, t, n, r) {
215
+ let i = r ? r.blockPosition : Infinity, a = r ? r.dataPosition : 0, o = !1;
216
+ for (let r = 0; r < n; r++) {
217
+ let n = t + r * 8, s = e[n + 7] * 1099511627776 + e[n + 6] * 4294967296 + e[n + 5] * 16777216 + e[n + 4] * 65536 + e[n + 3] * 256 + e[n + 2], c = e[n + 1] << 8 | e[n];
218
+ (s < i || s === i && c < a) && (i = s, a = c, o = !0);
219
+ }
220
+ return o ? new u(i, a) : r;
221
+ }
222
+ function g(e) {
223
+ let t = new TextDecoder("utf-8"), n = [], r = {}, i = 0, a = 0;
224
+ for (; a < e.length;) {
225
+ let o = e.indexOf(0, a);
226
+ if (o === -1) break;
227
+ if (o > a) {
228
+ let s = t.decode(e.subarray(a, o));
229
+ n[i] = s, r[s] = i;
230
+ }
231
+ a = o + 1, i++;
232
+ }
233
+ return {
234
+ refNameToId: r,
235
+ refIdToName: n
236
+ };
237
+ }
238
+ var _ = {
239
+ 0: "generic",
240
+ 1: "SAM",
241
+ 2: "VCF",
242
+ 3: "GAF"
243
+ };
244
+ function v(e, t) {
245
+ let n = new DataView(e.buffer, e.byteOffset, e.byteLength), r = n.getInt32(t, !0), i = r & 65536 ? "zero-based-half-open" : "1-based-closed", a = _[r & 15];
246
+ if (!a) throw Error(`invalid Tabix preset format flags ${r}`);
247
+ let o = {
248
+ ref: n.getInt32(t + 4, !0),
249
+ start: n.getInt32(t + 8, !0),
250
+ end: n.getInt32(t + 12, !0)
251
+ }, s = n.getInt32(t + 16, !0), c = s ? String.fromCharCode(s) : void 0, l = n.getInt32(t + 20, !0), u = n.getInt32(t + 24, !0), { refIdToName: d, refNameToId: f } = g(e.subarray(t + 28, t + 28 + u));
252
+ return {
253
+ refIdToName: d,
254
+ refNameToId: f,
255
+ skipLines: l,
256
+ metaChar: c,
257
+ columnNumbers: o,
258
+ format: a,
259
+ coordinateType: i
260
+ };
261
+ }
262
+ function y(e, t) {
263
+ return { lineCount: l(e, t) };
264
+ }
265
+ function b(e, t = 5) {
266
+ let n = new s({ maxSize: t });
267
+ return (t) => {
268
+ let r = n.get(t);
269
+ if (r !== void 0) return r;
270
+ let i = e(t);
271
+ return i !== void 0 && n.set(t, i), i;
272
+ };
273
+ }
274
+ //#endregion
275
+ //#region ../../node_modules/@gmod/tabix/esm/indexFile.js
276
+ function x(e, t, n, r) {
277
+ if (t > 2 ** (n + r * 3)) return;
278
+ let i = (8 ** (r + 1) - 1) / 7, a = (8 ** r - 1) / 7 + Math.floor((t - 1) / 2 ** n) + 1;
279
+ for (a >= i && (a = 0);;) {
280
+ for (; a % 8 == 1;) a = (a - 1) / 8;
281
+ if (a === 0) return;
282
+ let t = e[a];
283
+ if (t?.length) {
284
+ let e = t[0].minv;
285
+ for (let n = 1; n < t.length; n++) {
286
+ let r = t[n].minv;
287
+ r.compareTo(e) < 0 && (e = r);
288
+ }
289
+ return e;
290
+ }
291
+ a++;
292
+ }
293
+ }
294
+ function S(e, t) {
295
+ return e.format === "GAF" ? 0 : e.refNameToId[t];
296
+ }
297
+ var C = class {
298
+ filehandle;
299
+ parseCache = new i({});
300
+ constructor({ filehandle: e }) {
301
+ this.filehandle = e;
302
+ }
303
+ async readIndexBytes(t) {
304
+ let n = await this.filehandle.readFile({
305
+ signal: t.signal,
306
+ onProgress: t.onProgress
307
+ }), r = await e(n);
308
+ return {
309
+ bytes: r,
310
+ dataView: new DataView(r.buffer, r.byteOffset, r.byteLength)
311
+ };
312
+ }
313
+ async lineCount(e, t = {}) {
314
+ let n = await this.parse(t), r = S(n, e);
315
+ return r === void 0 ? -1 : n.indices(r)?.stats?.lineCount ?? -1;
316
+ }
317
+ async getMetadata(e = {}) {
318
+ let { indices: t, ...n } = await this.parse(e);
319
+ return n;
320
+ }
321
+ async blocksForRange(e, t, n, r = {}) {
322
+ let i = await this.parse(r), a = S(i, e);
323
+ if (a === void 0) return [];
324
+ let o = i.indices(a);
325
+ if (!o) return [];
326
+ i.format === "GAF" && (t = Math.max(t - 1, 0));
327
+ let s = [];
328
+ for (let [e, r] of this.reg2bins(t, n, i)) for (let t = e; t <= r; t++) {
329
+ let e = o.binIndex[t];
330
+ if (e) for (let t of e) s.push(t);
331
+ }
332
+ let c = f(s, this.lowestOffset(o, t, i)), l = x(o.binIndex, n, i.minShift, i.depth);
333
+ if (l) {
334
+ let e = c.length;
335
+ for (; e > 0 && c[e - 1].minv.compareTo(l) >= 0;) e--;
336
+ c.length = e;
337
+ }
338
+ return c;
339
+ }
340
+ parse(e = {}) {
341
+ return this.parseCache.get("index", e.signal, (t) => this._parse({
342
+ ...e,
343
+ signal: t
344
+ }));
345
+ }
346
+ async hasRefSeq(e, t = {}) {
347
+ return !!(await this.parse(t)).indices(e)?.binIndex;
348
+ }
349
+ }, w = 21582659, T = 38359875;
350
+ function E(e, t) {
351
+ return e * 2 ** t;
352
+ }
353
+ function D(e, t) {
354
+ return Math.floor(e / 2 ** t);
355
+ }
356
+ var O = class extends C {
357
+ async _parse(e = {}) {
358
+ let { bytes: t, dataView: n } = await this.readIndexBytes(e), r = n.getUint32(0, !0), i;
359
+ if (r === w) i = 1;
360
+ else if (r === T) i = 2;
361
+ else throw Error(`Not a CSI file (magic=${r})`);
362
+ let o = n.getInt32(4, !0), s = n.getInt32(8, !0), c = (8 ** (s + 1) - 1) / 7, l = 2 ** (o + s * 3), u = n.getInt32(12, !0), f = u >= 28 && (n.getInt32(16, !0) & 15) == 3, p = u >= 30 || f ? v(t, 16) : {
363
+ refIdToName: [],
364
+ refNameToId: {},
365
+ metaChar: void 0,
366
+ columnNumbers: {
367
+ ref: 0,
368
+ start: 1,
369
+ end: 2
370
+ },
371
+ coordinateType: "zero-based-half-open",
372
+ format: "generic"
373
+ }, g = n.getInt32(16 + u, !0), _ = 16 + u + 4, x, S = [];
374
+ for (let e = 0; e < g; e++) {
375
+ S.push(_);
376
+ let e = n.getInt32(_, !0);
377
+ _ += 4;
378
+ for (let r = 0; r < e; r++) {
379
+ let e = n.getUint32(_, !0);
380
+ if (_ += 4, e > c) _ += 44;
381
+ else {
382
+ x = h(t, _, 1, x), _ += 8;
383
+ let e = n.getInt32(_, !0);
384
+ _ += 4 + 16 * e;
385
+ }
386
+ }
387
+ }
388
+ function C(e) {
389
+ let r = S[e];
390
+ if (r === void 0) return;
391
+ let i = r, o = n.getInt32(i, !0);
392
+ i += 4;
393
+ let s = {}, l = {}, u;
394
+ for (let e = 0; e < o; e++) {
395
+ let e = n.getUint32(i, !0);
396
+ if (i += 4, e > c) u = y(t, i + 28), i += 44;
397
+ else {
398
+ l[e] = d(t, i), i += 8;
399
+ let r = n.getInt32(i, !0);
400
+ i += 4;
401
+ let o = Array.from({ length: r });
402
+ for (let n = 0; n < r; n++) o[n] = new a(d(t, i), d(t, i + 8), e), i += 16;
403
+ s[e] = o;
404
+ }
405
+ }
406
+ return m(Object.values(s).flat()), {
407
+ binIndex: s,
408
+ loffsets: l,
409
+ stats: u
410
+ };
411
+ }
412
+ return {
413
+ ...p,
414
+ csi: !0,
415
+ refCount: g,
416
+ maxBlockSize: 65536,
417
+ firstDataLine: x,
418
+ csiVersion: i,
419
+ indices: b(C),
420
+ minShift: o,
421
+ depth: s,
422
+ maxBinNumber: c,
423
+ maxRefLength: l
424
+ };
425
+ }
426
+ lowestOffset(e, t, { minShift: n, depth: r }) {
427
+ let { loffsets: i } = e, a;
428
+ if (i) {
429
+ let e = (E(1, 3 * r) - 1) / 7 + D(Math.max(t, 0), n);
430
+ for (; a === void 0 && e > 0;) if (a = i[e], a === void 0) {
431
+ let t = Math.floor((e - 1) / 8), n = t * 8 + 1;
432
+ e = e > n ? e - 1 : t;
433
+ }
434
+ a ??= i[0];
435
+ }
436
+ return a;
437
+ }
438
+ reg2bins(e, t, { minShift: n, depth: r, maxBinNumber: i }) {
439
+ e = Math.max(e, 0);
440
+ let a = 2 ** (n + r * 3);
441
+ t > a && (t = a), --t;
442
+ let o = 0, s = 0, c = n + r * 3, l = [];
443
+ for (; o <= r; c -= 3, s += E(1, o * 3), o += 1) {
444
+ let a = s + D(e, c), o = s + D(t, c);
445
+ if (o - a + l.length > i) throw Error(`query ${e}-${t} is too large for current binning scheme (shift ${n}, depth ${r}), try a smaller query or a coarser index binning scheme`);
446
+ l.push([a, o]);
447
+ }
448
+ return l;
449
+ }
450
+ }, k = 21578324, A = 5, j = 14, M = 2 ** 29;
451
+ function N(e) {
452
+ return Math.min(Math.max(e, 0), M);
453
+ }
454
+ var P = class extends C {
455
+ reg2bins(e, t) {
456
+ e > M && console.warn("querying outside of possible tabix range");
457
+ let n = N(e), r = Math.min(t, M) - 1, i = [];
458
+ return n <= r && i.push([0, 0], [1 + (n >> 26), 1 + (r >> 26)], [9 + (n >> 23), 9 + (r >> 23)], [73 + (n >> 20), 73 + (r >> 20)], [585 + (n >> 17), 585 + (r >> 17)], [4681 + (n >> 14), 4681 + (r >> 14)]), i;
459
+ }
460
+ lowestOffset(e, t) {
461
+ let n = e.linearIndex;
462
+ return n?.[Math.min(N(t) >> j, n.length - 1)];
463
+ }
464
+ async _parse(e = {}) {
465
+ let { bytes: t, dataView: n } = await this.readIndexBytes(e);
466
+ if (n.getUint32(0, !0) !== k) throw Error("Not a TBI file");
467
+ let r = n.getUint32(4, !0), { refNameToId: i, refIdToName: o, coordinateType: s, format: c, columnNumbers: l, metaChar: u, skipLines: f } = v(t, 8), p = 36 + n.getInt32(32, !0), g, _ = [];
468
+ for (let e = 0; e < r; e++) {
469
+ _.push(p);
470
+ let e = n.getInt32(p, !0);
471
+ p += 4;
472
+ for (let t = 0; t < e; t++) {
473
+ let e = n.getUint32(p, !0);
474
+ p += 4;
475
+ let t = n.getInt32(p, !0);
476
+ if (p += 4, e > 37450) throw Error("tabix index contains too many bins, please use a CSI index");
477
+ p += 16 * t;
478
+ }
479
+ let r = n.getInt32(p, !0);
480
+ p += 4, g = h(t, p, r, g), p += 8 * r;
481
+ }
482
+ function x(e) {
483
+ let r = _[e];
484
+ if (r === void 0) return;
485
+ let i = r, o = n.getInt32(i, !0);
486
+ i += 4;
487
+ let s = {}, c;
488
+ for (let e = 0; e < o; e++) {
489
+ let e = n.getUint32(i, !0);
490
+ if (i += 4, e > 37450) throw Error("tabix index contains too many bins, please use a CSI index");
491
+ if (e === 37450) {
492
+ let e = n.getInt32(i, !0);
493
+ i += 4, e === 2 && (c = y(t, i + 16)), i += 16 * e;
494
+ } else {
495
+ let r = n.getInt32(i, !0);
496
+ i += 4;
497
+ let o = Array.from({ length: r });
498
+ for (let n = 0; n < r; n++) o[n] = new a(d(t, i), d(t, i + 8), e), i += 16;
499
+ s[e] = o;
500
+ }
501
+ }
502
+ let l = n.getInt32(i, !0);
503
+ i += 4;
504
+ let u = Array.from({ length: l });
505
+ for (let e = 0; e < l; e++) u[e] = d(t, i), i += 8;
506
+ return m(Object.values(s).flat(), u.map((e) => e.blockPosition)), {
507
+ binIndex: s,
508
+ linearIndex: u,
509
+ stats: c
510
+ };
511
+ }
512
+ return {
513
+ indices: b(x),
514
+ metaChar: u,
515
+ minShift: j,
516
+ depth: A,
517
+ maxBinNumber: 37449,
518
+ maxRefLength: M,
519
+ skipLines: f,
520
+ firstDataLine: g,
521
+ columnNumbers: l,
522
+ coordinateType: s,
523
+ format: c,
524
+ refIdToName: o,
525
+ refNameToId: i,
526
+ maxBlockSize: 65536
527
+ };
528
+ }
529
+ }, F = 9, I = 10, L = 13, R = 59, z = 60, B = 62, V = 6, H = 1024 * 2 ** 20, U = 18e4;
530
+ function W(e, t, i) {
531
+ if (e) return e;
532
+ if (t) return new n(t);
533
+ if (i) return new r(i);
534
+ throw TypeError("must provide either filehandle, path, or url");
535
+ }
536
+ function G({ tbiFilehandle: e, csiFilehandle: t, tbiPath: i, csiPath: a, tbiUrl: o, csiUrl: s, path: c, url: l }) {
537
+ if (e) return new P({ filehandle: e });
538
+ if (t) return new O({ filehandle: t });
539
+ if (i) return new P({ filehandle: new n(i) });
540
+ if (a) return new O({ filehandle: new n(a) });
541
+ if (s) return new O({ filehandle: new r(s) });
542
+ if (o) return new P({ filehandle: new r(o) });
543
+ if (c) return new P({ filehandle: new n(`${c}.tbi`) });
544
+ if (l) return new P({ filehandle: new r(`${l}.tbi`) });
545
+ throw TypeError("must provide one of tbiFilehandle, tbiPath, csiFilehandle, csiPath, tbiUrl, csiUrl");
546
+ }
547
+ function K(e, t, n, r, i) {
548
+ return e[n] * 256 + (r - t[n]) + i + 1;
549
+ }
550
+ function q(e, t, n, r, i, a) {
551
+ let o = t + (r - n);
552
+ if (e[i] === 46) return o;
553
+ let s = i;
554
+ for (let n = i; n <= a; n++) if (n === a || e[n] === R) {
555
+ let r = n - s;
556
+ if (r >= 10 && e[s] === 83 && e[s + 1] === 86 && e[s + 2] === 84 && e[s + 3] === 89 && e[s + 4] === 80 && e[s + 5] === 69 && e[s + 6] === 61 && e[s + 7] === 84 && e[s + 8] === 82 && e[s + 9] === 65) return t + 1;
557
+ r >= 4 && e[s] === 69 && e[s + 1] === 78 && e[s + 2] === 68 && e[s + 3] === 61 && (o = Z(e, s + 4, n)), s = n + 1;
558
+ }
559
+ return o;
560
+ }
561
+ var J = new TextDecoder();
562
+ function Y(e, t) {
563
+ let n = -1, r = t.charCodeAt(0);
564
+ for (let t = 0, i = e.length; t < i; t++) {
565
+ let i = e[t];
566
+ if (t === n + 1 && i !== r) break;
567
+ i === I && (n = t);
568
+ }
569
+ return e.subarray(0, n + 1);
570
+ }
571
+ function X(e, t) {
572
+ let n = 0;
573
+ for (let r = 0; r < t; r++) {
574
+ let t = e.indexOf(I, n);
575
+ if (t === -1) {
576
+ n = e.length;
577
+ break;
578
+ }
579
+ n = t + 1;
580
+ }
581
+ return J.decode(e.subarray(0, n)).split(/\r?\n/).slice(0, t);
582
+ }
583
+ function Z(e, t, n) {
584
+ let r = 0;
585
+ for (let i = t; i < n; i++) {
586
+ let t = e[i];
587
+ if (t >= 48 && t <= 57) r = r * 10 + (t - 48);
588
+ else break;
589
+ }
590
+ return r;
591
+ }
592
+ function Q(e, t, n, r, { start: i, end: a, pathCol: o, metaCharCode: s, decoder: c, callback: l }) {
593
+ let u = 0, d = 0;
594
+ for (; u < e.length;) {
595
+ let f = e.indexOf(I, u);
596
+ if (f === -1) break;
597
+ let p = u;
598
+ u = f + 1;
599
+ let m = p + r;
600
+ for (; d < n.length && m >= n[d];) d++;
601
+ if (e[p] === s) continue;
602
+ let h = p;
603
+ for (let t = 1; t < o; t++) {
604
+ let t = e.indexOf(F, h);
605
+ if (t === -1 || t >= f) {
606
+ h = f;
607
+ break;
608
+ }
609
+ h = t + 1;
610
+ }
611
+ let g = e[h];
612
+ if (g !== B && g !== z) continue;
613
+ let _ = e.indexOf(F, h);
614
+ (_ === -1 || _ > f) && (_ = f);
615
+ let v = Infinity, y = -1, b = h;
616
+ for (; b < _;) {
617
+ let t = 0, n = b + 1;
618
+ for (; n < _; n++) {
619
+ let r = e[n] - 48;
620
+ if (r < 0 || r > 9) break;
621
+ t = t * 10 + r;
622
+ }
623
+ t < v && (v = t), t > y && (y = t), b = n;
624
+ }
625
+ if (v >= a) return !0;
626
+ if (y >= i) {
627
+ let i = e[f - 1] === L ? f - 1 : f;
628
+ l(c.decode(e.subarray(p, i)), K(t, n, d, p, r), v, y + 1);
629
+ }
630
+ }
631
+ return !1;
632
+ }
633
+ var $ = class {
634
+ filehandle;
635
+ index;
636
+ chunkCache;
637
+ headerCache = new i({});
638
+ bgzfWorkerPool;
639
+ constructor({ path: e, filehandle: t, url: n, tbiPath: r, tbiUrl: a, tbiFilehandle: o, csiPath: s, csiUrl: c, csiFilehandle: l, chunkCacheSize: u = H, chunkCacheIdleTimeoutMs: d = U, chunkCacheBudget: f, bgzfWorkerPool: p }) {
640
+ this.bgzfWorkerPool = p, this.filehandle = W(t, e, n), this.index = G({
641
+ tbiFilehandle: o,
642
+ csiFilehandle: l,
643
+ tbiPath: r,
644
+ csiPath: s,
645
+ tbiUrl: a,
646
+ csiUrl: c,
647
+ path: e,
648
+ url: n
649
+ }), this.chunkCache = new i({
650
+ maxSize: u,
651
+ sizeOf: (e) => e.buffer.byteLength,
652
+ cacheKey: (e) => e.toString(),
653
+ idleTimeoutMs: d,
654
+ budget: f,
655
+ fill: (e, t) => this.readChunk(e, { signal: t })
656
+ });
657
+ }
658
+ clearChunkCache() {
659
+ this.chunkCache.clear();
660
+ }
661
+ async bytesForRegions(e, t = {}) {
662
+ let n = [];
663
+ for (let { refName: r, start: i, end: a } of e) {
664
+ let e = await this.index.blocksForRange(r, i, a, t);
665
+ for (let t of e) n.push(t);
666
+ }
667
+ let r = 0;
668
+ for (let e of f(n)) r += e.fetchedSize();
669
+ return r;
670
+ }
671
+ async getLines(e, t, n, r) {
672
+ let i, a = {}, o, s;
673
+ typeof r == "function" ? o = r : (a = r, o = r.lineCallback, i = r.signal, s = r.onProgress);
674
+ let c = await this.index.getMetadata(a), l = t ?? 0, u = n ?? c.maxRefLength;
675
+ if (l > u) throw TypeError("invalid start and end coordinates. start must be less than or equal to end");
676
+ if (l === u) return;
677
+ let d = await this.index.blocksForRange(e, l, u, a), f = c.format === "VCF", p = c.columnNumbers.ref || 0, m = c.columnNumbers.start || 0, h = f ? 8 : c.columnNumbers.end || 0, g = Math.max(p, m, h), _ = c.metaChar?.charCodeAt(0), v = c.coordinateType === "1-based-closed" ? -1 : 0, y = new TextEncoder(), b = new TextDecoder(), x = y.encode(e), S = new Int32Array(g + 1), C = c.format === "GAF" ? {
678
+ start: l,
679
+ end: u,
680
+ pathCol: m,
681
+ metaCharCode: _,
682
+ decoder: b,
683
+ callback: o
684
+ } : void 0, w = 0;
685
+ for (let e of d) w += e.fetchedSize();
686
+ let T = 0;
687
+ s?.(0, w);
688
+ let E = 1, D = [], O = (e) => {
689
+ for (; D.length < Math.min(e, d.length);) {
690
+ let e = d[D.length], t = this.chunkCache.get(e, i);
691
+ t.catch(() => {}), D.push(t);
692
+ }
693
+ };
694
+ O(1);
695
+ for (let e = 0, t = d.length; e < t; e++) {
696
+ let t = d[e], { buffer: n, cpositions: r, dpositions: i } = await D[e];
697
+ T += t.fetchedSize(), s?.(T, w);
698
+ let a = t.minv.dataPosition;
699
+ if (C) {
700
+ if (Q(n, r, i, a, C)) return;
701
+ } else {
702
+ let e = 0, t = 0;
703
+ for (; e < n.length;) {
704
+ let s = n.indexOf(I, e);
705
+ if (s === -1) break;
706
+ let c = e + a;
707
+ for (; t < i.length && c >= i[t];) t++;
708
+ if (_ !== void 0 && n[e] === _) {
709
+ e = s + 1;
710
+ continue;
711
+ }
712
+ S[0] = e - 1;
713
+ for (let e = 0; e < g; e++) {
714
+ let t = S[e], r = t < s ? n.indexOf(F, t + 1) : -1;
715
+ S[e + 1] = r === -1 || r >= s ? s : r;
716
+ }
717
+ let d = S[p - 1] + 1, y = S[p] - d;
718
+ if (y !== x.length) {
719
+ e = s + 1;
720
+ continue;
721
+ }
722
+ let C = !0;
723
+ for (let e = 0; e < y; e++) if (n[d + e] !== x[e]) {
724
+ C = !1;
725
+ break;
726
+ }
727
+ if (!C) {
728
+ e = s + 1;
729
+ continue;
730
+ }
731
+ let w = Z(n, S[m - 1] + 1, S[m]) + v;
732
+ if (w >= u) return;
733
+ let T;
734
+ if (T = h === 0 || h === m ? w + 1 : f ? q(n, w, S[3] + 1, S[4], S[h - 1] + 1, S[h]) : Z(n, S[h - 1] + 1, S[h]), T > l) {
735
+ let c = n[s - 1] === L ? s - 1 : s, l = b.decode(n.subarray(e, c));
736
+ o(l, K(r, i, t, e, a), w, T);
737
+ }
738
+ e = s + 1;
739
+ }
740
+ }
741
+ E = Math.min(E * 2, V), O(e + 1 + E);
742
+ }
743
+ }
744
+ async getMetadata(e = {}) {
745
+ return this.index.getMetadata(e);
746
+ }
747
+ async readHeaderBytes(t) {
748
+ let { firstDataLine: n, maxBlockSize: r } = await this.getMetadata(t), i = (n?.blockPosition ?? 0) + r, a = await this.filehandle.read(i, 0, t);
749
+ return e(a);
750
+ }
751
+ async parseHeader(e) {
752
+ let { metaChar: t, skipLines: n = 0 } = await this.getMetadata(e), r = await this.readHeaderBytes(e);
753
+ return {
754
+ header: J.decode(t ? Y(r, t) : r),
755
+ skippedLines: n > 0 ? X(r, n) : []
756
+ };
757
+ }
758
+ getParsedHeader(e = {}) {
759
+ return this.headerCache.get("header", e.signal, (t) => this.parseHeader({
760
+ ...e,
761
+ signal: t
762
+ }));
763
+ }
764
+ async getHeaderBuffer(e = {}) {
765
+ let { metaChar: t } = await this.getMetadata(e), n = await this.readHeaderBytes(e);
766
+ return t ? Y(n, t) : n;
767
+ }
768
+ async getSkippedLines(e = {}) {
769
+ let { skipLines: t = 0 } = await this.getMetadata(e);
770
+ return t <= 0 ? [] : (await this.getParsedHeader(e)).skippedLines;
771
+ }
772
+ async getHeader(e = {}) {
773
+ return (await this.getParsedHeader(e)).header;
774
+ }
775
+ async getHeaderLines(e = {}) {
776
+ let { header: t, skippedLines: n } = await this.getParsedHeader(e);
777
+ return (t ? t.split(/\r?\n/) : n).filter(Boolean);
778
+ }
779
+ async getReferenceSequenceNames(e = {}) {
780
+ return (await this.getMetadata(e)).refIdToName;
781
+ }
782
+ async lineCount(e, t = {}) {
783
+ return this.index.lineCount(e, t);
784
+ }
785
+ async readChunk(e, n = {}) {
786
+ let r = await this.filehandle.read(e.fetchedSize(), e.minv.blockPosition, n), i = await this.bgzfWorkerPool;
787
+ return t(r, e, i);
788
+ }
789
+ };
790
+ //#endregion
791
+ export { O as CSI, P as TBI, $ as TabixIndexedFile, u as VirtualOffset };