@@ -4,7 +4,7 @@ import alignIO from './alignIO.ts';
44import { alignmentOf , customAlignmentOf } from './alignmentOf.ts' ;
55import { isUnstruct , type Unstruct } from './dataTypes.ts' ;
66import { sizeOf } from './sizeOf.ts' ;
7- import type { BaseData , WgslStruct } from './wgslTypes.ts' ;
7+ import type { WgslStruct } from './wgslTypes.ts' ;
88
99export interface OffsetInfo {
1010 offset : number ;
@@ -17,16 +17,18 @@ const cachedOffsets = new WeakMap<
1717 Record < string , OffsetInfo >
1818> ( ) ;
1919
20- export function offsetsForProps < T extends Record < string , BaseData > > (
21- struct : WgslStruct < T > | Unstruct < T > ,
22- ) : Record < keyof T , OffsetInfo > {
20+ export function offsetsForProps < T extends WgslStruct | Unstruct > (
21+ struct : T ,
22+ ) : Record < keyof T [ 'propTypes' ] , OffsetInfo > {
23+ type Key = keyof T [ 'propTypes' ] ;
24+
2325 const cached = cachedOffsets . get ( struct ) ;
2426 if ( cached ) {
25- return cached as Record < keyof T , OffsetInfo > ;
27+ return cached as Record < Key , OffsetInfo > ;
2628 }
2729
2830 const measurer = new Measurer ( ) ;
29- const offsets = { } as Record < keyof T , OffsetInfo > ;
31+ const offsets = { } as Record < Key , OffsetInfo > ;
3032 let lastEntry : OffsetInfo | undefined ;
3133
3234 for ( const key in struct . propTypes ) {
@@ -47,7 +49,7 @@ export function offsetsForProps<T extends Record<string, BaseData>>(
4749 }
4850
4951 const propSize = sizeOf ( prop ) ;
50- offsets [ key ] = { offset : measurer . size , size : propSize } ;
52+ offsets [ key as Key ] = { offset : measurer . size , size : propSize } ;
5153 lastEntry = offsets [ key ] ;
5254 measurer . add ( propSize ) ;
5355 }
@@ -57,12 +59,6 @@ export function offsetsForProps<T extends Record<string, BaseData>>(
5759 measurer . size ;
5860 }
5961
60- cachedOffsets . set (
61- struct as
62- | WgslStruct < Record < string , BaseData > >
63- | Unstruct < Record < string , BaseData > > ,
64- offsets ,
65- ) ;
66-
62+ cachedOffsets . set ( struct , offsets ) ;
6763 return offsets ;
6864}
0 commit comments