import { VNode } from 'vue' ; import { isString } from './is' ; export const NOOP = ( ) => { return undefined ; } ; export const isServerRendering = ( ( ) => { try { return ! ( typeof window !== 'undefined' && document !== undefined ) ; } catch ( e ) { return true ; } } ) ( ) ; export const on = ( ( ) => { if ( isServerRendering ) { return NOOP ; } return < K extends keyof HTMLElementEventMap > ( element , event , handler , options = false ) => { element . addEventListener ( event , handler as EventListenerOrEventListenerObject , options ) ; } ; } ) ( ) ; export const off = ( ( ) => { if ( isServerRendering ) { return NOOP ; } return < K extends keyof HTMLElementEventMap > ( element , type , handler , options = false ) => { element . removeEventListener ( type , handler as EventListenerOrEventListenerObject , options ) ; } ; } ) ( ) ; export const findDomNode = ( vnode ) => { let node = vnode . el ; while ( node && ! node . tagName ) { node = node . nextSibling ; } return node as HTMLElement ; } ; export const contains = ( root , ele ) => { let node = ele ; while ( node ) { if ( node === root ) { return true ; } node = node . parentNode ; } return false ; } ; export const OVERLAY_TYPES = [ 'modal' , 'message' , 'notification' ] as const ; export const getOverlay = ( type ) => { const popper = document . createElement ( 'div' ) ; popper . setAttribute ( 'class' , `arco-overlay arco-overlay-${ type }` ) ; return popper ; } ; export const querySelector = ( selectors , container ? ) => { if ( isServerRendering ) { return NOOP ( ) ; } return ( ( container ?? document ) . querySelector < HTMLElement > ( selectors ) ?? undefined ) ; } ; export const getElement = ( target , container ? ) : HTMLElement | undefined => { if ( isString ( target ) ) { const selector = target [ 0 ] === '#' ? `[id='${ target . slice ( 1 ) }']` : target ; return querySelector ( selector , container ) ; } return target ; } ; param target param relative export const getRelativeRect = ( target , relative ) => { const targetRect = target . getBoundingClientRect ( ) ; const relativeRect = relative . getBoundingClientRect ( ) ; return { top : targetRect . top - relativeRect . top , bottom : relativeRect . bottom - targetRect . bottom , left : targetRect . left - relativeRect . left , right : relativeRect . right - targetRect . right , width : targetRect . width , height : targetRect . height } ; } ; export const getScrollBarWidth = ( element ) => { return element . tagName === 'BODY' ? window . innerWidth - ( document . documentElement . offsetWidth || document . body . offsetWidth ) : element . offsetWidth - element . clientWidth ; } ;