UNPKG

@wordpress/block-library

Version:
31 lines (27 loc) 798 B
function getComputedStyle( node ) { return node.ownerDocument.defaultView.getComputedStyle( node ); } export function detectColors( colorsDetectionElement, setColor, setBackground ) { if ( ! colorsDetectionElement ) { return; } setColor( getComputedStyle( colorsDetectionElement ).color ); let backgroundColorNode = colorsDetectionElement; let backgroundColor = getComputedStyle( backgroundColorNode ).backgroundColor; while ( backgroundColor === 'rgba(0, 0, 0, 0)' && backgroundColorNode.parentNode && backgroundColorNode.parentNode.nodeType === backgroundColorNode.parentNode.ELEMENT_NODE ) { backgroundColorNode = backgroundColorNode.parentNode; backgroundColor = getComputedStyle( backgroundColorNode ).backgroundColor; } setBackground( backgroundColor ); }