function walkFromNode(node, walkForward) {
   if (!walkForward) {
     return node.previousSibling || node.parentNode || null;
   }
 
   while (node) {
     if (node.nextSibling) {
       return node.nextSibling;
     }
 
     node = node.parentNode;
   }
 
   return null;
 }
Returns the next valid node (element or text). This is needed as Safari doesn't support
TreeWalker inside Shadow DOM. Don't escape shadow roots.

@param {!Node} node to start from
@param {boolean} walkForward should this walk in natural direction
@return {Node} node found, if any