react-native-web-internals
Version:
React Native for Web
122 lines (121 loc) • 6.43 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf, __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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
mod
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
var createReactDOMStyle_exports = {};
__export(createReactDOMStyle_exports, {
createTransformValue: () => createTransformValue,
default: () => createReactDOMStyle_default
});
module.exports = __toCommonJS(createReactDOMStyle_exports);
var import_canUseDOM = __toESM(require("../../modules/canUseDOM")), import_normalizeValueWithProperty = __toESM(require("./normalizeValueWithProperty"));
const emptyObject = {}, supportsCSS3TextDecoration = !import_canUseDOM.default || window.CSS != null && window.CSS.supports != null && (window.CSS.supports("text-decoration-line", "none") || window.CSS.supports("-webkit-text-decoration-line", "none")), ignoredProps = {
elevation: !0,
overlayColor: !0,
resizeMode: !0,
tintColor: !0
}, MONOSPACE_FONT_STACK = "monospace,monospace", SYSTEM_FONT_STACK = '-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif', STYLE_SHORT_FORM_EXPANSIONS = {
borderColor: [
"borderTopColor",
"borderRightColor",
"borderBottomColor",
"borderLeftColor"
],
borderRadius: [
"borderTopLeftRadius",
"borderTopRightRadius",
"borderBottomRightRadius",
"borderBottomLeftRadius"
],
borderStyle: [
"borderTopStyle",
"borderRightStyle",
"borderBottomStyle",
"borderLeftStyle"
],
borderWidth: [
"borderTopWidth",
"borderRightWidth",
"borderBottomWidth",
"borderLeftWidth"
],
marginHorizontal: ["marginRight", "marginLeft"],
marginVertical: ["marginTop", "marginBottom"],
overflow: ["overflowX", "overflowY"],
overscrollBehavior: ["overscrollBehaviorX", "overscrollBehaviorY"],
paddingHorizontal: ["paddingRight", "paddingLeft"],
paddingVertical: ["paddingTop", "paddingBottom"]
}, mapTransform = (transform) => {
const type = Object.keys(transform)[0], value = transform[type];
if (type === "matrix" || type === "matrix3d")
return `${type}(${value.join(",")})`;
{
const normalizedValue = (0, import_normalizeValueWithProperty.default)(value, type);
return `${type}(${normalizedValue})`;
}
}, createTransformValue = (style) => {
let transform = style.transform;
return Array.isArray(style.transform) && (transform = style.transform.map(mapTransform).join(" ")), transform;
}, createReactDOMStyle = (style, isInline) => {
if (!style)
return emptyObject;
const resolvedStyle = {};
for (const prop in style) {
const value = style[prop];
if (
// Ignore everything with a null value
!(value == null || // Ignore some React Native styles
ignoredProps[prop])
)
if (prop === "aspectRatio")
resolvedStyle[prop] = value.toString();
else if (prop === "backgroundClip")
value === "text" && (resolvedStyle.backgroundClip = value, resolvedStyle.WebkitBackgroundClip = value);
else if (prop === "flex")
value === -1 ? (resolvedStyle.flexGrow = 0, resolvedStyle.flexShrink = 1, resolvedStyle.flexBasis = "auto") : resolvedStyle.flex = value;
else if (prop === "font")
resolvedStyle[prop] = value.replace("System", SYSTEM_FONT_STACK);
else if (prop === "fontFamily")
if (value.indexOf("System") > -1) {
const stack = value.split(/,\s*/);
stack[stack.indexOf("System")] = SYSTEM_FONT_STACK, resolvedStyle[prop] = stack.join(",");
} else value === "monospace" ? resolvedStyle[prop] = MONOSPACE_FONT_STACK : resolvedStyle[prop] = value;
else if (prop === "fontVariant")
Array.isArray(value) && value.length > 0 && (resolvedStyle.fontVariant = value.join(" "));
else if (prop === "textAlignVertical")
resolvedStyle.verticalAlign = value === "center" ? "middle" : value;
else if (prop === "textDecorationLine")
supportsCSS3TextDecoration ? resolvedStyle.textDecorationLine = value : resolvedStyle.textDecoration = value;
else if (prop === "transform" || prop === "transformMatrix")
resolvedStyle.transform = createTransformValue(style);
else if (prop === "writingDirection")
resolvedStyle.direction = value;
else {
const value2 = (0, import_normalizeValueWithProperty.default)(style[prop], prop), longFormProperties = STYLE_SHORT_FORM_EXPANSIONS[prop];
isInline && prop === "margin" ? (style.marginHorizontal == null && (resolvedStyle.marginLeft = value2, resolvedStyle.marginRight = value2), style.marginVertical == null && (resolvedStyle.marginTop = value2, resolvedStyle.marginBottom = value2)) : isInline && prop === "padding" ? (style.paddingHorizontal == null && (resolvedStyle.paddingLeft = value2, resolvedStyle.paddingRight = value2), style.paddingVertical == null && (resolvedStyle.paddingTop = value2, resolvedStyle.paddingBottom = value2)) : longFormProperties ? longFormProperties.forEach((longForm, i) => {
style[longForm] == null && (resolvedStyle[longForm] = value2);
}) : resolvedStyle[prop] = Array.isArray(value2) ? value2.join(",") : value2;
}
}
return resolvedStyle;
};
var createReactDOMStyle_default = createReactDOMStyle;
//# sourceMappingURL=createReactDOMStyle.js.map