@@ -33,47 +33,52 @@ export default class TemplateFactory implements FlasherInterface {
33
33
return ;
34
34
}
35
35
36
- template . style . transition = this . options . style . transition as string ;
36
+ let options = JSON . parse ( JSON . stringify ( this . options ) ) ;
37
+ if ( ! Array . isArray ( notification . options ) ) {
38
+ options = deepmerge ( options , notification . options ) ;
39
+ }
40
+
41
+ template . style . transition = options . style . transition as string ;
37
42
38
43
if ( undefined !== notification . options && undefined !== notification . options . position ) {
39
- this . options . position = notification . options . position as unknown as string ;
44
+ options . position = notification . options . position as unknown as string ;
40
45
}
41
46
42
- let container = document . getElementById ( `flasher-container-${ this . options . position } ` ) ;
47
+ let container = document . getElementById ( `flasher-container-${ options . position } ` ) ;
43
48
if ( container === null ) {
44
49
container = document . createElement ( 'div' ) ;
45
50
46
- container . id = `flasher-container-${ this . options . position } ` ;
51
+ container . id = `flasher-container-${ options . position } ` ;
47
52
48
- Object . keys ( this . options . style ) . forEach ( ( key : string ) => {
49
- container ! . style . setProperty ( key , this . options . style [ key as keyof Properties ] as string ) ;
53
+ Object . keys ( options . style ) . forEach ( ( key : string ) => {
54
+ container ! . style . setProperty ( key , options . style [ key as keyof Properties ] as string ) ;
50
55
} ) ;
51
56
52
- container . style . maxWidth = this . options . style . maxWidth as string ;
57
+ container . style . maxWidth = options . style . maxWidth as string ;
53
58
54
- switch ( this . options . position ) {
59
+ switch ( options . position ) {
55
60
case 'top-left' :
56
- container . style . top = this . options . style . top as string || '0' ;
57
- container . style . left = this . options . style . left as string || '0.5em' ;
61
+ container . style . top = options . style . top as string || '0' ;
62
+ container . style . left = options . style . left as string || '0.5em' ;
58
63
break ;
59
64
case 'top-right' :
60
- container . style . top = this . options . style . top as string || '0' ;
61
- container . style . right = this . options . style . right as string || '0.5em' ;
65
+ container . style . top = options . style . top as string || '0' ;
66
+ container . style . right = options . style . right as string || '0.5em' ;
62
67
break ;
63
68
case 'bottom-left' :
64
- container . style . bottom = this . options . style . bottom as string || '0' ;
65
- container . style . left = this . options . style . left as string || '0.5em' ;
69
+ container . style . bottom = options . style . bottom as string || '0' ;
70
+ container . style . left = options . style . left as string || '0.5em' ;
66
71
break ;
67
72
case 'bottom-right' :
68
73
default :
69
- container . style . bottom = this . options . style . bottom as string || '0' ;
70
- container . style . right = this . options . style . right as string || '0.5em' ;
74
+ container . style . bottom = options . style . bottom as string || '0' ;
75
+ container . style . right = options . style . right as string || '0.5em' ;
71
76
break ;
72
77
}
73
78
document . getElementsByTagName ( 'body' ) [ 0 ] . appendChild ( container ) ;
74
79
}
75
80
76
- switch ( this . options . direction ) {
81
+ switch ( options . direction ) {
77
82
case 'top' :
78
83
container . insertBefore ( template , container . firstChild ) ;
79
84
break ;
@@ -91,14 +96,14 @@ export default class TemplateFactory implements FlasherInterface {
91
96
} ) ;
92
97
93
98
const progressBar = template . querySelector ( '.flasher-progress' ) ;
94
- if ( progressBar instanceof HTMLElement && this . options . timeout > 0 ) {
99
+ if ( progressBar instanceof HTMLElement && options . timeout > 0 ) {
95
100
let width = 0 ;
96
101
let progress : NodeJS . Timeout ;
97
- const lapse = 1000 / this . options . fps ;
102
+ const lapse = 1000 / options . fps ;
98
103
99
104
const showProgress = ( ) => {
100
105
width += 1 ;
101
- const percent = ( 1 - lapse * ( width / this . options . timeout ) ) * 100 ;
106
+ const percent = ( 1 - lapse * ( width / options . timeout ) ) * 100 ;
102
107
progressBar . style . width = `${ percent } %` ;
103
108
104
109
if ( percent <= 0 ) {
0 commit comments