react-native-web-internals
Version:
React Native for Web
105 lines (104 loc) • 4.53 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: !0 });
}, __copyProps = (to, from, except, desc) => {
if (from && typeof from == "object" || typeof from == "function")
for (let key of __getOwnPropNames(from))
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
var StyleSheet_exports = {};
__export(StyleSheet_exports, {
default: () => StyleSheet,
flatten: () => flatten
});
module.exports = __toCommonJS(StyleSheet_exports);
var import_styleq = require("styleq"), import_transform_localize_style = require("styleq/transform-localize-style.js"), import__ = require("../index"), import_compiler = require("./compiler/index"), import_dom = require("./dom/index"), import_preprocess = require("./preprocess"), import_validate = require("./validate");
const staticStyleMap = /* @__PURE__ */ new WeakMap(), sheet = (0, import_dom.createSheet)();
function customStyleq(styles, isRTL) {
return import_styleq.styleq.factory({
transform(style) {
const compiledStyle = staticStyleMap.get(style);
return compiledStyle != null ? (0, import_transform_localize_style.localizeStyle)(compiledStyle, isRTL) : style;
}
})(styles);
}
function insertRules(compiledOrderedRules) {
compiledOrderedRules.forEach(([rules, order]) => {
sheet != null && rules.forEach((rule) => {
sheet.insert(rule, order);
});
});
}
function compileAndInsertAtomic(style) {
const [compiledStyle, compiledOrderedRules] = (0, import_compiler.atomic)((0, import_preprocess.preprocess)(style));
return insertRules(compiledOrderedRules), compiledStyle;
}
function compileAndInsertReset(style, key) {
const [compiledStyle, compiledOrderedRules] = (0, import_compiler.classic)(style, key);
return insertRules(compiledOrderedRules), compiledStyle;
}
const absoluteFillObject = {
position: "absolute",
left: 0,
right: 0,
top: 0,
bottom: 0
}, absoluteFill = create({ x: { ...absoluteFillObject } }).x;
function create(styles) {
return Object.keys(styles).forEach((key) => {
const styleObj = styles[key];
if (styleObj != null && styleObj.$$css !== !0) {
let compiledStyles;
key.indexOf("$raw") > -1 ? compiledStyles = compileAndInsertReset(styleObj, key.split("$raw")[0]) : (process.env.NODE_ENV !== "production" && ((0, import_validate.validate)(styleObj), styles[key] = Object.freeze(styleObj)), compiledStyles = compileAndInsertAtomic(styleObj)), staticStyleMap.set(styleObj, compiledStyles);
}
}), styles;
}
function compose(style1, style2) {
if (process.env.NODE_ENV !== "production") {
const len = arguments.length;
if (len > 2) {
const readableStyles = [...arguments].map((a) => flatten(a));
throw new Error(
`StyleSheet.compose() only accepts 2 arguments, received ${len}: ${JSON.stringify(
readableStyles
)}`
);
}
}
return style1 && style2 ? [style1, style2] : style1 || style2;
}
function flatten(...styles) {
const flatArray = styles.flat(1 / 0), result = {};
for (let i = 0; i < flatArray.length; i++) {
const style = flatArray[i];
style != null && typeof style == "object" && Object.assign(result, style);
}
return result;
}
function getSheet() {
return {
id: sheet.id,
textContent: sheet.getTextContent()
};
}
function StyleSheet(styles, options) {
const isRTL = options != null && options.writingDirection === "rtl", styleProps = customStyleq(styles, isRTL);
return Array.isArray(styleProps) && styleProps[1] != null && (styleProps[1] = (0, import_compiler.inline)((0, import_preprocess.preprocess)(styleProps[1]), isRTL)), styleProps;
}
StyleSheet.absoluteFill = absoluteFill;
StyleSheet.absoluteFillObject = absoluteFillObject;
StyleSheet.create = create;
StyleSheet.compose = compose;
StyleSheet.flatten = flatten;
StyleSheet.getSheet = getSheet;
StyleSheet.hairlineWidth = 1;
setTimeout(() => {
import__.canUseDOM && window.__REACT_DEVTOOLS_GLOBAL_HOOK__ && (window.__REACT_DEVTOOLS_GLOBAL_HOOK__.resolveRNStyle = StyleSheet.flatten);
}, 100);
//# sourceMappingURL=index.js.map