omezarr-tilesource 0.3.0 → 0.5.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.
@@ -1,2680 +1,9 @@
1
- import { r as e } from "./chunk-BXES_1_E.js";
2
- import { n as t, t as n } from "./dist-DIvEDGnZ.js";
3
- import r from "openseadragon";
4
- //#region node_modules/.pnpm/@zarrita+storage@0.2.0/node_modules/@zarrita/storage/dist/src/util.js
5
- function i(e) {
6
- return e.slice(1);
7
- }
8
- function a(e, t, n, r = {}) {
9
- return t !== void 0 && n !== void 0 && (r = {
10
- ...r,
11
- headers: {
12
- ...r.headers,
13
- Range: `bytes=${t}-${t + n - 1}`
14
- }
15
- }), fetch(e, r);
16
- }
17
- function o(e, t) {
18
- return {
19
- ...e,
20
- ...t,
21
- headers: {
22
- ...e.headers,
23
- ...t.headers
24
- }
25
- };
26
- }
27
- function s(e, t = "") {
28
- if (!e) throw Error(t);
29
- }
30
- //#endregion
31
- //#region node_modules/.pnpm/@zarrita+storage@0.2.0/node_modules/@zarrita/storage/dist/src/fetch.js
32
- function c(e, t) {
33
- let n = typeof e == "string" ? new URL(e) : e;
34
- n.pathname.endsWith("/") || (n.pathname += "/");
35
- let r = new URL(t.slice(1), n);
36
- return r.search = n.search, r;
37
- }
38
- async function l(e) {
39
- if (e.status !== 404) {
40
- if (e.status === 200 || e.status === 206) return new Uint8Array(await e.arrayBuffer());
41
- throw Error(`Unexpected response status ${e.status} ${e.statusText}`);
42
- }
43
- }
44
- var u = class {
45
- url;
46
- #e;
47
- #t;
48
- #n;
49
- constructor(e, t = {}) {
50
- this.url = e, this.#e = t.fetch ?? ((e) => fetch(e)), this.#t = t.overrides ?? {}, this.#n = t.useSuffixRequest ?? !1;
51
- }
52
- #r(e, t) {
53
- return new Request(e, o(this.#t, t));
54
- }
55
- async get(e, t = {}) {
56
- let n = c(this.url, e).href, r = this.#r(n, t);
57
- return l(await this.#e(r));
58
- }
59
- async getRange(e, t, n = {}) {
60
- let r = c(this.url, e), i;
61
- if ("suffixLength" in t) i = await this.#i(r, t.suffixLength, n);
62
- else {
63
- let e = {
64
- ...n,
65
- headers: {
66
- ...n.headers,
67
- Range: `bytes=${t.offset}-${t.offset + t.length - 1}`
68
- }
69
- }, a = this.#r(r, e);
70
- i = await this.#e(a);
71
- }
72
- return l(i);
73
- }
74
- async #i(e, t, n) {
75
- if (this.#n) {
76
- let r = {
77
- ...n,
78
- headers: {
79
- ...n.headers,
80
- Range: `bytes=-${t}`
81
- }
82
- };
83
- return this.#e(this.#r(e, r));
84
- }
85
- let r = this.#r(e, {
86
- ...n,
87
- method: "HEAD"
88
- }), i = await this.#e(r);
89
- if (!i.ok) return i;
90
- let a = i.headers.get("Content-Length"), o = Number(a), s = o - t, c = {
91
- ...n,
92
- headers: {
93
- ...n.headers,
94
- Range: `bytes=${s}-${o - 1}`
95
- }
96
- };
97
- return this.#e(this.#r(e, c));
98
- }
99
- };
100
- //#endregion
101
- //#region node_modules/.pnpm/unzipit@2.0.0/node_modules/unzipit/dist/unzipit.module.js
102
- n();
103
- function d(e) {
104
- return e.arrayBuffer ? e.arrayBuffer() : new Promise((t, n) => {
105
- let r = new FileReader();
106
- r.addEventListener("loadend", () => {
107
- t(r.result);
108
- }), r.addEventListener("error", n), r.readAsArrayBuffer(e);
109
- });
110
- }
111
- async function f(e) {
112
- let t = await d(e);
113
- return new Uint8Array(t);
114
- }
115
- function p(e) {
116
- return typeof Blob < "u" && e instanceof Blob;
117
- }
118
- function m(e) {
119
- return typeof SharedArrayBuffer < "u" && e instanceof SharedArrayBuffer;
120
- }
121
- var h = t !== void 0 && !!t?.versions && t?.versions?.node !== void 0 && t?.versions?.electron === void 0;
122
- function g(e) {
123
- return e.byteOffset === 0 && e.byteLength === e.buffer.byteLength;
124
- }
125
- var _ = class {
126
- constructor(e) {
127
- this.typedArray = e instanceof ArrayBuffer || m(e) ? new Uint8Array(e) : new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
128
- }
129
- async getLength() {
130
- return this.typedArray.byteLength;
131
- }
132
- async read(e, t) {
133
- return new Uint8Array(this.typedArray.buffer, this.typedArray.byteOffset + e, t);
134
- }
135
- }, ee = class {
136
- constructor(e) {
137
- this.blob = e;
138
- }
139
- async getLength() {
140
- return this.blob.size;
141
- }
142
- async read(e, t) {
143
- let n = await d(this.blob.slice(e, e + t));
144
- return new Uint8Array(n);
145
- }
146
- async sliceAsBlob(e, t, n = "") {
147
- return this.blob.slice(e, e + t, n);
148
- }
149
- }, v = {
150
- numWorkers: 1,
151
- workerURL: "",
152
- useWorkers: !1
153
- }, te = 0, ne = 0, re = !0, ie = [], y = [], b = [], x = /* @__PURE__ */ new Map();
154
- function ae(e) {
155
- ce(e.target);
156
- let { id: t, error: n, data: r } = e.data, i = x.get(t);
157
- x.delete(t), n ? i.reject(n) : i.resolve(r);
158
- }
159
- function oe(e) {
160
- return new Promise((t, n) => {
161
- let r = new Worker(e);
162
- r.onmessage = (e) => {
163
- e.data === "start" ? (r.onerror = null, r.onmessage = null, t(r)) : n(/* @__PURE__ */ Error(`unexpected message: ${e.data}`));
164
- }, r.onerror = n;
165
- });
166
- }
167
- var se = function() {
168
- return h ? {
169
- async createWorker(t) {
170
- let { Worker: n } = await import("./__vite-browser-external-BIIyDRRX.js").then((t) => /* @__PURE__ */ e(t.default, 1));
171
- return new n(t);
172
- },
173
- addEventListener(e, t) {
174
- e.on("message", (n) => {
175
- t({
176
- target: e,
177
- data: n
178
- });
179
- });
180
- },
181
- async terminate(e) {
182
- await e.terminate();
183
- }
184
- } : {
185
- async createWorker(e) {
186
- try {
187
- return await oe(e);
188
- } catch {
189
- console.warn("could not load worker:", e);
190
- }
191
- let t;
192
- try {
193
- let n = await fetch(e, { mode: "cors" });
194
- if (!n.ok) throw Error(`could not load: ${e}`);
195
- t = await n.text(), e = URL.createObjectURL(new Blob([t], { type: "application/javascript" }));
196
- let r = await oe(e);
197
- return v.workerURL = e, r;
198
- } catch {
199
- console.warn("could not load worker via fetch:", e);
200
- }
201
- if (t !== void 0) try {
202
- e = `data:application/javascript;base64,${btoa(t)}`;
203
- let n = await oe(e);
204
- return v.workerURL = e, n;
205
- } catch {
206
- console.warn("could not load worker via dataURI");
207
- }
208
- throw console.warn("workers will not be used"), Error("can not start workers");
209
- },
210
- addEventListener(e, t) {
211
- e.addEventListener("message", t);
212
- },
213
- async terminate(e) {
214
- e.terminate();
215
- }
216
- };
217
- }();
218
- function ce(e) {
219
- y.push(e), fe();
220
- }
221
- async function le() {
222
- if (y.length === 0 && ne < v.numWorkers) {
223
- ++ne;
224
- try {
225
- let e = await se.createWorker(v.workerURL);
226
- ie.push(e), y.push(e), se.addEventListener(e, ae);
227
- } catch {
228
- re = !1;
229
- }
230
- }
231
- return y.pop();
232
- }
233
- async function ue(e) {
234
- let t = new DecompressionStream("deflate-raw"), n = t.writable.getWriter();
235
- n.write(e).then(() => n.close()).catch(() => {});
236
- let r = [], i = t.readable.getReader();
237
- for (;;) {
238
- let { done: e, value: t } = await i.read();
239
- if (e) break;
240
- r.push(t);
241
- }
242
- let a = r.reduce((e, t) => e + t.byteLength, 0), o = new Uint8Array(a), s = 0;
243
- for (let e of r) o.set(e, s), s += e.byteLength;
244
- return o;
245
- }
246
- async function de(e, t, n, r) {
247
- try {
248
- let r = await ue(e);
249
- n(t ? new Blob([r], { type: t }) : r.buffer);
250
- } catch (e) {
251
- r(e);
252
- }
253
- }
254
- async function fe() {
255
- if (b.length !== 0) {
256
- if (v.useWorkers && re) {
257
- let e = await le();
258
- if (re) {
259
- if (e) {
260
- if (b.length === 0) {
261
- ce(e);
262
- return;
263
- }
264
- let { id: t, src: n, uncompressedSize: r, type: i, resolve: a, reject: o } = b.shift();
265
- x.set(t, {
266
- id: t,
267
- src: n,
268
- uncompressedSize: r,
269
- type: i,
270
- resolve: a,
271
- reject: o
272
- }), e.postMessage({
273
- type: "inflate",
274
- data: {
275
- id: t,
276
- type: i,
277
- src: n,
278
- uncompressedSize: r
279
- }
280
- }, []);
281
- }
282
- return;
283
- }
284
- }
285
- for (; b.length;) {
286
- let { src: e, type: t, resolve: n, reject: r } = b.shift();
287
- de(p(e) ? await f(e) : e, t, n, r);
288
- }
289
- }
290
- }
291
- function pe(e, t, n) {
292
- return new Promise((r, i) => {
293
- b.push({
294
- src: e,
295
- uncompressedSize: t,
296
- type: n,
297
- resolve: r,
298
- reject: i,
299
- id: te++
300
- }), fe();
301
- });
302
- }
303
- function me(e, t) {
304
- let n = e & 31, r = (e >> 5 & 15) - 1, i = (e >> 9 & 127) + 1980, a = (t & 31) * 2, o = t >> 5 & 63, s = t >> 11 & 31;
305
- return new Date(i, r, n, s, o, a, 0);
306
- }
307
- var he = class {
308
- constructor(e, t) {
309
- this._reader = e, this._rawEntry = t, this.name = t.name, this.nameBytes = t.nameBytes, this.size = t.uncompressedSize, this.compressedSize = t.compressedSize, this.comment = t.comment, this.commentBytes = t.commentBytes, this.compressionMethod = t.compressionMethod, this.lastModDate = me(t.lastModFileDate, t.lastModFileTime), this.isDirectory = t.uncompressedSize === 0 && t.name.endsWith("/"), this.encrypted = !!(t.generalPurposeBitFlag & 1), this.externalFileAttributes = t.externalFileAttributes, this.versionMadeBy = t.versionMadeBy;
310
- }
311
- async blob(e = "application/octet-stream") {
312
- return await ke(this._reader, this._rawEntry, e);
313
- }
314
- async arrayBuffer() {
315
- return await Oe(this._reader, this._rawEntry);
316
- }
317
- async text() {
318
- let e = await this.arrayBuffer();
319
- return E(new Uint8Array(e));
320
- }
321
- async json() {
322
- let e = await this.text();
323
- return JSON.parse(e);
324
- }
325
- }, ge = 22, _e = 101010256, ve = 101075792;
326
- async function S(e, t, n) {
327
- return await e.read(t, n);
328
- }
329
- async function ye(e, t, n, r) {
330
- return e.sliceAsBlob ? await e.sliceAsBlob(t, n, r) : await e.read(t, n);
331
- }
332
- var be = { unsigned() {
333
- return 0;
334
- } };
335
- function C(e, t) {
336
- return e[t] + e[t + 1] * 256;
337
- }
338
- function w(e, t) {
339
- return e[t] + e[t + 1] * 256 + e[t + 2] * 65536 + e[t + 3] * 16777216;
340
- }
341
- function T(e, t) {
342
- return w(e, t) + w(e, t + 4) * 4294967296;
343
- }
344
- var xe = new TextDecoder();
345
- function E(e, t) {
346
- return m(e.buffer) && (e = new Uint8Array(e)), xe.decode(e);
347
- }
348
- async function Se(e, t) {
349
- let n = Math.min(65557, t), r = t - n, i = await S(e, r, n);
350
- for (let t = n - ge; t >= 0; --t) {
351
- if (w(i, t) !== _e) continue;
352
- let n = new Uint8Array(i.buffer, i.byteOffset + t, i.byteLength - t), a = C(n, 4);
353
- if (a !== 0) throw Error(`multi-volume zip files are not supported. This is volume: ${a}`);
354
- let o = C(n, 10), s = w(n, 12), c = w(n, 16), l = C(n, 20), u = n.length - ge;
355
- if (l !== u) throw Error(`invalid comment length. expected: ${u}, actual: ${l}`);
356
- let d = new Uint8Array(n.buffer, n.byteOffset + 22, l), f = E(d);
357
- return o === 65535 || c === 4294967295 ? await we(e, r + t, f, d) : await Ee(e, c, s, o, f, d);
358
- }
359
- throw Error("could not find end of central directory. maybe not zip file");
360
- }
361
- var Ce = 117853008;
362
- async function we(e, t, n, r) {
363
- let i = await S(e, t - 20, 20);
364
- if (w(i, 0) !== Ce) throw Error("invalid zip64 end of central directory locator signature");
365
- let a = await S(e, T(i, 8), 56);
366
- if (w(a, 0) !== ve) throw Error("invalid zip64 end of central directory record signature");
367
- let o = T(a, 32), s = T(a, 40);
368
- return Ee(e, T(a, 48), s, o, n, r);
369
- }
370
- var Te = 33639248;
371
- async function Ee(e, t, n, r, i, a) {
372
- let o = 0, s = await S(e, t, n), c = [];
373
- for (let e = 0; e < r; ++e) {
374
- let e = s.subarray(o, o + 46), t = w(e, 0);
375
- if (t !== Te) throw Error(`invalid central directory file header signature: 0x${t.toString(16)}`);
376
- let n = {
377
- versionMadeBy: C(e, 4),
378
- versionNeededToExtract: C(e, 6),
379
- generalPurposeBitFlag: C(e, 8),
380
- compressionMethod: C(e, 10),
381
- lastModFileTime: C(e, 12),
382
- lastModFileDate: C(e, 14),
383
- crc32: w(e, 16),
384
- compressedSize: w(e, 20),
385
- uncompressedSize: w(e, 24),
386
- fileNameLength: C(e, 28),
387
- extraFieldLength: C(e, 30),
388
- fileCommentLength: C(e, 32),
389
- internalFileAttributes: C(e, 36),
390
- externalFileAttributes: w(e, 38),
391
- relativeOffsetOfLocalHeader: w(e, 42)
392
- };
393
- if (n.generalPurposeBitFlag & 64) throw Error("strong encryption is not supported");
394
- o += 46;
395
- let r = s.subarray(o, o + n.fileNameLength + n.extraFieldLength + n.fileCommentLength);
396
- n.generalPurposeBitFlag & 2048, n.nameBytes = r.slice(0, n.fileNameLength), n.name = E(n.nameBytes);
397
- let i = n.fileNameLength + n.extraFieldLength, a = r.slice(n.fileNameLength, i);
398
- n.extraFields = [];
399
- let l = 0;
400
- for (; l < a.length - 3;) {
401
- let e = C(a, l + 0), t = C(a, l + 2), r = l + 4, i = r + t;
402
- if (i > a.length) throw Error("extra field length exceeds extra field buffer size");
403
- n.extraFields.push({
404
- id: e,
405
- data: a.slice(r, i)
406
- }), l = i;
407
- }
408
- if (n.commentBytes = r.slice(i, i + n.fileCommentLength), n.comment = E(n.commentBytes), o += r.length, n.uncompressedSize === 4294967295 || n.compressedSize === 4294967295 || n.relativeOffsetOfLocalHeader === 4294967295) {
409
- let e = n.extraFields.find((e) => e.id === 1);
410
- if (!e) throw Error("expected zip64 extended information extra field");
411
- let t = e.data, r = 0;
412
- if (n.uncompressedSize === 4294967295) {
413
- if (r + 8 > t.length) throw Error("zip64 extended information extra field does not include uncompressed size");
414
- n.uncompressedSize = T(t, r), r += 8;
415
- }
416
- if (n.compressedSize === 4294967295) {
417
- if (r + 8 > t.length) throw Error("zip64 extended information extra field does not include compressed size");
418
- n.compressedSize = T(t, r), r += 8;
419
- }
420
- if (n.relativeOffsetOfLocalHeader === 4294967295) {
421
- if (r + 8 > t.length) throw Error("zip64 extended information extra field does not include relative header offset");
422
- n.relativeOffsetOfLocalHeader = T(t, r), r += 8;
423
- }
424
- }
425
- let u = n.extraFields.find((e) => e.id === 28789 && e.data.length >= 6 && e.data[0] === 1 && w(e.data, 1), be.unsigned());
426
- if (u && (n.fileName = E(u.data.slice(5))), n.compressionMethod === 0) {
427
- let e = n.uncompressedSize;
428
- if (n.generalPurposeBitFlag & 1 && (e += 12), n.compressedSize !== e) throw Error(`compressed size mismatch for stored file: ${n.compressedSize} != ${e}`);
429
- }
430
- c.push(n);
431
- }
432
- return {
433
- zip: {
434
- comment: i,
435
- commentBytes: a
436
- },
437
- entries: c.map((t) => new he(e, t))
438
- };
439
- }
440
- async function De(e, t) {
441
- if (t.generalPurposeBitFlag & 1) throw Error("encrypted entries not supported");
442
- let n = await S(e, t.relativeOffsetOfLocalHeader, 30), r = await e.getLength(), i = w(n, 0);
443
- if (i !== 67324752) throw Error(`invalid local file header signature: 0x${i.toString(16)}`);
444
- let a = C(n, 26), o = C(n, 28), s = t.relativeOffsetOfLocalHeader + n.length + a + o, c;
445
- if (t.compressionMethod === 0) c = !1;
446
- else if (t.compressionMethod === 8) c = !0;
447
- else throw Error(`unsupported compression method: ${t.compressionMethod}`);
448
- let l = s, u = l + t.compressedSize;
449
- if (t.compressedSize !== 0 && u > r) throw Error(`file data overflows file bounds: ${l} + ${t.compressedSize} > ${r}`);
450
- return {
451
- decompress: c,
452
- fileDataStart: l
453
- };
454
- }
455
- async function Oe(e, t) {
456
- let { decompress: n, fileDataStart: r } = await De(e, t);
457
- if (!n) {
458
- let n = await S(e, r, t.compressedSize);
459
- return g(n) ? n.buffer : n.slice().buffer;
460
- }
461
- let i = await ye(e, r, t.compressedSize);
462
- return await pe((i instanceof Uint8Array, i), t.uncompressedSize);
463
- }
464
- async function ke(e, t, n) {
465
- let { decompress: r, fileDataStart: i } = await De(e, t);
466
- if (!r) {
467
- let r = await ye(e, i, t.compressedSize, n);
468
- return p(r) ? r : new Blob([r], { type: n });
469
- }
470
- let a = await ye(e, i, t.compressedSize);
471
- return await pe((a instanceof Uint8Array, a), t.uncompressedSize, n);
472
- }
473
- async function Ae(e) {
474
- let t;
475
- if (typeof Blob < "u" && e instanceof Blob) t = new ee(e);
476
- else if (e instanceof ArrayBuffer || e && e.buffer && e.buffer instanceof ArrayBuffer) t = new _(e);
477
- else if (m(e) || m(e.buffer)) t = new _(e);
478
- else if (typeof e == "string") {
479
- let n = await fetch(e);
480
- if (!n.ok) throw Error(`failed http request ${e}, status: ${n.status}: ${n.statusText}`);
481
- t = new ee(await n.blob());
482
- } else if (typeof e.getLength == "function" && typeof e.read == "function") t = e;
483
- else throw Error("unsupported source type");
484
- let n = await t.getLength();
485
- if (n > 2 ** 53 - 1) throw Error(`file too large. size: ${n}. Only file sizes up 4503599627370496 bytes are supported`);
486
- return await Se(t, n);
487
- }
488
- async function je(e) {
489
- let { zip: t, entries: n } = await Ae(e);
490
- return {
491
- zip: t,
492
- entries: Object.fromEntries(n.map((e) => [e.name, e]))
493
- };
494
- }
495
- //#endregion
496
- //#region node_modules/.pnpm/@zarrita+storage@0.2.0/node_modules/@zarrita/storage/dist/src/zip.js
497
- function Me(e) {
498
- if (!("_rawEntry" in e)) return;
499
- let t = e._rawEntry;
500
- if (typeof t == "object" && t && "relativeOffsetOfLocalHeader" in t && typeof t.relativeOffsetOfLocalHeader == "number") return { relativeOffsetOfLocalHeader: t.relativeOffsetOfLocalHeader };
501
- }
502
- var Ne = class {
503
- blob;
504
- constructor(e) {
505
- this.blob = e;
506
- }
507
- async getLength() {
508
- return this.blob.size;
509
- }
510
- async read(e, t) {
511
- let n = this.blob.slice(e, e + t);
512
- return new Uint8Array(await n.arrayBuffer());
513
- }
514
- }, Pe = class {
515
- url;
516
- length;
517
- #e;
518
- constructor(e, t = {}) {
519
- this.url = e, this.#e = t.overrides ?? {};
520
- }
521
- async getLength() {
522
- if (this.length === void 0) {
523
- let e = await fetch(this.url, {
524
- ...this.#e,
525
- method: "HEAD"
526
- });
527
- if (s(e.ok, `failed http request ${this.url}, status: ${e.status}: ${e.statusText}`), this.length = Number(e.headers.get("content-length")), Number.isNaN(this.length)) throw Error("could not get length");
528
- }
529
- return this.length;
530
- }
531
- async read(e, t) {
532
- if (t === 0) return new Uint8Array();
533
- let n = await a(this.url, e, t, this.#e);
534
- return s(n.ok, `failed http request ${this.url}, status: ${n.status} offset: ${e} size: ${t}: ${n.statusText}`), new Uint8Array(await n.arrayBuffer());
535
- }
536
- }, Fe = class e {
537
- info;
538
- reader;
539
- constructor(e, t = {}) {
540
- this.reader = e, this.info = je(e).then((e) => (t.transformEntries && (e.entries = t.transformEntries(e.entries)), e));
541
- }
542
- async getEntryDataOffset(e) {
543
- let t = e.relativeOffsetOfLocalHeader, n = await this.reader.read(t, 30), r = n[26] + n[27] * 256, i = n[28] + n[29] * 256;
544
- return t + 30 + r + i;
545
- }
546
- async get(e) {
547
- let t = (await this.info).entries[i(e)];
548
- if (t) return new Uint8Array(await t.arrayBuffer());
549
- }
550
- async getRange(e, t) {
551
- let n = (await this.info).entries[i(e)];
552
- if (!n) return;
553
- let r = Me(n);
554
- if (!r) throw Error("ZipFileStore.getRange requires internal unzipit properties that are not available. This may indicate an incompatible version of unzipit.");
555
- if (n.compressionMethod !== 0) {
556
- let n = await this.get(e);
557
- return n ? "suffixLength" in t ? n.slice(-t.suffixLength) : n.slice(t.offset, t.offset + t.length) : void 0;
558
- }
559
- let a = await this.getEntryDataOffset(r);
560
- if ("suffixLength" in t) {
561
- let e = a + n.size - t.suffixLength;
562
- return this.reader.read(e, t.suffixLength);
563
- }
564
- return this.reader.read(a + t.offset, t.length);
565
- }
566
- async has(e) {
567
- return i(e) in (await this.info).entries;
568
- }
569
- static fromUrl(t, n = {}) {
570
- return new e(new Pe(t, n), n);
571
- }
572
- static fromBlob(t, n = {}) {
573
- return new e(new Ne(t), n);
574
- }
575
- }, D = class extends Error {}, O = class extends D {
576
- _tag = "NotFoundError";
577
- name = "NotFoundError";
578
- path;
579
- found;
580
- constructor(e, t = {}) {
581
- super(`Not found: ${e}`, { cause: t.cause }), this.path = t.path, this.found = t.found;
582
- }
583
- }, k = class extends D {
584
- _tag = "InvalidMetadataError";
585
- name = "InvalidMetadataError";
586
- path;
587
- constructor(e, t = {}) {
588
- super(e, { cause: t.cause }), this.path = t.path;
589
- }
590
- }, Ie = class extends D {
591
- _tag = "UnknownCodecError";
592
- name = "UnknownCodecError";
593
- codec;
594
- constructor(e) {
595
- super(`Unknown codec: ${e}`), this.codec = e;
596
- }
597
- }, Le = class extends D {
598
- _tag = "CodecPipelineError";
599
- name = "CodecPipelineError";
600
- direction;
601
- codec;
602
- chunkPath;
603
- constructor(e) {
604
- let t = [
605
- `Failed to ${e.direction} chunk`,
606
- e.codec && `via codec "${e.codec}"`,
607
- e.chunkPath && `at ${e.chunkPath}`
608
- ].filter(Boolean);
609
- super(t.join(" "), { cause: e.cause }), this.direction = e.direction, this.codec = e.codec, this.chunkPath = e.chunkPath;
610
- }
611
- }, A = class extends D {
612
- _tag = "InvalidSelectionError";
613
- name = "InvalidSelectionError";
614
- }, Re = class extends D {
615
- _tag = "UnsupportedError";
616
- name = "UnsupportedError";
617
- feature;
618
- constructor(e) {
619
- super(`Unsupported: ${e}`), this.feature = e;
620
- }
621
- };
622
- //#endregion
623
- //#region node_modules/.pnpm/zarrita@0.7.5/node_modules/zarrita/dist/src/codecs/_shared.js
624
- function j(e) {
625
- return () => {
626
- throw new Re(`${e} encode`);
627
- };
628
- }
629
- //#endregion
630
- //#region node_modules/.pnpm/zarrita@0.7.5/node_modules/zarrita/dist/src/codecs/bitround.js
631
- var ze = class e {
632
- kind = "array_to_array";
633
- constructor(e, t) {
634
- if (e.keepbits < 0) throw new k("keepbits must be zero or positive");
635
- }
636
- static fromConfig(t, n) {
637
- return new e(t, n);
638
- }
639
- encode = j("bitround");
640
- decode(e) {
641
- return e;
642
- }
643
- };
644
- //#endregion
645
- //#region node_modules/.pnpm/zarrita@0.7.5/node_modules/zarrita/dist/src/typedarray.js
646
- function M(e) {
647
- return e instanceof ArrayBuffer || e instanceof SharedArrayBuffer;
648
- }
649
- var Be = class {
650
- #e;
651
- constructor(e, t, n) {
652
- typeof e == "number" ? this.#e = new Uint8Array(e) : M(e) ? this.#e = new Uint8Array(e, t, n) : this.#e = new Uint8Array(Array.from(e, (e) => +!!e));
653
- }
654
- get BYTES_PER_ELEMENT() {
655
- return 1;
656
- }
657
- get byteOffset() {
658
- return this.#e.byteOffset;
659
- }
660
- get byteLength() {
661
- return this.#e.byteLength;
662
- }
663
- get buffer() {
664
- return this.#e.buffer;
665
- }
666
- get length() {
667
- return this.#e.length;
668
- }
669
- get(e) {
670
- let t = this.#e[e];
671
- return typeof t == "number" ? t !== 0 : t;
672
- }
673
- set(e, t) {
674
- this.#e[e] = +!!t;
675
- }
676
- fill(e) {
677
- this.#e.fill(+!!e);
678
- }
679
- *[Symbol.iterator]() {
680
- for (let e = 0; e < this.length; e++) yield this.get(e);
681
- }
682
- }, N = class {
683
- _data;
684
- chars;
685
- #e;
686
- constructor(e, t, n, r) {
687
- if (this.chars = e, this.#e = new TextEncoder(), typeof t == "number") this._data = new Uint8Array(t * e);
688
- else if (M(t)) r && (r *= e), this._data = new Uint8Array(t, n, r);
689
- else {
690
- let n = Array.from(t);
691
- this._data = new Uint8Array(n.length * e);
692
- for (let e = 0; e < n.length; e++) this.set(e, n[e]);
693
- }
694
- }
695
- get BYTES_PER_ELEMENT() {
696
- return this.chars;
697
- }
698
- get byteOffset() {
699
- return this._data.byteOffset;
700
- }
701
- get byteLength() {
702
- return this._data.byteLength;
703
- }
704
- get buffer() {
705
- return this._data.buffer;
706
- }
707
- get length() {
708
- return this.byteLength / this.BYTES_PER_ELEMENT;
709
- }
710
- get(e) {
711
- let t = new Uint8Array(this.buffer, this.byteOffset + this.chars * e, this.chars);
712
- return new TextDecoder().decode(t).replace(/\x00/g, "");
713
- }
714
- set(e, t) {
715
- let n = new Uint8Array(this.buffer, this.byteOffset + this.chars * e, this.chars);
716
- n.fill(0), n.set(this.#e.encode(t));
717
- }
718
- fill(e) {
719
- let t = this.#e.encode(e);
720
- for (let e = 0; e < this.length; e++) this._data.set(t, e * this.chars);
721
- }
722
- *[Symbol.iterator]() {
723
- for (let e = 0; e < this.length; e++) yield this.get(e);
724
- }
725
- }, Ve = class e {
726
- #e;
727
- chars;
728
- constructor(t, n, r, i) {
729
- if (this.chars = t, typeof n == "number") this.#e = new Int32Array(n * t);
730
- else if (M(n)) i && (i *= t), this.#e = new Int32Array(n, r, i);
731
- else {
732
- let r = n, i = new e(t, 1);
733
- this.#e = new Int32Array((function* () {
734
- for (let e of r) i.set(0, e), yield* i.#e;
735
- })());
736
- }
737
- }
738
- get BYTES_PER_ELEMENT() {
739
- return this.#e.BYTES_PER_ELEMENT * this.chars;
740
- }
741
- get byteLength() {
742
- return this.#e.byteLength;
743
- }
744
- get byteOffset() {
745
- return this.#e.byteOffset;
746
- }
747
- get buffer() {
748
- return this.#e.buffer;
749
- }
750
- get length() {
751
- return this.#e.length / this.chars;
752
- }
753
- get(e) {
754
- let t = this.chars * e, n = "";
755
- for (let e = 0; e < this.chars; e++) n += String.fromCodePoint(this.#e[t + e]);
756
- return n.replace(/\u0000/g, "");
757
- }
758
- set(e, t) {
759
- let n = this.chars * e, r = this.#e.subarray(n, n + this.chars);
760
- r.fill(0);
761
- for (let e = 0; e < this.chars; e++) r[e] = t.codePointAt(e) ?? 0;
762
- }
763
- fill(e) {
764
- this.set(0, e);
765
- let t = this.#e.subarray(0, this.chars);
766
- for (let e = 1; e < this.length; e++) this.#e.set(t, e * this.chars);
767
- }
768
- *[Symbol.iterator]() {
769
- for (let e = 0; e < this.length; e++) yield this.get(e);
770
- }
771
- };
772
- //#endregion
773
- //#region node_modules/.pnpm/zarrita@0.7.5/node_modules/zarrita/dist/src/util.js
774
- function He() {
775
- if (typeof SharedArrayBuffer > "u") throw Error("SharedArrayBuffer is not available. In browsers, this requires Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy headers to be set.");
776
- }
777
- function Ue(e, t) {
778
- return t ? new SharedArrayBuffer(e) : new ArrayBuffer(e);
779
- }
780
- function P(e) {
781
- let t = new TextDecoder().decode(e);
782
- try {
783
- return JSON.parse(t);
784
- } catch (e) {
785
- throw new k("Failed to decode JSON", { cause: e });
786
- }
787
- }
788
- function We(e, t) {
789
- let n = t / 2, r = t - 1, i = 0;
790
- for (let a = 0; a < e.length; a += t) for (let t = 0; t < n; t += 1) i = e[a + t], e[a + t] = e[a + r - t], e[a + r - t] = i;
791
- }
792
- function F(e) {
793
- if (e === "v2:object") return globalThis.Array;
794
- let t = e.match(/v2:([US])(\d+)/);
795
- if (t) {
796
- let [, e, n] = t;
797
- return (e === "U" ? Ve : N).bind(null, Number(n));
798
- }
799
- if (e === "string") return globalThis.Array;
800
- let n = {
801
- int8: Int8Array,
802
- int16: Int16Array,
803
- int32: Int32Array,
804
- int64: globalThis.BigInt64Array,
805
- uint8: Uint8Array,
806
- uint16: Uint16Array,
807
- uint32: Uint32Array,
808
- uint64: globalThis.BigUint64Array,
809
- float16: globalThis.Float16Array,
810
- float32: Float32Array,
811
- float64: Float64Array,
812
- bool: Be
813
- }[e];
814
- if (!n) throw new k(`Unknown or unsupported dataType: ${e}`);
815
- return n;
816
- }
817
- function I(e, t) {
818
- let n = e.length;
819
- typeof t == "string" && (t = t === "C" ? Array.from({ length: n }, (e, t) => t) : Array.from({ length: n }, (e, t) => n - 1 - t)), L(n === t.length, "Order length must match the number of dimensions.");
820
- let r = 1, i = Array(n);
821
- for (let n = t.length - 1; n >= 0; n--) i[t[n]] = r, r *= e[t[n]];
822
- return i;
823
- }
824
- function Ge({ name: e, configuration: t }) {
825
- if (e === "default") {
826
- let e = t?.separator ?? "/";
827
- return (t) => ["c", ...t].join(e);
828
- }
829
- if (e === "v2") {
830
- let e = t?.separator ?? ".";
831
- return (t) => t.join(e) || "0";
832
- }
833
- throw new k(`Unknown chunk key encoding: ${e}`);
834
- }
835
- function Ke(e) {
836
- if (e === "|O") return { dataType: "v2:object" };
837
- let t = e.match(/^([<|>])(.*)$/);
838
- if (!t) throw new k(`Invalid dtype: ${e}`);
839
- let [, n, r] = t, i = {
840
- b1: "bool",
841
- i1: "int8",
842
- u1: "uint8",
843
- i2: "int16",
844
- u2: "uint16",
845
- i4: "int32",
846
- u4: "uint32",
847
- i8: "int64",
848
- u8: "uint64",
849
- f2: "float16",
850
- f4: "float32",
851
- f8: "float64"
852
- }[r] ?? (r.startsWith("S") || r.startsWith("U") ? `v2:${r}` : void 0);
853
- if (!i) throw new k(`Unsupported or unknown dtype: ${e}`);
854
- return n === "|" ? { dataType: i } : {
855
- dataType: i,
856
- endian: n === "<" ? "little" : "big"
857
- };
858
- }
859
- function qe(e) {
860
- return (e.id === "fixedscaleoffset" || e.id === "numcodecs.fixedscaleoffset") && typeof e.scale == "number" && typeof e.offset == "number" && (e.astype === void 0 || typeof e.astype == "string") && (e.dtype === void 0 || typeof e.dtype == "string");
861
- }
862
- function Je(e, t = {}) {
863
- let n = [], r = Ke(e.dtype);
864
- e.order === "F" && n.push({
865
- name: "transpose",
866
- configuration: { order: "F" }
867
- });
868
- for (let t of e.filters ?? []) {
869
- if (t.id === "fixedscaleoffset" || t.id === "numcodecs.fixedscaleoffset") {
870
- if (!qe(t)) throw new k(`Invalid fixedscaleoffset filter: ${JSON.stringify(t)}`);
871
- n.push({
872
- name: "scale_offset",
873
- configuration: {
874
- scale: t.scale,
875
- offset: t.offset
876
- }
877
- });
878
- let r = t.astype ?? t.dtype;
879
- if (r !== void 0 && r !== e.dtype) {
880
- let e = Ke(r).dataType;
881
- if (!Xe(e, "number") && !Xe(e, "bigint")) throw new k(`fixedscaleoffset astype must be a numeric data type, got ${r}`);
882
- n.push({
883
- name: "cast_value",
884
- configuration: {
885
- data_type: e,
886
- rounding: "nearest-even",
887
- out_of_range: "wrap"
888
- }
889
- });
890
- }
891
- continue;
892
- }
893
- let { id: r, ...i } = t;
894
- n.push({
895
- name: `numcodecs.${r}`,
896
- configuration: i
897
- });
898
- }
899
- if ("endian" in r && r.endian === "big" && n.push({
900
- name: "bytes",
901
- configuration: { endian: "big" }
902
- }), e.compressor) {
903
- let { id: t, ...r } = e.compressor;
904
- n.push({
905
- name: `numcodecs.${t}`,
906
- configuration: r
907
- });
908
- }
909
- let i;
910
- return globalThis.Array.isArray(t._ARRAY_DIMENSIONS) && (i = t._ARRAY_DIMENSIONS), {
911
- zarr_format: 3,
912
- node_type: "array",
913
- shape: e.shape,
914
- data_type: r.dataType,
915
- chunk_grid: {
916
- name: "regular",
917
- configuration: { chunk_shape: e.chunks }
918
- },
919
- chunk_key_encoding: {
920
- name: "v2",
921
- configuration: { separator: e.dimension_separator ?? "." }
922
- },
923
- codecs: n,
924
- fill_value: e.fill_value,
925
- dimension_names: i,
926
- attributes: t
927
- };
928
- }
929
- function Ye(e, t = {}) {
930
- return {
931
- zarr_format: 3,
932
- node_type: "group",
933
- attributes: t
934
- };
935
- }
936
- function Xe(e, t) {
937
- if (t !== "number" && t !== "bigint" && t !== "boolean" && t !== "object" && t !== "string") return e === t;
938
- let n = e === "bool";
939
- if (t === "boolean") return n;
940
- let r = e.startsWith("v2:U") || e.startsWith("v2:S") || e === "string";
941
- if (t === "string") return r;
942
- let i = e === "int64" || e === "uint64";
943
- if (t === "bigint") return i;
944
- let a = e === "v2:object";
945
- return t === "object" ? a : !r && !i && !n && !a;
946
- }
947
- function Ze(e) {
948
- return e?.name === "sharding_indexed";
949
- }
950
- function Qe(e) {
951
- if ((e.data_type === "uint64" || e.data_type === "int64") && e.fill_value != null) return BigInt(e.fill_value);
952
- let t = e.data_type === "float16" || e.data_type === "float32" || e.data_type === "float64";
953
- if (typeof e.fill_value == "string" && t) {
954
- let t = {
955
- NaN: NaN,
956
- Infinity: Infinity,
957
- "-Infinity": -Infinity
958
- };
959
- if (e.fill_value in t) return t[e.fill_value];
960
- }
961
- return e.fill_value;
962
- }
963
- function $e(e) {
964
- let t = e.signal, n = e.opts?.signal;
965
- return t && n ? AbortSignal.any([t, n]) : t ?? n;
966
- }
967
- function et(e, ...t) {
968
- if (!t.some((t) => e instanceof t)) throw e;
969
- }
970
- function L(e, t = "") {
971
- if (!e) throw Error(t);
972
- }
973
- async function tt(e, { format: t, signal: n }) {
974
- let r;
975
- if (e instanceof ArrayBuffer) r = new Response(e);
976
- else {
977
- let t = new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
978
- r = new Response(t.slice().buffer);
979
- }
980
- L(r.body, "Response does not contain body.");
981
- try {
982
- return await new Response(r.body.pipeThrough(new DecompressionStream(t), { signal: n })).arrayBuffer();
983
- } catch {
984
- throw n?.throwIfAborted(), Error(`Failed to decode ${t}`);
985
- }
986
- }
987
- //#endregion
988
- //#region node_modules/.pnpm/zarrita@0.7.5/node_modules/zarrita/dist/src/codecs/bytes.js
989
- var nt = rt();
990
- function rt() {
991
- let e = new Uint32Array([305419896]);
992
- return new Uint8Array(e.buffer, e.byteOffset, e.byteLength)[0] !== 18;
993
- }
994
- function it(e) {
995
- return "BYTES_PER_ELEMENT" in e ? e.BYTES_PER_ELEMENT : 4;
996
- }
997
- var at = class e {
998
- kind = "array_to_bytes";
999
- #e;
1000
- #t;
1001
- #n;
1002
- #r;
1003
- #i;
1004
- constructor(e, t) {
1005
- this.#i = e?.endian, this.#t = F(t.dataType), this.#r = t.shape, this.#e = I(t.shape, "C");
1006
- let n = new this.#t(0);
1007
- this.#n = n.BYTES_PER_ELEMENT;
1008
- }
1009
- static fromConfig(t, n) {
1010
- return new e(t, n);
1011
- }
1012
- encode(e) {
1013
- let t = new Uint8Array(e.data.buffer);
1014
- return nt && this.#i === "big" && (t = t.slice(), We(t, it(this.#t))), t;
1015
- }
1016
- computeEncodedSize(e) {
1017
- return e;
1018
- }
1019
- decode(e) {
1020
- return nt && this.#i === "big" && (e = e.slice(), We(e, it(this.#t))), e.byteOffset % this.#n !== 0 && (e = e.slice()), {
1021
- data: new this.#t(e.buffer, e.byteOffset, e.byteLength / this.#n),
1022
- shape: this.#r,
1023
- stride: this.#e
1024
- };
1025
- }
1026
- }, ot = {
1027
- NaN: NaN,
1028
- Infinity: Infinity,
1029
- "-Infinity": -Infinity
1030
- }, st = {
1031
- float16: 2,
1032
- float32: 4,
1033
- float64: 8
1034
- };
1035
- function R(e) {
1036
- return e in st;
1037
- }
1038
- function ct(e) {
1039
- return e === "int64" || e === "uint64";
1040
- }
1041
- function lt(e, t) {
1042
- let n = BigInt(e), r = new ArrayBuffer(t), i = new DataView(r);
1043
- if (t === 2) {
1044
- if (typeof i.getFloat16 != "function") throw new Re("float16 hex-encoded scalar decoding (requires DataView.prototype.getFloat16)");
1045
- return i.setUint16(0, Number(n)), i.getFloat16(0);
1046
- }
1047
- return t === 4 ? (i.setUint32(0, Number(n)), i.getFloat32(0)) : (i.setBigUint64(0, n), i.getFloat64(0));
1048
- }
1049
- function z(e, t) {
1050
- if (ct(e)) {
1051
- if (typeof t != "number" || !Number.isInteger(t)) throw new k(`Expected an integer value for data type "${e}", got ${JSON.stringify(t)}`);
1052
- return BigInt(t);
1053
- }
1054
- if (typeof t == "number") {
1055
- if (!R(e) && !Number.isInteger(t)) throw new k(`Expected an integer value for data type "${e}", got ${t}`);
1056
- return t;
1057
- }
1058
- if (!R(e)) throw new k(`String-encoded scalar "${t}" is not valid for non-float data type "${e}"`);
1059
- return t in ot ? ot[t] : lt(t, st[e]);
1060
- }
1061
- //#endregion
1062
- //#region node_modules/.pnpm/zarrita@0.7.5/node_modules/zarrita/dist/src/codecs/cast_value.js
1063
- var ut = new Set([
1064
- "int8",
1065
- "uint8",
1066
- "int16",
1067
- "uint16",
1068
- "int32",
1069
- "uint32",
1070
- "int64",
1071
- "uint64",
1072
- "float16",
1073
- "float32",
1074
- "float64"
1075
- ]), dt = {
1076
- int8: [-128, 2 ** 7 - 1],
1077
- uint8: [0, 2 ** 8 - 1],
1078
- int16: [-(2 ** 15), 2 ** 15 - 1],
1079
- uint16: [0, 2 ** 16 - 1],
1080
- int32: [-(2 ** 31), 2 ** 31 - 1],
1081
- uint32: [0, 2 ** 32 - 1]
1082
- }, ft = {
1083
- int64: [-(2n ** 63n), 2n ** 63n - 1n],
1084
- uint64: [0n, 2n ** 64n - 1n]
1085
- };
1086
- function pt(e, t, n) {
1087
- return e.map(([e, r]) => ({
1088
- src: z(t, e),
1089
- tgt: z(n, r)
1090
- }));
1091
- }
1092
- function mt(e, t) {
1093
- for (let n of t) if (typeof n.src == "number" && Number.isNaN(n.src)) {
1094
- if (typeof e == "number" && Number.isNaN(e)) return n.tgt;
1095
- } else if (e === n.src) return n.tgt;
1096
- }
1097
- function ht(e) {
1098
- if (!Number.isFinite(e)) return e;
1099
- if (Math.abs(e - Math.trunc(e)) === .5) {
1100
- let t = Math.floor(e), n = Math.ceil(e);
1101
- return t % 2 == 0 ? t : n;
1102
- }
1103
- return Math.round(e);
1104
- }
1105
- function gt(e) {
1106
- return Math.sign(e) * Math.floor(Math.abs(e) + .5);
1107
- }
1108
- function _t(e) {
1109
- switch (e) {
1110
- case "nearest-even": return ht;
1111
- case "towards-zero": return Math.trunc;
1112
- case "towards-positive": return Math.ceil;
1113
- case "towards-negative": return Math.floor;
1114
- case "nearest-away": return gt;
1115
- }
1116
- }
1117
- function vt(e, t, n) {
1118
- let r = t - e + 1;
1119
- switch (n) {
1120
- case "clamp": return (n) => n < e ? e : n > t ? t : n;
1121
- case "wrap": return (n) => n >= e && n <= t ? n : ((n - e) % r + r) % r + e;
1122
- default: return (n) => {
1123
- if (n >= e && n <= t) return n;
1124
- throw Error(`Value ${n} out of range [${e}, ${t}]. Set out_of_range='clamp' or out_of_range='wrap' to handle this.`);
1125
- };
1126
- }
1127
- }
1128
- function B(e, t, n) {
1129
- let r = t - e + 1n;
1130
- switch (n) {
1131
- case "clamp": return (n) => n < e ? e : n > t ? t : n;
1132
- case "wrap": return (n) => n >= e && n <= t ? n : ((n - e) % r + r) % r + e;
1133
- default: return (n) => {
1134
- if (n >= e && n <= t) return n;
1135
- throw Error(`Value ${n} out of range [${e}, ${t}]. Set out_of_range='clamp' or out_of_range='wrap' to handle this.`);
1136
- };
1137
- }
1138
- }
1139
- var yt = class e {
1140
- kind = "array_to_array";
1141
- #e;
1142
- #t;
1143
- #n;
1144
- #r;
1145
- constructor(e, t, n, r, i, a) {
1146
- this.#e = t, this.#t = F(e), this.#n = bt(t, e, n, r, i), this.#r = bt(e, t, n, r, a);
1147
- }
1148
- getEncodedMeta(e) {
1149
- let t = e.fillValue;
1150
- return t != null && (t = this.#r(t)), {
1151
- ...e,
1152
- dataType: this.#e,
1153
- fillValue: t
1154
- };
1155
- }
1156
- static fromConfig(t, n) {
1157
- let r = n.dataType, i = t.data_type;
1158
- if (!ut.has(r)) throw new k(`cast_value codec does not support array data type: ${r}`);
1159
- if (!ut.has(i)) throw new k(`cast_value codec does not support encoded data type: ${i}`);
1160
- let a = t.rounding ?? "nearest-even", o = t.scalar_map?.decode ? pt(t.scalar_map.decode, i, r) : [], s = t.scalar_map?.encode ? pt(t.scalar_map.encode, r, i) : [];
1161
- return new e(r, i, a, t.out_of_range, o, s);
1162
- }
1163
- encode = j("cast_value");
1164
- decode(e) {
1165
- let t = e.data, n = new this.#t(t.length);
1166
- for (let e = 0; e < t.length; e++) n[e] = this.#n(t[e]);
1167
- return {
1168
- data: n,
1169
- shape: e.shape,
1170
- stride: e.stride
1171
- };
1172
- }
1173
- };
1174
- function bt(e, t, n, r, i) {
1175
- let a = R(e), o = ct(e), s = R(t), c = ct(t), l;
1176
- if (a && s) {
1177
- if (n !== "nearest-even") throw new k(`cast_value float -> float only supports "nearest-even" rounding, got "${n}"`);
1178
- l = (e) => e;
1179
- } else if (a && !s && !c) {
1180
- let e = _t(n), i = vt(...dt[t], r);
1181
- l = (t) => {
1182
- if (!Number.isFinite(t)) throw Error(`Cannot cast ${t} to integer type without scalar_map`);
1183
- return i(e(t));
1184
- };
1185
- } else if (a && c) {
1186
- let e = _t(n), i = B(...ft[t], r);
1187
- l = (t) => {
1188
- if (!Number.isFinite(t)) throw Error(`Cannot cast ${t} to integer type without scalar_map`);
1189
- return i(BigInt(e(t)));
1190
- };
1191
- } else if (!a && !o && s) l = (e) => e;
1192
- else if (o && s) l = (e) => Number(e);
1193
- else if (!a && !o && !s && !c) l = vt(...dt[t], r);
1194
- else if (!a && !o && c) {
1195
- let e = B(...ft[t], r);
1196
- l = (t) => e(BigInt(t));
1197
- } else if (o && !s && !c) {
1198
- let e = vt(...dt[t], r);
1199
- l = (t) => e(Number(t));
1200
- } else if (o && c) l = B(...ft[t], r);
1201
- else throw Error(`Unhandled type combination: ${e} -> ${t}`);
1202
- return i.length === 0 ? l : (e) => {
1203
- let t = mt(e, i);
1204
- return t === void 0 ? l(e) : t;
1205
- };
1206
- }
1207
- //#endregion
1208
- //#region node_modules/.pnpm/zarrita@0.7.5/node_modules/zarrita/dist/src/codecs/crc32c.js
1209
- var xt = class e {
1210
- kind = "bytes_to_bytes";
1211
- static fromConfig() {
1212
- return new e();
1213
- }
1214
- encode = j("crc32c");
1215
- decode(e) {
1216
- return new Uint8Array(e.buffer, e.byteOffset, e.byteLength - 4);
1217
- }
1218
- computeEncodedSize(e) {
1219
- return e + 4;
1220
- }
1221
- }, St = new Set([
1222
- "int8",
1223
- "uint8",
1224
- "int16",
1225
- "uint16",
1226
- "int32",
1227
- "uint32",
1228
- "int64",
1229
- "uint64",
1230
- "float16",
1231
- "float32",
1232
- "float64"
1233
- ]);
1234
- function Ct(e, t) {
1235
- let n = e.length, r = n === 0 || t[n - 1] === 1;
1236
- for (let i = n - 2; i >= 0 && r; i--) r = t[i] === t[i + 1] * e[i + 1];
1237
- if (r) return;
1238
- let i = n === 0 || t[0] === 1;
1239
- for (let r = 1; r < n && i; r++) i = t[r] === t[r - 1] * e[r - 1];
1240
- if (!i) throw Error(`DeltaCodec requires C- or Fortran-contiguous strides, got shape=${JSON.stringify(e)} stride=${JSON.stringify(t)}`);
1241
- }
1242
- var wt = class e {
1243
- kind = "array_to_array";
1244
- #e;
1245
- constructor(e) {
1246
- this.#e = e;
1247
- }
1248
- static fromConfig(t, n) {
1249
- if (!St.has(n.dataType)) throw new k(`Delta codec does not support data type: ${n.dataType}`);
1250
- return new e(F(n.dataType));
1251
- }
1252
- encode(e) {
1253
- Ct(e.shape, e.stride);
1254
- let t = e.data, n = new this.#e(t.length);
1255
- n[0] = t[0];
1256
- for (let e = 1; e < t.length; e++) n[e] = t[e] - t[e - 1];
1257
- return {
1258
- data: n,
1259
- shape: e.shape,
1260
- stride: e.stride
1261
- };
1262
- }
1263
- decode(e) {
1264
- Ct(e.shape, e.stride);
1265
- let t = e.data, n = new this.#e(t.length);
1266
- n[0] = t[0];
1267
- for (let e = 1; e < t.length; e++) n[e] = n[e - 1] + t[e];
1268
- return {
1269
- data: n,
1270
- shape: e.shape,
1271
- stride: e.stride
1272
- };
1273
- }
1274
- }, Tt = class e {
1275
- kind = "bytes_to_bytes";
1276
- static fromConfig(t) {
1277
- return new e();
1278
- }
1279
- encode = j("gzip");
1280
- async decode(e) {
1281
- let t = await tt(e, { format: "gzip" });
1282
- return new Uint8Array(t);
1283
- }
1284
- };
1285
- //#endregion
1286
- //#region node_modules/.pnpm/zarrita@0.7.5/node_modules/zarrita/dist/src/codecs/json2.js
1287
- function Et(e, t) {
1288
- return L(!Number.isNaN(t), "JsonCodec allow_nan is false but NaN was encountered during encoding."), L(t !== Infinity, "JsonCodec allow_nan is false but Infinity was encountered during encoding."), L(t !== -Infinity, "JsonCodec allow_nan is false but -Infinity was encountered during encoding."), t;
1289
- }
1290
- function Dt(e, t) {
1291
- return t instanceof Object && !Array.isArray(t) ? Object.keys(t).sort().reduce((e, n) => (e[n] = t[n], e), {}) : t;
1292
- }
1293
- var Ot = class e {
1294
- configuration;
1295
- kind = "array_to_bytes";
1296
- #e;
1297
- #t;
1298
- constructor(e = {}) {
1299
- this.configuration = e;
1300
- let { encoding: t = "utf-8", skipkeys: n = !1, ensure_ascii: r = !0, check_circular: i = !0, allow_nan: a = !0, sort_keys: o = !0, indent: s, strict: c = !0 } = e, l = e.separators;
1301
- l ||= s ? [", ", ": "] : [",", ":"], this.#e = {
1302
- encoding: t,
1303
- skipkeys: n,
1304
- ensure_ascii: r,
1305
- check_circular: i,
1306
- allow_nan: a,
1307
- indent: s,
1308
- separators: l,
1309
- sort_keys: o
1310
- }, this.#t = { strict: c };
1311
- }
1312
- static fromConfig(t) {
1313
- return new e(t);
1314
- }
1315
- encode(e) {
1316
- let { indent: t, encoding: n, ensure_ascii: r, check_circular: i, allow_nan: a, sort_keys: o } = this.#e;
1317
- L(n === "utf-8", "JsonCodec does not yet support non-utf-8 encoding.");
1318
- let s = [];
1319
- L(i, "JsonCodec does not yet support skipping the check for circular references during encoding."), a || s.push(Et), o && s.push(Dt);
1320
- let c = Array.from(e.data);
1321
- c.push("|O"), c.push(e.shape);
1322
- let l;
1323
- s.length && (l = (e, t) => {
1324
- let n = t;
1325
- for (let t of s) n = t(e, n);
1326
- return n;
1327
- });
1328
- let u = JSON.stringify(c, l, t);
1329
- return r && (u = u.replace(/[\u007F-\uFFFF]/g, (e) => {
1330
- let t = `0000${e.charCodeAt(0).toString(16)}`;
1331
- return `\\u${t.substring(t.length - 4)}`;
1332
- })), new TextEncoder().encode(u);
1333
- }
1334
- decode(e) {
1335
- let { strict: t } = this.#t;
1336
- L(t, "JsonCodec does not yet support non-strict decoding.");
1337
- let n = P(e), r = n.pop();
1338
- return n.pop(), L(r, "0D not implemented for JsonCodec."), {
1339
- data: n,
1340
- shape: r,
1341
- stride: I(r, "C")
1342
- };
1343
- }
1344
- }, kt = new Set([
1345
- "int8",
1346
- "uint8",
1347
- "int16",
1348
- "uint16",
1349
- "int32",
1350
- "uint32",
1351
- "int64",
1352
- "uint64",
1353
- "float16",
1354
- "float32",
1355
- "float64"
1356
- ]), At = class e {
1357
- kind = "array_to_array";
1358
- #e;
1359
- #t;
1360
- #n;
1361
- constructor(e, t, n) {
1362
- this.#t = e, this.#n = t, this.#e = n;
1363
- }
1364
- static fromConfig(t, n) {
1365
- if (!kt.has(n.dataType)) throw new k(`scale_offset codec does not support data type: ${n.dataType}`);
1366
- return new e(z(n.dataType, t.scale ?? 1), z(n.dataType, t.offset ?? 0), F(n.dataType));
1367
- }
1368
- encode = j("scale_offset");
1369
- decode(e) {
1370
- let t = e.data, n = new this.#e(t.length);
1371
- for (let e = 0; e < t.length; e++) n[e] = t[e] / this.#t + this.#n;
1372
- return {
1373
- data: n,
1374
- shape: e.shape,
1375
- stride: e.stride
1376
- };
1377
- }
1378
- }, jt = class e {
1379
- kind = "bytes_to_bytes";
1380
- #e;
1381
- constructor(e, t) {
1382
- if (t) {
1383
- let e = new (F(t.dataType))(0);
1384
- L("BYTES_PER_ELEMENT" in e, `Shuffle codec requires a fixed-size dtype, got "${t.dataType}"`), this.#e = e.BYTES_PER_ELEMENT;
1385
- } else this.#e = e.elementsize ?? 4;
1386
- }
1387
- static fromConfig(t, n) {
1388
- return new e(t, n);
1389
- }
1390
- encode(e) {
1391
- return Mt(e, this.#e);
1392
- }
1393
- decode(e) {
1394
- return Nt(e, this.#e);
1395
- }
1396
- };
1397
- function Mt(e, t) {
1398
- let n = e.length, r = Math.floor(n / t), i = new Uint8Array(n);
1399
- for (let n = 0; n < t; n++) for (let a = 0; a < r; a++) i[n * r + a] = e[a * t + n];
1400
- return i;
1401
- }
1402
- function Nt(e, t) {
1403
- let n = e.length, r = Math.floor(n / t), i = new Uint8Array(n);
1404
- for (let n = 0; n < t; n++) for (let a = 0; a < r; a++) i[a * t + n] = e[n * r + a];
1405
- return i;
1406
- }
1407
- //#endregion
1408
- //#region node_modules/.pnpm/zarrita@0.7.5/node_modules/zarrita/dist/src/codecs/transpose.js
1409
- function Pt(e) {
1410
- return e instanceof Be || e instanceof N || e instanceof Ve ? new Proxy(e, {
1411
- get(e, t) {
1412
- return e.get(Number(t));
1413
- },
1414
- set(e, t, n) {
1415
- return e.set(Number(t), n), !0;
1416
- }
1417
- }) : e;
1418
- }
1419
- function Ft(e, t) {
1420
- let n;
1421
- return n = e.data instanceof N || e.data instanceof Ve ? new e.data.constructor(e.data.chars, e.data.length) : new e.data.constructor(e.data.length), {
1422
- data: n,
1423
- shape: e.shape,
1424
- stride: I(e.shape, t)
1425
- };
1426
- }
1427
- function It(e, t) {
1428
- let n = Ft(e, t), r = e.shape.length, i = e.shape.reduce((e, t) => e * t, 1), a = Array(r).fill(0), o = Pt(e.data), s = Pt(n.data);
1429
- for (let t = 0; t < i; t++) {
1430
- let t = 0, i = 0;
1431
- for (let o = 0; o < r; o++) t += a[o] * e.stride[o], i += a[o] * n.stride[o];
1432
- s[i] = o[t], a[0] += 1;
1433
- for (let t = 0; t < r; t++) if (a[t] === e.shape[t]) {
1434
- if (t + 1 === r) break;
1435
- a[t] = 0, a[t + 1] += 1;
1436
- }
1437
- }
1438
- return n;
1439
- }
1440
- function Lt(e) {
1441
- let t = e.shape.length;
1442
- return L(t === e.stride.length, "Shape and stride must have the same length."), e.stride.map((e, t) => ({
1443
- stride: e,
1444
- index: t
1445
- })).sort((e, t) => t.stride - e.stride).map((e) => e.index);
1446
- }
1447
- function Rt(e, t) {
1448
- let n = Lt(e);
1449
- return L(n.length === t.length, "Orders must match"), n.every((e, n) => e === t[n]);
1450
- }
1451
- var zt = class e {
1452
- kind = "array_to_array";
1453
- #e;
1454
- constructor(e, t) {
1455
- let n = e.order ?? "C", r = t.shape.length, i = Array(r);
1456
- if (n === "C") for (let e = 0; e < r; ++e) i[e] = e;
1457
- else if (n === "F") for (let e = 0; e < r; ++e) i[e] = r - e - 1;
1458
- else {
1459
- i = n;
1460
- let e = Array(r);
1461
- i.forEach((t) => {
1462
- L(!e[t], `Invalid permutation: ${JSON.stringify(n)}`), e[t] = !0;
1463
- });
1464
- }
1465
- this.#e = i;
1466
- }
1467
- static fromConfig(t, n) {
1468
- return new e(t, n);
1469
- }
1470
- encode(e) {
1471
- return Rt(e, this.#e) ? e : It(e, this.#e);
1472
- }
1473
- decode(e) {
1474
- return {
1475
- data: e.data,
1476
- shape: e.shape,
1477
- stride: I(e.shape, this.#e)
1478
- };
1479
- }
1480
- }, Bt = class e {
1481
- kind = "array_to_bytes";
1482
- #e;
1483
- #t;
1484
- constructor(e) {
1485
- this.#e = e, this.#t = I(e, "C");
1486
- }
1487
- static fromConfig(t, n) {
1488
- return new e(n.shape);
1489
- }
1490
- encode = j("vlen-utf8");
1491
- decode(e) {
1492
- let t = new TextDecoder(), n = new DataView(e.buffer), r = Array(n.getUint32(0, !0)), i = 4;
1493
- for (let a = 0; a < r.length; a++) {
1494
- let o = n.getUint32(i, !0);
1495
- i += 4, r[a] = t.decode(e.buffer.slice(i, i + o)), i += o;
1496
- }
1497
- return {
1498
- data: r,
1499
- shape: this.#e,
1500
- stride: this.#t
1501
- };
1502
- }
1503
- }, Vt = class e {
1504
- kind = "bytes_to_bytes";
1505
- static fromConfig(t) {
1506
- return new e();
1507
- }
1508
- encode = j("zlib");
1509
- async decode(e) {
1510
- let t = await tt(e, { format: "deflate" });
1511
- return new Uint8Array(t);
1512
- }
1513
- };
1514
- //#endregion
1515
- //#region node_modules/.pnpm/zarrita@0.7.5/node_modules/zarrita/dist/src/codecs.js
1516
- function Ht() {
1517
- let e = () => import("./blosc-D7C3XedS.js").then((e) => e.default), t = () => import("./lz4-O6H78S8a.js").then((e) => e.default), n = () => import("./zstd-GeB6dyr_.js").then((e) => e.default), r = () => Tt, i = () => Vt;
1518
- return (/* @__PURE__ */ new Map()).set("blosc", e).set("lz4", t).set("zstd", n).set("gzip", r).set("zlib", i).set("transpose", () => zt).set("bytes", () => at).set("crc32c", () => xt).set("vlen-utf8", () => Bt).set("json2", () => Ot).set("bitround", () => ze).set("cast_value", () => yt).set("scale_offset", () => At).set("numcodecs.blosc", e).set("numcodecs.lz4", t).set("numcodecs.zstd", n).set("numcodecs.gzip", r).set("numcodecs.zlib", i).set("numcodecs.vlen-utf8", () => Bt).set("numcodecs.shuffle", () => jt).set("numcodecs.delta", () => wt).set("numcodecs.bitround", () => ze).set("numcodecs.json2", () => Ot);
1519
- }
1520
- var Ut = Ht();
1521
- function V(e) {
1522
- let t;
1523
- function n() {
1524
- return t ||= Gt(e), t;
1525
- }
1526
- async function r(e, t, n) {
1527
- try {
1528
- return await n();
1529
- } catch (n) {
1530
- throw new Le({
1531
- direction: e,
1532
- codec: t,
1533
- cause: n
1534
- });
1535
- }
1536
- }
1537
- return {
1538
- async encode(e) {
1539
- let t = await n();
1540
- for (let { name: n, codec: i } of t.arrayToArray) e = await r("encode", n, () => i.encode(e));
1541
- let i = await r("encode", t.arrayToBytes.name, () => t.arrayToBytes.codec.encode(e));
1542
- for (let { name: e, codec: n } of t.bytesToBytes) i = await r("encode", e, () => n.encode(i));
1543
- return i;
1544
- },
1545
- async decode(e) {
1546
- let t = await n();
1547
- for (let n = t.bytesToBytes.length - 1; n >= 0; n--) {
1548
- let { name: i, codec: a } = t.bytesToBytes[n];
1549
- e = await r("decode", i, () => a.decode(e));
1550
- }
1551
- let i = await r("decode", t.arrayToBytes.name, () => t.arrayToBytes.codec.decode(e));
1552
- for (let e = t.arrayToArray.length - 1; e >= 0; e--) {
1553
- let { name: n, codec: a } = t.arrayToArray[e];
1554
- i = await r("decode", n, () => a.decode(i));
1555
- }
1556
- return i;
1557
- },
1558
- async computeEncodedSize(e) {
1559
- let t = await n(), r = Wt(t.arrayToBytes.name, t.arrayToBytes.codec, e);
1560
- for (let { name: e, codec: n } of t.bytesToBytes) r = Wt(e, n, r);
1561
- return r;
1562
- }
1563
- };
1564
- }
1565
- function Wt(e, t, n) {
1566
- if (!t.computeEncodedSize) throw new k(`Codec "${e}" cannot compute its encoded size; it is not a fixed-size codec and cannot be used in a sharding index pipeline`);
1567
- return t.computeEncodedSize(n);
1568
- }
1569
- async function Gt(e) {
1570
- let t = e.codecs.map(async (e) => {
1571
- let t = await Ut.get(e.name)?.();
1572
- if (!t) throw new Ie(e.name);
1573
- return {
1574
- Codec: t,
1575
- meta: e
1576
- };
1577
- }), n = [], r, i = [], a = { ...e };
1578
- for await (let { Codec: e, meta: o } of t) {
1579
- let t = e.fromConfig(o.configuration, a);
1580
- switch (t.kind) {
1581
- case "array_to_array":
1582
- n.push({
1583
- name: o.name,
1584
- codec: t
1585
- }), t.getEncodedMeta && (a = t.getEncodedMeta(a));
1586
- break;
1587
- case "array_to_bytes":
1588
- r = {
1589
- name: o.name,
1590
- codec: t
1591
- };
1592
- break;
1593
- default: i.push({
1594
- name: o.name,
1595
- codec: t
1596
- });
1597
- }
1598
- }
1599
- if (!r) {
1600
- if (!Kt(a)) throw new k(`Cannot encode ${a.dataType} to bytes without a codec`);
1601
- r = {
1602
- name: "bytes",
1603
- codec: at.fromConfig({ endian: "little" }, a)
1604
- };
1605
- }
1606
- return {
1607
- arrayToArray: n,
1608
- arrayToBytes: r,
1609
- bytesToBytes: i
1610
- };
1611
- }
1612
- function Kt(e) {
1613
- return e.dataType !== "v2:object" && e.dataType !== "string";
1614
- }
1615
- //#endregion
1616
- //#region node_modules/.pnpm/zarrita@0.7.5/node_modules/zarrita/dist/src/codecs/sharding.js
1617
- var qt = 18446744073709551615n;
1618
- function Jt(e, t, n, r) {
1619
- if (!e.store.getRange) throw new Re("sharding requires a store with getRange");
1620
- let i = e.store.getRange.bind(e.store), a = t.map((e, t) => e / r.chunk_shape[t]), o = V({
1621
- dataType: "uint64",
1622
- shape: [...a, 2],
1623
- codecs: r.index_codecs,
1624
- fillValue: null
1625
- }), s = 16 * a.reduce((e, t) => e * t, 1), c = {};
1626
- return async (t, r) => {
1627
- let l = t.map((e, t) => Math.floor(e / a[t])), u = e.resolve(n(l)).path;
1628
- u in c || (c[u] = (async () => {
1629
- let e = await i(u, { suffixLength: await o.computeEncodedSize(s) }, r);
1630
- return e ? await o.decode(e) : null;
1631
- })().catch((e) => {
1632
- throw delete c[u], e;
1633
- }));
1634
- let d = await c[u];
1635
- if (d === null) return;
1636
- let { data: f, shape: p, stride: m } = d, h = t.map((e, t) => e % p[t]).reduce((e, t, n) => e + t * m[n], 0), g = f[h], _ = f[h + 1];
1637
- if (!(g === qt && _ === qt)) return i(u, {
1638
- offset: Number(g),
1639
- length: Number(_)
1640
- }, r);
1641
- };
1642
- }
1643
- //#endregion
1644
- //#region node_modules/.pnpm/zarrita@0.7.5/node_modules/zarrita/dist/src/hierarchy.js
1645
- var H = class e {
1646
- store;
1647
- path;
1648
- constructor(e, t = "/") {
1649
- this.store = e, this.path = t;
1650
- }
1651
- resolve(t) {
1652
- let n = new URL(`file://${this.path.endsWith("/") ? this.path : `${this.path}/`}`);
1653
- return new e(this.store, decodeURIComponent(new URL(t, n).pathname));
1654
- }
1655
- };
1656
- function Yt(e) {
1657
- return new H(e ?? /* @__PURE__ */ new Map());
1658
- }
1659
- var U = class extends H {
1660
- kind = "group";
1661
- #e;
1662
- constructor(e, t, n) {
1663
- super(e, t), this.#e = n;
1664
- }
1665
- get attrs() {
1666
- return this.#e.attributes;
1667
- }
1668
- };
1669
- function Xt(e) {
1670
- return e.find((e) => e.name === "transpose")?.configuration?.order ?? "C";
1671
- }
1672
- function Zt(e, t) {
1673
- let n = new Map(t.map((e, t) => [e, t]));
1674
- return e.filter((e) => n.has(e)).map((e) => n.get(e));
1675
- }
1676
- function Qt(e) {
1677
- return (t, n) => I(t, globalThis.Array.isArray(e) && n ? Zt(e, n) : e);
1678
- }
1679
- var W = Symbol("zarrita.context");
1680
- function $t(e) {
1681
- return e[W];
1682
- }
1683
- function en(e, t) {
1684
- let { configuration: n } = t.codecs.find(Ze) ?? {}, r = {
1685
- encodeChunkKey: Ge(t.chunk_key_encoding),
1686
- TypedArray: F(t.data_type),
1687
- fillValue: t.fill_value
1688
- };
1689
- if (n) {
1690
- let i = Xt(n.codecs);
1691
- return {
1692
- ...r,
1693
- kind: "sharded",
1694
- chunkShape: n.chunk_shape,
1695
- codec: V({
1696
- dataType: t.data_type,
1697
- shape: n.chunk_shape,
1698
- codecs: n.codecs,
1699
- fillValue: t.fill_value
1700
- }),
1701
- getStrides: Qt(i),
1702
- getChunkBytes: Jt(e, t.chunk_grid.configuration.chunk_shape, r.encodeChunkKey, n)
1703
- };
1704
- }
1705
- let i = Xt(t.codecs);
1706
- return {
1707
- ...r,
1708
- kind: "regular",
1709
- chunkShape: t.chunk_grid.configuration.chunk_shape,
1710
- codec: V({
1711
- dataType: t.data_type,
1712
- shape: t.chunk_grid.configuration.chunk_shape,
1713
- codecs: t.codecs,
1714
- fillValue: t.fill_value
1715
- }),
1716
- getStrides: Qt(i),
1717
- async getChunkBytes(t, n) {
1718
- let i = r.encodeChunkKey(t), a = e.resolve(i).path;
1719
- return e.store.get(a, n);
1720
- }
1721
- };
1722
- }
1723
- var G = class extends H {
1724
- kind = "array";
1725
- #e;
1726
- [W];
1727
- constructor(e, t, n) {
1728
- super(e, t), this.#e = {
1729
- ...n,
1730
- fill_value: Qe(n)
1731
- }, this[W] = en(this, this.#e);
1732
- }
1733
- get attrs() {
1734
- return this.#e.attributes;
1735
- }
1736
- get dimensionNames() {
1737
- return this.#e.dimension_names;
1738
- }
1739
- get fillValue() {
1740
- return this.#e.fill_value;
1741
- }
1742
- get shape() {
1743
- return this.#e.shape;
1744
- }
1745
- get chunks() {
1746
- return this[W].chunkShape;
1747
- }
1748
- get dtype() {
1749
- return this.#e.data_type;
1750
- }
1751
- async getChunk(e, t, n) {
1752
- n?.useSharedArrayBuffer && He();
1753
- let r = this[W], i = await r.getChunkBytes(e, t);
1754
- if (!i) {
1755
- let e = r.chunkShape.reduce((e, t) => e * t, 1), t;
1756
- if (n?.useSharedArrayBuffer) {
1757
- let n = new r.TypedArray(0);
1758
- if (!("BYTES_PER_ELEMENT" in n)) console.warn("zarrita: useSharedArrayBuffer is not supported for non-buffer-backed data types."), t = new r.TypedArray(e);
1759
- else {
1760
- let i = Ue(e * n.BYTES_PER_ELEMENT, !0);
1761
- t = new r.TypedArray(i, 0, e);
1762
- }
1763
- } else t = new r.TypedArray(e);
1764
- return t.fill(r.fillValue), {
1765
- data: t,
1766
- shape: r.chunkShape,
1767
- stride: r.getStrides(r.chunkShape)
1768
- };
1769
- }
1770
- return r.codec.decode(i);
1771
- }
1772
- is(e) {
1773
- return Xe(this.dtype, e);
1774
- }
1775
- };
1776
- //#endregion
1777
- //#region node_modules/.pnpm/zarrita@0.7.5/node_modules/zarrita/dist/src/extension/extend.js
1778
- function tn(e, t) {
1779
- let n = e;
1780
- for (let e of t) n = n instanceof Promise ? n.then((t) => e(t)) : e(n);
1781
- return n;
1782
- }
1783
- //#endregion
1784
- //#region node_modules/.pnpm/zarrita@0.7.5/node_modules/zarrita/dist/src/extension/extend-array.js
1785
- function nn(e, ...t) {
1786
- return tn(e, t);
1787
- }
1788
- //#endregion
1789
- //#region node_modules/.pnpm/zarrita@0.7.5/node_modules/zarrita/dist/src/open.js
1790
- async function rn(e) {
1791
- let t = e.store.arrayExtensions;
1792
- return t?.length ? await nn(e, ...t) : e;
1793
- }
1794
- var K = an();
1795
- function an() {
1796
- let e = /* @__PURE__ */ new WeakMap();
1797
- function t(t) {
1798
- let n = e.get(t) ?? {
1799
- v2: 0,
1800
- v3: 0
1801
- };
1802
- return e.set(t, n), n;
1803
- }
1804
- return {
1805
- increment(e, n) {
1806
- t(e)[n] += 1;
1807
- },
1808
- versionMax(e) {
1809
- let n = t(e);
1810
- return n.v3 > n.v2 ? "v3" : "v2";
1811
- }
1812
- };
1813
- }
1814
- async function on(e, t) {
1815
- let n = await e.store.get(e.resolve(".zattrs").path, { signal: t });
1816
- return n ? P(n) : {};
1817
- }
1818
- async function sn(e, t = {}) {
1819
- let n = "store" in e ? e : new H(e), { signal: r } = t, i = {};
1820
- return (t.attrs ?? !0) && (i = await on(n, r)), r?.throwIfAborted(), t.kind === "array" ? cn(n, i, r) : t.kind === "group" ? ln(n, i, r) : cn(n, i, r).catch((e) => (et(e, O, k), ln(n, i, r)));
1821
- }
1822
- async function cn(e, t, n) {
1823
- let { path: r } = e.resolve(".zarray"), i = await e.store.get(r, { signal: n });
1824
- if (!i) throw new O("v2 array", { path: r });
1825
- return K.increment(e.store, "v2"), rn(new G(e.store, e.path, Je(P(i), t)));
1826
- }
1827
- async function ln(e, t, n) {
1828
- let { path: r } = e.resolve(".zgroup"), i = await e.store.get(r, { signal: n });
1829
- if (!i) throw new O("v2 group", { path: r });
1830
- return K.increment(e.store, "v2"), new U(e.store, e.path, Ye(P(i), t));
1831
- }
1832
- async function un(e, t) {
1833
- let { store: n, path: r } = e.resolve("zarr.json"), i = await e.store.get(r, { signal: t });
1834
- if (!i) throw new O("v3 array or group", { path: r });
1835
- let a = P(i);
1836
- return a.node_type === "array" && (a.fill_value = Qe(a)), a.node_type === "array" ? rn(new G(n, e.path, a)) : new U(n, e.path, a);
1837
- }
1838
- async function dn(e, t = {}) {
1839
- let n = "store" in e ? e : new H(e), r = await un(n, t.signal);
1840
- if (K.increment(n.store, "v3"), t.kind === void 0 || t.kind === "array" && r instanceof G || t.kind === "group" && r instanceof U) return r;
1841
- let i = r instanceof G ? "array" : "group";
1842
- throw new O(`${t.kind} at ${n.path}`, {
1843
- path: n.path,
1844
- found: i
1845
- });
1846
- }
1847
- async function q(e, t = {}) {
1848
- let n = "store" in e ? e.store : e, r = K.versionMax(n), i = r === "v2" ? q.v2 : q.v3, a = r === "v2" ? q.v3 : q.v2;
1849
- return i(e, t).catch((n) => (et(n, O, k), a(e, t)));
1850
- }
1851
- q.v2 = sn, q.v3 = dn;
1852
- //#endregion
1853
- //#region node_modules/.pnpm/zarrita@0.7.5/node_modules/zarrita/dist/src/indexing/util.js
1854
- function* fn(e, t, n = 1) {
1855
- t === void 0 && (t = e, e = 0);
1856
- for (let r = e; r < t; r += n) yield r;
1857
- }
1858
- function* pn(...e) {
1859
- if (e.length === 0) return;
1860
- let t = e.map((e) => e[Symbol.iterator]()), n = t.map((e) => e.next());
1861
- if (n.some((e) => e.done)) throw Error("Input contains an empty iterator.");
1862
- for (let r = 0;;) {
1863
- if (n[r].done) {
1864
- if (t[r] = e[r][Symbol.iterator](), n[r] = t[r].next(), ++r >= t.length) return;
1865
- } else yield n.map(({ value: e }) => e), r = 0;
1866
- n[r] = t[r].next();
1867
- }
1868
- }
1869
- function mn({ start: e, stop: t, step: n }, r) {
1870
- if (n === 0) throw new A("slice step cannot be zero");
1871
- n ??= 1;
1872
- let i = n < 0, [a, o] = i ? [-1, r - 1] : [0, r];
1873
- return e === null ? e = i ? o : a : e < 0 ? (e += r, e < a && (e = a)) : e > o && (e = o), t === null ? t = i ? a : o : t < 0 ? (t += r, t < a && (t = a)) : t > o && (t = o), [
1874
- e,
1875
- t,
1876
- n
1877
- ];
1878
- }
1879
- function hn(e) {
1880
- if (e == null) return null;
1881
- if (typeof e == "bigint") {
1882
- if (e > 2 ** 53 - 1 || e < -(2 ** 53 - 1)) throw new A(`Cannot safely convert ${e} to a number. Value exceeds Number.MAX_SAFE_INTEGER.`);
1883
- return Number(e);
1884
- }
1885
- return e;
1886
- }
1887
- function J(e, t, n = null) {
1888
- return t === void 0 && (t = e, e = null), {
1889
- start: hn(e),
1890
- stop: hn(t),
1891
- step: hn(n)
1892
- };
1893
- }
1894
- function gn() {
1895
- let e = [];
1896
- return {
1897
- add: (t) => e.push(t()),
1898
- onIdle: () => Promise.all(e)
1899
- };
1900
- }
1901
- //#endregion
1902
- //#region node_modules/.pnpm/zarrita@0.7.5/node_modules/zarrita/dist/src/indexing/indexer.js
1903
- function _n(e, t) {
1904
- throw new A(`too many indicies for array; expected ${t.length}, got ${e.length}`);
1905
- }
1906
- function vn(e) {
1907
- throw new A(`index out of bounds for dimension with length ${e}`);
1908
- }
1909
- function yn() {
1910
- throw new A("only slices with step >= 1 are supported");
1911
- }
1912
- function bn(e, t) {
1913
- e.length > t.length && _n(e, t);
1914
- }
1915
- function xn(e, t) {
1916
- return e = Math.trunc(e), e < 0 && (e = t + e), (e >= t || e < 0) && vn(t), e;
1917
- }
1918
- var Sn = class {
1919
- dimSel;
1920
- dimLen;
1921
- dimChunkLen;
1922
- nitems;
1923
- constructor({ dimSel: e, dimLen: t, dimChunkLen: n }) {
1924
- e = xn(e, t), this.dimSel = e, this.dimLen = t, this.dimChunkLen = n, this.nitems = 1;
1925
- }
1926
- *[Symbol.iterator]() {
1927
- let e = Math.floor(this.dimSel / this.dimChunkLen), t = e * this.dimChunkLen;
1928
- yield {
1929
- dimChunkIx: e,
1930
- dimChunkSel: this.dimSel - t
1931
- };
1932
- }
1933
- }, Cn = class {
1934
- start;
1935
- stop;
1936
- step;
1937
- dimLen;
1938
- dimChunkLen;
1939
- nitems;
1940
- nchunks;
1941
- constructor({ dimSel: e, dimLen: t, dimChunkLen: n }) {
1942
- let [r, i, a] = mn(e, t);
1943
- this.start = r, this.stop = i, this.step = a, this.step < 1 && yn(), this.dimLen = t, this.dimChunkLen = n, this.nitems = Math.max(0, Math.ceil((this.stop - this.start) / this.step)), this.nchunks = Math.ceil(this.dimLen / this.dimChunkLen);
1944
- }
1945
- *[Symbol.iterator]() {
1946
- let e = Math.floor(this.start / this.dimChunkLen), t = Math.ceil(this.stop / this.dimChunkLen);
1947
- for (let n of fn(e, t)) {
1948
- let e = n * this.dimChunkLen, t = Math.min(this.dimLen, (n + 1) * this.dimChunkLen), r = t - e, i = 0, a = 0;
1949
- if (this.start < e) {
1950
- let t = (e - this.start) % this.step;
1951
- t && (a += this.step - t), i = Math.ceil((e - this.start) / this.step);
1952
- } else a = this.start - e;
1953
- let o = this.stop > t ? r : this.stop - e, s = [
1954
- a,
1955
- o,
1956
- this.step
1957
- ], c = Math.ceil((o - a) / this.step);
1958
- yield {
1959
- dimChunkIx: n,
1960
- dimChunkSel: s,
1961
- dimOutSel: [
1962
- i,
1963
- i + c,
1964
- 1
1965
- ]
1966
- };
1967
- }
1968
- }
1969
- };
1970
- function wn(e, t) {
1971
- let n = [];
1972
- return e === null ? n = t.map((e) => J(null)) : Array.isArray(e) && (n = e.map((e) => e ?? J(null))), bn(n, t), n;
1973
- }
1974
- var Tn = class {
1975
- dimIndexers;
1976
- shape;
1977
- outputAxes;
1978
- constructor({ selection: e, shape: t, chunkShape: n }) {
1979
- this.dimIndexers = wn(e, t).map((e, r) => new (typeof e == "number" ? Sn : Cn)({
1980
- dimSel: e,
1981
- dimLen: t[r],
1982
- dimChunkLen: n[r]
1983
- })), this.shape = this.dimIndexers.filter((e) => e instanceof Cn).map((e) => e.nitems), this.outputAxes = this.dimIndexers.map((e, t) => ({
1984
- ixr: e,
1985
- axis: t
1986
- })).filter(({ ixr: e }) => e instanceof Cn).map(({ axis: e }) => e);
1987
- }
1988
- *[Symbol.iterator]() {
1989
- for (let e of pn(...this.dimIndexers)) yield {
1990
- chunkCoords: e.map((e) => e.dimChunkIx),
1991
- mapping: e.map((e) => "dimOutSel" in e ? {
1992
- from: e.dimChunkSel,
1993
- to: e.dimOutSel
1994
- } : {
1995
- from: e.dimChunkSel,
1996
- to: null
1997
- })
1998
- };
1999
- }
2000
- };
2001
- //#endregion
2002
- //#region node_modules/.pnpm/zarrita@0.7.5/node_modules/zarrita/dist/src/indexing/get.js
2003
- function En(e, t) {
2004
- return "get" in e ? e.get(t) : e[t];
2005
- }
2006
- async function Dn(e, t, n, r) {
2007
- n.useSharedArrayBuffer && He();
2008
- let i = $e(n), a = $t(e), o = new Tn({
2009
- selection: t,
2010
- shape: e.shape,
2011
- chunkShape: e.chunks
2012
- });
2013
- if (e.shape.length === 0) {
2014
- let { data: t } = await e.getChunk([], { signal: i }, { useSharedArrayBuffer: n.useSharedArrayBuffer });
2015
- return En(t, 0);
2016
- }
2017
- let s = o.shape.reduce((e, t) => e * t, 1), c;
2018
- if (n.useSharedArrayBuffer) {
2019
- let e = new a.TypedArray(0);
2020
- if (!("BYTES_PER_ELEMENT" in e)) console.warn("zarrita: useSharedArrayBuffer is not supported for non-buffer-backed data types."), c = new a.TypedArray(s);
2021
- else {
2022
- let t = Ue(s * e.BYTES_PER_ELEMENT, !0);
2023
- c = new a.TypedArray(t, 0, s);
2024
- }
2025
- } else c = new a.TypedArray(s);
2026
- let l = r.prepare(c, o.shape, a.getStrides(o.shape, o.outputAxes)), u = n.createQueue?.() ?? gn();
2027
- for (let { chunkCoords: t, mapping: a } of o) u.add(async () => {
2028
- i?.throwIfAborted();
2029
- let { data: o, shape: s, stride: c } = await e.getChunk(t, { signal: i }, { useSharedArrayBuffer: n.useSharedArrayBuffer }), u = r.prepare(o, s, c);
2030
- r.setFromChunk(l, u, a);
2031
- });
2032
- return await u.onIdle(), o.shape.length === 0 ? En(l.data, 0) : l;
2033
- }
2034
- //#endregion
2035
- //#region node_modules/.pnpm/zarrita@0.7.5/node_modules/zarrita/dist/src/indexing/ops.js
2036
- function On(e, t = 0, n) {
2037
- let r = n ?? e.length - t;
2038
- return {
2039
- length: r,
2040
- subarray(n, i = r) {
2041
- return On(e, t + n, i - n);
2042
- },
2043
- set(n, r = 0) {
2044
- for (let i = 0; i < n.length; i++) e[t + r + i] = n.get(i);
2045
- },
2046
- get(n) {
2047
- return e[t + n];
2048
- }
2049
- };
2050
- }
2051
- function kn(e) {
2052
- return globalThis.Array.isArray(e.data) ? {
2053
- data: On(e.data),
2054
- stride: e.stride,
2055
- bytesPerElement: 1
2056
- } : {
2057
- data: new Uint8Array(e.data.buffer, e.data.byteOffset, e.data.byteLength),
2058
- stride: e.stride,
2059
- bytesPerElement: e.data.BYTES_PER_ELEMENT
2060
- };
2061
- }
2062
- function An(e) {
2063
- return "chars" in e ? e.constructor.bind(null, e.chars) : e.constructor;
2064
- }
2065
- function jn(e, t) {
2066
- if (globalThis.Array.isArray(e.data)) return On([t]);
2067
- let n = new (An(e.data))([t]);
2068
- return new Uint8Array(n.buffer, n.byteOffset, n.byteLength);
2069
- }
2070
- var Mn = {
2071
- prepare(e, t, n) {
2072
- return {
2073
- data: e,
2074
- shape: t,
2075
- stride: n
2076
- };
2077
- },
2078
- setScalar(e, t, n) {
2079
- let r = kn(e);
2080
- Pn(r, t, jn(e, n), r.bytesPerElement);
2081
- },
2082
- setFromChunk(e, t, n) {
2083
- let r = kn(e);
2084
- X(r, kn(t), r.bytesPerElement, n);
2085
- }
2086
- };
2087
- async function Nn(e, t = null, n = {}) {
2088
- return Dn(e, t, n, Mn);
2089
- }
2090
- function Y(e, t, n) {
2091
- return n < 0 && t < e ? Math.floor((e - t - 1) / -n) + 1 : e < t ? Math.floor((t - e - 1) / n) + 1 : 0;
2092
- }
2093
- function Pn(e, t, n, r) {
2094
- if (t.length === 0) {
2095
- e.data.set(n, 0);
2096
- return;
2097
- }
2098
- let [i, ...a] = t, [o, ...s] = e.stride;
2099
- if (typeof i == "number") {
2100
- Pn({
2101
- data: e.data.subarray(o * i * r),
2102
- stride: s
2103
- }, a, n, r);
2104
- return;
2105
- }
2106
- let [c, l, u] = i, d = Y(c, l, u);
2107
- if (a.length === 0) {
2108
- for (let t = 0; t < d; t++) e.data.set(n, o * (c + u * t) * r);
2109
- return;
2110
- }
2111
- for (let t = 0; t < d; t++) Pn({
2112
- data: e.data.subarray(o * (c + u * t) * r),
2113
- stride: s
2114
- }, a, n, r);
2115
- }
2116
- function Fn(e, t, n) {
2117
- if (e.length !== t.length || e.length !== n.length) return null;
2118
- let r = 1, i = 0, a = 0;
2119
- for (let o = e.length - 1; o >= 0; o--) {
2120
- let s = e[o];
2121
- if (s.from === null || s.to === null || t[o] !== r || n[o] !== r) return null;
2122
- let [c, l, u] = s.to, [d, , f] = s.from;
2123
- if (u !== 1 || f !== 1) return null;
2124
- i += r * c, a += r * d, r *= Y(c, l, u);
2125
- }
2126
- return {
2127
- size: r,
2128
- destOffset: i,
2129
- srcOffset: a
2130
- };
2131
- }
2132
- function X(e, t, n, r) {
2133
- let i = Fn(r, e.stride, t.stride);
2134
- if (i !== null) {
2135
- let r = i.srcOffset * n;
2136
- e.data.set(t.data.subarray(r, r + i.size * n), i.destOffset * n);
2137
- return;
2138
- }
2139
- let [a, ...o] = r, [s, ...c] = e.stride, [l, ...u] = t.stride;
2140
- if (a.from === null) {
2141
- if (o.length === 0) {
2142
- e.data.set(t.data.subarray(0, n), s * a.to * n);
2143
- return;
2144
- }
2145
- X({
2146
- data: e.data.subarray(s * a.to * n),
2147
- stride: c
2148
- }, t, n, o);
2149
- return;
2150
- }
2151
- if (a.to === null) {
2152
- if (o.length === 0) {
2153
- let r = l * a.from * n;
2154
- e.data.set(t.data.subarray(r, r + n), 0);
2155
- return;
2156
- }
2157
- X(e, {
2158
- data: t.data.subarray(l * a.from * n),
2159
- stride: u
2160
- }, n, o);
2161
- return;
2162
- }
2163
- let [d, f, p] = a.to, [m, h, g] = a.from, _ = Y(d, f, p);
2164
- if (o.length === 0) {
2165
- for (let r = 0; r < _; r++) {
2166
- let i = l * (m + g * r) * n;
2167
- e.data.set(t.data.subarray(i, i + n), s * (d + p * r) * n);
2168
- }
2169
- return;
2170
- }
2171
- for (let r = 0; r < _; r++) X({
2172
- data: e.data.subarray(s * (d + r * p) * n),
2173
- stride: c
2174
- }, {
2175
- data: t.data.subarray(l * (m + r * g) * n),
2176
- stride: u
2177
- }, n, o);
2178
- }
2179
- //#endregion
2180
- //#region node_modules/.pnpm/ome-zarr.js@0.0.20/node_modules/ome-zarr.js/dist/ome-zarr.js
2181
- var In = Object.defineProperty, Ln = (e, t, n) => t in e ? In(e, t, {
2182
- enumerable: !0,
2183
- configurable: !0,
2184
- writable: !0,
2185
- value: n
2186
- }) : e[t] = n, Z = (e, t, n) => Ln(e, typeof t == "symbol" ? t : t + "", n);
2187
- function Rn(e, t, n) {
2188
- let { dst: r, blending: i = "additive" } = n ?? {}, [a, o] = e.shape, s = r ?? new Uint8ClampedArray(4 * a * o).fill(0), c = a * o * 4, l = 0;
2189
- for (let n = 0; n < c; n += 4) {
2190
- let r = Number(e.data[l]);
2191
- l += 1;
2192
- let [a, o, c, u = 255] = t(r), d = s[n + 3] / 255, f = (u ?? 255) / 255;
2193
- if (i === "additive") s[n] = Math.min(s[n] * d + a, 255), s[n + 1] = Math.min(s[n + 1] * d + o, 255), s[n + 2] = Math.min(s[n + 2] * d + c, 255), s[n + 3] = Math.min(d + f, 1) * 255;
2194
- else if (i === "translucent") s[n] = a * f + s[n] * d * (1 - f), s[n + 1] = o * f + s[n + 1] * d * (1 - f), s[n + 2] = c * f + s[n + 2] * d * (1 - f), s[n + 3] = (f + d * (1 - f)) * 255;
2195
- else throw Error("Invalid blending mode");
2196
- }
2197
- return s;
2198
- }
2199
- function zn(e, t, n) {
2200
- let r = t.length, { dst: i, blending: a = "additive" } = n ?? {}, o;
2201
- if (n != null && n.range) {
2202
- let e = n.range;
2203
- o = function(n) {
2204
- let [i, a] = e;
2205
- return n < i && (n = i), n > a && (n = a), n = Math.round((r - 1) * (n - i) / (a - i)), t[n];
2206
- };
2207
- } else o = function(e) {
2208
- return e <= 0 ? t[0] : t[(e - 1) % (r - 1) + 1];
2209
- };
2210
- return Rn(e, o, {
2211
- dst: i,
2212
- blending: a
2213
- });
2214
- }
2215
- function Bn(e, t, n) {
2216
- let { dst: r, blending: i = "additive", fillValue: a = [
2217
- 0,
2218
- 0,
2219
- 0,
2220
- 0
2221
- ] } = n ?? {};
2222
- function o(e) {
2223
- return t.get(e) ?? a;
2224
- }
2225
- return Rn(e, o, {
2226
- dst: r,
2227
- blending: i
2228
- });
2229
- }
2230
- async function Vn(e, t, n, r, i, a) {
2231
- let { signal: o, calcMinMaxForRange: s } = a ?? {};
2232
- o?.throwIfAborted();
2233
- let c = e.shape, l = t?.map((e) => e.name || e.toString()) || [
2234
- "t",
2235
- "c",
2236
- "z",
2237
- "y",
2238
- "x"
2239
- ], u = c[l.indexOf("c")] || 1, d, f, p = [], m;
2240
- if (n) {
2241
- let e = 0;
2242
- d = n.map((t) => (t.active ??= !0, e += +!!t.active, t.active && e <= Q)), f = n.map((e) => Zn(e.color)), p = n.map((e) => "lut" in e && e.lut ? e.lut : "colorMap" in e ? e.colorMap : void 0);
2243
- } else d = Qn(u), f = tr(u, d);
2244
- let h = d.reduce((e, t, n) => (t && e.push(n), e), []);
2245
- f = h.map((e) => f[e]), m = h.map((e) => {
2246
- var t;
2247
- return !!((t = n?.[e]) != null && t.inverted);
2248
- }), p !== void 0 && (p = p.filter((e, t) => h.includes(t)));
2249
- let g = lr(h, c, l, r).map((t) => Nn(e, t, { opts: { signal: o } })), _ = await Promise.all(g);
2250
- o?.throwIfAborted();
2251
- let ee = Hn(_, h.map((e, t) => {
2252
- if (n && n[e]) {
2253
- let t = n[e];
2254
- if (t?.window?.start !== void 0 && t?.window?.end !== void 0) return [t.window.start, t.window.end];
2255
- }
2256
- if (s) return nr(_[t]);
2257
- }), f, p, m, i), v = _[0].shape[0];
2258
- return {
2259
- data: ee,
2260
- width: _[0].shape[1],
2261
- height: v
2262
- };
2263
- }
2264
- function Hn(e, t, n, r, i, a = !1) {
2265
- let o = n.map((e, t) => {
2266
- let n = r != null && r.length ? r[t] : void 0;
2267
- return n ||= Array.from({ length: 256 }, (t, n) => [
2268
- e[0] * n / 255,
2269
- e[1] * n / 255,
2270
- e[2] * n / 255,
2271
- 255
2272
- ]), i && i[t] && Array.isArray(n) && (n = n.reverse()), n;
2273
- }), s = performance.now(), c;
2274
- if (o[0] instanceof Map) {
2275
- let t = o[0], n = t.get(Xn);
2276
- c = Bn(e[0], t, { fillValue: n });
2277
- } else c = zn(e[0], o[0], { range: t[0] });
2278
- for (let n = 1; n < e.length; n++) if (o[n] instanceof Map) {
2279
- let t = o[n], r = t.get(Infinity);
2280
- c = Bn(e[n], t, {
2281
- blending: "additive",
2282
- dst: c,
2283
- fillValue: r
2284
- });
2285
- } else c = zn(e[n], o[n], {
2286
- blending: "additive",
2287
- dst: c,
2288
- range: t[n]
2289
- });
2290
- return performance.now() - s < 100 && a && ar(c, 5)[4] < 1 && (c = ir(c, 2)), c;
2291
- }
2292
- function Un(e, t) {
2293
- return e + (e.endsWith("/") ? "" : "/") + "|zarr" + t + ":";
2294
- }
2295
- function Wn(e) {
2296
- return e.split("/").filter(Boolean).pop() || "Default";
2297
- }
2298
- function Gn(e, t, n, r, i) {
2299
- let a = {};
2300
- r.forEach((e, t) => {
2301
- a[e.name] = {
2302
- ...e,
2303
- index: t
2304
- };
2305
- });
2306
- let o = "4panel-alt";
2307
- "z" in a ? i[a.z.index] === 1 && (o = "xy") : o = "xy";
2308
- let s = n === "segmentation" && (!a.c || i[a.c?.index] === 1) ? "segmentation" : "auto", c = {
2309
- layers: [{
2310
- name: Wn(e),
2311
- source: Un(e, t),
2312
- type: s
2313
- }],
2314
- layout: o
2315
- }, l = JSON.stringify(c);
2316
- return encodeURIComponent(l);
2317
- }
2318
- var Kn = class {
2319
- constructor(e, t) {
2320
- Z(this, "attrs"), Z(this, "imgAttrs"), Z(this, "store"), Z(this, "multiscales"), Z(this, "paths"), Z(this, "scales"), Z(this, "shapes"), Z(this, "arrays", {}), Z(this, "omero"), Z(this, "axes"), Z(this, "zarr_version"), Z(this, "omezarr_version");
2321
- var n;
2322
- this.store = t, "ome" in e ? (this.attrs = e, this.imgAttrs = JSON.parse(JSON.stringify(this.attrs.ome)), this.zarr_version = 3, this.omezarr_version = this.imgAttrs.version, this.axes = this.imgAttrs.multiscales[0].axes, !this.axes && (n = this.imgAttrs.multiscales[0].coordinateSystems?.[0]) != null && n.axes && (this.axes = this.imgAttrs.multiscales[0].coordinateSystems[0].axes)) : (this.attrs = e, this.imgAttrs = JSON.parse(JSON.stringify(this.attrs)), this.zarr_version = 2, this.omezarr_version = this.imgAttrs.multiscales[0].version || "0.4", this.axes = this.imgAttrs.multiscales[0].axes || [
2323
- "t",
2324
- "c",
2325
- "z",
2326
- "y",
2327
- "x"
2328
- ].map((e) => ({ name: e }))), this.multiscales = this.imgAttrs.multiscales, this.omero = this.imgAttrs.omero, this.calcMinMaxForRange = !0, this.paths = this.multiscales[0].datasets.map((e) => e.path), this.scales = this.getScales();
2329
- }
2330
- static async load(e, t = {}) {
2331
- let { signal: n } = t ?? {};
2332
- n?.throwIfAborted(), typeof e == "string" && (e = new u(e));
2333
- let r;
2334
- if (t.attrs) r = t.attrs;
2335
- else {
2336
- let t;
2337
- e instanceof U ? t = e : (t = await cr(e, void 0, void 0, { signal: n }), n?.throwIfAborted()), r = t.attrs;
2338
- }
2339
- let i = new this(r, e), a = t.datasetIndex ?? 0;
2340
- return await i.openArray(a), i;
2341
- }
2342
- checkChannelIndex(e) {
2343
- if (!this.omero) throw Error("No Omero metadata found in image");
2344
- if (e < 0 || e >= this.omero.channels.length) throw Error(`Invalid channel index: ${e} for image with ${this.omero.channels.length} channels`);
2345
- return this.omero;
2346
- }
2347
- setChannelActive(e, t) {
2348
- let n = this.checkChannelIndex(e);
2349
- n.channels[e].active = t;
2350
- }
2351
- setChannelColor(e, t) {
2352
- let n = this.checkChannelIndex(e);
2353
- n.channels[e].color = t;
2354
- }
2355
- setChannelStart(e, t) {
2356
- let n = this.checkChannelIndex(e);
2357
- n.channels[e].window.start = t;
2358
- }
2359
- setChannelEnd(e, t) {
2360
- let n = this.checkChannelIndex(e);
2361
- n.channels[e].window.end = t;
2362
- }
2363
- setChannelInverted(e, t) {
2364
- let n = this.checkChannelIndex(e);
2365
- n.channels[e].inverted = t;
2366
- }
2367
- setChannelLut(e, t) {
2368
- let n = this.checkChannelIndex(e);
2369
- t == null ? delete n.channels[e].lut : n.channels[e].lut = t;
2370
- }
2371
- setChannelColorMap(e, t) {
2372
- let n = this.checkChannelIndex(e);
2373
- n.channels[e].colorMap = t;
2374
- }
2375
- setZIndex(e) {
2376
- if (!this.omero) throw Error("No Omero metadata found in image");
2377
- this.omero.rdefs.defaultZ = e;
2378
- }
2379
- setTIndex(e) {
2380
- if (!this.omero) throw Error("No Omero metadata found in image");
2381
- this.omero.rdefs.defaultT = e;
2382
- }
2383
- async getShape(e = 0) {
2384
- return (await this.openArray(e)).shape;
2385
- }
2386
- getAxesNames() {
2387
- return this.axes.map((e) => e.name || e.toString());
2388
- }
2389
- getVersion() {
2390
- return this.omezarr_version;
2391
- }
2392
- getZarrVersion() {
2393
- return this.zarr_version;
2394
- }
2395
- async getLabelsPaths() {
2396
- var e;
2397
- let t = [];
2398
- try {
2399
- let n = await cr(this.store, "labels", this.zarr_version);
2400
- n && (e = n.attrs) != null && e.labels && (t = n.attrs.labels);
2401
- } catch (e) {
2402
- console.info("Failed to load labels group:", e);
2403
- }
2404
- return t;
2405
- }
2406
- async getNeuroglancerUrl() {
2407
- let e = this.store.url || "";
2408
- if (!e) throw Error("Cannot generate Neuroglancer URL: store does not have a URL");
2409
- let t = this.getZarrVersion(), n = this.imgAttrs["image-label"] ? "segmentation" : "auto", r = await this.getShape();
2410
- return "https://neuroglancer-demo.appspot.com/#!" + Gn(e.toString(), t, n, this.axes, r);
2411
- }
2412
- async openArray(e, t) {
2413
- let n;
2414
- if (typeof e == "number" ? (e < 0 && (e = this.paths.length + e), n = this.paths[e]) : n = e, this.arrays[n]) return this.arrays[n];
2415
- let r = await sr(this.store, n, this.zarr_version, t);
2416
- if (this.arrays[n] = r, !this.omero) {
2417
- let e = (await this.calcShapes())?.[0] || r.shape, t = this.axes.map((e) => e.name || e.toString()), n = e[t.findIndex((e) => e === "c")] || 1, i = e[t.findIndex((e) => e === "z")] || 1, a = e[t.findIndex((e) => e === "t")] || 1;
2418
- if (this.omero = $n({
2419
- sizeC: n,
2420
- sizeZ: i,
2421
- sizeT: a
2422
- }, r.dtype), t.includes("z")) {
2423
- let n = e[t.findIndex((e) => e === "z")] || 1;
2424
- this.omero.rdefs.defaultZ = Math.floor(n / 2);
2425
- }
2426
- }
2427
- return r;
2428
- }
2429
- async calcShapes(e) {
2430
- if (this.shapes !== void 0) return this.shapes;
2431
- if (e === void 0) {
2432
- for (let t = 0; t < this.paths.length; t++) if (this.arrays[this.paths[t]]) {
2433
- e = t;
2434
- break;
2435
- }
2436
- }
2437
- e === void 0 && (e = 0);
2438
- let t = (await this.openArray(e)).shape, n = this.scales, r = n[e], i = n.map((e) => t.map((t, n) => Math.floor(t * r[n] / e[n])));
2439
- return this.shapes = i, i;
2440
- }
2441
- getScales() {
2442
- let e = this.multiscales[0].datasets.map((e) => {
2443
- let t;
2444
- if (Array.isArray(e.coordinateTransformations)) {
2445
- for (let n of e.coordinateTransformations) if ("scale" in n) {
2446
- t = n.scale;
2447
- break;
2448
- } else if ("transformations" in n) {
2449
- for (let e of n.transformations) if ("scale" in e) {
2450
- t = e.scale;
2451
- break;
2452
- }
2453
- }
2454
- }
2455
- return t;
2456
- }).filter((e) => e !== void 0);
2457
- if (e.length > 0 && e.length !== this.multiscales[0].datasets.length) throw Error("Could not determine scales for all datasets");
2458
- return e;
2459
- }
2460
- async getPathForTargetSize(e, t) {
2461
- let n = [];
2462
- if (t == null) {
2463
- t = 0;
2464
- for (let e = 0; e < this.paths.length; e++) if (this.arrays[this.paths[e]]) {
2465
- t = e;
2466
- break;
2467
- }
2468
- }
2469
- if (this.scales.length == 0) {
2470
- let e = (await this.openArray(t)).shape, r = e.length, i = e[r - 1], a = e[r - 2], o = Math.max(i, a);
2471
- n = this.paths.map((e, n) => o * 2 ** (t - n));
2472
- } else {
2473
- let e = await this.calcShapes(), t = e[0].length;
2474
- n = e.map((e) => Math.max(e[t - 1], e[t - 2]));
2475
- }
2476
- let r;
2477
- for (r = 0; r < n.length; r++) {
2478
- let t = n[r], i = n[r + 1];
2479
- if (i) {
2480
- if (i > e) continue;
2481
- e < (t + i) / 2 && (r += 1);
2482
- break;
2483
- } else break;
2484
- }
2485
- return this.paths[r];
2486
- }
2487
- async renderArray(e = {}) {
2488
- let t;
2489
- if (e.arr) t = typeof e.arr == "string" ? await q(new u(e.arr), { kind: "array" }) : e.arr;
2490
- else {
2491
- let n;
2492
- if (e.arrayPathOrIndex !== void 0) n = e.arrayPathOrIndex;
2493
- else if (e.targetSize !== void 0) n = await this.getPathForTargetSize(e.targetSize);
2494
- else throw Error("Need to specify arr OR targetSize OR arrayPathOrIndex ");
2495
- t = await this.openArray(n);
2496
- }
2497
- let n = e.maxSize ?? 1e3, r = t.shape, i = r.length, a = r[i - 1], o = r[i - 2];
2498
- if (o * a > n * n && !e.slices) throw Error(`Array size (${a} * ${o}) is larger than specified 'maxSize' of ${n} * ${n}`);
2499
- let s = e.slices || {};
2500
- s.z ??= this.omero?.rdefs?.defaultZ;
2501
- let c = this.getAxesNames().indexOf("z");
2502
- if (c != -1 && Number.isInteger(s.z)) {
2503
- let e = await this.getShape();
2504
- e && e[c] != r[c] && (s.z = Math.floor(s.z * r[c] / e[c]));
2505
- }
2506
- s.t ??= this.omero?.rdefs?.defaultT;
2507
- let l = e.channels || this.omero?.channels, d = this.calcMinMaxForRange ?? !0;
2508
- e?.calcMinMaxForRange != null && (d = e.calcMinMaxForRange);
2509
- let { data: f, width: p, height: m } = await Vn(t, this.axes, l, s, !!e.autoBoost, {
2510
- signal: e.signal,
2511
- calcMinMaxForRange: !!d
2512
- });
2513
- return {
2514
- data: f,
2515
- width: p,
2516
- height: m
2517
- };
2518
- }
2519
- async render(e = {}) {
2520
- let { data: t, width: n } = await this.renderArray(e);
2521
- return ur(t, n);
2522
- }
2523
- }, Q = 3, $ = {
2524
- cyan: "#00FFFF",
2525
- yellow: "#FFFF00",
2526
- magenta: "#FF00FF",
2527
- red: "#FF0000",
2528
- green: "#00FF00",
2529
- blue: "#0000FF",
2530
- white: "#FFFFFF"
2531
- }, qn = [$.magenta, $.green], Jn = [
2532
- $.red,
2533
- $.green,
2534
- $.blue
2535
- ], Yn = Object.values($), Xn = Infinity;
2536
- function Zn(e) {
2537
- return e.startsWith("#") && (e = e.slice(1)), [
2538
- parseInt(e.slice(0, 2), 16),
2539
- parseInt(e.slice(2, 4), 16),
2540
- parseInt(e.slice(4, 6), 16)
2541
- ];
2542
- }
2543
- function Qn(e) {
2544
- let t;
2545
- return t = e <= Q ? Array(e).fill(!0) : [...Array(Q).fill(!0), ...Array(e - Q).fill(!1)], t;
2546
- }
2547
- function $n({ sizeC: e, sizeZ: t, sizeT: n }, r) {
2548
- let i = Qn(e), a = er(e, i), o = rr(r);
2549
- return {
2550
- channels: i.map((e, t) => ({
2551
- active: e,
2552
- color: a[t],
2553
- window: {
2554
- min: o.min,
2555
- max: o.max
2556
- }
2557
- })),
2558
- rdefs: {
2559
- defaultT: n === void 0 ? 0 : Math.floor(n / 2),
2560
- defaultZ: t === void 0 ? 0 : Math.floor(t / 2),
2561
- model: "color"
2562
- }
2563
- };
2564
- }
2565
- function er(e, t) {
2566
- let n = [];
2567
- if (e == 1) n = [$.white];
2568
- else if (e == 2) n = qn;
2569
- else if (e === 3) n = Jn;
2570
- else if (e <= Q) n = Yn.slice(0, e);
2571
- else {
2572
- n = Array(e).fill($.white);
2573
- let r = t.flatMap((e, t) => e ? t : []);
2574
- for (let [e, t] of r.entries()) n[t] = Yn[e];
2575
- }
2576
- return n = n.map((e) => (e.startsWith("#") && (e = e.slice(1)), e)), n;
2577
- }
2578
- function tr(e, t) {
2579
- return er(e, t).map(Zn);
2580
- }
2581
- function nr(e) {
2582
- let t = e.data, n = 0, r = Infinity, i = e.data.length;
2583
- for (let e = 0; e < i; e++) {
2584
- let i = Number(t[e]);
2585
- n = Math.max(n, i), r = Math.min(r, i);
2586
- }
2587
- return [r, n];
2588
- }
2589
- function rr(e) {
2590
- let t = 0, n = 65535;
2591
- if (e) if (e.includes("int") || e.includes("uint")) {
2592
- let r = e.match(/\d+/);
2593
- if (r) {
2594
- let i = parseInt(r[0]);
2595
- e.startsWith("u") ? (t = 0, n = 2 ** i - 1) : (t = -(2 ** (i - 1)), n = 2 ** (i - 1) - 1);
2596
- } else {
2597
- let r = e.match(/^[<>|]([iuf])(\d+)$/);
2598
- if (r) {
2599
- let e = r[1], i = parseInt(r[2], 10) * 8;
2600
- e === "i" ? (t = -(2 ** (i - 1)), n = 2 ** (i - 1) - 1) : e === "u" && (t = 0, n = 2 ** i - 1);
2601
- } else console.warn("Could not determine min/max values for dtype: ", e);
2602
- }
2603
- } else console.warn("Unrecognized dtype format: ", e);
2604
- return {
2605
- min: t,
2606
- max: n
2607
- };
2608
- }
2609
- function ir(e, t) {
2610
- for (let n = 0; n < e.length / 4; n++) for (let r = 0; r < 3; r++) {
2611
- let i = e[n * 4 + r];
2612
- i = Math.min(255, i * t), e[n * 4 + r] = i;
2613
- }
2614
- return e;
2615
- }
2616
- function ar(e, t = 5) {
2617
- let n = Array(t).fill(0), r = 256 / t, i = e.length / 4;
2618
- for (let t = 0; t < i; t++) {
2619
- let i = e[t * 4];
2620
- i = Math.max(e[t * 4 + 1], i), i = Math.max(e[t * 4 + 2], i);
2621
- let a = Math.floor(i / r);
2622
- n[a] += 1;
2623
- }
2624
- return n = n.map((e) => 100 * e / i), n;
2625
- }
2626
- async function or(e, t, n, r, i) {
2627
- let { signal: a } = i ?? {};
2628
- a?.throwIfAborted();
2629
- let o = r === 3 ? q.v3 : r === 2 ? q.v2 : q, s;
2630
- s = e instanceof U ? e : Yt(typeof e == "string" ? new u(e) : e), n && (s = s.resolve(n));
2631
- let c = await o(s, { kind: t });
2632
- return a?.throwIfAborted(), c;
2633
- }
2634
- async function sr(e, t, n, r) {
2635
- let { signal: i } = r ?? {};
2636
- return i?.throwIfAborted(), or(e, "array", t, n, { signal: i });
2637
- }
2638
- async function cr(e, t, n, r) {
2639
- let { signal: i } = r ?? {};
2640
- return i?.throwIfAborted(), or(e, "group", t, n, { signal: i });
2641
- }
2642
- function lr(e, t, n, r) {
2643
- return e.map((e) => t.map((t, i) => {
2644
- let a = n[i];
2645
- if (a == "c") return e;
2646
- if (a in r) {
2647
- let e = r[a];
2648
- if (Array.isArray(e)) return J(e[0], e[1]);
2649
- if (Number.isInteger(e)) return e === void 0 ? void 0 : e;
2650
- }
2651
- return a == "x" || a == "y" ? J(0, t) : a == "z" || a == "t" ? parseInt(t / 2 + "") : 0;
2652
- }));
2653
- }
2654
- async function ur(e, t) {
2655
- let n = e.length / (t * 4);
2656
- if (typeof document < "u") {
2657
- let r = document.createElement("canvas");
2658
- r.width = t, r.height = n;
2659
- let i = r.getContext("2d");
2660
- return i ? (i.putImageData(new ImageData(e, t, n), 0, 0), r.toDataURL("image/png")) : "";
2661
- } else {
2662
- let { PNG: r } = await import("./png-K1gqQ34g-BW3a7qE6.js").then((e) => e.p), { Buffer: i } = await import("./__vite-browser-external-YbutIfMq-DmIpWUUk.js").then((e) => e._), a = new r({
2663
- width: t,
2664
- height: n
2665
- });
2666
- a.data = i.from(e.buffer, e.byteOffset, e.byteLength);
2667
- let o = [], s = a.pack();
2668
- return new Promise((e, t) => {
2669
- s.on("data", (e) => o.push(e)), s.on("end", () => {
2670
- e(`data:image/png;base64,${i.concat(o).toString("base64")}`);
2671
- }), s.on("error", t);
2672
- });
2673
- }
2674
- }
2675
- //#endregion
1
+ import e from "@zarrita/storage/zip";
2
+ import { NgffImage as t, getSlices as n, renderChunks as r } from "ome-zarr.js";
3
+ import i from "openseadragon";
4
+ import * as a from "zarrita";
2676
5
  //#region src/OMEZarrTileSource.ts
2677
- var dr = class e extends r.TileSource {
6
+ var o = class o extends i.TileSource {
2678
7
  zip;
2679
8
  c;
2680
9
  z;
@@ -2685,11 +14,28 @@ var dr = class e extends r.TileSource {
2685
14
  height = 10;
2686
15
  _image;
2687
16
  _arrays;
17
+ _readyPromise = new Promise((e, t) => {
18
+ this.addOnceHandler("ready", () => e(this)), this.addOnceHandler("open-failed", (e) => t(Error(e.message)));
19
+ });
2688
20
  static {
2689
- e._learnConverters(r);
21
+ o._learnConverters(i);
2690
22
  }
2691
- constructor(e) {
2692
- typeof e == "string" ? (super(e), this.url = e, this.dataType = "context2d") : (super(e.url), this.url = e.url, this.zip = e.zip, this.c = e.c, this.z = e.z, this.t = e.t, this.dataType = e.dataType ?? "context2d", this.autoBoost = e.autoBoost);
23
+ static open(e, t) {
24
+ return new o(e, t).whenReady();
25
+ }
26
+ constructor(e, t) {
27
+ typeof e == "string" ? (super(e), this.url = e, this.dataType = "context2d") : (super(e.url), this.url = e.url, this.zip = e.zip, this.c = e.c, this.z = e.z, this.t = e.t, this.dataType = e.dataType ?? "context2d", this.autoBoost = e.autoBoost), this._image = t, this._readyPromise.catch(() => {});
28
+ }
29
+ get image() {
30
+ if (this._image === void 0) throw Error("tile source not ready");
31
+ return this._image;
32
+ }
33
+ get arrays() {
34
+ if (this._arrays === void 0) throw Error("tile source not ready");
35
+ return this._arrays;
36
+ }
37
+ whenReady() {
38
+ return this._readyPromise;
2693
39
  }
2694
40
  supports(e) {
2695
41
  return Array.isArray(e) || e instanceof Document ? !1 : typeof e == "string" ? e.endsWith(".ozx") : "type" in e && e.type === "ome-zarr";
@@ -2706,11 +52,11 @@ var dr = class e extends r.TileSource {
2706
52
  ...e
2707
53
  };
2708
54
  }
2709
- equals(t) {
2710
- return t instanceof e && this.url === t.url && this.zip === t.zip && this.c === t.c && this.z === t.z && this.t === t.t && this.dataType === t.dataType && this.autoBoost === t.autoBoost;
55
+ equals(e) {
56
+ return e instanceof o && this.url === e.url && this.zip === e.zip && this.c === e.c && this.z === e.z && this.t === e.t && this.dataType === e.dataType && this.autoBoost === e.autoBoost;
2711
57
  }
2712
- getImageInfo(e) {
2713
- Kn.load(this.zip || this.zip === void 0 && e.endsWith(".ozx") ? Fe.fromUrl(e) : e).then(async (e) => {
58
+ getImageInfo(n) {
59
+ Promise.resolve(this._image ?? t.load(this.zip || this.zip === void 0 && n.endsWith(".ozx") ? e.fromUrl(n) : n)).then(async (e) => {
2714
60
  let t = e.getAxesNames();
2715
61
  for (let e of t) if (![
2716
62
  "t",
@@ -2721,16 +67,21 @@ var dr = class e extends r.TileSource {
2721
67
  ].includes(e)) throw Error(`unsupported axis: ${e}`);
2722
68
  if (!t.includes("x") || !t.includes("y")) throw Error("missing X or Y axis");
2723
69
  if (t.indexOf("y") > t.indexOf("x")) throw Error("X axis must come after Y axis");
2724
- let n = await Promise.all(e.paths.map((t) => e.openArray(t))), r = t.indexOf("c"), i = r >= 0 ? n[0].shape[r] : 1;
2725
- if (this.z !== void 0 && e.setZIndex(this.z), this.t !== void 0 && e.setTIndex(this.t), this.dataType !== "context2d" && this.c === void 0 && i > 1) throw Error(`Multi-channel image with ${i} channels; specify c or render as "context2d"`);
2726
- let a = e.checkChannelIndex(this.c ?? 0);
2727
- if (a.channels.length !== i) throw Error(`OME-Zarr metadata lists ${a.channels.length} channels, but the image has ${i}`);
2728
- if (this._getActiveChannelIndices(a).length === 0) throw Error("No active channels; specify c or activate channels in the OME-Zarr metadata");
70
+ let n = await Promise.all(e.paths.map((t) => e.openArray(t))), r = t.indexOf("t"), i = r >= 0 ? n[0].shape[r] : 1;
71
+ if (this.t !== void 0 && (this.t < 0 || this.t >= i)) throw Error(`Invalid t index ${this.t} for image with ${i} timepoints`);
72
+ let a = t.indexOf("z"), o = a >= 0 ? n[0].shape[a] : 1;
73
+ if (this.z !== void 0 && (this.z < 0 || this.z >= o)) throw Error(`Invalid z index ${this.z} for image with ${o} z-slices`);
74
+ let s = t.indexOf("c"), c = s >= 0 ? n[0].shape[s] : 1;
75
+ if (this.c !== void 0 && (this.c < 0 || this.c >= c)) throw Error(`Invalid c index ${this.c} for image with ${c} channels`);
76
+ if (this.dataType !== "context2d" && this.c === void 0 && c > 1) throw Error(`Multi-channel image with ${c} channels; specify c or render as "context2d"`);
77
+ let l = e.checkChannelIndex(this.c ?? 0);
78
+ if (l.channels.length !== c) throw Error(`OME-Zarr metadata lists ${l.channels.length} channels, but the image has ${c}`);
79
+ if (this._getActiveChannelIndices(l).length === 0) throw Error("No active channels; specify c or activate channels in the OME-Zarr metadata");
2729
80
  this._image = e, this._arrays = n, this.width = n[0].shape[t.indexOf("x")], this.height = n[0].shape[t.indexOf("y")], this.maxLevel = n.length - 1, this.raiseEvent("ready", { tileSource: this });
2730
- }).catch((t) => {
81
+ }).catch((e) => {
2731
82
  this._image = void 0, this._arrays = void 0, this.width = 10, this.height = 10, this.maxLevel = 0, this.raiseEvent("open-failed", {
2732
- message: `failed to get image info for ${e}: ${t}`,
2733
- source: e
83
+ message: `failed to get image info for ${n}: ${e}`,
84
+ source: n
2734
85
  });
2735
86
  });
2736
87
  }
@@ -2757,47 +108,47 @@ var dr = class e extends r.TileSource {
2757
108
  let r = new URL(this.url);
2758
109
  return r.searchParams.append("level", e.toString()), r.searchParams.append("x", t.toString()), r.searchParams.append("y", n.toString()), this.zip !== void 0 && r.searchParams.append("zip", this.zip.toString()), this.c !== void 0 && r.searchParams.append("c", this.c.toString()), this.z !== void 0 && r.searchParams.append("z", this.z.toString()), this.t !== void 0 && r.searchParams.append("t", this.t.toString()), r.searchParams.append("dataType", this.dataType), this.autoBoost !== void 0 && r.searchParams.append("autoBoost", this.autoBoost.toString()), r.toString();
2759
110
  }
2760
- downloadTileStart(t) {
2761
- let n = t.userData, r = new AbortController();
2762
- n.abortController = r;
2763
- let i = new URLSearchParams(t.src), a = +i.get("level"), o = +i.get("x"), s = +i.get("y");
111
+ downloadTileStart(e) {
112
+ let t = e.userData, r = new AbortController();
113
+ t.abortController = r;
114
+ let i = new URLSearchParams(e.src), s = +i.get("level"), c = +i.get("x"), l = +i.get("y");
2764
115
  try {
2765
116
  if (this._image === void 0 || this._arrays === void 0) throw Error("tile source not ready");
2766
- let n = this._arrays[this.maxLevel - a], i = this._image.checkChannelIndex(this.c ?? 0), c = this._getActiveChannelIndices(i), l = c.map((e) => i.channels[e]), u = this.getTileWidth(a), d = this.getTileHeight(a), f = lr(c, n.shape, this._image.getAxesNames(), {
2767
- x: [o * u, (o + 1) * u],
2768
- y: [s * d, (s + 1) * d],
2769
- z: i.rdefs.defaultZ,
2770
- t: i.rdefs.defaultT
117
+ let t = this._arrays[this.maxLevel - s], i = this._image.checkChannelIndex(this.c ?? 0), u = this._getActiveChannelIndices(i), d = u.map((e) => i.channels[e]), f = this.getTileWidth(s), p = this.getTileHeight(s), m = n(u, t.shape, this._image.getAxesNames(), {
118
+ x: [c * f, (c + 1) * f],
119
+ y: [l * p, (l + 1) * p],
120
+ z: this.z ?? i.rdefs?.defaultZ,
121
+ t: this.t ?? i.rdefs?.defaultT
2771
122
  });
2772
- Promise.all(f.map((e) => Nn(n, e, { signal: r.signal }))).then((n) => {
123
+ Promise.all(m.map((e) => a.get(t, e, { signal: r.signal }))).then((t) => {
2773
124
  if (this.dataType === "context2d") {
2774
- let r = e._render(n, l, this.autoBoost);
2775
- t.finish(r, null, "context2d");
125
+ let n = o._render(t, d, this.autoBoost);
126
+ e.finish(n, null, "context2d");
2776
127
  } else {
2777
- let e = {
2778
- chunk: n[0],
2779
- channel: l[0],
128
+ let n = {
129
+ chunk: t[0],
130
+ channel: d[0],
2780
131
  autoBoost: this.autoBoost
2781
132
  };
2782
- t.finish(e, null, "ome-zarr");
133
+ e.finish(n, null, "ome-zarr");
2783
134
  }
2784
- }, (e) => {
135
+ }).catch((t) => {
2785
136
  let n = r.signal.aborted;
2786
- r.abort(), n || t.fail(`failed to render tile for level=${a}, x=${o}, y=${s}: ${e}`, null);
137
+ r.abort(), n || e.fail(`failed to render tile for level=${s}, x=${c}, y=${l}: ${String(t)}`, null);
2787
138
  });
2788
- } catch (e) {
2789
- t.fail(`failed to download tile for level=${a}, x=${o}, y=${s}: ${String(e)}`, null);
139
+ } catch (t) {
140
+ e.fail(`failed to download tile for level=${s}, x=${c}, y=${l}: ${String(t)}`, null);
2790
141
  }
2791
142
  }
2792
143
  downloadTileAbort(e) {
2793
144
  let t = e.userData;
2794
145
  t.abortController !== void 0 && (t.abortController.abort(), t.abortController = void 0);
2795
146
  }
2796
- static enable(t = r) {
2797
- Object.assign(t, { OMEZarrTileSource: e }), e._learnConverters(t);
147
+ static enable(e = i) {
148
+ Object.assign(e, { OMEZarrTileSource: o }), o._learnConverters(e);
2798
149
  }
2799
- static _learnConverters(t) {
2800
- t.converter.existsType("ome-zarr") || (t.converter.learn("ome-zarr", "context2d", (t, { chunk: n, channel: r, autoBoost: i }) => e._render([n], [r], i), 1, 1), t.converter.learn("ome-zarr", "ome-zarr", (e, t) => ({
150
+ static _learnConverters(e) {
151
+ e.converter.existsType("ome-zarr") || (e.converter.learn("ome-zarr", "context2d", (e, { chunk: t, channel: n, autoBoost: r }) => o._render([t], [n], r), 1, 1), e.converter.learn("ome-zarr", "ome-zarr", (e, t) => ({
2801
152
  ...t,
2802
153
  chunk: {
2803
154
  ...t.chunk,
@@ -2809,26 +160,30 @@ var dr = class e extends r.TileSource {
2809
160
  return this.c !== void 0 || this.dataType !== "context2d" ? [this.c ?? 0] : e.channels.flatMap((e, t) => e.active === !1 ? [] : [t]);
2810
161
  }
2811
162
  static _render(e, t, n) {
2812
- let r = t.map((e) => {
163
+ let i = t.map((e) => {
2813
164
  let t = e.color.replace(/^#/, "");
2814
165
  return [
2815
166
  parseInt(t.slice(0, 2), 16),
2816
167
  parseInt(t.slice(2, 4), 16),
2817
168
  parseInt(t.slice(4, 6), 16)
2818
169
  ];
2819
- }), i = Hn(e, t.map((t, n) => {
2820
- let [r, i] = t.window.start !== void 0 && t.window.end !== void 0 ? [t.window.start, t.window.end] : nr(e[n]);
170
+ }), a = r(e, t.map((t, n) => {
171
+ let [r, i] = t.window.start !== void 0 && t.window.end !== void 0 ? [t.window.start, t.window.end] : o._getDataTypeRange(e[n]);
2821
172
  return r < i ? [r, i] : [r, r + 1];
2822
- }), r, t.map((e) => e.lut ?? e.colorMap), t.map((e) => e.inverted === !0), n), a = e[0].shape[1], o = e[0].shape[0], s = document.createElement("canvas");
2823
- s.width = a, s.height = o;
2824
- let c = s.getContext("2d");
2825
- if (c === null) throw Error("failed to get 2D canvas context");
2826
- let l = new ImageData(i, a, o);
2827
- return c.putImageData(l, 0, 0), c;
173
+ }), i, t.map((e) => e.lut ?? e.colorMap), t.map((e) => e.inverted === !0), n), s = e[0].shape[1], c = e[0].shape[0], l = document.createElement("canvas");
174
+ l.width = s, l.height = c;
175
+ let u = l.getContext("2d");
176
+ if (u === null) throw Error("failed to get 2D canvas context");
177
+ let d = new ImageData(a, s, c);
178
+ return u.putImageData(d, 0, 0), u;
179
+ }
180
+ static _getDataTypeRange(e) {
181
+ let { data: t } = e;
182
+ return t instanceof Int8Array ? [-128, 127] : t instanceof Uint8Array ? [0, 255] : t instanceof Int16Array ? [-32768, 32767] : t instanceof Uint16Array ? [0, 65535] : t instanceof Int32Array ? [-2147483648, 2147483647] : t instanceof Uint32Array ? [0, 4294967295] : t instanceof BigInt64Array ? [-(2 ** 63), 2 ** 63 - 1] : t instanceof BigUint64Array ? [0, 2 ** 64 - 1] : [0, 1];
2828
183
  }
2829
184
  };
2830
185
  //#endregion
2831
186
  //#region src/main.ts
2832
- globalThis.OpenSeadragon && dr.enable(globalThis.OpenSeadragon);
187
+ globalThis.OpenSeadragon && o.enable(globalThis.OpenSeadragon);
2833
188
  //#endregion
2834
- export { dr as OMEZarrTileSource };
189
+ export { o as OMEZarrTileSource };