UNPKG

react-native-web-internals

Version:

React Native for Web

118 lines (117 loc) 4.81 kB
"use strict"; 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"), staticStyleMap = /* @__PURE__ */ new WeakMap(), sheet = (0, import_dom.createSheet)(); function customStyleq(styles, isRTL) { return import_styleq.styleq.factory({ transform(style) { var compiledStyle = staticStyleMap.get(style); return compiledStyle != null ? (0, import_transform_localize_style.localizeStyle)(compiledStyle, isRTL) : style; } })(styles); } function insertRules(compiledOrderedRules) { compiledOrderedRules.forEach(function(param) { var [rules, order] = param; sheet != null && rules.forEach(function(rule) { sheet.insert(rule, order); }); }); } function compileAndInsertAtomic(style) { var [compiledStyle, compiledOrderedRules] = (0, import_compiler.atomic)((0, import_preprocess.preprocess)(style)); return insertRules(compiledOrderedRules), compiledStyle; } function compileAndInsertReset(style, key) { var [compiledStyle, compiledOrderedRules] = (0, import_compiler.classic)(style, key); return insertRules(compiledOrderedRules), compiledStyle; } var absoluteFillObject = { position: "absolute", left: 0, right: 0, top: 0, bottom: 0 }, absoluteFill = create({ x: { ...absoluteFillObject } }).x; function create(styles) { return Object.keys(styles).forEach(function(key) { var styleObj = styles[key]; if (styleObj != null && styleObj.$$css !== !0) { var 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") { var len = arguments.length; if (len > 2) { var readableStyles = [ ...arguments ].map(function(a) { return 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() { for (var _len = arguments.length, styles = new Array(_len), _key = 0; _key < _len; _key++) styles[_key] = arguments[_key]; for (var flatArray = styles.flat(1 / 0), result = {}, i = 0; i < flatArray.length; i++) { var 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) { var 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(function() { import__.canUseDOM && window.__REACT_DEVTOOLS_GLOBAL_HOOK__ && (window.__REACT_DEVTOOLS_GLOBAL_HOOK__.resolveRNStyle = StyleSheet.flatten); }, 100); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { flatten }); //# sourceMappingURL=index.js.map