export function getTooltipRect ( { parentRect , tooltipSize , vertical , horizontal , isMultiLine = false , isIcon = false , outerMargin , } ) { const top = getTop ( { parentRect , tooltipHeight : tooltipSize . height , vertical , outerMargin , } ) ; const left = getLeft ( { parentRect , tooltipWidth : tooltipSize . width , horizontal , vertical , isIcon , outerMargin , } ) ; return { top : top + window . pageYOffset , left : left + window . pageXOffset , $width : isMultiLine ? Math . min ( parentRect . width , tooltipSize . width ) : tooltipSize . width , $height : tooltipSize . height , } ; } function getTop ( { parentRect , tooltipHeight , vertical , outerMargin , } ) { switch ( vertical ) { case 'top' : return parentRect . top + parentRect . height + outerMargin ; case 'middle' : return parentRect . top + ( parentRect . height - tooltipHeight ) / 2 ; case 'bottom' : return parentRect . top - tooltipHeight - outerMargin ; } } function getLeft ( { parentRect , tooltipWidth , horizontal , vertical , isIcon , outerMargin , } ) { switch ( vertical ) { case 'middle' : switch ( horizontal ) { case 'right' : return parentRect . left - tooltipWidth - outerMargin ; default : return parentRect . left + parentRect . width + outerMargin ; } case 'top' : case 'bottom' : { const arrowPosition = 29 ; const iconGap = isIcon ? arrowPosition - parentRect . width / 2 : 0 ; switch ( horizontal ) { case 'right' : return parentRect . left + parentRect . width - tooltipWidth + iconGap ; case 'center' : return parentRect . left + ( parentRect . width - tooltipWidth ) / 2 ; case 'left' : return parentRect . left - iconGap ; } } } }