(style: CSSStyleDeclaration, iterate: (property: string, value: string) => void)
| 70 | }) : null; |
| 71 | |
| 72 | export function iterateCSSDeclarations(style: CSSStyleDeclaration, iterate: (property: string, value: string) => void): void { |
| 73 | const cssText = style.cssText; |
| 74 | if (cssText.includes('var(')) { |
| 75 | if (isSafari) { |
| 76 | // Safari doesn't show shorthand properties' values |
| 77 | shorthandVarDepPropRegexps!.forEach(([prop, regexp]) => { |
| 78 | const match = cssText.match(regexp); |
| 79 | if (match && match[1]) { |
| 80 | const val = match[1].trim(); |
| 81 | iterate(prop, val); |
| 82 | } |
| 83 | }); |
| 84 | } else { |
| 85 | shorthandVarDependantProperties.forEach((prop) => { |
| 86 | const val = style.getPropertyValue(prop); |
| 87 | if (val && val.includes('var(')) { |
| 88 | iterate(prop, val); |
| 89 | } |
| 90 | }); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | if ( |
| 95 | ( |
| 96 | cssText.includes('background-color: ;') || |
| 97 | cssText.includes('background-image: ;') |
| 98 | ) && !style.getPropertyValue('background') |
| 99 | ) { |
| 100 | handleEmptyShorthand('background', style, iterate); |
| 101 | } |
| 102 | if (cssText.includes('border-') && cssText.includes('-color: ;') && !style.getPropertyValue('border')) { |
| 103 | handleEmptyShorthand('border', style, iterate); |
| 104 | } |
| 105 | |
| 106 | forEach(style, (property) => { |
| 107 | const value = style.getPropertyValue(property).trim(); |
| 108 | if (!value) { |
| 109 | return; |
| 110 | } |
| 111 | iterate(property, value); |
| 112 | }); |
| 113 | } |
| 114 | |
| 115 | // `rule.cssText` fails when the rule has both |
| 116 | // `background: var()` and `background-*`. |
no test coverage detected