feat(spice): registerSpiceMapper seam for overlay-registered components

componentToSpice/isSpiceMapped now consult a pro-registered mapper table after
the static MAPPERS, so a private build can give its closed components a SPICE
model (e.g. the DFRobot Gravity analog sensors emit a voltage source at AOUT).
Empty in a pure OSS build. Mapper type exported.
This commit is contained in:
David Montero Crespo 2026-07-24 03:56:15 +02:00
parent a9fcf69035
commit 57ffc5c085
1 changed files with 13 additions and 3 deletions

View File

@ -31,7 +31,7 @@ export interface MapperContext {
vcc: number;
}
type Mapper = (
export type Mapper = (
comp: ComponentForSpice,
netLookup: NetLookup,
ctx: MapperContext,
@ -1287,19 +1287,29 @@ MAPPERS['photoresistor-sensor'] = MAPPERS['photoresistor'];
* Returns null if we have no mapping for this metadataId (caller should
* skip the component gracefully it just won't participate in the solve).
*/
// Overlay seam: a private build registers SPICE mappers for components it
// ships outside the OSS tree (e.g. the DFRobot Gravity analog sensors emit a
// voltage source at AOUT). Same contract as the other pro seams — empty in a
// pure OSS build. Consulted after the static MAPPERS so OSS mappings win.
const proMappers: Record<string, Mapper> = {};
export function registerSpiceMapper(id: string, mapper: Mapper): void {
proMappers[id] = mapper;
}
export function componentToSpice(
comp: ComponentForSpice,
netLookup: NetLookup,
ctx: MapperContext,
): SpiceEmission | null {
const mapper = MAPPERS[comp.metadataId];
const mapper = MAPPERS[comp.metadataId] ?? proMappers[comp.metadataId];
if (!mapper) return null;
return mapper(comp, netLookup, ctx);
}
/** True if we have a mapping for this metadataId. */
export function isSpiceMapped(metadataId: string): boolean {
return metadataId in MAPPERS;
return metadataId in MAPPERS || metadataId in proMappers;
}
/** All metadataIds with a SPICE mapping (for docs / UI hints). */