vitessce 3.8.5 → 3.8.6

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,17 +1,17 @@
1
- import { aw as i, ax as Ce, ay as oe, ar as ce, as as Ee, az as pe, l as le, aA as Te, aB as Se, m as te, aC as ae, e as R, V as b, ag as V, ae as we, aq as I, aD as ze, aE as ke, av as Ie, W as De, ad as Me, z as Ae, aF as Pe, ao as D, aG as Be, am as Ne } from "./index-B1jRU6rn.js";
2
- import { useRef as z, useState as ne, useMemo as ue, useEffect as H, useCallback as he } from "react";
3
- import { u as fe, a as Ue, O as de, C as Oe } from "./OrbitControls-Cpzab6dg.js";
4
- const T = 32, k = 64, O = 64, se = 4, ie = k * O * se, ve = k * T, me = O * T, xe = se * T, G = {
1
+ import { aw as r, ax as ye, ay as ae, ar as le, as as Te, az as pe, l as ce, aA as Ee, aB as Se, m as te, aC as oe, e as C, V as b, ag as V, ae as we, aq as D, aD as ze, aE as ke, av as Ie, W as De, ad as Me, z as Pe, aF as Ae, ao as M, aG as Be, am as Ne } from "./index-Du-5tfGa.js";
2
+ import { useRef as z, useState as re, useMemo as ue, useEffect as H, useCallback as he } from "react";
3
+ import { u as fe, a as Ue, O as de, C as Oe } from "./OrbitControls-C2dOs24x.js";
4
+ const E = 32, I = 64, O = 64, se = 4, ie = I * O * se, ve = I * E, me = O * E, xe = se * E, G = {
5
5
  NOT_STARTED: "not_started",
6
6
  IN_PROGRESS: "in_progress",
7
7
  COMPLETE: "complete",
8
8
  FAILED: "failed"
9
9
  };
10
- function M(h) {
11
- oe(ae.DEBUG) && console.warn(`%cDM: ${h}`, "background: blue; color: white; padding: 2px; border-radius: 3px;");
10
+ function k(f) {
11
+ ae(oe.DEBUG) && console.warn(`%cDM: ${f}`, "background: blue; color: white; padding: 2px; border-radius: 3px;");
12
12
  }
13
- function Fe(h) {
14
- return h.map((t) => {
13
+ function Le(f) {
14
+ return f.map((t) => {
15
15
  const { dims: e } = t;
16
16
  return [
17
17
  // Other spatial-accelerated code assumes TCZYX dimension order
@@ -25,8 +25,8 @@ function Fe(h) {
25
25
  ];
26
26
  });
27
27
  }
28
- function Le(h) {
29
- return h.map((t) => {
28
+ function Fe(f) {
29
+ return f.map((t) => {
30
30
  const e = [
31
31
  t.depth,
32
32
  // z
@@ -36,14 +36,14 @@ function Le(h) {
36
36
  // x
37
37
  ];
38
38
  return [
39
- Math.ceil((e[0] || 1) / T),
40
- Math.ceil((e[1] || 1) / T),
41
- Math.ceil((e[2] || 1) / T)
39
+ Math.ceil((e[0] || 1) / E),
40
+ Math.ceil((e[1] || 1) / E),
41
+ Math.ceil((e[2] || 1) / E)
42
42
  ];
43
43
  });
44
44
  }
45
- function Ve(h, t) {
46
- i.debug("_initMRMCPT", h, t);
45
+ function Ve(f, t) {
46
+ r.debug("_initMRMCPT", f, t);
47
47
  const e = {
48
48
  channelOffsets: [
49
49
  [0, 0, 1],
@@ -68,88 +68,89 @@ function Ve(h, t) {
68
68
  // original z extent plus the l0 z extent times the channel count
69
69
  };
70
70
  e.xExtent = 1, e.yExtent = 1, e.zExtent = 1;
71
- const n = h[0][0];
72
- e.z0Extent = n, e.lowestDataRes = h.length - 1;
73
- for (let l = h.length - 1; l > 0; l--)
71
+ const i = f[0][0];
72
+ e.z0Extent = i, e.lowestDataRes = f.length - 1;
73
+ for (let c = f.length - 1; c > 0; c--)
74
74
  e.anchors.push([
75
75
  e.xExtent,
76
76
  e.yExtent,
77
77
  e.zExtent
78
- ]), e.xExtent += h[l][2], e.yExtent += h[l][1], e.zExtent += h[l][0];
79
- e.anchors.push([0, 0, e.zExtent]), e.anchors.reverse(), e.zTotal = e.zExtent + t * n;
80
- const o = new Uint8Array(ve * me * xe);
81
- o.fill(0);
82
- const r = new Uint32Array(e.xExtent * e.yExtent * e.zTotal);
83
- r.fill(0);
84
- const a = new ce(o, ve, me, xe);
85
- a.format = Ee, a.type = pe, a.internalFormat = "R8", a.minFilter = le, a.magFilter = le, a.generateMipmaps = !1, a.needsUpdate = !0;
86
- const c = new ce(r, e.xExtent, e.yExtent, e.zTotal);
87
- return c.format = Te, c.type = Se, c.internalFormat = "R32UI", c.minFilter = te, c.magFilter = te, c.generateMipmaps = !1, c.needsUpdate = !0, i.debug("_initMRMCPT", e, c, a), {
78
+ ]), e.xExtent += f[c][2], e.yExtent += f[c][1], e.zExtent += f[c][0];
79
+ e.anchors.push([0, 0, e.zExtent]), e.anchors.reverse(), e.zTotal = e.zExtent + t * i;
80
+ const a = new Uint8Array(ve * me * xe);
81
+ a.fill(0);
82
+ const n = new Uint32Array(e.xExtent * e.yExtent * e.zTotal);
83
+ n.fill(0);
84
+ const o = new le(a, ve, me, xe);
85
+ o.format = Te, o.type = pe, o.internalFormat = "R8", o.minFilter = ce, o.magFilter = ce, o.generateMipmaps = !1, o.needsUpdate = !0;
86
+ const l = new le(n, e.xExtent, e.yExtent, e.zTotal);
87
+ return l.format = Ee, l.type = Se, l.internalFormat = "R32UI", l.minFilter = te, l.magFilter = te, l.generateMipmaps = !1, l.needsUpdate = !0, r.debug("_initMRMCPT", e, l, o), {
88
88
  PT: e,
89
- ptTHREE: c,
90
- bcTHREE: a
89
+ ptTHREE: l,
90
+ bcTHREE: o
91
91
  };
92
92
  }
93
- function Ge(h, t, e, n, o) {
94
- const r = (a) => Math.max(0, Math.min(127, Math.floor(a / 2)));
95
- return (1 << 31 | 1 << 30 | r(h) << 23 | r(t) << 16 | (e & 63) << 10 | (n & 63) << 4 | o & 15) >>> 0;
93
+ function Ge(f, t, e, i, a) {
94
+ const n = (o) => Math.max(0, Math.min(127, Math.floor(o / 2)));
95
+ return (1 << 31 | 1 << 30 | n(f) << 23 | n(t) << 16 | (e & 63) << 10 | (i & 63) << 4 | a & 15) >>> 0;
96
96
  }
97
- function Ze(h, t, e, n) {
98
- const { PT_zExtent: o, PT_z0Extent: r, PT_anchors: a } = n;
99
- let c = -1, l = -1, s = -1, x = -1, m = -1;
100
- if (e >= o)
101
- l = 0, s = h, x = t, m = (e - o) % r, c = Math.floor((e - o) / r);
97
+ function Ze(f, t, e, i) {
98
+ const { PT_zExtent: a, PT_z0Extent: n, PT_anchors: o } = i;
99
+ let l = -1, c = -1, s = -1, x = -1, m = -1;
100
+ if (e >= a)
101
+ c = 0, s = f, x = t, m = (e - a) % n, l = Math.floor((e - a) / n);
102
102
  else
103
- for (let u = 1; u < a.length; u++)
104
- if (!(h < a[u][0] && t < a[u][1] && e < a[u][2])) {
105
- l = u;
103
+ for (let u = 1; u < o.length; u++)
104
+ if (!(f < o[u][0] && t < o[u][1] && e < o[u][2])) {
105
+ c = u;
106
106
  const d = [0, 0, 0];
107
- h >= a[u][0] && (d[0] = 1), t >= a[u][1] && (d[1] = 1), e >= a[u][2] && (d[2] = 1);
107
+ f >= o[u][0] && (d[0] = 1), t >= o[u][1] && (d[1] = 1), e >= o[u][2] && (d[2] = 1);
108
108
  const v = d[0] << 2 | d[1] << 1 | d[2];
109
- c = Math.max(1, Math.min(7, v)) - 1;
110
- const f = d.map((p, _) => p * a[u][_]);
111
- s = h - f[0], x = t - f[1], m = e - f[2];
109
+ l = Math.max(1, Math.min(7, v)) - 1;
110
+ const h = d.map((p, _) => p * o[u][_]);
111
+ s = f - h[0], x = t - h[1], m = e - h[2];
112
112
  break;
113
113
  }
114
114
  return {
115
- channel: c,
116
- resolution: l,
115
+ channel: l,
116
+ resolution: c,
117
117
  x: s,
118
118
  y: x,
119
119
  z: m
120
120
  };
121
121
  }
122
- function Xe(h, t) {
122
+ function Xe(f, t) {
123
123
  const e = /* @__PURE__ */ new Map();
124
- for (let o = 0; o < h.length; o += 4) {
125
- const r = h[o], a = h[o + 1], c = h[o + 2], l = h[o + 3];
126
- if ((r | a | c | l) === 0)
124
+ for (let a = 0; a < f.length; a += 4) {
125
+ const n = f[a], o = f[a + 1], l = f[a + 2], c = f[a + 3];
126
+ if ((n | o | l | c) === 0)
127
127
  continue;
128
- const s = (r << 24 | a << 16 | c << 8 | l) >>> 0;
128
+ const s = (n << 24 | o << 16 | l << 8 | c) >>> 0;
129
129
  e.set(s, (e.get(s) || 0) + 1);
130
130
  }
131
- return { requests: [...e.entries()].sort((o, r) => r[1] - o[1]).slice(0, t).map(([o]) => ({
132
- x: o >> 22 & 1023,
133
- y: o >> 12 & 1023,
134
- z: o & 4095
131
+ return { requests: [...e.entries()].sort((a, n) => n[1] - a[1]).slice(0, t).map(([a]) => ({
132
+ x: a >> 22 & 1023,
133
+ y: a >> 12 & 1023,
134
+ z: a & 4095
135
135
  })), origRequestCount: e.size };
136
136
  }
137
137
  class je {
138
138
  constructor(t) {
139
- M("CLASS INITIALIZING");
140
- const e = t.getContext?.() || t, n = t;
141
- e.domElement && e.getContext ? this.gl = e.getContext() : e.isWebGLRenderer ? this.gl = e.getContext() : this.gl = e, this.renderer = n, (!this.gl || typeof this.gl.getParameter != "function") && (i.debug("Unable to get WebGL context, using mock context"), this.gl = {
142
- getParameter: (o) => ({
139
+ k("CLASS INITIALIZING"), r.debug("VolumeDataManager constructor", { glParam: t, glParamContext: t.getContext?.() });
140
+ const e = t.getContext?.() || t, i = t;
141
+ e.domElement && e.getContext ? this.gl = e.getContext() : e.isWebGLRenderer ? this.gl = e.getContext() : this.gl = e, this.renderer = i, (!this.gl || typeof this.gl.getParameter != "function") && (r.debug("Unable to get WebGL context, using mock context"), this.gl = {
142
+ getParameter: (a) => ({
143
143
  MAX_TEXTURE_SIZE: 4096,
144
144
  MAX_3D_TEXTURE_SIZE: 256,
145
145
  MAX_RENDERBUFFER_SIZE: 4096,
146
146
  MAX_UNIFORM_BUFFER_BINDINGS: 16
147
- })[o] || 0,
147
+ })[a] || 0,
148
+ isContextLost: () => !1,
148
149
  MAX_TEXTURE_SIZE: "MAX_TEXTURE_SIZE",
149
150
  MAX_3D_TEXTURE_SIZE: "MAX_3D_TEXTURE_SIZE",
150
151
  MAX_RENDERBUFFER_SIZE: "MAX_RENDERBUFFER_SIZE",
151
152
  MAX_UNIFORM_BUFFER_BINDINGS: "MAX_UNIFORM_BUFFER_BINDINGS"
152
- }), i.debug("GL CONSTANTS"), i.debug(this.gl), i.debug(this.gl.TEXTURE0), i.debug(this.gl.textures), i.debug("RENDERER"), i.debug(this.renderer), this.deviceLimits = {
153
+ }), this._originalGlParam = t, this._isContextLost = !1, this._contextRestoredCallbacks = [], this.gl && this.gl.canvas && (this.gl.canvas.addEventListener("webglcontextlost", this._handleContextLost.bind(this)), this.gl.canvas.addEventListener("webglcontextrestored", this._handleContextRestored.bind(this))), r.debug("GL CONSTANTS"), r.debug(this.gl), r.debug(this.gl.TEXTURE0), r.debug(this.gl.textures), r.debug("RENDERER"), r.debug(this.renderer), this.deviceLimits = {
153
154
  maxTextureSize: this.gl.getParameter(this.gl.MAX_TEXTURE_SIZE),
154
155
  max3DTextureSize: this.gl.getParameter(this.gl.MAX_3D_TEXTURE_SIZE),
155
156
  maxRenderbufferSize: this.gl.getParameter(this.gl.MAX_RENDERBUFFER_SIZE),
@@ -212,10 +213,51 @@ class je {
212
213
  // l0 z extent
213
214
  zTotal: 0
214
215
  // original z extent plus the l0 z extent times the channel count
215
- }, this.bricksEverLoaded = /* @__PURE__ */ new Set(), this.isBusy = !1, this.BCTimeStamps = new Array(ie).fill(0), this.BCMinMax = new Array(ie).fill([0, 0]), this.BCFull = !1, this.BCUnusedIndex = 0, this.bc2pt = new Array(ie).fill(null), this.LRUStack = [], this.triggerUsage = !0, this.triggerRequest = !1, this.timeStamp = 0, this.k = 40, this.noNewRequests = !1, this.needsBailout = !1, this.initStatus = G.NOT_STARTED, this.initError = null, M("VolumeDataManager constructor complete");
216
+ }, this.bricksEverLoaded = /* @__PURE__ */ new Set(), this.isBusy = !1, this.BCTimeStamps = new Array(ie).fill(0), this.BCMinMax = new Array(ie).fill([0, 0]), this.BCFull = !1, this.BCUnusedIndex = 0, this.bc2pt = new Array(ie).fill(null), this.LRUStack = [], this.triggerUsage = !0, this.triggerRequest = !1, this.timeStamp = 0, this.k = 40, this.noNewRequests = !1, this.needsBailout = !1, this.initStatus = G.NOT_STARTED, this.initError = null, this._lastChannelConfig = null, k("VolumeDataManager constructor complete");
217
+ }
218
+ /**
219
+ * Handle WebGL context loss
220
+ */
221
+ _handleContextLost(t) {
222
+ k("CONTEXT LOST"), r.warn("WebGL context lost, preventing default and setting flag"), t.preventDefault(), this._isContextLost = !0, this.channels && this.channels.zarrMappings && (this._lastChannelConfig = {
223
+ zarrMappings: [...this.channels.zarrMappings],
224
+ colorMappings: [...this.channels.colorMappings],
225
+ downsampleMin: [...this.channels.downsampleMin],
226
+ downsampleMax: [...this.channels.downsampleMax]
227
+ });
228
+ }
229
+ /**
230
+ * Handle WebGL context restoration
231
+ */
232
+ _handleContextRestored(t) {
233
+ if (k("CONTEXT RESTORED"), r.warn("WebGL context restored, reinitializing textures"), this._isContextLost = !1, this._originalGlParam && this._originalGlParam.getContext && (this.gl = this._originalGlParam.getContext()), this._lastChannelConfig && (this.channels.zarrMappings = [...this._lastChannelConfig.zarrMappings], this.channels.colorMappings = [...this._lastChannelConfig.colorMappings], this.channels.downsampleMin = [...this._lastChannelConfig.downsampleMin], this.channels.downsampleMax = [...this._lastChannelConfig.downsampleMax], r.debug("Restored channel configuration after context loss")), this.PT && this.zarrStore && this.zarrStore.brickLayout)
234
+ try {
235
+ this.initMRMCPT(), r.debug("Successfully reinitialized MRMCPT after context restoration");
236
+ } catch (e) {
237
+ r.error("Failed to reinitialize MRMCPT after context restoration:", e);
238
+ }
239
+ this._contextRestoredCallbacks.forEach((e) => {
240
+ try {
241
+ e();
242
+ } catch (i) {
243
+ r.error("Error in context restored callback:", i);
244
+ }
245
+ });
246
+ }
247
+ /**
248
+ * Check if WebGL context is lost
249
+ */
250
+ isContextLost() {
251
+ return this._isContextLost ? !0 : this.gl && typeof this.gl.isContextLost == "function" ? this.gl.isContextLost() : !1;
252
+ }
253
+ /**
254
+ * Register a callback to be called when context is restored
255
+ */
256
+ onContextRestored(t) {
257
+ typeof t == "function" && this._contextRestoredCallbacks.push(t);
216
258
  }
217
259
  initImages(t, e) {
218
- M("INIT IMAGES"), this.images = t, this.imageLayerScopes = e;
260
+ k("INIT IMAGES"), this.images = t, this.imageLayerScopes = e;
219
261
  }
220
262
  /**
221
263
  * Initialize the VolumeDataManager with Zarr store details and device limits
@@ -224,8 +266,8 @@ class je {
224
266
  * @returns {Promise<Object>} Object with Zarr store details and device limits
225
267
  */
226
268
  async init(t) {
227
- if (M("INIT()"), this.initStatus !== G.NOT_STARTED)
228
- return i.debug("VolumeDataManager init() was called more than once!"), this.initStatus === G.COMPLETE ? {
269
+ if (k("INIT()"), this.initStatus !== G.NOT_STARTED)
270
+ return r.debug("VolumeDataManager init() was called more than once!"), this.initStatus === G.COMPLETE ? {
229
271
  success: !0,
230
272
  deviceLimits: this.deviceLimits,
231
273
  zarrStore: this.zarrStore,
@@ -241,27 +283,27 @@ class je {
241
283
  pending: !0,
242
284
  error: "Initialization in progress"
243
285
  };
244
- this.initStatus = G.IN_PROGRESS, M("INIT() IN PROGRESS");
286
+ this.initStatus = G.IN_PROGRESS, k("INIT() IN PROGRESS");
245
287
  try {
246
288
  const e = this.images?.[this.imageLayerScopes?.[0]]?.image?.instance;
247
- if (this.ngffMetadata = e.vivLoader.metadata, i.debug("ngffMetadata", this.ngffMetadata), !e || e.getType() !== "ome-zarr")
289
+ if (this.ngffMetadata = e.vivLoader.metadata, r.debug("ngffMetadata", this.ngffMetadata), !e || e.getType() !== "ome-zarr")
248
290
  throw new Error("Invalid imageWrapper or not an OME-Zarr image");
249
- const n = e.getMultiResolutionStats(), o = Fe(n), r = n.length;
250
- this.zarrStore.resolutions = r;
251
- const a = e.getData();
252
- if (!Array.isArray(a) || a.length < 1)
291
+ const i = e.getMultiResolutionStats(), a = Le(i), n = i.length;
292
+ this.zarrStore.resolutions = n;
293
+ const o = e.getData();
294
+ if (!Array.isArray(o) || o.length < 1)
253
295
  throw new Error("Not a multiresolution loader");
254
- if (!Ce(a[0].labels, ["t", "c", "z", "y", "x"]))
296
+ if (!ye(o[0].labels, ["t", "c", "z", "y", "x"]))
255
297
  throw new Error("Expected OME-Zarr data with dimensions [t, c, z, y, x]");
256
- i.debug("vivData", a);
257
- const c = a.map((s) => s._data), l = new Array(r).fill(null);
258
- if (c.length > 0) {
259
- const s = c[0];
298
+ r.debug("vivData", o);
299
+ const l = o.map((s) => s._data), c = new Array(n).fill(null);
300
+ if (l.length > 0) {
301
+ const s = l[0];
260
302
  if (this.zarrStore = {
261
- resolutions: r,
303
+ resolutions: n,
262
304
  chunkSize: s.chunks,
263
- shapes: o,
264
- arrays: c,
305
+ shapes: a,
306
+ arrays: l,
265
307
  dtype: s.dtype,
266
308
  physicalSizeTotal: [],
267
309
  // Will be populated if metadata exists
@@ -271,14 +313,14 @@ class je {
271
313
  // Calculate from shapes and chunk sizes
272
314
  // store: this.store,
273
315
  // group: this.group,
274
- channelCount: o[0][1],
275
- scales: l
316
+ channelCount: a[0][1],
317
+ scales: c
276
318
  }, this.channels.colorMappings = new Array(Math.min(this.zarrStore.channelCount, 7)).fill(-1), this.channels.zarrMappings = new Array(Math.min(this.zarrStore.channelCount, 7)).fill(void 0), this.channels.downsampleMin = new Array(Math.min(this.zarrStore.channelCount, 7)).fill(void 0), this.channels.downsampleMax = new Array(Math.min(this.zarrStore.channelCount, 7)).fill(void 0), s.meta && s.meta.physicalSizes) {
277
- const { x: d, y: v, z: f } = s.meta.physicalSizes, p = f?.size || 1, _ = v?.size || 1, E = d?.size || 1;
278
- this.zarrStore.physicalSizeVoxel = [p, _, E], s.shape && s.shape.length >= 5 && (this.zarrStore.physicalSizeTotal = [
319
+ const { x: d, y: v, z: h } = s.meta.physicalSizes, p = h?.size || 1, _ = v?.size || 1, y = d?.size || 1;
320
+ this.zarrStore.physicalSizeVoxel = [p, _, y], s.shape && s.shape.length >= 5 && (this.zarrStore.physicalSizeTotal = [
279
321
  (s.shape[2] || 1) * p,
280
322
  (s.shape[3] || 1) * _,
281
- (s.shape[4] || 1) * E
323
+ (s.shape[4] || 1) * y
282
324
  ]);
283
325
  } else
284
326
  this.zarrStore.physicalSizeVoxel = [1, 1, 1], this.zarrStore.physicalSizeTotal = [
@@ -290,41 +332,41 @@ class je {
290
332
  if (!x)
291
333
  throw new Error("Expected multiscales metadata in group.attrs");
292
334
  if (x?.[0]?.datasets?.[0]?.coordinateTransformations) {
293
- for (let d = 0; d < r; d++)
335
+ for (let d = 0; d < n; d++)
294
336
  if (x?.[0]?.datasets?.[d]?.coordinateTransformations?.[0]?.scale) {
295
337
  const { scale: v } = x[0].datasets[d].coordinateTransformations[0];
296
- l[d] = [v[4], v[3], v[2]];
338
+ c[d] = [v[4], v[3], v[2]];
297
339
  }
298
340
  } else {
299
- i.error("no coordinateTransformations available, assuming downsampling ratio of 2 per dimension");
300
- for (let d = 0; d < r; d++) {
341
+ r.error("no coordinateTransformations available, assuming downsampling ratio of 2 per dimension");
342
+ for (let d = 0; d < n; d++) {
301
343
  const v = 2 ** d;
302
- l[d] = [v, v, v];
344
+ c[d] = [v, v, v];
303
345
  }
304
346
  }
305
- this.zarrStore.scales = l;
347
+ this.zarrStore.scales = c;
306
348
  const { coordinateTransformations: m } = this.ngffMetadata;
307
349
  if (m?.[0]?.scale) {
308
350
  const { scale: d } = m[0], v = d.length;
309
351
  if (v >= 3) {
310
- const f = d[v - 3], p = d[v - 2], _ = d[v - 1];
311
- this.zarrStore.physicalSizeVoxel = [f, p, _], s.shape && s.shape.length >= 5 && (this.zarrStore.physicalSizeTotal = [
312
- (s.shape[2] || 1) * f,
352
+ const h = d[v - 3], p = d[v - 2], _ = d[v - 1];
353
+ this.zarrStore.physicalSizeVoxel = [h, p, _], s.shape && s.shape.length >= 5 && (this.zarrStore.physicalSizeTotal = [
354
+ (s.shape[2] || 1) * h,
313
355
  (s.shape[3] || 1) * p,
314
356
  (s.shape[4] || 1) * _
315
357
  ]);
316
358
  }
317
359
  }
318
- this.zarrStore.brickLayout = Le(e.getMultiResolutionStats()), i.debug("config", t);
360
+ this.zarrStore.brickLayout = Fe(e.getMultiResolutionStats()), r.debug("config", t);
319
361
  const { omero: u } = this.ngffMetadata || {};
320
362
  if (!u)
321
363
  throw new Error("Expected omero metadata in ngffMetadata");
322
- i.debug("omero", u), Object.keys(t).forEach((d, v) => {
323
- const f = t[d].spatialTargetC;
324
- this.channels.zarrMappings[v] = f, this.channels.colorMappings[v] = v, this.channels.downsampleMin[v] = u?.channels?.[f]?.window?.min || 0, this.channels.downsampleMax[v] = u?.channels?.[f]?.window?.max || 65535;
325
- }), i.debug("zarrMappings after init", this.channels.zarrMappings), i.debug("colorMappings after init", this.channels.colorMappings), i.debug("downsampleMin after init", this.channels.downsampleMin), i.debug("downsampleMax after init", this.channels.downsampleMax), this.initMRMCPT();
364
+ r.debug("omero", u), Object.keys(t).forEach((d, v) => {
365
+ const h = t[d].spatialTargetC;
366
+ this.channels.zarrMappings[v] = h, this.channels.colorMappings[v] = v, this.channels.downsampleMin[v] = u?.channels?.[h]?.window?.min || 0, this.channels.downsampleMax[v] = u?.channels?.[h]?.window?.max || 65535;
367
+ }), r.debug("zarrMappings after init", this.channels.zarrMappings), r.debug("colorMappings after init", this.channels.colorMappings), r.debug("downsampleMin after init", this.channels.downsampleMin), r.debug("downsampleMax after init", this.channels.downsampleMax), this.initMRMCPT();
326
368
  }
327
- return this.initStatus = G.COMPLETE, M("INIT() COMPLETE"), {
369
+ return this.initStatus = G.COMPLETE, k("INIT() COMPLETE"), {
328
370
  success: !0,
329
371
  deviceLimits: this.deviceLimits,
330
372
  zarrStore: this.zarrStore,
@@ -334,7 +376,7 @@ class je {
334
376
  error: null
335
377
  };
336
378
  } catch (e) {
337
- return M("INIT() FAILED"), i.error("Error initializing VolumeDataManager:", e), this.initStatus = G.FAILED, this.initError = e.message || "Unknown error", {
379
+ return k("INIT() FAILED"), r.error("Error initializing VolumeDataManager:", e), this.initStatus = G.FAILED, this.initError = e.message || "Unknown error", {
338
380
  success: !1,
339
381
  error: this.initError
340
382
  };
@@ -350,9 +392,9 @@ class je {
350
392
  * -
351
393
  */
352
394
  initMRMCPT() {
353
- M("initMRMCPT");
354
- const { PT: t, ptTHREE: e, bcTHREE: n } = Ve(this.zarrStore.brickLayout, this.channels.zarrMappings.length);
355
- this.PT = t, this.ptTHREE = e, this.bcTHREE = n, M("initMRMCPT() COMPLETE");
395
+ k("initMRMCPT");
396
+ const { PT: t, ptTHREE: e, bcTHREE: i } = Ve(this.zarrStore.brickLayout, this.channels.zarrMappings.length);
397
+ this.PT = t, this.ptTHREE = e, this.bcTHREE = i, k("initMRMCPT() COMPLETE");
356
398
  }
357
399
  /*
358
400
  testTexture() {
@@ -367,45 +409,50 @@ class je {
367
409
  await this.handleBrickRequests(t);
368
410
  }
369
411
  updateChannels(t) {
370
- if (M("updateChannels"), i.debug("channelProps", t), i.debug("this.channels.zarrMappings", this.channels.zarrMappings), i.debug("this.channels.colorMappings", this.channels.colorMappings), i.debug("this.channels.downsampleMin", this.channels.downsampleMin), i.debug("this.channels.downsampleMax", this.channels.downsampleMax), this.channels.zarrMappings.length === 0) {
371
- i.debug("channels not initialized yet");
412
+ if (k("updateChannels"), r.debug("channelProps", t), r.debug("this.channels.zarrMappings", this.channels.zarrMappings), r.debug("this.channels.colorMappings", this.channels.colorMappings), r.debug("this.channels.downsampleMin", this.channels.downsampleMin), r.debug("this.channels.downsampleMax", this.channels.downsampleMax), this.channels.zarrMappings.length === 0) {
413
+ r.debug("channels not initialized yet");
372
414
  return;
373
415
  }
374
- const e = Object.values(t).map((c) => c.spatialTargetC).filter((c) => c !== void 0), n = this.channels.zarrMappings.filter((c) => c !== void 0), o = [...new Set(e)].sort((c, l) => c - l), r = [...new Set(n)].sort((c, l) => c - l);
375
- o.length === r.length && o.every((c, l) => c === r[l]) && i.debug("Channel mappings unchanged, skipping update"), i.debug("Channel mappings changed:", {
376
- current: r,
377
- requested: o
378
- }), Object.entries(t).forEach(([c, l]) => {
379
- const s = l.spatialTargetC;
380
- i.debug(`UI channel "${c}" wants zarr channel ${s}`);
416
+ const e = Object.values(t).map((l) => l.spatialTargetC).filter((l) => l !== void 0), i = this.channels.zarrMappings.filter((l) => l !== void 0), a = [...new Set(e)].sort((l, c) => l - c), n = [...new Set(i)].sort((l, c) => l - c);
417
+ a.length === n.length && a.every((l, c) => l === n[c]) && r.debug("Channel mappings unchanged, skipping update"), r.debug("Channel mappings changed:", {
418
+ current: n,
419
+ requested: a
420
+ }), Object.entries(t).forEach(([l, c]) => {
421
+ const s = c.spatialTargetC;
422
+ r.debug(`UI channel "${l}" wants zarr channel ${s}`);
381
423
  const x = this.channels.zarrMappings.indexOf(s);
382
424
  if (x === -1) {
383
425
  const m = this.channels.zarrMappings.findIndex((u) => u === void 0);
384
426
  if (m !== -1)
385
- this.channels.zarrMappings[m] = s, i.debug("channelData", l), i.debug("this.ngffMetadata?.omero?.channels", this.ngffMetadata?.omero?.channels), i.debug("targetZarrChannel", s), this.channels.downsampleMin[m] = this.ngffMetadata?.omero?.channels?.[s]?.window?.min || 0, this.channels.downsampleMax[m] = this.ngffMetadata?.omero?.channels?.[s]?.window?.max || 65535, i.debug(`Mapped zarr channel ${s} to slot ${m}`), i.debug("channels", this.channels);
427
+ this.channels.zarrMappings[m] = s, r.debug("channelData", c), r.debug("this.ngffMetadata?.omero?.channels", this.ngffMetadata?.omero?.channels), r.debug("targetZarrChannel", s), this.channels.downsampleMin[m] = this.ngffMetadata?.omero?.channels?.[s]?.window?.min || 0, this.channels.downsampleMax[m] = this.ngffMetadata?.omero?.channels?.[s]?.window?.max || 65535, r.debug(`Mapped zarr channel ${s} to slot ${m}`), r.debug("channels", this.channels);
386
428
  else {
387
- i.debug("No free slots found, looking for unused mapped channels");
388
- const u = this.channels.zarrMappings.filter((f) => f !== void 0), d = e, v = u.filter((f) => !d.includes(f));
389
- if (i.debug("Currently mapped:", u), i.debug("Still requested:", d), i.debug("Unused mapped channels:", v), v.length > 0) {
390
- const f = this.channels.zarrMappings.findIndex((p) => v.includes(p));
391
- if (f !== -1) {
392
- const p = this.channels.zarrMappings[f];
393
- this.channels.zarrMappings[f] = s, this.channels.downsampleMin[f] = this.ngffMetadata?.omero?.channels?.[s]?.window?.min || 0, this.channels.downsampleMax[f] = this.ngffMetadata?.omero?.channels?.[s]?.window?.max || 65535, i.debug(`Reused slot ${f}: ${p} -> ${s}`), this._purgeChannel(f);
429
+ r.debug("No free slots found, looking for unused mapped channels");
430
+ const u = this.channels.zarrMappings.filter((h) => h !== void 0), d = e, v = u.filter((h) => !d.includes(h));
431
+ if (r.debug("Currently mapped:", u), r.debug("Still requested:", d), r.debug("Unused mapped channels:", v), v.length > 0) {
432
+ const h = this.channels.zarrMappings.findIndex((p) => v.includes(p));
433
+ if (h !== -1) {
434
+ const p = this.channels.zarrMappings[h];
435
+ this.channels.zarrMappings[h] = s, this.channels.downsampleMin[h] = this.ngffMetadata?.omero?.channels?.[s]?.window?.min || 0, this.channels.downsampleMax[h] = this.ngffMetadata?.omero?.channels?.[s]?.window?.max || 65535, r.debug(`Reused slot ${h}: ${p} -> ${s}`), this._purgeChannel(h);
394
436
  } else
395
- i.error("Could not find slot to reuse - this should not happen");
437
+ r.error("Could not find slot to reuse - this should not happen");
396
438
  } else
397
- i.error("All slots are full and all mapped channels are still in use");
439
+ r.error("All slots are full and all mapped channels are still in use");
398
440
  }
399
441
  } else
400
- i.debug(`Zarr channel ${s} already mapped to slot ${x}`);
442
+ r.debug(`Zarr channel ${s} already mapped to slot ${x}`);
401
443
  });
402
- const a = Object.values(t).map((c) => {
403
- const l = this.channels.zarrMappings.indexOf(c.spatialTargetC);
404
- return l !== -1 ? l : -1;
444
+ const o = Object.values(t).map((l) => {
445
+ const c = this.channels.zarrMappings.indexOf(l.spatialTargetC);
446
+ return c !== -1 ? c : -1;
405
447
  });
406
- for (; a.length < 7; )
407
- a.push(-1);
408
- i.debug("newColorMappings", a), this.channels.colorMappings = a, i.debug("updatedChannels", this.channels);
448
+ for (; o.length < 7; )
449
+ o.push(-1);
450
+ r.debug("newColorMappings", o), this.channels.colorMappings = o, r.debug("updatedChannels", this.channels), this._lastChannelConfig = {
451
+ zarrMappings: [...this.channels.zarrMappings],
452
+ colorMappings: [...this.channels.colorMappings],
453
+ downsampleMin: [...this.channels.downsampleMin],
454
+ downsampleMax: [...this.channels.downsampleMax]
455
+ };
409
456
  }
410
457
  /**
411
458
  * Try to load a resolution level
@@ -437,53 +484,53 @@ class je {
437
484
  * @returns {Array} Physical dimensions [X, Y, Z]
438
485
  */
439
486
  getPhysicalDimensionsXYZ() {
440
- i.debug("getPhysicalDimensionsXYZ"), i.debug("this.zarrStore.physicalSizeTotal", this.zarrStore.physicalSizeTotal);
487
+ r.debug("getPhysicalDimensionsXYZ"), r.debug("this.zarrStore.physicalSizeTotal", this.zarrStore.physicalSizeTotal);
441
488
  const t = [
442
489
  this.zarrStore.physicalSizeTotal[2],
443
490
  this.zarrStore.physicalSizeTotal[1],
444
491
  this.zarrStore.physicalSizeTotal[0]
445
492
  ];
446
- return i.debug("out", t), t;
493
+ return r.debug("out", t), t;
447
494
  }
448
495
  /**
449
496
  * Get the maximum resolution
450
497
  * @returns {number} Maximum resolution
451
498
  */
452
499
  getMaxResolutionXYZ() {
453
- i.debug("getMaxResolutionXYZ"), i.debug("this.zarrStore.shapes", this.zarrStore.shapes);
500
+ r.debug("getMaxResolutionXYZ"), r.debug("this.zarrStore.shapes", this.zarrStore.shapes);
454
501
  const t = [
455
502
  this.zarrStore.shapes[0][4],
456
503
  this.zarrStore.shapes[0][3],
457
504
  this.zarrStore.shapes[0][2]
458
505
  ];
459
- return i.debug("out", t), t;
506
+ return r.debug("out", t), t;
460
507
  }
461
508
  getOriginalScaleXYZ() {
462
- M("getOriginalScaleXYZ"), i.debug("this.zarrStore.physicalSizeVoxel", this.zarrStore.physicalSizeVoxel);
509
+ k("getOriginalScaleXYZ"), r.debug("this.zarrStore.physicalSizeVoxel", this.zarrStore.physicalSizeVoxel);
463
510
  const t = [
464
511
  this.zarrStore.physicalSizeVoxel[2],
465
512
  this.zarrStore.physicalSizeVoxel[1],
466
513
  this.zarrStore.physicalSizeVoxel[0]
467
514
  ];
468
- return i.debug("out", t), t;
515
+ return r.debug("out", t), t;
469
516
  }
470
517
  getNormalizedScaleXYZ() {
471
- i.debug("getNormalizedScaleXYZ");
518
+ r.debug("getNormalizedScaleXYZ");
472
519
  const t = [
473
520
  1,
474
521
  this.zarrStore.physicalSizeVoxel[1] / this.zarrStore.physicalSizeVoxel[2],
475
522
  this.zarrStore.physicalSizeVoxel[0] / this.zarrStore.physicalSizeVoxel[0]
476
523
  ];
477
- return i.debug("out", t), t;
524
+ return r.debug("out", t), t;
478
525
  }
479
526
  getBoxDimensionsXYZ() {
480
- i.debug("getBoxDimensionsXYZ"), i.debug("this.zarrStore.shapes", this.zarrStore.shapes);
527
+ r.debug("getBoxDimensionsXYZ"), r.debug("this.zarrStore.shapes", this.zarrStore.shapes);
481
528
  const t = [
482
529
  1,
483
530
  this.zarrStore.shapes[0][3] / this.zarrStore.shapes[0][4],
484
531
  this.zarrStore.shapes[0][2] / this.zarrStore.shapes[0][4]
485
532
  ];
486
- return i.debug("out", t), t;
533
+ return r.debug("out", t), t;
487
534
  }
488
535
  /**
489
536
  * Load a specific Zarr chunk based on [t,c,z,y,x] coordinates
@@ -495,41 +542,49 @@ class je {
495
542
  * @param {number} resolution - Resolution level
496
543
  * @returns {Promise<Uint8Array>} 32x32x32 chunk data
497
544
  */
498
- async loadZarrChunk(t = 0, e = 0, n, o, r, a) {
499
- if (!this.zarrStore || !this.zarrStore.arrays[a])
545
+ async loadZarrChunk(t = 0, e = 0, i, a, n, o) {
546
+ if (!this.zarrStore || !this.zarrStore.arrays[o])
500
547
  throw new Error("Zarr store or resolution not initialized");
501
- const l = await this.zarrStore.arrays[a].getChunk([t, e, n, o, r]);
502
- if (!l)
503
- throw new Error(`No chunk found at coordinates [${t},${e},${n},${o},${r}]`);
504
- if (l.data.length !== T * T * T)
505
- throw new Error(`Unexpected chunk size: ${l.data.length}`);
506
- return l.data;
548
+ const c = await this.zarrStore.arrays[o].getChunk([t, e, i, a, n]);
549
+ if (!c)
550
+ throw new Error(`No chunk found at coordinates [${t},${e},${i},${a},${n}]`);
551
+ if (c.data.length !== E * E * E)
552
+ throw new Error(`Unexpected chunk size: ${c.data.length}`);
553
+ return c.data;
507
554
  }
508
555
  async processRequestData(t) {
509
556
  if (this.isBusy) {
510
- i.debug("processRequestData: already busy, skipping");
557
+ r.debug("processRequestData: already busy, skipping");
558
+ return;
559
+ }
560
+ if (this.isContextLost()) {
561
+ r.debug("processRequestData: WebGL context is lost, skipping");
511
562
  return;
512
563
  }
513
564
  this.isBusy = !0, this.triggerRequest = !1;
514
- const { requests: e, origRequestCount: n } = Xe(t, this.k);
515
- e.length === 0 && (this.noNewRequests = !0), i.debug(`processRequestData: handling ${e.length} requests of ${n}`), await this.handleBrickRequests(e), this.triggerUsage = !0, this.isBusy = !1;
565
+ const { requests: e, origRequestCount: i } = Xe(t, this.k);
566
+ e.length === 0 && (this.noNewRequests = !0), r.debug(`processRequestData: handling ${e.length} requests of ${i}`), await this.handleBrickRequests(e), this.triggerUsage = !0, this.isBusy = !1;
516
567
  }
517
568
  async processUsageData(t) {
518
569
  if (this.isBusy) {
519
- i.debug("processUsageData: already busy, skipping"), this.needsBailout = !0;
570
+ r.debug("processUsageData: already busy, skipping"), this.needsBailout = !0;
571
+ return;
572
+ }
573
+ if (this.isContextLost()) {
574
+ r.debug("processUsageData: WebGL context is lost, skipping");
520
575
  return;
521
576
  }
522
577
  this.isBusy = !0, this.triggerUsage = !1;
523
- const e = ++this.timeStamp, n = /* @__PURE__ */ new Set();
524
- for (let o = 0; o < t.length; o += 4) {
525
- const r = t[o], a = t[o + 1], c = t[o + 2];
526
- if ((r | a | c) === 0)
578
+ const e = ++this.timeStamp, i = /* @__PURE__ */ new Set();
579
+ for (let a = 0; a < t.length; a += 4) {
580
+ const n = t[a], o = t[a + 1], l = t[a + 2];
581
+ if ((n | o | l) === 0)
527
582
  continue;
528
- const l = c * k * O + a * k + r;
529
- l < this.BCTimeStamps.length && n.add(l);
583
+ const c = l * I * O + o * I + n;
584
+ c < this.BCTimeStamps.length && i.add(c);
530
585
  }
531
- Array.from(n).forEach((o) => {
532
- this.BCTimeStamps[o] = e;
586
+ Array.from(i).forEach((a) => {
587
+ this.BCTimeStamps[a] = e;
533
588
  }), this.BCFull && this._buildLRU(), this.triggerRequest = !0, this.isBusy = !1;
534
589
  }
535
590
  // Helper method to update PT entries for evicted bricks
@@ -537,37 +592,45 @@ class je {
537
592
  const e = this.bc2pt[t];
538
593
  if (!e)
539
594
  return;
540
- const [n, o] = this.BCMinMax[t] || [0, 0], r = (0 | 1 << 30 | Math.min(127, n >> 1) << 23 | Math.min(127, o >> 1) << 16) >>> 0;
541
- this._updatePTEntry(e.x, e.y, e.z, r), this.bc2pt[t] = null;
595
+ const [i, a] = this.BCMinMax[t] || [0, 0], n = (0 | 1 << 30 | Math.min(127, i >> 1) << 23 | Math.min(127, a >> 1) << 16) >>> 0;
596
+ this._updatePTEntry(e.x, e.y, e.z, n), this.bc2pt[t] = null;
542
597
  }
543
598
  _purgeChannel(t) {
544
- if (i.debug("purging channel", t), i.debug("corresponding zarr channel", this.channels.zarrMappings[t]), !this.ptTHREE) {
545
- i.error("pagetable texture not initialized");
599
+ if (r.debug("purging channel", t), r.debug("corresponding zarr channel", this.channels.zarrMappings[t]), !this.ptTHREE) {
600
+ r.error("pagetable texture not initialized");
601
+ return;
602
+ }
603
+ if (this.isContextLost()) {
604
+ r.warn("WebGL context is lost, skipping channel purge");
546
605
  return;
547
606
  }
548
607
  this.channels.downsampleMin[t] = void 0, this.channels.downsampleMax[t] = void 0, this.channels.zarrMappings[t] = void 0;
549
608
  const e = this.PT.channelOffsets[t];
550
- i.debug("channelMask", e), i.error("TODO: not tested yet");
551
- const { gl: n } = this, o = this.renderer.properties.get(this.ptTHREE).__webglTexture;
552
- n.activeTexture(n.TEXTURE0), n.bindTexture(n.TEXTURE_3D, o);
553
- for (let r = 0; r < this.zarrStore.resolutions; r++) {
554
- const a = [
555
- this.PT.anchors[r][2] * e[2],
556
- this.PT.anchors[r][1] * e[1],
557
- this.PT.anchors[r][0] * e[0]
609
+ r.debug("channelMask", e), r.error("TODO: not tested yet");
610
+ const { gl: i } = this, a = this.renderer.properties.get(this.ptTHREE).__webglTexture;
611
+ i.activeTexture(i.TEXTURE0), i.bindTexture(i.TEXTURE_3D, a);
612
+ for (let n = 0; n < this.zarrStore.resolutions; n++) {
613
+ const o = [
614
+ this.PT.anchors[n][2] * e[2],
615
+ this.PT.anchors[n][1] * e[1],
616
+ this.PT.anchors[n][0] * e[0]
558
617
  ];
559
- i.debug("anchor", a);
560
- const c = this.zarrStore.brickLayout[r], l = c[0] * c[1] * c[2];
561
- i.debug("extents", c), i.debug("size", l), n.texSubImage3D(n.TEXTURE_3D, 0, a[0], a[1], a[2], c[0], c[1], c[2], n.RED_INTEGER, n.UNSIGNED_INT, new Uint32Array(l));
618
+ r.debug("anchor", o);
619
+ const l = this.zarrStore.brickLayout[n], c = l[0] * l[1] * l[2];
620
+ r.debug("extents", l), r.debug("size", c), i.texSubImage3D(i.TEXTURE_3D, 0, o[0], o[1], o[2], l[0], l[1], l[2], i.RED_INTEGER, i.UNSIGNED_INT, new Uint32Array(c));
562
621
  }
563
- n.bindTexture(n.TEXTURE_3D, null);
622
+ i.bindTexture(i.TEXTURE_3D, null);
564
623
  }
565
624
  // Update a PT entry
566
- _updatePTEntry(t, e, n, o) {
625
+ _updatePTEntry(t, e, i, a) {
567
626
  if (!this.ptTHREE)
568
627
  return;
569
- const { gl: r } = this, a = this.renderer.properties.get(this.ptTHREE).__webglTexture;
570
- r.activeTexture(r.TEXTURE0), r.bindTexture(r.TEXTURE_3D, a), r.texSubImage3D(r.TEXTURE_3D, 0, t, e, n, 1, 1, 1, r.RED_INTEGER, r.UNSIGNED_INT, new Uint32Array([o])), r.bindTexture(r.TEXTURE_3D, null);
628
+ if (this.isContextLost()) {
629
+ r.warn("WebGL context is lost, skipping PT entry update");
630
+ return;
631
+ }
632
+ const { gl: n } = this, o = this.renderer.properties.get(this.ptTHREE).__webglTexture;
633
+ n.activeTexture(n.TEXTURE0), n.bindTexture(n.TEXTURE_3D, o), n.texSubImage3D(n.TEXTURE_3D, 0, t, e, i, 1, 1, 1, n.RED_INTEGER, n.UNSIGNED_INT, new Uint32Array([a])), n.bindTexture(n.TEXTURE_3D, null);
571
634
  }
572
635
  /* ------------------------------------------------------------- *
573
636
  * 2. Allocate the next n free bricks in the brick cache *
@@ -579,17 +642,17 @@ class je {
579
642
  */
580
643
  _allocateBCSlots(t) {
581
644
  let e = [];
582
- const n = k * O * se;
583
- if (!this.BCFull && this.BCUnusedIndex + t > n && (this.BCFull = !0, i.debug("BRICK CACHE FULL")), this.BCFull)
584
- this.LRUStack.length < t && this._buildLRU(), e = this.LRUStack.splice(0, t).map((o) => {
585
- this._evictBrick(o);
586
- const r = Math.floor(o / (k * O)), a = o - r * k * O, c = Math.floor(a / k), l = a % k;
587
- return { bcIndex: o, x: l, y: c, z: r };
645
+ const i = I * O * se;
646
+ if (!this.BCFull && this.BCUnusedIndex + t > i && (this.BCFull = !0, r.debug("BRICK CACHE FULL")), this.BCFull)
647
+ this.LRUStack.length < t && this._buildLRU(), e = this.LRUStack.splice(0, t).map((a) => {
648
+ this._evictBrick(a);
649
+ const n = Math.floor(a / (I * O)), o = a - n * I * O, l = Math.floor(o / I), c = o % I;
650
+ return { bcIndex: a, x: c, y: l, z: n };
588
651
  });
589
652
  else {
590
- for (let o = 0; o < t; ++o) {
591
- const r = (this.BCUnusedIndex + o) % n, a = Math.floor(r / (k * O)), c = r - a * k * O, l = Math.floor(c / k), s = c % k;
592
- e.push({ bcIndex: r, x: s, y: l, z: a });
653
+ for (let a = 0; a < t; ++a) {
654
+ const n = (this.BCUnusedIndex + a) % i, o = Math.floor(n / (I * O)), l = n - o * I * O, c = Math.floor(l / I), s = l % I;
655
+ e.push({ bcIndex: n, x: s, y: c, z: o });
593
656
  }
594
657
  this.BCUnusedIndex += t;
595
658
  }
@@ -599,42 +662,71 @@ class je {
599
662
  * 4. Upload one brick + PT entry *
600
663
  * ------------------------------------------------------------- */
601
664
  async _uploadBrick(t, e) {
665
+ if (r.debug("uploading brick", t, e), this.isContextLost()) {
666
+ r.warn("WebGL context is lost, skipping brick upload");
667
+ return;
668
+ }
602
669
  if (t.x >= this.PT.xExtent || t.y >= this.PT.yExtent || t.z >= this.PT.zTotal || t.x < 0 || t.y < 0 || t.z < 0) {
603
- i.error("this.PT", this.PT), i.error("ptCoord out of bounds", t);
670
+ r.error("this.PT", this.PT), r.error("ptCoord out of bounds", t);
671
+ return;
672
+ }
673
+ const { channel: i, resolution: a, x: n, y: o, z: l } = Ze(t.x, t.y, t.z, { PT_zExtent: this.PT.zExtent, PT_z0Extent: this.PT.z0Extent, PT_anchors: this.PT.anchors });
674
+ if (!this.channels || !this.channels.zarrMappings || this.channels.zarrMappings.length === 0) {
675
+ r.error("Channel mappings not initialized, skipping brick upload");
604
676
  return;
605
677
  }
606
- const { channel: n, resolution: o, x: r, y: a, z: c } = Ze(t.x, t.y, t.z, { PT_zExtent: this.PT.zExtent, PT_z0Extent: this.PT.z0Extent, PT_anchors: this.PT.anchors }), l = this.channels.zarrMappings[n];
607
- if (l === void 0 || l === -1) {
608
- i.error("zarrChannel is undefined or -1", l);
678
+ if (i < 0 || i >= this.channels.zarrMappings.length) {
679
+ r.error("Channel index out of bounds", { channel: i, mappingsLength: this.channels.zarrMappings.length });
609
680
  return;
610
681
  }
611
- i.debug("starting to load zarr chunk", { resolution: o, z: c, y: a, x: r, zarrChannel: l });
612
- let s = await this.loadZarrChunk(0, l, c, a, r, o);
682
+ const c = this.channels.zarrMappings[i];
683
+ if (c === void 0 || c === -1)
684
+ if (r.warn("zarrChannel is undefined or -1", {
685
+ zarrChannel: c,
686
+ channel: i,
687
+ ptCoord: t,
688
+ channelMappings: this.channels.zarrMappings,
689
+ contextLost: this.isContextLost()
690
+ }), this._lastChannelConfig && this._lastChannelConfig.zarrMappings[i] !== void 0) {
691
+ r.warn("Attempting to use last known channel config"), this.channels.zarrMappings = [...this._lastChannelConfig.zarrMappings], this.channels.colorMappings = [...this._lastChannelConfig.colorMappings], this.channels.downsampleMin = [...this._lastChannelConfig.downsampleMin], this.channels.downsampleMax = [...this._lastChannelConfig.downsampleMax];
692
+ const y = this.channels.zarrMappings[i];
693
+ if (y !== void 0 && y !== -1)
694
+ r.debug("Successfully restored channel mapping, continuing with upload");
695
+ else {
696
+ r.error("Could not restore valid channel mapping, aborting brick upload");
697
+ return;
698
+ }
699
+ } else {
700
+ r.error("No fallback channel config available, aborting brick upload");
701
+ return;
702
+ }
703
+ r.debug("starting to load zarr chunk", { resolution: a, z: l, y: o, x: n, zarrChannel: c });
704
+ let s = await this.loadZarrChunk(0, c, l, o, n, a);
613
705
  if (s instanceof Uint16Array) {
614
- if (i.debug("chunk is Uint16Array, converting to Uint8Array"), this.channels.downsampleMin[n] === void 0) {
615
- const y = this.channels.zarrMappings[n];
616
- i.debug("channelId was not found in this.channels.downsampleMin[channel]", y), this.channels.downsampleMin[n] = this.ngffMetadata?.omero?.channels?.[y]?.window?.min || 0, this.channels.downsampleMax[n] = this.ngffMetadata?.omero?.channels?.[y]?.window?.max || 65535, i.debug("this.channels.downsampleMin[channel]", this.channels.downsampleMin[n]), i.debug("this.channels.downsampleMax[channel]", this.channels.downsampleMax[n]);
706
+ if (r.debug("chunk is Uint16Array, converting to Uint8Array"), this.channels.downsampleMin[i] === void 0) {
707
+ const R = this.channels.zarrMappings[i];
708
+ r.debug("channelId was not found in this.channels.downsampleMin[channel]", R), this.channels.downsampleMin[i] = this.ngffMetadata?.omero?.channels?.[R]?.window?.min || 0, this.channels.downsampleMax[i] = this.ngffMetadata?.omero?.channels?.[R]?.window?.max || 65535, r.debug("this.channels.downsampleMin[channel]", this.channels.downsampleMin[i]), r.debug("this.channels.downsampleMax[channel]", this.channels.downsampleMax[i]);
617
709
  }
618
- const E = new Uint8Array(s.length);
619
- for (let y = 0; y < s.length; y++)
620
- E[y] = Math.floor((s[y] - this.channels.downsampleMin[n]) / (this.channels.downsampleMax[n] - this.channels.downsampleMin[n]) * 255);
621
- s = E;
710
+ const y = new Uint8Array(s.length);
711
+ for (let R = 0; R < s.length; R++)
712
+ y[R] = Math.floor((s[R] - this.channels.downsampleMin[i]) / (this.channels.downsampleMax[i] - this.channels.downsampleMin[i]) * 255);
713
+ s = y;
622
714
  }
623
715
  if (!(s instanceof Uint8Array))
624
716
  throw new Error(`Unsupported chunk type: ${s.constructor.name}. Expected Uint8Array.`);
625
717
  let x = 255, m = 0;
626
- for (let E = 0; E < s.length; ++E) {
627
- const y = s[E];
628
- y < x && (x = y), y > m && (m = y);
718
+ for (let y = 0; y < s.length; ++y) {
719
+ const R = s[y];
720
+ R < x && (x = R), R > m && (m = R);
629
721
  }
630
722
  const { gl: u } = this, d = this.renderer.properties.get(this.bcTHREE).__webglTexture;
631
- u.activeTexture(u.TEXTURE2), u.bindTexture(u.TEXTURE_3D, d), u.pixelStorei(u.UNPACK_ALIGNMENT, 1), u.texSubImage3D(u.TEXTURE_3D, 0, e.x * T, e.y * T, e.z * T, T, T, T, u.RED, u.UNSIGNED_BYTE, s), u.pixelStorei(u.UNPACK_ALIGNMENT, 4), u.bindTexture(u.TEXTURE_3D, null);
723
+ u.activeTexture(u.TEXTURE2), u.bindTexture(u.TEXTURE_3D, d), u.pixelStorei(u.UNPACK_ALIGNMENT, 1), u.texSubImage3D(u.TEXTURE_3D, 0, e.x * E, e.y * E, e.z * E, E, E, E, u.RED, u.UNSIGNED_BYTE, s), u.pixelStorei(u.UNPACK_ALIGNMENT, 4), u.bindTexture(u.TEXTURE_3D, null);
632
724
  const v = u.getError();
633
- v !== u.NO_ERROR && i.error("WebGL error during brick upload:", v, s), n >= this.channels.zarrMappings.length && (i.debug("channel is out of bounds", n), x = 255, m = 255);
634
- const f = Ge(x, m, e.x, e.y, e.z), p = this.renderer.properties.get(this.ptTHREE).__webglTexture;
635
- u.activeTexture(u.TEXTURE0), u.bindTexture(u.TEXTURE_3D, p), u.texSubImage3D(u.TEXTURE_3D, 0, t.x, t.y, t.z, 1, 1, 1, u.RED_INTEGER, u.UNSIGNED_INT, new Uint32Array([f])), u.bindTexture(u.TEXTURE_3D, null);
725
+ v !== u.NO_ERROR && r.error("WebGL error during brick upload:", v, s), i >= this.channels.zarrMappings.length && (r.debug("channel is out of bounds", i), x = 255, m = 255);
726
+ const h = Ge(x, m, e.x, e.y, e.z), p = this.renderer.properties.get(this.ptTHREE).__webglTexture;
727
+ u.activeTexture(u.TEXTURE0), u.bindTexture(u.TEXTURE_3D, p), u.texSubImage3D(u.TEXTURE_3D, 0, t.x, t.y, t.z, 1, 1, 1, u.RED_INTEGER, u.UNSIGNED_INT, new Uint32Array([h])), u.bindTexture(u.TEXTURE_3D, null);
636
728
  const _ = u.getError();
637
- _ !== u.NO_ERROR && i.error("WebGL error during pagetable upload:", _, s), this.BCTimeStamps[e.bcIndex] = this.timeStamp, this.BCMinMax[e.bcIndex] = [x, m], this.bc2pt[e.bcIndex] = t;
729
+ _ !== u.NO_ERROR && r.error("WebGL error during pagetable upload:", _, s), this.BCTimeStamps[e.bcIndex] = this.timeStamp, this.BCMinMax[e.bcIndex] = [x, m], this.bc2pt[e.bcIndex] = t;
638
730
  }
639
731
  /* ------------------------------------------------------------- *
640
732
  * 5. Public: handle a batch of PT requests (array of {x,y,z}) *
@@ -643,23 +735,23 @@ class je {
643
735
  if (t.length === 0)
644
736
  return;
645
737
  const e = this._allocateBCSlots(t.length);
646
- i.debug("handleBrickRequests: starting for loop");
647
- for (let n = 0; n < t.length; ++n) {
648
- i.debug("uploading brick", t[n], e[n]), await this._uploadBrick(t[n], e[n]);
649
- const o = this.bricksEverLoaded.size;
650
- if (this.bricksEverLoaded.add(`${t[n].x},${t[n].y},${t[n].z}`), o === this.bricksEverLoaded.size && i.debug("DUPLICATE BRICK LOADED", t[n]), this.needsBailout) {
651
- i.debug("Bailing out of handleBrickRequests early due to needsBailout flag"), this.needsBailout = !1;
738
+ r.debug("Handling brick requests:", { requestCount: t.length, slotCount: e.length }), r.debug("handleBrickRequests: starting for loop");
739
+ for (let i = 0; i < t.length; ++i) {
740
+ r.debug("uploading brick", t[i], e[i]), await this._uploadBrick(t[i], e[i]);
741
+ const a = this.bricksEverLoaded.size;
742
+ if (this.bricksEverLoaded.add(`${t[i].x},${t[i].y},${t[i].z}`), a === this.bricksEverLoaded.size && r.debug("DUPLICATE BRICK LOADED", t[i]), this.needsBailout) {
743
+ r.debug("Bailing out of handleBrickRequests early due to needsBailout flag"), this.needsBailout = !1;
652
744
  break;
653
745
  }
654
746
  }
655
- i.debug("this.bricksEverLoaded", this.bricksEverLoaded);
747
+ r.debug("this.bricksEverLoaded", this.bricksEverLoaded);
656
748
  }
657
749
  /* --------------------------------------------------------- *
658
750
  * Rebuild the LRUStack with the k least-recently-used bricks *
659
751
  * --------------------------------------------------------- */
660
752
  _buildLRU() {
661
- const t = this.BCTimeStamps.map((e, n) => ({ index: n, time: e }));
662
- this.LRUStack = t.sort((e, n) => e.time - n.time).slice(0, this.k).map((e) => e.index);
753
+ const t = this.BCTimeStamps.map((e, i) => ({ index: i, time: e }));
754
+ this.LRUStack = t.sort((e, i) => e.time - i.time).slice(0, this.k).map((e) => e.index);
663
755
  }
664
756
  }
665
757
  const qe = `//
@@ -2270,7 +2362,7 @@ void main(void) {
2270
2362
  }
2271
2363
  `, He = {
2272
2364
  uniforms: {
2273
- u_size: { value: new R(1, 1, 1) },
2365
+ u_size: { value: new C(1, 1, 1) },
2274
2366
  clim0: { value: new b(0.2, 0.8) },
2275
2367
  clim1: { value: new b(0.2, 0.8) },
2276
2368
  clim2: { value: new b(0.2, 0.8) },
@@ -2283,7 +2375,7 @@ void main(void) {
2283
2375
  yClip: { value: new b(0, 1e6) },
2284
2376
  zClip: { value: new b(0, 1e6) },
2285
2377
  u_window_size: { value: new b(1, 1) },
2286
- u_vol_scale: { value: new R(1, 1, 1) },
2378
+ u_vol_scale: { value: new C(1, 1, 1) },
2287
2379
  u_renderstyle: { value: 2 },
2288
2380
  brickCacheTex: { type: "sampler3D", value: null },
2289
2381
  pageTableTex: { type: "usampler3D", value: null },
@@ -2311,38 +2403,38 @@ void main(void) {
2311
2403
  far: { value: 1e4 },
2312
2404
  opacity: { value: 1 },
2313
2405
  volumeCount: { value: 0 },
2314
- boxSize: { value: new R(1, 1, 1) },
2406
+ boxSize: { value: new C(1, 1, 1) },
2315
2407
  renderRes: { value: 1e3 },
2316
- voxelExtents: { value: new R(1, 1, 1) },
2317
- anchor0: { value: new R(0, 0, 0) },
2318
- anchor1: { value: new R(0, 0, 0) },
2319
- anchor2: { value: new R(0, 0, 0) },
2320
- anchor3: { value: new R(0, 0, 0) },
2321
- anchor4: { value: new R(0, 0, 0) },
2322
- anchor5: { value: new R(0, 0, 0) },
2323
- anchor6: { value: new R(0, 0, 0) },
2324
- anchor7: { value: new R(0, 0, 0) },
2325
- anchor8: { value: new R(0, 0, 0) },
2326
- anchor9: { value: new R(0, 0, 0) },
2327
- scale0: { value: new R(1, 1, 1) },
2328
- scale1: { value: new R(2, 2, 2) },
2329
- scale2: { value: new R(4, 4, 4) },
2330
- scale3: { value: new R(8, 8, 8) },
2331
- scale4: { value: new R(16, 16, 16) },
2332
- scale5: { value: new R(32, 32, 32) },
2333
- scale6: { value: new R(64, 64, 64) },
2334
- scale7: { value: new R(128, 128, 128) },
2335
- scale8: { value: new R(256, 256, 256) },
2336
- scale9: { value: new R(512, 512, 512) }
2408
+ voxelExtents: { value: new C(1, 1, 1) },
2409
+ anchor0: { value: new C(0, 0, 0) },
2410
+ anchor1: { value: new C(0, 0, 0) },
2411
+ anchor2: { value: new C(0, 0, 0) },
2412
+ anchor3: { value: new C(0, 0, 0) },
2413
+ anchor4: { value: new C(0, 0, 0) },
2414
+ anchor5: { value: new C(0, 0, 0) },
2415
+ anchor6: { value: new C(0, 0, 0) },
2416
+ anchor7: { value: new C(0, 0, 0) },
2417
+ anchor8: { value: new C(0, 0, 0) },
2418
+ anchor9: { value: new C(0, 0, 0) },
2419
+ scale0: { value: new C(1, 1, 1) },
2420
+ scale1: { value: new C(2, 2, 2) },
2421
+ scale2: { value: new C(4, 4, 4) },
2422
+ scale3: { value: new C(8, 8, 8) },
2423
+ scale4: { value: new C(16, 16, 16) },
2424
+ scale5: { value: new C(32, 32, 32) },
2425
+ scale6: { value: new C(64, 64, 64) },
2426
+ scale7: { value: new C(128, 128, 128) },
2427
+ scale8: { value: new C(256, 256, 256) },
2428
+ scale9: { value: new C(512, 512, 512) }
2337
2429
  },
2338
2430
  vertexShader: qe,
2339
2431
  fragmentShader: Ye
2340
2432
  };
2341
- function U(h) {
2342
- oe(ae.DEBUG) && console.warn(`%cRM: ${h}`, "background: orange; color: white; padding: 2px; border-radius: 3px;");
2433
+ function U(f) {
2434
+ ae(oe.DEBUG) && console.warn(`%cRM: ${f}`, "background: orange; color: white; padding: 2px; border-radius: 3px;");
2343
2435
  }
2344
- function ee(h, t) {
2345
- return h / t[1];
2436
+ function ee(f, t) {
2437
+ return f / t[1];
2346
2438
  }
2347
2439
  class Ke {
2348
2440
  constructor() {
@@ -2361,59 +2453,59 @@ class Ke {
2361
2453
  */
2362
2454
  extractRenderingSettingsFromProps(t) {
2363
2455
  U("Extracting rendering settings from props");
2364
- const { images: e = {}, imageLayerScopes: n = [], imageLayerCoordination: o = [{}], imageChannelScopesByLayer: r = {}, imageChannelCoordination: a = [{}], spatialRenderingMode: c } = t, l = n[0];
2365
- if (!l)
2456
+ const { images: e = {}, imageLayerScopes: i = [], imageLayerCoordination: a = [{}], imageChannelScopesByLayer: n = {}, imageChannelCoordination: o = [{}], spatialRenderingMode: l } = t, c = i[0];
2457
+ if (!c)
2366
2458
  return {
2367
2459
  valid: !1
2368
2460
  };
2369
- const s = r[l], x = o[0][l], m = a[0][l], u = e[l]?.image?.instance?.getData();
2461
+ const s = n[c], x = a[0][c], m = o[0][c], u = e[c]?.image?.instance?.getData();
2370
2462
  if (!u)
2371
2463
  return {
2372
2464
  valid: !1
2373
2465
  };
2374
- if (!m[s?.[0]][I.SPATIAL_CHANNEL_WINDOW])
2466
+ if (!m[s?.[0]][D.SPATIAL_CHANNEL_WINDOW])
2375
2467
  return {
2376
2468
  valid: !1
2377
2469
  };
2378
- const d = e[l].image.instance, v = c === "3D", f = x[I.PHOTOMETRIC_INTERPRETATION] === "RGB", p = x[I.SPATIAL_LAYER_VISIBLE], _ = x[I.SPATIAL_LAYER_OPACITY], E = f ? [
2470
+ const d = e[c].image.instance, v = l === "3D", h = x[D.PHOTOMETRIC_INTERPRETATION] === "RGB", p = x[D.SPATIAL_LAYER_VISIBLE], _ = x[D.SPATIAL_LAYER_OPACITY], y = h ? [
2379
2471
  [255, 0, 0],
2380
2472
  [0, 255, 0],
2381
2473
  [0, 0, 255]
2382
- ] : s.map((S) => m[S][I.SPATIAL_CHANNEL_COLOR]), y = f ? [
2474
+ ] : s.map((S) => m[S][D.SPATIAL_CHANNEL_COLOR]), R = h ? [
2383
2475
  [0, 255],
2384
2476
  [0, 255],
2385
2477
  [0, 255]
2386
- ] : s.map((S) => m[S][I.SPATIAL_CHANNEL_WINDOW] || [0, 255]);
2387
- this.maxRangeSet || (this.maxRange = Math.max(...y.map((S) => S[1])), this.maxRangeSet = !0);
2388
- const Z = f ? [
2478
+ ] : s.map((S) => m[S][D.SPATIAL_CHANNEL_WINDOW] || [0, 255]);
2479
+ this.maxRangeSet || (this.maxRange = Math.max(...R.map((S) => S[1])), this.maxRangeSet = !0);
2480
+ const Z = h ? [
2389
2481
  p && !0,
2390
2482
  p && !0,
2391
2483
  p && !0
2392
- ] : s.map((S) => p && m[S][I.SPATIAL_CHANNEL_VISIBLE]), $ = f ? [
2484
+ ] : s.map((S) => p && m[S][D.SPATIAL_CHANNEL_VISIBLE]), W = h ? [
2393
2485
  p && !0,
2394
2486
  p && !0,
2395
2487
  p && !0
2396
- ] : s.map((S) => p && d.getChannelIndex(m[S][I.SPATIAL_TARGET_C])), X = f ? [
2488
+ ] : s.map((S) => p && d.getChannelIndex(m[S][D.SPATIAL_TARGET_C])), X = h ? [
2397
2489
  p && null,
2398
2490
  p && null,
2399
2491
  p && null
2400
- ] : s.map((S) => m[S][I.SPATIAL_MAX_RESOLUTION]);
2401
- let A = x[I.SPATIAL_SLICE_X], P = x[I.SPATIAL_SLICE_Y], N = x[I.SPATIAL_SLICE_Z];
2402
- A = A !== null ? A : new b(-1, 1e5), P = P !== null ? P : new b(-1, 1e5), N = N !== null ? N : new b(-1, 1e5);
2403
- const j = e[l].image.loaders[0].channels;
2492
+ ] : s.map((S) => m[S][D.SPATIAL_MAX_RESOLUTION]);
2493
+ let P = x[D.SPATIAL_SLICE_X], A = x[D.SPATIAL_SLICE_Y], N = x[D.SPATIAL_SLICE_Z];
2494
+ P = P !== null ? P : new b(-1, 1e5), A = A !== null ? A : new b(-1, 1e5), N = N !== null ? N : new b(-1, 1e5);
2495
+ const j = e[c].image.loaders[0].channels;
2404
2496
  return {
2405
2497
  valid: !0,
2406
2498
  channelsVisible: Z,
2407
2499
  allChannels: j,
2408
- channelTargetC: $,
2500
+ channelTargetC: W,
2409
2501
  channelMaxResolutionIndex: X,
2410
2502
  data: u,
2411
- colors: E,
2412
- contrastLimits: y,
2503
+ colors: y,
2504
+ contrastLimits: R,
2413
2505
  is3dMode: v,
2414
2506
  layerTransparency: _,
2415
- xSlice: A,
2416
- ySlice: P,
2507
+ xSlice: P,
2508
+ ySlice: A,
2417
2509
  zSlice: N
2418
2510
  };
2419
2511
  }
@@ -2432,39 +2524,39 @@ class Ke {
2432
2524
  * @param {object} volumeDataManagerProps - Params derived from the volume data manager
2433
2525
  * @returns {Object|null} Updated rendering settings or null if rendering is not possible
2434
2526
  */
2435
- updateRendering({ zarrStoreShapes: t, originalScaleXYZ: e, physicalDimensionsXYZ: n, maxResolutionXYZ: o, boxDimensionsXYZ: r, normalizedScaleXYZ: a, bcTHREE: c, ptTHREE: l }) {
2436
- if (U("Updating rendering"), this.channelTargetC.findIndex((v, f) => this.channelsVisible[f]), !Array.isArray(t) || t.length === 0)
2527
+ updateRendering({ zarrStoreShapes: t, originalScaleXYZ: e, physicalDimensionsXYZ: i, maxResolutionXYZ: a, boxDimensionsXYZ: n, normalizedScaleXYZ: o, bcTHREE: l, ptTHREE: c }) {
2528
+ if (U("Updating rendering"), this.channelTargetC.findIndex((v, h) => this.channelsVisible[h]), !Array.isArray(t) || t.length === 0)
2437
2529
  return null;
2438
2530
  const s = t[0], x = {
2439
2531
  xLength: s[4] || 1,
2440
2532
  yLength: s[3] || 1,
2441
2533
  zLength: s[2] || 1
2442
2534
  }, m = [], u = [], d = [];
2443
- if (this.channelTargetC.forEach((v, f) => {
2444
- this.channelsVisible[f];
2535
+ if (this.channelTargetC.forEach((v, h) => {
2536
+ this.channelsVisible[h];
2445
2537
  {
2446
2538
  const _ = [0, this.maxRange ? this.maxRange : 255];
2447
2539
  u.push([
2448
- this.colors[f][0] / 255,
2449
- this.colors[f][1] / 255,
2450
- this.colors[f][2] / 255,
2451
- this.channelsVisible[f] ? 1 : 0
2452
- ]), i.debug("colorsSave", u), this.contrastLimits[f][0] === 0 && this.contrastLimits[f][1] === 255 ? d.push([
2540
+ this.colors[h][0] / 255,
2541
+ this.colors[h][1] / 255,
2542
+ this.colors[h][2] / 255,
2543
+ this.channelsVisible[h] ? 1 : 0
2544
+ ]), r.debug("colorsSave", u), this.contrastLimits[h][0] === 0 && this.contrastLimits[h][1] === 255 ? d.push([
2453
2545
  ee(_[0], _),
2454
2546
  ee(_[1], _)
2455
2547
  ]) : d.push([
2456
- ee(this.contrastLimits[f][0], _),
2457
- ee(this.contrastLimits[f][1], _)
2548
+ ee(this.contrastLimits[h][0], _),
2549
+ ee(this.contrastLimits[h][1], _)
2458
2550
  ]);
2459
2551
  }
2460
2552
  }), !this.zarrInit) {
2461
- this.originalScale = e, this.physicalDimensions = n, this.maxResolution = o;
2462
- const v = r;
2463
- this.normalizedScale = a, this.meshScale = [
2553
+ this.originalScale = e, this.physicalDimensions = i, this.maxResolution = a;
2554
+ const v = n;
2555
+ this.normalizedScale = o, this.meshScale = [
2464
2556
  this.originalScale[0] / this.originalScale[0],
2465
2557
  this.originalScale[1] / this.originalScale[0],
2466
2558
  this.originalScale[2] / this.originalScale[0]
2467
- ], this.geometrySize = v, this.boxSize = v, i.debug("this.boxSize", this.boxSize), i.debug("this.geometrySize", this.geometrySize), i.debug("this.meshScale", this.meshScale), i.debug("this.originalScale", this.originalScale), i.debug("this.physicalDimensions", this.physicalDimensions), i.debug("this.maxResolution", this.maxResolution), i.debug("scaledResolution", v), this.zarrInit = !0;
2559
+ ], this.geometrySize = v, this.boxSize = v, r.debug("this.boxSize", this.boxSize), r.debug("this.geometrySize", this.geometrySize), r.debug("this.meshScale", this.meshScale), r.debug("this.originalScale", this.originalScale), r.debug("this.physicalDimensions", this.physicalDimensions), r.debug("this.maxResolution", this.maxResolution), r.debug("scaledResolution", v), this.zarrInit = !0;
2468
2560
  }
2469
2561
  return this.updateUniforms(
2470
2562
  m,
@@ -2477,8 +2569,8 @@ class Ke {
2477
2569
  this.xSlice,
2478
2570
  this.ySlice,
2479
2571
  this.zSlice,
2480
- c,
2481
- l
2572
+ l,
2573
+ c
2482
2574
  ), {
2483
2575
  uniforms: this.uniforms,
2484
2576
  shader: this.shader,
@@ -2499,8 +2591,8 @@ class Ke {
2499
2591
  * @param {Vector2} ySlice - Y clipping plane
2500
2592
  * @param {Vector2} zSlice - Z clipping plane
2501
2593
  */
2502
- updateUniforms(t, e, n, o, r, a, c, l, s, x, m) {
2503
- U("Updating uniforms"), this.uniforms.boxSize.value.set(this.boxSize[0], this.boxSize[1], this.boxSize[2]), this.uniforms.brickCacheTex.value = x, this.uniforms.pageTableTex.value = m, this.uniforms.near.value = 0.1, this.uniforms.far.value = 3e3, this.uniforms.opacity.value = a, this.uniforms.volumeCount.value = t.length, this.uniforms.u_size.value.set(e.xLength, e.yLength, e.zLength), this.uniforms.u_window_size.value.set(0, 0), this.uniforms.u_vol_scale.value.set(1 / e.xLength, 1 / e.yLength, 1 / e.zLength * 2), this.uniforms.clim0.value.set(o.length > 0 ? o[0][0] : null, o.length > 0 ? o[0][1] : null), this.uniforms.clim1.value.set(o.length > 1 ? o[1][0] : null, o.length > 1 ? o[1][1] : null), this.uniforms.clim2.value.set(o.length > 2 ? o[2][0] : null, o.length > 2 ? o[2][1] : null), this.uniforms.clim3.value.set(o.length > 3 ? o[3][0] : null, o.length > 3 ? o[3][1] : null), this.uniforms.clim4.value.set(o.length > 4 ? o[4][0] : null, o.length > 4 ? o[4][1] : null), this.uniforms.clim5.value.set(o.length > 5 ? o[5][0] : null, o.length > 5 ? o[5][1] : null), this.uniforms.clim6.value.set(o.length > 6 ? o[6][0] : null, o.length > 6 ? o[6][1] : null), this.uniforms.xClip.value.set(c[0] * (1 / this.maxResolution[0]) * this.boxSize[0], c[1] * (1 / this.maxResolution[0]) * this.boxSize[0]), this.uniforms.yClip.value.set(l[0] * (1 / this.maxResolution[1]) * this.boxSize[1], l[1] * (1 / this.maxResolution[1]) * this.boxSize[1]), this.uniforms.zClip.value.set(s[0] * (1 / this.maxResolution[2]) * this.boxSize[2], s[1] * (1 / this.maxResolution[2]) * this.boxSize[2]), this.uniforms.color0.value.set(r.length > 0 ? r[0][0] : null, r.length > 0 ? r[0][1] : null, r.length > 0 ? r[0][2] : null, r.length > 0 ? r[0][3] : null), this.uniforms.color1.value.set(r.length > 1 ? r[1][0] : null, r.length > 1 ? r[1][1] : null, r.length > 1 ? r[1][2] : null, r.length > 1 ? r[1][3] : null), this.uniforms.color2.value.set(r.length > 2 ? r[2][0] : null, r.length > 2 ? r[2][1] : null, r.length > 2 ? r[2][2] : null, r.length > 2 ? r[2][3] : null), this.uniforms.color3.value.set(r.length > 3 ? r[3][0] : null, r.length > 3 ? r[3][1] : null, r.length > 3 ? r[3][2] : null, r.length > 3 ? r[3][3] : null), this.uniforms.color4.value.set(r.length > 4 ? r[4][0] : null, r.length > 4 ? r[4][1] : null, r.length > 4 ? r[4][2] : null, r.length > 4 ? r[4][3] : null), this.uniforms.color5.value.set(r.length > 5 ? r[5][0] : null, r.length > 5 ? r[5][1] : null, r.length > 5 ? r[5][2] : null, r.length > 5 ? r[5][3] : null), this.uniforms.color6.value.set(r.length > 6 ? r[6][0] : null, r.length > 6 ? r[6][1] : null, r.length > 6 ? r[6][2] : null, r.length > 6 ? r[6][3] : null);
2594
+ updateUniforms(t, e, i, a, n, o, l, c, s, x, m) {
2595
+ U("Updating uniforms"), this.uniforms.boxSize.value.set(this.boxSize[0], this.boxSize[1], this.boxSize[2]), this.uniforms.brickCacheTex.value = x, this.uniforms.pageTableTex.value = m, this.uniforms.near.value = 0.1, this.uniforms.far.value = 3e3, this.uniforms.opacity.value = o, this.uniforms.volumeCount.value = t.length, this.uniforms.u_size.value.set(e.xLength, e.yLength, e.zLength), this.uniforms.u_window_size.value.set(0, 0), this.uniforms.u_vol_scale.value.set(1 / e.xLength, 1 / e.yLength, 1 / e.zLength * 2), this.uniforms.clim0.value.set(a.length > 0 ? a[0][0] : null, a.length > 0 ? a[0][1] : null), this.uniforms.clim1.value.set(a.length > 1 ? a[1][0] : null, a.length > 1 ? a[1][1] : null), this.uniforms.clim2.value.set(a.length > 2 ? a[2][0] : null, a.length > 2 ? a[2][1] : null), this.uniforms.clim3.value.set(a.length > 3 ? a[3][0] : null, a.length > 3 ? a[3][1] : null), this.uniforms.clim4.value.set(a.length > 4 ? a[4][0] : null, a.length > 4 ? a[4][1] : null), this.uniforms.clim5.value.set(a.length > 5 ? a[5][0] : null, a.length > 5 ? a[5][1] : null), this.uniforms.clim6.value.set(a.length > 6 ? a[6][0] : null, a.length > 6 ? a[6][1] : null), this.uniforms.xClip.value.set(l[0] * (1 / this.maxResolution[0]) * this.boxSize[0], l[1] * (1 / this.maxResolution[0]) * this.boxSize[0]), this.uniforms.yClip.value.set(c[0] * (1 / this.maxResolution[1]) * this.boxSize[1], c[1] * (1 / this.maxResolution[1]) * this.boxSize[1]), this.uniforms.zClip.value.set(s[0] * (1 / this.maxResolution[2]) * this.boxSize[2], s[1] * (1 / this.maxResolution[2]) * this.boxSize[2]), this.uniforms.color0.value.set(n.length > 0 ? n[0][0] : null, n.length > 0 ? n[0][1] : null, n.length > 0 ? n[0][2] : null, n.length > 0 ? n[0][3] : null), this.uniforms.color1.value.set(n.length > 1 ? n[1][0] : null, n.length > 1 ? n[1][1] : null, n.length > 1 ? n[1][2] : null, n.length > 1 ? n[1][3] : null), this.uniforms.color2.value.set(n.length > 2 ? n[2][0] : null, n.length > 2 ? n[2][1] : null, n.length > 2 ? n[2][2] : null, n.length > 2 ? n[2][3] : null), this.uniforms.color3.value.set(n.length > 3 ? n[3][0] : null, n.length > 3 ? n[3][1] : null, n.length > 3 ? n[3][2] : null, n.length > 3 ? n[3][3] : null), this.uniforms.color4.value.set(n.length > 4 ? n[4][0] : null, n.length > 4 ? n[4][1] : null, n.length > 4 ? n[4][2] : null, n.length > 4 ? n[4][3] : null), this.uniforms.color5.value.set(n.length > 5 ? n[5][0] : null, n.length > 5 ? n[5][1] : null, n.length > 5 ? n[5][2] : null, n.length > 5 ? n[5][3] : null), this.uniforms.color6.value.set(n.length > 6 ? n[6][0] : null, n.length > 6 ? n[6][1] : null, n.length > 6 ? n[6][2] : null, n.length > 6 ? n[6][3] : null);
2504
2596
  for (let u = 0; u < 7; u++)
2505
2597
  typeof this.channelMaxResolutionIndex[u] == "number" && this.uniforms[`res${u}`].value.set(Math.max(1, this.channelMaxResolutionIndex[u]), this.zarrStoreNumResolutions - 1);
2506
2598
  }
@@ -2515,31 +2607,31 @@ class Ke {
2515
2607
  }
2516
2608
  */
2517
2609
  setChannelMapping(t) {
2518
- U("setting channel mapping"), i.debug("channelMapping", t), this.uniforms.channelMapping.value = t;
2610
+ U("setting channel mapping"), r.debug("channelMapping", t), this.uniforms.channelMapping.value = t;
2519
2611
  }
2520
2612
  // Only called on initialization of the
2521
2613
  // VolumeDataManager and VolumeRenderManager for a particular image.
2522
2614
  setZarrUniforms(t, e) {
2523
- U("setting zarr uniforms"), i.debug("zarrStore", t), i.debug("PT", e);
2524
- for (let n = 0; n <= 9; n++)
2525
- e.anchors && e.anchors[n] ? this.uniforms[`anchor${n}`].value.set(e.anchors[n][0] || 0, e.anchors[n][1] || 0, e.anchors[n][2] || 0) : (i.debug("anchor", n, "does not exist"), this.uniforms[`anchor${n}`].value.set(0, 0, 0)), t.scales && t.scales[n] ? this.uniforms[`scale${n}`].value.set(t.scales[n][0] || 1, t.scales[n][1] || 1, t.scales[n][2] || 1) : i.debug("scale", n, "does not exist");
2526
- i.debug("zarrStore.brickLayout", t.brickLayout), this.zarrStoreNumResolutions = t.brickLayout.length;
2527
- for (let n = 0; n < 7; n++)
2528
- this.uniforms[`res${n}`].value.set(
2615
+ U("setting zarr uniforms"), r.debug("zarrStore", t), r.debug("PT", e);
2616
+ for (let i = 0; i <= 9; i++)
2617
+ e.anchors && e.anchors[i] ? this.uniforms[`anchor${i}`].value.set(e.anchors[i][0] || 0, e.anchors[i][1] || 0, e.anchors[i][2] || 0) : (r.debug("anchor", i, "does not exist"), this.uniforms[`anchor${i}`].value.set(0, 0, 0)), t.scales && t.scales[i] ? this.uniforms[`scale${i}`].value.set(t.scales[i][0] || 1, t.scales[i][1] || 1, t.scales[i][2] || 1) : r.debug("scale", i, "does not exist");
2618
+ r.debug("zarrStore.brickLayout", t.brickLayout), this.zarrStoreNumResolutions = t.brickLayout.length;
2619
+ for (let i = 0; i < 7; i++)
2620
+ this.uniforms[`res${i}`].value.set(
2529
2621
  // TODO(mark) make this dependent on the per-channel maxResolution slider value.
2530
2622
  1,
2531
2623
  t.brickLayout.length - 1
2532
2624
  );
2533
- this.uniforms.resGlobal.value.set(1, t.brickLayout.length - 1), this.uniforms.voxelExtents.value.set(t.shapes[0][4], t.shapes[0][3], t.shapes[0][2]), this.uniforms.maxChannels.value = Math.min(t.channelCount, 7), i.debug("this.channelsVisible", this.channelsVisible), i.debug("zarrStore.shapes[0]", t.shapes[0]), i.debug("PT", e), i.debug("uniforms", this.uniforms);
2625
+ this.uniforms.resGlobal.value.set(1, t.brickLayout.length - 1), this.uniforms.voxelExtents.value.set(t.shapes[0][4], t.shapes[0][3], t.shapes[0][2]), this.uniforms.maxChannels.value = Math.min(t.channelCount, 7), r.debug("this.channelsVisible", this.channelsVisible), r.debug("zarrStore.shapes[0]", t.shapes[0]), r.debug("PT", e), r.debug("uniforms", this.uniforms);
2534
2626
  }
2535
2627
  }
2536
- const $e = `//
2628
+ const We = `//
2537
2629
  varying vec2 vUv;
2538
2630
  void main() {
2539
2631
  vUv = uv;
2540
2632
  gl_Position = vec4(position, 1.0);
2541
2633
  }
2542
- `, We = `//
2634
+ `, $e = `//
2543
2635
  // Input texture to blur
2544
2636
  uniform sampler2D tDiffuse;
2545
2637
  // Resolution of the texture (width, height)
@@ -2725,73 +2817,73 @@ void main() {
2725
2817
  gl_FragColor = color;
2726
2818
  }
2727
2819
  `;
2728
- function ge(h, t) {
2729
- const e = h.properties?.get(t);
2820
+ function ge(f, t) {
2821
+ const e = f.properties?.get(t);
2730
2822
  return e?.framebuffer || e?.__webglFramebuffer || t.__webglFramebuffer;
2731
2823
  }
2732
- function K(h) {
2733
- oe(ae.DEBUG) && console.warn(`%cV: ${h}`, "background: deeppink; color: white; padding: 2px; border-radius: 3px;");
2824
+ function K(f) {
2825
+ ae(oe.DEBUG) && console.warn(`%cV: ${f}`, "background: deeppink; color: white; padding: 2px; border-radius: 3px;");
2734
2826
  }
2735
- function Qe(h, t, e, { mrtRef: n }) {
2736
- h.setRenderTarget(n.current), h.clear(!0, !0, !0), h.render(e, t);
2827
+ function Qe(f, t, e, { mrtRef: i }) {
2828
+ f.setRenderTarget(i.current), f.clear(!0, !0, !0), f.render(e, t);
2737
2829
  }
2738
- function Je(h, { screenSceneRef: t, screenCameraRef: e }) {
2739
- h.setRenderTarget(null), h.clear(!0, !0, !0), h.render(t.current, e.current);
2830
+ function Je(f, { screenSceneRef: t, screenCameraRef: e }) {
2831
+ f.setRenderTarget(null), f.clear(!0, !0, !0), f.render(t.current, e.current);
2740
2832
  }
2741
- function et(h, { frameRef: t, dataManager: e, mrtRef: n, bufRequest: o, bufUsage: r }) {
2742
- const a = h.getContext(), c = t.current;
2743
- e.noNewRequests === !0 && c % 100 === 0 && c < 500 && (e.noNewRequests = !1), e.triggerRequest === !0 && e.noNewRequests === !1 ? (a.bindFramebuffer(a.READ_FRAMEBUFFER, ge(h, n.current)), a.readBuffer(a.COLOR_ATTACHMENT1), a.readPixels(0, 0, n.current.width, n.current.height, a.RGBA, a.UNSIGNED_BYTE, o.current), e.processRequestData(o.current)) : e.triggerUsage === !0 && e.noNewRequests === !1 && (a.bindFramebuffer(a.READ_FRAMEBUFFER, ge(h, n.current)), a.readBuffer(a.COLOR_ATTACHMENT2), a.readPixels(0, 0, n.current.width, n.current.height, a.RGBA, a.UNSIGNED_BYTE, r.current), e.processUsageData(r.current));
2833
+ function et(f, { frameRef: t, dataManager: e, mrtRef: i, bufRequest: a, bufUsage: n }) {
2834
+ const o = f.getContext(), l = t.current;
2835
+ e.noNewRequests === !0 && l % 100 === 0 && l < 500 && (e.noNewRequests = !1), e.triggerRequest === !0 && e.noNewRequests === !1 ? (o.bindFramebuffer(o.READ_FRAMEBUFFER, ge(f, i.current)), o.readBuffer(o.COLOR_ATTACHMENT1), o.readPixels(0, 0, i.current.width, i.current.height, o.RGBA, o.UNSIGNED_BYTE, a.current), e.processRequestData(a.current)) : e.triggerUsage === !0 && e.noNewRequests === !1 && (o.bindFramebuffer(o.READ_FRAMEBUFFER, ge(f, i.current)), o.readBuffer(o.COLOR_ATTACHMENT2), o.readPixels(0, 0, i.current.width, i.current.height, o.RGBA, o.UNSIGNED_BYTE, n.current), e.processUsageData(n.current));
2744
2836
  }
2745
- function tt(h, t) {
2746
- const { invalidate: e, isInteracting: n, dataManager: o, spatialRenderingModeChanging: r, meshRef: a, stillRef: c, screenQuadRef: l, lastSampleRef: s, frameRef: x, lastFrameCountRef: m } = t;
2747
- if (l.current && (c.current ? l.current.material.uniforms.gaussian.value = 0 : l.current.material.uniforms.gaussian.value = 7), n) {
2748
- o.noNewRequests = !1, o.triggerUsage = !0;
2837
+ function tt(f, t) {
2838
+ const { invalidate: e, isInteracting: i, dataManager: a, spatialRenderingModeChanging: n, meshRef: o, stillRef: l, screenQuadRef: c, lastSampleRef: s, frameRef: x, lastFrameCountRef: m } = t;
2839
+ if (c.current && (l.current ? c.current.material.uniforms.gaussian.value = 0 : c.current.material.uniforms.gaussian.value = 7), i) {
2840
+ a.noNewRequests = !1, a.triggerUsage = !0;
2749
2841
  return;
2750
2842
  }
2751
- if (r)
2843
+ if (n)
2752
2844
  return;
2753
- const u = a.current?.material?.uniforms, d = u?.renderRes?.value ?? o?.PT?.lowestDataRes;
2754
- if (o.noNewRequests) {
2755
- d !== 0 ? (u && (u.renderRes.value = 0), i.debug("Adaptive Quality: No new requests. Setting renderSpeed to 0 (best quality)."), c.current = !1, l.current.material.uniforms.gaussian.value = 7, e()) : c.current || (i.debug("Adaptive Quality: No new requests and already at best quality. Setting stillRef to true."), c.current = !0, l.current.material.uniforms.gaussian.value = 0);
2845
+ const u = o.current?.material?.uniforms, d = u?.renderRes?.value ?? a?.PT?.lowestDataRes;
2846
+ if (a.noNewRequests) {
2847
+ d !== 0 ? (u && (u.renderRes.value = 0), r.debug("Adaptive Quality: No new requests. Setting renderSpeed to 0 (best quality)."), l.current = !1, c.current.material.uniforms.gaussian.value = 7, e()) : l.current || (r.debug("Adaptive Quality: No new requests and already at best quality. Setting stillRef to true."), l.current = !0, c.current.material.uniforms.gaussian.value = 0);
2756
2848
  return;
2757
2849
  }
2758
- c.current && (c.current = !1, e());
2759
- const v = h.getElapsedTime();
2850
+ l.current && (l.current = !1, e());
2851
+ const v = f.getElapsedTime();
2760
2852
  if (v - s.current < 1)
2761
2853
  return;
2762
- const f = v - s.current, p = x.current - m.current;
2854
+ const h = v - s.current, p = x.current - m.current;
2763
2855
  let _ = 0;
2764
- f > 0 && (_ = p / f), s.current = v, m.current = x.current;
2765
- const E = _ > 100 && d > 0, y = _ < 30 && d < o.PT.lowestDataRes;
2766
- if (E || y) {
2767
- const Z = d + (y ? 1 : -1);
2856
+ h > 0 && (_ = p / h), s.current = v, m.current = x.current;
2857
+ const y = _ > 100 && d > 0, R = _ < 30 && d < a.PT.lowestDataRes;
2858
+ if (y || R) {
2859
+ const Z = d + (R ? 1 : -1);
2768
2860
  u && (u.renderRes.value = Z), e();
2769
2861
  }
2770
2862
  }
2771
- function rt(h) {
2863
+ function nt(f) {
2772
2864
  const {
2773
2865
  images: t,
2774
2866
  imageLayerScopes: e,
2775
- imageLayerCoordination: n,
2776
- imageChannelScopesByLayer: o,
2777
- imageChannelCoordination: r,
2867
+ imageLayerCoordination: i,
2868
+ imageChannelScopesByLayer: a,
2869
+ imageChannelCoordination: n,
2778
2870
  // onInitComplete,
2779
- spatialRenderingMode: a,
2780
- spatialRenderingModeChanging: c
2781
- } = h, {
2782
- gl: l
2871
+ spatialRenderingMode: o,
2872
+ spatialRenderingModeChanging: l
2873
+ } = f, {
2874
+ gl: c
2783
2875
  // scene,
2784
2876
  // camera
2785
- } = fe(), s = fe((C) => C.invalidate), x = z(null), m = z(null), u = z(null), d = z(null), v = z(null), [f, p] = ne({
2877
+ } = fe(), s = fe((T) => T.invalidate), x = z(null), m = z(null), u = z(null), d = z(null), v = z(null), [h, p] = re({
2786
2878
  uniforms: null,
2787
2879
  shader: null,
2788
2880
  meshScale: [1, 1, 1],
2789
2881
  geometrySize: [1, 1, 1]
2790
- }), [_, E] = ne(!1), y = z(null), Z = z(null), $ = z(null), [X, A] = ne(!1), P = z(null), N = z(!1), j = z(0), S = z(0), be = z(0), g = ue(() => new je(l), [l]), w = ue(() => new Ke(), []);
2882
+ }), [_, y] = re(!1), R = z(null), Z = z(null), W = z(null), [X, P] = re(!1), A = z(null), N = z(!1), j = z(0), S = z(0), be = z(0), g = ue(() => new je(c), [c]), w = ue(() => new Ke(), []);
2791
2883
  H(() => {
2792
2884
  K("useEffect MRT target matching canvas");
2793
- const { width: C, height: F } = l.domElement, L = new ze(C, F, 3);
2794
- L.texture.forEach((Y) => {
2885
+ const { width: T, height: L } = c.domElement, F = new ze(T, L, 3);
2886
+ F.texture.forEach((Y) => {
2795
2887
  Y.format = ke, Y.type = pe, Y.minFilter = te, Y.magFilter = te, Y.generateMipmaps = !1;
2796
2888
  });
2797
2889
  const B = new Ie(), Q = new De(-1, 1, 1, -1, 0.1, 10);
@@ -2799,35 +2891,35 @@ function rt(h) {
2799
2891
  const J = new Me({
2800
2892
  uniforms: {
2801
2893
  // Bind the first render target texture as the input of the gaussian blur shader.
2802
- tDiffuse: { value: L.texture[0] },
2803
- resolution: { value: new b(C, F) },
2894
+ tDiffuse: { value: F.texture[0] },
2895
+ resolution: { value: new b(T, L) },
2804
2896
  gaussian: { value: 7 }
2805
2897
  },
2806
- vertexShader: $e,
2807
- fragmentShader: We,
2898
+ vertexShader: We,
2899
+ fragmentShader: $e,
2808
2900
  transparent: !0
2809
- }), q = new Ae(new Pe(2, 2), J);
2810
- return B.add(q), y.current = B, Z.current = Q, $.current = q, u.current = new Uint8Array(C * F * 4), d.current = new Uint8Array(C * F * 4), v.current = L, () => {
2811
- L.dispose(), J.dispose(), q.geometry.dispose();
2901
+ }), q = new Pe(new Ae(2, 2), J);
2902
+ return B.add(q), R.current = B, Z.current = Q, W.current = q, u.current = new Uint8Array(T * L * 4), d.current = new Uint8Array(T * L * 4), v.current = F, () => {
2903
+ F.dispose(), J.dispose(), q.geometry.dispose();
2812
2904
  };
2813
- }, [l]);
2814
- const re = e?.[0], _e = t?.[re];
2815
- o?.[re];
2816
- const W = r?.[0]?.[re];
2905
+ }, [c]);
2906
+ const ne = e?.[0], _e = t?.[ne];
2907
+ a?.[ne];
2908
+ const $ = n?.[0]?.[ne];
2817
2909
  H(() => {
2818
2910
  if (K("useEffect INIT"), !g || !w) {
2819
- i.debug("dataManager or renderManager not initialized yet");
2911
+ r.debug("dataManager or renderManager not initialized yet");
2820
2912
  return;
2821
2913
  }
2822
2914
  if (!_e) {
2823
- i.debug("no first image layer yet");
2915
+ r.debug("no first image layer yet");
2824
2916
  return;
2825
2917
  }
2826
- if (!W) {
2827
- i.debug("no firstImageLayerChannelCoordination yet");
2918
+ if (!$) {
2919
+ r.debug("no firstImageLayerChannelCoordination yet");
2828
2920
  return;
2829
2921
  }
2830
- (async () => (g.initImages(t, e), await g.init(W), w.setZarrUniforms(g.zarrStore, g.PT), w.setChannelMapping(g.channels.colorMappings), i.debug("rm.uniforms", w.uniforms)))();
2922
+ (async () => (g.initImages(t, e), await g.init($), w.setZarrUniforms(g.zarrStore, g.PT), w.setChannelMapping(g.channels.colorMappings), r.debug("rm.uniforms", w.uniforms)))();
2831
2923
  }, [
2832
2924
  g,
2833
2925
  w,
@@ -2835,19 +2927,19 @@ function rt(h) {
2835
2927
  e
2836
2928
  ]), H(() => {
2837
2929
  K("useEffect spatialRenderingMode");
2838
- const C = a === "3D";
2839
- if (E(C), C && g && w) {
2840
- const F = {
2930
+ const T = o === "3D";
2931
+ if (y(T), T && g && w) {
2932
+ const L = {
2841
2933
  images: t,
2842
2934
  imageLayerScopes: e,
2843
- imageLayerCoordination: n,
2844
- imageChannelScopesByLayer: o,
2845
- imageChannelCoordination: r,
2846
- spatialRenderingMode: a
2935
+ imageLayerCoordination: i,
2936
+ imageChannelScopesByLayer: a,
2937
+ imageChannelCoordination: n,
2938
+ spatialRenderingMode: o
2847
2939
  };
2848
- if (w.updateFromProps(F)) {
2849
- const { zarrInit: L } = w;
2850
- L || (g.ptTHREE.needsUpdate = !1, g.bcTHREE.needsUpdate = !1, g.renderer.initTexture(g.bcTHREE), g.renderer.initTexture(g.ptTHREE), g.initTexture());
2940
+ if (w.updateFromProps(L)) {
2941
+ const { zarrInit: F } = w;
2942
+ F || (g.ptTHREE.needsUpdate = !1, g.bcTHREE.needsUpdate = !1, g.renderer.initTexture(g.bcTHREE), g.renderer.initTexture(g.ptTHREE), g.initTexture());
2851
2943
  const B = w.updateRendering({
2852
2944
  zarrStoreShapes: g.zarrStore.shapes,
2853
2945
  originalScaleXYZ: g.getOriginalScaleXYZ(),
@@ -2866,55 +2958,55 @@ function rt(h) {
2866
2958
  w,
2867
2959
  t,
2868
2960
  e,
2961
+ i,
2962
+ a,
2869
2963
  n,
2870
- o,
2871
- r,
2872
- a
2964
+ o
2873
2965
  ]), H(() => {
2874
2966
  if (K("useEffect isInteracting"), X) {
2875
- const C = m.current?.material?.uniforms;
2876
- C && (C.renderRes.value = g.PT.lowestDataRes), N.current = !1, s();
2967
+ const T = m.current?.material?.uniforms;
2968
+ T && (T.renderRes.value = g.PT.lowestDataRes), N.current = !1, s();
2877
2969
  }
2878
- }, [s, X]), Ue((C, F, L) => {
2879
- if (!v.current || !g || !w)
2970
+ }, [s, X]), Ue((T, L, F) => {
2971
+ if (!v.current || !g || !w || !h.shader)
2880
2972
  return;
2881
- const { gl: B, camera: Q, scene: J, clock: q } = C;
2882
- N.current || Qe(B, Q, J, { mrtRef: v }), Je(B, { screenSceneRef: y, screenCameraRef: Z }), et(B, { frameRef: j, dataManager: g, mrtRef: v, bufRequest: u, bufUsage: d }), tt(q, {
2973
+ const { gl: B, camera: Q, scene: J, clock: q } = T;
2974
+ N.current || Qe(B, Q, J, { mrtRef: v }), Je(B, { screenSceneRef: R, screenCameraRef: Z }), et(B, { frameRef: j, dataManager: g, mrtRef: v, bufRequest: u, bufUsage: d }), tt(q, {
2883
2975
  invalidate: s,
2884
2976
  isInteracting: X,
2885
2977
  dataManager: g,
2886
- spatialRenderingModeChanging: c,
2978
+ spatialRenderingModeChanging: l,
2887
2979
  meshRef: m,
2888
2980
  stillRef: N,
2889
- screenQuadRef: $,
2981
+ screenQuadRef: W,
2890
2982
  lastSampleRef: S,
2891
2983
  frameRef: j,
2892
2984
  lastFrameCountRef: be
2893
2985
  }), j.current += 1;
2894
2986
  }, 1);
2895
- const Re = he((C) => {
2896
- A(!0);
2897
- }, []), ye = he((C) => {
2898
- clearTimeout(P.current), P.current = setTimeout(() => {
2899
- A(!1);
2987
+ const Ce = he((T) => {
2988
+ P(!0);
2989
+ }, []), Re = he((T) => {
2990
+ clearTimeout(A.current), A.current = setTimeout(() => {
2991
+ P(!1);
2900
2992
  }, 300);
2901
2993
  }, []);
2902
2994
  return H(() => {
2903
- K("useEffect firstImageLayerChannelCoordination"), A(!0), i.debug("something about channels changed"), g.updateChannels(W), w.setChannelMapping(g.channels.colorMappings), clearTimeout(P.current), P.current = setTimeout(() => {
2904
- A(!1);
2995
+ K("useEffect firstImageLayerChannelCoordination"), P(!0), r.debug("something about channels changed"), g.updateChannels($), w.setChannelMapping(g.channels.colorMappings), clearTimeout(A.current), A.current = setTimeout(() => {
2996
+ P(!1);
2905
2997
  }, 300);
2906
- }, [W]), !_ || !g || !w ? null : f.shader ? D.jsxs("group", { children: [D.jsx(
2998
+ }, [$]), !_ || !g || !w ? null : h.shader ? M.jsxs("group", { children: [M.jsx(
2907
2999
  de,
2908
3000
  {
2909
3001
  // ref={mainOrbitControlsRef}
2910
3002
  enableDamping: !1,
2911
- onStart: Re,
2912
- onEnd: ye
3003
+ onStart: Ce,
3004
+ onEnd: Re
2913
3005
  }
2914
- ), D.jsxs("mesh", { ref: m, scale: f.meshScale, children: [D.jsx("boxGeometry", { args: f.geometrySize }), D.jsx("shaderMaterial", { uniforms: f.uniforms, vertexShader: f.shader.vertexShader, fragmentShader: f.shader.fragmentShader, side: Ne, transparent: !1, glslVersion: Be })] })] }) : D.jsxs("group", { children: [D.jsxs("mesh", { children: [D.jsx("boxGeometry", { args: [1, 1, 1] }), D.jsx("meshBasicMaterial", { color: "#444", wireframe: !0 })] }), D.jsx(de, { ref: x })] });
3006
+ ), M.jsxs("mesh", { ref: m, scale: h.meshScale, children: [M.jsx("boxGeometry", { args: h.geometrySize }), M.jsx("shaderMaterial", { uniforms: h.uniforms, vertexShader: h.shader.vertexShader, fragmentShader: h.shader.fragmentShader, side: Ne, transparent: !1, glslVersion: Be })] })] }) : M.jsxs("group", { children: [M.jsxs("mesh", { children: [M.jsx("boxGeometry", { args: [1, 1, 1] }), M.jsx("meshBasicMaterial", { color: "#444", wireframe: !0 })] }), M.jsx(de, { ref: x })] });
2915
3007
  }
2916
- function st(h) {
2917
- return D.jsx(Oe, { frameloop: "always", style: {
3008
+ function st(f) {
3009
+ return M.jsx(Oe, { frameloop: "always", style: {
2918
3010
  position: "absolute",
2919
3011
  top: 0,
2920
3012
  left: 0,
@@ -2934,7 +3026,7 @@ function st(h) {
2934
3026
  logarithmicDepthBuffer: !1,
2935
3027
  preserveDrawingBuffer: !1,
2936
3028
  autoClear: !1
2937
- }, children: D.jsx(rt, { ...h }) });
3029
+ }, children: M.jsx(nt, { ...f }) });
2938
3030
  }
2939
3031
  export {
2940
3032
  st as SpatialWrapper