| 1 |
// The baseline for relative requests — attributes alone make an unstyled h1 look |
| 2 |
// size-less, so "larger" snaps below the theme default. |
| 3 |
const ALLOWLIST = [ |
| 4 |
'fontSize', |
| 5 |
'lineHeight', |
| 6 |
'fontWeight', |
| 7 |
'fontFamily', |
| 8 |
'fontStyle', |
| 9 |
'letterSpacing', |
| 10 |
'textTransform', |
| 11 |
'textDecoration', |
| 12 |
'color', |
| 13 |
'backgroundColor', |
| 14 |
'borderRadius', |
| 15 |
'borderWidth', |
| 16 |
'borderStyle', |
| 17 |
'borderColor', |
| 18 |
'boxShadow', |
| 19 |
'padding', |
| 20 |
'margin', |
| 21 |
]; |
| 22 |
|
| 23 |
const isEmptyValue = (value) => |
| 24 |
!value || value === 'normal' || value === 'none' || value === 'auto'; |
| 25 |
|
| 26 |
export const readComputedStyles = (el) => { |
| 27 |
if (!el?.ownerDocument?.defaultView) return null; |
| 28 |
const cs = el.ownerDocument.defaultView.getComputedStyle(el); |
| 29 |
const out = {}; |
| 30 |
for (const prop of ALLOWLIST) { |
| 31 |
const value = cs[prop]; |
| 32 |
if (!isEmptyValue(value)) out[prop] = value; |
| 33 |
} |
| 34 |
return Object.keys(out).length ? out : null; |
| 35 |
}; |
| 36 |
|