@@ -11,7 +11,7 @@ import {
1111 type NumArray ,
1212} from '@h5web/shared/vis-models' ;
1313import { createArrayFromView } from '@h5web/shared/vis-utils' ;
14- import ndarray , { type NdArray , type TypedArray } from 'ndarray' ;
14+ import ndarray , { type NdArray } from 'ndarray' ;
1515
1616import { type DimensionMapping } from '../../dimension-mapper/models' ;
1717import { isAxis } from '../../dimension-mapper/utils' ;
@@ -32,29 +32,27 @@ export const INTERACTIONS_WITH_AXIAL_ZOOM = [
3232 { shortcut : 'Ctrl+Shift+Drag' , description : 'Select to zoom in Y' } ,
3333] ;
3434
35- export function getBaseArray < T extends unknown [ ] | TypedArray | undefined > (
35+ export function getBaseArray < T extends ArrayValue | undefined > (
3636 value : T ,
3737 rawDims : number [ ] ,
38- ) : T extends unknown [ ] | TypedArray ? NdArray < T > : undefined ;
38+ ) : T extends ArrayValue ? NdArray < T > : undefined ;
3939
4040export function getBaseArray (
41- value : unknown [ ] | TypedArray | undefined ,
41+ value : ArrayValue | undefined ,
4242 rawDims : number [ ] ,
43- ) : NdArray < unknown [ ] | TypedArray > | undefined {
43+ ) : NdArray < ArrayValue > | undefined {
4444 return value && ndarray ( value , rawDims ) ;
4545}
4646
47- export function applyMapping <
48- T extends NdArray < unknown [ ] | TypedArray > | undefined ,
49- > (
47+ export function applyMapping < T extends NdArray < ArrayValue > | undefined > (
5048 baseArray : T ,
5149 mapping : ( number | Axis | ':' ) [ ] ,
52- ) : T extends NdArray < unknown [ ] | TypedArray > ? T : undefined ;
50+ ) : T extends NdArray < ArrayValue > ? T : undefined ;
5351
5452export function applyMapping (
55- baseArray : NdArray < unknown [ ] | TypedArray > | undefined ,
53+ baseArray : NdArray < ArrayValue > | undefined ,
5654 mapping : ( number | Axis | ':' ) [ ] ,
57- ) : NdArray < unknown [ ] | TypedArray > | undefined {
55+ ) : NdArray < ArrayValue > | undefined {
5856 if ( ! baseArray ) {
5957 return undefined ;
6058 }
@@ -95,12 +93,16 @@ export function getImageInteractions(keepRatio: boolean): InteractionInfo[] {
9593 return keepRatio ? BASE_INTERACTIONS : INTERACTIONS_WITH_AXIAL_ZOOM ;
9694}
9795
96+ function isBoolArray ( val : ArrayValue < NumericLikeType > ) : val is boolean [ ] {
97+ return Array . isArray ( val ) && typeof val [ 0 ] === 'boolean' ;
98+ }
99+
98100export function toNumArray ( arr : ArrayValue < NumericLikeType > ) : NumArray {
99- if ( typeof arr [ 0 ] === 'boolean' ) {
101+ if ( isBoolArray ( arr ) ) {
100102 return arr . map ( ( val ) => ( val ? 1 : 0 ) ) ;
101103 }
102104
103- return arr as NumArray ;
105+ return arr ;
104106}
105107
106108const TYPE_STRINGS : Record < NumericLikeType [ 'class' ] , string > = {
0 commit comments