| 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 |
'minHeight', |
| 22 |
]; |
| 23 |
|
| 24 |
// Every block computes a min-height; only a set one is a size to step from. |
| 25 |
const isEmptyValue = (value, prop) => |
| 26 |
!value || |
| 27 |
value === 'normal' || |
| 28 |
value === 'none' || |
| 29 |
value === 'auto' || |
| 30 |
(prop === 'minHeight' && value === '0px'); |
| 31 |
|
| 32 |
export const readComputedStyles = (el) => { |
| 33 |
if (!el?.ownerDocument?.defaultView) return null; |
| 34 |
const cs = el.ownerDocument.defaultView.getComputedStyle(el); |
| 35 |
const out = {}; |
| 36 |
for (const prop of ALLOWLIST) { |
| 37 |
const value = cs[prop]; |
| 38 |
if (!isEmptyValue(value, prop)) out[prop] = value; |
| 39 |
} |
| 40 |
return Object.keys(out).length ? out : null; |
| 41 |
}; |
| 42 |
|