@@ -111,18 +111,27 @@ export default class ElementStyleObserver {
111
111
async handleEvent ( event ) {
112
112
if ( event . type === "animationstart" ) {
113
113
let animation = document . getAnimations ( ) . find ( a => a . effect . target === this . target ) ;
114
- let properties = this . getObservedAnimationProperties ( animation ) ;
114
+
115
+ // Get the observed properties that are being animated by the animation
116
+ let keyframes = animation . effect . getKeyframes ( ) ;
117
+ let properties = new Set ( keyframes . flatMap ( frame =>
118
+ Object . keys ( frame ) . filter ( prop => ! [ "offset" , "easing" , "composite" , "computedOffset" ] . includes ( prop ) )
119
+ ) ) ;
120
+ properties = [ ...properties ] . filter ( property => this . properties . has ( property ) ) ;
121
+
115
122
if ( properties . length === 0 ) {
116
123
return ;
117
124
}
118
125
else {
119
- let interval = setInterval ( ( ) => this . #handleChanges( properties ) , 16 ) ; // ~ 60fps
126
+ let interval = setInterval ( ( ) => this . #handleChanges( properties ) , this . options . animationThrottle ?? 16 ) ; // 16ms ~ 60fps
120
127
121
128
let cleanup = event => {
122
129
if ( event . animationName === animation . animationName ) {
123
130
clearInterval ( interval ) ;
124
131
this . target . removeEventListener ( "animationend" , cleanup ) ;
125
132
this . target . removeEventListener ( "animationcancel" , cleanup ) ;
133
+
134
+ // Pick up the recent changes
126
135
this . #handleChanges( properties ) ;
127
136
}
128
137
} ;
@@ -286,20 +295,6 @@ export default class ElementStyleObserver {
286
295
this . updateTransitionProperties ( ) ;
287
296
}
288
297
289
- /**
290
- * Get the observed properties that are being animated by an animation.
291
- * @param {Animation } animation
292
- * @returns {string[] }
293
- */
294
- getObservedAnimationProperties ( animation ) {
295
- let keyframes = animation . effect . getKeyframes ( ) ;
296
- let properties = new Set ( keyframes . flatMap ( frame =>
297
- Object . keys ( frame ) . filter ( prop => ! [ "offset" , "easing" , "composite" , "computedOffset" ] . includes ( prop ) )
298
- ) ) ;
299
-
300
- return [ ...properties ] . filter ( property => this . properties . has ( property ) ) ;
301
- }
302
-
303
298
/**
304
299
* Stop observing a target for changes to one or more CSS properties.
305
300
* @param { string | string[] } [properties] Properties to stop observing. Defaults to all observed properties.
0 commit comments