react-native-web-internals
Version:
React Native for Web
43 lines (42 loc) • 1.96 kB
JavaScript
import canUseDOM from "../../modules/canUseDOM.mjs";
import createCSSStyleSheet from "./createCSSStyleSheet.mjs";
import createOrderedCSSStyleSheet from "./createOrderedCSSStyleSheet.mjs";
const defaultId = "react-native-stylesheet",
roots = /* @__PURE__ */new WeakMap(),
sheets = [],
initialRules = [
// minimal top-level reset
"html{-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:rgba(0,0,0,0);}", "body{margin:0;}",
// minimal form pseudo-element reset
"button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0;}", "input::-webkit-search-cancel-button,input::-webkit-search-decoration,input::-webkit-search-results-button,input::-webkit-search-results-decoration{display:none;}"];
function createSheet(root, id = defaultId) {
let sheet;
if (canUseDOM) {
const rootNode = root != null ? root.getRootNode() : document;
if (sheets.length === 0) sheet = createOrderedCSSStyleSheet(createCSSStyleSheet(id)), initialRules.forEach(rule => {
sheet.insert(rule, 0);
}), roots.set(rootNode, sheets.length), sheets.push(sheet);else {
const index = roots.get(rootNode);
if (index == null) {
const initialSheet = sheets[0],
textContent = initialSheet != null ? initialSheet.getTextContent() : "";
sheet = createOrderedCSSStyleSheet(createCSSStyleSheet(id, rootNode, textContent)), roots.set(rootNode, sheets.length), sheets.push(sheet);
} else sheet = sheets[index];
}
} else sheets.length === 0 ? (sheet = createOrderedCSSStyleSheet(createCSSStyleSheet(id)), initialRules.forEach(rule => {
sheet.insert(rule, 0);
}), sheets.push(sheet)) : sheet = sheets[0];
return {
getTextContent() {
return sheet.getTextContent();
},
id,
insert(cssText, groupValue) {
sheets.forEach(s => {
s.insert(cssText, groupValue);
});
}
};
}
export { createSheet };
//# sourceMappingURL=index.mjs.map