* @param {!Document} doc * @param {string} css * @return {?CSSRuleList}
(doc, css)
| 277 | * @return {?CSSRuleList} |
| 278 | */ |
| 279 | function getStylesheetRules(doc, css) { |
| 280 | const style = /** @type {!HTMLStyleElement} */ (doc.createElement('style')); |
| 281 | style./*OK*/ textContent = css; |
| 282 | try { |
| 283 | (doc.head || doc.documentElement).appendChild(style); |
| 284 | if (style.sheet) { |
| 285 | return /** @type {!CSSStyleSheet} */ (style.sheet).cssRules; |
| 286 | } |
| 287 | return null; |
| 288 | } finally { |
| 289 | if (style.parentNode) { |
| 290 | style.parentNode.removeChild(style); |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * @param {boolean|undefined} val |