|
25 | 25 | * - Document styles defined in a `<custom-style>` are shimmed to ensure they
|
26 | 26 | * do not leak into local DOM when running on browsers without native
|
27 | 27 | * Shadow DOM.
|
28 |
| - * - Custom properties can be defined in a `<custom-style>`. Use the `html` selector |
| 28 | + * - Custom properties can be defined in a `<custom-style>`. Use the `html` selector |
29 | 29 | * to define custom properties that apply to all custom elements.
|
30 |
| - * - Custom mixins can be defined in a `<custom-style>`, if you import the optional |
| 30 | + * - Custom mixins can be defined in a `<custom-style>`, if you import the optional |
31 | 31 | * [apply shim](https://github.com/webcomponents/shadycss#about-applyshim)
|
32 | 32 | * (`shadycss/apply-shim.html`).
|
33 | 33 | *
|
34 | 34 | * To use:
|
35 |
| - * |
| 35 | + * |
36 | 36 | * - Import `custom-style.html`.
|
37 | 37 | * - Place a `<custom-style>` element in the main document, wrapping an inline `<style>` tag that
|
38 | 38 | * contains the CSS rules you want to shim.
|
39 |
| - * |
| 39 | + * |
40 | 40 | * For example:
|
41 | 41 | *
|
42 | 42 | * ```
|
|
91 | 91 | style.removeAttribute(attr);
|
92 | 92 | style.textContent = Polymer.StyleGather.cssFromModules(include) + style.textContent;
|
93 | 93 | }
|
| 94 | + /* |
| 95 | + HTML Imports styling the main document are deprecated in Chrome |
| 96 | + https://crbug.com/523952 |
| 97 | +
|
| 98 | + If this element is not in the main document, then it must be in an HTML Import document. |
| 99 | + In that case, copy the style into the main document and disable the current style. |
| 100 | + `__appliedElement` is used by the HTML Imports polyfill for this use case, and already understood by |
| 101 | + ShadyCSS's Custom Style Interface. |
| 102 | +
|
| 103 | + The ordering of `<custom-style>` should stay the same as when loaded by HTML Imports, but there may be odd |
| 104 | + cases of ordering w.r.t the main document styles. |
| 105 | + */ |
| 106 | + if (this.ownerDocument !== window.document) { |
| 107 | + let appliedStyle = style.cloneNode(true); |
| 108 | + style.__appliedElement = appliedStyle; |
| 109 | + // disable style in the HTML Import document |
| 110 | + style.setAttribute('media', 'none'); |
| 111 | + window.document.head.appendChild(appliedStyle); |
| 112 | + } |
94 | 113 | return this._style;
|
95 | 114 | }
|
96 | 115 | }
|
|
0 commit comments