1- import { animate , state , style , transition , trigger } from '@angular/animations' ;
1+ import { animate , AnimationMetadata , state , style , transition , trigger } from '@angular/animations' ;
22import {
33 AfterViewInit , ChangeDetectorRef , Directive , ElementRef , EventEmitter , Input , NgZone , OnDestroy , OnInit , Output , ViewChild
44} from '@angular/core' ;
@@ -70,7 +70,7 @@ const checkForRepeatedKeyTimestamps = isIOS();
7070const disableContentEditable = isEdge ( ) ;
7171const useHiddenInput = isAndroid ( ) || isChromeOS ( ) ;
7272
73- function getBackgroundColor ( className : string , darkMode = false ) : string {
73+ function getBackgroundColor ( className : string , defaultColor : string , darkMode = false ) : string {
7474 const outer = document . createElement ( 'div' ) ;
7575 const elem = document . createElement ( 'div' ) ;
7676
@@ -84,7 +84,7 @@ function getBackgroundColor(className: string, darkMode = false): string {
8484 document . body . removeChild ( outer ) ;
8585
8686 if ( result === 'transparent' || result === 'rgba(0, 0, 0, 0)' )
87- result = 'white' ;
87+ result = defaultColor ;
8888
8989 return result ;
9090}
@@ -129,32 +129,42 @@ const WARNING_BACKGROUND = 'tbw-warning-background';
129129
130130const DOT_DOT_TYPING_INTERVAL = 500 ;
131131
132- export const BACKGROUND_ANIMATIONS = trigger ( 'displayState' , [
133- state ( 'error' , style ( { backgroundColor : getBackgroundColor ( ERROR_BACKGROUND ) } ) ) ,
134- state ( 'normal' , style ( { backgroundColor : getBackgroundColor ( NORMAL_BACKGROUND ) } ) ) ,
135- state ( 'confirm' , style ( { backgroundColor : getBackgroundColor ( CONFIRM_BACKGROUND ) } ) ) ,
136- state ( 'warning' , style ( { backgroundColor : getBackgroundColor ( WARNING_BACKGROUND ) } ) ) ,
137- state ( 'view-only' , style ( { backgroundColor : getBackgroundColor ( VIEW_ONLY_BACKGROUND ) } ) ) ,
138- state ( 'disabled' , style ( { backgroundColor : getBackgroundColor ( DISABLED_BACKGROUND ) } ) ) ,
139- state ( 'dark-error' , style ( { backgroundColor : getBackgroundColor ( ERROR_BACKGROUND , true ) } ) ) ,
140- state ( 'dark-normal' , style ( { backgroundColor : getBackgroundColor ( NORMAL_BACKGROUND , true ) } ) ) ,
141- state ( 'dark-confirm' , style ( { backgroundColor : getBackgroundColor ( CONFIRM_BACKGROUND , true ) } ) ) ,
142- state ( 'dark-warning' , style ( { backgroundColor : getBackgroundColor ( WARNING_BACKGROUND , true ) } ) ) ,
143- state ( 'dark-view-only' , style ( { backgroundColor : getBackgroundColor ( VIEW_ONLY_BACKGROUND , true ) } ) ) ,
144- state ( 'dark-disabled' , style ( { backgroundColor : getBackgroundColor ( DISABLED_BACKGROUND , true ) } ) ) ,
145- transition ( 'normal => error' , animate ( FLASH_DURATION ) ) ,
146- transition ( 'error => normal' , animate ( FLASH_DURATION ) ) ,
147- transition ( 'normal => confirm' , animate ( FLASH_DURATION ) ) ,
148- transition ( 'confirm => normal' , animate ( FLASH_DURATION ) ) ,
149- transition ( 'warning => error' , animate ( FLASH_DURATION ) ) ,
150- transition ( 'error => warning' , animate ( FLASH_DURATION ) ) ,
151- transition ( 'dark-normal => dark-error' , animate ( FLASH_DURATION ) ) ,
152- transition ( 'dark-error => dark-normal' , animate ( FLASH_DURATION ) ) ,
153- transition ( 'dark-normal => dark-confirm' , animate ( FLASH_DURATION ) ) ,
154- transition ( 'dark-confirm => dark-normal' , animate ( FLASH_DURATION ) ) ,
155- transition ( 'dark-warning => dark-error' , animate ( FLASH_DURATION ) ) ,
156- transition ( 'dark-error => dark-warning' , animate ( FLASH_DURATION ) )
157- ] ) ;
132+ const stateDefinitions : AnimationMetadata [ ] = [ ] ;
133+ let stateDefinitionsRefreshed = false ;
134+
135+ function updateStateDefinitions ( ) : void {
136+ stateDefinitions . length = 0 ;
137+ stateDefinitions . push ( ...[
138+ state ( 'error' , style ( { backgroundColor : getBackgroundColor ( ERROR_BACKGROUND , '#F67' ) } ) ) ,
139+ state ( 'normal' , style ( { backgroundColor : getBackgroundColor ( NORMAL_BACKGROUND , 'white' ) } ) ) ,
140+ state ( 'confirm' , style ( { backgroundColor : getBackgroundColor ( CONFIRM_BACKGROUND , '#6C6' ) } ) ) ,
141+ state ( 'warning' , style ( { backgroundColor : getBackgroundColor ( WARNING_BACKGROUND , '#FC6' ) } ) ) ,
142+ state ( 'view-only' , style ( { backgroundColor : getBackgroundColor ( VIEW_ONLY_BACKGROUND , 'black' ) } ) ) ,
143+ state ( 'disabled' , style ( { backgroundColor : getBackgroundColor ( DISABLED_BACKGROUND , '#CCC' ) } ) ) ,
144+ state ( 'dark-error' , style ( { backgroundColor : getBackgroundColor ( ERROR_BACKGROUND , '#C36' , true ) } ) ) ,
145+ state ( 'dark-normal' , style ( { backgroundColor : getBackgroundColor ( NORMAL_BACKGROUND , '#333' , true ) } ) ) ,
146+ state ( 'dark-confirm' , style ( { backgroundColor : getBackgroundColor ( CONFIRM_BACKGROUND , '#292' , true ) } ) ) ,
147+ state ( 'dark-warning' , style ( { backgroundColor : getBackgroundColor ( WARNING_BACKGROUND , '#B80' , true ) } ) ) ,
148+ state ( 'dark-view-only' , style ( { backgroundColor : getBackgroundColor ( VIEW_ONLY_BACKGROUND , '#0A0' , true ) } ) ) ,
149+ state ( 'dark-disabled' , style ( { backgroundColor : getBackgroundColor ( DISABLED_BACKGROUND , '#444' , true ) } ) ) ,
150+ transition ( 'normal => error' , animate ( FLASH_DURATION ) ) ,
151+ transition ( 'error => normal' , animate ( FLASH_DURATION ) ) ,
152+ transition ( 'normal => confirm' , animate ( FLASH_DURATION ) ) ,
153+ transition ( 'confirm => normal' , animate ( FLASH_DURATION ) ) ,
154+ transition ( 'warning => error' , animate ( FLASH_DURATION ) ) ,
155+ transition ( 'error => warning' , animate ( FLASH_DURATION ) ) ,
156+ transition ( 'dark-normal => dark-error' , animate ( FLASH_DURATION ) ) ,
157+ transition ( 'dark-error => dark-normal' , animate ( FLASH_DURATION ) ) ,
158+ transition ( 'dark-normal => dark-confirm' , animate ( FLASH_DURATION ) ) ,
159+ transition ( 'dark-confirm => dark-normal' , animate ( FLASH_DURATION ) ) ,
160+ transition ( 'dark-warning => dark-error' , animate ( FLASH_DURATION ) ) ,
161+ transition ( 'dark-error => dark-warning' , animate ( FLASH_DURATION ) )
162+ ] ) ;
163+ }
164+
165+ updateStateDefinitions ( ) ;
166+
167+ export const BACKGROUND_ANIMATIONS = trigger ( 'displayState' , stateDefinitions ) ;
158168
159169export function getThePoint ( evt : MouseEvent | TouchEvent ) : Point {
160170 if ( ( evt as any ) . pageX != null )
@@ -350,6 +360,11 @@ export abstract class DigitSequenceEditorDirective<T> implements
350360 }
351361
352362 ngAfterViewInit ( ) : void {
363+ if ( ! stateDefinitionsRefreshed ) {
364+ updateStateDefinitions ( ) ;
365+ stateDefinitionsRefreshed = true ;
366+ }
367+
353368 this . checkDarkMode ( ) ;
354369
355370 setTimeout ( ( ) => {
0 commit comments