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