@@ -253,6 +253,8 @@ export interface KnightRiderOptions {
253253 colors ?: ColorInput [ ]
254254 /** Single color to derive trail from (alternative to providing colors array) */
255255 color ?: ColorInput
256+ /** Optional luminous head color while the trail remains derived from color */
257+ headColor ?: ColorInput
256258 /** Number of trail steps when using single color (default: 6) */
257259 trailSteps ?: number
258260 defaultColor ?: ColorInput
@@ -264,6 +266,26 @@ export interface KnightRiderOptions {
264266 minAlpha ?: number
265267}
266268
269+ function trailColors ( options : KnightRiderOptions ) {
270+ if ( options . colors ) return options . colors
271+ if ( options . color ) {
272+ const colors = deriveTrailColors ( options . color , options . trailSteps )
273+ if ( ! options . headColor ) return colors
274+ return [
275+ options . headColor instanceof RGBA ? options . headColor : RGBA . fromHex ( options . headColor as string ) ,
276+ ...colors . slice ( 1 ) ,
277+ ]
278+ }
279+ return [
280+ RGBA . fromHex ( "#ff0000" ) ,
281+ RGBA . fromHex ( "#ff5555" ) ,
282+ RGBA . fromHex ( "#dd0000" ) ,
283+ RGBA . fromHex ( "#aa0000" ) ,
284+ RGBA . fromHex ( "#770000" ) ,
285+ RGBA . fromHex ( "#440000" ) ,
286+ ]
287+ }
288+
267289/**
268290 * Creates frame strings for a Knight Rider style scanner animation
269291 * @param options Configuration options for the Knight Rider effect
@@ -275,18 +297,7 @@ export function createFrames(options: KnightRiderOptions = {}): string[] {
275297 const holdStart = options . holdStart ?? 30
276298 const holdEnd = options . holdEnd ?? 9
277299
278- const colors =
279- options . colors ??
280- ( options . color
281- ? deriveTrailColors ( options . color , options . trailSteps )
282- : [
283- RGBA . fromHex ( "#ff0000" ) , // Brightest Red (Center)
284- RGBA . fromHex ( "#ff5555" ) , // Glare/Bloom
285- RGBA . fromHex ( "#dd0000" ) , // Trail 1
286- RGBA . fromHex ( "#aa0000" ) , // Trail 2
287- RGBA . fromHex ( "#770000" ) , // Trail 3
288- RGBA . fromHex ( "#440000" ) , // Trail 4
289- ] )
300+ const colors = trailColors ( options )
290301
291302 const defaultColor =
292303 options . defaultColor ??
@@ -337,18 +348,7 @@ export function createColors(options: KnightRiderOptions = {}): ColorGenerator {
337348 const holdStart = options . holdStart ?? 30
338349 const holdEnd = options . holdEnd ?? 9
339350
340- const colors =
341- options . colors ??
342- ( options . color
343- ? deriveTrailColors ( options . color , options . trailSteps )
344- : [
345- RGBA . fromHex ( "#ff0000" ) , // Brightest Red (Center)
346- RGBA . fromHex ( "#ff5555" ) , // Glare/Bloom
347- RGBA . fromHex ( "#dd0000" ) , // Trail 1
348- RGBA . fromHex ( "#aa0000" ) , // Trail 2
349- RGBA . fromHex ( "#770000" ) , // Trail 3
350- RGBA . fromHex ( "#440000" ) , // Trail 4
351- ] )
351+ const colors = trailColors ( options )
352352
353353 const defaultColor =
354354 options . defaultColor ??
0 commit comments