@ -1,4 +1,4 @@
import type { PropDef } from '../types/props.js' ;
import type { PropDef , PropTypesFromTable } from '../types/props.js' ;
import type { LatLngBoundsExpression } from 'leaflet' ;
import type { LatLngBoundsExpression } from 'leaflet' ;
// Converts kebab-case to camelCase (e.g. "fill-color" → "fillColor").
// Converts kebab-case to camelCase (e.g. "fill-color" → "fillColor").
@ -108,12 +108,20 @@ export function setLayerAttr(
// constructors, like coordinates or URLs). Null attributes use the
// constructors, like coordinates or URLs). Null attributes use the
// default from PROPS if one exists (skipping empty-string defaults to
// default from PROPS if one exists (skipping empty-string defaults to
// avoid Leaflet rejecting them).
// avoid Leaflet rejecting them).
export function buildOptions (
//
// The return type is derived from the PROPS table: each prop name maps
// to its kind's value type (number for `num`, boolean for `bool-on`/`bool-off`,
// string for `str`). The `const` type parameter makes literal exclude arrays
// narrow correctly so excluded keys are stripped from the return type.
export function buildOptions <
TProps extends Record < string , PropDef > ,
const TExclude extends readonly string [ ] = [ ] ,
> (
el : HTMLElement ,
el : HTMLElement ,
props : Record < string , PropDef > ,
props : TProps ,
exclude : string [ ] = [ ] ,
exclude : TExclude = [ ] as unknown as TExclude ,
) : Record < string , unknown > {
) : Omit< PropTypesFromTable < TProps > , TExclude [ number ] > {
const opts : Record < string , unknown > = { } ;
const opts = { } as Record< string , unknown > ;
for ( const [ propName , spec ] of Object . entries ( props ) ) {
for ( const [ propName , spec ] of Object . entries ( props ) ) {
if ( exclude . includes ( propName ) ) continue ;
if ( exclude . includes ( propName ) ) continue ;
const val = el . getAttribute ( spec . attr ) ;
const val = el . getAttribute ( spec . attr ) ;
@ -126,7 +134,7 @@ export function buildOptions(
else if ( spec . kind === 'bool-off' ) opts [ propName ] = false ;
else if ( spec . kind === 'bool-off' ) opts [ propName ] = false ;
else opts [ propName ] = val ;
else opts [ propName ] = val ;
}
}
return opts ;
return opts as Omit < PropTypesFromTable < TProps > , TExclude [ number ] > ;
}
}
// Dispatches a custom `leaflet-register` event upward through the DOM
// Dispatches a custom `leaflet-register` event upward through the DOM