hidden-content-evaluate.js 919 B

12345678910111213141516171819202122232425262728293031323334
  1. import { hasContentVirtual, getComposedParent } from '../../commons/dom';
  2. function hiddenContentEvaluate(node, options, virtualNode) {
  3. const whitelist = [
  4. 'SCRIPT',
  5. 'HEAD',
  6. 'TITLE',
  7. 'NOSCRIPT',
  8. 'STYLE',
  9. 'TEMPLATE'
  10. ];
  11. if (
  12. !whitelist.includes(node.nodeName.toUpperCase()) &&
  13. hasContentVirtual(virtualNode)
  14. ) {
  15. const styles = window.getComputedStyle(node);
  16. if (styles.getPropertyValue('display') === 'none') {
  17. return undefined;
  18. } else if (styles.getPropertyValue('visibility') === 'hidden') {
  19. // Check if visibility isn't inherited
  20. const parent = getComposedParent(node);
  21. const parentStyle = parent && window.getComputedStyle(parent);
  22. if (
  23. !parentStyle ||
  24. parentStyle.getPropertyValue('visibility') !== 'hidden'
  25. ) {
  26. return undefined;
  27. }
  28. }
  29. }
  30. return true;
  31. }
  32. export default hiddenContentEvaluate;