UNPKG

@tamagui/react-native-web-lite

Version:
65 lines (64 loc) 3.65 kB
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 createElement_exports = {}; __export(createElement_exports, { default: () => createElement_default, useCreateElement: () => useCreateElement }); module.exports = __toCommonJS(createElement_exports); var import_react_native_web_internals = require("@tamagui/react-native-web-internals"), import_web = require("@tamagui/web"), import_react = __toESM(require("react")), import_jsx_runtime = require("react/jsx-runtime"); const useCreateElement = (component, props, options) => { const { element, styles } = createElementAndStyles(component, props, options), isHydrated = (0, import_web.useDidFinishSSR)(), styleTags = (0, import_react.useMemo)( () => isHydrated || !styles ? null : (0, import_web.getStyleTags)(styles), [ // never changes ] ); return (0, import_react.useInsertionEffect)(() => { if (!styles) return; const styleObj = {}; for (const style of styles) styleObj[style[0]] = style; (0, import_web.insertStyleRules)(styleObj); }, [styles]), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [ element, styleTags ] }); }, createElement = (component, props, options) => { const { element, styles } = createElementAndStyles(component, props, options); return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [ element, styles ? (0, import_web.getStyleTags)(styles) : null ] }); }, createElementAndStyles = (component, props, options) => { let accessibilityComponent; component && component.constructor === String && (accessibilityComponent = import_react_native_web_internals.AccessibilityUtil.propsToAccessibilityComponent(props)); const Component = accessibilityComponent || component, domProps = (0, import_react_native_web_internals.createDOMProps)(Component, props, options), styles = import_react_native_web_internals.stylesFromProps.get(domProps); let element = import_react.default.createElement(Component, domProps); return { element: domProps.dir ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native_web_internals.LocaleProvider, { direction: domProps.dir, locale: domProps.lang, children: element }) : element, styles }; }; var createElement_default = createElement; //# sourceMappingURL=index.js.map