@@ -332,26 +332,27 @@ function RemoteFunctions(config) {
332332 */
333333 function _calculateInfoBoxCharCount ( tagName , id , classes ) {
334334 // char count for tag name
335- let charCount = tagName . length ;
336-
335+ let tagNameCharCount = tagName . length ;
336+ let idNameCharCount = 0 ;
337+ let classNameCharCount = 0 ;
337338 // char count for id
338339 if ( id ) {
339- charCount + = id . length + 1 ; // +1 for #
340+ idNameCharCount = id . length + 1 ; // +1 for #
340341 }
341342
342343 // char count for classes
343344 if ( classes . length > 0 ) {
344345 for ( let i = 0 ; i < Math . min ( classes . length , 3 ) ; i ++ ) {
345- charCount += classes [ i ] . length + 1 ; // +1 for .
346+ classNameCharCount += classes [ i ] . length + 1 ; // +1 for .
346347 }
347348
348349 if ( classes . length > 3 ) {
349350 // "+ X more" for more than 3 classes
350351 const moreText = `+${ classes . length - 3 } more` ;
351- charCount += moreText . length ;
352+ classNameCharCount += moreText . length ;
352353 }
353354 }
354- return charCount ;
355+ return Math . max ( tagNameCharCount , idNameCharCount , classNameCharCount ) ;
355356 }
356357
357358 /**
@@ -363,11 +364,14 @@ function RemoteFunctions(config) {
363364 * @returns {Number } - the total char count
364365 */
365366 function checkOverlap ( elemWidth , tagName , id , classes ) {
366- const avgCharWidth = 7 ;
367+ let avgCharWidth = 6 ;
367368 const basePadding = 16 ;
368369
369370 // char count for tag name, id, and classes
370371 let charCount = _calculateInfoBoxCharCount ( tagName , id , classes ) ;
372+ if ( charCount <= 10 ) {
373+ avgCharWidth = 7.5 ;
374+ }
371375
372376 // calc estimate width based on the char count
373377 const infoBoxWidth = basePadding + ( charCount * avgCharWidth ) ;
@@ -637,14 +641,17 @@ function RemoteFunctions(config) {
637641 ? elemBounds . top + elemBounds . height + 5
638642 : elemBounds . top - pushBoxUp ) + scrollTop ;
639643
640- const avgCharWidth = 7 ;
644+ let avgCharWidth = 6 ;
641645 const basePadding = 16 ;
642646
643647 // Get the tag name
644648 const tagName = this . element . tagName . toLowerCase ( ) ;
645649
646650 // Count characters in tag name, id, and classes
647651 let charCount = _calculateInfoBoxCharCount ( tagName , id , classes ) ;
652+ if ( charCount <= 10 ) {
653+ avgCharWidth = 7.5 ;
654+ }
648655
649656 // Calculate estimated width based on character count
650657 // Formula: base padding + (character count * average character width)
@@ -698,7 +705,7 @@ function RemoteFunctions(config) {
698705 position: absolute;
699706 left: ${ leftPos } px;
700707 top: ${ topPos } px;
701- max-width: ${ boxWidth } px ;
708+ max-width: fit-content ;
702709 box-sizing: border-box;
703710 pointer-events: none;
704711 }
0 commit comments