zarrextra 0.2.1 → 0.2.3
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.
- package/README.md +16 -4
- package/dist/{chunkDecode-Dtm8HfWS.js → chunkDecode-CvE5qLLQ.js} +1 -1
- package/dist/{chunkDecode-Dtm8HfWS.js.map → chunkDecode-CvE5qLLQ.js.map} +1 -1
- package/dist/codec-worker.js +7547 -3152
- package/dist/codec-worker.js.map +1 -1
- package/dist/index.js +264 -125
- package/dist/index.js.map +1 -1
- package/dist/workers/index.d.ts +5 -14
- package/dist/workers/index.d.ts.map +1 -1
- package/dist/workers/index.package.d.ts +6 -0
- package/dist/workers/index.package.d.ts.map +1 -0
- package/dist/workers/workerControls.d.ts +16 -0
- package/dist/workers/workerControls.d.ts.map +1 -0
- package/dist/workers/workerUrl.package.d.ts +2 -0
- package/dist/workers/workerUrl.package.d.ts.map +1 -0
- package/dist/workers/workerUrl.source.d.ts +2 -0
- package/dist/workers/workerUrl.source.d.ts.map +1 -0
- package/dist/workers.js +33 -22
- package/dist/workers.js.map +1 -1
- package/package.json +2 -2
- package/dist/codecs-DNu3yP16.js +0 -158
- package/dist/codecs-DNu3yP16.js.map +0 -1
- package/dist/workers/codec-worker-init.d.ts +0 -2
- package/dist/workers/codec-worker-init.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,57 +1,196 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import * as o from "zarrita";
|
|
1
|
+
import { t as e } from "./chunkDecode-CvE5qLLQ.js";
|
|
2
|
+
import * as t from "zarrita";
|
|
4
3
|
//#region src/result.ts
|
|
5
|
-
var
|
|
4
|
+
var n = (e) => ({
|
|
6
5
|
ok: !0,
|
|
7
6
|
value: e
|
|
8
|
-
}),
|
|
7
|
+
}), r = (e) => ({
|
|
9
8
|
ok: !1,
|
|
10
9
|
error: e
|
|
11
|
-
}),
|
|
10
|
+
}), i = (e) => e.ok, a = (e) => !e.ok, o = (e) => {
|
|
12
11
|
if (e.ok) return e.value;
|
|
13
12
|
throw e.error instanceof Error ? e.error : Error(String(e.error));
|
|
14
|
-
},
|
|
13
|
+
}, s = (e, t) => e.ok ? e.value : t, c = Symbol("attrs"), l = Symbol(".zarray");
|
|
15
14
|
//#endregion
|
|
16
15
|
//#region src/prefixedStore.ts
|
|
17
|
-
function
|
|
16
|
+
function u(e) {
|
|
18
17
|
let t = e.replace(/^\/+|\/+$/g, "");
|
|
19
18
|
return t ? `/${t}` : "/";
|
|
20
19
|
}
|
|
21
|
-
function
|
|
22
|
-
let n =
|
|
20
|
+
function d(e, t) {
|
|
21
|
+
let n = u(e);
|
|
23
22
|
return n === "/" ? t : t === "/" ? n : `${n}${t}`;
|
|
24
23
|
}
|
|
25
|
-
function
|
|
24
|
+
function f(e, t) {
|
|
26
25
|
return {
|
|
27
26
|
async get(n, r) {
|
|
28
|
-
return await e.get(
|
|
27
|
+
return await e.get(d(t, n), r);
|
|
29
28
|
},
|
|
30
|
-
getRange: e.getRange ? async (n, r, i) => await e.getRange?.(
|
|
29
|
+
getRange: e.getRange ? async (n, r, i) => await e.getRange?.(d(t, n), r, i) : void 0
|
|
31
30
|
};
|
|
32
31
|
}
|
|
33
32
|
//#endregion
|
|
34
|
-
//#region src/
|
|
35
|
-
|
|
33
|
+
//#region src/codecs.ts
|
|
34
|
+
function ee(e) {
|
|
35
|
+
let t = e.dataType ?? e.data_type, n = e.shape ?? e.chunk_shape;
|
|
36
|
+
if (!t) throw Error("Chunk metadata is missing dataType / data_type.");
|
|
37
|
+
if (!n) throw Error("Chunk metadata is missing shape / chunk_shape.");
|
|
38
|
+
return {
|
|
39
|
+
dataType: t,
|
|
40
|
+
shape: n,
|
|
41
|
+
codecs: e.codecs ?? [],
|
|
42
|
+
fillValue: e.fillValue ?? e.fill_value ?? null
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function p(e) {
|
|
46
|
+
return (t, n) => t.endsWith(".wasm") ? e : t;
|
|
47
|
+
}
|
|
48
|
+
var m = [
|
|
49
|
+
"imagecodecs_jpeg2k",
|
|
50
|
+
"numcodecs.imagecodecs_jpeg2k",
|
|
51
|
+
"jpeg2k"
|
|
52
|
+
], h = "experimental.openjph_htj2k", g = [h, ...[
|
|
53
|
+
"experimental.imagecodecs_htj2k",
|
|
54
|
+
"imagecodecs_htj2k",
|
|
55
|
+
"numcodecs.imagecodecs_htj2k"
|
|
56
|
+
]], _ = Function("specifier", "return import(specifier)");
|
|
57
|
+
function v(e) {
|
|
58
|
+
throw Error(`${e} encode is not implemented in zarrextra; decode-only for now.`);
|
|
59
|
+
}
|
|
36
60
|
function y(e) {
|
|
37
|
-
return e instanceof
|
|
61
|
+
return e instanceof Uint8Array ? e : ArrayBuffer.isView(e) ? new Uint8Array(e.buffer, e.byteOffset, e.byteLength) : new Uint8Array(e);
|
|
38
62
|
}
|
|
39
63
|
function b(e) {
|
|
64
|
+
let t = new ArrayBuffer(e.byteLength);
|
|
65
|
+
return new Uint8Array(t).set(e), t;
|
|
66
|
+
}
|
|
67
|
+
function x(e) {
|
|
68
|
+
return e.reduce((e, t) => e * t, 1);
|
|
69
|
+
}
|
|
70
|
+
function S(e) {
|
|
71
|
+
let t = Array(e.length), n = 1;
|
|
72
|
+
for (let r = e.length - 1; r >= 0; --r) t[r] = n, n *= e[r] ?? 1;
|
|
73
|
+
return t;
|
|
74
|
+
}
|
|
75
|
+
function C(e, t) {
|
|
76
|
+
if (Array.isArray(e)) throw Error("Image codec decoder returned a plain array; expected binary data.");
|
|
77
|
+
let n = b(y(e)), r = x(t.shape), i;
|
|
78
|
+
switch (t.dataType) {
|
|
79
|
+
case "uint8":
|
|
80
|
+
i = new Uint8Array(n);
|
|
81
|
+
break;
|
|
82
|
+
case "int8":
|
|
83
|
+
i = new Int8Array(n);
|
|
84
|
+
break;
|
|
85
|
+
case "uint16":
|
|
86
|
+
i = new Uint16Array(n);
|
|
87
|
+
break;
|
|
88
|
+
case "int16":
|
|
89
|
+
i = new Int16Array(n);
|
|
90
|
+
break;
|
|
91
|
+
case "uint32":
|
|
92
|
+
i = new Uint32Array(n);
|
|
93
|
+
break;
|
|
94
|
+
case "int32":
|
|
95
|
+
i = new Int32Array(n);
|
|
96
|
+
break;
|
|
97
|
+
case "float32":
|
|
98
|
+
i = new Float32Array(n);
|
|
99
|
+
break;
|
|
100
|
+
case "float64":
|
|
101
|
+
i = new Float64Array(n);
|
|
102
|
+
break;
|
|
103
|
+
default: throw Error(`Image codec does not support Zarrita dtype '${t.dataType}'.`);
|
|
104
|
+
}
|
|
105
|
+
if (i.length !== r) throw Error(`Image codec decoded ${i.length} values, expected ${r} for chunk shape [${t.shape.join(", ")}].`);
|
|
106
|
+
return i;
|
|
107
|
+
}
|
|
108
|
+
function te(e, t) {
|
|
109
|
+
return async () => ({
|
|
110
|
+
kind: "array_to_bytes",
|
|
111
|
+
fromConfig(n, r) {
|
|
112
|
+
let i = ee(r);
|
|
113
|
+
return {
|
|
114
|
+
kind: "array_to_bytes",
|
|
115
|
+
encode: () => v(e),
|
|
116
|
+
async decode(e) {
|
|
117
|
+
return {
|
|
118
|
+
data: C(await t(e, i, n), i),
|
|
119
|
+
shape: i.shape,
|
|
120
|
+
stride: S(i.shape)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function w(e, t = {}) {
|
|
128
|
+
let n;
|
|
129
|
+
async function r() {
|
|
130
|
+
return n ??= Promise.resolve(e({ locateFile: t.locateFile })), await n;
|
|
131
|
+
}
|
|
132
|
+
return async (e) => {
|
|
133
|
+
let t = (await r()).J2KDecoder;
|
|
134
|
+
if (!t) throw Error("OpenJPEG runtime does not expose J2KDecoder.");
|
|
135
|
+
let n = new t();
|
|
136
|
+
return n.getEncodedBuffer(e.length).set(e), n.decode(), n.getDecodedBuffer();
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
async function ne(e) {
|
|
140
|
+
let t = await _("@cornerstonejs/codec-openjpeg/decode").catch(() => _("@cornerstonejs/codec-openjpeg")), n = t.default ?? t.OpenJPEGJS ?? t.OpenJPEGWASM ?? t;
|
|
141
|
+
if (typeof n != "function") throw Error("Could not find an OpenJPEG factory export in @cornerstonejs/codec-openjpeg.");
|
|
142
|
+
return w(n, e);
|
|
143
|
+
}
|
|
144
|
+
function T(e, t = {}) {
|
|
145
|
+
let n;
|
|
146
|
+
async function r() {
|
|
147
|
+
return n ??= Promise.resolve(e({ locateFile: t.locateFile })), await n;
|
|
148
|
+
}
|
|
149
|
+
return async (e) => {
|
|
150
|
+
let t = await r(), n = t.HTJ2KDecoder ?? t.JPHDecoder ?? t.J2KDecoder;
|
|
151
|
+
if (!n) throw Error("OpenJPH runtime does not expose a known decoder class; pass a custom decoder option.");
|
|
152
|
+
let i = new n();
|
|
153
|
+
return i.getEncodedBuffer(e.length).set(e), i.decode(), i.getDecodedBuffer();
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
async function re(e) {
|
|
157
|
+
let t = await _("@cornerstonejs/codec-openjph/wasmjs").catch(() => _("@cornerstonejs/codec-openjph")), n = t.default ?? t.OpenJPHJS ?? t;
|
|
158
|
+
if (typeof n != "function") throw Error("Could not find an OpenJPH factory export in @cornerstonejs/codec-openjph.");
|
|
159
|
+
let r = await _("@cornerstonejs/codec-openjph/wasm").catch(() => null), i = r ? r.default ?? r : void 0;
|
|
160
|
+
return T(n, { locateFile: e.locateFile ?? (i ? p(i) : void 0) });
|
|
161
|
+
}
|
|
162
|
+
function E(e, n, r, i = {}) {
|
|
163
|
+
let a = i.ids ?? n, o, s = async () => (o ??= Promise.resolve(i.decoder ?? r(i)), await o);
|
|
164
|
+
for (let n of a) t.registry.set(n, te(e, async (e, t, n) => await (await s())(e, t, n)));
|
|
165
|
+
}
|
|
166
|
+
function D(e = {}) {
|
|
167
|
+
E("imagecodecs_jpeg2k", m, ne, e);
|
|
168
|
+
}
|
|
169
|
+
function O(e = {}) {
|
|
170
|
+
E(h, g, re, e);
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/htj2k-encode.ts
|
|
174
|
+
var k = Function("specifier", "return import(specifier)");
|
|
175
|
+
function A(e) {
|
|
176
|
+
return e instanceof Uint16Array || e instanceof Int16Array ? 16 : 8;
|
|
177
|
+
}
|
|
178
|
+
function j(e) {
|
|
40
179
|
return e instanceof Int8Array || e instanceof Int16Array;
|
|
41
180
|
}
|
|
42
|
-
function
|
|
181
|
+
function M(e, t) {
|
|
43
182
|
let { width: n, height: r } = t, i = n * r;
|
|
44
183
|
if (e.length !== i) throw Error(`HTJ2K plane has ${e.length} samples, expected ${i} for ${n}x${r}.`);
|
|
45
184
|
return {
|
|
46
185
|
width: n,
|
|
47
186
|
height: r,
|
|
48
|
-
bitsPerSample:
|
|
49
|
-
isSigned:
|
|
187
|
+
bitsPerSample: A(e),
|
|
188
|
+
isSigned: j(e),
|
|
50
189
|
componentCount: 1,
|
|
51
190
|
isUsingColorTransform: !1
|
|
52
191
|
};
|
|
53
192
|
}
|
|
54
|
-
function
|
|
193
|
+
function N(e, t = {}) {
|
|
55
194
|
let n;
|
|
56
195
|
async function r() {
|
|
57
196
|
return n ??= Promise.resolve(e({ locateFile: t.locateFile })), await n;
|
|
@@ -59,19 +198,19 @@ function S(e, t = {}) {
|
|
|
59
198
|
return async (e, t, n = {}) => {
|
|
60
199
|
let i = (await r()).HTJ2KEncoder;
|
|
61
200
|
if (!i) throw Error("OpenJPH runtime does not expose HTJ2KEncoder.");
|
|
62
|
-
let a = n.reversible ?? !0, o = n.quality ?? 0, s =
|
|
201
|
+
let a = n.reversible ?? !0, o = n.quality ?? 0, s = M(e, t), c = new i();
|
|
63
202
|
c.setQuality(a, o);
|
|
64
203
|
let l = c.getDecodedBuffer(s);
|
|
65
204
|
return (s.bitsPerSample === 16 ? new Uint16Array(l.buffer, l.byteOffset, e.length) : new Uint8Array(l.buffer, l.byteOffset, e.length)).set(e), c.encode(), c.getEncodedBuffer();
|
|
66
205
|
};
|
|
67
206
|
}
|
|
68
|
-
async function
|
|
69
|
-
let t = await
|
|
207
|
+
async function P(e = {}) {
|
|
208
|
+
let t = await k("@cornerstonejs/codec-openjph/wasmjs").catch(() => k("@cornerstonejs/codec-openjph")), n = t.default ?? t.OpenJPHJS ?? t;
|
|
70
209
|
if (typeof n != "function") throw Error("Could not find an OpenJPH factory export in @cornerstonejs/codec-openjph.");
|
|
71
|
-
let
|
|
72
|
-
return
|
|
210
|
+
let r = await k("@cornerstonejs/codec-openjph/wasm").catch(() => null), i = r ? r.default ?? r : void 0;
|
|
211
|
+
return N(n, { locateFile: e.locateFile ?? (i ? p(i) : void 0) });
|
|
73
212
|
}
|
|
74
|
-
function
|
|
213
|
+
function F(e, t) {
|
|
75
214
|
switch (e) {
|
|
76
215
|
case "uint8": return t;
|
|
77
216
|
case "int8": return new Int8Array(t.buffer, t.byteOffset, t.byteLength);
|
|
@@ -80,45 +219,45 @@ function ee(e, t) {
|
|
|
80
219
|
default: throw Error(`Unsupported HTJ2K plane dtype '${e}'.`);
|
|
81
220
|
}
|
|
82
221
|
}
|
|
83
|
-
async function
|
|
84
|
-
return await (await
|
|
222
|
+
async function I(e, t, n = {}) {
|
|
223
|
+
return await (await P(n))(e, t, n);
|
|
85
224
|
}
|
|
86
225
|
//#endregion
|
|
87
226
|
//#region src/omeZarr.ts
|
|
88
|
-
function
|
|
227
|
+
function L(e) {
|
|
89
228
|
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
90
229
|
}
|
|
91
|
-
function
|
|
92
|
-
return
|
|
230
|
+
function R(e) {
|
|
231
|
+
return L(e) && typeof e.name == "string";
|
|
93
232
|
}
|
|
94
|
-
function
|
|
95
|
-
return
|
|
233
|
+
function z(e) {
|
|
234
|
+
return L(e) && typeof e.path == "string";
|
|
96
235
|
}
|
|
97
|
-
function
|
|
98
|
-
if (!
|
|
236
|
+
function B(e) {
|
|
237
|
+
if (!L(e)) return !1;
|
|
99
238
|
let t = e.datasets;
|
|
100
|
-
if (t !== void 0 && (!Array.isArray(t) || !t.every(
|
|
239
|
+
if (t !== void 0 && (!Array.isArray(t) || !t.every(z))) return !1;
|
|
101
240
|
let n = e.axes;
|
|
102
|
-
return !(n !== void 0 && (!Array.isArray(n) || !n.every((e) => typeof e == "string" ||
|
|
241
|
+
return !(n !== void 0 && (!Array.isArray(n) || !n.every((e) => typeof e == "string" || R(e))));
|
|
103
242
|
}
|
|
104
|
-
function
|
|
105
|
-
let t =
|
|
243
|
+
function V(e) {
|
|
244
|
+
let t = L(e.ome) ? e.ome : e;
|
|
106
245
|
if (!("multiscales" in t)) return t;
|
|
107
246
|
if (!Array.isArray(t.multiscales)) throw Error("OME-Zarr `multiscales` attribute must be an array.");
|
|
108
|
-
if (!t.multiscales.every(
|
|
247
|
+
if (!t.multiscales.every(B)) throw Error("OME-Zarr `multiscales` entries must contain valid dataset paths and axes.");
|
|
109
248
|
return t;
|
|
110
249
|
}
|
|
111
|
-
function
|
|
250
|
+
function H(e, t) {
|
|
112
251
|
let n = e[e.length - 1];
|
|
113
252
|
return !(n !== 3 && n !== 4 || t?.some((e) => e.toLowerCase() === "c"));
|
|
114
253
|
}
|
|
115
|
-
function
|
|
254
|
+
function U(e, t) {
|
|
116
255
|
let n = e.findIndex((e) => e.toLowerCase() === t);
|
|
117
256
|
if (n === -1) throw Error(`OME-Zarr labels must include '${t}' axis.`);
|
|
118
257
|
return n;
|
|
119
258
|
}
|
|
120
|
-
function
|
|
121
|
-
if (
|
|
259
|
+
function W(e, t) {
|
|
260
|
+
if (H(e, t)) {
|
|
122
261
|
let t = e.length;
|
|
123
262
|
return {
|
|
124
263
|
yIndex: t - 3,
|
|
@@ -126,16 +265,16 @@ function M(e, t) {
|
|
|
126
265
|
};
|
|
127
266
|
}
|
|
128
267
|
return {
|
|
129
|
-
yIndex:
|
|
130
|
-
xIndex:
|
|
268
|
+
yIndex: U(t, "y"),
|
|
269
|
+
xIndex: U(t, "x")
|
|
131
270
|
};
|
|
132
271
|
}
|
|
133
|
-
function
|
|
134
|
-
let { xIndex: n, yIndex: r } =
|
|
272
|
+
function G(e, t) {
|
|
273
|
+
let { xIndex: n, yIndex: r } = W(e, t);
|
|
135
274
|
return [e[r] ?? 0, e[n] ?? 0];
|
|
136
275
|
}
|
|
137
|
-
function
|
|
138
|
-
if (
|
|
276
|
+
function K(e, t, n) {
|
|
277
|
+
if (H(t, n)) {
|
|
139
278
|
let [t, n] = e.slice(-3);
|
|
140
279
|
return [t ?? 0, n ?? 0];
|
|
141
280
|
}
|
|
@@ -145,25 +284,25 @@ function P(e, t, n) {
|
|
|
145
284
|
}
|
|
146
285
|
return [e[0] ?? 0, 0];
|
|
147
286
|
}
|
|
148
|
-
function
|
|
149
|
-
let [t, n] =
|
|
287
|
+
function q(e) {
|
|
288
|
+
let [t, n] = G(e.shape, e.labels);
|
|
150
289
|
return {
|
|
151
290
|
height: t,
|
|
152
291
|
width: n
|
|
153
292
|
};
|
|
154
293
|
}
|
|
155
|
-
function
|
|
294
|
+
function J(e) {
|
|
156
295
|
return 2 ** Math.floor(Math.log2(e));
|
|
157
296
|
}
|
|
158
|
-
function
|
|
159
|
-
if (
|
|
297
|
+
function Y(e, t) {
|
|
298
|
+
if (H(e.shape, t)) {
|
|
160
299
|
let [t, n] = e.chunks.slice(-3);
|
|
161
|
-
return
|
|
300
|
+
return J(Math.min(t ?? 1, n ?? 1));
|
|
162
301
|
}
|
|
163
|
-
let n = e.chunks[
|
|
164
|
-
return
|
|
302
|
+
let n = e.chunks[U(t, "y")], r = e.chunks[U(t, "x")];
|
|
303
|
+
return J(Math.min(n ?? 1, r ?? 1));
|
|
165
304
|
}
|
|
166
|
-
function
|
|
305
|
+
function X(e) {
|
|
167
306
|
return e ? e.map((e) => typeof e == "string" ? e : e.name) : [
|
|
168
307
|
"t",
|
|
169
308
|
"c",
|
|
@@ -172,7 +311,7 @@ function R(e) {
|
|
|
172
311
|
"x"
|
|
173
312
|
];
|
|
174
313
|
}
|
|
175
|
-
function
|
|
314
|
+
function ie(e) {
|
|
176
315
|
return {
|
|
177
316
|
u1: "Uint8",
|
|
178
317
|
u2: "Uint16",
|
|
@@ -192,7 +331,7 @@ function z(e) {
|
|
|
192
331
|
float64: "Float64"
|
|
193
332
|
}[e.toLowerCase()] ?? e.charAt(0).toUpperCase() + e.slice(1);
|
|
194
333
|
}
|
|
195
|
-
function
|
|
334
|
+
function ae(e) {
|
|
196
335
|
if (new Set(e).size !== e.length) throw Error("OME-Zarr labels must be unique.");
|
|
197
336
|
return (t) => {
|
|
198
337
|
if (Array.isArray(t)) return [...t];
|
|
@@ -205,34 +344,34 @@ function te(e) {
|
|
|
205
344
|
return n;
|
|
206
345
|
};
|
|
207
346
|
}
|
|
208
|
-
var
|
|
347
|
+
var Z = class extends Error {}, oe = class {
|
|
209
348
|
constructor(e, t, n) {
|
|
210
|
-
this.data = e, this.labels = t, this.tileSize = n, this.indexer =
|
|
349
|
+
this.data = e, this.labels = t, this.tileSize = n, this.indexer = ae(t);
|
|
211
350
|
}
|
|
212
351
|
get shape() {
|
|
213
352
|
return this.data.shape;
|
|
214
353
|
}
|
|
215
354
|
get dtype() {
|
|
216
|
-
return
|
|
355
|
+
return ie(this.data.dtype);
|
|
217
356
|
}
|
|
218
357
|
chunkIndex(e, t) {
|
|
219
|
-
let { xIndex: n, yIndex: r } =
|
|
358
|
+
let { xIndex: n, yIndex: r } = W(this.data.shape, this.labels), i = this.indexer(e);
|
|
220
359
|
return i[n] = t.x, i[r] = t.y, i;
|
|
221
360
|
}
|
|
222
|
-
getSlices(e,
|
|
223
|
-
let { height:
|
|
224
|
-
if (
|
|
225
|
-
if (
|
|
226
|
-
return [
|
|
361
|
+
getSlices(e, n) {
|
|
362
|
+
let { height: r, width: i } = q(this), a = e * this.tileSize, o = Math.min((e + 1) * this.tileSize, i), s = n * this.tileSize, c = Math.min((n + 1) * this.tileSize, r);
|
|
363
|
+
if (a >= o || s >= c) throw new Z("Tile slice is zero-sized or inverted.");
|
|
364
|
+
if (a < 0 || s < 0 || o > i || c > r) throw new Z("Tile slice is out of bounds.");
|
|
365
|
+
return [t.slice(a, o), t.slice(s, c)];
|
|
227
366
|
}
|
|
228
|
-
async getRaw(
|
|
229
|
-
return await
|
|
367
|
+
async getRaw(t, n) {
|
|
368
|
+
return await e(this.data, t, { signal: n });
|
|
230
369
|
}
|
|
231
370
|
async getRaster({ selection: e, signal: t }) {
|
|
232
371
|
let n = this.chunkIndex(e, {
|
|
233
372
|
x: null,
|
|
234
373
|
y: null
|
|
235
|
-
}), r = await this.getRaw(n, t), [i, a] =
|
|
374
|
+
}), r = await this.getRaw(n, t), [i, a] = K(r.shape, this.data.shape, this.labels);
|
|
236
375
|
return {
|
|
237
376
|
data: r.data,
|
|
238
377
|
width: a,
|
|
@@ -243,7 +382,7 @@ var B = class extends Error {}, V = class {
|
|
|
243
382
|
let [i, a] = this.getSlices(e, t), o = this.chunkIndex(n, {
|
|
244
383
|
x: i,
|
|
245
384
|
y: a
|
|
246
|
-
}), s = await this.getRaw(o, r), [c, l] =
|
|
385
|
+
}), s = await this.getRaw(o, r), [c, l] = K(s.shape, this.data.shape, this.labels);
|
|
247
386
|
return {
|
|
248
387
|
data: s.data,
|
|
249
388
|
width: l,
|
|
@@ -251,86 +390,86 @@ var B = class extends Error {}, V = class {
|
|
|
251
390
|
};
|
|
252
391
|
}
|
|
253
392
|
onTileError(e) {
|
|
254
|
-
if (!(e instanceof
|
|
393
|
+
if (!(e instanceof Z)) throw e;
|
|
255
394
|
}
|
|
256
395
|
};
|
|
257
|
-
async function
|
|
258
|
-
let
|
|
396
|
+
async function se(e) {
|
|
397
|
+
let n = await t.withMaybeConsolidatedMetadata(e), r = t.root(n), i = V((await t.open(r, { kind: "group" })).attrs), a = i.multiscales?.[0], o = a?.datasets?.map((e) => e.path) ?? ["0"], s = X(a?.axes);
|
|
259
398
|
return {
|
|
260
|
-
data: await Promise.all(
|
|
399
|
+
data: await Promise.all(o.map((e) => t.open(r.resolve(e), { kind: "array" }))),
|
|
261
400
|
labels: s,
|
|
262
|
-
rootAttrs:
|
|
401
|
+
rootAttrs: i
|
|
263
402
|
};
|
|
264
403
|
}
|
|
265
|
-
async function
|
|
266
|
-
let { data: t, labels: n } = await
|
|
404
|
+
async function ce(e) {
|
|
405
|
+
let { data: t, labels: n } = await se(e);
|
|
267
406
|
if (t.length === 0) throw Error("OME-Zarr multiscale dataset is empty or has no valid arrays.");
|
|
268
|
-
let r =
|
|
269
|
-
return t.map((e) => new
|
|
407
|
+
let r = Y(t[0], n);
|
|
408
|
+
return t.map((e) => new oe(e, n, r));
|
|
270
409
|
}
|
|
271
410
|
//#endregion
|
|
272
411
|
//#region src/index.ts
|
|
273
|
-
var
|
|
274
|
-
function
|
|
412
|
+
var le = new TextDecoder();
|
|
413
|
+
function ue(e) {
|
|
275
414
|
return typeof e != "string";
|
|
276
415
|
}
|
|
277
|
-
function
|
|
416
|
+
function de(e) {
|
|
278
417
|
return "contents" in e && typeof e.contents == "function";
|
|
279
418
|
}
|
|
280
|
-
function
|
|
419
|
+
function fe(e) {
|
|
281
420
|
return e.replace(/\/+$/, "");
|
|
282
421
|
}
|
|
283
|
-
function
|
|
422
|
+
function pe(e) {
|
|
284
423
|
return typeof e == "string" ? e : "[store instance]";
|
|
285
424
|
}
|
|
286
|
-
function
|
|
425
|
+
function me(e, t) {
|
|
287
426
|
let n = e === "/" ? "" : e;
|
|
288
427
|
return t === "array" ? [`${n}/zarr.json`, `${n}/.zarray`] : [`${n}/zarr.json`, `${n}/.zgroup`];
|
|
289
428
|
}
|
|
290
|
-
async function
|
|
291
|
-
for (let r of
|
|
429
|
+
async function Q(e, t, n) {
|
|
430
|
+
for (let r of me(t, n)) {
|
|
292
431
|
let t = await e.get(r);
|
|
293
|
-
if (t) return JSON.parse(
|
|
432
|
+
if (t) return JSON.parse(le.decode(t));
|
|
294
433
|
}
|
|
295
434
|
}
|
|
296
|
-
async function
|
|
297
|
-
return
|
|
435
|
+
async function he(e, n, r) {
|
|
436
|
+
return n === "/" ? e.attrs : (r === "array" ? await t.open(e.resolve(n), { kind: "array" }) : await t.open(e.resolve(n), { kind: "group" })).attrs;
|
|
298
437
|
}
|
|
299
|
-
function
|
|
438
|
+
function ge(e, t) {
|
|
300
439
|
return e.path.split("/").filter(Boolean).length - t.path.split("/").filter(Boolean).length;
|
|
301
440
|
}
|
|
302
|
-
async function
|
|
303
|
-
let
|
|
304
|
-
for (let { path:
|
|
305
|
-
if (
|
|
306
|
-
let
|
|
307
|
-
for (let [
|
|
308
|
-
if (!(
|
|
441
|
+
async function _e(e) {
|
|
442
|
+
let n = await t.open(e, { kind: "group" }), r = { [c]: n.attrs }, i = e.contents().sort(ge);
|
|
443
|
+
for (let { path: a, kind: o } of i) {
|
|
444
|
+
if (a === "/") continue;
|
|
445
|
+
let i = a.split("/").filter(Boolean), s = r;
|
|
446
|
+
for (let [r, a] of i.entries()) {
|
|
447
|
+
if (!(a in s)) if (r !== i.length - 1) s[a] = {};
|
|
309
448
|
else {
|
|
310
|
-
let
|
|
311
|
-
if (
|
|
312
|
-
let
|
|
313
|
-
if (!
|
|
314
|
-
s[
|
|
315
|
-
[
|
|
316
|
-
[
|
|
317
|
-
get: () =>
|
|
449
|
+
let u = `/${i.slice(0, r + 1).join("/")}`, d = await he(n, u, o);
|
|
450
|
+
if (o === "array") {
|
|
451
|
+
let r = await Q(e, u, "array");
|
|
452
|
+
if (!r) throw Error(`Missing array metadata for '${u}'`);
|
|
453
|
+
s[a] = {
|
|
454
|
+
[c]: d,
|
|
455
|
+
[l]: r,
|
|
456
|
+
get: () => t.open(n.resolve(u), { kind: "array" })
|
|
318
457
|
};
|
|
319
|
-
} else s[
|
|
458
|
+
} else s[a] = { [c]: d };
|
|
320
459
|
}
|
|
321
|
-
s = s[
|
|
460
|
+
s = s[a];
|
|
322
461
|
}
|
|
323
462
|
}
|
|
324
|
-
return
|
|
463
|
+
return r;
|
|
325
464
|
}
|
|
326
|
-
async function
|
|
327
|
-
let
|
|
328
|
-
if (
|
|
465
|
+
async function ve(e) {
|
|
466
|
+
let n = ue(e) ? e : new t.FetchStore(fe(e));
|
|
467
|
+
if (de(n)) return n;
|
|
329
468
|
try {
|
|
330
|
-
return await
|
|
469
|
+
return await t.withConsolidatedMetadata(n);
|
|
331
470
|
} catch (e) {
|
|
332
471
|
try {
|
|
333
|
-
return await
|
|
472
|
+
return await t.withConsolidatedMetadata(n, {
|
|
334
473
|
format: "v2",
|
|
335
474
|
metadataKey: "zmetadata"
|
|
336
475
|
});
|
|
@@ -339,22 +478,22 @@ async function re(e) {
|
|
|
339
478
|
}
|
|
340
479
|
}
|
|
341
480
|
}
|
|
342
|
-
async function
|
|
481
|
+
async function ye(e) {
|
|
343
482
|
try {
|
|
344
|
-
let t = await
|
|
345
|
-
return
|
|
483
|
+
let t = await ve(e);
|
|
484
|
+
return n({
|
|
346
485
|
zarritaStore: t,
|
|
347
|
-
tree: await
|
|
486
|
+
tree: await _e(t)
|
|
348
487
|
});
|
|
349
488
|
} catch (t) {
|
|
350
489
|
let n = t instanceof Error ? t.message : String(t);
|
|
351
|
-
return
|
|
490
|
+
return r(/* @__PURE__ */ Error(`Failed to open zarr store '${pe(e)}': ${n}`));
|
|
352
491
|
}
|
|
353
492
|
}
|
|
354
493
|
function $(e) {
|
|
355
494
|
if (typeof e != "object" || !e) return e;
|
|
356
495
|
let t = {};
|
|
357
|
-
|
|
496
|
+
c in e && e[c] && (t._attrs = e[c]), l in e && e[l] && (t._zarray = e[l]);
|
|
358
497
|
for (let n in e) if (Object.prototype.hasOwnProperty.call(e, n)) {
|
|
359
498
|
let r = e[n];
|
|
360
499
|
typeof r == "function" ? t[n] = "<function>" : t[n] = $(r);
|
|
@@ -362,6 +501,6 @@ function $(e) {
|
|
|
362
501
|
return t;
|
|
363
502
|
}
|
|
364
503
|
//#endregion
|
|
365
|
-
export {
|
|
504
|
+
export { c as ATTRS_KEY, r as Err, n as Ok, l as ZARRAY_KEY, w as createOpenJpegDecoder, T as createOpenJphDecoder, N as createOpenJphEncoder, f as createPrefixedStore, p as createWasmLocateFile, I as encodeHtj2kPlane, a as isErr, i as isOk, ce as loadOmeZarrMultiscalesFromStore, P as loadOpenJphEncoder, ye as openExtraConsolidated, F as planeArrayForDtype, O as registerExperimentalHtj2kCodec, D as registerJpeg2kCodec, $ as serializeZarrTree, o as unwrap, s as unwrapOr };
|
|
366
505
|
|
|
367
506
|
//# sourceMappingURL=index.js.map
|