(shadowRoot, name, cssText)
| 9 | * @param {string} cssText |
| 10 | */ |
| 11 | export function installShadowStyle(shadowRoot, name, cssText) { |
| 12 | const doc = shadowRoot.ownerDocument; |
| 13 | const win = toWin(doc.defaultView); |
| 14 | if ( |
| 15 | shadowRoot.adoptedStyleSheets !== undefined && |
| 16 | win.CSSStyleSheet.prototype.replaceSync !== undefined |
| 17 | ) { |
| 18 | const cache = win[SHADOW_CSS_CACHE] || (win[SHADOW_CSS_CACHE] = {}); |
| 19 | let styleSheet = cache[name]; |
| 20 | if (!styleSheet) { |
| 21 | styleSheet = new win.CSSStyleSheet(); |
| 22 | devAssert(styleSheet.replaceSync); |
| 23 | styleSheet.replaceSync(cssText); |
| 24 | cache[name] = styleSheet; |
| 25 | } |
| 26 | shadowRoot.adoptedStyleSheets = |
| 27 | shadowRoot.adoptedStyleSheets.concat(styleSheet); |
| 28 | } else { |
| 29 | const styleEl = doc.createElement('style'); |
| 30 | styleEl.setAttribute('data-name', name); |
| 31 | styleEl.textContent = cssText; |
| 32 | shadowRoot.appendChild(styleEl); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @param {!Window} win |
no test coverage detected