dom_visible.js

/**
 * @module visible
 * @description Determine if an element is visible in the dom.
 *
 * @since 1.0.0
 *
 * @param {HTMLElement} elem The element to check for visibility.
 *
 * @return {boolean} Whether or not the element is visible.
 *
 * @example
 * import { getNodes, visible } from "@gravityforms/utils";
 *
 * function Example() {
 *   const target = getNodes( 'example' )[ 0 ];
 *   if ( visible( target ) ) {
 *       // do something
 *   }
 * }
 *
 */
export default function visible( elem ) {
	return !! (
		elem.offsetWidth ||
		elem.offsetHeight ||
		elem.getClientRects().length
	);
}