@@ -5,13 +5,18 @@ import { TOWER_ANIMATION_CSS } from './animations';
55import { computeTowers , type TowerData } from './layout' ;
66import { sanitizeFont , sanitizeHexColor , sanitizeRadius , sanitizeGoogleFontUrl } from './sanitizer' ;
77
8- import { SVG_WIDTH , SVG_HEIGHT , FONT_MAP } from './constants ' ;
8+ import { SVG_WIDTH , SVG_HEIGHT , FONT_MAP , isFontKey } from './generatorConstants ' ;
99
1010// helpers
1111function truncateUsername ( name : string , max = 20 ) : string {
1212 return name . length > max ? name . slice ( 0 , max ) + '…' : name ;
1313}
1414
15+ function getFontFromMap ( font : string | null ) : string | null {
16+ if ( ! font ) return null ;
17+ const f = font . toLowerCase ( ) ;
18+ return isFontKey ( f ) ? FONT_MAP [ f ] : null ;
19+ }
1520function getSizeScale ( size ?: 'small' | 'medium' | 'large' ) : number {
1621 if ( size === 'small' ) return 400 / SVG_WIDTH ;
1722 if ( size === 'large' ) return 800 / SVG_WIDTH ;
@@ -256,7 +261,7 @@ export function generateSVG(
256261 const text = `#${ sanitizeHexColor ( params . text , 'ffffff' ) } ` ;
257262
258263 const sanitizedFont = sanitizeFont ( params . font ) ;
259- const predefinedFont = sanitizedFont ? FONT_MAP [ sanitizedFont . toLowerCase ( ) ] : null ;
264+ const predefinedFont = getFontFromMap ( sanitizedFont ) ;
260265 const isPredefinedFont = Boolean ( predefinedFont ) ;
261266 const selectedFont = isPredefinedFont
262267 ? predefinedFont
@@ -300,7 +305,7 @@ function generateAutoThemeSVG(
300305 const safeUser = escapeXML ( params . user || 'GitHub User' ) ;
301306 const sanitizedFont = sanitizeFont ( params . font ) ;
302307 const selectedFont = sanitizedFont
303- ? FONT_MAP [ sanitizedFont . toLowerCase ( ) ] || `"${ sanitizedFont } ", sans-serif`
308+ ? getFontFromMap ( sanitizedFont ) || `"${ sanitizedFont } ", sans-serif`
304309 : null ;
305310 const statsFont = selectedFont || '"Space Grotesk", sans-serif' ;
306311 const sf = getSizeScale ( params . size ) ;
@@ -402,7 +407,7 @@ export function generateMonthlySVG(stats: MonthlyStats, params: BadgeParams): st
402407
403408 const sanitizeFont = ( name : string ) => name . replace ( / [ ^ a - z A - Z 0 - 9 \s - ] / g, '' ) . trim ( ) ;
404409 const sanitizedFont = params . font ? sanitizeFont ( params . font ) : null ;
405- const predefinedFont = sanitizedFont ? FONT_MAP [ sanitizedFont . toLowerCase ( ) ] : null ;
410+ const predefinedFont = getFontFromMap ( sanitizedFont ) ;
406411 const isPredefinedFont = Boolean ( predefinedFont ) ;
407412 const selectedFont = isPredefinedFont
408413 ? predefinedFont
@@ -489,7 +494,7 @@ function generateAutoThemeMonthlySVG(stats: MonthlyStats, params: BadgeParams):
489494 const safeUser = escapeXML ( params . user || 'GitHub User' ) ;
490495 const sanitizeFont = ( name : string ) => name . replace ( / [ ^ a - z A - Z 0 - 9 \s - ] / g, '' ) . trim ( ) ;
491496 const sanitizedFont = params . font ? sanitizeFont ( params . font ) : null ;
492- const predefinedFont = sanitizedFont ? FONT_MAP [ sanitizedFont . toLowerCase ( ) ] : null ;
497+ const predefinedFont = getFontFromMap ( sanitizedFont ) ;
493498 const isPredefinedFont = Boolean ( predefinedFont ) ;
494499 const selectedFont = isPredefinedFont
495500 ? predefinedFont
0 commit comments