@genome-spy/app 1.2.0 → 1.3.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.
Files changed (87) hide show
  1. package/dist/{SharedReadCache-Ey5QIiPM.js → SharedReadCache-9sT2aIxW.js} +6 -12
  2. package/dist/__vite-browser-external-Dgu_Ldik.js +7 -0
  3. package/dist/{agentApi-8hMSlqAQ.js → agentApi-BclFF9zB.js} +7130 -7509
  4. package/dist/agentApi.es.js +4344 -4015
  5. package/dist/agentShared.es.js +431 -458
  6. package/dist/arrayUtils-Bm7QnzhN.js +1306 -0
  7. package/dist/{blosc-JROzDOnd.js → blosc-C-W97QwH.js} +3 -3
  8. package/dist/{canvas2d-Bd8H8MMo.js → canvas2d-8MSf70d4.js} +78 -86
  9. package/dist/{canvas2d-D6VYooRf.js → canvas2d-BwGNI_Rx.js} +83 -91
  10. package/dist/clipOptions-SrrxeAEU.js +4316 -0
  11. package/dist/clipOptions-clBEbkjv.js +4326 -0
  12. package/dist/{layoutResult-D50MSHXR.js → color-jETn8xK_.js} +29 -10
  13. package/dist/color-uTRRsy8i.js +116 -0
  14. package/dist/{componentStyles-DGtQXvwc.js → componentStyles-C7FbjS-a.js} +1 -1
  15. package/dist/{containerView-aEVmYmkA.js → containerView-BItRtKqu.js} +5 -1
  16. package/dist/{containerView-CRJSc4bM.js → containerView-CWa6ZIJW.js} +5 -1
  17. package/dist/{debug-CQ0agCrd.js → debug-23s-jja_.js} +3 -2
  18. package/dist/{debug-DkIMiGdW.js → debug-CWRxvAss.js} +2 -3
  19. package/dist/dialog.es.js +1 -1
  20. package/dist/dist-CmY6iewb.js +1501 -0
  21. package/dist/dist-D6xbz5Ks.js +1501 -0
  22. package/dist/{esm-CjkeZi__.js → esm-BFwBAnbO.js} +25 -25
  23. package/dist/esm-BUkWqSr2.js +299 -0
  24. package/dist/{esm-C-6g-SkZ.js → esm-C0xXMLsR.js} +37 -41
  25. package/dist/{esm-CJeszW-t.js → esm-C2xhhXs0.js} +7 -7
  26. package/dist/esm-C6erfjPM.js +252 -0
  27. package/dist/{esm-DFHFX1sH.js → esm-CVjC7qA4.js} +34 -38
  28. package/dist/esm-CqY5ezGz.js +1249 -0
  29. package/dist/esm-DfMIJ_N2.js +1522 -0
  30. package/dist/esm-Dls41IbZ.js +787 -0
  31. package/dist/{esm-Bv7Frz7C.js → esm-DzQDfrsZ.js} +7 -10
  32. package/dist/esm-aGLCvYRP.js +238 -0
  33. package/dist/{esm-VFJeyk9i.js → esm-nzwgJFGz.js} +40 -36
  34. package/dist/figWigMetadataSourceAdapter-8Kf_vZRf.js +36 -0
  35. package/dist/figWigMetadataSourceAdapter-DdDMZpYO.js +36 -0
  36. package/dist/flowNode-BSjy0Wz3.js +1306 -0
  37. package/dist/flowOutput-D5qpxWe0.js +183 -0
  38. package/dist/index.es.js +4756 -5528
  39. package/dist/index.js +707 -547
  40. package/dist/inflate-BdC5KvHn.js +886 -0
  41. package/dist/{lz4-CUYSbVey.js → lz4-BLPgBOlE.js} +1 -1
  42. package/dist/{markUtils-CvLDz744.js → markUtils-RaatLEa-.js} +9 -6
  43. package/dist/metadataUtils-DxEPe0vj.js +879 -0
  44. package/dist/{order-BVvkjDRT.js → order-BnKzKjt4.js} +383 -347
  45. package/dist/{order-DmMoZsi1.js → order-BpJnq_nV.js} +375 -339
  46. package/dist/{parquetRead-0hFIa3Cc.js → parquetRead-D-yY8njE.js} +3 -11
  47. package/dist/{rasterExport-jeRVq6kY.js → rasterExport-B-WrX1pa.js} +5 -5
  48. package/dist/{rasterExport-DxvowWjH.js → rasterExport-C_vx4Jwd.js} +3 -3
  49. package/dist/{rasterization-DFj3Cvx4.js → rasterization-QktH8Sn2.js} +1 -1
  50. package/dist/{rectangle-Dl4Dy0hS.js → rectangle-BAdoDPXu.js} +34 -31
  51. package/dist/{renderCanvas2D-Bfm1NHFu.js → renderCanvas2D-CsRO78Pq.js} +88 -87
  52. package/dist/{renderCanvas2D-DVjhp834.js → renderCanvas2D-Y7pkRzbC.js} +93 -92
  53. package/dist/{rolldown-runtime-DF993M8W.js → rolldown-runtime-DeIk2rA4.js} +1 -1
  54. package/dist/{indexer-DOYMJ-Md.js → scaleNull-CVzag4z8.js} +2 -12
  55. package/dist/{indexer-DDC0YRGn.js → scaleNull-Pbz7QGnl.js} +2 -12
  56. package/dist/{scalePosition-0aeqp_kz.js → scalePosition-CRXa0rCC.js} +1 -1
  57. package/dist/schema.json +3801 -816
  58. package/dist/{svg-Bm2zxBPu.js → svg-BBMtLgtM.js} +369 -285
  59. package/dist/{svg-CkfuhONt.js → svg-JjWL6U-T.js} +371 -287
  60. package/dist/{svgRasterizer-DoRQEqFA.js → svgRasterizer-6OcftuoI.js} +2 -2
  61. package/dist/{svgRasterizer-raDDhBF-.js → svgRasterizer-DkNRaCPs.js} +4 -4
  62. package/dist/tableMetadataSourceAdapter-CUNwLsdi.js +291 -0
  63. package/dist/tableMetadataSourceAdapter-DQrEXCo6.js +1283 -0
  64. package/dist/url-DeOdSRrv.js +183 -0
  65. package/dist/{viewError-BkJeVYXA.js → viewError-B0TMfOpB.js} +1 -1
  66. package/dist/{viewError-IYqyluc7.js → viewError-D9aO90cI.js} +1 -1
  67. package/dist/{viewSelectors-7LyasQN-.js → viewSelectors-DkFvo33d.js} +832 -734
  68. package/dist/{viewSelectors-CbmkSQRT.js → viewSelectors-lM93fHAq.js} +900 -802
  69. package/dist/{viewUtils-DuddMNNw.js → viewUtils-0SJOewM6.js} +1861 -2459
  70. package/dist/webgl-CXIO3OQz.js +5782 -0
  71. package/dist/webgl-Pdvfhio5.js +5783 -0
  72. package/package.json +7 -5
  73. package/src/agentApi/index.d.ts +3 -2
  74. package/src/agentShared/index.d.ts +2 -0
  75. package/src/appTypes.d.ts +1 -6
  76. package/src/embedTypes.d.ts +36 -1
  77. package/src/index.d.ts +6 -0
  78. package/src/spec/sampleView.d.ts +68 -13
  79. package/src/state/paramProvenanceTypes.d.ts +25 -2
  80. package/src/state.d.ts +14 -52
  81. package/dist/clipOptions-DElJ8dTZ.js +0 -3097
  82. package/dist/clipOptions-D_wBNhzs.js +0 -3087
  83. package/dist/esm-Dndm-NaA.js +0 -1193
  84. package/dist/vega-scale-BoGHANI7.js +0 -2446
  85. package/dist/vega-scale-o9TRyzYH.js +0 -2443
  86. package/dist/webgl-CQfvgnxo.js +0 -5633
  87. package/dist/webgl-DVYkXtiZ.js +0 -5632
@@ -0,0 +1,1522 @@
1
+ import { n as e, r as t } from "./esm-C6erfjPM.js";
2
+ import { t as n } from "./esm-C3A-AuRi.js";
3
+ import { n as r, r as i } from "./esm-BUkWqSr2.js";
4
+ //#region ../../node_modules/@gmod/bam/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
+ }, o = class {
20
+ blockPosition;
21
+ dataPosition;
22
+ constructor(e, t) {
23
+ this.blockPosition = e, this.dataPosition = t;
24
+ }
25
+ toString() {
26
+ return `${this.blockPosition}:${this.dataPosition}`;
27
+ }
28
+ };
29
+ function s(e, t = 0) {
30
+ return new o(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]);
31
+ }
32
+ //#endregion
33
+ //#region ../../node_modules/@gmod/bam/esm/util.js
34
+ function c(e) {
35
+ if (e?.aborted) {
36
+ let { reason: t } = e;
37
+ throw t === void 0 ? new DOMException("This operation was aborted", "AbortError") : t;
38
+ }
39
+ }
40
+ function l(e, t) {
41
+ let n = e.length;
42
+ if (n === 0) return e;
43
+ let r;
44
+ if (t) {
45
+ let i = t.blockPosition, a = t.dataPosition;
46
+ r = [];
47
+ for (let t = 0; t < n; t++) {
48
+ let n = e[t], o = n.maxv;
49
+ (o.blockPosition - i || o.dataPosition - a) > 0 && r.push(n);
50
+ }
51
+ if (r.length === 0) return r;
52
+ } else r = e;
53
+ r.sort((e, t) => {
54
+ let n = e.minv.blockPosition - t.minv.blockPosition;
55
+ return n === 0 ? e.minv.dataPosition - t.minv.dataPosition : n;
56
+ });
57
+ let i = [r[0]], o = r[0].minv.blockPosition, s = r[0].maxv.blockPosition;
58
+ for (let e = 1; e < r.length; e++) {
59
+ let t = r[e], n = t.minv.blockPosition, c = t.maxv.blockPosition;
60
+ if (n - s < 65e3 && c - o < 5e6) {
61
+ let e = i[i.length - 1];
62
+ (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);
63
+ } else i.push(t), o = n, s = c;
64
+ }
65
+ return u(i);
66
+ }
67
+ function u(e) {
68
+ let t = [e[0]];
69
+ for (let n = 1; n < e.length; n++) {
70
+ let r = e[n], i = t[t.length - 1].maxv;
71
+ (r.minv.blockPosition - i.blockPosition || r.minv.dataPosition - i.dataPosition) >= 0 ? t.push(r) : (r.maxv.blockPosition - i.blockPosition || r.maxv.dataPosition - i.dataPosition) > 0 && t.push(new a(i, r.maxv, r.bin, r.endPosition));
72
+ }
73
+ return t;
74
+ }
75
+ function d(e, t) {
76
+ let n = e[t] | e[t + 1] << 8 | e[t + 2] << 16 | e[t + 3] << 24;
77
+ return { lineCount: ((e[t + 4] | e[t + 5] << 8 | e[t + 6] << 16 | e[t + 7] << 24) >>> 0) * 2 ** 32 + (n >>> 0) };
78
+ }
79
+ function f(e, t = []) {
80
+ if (e.length === 0) return;
81
+ let n = Array(t.length + e.length * 2), r = 0;
82
+ for (let e = 0, i = t.length; e < i; e++) n[r++] = t[e];
83
+ for (let t of e) n[r++] = t.minv.blockPosition, n[r++] = t.maxv.blockPosition;
84
+ n.sort((e, t) => e - t);
85
+ for (let t of e) {
86
+ let e = t.maxv.blockPosition, r = 0, i = n.length;
87
+ for (; r < i;) {
88
+ let t = r + i >>> 1;
89
+ n[t] > e ? i = t : r = t + 1;
90
+ }
91
+ r < n.length && (t.endPosition = Math.min(t.endPosition, n[r]));
92
+ }
93
+ }
94
+ function p(e, t, n) {
95
+ if (t + 4 > e.length) return;
96
+ let r = new DataView(e.buffer, e.byteOffset, e.byteLength), i = r.getInt32(t, !0), a = Object.create(null), o = [], s = new TextDecoder("utf8"), c = t + 4;
97
+ for (let t = 0; t < i; t++) {
98
+ if (c + 8 > e.length) return;
99
+ let i = r.getInt32(c, !0);
100
+ if (c + 8 + i > e.length) return;
101
+ let l = n(s.decode(e.subarray(c + 4, c + 4 + i - 1))), u = r.getInt32(c + i + 4, !0);
102
+ a[l] = t, o.push({
103
+ refName: l,
104
+ length: u
105
+ }), c += 8 + i;
106
+ }
107
+ return {
108
+ chrToIndex: a,
109
+ indexToChr: o,
110
+ end: c
111
+ };
112
+ }
113
+ function m(e, t, n, r) {
114
+ let i = r ? r.blockPosition : Infinity, a = r ? r.dataPosition : 0, s = !1;
115
+ for (let r = 0; r < n; r++) {
116
+ let n = t + r * 8, o = 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];
117
+ (o !== 0 || c !== 0) && (o < i || o === i && c < a) && (i = o, a = c, s = !0);
118
+ }
119
+ return s ? new o(i, a) : r;
120
+ }
121
+ function h(e, t = (e) => e) {
122
+ let n = new TextDecoder(), r = 0, i = 0, a = [], o = Object.create(null);
123
+ for (let s = 0; s < e.length; s++) if (!e[s]) {
124
+ if (i < s) {
125
+ let c = t(n.decode(e.subarray(i, s)));
126
+ a[r] = c, o[c] = r;
127
+ }
128
+ i = s + 1, r++;
129
+ }
130
+ return {
131
+ refNameToId: o,
132
+ refIdToName: a
133
+ };
134
+ }
135
+ function g(e) {
136
+ let t = 0;
137
+ for (let n of e) t += n.length;
138
+ let n = new Uint8Array(t), r = 0;
139
+ for (let t of e) n.set(t, r), r += t.length;
140
+ return n;
141
+ }
142
+ function _(e) {
143
+ return e.end > e.start ? e.end : e.start + 1;
144
+ }
145
+ function v(e, t, n, r, i = []) {
146
+ for (let a = 0, o = e.length; a < o; a++) {
147
+ let o = e[a];
148
+ if (o.ref_id === t) {
149
+ if (o.start >= r) break;
150
+ _(o) > n && i.push(o);
151
+ } else if (o.ref_id > t) break;
152
+ }
153
+ return i;
154
+ }
155
+ //#endregion
156
+ //#region ../../node_modules/@gmod/bam/esm/indexFile.js
157
+ function y(e, t = 5) {
158
+ let r = new n({ maxSize: t });
159
+ return (t) => {
160
+ let n = r.get(t);
161
+ if (n !== void 0) return n;
162
+ let i = e(t);
163
+ return i && r.set(t, i), i;
164
+ };
165
+ }
166
+ var b = class {
167
+ filehandle;
168
+ renameRefSeq;
169
+ setupP;
170
+ setupSignal;
171
+ constructor({ filehandle: e, renameRefSeq: t = (e) => e }) {
172
+ this.filehandle = e, this.renameRefSeq = t;
173
+ }
174
+ async blocksForRange(e, t, n, r = {}) {
175
+ t < 0 && (t = 0);
176
+ let i = (await this.parse(r)).indices(e);
177
+ if (!i) return [];
178
+ let a = this.reg2bins(t, n);
179
+ if (a.length === 0) return [];
180
+ let o = [], { binIndex: s } = i;
181
+ for (let [e, t] of a) for (let n = e; n <= t; n++) {
182
+ let e = s[n];
183
+ if (e) for (let t = 0, n = e.length; t < n; t++) o.push(e[t]);
184
+ }
185
+ return l(o, this.getLowestChunk(i, t));
186
+ }
187
+ async parse(e = {}, t = !1) {
188
+ c(e.signal);
189
+ let n = this.setupP;
190
+ if (!n) return this.startParse(e);
191
+ let r = this.setupSignal;
192
+ try {
193
+ return await n;
194
+ } catch (n) {
195
+ if (t || !r?.aborted || e.signal?.aborted) throw n;
196
+ return this.parse(e, !0);
197
+ }
198
+ }
199
+ startParse(e) {
200
+ let t = this._parse(e);
201
+ return this.setupP = t, this.setupSignal = e.signal, t.then(() => {
202
+ this.setupP === t && (this.setupSignal = void 0);
203
+ }, () => {
204
+ this.setupP === t && (this.setupP = void 0, this.setupSignal = void 0);
205
+ }), t;
206
+ }
207
+ async lineCount(e, t) {
208
+ return (await this.parse(t)).indices(e)?.stats?.lineCount ?? 0;
209
+ }
210
+ async hasRefSeq(e, t) {
211
+ return !!(await this.parse(t)).indices(e);
212
+ }
213
+ async estimatedBytesForRegions(e, t) {
214
+ let n = l((await Promise.all(e.map((e) => this.blocksForRange(e.refId, e.start, e.end, t)))).flat()), r = 0;
215
+ for (let e of n) r += e.fetchedSize();
216
+ return r;
217
+ }
218
+ }, x = /* @__PURE__ */ new Float64Array(), ee = 21578050, S = 14, te = 16384, C = 2 ** 29;
219
+ function ne(e, t) {
220
+ return e - e % t;
221
+ }
222
+ function w(e, t) {
223
+ let n = e % t;
224
+ return n === 0 ? e : e - n + t;
225
+ }
226
+ function re(e, t) {
227
+ return e > C && (e = C), t > C && (t = C), --t, [
228
+ [0, 0],
229
+ [1 + (e >> 26), 1 + (t >> 26)],
230
+ [9 + (e >> 23), 9 + (t >> 23)],
231
+ [73 + (e >> 20), 73 + (t >> 20)],
232
+ [585 + (e >> 17), 585 + (t >> 17)],
233
+ [4681 + (e >> S), 4681 + (t >> S)]
234
+ ];
235
+ }
236
+ var T = class extends b {
237
+ async _parse(e) {
238
+ let t = await this.filehandle.readFile(e), n = new DataView(t.buffer, t.byteOffset, t.byteLength);
239
+ if (n.getUint32(0, !0) !== ee) throw Error("Not a BAI file");
240
+ let r = n.getInt32(4, !0), i = 8, o, c = [];
241
+ for (let e = 0; e < r; e++) {
242
+ c.push(i);
243
+ let e = n.getInt32(i, !0);
244
+ i += 4;
245
+ for (let t = 0; t < e; t += 1) {
246
+ let e = n.getUint32(i, !0);
247
+ if (i += 4, e === 37450) i += 4, i += 32;
248
+ else if (e > 37450) throw Error("bai index contains too many bins, please use CSI");
249
+ else {
250
+ let e = n.getInt32(i, !0);
251
+ i += 4 + 16 * e;
252
+ }
253
+ }
254
+ let r = n.getInt32(i, !0);
255
+ i += 4, o = m(t, i, r, o), i += 8 * r;
256
+ }
257
+ function l(e) {
258
+ let r = c[e];
259
+ if (r === void 0) return;
260
+ let i = n.getInt32(r, !0), o;
261
+ r += 4;
262
+ let l = {};
263
+ for (let e = 0; e < i; e += 1) {
264
+ let e = n.getUint32(r, !0);
265
+ if (r += 4, e === 37450) r += 4, o = d(t, r + 16), r += 32;
266
+ else if (e > 37450) throw Error("bai index contains too many bins, please use CSI");
267
+ else {
268
+ let i = n.getInt32(r, !0);
269
+ r += 4;
270
+ let o = Array(i);
271
+ for (let n = 0; n < i; n++) {
272
+ let i = s(t, r);
273
+ r += 8;
274
+ let c = s(t, r);
275
+ r += 8, o[n] = new a(i, c, e);
276
+ }
277
+ l[e] = o;
278
+ }
279
+ }
280
+ let u = n.getInt32(r, !0);
281
+ r += 4;
282
+ let p = u === 0 ? x : new Float64Array(u), m = u === 0 ? x : new Float64Array(u);
283
+ for (let e = 0; e < u; e++) p[e] = t[r + 7] * 1099511627776 + t[r + 6] * 4294967296 + t[r + 5] * 16777216 + t[r + 4] * 65536 + t[r + 3] * 256 + t[r + 2], m[e] = t[r + 1] << 8 | t[r], r += 8;
284
+ return f(Object.values(l).flat(), p), {
285
+ binIndex: l,
286
+ linearBlockPositions: p,
287
+ linearDataPositions: m,
288
+ stats: o
289
+ };
290
+ }
291
+ return {
292
+ bai: !0,
293
+ firstDataLine: o,
294
+ indices: y(l),
295
+ refCount: r
296
+ };
297
+ }
298
+ async indexCov(e, t, n, r) {
299
+ let i = te, a = (await this.parse(r)).indices(e);
300
+ if (!a) return [];
301
+ let { linearBlockPositions: o, stats: s } = a, c = o.length;
302
+ if (c === 0) return [];
303
+ let l = (c - 1) * i, u = t === void 0 ? 0 : Math.min(Math.max(ne(t, i), 0), l), d = n === void 0 ? l : Math.min(w(n, i), l);
304
+ if (d <= u) return [];
305
+ let f = Array((d - u) / i), p = o[c - 1], m = s?.lineCount ?? 0, h = o[u / i];
306
+ for (let e = u / i, t = 0; e < d / i; e++, t++) {
307
+ let n = o[e + 1];
308
+ f[t] = {
309
+ score: (n - h) * m / p,
310
+ start: e * i,
311
+ end: e * i + i
312
+ }, h = n;
313
+ }
314
+ return f;
315
+ }
316
+ reg2bins(e, t) {
317
+ return re(e, t);
318
+ }
319
+ getLowestChunk(e, t) {
320
+ let { linearBlockPositions: n, linearDataPositions: r } = e, i = Math.min(t >> S, n.length - 1);
321
+ return i < 0 ? void 0 : {
322
+ blockPosition: n[i],
323
+ dataPosition: r[i]
324
+ };
325
+ }
326
+ }, E = [
327
+ 0,
328
+ 1996959894,
329
+ 3993919788,
330
+ 2567524794,
331
+ 124634137,
332
+ 1886057615,
333
+ 3915621685,
334
+ 2657392035,
335
+ 249268274,
336
+ 2044508324,
337
+ 3772115230,
338
+ 2547177864,
339
+ 162941995,
340
+ 2125561021,
341
+ 3887607047,
342
+ 2428444049,
343
+ 498536548,
344
+ 1789927666,
345
+ 4089016648,
346
+ 2227061214,
347
+ 450548861,
348
+ 1843258603,
349
+ 4107580753,
350
+ 2211677639,
351
+ 325883990,
352
+ 1684777152,
353
+ 4251122042,
354
+ 2321926636,
355
+ 335633487,
356
+ 1661365465,
357
+ 4195302755,
358
+ 2366115317,
359
+ 997073096,
360
+ 1281953886,
361
+ 3579855332,
362
+ 2724688242,
363
+ 1006888145,
364
+ 1258607687,
365
+ 3524101629,
366
+ 2768942443,
367
+ 901097722,
368
+ 1119000684,
369
+ 3686517206,
370
+ 2898065728,
371
+ 853044451,
372
+ 1172266101,
373
+ 3705015759,
374
+ 2882616665,
375
+ 651767980,
376
+ 1373503546,
377
+ 3369554304,
378
+ 3218104598,
379
+ 565507253,
380
+ 1454621731,
381
+ 3485111705,
382
+ 3099436303,
383
+ 671266974,
384
+ 1594198024,
385
+ 3322730930,
386
+ 2970347812,
387
+ 795835527,
388
+ 1483230225,
389
+ 3244367275,
390
+ 3060149565,
391
+ 1994146192,
392
+ 31158534,
393
+ 2563907772,
394
+ 4023717930,
395
+ 1907459465,
396
+ 112637215,
397
+ 2680153253,
398
+ 3904427059,
399
+ 2013776290,
400
+ 251722036,
401
+ 2517215374,
402
+ 3775830040,
403
+ 2137656763,
404
+ 141376813,
405
+ 2439277719,
406
+ 3865271297,
407
+ 1802195444,
408
+ 476864866,
409
+ 2238001368,
410
+ 4066508878,
411
+ 1812370925,
412
+ 453092731,
413
+ 2181625025,
414
+ 4111451223,
415
+ 1706088902,
416
+ 314042704,
417
+ 2344532202,
418
+ 4240017532,
419
+ 1658658271,
420
+ 366619977,
421
+ 2362670323,
422
+ 4224994405,
423
+ 1303535960,
424
+ 984961486,
425
+ 2747007092,
426
+ 3569037538,
427
+ 1256170817,
428
+ 1037604311,
429
+ 2765210733,
430
+ 3554079995,
431
+ 1131014506,
432
+ 879679996,
433
+ 2909243462,
434
+ 3663771856,
435
+ 1141124467,
436
+ 855842277,
437
+ 2852801631,
438
+ 3708648649,
439
+ 1342533948,
440
+ 654459306,
441
+ 3188396048,
442
+ 3373015174,
443
+ 1466479909,
444
+ 544179635,
445
+ 3110523913,
446
+ 3462522015,
447
+ 1591671054,
448
+ 702138776,
449
+ 2966460450,
450
+ 3352799412,
451
+ 1504918807,
452
+ 783551873,
453
+ 3082640443,
454
+ 3233442989,
455
+ 3988292384,
456
+ 2596254646,
457
+ 62317068,
458
+ 1957810842,
459
+ 3939845945,
460
+ 2647816111,
461
+ 81470997,
462
+ 1943803523,
463
+ 3814918930,
464
+ 2489596804,
465
+ 225274430,
466
+ 2053790376,
467
+ 3826175755,
468
+ 2466906013,
469
+ 167816743,
470
+ 2097651377,
471
+ 4027552580,
472
+ 2265490386,
473
+ 503444072,
474
+ 1762050814,
475
+ 4150417245,
476
+ 2154129355,
477
+ 426522225,
478
+ 1852507879,
479
+ 4275313526,
480
+ 2312317920,
481
+ 282753626,
482
+ 1742555852,
483
+ 4189708143,
484
+ 2394877945,
485
+ 397917763,
486
+ 1622183637,
487
+ 3604390888,
488
+ 2714866558,
489
+ 953729732,
490
+ 1340076626,
491
+ 3518719985,
492
+ 2797360999,
493
+ 1068828381,
494
+ 1219638859,
495
+ 3624741850,
496
+ 2936675148,
497
+ 906185462,
498
+ 1090812512,
499
+ 3747672003,
500
+ 2825379669,
501
+ 829329135,
502
+ 1181335161,
503
+ 3412177804,
504
+ 3160834842,
505
+ 628085408,
506
+ 1382605366,
507
+ 3423369109,
508
+ 3138078467,
509
+ 570562233,
510
+ 1426400815,
511
+ 3317316542,
512
+ 2998733608,
513
+ 733239954,
514
+ 1555261956,
515
+ 3268935591,
516
+ 3050360625,
517
+ 752459403,
518
+ 1541320221,
519
+ 2607071920,
520
+ 3965973030,
521
+ 1969922972,
522
+ 40735498,
523
+ 2617837225,
524
+ 3943577151,
525
+ 1913087877,
526
+ 83908371,
527
+ 2512341634,
528
+ 3803740692,
529
+ 2075208622,
530
+ 213261112,
531
+ 2463272603,
532
+ 3855990285,
533
+ 2094854071,
534
+ 198958881,
535
+ 2262029012,
536
+ 4057260610,
537
+ 1759359992,
538
+ 534414190,
539
+ 2176718541,
540
+ 4139329115,
541
+ 1873836001,
542
+ 414664567,
543
+ 2282248934,
544
+ 4279200368,
545
+ 1711684554,
546
+ 285281116,
547
+ 2405801727,
548
+ 4167216745,
549
+ 1634467795,
550
+ 376229701,
551
+ 2685067896,
552
+ 3608007406,
553
+ 1308918612,
554
+ 956543938,
555
+ 2808555105,
556
+ 3495958263,
557
+ 1231636301,
558
+ 1047427035,
559
+ 2932959818,
560
+ 3654703836,
561
+ 1088359270,
562
+ 936918e3,
563
+ 2847714899,
564
+ 3736837829,
565
+ 1202900863,
566
+ 817233897,
567
+ 3183342108,
568
+ 3401237130,
569
+ 1404277552,
570
+ 615818150,
571
+ 3134207493,
572
+ 3453421203,
573
+ 1423857449,
574
+ 601450431,
575
+ 3009837614,
576
+ 3294710456,
577
+ 1567103746,
578
+ 711928724,
579
+ 3020668471,
580
+ 3272380065,
581
+ 1510334235,
582
+ 755167117
583
+ ];
584
+ typeof Int32Array < "u" && (E = new Int32Array(E));
585
+ var ie = (e, t) => {
586
+ let n = t === 0 ? 0 : ~~t ^ -1;
587
+ for (let t = 0; t < e.length; t++) n = E[(n ^ e[t]) & 255] ^ n >>> 8;
588
+ return n ^ -1;
589
+ }, ae = 21582659, oe = 38359875, se = new o(0, 0);
590
+ function D(e, t) {
591
+ return e * 2 ** t;
592
+ }
593
+ function O(e, t) {
594
+ return Math.floor(e / 2 ** t);
595
+ }
596
+ var k = class extends b {
597
+ maxBinNumber = 0;
598
+ depth = 0;
599
+ minShift = 0;
600
+ async indexCov() {
601
+ return [];
602
+ }
603
+ parseAuxData(e, t) {
604
+ let n = new DataView(e.buffer, e.byteOffset, e.byteLength), r = n.getUint32(t, !0), i = r & 65536 ? "zero-based-half-open" : "1-based-closed", a = [
605
+ "generic",
606
+ "SAM",
607
+ "VCF"
608
+ ][r & 15];
609
+ if (!a) throw Error(`invalid Tabix preset format flags ${r}`);
610
+ let o = {
611
+ ref: n.getInt32(t + 4, !0),
612
+ start: n.getInt32(t + 8, !0),
613
+ end: n.getInt32(t + 12, !0)
614
+ }, s = n.getInt32(t + 16, !0), c = s ? String.fromCharCode(s) : "", l = n.getInt32(t + 20, !0), u = n.getInt32(t + 24, !0);
615
+ return {
616
+ columnNumbers: o,
617
+ coordinateType: i,
618
+ metaValue: s,
619
+ metaChar: c,
620
+ skipLines: l,
621
+ format: a,
622
+ formatFlags: r,
623
+ ...h(e.subarray(t + 28, t + 28 + u), this.renameRefSeq)
624
+ };
625
+ }
626
+ async _parse(e) {
627
+ let t = await this.filehandle.readFile(e), n = await r(t), i = new DataView(n.buffer, n.byteOffset, n.byteLength), o = i.getUint32(0, !0);
628
+ if (o !== ae && o !== oe) throw Error(`Not a CSI file ${o}`);
629
+ this.minShift = i.getInt32(4, !0), this.depth = i.getInt32(8, !0), this.maxBinNumber = ((1 << (this.depth + 1) * 3) - 1) / 7;
630
+ let c = this.maxBinNumber, l = i.getInt32(12, !0), u = l >= 30 ? this.parseAuxData(n, 16) : void 0, p = i.getInt32(16 + l, !0), h = 16 + l + 4, g, _ = [];
631
+ for (let e = 0; e < p; e++) {
632
+ _.push(h);
633
+ let e = i.getInt32(h, !0);
634
+ h += 4;
635
+ for (let t = 0; t < e; t++) {
636
+ let e = i.getUint32(h, !0);
637
+ if (h += 4, e > this.maxBinNumber) h += 44;
638
+ else {
639
+ g = m(n, h, 1, g), h += 8;
640
+ let e = i.getInt32(h, !0);
641
+ h += 4 + 16 * e;
642
+ }
643
+ }
644
+ }
645
+ function v(e) {
646
+ let t = _[e];
647
+ if (t === void 0) return;
648
+ let r = i.getInt32(t, !0);
649
+ t += 4;
650
+ let o = {}, l;
651
+ for (let e = 0; e < r; e++) {
652
+ let e = i.getUint32(t, !0);
653
+ if (t += 4, e > c) l = d(n, t + 28), t += 44;
654
+ else {
655
+ t += 8;
656
+ let r = i.getInt32(t, !0);
657
+ t += 4;
658
+ let c = Array(r);
659
+ for (let i = 0; i < r; i += 1) {
660
+ let r = s(n, t);
661
+ t += 8;
662
+ let o = s(n, t);
663
+ t += 8, c[i] = new a(r, o, e);
664
+ }
665
+ o[e] = c;
666
+ }
667
+ }
668
+ return f(Object.values(o).flat()), {
669
+ binIndex: o,
670
+ stats: l
671
+ };
672
+ }
673
+ return {
674
+ firstDataLine: g,
675
+ indices: y(v),
676
+ refCount: p,
677
+ csi: !0,
678
+ ...u
679
+ };
680
+ }
681
+ getLowestChunk() {
682
+ return se;
683
+ }
684
+ reg2bins(e, t) {
685
+ let n = 2 ** (this.minShift + this.depth * 3);
686
+ t > n && (t = n), --t;
687
+ let r = 0, i = 0, a = this.minShift + this.depth * 3, o = [];
688
+ for (; r <= this.depth; a -= 3, i += D(1, r * 3), r += 1) {
689
+ let n = i + O(e, a), r = i + O(t, a);
690
+ if (r - n + o.length > this.maxBinNumber) throw Error(`query ${e}-${t} is too large for current binning scheme (shift ${this.minShift}, depth ${this.depth}), try a smaller query or a coarser index binning scheme`);
691
+ o.push([n, r]);
692
+ }
693
+ return o;
694
+ }
695
+ }, ce = class {
696
+ read() {
697
+ throw Error("never called");
698
+ }
699
+ stat() {
700
+ throw Error("never called");
701
+ }
702
+ readFile() {
703
+ throw Error("never called");
704
+ }
705
+ close() {
706
+ throw Error("never called");
707
+ }
708
+ }, A = {
709
+ BAM_FPAIRED: 1,
710
+ BAM_FPROPER_PAIR: 2,
711
+ BAM_FUNMAP: 4,
712
+ BAM_FMUNMAP: 8,
713
+ BAM_FREVERSE: 16,
714
+ BAM_FMREVERSE: 32,
715
+ BAM_FREAD1: 64,
716
+ BAM_FREAD2: 128,
717
+ BAM_FSECONDARY: 256,
718
+ BAM_FQCFAIL: 512,
719
+ BAM_FDUP: 1024,
720
+ BAM_FSUPPLEMENTARY: 2048
721
+ }, j = "=ACMGRSVTWYHKDBN", M = j.split(""), N = Uint8Array.from(j, (e) => e.charCodeAt(0)), le = new Uint16Array(Uint8Array.of(1, 0).buffer)[0] === 1, P = /* @__PURE__ */ new Uint16Array(256), F = Array(256);
722
+ for (let e = 0; e < 16; e++) for (let t = 0; t < 16; t++) {
723
+ let n = N[e], r = N[t];
724
+ P[e << 4 | t] = le ? n | r << 8 : n << 8 | r, F[e << 4 | t] = M[e] + M[t];
725
+ }
726
+ var ue = 300, de = 1024, fe = 0, I;
727
+ function L() {
728
+ if (I === void 0) {
729
+ if (++fe < de) return;
730
+ let e = Array(65536);
731
+ for (let t = 0; t < 256; t++) {
732
+ let n = F[t], r = t << 8;
733
+ for (let t = 0; t < 256; t++) e[r | t] = n + F[t];
734
+ }
735
+ I = e;
736
+ }
737
+ return I;
738
+ }
739
+ var R = [
740
+ "F1F2",
741
+ "F1R2",
742
+ "R1F2",
743
+ "R1R2",
744
+ "F2F1",
745
+ "F2R1",
746
+ "R2F1",
747
+ "R2R1",
748
+ "F2F1",
749
+ "R2F1",
750
+ "F2R1",
751
+ "R2R1",
752
+ "F1F2",
753
+ "R1F2",
754
+ "F1R2",
755
+ "R1R2"
756
+ ], z = [
757
+ 77,
758
+ 73,
759
+ 68,
760
+ 78,
761
+ 83,
762
+ 72,
763
+ 80,
764
+ 61,
765
+ 88,
766
+ 63,
767
+ 63,
768
+ 63,
769
+ 63,
770
+ 63,
771
+ 63,
772
+ 63
773
+ ], B = new TextDecoder(), V = /* @__PURE__ */ new Map();
774
+ function pe(e, t) {
775
+ let n = e << 8 | t, r = V.get(n);
776
+ return r === void 0 && (r = String.fromCharCode(e, t), V.set(n, r)), r;
777
+ }
778
+ var me = 32;
779
+ function he(e, t, n) {
780
+ let r = n - t;
781
+ if (r < me) {
782
+ let i = Array(r);
783
+ for (let a = 0; a < r; a++) {
784
+ let r = e[t + a];
785
+ if (r > 127) return B.decode(e.subarray(t, n));
786
+ i[a] = r;
787
+ }
788
+ return String.fromCharCode(...i);
789
+ }
790
+ return B.decode(e.subarray(t, n));
791
+ }
792
+ var H = 397;
793
+ function ge(e) {
794
+ return e instanceof Uint32Array || e instanceof Int32Array || Array.isArray(e);
795
+ }
796
+ function _e(e, t, n, r, i) {
797
+ let a = e.byteOffset + n;
798
+ switch (r) {
799
+ case 105: {
800
+ if (a % 4 == 0) return new Int32Array(e.buffer, a, i);
801
+ let r = Array(i);
802
+ for (let e = 0; e < i; e++) r[e] = t.getInt32(n + e * 4, !0);
803
+ return r;
804
+ }
805
+ case 73: {
806
+ if (a % 4 == 0) return new Uint32Array(e.buffer, a, i);
807
+ let r = Array(i);
808
+ for (let e = 0; e < i; e++) r[e] = t.getUint32(n + e * 4, !0);
809
+ return r;
810
+ }
811
+ case 115: {
812
+ if (a % 2 == 0) return new Int16Array(e.buffer, a, i);
813
+ let r = Array(i);
814
+ for (let e = 0; e < i; e++) r[e] = t.getInt16(n + e * 2, !0);
815
+ return r;
816
+ }
817
+ case 83: {
818
+ if (a % 2 == 0) return new Uint16Array(e.buffer, a, i);
819
+ let r = Array(i);
820
+ for (let e = 0; e < i; e++) r[e] = t.getUint16(n + e * 2, !0);
821
+ return r;
822
+ }
823
+ case 99: return new Int8Array(e.buffer, a, i);
824
+ case 67: return new Uint8Array(e.buffer, a, i);
825
+ case 102: {
826
+ if (a % 4 == 0) return new Float32Array(e.buffer, a, i);
827
+ let r = Array(i);
828
+ for (let e = 0; e < i; e++) r[e] = t.getFloat32(n + e * 4, !0);
829
+ return r;
830
+ }
831
+ default: return;
832
+ }
833
+ }
834
+ function ve(e, t) {
835
+ return e === 105 || e === 73 || e === 102 ? t << 2 : e === 115 || e === 83 ? t << 1 : e === 99 || e === 67 ? t : -1;
836
+ }
837
+ function U(e, t, n, r, i) {
838
+ switch (n) {
839
+ case 65:
840
+ case 99:
841
+ case 67: return r + 1;
842
+ case 115:
843
+ case 83: return r + 2;
844
+ case 105:
845
+ case 73:
846
+ case 102: return r + 4;
847
+ case 90:
848
+ case 72: {
849
+ let t = r;
850
+ for (; t < i && e[t] !== 0;) t++;
851
+ return t + 1;
852
+ }
853
+ case 66: {
854
+ let n = e[r], i = ve(n, t.getInt32(r + 1, !0));
855
+ return i < 0 ? (console.error("Unknown BAM B tag subtype", n), 0) : r + 5 + i;
856
+ }
857
+ default: return console.error("Unknown BAM tag type", n), 0;
858
+ }
859
+ }
860
+ function W(e, t, n, r, i, a) {
861
+ switch (n) {
862
+ case 65: return String.fromCharCode(e[r]);
863
+ case 105: return t.getInt32(r, !0);
864
+ case 73: return t.getUint32(r, !0);
865
+ case 99: return t.getInt8(r);
866
+ case 67: return t.getUint8(r);
867
+ case 115: return t.getInt16(r, !0);
868
+ case 83: return t.getUint16(r, !0);
869
+ case 102: return t.getFloat32(r, !0);
870
+ case 90:
871
+ case 72: return a ? e.subarray(r, i - 1) : he(e, r, i - 1);
872
+ default: {
873
+ let n = e[r], i = t.getInt32(r + 1, !0);
874
+ return _e(e, t, r + 5, n, i);
875
+ }
876
+ }
877
+ }
878
+ var G = class {
879
+ fileOffset;
880
+ _byteArray;
881
+ _start;
882
+ _end;
883
+ _dataView;
884
+ _cachedEnd;
885
+ _cachedTags;
886
+ _cachedLengthOnRef;
887
+ _cachedNumericCigar;
888
+ _cachedNUMERIC_MD;
889
+ _cachedSeqStart;
890
+ constructor(e, t, n, r, i) {
891
+ this._byteArray = e, this._start = t, this._end = n, this.fileOffset = r, this._dataView = i;
892
+ }
893
+ get byteArray() {
894
+ return this._byteArray;
895
+ }
896
+ get flags() {
897
+ return this._dataView.getUint16(this._start + 18, !0);
898
+ }
899
+ get ref_id() {
900
+ return this._dataView.getInt32(this._start + 4, !0);
901
+ }
902
+ get start() {
903
+ return this._dataView.getInt32(this._start + 8, !0);
904
+ }
905
+ get end() {
906
+ return this._cachedEnd === void 0 && (this._cachedEnd = this.start + this.length_on_ref), this._cachedEnd;
907
+ }
908
+ get mq() {
909
+ let e = (this.bin_mq_nl & 65280) >> 8;
910
+ return e === 255 ? void 0 : e;
911
+ }
912
+ get score() {
913
+ return this.mq;
914
+ }
915
+ get qual() {
916
+ let e = this.seq_length;
917
+ if (e === 0) return null;
918
+ {
919
+ let t = this.seqStart + (e + 1 >> 1);
920
+ return this._byteArray.subarray(t, t + e);
921
+ }
922
+ }
923
+ get strand() {
924
+ return this.isReverseComplemented() ? -1 : 1;
925
+ }
926
+ get b0() {
927
+ return this._start + 36;
928
+ }
929
+ get seqStart() {
930
+ return this._cachedSeqStart === void 0 && (this._cachedSeqStart = this.b0 + this.read_name_length + this.num_cigar_bytes), this._cachedSeqStart;
931
+ }
932
+ get tagsStart() {
933
+ let e = this.seq_length;
934
+ return this.seqStart + (e + 1 >> 1) + e;
935
+ }
936
+ get name() {
937
+ let e = this.read_name_length - 1, t = this.b0, n = this._byteArray, r = Array(e);
938
+ for (let i = 0; i < e; i++) r[i] = n[t + i];
939
+ return String.fromCharCode(...r);
940
+ }
941
+ get NUMERIC_MD() {
942
+ if (this._cachedNUMERIC_MD === void 0) {
943
+ let e = this.getTagRaw("MD");
944
+ this._cachedNUMERIC_MD = e instanceof Uint8Array ? e : null;
945
+ }
946
+ return this._cachedNUMERIC_MD === null ? void 0 : this._cachedNUMERIC_MD;
947
+ }
948
+ get tags() {
949
+ return this._cachedTags === void 0 && (this._cachedTags = this._computeTags()), this._cachedTags;
950
+ }
951
+ getTag(e) {
952
+ return this._cachedTags === void 0 ? this._findTag(e, !1) : this._cachedTags[e];
953
+ }
954
+ getTagRaw(e) {
955
+ return this._findTag(e, !0);
956
+ }
957
+ getTagAlt(e, t) {
958
+ if (this._cachedTags !== void 0) return this._cachedTags[e] ?? this._cachedTags[t];
959
+ let n = e.charCodeAt(0), r = e.charCodeAt(1), i = t.charCodeAt(0), a = t.charCodeAt(1), o = this._end, s = this._byteArray, c = this.tagsStart, l = -1, u = 0, d = 0;
960
+ for (; c < o;) {
961
+ let e = s[c], t = s[c + 1], f = s[c + 2], p = c + 3, m = U(s, this._dataView, f, p, o);
962
+ if (m === 0) break;
963
+ if (e === n && t === r) return W(s, this._dataView, f, p, m, !1);
964
+ l < 0 && e === i && t === a && (l = f, u = p, d = m), c = m;
965
+ }
966
+ return l < 0 ? void 0 : W(s, this._dataView, l, u, d, !1);
967
+ }
968
+ _findTag(e, t) {
969
+ let n = e.charCodeAt(0), r = e.charCodeAt(1), i = this._end, a = this._byteArray, o = this.tagsStart;
970
+ for (; o < i;) {
971
+ let e = a[o] === n && a[o + 1] === r, s = a[o + 2], c = o + 3, l = U(a, this._dataView, s, c, i);
972
+ if (l === 0) break;
973
+ if (e) return W(a, this._dataView, s, c, l, t);
974
+ o = l;
975
+ }
976
+ }
977
+ _computeTags() {
978
+ let e = this._end, t = this._byteArray, n = Object.create(null), r = this.tagsStart;
979
+ for (; r < e;) {
980
+ let i = pe(t[r], t[r + 1]), a = t[r + 2], o = r + 3, s = U(t, this._dataView, a, o, e);
981
+ if (s === 0) break;
982
+ n[i] = W(t, this._dataView, a, o, s, !1), r = s;
983
+ }
984
+ return n;
985
+ }
986
+ isPaired() {
987
+ return !!(this.flags & A.BAM_FPAIRED);
988
+ }
989
+ isProperlyPaired() {
990
+ return !!(this.flags & A.BAM_FPROPER_PAIR);
991
+ }
992
+ isSegmentUnmapped() {
993
+ return !!(this.flags & A.BAM_FUNMAP);
994
+ }
995
+ isMateUnmapped() {
996
+ return !!(this.flags & A.BAM_FMUNMAP);
997
+ }
998
+ isReverseComplemented() {
999
+ return !!(this.flags & A.BAM_FREVERSE);
1000
+ }
1001
+ isMateReverseComplemented() {
1002
+ return !!(this.flags & A.BAM_FMREVERSE);
1003
+ }
1004
+ isRead1() {
1005
+ return !!(this.flags & A.BAM_FREAD1);
1006
+ }
1007
+ isRead2() {
1008
+ return !!(this.flags & A.BAM_FREAD2);
1009
+ }
1010
+ isSecondary() {
1011
+ return !!(this.flags & A.BAM_FSECONDARY);
1012
+ }
1013
+ isFailedQc() {
1014
+ return !!(this.flags & A.BAM_FQCFAIL);
1015
+ }
1016
+ isDuplicate() {
1017
+ return !!(this.flags & A.BAM_FDUP);
1018
+ }
1019
+ isSupplementary() {
1020
+ return !!(this.flags & A.BAM_FSUPPLEMENTARY);
1021
+ }
1022
+ _isCGTagPattern(e, t) {
1023
+ if (t === 2) {
1024
+ let t = this._dataView.getInt32(e, !0);
1025
+ return (t & 15) == 4 && t >> 4 === this.seq_length;
1026
+ }
1027
+ return !1;
1028
+ }
1029
+ _computeLengthOnRef() {
1030
+ let e = this._dataView.getInt32(this._start + 16, !0);
1031
+ if (e & A.BAM_FUNMAP << 16) return 0;
1032
+ let t = e & 65535, n = this.b0 + this.read_name_length;
1033
+ if (this._isCGTagPattern(n, t)) {
1034
+ let e = this._dataView.getInt32(n + 4, !0);
1035
+ return (e & 15) != 3 && console.warn("CG tag with no N tag"), e >> 4;
1036
+ }
1037
+ let r = this._byteArray.byteOffset + n;
1038
+ if (r % 4 == 0 && t > 50) {
1039
+ let e = new Uint32Array(this._byteArray.buffer, r, t);
1040
+ this._cachedNumericCigar = e;
1041
+ let n = 0;
1042
+ for (let r = 0; r < t; ++r) {
1043
+ let t = e[r];
1044
+ n += (t >> 4) * (H >> (t & 15) & 1);
1045
+ }
1046
+ return n;
1047
+ }
1048
+ let i = 0;
1049
+ for (let e = 0; e < t; ++e) {
1050
+ let t = this._dataView.getInt32(n + e * 4, !0);
1051
+ i += (t >> 4) * (H >> (t & 15) & 1);
1052
+ }
1053
+ return i;
1054
+ }
1055
+ _computeNumericCigar() {
1056
+ let e = this._dataView.getInt32(this._start + 16, !0) & 65535, t = this.b0 + this.read_name_length;
1057
+ if (this._isCGTagPattern(t, e)) {
1058
+ let e = this.getTag("CG");
1059
+ return ge(e) ? e : /* @__PURE__ */ new Uint32Array();
1060
+ }
1061
+ let n = this._byteArray.byteOffset + t;
1062
+ if (n % 4 == 0 && e > 50) return new Uint32Array(this._byteArray.buffer, n, e);
1063
+ let r = Array(e);
1064
+ for (let n = 0; n < e; ++n) r[n] = this._dataView.getInt32(t + n * 4, !0) | 0;
1065
+ return r;
1066
+ }
1067
+ get length_on_ref() {
1068
+ return this._cachedLengthOnRef === void 0 && (this._cachedLengthOnRef = this._computeLengthOnRef()), this._cachedLengthOnRef;
1069
+ }
1070
+ get NUMERIC_CIGAR() {
1071
+ return this._cachedNumericCigar === void 0 && (this._cachedNumericCigar = this._computeNumericCigar()), this._cachedNumericCigar;
1072
+ }
1073
+ get CIGAR() {
1074
+ let e = this.NUMERIC_CIGAR, t = "";
1075
+ for (let n = 0, r = e.length; n < r; n++) {
1076
+ let r = e[n];
1077
+ t += r >> 4, t += String.fromCharCode(z[r & 15]);
1078
+ }
1079
+ return t;
1080
+ }
1081
+ get num_cigar_ops() {
1082
+ return this.flag_nc & 65535;
1083
+ }
1084
+ get num_cigar_bytes() {
1085
+ return this.num_cigar_ops << 2;
1086
+ }
1087
+ get read_name_length() {
1088
+ return this.bin_mq_nl & 255;
1089
+ }
1090
+ get num_seq_bytes() {
1091
+ return this.seq_length + 1 >> 1;
1092
+ }
1093
+ get NUMERIC_SEQ() {
1094
+ let e = this.seqStart;
1095
+ return this._byteArray.subarray(e, e + this.num_seq_bytes);
1096
+ }
1097
+ get seq() {
1098
+ let e = this.seq_length, t = this._byteArray, n = this.seqStart, r = e >> 1, i;
1099
+ if (e < ue) {
1100
+ let a = L();
1101
+ if (i = "", a === void 0) for (let e = 0; e < r; e++) i += F[t[n + e]];
1102
+ else {
1103
+ let e = r >> 1;
1104
+ for (let r = 0; r < e; r++) {
1105
+ let e = n + 2 * r;
1106
+ i += a[t[e] << 8 | t[e + 1]];
1107
+ }
1108
+ r & 1 && (i += F[t[n + r - 1]]);
1109
+ }
1110
+ e & 1 && (i += M[(t[n + r] & 240) >> 4]);
1111
+ } else {
1112
+ let a = new Uint8Array(e + 1 & -2), o = new Uint16Array(a.buffer);
1113
+ for (let e = 0; e < r; e++) o[e] = P[t[n + e]];
1114
+ e & 1 && (a[e - 1] = N[(t[n + r] & 240) >> 4]), i = B.decode(a.subarray(0, e));
1115
+ }
1116
+ return i;
1117
+ }
1118
+ get pair_orientation() {
1119
+ let e = this.flags;
1120
+ if (!(e & A.BAM_FPAIRED)) return;
1121
+ let t = this.ref_id, n = this.next_refid, r = this.start, i = this.next_pos, a = t === n ? r === i ? !!(e & A.BAM_FREAD1) : r < i : t < n;
1122
+ return R[e >> 4 & 7 | (a ? 8 : 0)];
1123
+ }
1124
+ get bin_mq_nl() {
1125
+ return this._dataView.getInt32(this._start + 12, !0);
1126
+ }
1127
+ get flag_nc() {
1128
+ return this._dataView.getInt32(this._start + 16, !0);
1129
+ }
1130
+ get seq_length() {
1131
+ return this._dataView.getInt32(this._start + 20, !0);
1132
+ }
1133
+ get next_refid() {
1134
+ return this._dataView.getInt32(this._start + 24, !0);
1135
+ }
1136
+ get next_pos() {
1137
+ return this._dataView.getInt32(this._start + 28, !0);
1138
+ }
1139
+ get template_length() {
1140
+ return this._dataView.getInt32(this._start + 32, !0);
1141
+ }
1142
+ seqAt(e) {
1143
+ if (e < this.seq_length) {
1144
+ let t = this._byteArray[this.seqStart + (e >> 1)];
1145
+ return e & 1 ? M[t & 15] : M[(t & 240) >> 4];
1146
+ }
1147
+ }
1148
+ toJSON() {
1149
+ return {
1150
+ fileOffset: this.fileOffset,
1151
+ ref_id: this.ref_id,
1152
+ start: this.start,
1153
+ end: this.end,
1154
+ name: this.name,
1155
+ flags: this.flags,
1156
+ mq: this.mq,
1157
+ CIGAR: this.CIGAR,
1158
+ seq: this.seq,
1159
+ next_refid: this.next_refid,
1160
+ next_pos: this.next_pos,
1161
+ template_length: this.template_length,
1162
+ tags: this.tags
1163
+ };
1164
+ }
1165
+ };
1166
+ //#endregion
1167
+ //#region ../../node_modules/@gmod/bam/esm/sam.js
1168
+ function ye(e) {
1169
+ let t = e.split(/\r?\n/), n = [];
1170
+ for (let e of t) {
1171
+ let [t, ...r] = e.split(/\t/);
1172
+ t && n.push({
1173
+ tag: t.slice(1),
1174
+ data: r.map((e) => {
1175
+ let t = e.indexOf(":");
1176
+ return t === -1 ? {
1177
+ tag: e,
1178
+ value: ""
1179
+ } : {
1180
+ tag: e.slice(0, t),
1181
+ value: e.slice(t + 1)
1182
+ };
1183
+ })
1184
+ });
1185
+ }
1186
+ return n;
1187
+ }
1188
+ var K = 65536, be = 33554432;
1189
+ function q(n, r, i) {
1190
+ return n ?? (r ? new e(r) : i ? new t(i) : void 0);
1191
+ }
1192
+ function J(e, t, n) {
1193
+ let r = e?.[0];
1194
+ return !!r && (r.ref_id > t || r.ref_id === t && r.start >= n);
1195
+ }
1196
+ function Y(e) {
1197
+ let { minv: t, maxv: n } = e;
1198
+ return `${t.blockPosition}:${t.dataPosition}-${n.blockPosition}:${n.dataPosition}`;
1199
+ }
1200
+ var X = 104857600, Z = 6, xe = class {
1201
+ _maxBytes;
1202
+ entries = /* @__PURE__ */ new Map();
1203
+ bytes = 0;
1204
+ constructor(e) {
1205
+ this._maxBytes = e;
1206
+ }
1207
+ get maxBytes() {
1208
+ return this._maxBytes;
1209
+ }
1210
+ set maxBytes(e) {
1211
+ this._maxBytes = e, this.evict();
1212
+ }
1213
+ get size() {
1214
+ return this.entries.size;
1215
+ }
1216
+ get byteSize() {
1217
+ return this.bytes;
1218
+ }
1219
+ get(e) {
1220
+ let t = this.entries.get(e);
1221
+ return t && (this.entries.delete(e), this.entries.set(e, t)), t;
1222
+ }
1223
+ set(e, t) {
1224
+ this.delete(e), this.entries.set(e, t), this.bytes += t.bytes, this.evict();
1225
+ }
1226
+ evict() {
1227
+ let e = this.entries.keys();
1228
+ for (; this.bytes > this._maxBytes && this.entries.size > 1;) this.delete(e.next().value);
1229
+ }
1230
+ delete(e) {
1231
+ let t = this.entries.get(e);
1232
+ t && (this.entries.delete(e), this.bytes -= t.bytes);
1233
+ }
1234
+ clear() {
1235
+ this.entries.clear(), this.bytes = 0;
1236
+ }
1237
+ [Symbol.iterator]() {
1238
+ return this.entries[Symbol.iterator]();
1239
+ }
1240
+ }, Q = class {
1241
+ renameRefSeq;
1242
+ bam;
1243
+ header;
1244
+ chrToIndex;
1245
+ indexToChr;
1246
+ index;
1247
+ htsget = !1;
1248
+ headerP;
1249
+ chunkFeatureCache;
1250
+ inFlightChunks = /* @__PURE__ */ new Map();
1251
+ RecordClass;
1252
+ constructor({ bamFilehandle: e, bamPath: t, bamUrl: n, baiPath: r, baiFilehandle: i, baiUrl: a, csiPath: o, csiFilehandle: s, csiUrl: c, htsget: l, renameRefSeqs: u = (e) => e, recordClass: d, maxCacheBytes: f = X }) {
1253
+ this.renameRefSeq = u, this.RecordClass = d ?? G, this.chunkFeatureCache = new xe(f);
1254
+ let p = q(e, t, n);
1255
+ if (p) this.bam = p;
1256
+ else if (l) this.htsget = !0, this.bam = new ce();
1257
+ else throw Error("no bam source: pass bamFilehandle, bamPath, bamUrl, or htsget: true");
1258
+ let m = q(s, o, c), h = q(i, r, a) ?? q(void 0, t ? `${t}.bai` : void 0, n ? `${n}.bai` : void 0);
1259
+ if (m) this.index = new k({ filehandle: m });
1260
+ else if (h) this.index = new T({ filehandle: h });
1261
+ else if (!l) throw Error("no index source: pass csi*/bai* options or a bamPath/bamUrl so the .bai sibling can be inferred");
1262
+ }
1263
+ async getHeaderPre(e = {}) {
1264
+ if (!this.index) throw Error("no index to read a header from: use HtsgetFile for htsget sources");
1265
+ let t = await this.index.parse(e), n = t.firstDataLine === void 0 ? K : t.firstDataLine.blockPosition + K, i, a;
1266
+ do {
1267
+ let t = await this.bam.read(n, 0, { signal: e.signal });
1268
+ a = t.length < n, i = this.applyHeader(await r(t)), n *= 2;
1269
+ } while (i === void 0 && !a && n <= be);
1270
+ if (i === void 0) throw Error("Insufficient data for reference sequences");
1271
+ return i;
1272
+ }
1273
+ applyHeader(e) {
1274
+ let t = new DataView(e.buffer, e.byteOffset, e.byteLength);
1275
+ if (t.getInt32(0, !0) !== 21840194) throw Error("Not a BAM file");
1276
+ let n = t.getInt32(4, !0), r = p(e, n + 8, this.renameRefSeq), i;
1277
+ if (r) {
1278
+ let t = new TextDecoder("utf8").decode(e.subarray(8, 8 + n));
1279
+ this.header = t, this.chrToIndex = r.chrToIndex, this.indexToChr = r.indexToChr, i = ye(t);
1280
+ }
1281
+ return i;
1282
+ }
1283
+ getHeader(e) {
1284
+ return this.headerP ||= this.getHeaderPre(e).catch((e) => {
1285
+ throw this.headerP = void 0, e;
1286
+ }), this.headerP;
1287
+ }
1288
+ async getHeaderText(e = {}) {
1289
+ return await this.getHeader(e), this.header;
1290
+ }
1291
+ async getSeqId(e, t) {
1292
+ return await this.getHeader(t), this.chrToIndex?.[e];
1293
+ }
1294
+ async getRecordsForRange(e, t, n, r) {
1295
+ c(r?.signal);
1296
+ let i = await this.getSeqId(e, r);
1297
+ if (i === void 0 || !this.index) return [];
1298
+ let a = await this.index.blocksForRange(i, t - 1, n, r);
1299
+ return this._fetchChunkFeatures(a, i, t, n, r);
1300
+ }
1301
+ _startChunkRead(e, t) {
1302
+ let n = new AbortController(), r = this._readChunkFeatures(t, { signal: n.signal }).then((t) => (this.chunkFeatureCache.set(e, t), t)), i = {
1303
+ promise: r,
1304
+ signals: /* @__PURE__ */ new Set(),
1305
+ pinned: !1,
1306
+ controller: n,
1307
+ dispose: new AbortController(),
1308
+ settled: !1
1309
+ };
1310
+ this.inFlightChunks.set(e, i);
1311
+ let a = () => {
1312
+ i.settled = !0, i.dispose.abort(), i.signals.clear(), this.inFlightChunks.get(e) === i && this.inFlightChunks.delete(e);
1313
+ };
1314
+ return r.then(a, a), i;
1315
+ }
1316
+ joinChunkRead(e, t) {
1317
+ t === void 0 ? e.pinned = !0 : t.aborted ? !e.pinned && e.signals.size === 0 && e.controller.abort(t.reason) : e.signals.has(t) || (e.signals.add(t), t.addEventListener("abort", () => {
1318
+ e.signals.delete(t), !e.pinned && e.signals.size === 0 && e.controller.abort(t.reason);
1319
+ }, {
1320
+ once: !0,
1321
+ signal: e.dispose.signal
1322
+ }));
1323
+ }
1324
+ async _cachedChunkFeatures(e, t) {
1325
+ c(t.signal);
1326
+ let n = Y(e), r = this.chunkFeatureCache.get(n);
1327
+ if (r) return r.features;
1328
+ let i = this.inFlightChunks.get(n);
1329
+ i?.controller.signal.aborted && !i.settled && (this.inFlightChunks.get(n) === i && this.inFlightChunks.delete(n), i = void 0), i ??= this._startChunkRead(n, e), i.settled || this.joinChunkRead(i, t.signal);
1330
+ try {
1331
+ let e = await i.promise;
1332
+ return c(t.signal), e.features;
1333
+ } catch (e) {
1334
+ throw c(t.signal), e;
1335
+ }
1336
+ }
1337
+ async _fetchChunkFeatures(e, t, n, r, i = {}) {
1338
+ let { viewAsPairs: a, onProgress: o } = i, s = [], c = 0;
1339
+ for (let t = 0, n = e.length; t < n; t++) c += e[t].fetchedSize();
1340
+ let l = 0;
1341
+ o?.(0, c);
1342
+ let u = Array(e.length);
1343
+ if (e.length === 1) u[0] = await this._cachedChunkFeatures(e[0], i), o?.(c, c);
1344
+ else {
1345
+ let n = async (t) => {
1346
+ let n = e[t];
1347
+ u[t] = await this._cachedChunkFeatures(n, i), l += n.fetchedSize(), o?.(l, c);
1348
+ }, a = Math.min(Z, e.length);
1349
+ await Promise.all(Array.from({ length: a }, (e, t) => n(t)));
1350
+ let s = !1;
1351
+ for (let e = 0; e < a; e++) if (J(u[e], t, r)) {
1352
+ s = !0;
1353
+ break;
1354
+ }
1355
+ if (!s && e.length > a) {
1356
+ let t = a, r = async () => {
1357
+ for (; t < e.length;) await n(t++);
1358
+ }, i = Math.min(Z, e.length - a);
1359
+ await Promise.all(Array.from({ length: i }, () => r()));
1360
+ }
1361
+ o?.(c, c);
1362
+ }
1363
+ for (let i = 0, a = e.length; i < a; i++) {
1364
+ let e = u[i];
1365
+ e && v(e, t, n, r, s);
1366
+ }
1367
+ if (a) {
1368
+ let e = await this.fetchPairs(t, s, i);
1369
+ for (let t = 0, n = e.length; t < n; t++) s.push(e[t]);
1370
+ }
1371
+ return s;
1372
+ }
1373
+ async fetchPairs(e, t, n) {
1374
+ let { pairAcrossChr: r, maxInsertSize: i = 2e5 } = n, a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set();
1375
+ for (let e = 0, n = t.length; e < n; e++) {
1376
+ let n = t[e], r = n.name;
1377
+ a.set(r, (a.get(r) ?? 0) + 1), o.add(n.fileOffset);
1378
+ }
1379
+ let s = [];
1380
+ for (let o = 0, c = t.length; o < c; o++) {
1381
+ let c = t[o], l = c.name;
1382
+ this.index && a.get(l) === 1 && (r || c.next_refid === e && Math.abs(c.start - c.next_pos) < i) && s.push(this.index.blocksForRange(c.next_refid, c.next_pos, c.next_pos + 1, n));
1383
+ }
1384
+ let c = /* @__PURE__ */ new Map(), l = await Promise.all(s);
1385
+ for (let e = 0, t = l.length; e < t; e++) {
1386
+ let t = l[e];
1387
+ for (let e = 0, n = t.length; e < n; e++) {
1388
+ let n = t[e];
1389
+ c.set(Y(n), n);
1390
+ }
1391
+ }
1392
+ let u = [...c.values()], d = Array(u.length), f = 0, p = async () => {
1393
+ for (; f < u.length;) {
1394
+ let e = f++, t = await this._cachedChunkFeatures(u[e], n), r = [];
1395
+ for (let e = 0, n = t.length; e < n; e++) {
1396
+ let n = t[e];
1397
+ !o.has(n.fileOffset) && a.get(n.name) === 1 && r.push(n);
1398
+ }
1399
+ d[e] = r;
1400
+ }
1401
+ }, m = Math.min(Z, u.length);
1402
+ return await Promise.all(Array.from({ length: m }, () => p())), d.flat();
1403
+ }
1404
+ async _readChunkFeatures(e, t) {
1405
+ let n = await this.bam.read(e.fetchedSize(), e.minv.blockPosition, { signal: t.signal });
1406
+ c(t.signal);
1407
+ let { buffer: r, cpositions: a, dpositions: o } = await i(n, e);
1408
+ return {
1409
+ features: this.readBamFeatures(r, a, o, e),
1410
+ bytes: r.byteLength
1411
+ };
1412
+ }
1413
+ readBamFeatures(e, t, n, r) {
1414
+ let i = 0, a = [], o = 0, s = new DataView(e.buffer, e.byteOffset, e.byteLength), c = n.length > 0, l = t.length > 0;
1415
+ for (; i + 4 < e.length;) {
1416
+ let u = s.getInt32(i, !0), d = i + 4 + u - 1;
1417
+ if (c) {
1418
+ let e = i + r.minv.dataPosition;
1419
+ for (; o < n.length && e >= n[o];) o++;
1420
+ }
1421
+ if (d < e.length) {
1422
+ let c = new this.RecordClass(e, i, d, l ? t[o] * 256 + (i - n[o]) + r.minv.dataPosition + 1 : ie(e.subarray(i, d)) >>> 0, s);
1423
+ a.push(c);
1424
+ }
1425
+ i = d + 1;
1426
+ }
1427
+ return a;
1428
+ }
1429
+ async hasRefSeq(e, t) {
1430
+ let n = await this.getSeqId(e, t);
1431
+ return !this.index || n === void 0 ? !1 : this.index.hasRefSeq(n);
1432
+ }
1433
+ async lineCount(e, t) {
1434
+ let n = await this.getSeqId(e, t);
1435
+ return !this.index || n === void 0 ? 0 : this.index.lineCount(n);
1436
+ }
1437
+ async indexCov(e, t, n) {
1438
+ let r = await this.getSeqId(e);
1439
+ return !this.index || r === void 0 ? [] : this.index.indexCov(r, t, n);
1440
+ }
1441
+ async blocksForRange(e, t, n, r) {
1442
+ let i = await this.getSeqId(e, r);
1443
+ return !this.index || i === void 0 ? [] : this.index.blocksForRange(i, t, n, r);
1444
+ }
1445
+ clearFeatureCache() {
1446
+ this.chunkFeatureCache.clear();
1447
+ }
1448
+ async estimatedBytesForRegions(e, t) {
1449
+ if (!this.index) return 0;
1450
+ await this.getHeader(t);
1451
+ let n = e.flatMap((e) => {
1452
+ let t = this.chrToIndex?.[e.refName];
1453
+ return t === void 0 ? [] : [{
1454
+ refId: t,
1455
+ start: e.start,
1456
+ end: e.end
1457
+ }];
1458
+ });
1459
+ return this.index.estimatedBytesForRegions(n, t);
1460
+ }
1461
+ };
1462
+ //#endregion
1463
+ //#region ../../node_modules/@gmod/bam/esm/htsget.js
1464
+ function Se(e) {
1465
+ let t;
1466
+ try {
1467
+ t = JSON.parse(e);
1468
+ } catch {}
1469
+ let n = t?.htsget;
1470
+ return n?.error === void 0 ? e : n.message === void 0 ? n.error : `${n.error}: ${n.message}`;
1471
+ }
1472
+ function Ce(e) {
1473
+ let t = new DataView(e.buffer, e.byteOffset, e.byteLength);
1474
+ if (e.byteLength < 8 || t.getInt32(0, !0) !== 21840194) return 0;
1475
+ let n = p(e, 8 + t.getInt32(4, !0), (e) => e);
1476
+ if (!n) throw Error("truncated BAM header in htsget response");
1477
+ return n.end;
1478
+ }
1479
+ async function $(e, t, n) {
1480
+ let r = await e(t, n);
1481
+ if (!r.ok) throw Error(`HTTP ${r.status} fetching ${t}: ${Se(await r.text())}`);
1482
+ return r;
1483
+ }
1484
+ async function we(e, { url: t, headers: n }, r) {
1485
+ let { referer: i, ...a } = n ?? {}, o = t.startsWith("data:") ? await $(e, t) : await $(e, t, {
1486
+ ...r,
1487
+ headers: a
1488
+ });
1489
+ return new Uint8Array(await o.arrayBuffer());
1490
+ }
1491
+ async function Te(e, t, n) {
1492
+ return g(await Promise.all(t.map(async (t) => r(await we(e, t, n)))));
1493
+ }
1494
+ var Ee = class extends Q {
1495
+ baseUrl;
1496
+ trackId;
1497
+ fetchFn;
1498
+ constructor(e) {
1499
+ super({
1500
+ htsget: !0,
1501
+ recordClass: e.recordClass
1502
+ }), this.baseUrl = e.baseUrl, this.trackId = e.trackId, this.fetchFn = e.fetch ?? ((e, t) => fetch(e, t));
1503
+ }
1504
+ async fetchTicket(e, t) {
1505
+ let n = `${this.baseUrl}/${this.trackId}?${e}`, r = await (await $(this.fetchFn, n, { signal: t?.signal })).json();
1506
+ return Te(this.fetchFn, r.htsget.urls, { signal: t?.signal });
1507
+ }
1508
+ async getRecordsForRange(e, t, n, r) {
1509
+ await this.getHeader(r);
1510
+ let i = this.chrToIndex?.[e];
1511
+ if (i === void 0) return [];
1512
+ let s = await this.fetchTicket(`referenceName=${e}&start=${t}&end=${n}&format=BAM`, r), c = new o(0, 0);
1513
+ return v(this.readBamFeatures(s.subarray(Ce(s)), [], [], new a(c, c, 0)), i, t, n);
1514
+ }
1515
+ async getHeaderPre(e = {}) {
1516
+ let t = await this.fetchTicket("class=header&format=BAM", e), n = this.applyHeader(t);
1517
+ if (!n) throw Error("Insufficient data for reference sequences");
1518
+ return n;
1519
+ }
1520
+ };
1521
+ //#endregion
1522
+ export { T as BAI, Q as BamFile, G as BamRecord, k as CSI, X as DEFAULT_MAX_CACHE_BYTES, Ee as HtsgetFile };