@@ -4,6 +4,7 @@ import * as LiveBurst from "./live-burst";
44import * as LiveAcc from "./live-acc" ;
55import * as TimerProgress from "./timer-progress" ;
66import * as PageTransition from "../states/page-transition" ;
7+ import { requestDebouncedAnimationFrame } from "../utils/debounced-animation-frame" ;
78
89const unfocusPx = 3 ;
910let state = false ;
@@ -41,13 +42,13 @@ function initializeCache(): void {
4142// with cursor is a special case that is only used on the initial page load
4243// to avoid the cursor being invisible and confusing the user
4344export function set ( value : boolean , withCursor = false ) : void {
44- initializeCache ( ) ;
45+ requestDebouncedAnimationFrame ( "focus.set" , ( ) => {
46+ initializeCache ( ) ;
4547
46- if ( value && ! state ) {
47- state = true ;
48+ if ( value && ! state ) {
49+ state = true ;
4850
49- // batch DOM operations for better performance
50- requestAnimationFrame ( ( ) => {
51+ // batch DOM operations for better performance
5152 if ( cache . focus ) {
5253 for ( const el of cache . focus ) {
5354 el . classList . add ( "focus" ) ;
@@ -58,17 +59,15 @@ export function set(value: boolean, withCursor = false): void {
5859 el . style . cursor = "none" ;
5960 }
6061 }
61- } ) ;
6262
63- Caret . stopAnimation ( ) ;
64- LiveSpeed . show ( ) ;
65- LiveBurst . show ( ) ;
66- LiveAcc . show ( ) ;
67- TimerProgress . show ( ) ;
68- } else if ( ! value && state ) {
69- state = false ;
63+ Caret . stopAnimation ( ) ;
64+ LiveSpeed . show ( ) ;
65+ LiveBurst . show ( ) ;
66+ LiveAcc . show ( ) ;
67+ TimerProgress . show ( ) ;
68+ } else if ( ! value && state ) {
69+ state = false ;
7070
71- requestAnimationFrame ( ( ) => {
7271 if ( cache . focus ) {
7372 for ( const el of cache . focus ) {
7473 el . classList . remove ( "focus" ) ;
@@ -79,14 +78,14 @@ export function set(value: boolean, withCursor = false): void {
7978 el . style . cursor = "" ;
8079 }
8180 }
82- } ) ;
8381
84- Caret . startAnimation ( ) ;
85- LiveSpeed . hide ( ) ;
86- LiveBurst . hide ( ) ;
87- LiveAcc . hide ( ) ;
88- TimerProgress . hide ( ) ;
89- }
82+ Caret . startAnimation ( ) ;
83+ LiveSpeed . hide ( ) ;
84+ LiveBurst . hide ( ) ;
85+ LiveAcc . hide ( ) ;
86+ TimerProgress . hide ( ) ;
87+ }
88+ } ) ;
9089}
9190
9291$ ( document ) . on ( "mousemove" , function ( event ) {
0 commit comments