(shadowRoot, css)
| 213 | * @visibleForTesting |
| 214 | */ |
| 215 | export function scopeShadowCss(shadowRoot, css) { |
| 216 | const id = devAssert(shadowRoot['id']); |
| 217 | const doc = shadowRoot.ownerDocument; |
| 218 | let rules = null; |
| 219 | // Try to use a separate document. |
| 220 | try { |
| 221 | rules = getStylesheetRules(doc.implementation.createHTMLDocument(''), css); |
| 222 | } catch (e) { |
| 223 | // Ignore. |
| 224 | } |
| 225 | // Try to use the current document. |
| 226 | if (!rules) { |
| 227 | try { |
| 228 | rules = getStylesheetRules(doc, css); |
| 229 | } catch (e) { |
| 230 | // Ignore. |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | // No rules could be parsed - return css as is. |
| 235 | if (!rules) { |
| 236 | return css; |
| 237 | } |
| 238 | |
| 239 | // Patch selectors. |
| 240 | return ShadowCSS.scopeRules(rules, `.${id}`, transformRootSelectors); |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * Replaces top-level selectors such as `html` and `body` with their polyfill |
no test coverage detected