@genome-spy/app 1.1.1 → 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 (96) 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-sPuuT0KS.js → agentApi-BclFF9zB.js} +9981 -8914
  4. package/dist/agentApi.es.js +6783 -5135
  5. package/dist/agentShared.es.js +433 -460
  6. package/dist/arrayUtils-Bm7QnzhN.js +1306 -0
  7. package/dist/{blosc-JROzDOnd.js → blosc-C-W97QwH.js} +3 -3
  8. package/dist/{canvas2d-iDK4BC5j.js → canvas2d-8MSf70d4.js} +141 -134
  9. package/dist/{canvas2d-MXaFeZnP.js → canvas2d-BwGNI_Rx.js} +147 -141
  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/{viewIdentityRegistry-BIYd4TE0.js → containerView-BItRtKqu.js} +28 -31
  16. package/dist/{viewIdentityRegistry-BDKkEjXl.js → containerView-CWa6ZIJW.js} +28 -31
  17. package/dist/{debug-DbigmdrK.js → debug-23s-jja_.js} +10 -9
  18. package/dist/{debug-BlqDxTw3.js → debug-CWRxvAss.js} +9 -10
  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 +4766 -5522
  39. package/dist/index.js +1089 -685
  40. package/dist/inflate-BdC5KvHn.js +886 -0
  41. package/dist/{lz4-CUYSbVey.js → lz4-BLPgBOlE.js} +1 -1
  42. package/dist/markUtils-RaatLEa-.js +78 -0
  43. package/dist/{metadataChannels-DV62inJh.js → metadataChannels-DLSmx7kU.js} +6 -3
  44. package/dist/metadataUtils-DxEPe0vj.js +879 -0
  45. package/dist/order-BnKzKjt4.js +1151 -0
  46. package/dist/order-BpJnq_nV.js +1150 -0
  47. package/dist/{parquetRead-0hFIa3Cc.js → parquetRead-D-yY8njE.js} +3 -11
  48. package/dist/{rasterExport-B62RmAK1.js → rasterExport-B-WrX1pa.js} +5 -5
  49. package/dist/{rasterExport-DQH3hVg_.js → rasterExport-C_vx4Jwd.js} +4 -4
  50. package/dist/{rasterization-B05bDo5e.js → rasterization-QktH8Sn2.js} +26 -19
  51. package/dist/rectangle-BAdoDPXu.js +194 -0
  52. package/dist/{rectangle-DE98gIxF.js → rectangle-DZTR6NFQ.js} +10 -1
  53. package/dist/renderCanvas2D-CsRO78Pq.js +291 -0
  54. package/dist/{renderCanvas2D-Bdv-B4wj.js → renderCanvas2D-Y7pkRzbC.js} +98 -92
  55. package/dist/{rolldown-runtime-DF993M8W.js → rolldown-runtime-DeIk2rA4.js} +1 -1
  56. package/dist/{indexer-DbFTKGlm.js → scaleNull-CVzag4z8.js} +2 -12
  57. package/dist/{indexer-En7gpvLN.js → scaleNull-Pbz7QGnl.js} +2 -12
  58. package/dist/{scalePosition-ByvlXaML.js → scalePosition-CRXa0rCC.js} +8 -1
  59. package/dist/schema.json +33403 -16929
  60. package/dist/style.css +1 -1
  61. package/dist/{svg-N3tj05-e.js → svg-BBMtLgtM.js} +445 -362
  62. package/dist/{svg-DHsq1RpV.js → svg-JjWL6U-T.js} +464 -381
  63. package/dist/{svgRasterizer-CYVDlt5z.js → svgRasterizer-6OcftuoI.js} +3 -3
  64. package/dist/{svgRasterizer-CvCBlxLj.js → svgRasterizer-DkNRaCPs.js} +4 -4
  65. package/dist/tableMetadataSourceAdapter-CUNwLsdi.js +291 -0
  66. package/dist/tableMetadataSourceAdapter-DQrEXCo6.js +1283 -0
  67. package/dist/url-DeOdSRrv.js +183 -0
  68. package/dist/viewError-B0TMfOpB.js +33 -0
  69. package/dist/viewError-D9aO90cI.js +33 -0
  70. package/dist/{viewSelectors-DDLW-byr.js → viewSelectors-DkFvo33d.js} +914 -752
  71. package/dist/{viewSelectors-j-F9XwsE.js → viewSelectors-lM93fHAq.js} +942 -780
  72. package/dist/viewUtils-0SJOewM6.js +6195 -0
  73. package/dist/webgl-CXIO3OQz.js +5782 -0
  74. package/dist/webgl-Pdvfhio5.js +5783 -0
  75. package/package.json +7 -5
  76. package/src/agentApi/index.d.ts +3 -2
  77. package/src/agentShared/index.d.ts +2 -0
  78. package/src/appTypes.d.ts +1 -6
  79. package/src/embedTypes.d.ts +36 -1
  80. package/src/index.d.ts +6 -0
  81. package/src/spec/sampleView.d.ts +68 -13
  82. package/src/spec/view.d.ts +44 -5
  83. package/src/state/paramProvenanceTypes.d.ts +25 -2
  84. package/src/state.d.ts +14 -52
  85. package/dist/clipOptions-B5PibDq3.js +0 -2923
  86. package/dist/clipOptions-Cba4I0AO.js +0 -2903
  87. package/dist/esm-Dndm-NaA.js +0 -1193
  88. package/dist/order-B4uR9Q04.js +0 -1062
  89. package/dist/order-BSPy5DI8.js +0 -1062
  90. package/dist/renderCanvas2D-ChdoHGrU.js +0 -285
  91. package/dist/vega-scale-Byaw1K8O.js +0 -2446
  92. package/dist/vega-scale-Ctz_wa3z.js +0 -2443
  93. package/dist/viewError-BiR9VCgL.js +0 -29
  94. package/dist/viewUtils-JX6CMEYH.js +0 -6664
  95. package/dist/webgl-DdmOwEH0.js +0 -5544
  96. package/dist/webgl-Dw8xqZpX.js +0 -5544
@@ -0,0 +1,1501 @@
1
+ import { r as e } from "./esm-C6erfjPM.js";
2
+ import { t } from "./SharedReadCache-9sT2aIxW.js";
3
+ import { t as n } from "./inflate-BdC5KvHn.js";
4
+ //#region ../../node_modules/@genome-spy/figwig/dist/utils/binary.js
5
+ var r = class extends Error {
6
+ constructor(e, t) {
7
+ super(`Figwig: ${e}`, t), this.name = "FigWigError";
8
+ }
9
+ };
10
+ function i(e, t) {
11
+ if (!e) throw new r(t);
12
+ }
13
+ function a(e, t) {
14
+ return i(e <= BigInt(2 ** 53 - 1), `${t} exceeds Number.MAX_SAFE_INTEGER`), Number(e);
15
+ }
16
+ var o = class {
17
+ bytes;
18
+ view;
19
+ at = 0;
20
+ constructor(e) {
21
+ this.bytes = e, this.view = new DataView(e.buffer, e.byteOffset, e.byteLength);
22
+ }
23
+ need(e) {
24
+ i(Number.isSafeInteger(e) && e >= 0 && this.at + e <= this.bytes.length, "truncated or invalid binary structure");
25
+ }
26
+ u16() {
27
+ this.need(2);
28
+ let e = this.view.getUint16(this.at, !0);
29
+ return this.at += 2, e;
30
+ }
31
+ u32() {
32
+ this.need(4);
33
+ let e = this.view.getUint32(this.at, !0);
34
+ return this.at += 4, e;
35
+ }
36
+ u64(e = "uint64 value") {
37
+ this.need(8);
38
+ let t = a(this.view.getBigUint64(this.at, !0), e);
39
+ return this.at += 8, t;
40
+ }
41
+ f64() {
42
+ this.need(8);
43
+ let e = this.view.getFloat64(this.at, !0);
44
+ return this.at += 8, e;
45
+ }
46
+ take(e) {
47
+ this.need(e);
48
+ let t = this.bytes.subarray(this.at, this.at + e);
49
+ return this.at += e, t;
50
+ }
51
+ }, s = Uint32Array.from({ length: 256 }, (e, t) => {
52
+ let n = t;
53
+ for (let e = 0; e < 8; e++) n = n & 1 ? 3988292384 ^ n >>> 1 : n >>> 1;
54
+ return n >>> 0;
55
+ });
56
+ function c(e) {
57
+ let t = 4294967295;
58
+ for (let n of e) t = s[(t ^ n) & 255] ^ t >>> 8;
59
+ return (t ^ 4294967295) >>> 0;
60
+ }
61
+ function l(e, t, n) {
62
+ i(c(e) === t, `${n} CRC-32 mismatch`);
63
+ }
64
+ function u(e, t) {
65
+ let n = 0, r = e.length;
66
+ for (; n < r;) {
67
+ let i = n + Math.floor((r - n) / 2);
68
+ e[i] < t ? n = i + 1 : r = i;
69
+ }
70
+ return n;
71
+ }
72
+ function d(e) {
73
+ e?.throwIfAborted();
74
+ }
75
+ var f = new TextDecoder("utf-8", {
76
+ fatal: !0,
77
+ ignoreBOM: !0
78
+ }), p = {
79
+ uint8: 1,
80
+ uint16: 2,
81
+ uint32: 4,
82
+ int8: 1,
83
+ int16: 2,
84
+ int32: 4,
85
+ float32: 4,
86
+ float64: 8
87
+ };
88
+ function m(e) {
89
+ let t = new o(e);
90
+ t.need(128), i(t.u32() === 1464289606, "bad magic; expected FIGW");
91
+ let n = Uint8Array.from(e.subarray(0, 128)), r = new DataView(n.buffer), a = r.getUint32(104, !0);
92
+ r.setUint32(104, 0, !0), l(n, a, "header"), i(t.u16() === 1, "unsupported format version");
93
+ let s = t.u16(), c = t.u32(), u = t.u16(), d = t.u16(), f = t.u32(), p = t.u32(), m = t.u32(), h = t.u32(), g = t.u64("chromosome table offset"), _ = t.u64("statistics offset"), v = t.u64("index offset"), y = t.u64("data offset"), b = t.u64("metadata offset"), x = t.u64("metadata length");
94
+ t.u64("reserved zoom offset");
95
+ let S = t.u64("file length"), C = t.u32(), w = t.u32();
96
+ return i(C === 0, "unsupported required feature bits"), i(!(s & -2), "unsupported header flags"), i(c >= 16 && c <= 65536 && !(c & c - 1), "invalid tile size"), i(u === 0 || u === 1, "unsupported compression codec"), i(y === 128 && S >= 128, "invalid data offset or file length"), i(128 <= g && g <= _ && _ <= b && b <= v && v <= S, "table offsets outside file or out of order"), i(f > 0 && p > 0 && m > 0 && v + m * 8 <= S, "invalid counts or truncated directory"), i(!(s & 1) || m === p, "track order requires one group per track"), i(_ + 32 * p <= b && b + x <= v, "statistics or metadata extend into next table"), {
97
+ bytes: Uint8Array.from(e.subarray(0, 128)),
98
+ flags: s,
99
+ tile: c,
100
+ codec: u,
101
+ level: d,
102
+ nChroms: f,
103
+ nTracks: p,
104
+ nGroups: m,
105
+ tablesCrc: h,
106
+ chroms: g,
107
+ tracks: _,
108
+ index: v,
109
+ metadata: b,
110
+ metadataLength: x,
111
+ length: S,
112
+ optional: w
113
+ };
114
+ }
115
+ function h(e) {
116
+ return typeof e == "object" && !!e && !Array.isArray(e);
117
+ }
118
+ function g(e) {
119
+ let t = [e];
120
+ for (; t.length;) {
121
+ let e = t.pop();
122
+ if (e && typeof e == "object" && !Object.isFrozen(e)) {
123
+ Object.freeze(e);
124
+ for (let n of Object.values(e)) t.push(n);
125
+ }
126
+ }
127
+ return e;
128
+ }
129
+ function _(e, t) {
130
+ l(t, e.tablesCrc, "tables");
131
+ let n = new o(t), a = [], s = /* @__PURE__ */ new Set(), c = 0;
132
+ i(e.nChroms <= Math.floor((e.tracks - e.chroms) / 11), "chromosome count exceeds table bounds");
133
+ for (let t = 0; t < e.nChroms; t++) {
134
+ let o = n.u16();
135
+ i(n.at + o + 8 <= e.tracks - e.chroms, "truncated chromosome table");
136
+ let l = n.take(o), u;
137
+ try {
138
+ u = f.decode(l);
139
+ } catch (e) {
140
+ throw new r("invalid UTF-8 chromosome name", { cause: e });
141
+ }
142
+ let d = n.u64("chromosome length");
143
+ i(u.length > 0 && !s.has(u) && d > 0 && d <= 4294967295, "invalid or duplicate chromosome"), s.add(u);
144
+ let p = Math.ceil(d / e.tile);
145
+ a.push({
146
+ id: t,
147
+ name: u,
148
+ length: d,
149
+ tileOffset: c,
150
+ tileCount: p
151
+ }), c += p;
152
+ }
153
+ i(n.at === e.tracks - e.chroms, "chromosome table extent mismatch"), i(c <= 2 ** 26, "genome exceeds 2**26 tiles");
154
+ let u = [];
155
+ for (let t = 0; t < e.nTracks; t++) u.push({
156
+ sum: n.f64(),
157
+ nonzero: n.u64("nonzero base count"),
158
+ min: n.f64(),
159
+ max: n.f64()
160
+ });
161
+ n.at = e.metadata - e.chroms;
162
+ let d;
163
+ try {
164
+ d = JSON.parse(f.decode(n.take(e.metadataLength)));
165
+ } catch (e) {
166
+ throw new r("invalid JSON metadata", { cause: e });
167
+ }
168
+ i(h(d) && h(d.attributes) && Array.isArray(d.tracks) && d.tracks.length === e.nTracks, "invalid metadata or track count"), i(d.genome === void 0 || d.genome === null || typeof d.genome == "string", "invalid genome identifier");
169
+ let m = Array.from({ length: e.nGroups }, () => []), _ = new Uint32Array(e.nTracks), v = /* @__PURE__ */ new Set(), y = d.tracks.map((t, n) => {
170
+ i(h(t) && typeof t.name == "string" && t.name.length > 0 && !v.has(t.name), "invalid or duplicate track name"), i(typeof t.dtype == "string" && Object.hasOwn(p, t.dtype), "invalid track dtype"), i(typeof t.group == "number" && Number.isInteger(t.group) && t.group >= 0 && t.group < e.nGroups, "invalid track group"), v.add(t.name);
171
+ let r = {
172
+ index: n,
173
+ name: t.name,
174
+ dtype: t.dtype,
175
+ group: t.group,
176
+ metadata: t,
177
+ statistics: u[n]
178
+ };
179
+ return _[n] = m[r.group].length, m[r.group].push(r), r;
180
+ });
181
+ i(m.every((t) => t.length > 0 && t.length <= 2 ** 29 / e.tile && (!(e.flags & 1) || t.length === 1)), "empty or oversized track group"), n.at = e.index - e.chroms;
182
+ let b = [];
183
+ for (let t = 0; t < e.nGroups; t++) {
184
+ let r = n.u64("group index offset");
185
+ i(r >= e.index + 8 * e.nGroups && r < e.length && (t === 0 || r > b[t - 1]), "invalid group directory offsets"), b.push(r);
186
+ }
187
+ return i(b[0] === e.index + 8 * e.nGroups, "index records must follow directory"), {
188
+ header: g({
189
+ version: 1,
190
+ order: e.flags & 1 ? "tracks" : "positions",
191
+ tileSize: e.tile,
192
+ codec: e.codec,
193
+ compressionLevel: e.level,
194
+ genome: d.genome ?? null,
195
+ attributes: d.attributes ?? {},
196
+ metadata: d,
197
+ chromosomes: a,
198
+ tracks: y,
199
+ statistics: u,
200
+ groupCount: e.nGroups,
201
+ length: e.length
202
+ }),
203
+ fixed: e,
204
+ directory: b,
205
+ members: m,
206
+ trackSlots: _,
207
+ nTiles: c
208
+ };
209
+ }
210
+ //#endregion
211
+ //#region ../../node_modules/@genome-spy/figwig/dist/utils/inflate.js
212
+ function v(e, t, a) {
213
+ i(Number.isSafeInteger(t) && t > 0 && t <= a, "inflated allocation exceeds maxInflatedBytes"), i(e.length >= 4 && e[e.length - 4] === 0 && e[e.length - 3] === 0 && e[e.length - 2] === 255 && e[e.length - 1] === 255, "invalid summary restart full-flush marker");
214
+ let o = new Uint8Array(e.length + 2), s = new Uint8Array(t);
215
+ o.set(e), o.set([3, 0], e.length);
216
+ let c = new n({
217
+ raw: !0,
218
+ chunkSize: Math.min(65536, t + 1)
219
+ }), l = 0;
220
+ c.onData = (e) => {
221
+ i(l + e.length <= t, "summary restart expands beyond declared size"), s.set(e, l), l += e.length;
222
+ };
223
+ try {
224
+ c.push(o, !1);
225
+ } catch (e) {
226
+ throw e instanceof r ? e : new r("corrupt summary restart DEFLATE", { cause: e });
227
+ }
228
+ return i(c.err === 0 && c.ended && l === t && c.strm?.next_in === o.length, "corrupt, truncated, trailing, or wrong-sized summary restart"), s;
229
+ }
230
+ function y(e, t, a) {
231
+ i(Number.isSafeInteger(t) && t >= 0 && t <= a, "inflated allocation exceeds maxInflatedBytes"), i(e.length >= 6, "truncated zlib stream");
232
+ let o = e[0], s = e[1];
233
+ i((o & 15) == 8 && o >>> 4 <= 7 && ((o << 8) + s) % 31 == 0 && !(s & 32), "invalid or dictionary-dependent zlib header");
234
+ let c = new Uint8Array(t), l = new n({
235
+ raw: !0,
236
+ chunkSize: Math.min(65536, t + 1),
237
+ windowBits: (o >>> 4) + 8
238
+ }), u = 0, d = 1, f = 0;
239
+ l.onData = (e) => {
240
+ let n = e;
241
+ i(u + n.length <= t, "zlib stream expands beyond its declared size"), c.set(n, u), u += n.length;
242
+ for (let e = 0; e < n.length; e += 5552) {
243
+ let t = Math.min(n.length, e + 5552), r = e;
244
+ for (; r + 8 <= t; r += 8) {
245
+ let e = n[r], t = n[r + 1], i = n[r + 2], a = n[r + 3], o = n[r + 4], s = n[r + 5], c = n[r + 6], l = n[r + 7];
246
+ f += 8 * d + 8 * e + 7 * t + 6 * i + 5 * a + 4 * o + 3 * s + 2 * c + l, d += e + t + i + a + o + s + c + l;
247
+ }
248
+ for (; r < t; r++) d += n[r], f += d;
249
+ d %= 65521, f %= 65521;
250
+ }
251
+ };
252
+ try {
253
+ l.push(e.subarray(2, -4), !1);
254
+ } catch (e) {
255
+ throw e instanceof r ? e : new r("corrupt DEFLATE payload", { cause: e });
256
+ }
257
+ i(l.err === 0 && l.ended && u === t && l.strm?.next_in === e.length - 6, "corrupt, truncated, trailing, or wrong-sized zlib stream");
258
+ let p = new DataView(e.buffer, e.byteOffset + e.length - 4, 4).getUint32(0);
259
+ return i((f << 16 | d) >>> 0 === p, "zlib Adler-32 mismatch"), c;
260
+ }
261
+ //#endregion
262
+ //#region ../../node_modules/@genome-spy/figwig/dist/decoding/chunk.js
263
+ var b = [
264
+ 1,
265
+ 2,
266
+ 4,
267
+ 1,
268
+ 2,
269
+ 4,
270
+ 4,
271
+ 0,
272
+ 8
273
+ ], x = /* @__PURE__ */ new Uint32Array(), S = /* @__PURE__ */ new Float64Array();
274
+ function C(e) {
275
+ throw new r(`corrupt chunk: ${e}`);
276
+ }
277
+ function w(e, t = !1, n) {
278
+ (!Number.isInteger(e) || e < 0 || e > 255) && C("kind byte is outside 0..255");
279
+ let r = e & 7, i = e >>> 3 & 15, a = !!(e & 128);
280
+ return (r < 1 || r > 4 || i > 8) && C("unsupported kind or element code"), t ? (r !== 1 || a) && C("a block must have kind 1 without a stored bit") : (r === 1 || r === 4) && i === 7 && C("dense and runs chunks cannot use implicit-one elements"), n === 0 && a && C("the stored bit is forbidden with codec 0"), {
281
+ kind: r,
282
+ code: i,
283
+ width: b[i],
284
+ stored: a
285
+ };
286
+ }
287
+ function T(e, t) {
288
+ return Math.ceil(e / t) * t;
289
+ }
290
+ function E(e, t) {
291
+ (!Number.isSafeInteger(t) || t < 0 || t > e.byteLength) && C("payload is truncated or its element count is invalid");
292
+ }
293
+ function D(e) {
294
+ return e.byteLength % 8 != 0 && C("payload length is not a multiple of 8"), new DataView(e.buffer, e.byteOffset, e.byteLength);
295
+ }
296
+ function O(e, t, n, r) {
297
+ let i = new Float64Array(n), a = b[r];
298
+ for (let o = 0; o < n; o++, t += a) {
299
+ let n;
300
+ switch (r) {
301
+ case 0:
302
+ n = e.getUint8(t);
303
+ break;
304
+ case 1:
305
+ n = e.getUint16(t, !0);
306
+ break;
307
+ case 2:
308
+ n = e.getUint32(t, !0);
309
+ break;
310
+ case 3:
311
+ n = e.getInt8(t);
312
+ break;
313
+ case 4:
314
+ n = e.getInt16(t, !0);
315
+ break;
316
+ case 5:
317
+ n = e.getInt32(t, !0);
318
+ break;
319
+ case 6:
320
+ n = e.getFloat32(t, !0);
321
+ break;
322
+ case 7:
323
+ n = 1;
324
+ break;
325
+ case 8:
326
+ n = e.getFloat64(t, !0);
327
+ break;
328
+ default: return C("unsupported element code");
329
+ }
330
+ (n === Infinity || n === -Infinity) && C("infinite numeric value"), i[o] = n;
331
+ }
332
+ return i;
333
+ }
334
+ function k(e, t) {
335
+ (!Number.isSafeInteger(e) || e < 1 || !Number.isInteger(t) || t < 16 || t > 65536 || t & t - 1 || e * t > 2 ** 29) && C("invalid track count or tile size");
336
+ }
337
+ function A(e, t) {
338
+ (!Number.isSafeInteger(t) || t < 0 || e > t) && C("decoded allocation exceeds maxDecodedBytes");
339
+ }
340
+ function ee(e, t, n, r, i = 268435456) {
341
+ let a = w(t);
342
+ k(n, r);
343
+ let o = D(e);
344
+ if (A(n * 128, i), a.kind === 1) {
345
+ let t = n * r;
346
+ if (E(e, T(t * a.width, 8)), A(t * 8, i), a.code === 6 || a.code === 8) {
347
+ let e = 0;
348
+ for (; e < t; e++) {
349
+ let t = a.code === 6 ? o.getFloat32(e * 4, !0) : o.getFloat64(e * 8, !0);
350
+ if (!Number.isNaN(t)) break;
351
+ }
352
+ if (e === t) {
353
+ let e = new Uint32Array([0]), t = new Float64Array(n).fill(NaN);
354
+ return {
355
+ tracks: Array.from({ length: n }, (n, r) => ({
356
+ offsets: e,
357
+ values: t.subarray(r, r + 1),
358
+ runs: !0
359
+ })),
360
+ byteLength: e.byteLength + t.byteLength
361
+ };
362
+ }
363
+ }
364
+ let s = O(o, 0, t, a.code);
365
+ return {
366
+ tracks: Array.from({ length: n }, (e, t) => ({ values: s.subarray(t * r, (t + 1) * r) })),
367
+ byteLength: s.byteLength
368
+ };
369
+ }
370
+ if (a.kind === 3) return te(e, o, a, n, r, i);
371
+ E(e, 4 + 4 * n);
372
+ let s = o.getUint32(0, !0);
373
+ s > n * r && C("too many sparse entries or run changes"), A(s * 12, i);
374
+ let c = new Uint32Array(n), l = 4 + 4 * n;
375
+ for (let e = 0; e < n; e++) {
376
+ let t = o.getUint32(4 + e * 4, !0);
377
+ c[e] = t, l += t;
378
+ }
379
+ let u = l - 4 - 4 * n;
380
+ (u < s || u > 3 * s) && C("offset byte lengths do not match the entry count");
381
+ let d = T(l, 4);
382
+ E(e, T(d + s * a.width, 8));
383
+ let f = new Uint32Array(s), p = [], m = 0, h = 4 + 4 * n;
384
+ for (let t = 0; t < n; t++) {
385
+ let n = m, i = h + c[t], o = 0, l = !0;
386
+ for (; h < i;) {
387
+ let t = 0, n = !1;
388
+ for (let r = 0; r < 3; r++) {
389
+ h >= i && C("a varint runs past its track's bytes");
390
+ let a = e[h++];
391
+ if (t += (a & 127) * 2 ** (7 * r), a < 128) {
392
+ n = !0;
393
+ break;
394
+ }
395
+ }
396
+ n || C("a varint is longer than three bytes"), !l && t === 0 && C("sparse offsets or run changes do not strictly ascend"), o += t, (o >= r || m >= s) && C("an offset or entry count is out of bounds"), f[m++] = o, l = !1;
397
+ }
398
+ p.push({
399
+ offsets: f.subarray(n, m),
400
+ values: S,
401
+ ...a.kind === 4 ? { runs: !0 } : {}
402
+ });
403
+ }
404
+ m !== s && C("decoded offsets do not add up to the entry count");
405
+ let g = O(o, d, s, a.code), _ = 0;
406
+ for (let e of p) {
407
+ let t = e.offsets.length;
408
+ e.values = g.subarray(_, _ + t), _ += t;
409
+ }
410
+ return {
411
+ tracks: p,
412
+ byteLength: f.byteLength + g.byteLength
413
+ };
414
+ }
415
+ function te(e, t, n, r, i, a) {
416
+ E(e, 8);
417
+ let o = t.getUint32(0, !0);
418
+ o > r && C("matrix has too many present tracks");
419
+ let s = 4 + 4 * o, c = 8 + 8 * o;
420
+ E(e, c);
421
+ let l = t.getUint32(s + o * 4, !0);
422
+ l > o * i && C("matrix has too many entries"), A(l * 12, a);
423
+ let u = T(c + 2 * l, 4);
424
+ E(e, T(u + l * n.width, 8)), t.getUint32(s, !0) !== 0 && C("matrix first pointer is not zero");
425
+ let d = new Uint32Array(l), f = Array.from({ length: r }, () => ({
426
+ offsets: x,
427
+ values: S
428
+ })), p = -1, m = 0;
429
+ for (let e = 0; e < o; e++) {
430
+ let n = t.getUint32(4 + e * 4, !0);
431
+ (n <= p || n >= r) && C("matrix slots must strictly ascend and be in range");
432
+ let a = t.getUint32(s + (e + 1) * 4, !0);
433
+ (a < m || a > l) && C("matrix pointers must not decrease or exceed the entry count");
434
+ let o = -1;
435
+ for (let e = m; e < a; e++) {
436
+ let n = t.getUint16(c + e * 2, !0);
437
+ (n <= o || n >= i) && C("matrix offsets must strictly ascend and be in range"), d[e] = n, o = n;
438
+ }
439
+ f[n] = {
440
+ offsets: d.subarray(m, a),
441
+ values: S
442
+ }, p = n, m = a;
443
+ }
444
+ let h = O(t, u, l, n.code);
445
+ for (let e = 0; e < o; e++) {
446
+ let n = t.getUint32(4 + e * 4, !0), r = t.getUint32(s + e * 4, !0), i = t.getUint32(s + (e + 1) * 4, !0);
447
+ f[n].values = h.subarray(r, i);
448
+ }
449
+ return {
450
+ tracks: f,
451
+ byteLength: d.byteLength + h.byteLength
452
+ };
453
+ }
454
+ function j(e, t, n, r, i, a = 268435456) {
455
+ let o = w(t, !0);
456
+ (!Number.isInteger(n) || n < 1 || n > 65536 || !Number.isInteger(r) || r < 0 || r > 4294967295 || !Number.isInteger(i) || i < r || i > 4294967295) && C("invalid block entry count or position bounds");
457
+ let s = D(e), c = T(4 * n, 8);
458
+ E(e, T(c + n * o.width, 8)), A(128, a), A(n * 12, a);
459
+ let l = new Uint32Array(n), u = -1;
460
+ for (let e = 0; e < n; e++) {
461
+ let t = s.getUint32(e * 4, !0);
462
+ t <= u && C("block positions do not strictly ascend"), l[e] = t, u = t;
463
+ }
464
+ (l[0] !== r || l[n - 1] !== i) && C("block positions do not match its index record");
465
+ let d = O(s, c, n, o.code);
466
+ return {
467
+ tracks: [{
468
+ offsets: l,
469
+ values: d
470
+ }],
471
+ byteLength: l.byteLength + d.byteLength
472
+ };
473
+ }
474
+ //#endregion
475
+ //#region ../../node_modules/@genome-spy/figwig/dist/format/group.js
476
+ function M(e, t, n) {
477
+ let r = t.fixed;
478
+ i(e.offset >= 128 && e.size > 0 && e.offset <= r.chroms - e.size, "chunk offset or size outside data region"), i(e.raw > 0 && e.raw % 8 == 0 && e.raw <= n && (r.flags === 1 || e.size <= n + 64), "invalid chunk raw size");
479
+ let a = w(e.kind, r.flags === 1, r.codec);
480
+ i(r.codec !== 0 && !a.stored || e.size === e.raw, "stored chunk size differs from raw size");
481
+ }
482
+ function N(e, t, n, r, a) {
483
+ let o = r.fixed, s = [], c = r.members[n].length, d = e.u32(), f = e.u32(), p = [];
484
+ if (o.flags & 1) {
485
+ i(t.length + d * 112 <= a, "parsed block index allocation exceeds maxInflatedBytes"), e.need(d * 40), l(t.subarray(e.at, e.at + d * 40), f, "block index");
486
+ let o;
487
+ for (let t = 0; t < d; t++) {
488
+ let a = e.u32(), c = e.u32(), l = e.u32(), u = e.u32(), d = {
489
+ key: `${n}:${t}`,
490
+ group: n,
491
+ chrom: a,
492
+ first: c,
493
+ last: l,
494
+ n: u,
495
+ offset: e.u64("block offset"),
496
+ size: e.u32(),
497
+ raw: e.u32(),
498
+ kind: e.u32(),
499
+ crc: e.u32()
500
+ };
501
+ i(a < r.header.chromosomes.length && c <= l && l < r.header.chromosomes[a].length && u > 0 && u <= 65536 && u <= l - c + 1, "invalid track block bounds"), i(!o || a > o.chrom || a === o.chrom && c > o.last, "track blocks overlap or are out of order"), M(d, r, 12 * u + 64), o = d, s.push(d);
502
+ }
503
+ let c = [...s].sort((e, t) => e.offset - t.offset);
504
+ for (let e = 1; e < c.length; e++) i(c[e].offset >= c[e - 1].offset + c[e - 1].size, "blocks overlap in file");
505
+ } else {
506
+ e.need(d * 32 + 8), i(t.length + d * 64 <= a, "parsed group index allocation exceeds maxInflatedBytes");
507
+ let m = [];
508
+ for (let t = 0; t < d; t++) m.push({
509
+ first: e.u64("first tile"),
510
+ last: e.u64("last tile"),
511
+ offset: e.u64("run offset"),
512
+ size: e.u64("run size")
513
+ });
514
+ let h = e.u32(), g = e.u32(), _ = e.at;
515
+ i(h <= r.nTiles, "too many live tiles"), i(t.length + h * 128 + d * 64 <= a, "parsed group index allocation exceeds maxInflatedBytes");
516
+ let v = e.take(g);
517
+ l(t.subarray(8, _ + g), f, "group index");
518
+ let b = y(v, h * 17, a), x = new DataView(b.buffer, b.byteOffset, b.byteLength);
519
+ for (let e = 0; e < h; e++) {
520
+ let t = x.getUint32(e * 4, !0);
521
+ i(t < r.nTiles && (e === 0 || t > p[e - 1]), "live tiles out of order or range"), p.push(t), s.push({
522
+ key: `${n}:${e}`,
523
+ group: n,
524
+ tile: t,
525
+ offset: 0,
526
+ kind: b[4 * h + e],
527
+ size: x.getUint32(5 * h + 4 * e, !0),
528
+ raw: x.getUint32(9 * h + 4 * e, !0),
529
+ crc: x.getUint32(13 * h + 4 * e, !0)
530
+ });
531
+ }
532
+ let S = [...m].sort((e, t) => e.first - t.first), C = [...m].sort((e, t) => e.offset - t.offset);
533
+ for (let e = 0; e < m.length; e++) {
534
+ let t = S[e];
535
+ i(t.first <= t.last && t.last < r.nTiles && t.offset >= 128 && t.size > 0 && t.offset <= o.chroms - t.size, "invalid run bounds"), i(e === 0 || t.first > S[e - 1].last, "runs overlap in tile range"), i(e === 0 || C[e].offset >= C[e - 1].offset + C[e - 1].size, "runs overlap in file");
536
+ }
537
+ let w = 0;
538
+ for (let e of S) {
539
+ let t = u(p, e.first), n = u(p, e.last + 1);
540
+ i(t === w && n > t, "run leaves live tiles uncovered");
541
+ let a = e.offset;
542
+ for (let e = t; e < n; e++) {
543
+ let t = s[e];
544
+ t.offset = a, M(t, r, 8 * c * o.tile + 16 * c + 64), a += t.size;
545
+ }
546
+ i(a === e.offset + e.size, "run chunk sizes do not add up"), w = n;
547
+ }
548
+ i(w === h, "live tile has no run");
549
+ }
550
+ return {
551
+ chunks: s,
552
+ tiles: Uint32Array.from(p),
553
+ byteLength: t.length + s.length * 112 + p.length * 4
554
+ };
555
+ }
556
+ function P(e, t, n, r) {
557
+ let a = new o(e), s = N(a, e, t, n, r);
558
+ return i(a.at === e.length, "raw index extent mismatch"), s;
559
+ }
560
+ function F(e, t, n, r) {
561
+ i(Number.isSafeInteger(e) && Number.isSafeInteger(t) && Number.isSafeInteger(n) && Number.isSafeInteger(r) && e >= 0 && t >= e && n >= e && r >= 0 && n <= t - r, "group section outside record bounds");
562
+ }
563
+ async function I(e, t, n, r, a) {
564
+ F(e, t, n, r);
565
+ let s = await a(n, r);
566
+ return i(s.length === r, "truncated group section header"), new o(s);
567
+ }
568
+ async function ne(e, t, n, r) {
569
+ let a = (await I(e, t, e, 8, r)).u32(), o;
570
+ if (n.fixed.flags & 1) o = 8 + a * 40;
571
+ else {
572
+ let s = e + 8 + a * 32, c = await I(e, t, s, 8, r), l = c.u32(), u = c.u32();
573
+ i(l <= n.nTiles, "too many live tiles"), o = s - e + 8 + u;
574
+ }
575
+ return F(e, t, e, o), F(e, t, e + o, 12 + (n.fixed.optional & 1 ? 4 : 0)), o;
576
+ }
577
+ async function re(e, t, n, r, a) {
578
+ F(e, t, e, n);
579
+ let o = e + n, s = [], c = (n, a, c, u) => {
580
+ let d = r.header.chromosomes.reduce((e, t) => e + Math.ceil(t.tileCount / n), 0);
581
+ i(a <= d && (c > 0 || a === 0), "invalid summary count"), i(n === 1 || c > 0, "empty zoom stream"), F(e, t, o, c), c === 0 && l(/* @__PURE__ */ new Uint8Array(), u, "summary"), s.push({
582
+ factor: n,
583
+ n: a,
584
+ binCount: d,
585
+ offset: o,
586
+ size: c,
587
+ checksum: u
588
+ }), o += c;
589
+ }, u = await I(e, t, o, 12, a);
590
+ if (o += 12, c(1, u.u32(), u.u32(), u.u32()), r.fixed.optional & 1) {
591
+ F(e, t, o, 4);
592
+ let n = await I(e, t, o, Math.min(20, t - o), a), r = n.u32();
593
+ o += 4, i(r <= 12, "too many zoom levels"), i(!r || s[0].size > 0, "zoom without summary");
594
+ for (let s = 1; s <= r; s++) {
595
+ let r = s === 1 ? n : await I(e, t, o, 16, a), l = r.u32();
596
+ o += 16, i(l === 4 ** s, "invalid zoom factor"), c(l, r.u32(), r.u32(), r.u32());
597
+ }
598
+ }
599
+ return i(o === t, "group record extent mismatch"), s;
600
+ }
601
+ function ie(e, t, n, r) {
602
+ let a = n.members[t], s = e.factor !== 1;
603
+ if (e.bytes.length === 0) return {
604
+ factor: e.factor,
605
+ binSize: e.factor * n.fixed.tile,
606
+ bins: /* @__PURE__ */ new Uint32Array(),
607
+ sums: /* @__PURE__ */ new Float32Array(),
608
+ tracks: a,
609
+ available: !1
610
+ };
611
+ let c = new o(y(e.bytes, e.n * (4 + (s ? 8 : 4) * a.length), r)), l = new Uint32Array(e.n);
612
+ for (let t = 0; t < e.n; t++) l[t] = c.u32(), i(l[t] < e.binCount && (t === 0 || l[t] > l[t - 1]), "summary bins out of order or range");
613
+ let u = s ? new Float64Array(e.n * a.length) : new Float32Array(e.n * a.length);
614
+ for (let e = 0; e < u.length; e++) c.need(s ? 8 : 4), u[e] = s ? c.f64() : c.view.getFloat32(c.at, !0), s || (c.at += 4);
615
+ return {
616
+ factor: e.factor,
617
+ binSize: e.factor * n.fixed.tile,
618
+ bins: l,
619
+ sums: u,
620
+ tracks: a,
621
+ available: !0
622
+ };
623
+ }
624
+ //#endregion
625
+ //#region ../../node_modules/@genome-spy/figwig/dist/format/summary-index.js
626
+ var L = "org.figwig.summary-restarts", R = 4096;
627
+ function z(e, t, n) {
628
+ let r = Uint8Array.from(e), i = new DataView(r.buffer), a = i.getUint32(t, !0);
629
+ i.setUint32(t, 0, !0), l(r, a, n);
630
+ }
631
+ function B(e, t, n) {
632
+ i(Number.isSafeInteger(t) && Number.isSafeInteger(n) && n >= 0 && t >= e.firstData && t <= e.end - n, "summary restart directory extent outside data region");
633
+ }
634
+ function V(e) {
635
+ if (!(e.fixed.optional & 2)) return;
636
+ let t = e.header.metadata[L];
637
+ if (!t || typeof t != "object" || Array.isArray(t)) return;
638
+ let n = t;
639
+ if (n.version === 2) return i(n.length === 256 && Number.isSafeInteger(n.offset) && n.offset >= 128 && n.offset <= e.fixed.chroms - 256, "invalid summary restart locator"), n.offset;
640
+ }
641
+ function H(e, t, n) {
642
+ i(e.length === 256, "invalid summary restart root length");
643
+ let r = new o(e);
644
+ if (i(r.u32() === 1397905222 && r.u32() === 3231061, "invalid summary restart root magic"), i(r.u16() === 2 && r.u16() === 256, "unsupported summary restart root"), z(e, 12, "summary restart root"), i(e.subarray(36, 64).every((e) => e === 0) && e.subarray(192).every((e) => e === 0), "nonzero summary restart reserved fields"), !n.fixed.bytes.every((t, n) => t === e[64 + n])) return;
645
+ r.at = 16;
646
+ let a = r.u64("summary restart directory"), s = r.u32(), c = r.u32(), l = r.u32(), u = a + 32 * s;
647
+ return i(a === t + 256 && s === n.fixed.nGroups && c === 102 && l === 32768 && u <= n.fixed.chroms && n.fixed.chroms - t <= 16 * 1024 ** 2, "invalid summary restart root dimensions"), {
648
+ offset: t,
649
+ directory: a,
650
+ firstData: u,
651
+ end: n.fixed.chroms
652
+ };
653
+ }
654
+ function U(e, t, n, r) {
655
+ i(e.length === 32, "invalid summary restart group locator length"), z(e, 24, "summary restart group locator");
656
+ let a = new o(e), s = a.u64("summary restart levels"), c = a.u32(), l = a.u32(), u = a.u32(), d = a.u32();
657
+ return a.u32(), i(u === t && d === r.members[t].length && c >= 1 && c <= 13 && (c === 1 || !!(r.fixed.optional & 1)) && a.u32() === 0, "invalid summary restart group locator"), B(n, s, c * 32), {
658
+ offset: s,
659
+ count: c,
660
+ checksum: l
661
+ };
662
+ }
663
+ function W(e) {
664
+ let t = Math.ceil(e / 102);
665
+ return (t - 1) * R + 16 + (e - (t - 1) * 102) * 40;
666
+ }
667
+ function G(e, t, n, r, a) {
668
+ i(e.length === t.count * 32, "truncated summary restart levels"), l(e, t.checksum, "summary restart levels");
669
+ let s = new o(e), c = [], u = a.directory[r], d = a.directory[r + 1] ?? a.fixed.length, f = a.members[r].length;
670
+ for (let e = 0; e < t.count; e++) {
671
+ let t = s.u64("summary restart source"), r = s.u64("summary restart index"), o = s.u32(), l = s.u32(), p = s.u32(), m = s.u32(), h = 4 ** e, g = a.header.chromosomes.reduce((e, t) => e + Math.ceil(t.tileCount / h), 0);
672
+ i(t >= u + (e ? 16 : 12) && t <= d - l && o <= g && (l > 0 || o === 0) && (e === 0 || l > 0) && (l !== 0 || p === 0), "invalid summary restart source extent or count"), i(m === 0 ? r === 0 : m <= 2048 && !(m & m - 1) && m * (4 + (e ? 8 : 4) * f) <= 32768 && l > 0 && o > 0 && r > 0, "invalid summary restart window dimensions"), m && B(n, r, W(Math.ceil(g / m))), c.push({
673
+ factor: h,
674
+ offset: t,
675
+ index: r,
676
+ n: o,
677
+ size: l,
678
+ checksum: p,
679
+ windowBins: m,
680
+ binCount: g
681
+ });
682
+ }
683
+ return {
684
+ levels: c,
685
+ cacheBytes: e.length + c.length * 96 + 64
686
+ };
687
+ }
688
+ function K(e, t, n, r, a) {
689
+ let s = t * 102, c = Math.min(102, Math.ceil(n.binCount / n.windowBins) - s);
690
+ i(e.length === 16 + c * 40 && c > 0 && e.length + c * 160 <= a, "summary restart page allocation exceeds bounds or maxInflatedBytes"), z(e, 12, "summary restart page");
691
+ let l = new o(e);
692
+ i(l.u32() === 1347573574 && l.u32() === s && l.u32() === c, "invalid summary restart page header"), l.u32();
693
+ let u = [], d = (n.factor === 1 ? 4 : 8) * r, f, p = Infinity;
694
+ for (let e = 0; e < c; e++) {
695
+ let t = l.u32(), r = l.u32(), a = (e) => {
696
+ let r = l.u32(), a = l.u32(), o = l.u32(), s = l.u32();
697
+ return i(t ? a > 0 && a <= 2 * e + 64 && r >= 2 && r <= n.size - 4 - a : r === 0 && a === 0 && o === 0 && s === 0, "invalid summary restart fragment extent"), {
698
+ offset: r,
699
+ size: a,
700
+ checksum: o,
701
+ rawChecksum: s
702
+ };
703
+ };
704
+ i(t <= Math.min(n.windowBins, n.binCount - (s + e) * n.windowBins) && r <= n.n - t && (t > 0 || r === 0), "invalid summary restart window count or row");
705
+ let o = a(t * 4), c = a(t * d);
706
+ i(!t || o.offset + o.size <= c.offset, "overlapping summary restart fragments"), t && (i(!f || r === f.firstRow + f.n && o.offset >= f.ids.offset + f.ids.size && c.offset >= f.sums.offset + f.sums.size, "summary restart rows or fragments overlap or are out of order"), f || (p = c.offset), f = {
707
+ n: t,
708
+ firstRow: r,
709
+ ids: o,
710
+ sums: c
711
+ }), u.push({
712
+ n: t,
713
+ firstRow: r,
714
+ ids: o,
715
+ sums: c
716
+ });
717
+ }
718
+ return i(!f || f.ids.offset + f.ids.size <= p, "overlapping summary restart page fragments"), {
719
+ windows: u,
720
+ cacheBytes: e.length + c * 160 + 64
721
+ };
722
+ }
723
+ function q(e, t) {
724
+ let n = new o(e);
725
+ if (t.factor !== 1 && i(n.u32() === t.factor, "summary restart source factor mismatch"), i(n.u32() === t.n && n.u32() === t.size && n.u32() === t.checksum, "summary restart source header mismatch"), t.size) {
726
+ let r = e[n.at], a = e[n.at + 1];
727
+ i((r & 15) == 8 && (t.windowBins ? r >>> 4 == 7 : r >>> 4 <= 7) && ((r << 8) + a) % 31 == 0 && !(a & 32), "invalid summary restart zlib wrapper");
728
+ }
729
+ }
730
+ function J(e, t, n, r, a, o, s, c) {
731
+ let u = s.members[o], d = a.factor !== 1, f = n.n * 4, p = n.n * u.length * (d ? 8 : 4);
732
+ i(2 * (f + p) <= c, "parsed summary restart allocation exceeds maxInflatedBytes"), l(e, n.ids.checksum, "summary restart IDs"), l(t, n.sums.checksum, "summary restart sums");
733
+ let m = v(e, f, c), h = v(t, p, c);
734
+ l(m, n.ids.rawChecksum, "summary restart decoded IDs"), l(h, n.sums.rawChecksum, "summary restart decoded sums");
735
+ let g = new Uint32Array(n.n), _ = d ? new Float64Array(n.n * u.length) : new Float32Array(n.n * u.length), y = new DataView(m.buffer, m.byteOffset, m.byteLength), b = new DataView(h.buffer, h.byteOffset, h.byteLength), x = r * a.windowBins, S = Math.min(x + a.windowBins, a.binCount);
736
+ for (let e = 0; e < g.length; e++) g[e] = y.getUint32(4 * e, !0), i(g[e] >= x && g[e] < S && (!e || g[e] > g[e - 1]), "summary restart IDs out of order or window");
737
+ for (let e = 0; e < _.length; e++) _[e] = d ? b.getFloat64(8 * e, !0) : b.getFloat32(4 * e, !0);
738
+ return {
739
+ factor: a.factor,
740
+ binSize: a.factor * s.fixed.tile,
741
+ bins: g,
742
+ sums: _,
743
+ tracks: u,
744
+ available: !0
745
+ };
746
+ }
747
+ //#endregion
748
+ //#region ../../node_modules/@genome-spy/figwig/dist/utils/io.js
749
+ var ae = class {
750
+ concurrency;
751
+ active = 0;
752
+ waiting = [];
753
+ constructor(e) {
754
+ this.concurrency = e;
755
+ }
756
+ async run(e, t) {
757
+ d(e), await new Promise((t, n) => {
758
+ let r = {
759
+ signal: e,
760
+ start: () => {
761
+ this.active++, e?.removeEventListener("abort", r.onAbort), t();
762
+ },
763
+ reject: n,
764
+ onAbort: () => {
765
+ this.waiting = this.waiting.filter((e) => e !== r), n(e.reason);
766
+ }
767
+ };
768
+ this.active < this.concurrency ? r.start() : (this.waiting.push(r), e?.addEventListener("abort", r.onAbort, { once: !0 }));
769
+ });
770
+ try {
771
+ return d(e), await t();
772
+ } finally {
773
+ this.active--, this.waiting.shift()?.start();
774
+ }
775
+ }
776
+ }, Y = class {
777
+ read;
778
+ gap;
779
+ maxSize;
780
+ jobs = [];
781
+ scheduled = !1;
782
+ constructor(e, t, n) {
783
+ this.read = e, this.gap = t, this.maxSize = n;
784
+ }
785
+ get(e, t) {
786
+ return new Promise((n, r) => {
787
+ this.jobs.push({
788
+ ref: e,
789
+ signal: t,
790
+ resolve: n,
791
+ reject: r
792
+ }), this.scheduled || (this.scheduled = !0, queueMicrotask(() => this.flush()));
793
+ });
794
+ }
795
+ flush() {
796
+ let e = this.jobs;
797
+ this.jobs = [], this.scheduled = !1;
798
+ let t = [];
799
+ for (let n of e) n.signal.aborted ? n.reject(n.signal.reason) : t.push(n);
800
+ t.sort((e, t) => e.ref.offset - t.ref.offset);
801
+ let n = [], r = 0, i = 0;
802
+ for (let e of t) {
803
+ let t = e.ref.offset + e.ref.size;
804
+ n.length && (e.ref.offset > i + this.gap || Math.max(t, i) - r > this.maxSize) && (this.fill(n, r, i), n = []), n.length || (r = e.ref.offset), i = Math.max(n.length ? i : 0, t), n.push(e);
805
+ }
806
+ n.length && this.fill(n, r, i);
807
+ }
808
+ async fill(e, t, n) {
809
+ let r = new AbortController(), i = () => {
810
+ e.every((e) => e.signal.aborted) && r.abort(e.find((e) => e.signal.aborted)?.signal.reason);
811
+ };
812
+ for (let t of e) t.signal.addEventListener("abort", i, { once: !0 });
813
+ i();
814
+ try {
815
+ let i = await this.read(t, n - t, r.signal);
816
+ for (let n of e) n.signal.aborted ? n.reject(n.signal.reason) : n.resolve(i.subarray(n.ref.offset - t, n.ref.offset - t + n.ref.size));
817
+ } catch (t) {
818
+ for (let n of e) n.reject(t);
819
+ } finally {
820
+ for (let t of e) t.signal.removeEventListener("abort", i);
821
+ }
822
+ }
823
+ };
824
+ async function oe(e, t, n, r, a, o) {
825
+ return i(Number.isSafeInteger(n) && n >= 0 && Number.isSafeInteger(r) && r >= 0 && r <= a && Number.isSafeInteger(n + r), "read exceeds bounds or maxReadBytes"), t.run(o, async () => {
826
+ let t = await e.read(r, n, { signal: o });
827
+ return d(o), i(t.length === r, `truncated file: expected ${r} bytes at ${n}, received ${t.length}`), t;
828
+ });
829
+ }
830
+ //#endregion
831
+ //#region ../../node_modules/@genome-spy/figwig/dist/figwig.js
832
+ var se = {
833
+ uint8: Uint8Array,
834
+ uint16: Uint16Array,
835
+ uint32: Uint32Array,
836
+ int8: Int8Array,
837
+ int16: Int16Array,
838
+ int32: Int32Array,
839
+ float32: Float32Array,
840
+ float64: Float64Array
841
+ };
842
+ function X() {
843
+ return {
844
+ readRequests: 0,
845
+ indexBytes: 0,
846
+ dataBytes: 0,
847
+ summaryBytes: 0,
848
+ summaryIndexBytes: 0,
849
+ summaryInflatedBytes: 0,
850
+ chunksFetched: 0,
851
+ chunksDecompressed: 0,
852
+ indexLoadMs: 0,
853
+ decompressionMs: 0,
854
+ decodingMs: 0,
855
+ chunkCacheHits: 0,
856
+ chunkCacheMisses: 0,
857
+ cacheBytes: 0
858
+ };
859
+ }
860
+ function Z(e, t, n, r = 0) {
861
+ let i = e ?? t;
862
+ if (!Number.isSafeInteger(i) || i < r) throw RangeError(`Invalid ${n}`);
863
+ return i;
864
+ }
865
+ function Q(e, t) {
866
+ if (t === "float64") return !0;
867
+ if (t === "float32") return Number.isNaN(e) || Math.fround(e) === e;
868
+ let n = p[t] * 8, r = t.startsWith("u");
869
+ return Number.isInteger(e) && e >= (r ? 0 : -(2 ** (n - 1))) && e <= (r ? 2 ** n - 1 : 2 ** (n - 1) - 1);
870
+ }
871
+ function $(e, t) {
872
+ return ["sum", "mean"].includes(e) && [
873
+ "propagate",
874
+ "omit",
875
+ "zero"
876
+ ].includes(t);
877
+ }
878
+ function ce(e, t) {
879
+ if (e.length !== t.length) return !1;
880
+ for (let n = 0; n < e.length; n++) if (e[n] !== t[n]) return !1;
881
+ return !0;
882
+ }
883
+ var le = class {
884
+ filehandle;
885
+ options;
886
+ queue;
887
+ metadata;
888
+ groups;
889
+ chunks;
890
+ summaries;
891
+ reads;
892
+ indexReads;
893
+ lifetime = new AbortController();
894
+ closePromise;
895
+ trackNames;
896
+ metrics = X();
897
+ constructor(n) {
898
+ if (Number(!!n.filehandle) + Number(!!n.url) !== 1) throw TypeError("Provide exactly one of filehandle or url");
899
+ this.filehandle = n.filehandle ?? new e(n.url), this.options = {
900
+ verify: n.verify ?? !0,
901
+ maxOutputBytes: Z(n.maxOutputBytes, 256 * 1024 ** 2, "maxOutputBytes"),
902
+ maxReadBytes: Z(n.maxReadBytes, 64 * 1024 ** 2, "maxReadBytes", 128),
903
+ maxInflatedBytes: Z(n.maxInflatedBytes, 128 * 1024 ** 2, "maxInflatedBytes"),
904
+ indexCacheBytes: Z(n.indexCacheBytes, 32 * 1024 ** 2, "indexCacheBytes"),
905
+ chunkCacheBytes: Z(n.chunkCacheBytes, 64 * 1024 ** 2, "chunkCacheBytes"),
906
+ summaryCacheBytes: Z(n.summaryCacheBytes, 32 * 1024 ** 2, "summaryCacheBytes"),
907
+ maxConcurrentRequests: Z(n.maxConcurrentRequests, 6, "maxConcurrentRequests", 1),
908
+ coalesceGap: Z(n.coalesceGap, 4096, "coalesceGap"),
909
+ maxCoalescedBytes: Z(n.maxCoalescedBytes, 4 * 1024 ** 2, "maxCoalescedBytes", 1),
910
+ maxFeatures: Z(n.maxFeatures, 1e6, "maxFeatures")
911
+ }, this.queue = new ae(this.options.maxConcurrentRequests), this.metadata = new t({ maxSize: 1 }), this.groups = new t({
912
+ maxSize: this.options.indexCacheBytes,
913
+ sizeOf: (e) => e.byteLength <= this.options.indexCacheBytes ? e.byteLength : NaN
914
+ }), this.chunks = new t({
915
+ maxSize: this.options.chunkCacheBytes,
916
+ sizeOf: (e) => {
917
+ let t = e.byteLength + e.tracks.length * 128 + 64;
918
+ return t <= this.options.chunkCacheBytes ? t : NaN;
919
+ }
920
+ }), this.summaries = new t({
921
+ maxSize: this.options.summaryCacheBytes,
922
+ sizeOf: (e) => {
923
+ let t = "cacheBytes" in e ? e.cacheBytes : "indexSize" in e ? 64 : "levels" in e ? e.levels.length * 64 + 64 : e.bins.byteLength + e.sums.byteLength + 128;
924
+ return t <= this.options.summaryCacheBytes ? t : NaN;
925
+ }
926
+ }), this.indexReads = new Y((e, t, n) => this.read(e, t, "indexBytes", n), this.options.coalesceGap, Math.min(this.options.maxCoalescedBytes, this.options.maxReadBytes)), this.reads = new Y((e, t, n) => this.read(e, t, "dataBytes", n), this.options.coalesceGap, Math.min(this.options.maxCoalescedBytes, this.options.maxReadBytes));
927
+ }
928
+ signal(e) {
929
+ let t = e ? AbortSignal.any([this.lifetime.signal, e]) : this.lifetime.signal;
930
+ return d(t), t;
931
+ }
932
+ completed(e, t) {
933
+ return d(this.lifetime.signal), d(t), e;
934
+ }
935
+ async read(e, t, n, r) {
936
+ r = this.signal(r);
937
+ let i = await oe(this.filehandle, this.queue, e, t, this.options.maxReadBytes, r);
938
+ return d(r), this.metrics.readRequests++, this.metrics[n] += i.length, i;
939
+ }
940
+ state(e) {
941
+ return e = this.signal(e), this.metadata.get("metadata", e, async (e) => {
942
+ let t = await this.read(0, 128, "indexBytes", e);
943
+ d(e);
944
+ let n = m(t), r = await this.filehandle.stat();
945
+ d(e), i(Number.isSafeInteger(r.size) && (r.size === 0 || n.length <= r.size), "file length exceeds physical file size");
946
+ let a = await this.read(n.chroms, n.index + 8 * n.nGroups - n.chroms, "indexBytes", e);
947
+ return d(e), _(n, a);
948
+ });
949
+ }
950
+ group(e, t, n) {
951
+ return n = this.signal(n), this.groups.get(e, n, async (n) => {
952
+ let r = performance.now(), i = t.directory[e], { indexSize: a } = await this.groupHeader(e, t, n);
953
+ d(n);
954
+ let o = await this.indexReads.get({
955
+ offset: i,
956
+ size: a
957
+ }, n);
958
+ d(n);
959
+ let s = P(o, e, t, this.options.maxInflatedBytes);
960
+ return this.metrics.indexLoadMs += performance.now() - r, s;
961
+ });
962
+ }
963
+ groupHeader(e, t, n) {
964
+ return this.summaries.get(`index:${e}`, this.signal(n), async (n) => {
965
+ let r = t.directory[e], i = await ne(r, t.directory[e + 1] ?? t.fixed.length, t, (e, t) => this.indexReads.get({
966
+ offset: e,
967
+ size: t
968
+ }, n));
969
+ return d(n), { indexSize: i };
970
+ });
971
+ }
972
+ summaryCatalog(e, t, n) {
973
+ return this.summaries.get(`group:${e}`, this.signal(n), async (n) => {
974
+ let r = performance.now(), i = t.directory[e], a = t.directory[e + 1] ?? t.fixed.length, { indexSize: o } = await this.groupHeader(e, t, n);
975
+ d(n);
976
+ let s = await re(i, a, o, t, (e, t) => this.indexReads.get({
977
+ offset: e,
978
+ size: t
979
+ }, n));
980
+ return d(n), this.metrics.indexLoadMs += performance.now() - r, { levels: s };
981
+ });
982
+ }
983
+ async getHeader(e = {}) {
984
+ return this.completed((await this.state(e.signal)).header, e.signal);
985
+ }
986
+ async getTracks(e = {}) {
987
+ return this.completed((await this.getHeader(e)).tracks, e.signal);
988
+ }
989
+ async selectTracks(e, t = {}) {
990
+ return this.select(this.completed((await this.state(t.signal)).header, t.signal), e);
991
+ }
992
+ select(e, t) {
993
+ if (t === void 0) return [...e.tracks];
994
+ if (!Array.isArray(t)) {
995
+ if (typeof t != "object" || !t) throw TypeError("Invalid track selection");
996
+ return e.tracks.filter((e) => Object.entries(t).every(([t, n]) => Object.hasOwn(e.metadata, t) && Object.is(e.metadata[t], n)));
997
+ }
998
+ let n = /* @__PURE__ */ new Set();
999
+ return t.map((t) => {
1000
+ let r = typeof t == "number" ? Number.isInteger(t) ? e.tracks[t] : void 0 : (this.trackNames ??= new Map(e.tracks.map((e) => [e.name, e]))).get(t);
1001
+ if (!r) throw RangeError(`Unknown track: ${String(t)}`);
1002
+ if (n.has(r.index)) throw RangeError(`Duplicate track selection: ${r.name}`);
1003
+ return n.add(r.index), r;
1004
+ });
1005
+ }
1006
+ region(e, t) {
1007
+ let n = e.chromosomes.find((e) => e.name === t.chromosome);
1008
+ if (!n) throw RangeError(`Unknown chromosome: ${t.chromosome}`);
1009
+ if (!Number.isSafeInteger(t.start) || !Number.isSafeInteger(t.end) || t.start < 0 || t.end < t.start || t.end > n.length) throw RangeError(`Invalid interval ${t.chromosome}:${t.start}-${t.end}; chromosome length ${n.length}`);
1010
+ return n;
1011
+ }
1012
+ output(e) {
1013
+ if (!Number.isSafeInteger(e) || e > this.options.maxOutputBytes) throw RangeError("Requested output exceeds maxOutputBytes");
1014
+ }
1015
+ async getValues(e, t, n, r = {}) {
1016
+ return this.completed((await this.getValuesMulti([{
1017
+ chromosome: e,
1018
+ start: t,
1019
+ end: n
1020
+ }], r))[0], r.signal);
1021
+ }
1022
+ async getValuesMulti(e, t = {}) {
1023
+ t = {
1024
+ ...t,
1025
+ signal: this.signal(t.signal)
1026
+ };
1027
+ let n = await this.state(t.signal);
1028
+ d(t.signal);
1029
+ let { header: r } = n, i = this.select(r, t.tracks);
1030
+ e.forEach((e) => this.region(r, e)), this.output(e.reduce((e, t) => e + (t.end - t.start) * i.reduce((e, t) => e + p[t.dtype], 0), 0));
1031
+ let a = e.map((e) => ({
1032
+ ...e,
1033
+ tracks: i.map((t) => ({
1034
+ track: t,
1035
+ values: new se[t.dtype](e.end - e.start)
1036
+ }))
1037
+ }));
1038
+ return await this.visitDecoded(n, e, i, t, (t, n, i, o) => {
1039
+ let s = e[i];
1040
+ this.copy(t, n, s.start, s.end, a[i].tracks[o].values, r.tileSize);
1041
+ }), this.completed(a, t.signal);
1042
+ }
1043
+ async visitDecoded(e, t, n, r, a) {
1044
+ if (d(r.signal), !n.length || !t.some((e) => e.end > e.start)) return;
1045
+ let { header: o } = e, s = t.map((e) => this.region(o, e)), c = [...new Set(n.map((e) => e.group))], l = new Map(await Promise.all(c.map(async (t) => [t, await this.group(t, e, r.signal)])));
1046
+ d(r.signal);
1047
+ let f = /* @__PURE__ */ new Map(), p = [];
1048
+ for (let [n, r] of l) {
1049
+ for (let e = 0; e < t.length; e++) {
1050
+ let n = t[e], i = s[e];
1051
+ if (n.start !== n.end) {
1052
+ if (o.order === "positions") {
1053
+ let t = i.tileOffset + Math.floor(n.start / o.tileSize), a = i.tileOffset + Math.ceil(n.end / o.tileSize);
1054
+ for (let n = u(r.tiles, t); n < r.tiles.length && r.tiles[n] < a; n++) {
1055
+ let t = r.chunks[n];
1056
+ f.set(t.key, t), p.push({
1057
+ ref: t,
1058
+ regionIndex: e
1059
+ });
1060
+ }
1061
+ } else {
1062
+ let t = 0, a = r.chunks.length;
1063
+ for (; t < a;) {
1064
+ let e = Math.floor((t + a) / 2), o = r.chunks[e];
1065
+ o.chrom < i.id || o.chrom === i.id && o.last < n.start ? t = e + 1 : a = e;
1066
+ }
1067
+ for (let a = t; a < r.chunks.length; a++) {
1068
+ let t = r.chunks[a];
1069
+ if (t.chrom !== i.id || t.first >= n.end) break;
1070
+ f.set(t.key, t), p.push({
1071
+ ref: t,
1072
+ regionIndex: e
1073
+ });
1074
+ }
1075
+ }
1076
+ }
1077
+ }
1078
+ i(e.members[n].length > 0, "empty selected group");
1079
+ }
1080
+ let m = /* @__PURE__ */ new Map();
1081
+ n.forEach((t, n) => {
1082
+ let r = m.get(t.group) ?? [];
1083
+ r.push({
1084
+ outputIndex: n,
1085
+ slot: e.trackSlots[t.index]
1086
+ }), m.set(t.group, r);
1087
+ });
1088
+ let h = /* @__PURE__ */ new Map();
1089
+ for (let { ref: e, regionIndex: t } of p) {
1090
+ let n = h.get(e.key) ?? [];
1091
+ n.push(t), h.set(e.key, n);
1092
+ }
1093
+ let g = [...f.values()].sort((e, t) => e.offset - t.offset || e.group - t.group), _ = {}, v = 0;
1094
+ for (; v < g.length;) {
1095
+ let t = v, n = 0;
1096
+ for (; t < g.length;) {
1097
+ let r = g[t], i = e.members[r.group].length, { kind: a, width: s } = w(r.kind, r.n !== void 0), c = r.n === void 0 ? a === 1 ? i * o.tileSize * 8 : Math.ceil(r.raw * 12 / (s + (a === 3 ? 2 : 1))) : r.n * 12, l = Math.min(this.options.maxInflatedBytes, c) + i * 128 + 64;
1098
+ if (t > v && n + l > this.options.maxInflatedBytes) break;
1099
+ n += l, t++;
1100
+ }
1101
+ let i = g.slice(v, t), c = await Promise.all(i.map((t) => this.chunk(t, e, _, r.signal)));
1102
+ for (let e = 0; e < i.length; e++) {
1103
+ d(r.signal);
1104
+ let t = i[e], n = c[e];
1105
+ for (let e of h.get(t.key)) {
1106
+ let r = s[e], i = t.tile === void 0 ? 0 : (t.tile - r.tileOffset) * o.tileSize;
1107
+ for (let { outputIndex: r, slot: o } of m.get(t.group)) a(n.tracks[o], i, e, r);
1108
+ }
1109
+ }
1110
+ v = t;
1111
+ }
1112
+ }
1113
+ chunk(e, t, n, r) {
1114
+ return r = this.signal(r), this.chunks.has(e.key) ? this.metrics.chunkCacheHits++ : this.metrics.chunkCacheMisses++, this.chunks.get(e.key, r, async (r) => {
1115
+ i(e.raw <= this.options.maxInflatedBytes, "chunk exceeds maxInflatedBytes");
1116
+ let a = await this.reads.get(e, r);
1117
+ d(r), this.metrics.chunksFetched++, (this.options.verify || t.fixed.codec === 1 && e.kind & 128) && l(a, e.crc, "chunk");
1118
+ let o = performance.now(), s = n.last, c = s && e.n === void 0 && e.kind === s.kind && e.raw === s.raw && t.members[e.group].length === s.decoded.tracks.length && ce(a, s.bytes), u;
1119
+ if (c) u = s.decoded;
1120
+ else {
1121
+ let n = a;
1122
+ t.fixed.codec === 1 && !(e.kind & 128) && (n = y(a, e.raw, this.options.maxInflatedBytes), this.metrics.decompressionMs += performance.now() - o, this.metrics.chunksDecompressed++), o = performance.now(), u = e.n === void 0 ? ee(n, e.kind, t.members[e.group].length, t.fixed.tile, this.options.maxInflatedBytes) : j(n, e.kind, e.n, e.first, e.last, this.options.maxInflatedBytes);
1123
+ }
1124
+ let f = e.kind >>> 3 & 15;
1125
+ for (let n = 0; n < u.tracks.length; n++) {
1126
+ let r = t.members[e.group][n].dtype;
1127
+ if (!(r === "float64" || r === "float32" && f === 6)) for (let e of u.tracks[n].values) Q(e, r) || i(!1, `chunk value cannot be represented in declared ${r} dtype`);
1128
+ }
1129
+ return !c && e.n === void 0 && (e.kind & 7) == 1 && a.byteLength + u.byteLength + u.tracks.length * 128 + 64 <= Math.min(65536, this.options.maxInflatedBytes) && u.tracks.every((e) => e.runs && e.values.length === 1 && Number.isNaN(e.values[0])) && (n.last = {
1130
+ bytes: Uint8Array.from(a),
1131
+ kind: e.kind,
1132
+ raw: e.raw,
1133
+ decoded: u
1134
+ }), this.metrics.decodingMs += performance.now() - o, u;
1135
+ });
1136
+ }
1137
+ copy(e, t, n, r, i, a) {
1138
+ if (!e.offsets) {
1139
+ let a = Math.max(n, t), o = Math.min(r, t + e.values.length);
1140
+ o > a && i.set(e.values.subarray(a - t, o - t), a - n);
1141
+ } else if (e.runs) {
1142
+ let o = e.offsets, s = Math.max(0, u(o, Math.max(0, n - t)) - 1);
1143
+ for (; s < o.length && t + o[s] < r; s++) {
1144
+ let c = Math.max(n, t + o[s]), l = Math.min(r, t + (o[s + 1] ?? a));
1145
+ l > c && i.fill(e.values[s], c - n, l - n);
1146
+ }
1147
+ } else for (let a = u(e.offsets, Math.max(0, n - t)); a < e.offsets.length && t + e.offsets[a] < r; a++) i[t + e.offsets[a] - n] = e.values[a];
1148
+ }
1149
+ aggregate(e, t, n, r, i, a, o) {
1150
+ let s = n.tracks[r].values, { start: c, end: l, binSize: d } = n;
1151
+ if (!e.offsets) {
1152
+ let n = Math.max(c, t), r = Math.min(l, t + e.values.length);
1153
+ if (d === 1) {
1154
+ for (; n < r; n++) {
1155
+ let r = e.values[n - t], i = n - c;
1156
+ Number.isNaN(r) ? a === "propagate" ? s[i] = NaN : o && o[i]++ : r !== 0 && (s[i] += r);
1157
+ }
1158
+ return;
1159
+ }
1160
+ let i = Math.floor((n - c) / d);
1161
+ for (; n < r;) {
1162
+ let l = Math.min(r, c + (i + 1) * d), u = s[i], f = 0;
1163
+ for (; n < l; n++) {
1164
+ let r = e.values[n - t];
1165
+ Number.isNaN(r) ? a === "propagate" ? u = NaN : o && f++ : r !== 0 && (u += r);
1166
+ }
1167
+ s[i] = u, f && (o[i] += f), i++;
1168
+ }
1169
+ return;
1170
+ }
1171
+ let f = e.offsets;
1172
+ if (e.runs) {
1173
+ let n = (e, t, n) => {
1174
+ let r = Math.max(c, t), i = Math.min(l, n);
1175
+ if (r >= i || e === 0) return;
1176
+ let u = Math.floor((r - c) / d), f = Number.isNaN(e);
1177
+ for (; r < i;) {
1178
+ let t = Math.min(i, c + (u + 1) * d), n = t - r;
1179
+ f ? a === "propagate" ? s[u] = NaN : o && (o[u] += n) : s[u] += e * n, r = t, u++;
1180
+ }
1181
+ };
1182
+ for (let r = Math.max(0, u(f, Math.max(0, c - t)) - 1); r < f.length && t + f[r] < l; r++) n(e.values[r], t + f[r], t + (f[r + 1] ?? i));
1183
+ } else {
1184
+ let n = c - t, r = l - t;
1185
+ for (let t = u(f, Math.max(0, n)); t < f.length && f[t] < r; t++) {
1186
+ let r = e.values[t], i = Math.floor((f[t] - n) / d);
1187
+ Number.isNaN(r) ? a === "propagate" ? s[i] = NaN : o && o[i]++ : r !== 0 && (s[i] += r);
1188
+ }
1189
+ }
1190
+ }
1191
+ async getSummary(e, t = 0, n = {}) {
1192
+ let r = this.signal(n.signal), i = await this.state(r);
1193
+ if (d(r), !Number.isInteger(e) || e < 0 || e >= i.fixed.nGroups || !Number.isInteger(t) || t < 0) throw RangeError("Invalid group or summary level");
1194
+ let a = await this.summaries.get(`${e}:${t}`, r, async (n) => {
1195
+ let r = await this.summaryCatalog(e, i, n);
1196
+ d(n);
1197
+ let a = r.levels[t];
1198
+ if (!a) throw RangeError(`Zoom level ${t} is unavailable for group ${e}`);
1199
+ let o = performance.now(), s = a.size ? await this.indexReads.get({
1200
+ offset: a.offset,
1201
+ size: a.size
1202
+ }, n) : /* @__PURE__ */ new Uint8Array();
1203
+ return d(n), this.metrics.indexLoadMs += performance.now() - o, this.decodeSummary(a, s, e, i);
1204
+ });
1205
+ return this.completed(a, r);
1206
+ }
1207
+ decodeSummary(e, t, n, r) {
1208
+ this.metrics.summaryBytes += e.size, l(t, e.checksum, e.factor === 1 ? "summary" : "zoom");
1209
+ let i = ie({
1210
+ ...e,
1211
+ bytes: t
1212
+ }, n, r, this.options.maxInflatedBytes);
1213
+ return this.metrics.summaryInflatedBytes += i.bins.byteLength + i.sums.byteLength, i;
1214
+ }
1215
+ async getZoomLevels(e = {}) {
1216
+ e = {
1217
+ ...e,
1218
+ signal: this.signal(e.signal)
1219
+ };
1220
+ let t = await this.state(e.signal);
1221
+ d(e.signal);
1222
+ let n = this.select(t.header, e.tracks), r = /* @__PURE__ */ new Map();
1223
+ return await Promise.all([...new Set(n.map((e) => e.group))].map(async (n) => {
1224
+ let i = await this.summaryCatalog(n, t, e.signal);
1225
+ d(e.signal), i.levels.slice(1).forEach(({ factor: e }, i) => {
1226
+ let a = i + 1, o = r.get(a) ?? {
1227
+ level: a,
1228
+ factor: e,
1229
+ binSize: e * t.fixed.tile,
1230
+ groups: []
1231
+ };
1232
+ o.groups.push(n), r.set(a, o);
1233
+ });
1234
+ })), d(e.signal), [...r.values()].sort((e, t) => e.level - t.level).map((e) => ({
1235
+ ...e,
1236
+ groups: e.groups.sort((e, t) => e - t)
1237
+ }));
1238
+ }
1239
+ async getBins(e, t, n, r) {
1240
+ return this.completed((await this.getBinsMulti([{
1241
+ chromosome: e,
1242
+ start: t,
1243
+ end: n
1244
+ }], r))[0], r.signal);
1245
+ }
1246
+ async getBinsMulti(e, t) {
1247
+ t = {
1248
+ ...t,
1249
+ signal: this.signal(t.signal)
1250
+ };
1251
+ let { binSize: n, aggregation: r = "mean", missing: i = "propagate" } = t;
1252
+ if (!Number.isSafeInteger(n) || n < 1 || !$(r, i)) throw RangeError("Invalid binSize, aggregation, or missing policy");
1253
+ if (t.requireSummaries && i !== "zero") throw RangeError("Required summaries need missing: 'zero'");
1254
+ let a = await this.state(t.signal);
1255
+ d(t.signal);
1256
+ let o = this.select(a.header, t.tracks);
1257
+ e.forEach((e) => this.region(a.header, e));
1258
+ let s = i === "omit" && r === "mean";
1259
+ this.output(e.reduce((e, t) => e + Math.ceil((t.end - t.start) / n) * (8 + o.length * (s ? 12 : 8)), 0));
1260
+ let c = e.map((e) => {
1261
+ let t = Math.ceil((e.end - e.start) / n);
1262
+ return {
1263
+ ...e,
1264
+ binSize: n,
1265
+ source: "values",
1266
+ starts: Uint32Array.from({ length: t }, (t, r) => e.start + r * n),
1267
+ ends: Uint32Array.from({ length: t }, (t, r) => Math.min(e.end, e.start + (r + 1) * n)),
1268
+ tracks: o.map((e) => ({
1269
+ track: e,
1270
+ values: new Float64Array(t)
1271
+ }))
1272
+ };
1273
+ }), l = [];
1274
+ for (let n = 0; n < e.length; n++) if ((t.useSummaries || t.requireSummaries) && i === "zero" && await this.summaryBins(c[n], a, t)) c[n].source = "summary";
1275
+ else if (t.requireSummaries) {
1276
+ d(t.signal);
1277
+ let r = e[n];
1278
+ throw RangeError(`Required summaries are unavailable or bins are not tile-aligned for ${r.chromosome}:${r.start}-${r.end}`);
1279
+ } else l.push(n);
1280
+ let u = s ? c.map((e) => e.tracks.map(() => new Uint32Array(e.starts.length))) : void 0;
1281
+ if (l.length && await this.visitDecoded(a, l.map((t) => e[t]), o, t, (e, t, n, r) => {
1282
+ let o = l[n];
1283
+ this.aggregate(e, t, c[o], r, a.fixed.tile, i, u?.[o][r]);
1284
+ }), r === "mean") for (let e = 0; e < c.length; e++) {
1285
+ let t = c[e];
1286
+ for (let n = 0; n < t.tracks.length; n++) for (let r = 0; r < t.starts.length; r++) {
1287
+ let i = t.ends[r] - t.starts[r] - (u?.[e][n][r] ?? 0);
1288
+ t.tracks[n].values[r] = i ? t.tracks[n].values[r] / i : NaN;
1289
+ }
1290
+ }
1291
+ return d(t.signal), c;
1292
+ }
1293
+ async summaryBins(e, t, n) {
1294
+ let r = this.region(t.header, e), i = t.fixed.tile;
1295
+ if (e.start % i || e.binSize % i || e.end % i && e.end !== r.length) return !1;
1296
+ let a = await this.restartRoot(t, n.signal);
1297
+ if (a) return this.restartBins(e, t, a, n);
1298
+ let o = [...new Set(e.tracks.map((e) => e.track.group))], s = /* @__PURE__ */ new Map();
1299
+ if (await Promise.all(o.map(async (a) => {
1300
+ let o = await this.summaryCatalog(a, t, n.signal);
1301
+ d(n.signal);
1302
+ let c = 0;
1303
+ for (let t = 1; t < o.levels.length; t++) {
1304
+ let n = i * o.levels[t].factor;
1305
+ e.start % n === 0 && e.binSize % n === 0 && (e.end % n === 0 || e.end === r.length) && (c = t);
1306
+ }
1307
+ s.set(a, await this.getSummary(a, c, n));
1308
+ })), d(n.signal), [...s.values()].some((e) => !e.available)) return !1;
1309
+ for (let { track: n, values: i } of e.tracks) {
1310
+ let a = s.get(n.group), o = t.trackSlots[n.index], c = t.header.chromosomes.slice(0, r.id).reduce((e, t) => e + Math.ceil(t.tileCount / a.factor), 0), l = c + e.start / a.binSize, d = c + Math.ceil(e.end / a.binSize);
1311
+ for (let t = u(a.bins, l); t < a.bins.length && a.bins[t] < d; t++) {
1312
+ let n = Math.floor(((a.bins[t] - c) * a.binSize - e.start) / e.binSize);
1313
+ n >= 0 && n < i.length && (i[n] += a.sums[t * a.tracks.length + o]);
1314
+ }
1315
+ }
1316
+ return !0;
1317
+ }
1318
+ async readRestartBytes(e, t, n) {
1319
+ let r = performance.now(), i = await this.indexReads.get({
1320
+ offset: e,
1321
+ size: t
1322
+ }, n);
1323
+ return this.metrics.summaryIndexBytes += t, this.metrics.indexLoadMs += performance.now() - r, i;
1324
+ }
1325
+ async restartRoot(e, t) {
1326
+ let n = V(e);
1327
+ if (n !== void 0) return (await this.summaries.get("restart:root", this.signal(t), async (t) => ({
1328
+ root: H(await this.readRestartBytes(n, 256, t), n, e),
1329
+ cacheBytes: 256
1330
+ }))).root;
1331
+ }
1332
+ restartGroup(e, t, n, r) {
1333
+ return this.summaries.get(`restart:group:${e}`, this.signal(r), async (r) => {
1334
+ let i = U(await this.readRestartBytes(n.directory + e * 32, 32, r), e, n, t);
1335
+ return G(await this.readRestartBytes(i.offset, i.count * 32, r), i, n, e, t);
1336
+ });
1337
+ }
1338
+ async restartSource(e, t, n, r) {
1339
+ await this.summaries.get(`restart:source:${e}:${t}`, this.signal(r), async (e) => {
1340
+ let r = t ? 16 : 12;
1341
+ return q(await this.readRestartBytes(n.offset - r, r + Math.min(2, n.size), e), n), { cacheBytes: 32 };
1342
+ });
1343
+ }
1344
+ restartPage(e, t, n, r, a, o, s) {
1345
+ return this.summaries.get(`restart:page:${e}:${t}:${n}`, this.signal(s), async (t) => {
1346
+ let s = Math.min(102, Math.ceil(r.binCount / r.windowBins) - n * 102), c = r.index + n * R, l = 16 + s * 40;
1347
+ return B(o, c, l), i(s > 0 && l + s * 160 <= this.options.maxInflatedBytes, "summary restart page allocation exceeds maxInflatedBytes"), K(await this.readRestartBytes(c, l, t), n, r, a.members[e].length, this.options.maxInflatedBytes);
1348
+ });
1349
+ }
1350
+ restartWindow(e, t, n, r, a, o, s) {
1351
+ return this.summaries.get(`restart:data:${e}:${t}:${n}`, this.signal(s), async (s) => {
1352
+ let c = (await this.restartPage(e, t, Math.floor(n / 102), r, a, o, s)).windows[n % 102];
1353
+ if (d(s), !c.n) return {
1354
+ factor: r.factor,
1355
+ binSize: r.factor * a.fixed.tile,
1356
+ bins: /* @__PURE__ */ new Uint32Array(),
1357
+ sums: r.factor === 1 ? /* @__PURE__ */ new Float32Array() : /* @__PURE__ */ new Float64Array(),
1358
+ tracks: a.members[e],
1359
+ available: !0
1360
+ };
1361
+ i(2 * c.n * (4 + (t ? 8 : 4) * a.members[e].length) <= this.options.maxInflatedBytes, "parsed summary restart allocation exceeds maxInflatedBytes");
1362
+ let [l, u] = await Promise.all([c.ids, c.sums].map((e) => this.indexReads.get({
1363
+ offset: r.offset + e.offset,
1364
+ size: e.size
1365
+ }, s)));
1366
+ d(s), this.metrics.summaryBytes += l.length + u.length;
1367
+ let f = J(l, u, c, n, r, e, a, this.options.maxInflatedBytes);
1368
+ return this.metrics.summaryInflatedBytes += f.bins.byteLength + f.sums.byteLength, f;
1369
+ });
1370
+ }
1371
+ completeRestartSummary(e, t, n, r, i) {
1372
+ return this.summaries.get(`${e}:${t}`, this.signal(i), async (i) => {
1373
+ let a = t ? 16 : 12, o;
1374
+ if (a + n.size <= this.options.maxReadBytes) {
1375
+ let e = await this.indexReads.get({
1376
+ offset: n.offset - a,
1377
+ size: a + n.size
1378
+ }, i);
1379
+ d(i), this.metrics.summaryIndexBytes += a, q(e.subarray(0, a + Math.min(2, n.size)), n), o = e.subarray(a);
1380
+ } else await this.restartSource(e, t, n, i), o = await this.indexReads.get({
1381
+ offset: n.offset,
1382
+ size: n.size
1383
+ }, i), d(i);
1384
+ return this.decodeSummary(n, o, e, r);
1385
+ });
1386
+ }
1387
+ async restartBins(e, t, n, r) {
1388
+ let a = new AbortController();
1389
+ r = {
1390
+ ...r,
1391
+ signal: AbortSignal.any([this.signal(r.signal), a.signal])
1392
+ };
1393
+ try {
1394
+ let a = this.region(t.header, e), o = t.fixed.tile, s = [...new Set(e.tracks.map((e) => e.track.group))];
1395
+ i(s.length * 256 <= this.options.maxInflatedBytes, "summary restart query planning exceeds maxInflatedBytes");
1396
+ let c = await Promise.all(s.map(async (i) => {
1397
+ let s = await this.restartGroup(i, t, n, r.signal), c = 0;
1398
+ for (let t = 1; t < s.levels.length; t++) {
1399
+ let n = o * s.levels[t].factor;
1400
+ e.start % n === 0 && e.binSize % n === 0 && (e.end % n === 0 || e.end === a.length) && (c = t);
1401
+ }
1402
+ let l = s.levels[c], u = t.header.chromosomes.slice(0, a.id).reduce((e, t) => e + Math.ceil(t.tileCount / l.factor), 0);
1403
+ return {
1404
+ group: i,
1405
+ level: c,
1406
+ ref: l,
1407
+ offset: u
1408
+ };
1409
+ }));
1410
+ if (d(r.signal), c.some((e) => e.ref.size === 0)) return !1;
1411
+ let l = 0;
1412
+ return await Promise.all(Array.from({ length: Math.min(6, c.length, this.options.maxConcurrentRequests) }, async () => {
1413
+ for (; l < c.length;) {
1414
+ let { group: a, level: s, ref: f, offset: p } = c[l++], m = e.tracks.filter((e) => e.track.group === a), h = p + e.start / (o * f.factor), g = p + Math.ceil(e.end / (o * f.factor)), _ = (n) => {
1415
+ for (let { track: r, values: i } of m) {
1416
+ let a = t.trackSlots[r.index];
1417
+ for (let t = u(n.bins, h); t < n.bins.length && n.bins[t] < g; t++) {
1418
+ let r = Math.floor(((n.bins[t] - p) * n.binSize - e.start) / e.binSize);
1419
+ r >= 0 && r < i.length && (i[r] += n.sums[t * n.tracks.length + a]);
1420
+ }
1421
+ }
1422
+ };
1423
+ d(r.signal);
1424
+ let v = f.n * (4 + (s ? 8 : 4) * t.members[a].length);
1425
+ if (this.summaries.has(`${a}:${s}`) || !f.windowBins || (g - h) * 2 >= f.binCount && f.size <= this.options.maxReadBytes && v <= this.options.maxInflatedBytes) {
1426
+ let e = await this.completeRestartSummary(a, s, f, t, r.signal);
1427
+ d(r.signal), i(e.available && e.bins.length === f.n, "summary restart catalog disagrees with complete summary"), _(e);
1428
+ continue;
1429
+ }
1430
+ await this.restartSource(a, s, f, r.signal);
1431
+ let y = Math.floor(h / f.windowBins), b = Math.ceil(g / f.windowBins);
1432
+ for (let e = y; e < b; e += 4) {
1433
+ let i = await Promise.all(Array.from({ length: Math.min(4, b - e) }, (i, o) => this.restartWindow(a, s, e + o, f, t, n, r.signal)));
1434
+ d(r.signal);
1435
+ for (let e of i) _(e);
1436
+ }
1437
+ }
1438
+ })), d(r.signal), !0;
1439
+ } catch (e) {
1440
+ throw a.abort(e), e;
1441
+ }
1442
+ }
1443
+ async getFeatures(e, t, n, r = {}) {
1444
+ return this.completed((await this.getFeaturesMulti([{
1445
+ chromosome: e,
1446
+ start: t,
1447
+ end: n
1448
+ }], r))[0], r.signal);
1449
+ }
1450
+ async getFeaturesMulti(e, t = {}) {
1451
+ t = {
1452
+ ...t,
1453
+ signal: this.signal(t.signal)
1454
+ };
1455
+ let n = t.basesPerSpan ?? 1, { aggregation: r = "mean", missing: i = "propagate" } = t;
1456
+ if (!Number.isSafeInteger(n) || n < 1) throw RangeError("Invalid basesPerSpan");
1457
+ if (!$(r, i)) throw RangeError("Invalid aggregation or missing policy");
1458
+ if (t.requireSummaries && i !== "zero") throw RangeError("Required summaries need missing: 'zero'");
1459
+ let a = await this.state(t.signal);
1460
+ d(t.signal);
1461
+ let o = this.select(a.header, t.tracks);
1462
+ if (e.forEach((e) => this.region(a.header, e)), e.reduce((e, t) => e + Math.ceil((t.end - t.start) / n) * o.length, 0) > this.options.maxFeatures) throw RangeError("Requested features exceed maxFeatures; use typed arrays or a larger basesPerSpan");
1463
+ let s = n === 1 && !t.requireSummaries, c = s ? await this.getValuesMulti(e, t) : await this.getBinsMulti(e, {
1464
+ ...t,
1465
+ binSize: n
1466
+ });
1467
+ d(t.signal);
1468
+ let l = s && (i === "zero" || i === "omit" && r === "sum");
1469
+ return c.map((e) => {
1470
+ let r = [];
1471
+ for (let i of e.tracks) for (let a = 0; a < i.values.length; a++) {
1472
+ let o = i.values[a];
1473
+ l && Number.isNaN(o) && (o = 0), (t.includeZeros !== !1 || o !== 0) && r.push({
1474
+ track: i.track.name,
1475
+ trackIndex: i.track.index,
1476
+ start: e.start + a * n,
1477
+ end: Math.min(e.end, e.start + (a + 1) * n),
1478
+ score: o
1479
+ });
1480
+ }
1481
+ return r;
1482
+ });
1483
+ }
1484
+ getDiagnostics() {
1485
+ return {
1486
+ ...this.metrics,
1487
+ cacheBytes: this.groups.totalSize + this.chunks.totalSize + this.summaries.totalSize
1488
+ };
1489
+ }
1490
+ resetDiagnostics() {
1491
+ this.metrics = X();
1492
+ }
1493
+ clearCache() {
1494
+ this.groups.clear(), this.chunks.clear(), this.summaries.clear();
1495
+ }
1496
+ close() {
1497
+ return this.closePromise || (this.closePromise = Promise.resolve().then(() => this.filehandle.close()), this.lifetime.abort(new DOMException("Figwig reader is closed", "AbortError")), this.clearCache(), this.metadata.clear(), this.trackNames = void 0), this.closePromise;
1498
+ }
1499
+ };
1500
+ //#endregion
1501
+ export { le as FigWig, r as FigWigError };