This repository has been archived on 2022-03-12. You can view files and clone it, but cannot push or open issues or pull requests.

34 lines
856 B
JavaScript
Raw Normal View History

2021-04-02 02:24:13 +03:00
/**
* Copyright (c) Nicolas Gallagher.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment'; // $FlowFixMe: HTMLStyleElement is incorrectly typed - https://github.com/facebook/flow/issues/2696
export default function createCSSStyleSheet(id) {
if (canUseDOM) {
var element = document.getElementById(id);
if (element != null) {
// $FlowFixMe: HTMLElement is incorrectly typed
return element.sheet;
} else {
var _element = document.createElement('style');
_element.setAttribute('id', id);
var head = document.head;
if (head) {
head.insertBefore(_element, head.firstChild);
}
return _element.sheet;
}
} else {
return null;
}
}