license let shadowDomIsSupported ; /** Checks whether the user's browser support Shadow DOM. */ export function _supportsShadowDom ( ) { if ( shadowDomIsSupported == null ) { const head = typeof document !== 'undefined' ? document . head : null ; shadowDomIsSupported = ! ! ( head && ( ( head as any ) . createShadowRoot || head . attachShadow ) ) ; } return shadowDomIsSupported ; } /** Gets the shadow root of an element, if supported and the element is inside the Shadow DOM. */ export function _getShadowRoot ( element ) { if ( _supportsShadowDom ( ) ) { const rootNode = element . getRootNode ? element . getRootNode ( ) : null ; if ( typeof ShadowRoot !== 'undefined' && ShadowRoot && rootNode instanceof ShadowRoot ) { return rootNode ; } } return null ; } /**
 * Gets the currently-focused element on the page while
 * also piercing through Shadow DOM boundaries.
 */ export function _getFocusedElementPierceShadowDom ( ) { let activeElement = typeof document !== 'undefined' && document ? ( document . activeElement as HTMLElement | null ) : null ; while ( activeElement && activeElement . shadowRoot ) { const newActiveElement = activeElement . shadowRoot . activeElement as HTMLElement | null ; if ( newActiveElement === activeElement ) { break ; } else { activeElement = newActiveElement ; } } return activeElement ; } /** Gets the target of an event while accounting for Shadow DOM. */ export function _getEventTarget < T extends EventTarget > ( event ) { return ( event . composedPath ? event . composedPath ( ) [ 0 ] : event . target ) as T | null ; }