MCPcopy Index your code
hub / github.com/ampproject/amphtml / installShadowStyle

Function installShadowStyle

src/core/dom/shadow-embed.js:11–34  ·  view source on GitHub ↗
(shadowRoot, name, cssText)

Source from the content-addressed store, hash-verified

9 * @param {string} cssText
10 */
11export 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

Callers 2

rerender_Method · 0.90

Calls 4

toWinFunction · 0.90
devAssertFunction · 0.90
concatMethod · 0.80
setAttributeMethod · 0.45

Tested by

no test coverage detected