omezarr-tilesource 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -40,8 +40,8 @@ const tileSource2 = {
40
40
  url: url,
41
41
  // zip: undefined, // undefined = OME-Zarr ZIP auto-detection based on .ozx suffix
42
42
  // c: undefined, // undefined = composite of all active channels (requires dataType "context2d")
43
- // z: undefined, // undefined = omero metadata default
44
- // t: undefined, // undefined = omero metadata default
43
+ // z: undefined, // undefined = omero rdefs default (middle z-slice if missing)
44
+ // t: undefined, // undefined = omero rdefs default (middle timepoint if missing)
45
45
  // dataType: undefined, // "context2d" (default, rendered tiles) or "ome-zarr" (raw single-channel chunks)
46
46
  // autoBoost: undefined // boost brightness of dark tiles (default false)
47
47
  };
@@ -54,8 +54,8 @@ const tileSource4 = new OMEZarrTileSource({
54
54
  url: url,
55
55
  // zip: undefined, // undefined = OME-Zarr ZIP auto-detection based on .ozx suffix
56
56
  // c: undefined, // undefined = composite of all active channels (requires dataType "context2d")
57
- // z: undefined, // undefined = omero metadata default
58
- // t: undefined, // undefined = omero metadata default
57
+ // z: undefined, // undefined = omero rdefs default (middle z-slice if missing)
58
+ // t: undefined, // undefined = omero rdefs default (middle timepoint if missing)
59
59
  // dataType: undefined, // "context2d" (default, rendered tiles) or "ome-zarr" (raw single-channel chunks)
60
60
  // autoBoost: undefined // boost brightness of dark tiles (default false)
61
61
  });
@@ -71,6 +71,48 @@ const viewer = OpenSeadragon(
71
71
  );
72
72
  ```
73
73
 
74
+ ### Accessing OME-Zarr metadata
75
+
76
+ Directly instantiated tile sources start loading the OME-Zarr metadata
77
+ immediately. Await `whenReady()` (or use the `OMEZarrTileSource.open` shortcut)
78
+ to access the `NgffImage` instance (ome-zarr.js) and the opened zarrita arrays
79
+ (one per resolution level) before adding the tile source to a viewer:
80
+
81
+ ```javascript
82
+ const tileSource = await OMEZarrTileSource.open({ url: url, c: 0 });
83
+ // equivalent: await new OMEZarrTileSource({ url: url, c: 0 }).whenReady();
84
+
85
+ console.log(tileSource.image.getAxesNames()); // e.g. ["t", "z", "c", "y", "x"]
86
+ console.log(tileSource.image.omero?.channels); // omero channel metadata
87
+ console.log(tileSource.arrays[0].shape); // full-resolution array shape
88
+
89
+ viewer.addTiledImage({ tileSource: tileSource }); // no second metadata request
90
+ ```
91
+
92
+ The metadata is loaded once per tile source instance: OpenSeadragon reuses a
93
+ tile source instance passed to it as-is (waiting for it to become ready if
94
+ necessary), whereas a URL or an inline configuration object makes OpenSeadragon
95
+ create (and load) a new instance. `whenReady()` rejects (and `image`/`arrays`
96
+ throw) if loading fails.
97
+
98
+ ### Sharing OME-Zarr metadata between tile sources
99
+
100
+ A loaded `NgffImage` can be reused by other directly instantiated tile sources
101
+ for the same URL (e.g. one tile source per channel) by passing it as the second
102
+ constructor argument (also supported by `OMEZarrTileSource.open`). This skips
103
+ loading the OME-Zarr metadata (the `zip` option is ignored) and reuses the
104
+ opened zarrita arrays, which ome-zarr.js caches on the `NgffImage` instance.
105
+ The tile source never modifies the `NgffImage`, so sharing is safe:
106
+
107
+ ```javascript
108
+ const tileSource1 = await OMEZarrTileSource.open({ url: url, c: 0 });
109
+ const tileSource2 = new OMEZarrTileSource(
110
+ { url: url, c: 1 },
111
+ tileSource1.image,
112
+ );
113
+ // or, without a first tile source: NgffImage.load(url) from ome-zarr.js
114
+ ```
115
+
74
116
  ## Data pipeline
75
117
 
76
118
  By default (`dataType: "context2d"`), tiles are rendered by the tile source and
@@ -79,6 +121,11 @@ passed to OpenSeadragon as 2D canvas contexts, using the rendering settings
79
121
  multi-channel images without `c`, all active channels are rendered into a
80
122
  composite image.
81
123
 
124
+ Contrast limits are taken from the omero channel windows (`window.start`,
125
+ `window.end`). Channels without them are rendered using the data type range
126
+ for integer types (e.g. `[0, 65535]` for `uint16`) and `[0, 1]` for floating
127
+ point types.
128
+
82
129
  With `dataType: "ome-zarr"`, tiles are instead downloaded as raw single-channel
83
130
  zarrita chunks and passed to OpenSeadragon with the data type `ome-zarr` (see
84
131
  the `OMEZarrTileData` type). Multi-channel images therefore require the `c`
@@ -1,4 +1,4 @@
1
- import { t as e } from "./chunk-BXES_1_E.js";
1
+ import { t as e } from "./omezarr-tilesource.js";
2
2
  //#region __vite-browser-external
3
3
  var t = /* @__PURE__ */ e(((e, t) => {
4
4
  t.exports = {};
@@ -0,0 +1,90 @@
1
+ //#region node_modules/.pnpm/vite-plugin-node-polyfills@0.28.0_vite@8.0.14_yaml@2.9.0_/node_modules/vite-plugin-node-polyfills/shims/process/dist/index.js
2
+ function e(e) {
3
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
4
+ }
5
+ var t = { exports: {} }, n = t.exports = {}, r, i;
6
+ function a() {
7
+ throw Error("setTimeout has not been defined");
8
+ }
9
+ function o() {
10
+ throw Error("clearTimeout has not been defined");
11
+ }
12
+ (function() {
13
+ try {
14
+ r = typeof setTimeout == "function" ? setTimeout : a;
15
+ } catch {
16
+ r = a;
17
+ }
18
+ try {
19
+ i = typeof clearTimeout == "function" ? clearTimeout : o;
20
+ } catch {
21
+ i = o;
22
+ }
23
+ })();
24
+ function s(e) {
25
+ if (r === setTimeout) return setTimeout(e, 0);
26
+ if ((r === a || !r) && setTimeout) return r = setTimeout, setTimeout(e, 0);
27
+ try {
28
+ return r(e, 0);
29
+ } catch {
30
+ try {
31
+ return r.call(null, e, 0);
32
+ } catch {
33
+ return r.call(this, e, 0);
34
+ }
35
+ }
36
+ }
37
+ function c(e) {
38
+ if (i === clearTimeout) return clearTimeout(e);
39
+ if ((i === o || !i) && clearTimeout) return i = clearTimeout, clearTimeout(e);
40
+ try {
41
+ return i(e);
42
+ } catch {
43
+ try {
44
+ return i.call(null, e);
45
+ } catch {
46
+ return i.call(this, e);
47
+ }
48
+ }
49
+ }
50
+ var l = [], u = !1, d, f = -1;
51
+ function p() {
52
+ !u || !d || (u = !1, d.length ? l = d.concat(l) : f = -1, l.length && m());
53
+ }
54
+ function m() {
55
+ if (!u) {
56
+ var e = s(p);
57
+ u = !0;
58
+ for (var t = l.length; t;) {
59
+ for (d = l, l = []; ++f < t;) d && d[f].run();
60
+ f = -1, t = l.length;
61
+ }
62
+ d = null, u = !1, c(e);
63
+ }
64
+ }
65
+ n.nextTick = function(e) {
66
+ var t = Array(arguments.length - 1);
67
+ if (arguments.length > 1) for (var n = 1; n < arguments.length; n++) t[n - 1] = arguments[n];
68
+ l.push(new h(e, t)), l.length === 1 && !u && s(m);
69
+ };
70
+ function h(e, t) {
71
+ this.fun = e, this.array = t;
72
+ }
73
+ h.prototype.run = function() {
74
+ this.fun.apply(null, this.array);
75
+ }, n.title = "browser", n.browser = !0, n.env = {}, n.argv = [], n.version = "", n.versions = {};
76
+ function g() {}
77
+ n.on = g, n.addListener = g, n.once = g, n.off = g, n.removeListener = g, n.removeAllListeners = g, n.emit = g, n.prependListener = g, n.prependOnceListener = g, n.listeners = function(e) {
78
+ return [];
79
+ }, n.binding = function(e) {
80
+ throw Error("process.binding is not supported");
81
+ }, n.cwd = function() {
82
+ return "/";
83
+ }, n.chdir = function(e) {
84
+ throw Error("process.chdir is not supported");
85
+ }, n.umask = function() {
86
+ return 0;
87
+ };
88
+ var _ = t.exports, v = /* @__PURE__ */ e(_);
89
+ //#endregion
90
+ export { v as t };
@@ -1,5 +1,6 @@
1
1
  import { Channel } from 'ome-zarr.js';
2
2
  import { default as default_2 } from 'openseadragon';
3
+ import { NgffImage } from 'ome-zarr.js';
3
4
  import * as zarr from 'zarrita';
4
5
 
5
6
  export declare interface OMEZarrTileData {
@@ -20,8 +21,13 @@ export declare class OMEZarrTileSource extends default_2.TileSource {
20
21
  height: number;
21
22
  private _image?;
22
23
  private _arrays?;
23
- constructor(url: string);
24
- constructor(options: OMEZarrTileSourceOptions);
24
+ private readonly _readyPromise;
25
+ static open(config: string | OMEZarrTileSourceOptions, image?: NgffImage): Promise<OMEZarrTileSource>;
26
+ constructor(url: string, image?: NgffImage);
27
+ constructor(options: OMEZarrTileSourceOptions, image?: NgffImage);
28
+ get image(): NgffImage;
29
+ get arrays(): zarr.Array<zarr.NumberDataType | zarr.BigintDataType>[];
30
+ whenReady(): Promise<this>;
25
31
  supports(data: string | object | object[] | Document): boolean;
26
32
  configure(data: string | object | object[] | Document, _url: string, postData?: string | null): OMEZarrTileSourceOptions;
27
33
  equals(other: default_2.TileSource): boolean;
@@ -37,6 +43,7 @@ export declare class OMEZarrTileSource extends default_2.TileSource {
37
43
  private static _learnConverters;
38
44
  private _getActiveChannelIndices;
39
45
  private static _render;
46
+ private static _getDataTypeRange;
40
47
  }
41
48
 
42
49
  export declare interface OMEZarrTileSourceOptions {