7979 case "SENTIENCE_SHOW_OVERLAY" :
8080 ! function ( data ) {
8181 const { elements : elements , targetElementId : targetElementId } = data ;
82- if ( ! elements || ! Array . isArray ( elements ) ) return ;
82+ if ( ! elements || "object" != typeof elements || "number" != typeof elements . length ) return ;
83+ const elementsArray = Array . isArray ( elements ) ? elements : Array . from ( elements ) ;
8384 removeOverlay ( ) ;
8485 const host = document . createElement ( "div" ) ;
85- host . id = OVERLAY_HOST_ID , host . style . cssText = "\n position: fixed !important;\n top: 0 !important;\n left: 0 !important;\n width: 100vw !important;\n height: 100vh !important;\n pointer-events: none !important;\n z-index: 2147483647 !important;\n margin: 0 !important;\n padding: 0 !important;\n " ,
86+ host . id = OVERLAY_HOST_ID , host . style . cssText = "\n position: fixed !important;\n top: 0 !important;\n left: 0 !important;\n width: 100vw !important;\n height: 100vh !important;\n pointer-events: none !important;\n z-index: 2147483647 !important;\n margin: 0 !important;\n padding: 0 !important;\n " ,
8687 document . body . appendChild ( host ) ;
8788 const shadow = host . attachShadow ( {
8889 mode : "closed"
89- } ) , maxImportance = Math . max ( ...elements . map ( e => e . importance || 0 ) , 1 ) ;
90- elements . forEach ( element => {
90+ } ) , maxImportance = Math . max ( ...elementsArray . map ( e => e . importance || 0 ) , 1 ) ;
91+ elementsArray . forEach ( element => {
9192 const bbox = element . bbox ;
9293 if ( ! bbox ) return ;
9394 const isTarget = element . id === targetElementId , isPrimary = element . visual_cues ?. is_primary || ! 1 , importance = element . importance || 0 ;
9495 let color ;
9596 color = isTarget ? "#FF0000" : isPrimary ? "#0066FF" : "#00FF00" ;
9697 const importanceRatio = maxImportance > 0 ? importance / maxImportance : .5 , borderOpacity = isTarget ? 1 : isPrimary ? .9 : Math . max ( .4 , .5 + .5 * importanceRatio ) , fillOpacity = .2 * borderOpacity , borderWidth = isTarget ? 2 : isPrimary ? 1.5 : Math . max ( .5 , Math . round ( 2 * importanceRatio ) ) , hexOpacity = Math . round ( 255 * fillOpacity ) . toString ( 16 ) . padStart ( 2 , "0" ) , box = document . createElement ( "div" ) ;
97- if ( box . style . cssText = `\n position: absolute;\n left: ${ bbox . x } px;\n top: ${ bbox . y } px;\n width: ${ bbox . width } px;\n height: ${ bbox . height } px;\n border: ${ borderWidth } px solid ${ color } ;\n background-color: ${ color } ${ hexOpacity } ;\n box-sizing: border-box;\n opacity: ${ borderOpacity } ;\n pointer-events: none;\n ` ,
98+ if ( box . style . cssText = `\n position: absolute;\n left: ${ bbox . x } px;\n top: ${ bbox . y } px;\n width: ${ bbox . width } px;\n height: ${ bbox . height } px;\n border: ${ borderWidth } px solid ${ color } ;\n background-color: ${ color } ${ hexOpacity } ;\n box-sizing: border-box;\n opacity: ${ borderOpacity } ;\n pointer-events: none;\n ` ,
9899 importance > 0 || isPrimary ) {
99100 const badge = document . createElement ( "span" ) ;
100- badge . textContent = isPrimary ? `⭐${ importance } ` : `${ importance } ` , badge . style . cssText = `\n position: absolute;\n top: -18px;\n left: 0;\n background: ${ color } ;\n color: white;\n font-size: 11px;\n font-weight: bold;\n padding: 2px 6px;\n font-family: Arial, sans-serif;\n border-radius: 3px;\n opacity: 0.95;\n white-space: nowrap;\n pointer-events: none;\n ` ,
101+ badge . textContent = isPrimary ? `⭐${ importance } ` : `${ importance } ` , badge . style . cssText = `\n position: absolute;\n top: -18px;\n left: 0;\n background: ${ color } ;\n color: white;\n font-size: 11px;\n font-weight: bold;\n padding: 2px 6px;\n font-family: Arial, sans-serif;\n border-radius: 3px;\n opacity: 0.95;\n white-space: nowrap;\n pointer-events: none;\n ` ,
101102 box . appendChild ( badge ) ;
102103 }
103104 if ( isTarget ) {
104105 const targetIndicator = document . createElement ( "span" ) ;
105- targetIndicator . textContent = "🎯" , targetIndicator . style . cssText = "\n position: absolute;\n top: -18px;\n right: 0;\n font-size: 16px;\n pointer-events: none;\n " ,
106+ targetIndicator . textContent = "🎯" , targetIndicator . style . cssText = "\n position: absolute;\n top: -18px;\n right: 0;\n font-size: 16px;\n pointer-events: none;\n " ,
106107 box . appendChild ( targetIndicator ) ;
107108 }
108109 shadow . appendChild ( box ) ;
122123 if ( ! grids || ! Array . isArray ( grids ) ) return ;
123124 removeOverlay ( ) ;
124125 const host = document . createElement ( "div" ) ;
125- host . id = OVERLAY_HOST_ID , host . style . cssText = "\n position: fixed !important;\n top: 0 !important;\n left: 0 !important;\n width: 100vw !important;\n height: 100vh !important;\n pointer-events: none !important;\n z-index: 2147483647 !important;\n margin: 0 !important;\n padding: 0 !important;\n " ,
126+ host . id = OVERLAY_HOST_ID , host . style . cssText = "\n position: fixed !important;\n top: 0 !important;\n left: 0 !important;\n width: 100vw !important;\n height: 100vh !important;\n pointer-events: none !important;\n z-index: 2147483647 !important;\n margin: 0 !important;\n padding: 0 !important;\n " ,
126127 document . body . appendChild ( host ) ;
127128 const shadow = host . attachShadow ( {
128129 mode : "closed"
138139 let labelText = grid . label ? `Grid ${ grid . grid_id } : ${ grid . label } ` : `Grid ${ grid . grid_id } ` ;
139140 grid . is_dominant && ( labelText = `⭐ ${ labelText } (dominant)` ) ;
140141 const badge = document . createElement ( "span" ) ;
141- if ( badge . textContent = labelText , badge . style . cssText = `\n position: absolute;\n top: -18px;\n left: 0;\n background: ${ color } ;\n color: white;\n font-size: 11px;\n font-weight: bold;\n padding: 2px 6px;\n font-family: Arial, sans-serif;\n border-radius: 3px;\n opacity: 0.95;\n white-space: nowrap;\n pointer-events: none;\n ` ,
142+ if ( badge . textContent = labelText , badge . style . cssText = `\n position: absolute;\n top: -18px;\n left: 0;\n background: ${ color } ;\n color: white;\n font-size: 11px;\n font-weight: bold;\n padding: 2px 6px;\n font-family: Arial, sans-serif;\n border-radius: 3px;\n opacity: 0.95;\n white-space: nowrap;\n pointer-events: none;\n ` ,
142143 box . appendChild ( badge ) , isTarget ) {
143144 const targetIndicator = document . createElement ( "span" ) ;
144- targetIndicator . textContent = "🎯" , targetIndicator . style . cssText = "\n position: absolute;\n top: -18px;\n right: 0;\n font-size: 16px;\n pointer-events: none;\n " ,
145+ targetIndicator . textContent = "🎯" , targetIndicator . style . cssText = "\n position: absolute;\n top: -18px;\n right: 0;\n font-size: 16px;\n pointer-events: none;\n " ,
145146 box . appendChild ( targetIndicator ) ;
146147 }
147148 shadow . appendChild ( box ) ;
155156 let overlayTimeout = null ;
156157 function removeOverlay ( ) {
157158 const existing = document . getElementById ( OVERLAY_HOST_ID ) ;
158- existing && existing . remove ( ) , overlayTimeout && ( clearTimeout ( overlayTimeout ) ,
159+ existing && existing . remove ( ) , overlayTimeout && ( clearTimeout ( overlayTimeout ) ,
159160 overlayTimeout = null ) ;
160161 }
161- } ( ) ;
162+ } ( ) ;
0 commit comments