@@ -11,7 +11,6 @@ import {
1111 sanitizeRadius ,
1212 sanitizeGoogleFontUrl ,
1313 getLuminance ,
14- normalizeHexColor ,
1514 parseGradientStops ,
1615 getGradientCoordinates ,
1716} from './sanitizer' ;
@@ -158,15 +157,16 @@ function renderHeader(
158157
159158/**
160159 * Generates custom SVG gradient definitions from gradient_stops and gradient_dir parameters.
161- * Returns a string of linearGradient elements for each intensity level (1-4).
162- * If custom stops are invalid or insufficient, returns an empty string (fallback to default behavior).
160+ * Returns an object with gradient SVG elements and the gradient ID (or empty string if invalid).
161+ * If custom stops are invalid or insufficient, returns { gradients: '', gradientId: '' }.
162+ * Also stores the gradient ID on the params object for tower rendering to use.
163163 */
164- function generateCustomGradients ( params : BadgeParams , bgHex : string ) : string {
164+ function generateCustomGradients ( params : BadgeParams ) : { gradients : string ; gradientId : string } {
165165 const stops = parseGradientStops ( params . gradient_stops ) ;
166166
167167 // Require at least 2 valid colors for custom gradient
168168 if ( stops . length < 2 ) {
169- return '' ;
169+ return { gradients : '' , gradientId : '' } ;
170170 }
171171
172172 const coords = getGradientCoordinates ( params . gradient_dir ) ;
@@ -207,10 +207,10 @@ ${stopElements}
207207 </linearGradient>` ;
208208 }
209209
210- // Store the gradient ID in a temporary attribute so tower rendering can use it
211- ( params as any ) . __customGradientId = gradientId ;
210+ // Store the gradient ID on params for tower rendering to use
211+ params . __customGradientId = gradientId ;
212212
213- return gradients ;
213+ return { gradients, gradientId } ;
214214}
215215
216216function renderDefs ( sf : number , params : BadgeParams ) : string {
@@ -219,15 +219,15 @@ function renderDefs(sf: number, params: BadgeParams): string {
219219 let gradients = '' ;
220220 if ( params . gradient ) {
221221 // Try to use custom gradient if gradient_stops is provided
222- const bgStr = params . bg || '0d1117' ;
223- const bgHex = bgStr . startsWith ( '#' ) ? bgStr : `#${ bgStr } ` ;
224-
225- const customGradients = generateCustomGradients ( params , bgHex ) ;
226- if ( customGradients ) {
222+ const result = generateCustomGradients ( params ) ;
223+ if ( result . gradientId ) {
227224 // Custom gradient stops were valid and used
228- gradients = customGradients ;
225+ gradients = result . gradients ;
229226 } else {
230227 // Fallback to default gradient behavior
228+ const bgStr = params . bg || '0d1117' ;
229+ const bgHex = bgStr . startsWith ( '#' ) ? bgStr : `#${ bgStr } ` ;
230+
231231 if ( params . autoTheme ) {
232232 for ( let i = 0 ; i < 4 ; i ++ ) {
233233 const level = i + 1 ;
@@ -245,7 +245,9 @@ function renderDefs(sf: number, params: BadgeParams): string {
245245 const c = accent [ idx ] || accent [ accent . length - 1 ] || '00ffaa' ;
246246 return c . startsWith ( '#' ) ? c : `#${ c } ` ;
247247 } )
248- : [ 0 , 1 , 2 , 3 ] . map ( ( ) => ( String ( accent ) . startsWith ( '#' ) ? String ( accent ) : `#${ accent } ` ) ) ;
248+ : [ 0 , 1 , 2 , 3 ] . map ( ( ) =>
249+ String ( accent ) . startsWith ( '#' ) ? String ( accent ) : `#${ accent } `
250+ ) ;
249251
250252 colors . forEach ( ( c , idx ) => {
251253 const level = idx + 1 ;
@@ -405,7 +407,7 @@ function renderTowers(
405407
406408 if ( ! isGhost && t . intensityLevel > 0 && params . gradient === true ) {
407409 // Use custom gradient ID if available, otherwise use default gradient ID
408- const customGradId = ( params as any ) . __customGradientId ;
410+ const customGradId = params . __customGradientId ;
409411 const gradId = customGradId
410412 ? `${ customGradId } -level-${ t . intensityLevel } `
411413 : `tower-grad-level-${ t . intensityLevel } ` ;
0 commit comments