import { Children , cloneElement , ReactNode , ReactElement } from 'react' ; import { BooleanPredicate , PredicateParams , MenuAnimation , TriggerEvent , } from '../types' ; export function isFn ( v ) { return typeof v === 'function' ; } export function isStr ( v ) { return typeof v === 'string' ; } export function isTouchEvent ( e ) { return e . type === 'touchend' ; } export function cloneItems ( children , props ) { return Children . map ( Children . toArray ( children ) . filter ( Boolean ) , item => cloneElement ( item as ReactElement < any > , props ) ) ; } export function getMousePosition ( e ) { const pos = { x : 0 , y : 0 , } ; if ( isTouchEvent ( e ) && e . changedTouches && e . changedTouches . length > 0 ) { pos . x = e . changedTouches [ 0 ] . clientX ; pos . y = e . changedTouches [ 0 ] . clientY ; } else { pos . x = ( e as MouseEvent ) . clientX ; pos . y = ( e as MouseEvent ) . clientY ; } if ( ! pos . x || pos . x < 0 ) pos . x = 0 ; if ( ! pos . y || pos . y < 0 ) pos . y = 0 ; return pos ; } export function getPredicateValue ( predicate , payload ) { return isFn ( predicate ) ? predicate ( payload ) : predicate ; } export function hasExitAnimation ( animation ) { return ! ! ( animation && ( isStr ( animation ) || ( 'exit' in animation && animation . exit ) ) ) ; }