function getParentNode ( node , path ) { if ( node . parentNode ) { path . push ( node . parentNode ) ; getParentNode ( node . parentNode , path ) ; } } function getPath ( node ) { const path = [ ] ; path . push ( node ) ; getParentNode ( node , path ) ; return path ; } export const getSelector = ( event ) => { const immutableTarget = ( event . target || event . srcElement ) as any ; let target = ( event . target || event . srcElement ) as any ; const elements = [ ] ; for ( let i = 0 ; target && target . nodeType === Node . ELEMENT_NODE && target . nodeType !== Node . DOCUMENT_TYPE_NODE ; target = target . previousSibling ) { if ( i ) elements . push ( target ) ; i += 1 ; } const path = typeof event . path === 'undefined' ? getPath ( event . target as Node ) : event . path ; const { outerHTML } = immutableTarget ; return path . reverse ( ) . map ( ( node ) => ( node . localName || '' ) + ( node . id ? `#${ node . id }` : '' ) + ( node . className ? `.${ node . className }` : '' ) + ( node . outerHTML === outerHTML ? `:nth-child(${ elements . length })` : '' ) ) . filter ( ( v ) : boolean => Boolean ( v ) ) . join ( ' > ' ) ; } ;