All files / react-native-web/src/exports/StyleSheet createCompileableStyle.js

100% Statements 21/21
92.86% Branches 26/28
100% Functions 3/3
100% Lines 21/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71                        21x     6x 6x 6x 6x         9x 9x 9x 9x 9x 9x 9x   9x             4x       21x                   663x   663x           6x     663x 9x   663x        
/**
 * Copyright (c) Nicolas Gallagher.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow strict-local
 */
 
import normalizeValueWithProperty from './normalizeValueWithProperty';
import resolveShadowValue from './resolveShadowValue';
 
const defaultOffset = { height: 0, width: 0 };
 
function boxShadowReducer(resolvedStyle, style) {
  const { boxShadow } = style;
  const shadow = resolveShadowValue(style);
  Eif (shadow != null) {
    resolvedStyle.boxShadow = boxShadow ? `${boxShadow}, ${shadow}` : shadow;
  }
}
 
function textShadowReducer(resolvedStyle, style) {
  const { textShadowColor, textShadowOffset, textShadowRadius } = style;
  const { height, width } = textShadowOffset || defaultOffset;
  const radius = textShadowRadius || 0;
  const offsetX = normalizeValueWithProperty(width);
  const offsetY = normalizeValueWithProperty(height);
  const blurRadius = normalizeValueWithProperty(radius);
  const color = normalizeValueWithProperty(textShadowColor, 'textShadowColor');
 
  if (
    color &&
    (height !== 0 || width !== 0 || radius !== 0) &&
    offsetX != null &&
    offsetY != null &&
    blurRadius != null
  ) {
    resolvedStyle.textShadow = `${offsetX} ${offsetY} ${blurRadius} ${color}`;
  }
}
 
const createCompileableStyle = (styles: Object): Object => {
  const {
    shadowColor,
    shadowOffset,
    shadowOpacity,
    shadowRadius,
    textShadowColor,
    textShadowOffset,
    textShadowRadius,
    ...nextStyles
  } = styles;
 
  if (
    shadowColor != null ||
    shadowOffset != null ||
    shadowOpacity != null ||
    shadowRadius != null
  ) {
    boxShadowReducer(nextStyles, styles);
  }
 
  if (textShadowColor != null || textShadowOffset != null || textShadowRadius != null) {
    textShadowReducer(nextStyles, styles);
  }
  return nextStyles;
};
 
export default createCompileableStyle;