@@ -5,6 +5,7 @@ import { ReactScanInternals } from '../index';
55import { getLabelText } from '../utils' ;
66import { isOutlineUnstable , throttle } from './utils' ;
77import { log } from './log' ;
8+ import { recalcOutlineColor } from './perf-observer' ;
89
910export interface PendingOutline {
1011 rect : DOMRect ;
@@ -29,7 +30,7 @@ export interface PaintedOutline {
2930
3031export const MONO_FONT =
3132 'Menlo,Consolas,Monaco,Liberation Mono,Lucida Console,monospace' ;
32- export const PURPLE_RGB = '115,97,230' ;
33+ export const colorRef = { current : '115,97,230' } ;
3334
3435export const getOutlineKey = ( outline : PendingOutline ) : string => {
3536 return `${ outline . rect . top } -${ outline . rect . left } -${ outline . rect . width } -${ outline . rect . height } ` ;
@@ -45,6 +46,8 @@ export const getRect = (domNode: HTMLElement): DOMRect | null => {
4546 return null ;
4647 }
4748
49+ // if (!document.documentElement.contains(domNode)) return null;
50+
4851 const rect = domNode . getBoundingClientRect ( ) ;
4952 const isVisible =
5053 rect . top >= 0 ||
@@ -135,6 +138,7 @@ export const flushOutlines = (
135138 ctx : CanvasRenderingContext2D ,
136139 previousOutlines : Map < string , PendingOutline > = new Map ( ) ,
137140 toolbar : HTMLElement | null = null ,
141+ perfObserver : PerformanceObserver | null = null ,
138142) => {
139143 if ( ! ReactScanInternals . scheduledOutlines . length ) {
140144 return ;
@@ -144,6 +148,10 @@ export const flushOutlines = (
144148 ReactScanInternals . scheduledOutlines = [ ] ;
145149
146150 requestAnimationFrame ( ( ) => {
151+ if ( perfObserver ) {
152+ recalcOutlineColor ( perfObserver . takeRecords ( ) ) ;
153+ }
154+ recalcOutlines ( ) ;
147155 void ( async ( ) => {
148156 const secondOutlines = ReactScanInternals . scheduledOutlines ;
149157 ReactScanInternals . scheduledOutlines = [ ] ;
@@ -182,7 +190,7 @@ export const flushOutlines = (
182190 } ) ,
183191 ) ;
184192 if ( ReactScanInternals . scheduledOutlines . length ) {
185- flushOutlines ( ctx , newPreviousOutlines , toolbar ) ;
193+ flushOutlines ( ctx , newPreviousOutlines , toolbar , perfObserver ) ;
186194 }
187195 } ) ( ) ;
188196 } ) ;
@@ -272,9 +280,9 @@ export const fadeOutOutline = (ctx: CanvasRenderingContext2D) => {
272280
273281 ctx . save ( ) ;
274282
275- ctx . strokeStyle = `rgba(${ PURPLE_RGB } , ${ maxStrokeAlpha } )` ;
283+ ctx . strokeStyle = `rgba(${ colorRef . current } , ${ maxStrokeAlpha } )` ;
276284 ctx . lineWidth = 1 ;
277- ctx . fillStyle = `rgba(${ PURPLE_RGB } , ${ maxFillAlpha } )` ;
285+ ctx . fillStyle = `rgba(${ colorRef . current } , ${ maxFillAlpha } )` ;
278286
279287 ctx . stroke ( combinedPath ) ;
280288 ctx . fill ( combinedPath ) ;
@@ -295,7 +303,7 @@ export const fadeOutOutline = (ctx: CanvasRenderingContext2D) => {
295303 const labelX : number = rect . x ;
296304 const labelY : number = rect . y - textHeight - 4 ;
297305
298- ctx . fillStyle = `rgba(${ PURPLE_RGB } ,${ alpha } )` ;
306+ ctx . fillStyle = `rgba(${ colorRef . current } ,${ alpha } )` ;
299307 ctx . fillRect ( labelX , labelY , textWidth + 4 , textHeight + 4 ) ;
300308
301309 ctx . fillStyle = `rgba(255,255,255,${ alpha } )` ;
0 commit comments