@@ -59,8 +59,8 @@ function createHighlightElement(activeElement, detail, id) {
5959 return highlight ;
6060}
6161
62- function removeHighlightElement ( ) {
63- const highlightElement = document . getElementById ( highlightElementID ) ;
62+ function removeHighlightElement ( shadowRoot ) {
63+ const highlightElement = shadowRoot . querySelector ( `# ${ highlightElementID } ` ) ;
6464
6565 if ( highlightElement ) {
6666 highlightElement . remove ( ) ;
@@ -69,8 +69,8 @@ function removeHighlightElement() {
6969 dispatchCustomEvent ( 'lvdbg:remove-tooltip' ) ;
7070}
7171
72- function handleHighlight ( { detail } ) {
73- let highlightElement = document . getElementById ( highlightElementID ) ;
72+ function handleHighlight ( { detail } , shadowRoot ) {
73+ let highlightElement = shadowRoot . querySelector ( `# ${ highlightElementID } ` ) ;
7474
7575 if ( highlightElement ) {
7676 highlightElement . remove ( ) ;
@@ -95,13 +95,13 @@ function handleHighlight({ detail }) {
9595 highlightElementID
9696 ) ;
9797
98- document . body . appendChild ( highlightElement ) ;
98+ shadowRoot . appendChild ( highlightElement ) ;
9999 showTooltip ( detail ) ;
100100 }
101101}
102102
103- function handleHighlightResize ( ) {
104- const highlight = document . getElementById ( highlightElementID ) ;
103+ function handleHighlightResize ( shadowRoot ) {
104+ const highlight = shadowRoot . querySelector ( `# ${ highlightElementID } ` ) ;
105105 if ( highlight ) {
106106 const activeElement = document . querySelector (
107107 `[${ highlight . dataset . attr } ="${ highlight . dataset . val } "]`
@@ -115,7 +115,7 @@ function handleHighlightResize() {
115115 }
116116}
117117
118- function handlePulse ( { detail } ) {
118+ function handlePulse ( { detail } , shadowRoot ) {
119119 const activeElement = document . querySelector (
120120 `[${ detail . attr } ="${ detail . val } "]`
121121 ) ;
@@ -127,7 +127,7 @@ function handlePulse({ detail }) {
127127 highlightPulseElementID
128128 ) ;
129129
130- document . body . appendChild ( highlightPulse ) ;
130+ shadowRoot . appendChild ( highlightPulse ) ;
131131
132132 const w = highlightPulse . offsetWidth ;
133133 const h = highlightPulse . offsetHeight ;
@@ -186,13 +186,21 @@ function showTooltip(detail) {
186186 dispatchCustomEvent ( 'lvdbg:show-tooltip' , props ) ;
187187}
188188
189- export default function initHighlight ( debugChannel ) {
190- document . addEventListener ( 'lvdbg:inspect-highlight' , handleHighlight ) ;
191- document . addEventListener ( 'lvdbg:inspect-pulse' , handlePulse ) ;
192- document . addEventListener ( 'lvdbg:inspect-clear' , removeHighlightElement ) ;
189+ export default function initHighlight ( debugChannel , shadowRoot ) {
190+ document . addEventListener ( 'lvdbg:inspect-highlight' , ( event ) =>
191+ handleHighlight ( event , shadowRoot )
192+ ) ;
193+ document . addEventListener ( 'lvdbg:inspect-pulse' , ( event ) =>
194+ handlePulse ( event , shadowRoot )
195+ ) ;
196+ document . addEventListener ( 'lvdbg:inspect-clear' , ( ) =>
197+ removeHighlightElement ( shadowRoot )
198+ ) ;
193199
194- debugChannel . on ( 'highlight' , ( e ) => handleHighlight ( { detail : e } ) ) ;
195- debugChannel . on ( 'pulse' , ( e ) => handlePulse ( { detail : e } ) ) ;
200+ debugChannel . on ( 'highlight' , ( e ) =>
201+ handleHighlight ( { detail : e } , shadowRoot )
202+ ) ;
203+ debugChannel . on ( 'pulse' , ( e ) => handlePulse ( { detail : e } , shadowRoot ) ) ;
196204
197- window . addEventListener ( 'resize' , handleHighlightResize ) ;
205+ window . addEventListener ( 'resize' , ( ) => handleHighlightResize ( shadowRoot ) ) ;
198206}
0 commit comments