@@ -120,10 +120,20 @@ export class Flash extends Directive {
120120 return ;
121121 }
122122
123- // Store original values
124- this . originalAlpha = flashProps . originalAlpha ?? instance . alpha ?? 1 ;
123+ // Store original values once at mount time
124+ // Only set if not already stored (to preserve values from first mount)
125+ if ( this . originalAlpha === 1 && ! flashProps . originalAlpha ) {
126+ this . originalAlpha = instance . alpha ?? 1 ;
127+ } else if ( flashProps . originalAlpha !== undefined ) {
128+ this . originalAlpha = flashProps . originalAlpha ;
129+ }
130+
125131 const currentTint = ( instance as any ) . tint ;
126- this . originalTint = flashProps . originalTint ?? ( isSignal ( currentTint ) ? currentTint ( ) : currentTint ) ?? 0xffffff ;
132+ if ( this . originalTint === 0xffffff && ! flashProps . originalTint ) {
133+ this . originalTint = ( isSignal ( currentTint ) ? currentTint ( ) : currentTint ) ?? 0xffffff ;
134+ } else if ( flashProps . originalTint !== undefined ) {
135+ this . originalTint = flashProps . originalTint ;
136+ }
127137
128138 // Listen to trigger activation
129139 this . flashSubscription = on ( flashProps . trigger , async ( data ) => {
@@ -157,18 +167,20 @@ export class Flash extends Directive {
157167 const flashProps = this . flashProps ;
158168
159169 // Use data from trigger to override defaults if provided
160- const type = data ?. type ?? flashProps . type ( ) ;
161- const duration = data ?. duration ?? flashProps . duration ( ) ;
162- const cycles = data ?. cycles ?? flashProps . cycles ( ) ;
163- const flashAlpha = data ?. alpha ?? flashProps . alpha ( ) ;
164- const flashTint = data ?. tint ?? flashProps . tint ( ) ;
170+ const type = data ?. type ?? ( typeof flashProps . type === 'function' ? flashProps . type ( ) : flashProps . type ) ;
171+ const duration = data ?. duration ?? ( typeof flashProps . duration === 'function' ? flashProps . duration ( ) : flashProps . duration ) ;
172+ const cycles = data ?. cycles ?? ( typeof flashProps . cycles === 'function' ? flashProps . cycles ( ) : flashProps . cycles ) ;
173+ const flashAlpha = data ?. alpha ?? ( typeof flashProps . alpha === 'function' ? flashProps . alpha ( ) : flashProps . alpha ) ;
174+ const flashTint = data ?. tint ?? ( typeof flashProps . tint === 'function' ? flashProps . tint ( ) : flashProps . tint ) ;
165175
166- // Store original values if not already stored
167- this . originalAlpha = flashProps . originalAlpha ?? instance . alpha ?? 1 ;
168- const currentTint = ( instance as any ) . tint ;
169- this . originalTint = flashProps . originalTint ?? ( isSignal ( currentTint ) ? currentTint ( ) : currentTint ) ?? 0xffffff ;
176+ // Stop any existing animation first
177+ if ( this . progressSignal ) {
178+ // Stop the animation immediately
179+ this . progressSignal . set ( 0 , { duration : 0 } ) ;
180+ }
170181
171- // Stop any existing animation and clean up
182+ // Clean up effects BEFORE restoring values
183+ // This prevents effects from continuing to update values after we restore
172184 if ( this . alphaEffect ) {
173185 this . alphaEffect . unsubscribe ( ) ;
174186 this . alphaEffect = null ;
@@ -178,12 +190,20 @@ export class Flash extends Directive {
178190 this . tintEffect = null ;
179191 }
180192
181- // Restore original values before starting new flash
193+ // Always restore to original values immediately after stopping effects
194+ // This ensures that if a new flash starts before the previous one completes,
195+ // we restore to the true original values, not the intermediate animation values
182196 instance . alpha = this . originalAlpha ;
183- if ( ( instance as any ) . tint !== undefined ) {
197+ const currentTint = ( instance as any ) . tint ;
198+ if ( currentTint !== undefined ) {
184199 // Ensure originalTint is a primitive value, not a signal
185200 const tintValue = typeof this . originalTint === 'number' ? this . originalTint : 0xffffff ;
186- ( instance as any ) . tint = tintValue ;
201+ // Handle both signal and primitive tint
202+ if ( isSignal ( currentTint ) ) {
203+ currentTint . set ( tintValue ) ;
204+ } else {
205+ ( instance as any ) . tint = tintValue ;
206+ }
187207 }
188208
189209 // Call onStart callback
@@ -199,17 +219,17 @@ export class Flash extends Directive {
199219 } ;
200220
201221 // Create or recreate progress signal for flash animation
202- if ( this . progressSignal ) {
203- // Reset to 0 immediately without animation
204- this . progressSignal . set ( 0 , { duration : 0 } ) ;
205- // Wait a bit to ensure the reset is complete
206- await new Promise ( resolve => setTimeout ( resolve , 0 ) ) ;
207- } else {
222+ // Note: We already stopped the previous animation above, so we can reuse the signal
223+ if ( ! this . progressSignal ) {
208224 this . progressSignal = animatedSignal ( 0 , {
209225 duration : duration ,
210226 ease : ( t ) => t , // Linear ease
211227 } ) ;
212228 }
229+ // Reset to 0 immediately without animation to start fresh
230+ this . progressSignal . set ( 0 , { duration : 0 } ) ;
231+ // Wait a bit to ensure the reset is complete before starting new animation
232+ await new Promise ( resolve => setTimeout ( resolve , 0 ) ) ;
213233
214234 // Create effect to update alpha based on progress
215235 if ( type === 'alpha' || type === 'both' ) {
@@ -239,8 +259,14 @@ export class Flash extends Directive {
239259 if ( type === 'tint' || type === 'both' ) {
240260 this . tintEffect = effect ( ( ) => {
241261 if ( ! instance || ! this . progressSignal || ! this . currentFlashConfig ) return ;
242- if ( ( instance as any ) . tint === undefined ) return ;
243-
262+
263+ // Get current tint value - handle both signal and primitive
264+ const currentTint = ( instance as any ) . tint ;
265+ if ( currentTint === undefined ) return ;
266+
267+ // Check if tint is a signal
268+ const tintIsSignal = isSignal ( currentTint ) ;
269+
244270 const progress = this . progressSignal ( ) ;
245271 const config = this . currentFlashConfig ;
246272
@@ -266,7 +292,14 @@ export class Flash extends Directive {
266292 const g = Math . round ( g1 + ( g2 - g1 ) * flashPhase ) ;
267293 const b = Math . round ( b1 + ( b2 - b1 ) * flashPhase ) ;
268294
269- ( instance as any ) . tint = ( r << 16 ) | ( g << 8 ) | b ;
295+ const newTintValue = ( r << 16 ) | ( g << 8 ) | b ;
296+
297+ // Handle both signal and primitive tint
298+ if ( tintIsSignal ) {
299+ currentTint . set ( newTintValue ) ;
300+ } else {
301+ ( instance as any ) . tint = newTintValue ;
302+ }
270303 } ) . subscription ;
271304 }
272305
@@ -279,10 +312,16 @@ export class Flash extends Directive {
279312 // Restore original values
280313 if ( instance ) {
281314 instance . alpha = this . originalAlpha ;
282- if ( ( instance as any ) . tint !== undefined ) {
315+ const currentTint = ( instance as any ) . tint ;
316+ if ( currentTint !== undefined ) {
283317 // Ensure originalTint is a primitive value, not a signal
284318 const tintValue = typeof this . originalTint === 'number' ? this . originalTint : 0xffffff ;
285- ( instance as any ) . tint = tintValue ;
319+ // Handle both signal and primitive tint
320+ if ( isSignal ( currentTint ) ) {
321+ currentTint . set ( tintValue ) ;
322+ } else {
323+ ( instance as any ) . tint = tintValue ;
324+ }
286325 }
287326 }
288327
@@ -344,10 +383,16 @@ export class Flash extends Directive {
344383 if ( this . elementRef ?. componentInstance ) {
345384 const instance = this . elementRef . componentInstance ;
346385 instance . alpha = this . originalAlpha ;
347- if ( ( instance as any ) . tint !== undefined ) {
386+ const currentTint = ( instance as any ) . tint ;
387+ if ( currentTint !== undefined ) {
348388 // Ensure originalTint is a primitive value, not a signal
349389 const tintValue = typeof this . originalTint === 'number' ? this . originalTint : 0xffffff ;
350- ( instance as any ) . tint = tintValue ;
390+ // Handle both signal and primitive tint
391+ if ( isSignal ( currentTint ) ) {
392+ currentTint . set ( tintValue ) ;
393+ } else {
394+ ( instance as any ) . tint = tintValue ;
395+ }
351396 }
352397 }
353398
0 commit comments