@@ -251,41 +251,26 @@ export function addDisposableNonBubblingMouseOutListener(node: Element, handler:
251251 } ) ;
252252}
253253
254- const _animationFrame = ( function ( ) {
255- let emulatedRequestAnimationFrame = ( callback : ( time : number ) => void ) : number => {
256- return setTimeout ( ( ) => callback ( new Date ( ) . getTime ( ) ) , 0 ) ;
257- } ;
258- let nativeRequestAnimationFrame : ( callback : ( time : number ) => void ) => number =
259- self . requestAnimationFrame
260- || ( < any > self ) . msRequestAnimationFrame
261- || ( < any > self ) . webkitRequestAnimationFrame
262- || ( < any > self ) . mozRequestAnimationFrame
263- || ( < any > self ) . oRequestAnimationFrame ;
264-
265-
266-
267- let emulatedCancelAnimationFrame = ( id : number ) => { } ;
268- let nativeCancelAnimationFrame : ( id : number ) => void =
269- self . cancelAnimationFrame || ( < any > self ) . cancelRequestAnimationFrame
270- || ( < any > self ) . msCancelAnimationFrame || ( < any > self ) . msCancelRequestAnimationFrame
271- || ( < any > self ) . webkitCancelAnimationFrame || ( < any > self ) . webkitCancelRequestAnimationFrame
272- || ( < any > self ) . mozCancelAnimationFrame || ( < any > self ) . mozCancelRequestAnimationFrame
273- || ( < any > self ) . oCancelAnimationFrame || ( < any > self ) . oCancelRequestAnimationFrame ;
274-
275- let isNative = ! ! nativeRequestAnimationFrame ;
276- let request = nativeRequestAnimationFrame || emulatedRequestAnimationFrame ;
277- let cancel = nativeCancelAnimationFrame || emulatedCancelAnimationFrame ;
278-
279- return {
280- isNative : isNative ,
281- request : ( callback : ( time : number ) => void ) : number => {
282- return request ( callback ) ;
283- } ,
284- cancel : ( id : number ) => {
285- return cancel ( id ) ;
286- }
287- } ;
288- } ) ( ) ;
254+ interface IRequestAnimationFrame {
255+ ( callback : ( time : number ) => void ) : number ;
256+ }
257+ let _animationFrame : IRequestAnimationFrame = null ;
258+ function doRequestAnimationFrame ( callback : ( time : number ) => void ) : number {
259+ if ( ! _animationFrame ) {
260+ const emulatedRequestAnimationFrame = ( callback : ( time : number ) => void ) : number => {
261+ return setTimeout ( ( ) => callback ( new Date ( ) . getTime ( ) ) , 0 ) ;
262+ } ;
263+ _animationFrame = (
264+ self . requestAnimationFrame
265+ || ( < any > self ) . msRequestAnimationFrame
266+ || ( < any > self ) . webkitRequestAnimationFrame
267+ || ( < any > self ) . mozRequestAnimationFrame
268+ || ( < any > self ) . oRequestAnimationFrame
269+ || emulatedRequestAnimationFrame
270+ ) ;
271+ }
272+ return _animationFrame ( callback ) ;
273+ }
289274
290275/**
291276 * Schedule a callback to be run at the next animation frame.
@@ -375,7 +360,7 @@ class AnimationFrameQueueItem implements IDisposable {
375360
376361 if ( ! animFrameRequested ) {
377362 animFrameRequested = true ;
378- _animationFrame . request ( animationFrameRunner ) ;
363+ doRequestAnimationFrame ( animationFrameRunner ) ;
379364 }
380365
381366 return item ;
@@ -662,7 +647,13 @@ export function createStyleSheet(container: HTMLElement = document.getElementsBy
662647 return style ;
663648}
664649
665- const sharedStyle = < any > createStyleSheet ( ) ;
650+ let _sharedStyleSheet : HTMLStyleElement = null ;
651+ function getSharedStyleSheet ( ) : HTMLStyleElement {
652+ if ( ! _sharedStyleSheet ) {
653+ _sharedStyleSheet = createStyleSheet ( ) ;
654+ }
655+ return _sharedStyleSheet ;
656+ }
666657
667658function getDynamicStyleSheetRules ( style : any ) {
668659 if ( style && style . sheet && style . sheet . rules ) {
@@ -676,15 +667,15 @@ function getDynamicStyleSheetRules(style: any) {
676667 return [ ] ;
677668}
678669
679- export function createCSSRule ( selector : string , cssText : string , style : HTMLStyleElement = sharedStyle ) : void {
670+ export function createCSSRule ( selector : string , cssText : string , style : HTMLStyleElement = getSharedStyleSheet ( ) ) : void {
680671 if ( ! style || ! cssText ) {
681672 return ;
682673 }
683674
684675 ( < CSSStyleSheet > style . sheet ) . insertRule ( selector + '{' + cssText + '}' , 0 ) ;
685676}
686677
687- export function removeCSSRulesContainingSelector ( ruleName : string , style = sharedStyle ) : void {
678+ export function removeCSSRulesContainingSelector ( ruleName : string , style : HTMLStyleElement = getSharedStyleSheet ( ) ) : void {
688679 if ( ! style ) {
689680 return ;
690681 }
@@ -699,7 +690,7 @@ export function removeCSSRulesContainingSelector(ruleName: string, style = share
699690 }
700691
701692 for ( let i = toDelete . length - 1 ; i >= 0 ; i -- ) {
702- style . sheet . deleteRule ( toDelete [ i ] ) ;
693+ ( < any > style . sheet ) . deleteRule ( toDelete [ i ] ) ;
703694 }
704695}
705696
0 commit comments