@@ -48,8 +48,9 @@ class Dumper
4848
4949 document . documentElement . addEventListener ( 'click' , ( e ) => {
5050 let el ;
51+ let target = e . composedPath ( ) [ 0 ] ;
5152 // enables <span data-tracy-href=""> & ctrl key
52- if ( e . ctrlKey && ( el = e . target . closest ( '[data-tracy-href]' ) ) ) {
53+ if ( e . ctrlKey && ( el = target . closest ( '[data-tracy-href]' ) ) ) {
5354 location . href = el . getAttribute ( 'data-tracy-href' ) ;
5455 return false ;
5556 }
@@ -59,7 +60,7 @@ class Dumper
5960 document . documentElement . addEventListener ( 'tracy-beforetoggle' , ( e ) => {
6061 let el ;
6162 // initializes lazy <span data-tracy-dump> inside <pre data-tracy-snapshot>
62- if ( ( el = e . target . closest ( '[data-tracy-snapshot]' ) ) ) {
63+ if ( ( el = target . closest ( '[data-tracy-snapshot]' ) ) ) {
6364 let snapshot = JSON . parse ( el . getAttribute ( 'data-tracy-snapshot' ) ) ;
6465 el . removeAttribute ( 'data-tracy-snapshot' ) ;
6566 el . querySelectorAll ( '[data-tracy-dump]' ) . forEach ( ( toggler ) => {
@@ -73,7 +74,8 @@ class Dumper
7374 } ) ;
7475
7576 document . documentElement . addEventListener ( 'tracy-toggle' , ( e ) => {
76- if ( ! e . target . matches ( '.tracy-dump *' ) ) {
77+ let target = e . composedPath ( ) [ 0 ] ;
78+ if ( ! target . matches ( '.tracy-dump *' ) ) {
7779 return ;
7880 }
7981
@@ -86,12 +88,12 @@ class Dumper
8688
8789 } else if ( origE && origE . altKey && cont . querySelector ( '.tracy-toggle' ) ) { // triggered by alt key
8890 if ( e . detail . collapsed ) { // reopen
89- e . target . classList . toggle ( 'tracy-collapsed' , false ) ;
91+ target . classList . toggle ( 'tracy-collapsed' , false ) ;
9092 cont . classList . toggle ( 'tracy-collapsed' , false ) ;
9193 e . detail . collapsed = false ;
9294 }
9395
94- let expand = e . target . tracyAltExpand = ! e . target . tracyAltExpand ;
96+ let expand = target . tracyAltExpand = ! target . tracyAltExpand ;
9597 toggleChildren ( cont , expand ? { } : false ) ;
9698 }
9799
@@ -100,33 +102,36 @@ class Dumper
100102
101103 document . documentElement . addEventListener ( 'animationend' , ( e ) => {
102104 if ( e . animationName === 'tracy-dump-flash' ) {
103- e . target . classList . toggle ( 'tracy-dump-flash' , false ) ;
105+ let target = e . composedPath ( ) [ 0 ] ;
106+ target . classList . toggle ( 'tracy-dump-flash' , false ) ;
104107 }
105108 } ) ;
106109
107110 document . addEventListener ( 'mouseover' , ( e ) => {
108- if ( ! e . target . matches ( '.tracy-dump *' ) ) {
111+ let target = e . composedPath ( ) [ 0 ] ;
112+ if ( ! target . matches ( '.tracy-dump *' ) ) {
109113 return ;
110114 }
111115
112116 let el ;
113117
114- if ( e . target . matches ( '.tracy-dump-hash' ) && ( el = e . target . closest ( 'tracy-div' ) ) ) {
118+ if ( target . matches ( '.tracy-dump-hash' ) && ( el = target . closest ( 'tracy-div' ) ) ) {
115119 el . querySelectorAll ( '.tracy-dump-hash' ) . forEach ( ( el ) => {
116- if ( el . textContent === e . target . textContent ) {
120+ if ( el . textContent === target . textContent ) {
117121 el . classList . add ( 'tracy-dump-highlight' ) ;
118122 }
119123 } ) ;
120124 return ;
121125 }
122126
123- if ( ( el = e . target . closest ( '.tracy-toggle' ) ) && ! el . title ) {
127+ if ( ( el = target . closest ( '.tracy-toggle' ) ) && ! el . title ) {
124128 el . title = HINT_ALT ;
125129 }
126130 } ) ;
127131
128132 document . addEventListener ( 'mouseout' , ( e ) => {
129- if ( e . target . matches ( '.tracy-dump-hash' ) ) {
133+ let target = e . composedPath ( ) [ 0 ] ;
134+ if ( target . matches ( '.tracy-dump-hash' ) ) {
130135 document . querySelectorAll ( '.tracy-dump-hash.tracy-dump-highlight' ) . forEach ( ( el ) => {
131136 el . classList . remove ( 'tracy-dump-highlight' ) ;
132137 } ) ;
@@ -379,6 +384,26 @@ function toggleChildren(cont, usedIds) {
379384function UnknownEntityException ( ) { }
380385
381386
387+ class TracyDumpElement extends HTMLElement {
388+ constructor ( ) {
389+ super ( ) ;
390+ let templateContent = document . querySelector ( '.tracy-dump-template' ) . content ;
391+ this . attachShadow ( { mode : 'open' } ) ;
392+ this . shadowRoot . appendChild ( templateContent . cloneNode ( true ) ) ;
393+ }
394+
395+ connectedCallback ( ) {
396+ setTimeout ( ( ) => {
397+ while ( this . firstElementChild ) {
398+ this . shadowRoot . appendChild ( this . firstElementChild ) ;
399+ }
400+ } ) ;
401+ }
402+ }
403+
404+ window . customElements . define ( 'tracy-dump' , TracyDumpElement ) ;
405+
406+
382407let Tracy = window . Tracy = window . Tracy || { } ;
383408Tracy . Dumper = Tracy . Dumper || Dumper ;
384409
0 commit comments