@@ -36,26 +36,41 @@ export interface SuggestFixInput {
3636 memberName ?: string ;
3737 suggestedName ?: string ;
3838 eventName ?: string ;
39+ /** Optional token prefix from the component's library (e.g. '--hx-', '--fast-'). When provided, suggested tokens use this prefix instead of generic placeholders. */
40+ tokenPrefix ?: string ;
3941}
4042
4143// ─── Token heuristics ────────────────────────────────────────────────────────
4244
43- const TOKEN_SUGGESTIONS : Record < string , string > = {
44- 'background-color' : '--sl-color-neutral-0' ,
45- background : '--sl-color-neutral-0' ,
46- color : '--sl-color-neutral-900' ,
47- 'border-color' : '--sl-color-neutral-300' ,
48- 'box-shadow' : '--sl-shadow-medium' ,
49- 'font-family' : '--sl-font-sans' ,
50- 'font-size' : '--sl-font-size-medium' ,
51- 'border-radius' : '--sl-border-radius-medium' ,
52- padding : '--sl-spacing-medium' ,
53- margin : '--sl-spacing-medium' ,
54- gap : '--sl-spacing-small' ,
45+ /** Maps CSS properties to semantic token suffixes (library-agnostic). */
46+ const TOKEN_SUFFIXES : Record < string , string > = {
47+ 'background-color' : 'color-neutral-0' ,
48+ background : 'color-neutral-0' ,
49+ color : 'color-neutral-900' ,
50+ 'border-color' : 'color-neutral-300' ,
51+ 'box-shadow' : 'shadow-medium' ,
52+ 'font-family' : 'font-sans' ,
53+ 'font-size' : 'font-size-medium' ,
54+ 'border-radius' : 'border-radius-medium' ,
55+ padding : 'spacing-medium' ,
56+ margin : 'spacing-medium' ,
57+ gap : 'spacing-small' ,
5558} ;
5659
57- function suggestTokenForProperty ( property : string ) : string {
58- return TOKEN_SUGGESTIONS [ property ] ?? '--your-design-token' ;
60+ /**
61+ * Suggests a token name for a CSS property. When a tokenPrefix is provided,
62+ * generates a library-specific token (e.g. `--hx-color-neutral-0`).
63+ * Without a prefix, returns a generic placeholder.
64+ */
65+ function suggestTokenForProperty ( property : string , tokenPrefix ?: string ) : string {
66+ const suffix = TOKEN_SUFFIXES [ property ] ;
67+ if ( ! suffix ) {
68+ return tokenPrefix ? `${ tokenPrefix } design-token` : '--your-design-token' ;
69+ }
70+ if ( tokenPrefix ) {
71+ return `${ tokenPrefix } ${ suffix } ` ;
72+ }
73+ return `--your-${ suffix } ` ;
5974}
6075
6176// ─── Shadow DOM fixes ────────────────────────────────────────────────────────
@@ -193,7 +208,7 @@ function fixShadowDom(input: SuggestFixInput): FixSuggestion {
193208// ─── Token fallback fixes ────────────────────────────────────────────────────
194209
195210function fixTokenFallback ( input : SuggestFixInput ) : FixSuggestion {
196- const { original, property } = input ;
211+ const { original, property, tokenPrefix } = input ;
197212
198213 if ( input . issue === 'missing-fallback' ) {
199214 // Extract the var() call and add a sensible fallback
@@ -223,7 +238,7 @@ function fixTokenFallback(input: SuggestFixInput): FixSuggestion {
223238 }
224239
225240 if ( input . issue === 'hardcoded-color' ) {
226- const token = suggestTokenForProperty ( property ?? 'color' ) ;
241+ const token = suggestTokenForProperty ( property ?? 'color' , tokenPrefix ) ;
227242 // Extract the property and value
228243 const propMatch = original . match ( / ( [ a - z - ] + ) \s * : \s * ( [ ^ ; ] + ) / i) ;
229244 if ( propMatch ) {
@@ -250,10 +265,10 @@ function fixTokenFallback(input: SuggestFixInput): FixSuggestion {
250265// ─── Theme compatibility fixes ───────────────────────────────────────────────
251266
252267function fixThemeCompat ( input : SuggestFixInput ) : FixSuggestion {
253- const { original, property } = input ;
268+ const { original, property, tokenPrefix } = input ;
254269
255270 if ( input . issue === 'hardcoded-color' ) {
256- const token = suggestTokenForProperty ( property ?? 'background' ) ;
271+ const token = suggestTokenForProperty ( property ?? 'background' , tokenPrefix ) ;
257272 const propMatch = original . match ( / ( [ a - z - ] + ) \s * : \s * ( [ ^ ; ] + ) / i) ;
258273 if ( propMatch ) {
259274 const [ , prop , value ] = propMatch ;
@@ -269,9 +284,11 @@ function fixThemeCompat(input: SuggestFixInput): FixSuggestion {
269284 }
270285
271286 if ( input . issue === 'contrast-pair' ) {
287+ const bgToken = suggestTokenForProperty ( 'background-color' , tokenPrefix ) ;
288+ const fgToken = suggestTokenForProperty ( 'color' , tokenPrefix ) ;
272289 return {
273290 original,
274- suggestion : `background: var(--sl-color-neutral-0 ); color: var(--sl-color-neutral-900 );` ,
291+ suggestion : `background: var(${ bgToken } ); color: var(${ fgToken } );` ,
275292 explanation : `Light-on-light or dark-on-dark color pairs create contrast issues. Use semantic token pairs (surface + on-surface) that maintain readable contrast across themes.` ,
276293 severity : 'warning' ,
277294 } ;
0 commit comments