/** Check that `nodeA` and `nodeB` are from the same tree path */ export const isRelativeNode = ( nodeA , nodeB ) : boolean => { return ! ! ( nodeA && nodeB ) && ( nodeA . contains ( nodeB ) || nodeB . contains ( nodeA ) ) ; } ; /** Create function that finds next dom element, that matches selector, in the sequence declared by `next` function */ export const createSequenceFinder = ( next ) => { return function ( base , sel ) : Element | null { for ( let target = next ( base ) ; target ; target = next ( target ) ) { if ( ! sel || target . matches ( sel ) ) return target ; } return null ; } ; } ; returns export const findNext = createSequenceFinder ( ( el ) => el . nextElementSibling ) ; returns export const findPrev = createSequenceFinder ( ( el ) => el . previousElementSibling ) ; returns export const findParent = createSequenceFinder ( ( el ) => el . parentElement ) ; returns export const findAll = ( base , sel ) : Element [ ] => { return sel ? Array . from ( base . querySelectorAll ( sel ) ) : [ base ] ; } ; returns export const findChildren = ( base , sel ) : Element [ ] => { return Array . from ( base . children ) . filter ( ( el ) => ! sel || el . matches ( sel ) ) ; } ; /**
 * Find closest parent node of `node` by `predicate`.
 * Optional `skipSelf` to skip initial node
 */ export const findClosestBy = ( node , predicate , skipSelf = false ) : Node | null => { let current = skipSelf && node ? node . parentNode : node ; while ( current ) { if ( predicate ( current ) ) return current ; current = current . parentNode ; } return null ; } ; deprecated export abstract class TraversingUtils { static isRelative = isRelativeNode ; static closestBy = findClosestBy ; static createSequenceFinder = createSequenceFinder ; static findNext = findNext ; static findPrev = findPrev ; static findParent = findParent ; static findAll = findAll ; static findChildren = findChildren ; }