UNPKG

react-native-web-internals

Version:

React Native for Web

45 lines (44 loc) 2.72 kB
import normalizeColor from "./compiler/normalizeColor"; import normalizeValueWithProperty from "./compiler/normalizeValueWithProperty"; const emptyObject = {}, defaultOffset = { height: 0, width: 0 }, createBoxShadowValue = (style) => { const { shadowColor, shadowOffset, shadowOpacity, shadowRadius } = style, { height, width } = shadowOffset || defaultOffset, offsetX = normalizeValueWithProperty(width), offsetY = normalizeValueWithProperty(height), blurRadius = normalizeValueWithProperty(shadowRadius || 0), color = normalizeColor(shadowColor || "black", shadowOpacity); if (color != null && offsetX != null && offsetY != null && blurRadius != null) return `${offsetX} ${offsetY} ${blurRadius} ${color}`; }, createTextShadowValue = (style) => { const { textShadowColor, textShadowOffset, textShadowRadius } = style, { height, width } = textShadowOffset || defaultOffset, radius = textShadowRadius || 0, offsetX = normalizeValueWithProperty(width), offsetY = normalizeValueWithProperty(height), blurRadius = normalizeValueWithProperty(radius), color = normalizeValueWithProperty(textShadowColor, "textShadowColor"); if (color && (height !== 0 || width !== 0 || radius !== 0) && offsetX != null && offsetY != null && blurRadius != null) return `${offsetX} ${offsetY} ${blurRadius} ${color}`; }, preprocess = (originalStyle) => { const style = originalStyle || emptyObject, nextStyle = {}; for (const originalProp in style) { const originalValue = style[originalProp]; let prop = originalProp, value = originalValue; if (!(!Object.prototype.hasOwnProperty.call(style, originalProp) || originalValue == null)) { if (prop === "shadowColor" || prop === "shadowOffset" || prop === "shadowOpacity" || prop === "shadowRadius") { const boxShadowValue = createBoxShadowValue(style); if (boxShadowValue != null && nextStyle.boxShadow == null) { const { boxShadow } = style; prop = "boxShadow", value = boxShadow ? `${boxShadow}, ${boxShadowValue}` : boxShadowValue; } else continue; } if (prop === "textShadowColor" || prop === "textShadowOffset" || prop === "textShadowRadius") { const textShadowValue = createTextShadowValue(style); if (textShadowValue != null && nextStyle.textShadow == null) { const { textShadow } = style; prop = "textShadow", value = textShadow ? `${textShadow}, ${textShadowValue}` : textShadowValue; } else continue; } nextStyle[prop] = value; } } return nextStyle; }, processStyle = preprocess; export { createBoxShadowValue, createTextShadowValue, preprocess, processStyle }; //# sourceMappingURL=preprocess.js.map