File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,13 +8,36 @@ const defaultFontUrl = '/fonts/orbitron.woff2';
88
99export const themes : { [ key : string ] : Theme } = { ...baseThemes , ...graphThemes } ;
1010
11+ /**
12+ * Normalises a theme name for fuzzy lookup:
13+ * lower-case + collapse spaces / underscores / hyphens to a single hyphen.
14+ * e.g. "Tokyo Night", "tokyoNight", "tokyo_night" all → "tokyo-night"
15+ */
16+ function normalizeKey ( name : string ) : string {
17+ return name . toLowerCase ( ) . replace ( / [ \s _ ] + / g, '-' ) ;
18+ }
19+
20+ /** Pre-built map: normalised key → original themes key */
21+ const themeIndex : Map < string , string > = new Map (
22+ Object . keys ( themes ) . map ( k => [ normalizeKey ( k ) , k ] )
23+ ) ;
24+
25+ /** Resolve a user-supplied theme name to the actual themes key, or 'default'. */
26+ function resolveThemeName ( name : string ) : string {
27+ // Exact match first (fast path)
28+ if ( themes [ name ] ) return name ;
29+ // Normalised match (case / separator insensitive)
30+ const resolved = themeIndex . get ( normalizeKey ( name ) ) ;
31+ return resolved ?? 'default' ;
32+ }
33+
1134export function getTheme ( themeName : string = 'default' , customColors ?: {
1235 bgColor ?: string ;
1336 borderColor ?: string ;
1437 textColor ?: string ;
1538 titleColor ?: string ;
1639} ) : Theme {
17- const theme = themes [ themeName ] || themes . default ;
40+ const theme = themes [ resolveThemeName ( themeName ) ] ;
1841
1942 return {
2043 ...themes . default ,
You can’t perform that action at this time.
0 commit comments