@vitessce/zarr 3.3.8 → 3.3.10

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.
Files changed (75) hide show
  1. package/dist/{deflate-2f7f502f.js → deflate-b162c7aa.js} +1 -1
  2. package/dist/{index-200d5108.js → index-184aee21.js} +290 -124
  3. package/dist/index.js +1 -1
  4. package/dist/{jpeg-3ff942a5.js → jpeg-dbb0f9d9.js} +1 -1
  5. package/dist/{lerc-762cc666.js → lerc-e45d57dc.js} +1 -1
  6. package/dist/{lzw-97464fce.js → lzw-05e88e18.js} +1 -1
  7. package/dist/{packbits-daaf8f04.js → packbits-922f4592.js} +1 -1
  8. package/dist/{raw-8fdba750.js → raw-a8de9c08.js} +1 -1
  9. package/dist/{webimage-e98ea52f.js → webimage-27013e2d.js} +1 -1
  10. package/dist-tsc/AnnDataSource.d.ts +96 -30
  11. package/dist-tsc/AnnDataSource.d.ts.map +1 -1
  12. package/dist-tsc/AnnDataSource.js +147 -53
  13. package/dist-tsc/MuDataSource.d.ts +1 -1
  14. package/dist-tsc/MuDataSource.d.ts.map +1 -1
  15. package/dist-tsc/SpatialDataShapesSource.d.ts +40 -12
  16. package/dist-tsc/SpatialDataShapesSource.d.ts.map +1 -1
  17. package/dist-tsc/SpatialDataShapesSource.js +58 -27
  18. package/dist-tsc/SpatialDataTableSource.d.ts +35 -14
  19. package/dist-tsc/SpatialDataTableSource.d.ts.map +1 -1
  20. package/dist-tsc/SpatialDataTableSource.js +57 -27
  21. package/dist-tsc/ZarrDataSource.d.ts +22 -11
  22. package/dist-tsc/ZarrDataSource.d.ts.map +1 -1
  23. package/dist-tsc/ZarrDataSource.js +20 -3
  24. package/dist-tsc/anndata-loaders/FeatureLabelsAnndataLoader.d.ts +18 -5
  25. package/dist-tsc/anndata-loaders/FeatureLabelsAnndataLoader.d.ts.map +1 -1
  26. package/dist-tsc/anndata-loaders/FeatureLabelsAnndataLoader.js +12 -4
  27. package/dist-tsc/anndata-loaders/ObsEmbeddingAnndataLoader.d.ts +22 -5
  28. package/dist-tsc/anndata-loaders/ObsEmbeddingAnndataLoader.d.ts.map +1 -1
  29. package/dist-tsc/anndata-loaders/ObsEmbeddingAnndataLoader.js +13 -5
  30. package/dist-tsc/anndata-loaders/ObsFeatureColumnsAnndataLoader.d.ts +9 -2
  31. package/dist-tsc/anndata-loaders/ObsFeatureColumnsAnndataLoader.d.ts.map +1 -1
  32. package/dist-tsc/anndata-loaders/ObsFeatureMatrixAnndataLoader.d.ts +9 -2
  33. package/dist-tsc/anndata-loaders/ObsFeatureMatrixAnndataLoader.d.ts.map +1 -1
  34. package/dist-tsc/anndata-loaders/ObsLabelsAnndataLoader.d.ts +8 -2
  35. package/dist-tsc/anndata-loaders/ObsLabelsAnndataLoader.d.ts.map +1 -1
  36. package/dist-tsc/anndata-loaders/ObsLocationsAnndataLoader.d.ts +8 -2
  37. package/dist-tsc/anndata-loaders/ObsLocationsAnndataLoader.d.ts.map +1 -1
  38. package/dist-tsc/anndata-loaders/ObsPointsAnndataLoader.d.ts +8 -2
  39. package/dist-tsc/anndata-loaders/ObsPointsAnndataLoader.d.ts.map +1 -1
  40. package/dist-tsc/anndata-loaders/ObsSegmentationsAnndataLoader.d.ts +9 -2
  41. package/dist-tsc/anndata-loaders/ObsSegmentationsAnndataLoader.d.ts.map +1 -1
  42. package/dist-tsc/anndata-loaders/ObsSetsAnndataLoader.d.ts +10 -3
  43. package/dist-tsc/anndata-loaders/ObsSetsAnndataLoader.d.ts.map +1 -1
  44. package/dist-tsc/anndata-loaders/ObsSpotsAnndataLoader.d.ts +8 -2
  45. package/dist-tsc/anndata-loaders/ObsSpotsAnndataLoader.d.ts.map +1 -1
  46. package/dist-tsc/anndata-loaders/SampleEdgesAnndataLoader.d.ts +8 -2
  47. package/dist-tsc/anndata-loaders/SampleEdgesAnndataLoader.d.ts.map +1 -1
  48. package/dist-tsc/genomic-loaders/GenomicProfilesZarrLoader.d.ts +3 -1
  49. package/dist-tsc/genomic-loaders/GenomicProfilesZarrLoader.d.ts.map +1 -1
  50. package/dist-tsc/matrix-loaders/MatrixZarrAsObsFeatureMatrix.d.ts +9 -2
  51. package/dist-tsc/matrix-loaders/MatrixZarrAsObsFeatureMatrix.d.ts.map +1 -1
  52. package/dist-tsc/ome-loaders/OmeZarrAsObsSegmentationsLoader.d.ts +10 -1
  53. package/dist-tsc/ome-loaders/OmeZarrAsObsSegmentationsLoader.d.ts.map +1 -1
  54. package/dist-tsc/ome-loaders/OmeZarrLoader.d.ts +12 -2
  55. package/dist-tsc/ome-loaders/OmeZarrLoader.d.ts.map +1 -1
  56. package/dist-tsc/ome-loaders/OmeZarrLoader.js +2 -2
  57. package/dist-tsc/spatialdata-loaders/SpatialDataImageLoader.d.ts +1 -1
  58. package/dist-tsc/spatialdata-loaders/SpatialDataImageLoader.d.ts.map +1 -1
  59. package/dist-tsc/spatialdata-loaders/SpatialDataLabelsLoader.d.ts +1 -1
  60. package/dist-tsc/spatialdata-loaders/SpatialDataLabelsLoader.d.ts.map +1 -1
  61. package/dist-tsc/spatialdata-loaders/SpatialDataObsSetsLoader.d.ts +1 -2
  62. package/dist-tsc/spatialdata-loaders/SpatialDataObsSetsLoader.d.ts.map +1 -1
  63. package/dist-tsc/spatialdata-loaders/SpatialDataObsSpotsLoader.d.ts +8 -2
  64. package/dist-tsc/spatialdata-loaders/SpatialDataObsSpotsLoader.d.ts.map +1 -1
  65. package/dist-tsc/utils.d.ts +14 -2
  66. package/dist-tsc/utils.d.ts.map +1 -1
  67. package/dist-tsc/utils.js +19 -1
  68. package/package.json +16 -10
  69. package/src/AnnDataSource.js +170 -53
  70. package/src/SpatialDataShapesSource.js +61 -28
  71. package/src/SpatialDataTableSource.js +60 -27
  72. package/src/ZarrDataSource.js +20 -3
  73. package/src/anndata-loaders/FeatureLabelsAnndataLoader.js +13 -4
  74. package/src/anndata-loaders/ObsEmbeddingAnndataLoader.js +14 -5
  75. package/src/utils.js +20 -1
@@ -2472,28 +2472,41 @@ class ZipFileStore {
2472
2472
  const ZipFileStore$1 = ZipFileStore;
2473
2473
  function zarrOpenRoot(url, fileType, requestInit2) {
2474
2474
  let store;
2475
+ const opts2 = requestInit2 ? { overrides: requestInit2 } : void 0;
2475
2476
  if (fileType && fileType.endsWith(".zip")) {
2476
- store = ZipFileStore$1.fromUrl(url, { overrides: requestInit2 });
2477
+ store = ZipFileStore$1.fromUrl(url, opts2);
2477
2478
  } else {
2478
- store = new FetchStore$1(url, { overrides: requestInit2 });
2479
+ store = new FetchStore$1(url, opts2);
2479
2480
  }
2480
2481
  return root$3(store);
2481
2482
  }
2482
2483
  class ZarrDataSource {
2484
+ /**
2485
+ * @param {DataSourceParams} params The parameters object.
2486
+ */
2483
2487
  constructor({ url, requestInit: requestInit2, store, fileType }) {
2484
2488
  if (store) {
2485
2489
  this.storeRoot = root$3(store);
2486
- } else {
2490
+ } else if (url) {
2487
2491
  this.storeRoot = zarrOpenRoot(url, fileType, requestInit2);
2492
+ } else {
2493
+ throw new Error("Either a store or a URL must be provided to the ZarrDataSource constructor.");
2488
2494
  }
2489
2495
  }
2496
+ /**
2497
+ *
2498
+ * @param {string} path
2499
+ * @returns {ZarrLocation<Readable>}
2500
+ */
2490
2501
  getStoreRoot(path) {
2491
2502
  return this.storeRoot.resolve(path);
2492
2503
  }
2493
2504
  /**
2494
- * Class method for decoding json from the store.
2505
+ * Method for accessing JSON attributes, relative to the store root.
2495
2506
  * @param {string} key A path to the item.
2496
- * @returns {Promise} This async function returns a promise
2507
+ * @param {ZarrLocation<Readable>|null} storeRootParam An optional location,
2508
+ * which if provided will override the default store root.
2509
+ * @returns {Promise<any>} This async function returns a promise
2497
2510
  * that resolves to the parsed JSON if successful.
2498
2511
  * @throws This may throw an error.
2499
2512
  */
@@ -2514,16 +2527,41 @@ function dirname$1(path) {
2514
2527
  }
2515
2528
  function basename(path) {
2516
2529
  const arr = path.split("/");
2517
- return arr.at(-1);
2530
+ const result = arr.at(-1);
2531
+ if (!result) {
2532
+ console.error("basename of path is empty", path);
2533
+ return "";
2534
+ }
2535
+ return result;
2518
2536
  }
2519
2537
  class AnnDataSource extends ZarrDataSource {
2520
- constructor(...args) {
2521
- super(...args);
2538
+ /**
2539
+ *
2540
+ * @param {DataSourceParams} params
2541
+ */
2542
+ constructor(params) {
2543
+ super(params);
2522
2544
  this.promises = /* @__PURE__ */ new Map();
2523
2545
  }
2546
+ /**
2547
+ *
2548
+ * @param {string[]} paths Paths to multiple string-valued columns
2549
+ * within the obs dataframe.
2550
+ * @returns {Promise<(undefined | string[] | string[][])[]>} Returns
2551
+ * each column as an array of strings,
2552
+ * ordered the same as the paths.
2553
+ */
2524
2554
  loadObsColumns(paths) {
2525
2555
  return this._loadColumns(paths);
2526
2556
  }
2557
+ /**
2558
+ *
2559
+ * @param {string[]} paths Paths to multiple string-valued columns
2560
+ * within the var dataframe.
2561
+ * @returns {Promise<(undefined | string[] | string[][])[]>} Returns
2562
+ * each column as an array of strings,
2563
+ * ordered the same as the paths.
2564
+ */
2527
2565
  loadVarColumns(paths) {
2528
2566
  return this._loadColumns(paths);
2529
2567
  }
@@ -2531,8 +2569,10 @@ class AnnDataSource extends ZarrDataSource {
2531
2569
  * Class method for loading obs variables.
2532
2570
  * Takes the location as an argument because this is shared across objects,
2533
2571
  * which have different ways of specifying location.
2534
- * @param {string[]} paths An array of strings like "obs/leiden" or "obs/bulk_labels."
2535
- * @returns {Promise} A promise for an array of ids with one per cell.
2572
+ * @param {string[] | string[][]} paths An array of strings like
2573
+ * "obs/leiden" or "obs/bulk_labels."
2574
+ * @returns {Promise<(undefined | string[] | string[][])[]>} A promise
2575
+ * for an array of ids with one per cell.
2536
2576
  */
2537
2577
  _loadColumns(paths) {
2538
2578
  const promises = paths.map((path) => {
@@ -2544,7 +2584,10 @@ class AnnDataSource extends ZarrDataSource {
2544
2584
  });
2545
2585
  this.promises.set(col, obsPromise);
2546
2586
  }
2547
- return this.promises.get(col);
2587
+ return (
2588
+ /** @type {Promise<string[]>} */
2589
+ this.promises.get(col)
2590
+ );
2548
2591
  };
2549
2592
  if (!path) {
2550
2593
  return Promise.resolve(void 0);
@@ -2556,34 +2599,51 @@ class AnnDataSource extends ZarrDataSource {
2556
2599
  });
2557
2600
  return Promise.all(promises);
2558
2601
  }
2602
+ /**
2603
+ *
2604
+ * @param {string} path
2605
+ * @returns
2606
+ */
2559
2607
  async _loadColumn(path) {
2560
2608
  const { storeRoot } = this;
2561
2609
  const prefix = dirname$1(path);
2562
2610
  const { categories, "encoding-type": encodingType } = await this.getJson(`${path}/.zattrs`);
2563
2611
  let categoriesValues;
2564
- let codes;
2612
+ let codesPath;
2565
2613
  if (categories) {
2566
- const { dtype } = await open(storeRoot.resolve(`/${prefix}/${categories}`));
2614
+ const { dtype } = await open(
2615
+ storeRoot.resolve(`/${prefix}/${categories}`),
2616
+ { kind: "array" }
2617
+ );
2567
2618
  if (dtype === "v2:object") {
2568
2619
  categoriesValues = await this.getFlatArrDecompressed(
2569
2620
  `/${prefix}/${categories}`
2570
2621
  );
2571
2622
  }
2572
2623
  } else if (encodingType === "categorical") {
2573
- const { dtype } = await open(storeRoot.resolve(`/${path}/categories`));
2624
+ const { dtype } = await open(
2625
+ storeRoot.resolve(`/${path}/categories`),
2626
+ { kind: "array" }
2627
+ );
2574
2628
  if (dtype === "v2:object") {
2575
2629
  categoriesValues = await this.getFlatArrDecompressed(
2576
2630
  `/${path}/categories`
2577
2631
  );
2578
2632
  }
2579
- codes = `/${path}/codes`;
2633
+ codesPath = `/${path}/codes`;
2580
2634
  } else {
2581
- const { dtype } = await open(storeRoot.resolve(`/${path}`));
2635
+ const { dtype } = await open(
2636
+ storeRoot.resolve(`/${path}`),
2637
+ { kind: "array" }
2638
+ );
2582
2639
  if (dtype === "v2:object") {
2583
2640
  return this.getFlatArrDecompressed(path);
2584
2641
  }
2585
2642
  }
2586
- const arr = await open(storeRoot.resolve(codes || path), { kind: "array" });
2643
+ const arr = await open(
2644
+ storeRoot.resolve(codesPath || path),
2645
+ { kind: "array" }
2646
+ );
2587
2647
  const values = await get$1(arr, [null]);
2588
2648
  const { data } = values;
2589
2649
  const mappedValues = Array.from(data).map(
@@ -2594,7 +2654,7 @@ class AnnDataSource extends ZarrDataSource {
2594
2654
  /**
2595
2655
  * Class method for loading general numeric arrays.
2596
2656
  * @param {string} path A string like obsm.X_pca.
2597
- * @returns {Promise} A promise for a zarr array containing the data.
2657
+ * @returns {Promise<Chunk<any>>} A promise for a zarr array containing the data.
2598
2658
  */
2599
2659
  loadNumeric(path) {
2600
2660
  const { storeRoot } = this;
@@ -2603,8 +2663,11 @@ class AnnDataSource extends ZarrDataSource {
2603
2663
  /**
2604
2664
  * Class method for loading specific columns of numeric arrays.
2605
2665
  * @param {string} path A string like obsm.X_pca.
2606
- * @param {number[]} dims The column indices to load.
2607
- * @returns {Promise} A promise for a zarr array containing the data.
2666
+ * @param {[number, number]} dims The column indices to load.
2667
+ * @returns {Promise<{
2668
+ * data: [ZarrTypedArray<any>, ZarrTypedArray<any>],
2669
+ * shape: [number, number],
2670
+ * }>} A promise for a zarr array containing the data.
2608
2671
  */
2609
2672
  loadNumericForDims(path, dims) {
2610
2673
  const { storeRoot } = this;
@@ -2614,7 +2677,10 @@ class AnnDataSource extends ZarrDataSource {
2614
2677
  (loadedArr) => get$1(loadedArr, [null, dim])
2615
2678
  ))
2616
2679
  ).then((cols) => ({
2617
- data: cols.map((col) => col.data),
2680
+ data: (
2681
+ /** @type {[ZarrTypedArray<any>, ZarrTypedArray<any>]} */
2682
+ cols.map((col) => col.data)
2683
+ ),
2618
2684
  shape: [dims.length, cols[0].shape[0]]
2619
2685
  }));
2620
2686
  }
@@ -2622,7 +2688,7 @@ class AnnDataSource extends ZarrDataSource {
2622
2688
  * A common method for loading flattened data
2623
2689
  * i.e that which has shape [n] where n is a natural number.
2624
2690
  * @param {string} path A path to a flat array location, like obs/_index
2625
- * @returns {Array} The data from the zarr array.
2691
+ * @returns {Promise<string[]>} The data from the zarr array.
2626
2692
  */
2627
2693
  async getFlatArrDecompressed(path) {
2628
2694
  var _a3;
@@ -2632,13 +2698,18 @@ class AnnDataSource extends ZarrDataSource {
2632
2698
  if ((_a3 = data.data) == null ? void 0 : _a3[Symbol.iterator]) {
2633
2699
  return Array.from(data.data);
2634
2700
  }
2635
- return data.data;
2701
+ return (
2702
+ /** @type {string[]} */
2703
+ data.data
2704
+ );
2636
2705
  }
2637
2706
  /**
2638
2707
  * Class method for loading the obs index.
2639
- * @returns {Promise} An promise for a zarr array containing the indices.
2708
+ * @param {string|undefined} path Used by subclasses.
2709
+ * @returns {Promise<string[]>} An promise for a zarr array
2710
+ * containing the indices.
2640
2711
  */
2641
- loadObsIndex() {
2712
+ loadObsIndex(path = void 0) {
2642
2713
  if (this.obsIndex) {
2643
2714
  return this.obsIndex;
2644
2715
  }
@@ -2647,9 +2718,10 @@ class AnnDataSource extends ZarrDataSource {
2647
2718
  }
2648
2719
  /**
2649
2720
  * Class method for loading the var index.
2650
- * @returns {Promise} An promise for a zarr array containing the indices.
2721
+ * @param {string|undefined} path Used by subclasses.
2722
+ * @returns {Promise<string[]>} An promise for a zarr array containing the indices.
2651
2723
  */
2652
- loadVarIndex() {
2724
+ loadVarIndex(path = void 0) {
2653
2725
  if (this.varIndex) {
2654
2726
  return this.varIndex;
2655
2727
  }
@@ -2658,60 +2730,113 @@ class AnnDataSource extends ZarrDataSource {
2658
2730
  }
2659
2731
  /**
2660
2732
  * Class method for loading the var alias.
2661
- * @returns {Promise} An promise for a zarr array containing the aliased names.
2733
+ * @param {string} varPath
2734
+ * @param {string|undefined} matrixPath
2735
+ * @returns {Promise<string[]>} An promise for a zarr array containing the aliased names.
2662
2736
  */
2663
- async loadVarAlias(varPath) {
2737
+ async loadVarAlias(varPath, matrixPath = void 0) {
2664
2738
  if (this.varAlias) {
2665
2739
  return this.varAlias;
2666
2740
  }
2667
2741
  [this.varAlias] = await this.loadVarColumns([varPath]);
2668
2742
  const index2 = await this.loadVarIndex();
2669
2743
  this.varAlias = this.varAlias.map(
2744
+ /** @type {(val: string, ind: number) => string} */
2670
2745
  (val, ind) => val ? val.concat(` (${index2[ind]})`) : index2[ind]
2671
2746
  );
2672
2747
  return this.varAlias;
2673
2748
  }
2749
+ /**
2750
+ *
2751
+ * @param {string} path
2752
+ * @returns {Promise<object>}
2753
+ */
2674
2754
  async _loadAttrs(path) {
2675
2755
  return this.getJson(`${path}/.zattrs`);
2676
2756
  }
2757
+ /**
2758
+ *
2759
+ * @param {string} path
2760
+ * @returns {Promise<string>}
2761
+ */
2677
2762
  async _loadString(path) {
2678
2763
  const { storeRoot } = this;
2679
- const { "encoding-type": encodingType, "encoding-version": encodingVersion } = await this._loadAttrs(path);
2680
- if (encodingType === "string" && encodingVersion === "0.2.0") {
2681
- const arr = await open(storeRoot.resolve(path), { kind: "array" });
2682
- const { data } = await arr.getChunk([]);
2683
- return data.get(0);
2764
+ const zattrs = await this._loadAttrs(path);
2765
+ if ("encoding-type" in zattrs && "encoding-version" in zattrs) {
2766
+ const {
2767
+ "encoding-type": encodingType,
2768
+ "encoding-version": encodingVersion
2769
+ } = zattrs;
2770
+ if (encodingType === "string" && encodingVersion === "0.2.0") {
2771
+ const arr = await open(storeRoot.resolve(path), { kind: "array" });
2772
+ const { data } = (
2773
+ /** @type {{ data: ByteStringArray }} */
2774
+ await arr.getChunk([])
2775
+ );
2776
+ return data.get(0);
2777
+ }
2778
+ throw new Error(`Unsupported encoding type ${encodingType} and version ${encodingVersion} in AnnDataSource._loadString`);
2684
2779
  }
2685
- throw new Error(`Unsupported encoding type ${encodingType} and version ${encodingVersion} in AnnDataSource._loadString`);
2780
+ throw new Error("Keys for encoding-type or encoding-version not found in AnnDataSource._loadString");
2686
2781
  }
2782
+ /**
2783
+ *
2784
+ * @param {string} path
2785
+ * @returns {Promise<string[]>}
2786
+ */
2687
2787
  async _loadStringArray(path) {
2688
- const { "encoding-type": encodingType, "encoding-version": encodingVersion } = await this._loadAttrs(path);
2689
- if (encodingType === "string-array" && encodingVersion === "0.2.0") {
2690
- return this.getFlatArrDecompressed(path);
2788
+ const zattrs = await this._loadAttrs(path);
2789
+ if ("encoding-type" in zattrs && "encoding-version" in zattrs) {
2790
+ const { "encoding-type": encodingType, "encoding-version": encodingVersion } = zattrs;
2791
+ if (encodingType === "string-array" && encodingVersion === "0.2.0") {
2792
+ return this.getFlatArrDecompressed(path);
2793
+ }
2794
+ throw new Error(`Unsupported encoding type ${encodingType} and version ${encodingVersion} in AnnDataSource._loadStringArray`);
2691
2795
  }
2692
- throw new Error(`Unsupported encoding type ${encodingType} and version ${encodingVersion} in AnnDataSource._loadStringArray`);
2796
+ throw new Error("Keys for encoding-type or encoding-version not found in AnnDataSource._loadString");
2693
2797
  }
2798
+ /**
2799
+ *
2800
+ * @param {string} path
2801
+ * @returns
2802
+ */
2694
2803
  async _loadElement(path) {
2695
- const { "encoding-type": encodingType } = await this._loadAttrs(path);
2696
- if (encodingType === "string") {
2697
- return this._loadString(path);
2698
- }
2699
- if (encodingType === "string-array") {
2700
- return this._loadStringArray(path);
2804
+ const zattrs = await this._loadAttrs(path);
2805
+ if ("encoding-type" in zattrs) {
2806
+ const { "encoding-type": encodingType } = zattrs;
2807
+ if (encodingType === "string") {
2808
+ return this._loadString(path);
2809
+ }
2810
+ if (encodingType === "string-array") {
2811
+ return this._loadStringArray(path);
2812
+ }
2701
2813
  }
2702
2814
  return null;
2703
2815
  }
2816
+ /**
2817
+ *
2818
+ * @param {string} path
2819
+ * @param {string[]} keys
2820
+ * @returns
2821
+ */
2704
2822
  async _loadDict(path, keys3) {
2705
- const { "encoding-type": encodingType, "encoding-version": encodingVersion } = await this._loadAttrs(path);
2706
- if (encodingType === "dict" && encodingVersion === "0.1.0") {
2707
- const result = {};
2708
- await Promise.all(keys3.map(async (key) => {
2709
- const val = await this._loadElement(`${path}/${key}`);
2710
- result[key] = val;
2711
- }));
2712
- return result;
2823
+ const zattrs = await this._loadAttrs(path);
2824
+ if ("encoding-type" in zattrs && "encoding-version" in zattrs) {
2825
+ const {
2826
+ "encoding-type": encodingType,
2827
+ "encoding-version": encodingVersion
2828
+ } = zattrs;
2829
+ if (encodingType === "dict" && encodingVersion === "0.1.0") {
2830
+ const result = {};
2831
+ await Promise.all(keys3.map(async (key) => {
2832
+ const val = await this._loadElement(`${path}/${key}`);
2833
+ result[key] = val;
2834
+ }));
2835
+ return result;
2836
+ }
2837
+ throw new Error(`Unsupported encoding type ${encodingType} and version ${encodingVersion} in AnnDataSource._loadDict`);
2713
2838
  }
2714
- throw new Error(`Unsupported encoding type ${encodingType} and version ${encodingVersion} in AnnDataSource._loadDict`);
2839
+ throw new Error("Keys for encoding-type or encoding-version not found in AnnDataSource._loadString");
2715
2840
  }
2716
2841
  }
2717
2842
  const regex$3 = /^mod\/([^/]*)\/(.*)$/;
@@ -2798,17 +2923,30 @@ function getVarPath$1(arrPath) {
2798
2923
  return `${getTablePrefix(arrPath)}var`;
2799
2924
  }
2800
2925
  class SpatialDataTableSource extends AnnDataSource {
2926
+ /**
2927
+ *
2928
+ * @param {DataSourceParams} params
2929
+ */
2930
+ constructor(params) {
2931
+ super(params);
2932
+ this.obsIndices = {};
2933
+ this.varIndices = {};
2934
+ this.varAliases = {};
2935
+ }
2936
+ /**
2937
+ *
2938
+ * @param {string} tablePath
2939
+ * @returns
2940
+ */
2801
2941
  async loadSpatialDataAttrs(tablePath) {
2802
2942
  return this._loadDict(`${tablePath}uns/spatialdata_attrs`, ["instance_key", "region", "region_key"]);
2803
2943
  }
2804
2944
  /**
2805
2945
  * Class method for loading the obs index.
2806
- * @returns {Promise} An promise for a zarr array containing the indices.
2946
+ * @param {string|undefined} path
2947
+ * @returns {Promise<string[]>} An promise for a zarr array containing the indices.
2807
2948
  */
2808
- async loadObsIndex(path = null) {
2809
- if (!this.obsIndex) {
2810
- this.obsIndex = {};
2811
- }
2949
+ async loadObsIndex(path = void 0) {
2812
2950
  const obsPath = getObsPath(path);
2813
2951
  const { _index } = await this.getJson(`${obsPath}/.zattrs`);
2814
2952
  let indexPath = `${obsPath}/${_index}`;
@@ -2819,45 +2957,43 @@ class SpatialDataTableSource extends AnnDataSource {
2819
2957
  // region,
2820
2958
  } = await this.loadSpatialDataAttrs(getTablePrefix(path));
2821
2959
  indexPath = `${obsPath}/${instanceKey}`;
2822
- if (this.obsIndex[indexPath]) {
2823
- return this.obsIndex[indexPath];
2960
+ if (indexPath in this.obsIndices) {
2961
+ return this.obsIndices[indexPath];
2824
2962
  }
2825
- this.obsIndex[indexPath] = this._loadColumn(indexPath);
2826
- return this.obsIndex[indexPath];
2963
+ this.obsIndices[indexPath] = this._loadColumn(indexPath);
2964
+ return this.obsIndices[indexPath];
2827
2965
  }
2828
2966
  /**
2829
2967
  * Class method for loading the var index.
2830
- * @returns {Promise} An promise for a zarr array containing the indices.
2968
+ * @param {string|undefined} path
2969
+ * @returns {Promise<string[]>} An promise for a zarr array containing the indices.
2831
2970
  */
2832
- loadVarIndex(path = null) {
2833
- if (!this.varIndex) {
2834
- this.varIndex = {};
2835
- }
2971
+ loadVarIndex(path = void 0) {
2836
2972
  const varPath = getVarPath$1(path);
2837
- if (this.varIndex[varPath]) {
2838
- return this.varIndex[varPath];
2973
+ if (varPath in this.varIndices) {
2974
+ return this.varIndices[varPath];
2839
2975
  }
2840
- this.varIndex[varPath] = this.getJson(`${varPath}/.zattrs`).then(({ _index }) => this.getFlatArrDecompressed(`${varPath}/${_index}`));
2841
- return this.varIndex[varPath];
2976
+ this.varIndices[varPath] = this.getJson(`${varPath}/.zattrs`).then(({ _index }) => this.getFlatArrDecompressed(`${varPath}/${_index}`));
2977
+ return this.varIndices[varPath];
2842
2978
  }
2843
2979
  /**
2844
2980
  * Class method for loading the var alias.
2845
- * @returns {Promise} An promise for a zarr array containing the aliased names.
2981
+ * @param {string} varPath
2982
+ * @param {string} matrixPath
2983
+ * @returns {Promise<string[]>} An promise for a zarr array containing the aliased names.
2846
2984
  */
2847
2985
  async loadVarAlias(varPath, matrixPath) {
2848
- if (!this.varAlias) {
2849
- this.varAlias = {};
2850
- }
2851
- if (this.varAlias[varPath]) {
2852
- return this.varAlias[varPath];
2986
+ if (varPath in this.varAliases) {
2987
+ return this.varAliases[varPath];
2853
2988
  }
2854
2989
  const [varAliasData] = await this.loadVarColumns([varPath]);
2855
- this.varAlias[varPath] = varAliasData;
2990
+ this.varAliases[varPath] = /** @type {string[]} */
2991
+ varAliasData;
2856
2992
  const index2 = await this.loadVarIndex(matrixPath);
2857
- this.varAlias[varPath] = this.varAlias[varPath].map(
2993
+ this.varAliases[varPath] = this.varAliases[varPath].map(
2858
2994
  (val, ind) => val ? val.concat(` (${index2[ind]})`) : index2[ind]
2859
2995
  );
2860
- return this.varAlias[varPath];
2996
+ return this.varAliases[varPath];
2861
2997
  }
2862
2998
  }
2863
2999
  const regex$1 = /^shapes\/([^/]*)\/(.*)$/;
@@ -2877,17 +3013,31 @@ function getVarPath(arrPath) {
2877
3013
  return `${getShapesPrefix(arrPath)}var`;
2878
3014
  }
2879
3015
  class SpatialDataShapesSource extends AnnDataSource {
3016
+ /**
3017
+ *
3018
+ * @param {DataSourceParams} params
3019
+ */
3020
+ constructor(params) {
3021
+ super(params);
3022
+ this.obsIndices = {};
3023
+ this.varIndices = {};
3024
+ this.varAliases = {};
3025
+ }
3026
+ /**
3027
+ *
3028
+ * @param {string} tablePath
3029
+ * @returns
3030
+ */
2880
3031
  async loadSpatialDataAttrs(tablePath) {
2881
3032
  return this._loadDict(`${tablePath}/uns/spatialdata_attrs`, ["instance_key", "region", "region_key"]);
2882
3033
  }
2883
3034
  /**
2884
3035
  * Class method for loading the obs index.
2885
- * @returns {Promise} An promise for a zarr array containing the indices.
3036
+ * @param {string|undefined} path
3037
+ * @param {string|undefined} tablePath
3038
+ * @returns {Promise<string[]>} An promise for a zarr array containing the indices.
2886
3039
  */
2887
- async loadObsIndex(path = null, tablePath = null) {
2888
- if (!this.obsIndex) {
2889
- this.obsIndex = {};
2890
- }
3040
+ async loadObsIndex(path = void 0, tablePath = void 0) {
2891
3041
  let indexPath = getIndexPath(path);
2892
3042
  if (tablePath) {
2893
3043
  const obsPath = `${tablePath}/obs`;
@@ -2901,45 +3051,43 @@ class SpatialDataShapesSource extends AnnDataSource {
2901
3051
  } = await this.loadSpatialDataAttrs(tablePath);
2902
3052
  indexPath = `${obsPath}/${instanceKey}`;
2903
3053
  }
2904
- if (this.obsIndex[indexPath]) {
2905
- return this.obsIndex[indexPath];
3054
+ if (indexPath in this.obsIndices) {
3055
+ return this.obsIndices[indexPath];
2906
3056
  }
2907
- this.obsIndex[indexPath] = this._loadColumn(indexPath);
2908
- return this.obsIndex[indexPath];
3057
+ this.obsIndices[indexPath] = this._loadColumn(indexPath);
3058
+ return this.obsIndices[indexPath];
2909
3059
  }
2910
3060
  /**
2911
3061
  * Class method for loading the var index.
2912
- * @returns {Promise} An promise for a zarr array containing the indices.
3062
+ * @param {string|undefined} path
3063
+ * @returns {Promise<string[]>} An promise for a zarr array containing the indices.
2913
3064
  */
2914
- loadVarIndex(path = null) {
2915
- if (!this.varIndex) {
2916
- this.varIndex = {};
2917
- }
3065
+ loadVarIndex(path = void 0) {
2918
3066
  const varPath = getVarPath(path);
2919
- if (this.varIndex[varPath]) {
2920
- return this.varIndex[varPath];
3067
+ if (varPath in this.varIndices) {
3068
+ return this.varIndices[varPath];
2921
3069
  }
2922
- this.varIndex[varPath] = this.getJson(`${varPath}/.zattrs`).then(({ _index }) => this.getFlatArrDecompressed(`${varPath}/${_index}`));
2923
- return this.varIndex[varPath];
3070
+ this.varIndices[varPath] = this.getJson(`${varPath}/.zattrs`).then(({ _index }) => this.getFlatArrDecompressed(`${varPath}/${_index}`));
3071
+ return this.varIndices[varPath];
2924
3072
  }
2925
3073
  /**
2926
3074
  * Class method for loading the var alias.
2927
- * @returns {Promise} An promise for a zarr array containing the aliased names.
3075
+ * @param {string} varPath
3076
+ * @param {string} matrixPath
3077
+ * @returns {Promise<string[]>} An promise for a zarr array containing the aliased names.
2928
3078
  */
2929
3079
  async loadVarAlias(varPath, matrixPath) {
2930
- if (!this.varAlias) {
2931
- this.varAlias = {};
2932
- }
2933
- if (this.varAlias[varPath]) {
2934
- return this.varAlias[varPath];
3080
+ if (varPath in this.varAliases) {
3081
+ return this.varAliases[varPath];
2935
3082
  }
2936
3083
  const [varAliasData] = await this.loadVarColumns([varPath]);
2937
- this.varAlias[varPath] = varAliasData;
3084
+ this.varAliases[varPath] = /** @type {string[]} */
3085
+ varAliasData;
2938
3086
  const index2 = await this.loadVarIndex(matrixPath);
2939
- this.varAlias[varPath] = this.varAlias[varPath].map(
3087
+ this.varAliases[varPath] = this.varAliases[varPath].map(
2940
3088
  (val, ind) => val ? val.concat(` (${index2[ind]})`) : index2[ind]
2941
3089
  );
2942
- return this.varAlias[varPath];
3090
+ return this.varAliases[varPath];
2943
3091
  }
2944
3092
  }
2945
3093
  class MatrixZarrAsObsFeatureMatrixLoader extends AbstractTwoStepLoader {
@@ -3312,20 +3460,29 @@ class ObsFeatureMatrixAnndataLoader extends AbstractTwoStepLoader {
3312
3460
  class ObsEmbeddingAnndataLoader extends AbstractTwoStepLoader {
3313
3461
  /**
3314
3462
  * Class method for loading embedding coordinates, such as those from UMAP or t-SNE.
3315
- * @returns {Promise} A promise for an array of columns.
3463
+ * @returns {Promise<MatrixResult>} A promise for an array of columns.
3316
3464
  */
3317
- loadEmbedding() {
3465
+ async loadEmbedding() {
3318
3466
  const { path, dims = [0, 1] } = this.options;
3319
3467
  if (this.embedding) {
3320
- return this.embedding;
3468
+ return (
3469
+ /** @type {Promise<MatrixResult>} */
3470
+ this.embedding
3471
+ );
3321
3472
  }
3322
3473
  if (!this.embedding) {
3323
3474
  this.embedding = this.dataSource.loadNumericForDims(path, dims);
3324
- return this.embedding;
3475
+ return (
3476
+ /** @type {Promise<MatrixResult>} */
3477
+ this.embedding
3478
+ );
3325
3479
  }
3326
- this.embedding = Promise.resolve(null);
3327
3480
  return this.embedding;
3328
3481
  }
3482
+ /**
3483
+ *
3484
+ * @returns {Promise<LoaderResult<ObsEmbeddingData>>}
3485
+ */
3329
3486
  async load() {
3330
3487
  const { path } = this.options;
3331
3488
  const superResult = await super.load().catch((reason) => Promise.resolve(reason));
@@ -3567,8 +3724,11 @@ const CoordinationType$1 = {
3567
3724
  PHOTOMETRIC_INTERPRETATION: "photometricInterpretation",
3568
3725
  // For 3D volume rendering
3569
3726
  SPATIAL_RENDERING_MODE: "spatialRenderingMode",
3727
+ // For whole spatial view
3570
3728
  VOLUMETRIC_RENDERING_ALGORITHM: "volumetricRenderingAlgorithm",
3729
+ // Could be per-image-layer
3571
3730
  SPATIAL_TARGET_RESOLUTION: "spatialTargetResolution",
3731
+ // Per-spatial-layer
3572
3732
  // For clipping plane sliders
3573
3733
  SPATIAL_SLICE_X: "spatialSliceX",
3574
3734
  SPATIAL_SLICE_Y: "spatialSliceY",
@@ -3577,10 +3737,12 @@ const CoordinationType$1 = {
3577
3737
  SPOT_LAYER: "spotLayer",
3578
3738
  POINT_LAYER: "pointLayer",
3579
3739
  SPATIAL_SPOT_RADIUS: "spatialSpotRadius",
3740
+ // In micrometers?
3580
3741
  SPATIAL_SPOT_FILLED: "spatialSpotFilled",
3581
3742
  SPATIAL_SPOT_STROKE_WIDTH: "spatialSpotStrokeWidth",
3582
3743
  SPATIAL_LAYER_COLOR: "spatialLayerColor",
3583
3744
  PIXEL_HIGHLIGHT: "pixelHighlight",
3745
+ // Per-image-layer
3584
3746
  TOOLTIP_CROSSHAIRS_VISIBLE: "tooltipCrosshairsVisible",
3585
3747
  LEGEND_VISIBLE: "legendVisible",
3586
3748
  SPATIAL_CHANNEL_LABELS_VISIBLE: "spatialChannelLabelsVisible",
@@ -123103,16 +123265,16 @@ function addDecoder(cases, importFn) {
123103
123265
  }
123104
123266
  cases.forEach((c) => registry$1.set(c, importFn));
123105
123267
  }
123106
- addDecoder([void 0, 1], () => import("./raw-8fdba750.js").then((m) => m.default));
123107
- addDecoder(5, () => import("./lzw-97464fce.js").then((m) => m.default));
123268
+ addDecoder([void 0, 1], () => import("./raw-a8de9c08.js").then((m) => m.default));
123269
+ addDecoder(5, () => import("./lzw-05e88e18.js").then((m) => m.default));
123108
123270
  addDecoder(6, () => {
123109
123271
  throw new Error("old style JPEG compression is not supported.");
123110
123272
  });
123111
- addDecoder(7, () => import("./jpeg-3ff942a5.js").then((m) => m.default));
123112
- addDecoder([8, 32946], () => import("./deflate-2f7f502f.js").then((m) => m.default));
123113
- addDecoder(32773, () => import("./packbits-daaf8f04.js").then((m) => m.default));
123114
- addDecoder(34887, () => import("./lerc-762cc666.js").then((m) => m.default));
123115
- addDecoder(50001, () => import("./webimage-e98ea52f.js").then((m) => m.default));
123273
+ addDecoder(7, () => import("./jpeg-dbb0f9d9.js").then((m) => m.default));
123274
+ addDecoder([8, 32946], () => import("./deflate-b162c7aa.js").then((m) => m.default));
123275
+ addDecoder(32773, () => import("./packbits-922f4592.js").then((m) => m.default));
123276
+ addDecoder(34887, () => import("./lerc-e45d57dc.js").then((m) => m.default));
123277
+ addDecoder(50001, () => import("./webimage-27013e2d.js").then((m) => m.default));
123116
123278
  function decodeRowAcc(row, stride) {
123117
123279
  let length2 = row.length - stride;
123118
123280
  let offset = 0;
@@ -149654,9 +149816,9 @@ class ObsLabelsAnndataLoader extends AbstractTwoStepLoader {
149654
149816
  class FeatureLabelsAnndataLoader extends AbstractTwoStepLoader {
149655
149817
  /**
149656
149818
  * Class method for loading feature string labels.
149657
- * @returns {Promise} A promise for the array.
149819
+ * @returns {Promise<string[]>} A promise for the array.
149658
149820
  */
149659
- loadLabels() {
149821
+ async loadLabels() {
149660
149822
  const { path } = this.options;
149661
149823
  if (this.labels) {
149662
149824
  return this.labels;
@@ -149665,9 +149827,12 @@ class FeatureLabelsAnndataLoader extends AbstractTwoStepLoader {
149665
149827
  this.labels = this.dataSource._loadColumn(path);
149666
149828
  return this.labels;
149667
149829
  }
149668
- this.labels = Promise.resolve(null);
149669
149830
  return this.labels;
149670
149831
  }
149832
+ /**
149833
+ *
149834
+ * @returns {Promise<LoaderResult<FeatureLabelsData>>}
149835
+ */
149671
149836
  async load() {
149672
149837
  const { path } = this.options;
149673
149838
  const superResult = await super.load().catch((reason) => Promise.resolve(reason));
@@ -149684,7 +149849,7 @@ class FeatureLabelsAnndataLoader extends AbstractTwoStepLoader {
149684
149849
  {
149685
149850
  featureIndex,
149686
149851
  featureLabels,
149687
- featureLabelsMap: new Map(featureIndex.map((key, i2) => [key, featureLabels[i2]]))
149852
+ featureLabelsMap: new Map(featureIndex.map((key, i2) => [key, featureLabels == null ? void 0 : featureLabels[i2]]))
149688
149853
  },
149689
149854
  null
149690
149855
  )));
@@ -149916,6 +150081,7 @@ class ImageWrapper {
149916
150081
  name: channel.Name || `Channel ${i2}`,
149917
150082
  defaultColor: channel.Color ? channel.Color : void 0,
149918
150083
  defaultWindow: void 0,
150084
+ // TODO: does OME-TIFF support this?
149919
150085
  autoDefaultColor: VIEWER_PALETTE[i2 % VIEWER_PALETTE.length]
149920
150086
  }));
149921
150087
  }