text: function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  
  /**
   * Copyright (c) Nicolas Gallagher.
   * Copyright (c) Facebook, Inc. and its affiliates.
   *
   * This source code is licensed under the MIT license found in the
   * LICENSE file in the root directory of this source tree.
   *
   * 
   */
  import * as React from 'react';
  import createElement from '../createElement';
  import css from '../StyleSheet/css';
  import * as forwardedProps from '../../modules/forwardedProps';
  import pick from '../../modules/pick';
  import useElementLayout from '../../modules/useElementLayout';
  import useMergeRefs from '../../modules/useMergeRefs';
  import usePlatformMethods from '../../modules/usePlatformMethods';
  import useResponderEvents from '../../modules/useResponderEvents';
  import StyleSheet from '../StyleSheet';
  import TextAncestorContext from './TextAncestorContext';
  
  var forwardPropsList = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, forwardedProps.defaultProps), forwardedProps.accessibilityProps), forwardedProps.clickProps), forwardedProps.focusProps), forwardedProps.keyboardProps), forwardedProps.mouseProps), forwardedProps.touchProps), forwardedProps.styleProps), {}, {
    href: true,
    lang: true,
    pointerEvents: true
  });
  
  var pickProps = function pickProps(props) {
    return pick(props, forwardPropsList);
  };
  
  var Text = /*#__PURE__*/React.forwardRef(function (props, forwardedRef) {
    var dir = props.dir,
        hrefAttrs = props.hrefAttrs,
        numberOfLines = props.numberOfLines,
        onClick = props.onClick,
        onLayout = props.onLayout,
        onPress = props.onPress,
        onMoveShouldSetResponder = props.onMoveShouldSetResponder,
        onMoveShouldSetResponderCapture = props.onMoveShouldSetResponderCapture,
        onResponderEnd = props.onResponderEnd,
        onResponderGrant = props.onResponderGrant,
        onResponderMove = props.onResponderMove,
        onResponderReject = props.onResponderReject,
        onResponderRelease = props.onResponderRelease,
        onResponderStart = props.onResponderStart,
        onResponderTerminate = props.onResponderTerminate,
        onResponderTerminationRequest = props.onResponderTerminationRequest,
        onScrollShouldSetResponder = props.onScrollShouldSetResponder,
        onScrollShouldSetResponderCapture = props.onScrollShouldSetResponderCapture,
        onSelectionChangeShouldSetResponder = props.onSelectionChangeShouldSetResponder,
        onSelectionChangeShouldSetResponderCapture = props.onSelectionChangeShouldSetResponderCapture,
        onStartShouldSetResponder = props.onStartShouldSetResponder,
        onStartShouldSetResponderCapture = props.onStartShouldSetResponderCapture,
        selectable = props.selectable;
    var hasTextAncestor = React.useContext(TextAncestorContext);
    var hostRef = React.useRef(null);
    var classList = [classes.text, hasTextAncestor === true && classes.textHasAncestor, numberOfLines != null && classes.textMultiLine];
    var style = [props.style, numberOfLines != null && {
      WebkitLineClamp: numberOfLines
    }, selectable === true && styles.selectable, selectable === false && styles.notSelectable, onPress && styles.pressable];
    useElementLayout(hostRef, onLayout);
    useResponderEvents(hostRef, {
      onMoveShouldSetResponder: onMoveShouldSetResponder,
      onMoveShouldSetResponderCapture: onMoveShouldSetResponderCapture,
      onResponderEnd: onResponderEnd,
      onResponderGrant: onResponderGrant,
      onResponderMove: onResponderMove,
      onResponderReject: onResponderReject,
      onResponderRelease: onResponderRelease,
      onResponderStart: onResponderStart,
      onResponderTerminate: onResponderTerminate,
      onResponderTerminationRequest: onResponderTerminationRequest,
      onScrollShouldSetResponder: onScrollShouldSetResponder,
      onScrollShouldSetResponderCapture: onScrollShouldSetResponderCapture,
      onSelectionChangeShouldSetResponder: onSelectionChangeShouldSetResponder,
      onSelectionChangeShouldSetResponderCapture: onSelectionChangeShouldSetResponderCapture,
      onStartShouldSetResponder: onStartShouldSetResponder,
      onStartShouldSetResponderCapture: onStartShouldSetResponderCapture
    });
    var handleClick = React.useCallback(function (e) {
      if (onClick != null) {
        onClick(e);
      } else if (onPress != null) {
        e.stopPropagation();
        onPress(e);
      }
    }, [onClick, onPress]);
    var component = hasTextAncestor ? 'span' : 'div';
    var supportedProps = pickProps(props);
    supportedProps.classList = classList;
    supportedProps.dir = dir; // 'auto' by default allows browsers to infer writing direction (root elements only)
  
    if (!hasTextAncestor) {
      supportedProps.dir = dir != null ? dir : 'auto';
    }
  
    if (onClick || onPress) {
      supportedProps.onClick = handleClick;
    }
  
    supportedProps.style = style;
  
    if (props.href != null) {
      component = 'a';
  
      if (hrefAttrs != null) {
        var download = hrefAttrs.download,
            rel = hrefAttrs.rel,
            target = hrefAttrs.target;
  
        if (download != null) {
          supportedProps.download = download;
        }
  
        if (rel != null) {
          supportedProps.rel = rel;
        }
  
        if (typeof target === 'string') {
          supportedProps.target = target.charAt(0) !== '_' ? '_' + target : target;
        }
      }
    }
  
    var platformMethodsRef = usePlatformMethods(supportedProps);
    var setRef = useMergeRefs(hostRef, platformMethodsRef, forwardedRef);
    supportedProps.ref = setRef;
    var element = createElement(component, supportedProps);
    return hasTextAncestor ? element : /*#__PURE__*/React.createElement(TextAncestorContext.Provider, {
      value: true
    }, element);
  });
  Text.displayName = 'Text';
  var classes = css.create({
    text: {
      border: '0 solid black',
      boxSizing: 'border-box',
      color: 'black',
      display: 'inline',
      font: '14px System',
      margin: 0,
      padding: 0,
      whiteSpace: 'pre-wrap',
      wordWrap: 'break-word'
    },
    textHasAncestor: {
      color: 'inherit',
      font: 'inherit',
      whiteSpace: 'inherit'
    },
    // See #13
    textMultiLine: {
      display: '-webkit-box',
      maxWidth: '100%',
      overflow: 'hidden',
      textOverflow: 'ellipsis',
      WebkitBoxOrient: 'vertical'
    }
  });
  var styles = StyleSheet.create({
    notSelectable: {
      userSelect: 'none'
    },
    selectable: {
      userSelect: 'text'
    },
    pressable: {
      cursor: 'pointer'
    }
  });
  export default Text;