import { BasePlacement , Placement } from "@popperjs/core" ; /** Converts a full placement to one of the four positions by stripping text after the `-`. */ export function getBasePlacement ( placement ) { return placement . split ( "-" ) [ 0 ] as BasePlacement ; } /** Returns true if position is left or right. */ export function isVerticalPlacement ( side ) { return [ "left" , "right" ] . indexOf ( side ) !== - 1 ; } /** Returns the opposite position. */ export function getOppositePlacement ( side ) { switch ( side ) { case "top" : return "bottom" ; case "left" : return "right" ; case "bottom" : return "top" ; default : return "left" ; } } /** Returns the CSS alignment keyword corresponding to given placement. */ export function getAlignment ( placement ) { const align = placement . split ( "-" ) [ 1 ] as "start" | "end" | undefined ; switch ( align ) { case "start" : return "left" ; case "end" : return "right" ; default : return "center" ; } } /** Modifier helper function to compute popper transform-origin based on arrow position */ export function getTransformOrigin ( placement , arrowStyles ) { const basePlacement = getBasePlacement ( placement ) ; if ( arrowStyles === undefined ) { return isVerticalPlacement ( basePlacement ) ? `${ getOppositePlacement ( basePlacement ) } ${ getAlignment ( basePlacement ) }` : `${ getAlignment ( basePlacement ) } ${ getOppositePlacement ( basePlacement ) }` ; } else { const arrowSizeShift = 30 / 2 ; return isVerticalPlacement ( basePlacement ) ? `${ getOppositePlacement ( basePlacement ) } ${ parseInt ( arrowStyles . top , 10 ) + arrowSizeShift }px` : `${ parseInt ( arrowStyles . left , 10 ) + arrowSizeShift }px ${ getOppositePlacement ( basePlacement ) }` ; } }