@tamagui/react-native-web-lite
Version:
React Native for Web
197 lines • 6.66 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__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: true
}) : target, mod));
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
value: true
}), mod);
var Text_exports = {};
__export(Text_exports, {
Text: () => Text,
default: () => Text_default
});
module.exports = __toCommonJS(Text_exports);
var import_react_native_web_internals = require("@tamagui/react-native-web-internals");
var React = __toESM(require("react"), 1);
var import_createElement = require("../createElement/index.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
const pickProps = props => (0, import_react_native_web_internals.pick)(props, import_react_native_web_internals.forwardPropsListText);
const Text = React.forwardRef((props, forwardedRef) => {
const {
hrefAttrs,
numberOfLines,
onClick,
onLayout,
onPress,
onMoveShouldSetResponder,
onMoveShouldSetResponderCapture,
onResponderEnd,
onResponderGrant,
onResponderMove,
onResponderReject,
onResponderRelease,
onResponderStart,
onResponderTerminate,
onResponderTerminationRequest,
onScrollShouldSetResponder,
onScrollShouldSetResponderCapture,
onSelectionChangeShouldSetResponder,
onSelectionChangeShouldSetResponderCapture,
onStartShouldSetResponder,
onStartShouldSetResponderCapture,
selectable,
...rest
} = props;
const hasTextAncestor = React.useContext(import_react_native_web_internals.TextAncestorContext);
const hostRef = React.useRef(null);
const {
direction: contextDirection
} = (0, import_react_native_web_internals.useLocaleContext)();
(0, import_react_native_web_internals.useElementLayout)(hostRef, onLayout);
(0, import_react_native_web_internals.useResponderEvents)(hostRef, {
onMoveShouldSetResponder,
onMoveShouldSetResponderCapture,
onResponderEnd,
onResponderGrant,
onResponderMove,
onResponderReject,
onResponderRelease,
onResponderStart,
onResponderTerminate,
onResponderTerminationRequest,
onScrollShouldSetResponder,
onScrollShouldSetResponderCapture,
onSelectionChangeShouldSetResponder,
onSelectionChangeShouldSetResponderCapture,
onStartShouldSetResponder,
onStartShouldSetResponderCapture
});
const handleClick = React.useCallback(e => {
if (onClick != null) {
onClick(e);
} else if (onPress != null) {
e.stopPropagation();
onPress(e);
}
}, [onClick, onPress]);
let component = hasTextAncestor ? "span" : "div";
const langDirection = props.lang != null ? (0, import_react_native_web_internals.getLocaleDirection)(props.lang) : null;
const componentDirection = props.dir || langDirection;
const writingDirection = componentDirection || contextDirection;
const supportedProps = pickProps(rest);
supportedProps.dir = componentDirection;
if (!hasTextAncestor) {
supportedProps.dir = componentDirection != null ? componentDirection : "auto";
}
if (onClick || onPress) {
supportedProps.onClick = handleClick;
}
supportedProps.style = [numberOfLines != null && numberOfLines > 1 && {
WebkitLineClamp: numberOfLines
}, hasTextAncestor === true ? styles.textHasAncestor$raw : styles.text, numberOfLines === 1 && styles.textOneLine, numberOfLines != null && numberOfLines > 1 && styles.textMultiLine, props.style, selectable === true && styles.selectable, selectable === false && styles.notSelectable, onPress && styles.pressable];
if (props.href != null) {
component = "a";
if (hrefAttrs != null) {
const {
download,
rel,
target
} = hrefAttrs;
if (download != null) {
supportedProps.download = download;
}
if (rel != null) {
supportedProps.rel = rel;
}
if (typeof target === "string") {
supportedProps.target = target.charAt(0) !== "_" ? "_" + target : target;
}
}
}
const platformMethodsRef = (0, import_react_native_web_internals.usePlatformMethods)(supportedProps);
const setRef = (0, import_react_native_web_internals.useMergeRefs)(hostRef, platformMethodsRef, forwardedRef);
supportedProps.ref = setRef;
const element = (0, import_createElement.useCreateElement)(component, supportedProps, {
writingDirection
});
return hasTextAncestor ? element : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react_native_web_internals.TextAncestorContext.Provider, {
value: true,
children: element
});
});
Text.displayName = "Text";
const textStyle = {
backgroundColor: "transparent",
border: "0 solid black",
boxSizing: "border-box",
color: "black",
display: "inline",
font: "14px System",
listStyle: "none",
margin: 0,
padding: 0,
textAlign: "inherit",
textDecoration: "none",
whiteSpace: "pre-wrap",
wordWrap: "break-word"
};
const styles = {
text: textStyle,
textHasAncestor$raw: {
...textStyle,
color: "inherit",
font: "inherit",
whiteSpace: "inherit"
},
textOneLine: {
maxWidth: "100%",
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
wordWrap: "normal"
},
// See #13
textMultiLine: {
display: "-webkit-box",
maxWidth: "100%",
overflow: "hidden",
textOverflow: "ellipsis",
WebkitBoxOrient: "vertical"
},
notSelectable: {
userSelect: "none"
},
selectable: {
userSelect: "text"
},
pressable: {
cursor: "pointer"
}
};
var Text_default = Text;