GT2/Ejectable/node_modules/react-native-web/dist/exports/StyleSheet/createCSSStyleSheet.js

34 lines
856 B
JavaScript
Raw Normal View History

2021-08-16 00:14:59 +00: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;
}
}