|
24 | 24 | return PolymerDomModule.import(moduleId);
|
25 | 25 | }
|
26 | 26 |
|
| 27 | + function styleForImport(importDoc) { |
| 28 | + // NOTE: polyfill affordance. |
| 29 | + // under the HTMLImports polyfill, there will be no 'body', |
| 30 | + // but the import pseudo-doc can be used directly. |
| 31 | + let container = importDoc.body ? importDoc.body : importDoc; |
| 32 | + const importCss = Polymer.ResolveUrl.resolveCss(container.textContent, |
| 33 | + importDoc.baseURI); |
| 34 | + const style = document.createElement('style'); |
| 35 | + style.textContent = importCss; |
| 36 | + return style; |
| 37 | + } |
| 38 | + |
27 | 39 | /** @typedef {{assetpath: string}} */
|
28 | 40 | let templateWithAssetPath; // eslint-disable-line no-unused-vars
|
29 | 41 |
|
|
108 | 120 | if (include) {
|
109 | 121 | styles.push(...this.stylesFromModules(include));
|
110 | 122 | }
|
111 |
| - if (window.ShadyDOM && e.hasAttribute(SHADY_UNSCOPED_ATTR)) { |
112 |
| - e.textContent = baseURI ? |
113 |
| - Polymer.ResolveUrl.resolveCss(e.textContent, baseURI) : e.textContent; |
114 |
| - document.head.insertBefore(e, document.head.firstChild); |
115 |
| - } else { |
116 |
| - styles.push(e); |
| 123 | + if (baseURI) { |
| 124 | + e.textContent = Polymer.ResolveUrl.resolveCss(e.textContent, baseURI); |
117 | 125 | }
|
| 126 | + styles.push(e); |
118 | 127 | }
|
119 | 128 | template._styles = styles;
|
120 | 129 | }
|
|
147 | 156 | let p = p$[i];
|
148 | 157 | if (p.import) {
|
149 | 158 | const importDoc = p.import;
|
150 |
| - if (!importDoc._style) { |
151 |
| - // NOTE: polyfill affordance. |
152 |
| - // under the HTMLImports polyfill, there will be no 'body', |
153 |
| - // but the import pseudo-doc can be used directly. |
154 |
| - let container = importDoc.body ? importDoc.body : importDoc; |
155 |
| - const importCss = Polymer.ResolveUrl.resolveCss(container.textContent, |
156 |
| - importDoc.baseURI); |
157 |
| - const style = document.createElement('style'); |
158 |
| - if (p.hasAttribute(SHADY_UNSCOPED_ATTR)) { |
159 |
| - style.setAttribute(SHADY_UNSCOPED_ATTR, ''); |
160 |
| - } |
161 |
| - style.textContent = importCss; |
162 |
| - importDoc._style = style; |
163 |
| - } |
164 |
| - // support the shady-unscoped promoting styles to main document |
165 |
| - if (window.ShadyDOM && |
166 |
| - importDoc._style.hasAttribute(SHADY_UNSCOPED_ATTR) && |
167 |
| - !importDoc._style.parentNode) { |
168 |
| - document.head.insertBefore(importDoc._style, document.head.firstChild); |
169 |
| - } else { |
170 |
| - styles.push(importDoc._style); |
| 159 | + const unscoped = p.hasAttribute(SHADY_UNSCOPED_ATTR); |
| 160 | + if (unscoped && !importDoc._unscopedStyle) { |
| 161 | + const style = styleForImport(importDoc); |
| 162 | + style.setAttribute(SHADY_UNSCOPED_ATTR, ''); |
| 163 | + importDoc._unscopedStyle = style; |
| 164 | + } else if (!importDoc._style) { |
| 165 | + importDoc._style = styleForImport(importDoc); |
171 | 166 | }
|
| 167 | + styles.push(unscoped ? importDoc._unscopedStyle : importDoc._style); |
172 | 168 | }
|
173 | 169 | }
|
174 | 170 | return styles;
|
|
218 | 214 | // include css from the first template in the module
|
219 | 215 | let t = m.querySelector('template');
|
220 | 216 | if (t) {
|
221 |
| - cssText += this.cssFromTemplate(t, /** @type {templateWithAssetPath} */(m).assetpath); |
| 217 | + cssText += this.cssFromTemplate(t, |
| 218 | + /** @type {templateWithAssetPath} */(m).assetpath); |
222 | 219 | }
|
223 | 220 | m._cssText = cssText || null;
|
224 | 221 | }
|
|
250 | 247 | if (e.parentNode) {
|
251 | 248 | e.parentNode.removeChild(e);
|
252 | 249 | }
|
253 |
| - const styleCss = baseURI ? |
254 |
| - Polymer.ResolveUrl.resolveCss(e.textContent, baseURI) : e.textContent; |
255 |
| - if (window.ShadyDOM && e.hasAttribute(SHADY_UNSCOPED_ATTR)) { |
256 |
| - e.textContent = styleCss; |
257 |
| - document.head.insertBefore(e, document.head.firstChild); |
258 |
| - } else { |
259 |
| - cssText += styleCss; |
260 |
| - } |
| 250 | + cssText += e.textContent; |
261 | 251 | }
|
262 | 252 | return cssText;
|
263 | 253 | },
|
|
294 | 284 | cssText += styles[i].textContent;
|
295 | 285 | }
|
296 | 286 | return cssText;
|
297 |
| - }, |
| 287 | + } |
298 | 288 | };
|
299 | 289 |
|
300 | 290 | Polymer.StyleGather = StyleGather;
|
|
0 commit comments