@tamagui/web 1.2.9 → 1.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/dist/esm/Tamagui.mjs +41 -0
  2. package/dist/esm/Tamagui.mjs.map +7 -0
  3. package/dist/esm/addTheme.mjs +54 -0
  4. package/dist/esm/addTheme.mjs.map +7 -0
  5. package/dist/esm/config.mjs +84 -0
  6. package/dist/esm/config.mjs.map +7 -0
  7. package/dist/esm/constants/constants.mjs +22 -0
  8. package/dist/esm/constants/constants.mjs.map +7 -0
  9. package/dist/esm/constants/isDevTools.mjs +13 -0
  10. package/dist/esm/constants/isDevTools.mjs.map +7 -0
  11. package/dist/esm/contexts/ButtonNestingContext.mjs +6 -0
  12. package/dist/esm/contexts/ButtonNestingContext.mjs.map +7 -0
  13. package/dist/esm/contexts/FontLanguageContext.mjs +6 -0
  14. package/dist/esm/contexts/FontLanguageContext.mjs.map +7 -0
  15. package/dist/esm/contexts/TextAncestorContext.mjs +6 -0
  16. package/dist/esm/contexts/TextAncestorContext.mjs.map +7 -0
  17. package/dist/esm/createComponent.mjs +853 -0
  18. package/dist/esm/createComponent.mjs.map +7 -0
  19. package/dist/esm/createFont.mjs +45 -0
  20. package/dist/esm/createFont.mjs.map +7 -0
  21. package/dist/esm/createShorthands.mjs +7 -0
  22. package/dist/esm/createShorthands.mjs.map +7 -0
  23. package/dist/esm/createTamagui.mjs +190 -0
  24. package/dist/esm/createTamagui.mjs.map +7 -0
  25. package/dist/esm/createTheme.mjs +7 -0
  26. package/dist/esm/createTheme.mjs.map +7 -0
  27. package/dist/esm/createTokens.mjs +15 -0
  28. package/dist/esm/createTokens.mjs.map +7 -0
  29. package/dist/esm/createVariable.mjs +78 -0
  30. package/dist/esm/createVariable.mjs.map +7 -0
  31. package/dist/esm/createVariables.mjs +35 -0
  32. package/dist/esm/createVariables.mjs.map +7 -0
  33. package/dist/esm/helpers/RNComponents.mjs +16 -0
  34. package/dist/esm/helpers/RNComponents.mjs.map +7 -0
  35. package/dist/esm/helpers/ThemeManager.mjs +209 -0
  36. package/dist/esm/helpers/ThemeManager.mjs.map +7 -0
  37. package/dist/esm/helpers/ThemeManagerContext.mjs +6 -0
  38. package/dist/esm/helpers/ThemeManagerContext.mjs.map +7 -0
  39. package/dist/esm/helpers/createMediaStyle.mjs +42 -0
  40. package/dist/esm/helpers/createMediaStyle.mjs.map +7 -0
  41. package/dist/esm/helpers/createPropMapper.mjs +396 -0
  42. package/dist/esm/helpers/createPropMapper.mjs.map +7 -0
  43. package/dist/esm/helpers/createProxy.mjs +19 -0
  44. package/dist/esm/helpers/createProxy.mjs.map +7 -0
  45. package/dist/esm/helpers/expandStyle.mjs +71 -0
  46. package/dist/esm/helpers/expandStyle.mjs.map +7 -0
  47. package/dist/esm/helpers/expandStyles.mjs +90 -0
  48. package/dist/esm/helpers/expandStyles.mjs.map +7 -0
  49. package/dist/esm/helpers/extendStaticConfig.mjs +66 -0
  50. package/dist/esm/helpers/extendStaticConfig.mjs.map +7 -0
  51. package/dist/esm/helpers/getAnimationDriver.mjs +8 -0
  52. package/dist/esm/helpers/getAnimationDriver.mjs.map +7 -0
  53. package/dist/esm/helpers/getExpandedShorthands.mjs +16 -0
  54. package/dist/esm/helpers/getExpandedShorthands.mjs.map +7 -0
  55. package/dist/esm/helpers/getFontLanguage.mjs +5 -0
  56. package/dist/esm/helpers/getFontLanguage.mjs.map +7 -0
  57. package/dist/esm/helpers/getSplitStyles.mjs +849 -0
  58. package/dist/esm/helpers/getSplitStyles.mjs.map +7 -0
  59. package/dist/esm/helpers/getStylesAtomic.mjs +200 -0
  60. package/dist/esm/helpers/getStylesAtomic.mjs.map +7 -0
  61. package/dist/esm/helpers/getStylesAtomic.native.mjs +12 -0
  62. package/dist/esm/helpers/getStylesAtomic.native.mjs.map +7 -0
  63. package/dist/esm/helpers/getThemeCSSRules.mjs +86 -0
  64. package/dist/esm/helpers/getThemeCSSRules.mjs.map +7 -0
  65. package/dist/esm/helpers/getThemeCSSRules.native.mjs +7 -0
  66. package/dist/esm/helpers/getThemeCSSRules.native.mjs.map +7 -0
  67. package/dist/esm/helpers/getVariantExtras.mjs +67 -0
  68. package/dist/esm/helpers/getVariantExtras.mjs.map +7 -0
  69. package/dist/esm/helpers/insertStyleRule.mjs +186 -0
  70. package/dist/esm/helpers/insertStyleRule.mjs.map +7 -0
  71. package/dist/esm/helpers/isObj.mjs +5 -0
  72. package/dist/esm/helpers/isObj.mjs.map +7 -0
  73. package/dist/esm/helpers/isTamaguiComponent.mjs +8 -0
  74. package/dist/esm/helpers/isTamaguiComponent.mjs.map +7 -0
  75. package/dist/esm/helpers/isTamaguiElement.mjs +9 -0
  76. package/dist/esm/helpers/isTamaguiElement.mjs.map +7 -0
  77. package/dist/esm/helpers/matchMedia.mjs +17 -0
  78. package/dist/esm/helpers/matchMedia.mjs.map +7 -0
  79. package/dist/esm/helpers/matchMedia.native.mjs +23 -0
  80. package/dist/esm/helpers/matchMedia.native.mjs.map +7 -0
  81. package/dist/esm/helpers/mergeProps.mjs +30 -0
  82. package/dist/esm/helpers/mergeProps.mjs.map +7 -0
  83. package/dist/esm/helpers/mergeTransform.mjs +21 -0
  84. package/dist/esm/helpers/mergeTransform.mjs.map +7 -0
  85. package/dist/esm/helpers/normalizeColor.mjs +36 -0
  86. package/dist/esm/helpers/normalizeColor.mjs.map +7 -0
  87. package/dist/esm/helpers/normalizeValueWithProperty.mjs +113 -0
  88. package/dist/esm/helpers/normalizeValueWithProperty.mjs.map +7 -0
  89. package/dist/esm/helpers/proxyThemeVariables.mjs +16 -0
  90. package/dist/esm/helpers/proxyThemeVariables.mjs.map +7 -0
  91. package/dist/esm/helpers/pseudoDescriptors.mjs +29 -0
  92. package/dist/esm/helpers/pseudoDescriptors.mjs.map +7 -0
  93. package/dist/esm/helpers/registerCSSVariable.mjs +14 -0
  94. package/dist/esm/helpers/registerCSSVariable.mjs.map +7 -0
  95. package/dist/esm/helpers/themeable.mjs +28 -0
  96. package/dist/esm/helpers/themeable.mjs.map +7 -0
  97. package/dist/esm/helpers/themes.mjs +53 -0
  98. package/dist/esm/helpers/themes.mjs.map +7 -0
  99. package/dist/esm/helpers/timer.mjs +11 -0
  100. package/dist/esm/helpers/timer.mjs.map +7 -0
  101. package/dist/esm/helpers/useShallowSetState.mjs +35 -0
  102. package/dist/esm/helpers/useShallowSetState.mjs.map +7 -0
  103. package/dist/esm/helpers/warnOnce.mjs +14 -0
  104. package/dist/esm/helpers/warnOnce.mjs.map +7 -0
  105. package/dist/esm/helpers/withStaticProperties.mjs +8 -0
  106. package/dist/esm/helpers/withStaticProperties.mjs.map +7 -0
  107. package/dist/esm/hooks/getThemeUnwrapped.mjs +9 -0
  108. package/dist/esm/hooks/getThemeUnwrapped.mjs.map +7 -0
  109. package/dist/esm/hooks/useId.mjs +5 -0
  110. package/dist/esm/hooks/useId.mjs.map +7 -0
  111. package/dist/esm/hooks/useIsTouchDevice.mjs +9 -0
  112. package/dist/esm/hooks/useIsTouchDevice.mjs.map +7 -0
  113. package/dist/esm/hooks/useMedia.mjs +225 -0
  114. package/dist/esm/hooks/useMedia.mjs.map +7 -0
  115. package/dist/esm/hooks/useSafeRef.mjs +35 -0
  116. package/dist/esm/hooks/useSafeRef.mjs.map +7 -0
  117. package/dist/esm/hooks/useServerHooks.mjs +11 -0
  118. package/dist/esm/hooks/useServerHooks.mjs.map +7 -0
  119. package/dist/esm/hooks/useStyle.mjs +37 -0
  120. package/dist/esm/hooks/useStyle.mjs.map +7 -0
  121. package/dist/esm/hooks/useTheme.mjs +205 -0
  122. package/dist/esm/hooks/useTheme.mjs.map +7 -0
  123. package/dist/esm/hooks/useThemeName.mjs +28 -0
  124. package/dist/esm/hooks/useThemeName.mjs.map +7 -0
  125. package/dist/esm/index.mjs +77 -0
  126. package/dist/esm/index.mjs.map +7 -0
  127. package/dist/esm/inject-styles.mjs +16 -0
  128. package/dist/esm/inject-styles.mjs.map +7 -0
  129. package/dist/esm/insertFont.mjs +67 -0
  130. package/dist/esm/insertFont.mjs.map +7 -0
  131. package/dist/esm/setupHooks.mjs +9 -0
  132. package/dist/esm/setupHooks.mjs.map +7 -0
  133. package/dist/esm/setupReactNative.mjs +25 -0
  134. package/dist/esm/setupReactNative.mjs.map +7 -0
  135. package/dist/esm/styled.mjs +71 -0
  136. package/dist/esm/styled.mjs.map +7 -0
  137. package/dist/esm/types.mjs +1 -0
  138. package/dist/esm/types.mjs.map +7 -0
  139. package/dist/esm/updateTheme.mjs +23 -0
  140. package/dist/esm/updateTheme.mjs.map +7 -0
  141. package/dist/esm/views/FontLanguage.mjs +17 -0
  142. package/dist/esm/views/FontLanguage.mjs.map +7 -0
  143. package/dist/esm/views/FontLanguage.native.mjs +11 -0
  144. package/dist/esm/views/FontLanguage.native.mjs.map +7 -0
  145. package/dist/esm/views/FontLanguage.types.mjs +1 -0
  146. package/dist/esm/views/FontLanguage.types.mjs.map +7 -0
  147. package/dist/esm/views/Slot.mjs +66 -0
  148. package/dist/esm/views/Slot.mjs.map +7 -0
  149. package/dist/esm/views/Stack.mjs +14 -0
  150. package/dist/esm/views/Stack.mjs.map +7 -0
  151. package/dist/esm/views/TamaguiProvider.mjs +56 -0
  152. package/dist/esm/views/TamaguiProvider.mjs.map +7 -0
  153. package/dist/esm/views/Text.mjs +70 -0
  154. package/dist/esm/views/Text.mjs.map +7 -0
  155. package/dist/esm/views/Theme.mjs +63 -0
  156. package/dist/esm/views/Theme.mjs.map +7 -0
  157. package/dist/esm/views/ThemeProvider.mjs +45 -0
  158. package/dist/esm/views/ThemeProvider.mjs.map +7 -0
  159. package/package.json +11 -11
@@ -0,0 +1,853 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useComposedRefs } from "@tamagui/compose-refs";
3
+ import { isClient, isRSC, isServer, isWeb } from "@tamagui/constants";
4
+ import {
5
+ stylePropsView,
6
+ validPseudoKeys,
7
+ validStyles
8
+ } from "@tamagui/helpers";
9
+ import React, {
10
+ Children,
11
+ Fragment,
12
+ createElement,
13
+ forwardRef,
14
+ memo,
15
+ useCallback,
16
+ useContext,
17
+ useEffect,
18
+ useRef
19
+ } from "react";
20
+ import { onConfiguredOnce } from "./config";
21
+ import { stackDefaultStyles } from "./constants/constants";
22
+ import { FontLanguageContext } from "./contexts/FontLanguageContext";
23
+ import { TextAncestorContext } from "./contexts/TextAncestorContext";
24
+ import { didGetVariableValue, setDidGetVariableValue } from "./createVariable";
25
+ import { extendStaticConfig, parseStaticConfig } from "./helpers/extendStaticConfig";
26
+ import { useSplitStyles } from "./helpers/getSplitStyles";
27
+ import { getAllSelectors } from "./helpers/insertStyleRule";
28
+ import { mergeProps } from "./helpers/mergeProps";
29
+ import { proxyThemeVariables } from "./helpers/proxyThemeVariables";
30
+ import { useShallowSetState } from "./helpers/useShallowSetState";
31
+ import { setMediaShouldUpdate, useMedia } from "./hooks/useMedia";
32
+ import { useServerRef, useServerState } from "./hooks/useServerHooks";
33
+ import { useThemeWithState } from "./hooks/useTheme";
34
+ import { hooks } from "./setupHooks";
35
+ import { Slot } from "./views/Slot";
36
+ import { useThemedChildren } from "./views/Theme";
37
+ process.env.TAMAGUI_TARGET;
38
+ const defaultComponentState = {
39
+ hover: false,
40
+ press: false,
41
+ pressIn: false,
42
+ focus: false,
43
+ unmounted: true
44
+ };
45
+ const defaultComponentStateMounted = {
46
+ ...defaultComponentState,
47
+ unmounted: false
48
+ };
49
+ let tamaguiConfig;
50
+ let AnimatedText;
51
+ let AnimatedView;
52
+ let initialTheme;
53
+ const mouseUps = /* @__PURE__ */ new Set();
54
+ if (typeof document !== "undefined") {
55
+ const cancelTouches = () => {
56
+ mouseUps.forEach((x) => x());
57
+ mouseUps.clear();
58
+ };
59
+ addEventListener("mouseup", cancelTouches);
60
+ addEventListener("touchend", cancelTouches);
61
+ addEventListener("touchcancel", cancelTouches);
62
+ }
63
+ function mergeShorthands({ defaultProps }, { shorthands }) {
64
+ for (const key of Object.keys(defaultProps)) {
65
+ defaultProps[shorthands[key] || key] = defaultProps[key];
66
+ }
67
+ }
68
+ let BaseText;
69
+ let BaseView;
70
+ let hasSetupBaseViews = false;
71
+ function createComponent(configIn, ParentComponent) {
72
+ const staticConfig = (() => {
73
+ const next = extendStaticConfig(configIn, ParentComponent);
74
+ if ("parsed" in next) {
75
+ return next;
76
+ } else {
77
+ return parseStaticConfig(next);
78
+ }
79
+ })();
80
+ const defaultComponentClassName = `is_${staticConfig.componentName}`;
81
+ let tamaguiDefaultProps;
82
+ let defaultTag;
83
+ const component = forwardRef((propsIn, forwardedRef) => {
84
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
85
+ if (process.env.TAMAGUI_TARGET === "native") {
86
+ if (!hasSetupBaseViews) {
87
+ hasSetupBaseViews = true;
88
+ const baseViews = (_b = (_a = hooks).getBaseViews) == null ? void 0 : _b.call(_a);
89
+ if (baseViews) {
90
+ BaseText = baseViews.Text;
91
+ BaseView = baseViews.View;
92
+ }
93
+ }
94
+ }
95
+ if (process.env.NODE_ENV === "test") {
96
+ if (propsIn["data-test-renders"]) {
97
+ propsIn["data-test-renders"]["current"] ??= 0;
98
+ propsIn["data-test-renders"]["current"] += 1;
99
+ }
100
+ }
101
+ let props;
102
+ if (tamaguiDefaultProps && !propsIn.asChild) {
103
+ props = mergeProps(tamaguiDefaultProps, propsIn)[0];
104
+ } else {
105
+ props = propsIn;
106
+ }
107
+ const debugProp = props["debug"];
108
+ const { Component, isText, isZStack } = staticConfig;
109
+ const componentName = props.componentName || staticConfig.componentName;
110
+ const componentClassName = props.asChild ? "" : props.componentName ? `is_${props.componentName}` : defaultComponentClassName;
111
+ const animationsConfig = tamaguiConfig.animations;
112
+ const useAnimations = animationsConfig == null ? void 0 : animationsConfig.useAnimations;
113
+ const avoidClassesWhileAnimating = animationsConfig.isReactNative;
114
+ const hasEnterStyle = !!props.enterStyle;
115
+ const needsMount = Boolean(
116
+ (isWeb ? isClient : true) && (hasEnterStyle || props.animation)
117
+ );
118
+ const states = useServerState(
119
+ needsMount ? defaultComponentState : defaultComponentStateMounted
120
+ );
121
+ const state = propsIn.forceStyle ? { ...states[0], [propsIn.forceStyle]: true } : states[0];
122
+ const setState = states[1];
123
+ const setStateShallow = useShallowSetState(setState, debugProp, componentName);
124
+ const stateRef = useRef(
125
+ void 0
126
+ );
127
+ stateRef.current ??= {};
128
+ const isAnimated = (() => {
129
+ const next = !!(useAnimations && props.animation);
130
+ if (next && !stateRef.current.hasAnimated) {
131
+ stateRef.current.hasAnimated = true;
132
+ }
133
+ return next || stateRef.current.hasAnimated;
134
+ })();
135
+ const usePresence = (_c = tamaguiConfig.animations) == null ? void 0 : _c.usePresence;
136
+ const presence = !isRSC && isAnimated ? usePresence() : null;
137
+ if (isAnimated && presence) {
138
+ const presenceState = presence[2];
139
+ if (presenceState) {
140
+ if (state.unmounted && presenceState.enterVariant) {
141
+ props[presenceState.enterVariant] = true;
142
+ }
143
+ if (!presenceState.isPresent && presenceState.exitVariant) {
144
+ props[presenceState.exitVariant] = true;
145
+ }
146
+ }
147
+ }
148
+ const isReactNative = Boolean(
149
+ staticConfig.isReactNative || isAnimated && tamaguiConfig.animations.isReactNative
150
+ );
151
+ if (process.env.NODE_ENV === "development") {
152
+ if (debugProp) {
153
+ const name = `${componentName || (Component == null ? void 0 : Component.displayName) || (Component == null ? void 0 : Component.name) || "[Unnamed Component]"}`;
154
+ const type = isReactNative ? "(rnw)" : "";
155
+ const dataIs = propsIn["data-is"] || "";
156
+ const banner = `${name}${dataIs ? ` ${dataIs}` : ""} ${type}`;
157
+ console.group(`%c ${banner}`, "background: yellow;");
158
+ if (!isServer) {
159
+ console.log("state", state);
160
+ }
161
+ }
162
+ }
163
+ const shouldAvoidClasses = !isWeb || !!(props.animation && avoidClassesWhileAnimating) || !staticConfig.acceptsClassName;
164
+ const shouldForcePseudo = !!propsIn.forceStyle;
165
+ const noClassNames = shouldAvoidClasses || shouldForcePseudo;
166
+ const themeState = useThemeWithState({
167
+ name: props.theme,
168
+ componentName,
169
+ reset: props.reset,
170
+ inverse: props.themeInverse,
171
+ // @ts-expect-error
172
+ disable: props["data-themeable"],
173
+ debug: props.debug,
174
+ shouldUpdate: () => !!stateRef.current.didAccessThemeVariableValue
175
+ });
176
+ const hasTextAncestor = !!(isWeb && isText ? useContext(TextAncestorContext) : false);
177
+ const languageContext = isRSC ? null : useContext(FontLanguageContext);
178
+ const isDisabled = props.disabled ?? ((_d = props.accessibilityState) == null ? void 0 : _d.disabled);
179
+ const isTaggable = !Component || typeof Component === "string";
180
+ const element = isWeb ? isTaggable ? props.tag || defaultTag || Component : Component : Component;
181
+ const BaseTextComponent = BaseText || element || "span";
182
+ const BaseViewComponent = BaseView || element || (hasTextAncestor ? "span" : "div");
183
+ let elementType = isText ? (isAnimated ? AnimatedText : null) || BaseTextComponent : (isAnimated ? AnimatedView : null) || BaseViewComponent;
184
+ elementType = Component || elementType;
185
+ const isStringElement = typeof elementType === "string";
186
+ const isExiting = (presence == null ? void 0 : presence[0]) === false;
187
+ const mediaState = useMedia(
188
+ // @ts-ignore, we just pass a stable object so we can get it later with
189
+ // should match to the one used in `setMediaShouldUpdate` below
190
+ stateRef,
191
+ debugProp ? { props, staticConfig } : null
192
+ );
193
+ setDidGetVariableValue(false);
194
+ const splitStyles = useSplitStyles(
195
+ props,
196
+ staticConfig,
197
+ themeState.theme,
198
+ {
199
+ ...state,
200
+ mediaState,
201
+ noClassNames,
202
+ dynamicStylesInline: noClassNames,
203
+ hasTextAncestor,
204
+ resolveVariablesAs: "auto",
205
+ isExiting
206
+ },
207
+ null,
208
+ languageContext || void 0,
209
+ elementType,
210
+ debugProp
211
+ );
212
+ const isMediaSpaced = Array.isArray(splitStyles.hasMedia);
213
+ const shouldListenForMedia = didGetVariableValue() || isMediaSpaced || noClassNames && splitStyles.hasMedia === true;
214
+ setMediaShouldUpdate(stateRef, {
215
+ enabled: shouldListenForMedia,
216
+ keys: noClassNames && isMediaSpaced ? splitStyles.hasMedia : null
217
+ });
218
+ const hostRef = useServerRef(null);
219
+ const isAnimatedReactNativeWeb = isAnimated && avoidClassesWhileAnimating;
220
+ if (process.env.NODE_ENV === "development") {
221
+ if (!process.env.TAMAGUI_TARGET) {
222
+ console.error(
223
+ `No process.env.TAMAGUI_TARGET set, please set it to "native" or "web".`
224
+ );
225
+ }
226
+ if (debugProp) {
227
+ console.groupCollapsed("props");
228
+ console.log("props in", propsIn, "mapped to", props, "in order", Object.keys(props));
229
+ console.log("splitStyles", splitStyles);
230
+ console.log("shouldListenForMedia", shouldListenForMedia);
231
+ console.log("className", Object.values(splitStyles.classNames));
232
+ if (isClient) {
233
+ console.log("ref", hostRef, "(click to view)");
234
+ }
235
+ console.groupEnd();
236
+ if (debugProp === "break") {
237
+ debugger;
238
+ }
239
+ }
240
+ }
241
+ const {
242
+ viewProps: viewPropsIn,
243
+ pseudos,
244
+ style: splitStylesStyle,
245
+ classNames,
246
+ space
247
+ } = splitStyles;
248
+ const propsWithAnimation = props;
249
+ let animationStyles;
250
+ if (!isRSC && isAnimated && useAnimations) {
251
+ const animations = useAnimations({
252
+ props: propsWithAnimation,
253
+ style: splitStylesStyle,
254
+ presence,
255
+ state,
256
+ pseudos: pseudos || null,
257
+ onDidAnimate: props.onDidAnimate,
258
+ hostRef,
259
+ staticConfig
260
+ });
261
+ if (animations) {
262
+ animationStyles = animations.style;
263
+ }
264
+ }
265
+ const {
266
+ hitSlop,
267
+ asChild,
268
+ children,
269
+ onPress,
270
+ onPressIn,
271
+ onPressOut,
272
+ onHoverIn,
273
+ onHoverOut,
274
+ themeShallow,
275
+ spaceDirection: _spaceDirection,
276
+ disabled: disabledProp,
277
+ onMouseUp,
278
+ onMouseDown,
279
+ onMouseEnter,
280
+ onMouseLeave,
281
+ separator,
282
+ // ignore from here on out
283
+ forceStyle: _forceStyle,
284
+ // @ts-ignore for next/link compat etc
285
+ onClick,
286
+ theme: _themeProp,
287
+ // @ts-ignore
288
+ defaultVariants,
289
+ ...nonTamaguiProps
290
+ } = viewPropsIn;
291
+ const disabled = ((_e = props.accessibilityState) == null ? void 0 : _e.disabled) || props.accessibilityDisabled;
292
+ let viewProps = nonTamaguiProps;
293
+ if (process.env.TAMAGUI_TARGET === "web" && !isReactNative) {
294
+ const nextProps = (_g = (_f = hooks).usePropsTransform) == null ? void 0 : _g.call(_f, elementType, nonTamaguiProps, hostRef);
295
+ if (!asChild) {
296
+ viewProps = nextProps;
297
+ }
298
+ }
299
+ viewProps.ref = useComposedRefs(hostRef, forwardedRef);
300
+ if (process.env.NODE_ENV === "development") {
301
+ if (!isText && isWeb && !staticConfig.isHOC) {
302
+ Children.toArray(props.children).forEach((item) => {
303
+ if (typeof item === "string" && item !== "\n") {
304
+ console.error(
305
+ `Unexpected text node: ${item}. A text node cannot be a child of a <View>.`
306
+ );
307
+ }
308
+ });
309
+ }
310
+ }
311
+ const unPress = useCallback(() => {
312
+ setStateShallow({
313
+ press: false,
314
+ pressIn: false
315
+ });
316
+ }, [setStateShallow]);
317
+ if (isWeb) {
318
+ useEffect(() => {
319
+ return () => {
320
+ mouseUps.delete(unPress);
321
+ };
322
+ }, []);
323
+ }
324
+ const shouldSetMounted = needsMount && state.unmounted;
325
+ useEffect(() => {
326
+ if (!shouldSetMounted)
327
+ return;
328
+ if (state.unmounted === true && needsMount) {
329
+ setStateShallow({
330
+ unmounted: false
331
+ });
332
+ return;
333
+ }
334
+ setStateShallow({
335
+ unmounted: false
336
+ });
337
+ }, [shouldSetMounted, state.unmounted]);
338
+ let styles;
339
+ if (isStringElement && shouldAvoidClasses && !shouldForcePseudo) {
340
+ styles = {
341
+ ...animationStyles ?? splitStylesStyle
342
+ };
343
+ } else {
344
+ styles = [animationStyles ?? splitStylesStyle];
345
+ if (shouldForcePseudo) {
346
+ const next = {};
347
+ styles.forEach((style) => Object.assign(next, style));
348
+ Object.assign(splitStyles.style, next);
349
+ }
350
+ }
351
+ let fontFamily = isText ? splitStyles.fontFamily || staticConfig.defaultProps.fontFamily : null;
352
+ if (fontFamily && fontFamily[0] === "$") {
353
+ fontFamily = fontFamily.slice(1);
354
+ }
355
+ const fontFamilyClassName = fontFamily ? `font_${fontFamily}` : "";
356
+ const classList = [
357
+ hasEnterStyle && (state.unmounted && needsMount || !isClient) ? "t_will-mount" : "",
358
+ componentName ? componentClassName : "",
359
+ fontFamilyClassName,
360
+ classNames ? Object.values(classNames).join(" ") : ""
361
+ ];
362
+ const className = classList.join(" ");
363
+ if (process.env.TAMAGUI_TARGET === "web") {
364
+ const style = animationStyles ?? splitStyles.style;
365
+ if (isAnimatedReactNativeWeb) {
366
+ viewProps.style = style;
367
+ } else if (isReactNative) {
368
+ const rnwStyle = { $$css: true };
369
+ for (const name of className.split(" ")) {
370
+ rnwStyle[name] = name;
371
+ }
372
+ viewProps.style = [rnwStyle, ...Array.isArray(style) ? style : [style]];
373
+ if (process.env.NODE_ENV === "development") {
374
+ Object.keys(viewProps).forEach((key) => {
375
+ if (key.startsWith("data-")) {
376
+ viewProps.dataSet ??= {};
377
+ viewProps.dataSet[key.replace("data-", "")] = viewProps[key];
378
+ delete viewProps[key];
379
+ }
380
+ });
381
+ }
382
+ } else {
383
+ viewProps.className = className;
384
+ viewProps.style = style;
385
+ }
386
+ }
387
+ if (process.env.TAMAGUI_TARGET === "native") {
388
+ if (splitStyles.fontFamily) {
389
+ const faceInfo = (_h = tamaguiConfig.fontsParsed[splitStyles.fontFamily]) == null ? void 0 : _h.face;
390
+ if (faceInfo) {
391
+ const [weight, style] = (() => {
392
+ var _a2, _b2;
393
+ let weight2;
394
+ let style2;
395
+ for (let i = styles.length; i >= 0; i--) {
396
+ weight2 ??= (_a2 = styles[i]) == null ? void 0 : _a2.fontWeight;
397
+ style2 ??= (_b2 = styles[i]) == null ? void 0 : _b2.fontStyle;
398
+ }
399
+ return [weight2 || "400", style2 || "normal"];
400
+ })();
401
+ const overrideFace = (_j = (_i = faceInfo[weight]) == null ? void 0 : _i[style]) == null ? void 0 : _j.val;
402
+ if (overrideFace) {
403
+ for (const style2 of styles) {
404
+ if (style2 == null ? void 0 : style2.fontFamily) {
405
+ style2.fontFamily = overrideFace;
406
+ style2.fontWeight = void 0;
407
+ style2.fontStyle = void 0;
408
+ }
409
+ }
410
+ }
411
+ }
412
+ }
413
+ viewProps.style = styles;
414
+ }
415
+ const runtimePressStyle = !disabled && noClassNames && (pseudos == null ? void 0 : pseudos.pressStyle);
416
+ const attachPress = Boolean(
417
+ runtimePressStyle || onPress || onPressOut || onPressIn || onClick
418
+ );
419
+ const runtimeHoverStyle = !disabled && noClassNames && (pseudos == null ? void 0 : pseudos.hoverStyle);
420
+ const isHoverable = isWeb && !!(runtimeHoverStyle || onHoverIn || onHoverOut || onMouseEnter || onMouseLeave);
421
+ const handlesPressEvents = !(isWeb || asChild);
422
+ const shouldAttach = Boolean(
423
+ attachPress || isHoverable || noClassNames && "pressStyle" in props || isWeb && noClassNames && "hoverStyle" in props
424
+ );
425
+ const events = shouldAttach && !isRSC && !isDisabled && !asChild ? {
426
+ onPressOut: attachPress ? (e) => {
427
+ unPress();
428
+ onPressOut == null ? void 0 : onPressOut(e);
429
+ onMouseUp == null ? void 0 : onMouseUp(e);
430
+ } : void 0,
431
+ ...isHoverable && {
432
+ onMouseEnter: isHoverable ? (e) => {
433
+ const next = {};
434
+ if (isHoverable) {
435
+ next.hover = true;
436
+ }
437
+ if (state.pressIn) {
438
+ next.press = true;
439
+ }
440
+ if (isHoverable || state.pressIn) {
441
+ setStateShallow(next);
442
+ }
443
+ onHoverIn == null ? void 0 : onHoverIn(e);
444
+ onMouseEnter == null ? void 0 : onMouseEnter(e);
445
+ } : void 0,
446
+ onMouseLeave: isHoverable ? (e) => {
447
+ const next = {};
448
+ mouseUps.add(unPress);
449
+ if (isHoverable) {
450
+ next.hover = false;
451
+ }
452
+ if (state.pressIn) {
453
+ next.press = false;
454
+ next.pressIn = false;
455
+ }
456
+ if (Object.keys(next).length) {
457
+ setStateShallow(next);
458
+ }
459
+ onHoverOut == null ? void 0 : onHoverOut(e);
460
+ onMouseLeave == null ? void 0 : onMouseLeave(e);
461
+ } : void 0
462
+ },
463
+ onPressIn: attachPress ? (e) => {
464
+ setStateShallow({
465
+ press: true,
466
+ pressIn: true,
467
+ hover: false
468
+ });
469
+ onPressIn == null ? void 0 : onPressIn(e);
470
+ onMouseDown == null ? void 0 : onMouseDown(e);
471
+ if (isWeb) {
472
+ mouseUps.add(unPress);
473
+ }
474
+ } : void 0,
475
+ onPress: attachPress ? (e) => {
476
+ unPress();
477
+ isWeb && (onClick == null ? void 0 : onClick(e));
478
+ onPress == null ? void 0 : onPress(e);
479
+ } : void 0
480
+ } : null;
481
+ if (process.env.TAMAGUI_TARGET === "native") {
482
+ if (events) {
483
+ Object.assign(events, {
484
+ cancelable: !props.rejectResponderTermination,
485
+ disabled: isDisabled,
486
+ hitSlop: props.hitSlop,
487
+ delayLongPress: props.delayLongPress,
488
+ delayPressIn: props.delayPressIn,
489
+ delayPressOut: props.delayPressOut,
490
+ focusable: viewProps.focusable ?? true,
491
+ minPressDuration: 0
492
+ });
493
+ }
494
+ }
495
+ (_l = (_k = hooks).useEvents) == null ? void 0 : _l.call(_k, viewProps, events, splitStyles, setStateShallow);
496
+ const shouldReset = !!(themeShallow && themeState.isNewTheme);
497
+ if (shouldReset) {
498
+ stateRef.current.themeShallow = true;
499
+ }
500
+ let content = !children || asChild ? children : spacedChildren({
501
+ separator,
502
+ children,
503
+ space,
504
+ direction: props.spaceDirection || "both",
505
+ isZStack,
506
+ debug: debugProp
507
+ });
508
+ if (asChild) {
509
+ elementType = Slot;
510
+ viewProps = {
511
+ ...viewProps,
512
+ onPress,
513
+ onPressIn,
514
+ onPressOut
515
+ };
516
+ }
517
+ content = createElement(elementType, viewProps, content);
518
+ content = useThemedChildren(themeState, content, {
519
+ shallow: stateRef.current.themeShallow
520
+ });
521
+ if (process.env.TAMAGUI_TARGET === "web") {
522
+ if (events || isAnimatedReactNativeWeb) {
523
+ content = /* @__PURE__ */ jsx(
524
+ "span",
525
+ {
526
+ className: `${isAnimatedReactNativeWeb ? className : ""} _dsp_contents`,
527
+ ...events && {
528
+ onMouseEnter: events.onMouseEnter,
529
+ onMouseLeave: events.onMouseLeave,
530
+ onClick: events.onPress,
531
+ onMouseDown: events.onPressIn,
532
+ onMouseUp: events.onPressOut,
533
+ onTouchStart: events.onPressIn,
534
+ onTouchEnd: events.onPressOut
535
+ },
536
+ children: content
537
+ }
538
+ );
539
+ }
540
+ }
541
+ if (process.env.NODE_ENV === "development" && process.env.DEBUG !== "tamagui") {
542
+ if (debugProp) {
543
+ const element2 = typeof elementType === "string" ? elementType : "Component";
544
+ console.groupCollapsed(`render <${element2} /> with props`, viewProps);
545
+ for (const key in viewProps) {
546
+ console.log(key, viewProps[key]);
547
+ }
548
+ console.log("children", content);
549
+ console.groupEnd();
550
+ if (typeof window !== "undefined") {
551
+ console.log({ state, themeState, isAnimated, isAnimatedReactNativeWeb, tamaguiDefaultProps, viewProps, splitStyles, animationStyles, handlesPressEvents, isStringElement, classNamesIn: (_m = props.className) == null ? void 0 : _m.split(" "), classNamesOut: (_n = viewProps.className) == null ? void 0 : _n.split(" "), events, shouldAttach, styles, pseudos, content, shouldAvoidClasses, avoidClasses: avoidClassesWhileAnimating, animation: props.animation, style: splitStylesStyle, staticConfig, tamaguiConfig, shouldForcePseudo, classNamesFull: Object.fromEntries(Object.entries(classNames).map(([k, v]) => [v, getAllSelectors()[v]])) });
552
+ }
553
+ console.groupEnd();
554
+ }
555
+ }
556
+ return content;
557
+ });
558
+ if (staticConfig.componentName) {
559
+ component.displayName = staticConfig.componentName;
560
+ }
561
+ onConfiguredOnce((conf) => {
562
+ if (!tamaguiConfig) {
563
+ tamaguiConfig = conf;
564
+ if (tamaguiConfig.animations) {
565
+ AnimatedText = tamaguiConfig.animations.Text;
566
+ AnimatedView = tamaguiConfig.animations.View;
567
+ }
568
+ if (!initialTheme) {
569
+ const next = conf.themes[Object.keys(conf.themes)[0]];
570
+ initialTheme = proxyThemeVariables(next);
571
+ if (process.env.NODE_ENV === "development") {
572
+ if (!initialTheme) {
573
+ console.log("Warning: Missing theme");
574
+ }
575
+ }
576
+ }
577
+ }
578
+ mergeShorthands(staticConfig, tamaguiConfig);
579
+ let defaultPropsIn = staticConfig.defaultProps || {};
580
+ const parentNames = [...staticConfig.parentNames || [], staticConfig.componentName];
581
+ if (tamaguiConfig.defaultProps && parentNames && staticConfig.componentName) {
582
+ defaultPropsIn = mergeConfigDefaultProps(
583
+ staticConfig.componentName,
584
+ defaultPropsIn,
585
+ tamaguiConfig.defaultProps,
586
+ parentNames,
587
+ tamaguiConfig
588
+ );
589
+ }
590
+ const debug = defaultPropsIn["debug"];
591
+ const [ourProps, ourClassNames] = mergeProps(defaultPropsIn, {});
592
+ if (ourProps.tag) {
593
+ defaultTag = ourProps.tag;
594
+ }
595
+ const noClassNames = !staticConfig.acceptsClassName;
596
+ const { name, variants, defaultVariants, ...restProps } = ourProps;
597
+ const [defaults, defaultsClassnames] = mergeProps(component.defaultProps, {
598
+ ...defaultVariants,
599
+ ...restProps
600
+ });
601
+ if (!isWeb) {
602
+ for (const key in staticConfig.defaultProps) {
603
+ const val = staticConfig.defaultProps[key];
604
+ if (validPseudoKeys[key])
605
+ continue;
606
+ defaults[key] = val;
607
+ }
608
+ }
609
+ tamaguiDefaultProps = defaults;
610
+ if (process.env.NODE_ENV === "development" && debug) {
611
+ if (process.env.IS_STATIC !== "is_static") {
612
+ console.log(`\u{1F41B} [${staticConfig.componentName || "Component"}]`, {
613
+ staticConfig,
614
+ tamaguiDefaultProps,
615
+ defaults,
616
+ defaultPropsIn,
617
+ defaultPropsKeyOrder: Object.keys(staticConfig.defaultProps),
618
+ defaultPropsInKeyOrder: Object.keys(defaultPropsIn).map((k) => [
619
+ k,
620
+ defaultPropsIn[k]
621
+ ]),
622
+ ourProps,
623
+ ourClassNames,
624
+ defaultsClassnames,
625
+ defaultTag,
626
+ noClassNames
627
+ });
628
+ }
629
+ }
630
+ });
631
+ let res = component;
632
+ if (configIn.memo) {
633
+ res = memo(res);
634
+ }
635
+ res.staticConfig = {
636
+ validStyles: staticConfig.validStyles || stylePropsView,
637
+ ...staticConfig
638
+ };
639
+ res.extractable = (Component, conf) => {
640
+ Component.staticConfig = extendStaticConfig(
641
+ {
642
+ Component,
643
+ ...conf,
644
+ neverFlatten: true,
645
+ isHOC: true,
646
+ defaultProps: {
647
+ ...Component.defaultProps,
648
+ ...conf == null ? void 0 : conf.defaultProps
649
+ }
650
+ },
651
+ res
652
+ );
653
+ return Component;
654
+ };
655
+ return res;
656
+ }
657
+ const Unspaced = (props) => {
658
+ return props.children;
659
+ };
660
+ Unspaced["isUnspaced"] = true;
661
+ const Spacer = createComponent({
662
+ acceptsClassName: true,
663
+ memo: true,
664
+ componentName: "Spacer",
665
+ validStyles,
666
+ defaultProps: {
667
+ ...stackDefaultStyles,
668
+ // avoid nesting issues
669
+ tag: "span",
670
+ size: true,
671
+ pointerEvents: "none"
672
+ },
673
+ variants: {
674
+ size: {
675
+ "...size": (size, { tokens }) => {
676
+ size = size === true ? "$true" : size;
677
+ const sizePx = tokens.space[size] ?? size;
678
+ return {
679
+ width: sizePx,
680
+ height: sizePx,
681
+ minWidth: sizePx,
682
+ minHeight: sizePx
683
+ };
684
+ }
685
+ },
686
+ flex: {
687
+ true: {
688
+ flexGrow: 1
689
+ }
690
+ },
691
+ direction: {
692
+ horizontal: {
693
+ height: 0,
694
+ minHeight: 0
695
+ },
696
+ vertical: {
697
+ width: 0,
698
+ minWidth: 0
699
+ },
700
+ both: {}
701
+ }
702
+ }
703
+ });
704
+ function spacedChildren(props) {
705
+ var _a, _b, _c;
706
+ const { isZStack, children, space, direction, spaceFlex, separator } = props;
707
+ const hasSpace = !!(space || spaceFlex);
708
+ const hasSeparator = !(separator === void 0 || separator === null);
709
+ if (!(hasSpace || hasSeparator || isZStack)) {
710
+ return children;
711
+ }
712
+ const childrenList = Children.toArray(children);
713
+ const len = childrenList.length;
714
+ if (len <= 1 && !isZStack && !((_b = (_a = childrenList[0]) == null ? void 0 : _a["type"]) == null ? void 0 : _b["shouldForwardSpace"])) {
715
+ return childrenList;
716
+ }
717
+ const final = [];
718
+ for (let [index, child] of childrenList.entries()) {
719
+ const isEmpty = child === null || child === void 0 || Array.isArray(child) && child.length === 0;
720
+ if (!isEmpty && React.isValidElement(child) && ((_c = child.type) == null ? void 0 : _c["shouldForwardSpace"])) {
721
+ child = React.cloneElement(child, {
722
+ space,
723
+ spaceFlex,
724
+ separator,
725
+ key: child.key
726
+ });
727
+ }
728
+ if (isEmpty || !child || child["key"] && !isZStack) {
729
+ final.push(child);
730
+ } else {
731
+ final.push(
732
+ /* @__PURE__ */ jsx(Fragment, { children: isZStack ? /* @__PURE__ */ jsx(AbsoluteFill, { children: child }) : child }, index)
733
+ );
734
+ }
735
+ if (isUnspaced(child) && index === 0)
736
+ continue;
737
+ if (isZStack)
738
+ continue;
739
+ const next = childrenList[index + 1];
740
+ if (next && !isUnspaced(next)) {
741
+ if (separator) {
742
+ if (hasSpace) {
743
+ final.push(
744
+ createSpacer({
745
+ key: `_${index}_00tmgui`,
746
+ direction,
747
+ space,
748
+ spaceFlex
749
+ })
750
+ );
751
+ }
752
+ final.push(
753
+ React.isValidElement(separator) ? React.cloneElement(separator, { key: `sep_${index}` }) : separator
754
+ );
755
+ if (hasSpace) {
756
+ final.push(
757
+ createSpacer({
758
+ key: `_${index}01tmgui`,
759
+ direction,
760
+ space,
761
+ spaceFlex
762
+ })
763
+ );
764
+ }
765
+ } else {
766
+ final.push(
767
+ createSpacer({
768
+ key: `_${index}02tmgui`,
769
+ direction,
770
+ space,
771
+ spaceFlex
772
+ })
773
+ );
774
+ }
775
+ }
776
+ }
777
+ if (process.env.NODE_ENV === "development") {
778
+ if (props.debug) {
779
+ console.log(` Spaced children`, final, props);
780
+ }
781
+ }
782
+ return final;
783
+ }
784
+ function createSpacer({ key, direction, space, spaceFlex }) {
785
+ return (
786
+ // @ts-ignore this one blew up but the types seem better
787
+ /* @__PURE__ */ jsx(
788
+ Spacer,
789
+ {
790
+ size: space,
791
+ direction,
792
+ ...typeof spaceFlex !== "undefined" && {
793
+ flex: spaceFlex === true ? 1 : spaceFlex === false ? 0 : spaceFlex
794
+ }
795
+ },
796
+ key
797
+ )
798
+ );
799
+ }
800
+ function isUnspaced(child) {
801
+ var _a, _b;
802
+ return ((_a = child == null ? void 0 : child["type"]) == null ? void 0 : _a["isVisuallyHidden"]) || ((_b = child == null ? void 0 : child["type"]) == null ? void 0 : _b["isUnspaced"]);
803
+ }
804
+ const DefaultProps = /* @__PURE__ */ new Map();
805
+ function mergeConfigDefaultProps(name, props, configDefaults, parentNames, conf) {
806
+ const len = parentNames.length;
807
+ let prev;
808
+ for (let i = 0; i < len; i++) {
809
+ const n = parentNames[i];
810
+ if (!n)
811
+ continue;
812
+ if (DefaultProps.has(n)) {
813
+ prev = DefaultProps.get(n);
814
+ continue;
815
+ }
816
+ const props2 = configDefaults[n];
817
+ if (!props2) {
818
+ if (prev) {
819
+ DefaultProps.set(n, prev);
820
+ }
821
+ continue;
822
+ }
823
+ prev = mergeProps(prev || {}, props2, false, conf.inverseShorthands)[0];
824
+ DefaultProps.set(n, prev);
825
+ }
826
+ const ourDefaultsMerged = DefaultProps.get(name);
827
+ if (ourDefaultsMerged) {
828
+ return mergeProps(props, ourDefaultsMerged, false, conf.inverseShorthands)[0];
829
+ }
830
+ return props;
831
+ }
832
+ const AbsoluteFill = createComponent({
833
+ componentName: "AbsoluteFill",
834
+ defaultProps: {
835
+ ...stackDefaultStyles,
836
+ flexDirection: "column",
837
+ position: "absolute",
838
+ top: 0,
839
+ right: 0,
840
+ bottom: 0,
841
+ left: 0,
842
+ pointerEvents: "box-none"
843
+ }
844
+ });
845
+ export {
846
+ Spacer,
847
+ Unspaced,
848
+ createComponent,
849
+ defaultComponentState,
850
+ mouseUps,
851
+ spacedChildren
852
+ };
853
+ //# sourceMappingURL=createComponent.mjs.map