@@ -176,14 +176,14 @@ export function addDisposableGenericMouseUpListener(node: EventTarget, handler:
176
176
* If currently in an animation frame, `runner` will be executed immediately.
177
177
* @return token that can be used to cancel the scheduled runner (only if `runner` was not executed immediately).
178
178
*/
179
- export let runAtThisOrScheduleAtNextAnimationFrame : ( runner : ( ) => void , priority ?: number ) => IDisposable ;
179
+ export let runAtThisOrScheduleAtNextAnimationFrame : ( runner : ( ) => void , targetWindow : Window , priority ?: number ) => IDisposable ;
180
180
/**
181
181
* Schedule a callback to be run at the next animation frame.
182
182
* This allows multiple parties to register callbacks that should run at the next animation frame.
183
183
* If currently in an animation frame, `runner` will be executed at the next animation frame.
184
184
* @return token that can be used to cancel the scheduled runner.
185
185
*/
186
- export let scheduleAtNextAnimationFrame : ( runner : ( ) => void , priority ?: number ) => IDisposable ;
186
+ export let scheduleAtNextAnimationFrame : ( runner : ( ) => void , targetWindow : Window , priority ?: number ) => IDisposable ;
187
187
188
188
class AnimationFrameQueueItem implements IDisposable {
189
189
@@ -252,35 +252,35 @@ class AnimationFrameQueueItem implements IDisposable {
252
252
inAnimationFrameRunner = false ;
253
253
} ;
254
254
255
- scheduleAtNextAnimationFrame = ( runner : ( ) => void , priority : number = 0 ) => {
255
+ scheduleAtNextAnimationFrame = ( runner : ( ) => void , targetWindow : Window , priority : number = 0 ) => {
256
256
const item = new AnimationFrameQueueItem ( runner , priority ) ;
257
257
NEXT_QUEUE . push ( item ) ;
258
258
259
259
if ( ! animFrameRequested ) {
260
260
animFrameRequested = true ;
261
- requestAnimationFrame ( animationFrameRunner ) ;
261
+ targetWindow . requestAnimationFrame ( animationFrameRunner ) ;
262
262
}
263
263
264
264
return item ;
265
265
} ;
266
266
267
- runAtThisOrScheduleAtNextAnimationFrame = ( runner : ( ) => void , priority ?: number ) => {
267
+ runAtThisOrScheduleAtNextAnimationFrame = ( runner : ( ) => void , targetWindow : Window , priority ?: number ) => {
268
268
if ( inAnimationFrameRunner ) {
269
269
const item = new AnimationFrameQueueItem ( runner , priority ) ;
270
270
CURRENT_QUEUE ! . push ( item ) ;
271
271
return item ;
272
272
} else {
273
- return scheduleAtNextAnimationFrame ( runner , priority ) ;
273
+ return scheduleAtNextAnimationFrame ( runner , targetWindow , priority ) ;
274
274
}
275
275
} ;
276
276
} ) ( ) ;
277
277
278
- export function measure ( callback : ( ) => void ) : IDisposable {
279
- return scheduleAtNextAnimationFrame ( callback , 10000 /* must be early */ ) ;
278
+ export function measure ( callback : ( ) => void , targetWindow : Window ) : IDisposable {
279
+ return scheduleAtNextAnimationFrame ( callback , targetWindow , 10000 /* must be early */ ) ;
280
280
}
281
281
282
- export function modify ( callback : ( ) => void ) : IDisposable {
283
- return scheduleAtNextAnimationFrame ( callback , - 10000 /* must be late */ ) ;
282
+ export function modify ( callback : ( ) => void , targetWindow : Window ) : IDisposable {
283
+ return scheduleAtNextAnimationFrame ( callback , targetWindow , - 10000 /* must be late */ ) ;
284
284
}
285
285
286
286
/**
@@ -780,16 +780,15 @@ export function getActiveWindow(): WindowGlobal {
780
780
return document . defaultView ?. window ?? window ;
781
781
}
782
782
783
- export function getWindow ( element : Node ) : WindowGlobal ;
784
- export function getWindow ( event : UIEvent ) : WindowGlobal ;
785
- export function getWindow ( obj : unknown ) : WindowGlobal ;
783
+ export function getWindow ( element : Node | undefined | null ) : WindowGlobal ;
784
+ export function getWindow ( event : UIEvent | undefined | null ) : WindowGlobal ;
786
785
export function getWindow ( e : unknown ) : WindowGlobal {
787
- const candidateNode = e as Node | undefined ;
786
+ const candidateNode = e as Node | undefined | null ;
788
787
if ( candidateNode ?. ownerDocument ?. defaultView ) {
789
788
return candidateNode . ownerDocument . defaultView . window ;
790
789
}
791
790
792
- const candidateEvent = e as UIEvent | undefined ;
791
+ const candidateEvent = e as UIEvent | undefined | null ;
793
792
if ( candidateEvent ?. view ) {
794
793
return candidateEvent . view . window ;
795
794
}
@@ -996,22 +995,22 @@ function isCSSStyleRule(rule: CSSRule): rule is CSSStyleRule {
996
995
997
996
export function isMouseEvent ( e : unknown ) : e is MouseEvent {
998
997
// eslint-disable-next-line no-restricted-syntax
999
- return e instanceof MouseEvent || e instanceof getWindow ( e ) . MouseEvent ;
998
+ return e instanceof MouseEvent || e instanceof getWindow ( e as UIEvent ) . MouseEvent ;
1000
999
}
1001
1000
1002
1001
export function isKeyboardEvent ( e : unknown ) : e is KeyboardEvent {
1003
1002
// eslint-disable-next-line no-restricted-syntax
1004
- return e instanceof KeyboardEvent || e instanceof getWindow ( e ) . KeyboardEvent ;
1003
+ return e instanceof KeyboardEvent || e instanceof getWindow ( e as UIEvent ) . KeyboardEvent ;
1005
1004
}
1006
1005
1007
1006
export function isPointerEvent ( e : unknown ) : e is PointerEvent {
1008
1007
// eslint-disable-next-line no-restricted-syntax
1009
- return e instanceof PointerEvent || e instanceof getWindow ( e ) . PointerEvent ;
1008
+ return e instanceof PointerEvent || e instanceof getWindow ( e as UIEvent ) . PointerEvent ;
1010
1009
}
1011
1010
1012
1011
export function isDragEvent ( e : unknown ) : e is DragEvent {
1013
1012
// eslint-disable-next-line no-restricted-syntax
1014
- return e instanceof DragEvent || e instanceof getWindow ( e ) . DragEvent ;
1013
+ return e instanceof DragEvent || e instanceof getWindow ( e as UIEvent ) . DragEvent ;
1015
1014
}
1016
1015
1017
1016
export const EventType = {
@@ -1463,13 +1462,13 @@ export function windowOpenWithSuccess(url: string, noOpener = true): boolean {
1463
1462
return false ;
1464
1463
}
1465
1464
1466
- export function animate ( fn : ( ) => void ) : IDisposable {
1465
+ export function animate ( fn : ( ) => void , targetWindow : Window ) : IDisposable {
1467
1466
const step = ( ) => {
1468
1467
fn ( ) ;
1469
- stepDisposable = scheduleAtNextAnimationFrame ( step ) ;
1468
+ stepDisposable = scheduleAtNextAnimationFrame ( step , targetWindow ) ;
1470
1469
} ;
1471
1470
1472
- let stepDisposable = scheduleAtNextAnimationFrame ( step ) ;
1471
+ let stepDisposable = scheduleAtNextAnimationFrame ( step , targetWindow ) ;
1473
1472
return toDisposable ( ( ) => stepDisposable . dispose ( ) ) ;
1474
1473
}
1475
1474
0 commit comments