@@ -14,9 +14,9 @@ import type {
1414 NotivueStore ,
1515} from 'notivue'
1616
17- import { ref , shallowRef , triggerRef , unref , isRef , type Ref } from 'vue'
17+ import { ref , shallowRef , triggerRef , unref , isRef , type CSSProperties , type Ref } from 'vue'
1818
19- import { DEFAULT_CONFIG , NotificationTypeKeys as NType } from './constants'
19+ import { DEFAULT_CONFIG , MOTION_VARS_CSS , NotificationTypeKeys as NType } from './constants'
2020
2121import {
2222 createConfigRefs ,
@@ -60,7 +60,7 @@ export function createConfig(userConfig: NotivueConfig, isRunning: Readonly<Ref<
6060 const prev = config [ key as K ] . value as Obj
6161 const next = newConfig [ key as K ] as any
6262
63- config [ key as K ] . value = mergeDeep ( prev , next )
63+ config [ key as K ] . value = mergeDeep ( prev , next ) as any
6464 } else {
6565 config [ key as K ] . value = newConfig [ key as K ] as any
6666 }
@@ -169,12 +169,15 @@ export function createItems(config: ConfigSlice, queue: QueueSlice) {
169169}
170170
171171export function createElements ( ) {
172- type AnimationAttrs = { class : string ; onAnimationend : ( ) => void }
172+ type MotionAttrs = {
173+ style ?: CSSProperties
174+ onAnimationend ?: ( e ?: AnimationEvent ) => void
175+ }
173176
174177 return {
175178 root : ref < HTMLElement | null > ( null ) ,
176- rootAttrs : shallowRef < Partial < AnimationAttrs > > ( { } ) ,
177- setRootAttrs ( newAttrs : Partial < AnimationAttrs > ) {
179+ rootAttrs : shallowRef < Partial < MotionAttrs > > ( { } ) ,
180+ setRootAttrs ( newAttrs : Partial < MotionAttrs > ) {
178181 this . rootAttrs . value = newAttrs
179182 } ,
180183 items : ref < HTMLElement [ ] > ( [ ] ) ,
@@ -186,10 +189,10 @@ export function createElements() {
186189 } as {
187190 // Suppress TS7056
188191 root : Ref < HTMLElement | null >
189- rootAttrs : Ref < Partial < AnimationAttrs > >
192+ rootAttrs : Ref < Partial < MotionAttrs > >
190193 items : Ref < HTMLElement [ ] >
191194 containers : Ref < HTMLElement [ ] >
192- setRootAttrs ( newAttrs : Partial < AnimationAttrs > ) : void
195+ setRootAttrs ( newAttrs : Partial < MotionAttrs > ) : void
193196 getSortedItems ( ) : HTMLElement [ ]
194197 }
195198}
@@ -206,13 +209,17 @@ export function createAnimations(
206209 this . isReducedMotion . value = newVal
207210 } ,
208211 playLeave ( id : string , { isDestroy = false , isUserTriggered = false } = { } ) {
209- const { leave = '' } = config . animations . value
210212 const item = items . get ( id )
211213
214+ let isDone = false
215+
212216 window . clearTimeout ( item ?. timeout as number )
213217
214218 const onAnimationend = ( e ?: AnimationEvent ) => {
215219 if ( e && e . currentTarget !== e . target ) return
220+ if ( isDone ) return
221+
222+ isDone = true
216223
217224 if ( item ) {
218225 const slotItem = getSlotItem ( item )
@@ -229,7 +236,7 @@ export function createAnimations(
229236 items . remove ( id )
230237 }
231238
232- if ( ! item || ! leave || isDestroy || this . isReducedMotion . value ) {
239+ if ( ! item || isDestroy || this . isReducedMotion . value ) {
233240 items . addLifecycleEvent ( )
234241
235242 return onAnimationend ( )
@@ -241,36 +248,52 @@ export function createAnimations(
241248 zIndex : - 1 ,
242249 } ,
243250 animationAttrs : {
244- class : leave ,
251+ style : { animation : MOTION_VARS_CSS . leaveAnimation } ,
245252 onAnimationend,
246253 } ,
247254 } )
248255
249256 items . addLifecycleEvent ( )
257+
258+ requestAnimationFrame ( ( ) => {
259+ const el = elements . containers . value . find ( ( el ) => el . dataset . notivueContainer === id )
260+
261+ if ( el && getComputedStyle ( el ) . animationName === 'none' ) onAnimationend ( )
262+ } )
250263 } ,
251264 playClearAll ( ) {
252265 items . entries . value . forEach ( ( e ) => window . clearTimeout ( e . timeout as number ) )
253266
254- const { clearAll = '' } = config . animations . value
267+ let isDone = false
268+
269+ const onAnimationend = ( e ?: AnimationEvent ) => {
270+ if ( e && e . currentTarget !== e . target ) return
271+ if ( isDone ) return
272+
273+ isDone = true
255274
256- const onAnimationend = ( ) => {
257275 queue . clear ( )
258276 items . clear ( )
259277 }
260278
261- if ( ! clearAll || this . isReducedMotion . value ) return onAnimationend ( )
279+ if ( this . isReducedMotion . value ) return onAnimationend ( )
262280
263281 elements . setRootAttrs ( {
264- class : clearAll ,
282+ style : { animation : MOTION_VARS_CSS . clearAllAnimation } ,
265283 onAnimationend,
266284 } )
285+
286+ requestAnimationFrame ( ( ) => {
287+ const root = elements . root . value
288+
289+ if ( root && getComputedStyle ( root ) . animationName === 'none' ) onAnimationend ( )
290+ } )
267291 } ,
268292 updatePositions ( { isImmediate = false } = { } ) {
269293 console . log ( 'Updating positions' )
270294
271295 const isReduced = this . isReducedMotion . value || isImmediate
272296 const isTopAlign = config . position . value . startsWith ( 'top' )
273- const leaveClass = config . animations . value . leave
274297
275298 let accPrevHeights = 0
276299
@@ -279,12 +302,12 @@ export function createAnimations(
279302 const item = items . get ( id )
280303
281304 if ( ! el || ! item ) continue
282- if ( item . animationAttrs . class === leaveClass ) continue
305+ if ( item . animationAttrs . style ?. animation === MOTION_VARS_CSS . leaveAnimation ) continue
283306
284307 items . update ( id , {
285308 positionStyles : {
286309 transform : `translate3d(0, ${ accPrevHeights } px, 0)` ,
287- transition : isReduced ? 'none' : config . transition . value ,
310+ transition : isReduced ? 'none' : MOTION_VARS_CSS . transformTransition ,
288311 } ,
289312 } )
290313
@@ -479,11 +502,15 @@ export function createNotifyProxies({
479502 createdAt,
480503 duplicateCount : 0 ,
481504 animationAttrs : {
482- class : animations . isReducedMotion . value ? '' : config . animations . value . enter ,
483- onAnimationend ( ) {
484- if ( item . animationAttrs . class === config . animations . value . enter ) {
505+ style : animations . isReducedMotion . value
506+ ? { }
507+ : { animation : MOTION_VARS_CSS . enterAnimation } ,
508+ onAnimationend ( e ?: AnimationEvent ) {
509+ if ( e && e . currentTarget !== e . target ) return
510+
511+ if ( item . animationAttrs . style ?. animation === MOTION_VARS_CSS . enterAnimation ) {
485512 items . update ( entry . id , {
486- animationAttrs : { class : '' , onAnimationend : ( ) => { } } ,
513+ animationAttrs : { style : { } , onAnimationend : ( ) => { } } ,
487514 } )
488515 }
489516 } ,
0 commit comments