(cssRules /* : string[] */)
| 23 | // tag on it if that exists in the DOM. This could be used for e.g. reusing the |
| 24 | // same style tag that server-side rendering inserts. |
| 25 | const injectStyleTag = (cssRules /* : string[] */) => { |
| 26 | if (styleTag == null) { |
| 27 | // Try to find a style tag with the `data-aphrodite` attribute first. |
| 28 | styleTag = ((document.querySelector("style[data-aphrodite]") /* : any */) /* : ?HTMLStyleElement */); |
| 29 | |
| 30 | // If that doesn't work, generate a new style tag. |
| 31 | if (styleTag == null) { |
| 32 | // Taken from |
| 33 | // http://stackoverflow.com/questions/524696/how-to-create-a-style-tag-with-javascript |
| 34 | const head = document.head || document.getElementsByTagName('head')[0]; |
| 35 | styleTag = document.createElement('style'); |
| 36 | |
| 37 | styleTag.type = 'text/css'; |
| 38 | styleTag.setAttribute("data-aphrodite", ""); |
| 39 | head.appendChild(styleTag); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | // $FlowFixMe |
| 44 | const sheet = ((styleTag.styleSheet || styleTag.sheet /* : any */) /* : CSSStyleSheet */); |
| 45 | |
| 46 | if (sheet.insertRule) { |
| 47 | let numRules = sheet.cssRules.length; |
| 48 | cssRules.forEach((rule) => { |
| 49 | try { |
| 50 | sheet.insertRule(rule, numRules); |
| 51 | numRules += 1; |
| 52 | } catch(e) { |
| 53 | // The selector for this rule wasn't compatible with the browser |
| 54 | } |
| 55 | }); |
| 56 | } else { |
| 57 | styleTag.innerText = (styleTag.innerText || '') + cssRules.join(''); |
| 58 | } |
| 59 | }; |
| 60 | |
| 61 | // Custom handlers for stringifying CSS values that have side effects |
| 62 | // (such as fontFamily, which can cause @font-face rules to be injected) |
no test coverage detected