@@ -98,8 +98,13 @@ export class DevtoolsBrowser extends Element {
9898 super . connectedCallback ( )
9999 window . addEventListener ( 'resize' , this . #boundResize)
100100 window . addEventListener ( 'window-drag' , this . #boundResize)
101- window . addEventListener ( 'app-mutation-highlight' , this . #highlightMutation. bind ( this ) )
102- window . addEventListener ( 'app-mutation-select' , ( ev ) => this . #renderBrowserState( ev . detail ) )
101+ window . addEventListener (
102+ 'app-mutation-highlight' ,
103+ this . #highlightMutation. bind ( this )
104+ )
105+ window . addEventListener ( 'app-mutation-select' , ( ev ) =>
106+ this . #renderBrowserState( ev . detail )
107+ )
103108 await this . updateComplete
104109 }
105110
@@ -110,7 +115,7 @@ export class DevtoolsBrowser extends Element {
110115 this . #resizeTimer = window . setTimeout ( ( ) => this . #setIframeSize( ) , 80 )
111116 }
112117
113- #setIframeSize ( ) {
118+ #setIframeSize( ) {
114119 const metadata = this . metadata
115120 if ( ! this . section || ! this . iframe || ! this . header || ! metadata ) {
116121 return
@@ -173,11 +178,19 @@ export class DevtoolsBrowser extends Element {
173178 docEl . ownerDocument . replaceChild ( this . #vdom, docEl )
174179 }
175180
176- async #handleMutation ( mutation : TraceMutation ) {
177- if ( ! this . iframe ) await this . updateComplete
178- if ( mutation . type === 'attributes' ) return this . #handleAttributeMutation( mutation )
179- if ( mutation . type === 'childList' ) return this . #handleChildListMutation( mutation )
180- if ( mutation . type === 'characterData' ) return this . #handleCharacterDataMutation( mutation )
181+ async #handleMutation( mutation : TraceMutation ) {
182+ if ( ! this . iframe ) {
183+ await this . updateComplete
184+ }
185+ if ( mutation . type === 'attributes' ) {
186+ return this . #handleAttributeMutation( mutation )
187+ }
188+ if ( mutation . type === 'childList' ) {
189+ return this . #handleChildListMutation( mutation )
190+ }
191+ if ( mutation . type === 'characterData' ) {
192+ return this . #handleCharacterDataMutation( mutation )
193+ }
181194 }
182195
183196 #handleCharacterDataMutation( mutation : TraceMutation ) {
@@ -189,14 +202,19 @@ export class DevtoolsBrowser extends Element {
189202 el . textContent = mutation . newTextContent || ''
190203 }
191204
192- #handleAttributeMutation ( mutation : TraceMutation ) {
205+ #handleAttributeMutation( mutation : TraceMutation ) {
193206 if ( ! mutation . attributeName ) {
194207 return
195208 }
196209 const el = this . #queryElement( mutation . target ! )
197- if ( ! el ) return
210+ if ( ! el ) {
211+ return
212+ }
198213
199- if ( mutation . attributeValue === undefined || mutation . attributeValue === null ) {
214+ if (
215+ mutation . attributeValue === undefined ||
216+ mutation . attributeValue === null
217+ ) {
200218 el . removeAttribute ( mutation . attributeName )
201219 } else {
202220 el . setAttribute ( mutation . attributeName , mutation . attributeValue )
@@ -278,18 +296,26 @@ export class DevtoolsBrowser extends Element {
278296
279297 async #renderBrowserState( mutationEntry ?: TraceMutation ) {
280298 const mutations = this . mutations
281- if ( ! mutations ?. length ) return
299+ if ( ! mutations ?. length ) {
300+ return
301+ }
282302
283303 const targetIndex = mutationEntry ? mutations . indexOf ( mutationEntry ) : 0
284- if ( targetIndex < 0 ) return
304+ if ( targetIndex < 0 ) {
305+ return
306+ }
285307
286308 // locate nearest checkpoint (<= targetIndex)
287- const checkpointIndices = [ ...this . #checkpoints. keys ( ) ] . sort ( ( a , b ) => a - b )
288- const nearest = checkpointIndices . filter ( i => i <= targetIndex ) . pop ( )
309+ const checkpointIndices = [ ...this . #checkpoints. keys ( ) ] . sort (
310+ ( a , b ) => a - b
311+ )
312+ const nearest = checkpointIndices . filter ( ( i ) => i <= targetIndex ) . pop ( )
289313
290314 if ( nearest !== undefined ) {
291315 // start from checkpoint clone
292- this . #vdom = this . #checkpoints. get ( nearest ) ! . cloneNode ( true ) as DocumentFragment
316+ this . #vdom = this . #checkpoints
317+ . get ( nearest ) !
318+ . cloneNode ( true ) as DocumentFragment
293319 } else {
294320 this . #vdom = document . createDocumentFragment ( )
295321 }
@@ -299,20 +325,26 @@ export class DevtoolsBrowser extends Element {
299325 let rootIndex = startIndex
300326 for ( let i = startIndex ; i <= targetIndex ; i ++ ) {
301327 const m = mutations [ i ]
302- if ( m . addedNodes . length === 1 && Boolean ( m . url ) ) rootIndex = i
328+ if ( m . addedNodes . length === 1 && Boolean ( m . url ) ) {
329+ rootIndex = i
330+ }
303331 }
304332 if ( rootIndex !== startIndex ) {
305333 this . #vdom = document . createDocumentFragment ( )
306334 }
307335
308- this . #activeUrl = mutations [ rootIndex ] . url || this . metadata ?. url || 'unknown'
336+ this . #activeUrl =
337+ mutations [ rootIndex ] . url || this . metadata ?. url || 'unknown'
309338
310339 for ( let i = rootIndex ; i <= targetIndex ; i ++ ) {
311340 try {
312341 await this . #handleMutation( mutations [ i ] )
313342 // create checkpoint
314343 if ( i % this . #checkpointStride === 0 && ! this . #checkpoints. has ( i ) ) {
315- this . #checkpoints. set ( i , this . #vdom. cloneNode ( true ) as DocumentFragment )
344+ this . #checkpoints. set (
345+ i ,
346+ this . #vdom. cloneNode ( true ) as DocumentFragment
347+ )
316348 }
317349 } catch ( err : any ) {
318350 console . warn ( `Failed to render mutation ${ i } : ${ err ?. message } ` )
@@ -333,7 +365,9 @@ export class DevtoolsBrowser extends Element {
333365 */
334366 goToMutation ( index : number ) {
335367 const m = this . mutations [ index ]
336- if ( m ) this . #renderBrowserState( m )
368+ if ( m ) {
369+ this . #renderBrowserState( m )
370+ }
337371 }
338372
339373 render ( ) {
0 commit comments